OLD | NEW |
1 // Copyright 2011 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. |
(...skipping 15 matching lines...) Expand all Loading... |
27 | 27 |
28 // Flags: --allow-natives-syntax --smi-only-arrays --expose-gc | 28 // Flags: --allow-natives-syntax --smi-only-arrays --expose-gc |
29 | 29 |
30 // Test element kind of objects. | 30 // Test element kind of objects. |
31 // Since --smi-only-arrays affects builtins, its default setting at compile | 31 // Since --smi-only-arrays affects builtins, its default setting at compile |
32 // time sticks if built with snapshot. If --smi-only-arrays is deactivated | 32 // time sticks if built with snapshot. If --smi-only-arrays is deactivated |
33 // by default, only a no-snapshot build actually has smi-only arrays enabled | 33 // by default, only a no-snapshot build actually has smi-only arrays enabled |
34 // in this test case. Depending on whether smi-only arrays are actually | 34 // in this test case. Depending on whether smi-only arrays are actually |
35 // enabled, this test takes the appropriate code path to check smi-only arrays. | 35 // enabled, this test takes the appropriate code path to check smi-only arrays. |
36 | 36 |
37 support_smi_only_arrays = %HasFastSmiOnlyElements([1,2,3,4,5,6,7,8,9,10]); | 37 support_smi_only_arrays = %HasFastSmiOnlyElements(new Array(1,2,3,4,5,6,7,8)); |
38 | 38 |
39 if (support_smi_only_arrays) { | 39 if (support_smi_only_arrays) { |
40 print("Tests include smi-only arrays."); | 40 print("Tests include smi-only arrays."); |
41 } else { | 41 } else { |
42 print("Tests do NOT include smi-only arrays."); | 42 print("Tests do NOT include smi-only arrays."); |
43 } | 43 } |
44 | 44 |
45 var elements_kind = { | 45 var elements_kind = { |
46 fast_smi_only : 'fast smi only elements', | 46 fast_smi_only : 'fast smi only elements', |
47 fast : 'fast elements', | 47 fast : 'fast elements', |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 function monomorphic(array) { | 147 function monomorphic(array) { |
148 for (var i = 0; i < 3; i++) { | 148 for (var i = 0; i < 3; i++) { |
149 array[i] = i + 10; | 149 array[i] = i + 10; |
150 } | 150 } |
151 assertKind(elements_kind.fast_smi_only, array); | 151 assertKind(elements_kind.fast_smi_only, array); |
152 for (var i = 0; i < 3; i++) { | 152 for (var i = 0; i < 3; i++) { |
153 var a = array[i]; | 153 var a = array[i]; |
154 assertEquals(i + 10, a); | 154 assertEquals(i + 10, a); |
155 } | 155 } |
156 } | 156 } |
157 var smi_only = [1, 2, 3]; | 157 var smi_only = new Array(1, 2, 3); |
158 for (var i = 0; i < 3; i++) monomorphic(smi_only); | 158 for (var i = 0; i < 3; i++) monomorphic(smi_only); |
159 %OptimizeFunctionOnNextCall(monomorphic); | 159 %OptimizeFunctionOnNextCall(monomorphic); |
160 monomorphic(smi_only); | 160 monomorphic(smi_only); |
161 | 161 |
162 if (support_smi_only_arrays) { | 162 if (support_smi_only_arrays) { |
163 function construct_smis() { | 163 function construct_smis() { |
164 var a = [0, 0, 0]; | 164 var a = [0, 0, 0]; |
165 a[0] = 0; // Send the COW array map to the steak house. | 165 a[0] = 0; // Send the COW array map to the steak house. |
166 assertKind(elements_kind.fast_smi_only, a); | 166 assertKind(elements_kind.fast_smi_only, a); |
167 return a; | 167 return a; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 %OptimizeFunctionOnNextCall(convert_mixed); | 225 %OptimizeFunctionOnNextCall(convert_mixed); |
226 convert_mixed(smis, 1, elements_kind.fast); | 226 convert_mixed(smis, 1, elements_kind.fast); |
227 convert_mixed(doubles, 1, elements_kind.fast); | 227 convert_mixed(doubles, 1, elements_kind.fast); |
228 assertTrue(%HaveSameMap(smis, doubles)); | 228 assertTrue(%HaveSameMap(smis, doubles)); |
229 } | 229 } |
230 | 230 |
231 // Crankshaft support for smi-only elements in dynamic array literals. | 231 // Crankshaft support for smi-only elements in dynamic array literals. |
232 function get(foo) { return foo; } // Used to generate dynamic values. | 232 function get(foo) { return foo; } // Used to generate dynamic values. |
233 | 233 |
234 function crankshaft_test() { | 234 function crankshaft_test() { |
235 var a = [get(1), get(2), get(3)]; | 235 var a1 = [get(1), get(2), get(3)]; |
236 assertKind(elements_kind.fast_smi_only, a); | 236 assertKind(elements_kind.fast_smi_only, a1); |
| 237 var a2 = new Array(get(1), get(2), get(3)); |
| 238 assertKind(elements_kind.fast_smi_only, a2); |
237 var b = [get(1), get(2), get("three")]; | 239 var b = [get(1), get(2), get("three")]; |
238 assertKind(elements_kind.fast, b); | 240 assertKind(elements_kind.fast, b); |
239 var c = [get(1), get(2), get(3.5)]; | 241 var c = [get(1), get(2), get(3.5)]; |
240 if (support_smi_only_arrays) { | 242 if (support_smi_only_arrays) { |
241 assertKind(elements_kind.fast_double, c); | 243 assertKind(elements_kind.fast_double, c); |
242 } else { | 244 } else { |
243 assertKind(elements_kind.fast, c); | 245 assertKind(elements_kind.fast, c); |
244 } | 246 } |
245 } | 247 } |
246 for (var i = 0; i < 3; i++) { | 248 for (var i = 0; i < 3; i++) { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 var a = ["foo", "bar"]; | 333 var a = ["foo", "bar"]; |
332 assertKind(elements_kind.fast, a); | 334 assertKind(elements_kind.fast, a); |
333 var b = a.splice(0, 1); | 335 var b = a.splice(0, 1); |
334 assertKind(elements_kind.fast, b); | 336 assertKind(elements_kind.fast, b); |
335 var c = a.slice(0, 1); | 337 var c = a.slice(0, 1); |
336 assertKind(elements_kind.fast, c); | 338 assertKind(elements_kind.fast, c); |
337 } | 339 } |
338 | 340 |
339 // Throw away type information in the ICs for next stress run. | 341 // Throw away type information in the ICs for next stress run. |
340 gc(); | 342 gc(); |
OLD | NEW |