better (and correct!) control of 'maybedead'

This commit is contained in:
Roberto Ierusalimschy 2013-09-04 12:34:24 -03:00
parent aeff4f79fa
commit 0ad15fc100
1 changed files with 20 additions and 21 deletions

View File

@ -1,5 +1,5 @@
/* /*
** $Id: ltests.c,v 2.152 2013/08/30 19:14:26 roberto Exp roberto $ ** $Id: ltests.c,v 2.153 2013/09/03 15:37:10 roberto Exp roberto $
** Internal Module for Debugging of the Lua Implementation ** Internal Module for Debugging of the Lua Implementation
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -335,7 +335,7 @@ static void checkstack (global_State *g, lua_State *L1) {
static void checkobject (global_State *g, GCObject *o, int maybedead) { static void checkobject (global_State *g, GCObject *o, int maybedead) {
if (isdead(g, o)) if (isdead(g, o))
lua_assert(maybedead && issweepphase(g)); lua_assert(maybedead);
else { else {
lua_assert(g->gcstate != GCSpause || iswhite(o)); lua_assert(g->gcstate != GCSpause || iswhite(o));
lua_assert(!islocal(o) || !testbit(gch(o)->marked, LOCALMARK)); lua_assert(!islocal(o) || !testbit(gch(o)->marked, LOCALMARK));
@ -431,20 +431,32 @@ int lua_checkmemory (lua_State *L) {
lua_assert(!isdead(g, gcvalue(&g->l_registry))); lua_assert(!isdead(g, gcvalue(&g->l_registry)));
checkstack(g, g->mainthread); checkstack(g, g->mainthread);
resetbit(g->mainthread->marked, TESTGRAYBIT); resetbit(g->mainthread->marked, TESTGRAYBIT);
/* check 'allgc' list */
markgrays(g);
checkgray(g, g->allgc);
lua_assert(g->sweepgc == NULL || issweepphase(g)); lua_assert(g->sweepgc == NULL || issweepphase(g));
maybedead = 0; markgrays(g);
/* check 'localgc' list */
checkgray(g, g->localgc);
maybedead = (GCSatomic < g->gcstate && g->gcstate <= GCSsweeplocal);
for (o = g->localgc; o != NULL; o = gch(o)->next) {
checkobject(g, o, maybedead);
lua_assert(!tofinalize(o) && !testbit(o->gch.marked, LOCALMARK));
}
/* check 'allgc' list */
checkgray(g, g->allgc);
maybedead = (GCSatomic < g->gcstate && g->gcstate <= GCSsweepall);
isthread = 0; /* not traversing threads (yet) */ isthread = 0; /* not traversing threads (yet) */
for (o = g->allgc; o != NULL; o = gch(o)->next) { for (o = g->allgc; o != NULL; o = gch(o)->next) {
if (g->sweepgc && o == *g->sweepgc)
maybedead = 1; /* part of the list not yet swept */
if (gch(o)->tt == LUA_TTHREAD) isthread = 1; /* now travesing threads... */ if (gch(o)->tt == LUA_TTHREAD) isthread = 1; /* now travesing threads... */
else lua_assert(!isthread); /* ... and only threads */ else lua_assert(!isthread); /* ... and only threads */
checkobject(g, o, maybedead); checkobject(g, o, maybedead);
lua_assert(!tofinalize(o) && testbit(o->gch.marked, LOCALMARK)); lua_assert(!tofinalize(o) && testbit(o->gch.marked, LOCALMARK));
} }
/* check 'localfin' list */
checkgray(g, g->localfin);
for (o = g->localfin; o != NULL; o = gch(o)->next) {
checkobject(g, o, 0);
lua_assert(tofinalize(o) && !testbit(o->gch.marked, LOCALMARK));
lua_assert(gch(o)->tt == LUA_TUSERDATA || gch(o)->tt == LUA_TTABLE);
}
/* check 'finobj' list */ /* check 'finobj' list */
checkgray(g, g->finobj); checkgray(g, g->finobj);
for (o = g->finobj; o != NULL; o = gch(o)->next) { for (o = g->finobj; o != NULL; o = gch(o)->next) {
@ -460,19 +472,6 @@ int lua_checkmemory (lua_State *L) {
lua_assert(!isdead(g, o) && tofinalize(o)); lua_assert(!isdead(g, o) && tofinalize(o));
lua_assert(gch(o)->tt == LUA_TUSERDATA || gch(o)->tt == LUA_TTABLE); lua_assert(gch(o)->tt == LUA_TUSERDATA || gch(o)->tt == LUA_TTABLE);
} }
/* check 'localgc' list */
checkgray(g, g->localgc);
for (o = g->localgc; o != NULL; o = gch(o)->next) {
checkobject(g, o, 1);
lua_assert(!tofinalize(o) && !testbit(o->gch.marked, LOCALMARK));
}
/* check 'localfin' list */
checkgray(g, g->localfin);
for (o = g->localfin; o != NULL; o = gch(o)->next) {
checkobject(g, o, 0);
lua_assert(tofinalize(o) && !testbit(o->gch.marked, LOCALMARK));
lua_assert(gch(o)->tt == LUA_TUSERDATA || gch(o)->tt == LUA_TTABLE);
}
return 0; return 0;
} }