]> git.saurik.com Git - apple/javascriptcore.git/blob - tests/stress/new-largeish-contiguous-array-with-size.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / stress / new-largeish-contiguous-array-with-size.js
1 // We only need one run of this with any GC or JIT strategy. This test is not particularly fast.
2 // Unfortunately, it needs to run for a while to test the thing it's testing.
3 //@ slow!
4 //@ runWithRAMSize(10000000)
5
6 function foo(x) {
7 return new Array(x);
8 }
9
10 noInline(foo);
11
12 function test(size) {
13 var result = foo(size);
14 if (result.length != size)
15 throw "Error: bad result: " + result;
16 var sawThings = false;
17 for (var s in result)
18 sawThings = true;
19 if (sawThings)
20 throw "Error: array is in bad state: " + result;
21 result[0] = "42.5";
22 if (result[0] != "42.5")
23 throw "Error: array is in weird state: " + result;
24 }
25
26 var result = gcHeapSize();
27
28 for (var i = 0; i < 1000; ++i) {
29 // The test was written when we found that large array allocations weren't being accounted for
30 // in that part of the GC's accounting that determined the GC trigger. Consequently, the GC
31 // would run too infrequently in this loop and we would use an absurd amount of memory when this
32 // loop exited.
33 test(50000);
34 }
35
36 // Last time I tested, the heap should be 3725734 before and 125782 after. I don't want to enforce
37 // exactly that. If you regress the accounting code, the GC heap size at this point will be much
38 // more than that.
39 var result = gcHeapSize();
40 if (result > 10000000)
41 throw "Error: heap too big before forced GC: " + result;
42
43 // Do a final check after GC, just for sanity.
44 gc();
45 result = gcHeapSize();
46 if (result > 1000000)
47 throw "Error: heap too big after forced GC: " + result;