diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-09-11 09:47:48 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-09-11 09:47:48 -0300 |
| commit | d8aa8dd97e14dfd724e997261d305f2045d1ca63 (patch) | |
| tree | 675587d68a41657e6efc6f53334522a2e9b5bf03 | |
| parent | 115087344797d0aafb23f4fe5b902fdebd2c3310 (diff) | |
| download | lua-d8aa8dd97e14dfd724e997261d305f2045d1ca63.tar.gz lua-d8aa8dd97e14dfd724e997261d305f2045d1ca63.tar.bz2 lua-d8aa8dd97e14dfd724e997261d305f2045d1ca63.zip | |
objects in list 'tobefnz' have a GC life-cycle like all others
(specifically they are cleaned during sweep phase)
| -rw-r--r-- | lgc.c | 21 | ||||
| -rw-r--r-- | lgc.h | 7 | ||||
| -rw-r--r-- | ltests.c | 10 |
3 files changed, 21 insertions, 17 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lgc.c,v 2.158 2013/09/03 15:37:10 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 2.159 2013/09/11 12:26:14 roberto Exp roberto $ |
| 3 | ** Garbage Collector | 3 | ** Garbage Collector |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -85,9 +85,11 @@ | |||
| 85 | lua_longassert(!(iscollectable(o) && islocal(gcvalue(o)))); \ | 85 | lua_longassert(!(iscollectable(o) && islocal(gcvalue(o)))); \ |
| 86 | marklocalvalue(g,o); } | 86 | marklocalvalue(g,o); } |
| 87 | 87 | ||
| 88 | #define marklocalobject(g,t) \ | ||
| 89 | { if ((t) && iswhite(obj2gco(t))) reallymarkobject(g, obj2gco(t)); } | ||
| 90 | |||
| 88 | #define markobject(g,t) \ | 91 | #define markobject(g,t) \ |
| 89 | { lua_assert((t) == NULL || !islocal(obj2gco(t))); \ | 92 | { lua_assert((t) == NULL || !islocal(obj2gco(t))); marklocalobject(g,t); } |
| 90 | if ((t) && iswhite(obj2gco(t))) reallymarkobject(g, obj2gco(t)); } | ||
| 91 | 93 | ||
| 92 | static void reallymarkobject (global_State *g, GCObject *o); | 94 | static void reallymarkobject (global_State *g, GCObject *o); |
| 93 | 95 | ||
| @@ -291,10 +293,8 @@ static void markmt (global_State *g) { | |||
| 291 | */ | 293 | */ |
| 292 | static void markbeingfnz (global_State *g) { | 294 | static void markbeingfnz (global_State *g) { |
| 293 | GCObject *o; | 295 | GCObject *o; |
| 294 | for (o = g->tobefnz; o != NULL; o = gch(o)->next) { | 296 | for (o = g->tobefnz; o != NULL; o = gch(o)->next) |
| 295 | makewhite(g, o); | 297 | marklocalobject(g, o); |
| 296 | reallymarkobject(g, o); | ||
| 297 | } | ||
| 298 | } | 298 | } |
| 299 | 299 | ||
| 300 | 300 | ||
| @@ -781,7 +781,7 @@ static GCObject *udata2finalize (global_State *g) { | |||
| 781 | l_setbit(gch(o)->marked, LOCALMARK); | 781 | l_setbit(gch(o)->marked, LOCALMARK); |
| 782 | } | 782 | } |
| 783 | resetbit(gch(o)->marked, FINALIZEDBIT); /* object is back in 'allgc' */ | 783 | resetbit(gch(o)->marked, FINALIZEDBIT); /* object is back in 'allgc' */ |
| 784 | if (!keepinvariant(g)) /* not keeping invariant? */ | 784 | if (issweepphase(g)) |
| 785 | makewhite(g, o); /* "sweep" object */ | 785 | makewhite(g, o); /* "sweep" object */ |
| 786 | return o; | 786 | return o; |
| 787 | } | 787 | } |
| @@ -896,7 +896,7 @@ void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) { | |||
| 896 | ho->next = *p; /* link it in a "fin" list */ | 896 | ho->next = *p; /* link it in a "fin" list */ |
| 897 | *p = o; | 897 | *p = o; |
| 898 | l_setbit(ho->marked, FINALIZEDBIT); /* mark it as such */ | 898 | l_setbit(ho->marked, FINALIZEDBIT); /* mark it as such */ |
| 899 | if (!keepinvariant(g)) /* not keeping invariant? */ | 899 | if (issweepphase(g)) |
| 900 | makewhite(g, o); /* "sweep" object */ | 900 | makewhite(g, o); /* "sweep" object */ |
| 901 | } | 901 | } |
| 902 | } | 902 | } |
| @@ -1159,6 +1159,9 @@ static lu_mem singlestep (lua_State *L) { | |||
| 1159 | return sweepstep(L, g, GCSsweepall, &g->allgc); | 1159 | return sweepstep(L, g, GCSsweepall, &g->allgc); |
| 1160 | } | 1160 | } |
| 1161 | case GCSsweepall: { | 1161 | case GCSsweepall: { |
| 1162 | return sweepstep(L, g, GCSsweeptobefnz, &g->tobefnz); | ||
| 1163 | } | ||
| 1164 | case GCSsweeptobefnz: { | ||
| 1162 | return sweepstep(L, g, GCSsweepmainth, NULL); | 1165 | return sweepstep(L, g, GCSsweepmainth, NULL); |
| 1163 | } | 1166 | } |
| 1164 | case GCSsweepmainth: { /* sweep main thread */ | 1167 | case GCSsweepmainth: { /* sweep main thread */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lgc.h,v 2.71 2013/09/03 15:37:10 roberto Exp roberto $ | 2 | ** $Id: lgc.h,v 2.72 2013/09/11 12:26:14 roberto Exp roberto $ |
| 3 | ** Garbage Collector | 3 | ** Garbage Collector |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -42,8 +42,9 @@ | |||
| 42 | #define GCSsweeplocfin 3 | 42 | #define GCSsweeplocfin 3 |
| 43 | #define GCSsweepfin 4 | 43 | #define GCSsweepfin 4 |
| 44 | #define GCSsweepall 5 | 44 | #define GCSsweepall 5 |
| 45 | #define GCSsweepmainth 6 | 45 | #define GCSsweeptobefnz 6 |
| 46 | #define GCSpause 7 | 46 | #define GCSsweepmainth 7 |
| 47 | #define GCSpause 8 | ||
| 47 | 48 | ||
| 48 | 49 | ||
| 49 | #define issweepphase(g) \ | 50 | #define issweepphase(g) \ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltests.c,v 2.155 2013/09/05 19:31:49 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.156 2013/09/11 12:26:14 roberto Exp roberto $ |
| 3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -469,8 +469,8 @@ int lua_checkmemory (lua_State *L) { | |||
| 469 | /* check 'tobefnz' list */ | 469 | /* check 'tobefnz' list */ |
| 470 | checkgray(g, g->tobefnz); | 470 | checkgray(g, g->tobefnz); |
| 471 | for (o = g->tobefnz; o != NULL; o = gch(o)->next) { | 471 | for (o = g->tobefnz; o != NULL; o = gch(o)->next) { |
| 472 | lua_assert(!iswhite(o) || g->gcstate == GCSpause); | 472 | checkobject(g, o, 0); |
| 473 | lua_assert(!isdead(g, o) && tofinalize(o)); | 473 | lua_assert(tofinalize(o)); |
| 474 | lua_assert(gch(o)->tt == LUA_TUSERDATA || gch(o)->tt == LUA_TTABLE); | 474 | lua_assert(gch(o)->tt == LUA_TUSERDATA || gch(o)->tt == LUA_TTABLE); |
| 475 | } | 475 | } |
| 476 | return 0; | 476 | return 0; |
| @@ -650,8 +650,8 @@ static int gc_local (lua_State *L) { | |||
| 650 | 650 | ||
| 651 | static int gc_state (lua_State *L) { | 651 | static int gc_state (lua_State *L) { |
| 652 | static const char *statenames[] = {"propagate", "atomic", | 652 | static const char *statenames[] = {"propagate", "atomic", |
| 653 | "sweeplocal", "sweeplocfin", "sweepfin", "sweepall", "sweepmainth", | 653 | "sweeplocal", "sweeplocfin", "sweepfin", "sweepall", "sweeptobefnz", |
| 654 | "pause", ""}; | 654 | "sweepmainth", "pause", ""}; |
| 655 | int option = luaL_checkoption(L, 1, "", statenames); | 655 | int option = luaL_checkoption(L, 1, "", statenames); |
| 656 | if (option == GCSpause + 1) { | 656 | if (option == GCSpause + 1) { |
| 657 | lua_pushstring(L, statenames[G(L)->gcstate]); | 657 | lua_pushstring(L, statenames[G(L)->gcstate]); |
