diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2022-11-23 17:17:20 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2022-11-23 17:17:20 -0300 |
| commit | f356d5acdd9d8e8f7e9d1d7632c4657f945ff4f4 (patch) | |
| tree | baa2abdc9bd4707b42c0609da42aa1130757273b /lstate.c | |
| parent | 76953316d1283ab6324b59b914ef53a521408444 (diff) | |
| download | lua-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.c | 15 |
1 files changed, 8 insertions, 7 deletions
| @@ -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 | */ |
| 89 | void luaE_setdebt (global_State *g, l_mem debt) { | 89 | void 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 */ |
