mirror of
https://github.com/lua/lua
synced 2024-11-22 12:51:30 +03:00
new GC state to sweep 'localgc' list + small changes in sweep control
This commit is contained in:
parent
8ef9e8460e
commit
1bf4faec64
68
lgc.c
68
lgc.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lgc.c,v 2.155 2013/08/28 18:30:26 roberto Exp roberto $
|
||||
** $Id: lgc.c,v 2.156 2013/08/29 13:34:16 roberto Exp roberto $
|
||||
** Garbage Collector
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -979,12 +979,9 @@ static void setpause (global_State *g, l_mem estimate) {
|
||||
}
|
||||
|
||||
|
||||
#define sweepphases (bitmask(GCSsweepudata) | bitmask(GCSsweep))
|
||||
|
||||
|
||||
/*
|
||||
** enter first sweep phase and prepare pointers for other sweep phases.
|
||||
** The calls to 'sweeptolive' make pointers point to an object inside
|
||||
** Enter first sweep phase.
|
||||
** The call to 'sweeptolive' makes pointer point to an object inside
|
||||
** the list (instead of to the header), so that the real sweep do not
|
||||
** need to skip objects created between "now" and the start of the real
|
||||
** sweep.
|
||||
@ -993,11 +990,9 @@ static void setpause (global_State *g, l_mem estimate) {
|
||||
static int entersweep (lua_State *L) {
|
||||
global_State *g = G(L);
|
||||
int n = 0;
|
||||
g->gcstate = GCSsweepudata;
|
||||
lua_assert(g->sweepgc == NULL && g->sweepfin == NULL);
|
||||
/* prepare to sweep finalizable objects and regular objects */
|
||||
g->sweepfin = sweeptolive(L, &g->finobj, &n);
|
||||
g->sweepgc = sweeptolive(L, &g->allgc, &n);
|
||||
g->gcstate = GCSsweeplocal;
|
||||
lua_assert(g->sweepgc == NULL);
|
||||
g->sweepgc = sweeptolive(L, &g->localgc, &n);
|
||||
return n;
|
||||
}
|
||||
|
||||
@ -1068,6 +1063,20 @@ static l_mem atomic (lua_State *L) {
|
||||
}
|
||||
|
||||
|
||||
static lu_mem sweepstep (lua_State *L, global_State *g,
|
||||
int nextstate, GCObject **nextlist) {
|
||||
if (g->sweepgc) { /* is there still something to sweep? */
|
||||
g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX);
|
||||
return (GCSWEEPMAX * GCSWEEPCOST);
|
||||
}
|
||||
else { /* next phase */
|
||||
g->gcstate = nextstate;
|
||||
g->sweepgc = nextlist;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static lu_mem singlestep (lua_State *L) {
|
||||
global_State *g = G(L);
|
||||
switch (g->gcstate) {
|
||||
@ -1096,30 +1105,21 @@ static lu_mem singlestep (lua_State *L) {
|
||||
sw = entersweep(L);
|
||||
return work + sw * GCSWEEPCOST;
|
||||
}
|
||||
case GCSsweepudata: {
|
||||
if (g->sweepfin) {
|
||||
g->sweepfin = sweeplist(L, g->sweepfin, GCSWEEPMAX);
|
||||
return GCSWEEPMAX*GCSWEEPCOST;
|
||||
}
|
||||
else {
|
||||
sweepwholelist(L, &g->localgc);
|
||||
g->gcstate = GCSsweep;
|
||||
return GCLOCALPAUSE / 4; /* some magic for now */
|
||||
}
|
||||
case GCSsweeplocal: {
|
||||
return sweepstep(L, g, GCSsweepfin, &g->finobj);
|
||||
}
|
||||
case GCSsweep: {
|
||||
if (g->sweepgc) {
|
||||
g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX);
|
||||
return GCSWEEPMAX*GCSWEEPCOST;
|
||||
}
|
||||
else {
|
||||
/* sweep main thread */
|
||||
GCObject *mt = obj2gco(g->mainthread);
|
||||
sweeplist(L, &mt, 1);
|
||||
checkBuffer(L);
|
||||
g->gcstate = GCSpause; /* finish collection */
|
||||
return GCSWEEPCOST;
|
||||
}
|
||||
case GCSsweepfin: {
|
||||
return sweepstep(L, g, GCSsweepall, &g->allgc);
|
||||
}
|
||||
case GCSsweepall: {
|
||||
return sweepstep(L, g, GCSsweepmainth, NULL);
|
||||
}
|
||||
case GCSsweepmainth: { /* sweep main thread */
|
||||
GCObject *mt = obj2gco(g->mainthread);
|
||||
sweeplist(L, &mt, 1);
|
||||
checkBuffer(L);
|
||||
g->gcstate = GCSpause; /* finish collection */
|
||||
return GCSWEEPCOST;
|
||||
}
|
||||
default: lua_assert(0); return 0;
|
||||
}
|
||||
|
12
lgc.h
12
lgc.h
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lgc.h,v 2.68 2013/08/27 20:04:00 roberto Exp roberto $
|
||||
** $Id: lgc.h,v 2.69 2013/08/29 13:49:57 roberto Exp roberto $
|
||||
** Garbage Collector
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -38,13 +38,15 @@
|
||||
*/
|
||||
#define GCSpropagate 0
|
||||
#define GCSatomic 1
|
||||
#define GCSsweepudata 2
|
||||
#define GCSsweep 3
|
||||
#define GCSpause 4
|
||||
#define GCSsweeplocal 2
|
||||
#define GCSsweepfin 3
|
||||
#define GCSsweepall 4
|
||||
#define GCSsweepmainth 5
|
||||
#define GCSpause 6
|
||||
|
||||
|
||||
#define issweepphase(g) \
|
||||
(GCSsweepudata <= (g)->gcstate && (g)->gcstate <= GCSsweep)
|
||||
(GCSsweeplocal <= (g)->gcstate && (g)->gcstate <= GCSsweepmainth)
|
||||
|
||||
|
||||
/*
|
||||
|
4
lstate.c
4
lstate.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lstate.c,v 2.107 2013/08/27 18:53:35 roberto Exp roberto $
|
||||
** $Id: lstate.c,v 2.108 2013/08/28 18:30:26 roberto Exp roberto $
|
||||
** Global State
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -301,7 +301,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
|
||||
g->finobj = NULL;
|
||||
g->tobefnz = NULL;
|
||||
g->fixedgc = NULL;
|
||||
g->sweepgc = g->sweepfin = NULL;
|
||||
g->sweepgc = NULL;
|
||||
g->gray = g->grayagain = NULL;
|
||||
g->weak = g->ephemeron = g->allweak = NULL;
|
||||
g->totalbytes = sizeof(LG);
|
||||
|
5
lstate.h
5
lstate.h
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lstate.h,v 2.90 2013/08/26 12:41:10 roberto Exp roberto $
|
||||
** $Id: lstate.h,v 2.91 2013/08/27 18:53:35 roberto Exp roberto $
|
||||
** Global State
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -122,8 +122,7 @@ typedef struct global_State {
|
||||
GCObject *allgc; /* list of all collectable objects */
|
||||
GCObject *localgc; /* list of local objects */
|
||||
GCObject *finobj; /* list of collectable objects with finalizers */
|
||||
GCObject **sweepgc; /* current position of sweep in list 'allgc' */
|
||||
GCObject **sweepfin; /* current position of sweep in list 'finobj' */
|
||||
GCObject **sweepgc; /* current position of sweep in list */
|
||||
GCObject *gray; /* list of gray objects */
|
||||
GCObject *grayagain; /* list of objects to be traversed atomically */
|
||||
GCObject *weak; /* list of tables with weak values */
|
||||
|
5
ltests.c
5
ltests.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: ltests.c,v 2.150 2013/08/27 18:53:35 roberto Exp roberto $
|
||||
** $Id: ltests.c,v 2.151 2013/08/27 20:04:00 roberto Exp roberto $
|
||||
** Internal Module for Debugging of the Lua Implementation
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -653,7 +653,8 @@ static int gc_local (lua_State *L) {
|
||||
|
||||
static int gc_state (lua_State *L) {
|
||||
static const char *statenames[] = {"propagate", "atomic",
|
||||
"sweepudata", "sweep", "pause", ""};
|
||||
"sweeplocal", "sweepfin", "sweepall", "sweepmainth",
|
||||
"pause", ""};
|
||||
int option = luaL_checkoption(L, 1, "", statenames);
|
||||
if (option == GCSpause + 1) {
|
||||
lua_pushstring(L, statenames[G(L)->gcstate]);
|
||||
|
Loading…
Reference in New Issue
Block a user