mirror of https://github.com/rusefi/lua.git
a different option for the GC
This commit is contained in:
parent
a56d889f72
commit
c6254dceff
8
lapi.c
8
lapi.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lapi.c,v 2.21 2004/12/03 20:50:25 roberto Exp roberto $
|
** $Id: lapi.c,v 2.22 2004/12/06 17:53:42 roberto Exp roberto $
|
||||||
** Lua API
|
** Lua API
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -867,9 +867,9 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
|
||||||
luaC_step(L);
|
luaC_step(L);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LUA_GCSETSTEPMUL: {
|
case LUA_GCSETPACE: {
|
||||||
res = g->stepmul;
|
res = g->gcpace;
|
||||||
g->stepmul = data;
|
g->gcpace = data;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LUA_GCSETINCMODE: {
|
case LUA_GCSETINCMODE: {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lbaselib.c,v 1.161 2004/12/06 17:53:42 roberto Exp roberto $
|
** $Id: lbaselib.c,v 1.162 2004/12/07 18:31:34 roberto Exp roberto $
|
||||||
** Basic library
|
** Basic library
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -182,9 +182,9 @@ static int luaB_gcinfo (lua_State *L) {
|
||||||
|
|
||||||
static int luaB_collectgarbage (lua_State *L) {
|
static int luaB_collectgarbage (lua_State *L) {
|
||||||
static const char *const opts[] = {"stop", "restart", "collect",
|
static const char *const opts[] = {"stop", "restart", "collect",
|
||||||
"count", "step", "setstepmul", "setincmode", NULL};
|
"count", "step", "setpace", "setincmode", NULL};
|
||||||
static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT,
|
static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT,
|
||||||
LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETSTEPMUL, LUA_GCSETINCMODE};
|
LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPACE, LUA_GCSETINCMODE};
|
||||||
int o = luaL_findstring(luaL_optstring(L, 1, "collect"), opts);
|
int o = luaL_findstring(luaL_optstring(L, 1, "collect"), opts);
|
||||||
int ex = luaL_optint(L, 2, 0);
|
int ex = luaL_optint(L, 2, 0);
|
||||||
luaL_argcheck(L, o >= 0, 1, "invalid option");
|
luaL_argcheck(L, o >= 0, 1, "invalid option");
|
||||||
|
|
10
lgc.c
10
lgc.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lgc.c,v 2.17 2004/11/24 19:20:21 roberto Exp roberto $
|
** $Id: lgc.c,v 2.18 2004/12/06 17:53:42 roberto Exp roberto $
|
||||||
** Garbage Collector
|
** Garbage Collector
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -27,6 +27,7 @@
|
||||||
#define GCSWEEPMAX 10
|
#define GCSWEEPMAX 10
|
||||||
#define GCSWEEPCOST 30
|
#define GCSWEEPCOST 30
|
||||||
#define GCFINALIZECOST 100
|
#define GCFINALIZECOST 100
|
||||||
|
#define GCSTEPMUL 8
|
||||||
|
|
||||||
|
|
||||||
#define FIXEDMASK bitmask(FIXEDBIT)
|
#define FIXEDMASK bitmask(FIXEDBIT)
|
||||||
|
@ -621,18 +622,17 @@ static l_mem singlestep (lua_State *L) {
|
||||||
|
|
||||||
void luaC_step (lua_State *L) {
|
void luaC_step (lua_State *L) {
|
||||||
global_State *g = G(L);
|
global_State *g = G(L);
|
||||||
l_mem lim = (g->totalbytes - (g->GCthreshold - GCSTEPSIZE)) * g->stepmul;
|
l_mem lim = (g->totalbytes - (g->GCthreshold - GCSTEPSIZE)) * GCSTEPMUL;
|
||||||
do {
|
do {
|
||||||
lim -= singlestep(L);
|
lim -= singlestep(L);
|
||||||
if (g->gcstate == GCSpause)
|
if (g->gcstate == GCSpause)
|
||||||
break;
|
break;
|
||||||
} while (lim > 0 || !g->incgc);
|
} while (lim > 0 || !g->incgc);
|
||||||
if (g->incgc)
|
if (g->gcstate != GCSpause)
|
||||||
g->GCthreshold = g->totalbytes + GCSTEPSIZE; /* - lim/STEPMUL; */
|
g->GCthreshold = g->totalbytes + GCSTEPSIZE; /* - lim/STEPMUL; */
|
||||||
else {
|
else {
|
||||||
lua_assert(g->totalbytes >= g->estimate);
|
lua_assert(g->totalbytes >= g->estimate);
|
||||||
lua_assert(g->gcstate == GCSpause);
|
g->GCthreshold = g->estimate + ((g->estimate/GCDIV) * g->gcpace);
|
||||||
g->GCthreshold = 2*g->estimate;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: llimits.h,v 1.60 2004/09/10 17:30:46 roberto Exp roberto $
|
** $Id: llimits.h,v 1.61 2004/11/24 18:55:56 roberto Exp roberto $
|
||||||
** Limits, basic types, and some other `installation-dependent' definitions
|
** Limits, basic types, and some other `installation-dependent' definitions
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -73,6 +73,8 @@ typedef LUA_UACNUMBER l_uacNumber;
|
||||||
typedef lu_int32 Instruction;
|
typedef lu_int32 Instruction;
|
||||||
|
|
||||||
|
|
||||||
|
/* divisor for GC pace */
|
||||||
|
#define GCDIV 8
|
||||||
|
|
||||||
/* maximum stack for a Lua function */
|
/* maximum stack for a Lua function */
|
||||||
#define MAXSTACK 250
|
#define MAXSTACK 250
|
||||||
|
|
4
lstate.c
4
lstate.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lstate.c,v 2.17 2004/11/24 19:20:21 roberto Exp roberto $
|
** $Id: lstate.c,v 2.18 2004/12/06 17:53:42 roberto Exp roberto $
|
||||||
** Global State
|
** Global State
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -193,7 +193,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
|
||||||
setnilvalue(gval(g->dummynode));
|
setnilvalue(gval(g->dummynode));
|
||||||
gnext(g->dummynode) = NULL;
|
gnext(g->dummynode) = NULL;
|
||||||
g->totalbytes = sizeof(LG);
|
g->totalbytes = sizeof(LG);
|
||||||
g->stepmul = STEPMUL;
|
g->gcpace = GCDIV;
|
||||||
g->incgc = 1;
|
g->incgc = 1;
|
||||||
if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) {
|
if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) {
|
||||||
/* memory allocation error: free partial state */
|
/* memory allocation error: free partial state */
|
||||||
|
|
4
lstate.h
4
lstate.h
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lstate.h,v 2.8 2004/09/15 20:39:42 roberto Exp roberto $
|
** $Id: lstate.h,v 2.9 2004/12/06 17:53:42 roberto Exp roberto $
|
||||||
** Global State
|
** Global State
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -85,7 +85,7 @@ typedef struct global_State {
|
||||||
lu_mem totalbytes; /* number of bytes currently allocated */
|
lu_mem totalbytes; /* number of bytes currently allocated */
|
||||||
lu_mem estimate; /* an estimate of number of bytes actually in use */
|
lu_mem estimate; /* an estimate of number of bytes actually in use */
|
||||||
lu_mem prevestimate; /* previous estimate */
|
lu_mem prevestimate; /* previous estimate */
|
||||||
int stepmul; /* relative `speed' of the GC */
|
int gcpace; /* relative `speed' of the GC */
|
||||||
int incgc; /* 0 if GC is done non-incrementally */
|
int incgc; /* 0 if GC is done non-incrementally */
|
||||||
lua_CFunction panic; /* to be called in unprotected errors */
|
lua_CFunction panic; /* to be called in unprotected errors */
|
||||||
TValue _registry;
|
TValue _registry;
|
||||||
|
|
4
lua.h
4
lua.h
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lua.h,v 1.195 2004/12/01 15:50:18 roberto Exp roberto $
|
** $Id: lua.h,v 1.196 2004/12/06 17:53:42 roberto Exp roberto $
|
||||||
** Lua - An Extensible Extension Language
|
** Lua - An Extensible Extension Language
|
||||||
** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil
|
** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil
|
||||||
** http://www.lua.org mailto:info@lua.org
|
** http://www.lua.org mailto:info@lua.org
|
||||||
|
@ -225,7 +225,7 @@ LUA_API int lua_threadstatus (lua_State *L);
|
||||||
#define LUA_GCCOLLECT 2
|
#define LUA_GCCOLLECT 2
|
||||||
#define LUA_GCCOUNT 3
|
#define LUA_GCCOUNT 3
|
||||||
#define LUA_GCSTEP 4
|
#define LUA_GCSTEP 4
|
||||||
#define LUA_GCSETSTEPMUL 5
|
#define LUA_GCSETPACE 5
|
||||||
#define LUA_GCSETINCMODE 6
|
#define LUA_GCSETINCMODE 6
|
||||||
|
|
||||||
LUA_API int lua_gc (lua_State *L, int what, int data);
|
LUA_API int lua_gc (lua_State *L, int what, int data);
|
||||||
|
|
Loading…
Reference in New Issue