MCPcopy Create free account
hub / github.com/Achain-Dev/Achain / singlestep

Function singlestep

src/Chain/libraries/glua/lgc.cpp:1048–1101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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