** Traverse a thread, marking the elements in the stack up to its top ** and cleaning the rest of the stack in the final traversal. That ** ensures that the entire stack have valid (non-dead) objects. ** Threads have no barriers. In gen. mode, old threads must be visited ** at every cycle, because they might point to young objects. In inc. ** mode, the thread can still be modified before the end
| 627 | ** the propagate phase (which can only happen in incremental mode). |
| 628 | */ |
| 629 | static int traversethread (global_State *g, lua_State *th) { |
| 630 | UpVal *uv; |
| 631 | StkId o = th->stack.p; |
| 632 | if (isold(th) || g->gcstate == GCSpropagate) |
| 633 | linkgclist(th, g->grayagain); /* insert into 'grayagain' list */ |
| 634 | if (o == NULL) |
| 635 | return 1; /* stack not completely built yet */ |
| 636 | lua_assert(g->gcstate == GCSatomic || |
| 637 | th->openupval == NULL || isintwups(th)); |
| 638 | for (; o < th->top.p; o++) /* mark live elements in the stack */ |
| 639 | markvalue(g, s2v(o)); |
| 640 | for (uv = th->openupval; uv != NULL; uv = uv->u.open.next) |
| 641 | markobject(g, uv); /* open upvalues cannot be collected */ |
| 642 | if (g->gcstate == GCSatomic) { /* final traversal? */ |
| 643 | if (!g->gcemergency) |
| 644 | luaD_shrinkstack(th); /* do not change stack in emergency cycle */ |
| 645 | for (o = th->top.p; o < th->stack_last.p + EXTRA_STACK; o++) |
| 646 | setnilvalue(s2v(o)); /* clear dead stack slice */ |
| 647 | /* 'remarkupvals' may have removed thread from 'twups' list */ |
| 648 | if (!isintwups(th) && th->openupval != NULL) { |
| 649 | th->twups = g->twups; /* link it back to the list */ |
| 650 | g->twups = th; |
| 651 | } |
| 652 | } |
| 653 | return 1 + stacksize(th); |
| 654 | } |
| 655 | |
| 656 | |
| 657 | /* |
no test coverage detected