diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-08-30 16:14:26 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-08-30 16:14:26 -0300 |
commit | 1bf4faec64aca03e1036235e72675f0617124140 (patch) | |
tree | dca4218f3085090a27c288ccd11aaf1bdb520905 | |
parent | 8ef9e8460e775793f760deb28d0c3d10dda31b49 (diff) | |
download | lua-1bf4faec64aca03e1036235e72675f0617124140.tar.gz lua-1bf4faec64aca03e1036235e72675f0617124140.tar.bz2 lua-1bf4faec64aca03e1036235e72675f0617124140.zip |
new GC state to sweep 'localgc' list + small changes in sweep control
-rw-r--r-- | lgc.c | 68 | ||||
-rw-r--r-- | lgc.h | 12 | ||||
-rw-r--r-- | lstate.c | 4 | ||||
-rw-r--r-- | lstate.h | 5 | ||||
-rw-r--r-- | ltests.c | 5 |
5 files changed, 48 insertions, 46 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 2.155 2013/08/28 18:30:26 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 2.156 2013/08/29 13:34:16 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 | */ |
@@ -979,12 +979,9 @@ static void setpause (global_State *g, l_mem estimate) { | |||
979 | } | 979 | } |
980 | 980 | ||
981 | 981 | ||
982 | #define sweepphases (bitmask(GCSsweepudata) | bitmask(GCSsweep)) | ||
983 | |||
984 | |||
985 | /* | 982 | /* |
986 | ** enter first sweep phase and prepare pointers for other sweep phases. | 983 | ** Enter first sweep phase. |
987 | ** The calls to 'sweeptolive' make pointers point to an object inside | 984 | ** The call to 'sweeptolive' makes pointer point to an object inside |
988 | ** the list (instead of to the header), so that the real sweep do not | 985 | ** the list (instead of to the header), so that the real sweep do not |
989 | ** need to skip objects created between "now" and the start of the real | 986 | ** need to skip objects created between "now" and the start of the real |
990 | ** sweep. | 987 | ** sweep. |
@@ -993,11 +990,9 @@ static void setpause (global_State *g, l_mem estimate) { | |||
993 | static int entersweep (lua_State *L) { | 990 | static int entersweep (lua_State *L) { |
994 | global_State *g = G(L); | 991 | global_State *g = G(L); |
995 | int n = 0; | 992 | int n = 0; |
996 | g->gcstate = GCSsweepudata; | 993 | g->gcstate = GCSsweeplocal; |
997 | lua_assert(g->sweepgc == NULL && g->sweepfin == NULL); | 994 | lua_assert(g->sweepgc == NULL); |
998 | /* prepare to sweep finalizable objects and regular objects */ | 995 | g->sweepgc = sweeptolive(L, &g->localgc, &n); |
999 | g->sweepfin = sweeptolive(L, &g->finobj, &n); | ||
1000 | g->sweepgc = sweeptolive(L, &g->allgc, &n); | ||
1001 | return n; | 996 | return n; |
1002 | } | 997 | } |
1003 | 998 | ||
@@ -1068,6 +1063,20 @@ static l_mem atomic (lua_State *L) { | |||
1068 | } | 1063 | } |
1069 | 1064 | ||
1070 | 1065 | ||
1066 | static lu_mem sweepstep (lua_State *L, global_State *g, | ||
1067 | int nextstate, GCObject **nextlist) { | ||
1068 | if (g->sweepgc) { /* is there still something to sweep? */ | ||
1069 | g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX); | ||
1070 | return (GCSWEEPMAX * GCSWEEPCOST); | ||
1071 | } | ||
1072 | else { /* next phase */ | ||
1073 | g->gcstate = nextstate; | ||
1074 | g->sweepgc = nextlist; | ||
1075 | return 0; | ||
1076 | } | ||
1077 | } | ||
1078 | |||
1079 | |||
1071 | static lu_mem singlestep (lua_State *L) { | 1080 | static lu_mem singlestep (lua_State *L) { |
1072 | global_State *g = G(L); | 1081 | global_State *g = G(L); |
1073 | switch (g->gcstate) { | 1082 | switch (g->gcstate) { |
@@ -1096,30 +1105,21 @@ static lu_mem singlestep (lua_State *L) { | |||
1096 | sw = entersweep(L); | 1105 | sw = entersweep(L); |
1097 | return work + sw * GCSWEEPCOST; | 1106 | return work + sw * GCSWEEPCOST; |
1098 | } | 1107 | } |
1099 | case GCSsweepudata: { | 1108 | case GCSsweeplocal: { |
1100 | if (g->sweepfin) { | 1109 | return sweepstep(L, g, GCSsweepfin, &g->finobj); |
1101 | g->sweepfin = sweeplist(L, g->sweepfin, GCSWEEPMAX); | ||
1102 | return GCSWEEPMAX*GCSWEEPCOST; | ||
1103 | } | ||
1104 | else { | ||
1105 | sweepwholelist(L, &g->localgc); | ||
1106 | g->gcstate = GCSsweep; | ||
1107 | return GCLOCALPAUSE / 4; /* some magic for now */ | ||
1108 | } | ||
1109 | } | 1110 | } |
1110 | case GCSsweep: { | 1111 | case GCSsweepfin: { |
1111 | if (g->sweepgc) { | 1112 | return sweepstep(L, g, GCSsweepall, &g->allgc); |
1112 | g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX); | 1113 | } |
1113 | return GCSWEEPMAX*GCSWEEPCOST; | 1114 | case GCSsweepall: { |
1114 | } | 1115 | return sweepstep(L, g, GCSsweepmainth, NULL); |
1115 | else { | 1116 | } |
1116 | /* sweep main thread */ | 1117 | case GCSsweepmainth: { /* sweep main thread */ |
1117 | GCObject *mt = obj2gco(g->mainthread); | 1118 | GCObject *mt = obj2gco(g->mainthread); |
1118 | sweeplist(L, &mt, 1); | 1119 | sweeplist(L, &mt, 1); |
1119 | checkBuffer(L); | 1120 | checkBuffer(L); |
1120 | g->gcstate = GCSpause; /* finish collection */ | 1121 | g->gcstate = GCSpause; /* finish collection */ |
1121 | return GCSWEEPCOST; | 1122 | return GCSWEEPCOST; |
1122 | } | ||
1123 | } | 1123 | } |
1124 | default: lua_assert(0); return 0; | 1124 | default: lua_assert(0); return 0; |
1125 | } | 1125 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.h,v 2.68 2013/08/27 20:04:00 roberto Exp roberto $ | 2 | ** $Id: lgc.h,v 2.69 2013/08/29 13:49:57 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 | */ |
@@ -38,13 +38,15 @@ | |||
38 | */ | 38 | */ |
39 | #define GCSpropagate 0 | 39 | #define GCSpropagate 0 |
40 | #define GCSatomic 1 | 40 | #define GCSatomic 1 |
41 | #define GCSsweepudata 2 | 41 | #define GCSsweeplocal 2 |
42 | #define GCSsweep 3 | 42 | #define GCSsweepfin 3 |
43 | #define GCSpause 4 | 43 | #define GCSsweepall 4 |
44 | #define GCSsweepmainth 5 | ||
45 | #define GCSpause 6 | ||
44 | 46 | ||
45 | 47 | ||
46 | #define issweepphase(g) \ | 48 | #define issweepphase(g) \ |
47 | (GCSsweepudata <= (g)->gcstate && (g)->gcstate <= GCSsweep) | 49 | (GCSsweeplocal <= (g)->gcstate && (g)->gcstate <= GCSsweepmainth) |
48 | 50 | ||
49 | 51 | ||
50 | /* | 52 | /* |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.c,v 2.107 2013/08/27 18:53:35 roberto Exp roberto $ | 2 | ** $Id: lstate.c,v 2.108 2013/08/28 18:30:26 roberto Exp roberto $ |
3 | ** Global State | 3 | ** Global State |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -301,7 +301,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { | |||
301 | g->finobj = NULL; | 301 | g->finobj = NULL; |
302 | g->tobefnz = NULL; | 302 | g->tobefnz = NULL; |
303 | g->fixedgc = NULL; | 303 | g->fixedgc = NULL; |
304 | g->sweepgc = g->sweepfin = NULL; | 304 | g->sweepgc = NULL; |
305 | g->gray = g->grayagain = NULL; | 305 | g->gray = g->grayagain = NULL; |
306 | g->weak = g->ephemeron = g->allweak = NULL; | 306 | g->weak = g->ephemeron = g->allweak = NULL; |
307 | g->totalbytes = sizeof(LG); | 307 | g->totalbytes = sizeof(LG); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.h,v 2.90 2013/08/26 12:41:10 roberto Exp roberto $ | 2 | ** $Id: lstate.h,v 2.91 2013/08/27 18:53:35 roberto Exp roberto $ |
3 | ** Global State | 3 | ** Global State |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -122,8 +122,7 @@ typedef struct global_State { | |||
122 | GCObject *allgc; /* list of all collectable objects */ | 122 | GCObject *allgc; /* list of all collectable objects */ |
123 | GCObject *localgc; /* list of local objects */ | 123 | GCObject *localgc; /* list of local objects */ |
124 | GCObject *finobj; /* list of collectable objects with finalizers */ | 124 | GCObject *finobj; /* list of collectable objects with finalizers */ |
125 | GCObject **sweepgc; /* current position of sweep in list 'allgc' */ | 125 | GCObject **sweepgc; /* current position of sweep in list */ |
126 | GCObject **sweepfin; /* current position of sweep in list 'finobj' */ | ||
127 | GCObject *gray; /* list of gray objects */ | 126 | GCObject *gray; /* list of gray objects */ |
128 | GCObject *grayagain; /* list of objects to be traversed atomically */ | 127 | GCObject *grayagain; /* list of objects to be traversed atomically */ |
129 | GCObject *weak; /* list of tables with weak values */ | 128 | GCObject *weak; /* list of tables with weak values */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 2.150 2013/08/27 18:53:35 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.151 2013/08/27 20:04:00 roberto Exp roberto $ |
3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -653,7 +653,8 @@ static int gc_local (lua_State *L) { | |||
653 | 653 | ||
654 | static int gc_state (lua_State *L) { | 654 | static int gc_state (lua_State *L) { |
655 | static const char *statenames[] = {"propagate", "atomic", | 655 | static const char *statenames[] = {"propagate", "atomic", |
656 | "sweepudata", "sweep", "pause", ""}; | 656 | "sweeplocal", "sweepfin", "sweepall", "sweepmainth", |
657 | "pause", ""}; | ||
657 | int option = luaL_checkoption(L, 1, "", statenames); | 658 | int option = luaL_checkoption(L, 1, "", statenames); |
658 | if (option == GCSpause + 1) { | 659 | if (option == GCSpause + 1) { |
659 | lua_pushstring(L, statenames[G(L)->gcstate]); | 660 | lua_pushstring(L, statenames[G(L)->gcstate]); |