aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2012-05-22 14:50:39 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2012-05-22 14:50:39 -0300
commit086da10dacc9e2b8f7731609f0deec731c854627 (patch)
treed658d3bec0712aee85bb4de1f3324f76595cd3b9
parentb36b4b521f53e5ff2e18fff3c194d28f9a840868 (diff)
downloadlua-086da10dacc9e2b8f7731609f0deec731c854627.tar.gz
lua-086da10dacc9e2b8f7731609f0deec731c854627.tar.bz2
lua-086da10dacc9e2b8f7731609f0deec731c854627.zip
merge of fields 'lastmajormem' (used in gen. mode) and 'estimate'
(used in inc. mode)
-rw-r--r--lapi.c4
-rw-r--r--lgc.c17
-rw-r--r--lstate.c4
-rw-r--r--lstate.h5
4 files changed, 15 insertions, 15 deletions
diff --git a/lapi.c b/lapi.c
index be4449f8..547eeefd 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.160 2012/05/11 19:22:33 roberto Exp roberto $ 2** $Id: lapi.c,v 2.161 2012/05/21 13:18:10 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*/
@@ -1045,7 +1045,7 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
1045 } 1045 }
1046 case LUA_GCSTEP: { 1046 case LUA_GCSTEP: {
1047 if (g->gckind == KGC_GEN) { /* generational mode? */ 1047 if (g->gckind == KGC_GEN) { /* generational mode? */
1048 res = (g->lastmajormem == 0); /* 1 if will do major collection */ 1048 res = (g->GCestimate == 0); /* true if it will do major collection */
1049 luaC_forcestep(L); /* do a single step */ 1049 luaC_forcestep(L); /* do a single step */
1050 } 1050 }
1051 else { 1051 else {
diff --git a/lgc.c b/lgc.c
index 9831dce9..8883bb2a 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 2.124 2012/05/21 13:18:10 roberto Exp roberto $ 2** $Id: lgc.c,v 2.125 2012/05/22 17:32:25 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*/
@@ -917,7 +917,7 @@ void luaC_changemode (lua_State *L, int mode) {
917 if (mode == KGC_GEN) { /* change to generational mode */ 917 if (mode == KGC_GEN) { /* change to generational mode */
918 /* make sure gray lists are consistent */ 918 /* make sure gray lists are consistent */
919 luaC_runtilstate(L, bitmask(GCSpropagate)); 919 luaC_runtilstate(L, bitmask(GCSpropagate));
920 g->lastmajormem = gettotalbytes(g); 920 g->GCestimate = gettotalbytes(g);
921 g->gckind = KGC_GEN; 921 g->gckind = KGC_GEN;
922 } 922 }
923 else { /* change to incremental mode */ 923 else { /* change to incremental mode */
@@ -1014,7 +1014,7 @@ static lu_mem singlestep (lua_State *L) {
1014 } 1014 }
1015 else { /* no more `gray' objects */ 1015 else { /* no more `gray' objects */
1016 g->gcstate = GCSatomic; /* finish mark phase */ 1016 g->gcstate = GCSatomic; /* finish mark phase */
1017 g->estimate = g->GCmemtrav; /* save what was counted */ 1017 g->GCestimate = g->GCmemtrav; /* save what was counted */
1018 atomic(L); 1018 atomic(L);
1019 return GCATOMICCOST; 1019 return GCATOMICCOST;
1020 } 1020 }
@@ -1070,15 +1070,16 @@ void luaC_runtilstate (lua_State *L, int statesmask) {
1070 1070
1071static void generationalcollection (lua_State *L) { 1071static void generationalcollection (lua_State *L) {
1072 global_State *g = G(L); 1072 global_State *g = G(L);
1073 if (g->lastmajormem == 0) { /* signal for another major collection? */ 1073 if (g->GCestimate == 0) { /* signal for another major collection? */
1074 luaC_fullgc(L, 0); /* perform a full regular collection */ 1074 luaC_fullgc(L, 0); /* perform a full regular collection */
1075 g->lastmajormem = gettotalbytes(g); /* update control */ 1075 g->GCestimate = gettotalbytes(g); /* update control */
1076 } 1076 }
1077 else { 1077 else {
1078 lu_mem estimate = g->GCestimate;
1078 luaC_runtilstate(L, ~bitmask(GCSpause)); /* run complete cycle */ 1079 luaC_runtilstate(L, ~bitmask(GCSpause)); /* run complete cycle */
1079 luaC_runtilstate(L, bitmask(GCSpause)); 1080 luaC_runtilstate(L, bitmask(GCSpause));
1080 if (gettotalbytes(g) > g->lastmajormem/100 * g->gcmajorinc) 1081 if (gettotalbytes(g) > (estimate / 100) * g->gcmajorinc)
1081 g->lastmajormem = 0; /* signal for a major collection */ 1082 g->GCestimate = 0; /* signal for a major collection */
1082 } 1083 }
1083 luaE_setdebt(g, stddebt(g)); 1084 luaE_setdebt(g, stddebt(g));
1084} 1085}
@@ -1095,7 +1096,7 @@ static void step (lua_State *L) {
1095 debt -= work; 1096 debt -= work;
1096 } while (debt > -GCSTEPSIZE && g->gcstate != GCSpause); 1097 } while (debt > -GCSTEPSIZE && g->gcstate != GCSpause);
1097 if (g->gcstate == GCSpause) 1098 if (g->gcstate == GCSpause)
1098 debt = stddebtest(g, g->estimate); /* pause until next cycle */ 1099 debt = stddebtest(g, g->GCestimate); /* pause until next cycle */
1099 luaE_setdebt(g, debt); 1100 luaE_setdebt(g, debt);
1100} 1101}
1101 1102
diff --git a/lstate.c b/lstate.c
index fecd0fba..cb80de7d 100644
--- a/lstate.c
+++ b/lstate.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.c,v 2.94 2012/05/11 14:06:07 roberto Exp roberto $ 2** $Id: lstate.c,v 2.95 2012/05/22 17:32:25 roberto Exp roberto $
3** Global State 3** Global State
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -280,7 +280,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
280 g->uvhead.u.l.prev = &g->uvhead; 280 g->uvhead.u.l.prev = &g->uvhead;
281 g->uvhead.u.l.next = &g->uvhead; 281 g->uvhead.u.l.next = &g->uvhead;
282 g->gcrunning = 0; /* no GC while building state */ 282 g->gcrunning = 0; /* no GC while building state */
283 g->lastmajormem = 0; 283 g->GCestimate = 0;
284 g->strt.size = 0; 284 g->strt.size = 0;
285 g->strt.nuse = 0; 285 g->strt.nuse = 0;
286 g->strt.hash = NULL; 286 g->strt.hash = NULL;
diff --git a/lstate.h b/lstate.h
index 302834ab..665cf160 100644
--- a/lstate.h
+++ b/lstate.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.h,v 2.78 2012/05/20 20:36:44 roberto Exp roberto $ 2** $Id: lstate.h,v 2.79 2012/05/22 17:32:25 roberto Exp roberto $
3** Global State 3** Global State
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -114,8 +114,7 @@ typedef struct global_State {
114 lu_mem totalbytes; /* number of bytes currently allocated - GCdebt */ 114 lu_mem totalbytes; /* number of bytes currently allocated - GCdebt */
115 l_mem GCdebt; /* bytes allocated not yet compensated by the collector */ 115 l_mem GCdebt; /* bytes allocated not yet compensated by the collector */
116 lu_mem GCmemtrav; /* memory traversed by the GC */ 116 lu_mem GCmemtrav; /* memory traversed by the GC */
117 lu_mem lastmajormem; /* memory in use after last major collection */ 117 lu_mem GCestimate; /* an estimate of the non-garbage memory in use */
118 lu_mem estimate;
119 stringtable strt; /* hash table for strings */ 118 stringtable strt; /* hash table for strings */
120 TValue l_registry; 119 TValue l_registry;
121 unsigned int seed; /* randomized seed for hashes */ 120 unsigned int seed; /* randomized seed for hashes */