** Traverse an ephemeron table and link it to proper list. Returns true ** iff any object was marked during this traversal (which implies that ** convergence has to continue). During propagation phase, keep table ** in 'grayagain' list, to be visited again in the atomic phase. In ** the atomic phase, if table has any white->white entry, it has to ** be revisited during ephemeron convergence (as th
| 539 | ** by 'genlink'. |
| 540 | */ |
| 541 | static int traverseephemeron (global_State *g, Table *h, int inv) { |
| 542 | int hasclears = 0; /* true if table has white keys */ |
| 543 | int hasww = 0; /* true if table has entry "white-key -> white-value" */ |
| 544 | unsigned int i; |
| 545 | unsigned int nsize = sizenode(h); |
| 546 | int marked = traversearray(g, h); /* traverse array part */ |
| 547 | /* traverse hash part; if 'inv', traverse descending |
| 548 | (see 'convergeephemerons') */ |
| 549 | for (i = 0; i < nsize; i++) { |
| 550 | Node *n = inv ? gnode(h, nsize - 1 - i) : gnode(h, i); |
| 551 | if (isempty(gval(n))) /* entry is empty? */ |
| 552 | clearkey(n); /* clear its key */ |
| 553 | else if (iscleared(g, gckeyN(n))) { /* key is not marked (yet)? */ |
| 554 | hasclears = 1; /* table must be cleared */ |
| 555 | if (valiswhite(gval(n))) /* value not marked yet? */ |
| 556 | hasww = 1; /* white-white entry */ |
| 557 | } |
| 558 | else if (valiswhite(gval(n))) { /* value not marked yet? */ |
| 559 | marked = 1; |
| 560 | reallymarkobject(g, gcvalue(gval(n))); /* mark it now */ |
| 561 | } |
| 562 | } |
| 563 | /* link table into proper list */ |
| 564 | if (g->gcstate == GCSpropagate) |
| 565 | linkgclist(h, g->grayagain); /* must retraverse it in atomic phase */ |
| 566 | else if (hasww) /* table has white->white entries? */ |
| 567 | linkgclist(h, g->ephemeron); /* have to propagate again */ |
| 568 | else if (hasclears) /* table has white keys? */ |
| 569 | linkgclist(h, g->allweak); /* may have to clean white keys */ |
| 570 | else |
| 571 | genlink(g, obj2gco(h)); /* check whether collector still needs to see it */ |
| 572 | return marked; |
| 573 | } |
| 574 | |
| 575 | |
| 576 | static void traversestrongtable (global_State *g, Table *h) { |
no test coverage detected