diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-04-20 17:15:30 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-04-20 17:15:30 -0300 |
commit | 4aaf0ef75c7b8f617f31a2c3794e97dee899dc08 (patch) | |
tree | 1a40369dc7735cc413eb20696ee1805596424d78 | |
parent | ed720d09f37e642ba27603e8f2c8d2b68c39b84a (diff) | |
download | lua-4aaf0ef75c7b8f617f31a2c3794e97dee899dc08.tar.gz lua-4aaf0ef75c7b8f617f31a2c3794e97dee899dc08.tar.bz2 lua-4aaf0ef75c7b8f617f31a2c3794e97dee899dc08.zip |
"to-be-finalized" objects marked and sweeped like all other objects
-rw-r--r-- | lgc.c | 26 |
1 files changed, 13 insertions, 13 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 2.77 2010/04/05 14:15:35 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 2.78 2010/04/12 16:07:06 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 | */ |
@@ -222,8 +222,7 @@ static void markbeingfnz (global_State *g) { | |||
222 | GCObject *o; | 222 | GCObject *o; |
223 | for (o = g->tobefnz; o != NULL; o = gch(o)->next) { | 223 | for (o = g->tobefnz; o != NULL; o = gch(o)->next) { |
224 | lua_assert(testbit(gch(o)->marked, SEPARATED)); | 224 | lua_assert(testbit(gch(o)->marked, SEPARATED)); |
225 | makewhite(g, o); | 225 | markobject(g, o); |
226 | reallymarkobject(g, o); | ||
227 | } | 226 | } |
228 | } | 227 | } |
229 | 228 | ||
@@ -619,7 +618,6 @@ static Udata *udata2finalize (global_State *g) { | |||
619 | g->allgc = o; | 618 | g->allgc = o; |
620 | lua_assert(isfinalized(gch(o))); | 619 | lua_assert(isfinalized(gch(o))); |
621 | resetbit(gch(o)->marked, SEPARATED); /* mark it as such */ | 620 | resetbit(gch(o)->marked, SEPARATED); /* mark it as such */ |
622 | makewhite(g, o); | ||
623 | return rawgco2u(o); | 621 | return rawgco2u(o); |
624 | } | 622 | } |
625 | 623 | ||
@@ -634,15 +632,15 @@ static void GCTM (lua_State *L, int propagateerrors) { | |||
634 | global_State *g = G(L); | 632 | global_State *g = G(L); |
635 | Udata *udata = udata2finalize(g); | 633 | Udata *udata = udata2finalize(g); |
636 | const TValue *tm = gfasttm(g, udata->uv.metatable, TM_GC); | 634 | const TValue *tm = gfasttm(g, udata->uv.metatable, TM_GC); |
637 | if (tm != NULL && ttisfunction(tm)) { | 635 | if (tm != NULL && ttisfunction(tm)) { /* is there a finalizer? */ |
638 | int status; | 636 | int status; |
639 | lu_byte oldah = L->allowhook; | 637 | lu_byte oldah = L->allowhook; |
640 | lu_mem oldt = g->GCthreshold; | 638 | lu_mem oldt = g->GCthreshold; |
641 | L->allowhook = 0; /* stop debug hooks during GC tag method */ | 639 | L->allowhook = 0; /* stop debug hooks during GC tag method */ |
642 | g->GCthreshold = 2*g->totalbytes; /* avoid GC steps */ | 640 | g->GCthreshold = 2 * g->totalbytes; /* avoid GC steps */ |
643 | setobj2s(L, L->top, tm); | 641 | setobj2s(L, L->top, tm); /* push finalizer... */ |
644 | setuvalue(L, L->top+1, udata); | 642 | setuvalue(L, L->top+1, udata); /* ... and its argument */ |
645 | L->top += 2; | 643 | L->top += 2; /* and (next line) call the finalizer */ |
646 | status = luaD_pcall(L, dothecall, NULL, savestack(L, L->top - 2), 0); | 644 | status = luaD_pcall(L, dothecall, NULL, savestack(L, L->top - 2), 0); |
647 | L->allowhook = oldah; /* restore hooks */ | 645 | L->allowhook = oldah; /* restore hooks */ |
648 | g->GCthreshold = oldt; /* restore threshold */ | 646 | g->GCthreshold = oldt; /* restore threshold */ |
@@ -776,22 +774,24 @@ static l_mem singlestep (lua_State *L) { | |||
776 | case GCSsweepstring: { | 774 | case GCSsweepstring: { |
777 | if (g->sweepstrgc < g->strt.size) { | 775 | if (g->sweepstrgc < g->strt.size) { |
778 | sweepwholelist(L, &g->strt.hash[g->sweepstrgc++]); | 776 | sweepwholelist(L, &g->strt.hash[g->sweepstrgc++]); |
777 | return GCSWEEPCOST; | ||
779 | } | 778 | } |
780 | else { /* no more strings to sweep */ | 779 | else { /* no more strings to sweep */ |
781 | g->sweepgc = &g->udgc; /* prepare to sweep userdata */ | 780 | g->sweepgc = &g->udgc; /* prepare to sweep userdata */ |
782 | g->gcstate = GCSsweepudata; | 781 | g->gcstate = GCSsweepudata; |
782 | return 0; | ||
783 | } | 783 | } |
784 | return GCSWEEPCOST; | ||
785 | } | 784 | } |
786 | case GCSsweepudata: { | 785 | case GCSsweepudata: { |
787 | if (*g->sweepgc) { | 786 | if (*g->sweepgc) { |
788 | g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX); | 787 | g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX); |
789 | return GCSWEEPMAX*GCSWEEPCOST; | 788 | return GCSWEEPMAX*GCSWEEPCOST; |
790 | } | 789 | } |
791 | else { /* go to next phase */ | 790 | else { |
792 | g->sweepgc = &g->allgc; | 791 | sweepwholelist(L, &g->tobefnz); /* sweep 'to-be-finalized' list */ |
792 | g->sweepgc = &g->allgc; /* go to next phase */ | ||
793 | g->gcstate = GCSsweep; | 793 | g->gcstate = GCSsweep; |
794 | return 0; | 794 | return GCSWEEPCOST; |
795 | } | 795 | } |
796 | } | 796 | } |
797 | case GCSsweep: { | 797 | case GCSsweep: { |