Преглед изворни кода

new way to control GC speed (keeping a 'debt' counter)

Roberto Ierusalimschy пре 15 година
родитељ
комит
3eb1788bb4
3 измењених фајлова са 11 додато и 10 уклоњено
  1. 7 7
      lapi.c
  2. 2 1
      llimits.h
  3. 2 2
      lstate.h

+ 7 - 7
lapi.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lapi.c,v 2.123 2010/04/19 16:33:19 roberto Exp roberto $
+** $Id: lapi.c,v 2.124 2010/04/20 20:14:50 roberto Exp roberto $
 ** Lua API
 ** Lua API
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -913,11 +913,11 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
   g = G(L);
   g = G(L);
   switch (what) {
   switch (what) {
     case LUA_GCSTOP: {
     case LUA_GCSTOP: {
-      g->GCthreshold = MAX_LUMEM;
+      stopgc(g);
       break;
       break;
     }
     }
     case LUA_GCRESTART: {
     case LUA_GCRESTART: {
-      g->GCthreshold = g->totalbytes;
+      g->GCdebt = 0;
       break;
       break;
     }
     }
     case LUA_GCCOLLECT: {
     case LUA_GCCOLLECT: {
@@ -934,7 +934,7 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
       break;
       break;
     }
     }
     case LUA_GCSTEP: {
     case LUA_GCSTEP: {
-      lu_mem oldts = g->GCthreshold;
+      int stopped = gcstopped(g);
       if (g->gckind == KGC_GEN) {  /* generational mode? */
       if (g->gckind == KGC_GEN) {  /* generational mode? */
         res = (g->lastmajormem == 0);  /* 1 if will do major collection */
         res = (g->lastmajormem == 0);  /* 1 if will do major collection */
         luaC_step(L);  /* do a single step */
         luaC_step(L);  /* do a single step */
@@ -948,8 +948,8 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
           }
           }
         }
         }
       }
       }
-      if (oldts == MAX_LUMEM)  /* collector was stopped? */
-        g->GCthreshold = oldts;  /* keep it that way */
+      if (stopped)  /* collector was stopped? */
+        stopgc(g);  /* keep it that way */
       break;
       break;
     }
     }
     case LUA_GCSETPAUSE: {
     case LUA_GCSETPAUSE: {
@@ -963,7 +963,7 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
       break;
       break;
     }
     }
     case LUA_GCISRUNNING: {
     case LUA_GCISRUNNING: {
-      res = (g->GCthreshold != MAX_LUMEM);
+      res = !gcstopped(g);
       break;
       break;
     }
     }
     case LUA_GCGEN: {  /* change collector to generational mode */
     case LUA_GCGEN: {  /* change collector to generational mode */

+ 2 - 1
llimits.h

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: llimits.h,v 1.77 2009/12/17 12:50:20 roberto Exp roberto $
+** $Id: llimits.h,v 1.78 2010/04/19 17:40:13 roberto Exp roberto $
 ** Limits, basic types, and some other `installation-dependent' definitions
 ** Limits, basic types, and some other `installation-dependent' definitions
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -30,6 +30,7 @@ typedef unsigned char lu_byte;
 #define MAX_SIZET	((size_t)(~(size_t)0)-2)
 #define MAX_SIZET	((size_t)(~(size_t)0)-2)
 
 
 #define MAX_LUMEM	((lu_mem)(~(lu_mem)0)-2)
 #define MAX_LUMEM	((lu_mem)(~(lu_mem)0)-2)
+#define MIN_LMEM	((l_mem)~((~(lu_mem)0)>>1))
 
 
 
 
 #define MAX_INT (INT_MAX-2)  /* maximum value of an int (-2 for safety) */
 #define MAX_INT (INT_MAX-2)  /* maximum value of an int (-2 for safety) */

+ 2 - 2
lstate.h

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lstate.h,v 2.62 2010/04/12 16:07:06 roberto Exp roberto $
+** $Id: lstate.h,v 2.63 2010/04/13 20:48:12 roberto Exp roberto $
 ** Global State
 ** Global State
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -116,7 +116,7 @@ typedef struct global_State {
   lua_Alloc frealloc;  /* function to reallocate memory */
   lua_Alloc frealloc;  /* function to reallocate memory */
   void *ud;         /* auxiliary data to `frealloc' */
   void *ud;         /* auxiliary data to `frealloc' */
   lu_mem totalbytes;  /* number of bytes currently allocated */
   lu_mem totalbytes;  /* number of bytes currently allocated */
-  lu_mem GCthreshold;  /* when totalbytes > GCthreshold, run GC step */
+  l_mem GCdebt;  /* when positive, run a GC step */
   lu_mem lastmajormem;  /* memory in use after last major collection */
   lu_mem lastmajormem;  /* memory in use after last major collection */
   stringtable strt;  /* hash table for strings */
   stringtable strt;  /* hash table for strings */
   TValue l_registry;
   TValue l_registry;