diff --git a/lgc.c b/lgc.c index 6eac4f43..43927a93 100644 --- a/lgc.c +++ b/lgc.c @@ -1,5 +1,5 @@ /* -** $Id: lgc.c,v 2.81 2010/04/29 17:32:40 roberto Exp roberto $ +** $Id: lgc.c,v 2.82 2010/04/29 21:43:36 roberto Exp roberto $ ** Garbage Collector ** See Copyright Notice in lua.h */ @@ -23,6 +23,7 @@ #include "ltm.h" + #define GCSTEPSIZE 1024 #define GCSWEEPMAX 40 #define GCSWEEPCOST 1 @@ -288,9 +289,8 @@ static void remarkupvals (global_State *g) { */ static void markroot (lua_State *L) { global_State *g = G(L); - lua_assert(g->gckind == KGC_GEN || - (g->gray == NULL && g->grayagain == NULL && g->weak == NULL && - g->allweak == NULL && g->ephemeron == NULL)); + g->gray = g->grayagain = NULL; + g->weak = g->allweak = g->ephemeron = NULL; markobject(g, g->mainthread); markvalue(g, &g->l_registry); markmt(g); @@ -793,11 +793,6 @@ static void atomic (lua_State *L) { cleartable(g->allweak); lua_checkmemory(L); g->currentwhite = cast_byte(otherwhite(g)); /* flip current white */ - if (g->gckind != KGC_GEN) { - g->gray = NULL; /* all gray objects will become white */ - g->grayagain = NULL; - g->weak = g->ephemeron = g->allweak = NULL; - } } @@ -907,7 +902,10 @@ static void step (lua_State *L) { do { /* always perform at least one single step */ lim -= singlestep(L); } while (lim > 0 && g->gcstate != GCSpause); - g->GCdebt += (g->gcstate != GCSpause) ? -GCSTEPSIZE : stddebt(g); + if (g->gcstate != GCSpause) + g->GCdebt -= GCSTEPSIZE; + else + g->GCdebt = stddebt(g); } @@ -931,9 +929,6 @@ void luaC_fullgc (lua_State *L, int isemergency) { (as white has not changed, nothing will be collected) */ g->sweepstrgc = 0; g->gcstate = GCSsweepstring; - g->gray = NULL; - g->grayagain = NULL; - g->weak = g->ephemeron = g->allweak = NULL; } /* finish any pending sweep phase */ luaC_runtilstate(L, bit2mask(GCSpause, GCSfinalize)); diff --git a/ltests.c b/ltests.c index d302b97b..5764a7fa 100644 --- a/ltests.c +++ b/ltests.c @@ -1,5 +1,5 @@ /* -** $Id: ltests.c,v 2.97 2010/04/29 17:33:51 roberto Exp roberto $ +** $Id: ltests.c,v 2.98 2010/04/29 21:42:33 roberto Exp roberto $ ** Internal Module for Debugging of the Lua Implementation ** See Copyright Notice in lua.h */ @@ -380,6 +380,7 @@ static void checkgraylist (GCObject *l) { static void markgrays (global_State *g) { + if (!keepinvariant(g)) return; checkgraylist(g->gray); checkgraylist(g->grayagain); checkgraylist(g->weak); @@ -399,7 +400,7 @@ int lua_checkmemory (lua_State *L) { for (o = g->allgc; o != NULL; o = gch(o)->next) { checkobject(g, o); if (isgray(o)) { - lua_assert(issweepphase(g) || testbit(o->gch.marked, GRAYBIT)); + lua_assert(!keepinvariant(g) || testbit(o->gch.marked, GRAYBIT)); o->gch.marked = resetbit(o->gch.marked, GRAYBIT); } lua_assert(!testbit(o->gch.marked, SEPARATED));