aboutsummaryrefslogtreecommitdiff
path: root/lgc.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-02-05 15:14:54 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-02-05 15:14:54 -0200
commitdaff7c3b4de14278a06d86997baa6ab9db7b662b (patch)
treea1f6c70cfc4bd045a3be726049e2aa47be8c8839 /lgc.c
parenta131eae925cad604ab1bb248e0c2eda83c54bf82 (diff)
downloadlua-daff7c3b4de14278a06d86997baa6ab9db7b662b.tar.gz
lua-daff7c3b4de14278a06d86997baa6ab9db7b662b.tar.bz2
lua-daff7c3b4de14278a06d86997baa6ab9db7b662b.zip
small corrections in generational mode
(cannot call finalizers in emergency collections + should set everything before calling finalizers)
Diffstat (limited to 'lgc.c')
-rw-r--r--lgc.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/lgc.c b/lgc.c
index 7b223bcb..20397e48 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 2.244 2017/12/28 15:42:57 roberto Exp roberto $ 2** $Id: lgc.c,v 2.245 2018/01/28 15:13:26 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*/
@@ -860,6 +860,7 @@ static void GCTM (lua_State *L, int propagateerrors) {
860 global_State *g = G(L); 860 global_State *g = G(L);
861 const TValue *tm; 861 const TValue *tm;
862 TValue v; 862 TValue v;
863 lua_assert(!g->gcemergency);
863 setgcovalue(L, &v, udata2finalize(g)); 864 setgcovalue(L, &v, udata2finalize(g));
864 tm = luaT_gettmbyobj(L, &v, TM_GC); 865 tm = luaT_gettmbyobj(L, &v, TM_GC);
865 if (tm != NULL && ttisfunction(tm)) { /* is there a finalizer? */ 866 if (tm != NULL && ttisfunction(tm)) { /* is there a finalizer? */
@@ -905,10 +906,10 @@ static int runafewfinalizers (lua_State *L, int n) {
905/* 906/*
906** call all pending finalizers 907** call all pending finalizers
907*/ 908*/
908static void callallpendingfinalizers (lua_State *L) { 909static void callallpendingfinalizers (lua_State *L, int propagateerrors) {
909 global_State *g = G(L); 910 global_State *g = G(L);
910 while (g->tobefnz) 911 while (g->tobefnz)
911 GCTM(L, 0); 912 GCTM(L, propagateerrors);
912} 913}
913 914
914 915
@@ -1151,7 +1152,8 @@ static void finishgencycle (lua_State *L, global_State *g) {
1151 correctgraylists(g); 1152 correctgraylists(g);
1152 checkSizes(L, g); 1153 checkSizes(L, g);
1153 g->gcstate = GCSpropagate; /* skip restart */ 1154 g->gcstate = GCSpropagate; /* skip restart */
1154 callallpendingfinalizers(L); 1155 if (!g->gcemergency)
1156 callallpendingfinalizers(L, 1);
1155} 1157}
1156 1158
1157 1159
@@ -1211,9 +1213,9 @@ static void entergen (lua_State *L, global_State *g) {
1211 1213
1212 sweep2old(L, &g->tobefnz); 1214 sweep2old(L, &g->tobefnz);
1213 1215
1214 finishgencycle(L, g);
1215 g->gckind = KGC_GEN; 1216 g->gckind = KGC_GEN;
1216 g->GCestimate = gettotalbytes(g); /* base for memory control */ 1217 g->GCestimate = gettotalbytes(g); /* base for memory control */
1218 finishgencycle(L, g);
1217} 1219}
1218 1220
1219 1221
@@ -1226,8 +1228,8 @@ static void enterinc (global_State *g) {
1226 whitelist(g, g->allgc); 1228 whitelist(g, g->allgc);
1227 g->reallyold = g->old = g->survival = NULL; 1229 g->reallyold = g->old = g->survival = NULL;
1228 whitelist(g, g->finobj); 1230 whitelist(g, g->finobj);
1231 whitelist(g, g->tobefnz);
1229 g->finobjrold = g->finobjold = g->finobjsur = NULL; 1232 g->finobjrold = g->finobjold = g->finobjsur = NULL;
1230 lua_assert(g->tobefnz == NULL); /* no need to sweep */
1231 g->gcstate = GCSpause; 1233 g->gcstate = GCSpause;
1232 g->gckind = KGC_INC; 1234 g->gckind = KGC_INC;
1233} 1235}
@@ -1347,7 +1349,7 @@ void luaC_freeallobjects (lua_State *L) {
1347 luaC_changemode(L, KGC_INC); 1349 luaC_changemode(L, KGC_INC);
1348 separatetobefnz(g, 1); /* separate all objects with finalizers */ 1350 separatetobefnz(g, 1); /* separate all objects with finalizers */
1349 lua_assert(g->finobj == NULL); 1351 lua_assert(g->finobj == NULL);
1350 callallpendingfinalizers(L); 1352 callallpendingfinalizers(L, 0);
1351 deletelist(L, g->allgc, obj2gco(g->mainthread)); 1353 deletelist(L, g->allgc, obj2gco(g->mainthread));
1352 deletelist(L, g->finobj, NULL); 1354 deletelist(L, g->finobj, NULL);
1353 deletelist(L, g->fixedgc, NULL); /* collect fixed objects */ 1355 deletelist(L, g->fixedgc, NULL); /* collect fixed objects */