| 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 // Clearing feedback for the StoreIC in foo is important for runs with | |
| 67 // flag --stress-opt. | |
| 68 %ClearFunctionTypeFeedback(foo); | |
| 69 })(); | |
| 70 | |
| 71 | |
| 72 (function() { | |
| 73 var a = new Array(10); | |
| 74 | |
| 75 function foo2(a, i) { | |
| 76 a[i] = 50; | |
| 77 } | |
| 78 | |
| 79 // The KeyedStoreIC will learn GROW_MODE. | |
| 80 foo2(a, 10); | |
| 81 foo2(a, 12); | |
| 82 foo2(a, 31); | |
| 83 %OptimizeFunctionOnNextCall(foo2); | |
| 84 foo2(a, 40); | |
| 85 | |
| 86 // This test is way too slow without crankshaft. | |
| 87 if (4 != %GetOptimizationStatus(foo2)) { | |
| 88 assertOptimized(foo2); | |
| 89 assertTrue(%HasFastSmiElements(a)); | |
| 90 | |
| 91 // Grow a large array into large object space through the keyed store | |
| 92 // without deoptimizing. Grow by 10s. If we set elements too sparsely, the | |
| 93 // array will convert to dictionary mode. | |
| 94 a = new Array(99999); | |
| 95 assertTrue(%HasFastSmiElements(a)); | |
| 96 for (var i = 0; i < 263000; i += 10) { | |
| 97 foo2(a, i); | |
| 98 } | |
| 99 | |
| 100 // Verify that we are over 1 page in size, and foo2 remains optimized. | |
| 101 // This means we've smoothly transitioned to allocating in large object | |
| 102 // space. | |
| 103 assertTrue(%HasFastSmiElements(a)); | |
| 104 assertTrue(a.length * 4 > (1024 * 1024)); | |
| 105 assertOptimized(foo2); | |
| 106 } | |
| 107 | |
| 108 %ClearFunctionTypeFeedback(foo2); | |
| 109 })(); | |
| OLD | NEW |