'l_mem' renamed to 'l_obj' to count objects
This commit is contained in:
6
lapi.c
6
lapi.c
@@ -1163,7 +1163,7 @@ LUA_API int lua_gc (lua_State *L, int what, ...) {
|
|||||||
}
|
}
|
||||||
case LUA_GCSTEP: {
|
case LUA_GCSTEP: {
|
||||||
int data = va_arg(argp, int);
|
int data = va_arg(argp, int);
|
||||||
l_mem debt = 1; /* =1 to signal that it did an actual step */
|
l_obj debt = 1; /* =1 to signal that it did an actual step */
|
||||||
lu_byte oldstp = g->gcstp;
|
lu_byte oldstp = g->gcstp;
|
||||||
g->gcstp = 0; /* allow GC to run (GCSTPGC must be zero here) */
|
g->gcstp = 0; /* allow GC to run (GCSTPGC must be zero here) */
|
||||||
if (data == 0) {
|
if (data == 0) {
|
||||||
@@ -1217,8 +1217,8 @@ LUA_API int lua_gc (lua_State *L, int what, ...) {
|
|||||||
if (stepmul != 0)
|
if (stepmul != 0)
|
||||||
setgcparam(g->gcstepmul, stepmul);
|
setgcparam(g->gcstepmul, stepmul);
|
||||||
if (stepsize != 0)
|
if (stepsize != 0)
|
||||||
g->gcstepsize = (stepsize <= log2maxs(l_mem)) ? stepsize
|
g->gcstepsize = (stepsize <= log2maxs(l_obj)) ? stepsize
|
||||||
: log2maxs(l_mem);
|
: log2maxs(l_obj);
|
||||||
luaC_changemode(L, KGC_INC);
|
luaC_changemode(L, KGC_INC);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
50
lgc.c
50
lgc.c
@@ -93,7 +93,7 @@
|
|||||||
#define markobjectN(g,t) { if (t) markobject(g,t); }
|
#define markobjectN(g,t) { if (t) markobject(g,t); }
|
||||||
|
|
||||||
static void reallymarkobject (global_State *g, GCObject *o);
|
static void reallymarkobject (global_State *g, GCObject *o);
|
||||||
static l_mem atomic (lua_State *L);
|
static l_obj atomic (lua_State *L);
|
||||||
static void entersweep (lua_State *L);
|
static void entersweep (lua_State *L);
|
||||||
|
|
||||||
|
|
||||||
@@ -335,9 +335,9 @@ static void markmt (global_State *g) {
|
|||||||
/*
|
/*
|
||||||
** mark all objects in list of being-finalized
|
** mark all objects in list of being-finalized
|
||||||
*/
|
*/
|
||||||
static l_mem markbeingfnz (global_State *g) {
|
static l_obj markbeingfnz (global_State *g) {
|
||||||
GCObject *o;
|
GCObject *o;
|
||||||
l_mem count = 0;
|
l_obj count = 0;
|
||||||
for (o = g->tobefnz; o != NULL; o = o->next) {
|
for (o = g->tobefnz; o != NULL; o = o->next) {
|
||||||
count++;
|
count++;
|
||||||
markobject(g, o);
|
markobject(g, o);
|
||||||
@@ -357,8 +357,8 @@ static l_mem markbeingfnz (global_State *g) {
|
|||||||
** upvalues, as they have nothing to be checked. (If the thread gets an
|
** upvalues, as they have nothing to be checked. (If the thread gets an
|
||||||
** upvalue later, it will be linked in the list again.)
|
** upvalue later, it will be linked in the list again.)
|
||||||
*/
|
*/
|
||||||
static l_mem remarkupvals (global_State *g) {
|
static l_obj remarkupvals (global_State *g) {
|
||||||
l_mem work = 0;
|
l_obj work = 0;
|
||||||
lua_State *thread;
|
lua_State *thread;
|
||||||
lua_State **p = &g->twups;
|
lua_State **p = &g->twups;
|
||||||
while ((thread = *p) != NULL) {
|
while ((thread = *p) != NULL) {
|
||||||
@@ -662,8 +662,8 @@ static void propagatemark (global_State *g) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static l_mem propagateall (global_State *g) {
|
static l_obj propagateall (global_State *g) {
|
||||||
l_mem work = 0;
|
l_obj work = 0;
|
||||||
while (g->gray) {
|
while (g->gray) {
|
||||||
propagatemark(g);
|
propagatemark(g);
|
||||||
work++;
|
work++;
|
||||||
@@ -678,9 +678,9 @@ static l_mem propagateall (global_State *g) {
|
|||||||
** inverts the direction of the traversals, trying to speed up
|
** inverts the direction of the traversals, trying to speed up
|
||||||
** convergence on chains in the same table.
|
** convergence on chains in the same table.
|
||||||
*/
|
*/
|
||||||
static l_mem convergeephemerons (global_State *g) {
|
static l_obj convergeephemerons (global_State *g) {
|
||||||
int changed;
|
int changed;
|
||||||
l_mem work = 0;
|
l_obj work = 0;
|
||||||
int dir = 0;
|
int dir = 0;
|
||||||
do {
|
do {
|
||||||
GCObject *w;
|
GCObject *w;
|
||||||
@@ -715,8 +715,8 @@ static l_mem convergeephemerons (global_State *g) {
|
|||||||
/*
|
/*
|
||||||
** clear entries with unmarked keys from all weaktables in list 'l'
|
** clear entries with unmarked keys from all weaktables in list 'l'
|
||||||
*/
|
*/
|
||||||
static l_mem clearbykeys (global_State *g, GCObject *l) {
|
static l_obj clearbykeys (global_State *g, GCObject *l) {
|
||||||
l_mem work = 0;
|
l_obj work = 0;
|
||||||
for (; l; l = gco2t(l)->gclist) {
|
for (; l; l = gco2t(l)->gclist) {
|
||||||
Table *h = gco2t(l);
|
Table *h = gco2t(l);
|
||||||
Node *limit = gnodelast(h);
|
Node *limit = gnodelast(h);
|
||||||
@@ -737,8 +737,8 @@ static l_mem clearbykeys (global_State *g, GCObject *l) {
|
|||||||
** clear entries with unmarked values from all weaktables in list 'l' up
|
** clear entries with unmarked values from all weaktables in list 'l' up
|
||||||
** to element 'f'
|
** to element 'f'
|
||||||
*/
|
*/
|
||||||
static l_mem clearbyvalues (global_State *g, GCObject *l, GCObject *f) {
|
static l_obj clearbyvalues (global_State *g, GCObject *l, GCObject *f) {
|
||||||
l_mem work = 0;
|
l_obj work = 0;
|
||||||
for (; l != f; l = gco2t(l)->gclist) {
|
for (; l != f; l = gco2t(l)->gclist) {
|
||||||
Table *h = gco2t(l);
|
Table *h = gco2t(l);
|
||||||
Node *n, *limit = gnodelast(h);
|
Node *n, *limit = gnodelast(h);
|
||||||
@@ -1054,7 +1054,7 @@ void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) {
|
|||||||
static void setpause (global_State *g) {
|
static void setpause (global_State *g) {
|
||||||
unsigned int pause = getgcparam(g->gcpause);
|
unsigned int pause = getgcparam(g->gcpause);
|
||||||
lu_mem threshold = g->marked / 8 * pause / 12;
|
lu_mem threshold = g->marked / 8 * pause / 12;
|
||||||
l_mem debt = gettotalobjs(g) - threshold;
|
l_obj debt = gettotalobjs(g) - threshold;
|
||||||
if (debt > 0) debt = 0;
|
if (debt > 0) debt = 0;
|
||||||
luaE_setdebt(g, debt);
|
luaE_setdebt(g, debt);
|
||||||
}
|
}
|
||||||
@@ -1306,7 +1306,7 @@ static void atomic2gen (lua_State *L, global_State *g) {
|
|||||||
** total number of objects grows 'genminormul'%.
|
** total number of objects grows 'genminormul'%.
|
||||||
*/
|
*/
|
||||||
static void setminordebt (global_State *g) {
|
static void setminordebt (global_State *g) {
|
||||||
luaE_setdebt(g, -(cast(l_mem, (gettotalobjs(g) / 100)) * g->genminormul));
|
luaE_setdebt(g, -(cast(l_obj, (gettotalobjs(g) / 100)) * g->genminormul));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1431,8 +1431,8 @@ static void genstep (lua_State *L, global_State *g) {
|
|||||||
if (g->lastatomic != 0) /* last collection was a bad one? */
|
if (g->lastatomic != 0) /* last collection was a bad one? */
|
||||||
stepgenfull(L, g); /* do a full step */
|
stepgenfull(L, g); /* do a full step */
|
||||||
else {
|
else {
|
||||||
l_mem majorbase = g->GCestimate; /* objects after last major collection */
|
l_obj majorbase = g->GCestimate; /* objects after last major collection */
|
||||||
l_mem majorinc = (majorbase / 100) * getgcparam(g->genmajormul);
|
l_obj majorinc = (majorbase / 100) * getgcparam(g->genmajormul);
|
||||||
if (g->GCdebt > 0 && gettotalobjs(g) > majorbase + majorinc) {
|
if (g->GCdebt > 0 && gettotalobjs(g) > majorbase + majorinc) {
|
||||||
g->marked = 0;
|
g->marked = 0;
|
||||||
fullgen(L, g); /* do a major collection */
|
fullgen(L, g); /* do a major collection */
|
||||||
@@ -1512,8 +1512,8 @@ void luaC_freeallobjects (lua_State *L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static l_mem atomic (lua_State *L) {
|
static l_obj atomic (lua_State *L) {
|
||||||
l_mem work = 0;
|
l_obj work = 0;
|
||||||
global_State *g = G(L);
|
global_State *g = G(L);
|
||||||
GCObject *origweak, *origall;
|
GCObject *origweak, *origall;
|
||||||
GCObject *grayagain = g->grayagain; /* save original list */
|
GCObject *grayagain = g->grayagain; /* save original list */
|
||||||
@@ -1558,7 +1558,7 @@ static l_mem atomic (lua_State *L) {
|
|||||||
static void sweepstep (lua_State *L, global_State *g,
|
static void sweepstep (lua_State *L, global_State *g,
|
||||||
int nextstate, GCObject **nextlist) {
|
int nextstate, GCObject **nextlist) {
|
||||||
if (g->sweepgc) {
|
if (g->sweepgc) {
|
||||||
l_mem olddebt = g->GCdebt;
|
l_obj olddebt = g->GCdebt;
|
||||||
g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX);
|
g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX);
|
||||||
g->GCestimate += g->GCdebt - olddebt; /* update estimate */
|
g->GCestimate += g->GCdebt - olddebt; /* update estimate */
|
||||||
}
|
}
|
||||||
@@ -1569,9 +1569,9 @@ static void sweepstep (lua_State *L, global_State *g,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static l_mem singlestep (lua_State *L) {
|
static l_obj singlestep (lua_State *L) {
|
||||||
global_State *g = G(L);
|
global_State *g = G(L);
|
||||||
l_mem work;
|
l_obj work;
|
||||||
lua_assert(!g->gcstopem); /* collector is not reentrant */
|
lua_assert(!g->gcstopem); /* collector is not reentrant */
|
||||||
g->gcstopem = 1; /* no emergency collections while collecting */
|
g->gcstopem = 1; /* no emergency collections while collecting */
|
||||||
switch (g->gcstate) {
|
switch (g->gcstate) {
|
||||||
@@ -1658,10 +1658,10 @@ void luaC_runtilstate (lua_State *L, int statesmask) {
|
|||||||
*/
|
*/
|
||||||
static void incstep (lua_State *L, global_State *g) {
|
static void incstep (lua_State *L, global_State *g) {
|
||||||
int stepmul = (getgcparam(g->gcstepmul) | 1); /* avoid division by 0 */
|
int stepmul = (getgcparam(g->gcstepmul) | 1); /* avoid division by 0 */
|
||||||
l_mem debt = (g->GCdebt / 100) * stepmul;
|
l_obj debt = (g->GCdebt / 100) * stepmul;
|
||||||
l_mem stepsize = cast(l_mem, 1) << g->gcstepsize;
|
l_obj stepsize = cast(l_obj, 1) << g->gcstepsize;
|
||||||
do { /* repeat until pause or enough "credit" (negative debt) */
|
do { /* repeat until pause or enough "credit" (negative debt) */
|
||||||
l_mem work = singlestep(L); /* perform one single step */
|
l_obj work = singlestep(L); /* perform one single step */
|
||||||
debt -= work;
|
debt -= work;
|
||||||
} while (debt > -stepsize && g->gcstate != GCSpause);
|
} while (debt > -stepsize && g->gcstate != GCSpause);
|
||||||
if (g->gcstate == GCSpause)
|
if (g->gcstate == GCSpause)
|
||||||
|
|||||||
14
llimits.h
14
llimits.h
@@ -16,19 +16,21 @@
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** 'lu_mem' and 'l_mem' are unsigned/signed integers big enough to count
|
** 'lu_mem' is an unsigned integer big enough to count the total memory
|
||||||
** the total memory used by Lua (in bytes). Usually, 'size_t' and
|
** used by Lua (in bytes). 'l_obj' is a signed integer big enough to
|
||||||
|
** count the total number of objects used by Lua. (It is negative due
|
||||||
|
** to the use of debt in several computations.) Usually, 'size_t' and
|
||||||
** 'ptrdiff_t' should work, but we use 'long' for 16-bit machines.
|
** 'ptrdiff_t' should work, but we use 'long' for 16-bit machines.
|
||||||
*/
|
*/
|
||||||
#if defined(LUAI_MEM) /* { external definitions? */
|
#if defined(LUAI_MEM) /* { external definitions? */
|
||||||
typedef LUAI_UMEM lu_mem;
|
typedef LUAI_UMEM lu_mem;
|
||||||
typedef LUAI_MEM l_mem;
|
typedef LUAI_MEM l_obj;
|
||||||
#elif LUAI_IS32INT /* }{ */
|
#elif LUAI_IS32INT /* }{ */
|
||||||
typedef size_t lu_mem;
|
typedef size_t lu_mem;
|
||||||
typedef ptrdiff_t l_mem;
|
typedef ptrdiff_t l_obj;
|
||||||
#else /* 16-bit ints */ /* }{ */
|
#else /* 16-bit ints */ /* }{ */
|
||||||
typedef unsigned long lu_mem;
|
typedef unsigned long lu_mem;
|
||||||
typedef long l_mem;
|
typedef long l_obj;
|
||||||
#endif /* } */
|
#endif /* } */
|
||||||
|
|
||||||
|
|
||||||
@@ -47,7 +49,7 @@ typedef signed char ls_byte;
|
|||||||
|
|
||||||
#define MAX_LUMEM ((lu_mem)(~(lu_mem)0))
|
#define MAX_LUMEM ((lu_mem)(~(lu_mem)0))
|
||||||
|
|
||||||
#define MAX_LMEM ((l_mem)(MAX_LUMEM >> 1))
|
#define MAX_LMEM ((l_obj)(MAX_LUMEM >> 1))
|
||||||
|
|
||||||
|
|
||||||
#define MAX_INT INT_MAX /* maximum value of an int */
|
#define MAX_INT INT_MAX /* maximum value of an int */
|
||||||
|
|||||||
4
lstate.c
4
lstate.c
@@ -86,8 +86,8 @@ static unsigned int luai_makeseed (lua_State *L) {
|
|||||||
** set GCdebt to a new value keeping the value (totalobjs + GCdebt)
|
** set GCdebt to a new value keeping the value (totalobjs + GCdebt)
|
||||||
** invariant (and avoiding underflows in 'totalobjs')
|
** invariant (and avoiding underflows in 'totalobjs')
|
||||||
*/
|
*/
|
||||||
void luaE_setdebt (global_State *g, l_mem debt) {
|
void luaE_setdebt (global_State *g, l_obj debt) {
|
||||||
l_mem tb = gettotalobjs(g);
|
l_obj tb = gettotalobjs(g);
|
||||||
lua_assert(tb > 0);
|
lua_assert(tb > 0);
|
||||||
if (debt < tb - MAX_LMEM)
|
if (debt < tb - MAX_LMEM)
|
||||||
debt = tb - MAX_LMEM; /* will make 'totalobjs == MAX_LMEM' */
|
debt = tb - MAX_LMEM; /* will make 'totalobjs == MAX_LMEM' */
|
||||||
|
|||||||
10
lstate.h
10
lstate.h
@@ -249,10 +249,10 @@ typedef struct CallInfo {
|
|||||||
typedef struct global_State {
|
typedef struct global_State {
|
||||||
lua_Alloc frealloc; /* function to reallocate memory */
|
lua_Alloc frealloc; /* function to reallocate memory */
|
||||||
void *ud; /* auxiliary data to 'frealloc' */
|
void *ud; /* auxiliary data to 'frealloc' */
|
||||||
l_mem totalbytes; /* number of bytes currently allocated */
|
lu_mem totalbytes; /* number of bytes currently allocated */
|
||||||
l_mem totalobjs; /* total number of objects allocated - GCdebt */
|
l_obj totalobjs; /* total number of objects allocated - GCdebt */
|
||||||
l_mem GCdebt; /* bytes allocated not yet compensated by the collector */
|
l_obj GCdebt; /* bytes allocated not yet compensated by the collector */
|
||||||
lu_mem marked; /* number of objects marked in a GC cycle */
|
l_obj marked; /* number of objects marked in a GC cycle */
|
||||||
lu_mem GCestimate; /* an estimate of the non-garbage memory in use */
|
lu_mem GCestimate; /* an estimate of the non-garbage memory in use */
|
||||||
lu_mem lastatomic; /* see function 'genstep' in file 'lgc.c' */
|
lu_mem lastatomic; /* see function 'genstep' in file 'lgc.c' */
|
||||||
stringtable strt; /* hash table for strings */
|
stringtable strt; /* hash table for strings */
|
||||||
@@ -391,7 +391,7 @@ union GCUnion {
|
|||||||
#define gettotalobjs(g) ((g)->totalobjs + (g)->GCdebt)
|
#define gettotalobjs(g) ((g)->totalobjs + (g)->GCdebt)
|
||||||
|
|
||||||
|
|
||||||
LUAI_FUNC void luaE_setdebt (global_State *g, l_mem debt);
|
LUAI_FUNC void luaE_setdebt (global_State *g, l_obj debt);
|
||||||
LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);
|
LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);
|
||||||
LUAI_FUNC CallInfo *luaE_extendCI (lua_State *L);
|
LUAI_FUNC CallInfo *luaE_extendCI (lua_State *L);
|
||||||
LUAI_FUNC void luaE_freeCI (lua_State *L);
|
LUAI_FUNC void luaE_freeCI (lua_State *L);
|
||||||
|
|||||||
16
ltests.c
16
ltests.c
@@ -531,7 +531,7 @@ static void checkobject (global_State *g, GCObject *o, int maybedead,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static lu_mem checkgraylist (global_State *g, GCObject *o) {
|
static l_obj checkgraylist (global_State *g, GCObject *o) {
|
||||||
int total = 0; /* count number of elements in the list */
|
int total = 0; /* count number of elements in the list */
|
||||||
cast_void(g); /* better to keep it if we need to print an object */
|
cast_void(g); /* better to keep it if we need to print an object */
|
||||||
while (o) {
|
while (o) {
|
||||||
@@ -560,7 +560,7 @@ static lu_mem checkgraylist (global_State *g, GCObject *o) {
|
|||||||
/*
|
/*
|
||||||
** Check objects in gray lists.
|
** Check objects in gray lists.
|
||||||
*/
|
*/
|
||||||
static lu_mem checkgrays (global_State *g) {
|
static l_obj checkgrays (global_State *g) {
|
||||||
int total = 0; /* count number of elements in all lists */
|
int total = 0; /* count number of elements in all lists */
|
||||||
if (!keepinvariant(g)) return total;
|
if (!keepinvariant(g)) return total;
|
||||||
total += checkgraylist(g, g->gray);
|
total += checkgraylist(g, g->gray);
|
||||||
@@ -577,7 +577,7 @@ static lu_mem checkgrays (global_State *g) {
|
|||||||
** 'count' and check its TESTBIT. (It must have been previously set by
|
** 'count' and check its TESTBIT. (It must have been previously set by
|
||||||
** 'checkgraylist'.)
|
** 'checkgraylist'.)
|
||||||
*/
|
*/
|
||||||
static void incifingray (global_State *g, GCObject *o, lu_mem *count) {
|
static void incifingray (global_State *g, GCObject *o, l_obj *count) {
|
||||||
if (!keepinvariant(g))
|
if (!keepinvariant(g))
|
||||||
return; /* gray lists not being kept in these phases */
|
return; /* gray lists not being kept in these phases */
|
||||||
if (o->tt == LUA_VUPVAL) {
|
if (o->tt == LUA_VUPVAL) {
|
||||||
@@ -594,10 +594,10 @@ static void incifingray (global_State *g, GCObject *o, lu_mem *count) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static lu_mem checklist (global_State *g, int maybedead, int tof,
|
static l_obj checklist (global_State *g, int maybedead, int tof,
|
||||||
GCObject *newl, GCObject *survival, GCObject *old, GCObject *reallyold) {
|
GCObject *newl, GCObject *survival, GCObject *old, GCObject *reallyold) {
|
||||||
GCObject *o;
|
GCObject *o;
|
||||||
lu_mem total = 0; /* number of object that should be in gray lists */
|
l_obj total = 0; /* number of object that should be in gray lists */
|
||||||
for (o = newl; o != survival; o = o->next) {
|
for (o = newl; o != survival; o = o->next) {
|
||||||
checkobject(g, o, maybedead, G_NEW);
|
checkobject(g, o, maybedead, G_NEW);
|
||||||
incifingray(g, o, &total);
|
incifingray(g, o, &total);
|
||||||
@@ -626,8 +626,8 @@ int lua_checkmemory (lua_State *L) {
|
|||||||
global_State *g = G(L);
|
global_State *g = G(L);
|
||||||
GCObject *o;
|
GCObject *o;
|
||||||
int maybedead;
|
int maybedead;
|
||||||
lu_mem totalin; /* total of objects that are in gray lists */
|
l_obj totalin; /* total of objects that are in gray lists */
|
||||||
lu_mem totalshould; /* total of objects that should be in gray lists */
|
l_obj totalshould; /* total of objects that should be in gray lists */
|
||||||
if (keepinvariant(g)) {
|
if (keepinvariant(g)) {
|
||||||
assert(!iswhite(g->mainthread));
|
assert(!iswhite(g->mainthread));
|
||||||
assert(!iswhite(gcvalue(&g->l_registry)));
|
assert(!iswhite(gcvalue(&g->l_registry)));
|
||||||
@@ -1033,7 +1033,7 @@ static int query_inc (lua_State *L) {
|
|||||||
lua_pushinteger(L, g->GCdebt);
|
lua_pushinteger(L, g->GCdebt);
|
||||||
lua_pushinteger(L, getgcparam(g->gcpause));
|
lua_pushinteger(L, getgcparam(g->gcpause));
|
||||||
lua_pushinteger(L, getgcparam(g->gcstepmul));
|
lua_pushinteger(L, getgcparam(g->gcstepmul));
|
||||||
lua_pushinteger(L, cast(l_mem, 1) << g->gcstepsize);
|
lua_pushinteger(L, cast(l_obj, 1) << g->gcstepsize);
|
||||||
return 5;
|
return 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user