'KGC_NORMAL' -> 'KGC_INC' + emergency GC signalled by flag (instead
of mode)
This commit is contained in:
4
lapi.c
4
lapi.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lapi.c,v 2.263 2017/04/19 17:02:50 roberto Exp roberto $
|
** $Id: lapi.c,v 2.264 2017/04/20 18:22:44 roberto Exp roberto $
|
||||||
** Lua API
|
** Lua API
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -1111,7 +1111,7 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LUA_GCINC: {
|
case LUA_GCINC: {
|
||||||
luaC_changemode(L, KGC_NORMAL);
|
luaC_changemode(L, KGC_INC);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: res = -1; /* invalid option */
|
default: res = -1; /* invalid option */
|
||||||
|
|||||||
23
lgc.c
23
lgc.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lgc.c,v 2.223 2017/04/19 17:02:50 roberto Exp roberto $
|
** $Id: lgc.c,v 2.224 2017/04/20 18:24:33 roberto Exp roberto $
|
||||||
** Garbage Collector
|
** Garbage Collector
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -543,7 +543,7 @@ static lu_mem traversethread (global_State *g, lua_State *th) {
|
|||||||
g->twups = th;
|
g->twups = th;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (g->gckind != KGC_EMERGENCY)
|
else if (!g->gcemergency)
|
||||||
luaD_shrinkstack(th); /* do not change stack in emergency cycle */
|
luaD_shrinkstack(th); /* do not change stack in emergency cycle */
|
||||||
return (sizeof(lua_State) + sizeof(TValue) * th->stacksize +
|
return (sizeof(lua_State) + sizeof(TValue) * th->stacksize +
|
||||||
sizeof(CallInfo) * th->nci);
|
sizeof(CallInfo) * th->nci);
|
||||||
@@ -767,7 +767,7 @@ static GCObject **sweeptolive (lua_State *L, GCObject **p) {
|
|||||||
** If possible, shrink string table
|
** If possible, shrink string table
|
||||||
*/
|
*/
|
||||||
static void checkSizes (lua_State *L, global_State *g) {
|
static void checkSizes (lua_State *L, global_State *g) {
|
||||||
if (g->gckind != KGC_EMERGENCY) {
|
if (!g->gcemergency) {
|
||||||
l_mem olddebt = g->GCdebt;
|
l_mem olddebt = g->GCdebt;
|
||||||
if (g->strt.nuse < g->strt.size / 4) /* string table too big? */
|
if (g->strt.nuse < g->strt.size / 4) /* string table too big? */
|
||||||
luaS_resize(L, g->strt.size / 2); /* shrink it a little */
|
luaS_resize(L, g->strt.size / 2); /* shrink it a little */
|
||||||
@@ -1174,7 +1174,7 @@ static void enterinc (global_State *g) {
|
|||||||
g->finobjrold = g->finobjold = g->finobjsur = NULL;
|
g->finobjrold = g->finobjold = g->finobjsur = NULL;
|
||||||
lua_assert(g->tobefnz == NULL); /* no need to sweep */
|
lua_assert(g->tobefnz == NULL); /* no need to sweep */
|
||||||
g->gcstate = GCSpause;
|
g->gcstate = GCSpause;
|
||||||
g->gckind = KGC_NORMAL;
|
g->gckind = KGC_INC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1278,7 +1278,7 @@ static void deletealllist (lua_State *L, GCObject *p, GCObject *limit) {
|
|||||||
|
|
||||||
void luaC_freeallobjects (lua_State *L) {
|
void luaC_freeallobjects (lua_State *L) {
|
||||||
global_State *g = G(L);
|
global_State *g = G(L);
|
||||||
luaC_changemode(L, KGC_NORMAL);
|
luaC_changemode(L, KGC_INC);
|
||||||
separatetobefnz(g, 1); /* separate all objects with finalizers */
|
separatetobefnz(g, 1); /* separate all objects with finalizers */
|
||||||
lua_assert(g->finobj == NULL);
|
lua_assert(g->finobj == NULL);
|
||||||
callallpendingfinalizers(L);
|
callallpendingfinalizers(L);
|
||||||
@@ -1394,7 +1394,7 @@ static lu_mem singlestep (lua_State *L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
case GCScallfin: { /* call remaining finalizers */
|
case GCScallfin: { /* call remaining finalizers */
|
||||||
if (g->tobefnz && g->gckind != KGC_EMERGENCY) {
|
if (g->tobefnz && !g->gcemergency) {
|
||||||
int n = runafewfinalizers(L);
|
int n = runafewfinalizers(L);
|
||||||
return (n * GCFINALIZECOST);
|
return (n * GCFINALIZECOST);
|
||||||
}
|
}
|
||||||
@@ -1459,7 +1459,7 @@ void luaC_step (lua_State *L) {
|
|||||||
global_State *g = G(L);
|
global_State *g = G(L);
|
||||||
if (!g->gcrunning) /* not running? */
|
if (!g->gcrunning) /* not running? */
|
||||||
luaE_setdebt(g, -GCSTEPSIZE * 10); /* avoid being called too often */
|
luaE_setdebt(g, -GCSTEPSIZE * 10); /* avoid being called too often */
|
||||||
else if (g->gckind == KGC_NORMAL)
|
else if (g->gckind == KGC_INC)
|
||||||
incstep(L, g);
|
incstep(L, g);
|
||||||
else
|
else
|
||||||
genstep(L, g);
|
genstep(L, g);
|
||||||
@@ -1490,14 +1490,13 @@ static void fullinc (lua_State *L, global_State *g) {
|
|||||||
|
|
||||||
void luaC_fullgc (lua_State *L, int isemergency) {
|
void luaC_fullgc (lua_State *L, int isemergency) {
|
||||||
global_State *g = G(L);
|
global_State *g = G(L);
|
||||||
int gckind = g->gckind;
|
lua_assert(!g->gcemergency);
|
||||||
if (isemergency)
|
g->gcemergency = isemergency; /* set flag */
|
||||||
g->gckind = KGC_EMERGENCY; /* set flag */
|
if (g->gckind == KGC_INC)
|
||||||
if (gckind == KGC_NORMAL)
|
|
||||||
fullinc(L, g);
|
fullinc(L, g);
|
||||||
else
|
else
|
||||||
fullgen(L, g);
|
fullgen(L, g);
|
||||||
g->gckind = gckind;
|
g->gcemergency = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }====================================================== */
|
/* }====================================================== */
|
||||||
|
|||||||
5
lstate.c
5
lstate.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lstate.c,v 2.136 2017/04/11 19:00:27 roberto Exp roberto $
|
** $Id: lstate.c,v 2.137 2017/04/12 18:56:25 roberto Exp roberto $
|
||||||
** Global State
|
** Global State
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -209,6 +209,7 @@ static void f_luaopen (lua_State *L, void *ud) {
|
|||||||
luaT_init(L);
|
luaT_init(L);
|
||||||
luaX_init(L);
|
luaX_init(L);
|
||||||
g->gcrunning = 1; /* allow gc */
|
g->gcrunning = 1; /* allow gc */
|
||||||
|
g->gcemergency = 0;
|
||||||
g->version = lua_version(NULL);
|
g->version = lua_version(NULL);
|
||||||
luai_userstateopen(L);
|
luai_userstateopen(L);
|
||||||
}
|
}
|
||||||
@@ -317,7 +318,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
|
|||||||
g->panic = NULL;
|
g->panic = NULL;
|
||||||
g->version = NULL;
|
g->version = NULL;
|
||||||
g->gcstate = GCSpause;
|
g->gcstate = GCSpause;
|
||||||
g->gckind = KGC_NORMAL;
|
g->gckind = KGC_INC;
|
||||||
g->finobj = g->tobefnz = g->fixedgc = NULL;
|
g->finobj = g->tobefnz = g->fixedgc = NULL;
|
||||||
g->survival = g->old = g->reallyold = NULL;
|
g->survival = g->old = g->reallyold = NULL;
|
||||||
g->finobjsur = g->finobjold = g->finobjrold = NULL;
|
g->finobjsur = g->finobjold = g->finobjrold = NULL;
|
||||||
|
|||||||
6
lstate.h
6
lstate.h
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lstate.h,v 2.137 2017/04/11 18:41:09 roberto Exp roberto $
|
** $Id: lstate.h,v 2.138 2017/04/19 17:02:50 roberto Exp roberto $
|
||||||
** Global State
|
** Global State
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -69,9 +69,8 @@ struct lua_longjmp; /* defined in ldo.c */
|
|||||||
|
|
||||||
|
|
||||||
/* kinds of Garbage Collection */
|
/* kinds of Garbage Collection */
|
||||||
#define KGC_NORMAL 0
|
#define KGC_INC 0 /* incremental gc */
|
||||||
#define KGC_GEN 1 /* generational gc */
|
#define KGC_GEN 1 /* generational gc */
|
||||||
#define KGC_EMERGENCY 2 /* gc was forced by an allocation failure */
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct stringtable {
|
typedef struct stringtable {
|
||||||
@@ -151,6 +150,7 @@ typedef struct global_State {
|
|||||||
lu_byte genminormul; /* control for minor generational collections */
|
lu_byte genminormul; /* control for minor generational collections */
|
||||||
lu_byte genmajormul; /* control for major generational collections */
|
lu_byte genmajormul; /* control for major generational collections */
|
||||||
lu_byte gcrunning; /* true if GC is running */
|
lu_byte gcrunning; /* true if GC is running */
|
||||||
|
lu_byte gcemergency; /* true if this is an emergency collection */
|
||||||
GCObject *allgc; /* list of all collectable objects */
|
GCObject *allgc; /* list of all collectable objects */
|
||||||
GCObject **sweepgc; /* current position of sweep in list */
|
GCObject **sweepgc; /* current position of sweep in list */
|
||||||
GCObject *finobj; /* list of collectable objects with finalizers */
|
GCObject *finobj; /* list of collectable objects with finalizers */
|
||||||
|
|||||||
4
ltests.c
4
ltests.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: ltests.c,v 2.213 2017/04/18 19:42:12 roberto Exp roberto $
|
** $Id: ltests.c,v 2.214 2017/04/19 18:46:47 roberto Exp roberto $
|
||||||
** Internal Module for Debugging of the Lua Implementation
|
** Internal Module for Debugging of the Lua Implementation
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -199,7 +199,7 @@ static int testobjref1 (global_State *g, GCObject *f, GCObject *t) {
|
|||||||
if (isdead(g,t)) return 0;
|
if (isdead(g,t)) return 0;
|
||||||
if (issweepphase(g))
|
if (issweepphase(g))
|
||||||
return 1; /* no invariants */
|
return 1; /* no invariants */
|
||||||
else if (g->gckind == KGC_NORMAL)
|
else if (g->gckind == KGC_INC)
|
||||||
return !(isblack(f) && iswhite(t)); /* basic incremental invariant */
|
return !(isblack(f) && iswhite(t)); /* basic incremental invariant */
|
||||||
else { /* generational mode */
|
else { /* generational mode */
|
||||||
if ((getage(f) == G_OLD && isblack(f)) && !isold(t))
|
if ((getage(f) == G_OLD && isblack(f)) && !isold(t))
|
||||||
|
|||||||
Reference in New Issue
Block a user