summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/gc/bug-1531626.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/jit-test/tests/gc/bug-1531626.js')
-rw-r--r--js/src/jit-test/tests/gc/bug-1531626.js58
1 files changed, 58 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/gc/bug-1531626.js b/js/src/jit-test/tests/gc/bug-1531626.js
new file mode 100644
index 0000000000..c0d0af8ebd
--- /dev/null
+++ b/js/src/jit-test/tests/gc/bug-1531626.js
@@ -0,0 +1,58 @@
+// Test that setting the nursery size works as expected.
+//
+// It's an error to set the minimum size greater than the maximum
+// size. Parameter values are rounded to the nearest legal nursery
+// size.
+
+load(libdir + "asserts.js");
+
+const chunkSizeKB = gcparam('chunkBytes') / 1024;
+
+var testSizesKB = [128, 129, 255, 256, 516, 1023, 1024, 3*1024, 4*1024+1, 16*1024];
+
+// Valid maximum sizes must be >= 1MB.
+var testMaxSizesKB = testSizesKB.filter(x => x >= 1024);
+
+for (var max of testMaxSizesKB) {
+ // Don't test minimums greater than the maximum.
+ for (var min of testSizesKB.filter(x => x <= max)) {
+ setMinMax(min, max);
+ }
+}
+
+// The above loops raised the nursery size. Now reduce it to ensure that
+// forcibly-reducing it works correctly.
+gcparam('minNurseryBytes', 256*1024); // need to avoid min > max;
+setMinMax(256, 1024);
+
+// Try an invalid configuration.
+assertErrorMessage(
+ () => setMinMax(2*1024, 1024),
+ Object,
+ "Parameter value out of range");
+
+function setMinMax(min, max) {
+ // Set the maximum first so that we don't hit a case where max < min.
+ gcparam('maxNurseryBytes', max * 1024);
+ gcparam('minNurseryBytes', min * 1024);
+ assertEq(gcparam('maxNurseryBytes'), nearestLegalSize(max) * 1024);
+ assertEq(gcparam('minNurseryBytes'), nearestLegalSize(min) * 1024);
+ allocateSomeThings();
+ gc();
+}
+
+function allocateSomeThings() {
+ for (var i = 0; i < 1000; i++) {
+ var obj = { an: 'object', with: 'fields' };
+ }
+}
+
+function nearestLegalSize(sizeKB) {
+ let step = sizeKB >= chunkSizeKB ? chunkSizeKB : 4;
+ return round(sizeKB, step);
+}
+
+function round(x, y) {
+ x += y / 2;
+ return x - (x % y);
+}