aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lgc.c68
-rw-r--r--lgc.h12
-rw-r--r--lstate.c4
-rw-r--r--lstate.h5
-rw-r--r--ltests.c5
5 files changed, 48 insertions, 46 deletions
diff --git a/lgc.c b/lgc.c
index 8d273d44..aaa57a07 100644
--- a/lgc.c
+++ b/lgc.c
@@ -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) {
993static int entersweep (lua_State *L) { 990static 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
1066static 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
1071static lu_mem singlestep (lua_State *L) { 1080static 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 }
diff --git a/lgc.h b/lgc.h
index 978c7aca..db309360 100644
--- a/lgc.h
+++ b/lgc.h
@@ -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/*
diff --git a/lstate.c b/lstate.c
index 1fe59cd3..842f6a42 100644
--- a/lstate.c
+++ b/lstate.c
@@ -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);
diff --git a/lstate.h b/lstate.h
index e0aed2d9..e03b75f2 100644
--- a/lstate.h
+++ b/lstate.h
@@ -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 */
diff --git a/ltests.c b/ltests.c
index aa247aa6..ec7631e7 100644
--- a/ltests.c
+++ b/ltests.c
@@ -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
654static int gc_state (lua_State *L) { 654static 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]);