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: --track-allocation-sites --nooptimize-constructed-arrays | 29 // Flags: --track-allocation-sites --noalways-opt |
30 | 30 |
31 // TODO(mvstanton): remove --nooptimize-constructed-arrays and enable | 31 // TODO(mvstanton): remove --nooptimize-constructed-arrays and enable |
32 // the constructed array code below when the feature is turned on | 32 // the constructed array code below when the feature is turned on |
33 // by default. | 33 // by default. |
34 | 34 |
35 // Test element kind of objects. | 35 // Test element kind of objects. |
36 // Since --smi-only-arrays affects builtins, its default setting at compile | 36 // Since --smi-only-arrays affects builtins, its default setting at compile |
37 // time sticks if built with snapshot. If --smi-only-arrays is deactivated | 37 // time sticks if built with snapshot. If --smi-only-arrays is deactivated |
38 // by default, only a no-snapshot build actually has smi-only arrays enabled | 38 // by default, only a no-snapshot build actually has smi-only arrays enabled |
39 // in this test case. Depending on whether smi-only arrays are actually | 39 // in this test case. Depending on whether smi-only arrays are actually |
40 // enabled, this test takes the appropriate code path to check smi-only arrays. | 40 // enabled, this test takes the appropriate code path to check smi-only arrays. |
41 | 41 |
42 support_smi_only_arrays = %HasFastSmiElements(new Array(1,2,3,4,5,6,7,8)); | 42 // support_smi_only_arrays = %HasFastSmiElements(new Array(1,2,3,4,5,6,7,8)); |
| 43 support_smi_only_arrays = true; |
43 optimize_constructed_arrays = false; | 44 optimize_constructed_arrays = false; |
44 | 45 |
45 if (support_smi_only_arrays) { | 46 if (support_smi_only_arrays) { |
46 print("Tests include smi-only arrays."); | 47 print("Tests include smi-only arrays."); |
47 } else { | 48 } else { |
48 print("Tests do NOT include smi-only arrays."); | 49 print("Tests do NOT include smi-only arrays."); |
49 } | 50 } |
50 | 51 |
51 if (optimize_constructed_arrays) { | 52 if (optimize_constructed_arrays) { |
52 print("Tests include constructed array optimizations."); | 53 print("Tests include constructed array optimizations."); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 // Case: [1,2,3] as allocation site | 142 // Case: [1,2,3] as allocation site |
142 obj = fastliteralcase(get_standard_literal(), 1); | 143 obj = fastliteralcase(get_standard_literal(), 1); |
143 assertKind(elements_kind.fast_smi_only, obj); | 144 assertKind(elements_kind.fast_smi_only, obj); |
144 obj = fastliteralcase(get_standard_literal(), 1.5); | 145 obj = fastliteralcase(get_standard_literal(), 1.5); |
145 assertKind(elements_kind.fast_double, obj); | 146 assertKind(elements_kind.fast_double, obj); |
146 obj = fastliteralcase(get_standard_literal(), 2); | 147 obj = fastliteralcase(get_standard_literal(), 2); |
147 // TODO(hpayer): bring the following assert back as soon as allocation | 148 // TODO(hpayer): bring the following assert back as soon as allocation |
148 // sites work again for fast literals | 149 // sites work again for fast literals |
149 //assertKind(elements_kind.fast_double, obj); | 150 //assertKind(elements_kind.fast_double, obj); |
150 | 151 |
151 obj = fastliteralcase([5, 3, 2], 1.5); | 152 // The test below is in a loop because arrays that live |
152 assertKind(elements_kind.fast_double, obj); | 153 // at global scope without the chance of being recreated |
153 obj = fastliteralcase([3, 6, 2], 1.5); | 154 // don't have allocation site information attached. |
154 assertKind(elements_kind.fast_double, obj); | 155 for (i = 0; i < 2; i++) { |
155 obj = fastliteralcase([2, 6, 3], 2); | 156 obj = fastliteralcase([5, 3, 2], 1.5); |
156 assertKind(elements_kind.fast_smi_only, obj); | 157 assertKind(elements_kind.fast_double, obj); |
| 158 obj = fastliteralcase([3, 6, 2], 1.5); |
| 159 assertKind(elements_kind.fast_double, obj); |
| 160 obj = fastliteralcase([2, 6, 3], 2); |
| 161 assertKind(elements_kind.fast_smi_only, obj); |
| 162 } |
157 | 163 |
158 // Verify that we will not pretransition the double->fast path. | 164 // Verify that we will not pretransition the double->fast path. |
159 obj = fastliteralcase(get_standard_literal(), "elliot"); | 165 obj = fastliteralcase(get_standard_literal(), "elliot"); |
160 assertKind(elements_kind.fast, obj); | 166 assertKind(elements_kind.fast, obj); |
161 // This fails until we turn off optimistic transitions to the | 167 // This fails until we turn off optimistic transitions to the |
162 // most general elements kind seen on keyed stores. It's a goal | 168 // most general elements kind seen on keyed stores. It's a goal |
163 // to turn it off, but for now we need it. | 169 // to turn it off, but for now we need it. |
164 // obj = fastliteralcase(3); | 170 // obj = fastliteralcase(3); |
165 // assertKind(elements_kind.fast_double, obj); | 171 // assertKind(elements_kind.fast_double, obj); |
166 | 172 |
| 173 // Make sure this works in crankshafted code too. |
| 174 %OptimizeFunctionOnNextCall(get_standard_literal); |
| 175 get_standard_literal(); |
| 176 obj = get_standard_literal(); |
| 177 assertKind(elements_kind.fast_double, obj); |
| 178 |
167 function fastliteralcase_smifast(value) { | 179 function fastliteralcase_smifast(value) { |
168 var literal = [1, 2, 3, 4]; | 180 var literal = [1, 2, 3, 4]; |
169 literal[0] = value; | 181 literal[0] = value; |
170 return literal; | 182 return literal; |
171 } | 183 } |
172 | 184 |
173 obj = fastliteralcase_smifast(1); | 185 obj = fastliteralcase_smifast(1); |
174 assertKind(elements_kind.fast_smi_only, obj); | 186 assertKind(elements_kind.fast_smi_only, obj); |
175 obj = fastliteralcase_smifast("carter"); | 187 obj = fastliteralcase_smifast("carter"); |
176 assertKind(elements_kind.fast, obj); | 188 assertKind(elements_kind.fast, obj); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 } | 279 } |
268 | 280 |
269 obj = newarraycase_list_smiobj(1); | 281 obj = newarraycase_list_smiobj(1); |
270 assertKind(elements_kind.fast_smi_only, obj); | 282 assertKind(elements_kind.fast_smi_only, obj); |
271 obj = newarraycase_list_smiobj("coates"); | 283 obj = newarraycase_list_smiobj("coates"); |
272 assertKind(elements_kind.fast, obj); | 284 assertKind(elements_kind.fast, obj); |
273 obj = newarraycase_list_smiobj(2); | 285 obj = newarraycase_list_smiobj(2); |
274 assertKind(elements_kind.fast, obj); | 286 assertKind(elements_kind.fast, obj); |
275 } | 287 } |
276 } | 288 } |
OLD | NEW |