full collection does not restart collector + avoid changing GC

state if an error happens in a step
This commit is contained in:
Roberto Ierusalimschy 2010-12-29 16:00:23 -02:00
parent aa6faa6331
commit 868ff40339
3 changed files with 25 additions and 20 deletions

10
lapi.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: lapi.c,v 2.142 2010/12/20 18:17:46 roberto Exp roberto $ ** $Id: lapi.c,v 2.143 2010/12/20 19:40:07 roberto Exp roberto $
** Lua API ** Lua API
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -969,7 +969,6 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
break; break;
} }
case LUA_GCCOLLECT: { case LUA_GCCOLLECT: {
g->gcrunning = 1; /* restart collector if stopped ?? */
luaC_fullgc(L, 0); luaC_fullgc(L, 0);
break; break;
} }
@ -983,22 +982,19 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
break; break;
} }
case LUA_GCSTEP: { case LUA_GCSTEP: {
int running = g->gcrunning;
g->gcrunning = 1; /* allow steps */
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->lastmajormem == 0); /* 1 if will do major collection */
luaC_step(L); /* do a single step */ luaC_forcestep(L); /* do a single step */
} }
else { else {
while (data-- >= 0) { while (data-- >= 0) {
luaC_step(L); luaC_forcestep(L);
if (g->gcstate == GCSpause) { /* end of cycle? */ if (g->gcstate == GCSpause) { /* end of cycle? */
res = 1; /* signal it */ res = 1; /* signal it */
break; break;
} }
} }
} }
g->gcrunning = running; /* restore previous state */
break; break;
} }
case LUA_GCSETPAUSE: { case LUA_GCSETPAUSE: {

32
lgc.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: lgc.c,v 2.106 2010/12/20 18:17:46 roberto Exp roberto $ ** $Id: lgc.c,v 2.107 2010/12/20 19:40:07 roberto Exp roberto $
** Garbage Collector ** Garbage Collector
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -318,8 +318,7 @@ static void remarkupvals (global_State *g) {
** mark root set and reset all gray lists, to start a new ** mark root set and reset all gray lists, to start a new
** incremental (or full) collection ** incremental (or full) collection
*/ */
static void markroot (lua_State *L) { static void markroot (global_State *g) {
global_State *g = G(L);
g->gray = g->grayagain = NULL; g->gray = g->grayagain = NULL;
g->weak = g->allweak = g->ephemeron = NULL; g->weak = g->allweak = g->ephemeron = NULL;
markobject(g, g->mainthread); markobject(g, g->mainthread);
@ -889,7 +888,7 @@ static l_mem singlestep (lua_State *L) {
switch (g->gcstate) { switch (g->gcstate) {
case GCSpause: { case GCSpause: {
if (!isgenerational(g)) if (!isgenerational(g))
markroot(L); /* start a new collection */ markroot(g); /* start a new collection */
/* in any case, root must be marked */ /* in any case, root must be marked */
lua_assert(!iswhite(obj2gco(g->mainthread)) lua_assert(!iswhite(obj2gco(g->mainthread))
&& !iswhite(gcvalue(&g->l_registry))); && !iswhite(gcvalue(&g->l_registry)));
@ -986,15 +985,24 @@ static void step (lua_State *L) {
} }
void luaC_step (lua_State *L) { /*
** performs a basic GC step even if the collector is stopped
*/
void luaC_forcestep (lua_State *L) {
global_State *g = G(L); global_State *g = G(L);
if (g->gcrunning) { int i;
int i; if (isgenerational(g)) generationalcollection(L);
if (isgenerational(g)) generationalcollection(L); else step(L);
else step(L); for (i = 0; i < GCFINALIZENUM && g->tobefnz; i++)
for (i = 0; i < GCFINALIZENUM && g->tobefnz; i++) GCTM(L, 1); /* Call a few pending finalizers */
GCTM(L, 1); /* Call a few pending finalizers */ }
}
/*
** performs a basic GC step only if collector is running
*/
void luaC_step (lua_State *L) {
if (G(L)->gcrunning) luaC_forcestep(L);
} }

3
lgc.h
View File

@ -1,5 +1,5 @@
/* /*
** $Id: lgc.h,v 2.47 2010/12/17 12:02:29 roberto Exp roberto $ ** $Id: lgc.h,v 2.48 2010/12/20 18:17:46 roberto Exp roberto $
** Garbage Collector ** Garbage Collector
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -128,6 +128,7 @@
LUAI_FUNC void luaC_separateudata (lua_State *L, int all); LUAI_FUNC void luaC_separateudata (lua_State *L, int all);
LUAI_FUNC void luaC_freeallobjects (lua_State *L); LUAI_FUNC void luaC_freeallobjects (lua_State *L);
LUAI_FUNC void luaC_step (lua_State *L); LUAI_FUNC void luaC_step (lua_State *L);
LUAI_FUNC void luaC_forcestep (lua_State *L);
LUAI_FUNC void luaC_runtilstate (lua_State *L, int statesmask); LUAI_FUNC void luaC_runtilstate (lua_State *L, int statesmask);
LUAI_FUNC void luaC_fullgc (lua_State *L, int isemergency); LUAI_FUNC void luaC_fullgc (lua_State *L, int isemergency);
LUAI_FUNC GCObject *luaC_newobj (lua_State *L, int tt, size_t sz, LUAI_FUNC GCObject *luaC_newobj (lua_State *L, int tt, size_t sz,