diff options
-rw-r--r-- | lgc.c | 13 | ||||
-rw-r--r-- | lgc.h | 6 | ||||
-rw-r--r-- | llex.c | 10 | ||||
-rw-r--r-- | lstate.c | 7 | ||||
-rw-r--r-- | lstate.h | 6 | ||||
-rw-r--r-- | lstring.h | 4 | ||||
-rw-r--r-- | ltm.c | 4 |
7 files changed, 33 insertions, 17 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 2.148 2013/08/20 17:46:34 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 2.149 2013/08/21 19:21:16 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 | */ |
@@ -189,6 +189,16 @@ void luaC_checkupvalcolor (global_State *g, UpVal *uv) { | |||
189 | } | 189 | } |
190 | 190 | ||
191 | 191 | ||
192 | void luaC_fix (lua_State *L, GCObject *o) { | ||
193 | global_State *g = G(L); | ||
194 | lua_assert(g->allgc == o); | ||
195 | white2gray(o); | ||
196 | g->allgc = o->gch.next; /* remove object from 'allgc' list */ | ||
197 | o->gch.next = g->fixedgc; /* link it to 'fixedgc' list */ | ||
198 | g->fixedgc = o; | ||
199 | } | ||
200 | |||
201 | |||
192 | /* | 202 | /* |
193 | ** create a new collectable object (with given type and size) and link | 203 | ** create a new collectable object (with given type and size) and link |
194 | ** it to '*list'. 'offset' tells how many bytes to allocate before the | 204 | ** it to '*list'. 'offset' tells how many bytes to allocate before the |
@@ -927,6 +937,7 @@ void luaC_freeallobjects (lua_State *L) { | |||
927 | g->gckind = KGC_NORMAL; | 937 | g->gckind = KGC_NORMAL; |
928 | sweepwholelist(L, &g->finobj); /* finalizers can create objs. in 'finobj' */ | 938 | sweepwholelist(L, &g->finobj); /* finalizers can create objs. in 'finobj' */ |
929 | sweepwholelist(L, &g->allgc); | 939 | sweepwholelist(L, &g->allgc); |
940 | sweepwholelist(L, &g->fixedgc); /* collect fixed objects */ | ||
930 | lua_assert(g->strt.nuse == 0); | 941 | lua_assert(g->strt.nuse == 0); |
931 | } | 942 | } |
932 | 943 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.h,v 2.63 2013/08/20 17:46:34 roberto Exp roberto $ | 2 | ** $Id: lgc.h,v 2.64 2013/08/21 19:21:16 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 | */ |
@@ -76,8 +76,7 @@ | |||
76 | #define WHITE1BIT 1 /* object is white (type 1) */ | 76 | #define WHITE1BIT 1 /* object is white (type 1) */ |
77 | #define BLACKBIT 2 /* object is black */ | 77 | #define BLACKBIT 2 /* object is black */ |
78 | #define FINALIZEDBIT 3 /* object has been marked for finalization */ | 78 | #define FINALIZEDBIT 3 /* object has been marked for finalization */ |
79 | #define FIXEDBIT 4 /* object is fixed (should not be collected) */ | 79 | #define LOCALBIT 4 /* object is not local */ |
80 | #define LOCALBIT 5 /* object is not local */ | ||
81 | /* bit 7 is currently used by tests (luaL_checkmemory) */ | 80 | /* bit 7 is currently used by tests (luaL_checkmemory) */ |
82 | 81 | ||
83 | #define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT) | 82 | #define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT) |
@@ -127,6 +126,7 @@ | |||
127 | { if (nolocal(obj2gco(o)), isblack(obj2gco(p)) && iswhite(obj2gco(o))) \ | 126 | { if (nolocal(obj2gco(o)), isblack(obj2gco(p)) && iswhite(obj2gco(o))) \ |
128 | luaC_barrierback_(L,p); } | 127 | luaC_barrierback_(L,p); } |
129 | 128 | ||
129 | LUAI_FUNC void luaC_fix (lua_State *L, GCObject *o); | ||
130 | LUAI_FUNC void luaC_freeallobjects (lua_State *L); | 130 | LUAI_FUNC void luaC_freeallobjects (lua_State *L); |
131 | LUAI_FUNC void luaC_step (lua_State *L); | 131 | LUAI_FUNC void luaC_step (lua_State *L); |
132 | LUAI_FUNC void luaC_forcestep (lua_State *L); | 132 | LUAI_FUNC void luaC_forcestep (lua_State *L); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: llex.c,v 2.66 2013/05/14 15:59:04 roberto Exp roberto $ | 2 | ** $Id: llex.c,v 2.67 2013/06/19 14:27:00 roberto Exp roberto $ |
3 | ** Lexical Analyzer | 3 | ** Lexical Analyzer |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -15,6 +15,7 @@ | |||
15 | 15 | ||
16 | #include "lctype.h" | 16 | #include "lctype.h" |
17 | #include "ldo.h" | 17 | #include "ldo.h" |
18 | #include "lgc.h" | ||
18 | #include "llex.h" | 19 | #include "llex.h" |
19 | #include "lobject.h" | 20 | #include "lobject.h" |
20 | #include "lparser.h" | 21 | #include "lparser.h" |
@@ -64,9 +65,11 @@ static void save (LexState *ls, int c) { | |||
64 | 65 | ||
65 | void luaX_init (lua_State *L) { | 66 | void luaX_init (lua_State *L) { |
66 | int i; | 67 | int i; |
68 | TString *e = luaS_new(L, LUA_ENV); /* create env name */ | ||
69 | luaC_fix(L, obj2gco(e)); /* never collect this name */ | ||
67 | for (i=0; i<NUM_RESERVED; i++) { | 70 | for (i=0; i<NUM_RESERVED; i++) { |
68 | TString *ts = luaS_new(L, luaX_tokens[i]); | 71 | TString *ts = luaS_new(L, luaX_tokens[i]); |
69 | luaS_fix(ts); /* reserved words are never collected */ | 72 | luaC_fix(L, obj2gco(ts)); /* reserved words are never collected */ |
70 | ts->tsv.extra = cast_byte(i+1); /* reserved word */ | 73 | ts->tsv.extra = cast_byte(i+1); /* reserved word */ |
71 | } | 74 | } |
72 | } | 75 | } |
@@ -163,8 +166,7 @@ void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source, | |||
163 | ls->linenumber = 1; | 166 | ls->linenumber = 1; |
164 | ls->lastline = 1; | 167 | ls->lastline = 1; |
165 | ls->source = source; | 168 | ls->source = source; |
166 | ls->envn = luaS_new(L, LUA_ENV); /* create env name */ | 169 | ls->envn = luaS_new(L, LUA_ENV); /* get env name */ |
167 | luaS_fix(ls->envn); /* never collect this name */ | ||
168 | luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */ | 170 | luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */ |
169 | } | 171 | } |
170 | 172 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.c,v 2.102 2013/08/16 18:55:49 roberto Exp roberto $ | 2 | ** $Id: lstate.c,v 2.103 2013/08/21 19:21:16 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 | */ |
@@ -188,7 +188,7 @@ static void f_luaopen (lua_State *L, void *ud) { | |||
188 | luaX_init(L); | 188 | luaX_init(L); |
189 | /* pre-create memory-error message */ | 189 | /* pre-create memory-error message */ |
190 | g->memerrmsg = luaS_newliteral(L, MEMERRMSG); | 190 | g->memerrmsg = luaS_newliteral(L, MEMERRMSG); |
191 | luaS_fix(g->memerrmsg); /* it should never be collected */ | 191 | luaC_fix(L, obj2gco(g->memerrmsg)); /* it should never be collected */ |
192 | g->gcrunning = 1; /* allow gc */ | 192 | g->gcrunning = 1; /* allow gc */ |
193 | } | 193 | } |
194 | 194 | ||
@@ -270,7 +270,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { | |||
270 | g = &l->g; | 270 | g = &l->g; |
271 | L->next = NULL; | 271 | L->next = NULL; |
272 | L->tt = LUA_TTHREAD; | 272 | L->tt = LUA_TTHREAD; |
273 | g->currentwhite = bit2mask(WHITE0BIT, FIXEDBIT); | 273 | g->currentwhite = bitmask(WHITE0BIT); |
274 | L->marked = luaC_white(g) | bitmask(LOCALBIT); | 274 | L->marked = luaC_white(g) | bitmask(LOCALBIT); |
275 | g->gckind = KGC_NORMAL; | 275 | g->gckind = KGC_NORMAL; |
276 | preinit_state(L, g); | 276 | preinit_state(L, g); |
@@ -290,6 +290,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { | |||
290 | g->allgc = NULL; | 290 | g->allgc = NULL; |
291 | g->finobj = NULL; | 291 | g->finobj = NULL; |
292 | g->tobefnz = NULL; | 292 | g->tobefnz = NULL; |
293 | g->fixedgc = NULL; | ||
293 | g->sweepgc = g->sweepfin = NULL; | 294 | g->sweepgc = g->sweepfin = NULL; |
294 | g->gray = g->grayagain = NULL; | 295 | g->gray = g->grayagain = NULL; |
295 | g->weak = g->ephemeron = g->allweak = NULL; | 296 | g->weak = g->ephemeron = g->allweak = NULL; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.h,v 2.85 2013/08/20 17:46:34 roberto Exp roberto $ | 2 | ** $Id: lstate.h,v 2.86 2013/08/21 19:21:16 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 | */ |
@@ -24,6 +24,9 @@ | |||
24 | ** at the end of the 'allgc' list, after the 'l_registry' (which is | 24 | ** at the end of the 'allgc' list, after the 'l_registry' (which is |
25 | ** the first object to be added to the list). | 25 | ** the first object to be added to the list). |
26 | ** | 26 | ** |
27 | ** List 'fixedgc' keep objects that are not to be collected (currently | ||
28 | ** only small strings, such as reserved words). | ||
29 | ** | ||
27 | ** Open upvalues are not subject to independent garbage collection. They | 30 | ** Open upvalues are not subject to independent garbage collection. They |
28 | ** are collected together with their respective threads. (They are | 31 | ** are collected together with their respective threads. (They are |
29 | ** always gray, so they must be remarked in the atomic step. Usually | 32 | ** always gray, so they must be remarked in the atomic step. Usually |
@@ -132,6 +135,7 @@ typedef struct global_State { | |||
132 | GCObject *ephemeron; /* list of ephemeron tables (weak keys) */ | 135 | GCObject *ephemeron; /* list of ephemeron tables (weak keys) */ |
133 | GCObject *allweak; /* list of all-weak tables */ | 136 | GCObject *allweak; /* list of all-weak tables */ |
134 | GCObject *tobefnz; /* list of userdata to be GC */ | 137 | GCObject *tobefnz; /* list of userdata to be GC */ |
138 | GCObject *fixedgc; /* list of objects not to be collected */ | ||
135 | Mbuffer buff; /* temporary buffer for string concatenation */ | 139 | Mbuffer buff; /* temporary buffer for string concatenation */ |
136 | int gcpause; /* size of pause between successive GCs */ | 140 | int gcpause; /* size of pause between successive GCs */ |
137 | int gcstepmul; /* GC `granularity' */ | 141 | int gcstepmul; /* GC `granularity' */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstring.h,v 1.50 2013/08/16 18:55:49 roberto Exp roberto $ | 2 | ** $Id: lstring.h,v 1.51 2013/08/21 19:21:16 roberto Exp roberto $ |
3 | ** String table (keep all strings handled by Lua) | 3 | ** String table (keep all strings handled by Lua) |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -19,8 +19,6 @@ | |||
19 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ | 19 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ |
20 | (sizeof(s)/sizeof(char))-1)) | 20 | (sizeof(s)/sizeof(char))-1)) |
21 | 21 | ||
22 | #define luaS_fix(s) setbits((s)->tsv.marked, bit2mask(FIXEDBIT, LOCALBIT)) | ||
23 | |||
24 | 22 | ||
25 | /* | 23 | /* |
26 | ** test whether a string is a reserved word | 24 | ** test whether a string is a reserved word |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltm.c,v 2.19 2013/04/29 16:56:50 roberto Exp roberto $ | 2 | ** $Id: ltm.c,v 2.20 2013/05/06 17:19:11 roberto Exp roberto $ |
3 | ** Tag methods | 3 | ** Tag methods |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -43,7 +43,7 @@ void luaT_init (lua_State *L) { | |||
43 | int i; | 43 | int i; |
44 | for (i=0; i<TM_N; i++) { | 44 | for (i=0; i<TM_N; i++) { |
45 | G(L)->tmname[i] = luaS_new(L, luaT_eventname[i]); | 45 | G(L)->tmname[i] = luaS_new(L, luaT_eventname[i]); |
46 | luaS_fix(G(L)->tmname[i]); /* never collect these names */ | 46 | luaC_fix(L, obj2gco(G(L)->tmname[i])); /* never collect these names */ |
47 | } | 47 | } |
48 | } | 48 | } |
49 | 49 | ||