diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-11-17 11:58:57 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-11-17 11:58:57 -0200 |
commit | b234da1cc2053b8919a9b27af67291e48fdf9703 (patch) | |
tree | b32559df54e0d9c79fe271260f69238244ae2fc7 | |
parent | d6a1699e37257c0b3d4651a481ce0bf597bc4e45 (diff) | |
download | lua-b234da1cc2053b8919a9b27af67291e48fdf9703.tar.gz lua-b234da1cc2053b8919a9b27af67291e48fdf9703.tar.bz2 lua-b234da1cc2053b8919a9b27af67291e48fdf9703.zip |
changes in garbage collection control
-rw-r--r-- | hash.c | 15 | ||||
-rw-r--r-- | hash.h | 4 | ||||
-rw-r--r-- | opcode.c | 9 | ||||
-rw-r--r-- | table.c | 36 | ||||
-rw-r--r-- | table.h | 6 | ||||
-rw-r--r-- | tree.c | 15 | ||||
-rw-r--r-- | tree.h | 4 |
7 files changed, 40 insertions, 49 deletions
@@ -3,7 +3,7 @@ | |||
3 | ** hash manager for lua | 3 | ** hash manager for lua |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_hash="$Id: hash.c,v 2.16 1994/11/14 18:41:15 roberto Exp roberto $"; | 6 | char *rcs_hash="$Id: hash.c,v 2.17 1994/11/16 17:38:08 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include "mem.h" | 8 | #include "mem.h" |
9 | #include "opcode.h" | 9 | #include "opcode.h" |
@@ -183,9 +183,10 @@ static void call_fallbacks (void) | |||
183 | ** Garbage collection to arrays | 183 | ** Garbage collection to arrays |
184 | ** Delete all unmarked arrays. | 184 | ** Delete all unmarked arrays. |
185 | */ | 185 | */ |
186 | void lua_hashcollector (void) | 186 | int lua_hashcollector (void) |
187 | { | 187 | { |
188 | Hash *curr_array = listhead, *prev = NULL; | 188 | Hash *curr_array = listhead, *prev = NULL; |
189 | int counter = 0; | ||
189 | call_fallbacks(); | 190 | call_fallbacks(); |
190 | while (curr_array != NULL) | 191 | while (curr_array != NULL) |
191 | { | 192 | { |
@@ -195,7 +196,7 @@ void lua_hashcollector (void) | |||
195 | if (prev == NULL) listhead = next; | 196 | if (prev == NULL) listhead = next; |
196 | else prev->next = next; | 197 | else prev->next = next; |
197 | hashdelete(curr_array); | 198 | hashdelete(curr_array); |
198 | ++lua_recovered; | 199 | ++counter; |
199 | } | 200 | } |
200 | else | 201 | else |
201 | { | 202 | { |
@@ -204,6 +205,7 @@ void lua_hashcollector (void) | |||
204 | } | 205 | } |
205 | curr_array = next; | 206 | curr_array = next; |
206 | } | 207 | } |
208 | return counter; | ||
207 | } | 209 | } |
208 | 210 | ||
209 | 211 | ||
@@ -215,10 +217,9 @@ void lua_hashcollector (void) | |||
215 | */ | 217 | */ |
216 | Hash *lua_createarray (int nhash) | 218 | Hash *lua_createarray (int nhash) |
217 | { | 219 | { |
218 | Hash *array = hashcreate(nhash); | 220 | Hash *array; |
219 | if (lua_nentity == lua_block) | 221 | lua_pack(); |
220 | lua_pack(); | 222 | array = hashcreate(nhash); |
221 | lua_nentity++; | ||
222 | array->next = listhead; | 223 | array->next = listhead; |
223 | listhead = array; | 224 | listhead = array; |
224 | return array; | 225 | return array; |
@@ -2,7 +2,7 @@ | |||
2 | ** hash.h | 2 | ** hash.h |
3 | ** hash manager for lua | 3 | ** hash manager for lua |
4 | ** Luiz Henrique de Figueiredo - 17 Aug 90 | 4 | ** Luiz Henrique de Figueiredo - 17 Aug 90 |
5 | ** $Id: hash.h,v 2.4 1994/09/08 16:51:49 celes Exp roberto $ | 5 | ** $Id: hash.h,v 2.5 1994/11/14 18:41:15 roberto Exp roberto $ |
6 | */ | 6 | */ |
7 | 7 | ||
8 | #ifndef hash_h | 8 | #ifndef hash_h |
@@ -27,7 +27,7 @@ typedef struct Hash | |||
27 | int lua_equalObj (Object *t1, Object *t2); | 27 | int lua_equalObj (Object *t1, Object *t2); |
28 | Hash *lua_createarray (int nhash); | 28 | Hash *lua_createarray (int nhash); |
29 | void lua_hashmark (Hash *h); | 29 | void lua_hashmark (Hash *h); |
30 | void lua_hashcollector (void); | 30 | int lua_hashcollector (void); |
31 | Object *lua_hashget (Hash *t, Object *ref); | 31 | Object *lua_hashget (Hash *t, Object *ref); |
32 | Object *lua_hashdefine (Hash *t, Object *ref); | 32 | Object *lua_hashdefine (Hash *t, Object *ref); |
33 | void lua_next (void); | 33 | void lua_next (void); |
@@ -3,7 +3,7 @@ | |||
3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_opcode="$Id: opcode.c,v 3.12 1994/11/16 16:03:48 roberto Exp roberto $"; | 6 | char *rcs_opcode="$Id: opcode.c,v 3.13 1994/11/16 17:38:08 roberto Exp $"; |
7 | 7 | ||
8 | #include <setjmp.h> | 8 | #include <setjmp.h> |
9 | #include <stdio.h> | 9 | #include <stdio.h> |
@@ -454,8 +454,8 @@ int lua_storesubscript (void) | |||
454 | lua_Object lua_createTable (int initSize) | 454 | lua_Object lua_createTable (int initSize) |
455 | { | 455 | { |
456 | adjustC(0); | 456 | adjustC(0); |
457 | tag(top) = LUA_T_ARRAY; | ||
458 | avalue(top) = lua_createarray(initSize); | 457 | avalue(top) = lua_createarray(initSize); |
458 | tag(top) = LUA_T_ARRAY; | ||
459 | top++; | 459 | top++; |
460 | CBase++; /* incorporate object in the stack */ | 460 | CBase++; /* incorporate object in the stack */ |
461 | return Ref(top-1); | 461 | return Ref(top-1); |
@@ -585,8 +585,9 @@ int lua_pushnumber (real n) | |||
585 | int lua_pushstring (char *s) | 585 | int lua_pushstring (char *s) |
586 | { | 586 | { |
587 | lua_checkstack(top-stack+1); | 587 | lua_checkstack(top-stack+1); |
588 | svalue(top) = lua_createstring(s); | ||
588 | tag(top) = LUA_T_STRING; | 589 | tag(top) = LUA_T_STRING; |
589 | svalue(top++) = lua_createstring(s); | 590 | top++; |
590 | return 0; | 591 | return 0; |
591 | } | 592 | } |
592 | 593 | ||
@@ -843,8 +844,8 @@ static int lua_execute (Byte *pc, int base) | |||
843 | { | 844 | { |
844 | CodeWord size; | 845 | CodeWord size; |
845 | get_word(size,pc); | 846 | get_word(size,pc); |
846 | tag(top) = LUA_T_ARRAY; | ||
847 | avalue(top) = lua_createarray(size.w); | 847 | avalue(top) = lua_createarray(size.w); |
848 | tag(top) = LUA_T_ARRAY; | ||
848 | top++; | 849 | top++; |
849 | } | 850 | } |
850 | break; | 851 | break; |
@@ -3,7 +3,7 @@ | |||
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.18 1994/11/16 16:03:48 roberto Exp roberto $"; | 6 | char *rcs_table="$Id: table.c,v 2.19 1994/11/16 17:39:16 roberto Exp $"; |
7 | 7 | ||
8 | #include <string.h> | 8 | #include <string.h> |
9 | 9 | ||
@@ -33,12 +33,8 @@ static Long lua_maxconstant = 0; | |||
33 | char *lua_file[MAXFILE]; | 33 | char *lua_file[MAXFILE]; |
34 | int lua_nfile; | 34 | int lua_nfile; |
35 | 35 | ||
36 | /* Variables to controll garbage collection */ | ||
37 | #define GARBAGE_BLOCK 256 | 36 | #define GARBAGE_BLOCK 256 |
38 | Word lua_block=GARBAGE_BLOCK; /* when garbage collector will be called */ | 37 | #define MIN_GARBAGE_BLOCK 10 |
39 | Word lua_nentity; /* counter of new entities (strings and arrays) */ | ||
40 | Word lua_recovered; /* counter of recovered entities (strings and arrays) */ | ||
41 | |||
42 | 38 | ||
43 | static void lua_nextvar (void); | 39 | static void lua_nextvar (void); |
44 | 40 | ||
@@ -168,22 +164,18 @@ void lua_markobject (Object *o) | |||
168 | */ | 164 | */ |
169 | void lua_pack (void) | 165 | void lua_pack (void) |
170 | { | 166 | { |
171 | /* mark stack objects */ | 167 | static int block = GARBAGE_BLOCK; /* when garbage collector will be called */ |
172 | lua_travstack(lua_markobject); | 168 | static int nentity = 0; /* counter of new entities (strings and arrays) */ |
173 | 169 | int recovered = 0; | |
174 | /* mark symbol table objects */ | 170 | if (nentity++ < block) return; |
175 | lua_travsymbol(lua_markobject); | 171 | lua_travstack(lua_markobject); /* mark stack objects */ |
176 | 172 | lua_travsymbol(lua_markobject); /* mark symbol table objects */ | |
177 | /* mark locked objects */ | 173 | luaI_travlock(lua_markobject); /* mark locked objects */ |
178 | luaI_travlock(lua_markobject); | 174 | recovered += lua_strcollector(); |
179 | 175 | recovered += lua_hashcollector(); | |
180 | lua_recovered=0; | 176 | nentity = 0; /* reset counter */ |
181 | 177 | block=2*block-3*recovered/2; /* adapt block size */ | |
182 | lua_strcollector(); | 178 | if (block < MIN_GARBAGE_BLOCK) block = MIN_GARBAGE_BLOCK; |
183 | lua_hashcollector(); | ||
184 | |||
185 | lua_nentity = 0; /* reset counter */ | ||
186 | lua_block=2*lua_block-3*lua_recovered/2U; /* adapt block size */ | ||
187 | } | 179 | } |
188 | 180 | ||
189 | 181 | ||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | ** Module to control static tables | 2 | ** Module to control static tables |
3 | ** TeCGraf - PUC-Rio | 3 | ** TeCGraf - PUC-Rio |
4 | ** $Id: table.h,v 2.5 1994/11/14 21:40:14 roberto Exp roberto $ | 4 | ** $Id: table.h,v 2.6 1994/11/16 16:03:48 roberto Exp roberto $ |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #ifndef table_h | 7 | #ifndef table_h |
@@ -15,10 +15,6 @@ extern char **lua_constant; | |||
15 | extern char *lua_file[]; | 15 | extern char *lua_file[]; |
16 | extern int lua_nfile; | 16 | extern int lua_nfile; |
17 | 17 | ||
18 | extern Word lua_block; | ||
19 | extern Word lua_nentity; | ||
20 | extern Word lua_recovered; | ||
21 | |||
22 | 18 | ||
23 | void lua_initconstant (void); | 19 | void lua_initconstant (void); |
24 | int luaI_findsymbolbyname (char *name); | 20 | int luaI_findsymbolbyname (char *name); |
@@ -3,7 +3,7 @@ | |||
3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_tree="$Id: tree.c,v 1.6 1994/11/16 17:38:08 roberto Exp roberto $"; | 6 | char *rcs_tree="$Id: tree.c,v 1.7 1994/11/16 18:09:11 roberto Exp roberto $"; |
7 | 7 | ||
8 | 8 | ||
9 | #include <string.h> | 9 | #include <string.h> |
@@ -55,14 +55,13 @@ static TreeNode *tree_create (TreeNode **node, char *str) | |||
55 | 55 | ||
56 | char *lua_strcreate (char *str) | 56 | char *lua_strcreate (char *str) |
57 | { | 57 | { |
58 | StringNode *newString = (StringNode *)luaI_malloc(sizeof(StringNode)+ | 58 | StringNode *newString; |
59 | strlen(str)); | 59 | lua_pack(); |
60 | newString = (StringNode *)luaI_malloc(sizeof(StringNode)+strlen(str)); | ||
60 | newString->mark = UNMARKED_STRING; | 61 | newString->mark = UNMARKED_STRING; |
61 | strcpy(newString->str, str); | 62 | strcpy(newString->str, str); |
62 | newString->next = string_root; | 63 | newString->next = string_root; |
63 | string_root = newString; | 64 | string_root = newString; |
64 | if (lua_nentity == lua_block) lua_pack (); | ||
65 | lua_nentity++; | ||
66 | return newString->str; | 65 | return newString->str; |
67 | } | 66 | } |
68 | 67 | ||
@@ -77,9 +76,10 @@ TreeNode *lua_constcreate (char *str) | |||
77 | ** Garbage collection function. | 76 | ** Garbage collection function. |
78 | ** This function traverse the string list freeing unindexed strings | 77 | ** This function traverse the string list freeing unindexed strings |
79 | */ | 78 | */ |
80 | void lua_strcollector (void) | 79 | int lua_strcollector (void) |
81 | { | 80 | { |
82 | StringNode *curr = string_root, *prev = NULL; | 81 | StringNode *curr = string_root, *prev = NULL; |
82 | int counter = 0; | ||
83 | while (curr) | 83 | while (curr) |
84 | { | 84 | { |
85 | StringNode *next = curr->next; | 85 | StringNode *next = curr->next; |
@@ -88,7 +88,7 @@ void lua_strcollector (void) | |||
88 | if (prev == NULL) string_root = next; | 88 | if (prev == NULL) string_root = next; |
89 | else prev->next = next; | 89 | else prev->next = next; |
90 | luaI_free(curr); | 90 | luaI_free(curr); |
91 | ++lua_recovered; | 91 | ++counter; |
92 | } | 92 | } |
93 | else | 93 | else |
94 | { | 94 | { |
@@ -97,6 +97,7 @@ void lua_strcollector (void) | |||
97 | } | 97 | } |
98 | curr = next; | 98 | curr = next; |
99 | } | 99 | } |
100 | return counter; | ||
100 | } | 101 | } |
101 | 102 | ||
102 | /* | 103 | /* |
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | ** tree.h | 2 | ** tree.h |
3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
4 | ** $Id: tree.h,v 1.2 1994/11/14 21:40:14 roberto Exp roberto $ | 4 | ** $Id: tree.h,v 1.3 1994/11/16 16:03:48 roberto Exp roberto $ |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #ifndef tree_h | 7 | #ifndef tree_h |
@@ -30,7 +30,7 @@ typedef struct TreeNode | |||
30 | 30 | ||
31 | char *lua_strcreate (char *str); | 31 | char *lua_strcreate (char *str); |
32 | TreeNode *lua_constcreate (char *str); | 32 | TreeNode *lua_constcreate (char *str); |
33 | void lua_strcollector (void); | 33 | int lua_strcollector (void); |
34 | TreeNode *lua_varnext (char *n); | 34 | TreeNode *lua_varnext (char *n); |
35 | 35 | ||
36 | #endif | 36 | #endif |