aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2004-12-13 10:15:11 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2004-12-13 10:15:11 -0200
commitc6254dceffca200e4111f28af4230b6c892ec0d6 (patch)
treec9a122ae3c1d28cad4d9f8ed5578a8be18d0a27d
parenta56d889f7225a3cfdfa6dfeb55db2b4ae22f1572 (diff)
downloadlua-c6254dceffca200e4111f28af4230b6c892ec0d6.tar.gz
lua-c6254dceffca200e4111f28af4230b6c892ec0d6.tar.bz2
lua-c6254dceffca200e4111f28af4230b6c892ec0d6.zip
a different option for the GC
-rw-r--r--lapi.c8
-rw-r--r--lbaselib.c6
-rw-r--r--lgc.c10
-rw-r--r--llimits.h4
-rw-r--r--lstate.c4
-rw-r--r--lstate.h4
-rw-r--r--lua.h4
7 files changed, 21 insertions, 19 deletions
diff --git a/lapi.c b/lapi.c
index 9447f929..15133a8a 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.21 2004/12/03 20:50:25 roberto Exp roberto $ 2** $Id: lapi.c,v 2.22 2004/12/06 17:53:42 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -867,9 +867,9 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
867 luaC_step(L); 867 luaC_step(L);
868 break; 868 break;
869 } 869 }
870 case LUA_GCSETSTEPMUL: { 870 case LUA_GCSETPACE: {
871 res = g->stepmul; 871 res = g->gcpace;
872 g->stepmul = data; 872 g->gcpace = data;
873 break; 873 break;
874 } 874 }
875 case LUA_GCSETINCMODE: { 875 case LUA_GCSETINCMODE: {
diff --git a/lbaselib.c b/lbaselib.c
index f9b565e3..8278ddb0 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbaselib.c,v 1.161 2004/12/06 17:53:42 roberto Exp roberto $ 2** $Id: lbaselib.c,v 1.162 2004/12/07 18:31:34 roberto Exp roberto $
3** Basic library 3** Basic library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -182,9 +182,9 @@ static int luaB_gcinfo (lua_State *L) {
182 182
183static int luaB_collectgarbage (lua_State *L) { 183static int luaB_collectgarbage (lua_State *L) {
184 static const char *const opts[] = {"stop", "restart", "collect", 184 static const char *const opts[] = {"stop", "restart", "collect",
185 "count", "step", "setstepmul", "setincmode", NULL}; 185 "count", "step", "setpace", "setincmode", NULL};
186 static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT, 186 static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT,
187 LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETSTEPMUL, LUA_GCSETINCMODE}; 187 LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPACE, LUA_GCSETINCMODE};
188 int o = luaL_findstring(luaL_optstring(L, 1, "collect"), opts); 188 int o = luaL_findstring(luaL_optstring(L, 1, "collect"), opts);
189 int ex = luaL_optint(L, 2, 0); 189 int ex = luaL_optint(L, 2, 0);
190 luaL_argcheck(L, o >= 0, 1, "invalid option"); 190 luaL_argcheck(L, o >= 0, 1, "invalid option");
diff --git a/lgc.c b/lgc.c
index ae6af687..f401505c 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 2.17 2004/11/24 19:20:21 roberto Exp roberto $ 2** $Id: lgc.c,v 2.18 2004/12/06 17:53:42 roberto Exp roberto $
3** Garbage Collector 3** Garbage Collector
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -27,6 +27,7 @@
27#define GCSWEEPMAX 10 27#define GCSWEEPMAX 10
28#define GCSWEEPCOST 30 28#define GCSWEEPCOST 30
29#define GCFINALIZECOST 100 29#define GCFINALIZECOST 100
30#define GCSTEPMUL 8
30 31
31 32
32#define FIXEDMASK bitmask(FIXEDBIT) 33#define FIXEDMASK bitmask(FIXEDBIT)
@@ -621,18 +622,17 @@ static l_mem singlestep (lua_State *L) {
621 622
622void luaC_step (lua_State *L) { 623void luaC_step (lua_State *L) {
623 global_State *g = G(L); 624 global_State *g = G(L);
624 l_mem lim = (g->totalbytes - (g->GCthreshold - GCSTEPSIZE)) * g->stepmul; 625 l_mem lim = (g->totalbytes - (g->GCthreshold - GCSTEPSIZE)) * GCSTEPMUL;
625 do { 626 do {
626 lim -= singlestep(L); 627 lim -= singlestep(L);
627 if (g->gcstate == GCSpause) 628 if (g->gcstate == GCSpause)
628 break; 629 break;
629 } while (lim > 0 || !g->incgc); 630 } while (lim > 0 || !g->incgc);
630 if (g->incgc) 631 if (g->gcstate != GCSpause)
631 g->GCthreshold = g->totalbytes + GCSTEPSIZE; /* - lim/STEPMUL; */ 632 g->GCthreshold = g->totalbytes + GCSTEPSIZE; /* - lim/STEPMUL; */
632 else { 633 else {
633 lua_assert(g->totalbytes >= g->estimate); 634 lua_assert(g->totalbytes >= g->estimate);
634 lua_assert(g->gcstate == GCSpause); 635 g->GCthreshold = g->estimate + ((g->estimate/GCDIV) * g->gcpace);
635 g->GCthreshold = 2*g->estimate;
636 } 636 }
637} 637}
638 638
diff --git a/llimits.h b/llimits.h
index 1c9bc4e6..efbe3898 100644
--- a/llimits.h
+++ b/llimits.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llimits.h,v 1.60 2004/09/10 17:30:46 roberto Exp roberto $ 2** $Id: llimits.h,v 1.61 2004/11/24 18:55:56 roberto Exp roberto $
3** Limits, basic types, and some other `installation-dependent' definitions 3** Limits, basic types, and some other `installation-dependent' definitions
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -73,6 +73,8 @@ typedef LUA_UACNUMBER l_uacNumber;
73typedef lu_int32 Instruction; 73typedef lu_int32 Instruction;
74 74
75 75
76/* divisor for GC pace */
77#define GCDIV 8
76 78
77/* maximum stack for a Lua function */ 79/* maximum stack for a Lua function */
78#define MAXSTACK 250 80#define MAXSTACK 250
diff --git a/lstate.c b/lstate.c
index 021b8a68..35e3ed80 100644
--- a/lstate.c
+++ b/lstate.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.c,v 2.17 2004/11/24 19:20:21 roberto Exp roberto $ 2** $Id: lstate.c,v 2.18 2004/12/06 17:53:42 roberto Exp roberto $
3** Global State 3** Global State
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -193,7 +193,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
193 setnilvalue(gval(g->dummynode)); 193 setnilvalue(gval(g->dummynode));
194 gnext(g->dummynode) = NULL; 194 gnext(g->dummynode) = NULL;
195 g->totalbytes = sizeof(LG); 195 g->totalbytes = sizeof(LG);
196 g->stepmul = STEPMUL; 196 g->gcpace = GCDIV;
197 g->incgc = 1; 197 g->incgc = 1;
198 if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) { 198 if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) {
199 /* memory allocation error: free partial state */ 199 /* memory allocation error: free partial state */
diff --git a/lstate.h b/lstate.h
index 612a785e..06a5c5dc 100644
--- a/lstate.h
+++ b/lstate.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.h,v 2.8 2004/09/15 20:39:42 roberto Exp roberto $ 2** $Id: lstate.h,v 2.9 2004/12/06 17:53:42 roberto Exp roberto $
3** Global State 3** Global State
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -85,7 +85,7 @@ typedef struct global_State {
85 lu_mem totalbytes; /* number of bytes currently allocated */ 85 lu_mem totalbytes; /* number of bytes currently allocated */
86 lu_mem estimate; /* an estimate of number of bytes actually in use */ 86 lu_mem estimate; /* an estimate of number of bytes actually in use */
87 lu_mem prevestimate; /* previous estimate */ 87 lu_mem prevestimate; /* previous estimate */
88 int stepmul; /* relative `speed' of the GC */ 88 int gcpace; /* relative `speed' of the GC */
89 int incgc; /* 0 if GC is done non-incrementally */ 89 int incgc; /* 0 if GC is done non-incrementally */
90 lua_CFunction panic; /* to be called in unprotected errors */ 90 lua_CFunction panic; /* to be called in unprotected errors */
91 TValue _registry; 91 TValue _registry;
diff --git a/lua.h b/lua.h
index 80c7f1b3..649ec3fc 100644
--- a/lua.h
+++ b/lua.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.h,v 1.195 2004/12/01 15:50:18 roberto Exp roberto $ 2** $Id: lua.h,v 1.196 2004/12/06 17:53:42 roberto Exp roberto $
3** Lua - An Extensible Extension Language 3** Lua - An Extensible Extension Language
4** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil 4** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil
5** http://www.lua.org mailto:info@lua.org 5** http://www.lua.org mailto:info@lua.org
@@ -225,7 +225,7 @@ LUA_API int lua_threadstatus (lua_State *L);
225#define LUA_GCCOLLECT 2 225#define LUA_GCCOLLECT 2
226#define LUA_GCCOUNT 3 226#define LUA_GCCOUNT 3
227#define LUA_GCSTEP 4 227#define LUA_GCSTEP 4
228#define LUA_GCSETSTEPMUL 5 228#define LUA_GCSETPACE 5
229#define LUA_GCSETINCMODE 6 229#define LUA_GCSETINCMODE 6
230 230
231LUA_API int lua_gc (lua_State *L, int what, int data); 231LUA_API int lua_gc (lua_State *L, int what, int data);