From 0270c204c235a495ce4702ac3891eb30752d0c8d Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 6 Dec 2022 12:02:34 -0300 Subject: 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. --- lgc.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'lgc.c') 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) { */ static void setpause (global_State *g) { unsigned int pause = getgcparam(g->gcpause); - lu_mem threshold = g->marked / 8 * pause / 12; + l_obj threshold = g->marked / 8 * pause / 12; l_obj debt = gettotalobjs(g) - threshold; if (debt > 0) debt = 0; luaE_setdebt(g, debt); @@ -1600,18 +1600,16 @@ void luaC_runtilstate (lua_State *L, int statesmask) { ** controls when next step will be performed. */ static void incstep (lua_State *L, global_State *g) { - int stepmul = (getgcparam(g->gcstepmul) | 1); /* avoid division by 0 */ - l_obj debt = (g->GCdebt / 100) * stepmul; l_obj stepsize = cast(l_obj, 1) << g->gcstepsize; + l_obj work2do = stepsize * getgcparam(g->gcstepmul) / 100; do { /* repeat until pause or enough "credit" (negative debt) */ l_obj work = singlestep(L); /* perform one single step */ - debt -= work; - } while (debt > -stepsize && g->gcstate != GCSpause); + work2do -= work; + } while (work2do > 0 && g->gcstate != GCSpause); if (g->gcstate == GCSpause) setpause(g); /* pause until next cycle */ else { - debt = (debt / stepmul) * 100; /* apply step multiplier */ - luaE_setdebt(g, debt); + luaE_setdebt(g, -stepsize); } } -- cgit v1.2.3-55-g6feb