فهرست منبع

LOCALBLACK changed to LOCALMARK and used also to control whether object
is in 'localgc' list + luaC_newobj by default puts object in 'localgc'
list

Roberto Ierusalimschy 12 سال پیش
والد
کامیت
90972ff136
6فایلهای تغییر یافته به همراه24 افزوده شده و 20 حذف شده
  1. 4 6
      lfunc.c
  2. 10 6
      lgc.c
  3. 2 2
      lgc.h
  4. 3 3
      lstring.c
  5. 2 2
      ltable.c
  6. 3 1
      ltests.c

+ 4 - 6
lfunc.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lfunc.c,v 2.35 2013/08/26 12:41:10 roberto Exp roberto $
+** $Id: lfunc.c,v 2.36 2013/08/27 18:53:35 roberto Exp roberto $
 ** Auxiliary functions to manipulate prototypes and closures
 ** See Copyright Notice in lua.h
 */
@@ -21,16 +21,14 @@
 
 
 Closure *luaF_newCclosure (lua_State *L, int n) {
-  Closure *c = &luaC_newobj(L, LUA_TCCL, sizeCclosure(n),
-                               &G(L)->localgc, 0)->cl;
+  Closure *c = &luaC_newobj(L, LUA_TCCL, sizeCclosure(n), NULL, 0)->cl;
   c->c.nupvalues = cast_byte(n);
   return c;
 }
 
 
 Closure *luaF_newLclosure (lua_State *L, int n) {
-  Closure *c = &luaC_newobj(L, LUA_TLCL, sizeLclosure(n),
-                               &G(L)->localgc, 0)->cl;
+  Closure *c = &luaC_newobj(L, LUA_TLCL, sizeLclosure(n), NULL, 0)->cl;
   c->l.p = NULL;
   c->l.nupvalues = cast_byte(n);
   while (n--) c->l.upvals[n] = NULL;
@@ -87,7 +85,7 @@ void luaF_close (lua_State *L, StkId level) {
 
 
 Proto *luaF_newproto (lua_State *L) {
-  Proto *f = &luaC_newobj(L, LUA_TPROTO, sizeof(Proto), NULL, 0)->p;
+  Proto *f = &luaC_newobj(L, LUA_TPROTO, sizeof(Proto), &G(L)->allgc, 0)->p;
   nolocal(obj2gco(f));  /* prototypes are never local */
   f->k = NULL;
   f->sizek = 0;

+ 10 - 6
lgc.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lgc.c,v 2.152 2013/08/26 12:41:10 roberto Exp roberto $
+** $Id: lgc.c,v 2.153 2013/08/27 18:53:35 roberto Exp roberto $
 ** Garbage Collector
 ** See Copyright Notice in lua.h
 */
@@ -208,9 +208,11 @@ GCObject *luaC_newobj (lua_State *L, int tt, size_t sz, GCObject **list,
   global_State *g = G(L);
   char *raw = cast(char *, luaM_newobject(L, novariant(tt), sz));
   GCObject *o = obj2gco(raw + offset);
-  if (list == NULL)
-    list = &g->allgc;  /* standard list for collectable objects */
   gch(o)->marked = luaC_white(g);
+  if (list == NULL)
+    list = &g->localgc;  /* standard list for collectable objects */
+  else
+    l_setbit(gch(o)->marked, LOCALMARK);  /* mark object as not in 'localgc' */
   gch(o)->tt = tt;
   gch(o)->next = *list;
   *list = o;
@@ -894,7 +896,7 @@ static void localmarkthread (lua_State *l) {
     return;  /* stack not completely built yet */
   for (; o < l->top; o++) {  /* mark live elements in the stack */
     if (iscollectable(o))
-      l_setbit(gcvalue(o)->gch.marked, LOCALBLACK);
+      l_setbit(gcvalue(o)->gch.marked, LOCALMARK);
   }
 }
 
@@ -918,10 +920,12 @@ static void localsweep (lua_State *L, global_State *g, GCObject **p) {
       *p = curr->gch.next;  /* remove 'curr' from list */
       curr->gch.next = g->allgc;  /* link 'curr' in 'allgc' list */
       g->allgc = curr;
+      /* mark it as out of local list */
+      l_setbit(curr->gch.marked, LOCALMARK);
     }
     else {  /* still local */
-      if (testbit(curr->gch.marked, LOCALBLACK)) {  /* locally alive? */
-        resetbit(curr->gch.marked, LOCALBLACK);
+      if (testbit(curr->gch.marked, LOCALMARK)) {  /* locally alive? */
+        resetbit(curr->gch.marked, LOCALMARK);
         p = &curr->gch.next;  /* go to next element */
       }
       else {  /* object is dead */

+ 2 - 2
lgc.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lgc.h,v 2.66 2013/08/23 13:34:54 roberto Exp roberto $
+** $Id: lgc.h,v 2.67 2013/08/27 18:53:35 roberto Exp roberto $
 ** Garbage Collector
 ** See Copyright Notice in lua.h
 */
@@ -77,7 +77,7 @@
 #define BLACKBIT	2  /* object is black */
 #define FINALIZEDBIT	3  /* object has been marked for finalization */
 #define LOCALBIT	4  /* object is not local */
-#define LOCALBLACK	5  /* object is 'locally black' */
+#define LOCALMARK	5  /* object is 'locally marked' or out of local list */
 /* bit 7 is currently used by tests (luaL_checkmemory) */
 
 #define WHITEBITS	bit2mask(WHITE0BIT, WHITE1BIT)

+ 3 - 3
lstring.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lstring.c,v 2.30 2013/08/22 15:21:48 roberto Exp roberto $
+** $Id: lstring.c,v 2.31 2013/08/23 13:34:54 roberto Exp roberto $
 ** String table (keeps all strings handled by Lua)
 ** See Copyright Notice in lua.h
 */
@@ -106,7 +106,7 @@ static TString *createstrobj (lua_State *L, const char *str, size_t l,
   TString *ts;
   size_t totalsize;  /* total size of TString object */
   totalsize = sizeof(TString) + ((l + 1) * sizeof(char));
-  ts = &luaC_newobj(L, tag, totalsize, &G(L)->localgc, 0)->ts;
+  ts = &luaC_newobj(L, tag, totalsize, NULL, 0)->ts;
   ts->tsv.len = l;
   ts->tsv.hash = h;
   ts->tsv.extra = 0;
@@ -213,7 +213,7 @@ Udata *luaS_newudata (lua_State *L, size_t s, Table *e) {
   Udata *u;
   if (s > MAX_SIZE - sizeof(Udata))
     luaM_toobig(L);
-  u = &luaC_newobj(L, LUA_TUSERDATA, sizeof(Udata) + s, NULL, 0)->u;
+  u = &luaC_newobj(L, LUA_TUSERDATA, sizeof(Udata) + s, &G(L)->allgc, 0)->u;
   u->uv.len = s;
   u->uv.metatable = NULL;
   u->uv.env = e;

+ 2 - 2
ltable.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ltable.c,v 2.78 2013/06/20 15:02:49 roberto Exp roberto $
+** $Id: ltable.c,v 2.79 2013/08/18 16:12:18 roberto Exp roberto $
 ** Lua tables (hash)
 ** See Copyright Notice in lua.h
 */
@@ -378,7 +378,7 @@ static void rehash (lua_State *L, Table *t, const TValue *ek) {
 
 
 Table *luaH_new (lua_State *L) {
-  Table *t = &luaC_newobj(L, LUA_TTABLE, sizeof(Table), NULL, 0)->h;
+  Table *t = &luaC_newobj(L, LUA_TTABLE, sizeof(Table), &G(L)->allgc, 0)->h;
   t->metatable = NULL;
   t->flags = cast_byte(~0);
   t->array = NULL;

+ 3 - 1
ltests.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ltests.c,v 2.149 2013/08/26 12:41:10 roberto Exp roberto $
+** $Id: ltests.c,v 2.150 2013/08/27 18:53:35 roberto Exp roberto $
 ** Internal Module for Debugging of the Lua Implementation
 ** See Copyright Notice in lua.h
 */
@@ -452,6 +452,7 @@ int lua_checkmemory (lua_State *L) {
     else lua_assert(!isthread);  /* ... and only threads */
     checkobject(g, o, maybedead);
     lua_assert(!tofinalize(o));
+    lua_assert(testbit(o->gch.marked, LOCALMARK));
   }
   /* check 'finobj' list */
   checkgray(g, g->finobj);
@@ -473,6 +474,7 @@ int lua_checkmemory (lua_State *L) {
   checkgray(g, g->localgc);
   for (o = g->localgc; o != NULL; o = gch(o)->next) {
     checkobject(g, o, 1);
+    lua_assert(!testbit(o->gch.marked, LOCALMARK));
   }
   return 0;
 }