tenuring.js (2338B)
1 // Check that we switch to allocating in the tenured heap after the first 2 // nursery collection. 3 4 function buildObjectTree(depth) { 5 if (depth === 0) { 6 return "leaf"; 7 } 8 9 return { 10 left: buildObjectTree(depth - 1), 11 right: buildObjectTree(depth - 1) 12 }; 13 } 14 15 function buildArrayTree(depth) { 16 if (depth === 0) { 17 return []; 18 } 19 20 return [ 21 buildArrayTree(depth - 1), 22 buildArrayTree(depth - 1) 23 ]; 24 } 25 26 function testRoundTrip(depth, objectTree, expectedNurseryAllocated) { 27 const input = objectTree ? buildObjectTree(depth) : buildArrayTree(depth); 28 29 gc(); 30 const initialMinorNumber = gcparam('minorGCNumber'); 31 32 const output = deserialize(serialize(input)); 33 checkHeap(output, depth, objectTree, expectedNurseryAllocated); 34 35 const minorCollections = gcparam('minorGCNumber') - initialMinorNumber; 36 const expectedMinorCollections = expectedNurseryAllocated ? 0 : 1; 37 assertEq(minorCollections, expectedMinorCollections); 38 } 39 40 function checkHeap(tree, depth, objectTree, expectedNurseryAllocated) { 41 const counts = countHeapLocations(tree, objectTree); 42 43 const total = counts.nursery + counts.tenured; 44 assertEq(total, (2 ** (depth + 1)) - 1); 45 46 if (expectedNurseryAllocated) { 47 assertEq(counts.tenured, 0); 48 assertEq(counts.nursery >= 1, true); 49 } else { 50 assertEq(counts.tenured >= 1, true); 51 // We get a single nursery allocation when we trigger minor GC. 52 assertEq(counts.nursery <= 1, true); 53 } 54 } 55 56 function countHeapLocations(tree, objectTree, counts) { 57 if (!counts) { 58 counts = {nursery: 0, tenured: 0}; 59 } 60 61 if (isNurseryAllocated(tree)) { 62 counts.nursery++; 63 } else { 64 counts.tenured++; 65 } 66 67 if (objectTree) { 68 if (tree !== "leaf") { 69 countHeapLocations(tree.left, objectTree, counts); 70 countHeapLocations(tree.right, objectTree, counts); 71 } 72 } else { 73 if (tree.length !== 0) { 74 countHeapLocations(tree[0], objectTree, counts); 75 countHeapLocations(tree[1], objectTree, counts); 76 } 77 } 78 79 return counts; 80 } 81 82 gczeal(0); 83 gcparam('minNurseryBytes', 1024 * 1024); 84 gcparam('maxNurseryBytes', 1024 * 1024); 85 gcparam('semispaceNurseryEnabled', 0); 86 gc(); 87 88 testRoundTrip(1, true, true); 89 testRoundTrip(1, false, true); 90 testRoundTrip(4, true, true); 91 testRoundTrip(4, false, true); 92 testRoundTrip(15, true, false); 93 testRoundTrip(15, false, false);