MCPcopy Create free account
hub / github.com/DFHack/dfhack / singlestep

Function singlestep

depends/lua/src/lgc.c:1045–1097  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1043
1044
1045static lu_mem singlestep (lua_State *L) {
1046 global_State *g = G(L);
1047 switch (g->gcstate) {
1048 case GCSpause: {
1049 g->GCmemtrav = g->strt.size * sizeof(GCObject*);
1050 restartcollection(g);
1051 g->gcstate = GCSpropagate;
1052 return g->GCmemtrav;
1053 }
1054 case GCSpropagate: {
1055 g->GCmemtrav = 0;
1056 lua_assert(g->gray);
1057 propagatemark(g);
1058 if (g->gray == NULL) /* no more gray objects? */
1059 g->gcstate = GCSatomic; /* finish propagate phase */
1060 return g->GCmemtrav; /* memory traversed in this step */
1061 }
1062 case GCSatomic: {
1063 lu_mem work;
1064 propagateall(g); /* make sure gray list is empty */
1065 work = atomic(L); /* work is what was traversed by 'atomic' */
1066 entersweep(L);
1067 g->GCestimate = gettotalbytes(g); /* first estimate */;
1068 return work;
1069 }
1070 case GCSswpallgc: { /* sweep "regular" objects */
1071 return sweepstep(L, g, GCSswpfinobj, &g->finobj);
1072 }
1073 case GCSswpfinobj: { /* sweep objects with finalizers */
1074 return sweepstep(L, g, GCSswptobefnz, &g->tobefnz);
1075 }
1076 case GCSswptobefnz: { /* sweep objects to be finalized */
1077 return sweepstep(L, g, GCSswpend, NULL);
1078 }
1079 case GCSswpend: { /* finish sweeps */
1080 makewhite(g, g->mainthread); /* sweep main thread */
1081 checkSizes(L, g);
1082 g->gcstate = GCScallfin;
1083 return 0;
1084 }
1085 case GCScallfin: { /* call remaining finalizers */
1086 if (g->tobefnz && g->gckind != KGC_EMERGENCY) {
1087 int n = runafewfinalizers(L);
1088 return (n * GCFINALIZECOST);
1089 }
1090 else { /* emergency mode or no more finalizers */
1091 g->gcstate = GCSpause; /* finish collection */
1092 return 0;
1093 }
1094 }
1095 default: lua_assert(0); return 0;
1096 }
1097}
1098
1099
1100/*

Callers 2

luaC_runtilstateFunction · 0.85
luaC_stepFunction · 0.85

Calls 8

restartcollectionFunction · 0.85
propagatemarkFunction · 0.85
propagateallFunction · 0.85
atomicFunction · 0.85
entersweepFunction · 0.85
sweepstepFunction · 0.85
checkSizesFunction · 0.85
runafewfinalizersFunction · 0.85

Tested by

no test coverage detected