summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2013-08-27 17:04:00 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2013-08-27 17:04:00 -0300
commit90972ff136f310f00b04d9e9837ee0640983b743 (patch)
tree5362eb13fd6ab3d314bc9baefe3d73b1f0e02fad
parentaf35c7f398e8149b5f2481b63b399674e4ecdf7e (diff)
downloadlua-github-90972ff136f310f00b04d9e9837ee0640983b743.tar.gz
LOCALBLACK changed to LOCALMARK and used also to control whether object
is in 'localgc' list + luaC_newobj by default puts object in 'localgc' list
-rw-r--r--lfunc.c10
-rw-r--r--lgc.c16
-rw-r--r--lgc.h4
-rw-r--r--lstring.c6
-rw-r--r--ltable.c4
-rw-r--r--ltests.c4
6 files changed, 24 insertions, 20 deletions
diff --git a/lfunc.c b/lfunc.c
index 5bbae69c..0db0a87b 100644
--- a/lfunc.c
+++ b/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;
diff --git a/lgc.c b/lgc.c
index f09af8e7..f905d9d5 100644
--- a/lgc.c
+++ b/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 */
diff --git a/lgc.h b/lgc.h
index 13563db3..cce4293b 100644
--- a/lgc.h
+++ b/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)
diff --git a/lstring.c b/lstring.c
index 6d1ce978..3fb86ab2 100644
--- a/lstring.c
+++ b/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;
diff --git a/ltable.c b/ltable.c
index f5b8fcf6..ed5d9977 100644
--- a/ltable.c
+++ b/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;
diff --git a/ltests.c b/ltests.c
index e2057736..aa247aa6 100644
--- a/ltests.c
+++ b/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;
}