Explorar o código

first version of control for the generational collector

Roberto Ierusalimschy %!s(int64=8) %!d(string=hai) anos
pai
achega
c7bdc0e0e8
Modificáronse 3 ficheiros con 21 adicións e 7 borrados
  1. 5 1
      lapi.c
  2. 13 5
      lgc.c
  3. 3 1
      lstate.h

+ 5 - 1
lapi.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lapi.c,v 2.261 2017/04/06 13:08:56 roberto Exp roberto $
+** $Id: lapi.c,v 2.262 2017/04/11 18:41:09 roberto Exp roberto $
 ** Lua API
 ** See Copyright Notice in lua.h
 */
@@ -1098,6 +1098,10 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
       break;
     }
     case LUA_GCGEN: {
+      lu_byte aux = data & 0xff;
+      g->genminormul = (aux == 0) ? 20 : aux;
+      aux = (data >> 8) & 0xff;
+      g->genmajormul = (aux == 0) ? 100 : aux;
       luaC_changemode(L, KGC_GEN);
       break;
     }

+ 13 - 5
lgc.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lgc.c,v 2.221 2017/04/11 19:00:27 roberto Exp roberto $
+** $Id: lgc.c,v 2.222 2017/04/12 18:01:40 roberto Exp roberto $
 ** Garbage Collector
 ** See Copyright Notice in lua.h
 */
@@ -1158,6 +1158,7 @@ static void entergen (lua_State *L, global_State *g) {
 
   finishgencycle(L, g);
   g->gckind = KGC_GEN;
+  g->GCestimate = gettotalbytes(g);  /* base for memory control */
 }
 
 
@@ -1205,10 +1206,17 @@ static void fullgen (lua_State *L, global_State *g) {
 ** collection. (We still has to implement the full control.)
 */
 static void genstep (lua_State *L, global_State *g) {
-  lu_mem mem;
-  youngcollection(L, g);
-  mem = gettotalbytes(g);
-  luaE_setdebt(g, -((mem / 100) * 20));
+  lu_mem majorbase = g->GCestimate;
+lua_checkmemory(L);
+  if (gettotalbytes(g) > (majorbase / 100) * (100 + g->genmajormul))
+    fullgen(L, g);
+  else {
+    lu_mem mem;
+    youngcollection(L, g);
+    mem = gettotalbytes(g);
+    luaE_setdebt(g, -((mem / 100) * g->genminormul));
+    g->GCestimate = mem;
+  }
 lua_checkmemory(L);
 }
 

+ 3 - 1
lstate.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lstate.h,v 2.136 2017/04/05 16:50:51 roberto Exp roberto $
+** $Id: lstate.h,v 2.137 2017/04/11 18:41:09 roberto Exp roberto $
 ** Global State
 ** See Copyright Notice in lua.h
 */
@@ -148,6 +148,8 @@ typedef struct global_State {
   lu_byte currentwhite;
   lu_byte gcstate;  /* state of garbage collector */
   lu_byte gckind;  /* kind of GC running */
+  lu_byte genminormul;  /* control for minor generational collections */
+  lu_byte genmajormul;  /* control for major generational collections */
   lu_byte gcrunning;  /* true if GC is running */
   GCObject *allgc;  /* list of all collectable objects */
   GCObject **sweepgc;  /* current position of sweep in list */