Skip to content

Commit a1f77a2

Browse files
committed
Bug: set correct pause when (re)entering gen. collection.
1 parent c6cea85 commit a1f77a2

File tree

1 file changed

+31
-32
lines changed

1 file changed

+31
-32
lines changed

lgc.c

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,25 @@ void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) {
10411041
** =======================================================
10421042
*/
10431043

1044-
static void setpause (global_State *g);
1044+
1045+
/*
1046+
** Set the "time" to wait before starting a new GC cycle; cycle will
1047+
** start when memory use hits the threshold of ('estimate' * pause /
1048+
** PAUSEADJ). (Division by 'estimate' should be OK: it cannot be zero,
1049+
** because Lua cannot even start with less than PAUSEADJ bytes).
1050+
*/
1051+
static void setpause (global_State *g) {
1052+
l_mem threshold, debt;
1053+
int pause = getgcparam(g->gcpause);
1054+
l_mem estimate = g->GCestimate / PAUSEADJ; /* adjust 'estimate' */
1055+
lua_assert(estimate > 0);
1056+
threshold = (pause < MAX_LMEM / estimate) /* overflow? */
1057+
? estimate * pause /* no overflow */
1058+
: MAX_LMEM; /* overflow; truncate to maximum */
1059+
debt = gettotalbytes(g) - threshold;
1060+
if (debt > 0) debt = 0;
1061+
luaE_setdebt(g, debt);
1062+
}
10451063

10461064

10471065
/*
@@ -1285,6 +1303,15 @@ static void atomic2gen (lua_State *L, global_State *g) {
12851303
}
12861304

12871305

1306+
/*
1307+
** Set debt for the next minor collection, which will happen when
1308+
** memory grows 'genminormul'%.
1309+
*/
1310+
static void setminordebt (global_State *g) {
1311+
luaE_setdebt(g, -(cast(l_mem, (gettotalbytes(g) / 100)) * g->genminormul));
1312+
}
1313+
1314+
12881315
/*
12891316
** Enter generational mode. Must go until the end of an atomic cycle
12901317
** to ensure that all objects are correctly marked and weak tables
@@ -1297,6 +1324,7 @@ static lu_mem entergen (lua_State *L, global_State *g) {
12971324
luaC_runtilstate(L, bitmask(GCSpropagate)); /* start new cycle */
12981325
numobjs = atomic(L); /* propagates all and then do the atomic stuff */
12991326
atomic2gen(L, g);
1327+
setminordebt(g); /* set debt assuming next cycle will be minor */
13001328
return numobjs;
13011329
}
13021330

@@ -1342,15 +1370,6 @@ static lu_mem fullgen (lua_State *L, global_State *g) {
13421370
}
13431371

13441372

1345-
/*
1346-
** Set debt for the next minor collection, which will happen when
1347-
** memory grows 'genminormul'%.
1348-
*/
1349-
static void setminordebt (global_State *g) {
1350-
luaE_setdebt(g, -(cast(l_mem, (gettotalbytes(g) / 100)) * g->genminormul));
1351-
}
1352-
1353-
13541373
/*
13551374
** Does a major collection after last collection was a "bad collection".
13561375
**
@@ -1422,8 +1441,8 @@ static void genstep (lua_State *L, global_State *g) {
14221441
lu_mem numobjs = fullgen(L, g); /* do a major collection */
14231442
if (gettotalbytes(g) < majorbase + (majorinc / 2)) {
14241443
/* collected at least half of memory growth since last major
1425-
collection; keep doing minor collections */
1426-
setminordebt(g);
1444+
collection; keep doing minor collections. */
1445+
lua_assert(g->lastatomic == 0);
14271446
}
14281447
else { /* bad collection */
14291448
g->lastatomic = numobjs; /* signal that last collection was bad */
@@ -1449,26 +1468,6 @@ static void genstep (lua_State *L, global_State *g) {
14491468
*/
14501469

14511470

1452-
/*
1453-
** Set the "time" to wait before starting a new GC cycle; cycle will
1454-
** start when memory use hits the threshold of ('estimate' * pause /
1455-
** PAUSEADJ). (Division by 'estimate' should be OK: it cannot be zero,
1456-
** because Lua cannot even start with less than PAUSEADJ bytes).
1457-
*/
1458-
static void setpause (global_State *g) {
1459-
l_mem threshold, debt;
1460-
int pause = getgcparam(g->gcpause);
1461-
l_mem estimate = g->GCestimate / PAUSEADJ; /* adjust 'estimate' */
1462-
lua_assert(estimate > 0);
1463-
threshold = (pause < MAX_LMEM / estimate) /* overflow? */
1464-
? estimate * pause /* no overflow */
1465-
: MAX_LMEM; /* overflow; truncate to maximum */
1466-
debt = gettotalbytes(g) - threshold;
1467-
if (debt > 0) debt = 0;
1468-
luaE_setdebt(g, debt);
1469-
}
1470-
1471-
14721471
/*
14731472
** Enter first sweep phase.
14741473
** The call to 'sweeptolive' makes the pointer point to an object

0 commit comments

Comments
 (0)