mirror of
https://github.com/lua/lua.git
synced 2025-02-04 06:13:04 +08:00
merge of fields 'lastmajormem' (used in gen. mode) and 'estimate'
(used in inc. mode)
This commit is contained in:
parent
b36b4b521f
commit
086da10dac
4
lapi.c
4
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
|
** Lua API
|
||||||
** See Copyright Notice in lua.h
|
** 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: {
|
case LUA_GCSTEP: {
|
||||||
if (g->gckind == KGC_GEN) { /* generational mode? */
|
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 */
|
luaC_forcestep(L); /* do a single step */
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
17
lgc.c
17
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
|
** Garbage Collector
|
||||||
** See Copyright Notice in lua.h
|
** 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 */
|
if (mode == KGC_GEN) { /* change to generational mode */
|
||||||
/* make sure gray lists are consistent */
|
/* make sure gray lists are consistent */
|
||||||
luaC_runtilstate(L, bitmask(GCSpropagate));
|
luaC_runtilstate(L, bitmask(GCSpropagate));
|
||||||
g->lastmajormem = gettotalbytes(g);
|
g->GCestimate = gettotalbytes(g);
|
||||||
g->gckind = KGC_GEN;
|
g->gckind = KGC_GEN;
|
||||||
}
|
}
|
||||||
else { /* change to incremental mode */
|
else { /* change to incremental mode */
|
||||||
@ -1014,7 +1014,7 @@ static lu_mem singlestep (lua_State *L) {
|
|||||||
}
|
}
|
||||||
else { /* no more `gray' objects */
|
else { /* no more `gray' objects */
|
||||||
g->gcstate = GCSatomic; /* finish mark phase */
|
g->gcstate = GCSatomic; /* finish mark phase */
|
||||||
g->estimate = g->GCmemtrav; /* save what was counted */
|
g->GCestimate = g->GCmemtrav; /* save what was counted */
|
||||||
atomic(L);
|
atomic(L);
|
||||||
return GCATOMICCOST;
|
return GCATOMICCOST;
|
||||||
}
|
}
|
||||||
@ -1070,15 +1070,16 @@ void luaC_runtilstate (lua_State *L, int statesmask) {
|
|||||||
|
|
||||||
static void generationalcollection (lua_State *L) {
|
static void generationalcollection (lua_State *L) {
|
||||||
global_State *g = G(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 */
|
luaC_fullgc(L, 0); /* perform a full regular collection */
|
||||||
g->lastmajormem = gettotalbytes(g); /* update control */
|
g->GCestimate = gettotalbytes(g); /* update control */
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
lu_mem estimate = g->GCestimate;
|
||||||
luaC_runtilstate(L, ~bitmask(GCSpause)); /* run complete cycle */
|
luaC_runtilstate(L, ~bitmask(GCSpause)); /* run complete cycle */
|
||||||
luaC_runtilstate(L, bitmask(GCSpause));
|
luaC_runtilstate(L, bitmask(GCSpause));
|
||||||
if (gettotalbytes(g) > g->lastmajormem/100 * g->gcmajorinc)
|
if (gettotalbytes(g) > (estimate / 100) * g->gcmajorinc)
|
||||||
g->lastmajormem = 0; /* signal for a major collection */
|
g->GCestimate = 0; /* signal for a major collection */
|
||||||
}
|
}
|
||||||
luaE_setdebt(g, stddebt(g));
|
luaE_setdebt(g, stddebt(g));
|
||||||
}
|
}
|
||||||
@ -1095,7 +1096,7 @@ static void step (lua_State *L) {
|
|||||||
debt -= work;
|
debt -= work;
|
||||||
} while (debt > -GCSTEPSIZE && g->gcstate != GCSpause);
|
} while (debt > -GCSTEPSIZE && g->gcstate != GCSpause);
|
||||||
if (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);
|
luaE_setdebt(g, debt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
lstate.c
4
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
|
** Global State
|
||||||
** See Copyright Notice in lua.h
|
** 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.prev = &g->uvhead;
|
||||||
g->uvhead.u.l.next = &g->uvhead;
|
g->uvhead.u.l.next = &g->uvhead;
|
||||||
g->gcrunning = 0; /* no GC while building state */
|
g->gcrunning = 0; /* no GC while building state */
|
||||||
g->lastmajormem = 0;
|
g->GCestimate = 0;
|
||||||
g->strt.size = 0;
|
g->strt.size = 0;
|
||||||
g->strt.nuse = 0;
|
g->strt.nuse = 0;
|
||||||
g->strt.hash = NULL;
|
g->strt.hash = NULL;
|
||||||
|
5
lstate.h
5
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
|
** Global State
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -114,8 +114,7 @@ typedef struct global_State {
|
|||||||
lu_mem totalbytes; /* number of bytes currently allocated - GCdebt */
|
lu_mem totalbytes; /* number of bytes currently allocated - GCdebt */
|
||||||
l_mem GCdebt; /* bytes allocated not yet compensated by the collector */
|
l_mem GCdebt; /* bytes allocated not yet compensated by the collector */
|
||||||
lu_mem GCmemtrav; /* memory traversed by the GC */
|
lu_mem GCmemtrav; /* memory traversed by the GC */
|
||||||
lu_mem lastmajormem; /* memory in use after last major collection */
|
lu_mem GCestimate; /* an estimate of the non-garbage memory in use */
|
||||||
lu_mem estimate;
|
|
||||||
stringtable strt; /* hash table for strings */
|
stringtable strt; /* hash table for strings */
|
||||||
TValue l_registry;
|
TValue l_registry;
|
||||||
unsigned int seed; /* randomized seed for hashes */
|
unsigned int seed; /* randomized seed for hashes */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user