MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / sweepgen

Function sweepgen

lib/lua/src/lgc.c:1115–1148  ·  view source on GitHub ↗

** 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

Source from the content-addressed store, hash-verified

1113** will also remove objects turned white here from any gray list.
1114*/
1115static GCObject **sweepgen (lua_State *L, global_State *g, GCObject **p,
1116 GCObject *limit, GCObject **pfirstold1) {
1117 static const lu_byte nextage[] = {
1118 G_SURVIVAL, /* from G_NEW */
1119 G_OLD1, /* from G_SURVIVAL */
1120 G_OLD1, /* from G_OLD0 */
1121 G_OLD, /* from G_OLD1 */
1122 G_OLD, /* from G_OLD (do not change) */
1123 G_TOUCHED1, /* from G_TOUCHED1 (do not change) */
1124 G_TOUCHED2 /* from G_TOUCHED2 (do not change) */
1125 };
1126 int white = luaC_white(g);
1127 GCObject *curr;
1128 while ((curr = *p) != limit) {
1129 if (iswhite(curr)) { /* is 'curr' dead? */
1130 lua_assert(!isold(curr) && isdead(g, curr));
1131 *p = curr->next; /* remove 'curr' from list */
1132 freeobj(L, curr); /* erase 'curr' */
1133 }
1134 else { /* correct mark and age */
1135 if (getage(curr) == G_NEW) { /* new objects go back to white */
1136 int marked = curr->marked & ~maskgcbits; /* erase GC bits */
1137 curr->marked = cast_byte(marked | G_SURVIVAL | white);
1138 }
1139 else { /* all other objects will be old, and so keep their color */
1140 setage(curr, nextage[getage(curr)]);
1141 if (getage(curr) == G_OLD1 && *pfirstold1 == NULL)
1142 *pfirstold1 = curr; /* first OLD1 object in the list */
1143 }
1144 p = &curr->next; /* go to next element */
1145 }
1146 }
1147 return p;
1148}
1149
1150
1151/*

Callers 1

youngcollectionFunction · 0.85

Calls 1

freeobjFunction · 0.85

Tested by

no test coverage detected