** sweep at most 'count' elements from a list of GCObjects erasing dead ** objects, where a dead (not alive) object is one marked with the "old" ** (non current) white and not fixed. ** In non-generational mode, change all non-dead objects back to white, ** preparing for next collection cycle. ** In generational mode, keep black objects black, and also mark them as ** old; stop when hitting an old
| 716 | ** When object is a thread, sweep its list of open upvalues too. |
| 717 | */ |
| 718 | static GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count) { |
| 719 | global_State *g = G(L); |
| 720 | int ow = otherwhite(g); |
| 721 | int toclear, toset; /* bits to clear and to set in all live objects */ |
| 722 | int tostop; /* stop sweep when this is true */ |
| 723 | if (isgenerational(g)) { /* generational mode? */ |
| 724 | toclear = ~0; /* clear nothing */ |
| 725 | toset = bitmask(OLDBIT); /* set the old bit of all surviving objects */ |
| 726 | tostop = bitmask(OLDBIT); /* do not sweep old generation */ |
| 727 | } |
| 728 | else { /* normal mode */ |
| 729 | toclear = maskcolors; /* clear all color bits + old bit */ |
| 730 | toset = luaC_white(g); /* make object white */ |
| 731 | tostop = 0; /* do not stop */ |
| 732 | } |
| 733 | while (*p != NULL && count-- > 0) { |
| 734 | GCObject *curr = *p; |
| 735 | int marked = gch(curr)->marked; |
| 736 | if (isdeadm(ow, marked)) { /* is 'curr' dead? */ |
| 737 | *p = gch(curr)->next; /* remove 'curr' from list */ |
| 738 | freeobj(L, curr); /* erase 'curr' */ |
| 739 | } |
| 740 | else { |
| 741 | if (testbits(marked, tostop)) |
| 742 | return NULL; /* stop sweeping this list */ |
| 743 | if (gch(curr)->tt == LUA_TTHREAD) |
| 744 | sweepthread(L, gco2th(curr)); /* sweep thread's upvalues */ |
| 745 | /* update marks */ |
| 746 | gch(curr)->marked = cast_byte((marked & toclear) | toset); |
| 747 | p = &gch(curr)->next; /* go to next element */ |
| 748 | } |
| 749 | } |
| 750 | return (*p == NULL) ? NULL : p; |
| 751 | } |
| 752 | |
| 753 | |
| 754 | /* |
no test coverage detected