diff --git a/lgc.c b/lgc.c index eec73871..347b6778 100644 --- a/lgc.c +++ b/lgc.c @@ -932,15 +932,15 @@ static GCObject **findlast (GCObject **p) { /* ** Move all unreachable objects (or 'all' objects) that need ** finalization from list 'finobj' to list 'tobefnz' (to be finalized). -** (Note that objects after 'finobjold' cannot be white, so they -** don't need to be traversed. In incremental mode, 'finobjold' is NULL, +** (Note that objects after 'finobjold1' cannot be white, so they +** don't need to be traversed. In incremental mode, 'finobjold1' is NULL, ** so the whole list is traversed.) */ static void separatetobefnz (global_State *g, int all) { GCObject *curr; GCObject **p = &g->finobj; GCObject **lastnext = findlast(&g->tobefnz); - while ((curr = *p) != g->finobjold) { /* traverse all finalizable objects */ + while ((curr = *p) != g->finobjold1) { /* traverse all finalizable objects */ lua_assert(tofinalize(curr)); if (!(iswhite(curr) || all)) /* not being collected? */ p = &curr->next; /* don't bother with it */ @@ -975,8 +975,8 @@ void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) { else { /* correct pointers into 'allgc' list, if needed */ if (o == g->survival) g->survival = o->next; - if (o == g->old) - g->old = o->next; + if (o == g->old1) + g->old1 = o->next; if (o == g->reallyold) g->reallyold = o->next; } @@ -1178,17 +1178,17 @@ static void youngcollection (lua_State *L, global_State *g) { g->gcstate = GCSswpallgc; psurvival = sweepgen(L, g, &g->allgc, g->survival); /* sweep 'survival' */ - sweepgen(L, g, psurvival, g->old); - g->reallyold = g->old; - g->old = *psurvival; /* 'survival' survivals are old now */ + sweepgen(L, g, psurvival, g->old1); + g->reallyold = g->old1; + g->old1 = *psurvival; /* 'survival' survivals are old now */ g->survival = g->allgc; /* all news are survivals */ /* repeat for 'finobj' lists */ psurvival = sweepgen(L, g, &g->finobj, g->finobjsur); /* sweep 'survival' */ - sweepgen(L, g, psurvival, g->finobjold); - g->finobjrold = g->finobjold; - g->finobjold = *psurvival; /* 'survival' survivals are old now */ + sweepgen(L, g, psurvival, g->finobjold1); + g->finobjrold = g->finobjold1; + g->finobjold1 = *psurvival; /* 'survival' survivals are old now */ g->finobjsur = g->finobj; /* all news are survivals */ sweepgen(L, g, &g->tobefnz, NULL); @@ -1202,11 +1202,11 @@ static void atomic2gen (lua_State *L, global_State *g) { g->gcstate = GCSswpallgc; sweep2old(L, &g->allgc); /* everything alive now is old */ - g->reallyold = g->old = g->survival = g->allgc; + g->reallyold = g->old1 = g->survival = g->allgc; /* repeat for 'finobj' lists */ sweep2old(L, &g->finobj); - g->finobjrold = g->finobjold = g->finobjsur = g->finobj; + g->finobjrold = g->finobjold1 = g->finobjsur = g->finobj; sweep2old(L, &g->tobefnz); @@ -1239,10 +1239,10 @@ static lu_mem entergen (lua_State *L, global_State *g) { */ static void enterinc (global_State *g) { whitelist(g, g->allgc); - g->reallyold = g->old = g->survival = NULL; + g->reallyold = g->old1 = g->survival = NULL; whitelist(g, g->finobj); whitelist(g, g->tobefnz); - g->finobjrold = g->finobjold = g->finobjsur = NULL; + g->finobjrold = g->finobjold1 = g->finobjsur = NULL; g->gcstate = GCSpause; g->gckind = KGC_INC; g->lastatomic = 0; diff --git a/lstate.c b/lstate.c index 06fa13d7..38a2b45a 100644 --- a/lstate.c +++ b/lstate.c @@ -413,8 +413,8 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { g->gckind = KGC_INC; g->gcemergency = 0; g->finobj = g->tobefnz = g->fixedgc = NULL; - g->survival = g->old = g->reallyold = NULL; - g->finobjsur = g->finobjold = g->finobjrold = NULL; + g->survival = g->old1 = g->reallyold = NULL; + g->finobjsur = g->finobjold1 = g->finobjrold = NULL; g->sweepgc = NULL; g->gray = g->grayagain = NULL; g->weak = g->ephemeron = g->allweak = NULL; diff --git a/lstate.h b/lstate.h index 0c545ec5..c02b4c8b 100644 --- a/lstate.h +++ b/lstate.h @@ -32,13 +32,20 @@ ** ** 'allgc' -> 'survival': new objects; ** 'survival' -> 'old': objects that survived one collection; -** 'old' -> 'reallyold': objects that became old in last collection; +** 'old1' -> 'reallyold': objects that became old in last collection; ** 'reallyold' -> NULL: objects old for more than one cycle. ** ** 'finobj' -> 'finobjsur': new objects marked for finalization; -** 'finobjsur' -> 'finobjold': survived """"; -** 'finobjold' -> 'finobjrold': just old """"; +** 'finobjsur' -> 'finobjold1': survived """"; +** 'finobjold1' -> 'finobjrold': just old """"; ** 'finobjrold' -> NULL: really old """". +** +** All lists can contain elements older than their main ages, due +** to 'luaC_checkfinalizer' and 'udata2finalize', which move +** objects between the normal lists and the "marked for finalization" +** lists. Moreover, barriers can age young objects in young lists as +** OLD0, which then become OLD1. However, a list never contains +** elements younger than their main ages. */ /* @@ -257,10 +264,10 @@ typedef struct global_State { GCObject *fixedgc; /* list of objects not to be collected */ /* fields for generational collector */ GCObject *survival; /* start of objects that survived one GC cycle */ - GCObject *old; /* start of old objects */ - GCObject *reallyold; /* old objects with more than one cycle */ + GCObject *old1; /* start of old1 objects */ + GCObject *reallyold; /* objects more than one cycle old ("really old") */ GCObject *finobjsur; /* list of survival objects with finalizers */ - GCObject *finobjold; /* list of old objects with finalizers */ + GCObject *finobjold1; /* list of old1 objects with finalizers */ GCObject *finobjrold; /* list of really old objects with finalizers */ struct lua_State *twups; /* list of threads with open upvalues */ lua_CFunction panic; /* to be called in unprotected errors */ diff --git a/ltests.c b/ltests.c index a4e5d282..a13714d6 100644 --- a/ltests.c +++ b/ltests.c @@ -586,10 +586,10 @@ int lua_checkmemory (lua_State *L) { /* check 'allgc' list */ maybedead = (GCSatomic < g->gcstate && g->gcstate <= GCSswpallgc); - checklist(g, maybedead, 0, g->allgc, g->survival, g->old, g->reallyold); + checklist(g, maybedead, 0, g->allgc, g->survival, g->old1, g->reallyold); /* check 'finobj' list */ - checklist(g, 0, 1, g->finobj, g->finobjsur, g->finobjold, g->finobjrold); + checklist(g, 0, 1, g->finobj, g->finobjsur, g->finobjold1, g->finobjrold); /* check 'tobefnz' list */ for (o = g->tobefnz; o != NULL; o = o->next) {