aboutsummaryrefslogtreecommitdiff
path: root/lgc.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-01-10 14:45:58 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-01-10 14:45:58 -0300
commit7827c40c49d841daca2a40463b8a60f9a113f77e (patch)
tree28e4d4fe0f6a14a6d16c676153653a054d82dd9c /lgc.c
parente7af9cdf0b9fca080e8bb3463e16d60933e786f9 (diff)
downloadlua-7827c40c49d841daca2a40463b8a60f9a113f77e.tar.gz
lua-7827c40c49d841daca2a40463b8a60f9a113f77e.tar.bz2
lua-7827c40c49d841daca2a40463b8a60f9a113f77e.zip
A few more tweaks in the garbage collector
Diffstat (limited to 'lgc.c')
-rw-r--r--lgc.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/lgc.c b/lgc.c
index bc4ddb0b..4cdea02a 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1052,6 +1052,7 @@ static void setpause (global_State *g) {
1052 l_obj threshold = applygcparam(g, PAUSE, g->marked); 1052 l_obj threshold = applygcparam(g, PAUSE, g->marked);
1053 l_obj debt = threshold - gettotalobjs(g); 1053 l_obj debt = threshold - gettotalobjs(g);
1054 if (debt < 0) debt = 0; 1054 if (debt < 0) debt = 0;
1055//printf("pause: %ld %ld\n", debt, g->marked);
1055 luaE_setdebt(g, debt); 1056 luaE_setdebt(g, debt);
1056} 1057}
1057 1058
@@ -1246,7 +1247,7 @@ static void minor2inc (lua_State *L, global_State *g, int kind) {
1246/* 1247/*
1247** Decide whether to shift to major mode. It tests two conditions: 1248** Decide whether to shift to major mode. It tests two conditions:
1248** 1) Whether the number of added old objects in this collection is more 1249** 1) Whether the number of added old objects in this collection is more
1249** than half the number of new objects. ("step" is the number of objects 1250** than half the number of new objects. ('step' is the number of objects
1250** created between minor collections. Except for forward barriers, it 1251** created between minor collections. Except for forward barriers, it
1251** is the maximum number of objects that can become old in each minor 1252** is the maximum number of objects that can become old in each minor
1252** collection.) 1253** collection.)
@@ -1254,15 +1255,11 @@ static void minor2inc (lua_State *L, global_State *g, int kind) {
1254** than 'minormajor'% of the number of lived objects after the last 1255** than 'minormajor'% of the number of lived objects after the last
1255** major collection. (That percentage is computed in 'limit'.) 1256** major collection. (That percentage is computed in 'limit'.)
1256*/ 1257*/
1257static int checkminormajor (lua_State *L, global_State *g, l_obj addedold1) { 1258static int checkminormajor (global_State *g, l_obj addedold1) {
1258 l_obj step = applygcparam(g, MINORMUL, g->GCmajorminor); 1259 l_obj step = applygcparam(g, MINORMUL, g->GCmajorminor);
1259 l_obj limit = applygcparam(g, MINORMAJOR, g->GCmajorminor); 1260 l_obj limit = applygcparam(g, MINORMAJOR, g->GCmajorminor);
1260//printf("-> major? %ld %ld %ld %ld (%ld)\n", g->marked, limit, step, addedold1, gettotalobjs(g)); 1261//printf("-> (%ld) major? marked: %ld limit: %ld step: %ld addedold1: %ld)\n", gettotalobjs(g), g->marked, limit, step, addedold1);
1261 if (addedold1 >= (step >> 1) || g->marked >= limit) { 1262 return (addedold1 >= (step >> 1) || g->marked >= limit);
1262 minor2inc(L, g, KGC_GENMAJOR); /* go to major mode */
1263 return 1;
1264 }
1265 return 0; /* stay in minor mode */
1266} 1263}
1267 1264
1268/* 1265/*
@@ -1309,7 +1306,11 @@ static void youngcollection (lua_State *L, global_State *g) {
1309 g->marked = marked + addedold1; 1306 g->marked = marked + addedold1;
1310 1307
1311 /* decide whether to shift to major mode */ 1308 /* decide whether to shift to major mode */
1312 if (!checkminormajor(L, g, addedold1)) 1309 if (checkminormajor(g, addedold1)) {
1310 minor2inc(L, g, KGC_GENMAJOR); /* go to major mode */
1311 g->marked = 0; /* avoid pause in first major cycle */
1312 }
1313 else
1313 finishgencycle(L, g); /* still in minor mode; finish it */ 1314 finishgencycle(L, g); /* still in minor mode; finish it */
1314} 1315}
1315 1316
@@ -1401,12 +1402,12 @@ static void fullgen (lua_State *L, global_State *g) {
1401** since the last collection ('addedobjs'). 1402** since the last collection ('addedobjs').
1402*/ 1403*/
1403static int checkmajorminor (lua_State *L, global_State *g) { 1404static int checkmajorminor (lua_State *L, global_State *g) {
1404 if (g->gckind == KGC_GENMAJOR) { 1405 if (g->gckind == KGC_GENMAJOR) { /* generational mode? */
1405 l_obj numobjs = gettotalobjs(g); 1406 l_obj numobjs = gettotalobjs(g);
1406 l_obj addedobjs = numobjs - g->GCmajorminor; 1407 l_obj addedobjs = numobjs - g->GCmajorminor;
1407 l_obj limit = applygcparam(g, MAJORMINOR, addedobjs); 1408 l_obj limit = applygcparam(g, MAJORMINOR, addedobjs);
1408 l_obj tobecollected = numobjs - g->marked; 1409 l_obj tobecollected = numobjs - g->marked;
1409//printf("-> minor? %ld %ld %ld\n", tobecollected, limit, numobjs); 1410//printf("(%ld) -> minor? tobecollected: %ld limit: %ld\n", numobjs, tobecollected, limit);
1410 if (tobecollected > limit) { 1411 if (tobecollected > limit) {
1411 atomic2gen(L, g); /* return to generational mode */ 1412 atomic2gen(L, g); /* return to generational mode */
1412 setminordebt(g); 1413 setminordebt(g);