aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-04-19 14:02:50 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-04-19 14:02:50 -0300
commitc7bdc0e0e8ab03820b472a87b87c04475def5997 (patch)
tree991bf63ed4a9f108411529db4db468334d686dc2
parenta45945b6d511b00b1c84dc73881474030737e956 (diff)
downloadlua-c7bdc0e0e8ab03820b472a87b87c04475def5997.tar.gz
lua-c7bdc0e0e8ab03820b472a87b87c04475def5997.tar.bz2
lua-c7bdc0e0e8ab03820b472a87b87c04475def5997.zip
first version of control for the generational collector
-rw-r--r--lapi.c6
-rw-r--r--lgc.c18
-rw-r--r--lstate.h4
3 files changed, 21 insertions, 7 deletions
diff --git a/lapi.c b/lapi.c
index eb67d090..9bd4a55b 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.261 2017/04/06 13:08:56 roberto Exp roberto $ 2** $Id: lapi.c,v 2.262 2017/04/11 18:41:09 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*/
@@ -1098,6 +1098,10 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
1098 break; 1098 break;
1099 } 1099 }
1100 case LUA_GCGEN: { 1100 case LUA_GCGEN: {
1101 lu_byte aux = data & 0xff;
1102 g->genminormul = (aux == 0) ? 20 : aux;
1103 aux = (data >> 8) & 0xff;
1104 g->genmajormul = (aux == 0) ? 100 : aux;
1101 luaC_changemode(L, KGC_GEN); 1105 luaC_changemode(L, KGC_GEN);
1102 break; 1106 break;
1103 } 1107 }
diff --git a/lgc.c b/lgc.c
index c8d401e6..9995fbed 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 2.221 2017/04/11 19:00:27 roberto Exp roberto $ 2** $Id: lgc.c,v 2.222 2017/04/12 18:01:40 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*/
@@ -1158,6 +1158,7 @@ static void entergen (lua_State *L, global_State *g) {
1158 1158
1159 finishgencycle(L, g); 1159 finishgencycle(L, g);
1160 g->gckind = KGC_GEN; 1160 g->gckind = KGC_GEN;
1161 g->GCestimate = gettotalbytes(g); /* base for memory control */
1161} 1162}
1162 1163
1163 1164
@@ -1205,10 +1206,17 @@ static void fullgen (lua_State *L, global_State *g) {
1205** collection. (We still has to implement the full control.) 1206** collection. (We still has to implement the full control.)
1206*/ 1207*/
1207static void genstep (lua_State *L, global_State *g) { 1208static void genstep (lua_State *L, global_State *g) {
1208 lu_mem mem; 1209 lu_mem majorbase = g->GCestimate;
1209 youngcollection(L, g); 1210lua_checkmemory(L);
1210 mem = gettotalbytes(g); 1211 if (gettotalbytes(g) > (majorbase / 100) * (100 + g->genmajormul))
1211 luaE_setdebt(g, -((mem / 100) * 20)); 1212 fullgen(L, g);
1213 else {
1214 lu_mem mem;
1215 youngcollection(L, g);
1216 mem = gettotalbytes(g);
1217 luaE_setdebt(g, -((mem / 100) * g->genminormul));
1218 g->GCestimate = mem;
1219 }
1212lua_checkmemory(L); 1220lua_checkmemory(L);
1213} 1221}
1214 1222
diff --git a/lstate.h b/lstate.h
index dc74370b..d844fc8c 100644
--- a/lstate.h
+++ b/lstate.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.h,v 2.136 2017/04/05 16:50:51 roberto Exp roberto $ 2** $Id: lstate.h,v 2.137 2017/04/11 18:41:09 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*/
@@ -148,6 +148,8 @@ typedef struct global_State {
148 lu_byte currentwhite; 148 lu_byte currentwhite;
149 lu_byte gcstate; /* state of garbage collector */ 149 lu_byte gcstate; /* state of garbage collector */
150 lu_byte gckind; /* kind of GC running */ 150 lu_byte gckind; /* kind of GC running */
151 lu_byte genminormul; /* control for minor generational collections */
152 lu_byte genmajormul; /* control for major generational collections */
151 lu_byte gcrunning; /* true if GC is running */ 153 lu_byte gcrunning; /* true if GC is running */
152 GCObject *allgc; /* list of all collectable objects */ 154 GCObject *allgc; /* list of all collectable objects */
153 GCObject **sweepgc; /* current position of sweep in list */ 155 GCObject **sweepgc; /* current position of sweep in list */