new names and better order for GC states (sweep first lists that

can have dead objects)
This commit is contained in:
Roberto Ierusalimschy 2013-09-11 11:47:08 -03:00
parent dd373a8f66
commit 4eeb1831be
3 changed files with 30 additions and 30 deletions

30
lgc.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: lgc.c,v 2.161 2013/09/11 13:24:55 roberto Exp roberto $ ** $Id: lgc.c,v 2.162 2013/09/11 14:09:55 roberto Exp roberto $
** Garbage Collector ** Garbage Collector
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -1042,7 +1042,7 @@ static void setpause (global_State *g, l_mem estimate) {
static int entersweep (lua_State *L) { static int entersweep (lua_State *L) {
global_State *g = G(L); global_State *g = G(L);
int n = 0; int n = 0;
g->gcstate = GCSsweeplocal; g->gcstate = GCSswplocalgc;
lua_assert(g->sweepgc == NULL); lua_assert(g->sweepgc == NULL);
g->sweepgc = sweeptolive(L, &g->localgc, &n); g->sweepgc = sweeptolive(L, &g->localgc, &n);
if (g->sweepgc == NULL) /* no live objects in local list? */ if (g->sweepgc == NULL) /* no live objects in local list? */
@ -1151,25 +1151,25 @@ static lu_mem singlestep (lua_State *L) {
sw = entersweep(L); sw = entersweep(L);
return work + sw * GCSWEEPCOST; return work + sw * GCSWEEPCOST;
} }
case GCSsweeplocal: { case GCSswplocalgc: { /* sweep local objects */
return sweepstep(L, g, GCSsweeplocfin, &g->localfin); return sweepstep(L, g, GCSswpallgc, &g->allgc);
} }
case GCSsweeplocfin: { case GCSswpallgc: { /* sweep non-local objects */
return sweepstep(L, g, GCSsweepfin, &g->finobj); return sweepstep(L, g, GCSswpthreads, &g->mainthread->next);
} }
case GCSsweepfin: { case GCSswpthreads: { /* sweep threads */
return sweepstep(L, g, GCSsweepall, &g->allgc); return sweepstep(L, g, GCSswplocalfin, &g->localfin);
} }
case GCSsweepall: { case GCSswplocalfin: { /* sweep local objects with finalizers */
return sweepstep(L, g, GCSsweeptobefnz, &g->tobefnz); return sweepstep(L, g, GCSswpfinobj, &g->finobj);
} }
case GCSsweeptobefnz: { case GCSswpfinobj: { /* sweep non-local objects with finalizers */
return sweepstep(L, g, GCSsweepthreads, &g->mainthread->next); return sweepstep(L, g, GCSswptobefnz, &g->tobefnz);
} }
case GCSsweepthreads: { case GCSswptobefnz: { /* sweep objects to be finalized */
return sweepstep(L, g, GCSsweepend, NULL); return sweepstep(L, g, GCSswpend, NULL);
} }
case GCSsweepend: { case GCSswpend: { /* finish sweeps */
makewhite(g, obj2gco(g->mainthread)); /* sweep main thread */ makewhite(g, obj2gco(g->mainthread)); /* sweep main thread */
checkBuffer(L); checkBuffer(L);
g->gcstate = GCSpause; /* finish collection */ g->gcstate = GCSpause; /* finish collection */

18
lgc.h
View File

@ -1,5 +1,5 @@
/* /*
** $Id: lgc.h,v 2.73 2013/09/11 12:47:48 roberto Exp roberto $ ** $Id: lgc.h,v 2.74 2013/09/11 14:09:55 roberto Exp roberto $
** Garbage Collector ** Garbage Collector
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -38,18 +38,18 @@
*/ */
#define GCSpropagate 0 #define GCSpropagate 0
#define GCSatomic 1 #define GCSatomic 1
#define GCSsweeplocal 2 #define GCSswplocalgc 2
#define GCSsweeplocfin 3 #define GCSswpallgc 4
#define GCSsweepfin 4 #define GCSswpthreads 3
#define GCSsweepall 5 #define GCSswplocalfin 5
#define GCSsweeptobefnz 6 #define GCSswpfinobj 6
#define GCSsweepthreads 7 #define GCSswptobefnz 7
#define GCSsweepend 8 #define GCSswpend 8
#define GCSpause 9 #define GCSpause 9
#define issweepphase(g) \ #define issweepphase(g) \
(GCSsweeplocal <= (g)->gcstate && (g)->gcstate <= GCSsweepend) (GCSswplocalgc <= (g)->gcstate && (g)->gcstate <= GCSswpend)
/* /*

View File

@ -1,5 +1,5 @@
/* /*
** $Id: ltests.c,v 2.157 2013/09/11 12:47:48 roberto Exp roberto $ ** $Id: ltests.c,v 2.158 2013/09/11 14:09:55 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
*/ */
@ -434,14 +434,14 @@ int lua_checkmemory (lua_State *L) {
markgrays(g); markgrays(g);
/* check 'localgc' list */ /* check 'localgc' list */
checkgray(g, g->localgc); checkgray(g, g->localgc);
maybedead = (GCSatomic < g->gcstate && g->gcstate <= GCSsweeplocal); maybedead = (GCSatomic < g->gcstate && g->gcstate <= GCSswplocalgc);
for (o = g->localgc; o != NULL; o = gch(o)->next) { for (o = g->localgc; o != NULL; o = gch(o)->next) {
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 'allgc' list */ /* check 'allgc' list */
checkgray(g, g->allgc); checkgray(g, g->allgc);
maybedead = (GCSatomic < g->gcstate && g->gcstate <= GCSsweepall); maybedead = (GCSatomic < g->gcstate && g->gcstate <= GCSswpallgc);
for (o = g->allgc; o != NULL; o = gch(o)->next) { for (o = g->allgc; o != NULL; o = gch(o)->next) {
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));
@ -449,7 +449,7 @@ int lua_checkmemory (lua_State *L) {
} }
/* check thread list */ /* check thread list */
checkgray(g, obj2gco(g->mainthread)); checkgray(g, obj2gco(g->mainthread));
maybedead = (GCSatomic < g->gcstate && g->gcstate <= GCSsweepthreads); maybedead = (GCSatomic < g->gcstate && g->gcstate <= GCSswpthreads);
for (o = obj2gco(g->mainthread); o != NULL; o = gch(o)->next) { for (o = obj2gco(g->mainthread); o != NULL; o = gch(o)->next) {
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));
@ -655,8 +655,8 @@ static int gc_local (lua_State *L) {
static int gc_state (lua_State *L) { static int gc_state (lua_State *L) {
static const char *statenames[] = {"propagate", "atomic", static const char *statenames[] = {"propagate", "atomic",
"sweeplocal", "sweeplocfin", "sweepfin", "sweepall", "sweeplocalgc", "sweepallgc", "sweepthreads", "sweeplocalfin",
"sweeptobefnz", "sweepthreads", "sweepend", "pause", ""}; "sweepfinobj", "sweeptobefnz", "sweepend", "pause", ""};
int option = luaL_checkoption(L, 1, "", statenames); int option = luaL_checkoption(L, 1, "", statenames);
if (option == GCSpause + 1) { if (option == GCSpause + 1) {
lua_pushstring(L, statenames[G(L)->gcstate]); lua_pushstring(L, statenames[G(L)->gcstate]);