aboutsummaryrefslogtreecommitdiff
path: root/lgc.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-12-20 12:58:05 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-12-20 12:58:05 -0200
commit1d5b885437286a307a77b5d12756d73d374efd54 (patch)
treeb2daefb8d44be37af3b61816eb1f966c94d44393 /lgc.c
parent4dc0be950ad67e4385400aacd25e10325a2a6e59 (diff)
downloadlua-1d5b885437286a307a77b5d12756d73d374efd54.tar.gz
lua-1d5b885437286a307a77b5d12756d73d374efd54.tar.bz2
lua-1d5b885437286a307a77b5d12756d73d374efd54.zip
when running Lua code, there is no need to keep 'L->top' "correct";
set it only when needed.
Diffstat (limited to 'lgc.c')
-rw-r--r--lgc.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/lgc.c b/lgc.c
index 8d28d3bf..37bcdb8d 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 2.241 2017/12/01 17:38:49 roberto Exp roberto $ 2** $Id: lgc.c,v 2.242 2017/12/08 17:28:25 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*/
@@ -569,13 +569,23 @@ static int traverseLclosure (global_State *g, LClosure *cl) {
569} 569}
570 570
571 571
572/*
573** Traverse a thread, marking the elements in the stack up to its top
574** and cleaning the rest of the stack in the last traversal.
575** That ensures that the entire stack have valid (non-dead) objects.
576** In an emergency collection running Lua code, 'L->top' may not be
577** update. In that case, traverse at least up to 'ci->top'.
578*/
572static int traversethread (global_State *g, lua_State *th) { 579static int traversethread (global_State *g, lua_State *th) {
573 StkId o = th->stack; 580 StkId o = th->stack;
581 StkId top = th->top;
574 if (o == NULL) 582 if (o == NULL)
575 return 1; /* stack not completely built yet */ 583 return 1; /* stack not completely built yet */
576 lua_assert(g->gcstate == GCSatomic || 584 lua_assert(g->gcstate == GCSatomic ||
577 th->openupval == NULL || isintwups(th)); 585 th->openupval == NULL || isintwups(th));
578 for (; o < th->top; o++) /* mark live elements in the stack */ 586 if (g->gcemergency && isLuacode(th->ci) && top < th->ci->top)
587 top = th->ci->top;
588 for (; o < top; o++) /* mark live elements in the stack */
579 markvalue(g, s2v(o)); 589 markvalue(g, s2v(o));
580 if (g->gcstate == GCSatomic) { /* final traversal? */ 590 if (g->gcstate == GCSatomic) { /* final traversal? */
581 StkId lim = th->stack + th->stacksize; /* real end of stack */ 591 StkId lim = th->stack + th->stacksize; /* real end of stack */