OLD | NEW |
(Empty) | |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are |
| 4 // met: |
| 5 // |
| 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. |
| 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 |
| 28 // Flags: --allow-natives-syntax --noverify-heap --noenable-slow-asserts |
| 29 |
| 30 // --noverify-heap and --noenable-slow-asserts are set because the test is too |
| 31 // slow with it on. |
| 32 |
| 33 // Ensure that keyed stores work, and optimized functions learn if the |
| 34 // store required change to dictionary mode. Verify that stores that grow |
| 35 // the array into large object space don't cause a deopt. |
| 36 (function() { |
| 37 var a = []; |
| 38 |
| 39 function foo(a, i) { |
| 40 a[i] = 5.3; |
| 41 } |
| 42 |
| 43 foo(a, 1); |
| 44 foo(a, 2); |
| 45 foo(a, 3); |
| 46 %OptimizeFunctionOnNextCall(foo); |
| 47 a[3] = 0; |
| 48 foo(a, 3); |
| 49 assertEquals(a[3], 5.3); |
| 50 foo(a, 50000); |
| 51 assertUnoptimized(foo); |
| 52 assertTrue(%HasDictionaryElements(a)); |
| 53 |
| 54 var b = []; |
| 55 foo(b, 1); |
| 56 foo(b, 2); |
| 57 // Put b in dictionary mode. |
| 58 b[10000] = 5; |
| 59 assertTrue(%HasDictionaryElements(b)); |
| 60 foo(b, 3); |
| 61 %OptimizeFunctionOnNextCall(foo); |
| 62 foo(b, 50000); |
| 63 assertOptimized(foo); |
| 64 assertTrue(%HasDictionaryElements(b)); |
| 65 })(); |
| 66 |
| 67 |
| 68 (function() { |
| 69 var a = new Array(10); |
| 70 |
| 71 function foo2(a, i) { |
| 72 a[i] = 50; |
| 73 } |
| 74 |
| 75 // The KeyedStoreIC will learn GROW_MODE. |
| 76 foo2(a, 10); |
| 77 foo2(a, 12); |
| 78 foo2(a, 31); |
| 79 %OptimizeFunctionOnNextCall(foo2); |
| 80 foo2(a, 40); |
| 81 |
| 82 // This test is way too slow without crankshaft. |
| 83 if (4 != %GetOptimizationStatus(foo2)) { |
| 84 assertOptimized(foo2); |
| 85 assertTrue(%HasFastSmiElements(a)); |
| 86 |
| 87 // Grow a large array into large object space through the keyed store |
| 88 // without deoptimizing. Grow by 10s. If we set elements too sparsely, the |
| 89 // array will convert to dictionary mode. |
| 90 a = new Array(99999); |
| 91 assertTrue(%HasFastSmiElements(a)); |
| 92 for (var i = 0; i < 263000; i += 10) { |
| 93 foo2(a, i); |
| 94 } |
| 95 |
| 96 // Verify that we are over 1 page in size, and foo2 remains optimized. |
| 97 // This means we've smoothly transitioned to allocating in large object |
| 98 // space. |
| 99 assertTrue(%HasFastSmiElements(a)); |
| 100 assertTrue(a.length * 4 > (1024 * 1024)); |
| 101 assertOptimized(foo2); |
| 102 } |
| 103 })(); |
| 104 |
| 105 |
| 106 // Verify that it works with non-arrays too. |
| 107 (function() { |
| 108 // Get an object to create a fast elements array. It takes some effort. |
| 109 var o = {}; |
| 110 function foo(a, i) { |
| 111 a[i] = 50; |
| 112 } |
| 113 assertTrue(%HasFastSmiOrObjectElements(o)); |
| 114 |
| 115 foo(o, 0); |
| 116 foo(o, 1); |
| 117 %OptimizeFunctionOnNextCall(foo); |
| 118 // 16 should be enough to make the elements array grow, but not go to |
| 119 // dictionary mode. |
| 120 foo(o, 16); |
| 121 assertOptimized(foo); |
| 122 foo(o, 32000); |
| 123 assertUnoptimized(foo); |
| 124 assertTrue(%HasDictionaryElements(o)); |
| 125 })(); |
OLD | NEW |