aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWaldemar Celes <celes@tecgraf.puc-rio.br>1994-10-17 17:03:23 -0200
committerWaldemar Celes <celes@tecgraf.puc-rio.br>1994-10-17 17:03:23 -0200
commitf8c8159362f4bb8820908085adcb06900ef33b4c (patch)
tree2cbe498f152dad434973e4b718ba04dd08ca3b83
parentd1c5f4294365e9c5dbcd7f57bd0e3d55b548329c (diff)
downloadlua-f8c8159362f4bb8820908085adcb06900ef33b4c.tar.gz
lua-f8c8159362f4bb8820908085adcb06900ef33b4c.tar.bz2
lua-f8c8159362f4bb8820908085adcb06900ef33b4c.zip
adaptative garbage collection.
-rw-r--r--hash.c7
-rw-r--r--table.c13
-rw-r--r--table.h3
3 files changed, 14 insertions, 9 deletions
diff --git a/hash.c b/hash.c
index 916a0d43..97d6efb0 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.7 1994/09/08 15:27:10 celes Exp celes $"; 6char *rcs_hash="$Id: hash.c,v 2.8 1994/10/11 12:59:49 celes Exp $";
7 7
8#include <string.h> 8#include <string.h>
9#include <stdlib.h> 9#include <stdlib.h>
@@ -52,7 +52,7 @@ static int redimension (int nhash)
52 return nhash*2+1; 52 return nhash*2+1;
53} 53}
54 54
55static int index (Hash *t, Object *ref) /* hash function */ 55static int hashindex (Hash *t, Object *ref) /* hash function */
56{ 56{
57 switch (tag(ref)) 57 switch (tag(ref))
58 { 58 {
@@ -97,7 +97,7 @@ static int equalObj (Object *t1, Object *t2)
97 97
98static int present (Hash *t, Object *ref) 98static int present (Hash *t, Object *ref)
99{ 99{
100 int h = index(t, ref); 100 int h = hashindex(t, ref);
101 if (h < 0) return h; 101 if (h < 0) return h;
102 while (tag(ref(node(t, h))) != T_NIL) 102 while (tag(ref(node(t, h))) != T_NIL)
103 { 103 {
@@ -195,6 +195,7 @@ void lua_hashcollector (void)
195 if (prev == NULL) listhead = next; 195 if (prev == NULL) listhead = next;
196 else prev->next = next; 196 else prev->next = next;
197 hashdelete(curr_array); 197 hashdelete(curr_array);
198 ++lua_recovered;
198 } 199 }
199 else 200 else
200 { 201 {
diff --git a/table.c b/table.c
index 9ea24226..875a6e20 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.2 1994/07/19 21:27:18 celes Exp celes $"; 6char *rcs_table="$Id: table.c,v 2.3 1994/08/03 14:15:46 celes Exp $";
7 7
8#include <stdlib.h> 8#include <stdlib.h>
9#include <string.h> 9#include <string.h>
@@ -39,6 +39,7 @@ int lua_nfile;
39#define GARBAGE_BLOCK 256 39#define GARBAGE_BLOCK 256
40Word lua_block=GARBAGE_BLOCK; /* when garbage collector will be called */ 40Word lua_block=GARBAGE_BLOCK; /* when garbage collector will be called */
41Word lua_nentity; /* counter of new entities (strings and arrays) */ 41Word lua_nentity; /* counter of new entities (strings and arrays) */
42Word lua_recovered; /* counter of recovered entities (strings and arrays) */
42 43
43 44
44/* 45/*
@@ -210,10 +211,15 @@ void lua_pack (void)
210 /* mark symbol table strings */ 211 /* mark symbol table strings */
211 lua_travsymbol(lua_markobject); 212 lua_travsymbol(lua_markobject);
212 213
214 lua_recovered=0;
215
213 lua_strcollector(); 216 lua_strcollector();
214 lua_hashcollector(); 217 lua_hashcollector();
215 218
216 lua_nentity = 0; /* reset counter */ 219printf("lua_pack: lua_block=%d lua_recovered=%d %%=%.2f\n",lua_block,lua_recovered,100.0*lua_recovered/lua_block);
220
221 lua_nentity = 0; /* reset counter */
222 lua_block=2*lua_block-3*lua_recovered/2; /* adapt block size */
217} 223}
218 224
219 225
@@ -224,9 +230,6 @@ char *lua_createstring (char *s)
224{ 230{
225 if (s == NULL) return NULL; 231 if (s == NULL) return NULL;
226 232
227 if (lua_nentity == lua_block)
228 lua_pack ();
229 lua_nentity++;
230 return lua_strcreate(s); 233 return lua_strcreate(s);
231} 234}
232 235
diff --git a/table.h b/table.h
index 47be08c4..2ef50b0a 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.1 1994/04/20 22:07:57 celes Exp celes $ 4** $Id: table.h,v 2.2 1994/07/19 21:27:18 celes Exp $
5*/ 5*/
6 6
7#ifndef table_h 7#ifndef table_h
@@ -15,6 +15,7 @@ extern int lua_nfile;
15 15
16extern Word lua_block; 16extern Word lua_block;
17extern Word lua_nentity; 17extern Word lua_nentity;
18extern Word lua_recovered;
18 19
19 20
20void lua_initconstant (void); 21void lua_initconstant (void);