From c6254dceffca200e4111f28af4230b6c892ec0d6 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 13 Dec 2004 10:15:11 -0200 Subject: a different option for the GC --- lapi.c | 8 ++++---- lbaselib.c | 6 +++--- lgc.c | 10 +++++----- llimits.h | 4 +++- lstate.c | 4 ++-- lstate.h | 4 ++-- lua.h | 4 ++-- 7 files changed, 21 insertions(+), 19 deletions(-) diff --git a/lapi.c b/lapi.c index 9447f929..15133a8a 100644 --- a/lapi.c +++ b/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 ** 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); break; } - case LUA_GCSETSTEPMUL: { - res = g->stepmul; - g->stepmul = data; + case LUA_GCSETPACE: { + res = g->gcpace; + g->gcpace = data; break; } case LUA_GCSETINCMODE: { diff --git a/lbaselib.c b/lbaselib.c index f9b565e3..8278ddb0 100644 --- a/lbaselib.c +++ b/lbaselib.c @@ -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 ** 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 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, - 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 ex = luaL_optint(L, 2, 0); luaL_argcheck(L, o >= 0, 1, "invalid option"); diff --git a/lgc.c b/lgc.c index ae6af687..f401505c 100644 --- a/lgc.c +++ b/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 ** See Copyright Notice in lua.h */ @@ -27,6 +27,7 @@ #define GCSWEEPMAX 10 #define GCSWEEPCOST 30 #define GCFINALIZECOST 100 +#define GCSTEPMUL 8 #define FIXEDMASK bitmask(FIXEDBIT) @@ -621,18 +622,17 @@ static l_mem singlestep (lua_State *L) { void luaC_step (lua_State *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 { lim -= singlestep(L); if (g->gcstate == GCSpause) break; } while (lim > 0 || !g->incgc); - if (g->incgc) + if (g->gcstate != GCSpause) g->GCthreshold = g->totalbytes + GCSTEPSIZE; /* - lim/STEPMUL; */ else { lua_assert(g->totalbytes >= g->estimate); - lua_assert(g->gcstate == GCSpause); - g->GCthreshold = 2*g->estimate; + g->GCthreshold = g->estimate + ((g->estimate/GCDIV) * g->gcpace); } } diff --git a/llimits.h b/llimits.h index 1c9bc4e6..efbe3898 100644 --- a/llimits.h +++ b/llimits.h @@ -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 ** See Copyright Notice in lua.h */ @@ -73,6 +73,8 @@ typedef LUA_UACNUMBER l_uacNumber; typedef lu_int32 Instruction; +/* divisor for GC pace */ +#define GCDIV 8 /* maximum stack for a Lua function */ #define MAXSTACK 250 diff --git a/lstate.c b/lstate.c index 021b8a68..35e3ed80 100644 --- a/lstate.c +++ b/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 ** 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)); gnext(g->dummynode) = NULL; g->totalbytes = sizeof(LG); - g->stepmul = STEPMUL; + g->gcpace = GCDIV; g->incgc = 1; if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) { /* memory allocation error: free partial state */ diff --git a/lstate.h b/lstate.h index 612a785e..06a5c5dc 100644 --- a/lstate.h +++ b/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 ** See Copyright Notice in lua.h */ @@ -85,7 +85,7 @@ typedef struct global_State { lu_mem totalbytes; /* number of bytes currently allocated */ lu_mem estimate; /* an estimate of number of bytes actually in use */ 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 */ lua_CFunction panic; /* to be called in unprotected errors */ TValue _registry; diff --git a/lua.h b/lua.h index 80c7f1b3..649ec3fc 100644 --- a/lua.h +++ b/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 ** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil ** 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_GCCOUNT 3 #define LUA_GCSTEP 4 -#define LUA_GCSETSTEPMUL 5 +#define LUA_GCSETPACE 5 #define LUA_GCSETINCMODE 6 LUA_API int lua_gc (lua_State *L, int what, int data); -- cgit v1.2.3-55-g6feb