merge of fields 'lastmajormem' (used in gen. mode) and 'estimate'

(used in inc. mode)
This commit is contained in:
Roberto Ierusalimschy 2012-05-22 14:50:39 -03:00
parent b36b4b521f
commit 086da10dac
4 changed files with 15 additions and 15 deletions

4
lapi.c
View File

@ -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 {

17
lgc.c
View File

@ -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);
}

View File

@ -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;

View File

@ -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 */