aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2009-12-11 19:31:14 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2009-12-11 19:31:14 -0200
commit8da245bfd2a767e1a738c2a85492d1f64d68f016 (patch)
tree9cb12a687b8051d9402d3c861c2c33d251bf7acd
parenta2a2abcba4b3a221780a4499880aa16bf76e8204 (diff)
downloadlua-8da245bfd2a767e1a738c2a85492d1f64d68f016.tar.gz
lua-8da245bfd2a767e1a738c2a85492d1f64d68f016.tar.bz2
lua-8da245bfd2a767e1a738c2a85492d1f64d68f016.zip
better to keep GC state numbers sequential, to optimize switch in
'singlestep'
-rw-r--r--lgc.c16
-rw-r--r--lgc.h16
-rw-r--r--lstring.c4
3 files changed, 18 insertions, 18 deletions
diff --git a/lgc.c b/lgc.c
index 2d042390..286b2213 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 2.63 2009/11/26 11:39:20 roberto Exp roberto $ 2** $Id: lgc.c,v 2.64 2009/12/11 19:14:59 roberto Exp roberto $
3** Garbage Collector 3** Garbage Collector
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -786,12 +786,12 @@ void luaC_step (lua_State *L) {
786 786
787 787
788/* 788/*
789** advances the garbage collector until it reaches a "valid" state 789** advances the garbage collector until it reaches a state allowed
790** (defined by the caller) 790** by 'statemask'
791*/ 791*/
792void luaC_runtilstate (lua_State *L, int validstates) { 792void luaC_runtilstate (lua_State *L, int statesmask) {
793 global_State *g = G(L); 793 global_State *g = G(L);
794 while (!(g->gcstate & validstates)) 794 while (!testbit(statesmask, g->gcstate))
795 singlestep(L); 795 singlestep(L);
796} 796}
797 797
@@ -811,13 +811,13 @@ void luaC_fullgc (lua_State *L, int isemergency) {
811 g->gcstate = GCSsweepstring; 811 g->gcstate = GCSsweepstring;
812 } 812 }
813 /* finish any pending sweep phase */ 813 /* finish any pending sweep phase */
814 luaC_runtilstate(L, ~(GCSsweepstring | GCSsweep)); 814 luaC_runtilstate(L, ~bit2mask(GCSsweepstring, GCSsweep));
815 markroot(L); /* start a new collection */ 815 markroot(L); /* start a new collection */
816 /* run collector up to finalizers */ 816 /* run collector up to finalizers */
817 luaC_runtilstate(L, GCSfinalize); 817 luaC_runtilstate(L, bitmask(GCSfinalize));
818 g->gckind = KGC_NORMAL; 818 g->gckind = KGC_NORMAL;
819 if (!isemergency) /* do not run finalizers during emergency GC */ 819 if (!isemergency) /* do not run finalizers during emergency GC */
820 luaC_runtilstate(L, ~GCSfinalize); 820 luaC_runtilstate(L, ~bitmask(GCSfinalize));
821 g->GCthreshold = (g->totalbytes/100) * g->gcpause; 821 g->GCthreshold = (g->totalbytes/100) * g->gcpause;
822} 822}
823 823
diff --git a/lgc.h b/lgc.h
index cc285b3e..976b7442 100644
--- a/lgc.h
+++ b/lgc.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.h,v 2.24 2009/11/26 11:39:20 roberto Exp roberto $ 2** $Id: lgc.h,v 2.25 2009/12/11 19:14:59 roberto Exp roberto $
3** Garbage Collector 3** Garbage Collector
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -14,12 +14,12 @@
14/* 14/*
15** Possible states of the Garbage Collector 15** Possible states of the Garbage Collector
16*/ 16*/
17#define GCSpause 1 17#define GCSpause 0
18#define GCSpropagate 2 18#define GCSpropagate 1
19#define GCSatomic 4 19#define GCSatomic 2
20#define GCSsweepstring 8 20#define GCSsweepstring 3
21#define GCSsweep 16 21#define GCSsweep 4
22#define GCSfinalize 32 22#define GCSfinalize 5
23 23
24 24
25 25
@@ -96,7 +96,7 @@
96LUAI_FUNC void luaC_separateudata (lua_State *L, int all); 96LUAI_FUNC void luaC_separateudata (lua_State *L, int all);
97LUAI_FUNC void luaC_freeallobjects (lua_State *L); 97LUAI_FUNC void luaC_freeallobjects (lua_State *L);
98LUAI_FUNC void luaC_step (lua_State *L); 98LUAI_FUNC void luaC_step (lua_State *L);
99LUAI_FUNC void luaC_runtilstate (lua_State *L, int validstates); 99LUAI_FUNC void luaC_runtilstate (lua_State *L, int statesmask);
100LUAI_FUNC void luaC_fullgc (lua_State *L, int isemergency); 100LUAI_FUNC void luaC_fullgc (lua_State *L, int isemergency);
101LUAI_FUNC void luaC_link (lua_State *L, GCObject *o, lu_byte tt); 101LUAI_FUNC void luaC_link (lua_State *L, GCObject *o, lu_byte tt);
102LUAI_FUNC void luaC_linkupval (lua_State *L, UpVal *uv); 102LUAI_FUNC void luaC_linkupval (lua_State *L, UpVal *uv);
diff --git a/lstring.c b/lstring.c
index b79cdb61..4b0d398d 100644
--- a/lstring.c
+++ b/lstring.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstring.c,v 2.13 2009/04/29 17:09:41 roberto Exp roberto $ 2** $Id: lstring.c,v 2.14 2009/12/11 19:14:59 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*/
@@ -23,7 +23,7 @@ void luaS_resize (lua_State *L, int newsize) {
23 int i; 23 int i;
24 stringtable *tb = &G(L)->strt; 24 stringtable *tb = &G(L)->strt;
25 /* cannot resize while GC is traversing strings */ 25 /* cannot resize while GC is traversing strings */
26 luaC_runtilstate(L, ~GCSsweepstring); 26 luaC_runtilstate(L, ~bitmask(GCSsweepstring));
27 if (newsize > tb->size) { 27 if (newsize > tb->size) {
28 luaM_reallocvector(L, tb->hash, tb->size, newsize, GCObject *); 28 luaM_reallocvector(L, tb->hash, tb->size, newsize, GCObject *);
29 for (i = tb->size; i < newsize; i++) tb->hash[i] = NULL; 29 for (i = tb->size; i < newsize; i++) tb->hash[i] = NULL;