aboutsummaryrefslogtreecommitdiff
path: root/lgc.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2022-12-06 12:02:34 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2022-12-06 12:02:34 -0300
commit0270c204c235a495ce4702ac3891eb30752d0c8d (patch)
treef97e28fe989eb6c6ee96656c6f225fa50a44d7ef /lgc.c
parentefc7c5d503e30128e8282f0a70d3793e9ee3bd3a (diff)
downloadlua-0270c204c235a495ce4702ac3891eb30752d0c8d.tar.gz
lua-0270c204c235a495ce4702ac3891eb30752d0c8d.tar.bz2
lua-0270c204c235a495ce4702ac3891eb30752d0c8d.zip
Simplification in handling of GC debt
Each incremental step has always the same size (stepsize), and the debt for next step also is always the same.
Diffstat (limited to 'lgc.c')
-rw-r--r--lgc.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/lgc.c b/lgc.c
index 1b24fda6..c93b5994 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1037,7 +1037,7 @@ void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) {
1037*/ 1037*/
1038static void setpause (global_State *g) { 1038static void setpause (global_State *g) {
1039 unsigned int pause = getgcparam(g->gcpause); 1039 unsigned int pause = getgcparam(g->gcpause);
1040 lu_mem threshold = g->marked / 8 * pause / 12; 1040 l_obj threshold = g->marked / 8 * pause / 12;
1041 l_obj debt = gettotalobjs(g) - threshold; 1041 l_obj debt = gettotalobjs(g) - threshold;
1042 if (debt > 0) debt = 0; 1042 if (debt > 0) debt = 0;
1043 luaE_setdebt(g, debt); 1043 luaE_setdebt(g, debt);
@@ -1600,18 +1600,16 @@ void luaC_runtilstate (lua_State *L, int statesmask) {
1600** controls when next step will be performed. 1600** controls when next step will be performed.
1601*/ 1601*/
1602static void incstep (lua_State *L, global_State *g) { 1602static void incstep (lua_State *L, global_State *g) {
1603 int stepmul = (getgcparam(g->gcstepmul) | 1); /* avoid division by 0 */
1604 l_obj debt = (g->GCdebt / 100) * stepmul;
1605 l_obj stepsize = cast(l_obj, 1) << g->gcstepsize; 1603 l_obj stepsize = cast(l_obj, 1) << g->gcstepsize;
1604 l_obj work2do = stepsize * getgcparam(g->gcstepmul) / 100;
1606 do { /* repeat until pause or enough "credit" (negative debt) */ 1605 do { /* repeat until pause or enough "credit" (negative debt) */
1607 l_obj work = singlestep(L); /* perform one single step */ 1606 l_obj work = singlestep(L); /* perform one single step */
1608 debt -= work; 1607 work2do -= work;
1609 } while (debt > -stepsize && g->gcstate != GCSpause); 1608 } while (work2do > 0 && g->gcstate != GCSpause);
1610 if (g->gcstate == GCSpause) 1609 if (g->gcstate == GCSpause)
1611 setpause(g); /* pause until next cycle */ 1610 setpause(g); /* pause until next cycle */
1612 else { 1611 else {
1613 debt = (debt / stepmul) * 100; /* apply step multiplier */ 1612 luaE_setdebt(g, -stepsize);
1614 luaE_setdebt(g, debt);
1615 } 1613 }
1616} 1614}
1617 1615