Skip to content

Commit a04e0ff

Browse files
committed
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'.
1 parent 007b8c7 commit a04e0ff

File tree

5 files changed

+32
-32
lines changed

5 files changed

+32
-32
lines changed

lapi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,11 +1190,11 @@ LUA_API int lua_gc (lua_State *L, int what, ...) {
11901190
}
11911191
case LUA_GCCOUNT: {
11921192
/* GC values are expressed in Kbytes: #bytes/2^10 */
1193-
res = cast_int(g->totalbytes >> 10);
1193+
res = cast_int(g->GCtotalbytes >> 10);
11941194
break;
11951195
}
11961196
case LUA_GCCOUNTB: {
1197-
res = cast_int(g->totalbytes & 0x3ff);
1197+
res = cast_int(g->GCtotalbytes & 0x3ff);
11981198
break;
11991199
}
12001200
case LUA_GCSTEP: {

lgc.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ GCObject *luaC_newobj (lua_State *L, lu_byte tt, size_t sz) {
290290
** (only closures can), and a userdata's metatable must be a table.
291291
*/
292292
static void reallymarkobject (global_State *g, GCObject *o) {
293-
g->marked++;
293+
g->GCmarked++;
294294
switch (o->tt) {
295295
case LUA_VSHRSTR:
296296
case LUA_VLNGSTR: {
@@ -401,7 +401,7 @@ static void cleargraylists (global_State *g) {
401401
*/
402402
static void restartcollection (global_State *g) {
403403
cleargraylists(g);
404-
g->marked = NFIXED;
404+
g->GCmarked = NFIXED;
405405
markobject(g, g->mainthread);
406406
markvalue(g, &g->l_registry);
407407
markmt(g);
@@ -781,7 +781,7 @@ static void freeupval (lua_State *L, UpVal *uv) {
781781

782782

783783
static void freeobj (lua_State *L, GCObject *o) {
784-
G(L)->totalobjs--;
784+
G(L)->GCtotalobjs--;
785785
switch (o->tt) {
786786
case LUA_VPROTO:
787787
luaF_freeproto(L, gco2p(o));
@@ -1052,7 +1052,7 @@ void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) {
10521052
** approximately (marked * pause / 100).
10531053
*/
10541054
static void setpause (global_State *g) {
1055-
l_obj threshold = applygcparam(g, PAUSE, g->marked);
1055+
l_obj threshold = applygcparam(g, PAUSE, g->GCmarked);
10561056
l_obj debt = threshold - gettotalobjs(g);
10571057
if (debt < 0) debt = 0;
10581058
luaE_setdebt(g, debt);
@@ -1236,7 +1236,7 @@ static void finishgencycle (lua_State *L, global_State *g) {
12361236
** in generational mode.
12371237
*/
12381238
static void minor2inc (lua_State *L, global_State *g, lu_byte kind) {
1239-
g->GCmajorminor = g->marked; /* number of live objects */
1239+
g->GCmajorminor = g->GCmarked; /* number of live objects */
12401240
g->gckind = kind;
12411241
g->reallyold = g->old1 = g->survival = NULL;
12421242
g->finobjrold = g->finobjold1 = g->finobjsur = NULL;
@@ -1260,7 +1260,7 @@ static void minor2inc (lua_State *L, global_State *g, lu_byte kind) {
12601260
static int checkminormajor (global_State *g, l_obj addedold1) {
12611261
l_obj step = applygcparam(g, MINORMUL, g->GCmajorminor);
12621262
l_obj limit = applygcparam(g, MINORMAJOR, g->GCmajorminor);
1263-
return (addedold1 >= (step >> 1) || g->marked >= limit);
1263+
return (addedold1 >= (step >> 1) || g->GCmarked >= limit);
12641264
}
12651265

12661266
/*
@@ -1270,7 +1270,7 @@ static int checkminormajor (global_State *g, l_obj addedold1) {
12701270
*/
12711271
static void youngcollection (lua_State *L, global_State *g) {
12721272
l_obj addedold1 = 0;
1273-
l_obj marked = g->marked; /* preserve 'g->marked' */
1273+
l_obj marked = g->GCmarked; /* preserve 'g->GCmarked' */
12741274
GCObject **psurvival; /* to point to first non-dead survival object */
12751275
GCObject *dummy; /* dummy out parameter to 'sweepgen' */
12761276
lua_assert(g->gcstate == GCSpropagate);
@@ -1304,12 +1304,12 @@ static void youngcollection (lua_State *L, global_State *g) {
13041304
sweepgen(L, g, &g->tobefnz, NULL, &dummy, &addedold1);
13051305

13061306
/* keep total number of added old1 objects */
1307-
g->marked = marked + addedold1;
1307+
g->GCmarked = marked + addedold1;
13081308

13091309
/* decide whether to shift to major mode */
13101310
if (checkminormajor(g, addedold1)) {
13111311
minor2inc(L, g, KGC_GENMAJOR); /* go to major mode */
1312-
g->marked = 0; /* avoid pause in first major cycle */
1312+
g->GCmarked = 0; /* avoid pause in first major cycle */
13131313
}
13141314
else
13151315
finishgencycle(L, g); /* still in minor mode; finish it */
@@ -1338,8 +1338,8 @@ static void atomic2gen (lua_State *L, global_State *g) {
13381338
sweep2old(L, &g->tobefnz);
13391339

13401340
g->gckind = KGC_GENMINOR;
1341-
g->GCmajorminor = g->marked; /* "base" for number of objects */
1342-
g->marked = 0; /* to count the number of added old1 objects */
1341+
g->GCmajorminor = g->GCmarked; /* "base" for number of objects */
1342+
g->GCmarked = 0; /* to count the number of added old1 objects */
13431343
finishgencycle(L, g);
13441344
}
13451345

@@ -1407,14 +1407,14 @@ static int checkmajorminor (lua_State *L, global_State *g) {
14071407
l_obj numobjs = gettotalobjs(g);
14081408
l_obj addedobjs = numobjs - g->GCmajorminor;
14091409
l_obj limit = applygcparam(g, MAJORMINOR, addedobjs);
1410-
l_obj tobecollected = numobjs - g->marked;
1410+
l_obj tobecollected = numobjs - g->GCmarked;
14111411
if (tobecollected > limit) {
14121412
atomic2gen(L, g); /* return to generational mode */
14131413
setminordebt(g);
14141414
return 0; /* exit incremental collection */
14151415
}
14161416
}
1417-
g->GCmajorminor = g->marked; /* prepare for next collection */
1417+
g->GCmajorminor = g->GCmarked; /* prepare for next collection */
14181418
return 1; /* stay doing incremental collections */
14191419
}
14201420

@@ -1692,7 +1692,7 @@ static void fullinc (lua_State *L, global_State *g) {
16921692
luaC_runtilstate(L, GCSpause, 1);
16931693
luaC_runtilstate(L, GCScallfin, 1); /* run up to finalizers */
16941694
/* 'marked' must be correct after a full GC cycle */
1695-
lua_assert(g->marked == gettotalobjs(g));
1695+
lua_assert(g->GCmarked == gettotalobjs(g));
16961696
luaC_runtilstate(L, GCSpause, 1); /* finish collection */
16971697
setpause(g);
16981698
}

lmem.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ void luaM_free_ (lua_State *L, void *block, size_t osize) {
151151
global_State *g = G(L);
152152
lua_assert((osize == 0) == (block == NULL));
153153
callfrealloc(g, block, osize, 0);
154-
g->totalbytes -= osize;
154+
g->GCtotalbytes -= osize;
155155
}
156156

157157

@@ -181,10 +181,10 @@ void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) {
181181
if (l_unlikely(newblock == NULL && nsize > 0)) {
182182
newblock = tryagain(L, block, osize, nsize);
183183
if (newblock == NULL) /* still no memory? */
184-
return NULL; /* do not update 'totalbytes' */
184+
return NULL; /* do not update 'GCtotalbytes' */
185185
}
186186
lua_assert((nsize == 0) == (newblock == NULL));
187-
g->totalbytes += nsize - osize;
187+
g->GCtotalbytes += nsize - osize;
188188
return newblock;
189189
}
190190

@@ -209,7 +209,7 @@ void *luaM_malloc_ (lua_State *L, size_t size, int tag) {
209209
if (newblock == NULL)
210210
luaM_error(L);
211211
}
212-
g->totalbytes += size;
212+
g->GCtotalbytes += size;
213213
return newblock;
214214
}
215215
}

lstate.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ typedef struct LG {
7474

7575
/*
7676
** set GCdebt to a new value keeping the real number of allocated
77-
** objects (totalobjs - GCdebt) invariant and avoiding overflows in
78-
** 'totalobjs'.
77+
** objects (GCtotalobjs - GCdebt) invariant and avoiding overflows in
78+
** 'GCtotalobjs'.
7979
*/
8080
void luaE_setdebt (global_State *g, l_obj debt) {
8181
l_obj tb = gettotalobjs(g);
8282
lua_assert(tb > 0);
8383
if (debt > MAX_LOBJ - tb)
84-
debt = MAX_LOBJ - tb; /* will make 'totalobjs == MAX_LMEM' */
85-
g->totalobjs = tb + debt;
84+
debt = MAX_LOBJ - tb; /* will make GCtotalobjs == MAX_LOBJ */
85+
g->GCtotalobjs = tb + debt;
8686
g->GCdebt = debt;
8787
}
8888

@@ -269,7 +269,7 @@ static void close_state (lua_State *L) {
269269
}
270270
luaM_freearray(L, G(L)->strt.hash, cast_sizet(G(L)->strt.size));
271271
freestack(L);
272-
lua_assert(g->totalbytes == sizeof(LG));
272+
lua_assert(g->GCtotalbytes == sizeof(LG));
273273
lua_assert(gettotalobjs(g) == 1);
274274
(*g->frealloc)(g->ud, fromstate(L), sizeof(LG), 0); /* free main block */
275275
}
@@ -378,9 +378,9 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud, unsigned seed) {
378378
g->gray = g->grayagain = NULL;
379379
g->weak = g->ephemeron = g->allweak = NULL;
380380
g->twups = NULL;
381-
g->totalbytes = sizeof(LG);
382-
g->totalobjs = 1;
383-
g->marked = 0;
381+
g->GCtotalbytes = sizeof(LG);
382+
g->GCtotalobjs = 1;
383+
g->GCmarked = 0;
384384
g->GCdebt = 0;
385385
setivalue(&g->nilvalue, 0); /* to signal that state is not yet built */
386386
setgcparam(g, PAUSE, LUAI_GCPAUSE);

lstate.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,10 @@ struct CallInfo {
274274
typedef struct global_State {
275275
lua_Alloc frealloc; /* function to reallocate memory */
276276
void *ud; /* auxiliary data to 'frealloc' */
277-
lu_mem totalbytes; /* number of bytes currently allocated */
278-
l_obj totalobjs; /* total number of objects allocated + GCdebt */
277+
lu_mem GCtotalbytes; /* number of bytes currently allocated */
278+
l_obj GCtotalobjs; /* total number of objects allocated + GCdebt */
279279
l_obj GCdebt; /* objects counted but not yet allocated */
280-
l_obj marked; /* number of objects marked in a GC cycle */
280+
l_obj GCmarked; /* number of objects marked in a GC cycle */
281281
l_obj GCmajorminor; /* auxiliary counter to control major-minor shifts */
282282
stringtable strt; /* hash table for strings */
283283
TValue l_registry;
@@ -412,7 +412,7 @@ union GCUnion {
412412

413413

414414
/* actual number of total objects allocated */
415-
#define gettotalobjs(g) ((g)->totalobjs - (g)->GCdebt)
415+
#define gettotalobjs(g) ((g)->GCtotalobjs - (g)->GCdebt)
416416

417417

418418
LUAI_FUNC void luaE_setdebt (global_State *g, l_obj debt);

0 commit comments

Comments
 (0)