gczeal.js (5190B)
1 // |jit-test| skip-if: !hasFunction["gczeal"] 2 3 // Check zeal modes trigger GC as expected. 4 5 gczeal(0); 6 gcparam('minNurseryBytes', 1024 * 1024); 7 gcparam('maxNurseryBytes', 1024 * 1024); 8 gc(); 9 10 function checkGCsWithZeal(mode, freq, allocCount, expectedCounts) { 11 let counts = countGCsWithZeal(mode, freq, allocCount); 12 print(`checkGCsWithZeal ${mode} ${freq} ${allocCount}: ${JSON.stringify(expectedCounts)}`) 13 print(` got ${JSON.stringify(counts)}`); 14 for (const name in expectedCounts) { 15 assertEq(counts[name], expectedCounts[name], name); 16 } 17 } 18 19 function countGCsWithZeal(mode, freq, allocCount) { 20 gc(); 21 gczeal(mode, freq); 22 const counts = countGCs(allocCount); 23 gczeal(0); 24 return counts; 25 } 26 27 function countGCs(allocCount) { 28 const init = { 29 minor: gcparam("minorGCNumber"), 30 major: gcparam("majorGCNumber"), 31 slice: gcparam("sliceNumber") 32 } 33 34 let a = new Array(allocCount); 35 for (let i = 0; i < allocCount - 1 ; i++) { 36 a.push({x: i}); 37 } 38 finishgc(); 39 40 return { 41 minor: gcparam("minorGCNumber") - init.minor, 42 major: gcparam("majorGCNumber") - init.major, 43 slice: gcparam("sliceNumber") - init.slice 44 } 45 } 46 47 // 0: (None) Normal amount of collection (resets all modes) 48 checkGCsWithZeal(0, 0, 100, {major: 0, minor: 0, slice: 0}); 49 50 // 1: (RootsChange) Collect when roots are added or removed 51 checkGCsWithZeal(1, 0, 100, {major: 0, minor: 0, slice: 0}); 52 53 // 2: (Alloc) Collect when every N allocations (default: 100) 54 checkGCsWithZeal(2, 10, 100, {major: 10, minor: 10, slice: 10}); 55 checkGCsWithZeal(2, 20, 100, {major: 5, minor: 5, slice: 5}); 56 57 // 4: (VerifierPre) Verify pre write barriers between instructions 58 // This may trigger minor GCs because the pre barrier verifer disables and 59 // reenables generational GC every time it runs. 60 checkGCsWithZeal(4, 10, 100, {major: 0, slice: 0}); 61 62 // 6: (YieldBeforeRootMarking) Incremental GC in two slice that yields before root marking 63 checkGCsWithZeal(6, 10, 100, {major: 5, minor: 5, slice: 10}); 64 65 // 7: (GenerationalGC) Collect the nursery every N nursery allocations 66 checkGCsWithZeal(7, 10, 100, {major: 0, minor: 10, slice: 0}); 67 68 // 8: (YieldBeforeMarking) Incremental GC in two slices that yields between 69 // the root marking and marking phases 70 checkGCsWithZeal(8, 10, 100, {major: 5, minor: 5, slice: 10}); 71 72 // 9: (YieldBeforeSweeping) Incremental GC in two slices that yields between 73 // the marking and sweeping phases 74 checkGCsWithZeal(9, 10, 100, {major: 5, minor: 5, slice: 10}); 75 76 // 10: (IncrementalMultipleSlices) Incremental GC in many slices 77 // 78 // This produces non-deterministic results as we poll for background 79 // finalization to finish. The work budget is ignored for this phase. 80 let counts = countGCsWithZeal(10, 10, 1000); 81 assertEq(counts.major >= 1, true); 82 assertEq(counts.minor >= 1, true); 83 assertEq(counts.slice >= 90, true); 84 85 // 11: (IncrementalMarkingValidator) Verify incremental marking 86 checkGCsWithZeal(11, 0, 100, {major: 0, minor: 0, slice: 0}); 87 88 // 12: (ElementsBarrier) Use the individual element post-write barrier 89 // regardless of elements size 90 checkGCsWithZeal(12, 0, 100, {major: 0, minor: 0, slice: 0}); 91 92 // 13: (CheckHashTablesOnMinorGC) Check internal hashtables on minor GC 93 checkGCsWithZeal(13, 0, 100, {major: 0, minor: 0, slice: 0}); 94 95 // 14: (Compact) Perform a shrinking collection every N allocations 96 checkGCsWithZeal(14, 10, 100, {major: 10, minor: 10, slice: 10}); 97 98 // 15: (CheckHeapAfterGC) Walk the heap to check its integrity after every GC 99 checkGCsWithZeal(15, 0, 100, {major: 0, minor: 0, slice: 0}); 100 101 // 17: (YieldBeforeSweepingAtoms) Incremental GC in two slices that yields 102 // before sweeping the atoms table 103 checkGCsWithZeal(17, 10, 100, {major: 5, minor: 5, slice: 10}); 104 105 // 18: (CheckGrayMarking) Check gray marking invariants after every GC 106 checkGCsWithZeal(18, 0, 100, {major: 0, minor: 0, slice: 0}); 107 108 // 19: (YieldBeforeSweepingCaches) Incremental GC in two slices that yields 109 // before sweeping weak caches 110 checkGCsWithZeal(19, 10, 100, {major: 5, minor: 5, slice: 10}); 111 112 // 21: (YieldBeforeSweepingObjects) Incremental GC in multiple slices that 113 // yields before sweeping foreground finalized objects 114 checkGCsWithZeal(21, 10, 120, {major: 4, minor: 4, slice: 12}); 115 116 // 22: (YieldBeforeSweepingNonObjects) Incremental GC in multiple slices 117 // that yields before sweeping non-object GC things 118 checkGCsWithZeal(22, 10, 120, {major: 4, minor: 4, slice: 12}); 119 120 // 23: (YieldBeforeSweepingPropMapTrees) Incremental GC in multiple slices 121 // that yields before sweeping shape trees 122 checkGCsWithZeal(23, 10, 120, {major: 4, minor: 4, slice: 12}); 123 124 // 24: (CheckWeakMapMarking) Check weak map marking invariants after every 125 // GC 126 checkGCsWithZeal(24, 0, 100, {major: 0, minor: 0, slice: 0}); 127 128 // 25: (YieldWhileGrayMarking) Incremental GC in two slices that yields 129 // during gray marking 130 checkGCsWithZeal(25, 10, 100, {major: 5, minor: 5, slice: 10}); 131 132 // 26: (CheckHeapBeforeMinorGC) Check for invariant violations before every 133 // minor GC 134 checkGCsWithZeal(26, 0, 100, {major: 0, minor: 0, slice: 0});