summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lapi.c7
-rw-r--r--lbaselib.c8
-rw-r--r--lgc.c46
-rw-r--r--lstate.c7
-rw-r--r--lstate.h3
-rw-r--r--lua.h5
6 files changed, 41 insertions, 35 deletions
diff --git a/lapi.c b/lapi.c
index 1dacf222..46af4ce0 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.188 2013/08/27 18:53:35 roberto Exp roberto $ 2** $Id: lapi.c,v 2.189 2013/09/11 20:15:31 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -1086,6 +1086,11 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
1086 g->gcpause = data; 1086 g->gcpause = data;
1087 break; 1087 break;
1088 } 1088 }
1089 case LUA_GCSETLOCALPAUSE: {
1090 res = g->gclocalpause;
1091 g->gclocalpause = data;
1092 break;
1093 }
1089 case LUA_GCSETSTEPMUL: { 1094 case LUA_GCSETSTEPMUL: {
1090 res = g->gcstepmul; 1095 res = g->gcstepmul;
1091 g->gcstepmul = data; 1096 g->gcstepmul = data;
diff --git a/lbaselib.c b/lbaselib.c
index 63e9820b..9e3c5c87 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbaselib.c,v 1.280 2013/07/10 17:15:12 roberto Exp roberto $ 2** $Id: lbaselib.c,v 1.281 2013/08/05 16:58:28 roberto Exp roberto $
3** Basic library 3** Basic library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -174,9 +174,11 @@ static int luaB_rawset (lua_State *L) {
174 174
175static int luaB_collectgarbage (lua_State *L) { 175static int luaB_collectgarbage (lua_State *L) {
176 static const char *const opts[] = {"stop", "restart", "collect", 176 static const char *const opts[] = {"stop", "restart", "collect",
177 "count", "step", "setpause", "setstepmul", "isrunning", NULL}; 177 "count", "step", "setpause", "setstepmul",
178 "setlocalpause", "isrunning", NULL};
178 static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT, 179 static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT,
179 LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL, LUA_GCISRUNNING}; 180 LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL,
181 LUA_GCSETLOCALPAUSE, LUA_GCISRUNNING};
180 int o = optsnum[luaL_checkoption(L, 1, "collect", opts)]; 182 int o = optsnum[luaL_checkoption(L, 1, "collect", opts)];
181 int ex = luaL_optint(L, 2, 0); 183 int ex = luaL_optint(L, 2, 0);
182 int res = lua_gc(L, o, ex); 184 int res = lua_gc(L, o, ex);
diff --git a/lgc.c b/lgc.c
index 62e3777f..1f620345 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 2.163 2013/09/11 14:47:08 roberto Exp roberto $ 2** $Id: lgc.c,v 2.164 2013/09/11 14:56:15 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*/
@@ -25,12 +25,6 @@
25 25
26 26
27/* 27/*
28** How much memory to allocate before a new local collection
29*/
30#define GCLOCALPAUSE 8000
31
32
33/*
34** cost of sweeping one element (the size of a small object divided 28** cost of sweeping one element (the size of a small object divided
35** by some adjust for the sweep speed) 29** by some adjust for the sweep speed)
36*/ 30*/
@@ -149,7 +143,7 @@ void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v) {
149 global_State *g = G(L); 143 global_State *g = G(L);
150 lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o)); 144 lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o));
151 lua_assert(g->gcstate != GCSpause); 145 lua_assert(g->gcstate != GCSpause);
152 lua_assert(gch(o)->tt != LUA_TTABLE); 146 lua_assert(gch(o)->tt != LUA_TTABLE); /* tables use a back barrier */
153 if (keepinvariant(g)) /* must keep invariant? */ 147 if (keepinvariant(g)) /* must keep invariant? */
154 reallymarkobject(g, v); /* restore invariant */ 148 reallymarkobject(g, v); /* restore invariant */
155 else { /* sweep phase */ 149 else { /* sweep phase */
@@ -888,19 +882,18 @@ void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) {
888 return; /* nothing to be done */ 882 return; /* nothing to be done */
889 else { /* move 'o' to 'finobj' list */ 883 else { /* move 'o' to 'finobj' list */
890 GCObject **p; 884 GCObject **p;
891 GCheader *ho = gch(o); 885 if (g->sweepgc == &o->gch.next) { /* avoid removing current sweep object */
892 if (g->sweepgc == &ho->next) { /* avoid removing current sweep object */
893 lua_assert(issweepphase(g)); 886 lua_assert(issweepphase(g));
894 g->sweepgc = sweeptolive(L, g->sweepgc, NULL); 887 g->sweepgc = sweeptolive(L, g->sweepgc, NULL);
895 } 888 }
896 /* search for pointer pointing to 'o' */ 889 /* search for pointer pointing to 'o' */
897 p = (testbit(ho->marked, LOCALMARK)) ? &g->allgc : &g->localgc; 890 p = (testbit(o->gch.marked, LOCALMARK)) ? &g->allgc : &g->localgc;
898 for (; *p != o; p = &gch(*p)->next) { /* empty */ } 891 for (; *p != o; p = &gch(*p)->next) { /* empty */ }
899 *p = ho->next; /* remove 'o' from its list */ 892 *p = o->gch.next; /* remove 'o' from its list */
900 p = (testbit(ho->marked, LOCALMARK)) ? &g->finobj : &g->localfin; 893 p = (testbit(o->gch.marked, LOCALMARK)) ? &g->finobj : &g->localfin;
901 ho->next = *p; /* link it in a "fin" list */ 894 o->gch.next = *p; /* link it in a "fin" list */
902 *p = o; 895 *p = o;
903 l_setbit(ho->marked, FINALIZEDBIT); /* mark it as such */ 896 l_setbit(o->gch.marked, FINALIZEDBIT); /* mark it as such */
904 if (issweepphase(g)) 897 if (issweepphase(g))
905 makewhite(g, o); /* "sweep" object */ 898 makewhite(g, o); /* "sweep" object */
906 } 899 }
@@ -1032,7 +1025,7 @@ static void setpause (global_State *g, l_mem estimate) {
1032 ? estimate * g->gcpause /* no overflow */ 1025 ? estimate * g->gcpause /* no overflow */
1033 : MAX_LMEM; /* overflow; truncate to maximum */ 1026 : MAX_LMEM; /* overflow; truncate to maximum */
1034 g->GCthreshold = threshold; 1027 g->GCthreshold = threshold;
1035 luaE_setdebt(g, -GCLOCALPAUSE); 1028 luaE_setdebt(g, -g->gclocalpause);
1036} 1029}
1037 1030
1038 1031
@@ -1050,8 +1043,6 @@ static int entersweep (lua_State *L) {
1050 g->gcstate = GCSswplocalgc; 1043 g->gcstate = GCSswplocalgc;
1051 lua_assert(g->sweepgc == NULL); 1044 lua_assert(g->sweepgc == NULL);
1052 g->sweepgc = sweeptolive(L, &g->localgc, &n); 1045 g->sweepgc = sweeptolive(L, &g->localgc, &n);
1053 if (g->sweepgc == NULL) /* no live objects in local list? */
1054 g->sweepgc = &g->localgc; /* 'sweepgc' cannot be NULL here */
1055 return n; 1046 return n;
1056} 1047}
1057 1048
@@ -1099,7 +1090,7 @@ static l_mem atomic (lua_State *L) {
1099 work += g->GCmemtrav; /* stop counting (objects being finalized) */ 1090 work += g->GCmemtrav; /* stop counting (objects being finalized) */
1100 separatetobefnz(g, 0); /* separate objects to be finalized */ 1091 separatetobefnz(g, 0); /* separate objects to be finalized */
1101 markbeingfnz(g); /* mark objects that will be finalized */ 1092 markbeingfnz(g); /* mark objects that will be finalized */
1102 propagateall(g); /* remark, to propagate `preserveness' */ 1093 propagateall(g); /* remark, to propagate 'resurrection' */
1103 work -= g->GCmemtrav; /* restart counting */ 1094 work -= g->GCmemtrav; /* restart counting */
1104 convergeephemerons(g); 1095 convergeephemerons(g);
1105 /* at this point, all resurrected objects are marked. */ 1096 /* at this point, all resurrected objects are marked. */
@@ -1117,14 +1108,15 @@ static l_mem atomic (lua_State *L) {
1117 1108
1118static lu_mem sweepstep (lua_State *L, global_State *g, 1109static lu_mem sweepstep (lua_State *L, global_State *g,
1119 int nextstate, GCObject **nextlist) { 1110 int nextstate, GCObject **nextlist) {
1120 g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX); 1111 if (g->sweepgc) {
1121 if (g->sweepgc) /* is there still something to sweep? */ 1112 g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX);
1122 return (GCSWEEPMAX * GCSWEEPCOST); 1113 if (g->sweepgc) /* is there still something to sweep? */
1123 else { /* enter next state */ 1114 return (GCSWEEPMAX * GCSWEEPCOST);
1124 g->gcstate = nextstate;
1125 g->sweepgc = nextlist;
1126 return 0;
1127 } 1115 }
1116 /* else enter next state */
1117 g->gcstate = nextstate;
1118 g->sweepgc = nextlist;
1119 return 0;
1128} 1120}
1129 1121
1130 1122
@@ -1245,7 +1237,7 @@ void luaC_step (lua_State *L) {
1245 luaC_forcestep(L); /* restart collection */ 1237 luaC_forcestep(L); /* restart collection */
1246 } 1238 }
1247 else 1239 else
1248 luaE_setdebt(g, -GCLOCALPAUSE); 1240 luaE_setdebt(g, -g->gclocalpause);
1249 } 1241 }
1250 } 1242 }
1251 else luaE_setdebt(g, -GCSTEPSIZE); /* avoid being called too often */ 1243 else luaE_setdebt(g, -GCSTEPSIZE); /* avoid being called too often */
diff --git a/lstate.c b/lstate.c
index f9d857fb..0c3eb8f1 100644
--- a/lstate.c
+++ b/lstate.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.c,v 2.112 2013/09/11 12:26:14 roberto Exp roberto $ 2** $Id: lstate.c,v 2.113 2013/09/11 14:09:55 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*/
@@ -30,6 +30,10 @@
30#define LUAI_GCPAUSE 200 /* 200% */ 30#define LUAI_GCPAUSE 200 /* 200% */
31#endif 31#endif
32 32
33#if !defined(LUAI_GCLOCALPAUSE)
34#define LUAI_GCLOCALPAUSE (1000 * sizeof(TString))
35#endif
36
33#if !defined(LUAI_GCMUL) 37#if !defined(LUAI_GCMUL)
34#define LUAI_GCMUL 200 /* GC runs 'twice the speed' of memory allocation */ 38#define LUAI_GCMUL 200 /* GC runs 'twice the speed' of memory allocation */
35#endif 39#endif
@@ -301,6 +305,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
301 g->totalbytes = sizeof(LG); 305 g->totalbytes = sizeof(LG);
302 g->GCdebt = 0; 306 g->GCdebt = 0;
303 g->gcpause = LUAI_GCPAUSE; 307 g->gcpause = LUAI_GCPAUSE;
308 g->gclocalpause = LUAI_GCLOCALPAUSE;
304 g->gcstepmul = LUAI_GCMUL; 309 g->gcstepmul = LUAI_GCMUL;
305 for (i=0; i < LUA_NUMTAGS; i++) g->mt[i] = NULL; 310 for (i=0; i < LUA_NUMTAGS; i++) g->mt[i] = NULL;
306 if (luaD_rawrunprotected(L, f_luaopen, NULL) != LUA_OK) { 311 if (luaD_rawrunprotected(L, f_luaopen, NULL) != LUA_OK) {
diff --git a/lstate.h b/lstate.h
index fc8f775d..f886f3e3 100644
--- a/lstate.h
+++ b/lstate.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.h,v 2.94 2013/09/05 19:31:49 roberto Exp roberto $ 2** $Id: lstate.h,v 2.95 2013/09/11 14:09:55 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*/
@@ -131,6 +131,7 @@ typedef struct global_State {
131 GCObject *fixedgc; /* list of objects not to be collected */ 131 GCObject *fixedgc; /* list of objects not to be collected */
132 Mbuffer buff; /* temporary buffer for string concatenation */ 132 Mbuffer buff; /* temporary buffer for string concatenation */
133 int gcpause; /* size of pause between successive GCs */ 133 int gcpause; /* size of pause between successive GCs */
134 int gclocalpause; /* size of pause between local collections */
134 int gcstepmul; /* GC `granularity' */ 135 int gcstepmul; /* GC `granularity' */
135 lua_CFunction panic; /* to be called in unprotected errors */ 136 lua_CFunction panic; /* to be called in unprotected errors */
136 struct lua_State *mainthread; 137 struct lua_State *mainthread;
diff --git a/lua.h b/lua.h
index b316d11b..93ba9b0b 100644
--- a/lua.h
+++ b/lua.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.h,v 1.292 2013/07/05 14:29:51 roberto Exp roberto $ 2** $Id: lua.h,v 1.293 2013/08/05 16:58:28 roberto Exp roberto $
3** Lua - A Scripting Language 3** Lua - A Scripting Language
4** Lua.org, PUC-Rio, Brazil (http://www.lua.org) 4** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
5** See Copyright Notice at the end of this file 5** See Copyright Notice at the end of this file
@@ -288,7 +288,8 @@ LUA_API int (lua_status) (lua_State *L);
288#define LUA_GCSTEP 5 288#define LUA_GCSTEP 5
289#define LUA_GCSETPAUSE 6 289#define LUA_GCSETPAUSE 6
290#define LUA_GCSETSTEPMUL 7 290#define LUA_GCSETSTEPMUL 7
291#define LUA_GCISRUNNING 8 291#define LUA_GCSETLOCALPAUSE 8
292#define LUA_GCISRUNNING 9
292 293
293LUA_API int (lua_gc) (lua_State *L, int what, int data); 294LUA_API int (lua_gc) (lua_State *L, int what, int data);
294 295