aboutsummaryrefslogtreecommitdiff
path: root/lgc.c
diff options
context:
space:
mode:
Diffstat (limited to 'lgc.c')
-rw-r--r--lgc.c21
1 files changed, 7 insertions, 14 deletions
diff --git a/lgc.c b/lgc.c
index 36e34368..18a05142 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 2.230 2017/06/01 19:16:34 roberto Exp roberto $ 2** $Id: lgc.c,v 2.231 2017/06/09 16:48:44 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*/
@@ -75,8 +75,6 @@
75 75
76#define keyiswhite(n) (keyiscollectable(n) && iswhite(gckey(n))) 76#define keyiswhite(n) (keyiscollectable(n) && iswhite(gckey(n)))
77 77
78#define checkdeadkey(n) lua_assert(!keyisdead(n) || ttisnil(gval(n)))
79
80 78
81#define checkconsistency(obj) \ 79#define checkconsistency(obj) \
82 lua_longassert(!iscollectable(obj) || righttt(obj)) 80 lua_longassert(!iscollectable(obj) || righttt(obj))
@@ -119,13 +117,11 @@ static lu_mem atomic (lua_State *L);
119 117
120 118
121/* 119/*
122** If key is not marked, mark its entry as dead. This allows key to be 120** If key is not marked, mark its entry as dead. This allows the
123** collected, but keeps its entry in the table. A dead node is needed 121** collection of the key, but keeps its entry in the table (its removal
124** when Lua looks up for a key (it may be part of a chain) and when 122** could break a chain). Other places never manipulate dead keys,
125** traversing a weak table (key might be removed from the table during 123** because its associated nil value is enough to signal that the entry
126** traversal). Other places never manipulate dead keys, because its 124** is logically empty.
127** associated nil value is enough to signal that the entry is logically
128** empty.
129*/ 125*/
130static void removeentry (Node *n) { 126static void removeentry (Node *n) {
131 lua_assert(ttisnil(gval(n))); 127 lua_assert(ttisnil(gval(n)));
@@ -203,7 +199,7 @@ LUAI_FUNC void luaC_protobarrier_ (lua_State *L, Proto *p) {
203 lua_assert(g->gckind != KGC_GEN || isold(p)); 199 lua_assert(g->gckind != KGC_GEN || isold(p));
204 if (getage(p) == G_OLD1) /* still need to be visited? */ 200 if (getage(p) == G_OLD1) /* still need to be visited? */
205 linkgclist(p, g->grayagain); /* link it in 'grayagain' */ 201 linkgclist(p, g->grayagain); /* link it in 'grayagain' */
206 else 202 else
207 linkgclist(p, g->protogray); /* link it in 'protogray' */ 203 linkgclist(p, g->protogray); /* link it in 'protogray' */
208 black2gray(p); /* make prototype gray (to avoid other barriers) */ 204 black2gray(p); /* make prototype gray (to avoid other barriers) */
209} 205}
@@ -391,7 +387,6 @@ static void traverseweakvalue (global_State *g, Table *h) {
391 worth traversing it now just to check) */ 387 worth traversing it now just to check) */
392 int hasclears = (h->sizearray > 0); 388 int hasclears = (h->sizearray > 0);
393 for (n = gnode(h, 0); n < limit; n++) { /* traverse hash part */ 389 for (n = gnode(h, 0); n < limit; n++) { /* traverse hash part */
394 checkdeadkey(n);
395 if (ttisnil(gval(n))) /* entry is empty? */ 390 if (ttisnil(gval(n))) /* entry is empty? */
396 removeentry(n); /* remove it */ 391 removeentry(n); /* remove it */
397 else { 392 else {
@@ -434,7 +429,6 @@ static int traverseephemeron (global_State *g, Table *h) {
434 } 429 }
435 /* traverse hash part */ 430 /* traverse hash part */
436 for (n = gnode(h, 0); n < limit; n++) { 431 for (n = gnode(h, 0); n < limit; n++) {
437 checkdeadkey(n);
438 if (ttisnil(gval(n))) /* entry is empty? */ 432 if (ttisnil(gval(n))) /* entry is empty? */
439 removeentry(n); /* remove it */ 433 removeentry(n); /* remove it */
440 else if (iscleared(g, gckeyN(n))) { /* key is not marked (yet)? */ 434 else if (iscleared(g, gckeyN(n))) { /* key is not marked (yet)? */
@@ -468,7 +462,6 @@ static void traversestrongtable (global_State *g, Table *h) {
468 for (i = 0; i < h->sizearray; i++) /* traverse array part */ 462 for (i = 0; i < h->sizearray; i++) /* traverse array part */
469 markvalue(g, &h->array[i]); 463 markvalue(g, &h->array[i]);
470 for (n = gnode(h, 0); n < limit; n++) { /* traverse hash part */ 464 for (n = gnode(h, 0); n < limit; n++) { /* traverse hash part */
471 checkdeadkey(n);
472 if (ttisnil(gval(n))) /* entry is empty? */ 465 if (ttisnil(gval(n))) /* entry is empty? */
473 removeentry(n); /* remove it */ 466 removeentry(n); /* remove it */
474 else { 467 else {