diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-08-20 14:46:34 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-08-20 14:46:34 -0300 |
commit | 8f6b80aa1da8b07b944738ece7eb1348b360df49 (patch) | |
tree | a3ceb752923fcc1dd2b2fdf3911a84cd232496a6 /lgc.c | |
parent | 9eff921f8fe689794308cdb3fa7bb214604f75d3 (diff) | |
download | lua-8f6b80aa1da8b07b944738ece7eb1348b360df49.tar.gz lua-8f6b80aa1da8b07b944738ece7eb1348b360df49.tar.bz2 lua-8f6b80aa1da8b07b944738ece7eb1348b360df49.zip |
GC bits SEPARATED and FINALIZEDBIT mixed in FINALIZEDBIT (with simpler
control)
Diffstat (limited to 'lgc.c')
-rw-r--r-- | lgc.c | 19 |
1 files changed, 7 insertions, 12 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 2.146 2013/08/16 18:55:49 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 2.147 2013/08/19 14:18:43 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 | */ |
@@ -65,8 +65,6 @@ | |||
65 | 65 | ||
66 | #define valiswhite(x) (iscollectable(x) && iswhite(gcvalue(x))) | 66 | #define valiswhite(x) (iscollectable(x) && iswhite(gcvalue(x))) |
67 | 67 | ||
68 | #define isfinalized(x) testbit(gch(x)->marked, FINALIZEDBIT) | ||
69 | |||
70 | #define checkdeadkey(n) lua_assert(!ttisdeadkey(gkey(n)) || ttisnil(gval(n))) | 68 | #define checkdeadkey(n) lua_assert(!ttisdeadkey(gkey(n)) || ttisnil(gval(n))) |
71 | 69 | ||
72 | 70 | ||
@@ -764,11 +762,11 @@ static void checkSizes (lua_State *L) { | |||
764 | 762 | ||
765 | static GCObject *udata2finalize (global_State *g) { | 763 | static GCObject *udata2finalize (global_State *g) { |
766 | GCObject *o = g->tobefnz; /* get first element */ | 764 | GCObject *o = g->tobefnz; /* get first element */ |
767 | lua_assert(isfinalized(o)); | 765 | lua_assert(tofinalize(o)); |
768 | g->tobefnz = gch(o)->next; /* remove it from 'tobefnz' list */ | 766 | g->tobefnz = gch(o)->next; /* remove it from 'tobefnz' list */ |
769 | gch(o)->next = g->allgc; /* return it to 'allgc' list */ | 767 | gch(o)->next = g->allgc; /* return it to 'allgc' list */ |
770 | g->allgc = o; | 768 | g->allgc = o; |
771 | resetbit(gch(o)->marked, SEPARATED); /* mark that it is not in 'tobefnz' */ | 769 | resetbit(gch(o)->marked, FINALIZEDBIT); /* object is back in 'allgc' */ |
772 | if (!keepinvariant(g)) /* not keeping invariant? */ | 770 | if (!keepinvariant(g)) /* not keeping invariant? */ |
773 | makewhite(g, o); /* "sweep" object */ | 771 | makewhite(g, o); /* "sweep" object */ |
774 | return o; | 772 | return o; |
@@ -826,12 +824,10 @@ static void separatetobefnz (lua_State *L, int all) { | |||
826 | while (*lastnext != NULL) | 824 | while (*lastnext != NULL) |
827 | lastnext = &gch(*lastnext)->next; | 825 | lastnext = &gch(*lastnext)->next; |
828 | while ((curr = *p) != NULL) { /* traverse all finalizable objects */ | 826 | while ((curr = *p) != NULL) { /* traverse all finalizable objects */ |
829 | lua_assert(!isfinalized(curr)); | 827 | lua_assert(tofinalize(curr)); |
830 | lua_assert(testbit(gch(curr)->marked, SEPARATED)); | ||
831 | if (!(iswhite(curr) || all)) /* not being collected? */ | 828 | if (!(iswhite(curr) || all)) /* not being collected? */ |
832 | p = &gch(curr)->next; /* don't bother with it */ | 829 | p = &gch(curr)->next; /* don't bother with it */ |
833 | else { | 830 | else { |
834 | l_setbit(gch(curr)->marked, FINALIZEDBIT); /* won't be finalized again */ | ||
835 | *p = gch(curr)->next; /* remove 'curr' from 'finobj' list */ | 831 | *p = gch(curr)->next; /* remove 'curr' from 'finobj' list */ |
836 | gch(curr)->next = *lastnext; /* link at the end of 'tobefnz' list */ | 832 | gch(curr)->next = *lastnext; /* link at the end of 'tobefnz' list */ |
837 | *lastnext = curr; | 833 | *lastnext = curr; |
@@ -847,9 +843,8 @@ static void separatetobefnz (lua_State *L, int all) { | |||
847 | */ | 843 | */ |
848 | void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) { | 844 | void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) { |
849 | global_State *g = G(L); | 845 | global_State *g = G(L); |
850 | if (testbit(gch(o)->marked, SEPARATED) || /* obj. is already separated... */ | 846 | if (tofinalize(o) || /* obj. is already marked... */ |
851 | isfinalized(o) || /* ... or is finalized... */ | 847 | gfasttm(g, mt, TM_GC) == NULL) /* or has no finalizer? */ |
852 | gfasttm(g, mt, TM_GC) == NULL) /* or has no finalizer? */ | ||
853 | return; /* nothing to be done */ | 848 | return; /* nothing to be done */ |
854 | else { /* move 'o' to 'finobj' list */ | 849 | else { /* move 'o' to 'finobj' list */ |
855 | GCObject **p; | 850 | GCObject **p; |
@@ -863,7 +858,7 @@ void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) { | |||
863 | *p = ho->next; /* remove 'o' from root list */ | 858 | *p = ho->next; /* remove 'o' from root list */ |
864 | ho->next = g->finobj; /* link it in list 'finobj' */ | 859 | ho->next = g->finobj; /* link it in list 'finobj' */ |
865 | g->finobj = o; | 860 | g->finobj = o; |
866 | l_setbit(ho->marked, SEPARATED); /* mark it as such */ | 861 | l_setbit(ho->marked, FINALIZEDBIT); /* mark it as such */ |
867 | if (!keepinvariant(g)) /* not keeping invariant? */ | 862 | if (!keepinvariant(g)) /* not keeping invariant? */ |
868 | makewhite(g, o); /* "sweep" object */ | 863 | makewhite(g, o); /* "sweep" object */ |
869 | } | 864 | } |