diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-10-22 14:58:14 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-10-22 14:58:14 -0300 |
commit | 81bc5711a8b71ced34eef8750deb0ce4475d5cd5 (patch) | |
tree | 452e7c82585045989f041cb78c0fcdb7cdd5f724 /lgc.c | |
parent | 6a77a6b73f0f06c4396e9b60d44b064b999cb06a (diff) | |
download | lua-81bc5711a8b71ced34eef8750deb0ce4475d5cd5.tar.gz lua-81bc5711a8b71ced34eef8750deb0ce4475d5cd5.tar.bz2 lua-81bc5711a8b71ced34eef8750deb0ce4475d5cd5.zip |
only one instance of registry and default metatable per global state
Diffstat (limited to 'lgc.c')
-rw-r--r-- | lgc.c | 20 |
1 files changed, 12 insertions, 8 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 1.151 2002/09/19 19:54:22 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 1.152 2002/10/08 18:46:08 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 | */ |
@@ -34,7 +34,6 @@ typedef struct GCState { | |||
34 | #define resetbit(x,b) ((x) &= cast(lu_byte, ~(1<<(b)))) | 34 | #define resetbit(x,b) ((x) &= cast(lu_byte, ~(1<<(b)))) |
35 | #define testbit(x,b) ((x) & (1<<(b))) | 35 | #define testbit(x,b) ((x) & (1<<(b))) |
36 | 36 | ||
37 | #define mark(x) setbit((x)->gch.marked, 0) | ||
38 | #define unmark(x) resetbit((x)->gch.marked, 0) | 37 | #define unmark(x) resetbit((x)->gch.marked, 0) |
39 | #define ismarked(x) ((x)->gch.marked & ((1<<4)|1)) | 38 | #define ismarked(x) ((x)->gch.marked & ((1<<4)|1)) |
40 | 39 | ||
@@ -101,7 +100,7 @@ static void markclosure (GCState *st, Closure *cl) { | |||
101 | 100 | ||
102 | 101 | ||
103 | static void reallymarkobject (GCState *st, GCObject *o) { | 102 | static void reallymarkobject (GCState *st, GCObject *o) { |
104 | mark(o); | 103 | setbit(o->gch.marked, 0); /* mark object */ |
105 | switch (o->gch.tt) { | 104 | switch (o->gch.tt) { |
106 | case LUA_TFUNCTION: { | 105 | case LUA_TFUNCTION: { |
107 | markclosure(st, &o->cl); | 106 | markclosure(st, &o->cl); |
@@ -135,15 +134,13 @@ static void traversestacks (GCState *st) { | |||
135 | do { /* for each thread */ | 134 | do { /* for each thread */ |
136 | StkId o, lim; | 135 | StkId o, lim; |
137 | CallInfo *ci; | 136 | CallInfo *ci; |
138 | if (ttisnil(defaultmeta(L1))) { /* incomplete state? */ | 137 | if (ttisnil(gt(L1))) { /* incomplete state? */ |
139 | lua_assert(L1 != st->L); | 138 | lua_assert(L1 != st->L); |
140 | L1 = L1->next; | 139 | L1 = L1->next; |
141 | luaE_closethread(st->L, L1->previous); /* collect it */ | 140 | luaE_closethread(st->L, L1->previous); /* collect it */ |
142 | continue; | 141 | continue; |
143 | } | 142 | } |
144 | markobject(st, defaultmeta(L1)); | ||
145 | markobject(st, gt(L1)); | 143 | markobject(st, gt(L1)); |
146 | markobject(st, registry(L1)); | ||
147 | for (o=L1->stack; o<L1->top; o++) | 144 | for (o=L1->stack; o<L1->top; o++) |
148 | markobject(st, o); | 145 | markobject(st, o); |
149 | lim = o; | 146 | lim = o; |
@@ -156,6 +153,8 @@ static void traversestacks (GCState *st) { | |||
156 | lua_assert(L1->previous->next == L1 && L1->next->previous == L1); | 153 | lua_assert(L1->previous->next == L1 && L1->next->previous == L1); |
157 | L1 = L1->next; | 154 | L1 = L1->next; |
158 | } while (L1 != st->L); | 155 | } while (L1 != st->L); |
156 | markobject(st, defaultmeta(L1)); | ||
157 | markobject(st, registry(L1)); | ||
159 | } | 158 | } |
160 | 159 | ||
161 | 160 | ||
@@ -342,6 +341,7 @@ static void checkSizes (lua_State *L) { | |||
342 | size_t newsize = luaZ_sizebuffer(&G(L)->buff) / 2; | 341 | size_t newsize = luaZ_sizebuffer(&G(L)->buff) / 2; |
343 | luaZ_resizebuffer(L, &G(L)->buff, newsize); | 342 | luaZ_resizebuffer(L, &G(L)->buff, newsize); |
344 | } | 343 | } |
344 | G(L)->GCthreshold = 2*G(L)->nblocks; /* new threshold */ | ||
345 | } | 345 | } |
346 | 346 | ||
347 | 347 | ||
@@ -389,7 +389,7 @@ void luaC_sweep (lua_State *L, int all) { | |||
389 | } | 389 | } |
390 | 390 | ||
391 | 391 | ||
392 | void luaC_collectgarbage (lua_State *L) { | 392 | static void mark (lua_State *L) { |
393 | GCState st; | 393 | GCState st; |
394 | Table *toclear; | 394 | Table *toclear; |
395 | st.L = L; | 395 | st.L = L; |
@@ -407,9 +407,13 @@ void luaC_collectgarbage (lua_State *L) { | |||
407 | /* `propagatemarks' may reborne some weak tables; clear them too */ | 407 | /* `propagatemarks' may reborne some weak tables; clear them too */ |
408 | cleartablekeys(st.toclear); | 408 | cleartablekeys(st.toclear); |
409 | cleartablevalues(st.toclear); | 409 | cleartablevalues(st.toclear); |
410 | } | ||
411 | |||
412 | |||
413 | void luaC_collectgarbage (lua_State *L) { | ||
414 | mark(L); | ||
410 | luaC_sweep(L, 0); | 415 | luaC_sweep(L, 0); |
411 | checkSizes(L); | 416 | checkSizes(L); |
412 | G(L)->GCthreshold = 2*G(L)->nblocks; /* new threshold */ | ||
413 | callGCTM(L); | 417 | callGCTM(L); |
414 | } | 418 | } |
415 | 419 | ||