diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-05-14 15:38:29 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-05-14 15:38:29 -0300 |
commit | bd9e68cfcdbbae2fd49ab51a9df4a93ec56eff45 (patch) | |
tree | f11ad6c42c0bb42eaa1b45548684fbc60c27996b /table.c | |
parent | 9747f3c87a205d9aa914a650686d6dc4accde1d9 (diff) | |
download | lua-bd9e68cfcdbbae2fd49ab51a9df4a93ec56eff45.tar.gz lua-bd9e68cfcdbbae2fd49ab51a9df4a93ec56eff45.tar.bz2 lua-bd9e68cfcdbbae2fd49ab51a9df4a93ec56eff45.zip |
new implementation of gc: "Pre-collect" garbage in temporary lists and
then call fallbacks.
Diffstat (limited to 'table.c')
-rw-r--r-- | table.c | 46 |
1 files changed, 29 insertions, 17 deletions
@@ -3,10 +3,11 @@ | |||
3 | ** Module to control static tables | 3 | ** Module to control static tables |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_table="$Id: table.c,v 2.67 1997/04/06 14:08:08 roberto Exp roberto $"; | 6 | char *rcs_table="$Id: table.c,v 2.68 1997/04/07 14:48:53 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include "luamem.h" | 8 | #include "luamem.h" |
9 | #include "auxlib.h" | 9 | #include "auxlib.h" |
10 | #include "func.h" | ||
10 | #include "opcode.h" | 11 | #include "opcode.h" |
11 | #include "tree.h" | 12 | #include "tree.h" |
12 | #include "hash.h" | 13 | #include "hash.h" |
@@ -176,32 +177,43 @@ static void call_nilIM (void) | |||
176 | ** Garbage collection. | 177 | ** Garbage collection. |
177 | ** Delete all unused strings and arrays. | 178 | ** Delete all unused strings and arrays. |
178 | */ | 179 | */ |
179 | Long luaI_collectgarbage (void) | 180 | static long gc_block = GARBAGE_BLOCK; |
181 | static long gc_nentity = 0; /* total of strings, arrays, etc */ | ||
182 | |||
183 | static void markall (void) | ||
180 | { | 184 | { |
181 | Long recovered = 0; | ||
182 | lua_travstack(lua_markobject); /* mark stack objects */ | 185 | lua_travstack(lua_markobject); /* mark stack objects */ |
183 | lua_travsymbol(lua_markobject); /* mark symbol table objects */ | 186 | lua_travsymbol(lua_markobject); /* mark symbol table objects */ |
184 | luaI_travlock(lua_markobject); /* mark locked objects */ | 187 | luaI_travlock(lua_markobject); /* mark locked objects */ |
185 | luaI_travfallbacks(lua_markobject); /* mark fallbacks */ | 188 | luaI_travfallbacks(lua_markobject); /* mark fallbacks */ |
186 | luaI_hashcallIM(); | 189 | } |
187 | luaI_strcallIM(); | 190 | |
191 | |||
192 | static void lua_collectgarbage (void) | ||
193 | { | ||
194 | long recovered = 0; | ||
195 | Hash *freetable; | ||
196 | TaggedString *freestr; | ||
197 | TFunc *freefunc; | ||
198 | markall(); | ||
199 | freetable = luaI_hashcollector(&recovered); | ||
200 | freestr = luaI_strcollector(&recovered); | ||
201 | freefunc = luaI_funccollector(&recovered); | ||
202 | gc_block = 2*(gc_block-recovered); | ||
203 | gc_nentity -= recovered; | ||
204 | luaI_hashcallIM(freetable); | ||
205 | luaI_strcallIM(freestr); | ||
188 | call_nilIM(); | 206 | call_nilIM(); |
189 | luaI_invalidaterefs(); | 207 | luaI_hashfree(freetable); |
190 | recovered += lua_strcollector(); | 208 | luaI_strfree(freestr); |
191 | recovered += lua_hashcollector(); | 209 | luaI_funcfree(freefunc); |
192 | recovered += luaI_funccollector(); | ||
193 | return recovered; | ||
194 | } | 210 | } |
195 | 211 | ||
212 | |||
196 | void lua_pack (void) | 213 | void lua_pack (void) |
197 | { | 214 | { |
198 | static unsigned long block = GARBAGE_BLOCK; | 215 | if (gc_nentity++ >= gc_block) |
199 | static unsigned long nentity = 0; /* total of strings, arrays, etc */ | 216 | lua_collectgarbage(); |
200 | unsigned long recovered = 0; | ||
201 | if (nentity++ < block) return; | ||
202 | recovered = luaI_collectgarbage(); | ||
203 | block = 2*(block-recovered); | ||
204 | nentity -= recovered; | ||
205 | } | 217 | } |
206 | 218 | ||
207 | 219 | ||