This commit is contained in:
Roberto Ierusalimschy 2002-08-16 17:00:28 -03:00
parent da19c436cc
commit ecc7769de2
3 changed files with 28 additions and 28 deletions

48
lgc.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: lgc.c,v 1.145 2002/08/06 17:06:56 roberto Exp roberto $ ** $Id: lgc.c,v 1.146 2002/08/16 14:45:55 roberto Exp roberto $
** Garbage Collector ** Garbage Collector
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -58,7 +58,7 @@ static void reallymarkobject (GCState *st, TObject *o);
#define markobject(st,o) if (ismarkable(o)) reallymarkobject(st,o) #define markobject(st,o) if (ismarkable(o)) reallymarkobject(st,o)
static void protomark (Proto *f) { static void markproto (Proto *f) {
if (!f->marked) { if (!f->marked) {
int i; int i;
f->marked = 1; f->marked = 1;
@ -68,7 +68,7 @@ static void protomark (Proto *f) {
strmark(tsvalue(f->k+i)); strmark(tsvalue(f->k+i));
} }
for (i=0; i<f->sizep; i++) for (i=0; i<f->sizep; i++)
protomark(f->p[i]); markproto(f->p[i]);
for (i=0; i<f->sizelocvars; i++) /* mark local-variable names */ for (i=0; i<f->sizelocvars; i++) /* mark local-variable names */
strmark(f->locvars[i].varname); strmark(f->locvars[i].varname);
} }
@ -97,7 +97,7 @@ static void markclosure (GCState *st, Closure *cl) {
int i; int i;
lua_assert(cl->l.nupvalues == cl->l.p->nupvalues); lua_assert(cl->l.nupvalues == cl->l.p->nupvalues);
marktable(st, hvalue(&cl->l.g)); marktable(st, hvalue(&cl->l.g));
protomark(cl->l.p); markproto(cl->l.p);
for (i=0; i<cl->l.nupvalues; i++) { /* mark its upvalues */ for (i=0; i<cl->l.nupvalues; i++) { /* mark its upvalues */
UpVal *u = cl->l.upvals[i]; UpVal *u = cl->l.upvals[i];
if (!u->marked) { if (!u->marked) {
@ -147,7 +147,7 @@ static void checkstacksizes (lua_State *L, StkId max) {
} }
static void markstacks (GCState *st) { static void traversestacks (GCState *st) {
lua_State *L1 = st->L; lua_State *L1 = st->L;
do { /* for each thread */ do { /* for each thread */
StkId o, lim; StkId o, lim;
@ -251,7 +251,7 @@ static void propagatemarks (GCState *st) {
} }
static int hasmark (const TObject *o) { static int ismarked (const TObject *o) {
switch (ttype(o)) { switch (ttype(o)) {
case LUA_TUSERDATA: case LUA_TUSERDATA:
return isudmarked(uvalue(o)); return isudmarked(uvalue(o));
@ -279,7 +279,7 @@ static void cleartablekeys (GCState *st) {
int i = sizenode(h); int i = sizenode(h);
while (i--) { while (i--) {
Node *n = node(h, i); Node *n = node(h, i);
if (!hasmark(key(n))) /* key was collected? */ if (!ismarked(key(n))) /* key was collected? */
removekey(n); /* remove entry from table */ removekey(n); /* remove entry from table */
} }
} }
@ -297,13 +297,13 @@ static void cleartablevalues (GCState *st) {
int i = sizearray(h); int i = sizearray(h);
while (i--) { while (i--) {
TObject *o = &h->array[i]; TObject *o = &h->array[i];
if (!hasmark(o)) /* value was collected? */ if (!ismarked(o)) /* value was collected? */
setnilvalue(o); /* remove value */ setnilvalue(o); /* remove value */
} }
i = sizenode(h); i = sizenode(h);
while (i--) { while (i--) {
Node *n = node(h, i); Node *n = node(h, i);
if (!hasmark(val(n))) /* value was collected? */ if (!ismarked(val(n))) /* value was collected? */
removekey(n); /* remove entry from table */ removekey(n); /* remove entry from table */
} }
} }
@ -311,7 +311,7 @@ static void cleartablevalues (GCState *st) {
} }
static void collectproto (lua_State *L) { static void sweepproto (lua_State *L) {
Proto **p = &G(L)->rootproto; Proto **p = &G(L)->rootproto;
Proto *curr; Proto *curr;
while ((curr = *p) != NULL) { while ((curr = *p) != NULL) {
@ -327,7 +327,7 @@ static void collectproto (lua_State *L) {
} }
static void collectclosures (lua_State *L) { static void sweepclosures (lua_State *L) {
Closure **p = &G(L)->rootcl; Closure **p = &G(L)->rootcl;
Closure *curr; Closure *curr;
while ((curr = *p) != NULL) { while ((curr = *p) != NULL) {
@ -343,7 +343,7 @@ static void collectclosures (lua_State *L) {
} }
static void collectupval (lua_State *L) { static void sweepupval (lua_State *L) {
UpVal **v = &G(L)->rootupval; UpVal **v = &G(L)->rootupval;
UpVal *curr; UpVal *curr;
while ((curr = *v) != NULL) { while ((curr = *v) != NULL) {
@ -359,7 +359,7 @@ static void collectupval (lua_State *L) {
} }
static void collecttable (lua_State *L) { static void sweeptable (lua_State *L) {
Table **p = &G(L)->roottable; Table **p = &G(L)->roottable;
Table *curr; Table *curr;
while ((curr = *p) != NULL) { while ((curr = *p) != NULL) {
@ -376,7 +376,7 @@ static void collecttable (lua_State *L) {
static void collectudata (lua_State *L) { static void sweepudata (lua_State *L) {
Udata **p = &G(L)->rootudata; Udata **p = &G(L)->rootudata;
Udata *curr; Udata *curr;
while ((curr = *p) != NULL) { while ((curr = *p) != NULL) {
@ -392,7 +392,7 @@ static void collectudata (lua_State *L) {
} }
static void collectstrings (lua_State *L, int all) { static void sweepstrings (lua_State *L, int all) {
int i; int i;
for (i=0; i<G(L)->strt.size; i++) { /* for each list */ for (i=0; i<G(L)->strt.size; i++) { /* for each list */
TString **p = &G(L)->strt.hash[i]; TString **p = &G(L)->strt.hash[i];
@ -462,13 +462,13 @@ void luaC_callallgcTM (lua_State *L) {
} }
void luaC_collect (lua_State *L, int all) { void luaC_sweep (lua_State *L, int all) {
collectudata(L); sweepudata(L);
collectstrings(L, all); sweepstrings(L, all);
collecttable(L); sweeptable(L);
collectproto(L); sweepproto(L);
collectupval(L); sweepupval(L);
collectclosures(L); sweepclosures(L);
} }
@ -477,14 +477,14 @@ void luaC_collectgarbage (lua_State *L) {
st.L = L; st.L = L;
st.tmark = NULL; st.tmark = NULL;
st.toclear = NULL; st.toclear = NULL;
markstacks(&st); /* mark all stacks */ traversestacks(&st); /* mark all stacks */
propagatemarks(&st); /* mark all reachable objects */ propagatemarks(&st); /* mark all reachable objects */
cleartablevalues(&st); cleartablevalues(&st);
separateudata(L); /* separate userdata to be preserved */ separateudata(L); /* separate userdata to be preserved */
marktmu(&st); /* mark `preserved' userdata */ marktmu(&st); /* mark `preserved' userdata */
propagatemarks(&st); /* remark */ propagatemarks(&st); /* remark */
cleartablekeys(&st); cleartablekeys(&st);
luaC_collect(L, 0); luaC_sweep(L, 0);
checkMbuffer(L); checkMbuffer(L);
G(L)->GCthreshold = 2*G(L)->nblocks; /* new threshold */ G(L)->GCthreshold = 2*G(L)->nblocks; /* new threshold */
callGCTM(L); callGCTM(L);

4
lgc.h
View File

@ -1,5 +1,5 @@
/* /*
** $Id: lgc.h,v 1.1 2001/11/29 22:14:34 rieru Exp rieru $ ** $Id: lgc.h,v 1.14 2001/12/10 22:11:23 roberto Exp roberto $
** Garbage Collector ** Garbage Collector
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -16,7 +16,7 @@
void luaC_callallgcTM (lua_State *L); void luaC_callallgcTM (lua_State *L);
void luaC_collect (lua_State *L, int all); void luaC_sweep (lua_State *L, int all);
void luaC_collectgarbage (lua_State *L); void luaC_collectgarbage (lua_State *L);

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lstate.c,v 1.102 2002/08/06 15:32:22 roberto Exp roberto $ ** $Id: lstate.c,v 1.103 2002/08/07 19:22:39 roberto Exp roberto $
** Global State ** Global State
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -159,7 +159,7 @@ void luaE_closethread (lua_State *OL, lua_State *L) {
static void close_state (lua_State *L) { static void close_state (lua_State *L) {
luaF_close(L, L->stack); /* close all upvalues for this thread */ luaF_close(L, L->stack); /* close all upvalues for this thread */
if (G(L)) { /* close global state */ if (G(L)) { /* close global state */
luaC_collect(L, 1); /* collect all elements */ luaC_sweep(L, 1); /* collect all elements */
lua_assert(G(L)->rootproto == NULL); lua_assert(G(L)->rootproto == NULL);
lua_assert(G(L)->rootudata == NULL); lua_assert(G(L)->rootudata == NULL);
lua_assert(G(L)->rootcl == NULL); lua_assert(G(L)->rootcl == NULL);