** Sweep for generational mode. Delete dead objects. (Because the ** collection is not incremental, there are no "new white" objects ** during the sweep. So, any white object must be dead.) For ** non-dead objects, advance their ages and clear the color of ** new objects. (Old objects keep their colors.) ** The ages of G_TOUCHED1 and G_TOUCHED2 objects cannot be advanced ** here, because these old
| 1086 | ** will also remove objects turned white here from any gray list. |
| 1087 | */ |
| 1088 | static GCObject **sweepgen (lua_State *L, global_State *g, GCObject **p, |
| 1089 | GCObject *limit, GCObject **pfirstold1) { |
| 1090 | static const lu_byte nextage[] = { |
| 1091 | G_SURVIVAL, /* from G_NEW */ |
| 1092 | G_OLD1, /* from G_SURVIVAL */ |
| 1093 | G_OLD1, /* from G_OLD0 */ |
| 1094 | G_OLD, /* from G_OLD1 */ |
| 1095 | G_OLD, /* from G_OLD (do not change) */ |
| 1096 | G_TOUCHED1, /* from G_TOUCHED1 (do not change) */ |
| 1097 | G_TOUCHED2 /* from G_TOUCHED2 (do not change) */ |
| 1098 | }; |
| 1099 | int white = luaC_white(g); |
| 1100 | GCObject *curr; |
| 1101 | while ((curr = *p) != limit) { |
| 1102 | if (iswhite(curr)) { /* is 'curr' dead? */ |
| 1103 | lua_assert(!isold(curr) && isdead(g, curr)); |
| 1104 | *p = curr->next; /* remove 'curr' from list */ |
| 1105 | freeobj(L, curr); /* erase 'curr' */ |
| 1106 | } |
| 1107 | else { /* correct mark and age */ |
| 1108 | if (getage(curr) == G_NEW) { /* new objects go back to white */ |
| 1109 | int marked = curr->marked & ~maskgcbits; /* erase GC bits */ |
| 1110 | curr->marked = cast_byte(marked | G_SURVIVAL | white); |
| 1111 | } |
| 1112 | else { /* all other objects will be old, and so keep their color */ |
| 1113 | setage(curr, nextage[getage(curr)]); |
| 1114 | if (getage(curr) == G_OLD1 && *pfirstold1 == NULL) |
| 1115 | *pfirstold1 = curr; /* first OLD1 object in the list */ |
| 1116 | } |
| 1117 | p = &curr->next; /* go to next element */ |
| 1118 | } |
| 1119 | } |
| 1120 | return p; |
| 1121 | } |
| 1122 | |
| 1123 | |
| 1124 | /* |
no test coverage detected