Browse Source

better to keep GC state numbers sequential, to optimize switch in

'singlestep'
pull/9/head
Roberto Ierusalimschy 15 years ago
parent
commit
8da245bfd2
  1. 16
      lgc.c
  2. 16
      lgc.h
  3. 4
      lstring.c

16
lgc.c

@ -1,5 +1,5 @@
/*
** $Id: lgc.c,v 2.63 2009/11/26 11:39:20 roberto Exp roberto $
** $Id: lgc.c,v 2.64 2009/12/11 19:14:59 roberto Exp roberto $
** Garbage Collector
** See Copyright Notice in lua.h
*/
@ -786,12 +786,12 @@ void luaC_step (lua_State *L) {
/*
** advances the garbage collector until it reaches a "valid" state
** (defined by the caller)
** advances the garbage collector until it reaches a state allowed
** by 'statemask'
*/
void luaC_runtilstate (lua_State *L, int validstates) {
void luaC_runtilstate (lua_State *L, int statesmask) {
global_State *g = G(L);
while (!(g->gcstate & validstates))
while (!testbit(statesmask, g->gcstate))
singlestep(L);
}
@ -811,13 +811,13 @@ void luaC_fullgc (lua_State *L, int isemergency) {
g->gcstate = GCSsweepstring;
}
/* finish any pending sweep phase */
luaC_runtilstate(L, ~(GCSsweepstring | GCSsweep));
luaC_runtilstate(L, ~bit2mask(GCSsweepstring, GCSsweep));
markroot(L); /* start a new collection */
/* run collector up to finalizers */
luaC_runtilstate(L, GCSfinalize);
luaC_runtilstate(L, bitmask(GCSfinalize));
g->gckind = KGC_NORMAL;
if (!isemergency) /* do not run finalizers during emergency GC */
luaC_runtilstate(L, ~GCSfinalize);
luaC_runtilstate(L, ~bitmask(GCSfinalize));
g->GCthreshold = (g->totalbytes/100) * g->gcpause;
}

16
lgc.h

@ -1,5 +1,5 @@
/*
** $Id: lgc.h,v 2.24 2009/11/26 11:39:20 roberto Exp roberto $
** $Id: lgc.h,v 2.25 2009/12/11 19:14:59 roberto Exp roberto $
** Garbage Collector
** See Copyright Notice in lua.h
*/
@ -14,12 +14,12 @@
/*
** Possible states of the Garbage Collector
*/
#define GCSpause 1
#define GCSpropagate 2
#define GCSatomic 4
#define GCSsweepstring 8
#define GCSsweep 16
#define GCSfinalize 32
#define GCSpause 0
#define GCSpropagate 1
#define GCSatomic 2
#define GCSsweepstring 3
#define GCSsweep 4
#define GCSfinalize 5
@ -96,7 +96,7 @@
LUAI_FUNC void luaC_separateudata (lua_State *L, int all);
LUAI_FUNC void luaC_freeallobjects (lua_State *L);
LUAI_FUNC void luaC_step (lua_State *L);
LUAI_FUNC void luaC_runtilstate (lua_State *L, int validstates);
LUAI_FUNC void luaC_runtilstate (lua_State *L, int statesmask);
LUAI_FUNC void luaC_fullgc (lua_State *L, int isemergency);
LUAI_FUNC void luaC_link (lua_State *L, GCObject *o, lu_byte tt);
LUAI_FUNC void luaC_linkupval (lua_State *L, UpVal *uv);

4
lstring.c

@ -1,5 +1,5 @@
/*
** $Id: lstring.c,v 2.13 2009/04/29 17:09:41 roberto Exp roberto $
** $Id: lstring.c,v 2.14 2009/12/11 19:14:59 roberto Exp roberto $
** String table (keeps all strings handled by Lua)
** See Copyright Notice in lua.h
*/
@ -23,7 +23,7 @@ void luaS_resize (lua_State *L, int newsize) {
int i;
stringtable *tb = &G(L)->strt;
/* cannot resize while GC is traversing strings */
luaC_runtilstate(L, ~GCSsweepstring);
luaC_runtilstate(L, ~bitmask(GCSsweepstring));
if (newsize > tb->size) {
luaM_reallocvector(L, tb->hash, tb->size, newsize, GCObject *);
for (i = tb->size; i < newsize; i++) tb->hash[i] = NULL;

Loading…
Cancel
Save