mirror of
https://github.com/lua/lua
synced 2024-11-26 14:51:21 +03:00
ways to measure number of `blocks' for GC + details
This commit is contained in:
parent
53fb65d394
commit
d915cf4f9d
8
lfunc.c
8
lfunc.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lfunc.c,v 1.12 1999/10/04 17:51:04 roberto Exp roberto $
|
||||
** $Id: lfunc.c,v 1.13 1999/10/14 19:46:57 roberto Exp roberto $
|
||||
** Auxiliary functions to manipulate prototypes and closures
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -11,8 +11,8 @@
|
||||
#include "lmem.h"
|
||||
#include "lstate.h"
|
||||
|
||||
#define gcsizeproto(p) 5 /* approximate "weight" for a prototype */
|
||||
#define gcsizeclosure(c) 1 /* approximate "weight" for a closure */
|
||||
#define gcsizeproto(p) numblocks(0, sizeof(TProtoFunc))
|
||||
#define gcsizeclosure(c) numblocks(c->nelems, sizeof(Closure))
|
||||
|
||||
|
||||
|
||||
@ -21,8 +21,8 @@ Closure *luaF_newclosure (int nelems) {
|
||||
c->next = L->rootcl;
|
||||
L->rootcl = c;
|
||||
c->marked = 0;
|
||||
L->nblocks += gcsizeclosure(c);
|
||||
c->nelems = nelems;
|
||||
L->nblocks += gcsizeclosure(c);
|
||||
return c;
|
||||
}
|
||||
|
||||
|
14
lobject.h
14
lobject.h
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lobject.h,v 1.34 1999/10/19 13:33:22 roberto Exp roberto $
|
||||
** $Id: lobject.h,v 1.35 1999/11/04 17:22:26 roberto Exp roberto $
|
||||
** Type definitions for Lua objects
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -43,7 +43,17 @@ typedef unsigned char Byte; /* unsigned 8 bits */
|
||||
|
||||
#define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */
|
||||
|
||||
typedef unsigned int IntPoint; /* unsigned with same size as a pointer (for hashing) */
|
||||
|
||||
/* convertion of pointer to int (for hashing only) */
|
||||
#define IntPoint(p) ((unsigned int)(p))
|
||||
|
||||
|
||||
/*
|
||||
** number of `blocks' for garbage collection: each reference to other
|
||||
** objects count 1, and each 32 bytes of `raw' memory count 1; we add
|
||||
** 2 to the total as a minimum (and also to count the overhead of malloc)
|
||||
*/
|
||||
#define numblocks(o,b) ((o)+(b)/32+2)
|
||||
|
||||
|
||||
/*
|
||||
|
8
lstate.c
8
lstate.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lstate.c,v 1.14 1999/10/04 17:51:04 roberto Exp $
|
||||
** $Id: lstate.c,v 1.15 1999/10/14 17:53:35 roberto Exp roberto $
|
||||
** Global State
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -10,6 +10,7 @@
|
||||
#include "lgc.h"
|
||||
#include "llex.h"
|
||||
#include "lmem.h"
|
||||
#include "lref.h"
|
||||
#include "lstate.h"
|
||||
#include "lstring.h"
|
||||
#include "ltm.h"
|
||||
@ -41,13 +42,15 @@ void lua_open (void) {
|
||||
L->IMtable = NULL;
|
||||
L->refArray = NULL;
|
||||
L->refSize = 0;
|
||||
L->GCthreshold = GARBAGE_BLOCK;
|
||||
L->refFree = NONEXT;
|
||||
L->nblocks = 0;
|
||||
L->GCthreshold = MAX_INT; /* to avoid GC during pre-definitions */
|
||||
luaD_init();
|
||||
luaS_init();
|
||||
luaX_init();
|
||||
luaT_init();
|
||||
luaB_predefine();
|
||||
L->GCthreshold = L->nblocks*4;
|
||||
}
|
||||
|
||||
|
||||
@ -70,4 +73,3 @@ void lua_close (void) {
|
||||
L = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
12
lstate.h
12
lstate.h
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lstate.h,v 1.20 1999/10/04 17:51:04 roberto Exp roberto $
|
||||
** $Id: lstate.h,v 1.21 1999/11/04 17:22:26 roberto Exp roberto $
|
||||
** Global State
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -14,8 +14,6 @@
|
||||
#include "luadebug.h"
|
||||
|
||||
|
||||
#define GARBAGE_BLOCK 150
|
||||
|
||||
|
||||
typedef int StkId; /* index to stack elements */
|
||||
|
||||
@ -50,13 +48,6 @@ typedef struct stringtable {
|
||||
} stringtable;
|
||||
|
||||
|
||||
enum Status {LOCK, HOLD, FREE, COLLECTED};
|
||||
|
||||
struct ref {
|
||||
TObject o;
|
||||
enum Status status;
|
||||
};
|
||||
|
||||
|
||||
struct lua_State {
|
||||
/* thread-specific state */
|
||||
@ -82,6 +73,7 @@ struct lua_State {
|
||||
int last_tag; /* last used tag in IMtable */
|
||||
struct ref *refArray; /* locked objects */
|
||||
int refSize; /* size of refArray */
|
||||
int refFree; /* list of free positions in refArray */
|
||||
unsigned long GCthreshold;
|
||||
unsigned long nblocks; /* number of 'blocks' currently allocated */
|
||||
};
|
||||
|
11
lstring.c
11
lstring.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lstring.c,v 1.25 1999/10/19 13:33:22 roberto Exp roberto $
|
||||
** $Id: lstring.c,v 1.26 1999/11/04 17:22:26 roberto Exp roberto $
|
||||
** String table (keeps all strings handled by Lua)
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -15,7 +15,8 @@
|
||||
|
||||
|
||||
|
||||
#define gcsizestring(l) (1+(l/64)) /* "weight" for a string with length 'l' */
|
||||
#define gcsizestring(l) numblocks(0, sizeof(TaggedString)+l)
|
||||
#define gcsizeudata gcsizestring(0)
|
||||
|
||||
|
||||
|
||||
@ -109,7 +110,7 @@ static TaggedString *newone_u (void *buff, int tag, unsigned long h) {
|
||||
ts->u.d.value = buff;
|
||||
ts->u.d.tag = (tag == LUA_ANYTAG) ? 0 : tag;
|
||||
ts->constindex = -1; /* tag -> this is a userdata */
|
||||
L->nblocks++;
|
||||
L->nblocks += gcsizeudata;
|
||||
return ts;
|
||||
}
|
||||
|
||||
@ -147,7 +148,7 @@ TaggedString *luaS_newlstr (const char *str, long l) {
|
||||
|
||||
|
||||
TaggedString *luaS_createudata (void *udata, int tag) {
|
||||
unsigned long h = (IntPoint)udata;
|
||||
unsigned long h = IntPoint(udata);
|
||||
stringtable *tb = &L->string_root[(h%NUM_HASHUDATA)+NUM_HASHSTR];
|
||||
int h1 = h%tb->size;
|
||||
TaggedString *ts;
|
||||
@ -175,7 +176,7 @@ TaggedString *luaS_newfixedstring (const char *str) {
|
||||
|
||||
void luaS_free (TaggedString *t) {
|
||||
if (t->constindex == -1) /* is userdata? */
|
||||
L->nblocks--;
|
||||
L->nblocks -= gcsizeudata;
|
||||
else { /* is string */
|
||||
L->nblocks -= gcsizestring(t->u.s.len);
|
||||
luaM_free(t->u.s.gv);
|
||||
|
12
ltable.c
12
ltable.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: ltable.c,v 1.27 1999/10/19 13:33:22 roberto Exp roberto $
|
||||
** $Id: ltable.c,v 1.28 1999/10/26 10:53:40 roberto Exp roberto $
|
||||
** Lua tables (hash)
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -26,7 +26,7 @@
|
||||
#include "lua.h"
|
||||
|
||||
|
||||
#define gcsize(n) (1+(n/16))
|
||||
#define gcsize(n) numblocks(n*2, sizeof(Hash))
|
||||
|
||||
|
||||
|
||||
@ -48,16 +48,16 @@ Node *luaH_mainposition (const Hash *t, const TObject *key) {
|
||||
h = tsvalue(key)->hash;
|
||||
break;
|
||||
case LUA_T_ARRAY:
|
||||
h = (IntPoint)avalue(key);
|
||||
h = IntPoint(avalue(key));
|
||||
break;
|
||||
case LUA_T_PROTO:
|
||||
h = (IntPoint)tfvalue(key);
|
||||
h = IntPoint(tfvalue(key));
|
||||
break;
|
||||
case LUA_T_CPROTO:
|
||||
h = (IntPoint)fvalue(key);
|
||||
h = IntPoint(fvalue(key));
|
||||
break;
|
||||
case LUA_T_CLOSURE:
|
||||
h = (IntPoint)clvalue(key);
|
||||
h = IntPoint(clvalue(key));
|
||||
break;
|
||||
default:
|
||||
lua_error("unexpected type to index table");
|
||||
|
Loading…
Reference in New Issue
Block a user