aboutsummaryrefslogtreecommitdiff
path: root/lgc.c
diff options
context:
space:
mode:
Diffstat (limited to 'lgc.c')
-rw-r--r--lgc.c64
1 files changed, 32 insertions, 32 deletions
diff --git a/lgc.c b/lgc.c
index 495eb4ac..24278dab 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 2.183 2014/05/25 19:08:32 roberto Exp roberto $ 2** $Id: lgc.c,v 2.184 2014/06/30 19:48: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*/
@@ -62,10 +62,10 @@
62*/ 62*/
63#define maskcolors (~(bitmask(BLACKBIT) | WHITEBITS)) 63#define maskcolors (~(bitmask(BLACKBIT) | WHITEBITS))
64#define makewhite(g,x) \ 64#define makewhite(g,x) \
65 (gch(x)->marked = cast_byte((gch(x)->marked & maskcolors) | luaC_white(g))) 65 (x->marked = cast_byte((x->marked & maskcolors) | luaC_white(g)))
66 66
67#define white2gray(x) resetbits(gch(x)->marked, WHITEBITS) 67#define white2gray(x) resetbits(x->marked, WHITEBITS)
68#define black2gray(x) resetbit(gch(x)->marked, BLACKBIT) 68#define black2gray(x) resetbit(x->marked, BLACKBIT)
69 69
70 70
71#define valiswhite(x) (iscollectable(x) && iswhite(gcvalue(x))) 71#define valiswhite(x) (iscollectable(x) && iswhite(gcvalue(x)))
@@ -141,7 +141,7 @@ void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v) {
141 global_State *g = G(L); 141 global_State *g = G(L);
142 lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o)); 142 lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o));
143 lua_assert(g->gcstate != GCSpause); 143 lua_assert(g->gcstate != GCSpause);
144 lua_assert(gch(o)->tt != LUA_TTABLE); /* tables use a back barrier */ 144 lua_assert(o->tt != LUA_TTABLE); /* tables use a back barrier */
145 if (keepinvariant(g)) /* must keep invariant? */ 145 if (keepinvariant(g)) /* must keep invariant? */
146 reallymarkobject(g, v); /* restore invariant */ 146 reallymarkobject(g, v); /* restore invariant */
147 else { /* sweep phase */ 147 else { /* sweep phase */
@@ -159,7 +159,7 @@ void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v) {
159*/ 159*/
160void luaC_barrierback_ (lua_State *L, GCObject *o) { 160void luaC_barrierback_ (lua_State *L, GCObject *o) {
161 global_State *g = G(L); 161 global_State *g = G(L);
162 lua_assert(isblack(o) && !isdead(g, o) && gch(o)->tt == LUA_TTABLE); 162 lua_assert(isblack(o) && !isdead(g, o) && o->tt == LUA_TTABLE);
163 black2gray(o); /* make object gray (again) */ 163 black2gray(o); /* make object gray (again) */
164 gco2t(o)->gclist = g->grayagain; 164 gco2t(o)->gclist = g->grayagain;
165 g->grayagain = o; 165 g->grayagain = o;
@@ -185,8 +185,8 @@ void luaC_fix (lua_State *L, GCObject *o) {
185 global_State *g = G(L); 185 global_State *g = G(L);
186 lua_assert(g->allgc == o); /* object must be 1st in 'allgc' list! */ 186 lua_assert(g->allgc == o); /* object must be 1st in 'allgc' list! */
187 white2gray(o); /* they will be gray forever */ 187 white2gray(o); /* they will be gray forever */
188 g->allgc = o->gch.next; /* remove object from 'allgc' list */ 188 g->allgc = o->next; /* remove object from 'allgc' list */
189 o->gch.next = g->fixedgc; /* link it to 'fixedgc' list */ 189 o->next = g->fixedgc; /* link it to 'fixedgc' list */
190 g->fixedgc = o; 190 g->fixedgc = o;
191} 191}
192 192
@@ -198,9 +198,9 @@ void luaC_fix (lua_State *L, GCObject *o) {
198GCObject *luaC_newobj (lua_State *L, int tt, size_t sz) { 198GCObject *luaC_newobj (lua_State *L, int tt, size_t sz) {
199 global_State *g = G(L); 199 global_State *g = G(L);
200 GCObject *o = cast(GCObject *, luaM_newobject(L, novariant(tt), sz)); 200 GCObject *o = cast(GCObject *, luaM_newobject(L, novariant(tt), sz));
201 gch(o)->marked = luaC_white(g); 201 o->marked = luaC_white(g);
202 gch(o)->tt = tt; 202 o->tt = tt;
203 gch(o)->next = g->allgc; 203 o->next = g->allgc;
204 g->allgc = o; 204 g->allgc = o;
205 return o; 205 return o;
206} 206}
@@ -225,7 +225,7 @@ GCObject *luaC_newobj (lua_State *L, int tt, size_t sz) {
225static void reallymarkobject (global_State *g, GCObject *o) { 225static void reallymarkobject (global_State *g, GCObject *o) {
226 reentry: 226 reentry:
227 white2gray(o); 227 white2gray(o);
228 switch (gch(o)->tt) { 228 switch (o->tt) {
229 case LUA_TSHRSTR: 229 case LUA_TSHRSTR:
230 case LUA_TLNGSTR: { 230 case LUA_TLNGSTR: {
231 gray2black(o); 231 gray2black(o);
@@ -288,7 +288,7 @@ static void markmt (global_State *g) {
288*/ 288*/
289static void markbeingfnz (global_State *g) { 289static void markbeingfnz (global_State *g) {
290 GCObject *o; 290 GCObject *o;
291 for (o = g->tobefnz; o != NULL; o = gch(o)->next) 291 for (o = g->tobefnz; o != NULL; o = o->next)
292 markobject(g, o); 292 markobject(g, o);
293} 293}
294 294
@@ -528,7 +528,7 @@ static void propagatemark (global_State *g) {
528 GCObject *o = g->gray; 528 GCObject *o = g->gray;
529 lua_assert(isgray(o)); 529 lua_assert(isgray(o));
530 gray2black(o); 530 gray2black(o);
531 switch (gch(o)->tt) { 531 switch (o->tt) {
532 case LUA_TTABLE: { 532 case LUA_TTABLE: {
533 Table *h = gco2t(o); 533 Table *h = gco2t(o);
534 g->gray = h->gclist; /* remove from 'gray' list */ 534 g->gray = h->gclist; /* remove from 'gray' list */
@@ -685,7 +685,7 @@ static void freeLclosure (lua_State *L, LClosure *cl) {
685 685
686 686
687static void freeobj (lua_State *L, GCObject *o) { 687static void freeobj (lua_State *L, GCObject *o) {
688 switch (gch(o)->tt) { 688 switch (o->tt) {
689 case LUA_TPROTO: luaF_freeproto(L, gco2p(o)); break; 689 case LUA_TPROTO: luaF_freeproto(L, gco2p(o)); break;
690 case LUA_TLCL: { 690 case LUA_TLCL: {
691 freeLclosure(L, gco2lcl(o)); 691 freeLclosure(L, gco2lcl(o));
@@ -727,14 +727,14 @@ static GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count) {
727 int white = luaC_white(g); /* current white */ 727 int white = luaC_white(g); /* current white */
728 while (*p != NULL && count-- > 0) { 728 while (*p != NULL && count-- > 0) {
729 GCObject *curr = *p; 729 GCObject *curr = *p;
730 int marked = gch(curr)->marked; 730 int marked = curr->marked;
731 if (isdeadm(ow, marked)) { /* is 'curr' dead? */ 731 if (isdeadm(ow, marked)) { /* is 'curr' dead? */
732 *p = gch(curr)->next; /* remove 'curr' from list */ 732 *p = curr->next; /* remove 'curr' from list */
733 freeobj(L, curr); /* erase 'curr' */ 733 freeobj(L, curr); /* erase 'curr' */
734 } 734 }
735 else { /* update marks */ 735 else { /* update marks */
736 gch(curr)->marked = cast_byte((marked & maskcolors) | white); 736 curr->marked = cast_byte((marked & maskcolors) | white);
737 p = &gch(curr)->next; /* go to next element */ 737 p = &curr->next; /* go to next element */
738 } 738 }
739 } 739 }
740 return (*p == NULL) ? NULL : p; 740 return (*p == NULL) ? NULL : p;
@@ -781,10 +781,10 @@ static void checkSizes (lua_State *L, global_State *g) {
781static GCObject *udata2finalize (global_State *g) { 781static GCObject *udata2finalize (global_State *g) {
782 GCObject *o = g->tobefnz; /* get first element */ 782 GCObject *o = g->tobefnz; /* get first element */
783 lua_assert(tofinalize(o)); 783 lua_assert(tofinalize(o));
784 g->tobefnz = gch(o)->next; /* remove it from 'tobefnz' list */ 784 g->tobefnz = o->next; /* remove it from 'tobefnz' list */
785 gch(o)->next = g->allgc; /* return it to 'allgc' list */ 785 o->next = g->allgc; /* return it to 'allgc' list */
786 g->allgc = o; 786 g->allgc = o;
787 resetbit(gch(o)->marked, FINALIZEDBIT); /* object is "normal" again */ 787 resetbit(o->marked, FINALIZEDBIT); /* object is "normal" again */
788 if (issweepphase(g)) 788 if (issweepphase(g))
789 makewhite(g, o); /* "sweep" object */ 789 makewhite(g, o); /* "sweep" object */
790 return o; 790 return o;
@@ -859,7 +859,7 @@ static void callallpendingfinalizers (lua_State *L, int propagateerrors) {
859*/ 859*/
860static GCObject **findlast (GCObject **p) { 860static GCObject **findlast (GCObject **p) {
861 while (*p != NULL) 861 while (*p != NULL)
862 p = &gch(*p)->next; 862 p = &(*p)->next;
863 return p; 863 return p;
864} 864}
865 865
@@ -875,12 +875,12 @@ static void separatetobefnz (global_State *g, int all) {
875 while ((curr = *p) != NULL) { /* traverse all finalizable objects */ 875 while ((curr = *p) != NULL) { /* traverse all finalizable objects */
876 lua_assert(tofinalize(curr)); 876 lua_assert(tofinalize(curr));
877 if (!(iswhite(curr) || all)) /* not being collected? */ 877 if (!(iswhite(curr) || all)) /* not being collected? */
878 p = &gch(curr)->next; /* don't bother with it */ 878 p = &curr->next; /* don't bother with it */
879 else { 879 else {
880 *p = gch(curr)->next; /* remove 'curr' from "fin" list */ 880 *p = curr->next; /* remove 'curr' from "fin" list */
881 gch(curr)->next = *lastnext; /* link at the end of 'tobefnz' list */ 881 curr->next = *lastnext; /* link at the end of 'tobefnz' list */
882 *lastnext = curr; 882 *lastnext = curr;
883 lastnext = &gch(curr)->next; 883 lastnext = &curr->next;
884 } 884 }
885 } 885 }
886} 886}
@@ -899,15 +899,15 @@ void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) {
899 GCObject **p; 899 GCObject **p;
900 if (issweepphase(g)) { 900 if (issweepphase(g)) {
901 makewhite(g, o); /* "sweep" object 'o' */ 901 makewhite(g, o); /* "sweep" object 'o' */
902 if (g->sweepgc == &o->gch.next) /* should not remove 'sweepgc' object */ 902 if (g->sweepgc == &o->next) /* should not remove 'sweepgc' object */
903 g->sweepgc = sweeptolive(L, g->sweepgc, NULL); /* change 'sweepgc' */ 903 g->sweepgc = sweeptolive(L, g->sweepgc, NULL); /* change 'sweepgc' */
904 } 904 }
905 /* search for pointer pointing to 'o' */ 905 /* search for pointer pointing to 'o' */
906 for (p = &g->allgc; *p != o; p = &gch(*p)->next) { /* empty */ } 906 for (p = &g->allgc; *p != o; p = &(*p)->next) { /* empty */ }
907 *p = o->gch.next; /* remove 'o' from 'allgc' list */ 907 *p = o->next; /* remove 'o' from 'allgc' list */
908 o->gch.next = g->finobj; /* link it in "fin" list */ 908 o->next = g->finobj; /* link it in "fin" list */
909 g->finobj = o; 909 g->finobj = o;
910 l_setbit(o->gch.marked, FINALIZEDBIT); /* mark it as such */ 910 l_setbit(o->marked, FINALIZEDBIT); /* mark it as such */
911 } 911 }
912} 912}
913 913