From 086da10dacc9e2b8f7731609f0deec731c854627 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 22 May 2012 14:50:39 -0300 Subject: [PATCH] merge of fields 'lastmajormem' (used in gen. mode) and 'estimate' (used in inc. mode) --- lapi.c | 4 ++-- lgc.c | 17 +++++++++-------- lstate.c | 4 ++-- lstate.h | 5 ++--- 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 @@ /* -** $Id: lapi.c,v 2.160 2012/05/11 19:22:33 roberto Exp roberto $ +** $Id: lapi.c,v 2.161 2012/05/21 13:18:10 roberto Exp roberto $ ** Lua API ** See Copyright Notice in lua.h */ @@ -1045,7 +1045,7 @@ LUA_API int lua_gc (lua_State *L, int what, int data) { } case LUA_GCSTEP: { if (g->gckind == KGC_GEN) { /* generational mode? */ - res = (g->lastmajormem == 0); /* 1 if will do major collection */ + res = (g->GCestimate == 0); /* true if it will do major collection */ luaC_forcestep(L); /* do a single step */ } else { diff --git a/lgc.c b/lgc.c index 9831dce9..8883bb2a 100644 --- a/lgc.c +++ b/lgc.c @@ -1,5 +1,5 @@ /* -** $Id: lgc.c,v 2.124 2012/05/21 13:18:10 roberto Exp roberto $ +** $Id: lgc.c,v 2.125 2012/05/22 17:32:25 roberto Exp roberto $ ** Garbage Collector ** See Copyright Notice in lua.h */ @@ -917,7 +917,7 @@ void luaC_changemode (lua_State *L, int mode) { if (mode == KGC_GEN) { /* change to generational mode */ /* make sure gray lists are consistent */ luaC_runtilstate(L, bitmask(GCSpropagate)); - g->lastmajormem = gettotalbytes(g); + g->GCestimate = gettotalbytes(g); g->gckind = KGC_GEN; } else { /* change to incremental mode */ @@ -1014,7 +1014,7 @@ static lu_mem singlestep (lua_State *L) { } else { /* no more `gray' objects */ g->gcstate = GCSatomic; /* finish mark phase */ - g->estimate = g->GCmemtrav; /* save what was counted */ + g->GCestimate = g->GCmemtrav; /* save what was counted */ atomic(L); return GCATOMICCOST; } @@ -1070,15 +1070,16 @@ void luaC_runtilstate (lua_State *L, int statesmask) { static void generationalcollection (lua_State *L) { global_State *g = G(L); - if (g->lastmajormem == 0) { /* signal for another major collection? */ + if (g->GCestimate == 0) { /* signal for another major collection? */ luaC_fullgc(L, 0); /* perform a full regular collection */ - g->lastmajormem = gettotalbytes(g); /* update control */ + g->GCestimate = gettotalbytes(g); /* update control */ } else { + lu_mem estimate = g->GCestimate; luaC_runtilstate(L, ~bitmask(GCSpause)); /* run complete cycle */ luaC_runtilstate(L, bitmask(GCSpause)); - if (gettotalbytes(g) > g->lastmajormem/100 * g->gcmajorinc) - g->lastmajormem = 0; /* signal for a major collection */ + if (gettotalbytes(g) > (estimate / 100) * g->gcmajorinc) + g->GCestimate = 0; /* signal for a major collection */ } luaE_setdebt(g, stddebt(g)); } @@ -1095,7 +1096,7 @@ static void step (lua_State *L) { debt -= work; } while (debt > -GCSTEPSIZE && g->gcstate != GCSpause); if (g->gcstate == GCSpause) - debt = stddebtest(g, g->estimate); /* pause until next cycle */ + debt = stddebtest(g, g->GCestimate); /* pause until next cycle */ luaE_setdebt(g, debt); } diff --git a/lstate.c b/lstate.c index fecd0fba..cb80de7d 100644 --- a/lstate.c +++ b/lstate.c @@ -1,5 +1,5 @@ /* -** $Id: lstate.c,v 2.94 2012/05/11 14:06:07 roberto Exp roberto $ +** $Id: lstate.c,v 2.95 2012/05/22 17:32:25 roberto Exp roberto $ ** Global State ** See Copyright Notice in lua.h */ @@ -280,7 +280,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { g->uvhead.u.l.prev = &g->uvhead; g->uvhead.u.l.next = &g->uvhead; g->gcrunning = 0; /* no GC while building state */ - g->lastmajormem = 0; + g->GCestimate = 0; g->strt.size = 0; g->strt.nuse = 0; 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 @@ /* -** $Id: lstate.h,v 2.78 2012/05/20 20:36:44 roberto Exp roberto $ +** $Id: lstate.h,v 2.79 2012/05/22 17:32:25 roberto Exp roberto $ ** Global State ** See Copyright Notice in lua.h */ @@ -114,8 +114,7 @@ typedef struct global_State { lu_mem totalbytes; /* number of bytes currently allocated - GCdebt */ l_mem GCdebt; /* bytes allocated not yet compensated by the collector */ lu_mem GCmemtrav; /* memory traversed by the GC */ - lu_mem lastmajormem; /* memory in use after last major collection */ - lu_mem estimate; + lu_mem GCestimate; /* an estimate of the non-garbage memory in use */ stringtable strt; /* hash table for strings */ TValue l_registry; unsigned int seed; /* randomized seed for hashes */