diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-09-06 14:38:39 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-09-06 14:38:39 -0300 |
commit | a04e0ffdb9be42a77b5657f46cac8d7faa5a0f43 (patch) | |
tree | eb96915b808cf929015452bd08ca1e5c571683ce | |
parent | 007b8c7a01eaa97d796561a19c7e9af1ec474495 (diff) | |
download | lua-a04e0ffdb9be42a77b5657f46cac8d7faa5a0f43.tar.gz lua-a04e0ffdb9be42a77b5657f46cac8d7faa5a0f43.tar.bz2 lua-a04e0ffdb9be42a77b5657f46cac8d7faa5a0f43.zip |
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'.
-rw-r--r-- | lapi.c | 4 | ||||
-rw-r--r-- | lgc.c | 28 | ||||
-rw-r--r-- | lmem.c | 8 | ||||
-rw-r--r-- | lstate.c | 16 | ||||
-rw-r--r-- | lstate.h | 8 |
5 files changed, 32 insertions, 32 deletions
@@ -1190,11 +1190,11 @@ LUA_API int lua_gc (lua_State *L, int what, ...) { | |||
1190 | } | 1190 | } |
1191 | case LUA_GCCOUNT: { | 1191 | case LUA_GCCOUNT: { |
1192 | /* GC values are expressed in Kbytes: #bytes/2^10 */ | 1192 | /* GC values are expressed in Kbytes: #bytes/2^10 */ |
1193 | res = cast_int(g->totalbytes >> 10); | 1193 | res = cast_int(g->GCtotalbytes >> 10); |
1194 | break; | 1194 | break; |
1195 | } | 1195 | } |
1196 | case LUA_GCCOUNTB: { | 1196 | case LUA_GCCOUNTB: { |
1197 | res = cast_int(g->totalbytes & 0x3ff); | 1197 | res = cast_int(g->GCtotalbytes & 0x3ff); |
1198 | break; | 1198 | break; |
1199 | } | 1199 | } |
1200 | case LUA_GCSTEP: { | 1200 | case LUA_GCSTEP: { |
@@ -290,7 +290,7 @@ GCObject *luaC_newobj (lua_State *L, lu_byte tt, size_t sz) { | |||
290 | ** (only closures can), and a userdata's metatable must be a table. | 290 | ** (only closures can), and a userdata's metatable must be a table. |
291 | */ | 291 | */ |
292 | static void reallymarkobject (global_State *g, GCObject *o) { | 292 | static void reallymarkobject (global_State *g, GCObject *o) { |
293 | g->marked++; | 293 | g->GCmarked++; |
294 | switch (o->tt) { | 294 | switch (o->tt) { |
295 | case LUA_VSHRSTR: | 295 | case LUA_VSHRSTR: |
296 | case LUA_VLNGSTR: { | 296 | case LUA_VLNGSTR: { |
@@ -401,7 +401,7 @@ static void cleargraylists (global_State *g) { | |||
401 | */ | 401 | */ |
402 | static void restartcollection (global_State *g) { | 402 | static void restartcollection (global_State *g) { |
403 | cleargraylists(g); | 403 | cleargraylists(g); |
404 | g->marked = NFIXED; | 404 | g->GCmarked = NFIXED; |
405 | markobject(g, g->mainthread); | 405 | markobject(g, g->mainthread); |
406 | markvalue(g, &g->l_registry); | 406 | markvalue(g, &g->l_registry); |
407 | markmt(g); | 407 | markmt(g); |
@@ -781,7 +781,7 @@ static void freeupval (lua_State *L, UpVal *uv) { | |||
781 | 781 | ||
782 | 782 | ||
783 | static void freeobj (lua_State *L, GCObject *o) { | 783 | static void freeobj (lua_State *L, GCObject *o) { |
784 | G(L)->totalobjs--; | 784 | G(L)->GCtotalobjs--; |
785 | switch (o->tt) { | 785 | switch (o->tt) { |
786 | case LUA_VPROTO: | 786 | case LUA_VPROTO: |
787 | luaF_freeproto(L, gco2p(o)); | 787 | luaF_freeproto(L, gco2p(o)); |
@@ -1052,7 +1052,7 @@ void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) { | |||
1052 | ** approximately (marked * pause / 100). | 1052 | ** approximately (marked * pause / 100). |
1053 | */ | 1053 | */ |
1054 | static void setpause (global_State *g) { | 1054 | static void setpause (global_State *g) { |
1055 | l_obj threshold = applygcparam(g, PAUSE, g->marked); | 1055 | l_obj threshold = applygcparam(g, PAUSE, g->GCmarked); |
1056 | l_obj debt = threshold - gettotalobjs(g); | 1056 | l_obj debt = threshold - gettotalobjs(g); |
1057 | if (debt < 0) debt = 0; | 1057 | if (debt < 0) debt = 0; |
1058 | luaE_setdebt(g, debt); | 1058 | luaE_setdebt(g, debt); |
@@ -1236,7 +1236,7 @@ static void finishgencycle (lua_State *L, global_State *g) { | |||
1236 | ** in generational mode. | 1236 | ** in generational mode. |
1237 | */ | 1237 | */ |
1238 | static void minor2inc (lua_State *L, global_State *g, lu_byte kind) { | 1238 | 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 */ |
1240 | g->gckind = kind; | 1240 | g->gckind = kind; |
1241 | g->reallyold = g->old1 = g->survival = NULL; | 1241 | g->reallyold = g->old1 = g->survival = NULL; |
1242 | g->finobjrold = g->finobjold1 = g->finobjsur = NULL; | 1242 | g->finobjrold = g->finobjold1 = g->finobjsur = NULL; |
@@ -1260,7 +1260,7 @@ static void minor2inc (lua_State *L, global_State *g, lu_byte kind) { | |||
1260 | static int checkminormajor (global_State *g, l_obj addedold1) { | 1260 | static int checkminormajor (global_State *g, l_obj addedold1) { |
1261 | l_obj step = applygcparam(g, MINORMUL, g->GCmajorminor); | 1261 | l_obj step = applygcparam(g, MINORMUL, g->GCmajorminor); |
1262 | l_obj limit = applygcparam(g, MINORMAJOR, g->GCmajorminor); | 1262 | l_obj limit = applygcparam(g, MINORMAJOR, g->GCmajorminor); |
1263 | return (addedold1 >= (step >> 1) || g->marked >= limit); | 1263 | return (addedold1 >= (step >> 1) || g->GCmarked >= limit); |
1264 | } | 1264 | } |
1265 | 1265 | ||
1266 | /* | 1266 | /* |
@@ -1270,7 +1270,7 @@ static int checkminormajor (global_State *g, l_obj addedold1) { | |||
1270 | */ | 1270 | */ |
1271 | static void youngcollection (lua_State *L, global_State *g) { | 1271 | static void youngcollection (lua_State *L, global_State *g) { |
1272 | l_obj addedold1 = 0; | 1272 | l_obj addedold1 = 0; |
1273 | l_obj marked = g->marked; /* preserve 'g->marked' */ | 1273 | l_obj marked = g->GCmarked; /* preserve 'g->GCmarked' */ |
1274 | GCObject **psurvival; /* to point to first non-dead survival object */ | 1274 | GCObject **psurvival; /* to point to first non-dead survival object */ |
1275 | GCObject *dummy; /* dummy out parameter to 'sweepgen' */ | 1275 | GCObject *dummy; /* dummy out parameter to 'sweepgen' */ |
1276 | lua_assert(g->gcstate == GCSpropagate); | 1276 | lua_assert(g->gcstate == GCSpropagate); |
@@ -1304,12 +1304,12 @@ static void youngcollection (lua_State *L, global_State *g) { | |||
1304 | sweepgen(L, g, &g->tobefnz, NULL, &dummy, &addedold1); | 1304 | sweepgen(L, g, &g->tobefnz, NULL, &dummy, &addedold1); |
1305 | 1305 | ||
1306 | /* keep total number of added old1 objects */ | 1306 | /* keep total number of added old1 objects */ |
1307 | g->marked = marked + addedold1; | 1307 | g->GCmarked = marked + addedold1; |
1308 | 1308 | ||
1309 | /* decide whether to shift to major mode */ | 1309 | /* decide whether to shift to major mode */ |
1310 | if (checkminormajor(g, addedold1)) { | 1310 | if (checkminormajor(g, addedold1)) { |
1311 | minor2inc(L, g, KGC_GENMAJOR); /* go to major mode */ | 1311 | 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 */ |
1313 | } | 1313 | } |
1314 | else | 1314 | else |
1315 | finishgencycle(L, g); /* still in minor mode; finish it */ | 1315 | finishgencycle(L, g); /* still in minor mode; finish it */ |
@@ -1338,8 +1338,8 @@ static void atomic2gen (lua_State *L, global_State *g) { | |||
1338 | sweep2old(L, &g->tobefnz); | 1338 | sweep2old(L, &g->tobefnz); |
1339 | 1339 | ||
1340 | g->gckind = KGC_GENMINOR; | 1340 | g->gckind = KGC_GENMINOR; |
1341 | g->GCmajorminor = g->marked; /* "base" for number of objects */ | 1341 | g->GCmajorminor = g->GCmarked; /* "base" for number of objects */ |
1342 | g->marked = 0; /* to count the number of added old1 objects */ | 1342 | g->GCmarked = 0; /* to count the number of added old1 objects */ |
1343 | finishgencycle(L, g); | 1343 | finishgencycle(L, g); |
1344 | } | 1344 | } |
1345 | 1345 | ||
@@ -1407,14 +1407,14 @@ static int checkmajorminor (lua_State *L, global_State *g) { | |||
1407 | l_obj numobjs = gettotalobjs(g); | 1407 | l_obj numobjs = gettotalobjs(g); |
1408 | l_obj addedobjs = numobjs - g->GCmajorminor; | 1408 | l_obj addedobjs = numobjs - g->GCmajorminor; |
1409 | l_obj limit = applygcparam(g, MAJORMINOR, addedobjs); | 1409 | l_obj limit = applygcparam(g, MAJORMINOR, addedobjs); |
1410 | l_obj tobecollected = numobjs - g->marked; | 1410 | l_obj tobecollected = numobjs - g->GCmarked; |
1411 | if (tobecollected > limit) { | 1411 | if (tobecollected > limit) { |
1412 | atomic2gen(L, g); /* return to generational mode */ | 1412 | atomic2gen(L, g); /* return to generational mode */ |
1413 | setminordebt(g); | 1413 | setminordebt(g); |
1414 | return 0; /* exit incremental collection */ | 1414 | return 0; /* exit incremental collection */ |
1415 | } | 1415 | } |
1416 | } | 1416 | } |
1417 | g->GCmajorminor = g->marked; /* prepare for next collection */ | 1417 | g->GCmajorminor = g->GCmarked; /* prepare for next collection */ |
1418 | return 1; /* stay doing incremental collections */ | 1418 | return 1; /* stay doing incremental collections */ |
1419 | } | 1419 | } |
1420 | 1420 | ||
@@ -1692,7 +1692,7 @@ static void fullinc (lua_State *L, global_State *g) { | |||
1692 | luaC_runtilstate(L, GCSpause, 1); | 1692 | luaC_runtilstate(L, GCSpause, 1); |
1693 | luaC_runtilstate(L, GCScallfin, 1); /* run up to finalizers */ | 1693 | luaC_runtilstate(L, GCScallfin, 1); /* run up to finalizers */ |
1694 | /* 'marked' must be correct after a full GC cycle */ | 1694 | /* 'marked' must be correct after a full GC cycle */ |
1695 | lua_assert(g->marked == gettotalobjs(g)); | 1695 | lua_assert(g->GCmarked == gettotalobjs(g)); |
1696 | luaC_runtilstate(L, GCSpause, 1); /* finish collection */ | 1696 | luaC_runtilstate(L, GCSpause, 1); /* finish collection */ |
1697 | setpause(g); | 1697 | setpause(g); |
1698 | } | 1698 | } |
@@ -151,7 +151,7 @@ void luaM_free_ (lua_State *L, void *block, size_t osize) { | |||
151 | global_State *g = G(L); | 151 | global_State *g = G(L); |
152 | lua_assert((osize == 0) == (block == NULL)); | 152 | lua_assert((osize == 0) == (block == NULL)); |
153 | callfrealloc(g, block, osize, 0); | 153 | callfrealloc(g, block, osize, 0); |
154 | g->totalbytes -= osize; | 154 | g->GCtotalbytes -= osize; |
155 | } | 155 | } |
156 | 156 | ||
157 | 157 | ||
@@ -181,10 +181,10 @@ void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { | |||
181 | if (l_unlikely(newblock == NULL && nsize > 0)) { | 181 | if (l_unlikely(newblock == NULL && nsize > 0)) { |
182 | newblock = tryagain(L, block, osize, nsize); | 182 | newblock = tryagain(L, block, osize, nsize); |
183 | if (newblock == NULL) /* still no memory? */ | 183 | if (newblock == NULL) /* still no memory? */ |
184 | return NULL; /* do not update 'totalbytes' */ | 184 | return NULL; /* do not update 'GCtotalbytes' */ |
185 | } | 185 | } |
186 | lua_assert((nsize == 0) == (newblock == NULL)); | 186 | lua_assert((nsize == 0) == (newblock == NULL)); |
187 | g->totalbytes += nsize - osize; | 187 | g->GCtotalbytes += nsize - osize; |
188 | return newblock; | 188 | return newblock; |
189 | } | 189 | } |
190 | 190 | ||
@@ -209,7 +209,7 @@ void *luaM_malloc_ (lua_State *L, size_t size, int tag) { | |||
209 | if (newblock == NULL) | 209 | if (newblock == NULL) |
210 | luaM_error(L); | 210 | luaM_error(L); |
211 | } | 211 | } |
212 | g->totalbytes += size; | 212 | g->GCtotalbytes += size; |
213 | return newblock; | 213 | return newblock; |
214 | } | 214 | } |
215 | } | 215 | } |
@@ -74,15 +74,15 @@ typedef struct LG { | |||
74 | 74 | ||
75 | /* | 75 | /* |
76 | ** set GCdebt to a new value keeping the real number of allocated | 76 | ** set GCdebt to a new value keeping the real number of allocated |
77 | ** objects (totalobjs - GCdebt) invariant and avoiding overflows in | 77 | ** objects (GCtotalobjs - GCdebt) invariant and avoiding overflows in |
78 | ** 'totalobjs'. | 78 | ** 'GCtotalobjs'. |
79 | */ | 79 | */ |
80 | void luaE_setdebt (global_State *g, l_obj debt) { | 80 | void luaE_setdebt (global_State *g, l_obj debt) { |
81 | l_obj tb = gettotalobjs(g); | 81 | l_obj tb = gettotalobjs(g); |
82 | lua_assert(tb > 0); | 82 | lua_assert(tb > 0); |
83 | if (debt > MAX_LOBJ - tb) | 83 | if (debt > MAX_LOBJ - tb) |
84 | debt = MAX_LOBJ - tb; /* will make 'totalobjs == MAX_LMEM' */ | 84 | debt = MAX_LOBJ - tb; /* will make GCtotalobjs == MAX_LOBJ */ |
85 | g->totalobjs = tb + debt; | 85 | g->GCtotalobjs = tb + debt; |
86 | g->GCdebt = debt; | 86 | g->GCdebt = debt; |
87 | } | 87 | } |
88 | 88 | ||
@@ -269,7 +269,7 @@ static void close_state (lua_State *L) { | |||
269 | } | 269 | } |
270 | luaM_freearray(L, G(L)->strt.hash, cast_sizet(G(L)->strt.size)); | 270 | luaM_freearray(L, G(L)->strt.hash, cast_sizet(G(L)->strt.size)); |
271 | freestack(L); | 271 | freestack(L); |
272 | lua_assert(g->totalbytes == sizeof(LG)); | 272 | lua_assert(g->GCtotalbytes == sizeof(LG)); |
273 | lua_assert(gettotalobjs(g) == 1); | 273 | lua_assert(gettotalobjs(g) == 1); |
274 | (*g->frealloc)(g->ud, fromstate(L), sizeof(LG), 0); /* free main block */ | 274 | (*g->frealloc)(g->ud, fromstate(L), sizeof(LG), 0); /* free main block */ |
275 | } | 275 | } |
@@ -378,9 +378,9 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud, unsigned seed) { | |||
378 | g->gray = g->grayagain = NULL; | 378 | g->gray = g->grayagain = NULL; |
379 | g->weak = g->ephemeron = g->allweak = NULL; | 379 | g->weak = g->ephemeron = g->allweak = NULL; |
380 | g->twups = NULL; | 380 | g->twups = NULL; |
381 | g->totalbytes = sizeof(LG); | 381 | g->GCtotalbytes = sizeof(LG); |
382 | g->totalobjs = 1; | 382 | g->GCtotalobjs = 1; |
383 | g->marked = 0; | 383 | g->GCmarked = 0; |
384 | g->GCdebt = 0; | 384 | g->GCdebt = 0; |
385 | setivalue(&g->nilvalue, 0); /* to signal that state is not yet built */ | 385 | setivalue(&g->nilvalue, 0); /* to signal that state is not yet built */ |
386 | setgcparam(g, PAUSE, LUAI_GCPAUSE); | 386 | setgcparam(g, PAUSE, LUAI_GCPAUSE); |
@@ -274,10 +274,10 @@ struct CallInfo { | |||
274 | typedef struct global_State { | 274 | typedef struct global_State { |
275 | lua_Alloc frealloc; /* function to reallocate memory */ | 275 | lua_Alloc frealloc; /* function to reallocate memory */ |
276 | void *ud; /* auxiliary data to 'frealloc' */ | 276 | void *ud; /* auxiliary data to 'frealloc' */ |
277 | lu_mem totalbytes; /* number of bytes currently allocated */ | 277 | lu_mem GCtotalbytes; /* number of bytes currently allocated */ |
278 | l_obj totalobjs; /* total number of objects allocated + GCdebt */ | 278 | l_obj GCtotalobjs; /* total number of objects allocated + GCdebt */ |
279 | l_obj GCdebt; /* objects counted but not yet allocated */ | 279 | 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 */ |
281 | l_obj GCmajorminor; /* auxiliary counter to control major-minor shifts */ | 281 | l_obj GCmajorminor; /* auxiliary counter to control major-minor shifts */ |
282 | stringtable strt; /* hash table for strings */ | 282 | stringtable strt; /* hash table for strings */ |
283 | TValue l_registry; | 283 | TValue l_registry; |
@@ -412,7 +412,7 @@ union GCUnion { | |||
412 | 412 | ||
413 | 413 | ||
414 | /* actual number of total objects allocated */ | 414 | /* actual number of total objects allocated */ |
415 | #define gettotalobjs(g) ((g)->totalobjs - (g)->GCdebt) | 415 | #define gettotalobjs(g) ((g)->GCtotalobjs - (g)->GCdebt) |
416 | 416 | ||
417 | 417 | ||
418 | LUAI_FUNC void luaE_setdebt (global_State *g, l_obj debt); | 418 | LUAI_FUNC void luaE_setdebt (global_State *g, l_obj debt); |