| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. | 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
| 15 // | 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 // Flags: --allow-natives-syntax --smi-only-arrays --expose-gc | 28 // Flags: --allow-natives-syntax --smi-only-arrays --expose-gc |
| 29 // Flags: --nostress-opt | 29 // Flags: --notrack_allocation_sites |
| 30 |
| 31 // Limit the number of stress runs to reduce polymorphism it defeats some of the |
| 32 // assumptions made about how elements transitions work because transition stubs |
| 33 // end up going generic. |
| 34 // Flags: --stress-runs=2 |
| 30 | 35 |
| 31 // Test element kind of objects. | 36 // Test element kind of objects. |
| 32 // Since --smi-only-arrays affects builtins, its default setting at compile | 37 // Since --smi-only-arrays affects builtins, its default setting at compile |
| 33 // time sticks if built with snapshot. If --smi-only-arrays is deactivated | 38 // time sticks if built with snapshot. If --smi-only-arrays is deactivated |
| 34 // by default, only a no-snapshot build actually has smi-only arrays enabled | 39 // by default, only a no-snapshot build actually has smi-only arrays enabled |
| 35 // in this test case. Depending on whether smi-only arrays are actually | 40 // in this test case. Depending on whether smi-only arrays are actually |
| 36 // enabled, this test takes the appropriate code path to check smi-only arrays. | 41 // enabled, this test takes the appropriate code path to check smi-only arrays. |
| 37 | 42 |
| 38 support_smi_only_arrays = %HasFastSmiElements(new Array(1,2,3,4,5,6,7,8)); | 43 support_smi_only_arrays = %HasFastSmiElements(new Array(1,2,3,4,5,6,7,8)); |
| 39 | 44 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 | 116 |
| 112 if (support_smi_only_arrays) { | 117 if (support_smi_only_arrays) { |
| 113 var too = [1,2,3]; | 118 var too = [1,2,3]; |
| 114 assertKind(elements_kind.fast_smi_only, too); | 119 assertKind(elements_kind.fast_smi_only, too); |
| 115 too.dance = 0xD15C0; | 120 too.dance = 0xD15C0; |
| 116 too.drink = 0xC0C0A; | 121 too.drink = 0xC0C0A; |
| 117 assertKind(elements_kind.fast_smi_only, too); | 122 assertKind(elements_kind.fast_smi_only, too); |
| 118 } | 123 } |
| 119 | 124 |
| 120 // Make sure the element kind transitions from smi when a non-smi is stored. | 125 // Make sure the element kind transitions from smi when a non-smi is stored. |
| 121 function test_wrapper() { | 126 var you = new Array(); |
| 122 var you = new Array(); | 127 assertKind(elements_kind.fast_smi_only, you); |
| 123 assertKind(elements_kind.fast_smi_only, you); | 128 for (var i = 0; i < 1337; i++) { |
| 124 for (var i = 0; i < 1337; i++) { | 129 var val = i; |
| 125 var val = i; | 130 if (i == 1336) { |
| 126 if (i == 1336) { | 131 assertKind(elements_kind.fast_smi_only, you); |
| 127 assertKind(elements_kind.fast_smi_only, you); | 132 val = new Object(); |
| 128 val = new Object(); | |
| 129 } | |
| 130 you[i] = val; | |
| 131 } | 133 } |
| 132 assertKind(elements_kind.fast, you); | 134 you[i] = val; |
| 135 } |
| 136 assertKind(elements_kind.fast, you); |
| 133 | 137 |
| 134 assertKind(elements_kind.dictionary, new Array(0xDECAF)); | 138 assertKind(elements_kind.dictionary, new Array(0xDECAF)); |
| 135 | 139 |
| 136 var fast_double_array = new Array(0xDECAF); | 140 var fast_double_array = new Array(0xDECAF); |
| 137 for (var i = 0; i < 0xDECAF; i++) fast_double_array[i] = i / 2; | 141 for (var i = 0; i < 0xDECAF; i++) fast_double_array[i] = i / 2; |
| 138 assertKind(elements_kind.fast_double, fast_double_array); | 142 assertKind(elements_kind.fast_double, fast_double_array); |
| 139 | 143 |
| 140 assertKind(elements_kind.external_byte, new Int8Array(9001)); | 144 assertKind(elements_kind.external_byte, new Int8Array(9001)); |
| 141 assertKind(elements_kind.external_unsigned_byte, new Uint8Array(007)); | 145 assertKind(elements_kind.external_unsigned_byte, new Uint8Array(007)); |
| 142 assertKind(elements_kind.external_short, new Int16Array(666)); | 146 assertKind(elements_kind.external_short, new Int16Array(666)); |
| 143 assertKind(elements_kind.external_unsigned_short, new Uint16Array(42)); | 147 assertKind(elements_kind.external_unsigned_short, new Uint16Array(42)); |
| 144 assertKind(elements_kind.external_int, new Int32Array(0xF)); | 148 assertKind(elements_kind.external_int, new Int32Array(0xF)); |
| 145 assertKind(elements_kind.external_unsigned_int, new Uint32Array(23)); | 149 assertKind(elements_kind.external_unsigned_int, new Uint32Array(23)); |
| 146 assertKind(elements_kind.external_float, new Float32Array(7)); | 150 assertKind(elements_kind.external_float, new Float32Array(7)); |
| 147 assertKind(elements_kind.external_double, new Float64Array(0)); | 151 assertKind(elements_kind.external_double, new Float64Array(0)); |
| 148 assertKind(elements_kind.external_pixel, new Uint8ClampedArray(512)); | 152 assertKind(elements_kind.external_pixel, new Uint8ClampedArray(512)); |
| 149 | 153 |
| 150 // Crankshaft support for smi-only array elements. | 154 // Crankshaft support for smi-only array elements. |
| 151 function monomorphic(array) { | 155 function monomorphic(array) { |
| 152 assertKind(elements_kind.fast_smi_only, array); | 156 assertKind(elements_kind.fast_smi_only, array); |
| 153 for (var i = 0; i < 3; i++) { | 157 for (var i = 0; i < 3; i++) { |
| 154 array[i] = i + 10; | 158 array[i] = i + 10; |
| 155 } | |
| 156 assertKind(elements_kind.fast_smi_only, array); | |
| 157 for (var i = 0; i < 3; i++) { | |
| 158 var a = array[i]; | |
| 159 assertEquals(i + 10, a); | |
| 160 } | |
| 161 } | 159 } |
| 162 var smi_only = new Array(1, 2, 3); | 160 assertKind(elements_kind.fast_smi_only, array); |
| 163 assertKind(elements_kind.fast_smi_only, smi_only); | 161 for (var i = 0; i < 3; i++) { |
| 164 for (var i = 0; i < 3; i++) monomorphic(smi_only); | 162 var a = array[i]; |
| 165 %OptimizeFunctionOnNextCall(monomorphic); | 163 assertEquals(i + 10, a); |
| 166 monomorphic(smi_only); | 164 } |
| 167 } | 165 } |
| 168 | 166 var smi_only = new Array(1, 2, 3); |
| 169 // The test is called in a wrapper function to eliminate the transition learning | 167 assertKind(elements_kind.fast_smi_only, smi_only); |
| 170 // feedback of AllocationSites. | 168 for (var i = 0; i < 3; i++) monomorphic(smi_only); |
| 171 test_wrapper(); | 169 %OptimizeFunctionOnNextCall(monomorphic); |
| 172 %ClearFunctionTypeFeedback(test_wrapper); | 170 monomorphic(smi_only); |
| 173 | 171 |
| 174 if (support_smi_only_arrays) { | 172 if (support_smi_only_arrays) { |
| 175 %NeverOptimizeFunction(construct_smis); | 173 %NeverOptimizeFunction(construct_smis); |
| 176 | |
| 177 // This code exists to eliminate the learning influence of AllocationSites | |
| 178 // on the following tests. | |
| 179 var __sequence = 0; | |
| 180 function make_array_string() { | |
| 181 this.__sequence = this.__sequence + 1; | |
| 182 return "/* " + this.__sequence + " */ [0, 0, 0];" | |
| 183 } | |
| 184 function make_array() { | |
| 185 return eval(make_array_string()); | |
| 186 } | |
| 187 | |
| 188 function construct_smis() { | 174 function construct_smis() { |
| 189 var a = make_array(); | 175 var a = [0, 0, 0]; |
| 190 a[0] = 0; // Send the COW array map to the steak house. | 176 a[0] = 0; // Send the COW array map to the steak house. |
| 191 assertKind(elements_kind.fast_smi_only, a); | 177 assertKind(elements_kind.fast_smi_only, a); |
| 192 return a; | 178 return a; |
| 193 } | 179 } |
| 194 %NeverOptimizeFunction(construct_doubles); | 180 %NeverOptimizeFunction(construct_doubles); |
| 195 function construct_doubles() { | 181 function construct_doubles() { |
| 196 var a = construct_smis(); | 182 var a = construct_smis(); |
| 197 a[0] = 1.5; | 183 a[0] = 1.5; |
| 198 assertKind(elements_kind.fast_double, a); | 184 assertKind(elements_kind.fast_double, a); |
| 199 return a; | 185 return a; |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 var a = ["foo", "bar"]; | 350 var a = ["foo", "bar"]; |
| 365 assertKind(elements_kind.fast, a); | 351 assertKind(elements_kind.fast, a); |
| 366 var b = a.splice(0, 1); | 352 var b = a.splice(0, 1); |
| 367 assertKind(elements_kind.fast, b); | 353 assertKind(elements_kind.fast, b); |
| 368 var c = a.slice(0, 1); | 354 var c = a.slice(0, 1); |
| 369 assertKind(elements_kind.fast, c); | 355 assertKind(elements_kind.fast, c); |
| 370 } | 356 } |
| 371 | 357 |
| 372 // Throw away type information in the ICs for next stress run. | 358 // Throw away type information in the ICs for next stress run. |
| 373 gc(); | 359 gc(); |
| OLD | NEW |