aboutsummaryrefslogtreecommitdiff
path: root/lstate.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2022-11-23 17:17:20 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2022-11-23 17:17:20 -0300
commitf356d5acdd9d8e8f7e9d1d7632c4657f945ff4f4 (patch)
treebaa2abdc9bd4707b42c0609da42aa1130757273b /lstate.c
parent76953316d1283ab6324b59b914ef53a521408444 (diff)
downloadlua-f356d5acdd9d8e8f7e9d1d7632c4657f945ff4f4.tar.gz
lua-f356d5acdd9d8e8f7e9d1d7632c4657f945ff4f4.tar.bz2
lua-f356d5acdd9d8e8f7e9d1d7632c4657f945ff4f4.zip
First version of GC counting objects for control
Still needs to review generational mode.
Diffstat (limited to 'lstate.c')
-rw-r--r--lstate.c15
1 files changed, 8 insertions, 7 deletions
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) {
83 83
84 84
85/* 85/*
86** set GCdebt to a new value keeping the value (totalbytes + GCdebt) 86** set GCdebt to a new value keeping the value (totalobjs + GCdebt)
87** invariant (and avoiding underflows in 'totalbytes') 87** invariant (and avoiding underflows in 'totalobjs')
88*/ 88*/
89void luaE_setdebt (global_State *g, l_mem debt) { 89void luaE_setdebt (global_State *g, l_mem debt) {
90 l_mem tb = gettotalbytes(g); 90 l_mem tb = gettotalobjs(g);
91 lua_assert(tb > 0); 91 lua_assert(tb > 0);
92 if (debt < tb - MAX_LMEM) 92 if (debt < tb - MAX_LMEM)
93 debt = tb - MAX_LMEM; /* will make 'totalbytes == MAX_LMEM' */ 93 debt = tb - MAX_LMEM; /* will make 'totalobjs == MAX_LMEM' */
94 g->totalbytes = tb - debt; 94 g->totalobjs = tb - debt;
95 g->GCdebt = debt; 95 g->GCdebt = debt;
96} 96}
97 97
@@ -278,8 +278,8 @@ static void close_state (lua_State *L) {
278 } 278 }
279 luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size); 279 luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size);
280 freestack(L); 280 freestack(L);
281 lua_assert(gettotalbytes(g) == sizeof(LG)); 281 lua_assert(g->totalbytes == sizeof(LG));
282 lua_assert(g->totalobjs == 1); 282 lua_assert(gettotalobjs(g) == 1);
283 (*g->frealloc)(g->ud, fromstate(L), sizeof(LG), 0); /* free main block */ 283 (*g->frealloc)(g->ud, fromstate(L), sizeof(LG), 0); /* free main block */
284} 284}
285 285
@@ -389,6 +389,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
389 g->twups = NULL; 389 g->twups = NULL;
390 g->totalbytes = sizeof(LG); 390 g->totalbytes = sizeof(LG);
391 g->totalobjs = 1; 391 g->totalobjs = 1;
392 g->marked = 0;
392 g->GCdebt = 0; 393 g->GCdebt = 0;
393 g->lastatomic = 0; 394 g->lastatomic = 0;
394 setivalue(&g->nilvalue, 0); /* to signal that state is not yet built */ 395 setivalue(&g->nilvalue, 0); /* to signal that state is not yet built */