** Performs a full GC cycle; if 'isemergency', set a flag to avoid ** some operations which could change the interpreter state in some ** unexpected ways (running finalizers and shrinking some structures). ** Before running the collection, check 'keepinvariant'; if it is true, ** there may be some objects marked as black, so the collector has ** to sweep all objects to turn them back to white (as
| 1157 | ** changed, nothing will be collected). |
| 1158 | */ |
| 1159 | void luaC_fullgc (lua_State *L, int isemergency) { |
| 1160 | global_State *g = G(L); |
| 1161 | lua_assert(g->gckind == KGC_NORMAL); |
| 1162 | if (isemergency) g->gckind = KGC_EMERGENCY; /* set flag */ |
| 1163 | if (keepinvariant(g)) { /* black objects? */ |
| 1164 | entersweep(L); /* sweep everything to turn them back to white */ |
| 1165 | } |
| 1166 | /* finish any pending sweep phase to start a new cycle */ |
| 1167 | luaC_runtilstate(L, bitmask(GCSpause)); |
| 1168 | luaC_runtilstate(L, ~bitmask(GCSpause)); /* start new collection */ |
| 1169 | luaC_runtilstate(L, bitmask(GCScallfin)); /* run up to finalizers */ |
| 1170 | /* estimate must be correct after a full GC cycle */ |
| 1171 | lua_assert(g->GCestimate == gettotalbytes(g)); |
| 1172 | luaC_runtilstate(L, bitmask(GCSpause)); /* finish collection */ |
| 1173 | g->gckind = KGC_NORMAL; |
| 1174 | setpause(g); |
| 1175 | } |
| 1176 | |
| 1177 | /* }====================================================== */ |
| 1178 |
no test coverage detected