aboutsummaryrefslogtreecommitdiff
path: root/lgc.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2013-08-16 15:55:49 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2013-08-16 15:55:49 -0300
commit439d74e29f3234a034777f88b260523afe8c0446 (patch)
treea3ee160dccfd3cf0f065edbba07290c4ba9af93d /lgc.c
parent3679d33b02782ff7d7d0fa163b815902b189c89e (diff)
downloadlua-439d74e29f3234a034777f88b260523afe8c0446.tar.gz
lua-439d74e29f3234a034777f88b260523afe8c0446.tar.bz2
lua-439d74e29f3234a034777f88b260523afe8c0446.zip
added 'local' bit (true => object is only refered by local variables)
Diffstat (limited to 'lgc.c')
-rw-r--r--lgc.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/lgc.c b/lgc.c
index 75daf796..e4d6b6c1 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 2.144 2013/08/07 15:39:09 roberto Exp roberto $ 2** $Id: lgc.c,v 2.145 2013/08/13 17:36:44 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*/
@@ -74,11 +74,19 @@
74 lua_longassert(!iscollectable(obj) || righttt(obj)) 74 lua_longassert(!iscollectable(obj) || righttt(obj))
75 75
76 76
77#define markvalue(g,o) { checkconsistency(o); \ 77#define marklocalvalue(g,o) { checkconsistency(o); \
78 if (valiswhite(o)) reallymarkobject(g,gcvalue(o)); } 78 if (valiswhite(o)) reallymarkobject(g,gcvalue(o)); }
79 79
80#define markobject(g,t) { if ((t) && iswhite(obj2gco(t))) \ 80#define markvalue(g,o) { \
81 reallymarkobject(g, obj2gco(t)); } 81 lua_longassert(!(iscollectable(o) && islocal(gcvalue(o)))); \
82 marklocalvalue(g,o); }
83
84#define marklocalobject(g,t) { \
85 if ((t) && iswhite(obj2gco(t))) \
86 reallymarkobject(g, obj2gco(t)); }
87
88#define markobject(g,t) \
89 { lua_assert((t) == NULL || !islocal(obj2gco(t))); marklocalobject(g,t); }
82 90
83static void reallymarkobject (global_State *g, GCObject *o); 91static void reallymarkobject (global_State *g, GCObject *o);
84 92
@@ -259,7 +267,7 @@ static void reallymarkobject (global_State *g, GCObject *o) {
259 } 267 }
260 case LUA_TUPVAL: { 268 case LUA_TUPVAL: {
261 UpVal *uv = gco2uv(o); 269 UpVal *uv = gco2uv(o);
262 markvalue(g, uv->v); 270 marklocalvalue(g, uv->v);
263 if (uv->v != &uv->value) /* open? */ 271 if (uv->v != &uv->value) /* open? */
264 return; /* open upvalues remain gray */ 272 return; /* open upvalues remain gray */
265 size = sizeof(UpVal); 273 size = sizeof(UpVal);
@@ -331,7 +339,7 @@ static void remarkupvals (global_State *g) {
331 GCObject *uv = gco2th(thread)->openupval; 339 GCObject *uv = gco2th(thread)->openupval;
332 for (; uv != NULL; uv = gch(uv)->next) { 340 for (; uv != NULL; uv = gch(uv)->next) {
333 if (isgray(uv)) /* marked? */ 341 if (isgray(uv)) /* marked? */
334 markvalue(g, gco2uv(uv)->v); /* remark upvalue's value */ 342 marklocalvalue(g, gco2uv(uv)->v); /* remark upvalue's value */
335 } 343 }
336 } 344 }
337 } 345 }
@@ -486,7 +494,7 @@ static int traverseproto (global_State *g, Proto *f) {
486static lu_mem traverseCclosure (global_State *g, CClosure *cl) { 494static lu_mem traverseCclosure (global_State *g, CClosure *cl) {
487 int i; 495 int i;
488 for (i = 0; i < cl->nupvalues; i++) /* mark its upvalues */ 496 for (i = 0; i < cl->nupvalues; i++) /* mark its upvalues */
489 markvalue(g, &cl->upvalue[i]); 497 marklocalvalue(g, &cl->upvalue[i]);
490 return sizeCclosure(cl->nupvalues); 498 return sizeCclosure(cl->nupvalues);
491} 499}
492 500
@@ -494,7 +502,7 @@ static lu_mem traverseLclosure (global_State *g, LClosure *cl) {
494 int i; 502 int i;
495 markobject(g, cl->p); /* mark its prototype */ 503 markobject(g, cl->p); /* mark its prototype */
496 for (i = 0; i < cl->nupvalues; i++) /* mark its upvalues */ 504 for (i = 0; i < cl->nupvalues; i++) /* mark its upvalues */
497 markobject(g, cl->upvals[i]); 505 marklocalobject(g, cl->upvals[i]);
498 return sizeLclosure(cl->nupvalues); 506 return sizeLclosure(cl->nupvalues);
499} 507}
500 508
@@ -505,7 +513,7 @@ static lu_mem traversestack (global_State *g, lua_State *th) {
505 if (o == NULL) 513 if (o == NULL)
506 return 1; /* stack not completely built yet */ 514 return 1; /* stack not completely built yet */
507 for (; o < th->top; o++) /* mark live elements in the stack */ 515 for (; o < th->top; o++) /* mark live elements in the stack */
508 markvalue(g, o); 516 marklocalvalue(g, o);
509 if (g->gcstate == GCSatomic) { /* final traversal? */ 517 if (g->gcstate == GCSatomic) { /* final traversal? */
510 StkId lim = th->stack + th->stacksize; /* real end of stack */ 518 StkId lim = th->stack + th->stacksize; /* real end of stack */
511 for (; o < lim; o++) /* clear not-marked stack slice */ 519 for (; o < lim; o++) /* clear not-marked stack slice */