OLD | NEW |
(Empty) | |
| 1 // Copyright 2011 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 --smi-only-arrays |
| 29 |
| 30 // Ensure that ElementsKind transitions in various situations are hoisted (or |
| 31 // not hoisted) correctly, don't change the semantics programs and don't trigger |
| 32 // deopt through hoisting in important situations. |
| 33 |
| 34 support_smi_only_arrays = %HasFastSmiOnlyElements(new Array(1,2,3,4,5,6)); |
| 35 |
| 36 if (support_smi_only_arrays) { |
| 37 print("Tests include smi-only arrays."); |
| 38 } else { |
| 39 print("Tests do NOT include smi-only arrays."); |
| 40 } |
| 41 |
| 42 if (support_smi_only_arrays) { |
| 43 // Make sure that a simple elements array transitions inside a loop before |
| 44 // stores to an array gets hoisted in a way that doesn't generate a deopt in |
| 45 // simple cases.} |
| 46 function testDoubleConversion4(a) { |
| 47 var object = new Object(); |
| 48 a[0] = 0; |
| 49 var count = 3; |
| 50 do { |
| 51 a[0] = object; |
| 52 } while (--count > 0); |
| 53 } |
| 54 |
| 55 testDoubleConversion4(new Array(5)); |
| 56 %OptimizeFunctionOnNextCall(testDoubleConversion4); |
| 57 testDoubleConversion4(new Array(5)); |
| 58 testDoubleConversion4(new Array(5)); |
| 59 assertTrue(2 != %GetOptimizationStatus(testDoubleConversion4)); |
| 60 |
| 61 // Make sure that non-element related map checks that are not preceded by |
| 62 // transitions in a loop still get hoisted in a way that doesn't generate a |
| 63 // deopt in simple cases. |
| 64 function testExactMapHoisting(a) { |
| 65 var object = new Object(); |
| 66 a.foo = 0; |
| 67 a[0] = 0; |
| 68 a[1] = 1; |
| 69 var count = 3; |
| 70 do { |
| 71 a.foo = object; // This map check should be hoistable |
| 72 a[1] = object; |
| 73 result = a.foo == object && a[1] == object; |
| 74 } while (--count > 0); |
| 75 } |
| 76 |
| 77 testExactMapHoisting(new Array(5)); |
| 78 %OptimizeFunctionOnNextCall(testExactMapHoisting); |
| 79 testExactMapHoisting(new Array(5)); |
| 80 testExactMapHoisting(new Array(5)); |
| 81 assertTrue(2 != %GetOptimizationStatus(testExactMapHoisting)); |
| 82 |
| 83 // Make sure that non-element related map checks do NOT get hoisted if they |
| 84 // depend on an elements transition before them and it's not possible to hoist |
| 85 // that transition. |
| 86 function testExactMapHoisting2(a) { |
| 87 var object = new Object(); |
| 88 a.foo = 0; |
| 89 a[0] = 0; |
| 90 a[1] = 1; |
| 91 var count = 3; |
| 92 do { |
| 93 if (a.bar === undefined) { |
| 94 a[1] = 2.5; |
| 95 } |
| 96 a.foo = object; // This map check should NOT be hoistable because it |
| 97 // includes a check for the FAST_ELEMENTS map as well as |
| 98 // the FAST_DOUBLE_ELEMENTS map, which depends on the |
| 99 // double transition above in the if, which cannot be |
| 100 // hoisted. |
| 101 } while (--count > 0); |
| 102 } |
| 103 |
| 104 testExactMapHoisting2(new Array(5)); |
| 105 %OptimizeFunctionOnNextCall(testExactMapHoisting2); |
| 106 testExactMapHoisting2(new Array(5)); |
| 107 testExactMapHoisting2(new Array(5)); |
| 108 assertTrue(2 != %GetOptimizationStatus(testExactMapHoisting2)); |
| 109 |
| 110 // Make sure that non-element related map checks do get hoisted if they use |
| 111 // the transitioned map for the check and all transitions that they depend |
| 112 // upon can hoisted, too. |
| 113 function testExactMapHoisting3(a) { |
| 114 var object = new Object(); |
| 115 a.foo = 0; |
| 116 a[0] = 0; |
| 117 a[1] = 1; |
| 118 var count = 3; |
| 119 do { |
| 120 a[1] = 2.5; |
| 121 a.foo = object; // This map check should be hoistable because all elements |
| 122 // transitions in the loop can also be hoisted. |
| 123 } while (--count > 0); |
| 124 } |
| 125 |
| 126 var add_transition = new Array(5); |
| 127 add_transition.foo = 0; |
| 128 add_transition[0] = new Object(); // For FAST_ELEMENT transition to be created |
| 129 testExactMapHoisting3(new Array(5)); |
| 130 %OptimizeFunctionOnNextCall(testExactMapHoisting3); |
| 131 testExactMapHoisting3(new Array(5)); |
| 132 testExactMapHoisting3(new Array(5)); |
| 133 assertTrue(2 != %GetOptimizationStatus(testExactMapHoisting3)); |
| 134 |
| 135 function testDominatingTransitionHoisting1(a) { |
| 136 var object = new Object(); |
| 137 a[0] = 0; |
| 138 var count = 3; |
| 139 do { |
| 140 if (a.baz != true) { |
| 141 a[1] = 2.5; |
| 142 } |
| 143 a[0] = object; |
| 144 } while (--count > 3); |
| 145 } |
| 146 |
| 147 testDominatingTransitionHoisting1(new Array(5)); |
| 148 %OptimizeFunctionOnNextCall(testDominatingTransitionHoisting1); |
| 149 testDominatingTransitionHoisting1(new Array(5)); |
| 150 testDominatingTransitionHoisting1(new Array(5)); |
| 151 assertTrue(2 != %GetOptimizationStatus(testDominatingTransitionHoisting1)); |
| 152 |
| 153 function testHoistingWithSideEffect(a) { |
| 154 var object = new Object(); |
| 155 a[0] = 0; |
| 156 var count = 3; |
| 157 do { |
| 158 assertTrue(true); |
| 159 a[0] = object; |
| 160 } while (--count > 3); |
| 161 } |
| 162 |
| 163 testHoistingWithSideEffect(new Array(5)); |
| 164 %OptimizeFunctionOnNextCall(testHoistingWithSideEffect); |
| 165 testHoistingWithSideEffect(new Array(5)); |
| 166 testHoistingWithSideEffect(new Array(5)); |
| 167 assertTrue(2 != %GetOptimizationStatus(testHoistingWithSideEffect)); |
| 168 } |
OLD | NEW |