diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-04-29 14:31:31 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-04-29 14:31:31 -0300 |
| commit | 3eb1788bb4236cd983f1230ee14e2adb1b5b3ff5 (patch) | |
| tree | 6c2c41dd92bacf2dfe266d750b61b28a67198f9a | |
| parent | 00114a95b2a1234954a46fca6221d1c6922713f8 (diff) | |
| download | lua-3eb1788bb4236cd983f1230ee14e2adb1b5b3ff5.tar.gz lua-3eb1788bb4236cd983f1230ee14e2adb1b5b3ff5.tar.bz2 lua-3eb1788bb4236cd983f1230ee14e2adb1b5b3ff5.zip | |
new way to control GC speed (keeping a 'debt' counter)
| -rw-r--r-- | lapi.c | 14 | ||||
| -rw-r--r-- | llimits.h | 3 | ||||
| -rw-r--r-- | lstate.h | 4 |
3 files changed, 11 insertions, 10 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 2.123 2010/04/19 16:33:19 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.124 2010/04/20 20:14:50 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 | */ |
| @@ -913,11 +913,11 @@ LUA_API int lua_gc (lua_State *L, int what, int data) { | |||
| 913 | g = G(L); | 913 | g = G(L); |
| 914 | switch (what) { | 914 | switch (what) { |
| 915 | case LUA_GCSTOP: { | 915 | case LUA_GCSTOP: { |
| 916 | g->GCthreshold = MAX_LUMEM; | 916 | stopgc(g); |
| 917 | break; | 917 | break; |
| 918 | } | 918 | } |
| 919 | case LUA_GCRESTART: { | 919 | case LUA_GCRESTART: { |
| 920 | g->GCthreshold = g->totalbytes; | 920 | g->GCdebt = 0; |
| 921 | break; | 921 | break; |
| 922 | } | 922 | } |
| 923 | case LUA_GCCOLLECT: { | 923 | case LUA_GCCOLLECT: { |
| @@ -934,7 +934,7 @@ LUA_API int lua_gc (lua_State *L, int what, int data) { | |||
| 934 | break; | 934 | break; |
| 935 | } | 935 | } |
| 936 | case LUA_GCSTEP: { | 936 | case LUA_GCSTEP: { |
| 937 | lu_mem oldts = g->GCthreshold; | 937 | int stopped = gcstopped(g); |
| 938 | if (g->gckind == KGC_GEN) { /* generational mode? */ | 938 | if (g->gckind == KGC_GEN) { /* generational mode? */ |
| 939 | res = (g->lastmajormem == 0); /* 1 if will do major collection */ | 939 | res = (g->lastmajormem == 0); /* 1 if will do major collection */ |
| 940 | luaC_step(L); /* do a single step */ | 940 | luaC_step(L); /* do a single step */ |
| @@ -948,8 +948,8 @@ LUA_API int lua_gc (lua_State *L, int what, int data) { | |||
| 948 | } | 948 | } |
| 949 | } | 949 | } |
| 950 | } | 950 | } |
| 951 | if (oldts == MAX_LUMEM) /* collector was stopped? */ | 951 | if (stopped) /* collector was stopped? */ |
| 952 | g->GCthreshold = oldts; /* keep it that way */ | 952 | stopgc(g); /* keep it that way */ |
| 953 | break; | 953 | break; |
| 954 | } | 954 | } |
| 955 | case LUA_GCSETPAUSE: { | 955 | case LUA_GCSETPAUSE: { |
| @@ -963,7 +963,7 @@ LUA_API int lua_gc (lua_State *L, int what, int data) { | |||
| 963 | break; | 963 | break; |
| 964 | } | 964 | } |
| 965 | case LUA_GCISRUNNING: { | 965 | case LUA_GCISRUNNING: { |
| 966 | res = (g->GCthreshold != MAX_LUMEM); | 966 | res = !gcstopped(g); |
| 967 | break; | 967 | break; |
| 968 | } | 968 | } |
| 969 | case LUA_GCGEN: { /* change collector to generational mode */ | 969 | case LUA_GCGEN: { /* change collector to generational mode */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llimits.h,v 1.77 2009/12/17 12:50:20 roberto Exp roberto $ | 2 | ** $Id: llimits.h,v 1.78 2010/04/19 17:40:13 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 | */ |
| @@ -30,6 +30,7 @@ typedef unsigned char lu_byte; | |||
| 30 | #define MAX_SIZET ((size_t)(~(size_t)0)-2) | 30 | #define MAX_SIZET ((size_t)(~(size_t)0)-2) |
| 31 | 31 | ||
| 32 | #define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2) | 32 | #define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2) |
| 33 | #define MIN_LMEM ((l_mem)~((~(lu_mem)0)>>1)) | ||
| 33 | 34 | ||
| 34 | 35 | ||
| 35 | #define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */ | 36 | #define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstate.h,v 2.62 2010/04/12 16:07:06 roberto Exp roberto $ | 2 | ** $Id: lstate.h,v 2.63 2010/04/13 20:48:12 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 | */ |
| @@ -116,7 +116,7 @@ typedef struct global_State { | |||
| 116 | lua_Alloc frealloc; /* function to reallocate memory */ | 116 | lua_Alloc frealloc; /* function to reallocate memory */ |
| 117 | void *ud; /* auxiliary data to `frealloc' */ | 117 | void *ud; /* auxiliary data to `frealloc' */ |
| 118 | lu_mem totalbytes; /* number of bytes currently allocated */ | 118 | lu_mem totalbytes; /* number of bytes currently allocated */ |
| 119 | lu_mem GCthreshold; /* when totalbytes > GCthreshold, run GC step */ | 119 | l_mem GCdebt; /* when positive, run a GC step */ |
| 120 | lu_mem lastmajormem; /* memory in use after last major collection */ | 120 | lu_mem lastmajormem; /* memory in use after last major collection */ |
| 121 | stringtable strt; /* hash table for strings */ | 121 | stringtable strt; /* hash table for strings */ |
| 122 | TValue l_registry; | 122 | TValue l_registry; |
