| 1 |
// |jit-test| skip-if: !getBuildConfiguration("has-gczeal") || (getBuildConfiguration("osx") && getBuildConfiguration("arm64")) |
| 2 |
|
| 3 |
// Test aborting an incremental GC in all possible states |
| 4 |
|
| 5 |
gczeal(0); |
| 6 |
gc(); |
| 7 |
|
| 8 |
// Allocate objectCount objects in zoneCount zones and run a incremental |
| 9 |
// shrinking GC with slices with a work budget of sliceBudget until we reach |
| 10 |
// GC state abortState at which point, abort the GC. |
| 11 |
function testAbort(zoneCount, objectCount, sliceBudget, abortState) |
| 12 |
{ |
| 13 |
|
| 14 |
var zones = []; |
| 15 |
for (var i = 0; i < zoneCount; i++) { |
| 16 |
var zone = newGlobal({newCompartment: true}); |
| 17 |
evaluate("var objects; " + |
| 18 |
"function makeObjectGraph(objectCount) { " + |
| 19 |
" objects = []; " + |
| 20 |
" for (var i = 0; i < objectCount; i++) " + |
| 21 |
" objects.push({i: i}); " + |
| 22 |
"}", |
| 23 |
{ global: zone }); |
| 24 |
zone.makeObjectGraph(objectCount); |
| 25 |
zones.push(zone); |
| 26 |
} |
| 27 |
|
| 28 |
gc(); |
| 29 |
|
| 30 |
var didAbort = false; |
| 31 |
startgc(sliceBudget, "shrinking"); |
| 32 |
assertEq(currentgc().isShrinking, true); |
| 33 |
while (gcstate() !== "NotActive") { |
| 34 |
if (gcstate() == abortState) { |
| 35 |
abortgc(); |
| 36 |
didAbort = true; |
| 37 |
break; |
| 38 |
} |
| 39 |
|
| 40 |
gcslice(sliceBudget); |
| 41 |
} |
| 42 |
|
| 43 |
assertEq(gcstate(), "NotActive"); |
| 44 |
if (abortState) |
| 45 |
assertEq(didAbort, true); |
| 46 |
|
| 47 |
return zones; |
| 48 |
} |
| 49 |
|
| 50 |
gczeal(0); |
| 51 |
testAbort(10, 10000, 10000); |
| 52 |
testAbort(10, 10000, 10000, "Mark"); |
| 53 |
testAbort(10, 10000, 1000, "Sweep"); |
| 54 |
testAbort(10, 10000, 10000, "Compact"); |
| 55 |
// Note: we do not yield automatically before Finalize or Decommit, as they |
| 56 |
// yield internally. Thus, we may not witness an incremental state in this |
| 57 |
// phase and cannot test it explicitly. |