mirror of https://github.com/rusefi/lua.git
changes in garbage collection control
This commit is contained in:
parent
d6a1699e37
commit
b234da1cc2
15
hash.c
15
hash.c
|
@ -3,7 +3,7 @@
|
|||
** 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 "opcode.h"
|
||||
|
@ -183,9 +183,10 @@ static void call_fallbacks (void)
|
|||
** Garbage collection to arrays
|
||||
** Delete all unmarked arrays.
|
||||
*/
|
||||
void lua_hashcollector (void)
|
||||
int lua_hashcollector (void)
|
||||
{
|
||||
Hash *curr_array = listhead, *prev = NULL;
|
||||
int counter = 0;
|
||||
call_fallbacks();
|
||||
while (curr_array != NULL)
|
||||
{
|
||||
|
@ -195,7 +196,7 @@ void lua_hashcollector (void)
|
|||
if (prev == NULL) listhead = next;
|
||||
else prev->next = next;
|
||||
hashdelete(curr_array);
|
||||
++lua_recovered;
|
||||
++counter;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -204,6 +205,7 @@ void lua_hashcollector (void)
|
|||
}
|
||||
curr_array = next;
|
||||
}
|
||||
return counter;
|
||||
}
|
||||
|
||||
|
||||
|
@ -215,10 +217,9 @@ void lua_hashcollector (void)
|
|||
*/
|
||||
Hash *lua_createarray (int nhash)
|
||||
{
|
||||
Hash *array = hashcreate(nhash);
|
||||
if (lua_nentity == lua_block)
|
||||
lua_pack();
|
||||
lua_nentity++;
|
||||
Hash *array;
|
||||
lua_pack();
|
||||
array = hashcreate(nhash);
|
||||
array->next = listhead;
|
||||
listhead = array;
|
||||
return array;
|
||||
|
|
4
hash.h
4
hash.h
|
@ -2,7 +2,7 @@
|
|||
** hash.h
|
||||
** hash manager for lua
|
||||
** 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
|
||||
|
@ -27,7 +27,7 @@ typedef struct Hash
|
|||
int lua_equalObj (Object *t1, Object *t2);
|
||||
Hash *lua_createarray (int nhash);
|
||||
void lua_hashmark (Hash *h);
|
||||
void lua_hashcollector (void);
|
||||
int lua_hashcollector (void);
|
||||
Object *lua_hashget (Hash *t, Object *ref);
|
||||
Object *lua_hashdefine (Hash *t, Object *ref);
|
||||
void lua_next (void);
|
||||
|
|
9
opcode.c
9
opcode.c
|
@ -3,7 +3,7 @@
|
|||
** 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 <stdio.h>
|
||||
|
@ -454,8 +454,8 @@ int lua_storesubscript (void)
|
|||
lua_Object lua_createTable (int initSize)
|
||||
{
|
||||
adjustC(0);
|
||||
tag(top) = LUA_T_ARRAY;
|
||||
avalue(top) = lua_createarray(initSize);
|
||||
tag(top) = LUA_T_ARRAY;
|
||||
top++;
|
||||
CBase++; /* incorporate object in the stack */
|
||||
return Ref(top-1);
|
||||
|
@ -585,8 +585,9 @@ int lua_pushnumber (real n)
|
|||
int lua_pushstring (char *s)
|
||||
{
|
||||
lua_checkstack(top-stack+1);
|
||||
svalue(top) = lua_createstring(s);
|
||||
tag(top) = LUA_T_STRING;
|
||||
svalue(top++) = lua_createstring(s);
|
||||
top++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -843,8 +844,8 @@ static int lua_execute (Byte *pc, int base)
|
|||
{
|
||||
CodeWord size;
|
||||
get_word(size,pc);
|
||||
tag(top) = LUA_T_ARRAY;
|
||||
avalue(top) = lua_createarray(size.w);
|
||||
tag(top) = LUA_T_ARRAY;
|
||||
top++;
|
||||
}
|
||||
break;
|
||||
|
|
36
table.c
36
table.c
|
@ -3,7 +3,7 @@
|
|||
** 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>
|
||||
|
||||
|
@ -33,12 +33,8 @@ static Long lua_maxconstant = 0;
|
|||
char *lua_file[MAXFILE];
|
||||
int lua_nfile;
|
||||
|
||||
/* Variables to controll garbage collection */
|
||||
#define GARBAGE_BLOCK 256
|
||||
Word lua_block=GARBAGE_BLOCK; /* when garbage collector will be called */
|
||||
Word lua_nentity; /* counter of new entities (strings and arrays) */
|
||||
Word lua_recovered; /* counter of recovered entities (strings and arrays) */
|
||||
|
||||
#define MIN_GARBAGE_BLOCK 10
|
||||
|
||||
static void lua_nextvar (void);
|
||||
|
||||
|
@ -168,22 +164,18 @@ void lua_markobject (Object *o)
|
|||
*/
|
||||
void lua_pack (void)
|
||||
{
|
||||
/* mark stack objects */
|
||||
lua_travstack(lua_markobject);
|
||||
|
||||
/* mark symbol table objects */
|
||||
lua_travsymbol(lua_markobject);
|
||||
|
||||
/* mark locked objects */
|
||||
luaI_travlock(lua_markobject);
|
||||
|
||||
lua_recovered=0;
|
||||
|
||||
lua_strcollector();
|
||||
lua_hashcollector();
|
||||
|
||||
lua_nentity = 0; /* reset counter */
|
||||
lua_block=2*lua_block-3*lua_recovered/2U; /* adapt block size */
|
||||
static int block = GARBAGE_BLOCK; /* when garbage collector will be called */
|
||||
static int nentity = 0; /* counter of new entities (strings and arrays) */
|
||||
int recovered = 0;
|
||||
if (nentity++ < block) return;
|
||||
lua_travstack(lua_markobject); /* mark stack objects */
|
||||
lua_travsymbol(lua_markobject); /* mark symbol table objects */
|
||||
luaI_travlock(lua_markobject); /* mark locked objects */
|
||||
recovered += lua_strcollector();
|
||||
recovered += lua_hashcollector();
|
||||
nentity = 0; /* reset counter */
|
||||
block=2*block-3*recovered/2; /* adapt block size */
|
||||
if (block < MIN_GARBAGE_BLOCK) block = MIN_GARBAGE_BLOCK;
|
||||
}
|
||||
|
||||
|
||||
|
|
6
table.h
6
table.h
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
** Module to control static tables
|
||||
** 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
|
||||
|
@ -15,10 +15,6 @@ extern char **lua_constant;
|
|||
extern char *lua_file[];
|
||||
extern int lua_nfile;
|
||||
|
||||
extern Word lua_block;
|
||||
extern Word lua_nentity;
|
||||
extern Word lua_recovered;
|
||||
|
||||
|
||||
void lua_initconstant (void);
|
||||
int luaI_findsymbolbyname (char *name);
|
||||
|
|
15
tree.c
15
tree.c
|
@ -3,7 +3,7 @@
|
|||
** 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>
|
||||
|
@ -55,14 +55,13 @@ static TreeNode *tree_create (TreeNode **node, char *str)
|
|||
|
||||
char *lua_strcreate (char *str)
|
||||
{
|
||||
StringNode *newString = (StringNode *)luaI_malloc(sizeof(StringNode)+
|
||||
strlen(str));
|
||||
StringNode *newString;
|
||||
lua_pack();
|
||||
newString = (StringNode *)luaI_malloc(sizeof(StringNode)+strlen(str));
|
||||
newString->mark = UNMARKED_STRING;
|
||||
strcpy(newString->str, str);
|
||||
newString->next = string_root;
|
||||
string_root = newString;
|
||||
if (lua_nentity == lua_block) lua_pack ();
|
||||
lua_nentity++;
|
||||
return newString->str;
|
||||
}
|
||||
|
||||
|
@ -77,9 +76,10 @@ TreeNode *lua_constcreate (char *str)
|
|||
** Garbage collection function.
|
||||
** This function traverse the string list freeing unindexed strings
|
||||
*/
|
||||
void lua_strcollector (void)
|
||||
int lua_strcollector (void)
|
||||
{
|
||||
StringNode *curr = string_root, *prev = NULL;
|
||||
int counter = 0;
|
||||
while (curr)
|
||||
{
|
||||
StringNode *next = curr->next;
|
||||
|
@ -88,7 +88,7 @@ void lua_strcollector (void)
|
|||
if (prev == NULL) string_root = next;
|
||||
else prev->next = next;
|
||||
luaI_free(curr);
|
||||
++lua_recovered;
|
||||
++counter;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -97,6 +97,7 @@ void lua_strcollector (void)
|
|||
}
|
||||
curr = next;
|
||||
}
|
||||
return counter;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
4
tree.h
4
tree.h
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
** tree.h
|
||||
** 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
|
||||
|
@ -30,7 +30,7 @@ typedef struct TreeNode
|
|||
|
||||
char *lua_strcreate (char *str);
|
||||
TreeNode *lua_constcreate (char *str);
|
||||
void lua_strcollector (void);
|
||||
int lua_strcollector (void);
|
||||
TreeNode *lua_varnext (char *n);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue