From f356d5acdd9d8e8f7e9d1d7632c4657f945ff4f4 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 23 Nov 2022 17:17:20 -0300 Subject: First version of GC counting objects for control Still needs to review generational mode. --- lstate.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'lstate.c') diff --git a/lstate.c b/lstate.c index 3091a00e..9f615342 100644 --- a/lstate.c +++ b/lstate.c @@ -83,15 +83,15 @@ static unsigned int luai_makeseed (lua_State *L) { /* -** set GCdebt to a new value keeping the value (totalbytes + GCdebt) -** invariant (and avoiding underflows in 'totalbytes') +** set GCdebt to a new value keeping the value (totalobjs + GCdebt) +** invariant (and avoiding underflows in 'totalobjs') */ void luaE_setdebt (global_State *g, l_mem debt) { - l_mem tb = gettotalbytes(g); + l_mem tb = gettotalobjs(g); lua_assert(tb > 0); if (debt < tb - MAX_LMEM) - debt = tb - MAX_LMEM; /* will make 'totalbytes == MAX_LMEM' */ - g->totalbytes = tb - debt; + debt = tb - MAX_LMEM; /* will make 'totalobjs == MAX_LMEM' */ + g->totalobjs = tb - debt; g->GCdebt = debt; } @@ -278,8 +278,8 @@ static void close_state (lua_State *L) { } luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size); freestack(L); - lua_assert(gettotalbytes(g) == sizeof(LG)); - lua_assert(g->totalobjs == 1); + lua_assert(g->totalbytes == sizeof(LG)); + lua_assert(gettotalobjs(g) == 1); (*g->frealloc)(g->ud, fromstate(L), sizeof(LG), 0); /* free main block */ } @@ -389,6 +389,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { g->twups = NULL; g->totalbytes = sizeof(LG); g->totalobjs = 1; + g->marked = 0; g->GCdebt = 0; g->lastatomic = 0; setivalue(&g->nilvalue, 0); /* to signal that state is not yet built */ -- cgit v1.2.3-55-g6feb