OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
Jakob Kummerow
2012/01/23 17:16:55
nit: 2012
danno
2012/01/26 21:32:34
Done.
| |
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 } | 101 } |
102 assertEquals(expected, getKind(obj), name_opt); | 102 assertEquals(expected, getKind(obj), name_opt); |
103 } | 103 } |
104 | 104 |
105 var me = {}; | 105 var me = {}; |
106 assertKind(elements_kind.fast, me); | 106 assertKind(elements_kind.fast, me); |
107 me.dance = 0xD15C0; | 107 me.dance = 0xD15C0; |
108 me.drink = 0xC0C0A; | 108 me.drink = 0xC0C0A; |
109 assertKind(elements_kind.fast, me); | 109 assertKind(elements_kind.fast, me); |
110 | 110 |
111 var too = [1,2,3]; | 111 if (support_smi_only_arrays) { |
112 assertKind(elements_kind.fast_smi_only, too); | 112 var too = [1,2,3]; |
113 too.dance = 0xD15C0; | 113 assertKind(elements_kind.fast_smi_only, too); |
114 too.drink = 0xC0C0A; | 114 too.dance = 0xD15C0; |
115 assertKind(elements_kind.fast_smi_only, too); | 115 too.drink = 0xC0C0A; |
116 assertKind(elements_kind.fast_smi_only, too); | |
117 } | |
116 | 118 |
117 // Make sure the element kind transitions from smionly when a non-smi is stored. | 119 // Make sure the element kind transitions from smionly when a non-smi is stored. |
118 var you = new Array(); | 120 var you = new Array(); |
119 assertKind(elements_kind.fast_smi_only, you); | 121 assertKind(elements_kind.fast_smi_only, you); |
120 for (var i = 0; i < 1337; i++) { | 122 for (var i = 0; i < 1337; i++) { |
121 var val = i; | 123 var val = i; |
122 if (i == 1336) { | 124 if (i == 1336) { |
123 assertKind(elements_kind.fast_smi_only, you); | 125 assertKind(elements_kind.fast_smi_only, you); |
124 val = new Object(); | 126 val = new Object(); |
125 } | 127 } |
(...skipping 21 matching lines...) Expand all Loading... | |
147 function monomorphic(array) { | 149 function monomorphic(array) { |
148 for (var i = 0; i < 3; i++) { | 150 for (var i = 0; i < 3; i++) { |
149 array[i] = i + 10; | 151 array[i] = i + 10; |
150 } | 152 } |
151 assertKind(elements_kind.fast_smi_only, array); | 153 assertKind(elements_kind.fast_smi_only, array); |
152 for (var i = 0; i < 3; i++) { | 154 for (var i = 0; i < 3; i++) { |
153 var a = array[i]; | 155 var a = array[i]; |
154 assertEquals(i + 10, a); | 156 assertEquals(i + 10, a); |
155 } | 157 } |
156 } | 158 } |
157 var smi_only = [1, 2, 3]; | 159 var smi_only = new Array(1, 2, 3); |
158 for (var i = 0; i < 3; i++) monomorphic(smi_only); | 160 for (var i = 0; i < 3; i++) monomorphic(smi_only); |
159 %OptimizeFunctionOnNextCall(monomorphic); | 161 %OptimizeFunctionOnNextCall(monomorphic); |
160 monomorphic(smi_only); | 162 monomorphic(smi_only); |
161 | 163 |
162 if (support_smi_only_arrays) { | 164 if (support_smi_only_arrays) { |
163 function construct_smis() { | 165 function construct_smis() { |
164 var a = [0, 0, 0]; | 166 var a = [0, 0, 0]; |
165 a[0] = 0; // Send the COW array map to the steak house. | 167 a[0] = 0; // Send the COW array map to the steak house. |
166 assertKind(elements_kind.fast_smi_only, a); | 168 assertKind(elements_kind.fast_smi_only, a); |
167 return a; | 169 return a; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
225 %OptimizeFunctionOnNextCall(convert_mixed); | 227 %OptimizeFunctionOnNextCall(convert_mixed); |
226 convert_mixed(smis, 1, elements_kind.fast); | 228 convert_mixed(smis, 1, elements_kind.fast); |
227 convert_mixed(doubles, 1, elements_kind.fast); | 229 convert_mixed(doubles, 1, elements_kind.fast); |
228 assertTrue(%HaveSameMap(smis, doubles)); | 230 assertTrue(%HaveSameMap(smis, doubles)); |
229 } | 231 } |
230 | 232 |
231 // Crankshaft support for smi-only elements in dynamic array literals. | 233 // Crankshaft support for smi-only elements in dynamic array literals. |
232 function get(foo) { return foo; } // Used to generate dynamic values. | 234 function get(foo) { return foo; } // Used to generate dynamic values. |
233 | 235 |
234 function crankshaft_test() { | 236 function crankshaft_test() { |
235 var a = [get(1), get(2), get(3)]; | 237 if (support_smi_only_arrays) { |
236 assertKind(elements_kind.fast_smi_only, a); | 238 var a1 = [get(1), get(2), get(3)]; |
239 assertKind(elements_kind.fast_smi_only, a1); | |
240 } | |
241 var a2 = new Array(get(1), get(2), get(3)); | |
242 assertKind(elements_kind.fast_smi_only, a2); | |
237 var b = [get(1), get(2), get("three")]; | 243 var b = [get(1), get(2), get("three")]; |
238 assertKind(elements_kind.fast, b); | 244 assertKind(elements_kind.fast, b); |
239 var c = [get(1), get(2), get(3.5)]; | 245 var c = [get(1), get(2), get(3.5)]; |
240 if (support_smi_only_arrays) { | 246 if (support_smi_only_arrays) { |
241 assertKind(elements_kind.fast_double, c); | 247 assertKind(elements_kind.fast_double, c); |
242 } else { | |
243 assertKind(elements_kind.fast, c); | |
244 } | 248 } |
245 } | 249 } |
246 for (var i = 0; i < 3; i++) { | 250 for (var i = 0; i < 3; i++) { |
247 crankshaft_test(); | 251 crankshaft_test(); |
248 } | 252 } |
249 %OptimizeFunctionOnNextCall(crankshaft_test); | 253 %OptimizeFunctionOnNextCall(crankshaft_test); |
250 crankshaft_test(); | 254 crankshaft_test(); |
251 | 255 |
252 // Elements_kind transitions for arrays. | 256 // Elements_kind transitions for arrays. |
253 | 257 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
331 var a = ["foo", "bar"]; | 335 var a = ["foo", "bar"]; |
332 assertKind(elements_kind.fast, a); | 336 assertKind(elements_kind.fast, a); |
333 var b = a.splice(0, 1); | 337 var b = a.splice(0, 1); |
334 assertKind(elements_kind.fast, b); | 338 assertKind(elements_kind.fast, b); |
335 var c = a.slice(0, 1); | 339 var c = a.slice(0, 1); |
336 assertKind(elements_kind.fast, c); | 340 assertKind(elements_kind.fast, c); |
337 } | 341 } |
338 | 342 |
339 // Throw away type information in the ICs for next stress run. | 343 // Throw away type information in the ICs for next stress run. |
340 gc(); | 344 gc(); |
OLD | NEW |