aboutsummaryrefslogtreecommitdiff
path: root/lgc.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2022-12-13 11:55:14 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2022-12-13 11:55:14 -0300
commit40565b4a089f44fdcb16f4ed0080b0ca3755e4aa (patch)
treed3d692070a250e5756fad95388606736253da8c4 /lgc.c
parentff106c028ca944ee5e95b005628e2669b87bcaf2 (diff)
downloadlua-40565b4a089f44fdcb16f4ed0080b0ca3755e4aa.tar.gz
lua-40565b4a089f44fdcb16f4ed0080b0ca3755e4aa.tar.bz2
lua-40565b4a089f44fdcb16f4ed0080b0ca3755e4aa.zip
Revamp of GC parameters
More uniformity when handling GC parameters + avoid divisions by 100 when applying them.
Diffstat (limited to 'lgc.c')
-rw-r--r--lgc.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/lgc.c b/lgc.c
index c2b0535d..90a49091 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1030,14 +1030,10 @@ void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) {
1030/* 1030/*
1031** Set the "time" to wait before starting a new GC cycle; cycle will 1031** Set the "time" to wait before starting a new GC cycle; cycle will
1032** start when number of objects in use hits the threshold of 1032** start when number of objects in use hits the threshold of
1033** approximately ('marked' * pause / 100). (A direct multiplication 1033** approximately (marked * pause / 100).
1034** by 'pause' may overflow, and a direct division by 100 may undeflow
1035** to zero. So, the division is done in two steps. 8 * 12 is near 100
1036** and the division by 8 is cheap.)
1037*/ 1034*/
1038static void setpause (global_State *g) { 1035static void setpause (global_State *g) {
1039 unsigned int pause = getgcparam(g->gcpause); 1036 l_obj threshold = applygcparam(g, gcpause, g->marked);
1040 l_obj threshold = g->marked / 8 * pause / 12;
1041 l_obj debt = gettotalobjs(g) - threshold; 1037 l_obj debt = gettotalobjs(g) - threshold;
1042 if (debt > 0) debt = 0; 1038 if (debt > 0) debt = 0;
1043 luaE_setdebt(g, debt); 1039 luaE_setdebt(g, debt);
@@ -1289,7 +1285,7 @@ static void atomic2gen (lua_State *L, global_State *g) {
1289** total number of objects grows 'genminormul'%. 1285** total number of objects grows 'genminormul'%.
1290*/ 1286*/
1291static void setminordebt (global_State *g) { 1287static void setminordebt (global_State *g) {
1292 luaE_setdebt(g, -(gettotalobjs(g) / 100) * g->genminormul); 1288 luaE_setdebt(g, -applygcparam(g, genminormul, gettotalobjs(g)));
1293} 1289}
1294 1290
1295 1291
@@ -1387,7 +1383,7 @@ static void genmajorstep (lua_State *L, global_State *g) {
1387*/ 1383*/
1388static void genstep (lua_State *L, global_State *g) { 1384static void genstep (lua_State *L, global_State *g) {
1389 l_obj majorbase = g->GClastmajor; /* count after last major collection */ 1385 l_obj majorbase = g->GClastmajor; /* count after last major collection */
1390 l_obj majorinc = (majorbase / 100) * getgcparam(g->genmajormul); 1386 l_obj majorinc = applygcparam(g, genmajormul, majorbase);
1391 if (g->GCdebt > 0 && gettotalobjs(g) > majorbase + majorinc) { 1387 if (g->GCdebt > 0 && gettotalobjs(g) > majorbase + majorinc) {
1392 /* do a major collection */ 1388 /* do a major collection */
1393 enterinc(g); 1389 enterinc(g);
@@ -1601,7 +1597,7 @@ void luaC_runtilstate (lua_State *L, int statesmask) {
1601*/ 1597*/
1602static void incstep (lua_State *L, global_State *g) { 1598static void incstep (lua_State *L, global_State *g) {
1603 l_obj stepsize = cast(l_obj, 1) << g->gcstepsize; 1599 l_obj stepsize = cast(l_obj, 1) << g->gcstepsize;
1604 l_obj work2do = stepsize * getgcparam(g->gcstepmul) / 100; 1600 l_obj work2do = applygcparam(g, gcstepmul, stepsize);
1605 do { /* repeat until pause or enough "credit" (negative debt) */ 1601 do { /* repeat until pause or enough "credit" (negative debt) */
1606 l_obj work = singlestep(L); /* perform one single step */ 1602 l_obj work = singlestep(L); /* perform one single step */
1607 work2do -= work; 1603 work2do -= work;