Browse Source

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

pull/9/head
Roberto Ierusalimschy 15 years ago
parent
commit
3eb1788bb4
  1. 14
      lapi.c
  2. 3
      llimits.h
  3. 4
      lstate.h

14
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
** 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);
switch (what) {
case LUA_GCSTOP: {
g->GCthreshold = MAX_LUMEM;
stopgc(g);
break;
}
case LUA_GCRESTART: {
g->GCthreshold = g->totalbytes;
g->GCdebt = 0;
break;
}
case LUA_GCCOLLECT: {
@ -934,7 +934,7 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
break;
}
case LUA_GCSTEP: {
lu_mem oldts = g->GCthreshold;
int stopped = gcstopped(g);
if (g->gckind == KGC_GEN) { /* generational mode? */
res = (g->lastmajormem == 0); /* 1 if will do major collection */
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;
}
case LUA_GCSETPAUSE: {
@ -963,7 +963,7 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
break;
}
case LUA_GCISRUNNING: {
res = (g->GCthreshold != MAX_LUMEM);
res = !gcstopped(g);
break;
}
case LUA_GCGEN: { /* change collector to generational mode */

3
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
** 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_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) */

4
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
** See Copyright Notice in lua.h
*/
@ -116,7 +116,7 @@ typedef struct global_State {
lua_Alloc frealloc; /* function to reallocate memory */
void *ud; /* auxiliary data to `frealloc' */
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 */
stringtable strt; /* hash table for strings */
TValue l_registry;

Loading…
Cancel
Save