** Does a generational "step". ** Usually, this means doing a minor collection and setting the debt to ** make another collection when memory grows 'genminormul'% larger. ** ** However, there are exceptions. If memory grows 'genmajormul'% ** larger than it was at the end of the last major collection (kept ** in 'g->GCestimate'), the function does a major collection. At the ** end, it checks wheth
| 1440 | ** in that case, do a minor collection. |
| 1441 | */ |
| 1442 | static void genstep (lua_State *L, global_State *g) { |
| 1443 | if (g->lastatomic != 0) /* last collection was a bad one? */ |
| 1444 | stepgenfull(L, g); /* do a full step */ |
| 1445 | else { |
| 1446 | lu_mem majorbase = g->GCestimate; /* memory after last major collection */ |
| 1447 | lu_mem majorinc = (majorbase / 100) * getgcparam(g->genmajormul); |
| 1448 | if (g->GCdebt > 0 && gettotalbytes(g) > majorbase + majorinc) { |
| 1449 | lu_mem numobjs = fullgen(L, g); /* do a major collection */ |
| 1450 | if (gettotalbytes(g) < majorbase + (majorinc / 2)) { |
| 1451 | /* collected at least half of memory growth since last major |
| 1452 | collection; keep doing minor collections. */ |
| 1453 | lua_assert(g->lastatomic == 0); |
| 1454 | } |
| 1455 | else { /* bad collection */ |
| 1456 | g->lastatomic = numobjs; /* signal that last collection was bad */ |
| 1457 | setpause(g); /* do a long wait for next (major) collection */ |
| 1458 | } |
| 1459 | } |
| 1460 | else { /* regular case; do a minor collection */ |
| 1461 | youngcollection(L, g); |
| 1462 | setminordebt(g); |
| 1463 | g->GCestimate = majorbase; /* preserve base value */ |
| 1464 | } |
| 1465 | } |
| 1466 | lua_assert(isdecGCmodegen(g)); |
| 1467 | } |
| 1468 | |
| 1469 | /* }====================================================== */ |
| 1470 |
no test coverage detected