mirror of https://github.com/rusefi/lua.git
more options for 'kinds' of Garbage Collection + more agressive
shrinking of stacks and string hash
This commit is contained in:
parent
a73930228a
commit
5f0a2f6248
55
lgc.c
55
lgc.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lgc.c,v 2.41 2007/10/29 16:51:20 roberto Exp roberto $
|
** $Id: lgc.c,v 2.42 2007/10/31 15:41:19 roberto Exp roberto $
|
||||||
** Garbage Collector
|
** Garbage Collector
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -308,17 +308,18 @@ static void traverseclosure (global_State *g, Closure *cl) {
|
||||||
|
|
||||||
|
|
||||||
static void checkstacksizes (lua_State *L, StkId max) {
|
static void checkstacksizes (lua_State *L, StkId max) {
|
||||||
int ci_used = cast_int(L->ci - L->base_ci); /* number of `ci' in use */
|
/* should not change the stack when handling overflow or
|
||||||
int s_used = cast_int(max - L->stack); /* part of stack in use */
|
during an emergency gc cycle */
|
||||||
if (L->size_ci > LUAI_MAXCALLS) /* handling overflow? */
|
if (L->size_ci > LUAI_MAXCALLS || G(L)->gckind == KGC_EMERGENCY)
|
||||||
return; /* do not touch the stacks */
|
return; /* do not touch the stacks */
|
||||||
if (4*ci_used < L->size_ci && 2*BASIC_CI_SIZE < L->size_ci)
|
else {
|
||||||
luaD_reallocCI(L, L->size_ci/2); /* still big enough... */
|
int ci_used = cast_int(L->ci - L->base_ci) + 1; /* number of `ci' in use */
|
||||||
condhardstacktests(luaD_reallocCI(L, ci_used + 1));
|
int s_used = cast_int(max - L->stack) + 1; /* part of stack in use */
|
||||||
if (4*s_used < L->stacksize &&
|
if (2*ci_used < L->size_ci)
|
||||||
2*(BASIC_STACK_SIZE+EXTRA_STACK) < L->stacksize)
|
luaD_reallocCI(L, 2*ci_used);
|
||||||
luaD_reallocstack(L, L->stacksize/2); /* still big enough... */
|
if (2*s_used < (L->stacksize - EXTRA_STACK))
|
||||||
condhardstacktests(luaD_reallocstack(L, s_used));
|
luaD_reallocstack(L, 2*s_used);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -337,8 +338,7 @@ static void traversestack (global_State *g, lua_State *l) {
|
||||||
markvalue(g, o);
|
markvalue(g, o);
|
||||||
for (; o <= lim; o++)
|
for (; o <= lim; o++)
|
||||||
setnilvalue(o);
|
setnilvalue(o);
|
||||||
if (!g->emergencygc) /* cannot change stack in emergency... */
|
checkstacksizes(l, lim);
|
||||||
checkstacksizes(l, lim); /* ...(mutator does not expect that change) */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -498,15 +498,9 @@ static GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count) {
|
||||||
|
|
||||||
static void checkSizes (lua_State *L) {
|
static void checkSizes (lua_State *L) {
|
||||||
global_State *g = G(L);
|
global_State *g = G(L);
|
||||||
/* check size of string hash */
|
if (g->strt.nuse < cast(lu_int32, g->strt.size))
|
||||||
if (g->strt.nuse < cast(lu_int32, g->strt.size/4) &&
|
luaS_resize(L, 1 << luaO_ceillog2(g->strt.nuse));
|
||||||
g->strt.size > MINSTRTABSIZE*2)
|
luaZ_freebuffer(L, &g->buff);
|
||||||
luaS_resize(L, g->strt.size/2); /* table is too big */
|
|
||||||
/* check size of buffer */
|
|
||||||
if (luaZ_sizebuffer(&g->buff) > LUA_MINBUFFER*2) { /* buffer too big? */
|
|
||||||
size_t newsize = luaZ_sizebuffer(&g->buff) / 2;
|
|
||||||
luaZ_resizebuffer(L, &g->buff, newsize);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -698,7 +692,7 @@ static l_mem singlestep (lua_State *L) {
|
||||||
void luaC_step (lua_State *L) {
|
void luaC_step (lua_State *L) {
|
||||||
global_State *g = G(L);
|
global_State *g = G(L);
|
||||||
l_mem lim = (GCSTEPSIZE/100) * g->gcstepmul;
|
l_mem lim = (GCSTEPSIZE/100) * g->gcstepmul;
|
||||||
lua_assert(!g->emergencygc);
|
lua_assert(g->gckind == KGC_NORMAL);
|
||||||
if (lim == 0)
|
if (lim == 0)
|
||||||
lim = (MAX_LUMEM-1)/2; /* no limit */
|
lim = (MAX_LUMEM-1)/2; /* no limit */
|
||||||
g->gcdept += g->totalbytes - g->GCthreshold;
|
g->gcdept += g->totalbytes - g->GCthreshold;
|
||||||
|
@ -723,9 +717,9 @@ void luaC_step (lua_State *L) {
|
||||||
|
|
||||||
|
|
||||||
void luaC_fullgc (lua_State *L, int isemergency) {
|
void luaC_fullgc (lua_State *L, int isemergency) {
|
||||||
int stopstate;
|
|
||||||
global_State *g = G(L);
|
global_State *g = G(L);
|
||||||
g->emergencygc = isemergency;
|
lua_assert(g->gckind == KGC_NORMAL);
|
||||||
|
g->gckind = isemergency ? KGC_EMERGENCY : KGC_FORCED;
|
||||||
if (g->gcstate <= GCSpropagate) {
|
if (g->gcstate <= GCSpropagate) {
|
||||||
/* reset sweep marks to sweep all elements (returning them to white) */
|
/* reset sweep marks to sweep all elements (returning them to white) */
|
||||||
g->sweepstrgc = 0;
|
g->sweepstrgc = 0;
|
||||||
|
@ -743,12 +737,15 @@ void luaC_fullgc (lua_State *L, int isemergency) {
|
||||||
singlestep(L);
|
singlestep(L);
|
||||||
}
|
}
|
||||||
markroot(L);
|
markroot(L);
|
||||||
/* do not run finalizers during emergency GC */
|
/* run collector up to finalizers */
|
||||||
stopstate = isemergency ? GCSfinalize : GCSpause;
|
while (g->gcstate != GCSfinalize)
|
||||||
while (g->gcstate != stopstate)
|
|
||||||
singlestep(L);
|
singlestep(L);
|
||||||
|
g->gckind = KGC_NORMAL;
|
||||||
|
if (!isemergency) { /* do not run finalizers during emergency GC */
|
||||||
|
while (g->gcstate != GCSpause)
|
||||||
|
singlestep(L);
|
||||||
|
}
|
||||||
setthreshold(g);
|
setthreshold(g);
|
||||||
g->emergencygc = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue