aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-11-10 13:39:35 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-11-10 13:39:35 -0200
commitd915cf4f9dbe525f8faeb4cb04df13d5f08692da (patch)
treeb166ca7e66e02999fee1500363c4d301b7e53951
parent53fb65d39451f9245d8ed555f941829520ee6f24 (diff)
downloadlua-d915cf4f9dbe525f8faeb4cb04df13d5f08692da.tar.gz
lua-d915cf4f9dbe525f8faeb4cb04df13d5f08692da.tar.bz2
lua-d915cf4f9dbe525f8faeb4cb04df13d5f08692da.zip
ways to measure number of `blocks' for GC + details
-rw-r--r--lfunc.c8
-rw-r--r--lobject.h14
-rw-r--r--lstate.c8
-rw-r--r--lstate.h12
-rw-r--r--lstring.c11
-rw-r--r--ltable.c12
6 files changed, 35 insertions, 30 deletions
diff --git a/lfunc.c b/lfunc.c
index fc97c0a3..67aa23d4 100644
--- a/lfunc.c
+++ b/lfunc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lfunc.c,v 1.12 1999/10/04 17:51:04 roberto Exp roberto $ 2** $Id: lfunc.c,v 1.13 1999/10/14 19:46:57 roberto Exp roberto $
3** Auxiliary functions to manipulate prototypes and closures 3** Auxiliary functions to manipulate prototypes and closures
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -11,8 +11,8 @@
11#include "lmem.h" 11#include "lmem.h"
12#include "lstate.h" 12#include "lstate.h"
13 13
14#define gcsizeproto(p) 5 /* approximate "weight" for a prototype */ 14#define gcsizeproto(p) numblocks(0, sizeof(TProtoFunc))
15#define gcsizeclosure(c) 1 /* approximate "weight" for a closure */ 15#define gcsizeclosure(c) numblocks(c->nelems, sizeof(Closure))
16 16
17 17
18 18
@@ -21,8 +21,8 @@ Closure *luaF_newclosure (int nelems) {
21 c->next = L->rootcl; 21 c->next = L->rootcl;
22 L->rootcl = c; 22 L->rootcl = c;
23 c->marked = 0; 23 c->marked = 0;
24 L->nblocks += gcsizeclosure(c);
25 c->nelems = nelems; 24 c->nelems = nelems;
25 L->nblocks += gcsizeclosure(c);
26 return c; 26 return c;
27} 27}
28 28
diff --git a/lobject.h b/lobject.h
index 364653a1..9956d5cf 100644
--- a/lobject.h
+++ b/lobject.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.h,v 1.34 1999/10/19 13:33:22 roberto Exp roberto $ 2** $Id: lobject.h,v 1.35 1999/11/04 17:22:26 roberto Exp roberto $
3** Type definitions for Lua objects 3** Type definitions for Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -43,7 +43,17 @@ typedef unsigned char Byte; /* unsigned 8 bits */
43 43
44#define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */ 44#define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */
45 45
46typedef unsigned int IntPoint; /* unsigned with same size as a pointer (for hashing) */ 46
47/* convertion of pointer to int (for hashing only) */
48#define IntPoint(p) ((unsigned int)(p))
49
50
51/*
52** number of `blocks' for garbage collection: each reference to other
53** objects count 1, and each 32 bytes of `raw' memory count 1; we add
54** 2 to the total as a minimum (and also to count the overhead of malloc)
55*/
56#define numblocks(o,b) ((o)+(b)/32+2)
47 57
48 58
49/* 59/*
diff --git a/lstate.c b/lstate.c
index 281206bc..57aa292d 100644
--- a/lstate.c
+++ b/lstate.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.c,v 1.14 1999/10/04 17:51:04 roberto Exp $ 2** $Id: lstate.c,v 1.15 1999/10/14 17:53:35 roberto Exp roberto $
3** Global State 3** Global State
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -10,6 +10,7 @@
10#include "lgc.h" 10#include "lgc.h"
11#include "llex.h" 11#include "llex.h"
12#include "lmem.h" 12#include "lmem.h"
13#include "lref.h"
13#include "lstate.h" 14#include "lstate.h"
14#include "lstring.h" 15#include "lstring.h"
15#include "ltm.h" 16#include "ltm.h"
@@ -41,13 +42,15 @@ void lua_open (void) {
41 L->IMtable = NULL; 42 L->IMtable = NULL;
42 L->refArray = NULL; 43 L->refArray = NULL;
43 L->refSize = 0; 44 L->refSize = 0;
44 L->GCthreshold = GARBAGE_BLOCK; 45 L->refFree = NONEXT;
45 L->nblocks = 0; 46 L->nblocks = 0;
47 L->GCthreshold = MAX_INT; /* to avoid GC during pre-definitions */
46 luaD_init(); 48 luaD_init();
47 luaS_init(); 49 luaS_init();
48 luaX_init(); 50 luaX_init();
49 luaT_init(); 51 luaT_init();
50 luaB_predefine(); 52 luaB_predefine();
53 L->GCthreshold = L->nblocks*4;
51} 54}
52 55
53 56
@@ -70,4 +73,3 @@ void lua_close (void) {
70 L = NULL; 73 L = NULL;
71} 74}
72 75
73
diff --git a/lstate.h b/lstate.h
index c0ccb1e1..d508120e 100644
--- a/lstate.h
+++ b/lstate.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.h,v 1.20 1999/10/04 17:51:04 roberto Exp roberto $ 2** $Id: lstate.h,v 1.21 1999/11/04 17:22:26 roberto Exp roberto $
3** Global State 3** Global State
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -14,8 +14,6 @@
14#include "luadebug.h" 14#include "luadebug.h"
15 15
16 16
17#define GARBAGE_BLOCK 150
18
19 17
20typedef int StkId; /* index to stack elements */ 18typedef int StkId; /* index to stack elements */
21 19
@@ -50,13 +48,6 @@ typedef struct stringtable {
50} stringtable; 48} stringtable;
51 49
52 50
53enum Status {LOCK, HOLD, FREE, COLLECTED};
54
55struct ref {
56 TObject o;
57 enum Status status;
58};
59
60 51
61struct lua_State { 52struct lua_State {
62 /* thread-specific state */ 53 /* thread-specific state */
@@ -82,6 +73,7 @@ struct lua_State {
82 int last_tag; /* last used tag in IMtable */ 73 int last_tag; /* last used tag in IMtable */
83 struct ref *refArray; /* locked objects */ 74 struct ref *refArray; /* locked objects */
84 int refSize; /* size of refArray */ 75 int refSize; /* size of refArray */
76 int refFree; /* list of free positions in refArray */
85 unsigned long GCthreshold; 77 unsigned long GCthreshold;
86 unsigned long nblocks; /* number of 'blocks' currently allocated */ 78 unsigned long nblocks; /* number of 'blocks' currently allocated */
87}; 79};
diff --git a/lstring.c b/lstring.c
index f71425e8..f1353033 100644
--- a/lstring.c
+++ b/lstring.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstring.c,v 1.25 1999/10/19 13:33:22 roberto Exp roberto $ 2** $Id: lstring.c,v 1.26 1999/11/04 17:22:26 roberto Exp roberto $
3** String table (keeps all strings handled by Lua) 3** String table (keeps all strings handled by Lua)
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -15,7 +15,8 @@
15 15
16 16
17 17
18#define gcsizestring(l) (1+(l/64)) /* "weight" for a string with length 'l' */ 18#define gcsizestring(l) numblocks(0, sizeof(TaggedString)+l)
19#define gcsizeudata gcsizestring(0)
19 20
20 21
21 22
@@ -109,7 +110,7 @@ static TaggedString *newone_u (void *buff, int tag, unsigned long h) {
109 ts->u.d.value = buff; 110 ts->u.d.value = buff;
110 ts->u.d.tag = (tag == LUA_ANYTAG) ? 0 : tag; 111 ts->u.d.tag = (tag == LUA_ANYTAG) ? 0 : tag;
111 ts->constindex = -1; /* tag -> this is a userdata */ 112 ts->constindex = -1; /* tag -> this is a userdata */
112 L->nblocks++; 113 L->nblocks += gcsizeudata;
113 return ts; 114 return ts;
114} 115}
115 116
@@ -147,7 +148,7 @@ TaggedString *luaS_newlstr (const char *str, long l) {
147 148
148 149
149TaggedString *luaS_createudata (void *udata, int tag) { 150TaggedString *luaS_createudata (void *udata, int tag) {
150 unsigned long h = (IntPoint)udata; 151 unsigned long h = IntPoint(udata);
151 stringtable *tb = &L->string_root[(h%NUM_HASHUDATA)+NUM_HASHSTR]; 152 stringtable *tb = &L->string_root[(h%NUM_HASHUDATA)+NUM_HASHSTR];
152 int h1 = h%tb->size; 153 int h1 = h%tb->size;
153 TaggedString *ts; 154 TaggedString *ts;
@@ -175,7 +176,7 @@ TaggedString *luaS_newfixedstring (const char *str) {
175 176
176void luaS_free (TaggedString *t) { 177void luaS_free (TaggedString *t) {
177 if (t->constindex == -1) /* is userdata? */ 178 if (t->constindex == -1) /* is userdata? */
178 L->nblocks--; 179 L->nblocks -= gcsizeudata;
179 else { /* is string */ 180 else { /* is string */
180 L->nblocks -= gcsizestring(t->u.s.len); 181 L->nblocks -= gcsizestring(t->u.s.len);
181 luaM_free(t->u.s.gv); 182 luaM_free(t->u.s.gv);
diff --git a/ltable.c b/ltable.c
index e16fe5da..eceff082 100644
--- a/ltable.c
+++ b/ltable.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltable.c,v 1.27 1999/10/19 13:33:22 roberto Exp roberto $ 2** $Id: ltable.c,v 1.28 1999/10/26 10:53:40 roberto Exp roberto $
3** Lua tables (hash) 3** Lua tables (hash)
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -26,7 +26,7 @@
26#include "lua.h" 26#include "lua.h"
27 27
28 28
29#define gcsize(n) (1+(n/16)) 29#define gcsize(n) numblocks(n*2, sizeof(Hash))
30 30
31 31
32 32
@@ -48,16 +48,16 @@ Node *luaH_mainposition (const Hash *t, const TObject *key) {
48 h = tsvalue(key)->hash; 48 h = tsvalue(key)->hash;
49 break; 49 break;
50 case LUA_T_ARRAY: 50 case LUA_T_ARRAY:
51 h = (IntPoint)avalue(key); 51 h = IntPoint(avalue(key));
52 break; 52 break;
53 case LUA_T_PROTO: 53 case LUA_T_PROTO:
54 h = (IntPoint)tfvalue(key); 54 h = IntPoint(tfvalue(key));
55 break; 55 break;
56 case LUA_T_CPROTO: 56 case LUA_T_CPROTO:
57 h = (IntPoint)fvalue(key); 57 h = IntPoint(fvalue(key));
58 break; 58 break;
59 case LUA_T_CLOSURE: 59 case LUA_T_CLOSURE:
60 h = (IntPoint)clvalue(key); 60 h = IntPoint(clvalue(key));
61 break; 61 break;
62 default: 62 default:
63 lua_error("unexpected type to index table"); 63 lua_error("unexpected type to index table");