aboutsummaryrefslogtreecommitdiff
path: root/lgc.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-06-07 13:55:34 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-06-07 13:55:34 -0300
commitfabe4ec487cb034ef983a29c52df2927be463d3c (patch)
tree4b824977d6b99b657c821681ca1a643ad345569a /lgc.c
parent575074fd857b90cd7c14c7b172e8fe147080962a (diff)
downloadlua-fabe4ec487cb034ef983a29c52df2927be463d3c.tar.gz
lua-fabe4ec487cb034ef983a29c52df2927be463d3c.tar.bz2
lua-fabe4ec487cb034ef983a29c52df2927be463d3c.zip
better barrier for prototypes
Diffstat (limited to 'lgc.c')
-rw-r--r--lgc.c48
1 files changed, 20 insertions, 28 deletions
diff --git a/lgc.c b/lgc.c
index bf36d025..dd6af6c5 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 2.97 2010/06/02 18:36:58 roberto Exp roberto $ 2** $Id: lgc.c,v 2.98 2010/06/04 13:25:10 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*/
@@ -157,14 +157,24 @@ void luaC_barrierback_ (lua_State *L, GCObject *o) {
157 157
158 158
159/* 159/*
160** barrier for prototypes 160** barrier for prototypes. When creating first closure (cache is
161** NULL), use a forward barrier; this may be the only closure of the
162** prototype (if it is a "regular" function, with a single instance)
163** and the prototype may be big, so it is better to avoid traversing
164** it again. Otherwise, use a backward barrier, to avoid marking all
165** possible instances.
161*/ 166*/
162LUAI_FUNC void luaC_barrierproto_ (lua_State *L, GCObject *p) { 167LUAI_FUNC void luaC_barrierproto_ (lua_State *L, Proto *p, Closure *c) {
163 global_State *g = G(L); 168 global_State *g = G(L);
164 lua_assert(isblack(p)); 169 lua_assert(isblack(obj2gco(p)));
165 black2gray(p); /* make object gray (again) */ 170 if (p->cache == NULL) { /* first time? */
166 gco2p(p)->gclist = g->clearcache; 171 luaC_objbarrier(L, p, c);
167 g->clearcache = p; 172 }
173 else { /* use a backward barrier */
174 black2gray(obj2gco(p)); /* make prototype gray (again) */
175 p->gclist = g->grayagain;
176 g->grayagain = obj2gco(p);
177 }
168} 178}
169 179
170 180
@@ -312,7 +322,7 @@ static void remarkupvals (global_State *g) {
312static void markroot (lua_State *L) { 322static void markroot (lua_State *L) {
313 global_State *g = G(L); 323 global_State *g = G(L);
314 g->gray = g->grayagain = NULL; 324 g->gray = g->grayagain = NULL;
315 g->weak = g->allweak = g->ephemeron = g->clearcache = NULL; 325 g->weak = g->allweak = g->ephemeron = NULL;
316 markobject(g, g->mainthread); 326 markobject(g, g->mainthread);
317 markvalue(g, &g->l_registry); 327 markvalue(g, &g->l_registry);
318 markmt(g); 328 markmt(g);
@@ -422,19 +432,10 @@ static int traversetable (global_State *g, Table *h) {
422} 432}
423 433
424 434
425/*
426** if prototype's cached closure is not marked, erase it so it
427** can be collected
428*/
429static void checkcache (Proto *p) {
430 if (p->cache && iswhite(obj2gco(p->cache)))
431 p->cache = NULL; /* allow cache to be collected */
432}
433
434
435static int traverseproto (global_State *g, Proto *f) { 435static int traverseproto (global_State *g, Proto *f) {
436 int i; 436 int i;
437 checkcache(f); 437 if (f->cache && iswhite(obj2gco(f->cache)))
438 f->cache = NULL; /* allow cache to be collected */
438 stringmark(f->source); 439 stringmark(f->source);
439 for (i = 0; i < f->sizek; i++) /* mark literals */ 440 for (i = 0; i < f->sizek; i++) /* mark literals */
440 markvalue(g, &f->k[i]); 441 markvalue(g, &f->k[i]);
@@ -557,14 +558,6 @@ static void convergeephemerons (global_State *g) {
557** ======================================================= 558** =======================================================
558*/ 559*/
559 560
560/*
561** clear cache field in all prototypes in list 'l'
562*/
563static void clearproto (GCObject *l) {
564 for (; l != NULL; l = gco2p(l)->gclist)
565 checkcache(gco2p(l));
566}
567
568 561
569/* 562/*
570** clear collected entries from all weaktables in list 'l' 563** clear collected entries from all weaktables in list 'l'
@@ -878,7 +871,6 @@ static void atomic (lua_State *L) {
878 cleartable(g->weak); 871 cleartable(g->weak);
879 cleartable(g->ephemeron); 872 cleartable(g->ephemeron);
880 cleartable(g->allweak); 873 cleartable(g->allweak);
881 clearproto(g->clearcache);
882 g->sweepstrgc = 0; /* prepare to sweep strings */ 874 g->sweepstrgc = 0; /* prepare to sweep strings */
883 g->gcstate = GCSsweepstring; 875 g->gcstate = GCSsweepstring;
884 g->currentwhite = cast_byte(otherwhite(g)); /* flip current white */ 876 g->currentwhite = cast_byte(otherwhite(g)); /* flip current white */