'mainthread' is not inserted in the 'allgc' list anymore, but swept

separately.
This commit is contained in:
Roberto Ierusalimschy
2010-03-25 10:06:36 -03:00
parent 64d39ed1b6
commit 3aa9598177
4 changed files with 18 additions and 21 deletions

19
lgc.c
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lgc.c,v 2.70 2010/03/24 13:07:01 roberto Exp roberto $ ** $Id: lgc.c,v 2.71 2010/03/24 15:51:10 roberto Exp roberto $
** Garbage Collector ** Garbage Collector
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -572,7 +572,7 @@ static GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count) {
if (gch(curr)->tt == LUA_TTHREAD) if (gch(curr)->tt == LUA_TTHREAD)
sweepthread(L, gco2th(curr), alive); sweepthread(L, gco2th(curr), alive);
if (!alive) { if (!alive) {
lua_assert(isdead(g, curr) || deadmask == bitmask(SFIXEDBIT)); lua_assert(isdead(g, curr) || deadmask == 0);
*p = gch(curr)->next; /* remove 'curr' from list */ *p = gch(curr)->next; /* remove 'curr' from list */
freeobj(L, curr); /* erase 'curr' */ freeobj(L, curr); /* erase 'curr' */
} }
@@ -718,11 +718,11 @@ void luaC_freeallobjects (lua_State *L) {
int i; int i;
while (g->tobefnz) GCTM(L, 0); /* Call all pending finalizers */ while (g->tobefnz) GCTM(L, 0); /* Call all pending finalizers */
/* following "white" makes all objects look dead */ /* following "white" makes all objects look dead */
g->currentwhite = WHITEBITS | bitmask(SFIXEDBIT); g->currentwhite = WHITEBITS;
sweepwholelist(L, &g->udgc); sweepwholelist(L, &g->udgc);
lua_assert(g->udgc == NULL);
sweepwholelist(L, &g->allgc); sweepwholelist(L, &g->allgc);
lua_assert(g->allgc == obj2gco(g->mainthread) && lua_assert(g->allgc == NULL);
g->mainthread->next == NULL);
for (i = 0; i < g->strt.size; i++) /* free all string lists */ for (i = 0; i < g->strt.size; i++) /* free all string lists */
sweepwholelist(L, &g->strt.hash[i]); sweepwholelist(L, &g->strt.hash[i]);
lua_assert(g->strt.nuse == 0); lua_assert(g->strt.nuse == 0);
@@ -781,14 +781,15 @@ static l_mem singlestep (lua_State *L) {
case GCSsweepstring: { case GCSsweepstring: {
if (g->sweepstrgc < g->strt.size) { if (g->sweepstrgc < g->strt.size) {
sweepwholelist(L, &g->strt.hash[g->sweepstrgc++]); sweepwholelist(L, &g->strt.hash[g->sweepstrgc++]);
return GCSWEEPCOST;
} }
else { /* nothing more to sweep */ else { /* no more strings to sweep */
g->sweepgc = &g->udgc; /* sweep all userdata */ /* sweep main thread */
sweeplist(L, cast(GCObject **, &g->mainthread), 1);
g->sweepgc = &g->udgc; /* prepare to sweep userdata */
g->gcstate = GCSsweepudata; g->gcstate = GCSsweepudata;
checkSizes(L); checkSizes(L);
return 0;
} }
return GCSWEEPCOST;
} }
case GCSsweepudata: case GCSsweepudata:
case GCSsweep: { case GCSsweep: {

8
lgc.h
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lgc.h,v 2.28 2010/03/24 13:07:01 roberto Exp roberto $ ** $Id: lgc.h,v 2.29 2010/03/24 15:51:10 roberto Exp roberto $
** Garbage Collector ** Garbage Collector
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -48,8 +48,7 @@
** bit 3 - for userdata: has been finalized ** bit 3 - for userdata: has been finalized
** bit 4 - for userdata: it's in 'udgc' list or in 'tobefnz' ** bit 4 - for userdata: it's in 'udgc' list or in 'tobefnz'
** bit 5 - object is fixed (should not be collected) ** bit 5 - object is fixed (should not be collected)
** bit 6 - object is "super" fixed (only the main thread) ** bit 6 - object is old (only in generational mode)
** bit 7 - object is old (only in generational mode)
*/ */
#define WHITE0BIT 0 #define WHITE0BIT 0
#define WHITE1BIT 1 #define WHITE1BIT 1
@@ -57,8 +56,7 @@
#define FINALIZEDBIT 3 #define FINALIZEDBIT 3
#define SEPARATED 4 #define SEPARATED 4
#define FIXEDBIT 5 #define FIXEDBIT 5
#define SFIXEDBIT 6 #define OLDBIT 6
#define OLDBIT 7
#define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT) #define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT)

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lstate.c,v 2.71 2010/03/22 17:45:55 roberto Exp roberto $ ** $Id: lstate.c,v 2.72 2010/03/24 13:07:01 roberto Exp roberto $
** Global State ** Global State
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -247,7 +247,6 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
L->marked = luaC_white(g); L->marked = luaC_white(g);
g->gckind = KGC_NORMAL; g->gckind = KGC_NORMAL;
g->nCcalls = 0; g->nCcalls = 0;
set2bits(L->marked, FIXEDBIT, SFIXEDBIT);
preinit_state(L, g); preinit_state(L, g);
g->frealloc = f; g->frealloc = f;
g->ud = ud; g->ud = ud;
@@ -264,7 +263,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
g->panic = NULL; g->panic = NULL;
g->version = lua_version(NULL); g->version = lua_version(NULL);
g->gcstate = GCSpause; g->gcstate = GCSpause;
g->allgc = obj2gco(L); g->allgc = NULL;
g->udgc = NULL; g->udgc = NULL;
g->tobefnz = NULL; g->tobefnz = NULL;
g->totalbytes = sizeof(LG); g->totalbytes = sizeof(LG);

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: ltests.c,v 2.87 2010/01/13 16:18:25 roberto Exp roberto $ ** $Id: ltests.c,v 2.88 2010/03/24 13:07:01 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
*/ */
@@ -375,11 +375,10 @@ int lua_checkmemory (lua_State *L) {
checkliveness(g, &g->l_registry); checkliveness(g, &g->l_registry);
lua_assert(!isdead(g, obj2gco(g->l_gt))); lua_assert(!isdead(g, obj2gco(g->l_gt)));
checkstack(g, g->mainthread); checkstack(g, g->mainthread);
for (o = g->allgc; o != obj2gco(g->mainthread); o = gch(o)->next) { for (o = g->allgc; o != NULL; o = gch(o)->next) {
lua_assert(!testbits(o->gch.marked, bit2mask(SEPARATED, SFIXEDBIT))); lua_assert(!testbits(o->gch.marked, bitmask(SEPARATED)));
checkobject(g, o); checkobject(g, o);
} }
lua_assert(testbit(o->gch.marked, SFIXEDBIT));
for (o = g->udgc; o != NULL; o = gch(o)->next) { for (o = g->udgc; o != NULL; o = gch(o)->next) {
lua_assert(gch(o)->tt == LUA_TUSERDATA && lua_assert(gch(o)->tt == LUA_TUSERDATA &&
!isdead(g, o) && !isdead(g, o) &&