summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-02-13 15:25:20 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-02-13 15:25:20 -0200
commit90b0ac6495cb5b4f06b795bef3da346a55581284 (patch)
treeb4e75b2323b29cdae4bec2af1d0b7a737ad687b0
parentde3b1c9b53d74de4f22fe75b801cc57e1ba2840e (diff)
downloadlua-90b0ac6495cb5b4f06b795bef3da346a55581284.tar.gz
lua-90b0ac6495cb5b4f06b795bef3da346a55581284.tar.bz2
lua-90b0ac6495cb5b4f06b795bef3da346a55581284.zip
limit to 'gcstepmul' imposed by 'lua_gc' (+ some details in 'lgc.c')
-rw-r--r--lapi.c3
-rw-r--r--lgc.c29
2 files changed, 20 insertions, 12 deletions
diff --git a/lapi.c b/lapi.c
index 0fcb6eaa..d5765cc9 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.193 2014/01/27 13:34:32 roberto Exp roberto $ 2** $Id: lapi.c,v 2.194 2014/02/13 12:11:34 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -1086,6 +1086,7 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
1086 } 1086 }
1087 case LUA_GCSETSTEPMUL: { 1087 case LUA_GCSETSTEPMUL: {
1088 res = g->gcstepmul; 1088 res = g->gcstepmul;
1089 if (data < 40) data = 40; /* avoid ridiculous low values (and 0) */
1089 g->gcstepmul = data; 1090 g->gcstepmul = data;
1090 break; 1091 break;
1091 } 1092 }
diff --git a/lgc.c b/lgc.c
index 515267e7..ea0537df 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 2.171 2014/02/13 12:11:34 roberto Exp roberto $ 2** $Id: lgc.c,v 2.172 2014/02/13 14:46:38 roberto Exp roberto $
3** Garbage Collector 3** Garbage Collector
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -1060,9 +1060,9 @@ void luaC_runtilstate (lua_State *L, int statesmask) {
1060 1060
1061 1061
1062/* 1062/*
1063** run a few finalizers 1063** run a few (up to 'g->gcfinnum') finalizers
1064*/ 1064*/
1065static int dosomefinalization (lua_State *L) { 1065static int runafewfinalizers (lua_State *L) {
1066 global_State *g = G(L); 1066 global_State *g = G(L);
1067 unsigned int i; 1067 unsigned int i;
1068 lua_assert(!g->tobefnz || g->gcfinnum > 0); 1068 lua_assert(!g->tobefnz || g->gcfinnum > 0);
@@ -1075,19 +1075,26 @@ static int dosomefinalization (lua_State *L) {
1075 1075
1076 1076
1077/* 1077/*
1078** performs a basic GC step 1078** get GC debt and convert it from Kb to 'work units' (avoid zero debt
1079** and overflows)
1079*/ 1080*/
1080void luaC_forcestep (lua_State *L) { 1081static l_mem getdebt (global_State *g) {
1081 global_State *g = G(L);
1082 l_mem debt = g->GCdebt; 1082 l_mem debt = g->GCdebt;
1083 int stepmul = g->gcstepmul; 1083 int stepmul = g->gcstepmul;
1084 if (stepmul < 40) stepmul = 40; /* avoid ridiculous low values (and 0) */
1085 /* convert debt from Kb to 'work units' (avoid zero debt and overflows) */
1086 debt = (debt / STEPMULADJ) + 1; 1084 debt = (debt / STEPMULADJ) + 1;
1087 debt = (debt < MAX_LMEM / stepmul) ? debt * stepmul : MAX_LMEM; 1085 debt = (debt < MAX_LMEM / stepmul) ? debt * stepmul : MAX_LMEM;
1086 return debt;
1087}
1088
1089/*
1090** performs a basic GC step
1091*/
1092void luaC_forcestep (lua_State *L) {
1093 global_State *g = G(L);
1094 l_mem debt = getdebt(g);
1088 do { 1095 do {
1089 if (g->gcstate == GCScallfin && g->tobefnz) { 1096 if (g->gcstate == GCScallfin && g->tobefnz) {
1090 unsigned int n = dosomefinalization(L); 1097 unsigned int n = runafewfinalizers(L);
1091 debt -= (n * GCFINALIZECOST); 1098 debt -= (n * GCFINALIZECOST);
1092 } 1099 }
1093 else { /* perform one single step */ 1100 else { /* perform one single step */
@@ -1098,9 +1105,9 @@ void luaC_forcestep (lua_State *L) {
1098 if (g->gcstate == GCSpause) 1105 if (g->gcstate == GCSpause)
1099 setpause(g, g->GCestimate); /* pause until next cycle */ 1106 setpause(g, g->GCestimate); /* pause until next cycle */
1100 else { 1107 else {
1101 debt = (debt / stepmul) * STEPMULADJ; /* convert 'work units' to Kb */ 1108 debt = (debt / g->gcstepmul) * STEPMULADJ; /* convert 'work units' to Kb */
1102 luaE_setdebt(g, debt); 1109 luaE_setdebt(g, debt);
1103 dosomefinalization(L); 1110 runafewfinalizers(L);
1104 } 1111 }
1105} 1112}
1106 1113