changes in garbage collection control

This commit is contained in:
Roberto Ierusalimschy
1994-11-17 11:58:57 -02:00
parent d6a1699e37
commit b234da1cc2
7 changed files with 40 additions and 49 deletions

13
hash.c
View File

@@ -3,7 +3,7 @@
** hash manager for lua ** hash manager for lua
*/ */
char *rcs_hash="$Id: hash.c,v 2.16 1994/11/14 18:41:15 roberto Exp roberto $"; char *rcs_hash="$Id: hash.c,v 2.17 1994/11/16 17:38:08 roberto Exp roberto $";
#include "mem.h" #include "mem.h"
#include "opcode.h" #include "opcode.h"
@@ -183,9 +183,10 @@ static void call_fallbacks (void)
** Garbage collection to arrays ** Garbage collection to arrays
** Delete all unmarked arrays. ** Delete all unmarked arrays.
*/ */
void lua_hashcollector (void) int lua_hashcollector (void)
{ {
Hash *curr_array = listhead, *prev = NULL; Hash *curr_array = listhead, *prev = NULL;
int counter = 0;
call_fallbacks(); call_fallbacks();
while (curr_array != NULL) while (curr_array != NULL)
{ {
@@ -195,7 +196,7 @@ void lua_hashcollector (void)
if (prev == NULL) listhead = next; if (prev == NULL) listhead = next;
else prev->next = next; else prev->next = next;
hashdelete(curr_array); hashdelete(curr_array);
++lua_recovered; ++counter;
} }
else else
{ {
@@ -204,6 +205,7 @@ void lua_hashcollector (void)
} }
curr_array = next; curr_array = next;
} }
return counter;
} }
@@ -215,10 +217,9 @@ void lua_hashcollector (void)
*/ */
Hash *lua_createarray (int nhash) Hash *lua_createarray (int nhash)
{ {
Hash *array = hashcreate(nhash); Hash *array;
if (lua_nentity == lua_block)
lua_pack(); lua_pack();
lua_nentity++; array = hashcreate(nhash);
array->next = listhead; array->next = listhead;
listhead = array; listhead = array;
return array; return array;

4
hash.h
View File

@@ -2,7 +2,7 @@
** hash.h ** hash.h
** hash manager for lua ** hash manager for lua
** Luiz Henrique de Figueiredo - 17 Aug 90 ** Luiz Henrique de Figueiredo - 17 Aug 90
** $Id: hash.h,v 2.4 1994/09/08 16:51:49 celes Exp roberto $ ** $Id: hash.h,v 2.5 1994/11/14 18:41:15 roberto Exp roberto $
*/ */
#ifndef hash_h #ifndef hash_h
@@ -27,7 +27,7 @@ typedef struct Hash
int lua_equalObj (Object *t1, Object *t2); int lua_equalObj (Object *t1, Object *t2);
Hash *lua_createarray (int nhash); Hash *lua_createarray (int nhash);
void lua_hashmark (Hash *h); void lua_hashmark (Hash *h);
void lua_hashcollector (void); int lua_hashcollector (void);
Object *lua_hashget (Hash *t, Object *ref); Object *lua_hashget (Hash *t, Object *ref);
Object *lua_hashdefine (Hash *t, Object *ref); Object *lua_hashdefine (Hash *t, Object *ref);
void lua_next (void); void lua_next (void);

View File

@@ -3,7 +3,7 @@
** TecCGraf - PUC-Rio ** TecCGraf - PUC-Rio
*/ */
char *rcs_opcode="$Id: opcode.c,v 3.12 1994/11/16 16:03:48 roberto Exp roberto $"; char *rcs_opcode="$Id: opcode.c,v 3.13 1994/11/16 17:38:08 roberto Exp $";
#include <setjmp.h> #include <setjmp.h>
#include <stdio.h> #include <stdio.h>
@@ -454,8 +454,8 @@ int lua_storesubscript (void)
lua_Object lua_createTable (int initSize) lua_Object lua_createTable (int initSize)
{ {
adjustC(0); adjustC(0);
tag(top) = LUA_T_ARRAY;
avalue(top) = lua_createarray(initSize); avalue(top) = lua_createarray(initSize);
tag(top) = LUA_T_ARRAY;
top++; top++;
CBase++; /* incorporate object in the stack */ CBase++; /* incorporate object in the stack */
return Ref(top-1); return Ref(top-1);
@@ -585,8 +585,9 @@ int lua_pushnumber (real n)
int lua_pushstring (char *s) int lua_pushstring (char *s)
{ {
lua_checkstack(top-stack+1); lua_checkstack(top-stack+1);
svalue(top) = lua_createstring(s);
tag(top) = LUA_T_STRING; tag(top) = LUA_T_STRING;
svalue(top++) = lua_createstring(s); top++;
return 0; return 0;
} }
@@ -843,8 +844,8 @@ static int lua_execute (Byte *pc, int base)
{ {
CodeWord size; CodeWord size;
get_word(size,pc); get_word(size,pc);
tag(top) = LUA_T_ARRAY;
avalue(top) = lua_createarray(size.w); avalue(top) = lua_createarray(size.w);
tag(top) = LUA_T_ARRAY;
top++; top++;
} }
break; break;

36
table.c
View File

@@ -3,7 +3,7 @@
** Module to control static tables ** Module to control static tables
*/ */
char *rcs_table="$Id: table.c,v 2.18 1994/11/16 16:03:48 roberto Exp roberto $"; char *rcs_table="$Id: table.c,v 2.19 1994/11/16 17:39:16 roberto Exp $";
#include <string.h> #include <string.h>
@@ -33,12 +33,8 @@ static Long lua_maxconstant = 0;
char *lua_file[MAXFILE]; char *lua_file[MAXFILE];
int lua_nfile; int lua_nfile;
/* Variables to controll garbage collection */
#define GARBAGE_BLOCK 256 #define GARBAGE_BLOCK 256
Word lua_block=GARBAGE_BLOCK; /* when garbage collector will be called */ #define MIN_GARBAGE_BLOCK 10
Word lua_nentity; /* counter of new entities (strings and arrays) */
Word lua_recovered; /* counter of recovered entities (strings and arrays) */
static void lua_nextvar (void); static void lua_nextvar (void);
@@ -168,22 +164,18 @@ void lua_markobject (Object *o)
*/ */
void lua_pack (void) void lua_pack (void)
{ {
/* mark stack objects */ static int block = GARBAGE_BLOCK; /* when garbage collector will be called */
lua_travstack(lua_markobject); static int nentity = 0; /* counter of new entities (strings and arrays) */
int recovered = 0;
/* mark symbol table objects */ if (nentity++ < block) return;
lua_travsymbol(lua_markobject); lua_travstack(lua_markobject); /* mark stack objects */
lua_travsymbol(lua_markobject); /* mark symbol table objects */
/* mark locked objects */ luaI_travlock(lua_markobject); /* mark locked objects */
luaI_travlock(lua_markobject); recovered += lua_strcollector();
recovered += lua_hashcollector();
lua_recovered=0; nentity = 0; /* reset counter */
block=2*block-3*recovered/2; /* adapt block size */
lua_strcollector(); if (block < MIN_GARBAGE_BLOCK) block = MIN_GARBAGE_BLOCK;
lua_hashcollector();
lua_nentity = 0; /* reset counter */
lua_block=2*lua_block-3*lua_recovered/2U; /* adapt block size */
} }

View File

@@ -1,7 +1,7 @@
/* /*
** Module to control static tables ** Module to control static tables
** TeCGraf - PUC-Rio ** TeCGraf - PUC-Rio
** $Id: table.h,v 2.5 1994/11/14 21:40:14 roberto Exp roberto $ ** $Id: table.h,v 2.6 1994/11/16 16:03:48 roberto Exp roberto $
*/ */
#ifndef table_h #ifndef table_h
@@ -15,10 +15,6 @@ extern char **lua_constant;
extern char *lua_file[]; extern char *lua_file[];
extern int lua_nfile; extern int lua_nfile;
extern Word lua_block;
extern Word lua_nentity;
extern Word lua_recovered;
void lua_initconstant (void); void lua_initconstant (void);
int luaI_findsymbolbyname (char *name); int luaI_findsymbolbyname (char *name);

15
tree.c
View File

@@ -3,7 +3,7 @@
** TecCGraf - PUC-Rio ** TecCGraf - PUC-Rio
*/ */
char *rcs_tree="$Id: tree.c,v 1.6 1994/11/16 17:38:08 roberto Exp roberto $"; char *rcs_tree="$Id: tree.c,v 1.7 1994/11/16 18:09:11 roberto Exp roberto $";
#include <string.h> #include <string.h>
@@ -55,14 +55,13 @@ static TreeNode *tree_create (TreeNode **node, char *str)
char *lua_strcreate (char *str) char *lua_strcreate (char *str)
{ {
StringNode *newString = (StringNode *)luaI_malloc(sizeof(StringNode)+ StringNode *newString;
strlen(str)); lua_pack();
newString = (StringNode *)luaI_malloc(sizeof(StringNode)+strlen(str));
newString->mark = UNMARKED_STRING; newString->mark = UNMARKED_STRING;
strcpy(newString->str, str); strcpy(newString->str, str);
newString->next = string_root; newString->next = string_root;
string_root = newString; string_root = newString;
if (lua_nentity == lua_block) lua_pack ();
lua_nentity++;
return newString->str; return newString->str;
} }
@@ -77,9 +76,10 @@ TreeNode *lua_constcreate (char *str)
** Garbage collection function. ** Garbage collection function.
** This function traverse the string list freeing unindexed strings ** This function traverse the string list freeing unindexed strings
*/ */
void lua_strcollector (void) int lua_strcollector (void)
{ {
StringNode *curr = string_root, *prev = NULL; StringNode *curr = string_root, *prev = NULL;
int counter = 0;
while (curr) while (curr)
{ {
StringNode *next = curr->next; StringNode *next = curr->next;
@@ -88,7 +88,7 @@ void lua_strcollector (void)
if (prev == NULL) string_root = next; if (prev == NULL) string_root = next;
else prev->next = next; else prev->next = next;
luaI_free(curr); luaI_free(curr);
++lua_recovered; ++counter;
} }
else else
{ {
@@ -97,6 +97,7 @@ void lua_strcollector (void)
} }
curr = next; curr = next;
} }
return counter;
} }
/* /*

4
tree.h
View File

@@ -1,7 +1,7 @@
/* /*
** tree.h ** tree.h
** TecCGraf - PUC-Rio ** TecCGraf - PUC-Rio
** $Id: tree.h,v 1.2 1994/11/14 21:40:14 roberto Exp roberto $ ** $Id: tree.h,v 1.3 1994/11/16 16:03:48 roberto Exp roberto $
*/ */
#ifndef tree_h #ifndef tree_h
@@ -30,7 +30,7 @@ typedef struct TreeNode
char *lua_strcreate (char *str); char *lua_strcreate (char *str);
TreeNode *lua_constcreate (char *str); TreeNode *lua_constcreate (char *str);
void lua_strcollector (void); int lua_strcollector (void);
TreeNode *lua_varnext (char *n); TreeNode *lua_varnext (char *n);
#endif #endif