aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lapi.c4
-rw-r--r--lgc.c23
-rw-r--r--lstate.c5
-rw-r--r--lstate.h6
-rw-r--r--ltests.c4
5 files changed, 21 insertions, 21 deletions
diff --git a/lapi.c b/lapi.c
index 29f3d265..2be52631 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.263 2017/04/19 17:02:50 roberto Exp roberto $ 2** $Id: lapi.c,v 2.264 2017/04/20 18:22:44 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*/
@@ -1111,7 +1111,7 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
1111 break; 1111 break;
1112 } 1112 }
1113 case LUA_GCINC: { 1113 case LUA_GCINC: {
1114 luaC_changemode(L, KGC_NORMAL); 1114 luaC_changemode(L, KGC_INC);
1115 break; 1115 break;
1116 } 1116 }
1117 default: res = -1; /* invalid option */ 1117 default: res = -1; /* invalid option */
diff --git a/lgc.c b/lgc.c
index 59b6dde1..d27ea42b 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 2.223 2017/04/19 17:02:50 roberto Exp roberto $ 2** $Id: lgc.c,v 2.224 2017/04/20 18:24:33 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*/
@@ -543,7 +543,7 @@ static lu_mem traversethread (global_State *g, lua_State *th) {
543 g->twups = th; 543 g->twups = th;
544 } 544 }
545 } 545 }
546 else if (g->gckind != KGC_EMERGENCY) 546 else if (!g->gcemergency)
547 luaD_shrinkstack(th); /* do not change stack in emergency cycle */ 547 luaD_shrinkstack(th); /* do not change stack in emergency cycle */
548 return (sizeof(lua_State) + sizeof(TValue) * th->stacksize + 548 return (sizeof(lua_State) + sizeof(TValue) * th->stacksize +
549 sizeof(CallInfo) * th->nci); 549 sizeof(CallInfo) * th->nci);
@@ -767,7 +767,7 @@ static GCObject **sweeptolive (lua_State *L, GCObject **p) {
767** If possible, shrink string table 767** If possible, shrink string table
768*/ 768*/
769static void checkSizes (lua_State *L, global_State *g) { 769static void checkSizes (lua_State *L, global_State *g) {
770 if (g->gckind != KGC_EMERGENCY) { 770 if (!g->gcemergency) {
771 l_mem olddebt = g->GCdebt; 771 l_mem olddebt = g->GCdebt;
772 if (g->strt.nuse < g->strt.size / 4) /* string table too big? */ 772 if (g->strt.nuse < g->strt.size / 4) /* string table too big? */
773 luaS_resize(L, g->strt.size / 2); /* shrink it a little */ 773 luaS_resize(L, g->strt.size / 2); /* shrink it a little */
@@ -1174,7 +1174,7 @@ static void enterinc (global_State *g) {
1174 g->finobjrold = g->finobjold = g->finobjsur = NULL; 1174 g->finobjrold = g->finobjold = g->finobjsur = NULL;
1175 lua_assert(g->tobefnz == NULL); /* no need to sweep */ 1175 lua_assert(g->tobefnz == NULL); /* no need to sweep */
1176 g->gcstate = GCSpause; 1176 g->gcstate = GCSpause;
1177 g->gckind = KGC_NORMAL; 1177 g->gckind = KGC_INC;
1178} 1178}
1179 1179
1180 1180
@@ -1278,7 +1278,7 @@ static void deletealllist (lua_State *L, GCObject *p, GCObject *limit) {
1278 1278
1279void luaC_freeallobjects (lua_State *L) { 1279void luaC_freeallobjects (lua_State *L) {
1280 global_State *g = G(L); 1280 global_State *g = G(L);
1281 luaC_changemode(L, KGC_NORMAL); 1281 luaC_changemode(L, KGC_INC);
1282 separatetobefnz(g, 1); /* separate all objects with finalizers */ 1282 separatetobefnz(g, 1); /* separate all objects with finalizers */
1283 lua_assert(g->finobj == NULL); 1283 lua_assert(g->finobj == NULL);
1284 callallpendingfinalizers(L); 1284 callallpendingfinalizers(L);
@@ -1394,7 +1394,7 @@ static lu_mem singlestep (lua_State *L) {
1394 return 0; 1394 return 0;
1395 } 1395 }
1396 case GCScallfin: { /* call remaining finalizers */ 1396 case GCScallfin: { /* call remaining finalizers */
1397 if (g->tobefnz && g->gckind != KGC_EMERGENCY) { 1397 if (g->tobefnz && !g->gcemergency) {
1398 int n = runafewfinalizers(L); 1398 int n = runafewfinalizers(L);
1399 return (n * GCFINALIZECOST); 1399 return (n * GCFINALIZECOST);
1400 } 1400 }
@@ -1459,7 +1459,7 @@ void luaC_step (lua_State *L) {
1459 global_State *g = G(L); 1459 global_State *g = G(L);
1460 if (!g->gcrunning) /* not running? */ 1460 if (!g->gcrunning) /* not running? */
1461 luaE_setdebt(g, -GCSTEPSIZE * 10); /* avoid being called too often */ 1461 luaE_setdebt(g, -GCSTEPSIZE * 10); /* avoid being called too often */
1462 else if (g->gckind == KGC_NORMAL) 1462 else if (g->gckind == KGC_INC)
1463 incstep(L, g); 1463 incstep(L, g);
1464 else 1464 else
1465 genstep(L, g); 1465 genstep(L, g);
@@ -1490,14 +1490,13 @@ static void fullinc (lua_State *L, global_State *g) {
1490 1490
1491void luaC_fullgc (lua_State *L, int isemergency) { 1491void luaC_fullgc (lua_State *L, int isemergency) {
1492 global_State *g = G(L); 1492 global_State *g = G(L);
1493 int gckind = g->gckind; 1493 lua_assert(!g->gcemergency);
1494 if (isemergency) 1494 g->gcemergency = isemergency; /* set flag */
1495 g->gckind = KGC_EMERGENCY; /* set flag */ 1495 if (g->gckind == KGC_INC)
1496 if (gckind == KGC_NORMAL)
1497 fullinc(L, g); 1496 fullinc(L, g);
1498 else 1497 else
1499 fullgen(L, g); 1498 fullgen(L, g);
1500 g->gckind = gckind; 1499 g->gcemergency = 0;
1501} 1500}
1502 1501
1503/* }====================================================== */ 1502/* }====================================================== */
diff --git a/lstate.c b/lstate.c
index adc1bce9..653c90f2 100644
--- a/lstate.c
+++ b/lstate.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.c,v 2.136 2017/04/11 19:00:27 roberto Exp roberto $ 2** $Id: lstate.c,v 2.137 2017/04/12 18:56:25 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*/
@@ -209,6 +209,7 @@ static void f_luaopen (lua_State *L, void *ud) {
209 luaT_init(L); 209 luaT_init(L);
210 luaX_init(L); 210 luaX_init(L);
211 g->gcrunning = 1; /* allow gc */ 211 g->gcrunning = 1; /* allow gc */
212 g->gcemergency = 0;
212 g->version = lua_version(NULL); 213 g->version = lua_version(NULL);
213 luai_userstateopen(L); 214 luai_userstateopen(L);
214} 215}
@@ -317,7 +318,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
317 g->panic = NULL; 318 g->panic = NULL;
318 g->version = NULL; 319 g->version = NULL;
319 g->gcstate = GCSpause; 320 g->gcstate = GCSpause;
320 g->gckind = KGC_NORMAL; 321 g->gckind = KGC_INC;
321 g->finobj = g->tobefnz = g->fixedgc = NULL; 322 g->finobj = g->tobefnz = g->fixedgc = NULL;
322 g->survival = g->old = g->reallyold = NULL; 323 g->survival = g->old = g->reallyold = NULL;
323 g->finobjsur = g->finobjold = g->finobjrold = NULL; 324 g->finobjsur = g->finobjold = g->finobjrold = NULL;
diff --git a/lstate.h b/lstate.h
index d844fc8c..d2f23839 100644
--- a/lstate.h
+++ b/lstate.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.h,v 2.137 2017/04/11 18:41:09 roberto Exp roberto $ 2** $Id: lstate.h,v 2.138 2017/04/19 17:02:50 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*/
@@ -69,9 +69,8 @@ struct lua_longjmp; /* defined in ldo.c */
69 69
70 70
71/* kinds of Garbage Collection */ 71/* kinds of Garbage Collection */
72#define KGC_NORMAL 0 72#define KGC_INC 0 /* incremental gc */
73#define KGC_GEN 1 /* generational gc */ 73#define KGC_GEN 1 /* generational gc */
74#define KGC_EMERGENCY 2 /* gc was forced by an allocation failure */
75 74
76 75
77typedef struct stringtable { 76typedef struct stringtable {
@@ -151,6 +150,7 @@ typedef struct global_State {
151 lu_byte genminormul; /* control for minor generational collections */ 150 lu_byte genminormul; /* control for minor generational collections */
152 lu_byte genmajormul; /* control for major generational collections */ 151 lu_byte genmajormul; /* control for major generational collections */
153 lu_byte gcrunning; /* true if GC is running */ 152 lu_byte gcrunning; /* true if GC is running */
153 lu_byte gcemergency; /* true if this is an emergency collection */
154 GCObject *allgc; /* list of all collectable objects */ 154 GCObject *allgc; /* list of all collectable objects */
155 GCObject **sweepgc; /* current position of sweep in list */ 155 GCObject **sweepgc; /* current position of sweep in list */
156 GCObject *finobj; /* list of collectable objects with finalizers */ 156 GCObject *finobj; /* list of collectable objects with finalizers */
diff --git a/ltests.c b/ltests.c
index 9679bee2..77f0163d 100644
--- a/ltests.c
+++ b/ltests.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltests.c,v 2.213 2017/04/18 19:42:12 roberto Exp roberto $ 2** $Id: ltests.c,v 2.214 2017/04/19 18:46:47 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*/
@@ -199,7 +199,7 @@ static int testobjref1 (global_State *g, GCObject *f, GCObject *t) {
199 if (isdead(g,t)) return 0; 199 if (isdead(g,t)) return 0;
200 if (issweepphase(g)) 200 if (issweepphase(g))
201 return 1; /* no invariants */ 201 return 1; /* no invariants */
202 else if (g->gckind == KGC_NORMAL) 202 else if (g->gckind == KGC_INC)
203 return !(isblack(f) && iswhite(t)); /* basic incremental invariant */ 203 return !(isblack(f) && iswhite(t)); /* basic incremental invariant */
204 else { /* generational mode */ 204 else { /* generational mode */
205 if ((getage(f) == G_OLD && isblack(f)) && !isold(t)) 205 if ((getage(f) == G_OLD && isblack(f)) && !isold(t))