New option "setparms" for 'collectgarbage'

The generational mode also uses the parameters for the incremental
mode in its major collections, so it should be easy to change those
parameters without having to change the GC mode.
This commit is contained in:
Roberto Ierusalimschy
2023-12-22 14:48:07 -03:00
parent ad0ea7813b
commit e2cc179454
13 changed files with 163 additions and 78 deletions

16
lgc.c
View File

@@ -1049,7 +1049,7 @@ void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) {
** approximately (marked * pause / 100).
*/
static void setpause (global_State *g) {
l_obj threshold = luaO_applyparam(g->gcppause, g->marked);
l_obj threshold = applygcparam(g, PAUSE, g->marked);
l_obj debt = threshold - gettotalobjs(g);
if (debt < 0) debt = 0;
luaE_setdebt(g, debt);
@@ -1239,7 +1239,7 @@ static void minor2inc (lua_State *L, global_State *g, int kind) {
g->finobjrold = g->finobjold1 = g->finobjsur = NULL;
entersweep(L); /* continue as an incremental cycle */
/* set a debt equal to the step size */
luaE_setdebt(g, luaO_applyparam(g->gcpstepsize, 100));
luaE_setdebt(g, applygcparam(g, STEPSIZE, 100));
}
@@ -1255,8 +1255,8 @@ static void minor2inc (lua_State *L, global_State *g, int kind) {
** major collection. (That percentage is computed in 'limit'.)
*/
static int checkminormajor (lua_State *L, global_State *g, l_obj addedold1) {
l_obj step = luaO_applyparam(g->gcpgenminormul, g->GCmajorminor);
l_obj limit = luaO_applyparam(g->gcpminormajor, g->GCmajorminor);
l_obj step = applygcparam(g, MINORMUL, g->GCmajorminor);
l_obj limit = applygcparam(g, MINORMAJOR, g->GCmajorminor);
//printf("-> major? %ld %ld %ld %ld (%ld)\n", g->marked, limit, step, addedold1, gettotalobjs(g));
if (addedold1 >= (step >> 1) || g->marked >= limit) {
minor2inc(L, g, KGC_GENMAJOR); /* go to major mode */
@@ -1347,7 +1347,7 @@ static void atomic2gen (lua_State *L, global_State *g) {
** total number of objects grows 'genminormul'%.
*/
static void setminordebt (global_State *g) {
luaE_setdebt(g, luaO_applyparam(g->gcpgenminormul, g->GCmajorminor));
luaE_setdebt(g, applygcparam(g, MINORMUL, g->GCmajorminor));
}
@@ -1404,7 +1404,7 @@ static int checkmajorminor (lua_State *L, global_State *g) {
if (g->gckind == KGC_GENMAJOR) {
l_obj numobjs = gettotalobjs(g);
l_obj addedobjs = numobjs - g->GCmajorminor;
l_obj limit = luaO_applyparam(g->gcpmajorminor, addedobjs);
l_obj limit = applygcparam(g, MAJORMINOR, addedobjs);
l_obj tobecollected = numobjs - g->marked;
//printf("-> minor? %ld %ld %ld\n", tobecollected, limit, numobjs);
if (tobecollected > limit) {
@@ -1634,8 +1634,8 @@ void luaC_runtilstate (lua_State *L, int state, int fast) {
** controls when next step will be performed.
*/
static void incstep (lua_State *L, global_State *g) {
l_obj stepsize = luaO_applyparam(g->gcpstepsize, 100);
l_obj work2do = luaO_applyparam(g->gcpstepmul, stepsize);
l_obj stepsize = applygcparam(g, STEPSIZE, 100);
l_obj work2do = applygcparam(g, STEPMUL, stepsize);
int fast = 0;
if (work2do == 0) { /* special case: do a full collection */
work2do = MAX_LOBJ; /* do unlimited work */