lua

A copy of the Lua development repository
Log | Files | Refs | README

commit a04e0ffdb9be42a77b5657f46cac8d7faa5a0f43
parent 007b8c7a01eaa97d796561a19c7e9af1ec474495
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date:   Fri,  6 Sep 2024 14:38:12 -0300

Rename of fields in global state that control GC

All fields in the global state that control the pace of the garbage
collector prefixed with 'GC'.

Diffstat:
Mlapi.c | 4++--
Mlgc.c | 28++++++++++++++--------------
Mlmem.c | 8++++----
Mlstate.c | 16++++++++--------
Mlstate.h | 8++++----
5 files changed, 32 insertions(+), 32 deletions(-)

diff --git a/lapi.c b/lapi.c @@ -1190,11 +1190,11 @@ LUA_API int lua_gc (lua_State *L, int what, ...) { } case LUA_GCCOUNT: { /* GC values are expressed in Kbytes: #bytes/2^10 */ - res = cast_int(g->totalbytes >> 10); + res = cast_int(g->GCtotalbytes >> 10); break; } case LUA_GCCOUNTB: { - res = cast_int(g->totalbytes & 0x3ff); + res = cast_int(g->GCtotalbytes & 0x3ff); break; } case LUA_GCSTEP: { diff --git a/lgc.c b/lgc.c @@ -290,7 +290,7 @@ GCObject *luaC_newobj (lua_State *L, lu_byte tt, size_t sz) { ** (only closures can), and a userdata's metatable must be a table. */ static void reallymarkobject (global_State *g, GCObject *o) { - g->marked++; + g->GCmarked++; switch (o->tt) { case LUA_VSHRSTR: case LUA_VLNGSTR: { @@ -401,7 +401,7 @@ static void cleargraylists (global_State *g) { */ static void restartcollection (global_State *g) { cleargraylists(g); - g->marked = NFIXED; + g->GCmarked = NFIXED; markobject(g, g->mainthread); markvalue(g, &g->l_registry); markmt(g); @@ -781,7 +781,7 @@ static void freeupval (lua_State *L, UpVal *uv) { static void freeobj (lua_State *L, GCObject *o) { - G(L)->totalobjs--; + G(L)->GCtotalobjs--; switch (o->tt) { case LUA_VPROTO: luaF_freeproto(L, gco2p(o)); @@ -1052,7 +1052,7 @@ void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) { ** approximately (marked * pause / 100). */ static void setpause (global_State *g) { - l_obj threshold = applygcparam(g, PAUSE, g->marked); + l_obj threshold = applygcparam(g, PAUSE, g->GCmarked); l_obj debt = threshold - gettotalobjs(g); if (debt < 0) debt = 0; luaE_setdebt(g, debt); @@ -1236,7 +1236,7 @@ static void finishgencycle (lua_State *L, global_State *g) { ** in generational mode. */ static void minor2inc (lua_State *L, global_State *g, lu_byte kind) { - g->GCmajorminor = g->marked; /* number of live objects */ + g->GCmajorminor = g->GCmarked; /* number of live objects */ g->gckind = kind; g->reallyold = g->old1 = g->survival = NULL; g->finobjrold = g->finobjold1 = g->finobjsur = NULL; @@ -1260,7 +1260,7 @@ static void minor2inc (lua_State *L, global_State *g, lu_byte kind) { static int checkminormajor (global_State *g, l_obj addedold1) { l_obj step = applygcparam(g, MINORMUL, g->GCmajorminor); l_obj limit = applygcparam(g, MINORMAJOR, g->GCmajorminor); - return (addedold1 >= (step >> 1) || g->marked >= limit); + return (addedold1 >= (step >> 1) || g->GCmarked >= limit); } /* @@ -1270,7 +1270,7 @@ static int checkminormajor (global_State *g, l_obj addedold1) { */ static void youngcollection (lua_State *L, global_State *g) { l_obj addedold1 = 0; - l_obj marked = g->marked; /* preserve 'g->marked' */ + l_obj marked = g->GCmarked; /* preserve 'g->GCmarked' */ GCObject **psurvival; /* to point to first non-dead survival object */ GCObject *dummy; /* dummy out parameter to 'sweepgen' */ lua_assert(g->gcstate == GCSpropagate); @@ -1304,12 +1304,12 @@ static void youngcollection (lua_State *L, global_State *g) { sweepgen(L, g, &g->tobefnz, NULL, &dummy, &addedold1); /* keep total number of added old1 objects */ - g->marked = marked + addedold1; + g->GCmarked = marked + addedold1; /* decide whether to shift to major mode */ if (checkminormajor(g, addedold1)) { minor2inc(L, g, KGC_GENMAJOR); /* go to major mode */ - g->marked = 0; /* avoid pause in first major cycle */ + g->GCmarked = 0; /* avoid pause in first major cycle */ } else finishgencycle(L, g); /* still in minor mode; finish it */ @@ -1338,8 +1338,8 @@ static void atomic2gen (lua_State *L, global_State *g) { sweep2old(L, &g->tobefnz); g->gckind = KGC_GENMINOR; - g->GCmajorminor = g->marked; /* "base" for number of objects */ - g->marked = 0; /* to count the number of added old1 objects */ + g->GCmajorminor = g->GCmarked; /* "base" for number of objects */ + g->GCmarked = 0; /* to count the number of added old1 objects */ finishgencycle(L, g); } @@ -1407,14 +1407,14 @@ static int checkmajorminor (lua_State *L, global_State *g) { l_obj numobjs = gettotalobjs(g); l_obj addedobjs = numobjs - g->GCmajorminor; l_obj limit = applygcparam(g, MAJORMINOR, addedobjs); - l_obj tobecollected = numobjs - g->marked; + l_obj tobecollected = numobjs - g->GCmarked; if (tobecollected > limit) { atomic2gen(L, g); /* return to generational mode */ setminordebt(g); return 0; /* exit incremental collection */ } } - g->GCmajorminor = g->marked; /* prepare for next collection */ + g->GCmajorminor = g->GCmarked; /* prepare for next collection */ return 1; /* stay doing incremental collections */ } @@ -1692,7 +1692,7 @@ static void fullinc (lua_State *L, global_State *g) { luaC_runtilstate(L, GCSpause, 1); luaC_runtilstate(L, GCScallfin, 1); /* run up to finalizers */ /* 'marked' must be correct after a full GC cycle */ - lua_assert(g->marked == gettotalobjs(g)); + lua_assert(g->GCmarked == gettotalobjs(g)); luaC_runtilstate(L, GCSpause, 1); /* finish collection */ setpause(g); } diff --git a/lmem.c b/lmem.c @@ -151,7 +151,7 @@ void luaM_free_ (lua_State *L, void *block, size_t osize) { global_State *g = G(L); lua_assert((osize == 0) == (block == NULL)); callfrealloc(g, block, osize, 0); - g->totalbytes -= osize; + g->GCtotalbytes -= osize; } @@ -181,10 +181,10 @@ void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { if (l_unlikely(newblock == NULL && nsize > 0)) { newblock = tryagain(L, block, osize, nsize); if (newblock == NULL) /* still no memory? */ - return NULL; /* do not update 'totalbytes' */ + return NULL; /* do not update 'GCtotalbytes' */ } lua_assert((nsize == 0) == (newblock == NULL)); - g->totalbytes += nsize - osize; + g->GCtotalbytes += nsize - osize; return newblock; } @@ -209,7 +209,7 @@ void *luaM_malloc_ (lua_State *L, size_t size, int tag) { if (newblock == NULL) luaM_error(L); } - g->totalbytes += size; + g->GCtotalbytes += size; return newblock; } } diff --git a/lstate.c b/lstate.c @@ -74,15 +74,15 @@ typedef struct LG { /* ** set GCdebt to a new value keeping the real number of allocated -** objects (totalobjs - GCdebt) invariant and avoiding overflows in -** 'totalobjs'. +** objects (GCtotalobjs - GCdebt) invariant and avoiding overflows in +** 'GCtotalobjs'. */ void luaE_setdebt (global_State *g, l_obj debt) { l_obj tb = gettotalobjs(g); lua_assert(tb > 0); if (debt > MAX_LOBJ - tb) - debt = MAX_LOBJ - tb; /* will make 'totalobjs == MAX_LMEM' */ - g->totalobjs = tb + debt; + debt = MAX_LOBJ - tb; /* will make GCtotalobjs == MAX_LOBJ */ + g->GCtotalobjs = tb + debt; g->GCdebt = debt; } @@ -269,7 +269,7 @@ static void close_state (lua_State *L) { } luaM_freearray(L, G(L)->strt.hash, cast_sizet(G(L)->strt.size)); freestack(L); - lua_assert(g->totalbytes == sizeof(LG)); + lua_assert(g->GCtotalbytes == sizeof(LG)); lua_assert(gettotalobjs(g) == 1); (*g->frealloc)(g->ud, fromstate(L), sizeof(LG), 0); /* free main block */ } @@ -378,9 +378,9 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud, unsigned seed) { g->gray = g->grayagain = NULL; g->weak = g->ephemeron = g->allweak = NULL; g->twups = NULL; - g->totalbytes = sizeof(LG); - g->totalobjs = 1; - g->marked = 0; + g->GCtotalbytes = sizeof(LG); + g->GCtotalobjs = 1; + g->GCmarked = 0; g->GCdebt = 0; setivalue(&g->nilvalue, 0); /* to signal that state is not yet built */ setgcparam(g, PAUSE, LUAI_GCPAUSE); diff --git a/lstate.h b/lstate.h @@ -274,10 +274,10 @@ struct CallInfo { typedef struct global_State { lua_Alloc frealloc; /* function to reallocate memory */ void *ud; /* auxiliary data to 'frealloc' */ - lu_mem totalbytes; /* number of bytes currently allocated */ - l_obj totalobjs; /* total number of objects allocated + GCdebt */ + lu_mem GCtotalbytes; /* number of bytes currently allocated */ + l_obj GCtotalobjs; /* total number of objects allocated + GCdebt */ l_obj GCdebt; /* objects counted but not yet allocated */ - l_obj marked; /* number of objects marked in a GC cycle */ + l_obj GCmarked; /* number of objects marked in a GC cycle */ l_obj GCmajorminor; /* auxiliary counter to control major-minor shifts */ stringtable strt; /* hash table for strings */ TValue l_registry; @@ -412,7 +412,7 @@ union GCUnion { /* actual number of total objects allocated */ -#define gettotalobjs(g) ((g)->totalobjs - (g)->GCdebt) +#define gettotalobjs(g) ((g)->GCtotalobjs - (g)->GCdebt) LUAI_FUNC void luaE_setdebt (global_State *g, l_obj debt);