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: --notrack_allocation_sites | 29 // Flags: --nostress-opt |
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 | |
35 | 30 |
36 // Test element kind of objects. | 31 // Test element kind of objects. |
37 // Since --smi-only-arrays affects builtins, its default setting at compile | 32 // Since --smi-only-arrays affects builtins, its default setting at compile |
38 // time sticks if built with snapshot. If --smi-only-arrays is deactivated | 33 // time sticks if built with snapshot. If --smi-only-arrays is deactivated |
39 // by default, only a no-snapshot build actually has smi-only arrays enabled | 34 // by default, only a no-snapshot build actually has smi-only arrays enabled |
40 // in this test case. Depending on whether smi-only arrays are actually | 35 // in this test case. Depending on whether smi-only arrays are actually |
41 // enabled, this test takes the appropriate code path to check smi-only arrays. | 36 // enabled, this test takes the appropriate code path to check smi-only arrays. |
42 | 37 |
43 support_smi_only_arrays = %HasFastSmiElements(new Array(1,2,3,4,5,6,7,8)); | 38 support_smi_only_arrays = %HasFastSmiElements(new Array(1,2,3,4,5,6,7,8)); |
44 | 39 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 | 111 |
117 if (support_smi_only_arrays) { | 112 if (support_smi_only_arrays) { |
118 var too = [1,2,3]; | 113 var too = [1,2,3]; |
119 assertKind(elements_kind.fast_smi_only, too); | 114 assertKind(elements_kind.fast_smi_only, too); |
120 too.dance = 0xD15C0; | 115 too.dance = 0xD15C0; |
121 too.drink = 0xC0C0A; | 116 too.drink = 0xC0C0A; |
122 assertKind(elements_kind.fast_smi_only, too); | 117 assertKind(elements_kind.fast_smi_only, too); |
123 } | 118 } |
124 | 119 |
125 // Make sure the element kind transitions from smi when a non-smi is stored. | 120 // Make sure the element kind transitions from smi when a non-smi is stored. |
126 var you = new Array(); | 121 function test_wrapper() { |
127 assertKind(elements_kind.fast_smi_only, you); | 122 var you = new Array(); |
128 for (var i = 0; i < 1337; i++) { | 123 assertKind(elements_kind.fast_smi_only, you); |
129 var val = i; | 124 for (var i = 0; i < 1337; i++) { |
130 if (i == 1336) { | 125 var val = i; |
131 assertKind(elements_kind.fast_smi_only, you); | 126 if (i == 1336) { |
132 val = new Object(); | 127 assertKind(elements_kind.fast_smi_only, you); |
| 128 val = new Object(); |
| 129 } |
| 130 you[i] = val; |
133 } | 131 } |
134 you[i] = val; | 132 assertKind(elements_kind.fast, you); |
| 133 |
| 134 assertKind(elements_kind.dictionary, new Array(0xDECAF)); |
| 135 |
| 136 var fast_double_array = new Array(0xDECAF); |
| 137 for (var i = 0; i < 0xDECAF; i++) fast_double_array[i] = i / 2; |
| 138 assertKind(elements_kind.fast_double, fast_double_array); |
| 139 |
| 140 assertKind(elements_kind.external_byte, new Int8Array(9001)); |
| 141 assertKind(elements_kind.external_unsigned_byte, new Uint8Array(007)); |
| 142 assertKind(elements_kind.external_short, new Int16Array(666)); |
| 143 assertKind(elements_kind.external_unsigned_short, new Uint16Array(42)); |
| 144 assertKind(elements_kind.external_int, new Int32Array(0xF)); |
| 145 assertKind(elements_kind.external_unsigned_int, new Uint32Array(23)); |
| 146 assertKind(elements_kind.external_float, new Float32Array(7)); |
| 147 assertKind(elements_kind.external_double, new Float64Array(0)); |
| 148 assertKind(elements_kind.external_pixel, new Uint8ClampedArray(512)); |
| 149 |
| 150 // Crankshaft support for smi-only array elements. |
| 151 function monomorphic(array) { |
| 152 assertKind(elements_kind.fast_smi_only, array); |
| 153 for (var i = 0; i < 3; i++) { |
| 154 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 } |
| 162 var smi_only = new Array(1, 2, 3); |
| 163 assertKind(elements_kind.fast_smi_only, smi_only); |
| 164 for (var i = 0; i < 3; i++) monomorphic(smi_only); |
| 165 %OptimizeFunctionOnNextCall(monomorphic); |
| 166 monomorphic(smi_only); |
135 } | 167 } |
136 assertKind(elements_kind.fast, you); | |
137 | 168 |
138 assertKind(elements_kind.dictionary, new Array(0xDECAF)); | 169 // The test is called in a wrapper function to eliminate the transition learning |
139 | 170 // feedback of AllocationSites. |
140 var fast_double_array = new Array(0xDECAF); | 171 test_wrapper(); |
141 for (var i = 0; i < 0xDECAF; i++) fast_double_array[i] = i / 2; | 172 %ClearFunctionTypeFeedback(test_wrapper); |
142 assertKind(elements_kind.fast_double, fast_double_array); | |
143 | |
144 assertKind(elements_kind.external_byte, new Int8Array(9001)); | |
145 assertKind(elements_kind.external_unsigned_byte, new Uint8Array(007)); | |
146 assertKind(elements_kind.external_short, new Int16Array(666)); | |
147 assertKind(elements_kind.external_unsigned_short, new Uint16Array(42)); | |
148 assertKind(elements_kind.external_int, new Int32Array(0xF)); | |
149 assertKind(elements_kind.external_unsigned_int, new Uint32Array(23)); | |
150 assertKind(elements_kind.external_float, new Float32Array(7)); | |
151 assertKind(elements_kind.external_double, new Float64Array(0)); | |
152 assertKind(elements_kind.external_pixel, new Uint8ClampedArray(512)); | |
153 | |
154 // Crankshaft support for smi-only array elements. | |
155 function monomorphic(array) { | |
156 assertKind(elements_kind.fast_smi_only, array); | |
157 for (var i = 0; i < 3; i++) { | |
158 array[i] = i + 10; | |
159 } | |
160 assertKind(elements_kind.fast_smi_only, array); | |
161 for (var i = 0; i < 3; i++) { | |
162 var a = array[i]; | |
163 assertEquals(i + 10, a); | |
164 } | |
165 } | |
166 var smi_only = new Array(1, 2, 3); | |
167 assertKind(elements_kind.fast_smi_only, smi_only); | |
168 for (var i = 0; i < 3; i++) monomorphic(smi_only); | |
169 %OptimizeFunctionOnNextCall(monomorphic); | |
170 monomorphic(smi_only); | |
171 | 173 |
172 if (support_smi_only_arrays) { | 174 if (support_smi_only_arrays) { |
173 %NeverOptimizeFunction(construct_smis); | 175 %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 |
174 function construct_smis() { | 188 function construct_smis() { |
175 var a = [0, 0, 0]; | 189 var a = make_array(); |
176 a[0] = 0; // Send the COW array map to the steak house. | 190 a[0] = 0; // Send the COW array map to the steak house. |
177 assertKind(elements_kind.fast_smi_only, a); | 191 assertKind(elements_kind.fast_smi_only, a); |
178 return a; | 192 return a; |
179 } | 193 } |
180 %NeverOptimizeFunction(construct_doubles); | 194 %NeverOptimizeFunction(construct_doubles); |
181 function construct_doubles() { | 195 function construct_doubles() { |
182 var a = construct_smis(); | 196 var a = construct_smis(); |
183 a[0] = 1.5; | 197 a[0] = 1.5; |
184 assertKind(elements_kind.fast_double, a); | 198 assertKind(elements_kind.fast_double, a); |
185 return a; | 199 return a; |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 var a = ["foo", "bar"]; | 364 var a = ["foo", "bar"]; |
351 assertKind(elements_kind.fast, a); | 365 assertKind(elements_kind.fast, a); |
352 var b = a.splice(0, 1); | 366 var b = a.splice(0, 1); |
353 assertKind(elements_kind.fast, b); | 367 assertKind(elements_kind.fast, b); |
354 var c = a.slice(0, 1); | 368 var c = a.slice(0, 1); |
355 assertKind(elements_kind.fast, c); | 369 assertKind(elements_kind.fast, c); |
356 } | 370 } |
357 | 371 |
358 // Throw away type information in the ICs for next stress run. | 372 // Throw away type information in the ICs for next stress run. |
359 gc(); | 373 gc(); |
OLD | NEW |