Debian Codegraph @

js/src/jit-test/tests/gc/bug-1531626.js

raw
1 // Test that setting the nursery size works as expected.
2 //
3 // It's an error to set the minimum size greater than the maximum
4 // size. Parameter values are rounded to the nearest legal nursery
5 // size.
6
7 load(libdir + "asserts.js");
8
9 const chunkSizeKB = gcparam('chunkBytes') / 1024;
10 const pageSizeKB = gcparam('systemPageSizeKB');
11
12 const testSizesKB = [128, 129, 255, 256, 516, 1023, 1024, 3*1024, 4*1024+1, 16*1024];
13
14 // Valid maximum sizes must be >= 1MB.
15 const testMaxSizesKB = testSizesKB.filter(x => x >= 1024);
16
17 for (let max of testMaxSizesKB) {
18 // Don't test minimums greater than the maximum.
19 for (let min of testSizesKB.filter(x => x <= max)) {
20 setMinMax(min, max);
21 }
22 }
23
24 // The above loops raised the nursery size. Now reduce it to ensure that
25 // forcibly-reducing it works correctly.
26 setMinMax(256, 1024);
27
28 // Try invalid configurations.
29 const badSizesKB = [ 0, 1, 129 * 1024];
30 function assertParamOutOfRange(f) {
31 assertErrorMessage(f, Object, "Parameter value out of range");
32 }
33 for (let size of badSizesKB) {
34 assertParamOutOfRange(() => gcparam('minNurseryBytes', size * 1024));
35 assertParamOutOfRange(() => gcparam('maxNurseryBytes', size * 1024));
36 }
37
38 function setMinMax(min, max) {
39 gcparam('minNurseryBytes', min * 1024);
40 gcparam('maxNurseryBytes', max * 1024);
41 assertEq(gcparam('minNurseryBytes'), nearestLegalSize(min) * 1024);
42 assertEq(gcparam('maxNurseryBytes'), nearestLegalSize(max) * 1024);
43 allocateSomeThings();
44 gc();
45 }
46
47 function allocateSomeThings() {
48 for (let i = 0; i < 1000; i++) {
49 let obj = { an: 'object', with: 'fields' };
50 }
51 }
52
53 function nearestLegalSize(sizeKB) {
54 let step = sizeKB >= chunkSizeKB ? chunkSizeKB : pageSizeKB;
55 return round(sizeKB, step);
56 }
57
58 function round(x, y) {
59 x += y / 2;
60 return x - (x % y);
61 }