Debian Codegraph @

js/src/jit-test/lib/pretenure.js

raw
1 // Functions shared by gc/pretenure-*.js tests
2
3 const is64bit = getBuildConfiguration("pointer-byte-size") === 8;
4
5 // Count of objects that will exceed the size of the nursery.
6 const nurseryCount = is64bit ? 25000 : 50000;
7
8 // Count of objects that will exceed the tenured heap collection threshold.
9 const tenuredCount = is64bit ? 400000 : 800000;
10
11 function setupPretenureTest() {
12 // The test requires that baseline is enabled and is not bypassed with
13 // --ion-eager or similar.
14 let jitOptions = getJitCompilerOptions();
15 if (!jitOptions['baseline.enable'] ||
16 jitOptions['ion.warmup.trigger'] <= jitOptions['baseline.warmup.trigger']) {
17 print("Unsupported JIT options");
18 quit();
19 }
20
21 // Disable zeal modes that will interfere with this test.
22 gczeal(0);
23
24 setJitCompilerOption("offthread-compilation.enable", 0)
25
26 // Restrict nursery size so we can fill it quicker, and ensure it is resized.
27 let size = 1024 * 1024;
28 if (gcparam("semispaceNurseryEnabled")) {
29 size *= 2;
30 }
31 gcparam("minNurseryBytes", size);
32 gcparam("maxNurseryBytes", size);
33
34 // Limit allocation threshold so we trigger major GCs sooner.
35 gcparam("allocationThreshold", 1 /* MB */);
36
37 // Disable incremental GC so there's at most one minor GC per major GC.
38 gcparam("incrementalGCEnabled", false);
39
40 // Disable balanced heap limits to make the number of GCs predictable.
41 gcparam("balancedHeapLimitsEnabled", false);
42
43 // Force a nursery collection to apply size parameters.
44 let o = {};
45
46 // Run a full (all-zones) shrinking GC. The heap size after this GC is
47 // significant because it affects the number of major GCs triggered by the
48 // tests.
49 gc(undefined, 'shrinking');
50 }
51
52 function allocateObjects(count, longLived) {
53 let array = new Array(nurseryCount);
54 for (let i = 0; i < count; i++) {
55 let x = {x: i};
56 if (longLived) {
57 array[i % nurseryCount] = x;
58 } else {
59 array[0] = x;
60 }
61 }
62 return array;
63 }
64
65 function allocateArrays(count, longLived) {
66 let array = new Array(nurseryCount);
67 for (let i = 0; i < count; i++) {
68 let x = [i];
69 if (longLived) {
70 array[i % nurseryCount] = x;
71 } else {
72 array[0] = x;
73 }
74 }
75 return array;
76 }
77
78 function gcCounts() {
79 let major = gcparam("majorGCNumber")
80 let minor = gcparam("minorGCNumber");
81
82 // Only report minor collections that didn't happen as part of a major GC.
83 assertEq(minor >= major, true);
84 minor -= major;
85
86 return { minor, major };
87 }
88
89 function runTestAndCountCollections(thunk) {
90 let initialCounts = gcCounts();
91 thunk();
92 let finalCounts = gcCounts();
93 return { minor: finalCounts.minor - initialCounts.minor,
94 major: finalCounts.major - initialCounts.major };
95 }