aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1994-11-17 11:58:57 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1994-11-17 11:58:57 -0200
commitb234da1cc2053b8919a9b27af67291e48fdf9703 (patch)
treeb32559df54e0d9c79fe271260f69238244ae2fc7
parentd6a1699e37257c0b3d4651a481ce0bf597bc4e45 (diff)
downloadlua-b234da1cc2053b8919a9b27af67291e48fdf9703.tar.gz
lua-b234da1cc2053b8919a9b27af67291e48fdf9703.tar.bz2
lua-b234da1cc2053b8919a9b27af67291e48fdf9703.zip
changes in garbage collection control
-rw-r--r--hash.c15
-rw-r--r--hash.h4
-rw-r--r--opcode.c9
-rw-r--r--table.c36
-rw-r--r--table.h6
-rw-r--r--tree.c15
-rw-r--r--tree.h4
7 files changed, 40 insertions, 49 deletions
diff --git a/hash.c b/hash.c
index 37a02605..84368876 100644
--- a/hash.c
+++ b/hash.c
@@ -3,7 +3,7 @@
3** hash manager for lua 3** hash manager for lua
4*/ 4*/
5 5
6char *rcs_hash="$Id: hash.c,v 2.16 1994/11/14 18:41:15 roberto Exp roberto $"; 6char *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*/
186void lua_hashcollector (void) 186int 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*/
216Hash *lua_createarray (int nhash) 218Hash *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;
diff --git a/hash.h b/hash.h
index ba94dd99..cfb0ee5c 100644
--- a/hash.h
+++ b/hash.h
@@ -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
27int lua_equalObj (Object *t1, Object *t2); 27int lua_equalObj (Object *t1, Object *t2);
28Hash *lua_createarray (int nhash); 28Hash *lua_createarray (int nhash);
29void lua_hashmark (Hash *h); 29void lua_hashmark (Hash *h);
30void lua_hashcollector (void); 30int lua_hashcollector (void);
31Object *lua_hashget (Hash *t, Object *ref); 31Object *lua_hashget (Hash *t, Object *ref);
32Object *lua_hashdefine (Hash *t, Object *ref); 32Object *lua_hashdefine (Hash *t, Object *ref);
33void lua_next (void); 33void lua_next (void);
diff --git a/opcode.c b/opcode.c
index b6955aee..1451894e 100644
--- a/opcode.c
+++ b/opcode.c
@@ -3,7 +3,7 @@
3** TecCGraf - PUC-Rio 3** TecCGraf - PUC-Rio
4*/ 4*/
5 5
6char *rcs_opcode="$Id: opcode.c,v 3.12 1994/11/16 16:03:48 roberto Exp roberto $"; 6char *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)
454lua_Object lua_createTable (int initSize) 454lua_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)
585int lua_pushstring (char *s) 585int 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;
diff --git a/table.c b/table.c
index e52fcd4a..ab5fd5e8 100644
--- a/table.c
+++ b/table.c
@@ -3,7 +3,7 @@
3** Module to control static tables 3** Module to control static tables
4*/ 4*/
5 5
6char *rcs_table="$Id: table.c,v 2.18 1994/11/16 16:03:48 roberto Exp roberto $"; 6char *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;
33char *lua_file[MAXFILE]; 33char *lua_file[MAXFILE];
34int lua_nfile; 34int lua_nfile;
35 35
36/* Variables to controll garbage collection */
37#define GARBAGE_BLOCK 256 36#define GARBAGE_BLOCK 256
38Word lua_block=GARBAGE_BLOCK; /* when garbage collector will be called */ 37#define MIN_GARBAGE_BLOCK 10
39Word lua_nentity; /* counter of new entities (strings and arrays) */
40Word lua_recovered; /* counter of recovered entities (strings and arrays) */
41
42 38
43static void lua_nextvar (void); 39static void lua_nextvar (void);
44 40
@@ -168,22 +164,18 @@ void lua_markobject (Object *o)
168*/ 164*/
169void lua_pack (void) 165void 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
diff --git a/table.h b/table.h
index 1433814d..1cc3fcca 100644
--- a/table.h
+++ b/table.h
@@ -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;
15extern char *lua_file[]; 15extern char *lua_file[];
16extern int lua_nfile; 16extern int lua_nfile;
17 17
18extern Word lua_block;
19extern Word lua_nentity;
20extern Word lua_recovered;
21
22 18
23void lua_initconstant (void); 19void lua_initconstant (void);
24int luaI_findsymbolbyname (char *name); 20int luaI_findsymbolbyname (char *name);
diff --git a/tree.c b/tree.c
index e58a7dca..58f25de4 100644
--- a/tree.c
+++ b/tree.c
@@ -3,7 +3,7 @@
3** TecCGraf - PUC-Rio 3** TecCGraf - PUC-Rio
4*/ 4*/
5 5
6char *rcs_tree="$Id: tree.c,v 1.6 1994/11/16 17:38:08 roberto Exp roberto $"; 6char *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
56char *lua_strcreate (char *str) 56char *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*/
80void lua_strcollector (void) 79int 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/*
diff --git a/tree.h b/tree.h
index 7587f4ec..aa7a44c4 100644
--- a/tree.h
+++ b/tree.h
@@ -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
31char *lua_strcreate (char *str); 31char *lua_strcreate (char *str);
32TreeNode *lua_constcreate (char *str); 32TreeNode *lua_constcreate (char *str);
33void lua_strcollector (void); 33int lua_strcollector (void);
34TreeNode *lua_varnext (char *n); 34TreeNode *lua_varnext (char *n);
35 35
36#endif 36#endif