lua

A copy of the Lua development repository
Log | Files | Refs | README

commit 90b0ac6495cb5b4f06b795bef3da346a55581284
parent de3b1c9b53d74de4f22fe75b801cc57e1ba2840e
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date:   Thu, 13 Feb 2014 15:24:55 -0200

limit to 'gcstepmul' imposed by 'lua_gc' (+ some details in 'lgc.c')

Diffstat:
Mlapi.c | 3++-
Mlgc.c | 29++++++++++++++++++-----------
2 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/lapi.c b/lapi.c @@ -1,5 +1,5 @@ /* -** $Id: lapi.c,v 2.193 2014/01/27 13:34:32 roberto Exp roberto $ +** $Id: lapi.c,v 2.194 2014/02/13 12:11:34 roberto Exp roberto $ ** Lua API ** See Copyright Notice in lua.h */ @@ -1086,6 +1086,7 @@ LUA_API int lua_gc (lua_State *L, int what, int data) { } case LUA_GCSETSTEPMUL: { res = g->gcstepmul; + if (data < 40) data = 40; /* avoid ridiculous low values (and 0) */ g->gcstepmul = data; break; } diff --git a/lgc.c b/lgc.c @@ -1,5 +1,5 @@ /* -** $Id: lgc.c,v 2.171 2014/02/13 12:11:34 roberto Exp roberto $ +** $Id: lgc.c,v 2.172 2014/02/13 14:46:38 roberto Exp roberto $ ** Garbage Collector ** See Copyright Notice in lua.h */ @@ -1060,9 +1060,9 @@ void luaC_runtilstate (lua_State *L, int statesmask) { /* -** run a few finalizers +** run a few (up to 'g->gcfinnum') finalizers */ -static int dosomefinalization (lua_State *L) { +static int runafewfinalizers (lua_State *L) { global_State *g = G(L); unsigned int i; lua_assert(!g->tobefnz || g->gcfinnum > 0); @@ -1075,19 +1075,26 @@ static int dosomefinalization (lua_State *L) { /* -** performs a basic GC step +** get GC debt and convert it from Kb to 'work units' (avoid zero debt +** and overflows) */ -void luaC_forcestep (lua_State *L) { - global_State *g = G(L); +static l_mem getdebt (global_State *g) { l_mem debt = g->GCdebt; int stepmul = g->gcstepmul; - if (stepmul < 40) stepmul = 40; /* avoid ridiculous low values (and 0) */ - /* convert debt from Kb to 'work units' (avoid zero debt and overflows) */ debt = (debt / STEPMULADJ) + 1; debt = (debt < MAX_LMEM / stepmul) ? debt * stepmul : MAX_LMEM; + return debt; +} + +/* +** performs a basic GC step +*/ +void luaC_forcestep (lua_State *L) { + global_State *g = G(L); + l_mem debt = getdebt(g); do { if (g->gcstate == GCScallfin && g->tobefnz) { - unsigned int n = dosomefinalization(L); + unsigned int n = runafewfinalizers(L); debt -= (n * GCFINALIZECOST); } else { /* perform one single step */ @@ -1098,9 +1105,9 @@ void luaC_forcestep (lua_State *L) { if (g->gcstate == GCSpause) setpause(g, g->GCestimate); /* pause until next cycle */ else { - debt = (debt / stepmul) * STEPMULADJ; /* convert 'work units' to Kb */ + debt = (debt / g->gcstepmul) * STEPMULADJ; /* convert 'work units' to Kb */ luaE_setdebt(g, debt); - dosomefinalization(L); + runafewfinalizers(L); } }