Skip to content

Commit 6b51133

Browse files
committed
Thread stacks resized in the atomic phase
Although stack resize can be a little expensive, it seems unusual to have too many threads needing resize during one GC cycle. On the other hand, the change allows full collections to skip the propagate phase, going straight from a pause to the atomic phase.
1 parent cbae016 commit 6b51133

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lgc.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -638,16 +638,16 @@ static int traversethread (global_State *g, lua_State *th) {
638638
for (uv = th->openupval; uv != NULL; uv = uv->u.open.next)
639639
markobject(g, uv); /* open upvalues cannot be collected */
640640
if (g->gcstate == GCSatomic) { /* final traversal? */
641-
for (; o < th->stack_last.p + EXTRA_STACK; o++)
641+
if (!g->gcemergency)
642+
luaD_shrinkstack(th); /* do not change stack in emergency cycle */
643+
for (o = th->top.p; o < th->stack_last.p + EXTRA_STACK; o++)
642644
setnilvalue(s2v(o)); /* clear dead stack slice */
643645
/* 'remarkupvals' may have removed thread from 'twups' list */
644646
if (!isintwups(th) && th->openupval != NULL) {
645647
th->twups = g->twups; /* link it back to the list */
646648
g->twups = th;
647649
}
648650
}
649-
else if (!g->gcemergency)
650-
luaD_shrinkstack(th); /* do not change stack in emergency cycle */
651651
return 1 + stacksize(th);
652652
}
653653

@@ -1710,6 +1710,8 @@ static void fullinc (lua_State *L, global_State *g) {
17101710
entersweep(L); /* sweep everything to turn them back to white */
17111711
/* finish any pending sweep phase to start a new cycle */
17121712
luaC_runtilstate(L, bitmask(GCSpause));
1713+
luaC_runtilstate(L, bitmask(GCSpropagate)); /* start new cycle */
1714+
g->gcstate = GCSenteratomic; /* go straight to atomic phase ??? */
17131715
luaC_runtilstate(L, bitmask(GCScallfin)); /* run up to finalizers */
17141716
/* estimate must be correct after a full GC cycle */
17151717
lua_assert(g->GCestimate == gettotalbytes(g));

0 commit comments

Comments
 (0)