Pārlūkot izejas kodu

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

Roberto Ierusalimschy 15 gadi atpakaļ
vecāks
revīzija
3aa9598177
4 mainītis faili ar 18 papildinājumiem un 21 dzēšanām
  1. 10 9
      lgc.c
  2. 3 5
      lgc.h
  3. 2 3
      lstate.c
  4. 3 4
      ltests.c

+ 10 - 9
lgc.c

@@ -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
 ** 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)
       sweepthread(L, gco2th(curr), 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 */
       freeobj(L, curr);  /* erase 'curr' */
     }
@@ -718,11 +718,11 @@ void luaC_freeallobjects (lua_State *L) {
   int i;
   while (g->tobefnz) GCTM(L, 0);  /* Call all pending finalizers */
   /* following "white" makes all objects look dead */
-  g->currentwhite = WHITEBITS | bitmask(SFIXEDBIT);
+  g->currentwhite = WHITEBITS;
   sweepwholelist(L, &g->udgc);
+  lua_assert(g->udgc == NULL);
   sweepwholelist(L, &g->allgc);
-  lua_assert(g->allgc == obj2gco(g->mainthread) &&
-             g->mainthread->next == NULL);
+  lua_assert(g->allgc == NULL);
   for (i = 0; i < g->strt.size; i++)  /* free all string lists */
     sweepwholelist(L, &g->strt.hash[i]);
   lua_assert(g->strt.nuse == 0);
@@ -781,14 +781,15 @@ static l_mem singlestep (lua_State *L) {
     case GCSsweepstring: {
       if (g->sweepstrgc < g->strt.size) {
         sweepwholelist(L, &g->strt.hash[g->sweepstrgc++]);
-        return GCSWEEPCOST;
       }
-      else {  /* nothing more to sweep */
-        g->sweepgc = &g->udgc;  /* sweep all userdata */
+      else {  /* no more strings to sweep */
+        /* sweep main thread */
+        sweeplist(L, cast(GCObject **, &g->mainthread), 1);
+        g->sweepgc = &g->udgc;  /* prepare to sweep userdata */
         g->gcstate = GCSsweepudata;
         checkSizes(L);
-        return 0;
       }
+      return GCSWEEPCOST;
     }
     case GCSsweepudata:
     case GCSsweep: {

+ 3 - 5
lgc.h

@@ -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
 ** See Copyright Notice in lua.h
 */
@@ -48,8 +48,7 @@
 ** bit 3 - for userdata: has been finalized
 ** bit 4 - for userdata: it's in 'udgc' list or in 'tobefnz'
 ** bit 5 - object is fixed (should not be collected)
-** bit 6 - object is "super" fixed (only the main thread)
-** bit 7 - object is old (only in generational mode)
+** bit 6 - object is old (only in generational mode)
 */
 #define WHITE0BIT	0
 #define WHITE1BIT	1
@@ -57,8 +56,7 @@
 #define FINALIZEDBIT	3
 #define SEPARATED	4
 #define FIXEDBIT	5
-#define SFIXEDBIT	6
-#define OLDBIT		7
+#define OLDBIT		6
 
 #define WHITEBITS	bit2mask(WHITE0BIT, WHITE1BIT)
 

+ 2 - 3
lstate.c

@@ -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
 ** 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);
   g->gckind = KGC_NORMAL;
   g->nCcalls = 0;
-  set2bits(L->marked, FIXEDBIT, SFIXEDBIT);
   preinit_state(L, g);
   g->frealloc = f;
   g->ud = ud;
@@ -264,7 +263,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
   g->panic = NULL;
   g->version = lua_version(NULL);
   g->gcstate = GCSpause;
-  g->allgc = obj2gco(L);
+  g->allgc = NULL;
   g->udgc = NULL;
   g->tobefnz = NULL;
   g->totalbytes = sizeof(LG);

+ 3 - 4
ltests.c

@@ -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
 ** See Copyright Notice in lua.h
 */
@@ -375,11 +375,10 @@ int lua_checkmemory (lua_State *L) {
   checkliveness(g, &g->l_registry);
   lua_assert(!isdead(g, obj2gco(g->l_gt)));
   checkstack(g, g->mainthread);
-  for (o = g->allgc; o != obj2gco(g->mainthread); o = gch(o)->next) {
-    lua_assert(!testbits(o->gch.marked, bit2mask(SEPARATED, SFIXEDBIT)));
+  for (o = g->allgc; o != NULL; o = gch(o)->next) {
+    lua_assert(!testbits(o->gch.marked, bitmask(SEPARATED)));
     checkobject(g, o);
   }
-  lua_assert(testbit(o->gch.marked, SFIXEDBIT));
   for (o = g->udgc; o != NULL; o = gch(o)->next) {
     lua_assert(gch(o)->tt == LUA_TUSERDATA &&
                !isdead(g, o) &&