mirror of
https://github.com/lua/lua
synced 2025-01-06 01:22:06 +03:00
new parameter 'majorinc' to control frequency of major collections
in generational mode
This commit is contained in:
parent
daa5fe3e31
commit
6828f6d427
7
lapi.c
7
lapi.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lapi.c,v 2.133 2010/07/25 15:18:19 roberto Exp roberto $
|
||||
** $Id: lapi.c,v 2.134 2010/08/04 18:40:28 roberto Exp roberto $
|
||||
** Lua API
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -976,6 +976,11 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
|
||||
g->gcpause = data;
|
||||
break;
|
||||
}
|
||||
case LUA_GCSETMAJORINC: {
|
||||
res = g->gcmajorinc;
|
||||
g->gcmajorinc = data;
|
||||
break;
|
||||
}
|
||||
case LUA_GCSETSTEPMUL: {
|
||||
res = g->gcstepmul;
|
||||
g->gcstepmul = data;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lbaselib.c,v 1.246 2010/07/02 11:38:13 roberto Exp roberto $
|
||||
** $Id: lbaselib.c,v 1.247 2010/08/23 18:03:11 roberto Exp roberto $
|
||||
** Basic library
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -142,11 +142,11 @@ static int luaB_rawset (lua_State *L) {
|
||||
|
||||
static int luaB_collectgarbage (lua_State *L) {
|
||||
static const char *const opts[] = {"stop", "restart", "collect",
|
||||
"count", "step", "setpause", "setstepmul", "isrunning",
|
||||
"gen", "inc", NULL};
|
||||
"count", "step", "setpause", "setstepmul",
|
||||
"setmajorinc", "isrunning", "gen", "inc", NULL};
|
||||
static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT,
|
||||
LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL,
|
||||
LUA_GCISRUNNING, LUA_GCGEN, LUA_GCINC};
|
||||
LUA_GCSETMAJORINC, LUA_GCISRUNNING, LUA_GCGEN, LUA_GCINC};
|
||||
int o = optsnum[luaL_checkoption(L, 1, "collect", opts)];
|
||||
int ex = luaL_optint(L, 2, 0);
|
||||
int res = lua_gc(L, o, ex);
|
||||
|
4
lgc.c
4
lgc.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lgc.c,v 2.100 2010/06/25 12:18:10 roberto Exp roberto $
|
||||
** $Id: lgc.c,v 2.101 2010/06/30 14:11:17 roberto Exp roberto $
|
||||
** Garbage Collector
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -960,7 +960,7 @@ static void generationalcollection (lua_State *L) {
|
||||
else {
|
||||
luaC_runtilstate(L, ~bitmask(GCSpause)); /* run complete cycle */
|
||||
luaC_runtilstate(L, bitmask(GCSpause));
|
||||
if (g->totalbytes > g->lastmajormem/100 * g->gcpause)
|
||||
if (g->totalbytes > g->lastmajormem/100 * g->gcmajorinc)
|
||||
g->lastmajormem = 0; /* signal for a major collection */
|
||||
}
|
||||
g->GCdebt = stddebt(g);
|
||||
|
7
lstate.c
7
lstate.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lstate.c,v 2.84 2010/04/30 14:22:23 roberto Exp roberto $
|
||||
** $Id: lstate.c,v 2.85 2010/04/30 18:36:22 roberto Exp roberto $
|
||||
** Global State
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -29,6 +29,10 @@
|
||||
#define LUAI_GCPAUSE 200 /* 200% */
|
||||
#endif
|
||||
|
||||
#if !defined(LUAI_GCMAJOR)
|
||||
#define LUAI_GCMAJOR 200 /* 200% */
|
||||
#endif
|
||||
|
||||
#if !defined(LUAI_GCMUL)
|
||||
#define LUAI_GCMUL 200 /* GC runs 'twice the speed' of memory allocation */
|
||||
#endif
|
||||
@ -254,6 +258,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
|
||||
g->weak = g->ephemeron = g->allweak = NULL;
|
||||
g->totalbytes = sizeof(LG);
|
||||
g->gcpause = LUAI_GCPAUSE;
|
||||
g->gcmajorinc = LUAI_GCMAJOR;
|
||||
g->gcstepmul = LUAI_GCMUL;
|
||||
for (i=0; i < LUA_NUMTAGS; i++) g->mt[i] = NULL;
|
||||
if (luaD_rawrunprotected(L, f_luaopen, NULL) != LUA_OK) {
|
||||
|
3
lstate.h
3
lstate.h
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lstate.h,v 2.64 2010/04/29 17:31:31 roberto Exp roberto $
|
||||
** $Id: lstate.h,v 2.65 2010/05/03 17:39:48 roberto Exp roberto $
|
||||
** Global State
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -136,6 +136,7 @@ typedef struct global_State {
|
||||
UpVal uvhead; /* head of double-linked list of all open upvalues */
|
||||
Mbuffer buff; /* temporary buffer for string concatenation */
|
||||
int gcpause; /* size of pause between successive GCs */
|
||||
int gcmajorinc; /* how much to wait for a major GC (only in gen. mode) */
|
||||
int gcstepmul; /* GC `granularity' */
|
||||
lua_CFunction panic; /* to be called in unprotected errors */
|
||||
struct lua_State *mainthread;
|
||||
|
9
lua.h
9
lua.h
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lua.h,v 1.272 2010/07/25 15:02:41 roberto Exp roberto $
|
||||
** $Id: lua.h,v 1.273 2010/07/25 15:18:19 roberto Exp roberto $
|
||||
** Lua - A Scripting Language
|
||||
** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
|
||||
** See Copyright Notice at the end of this file
|
||||
@ -271,9 +271,10 @@ LUA_API int (lua_status) (lua_State *L);
|
||||
#define LUA_GCSTEP 5
|
||||
#define LUA_GCSETPAUSE 6
|
||||
#define LUA_GCSETSTEPMUL 7
|
||||
#define LUA_GCISRUNNING 8
|
||||
#define LUA_GCGEN 9
|
||||
#define LUA_GCINC 10
|
||||
#define LUA_GCSETMAJORINC 8
|
||||
#define LUA_GCISRUNNING 9
|
||||
#define LUA_GCGEN 10
|
||||
#define LUA_GCINC 11
|
||||
|
||||
LUA_API int (lua_gc) (lua_State *L, int what, int data);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user