MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / sweepgen

Function sweepgen

3rd/lua-5.4.3/src/lgc.c:1088–1121  ·  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

1086** will also remove objects turned white here from any gray list.
1087*/
1088static 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/*

Callers 1

youngcollectionFunction · 0.85

Calls 1

freeobjFunction · 0.85

Tested by

no test coverage detected