OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 = [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 function polymorphic(array, expected_kind) { | 161 |
162 array[1] = 42; | 162 if (support_smi_only_arrays) { |
163 assertKind(expected_kind, array); | 163 function construct_smis() { |
164 var a = array[1]; | 164 var a = [0, 0, 0]; |
165 assertEquals(42, a); | 165 a[0] = 0; // Send the COW array map to the steak house. |
| 166 assertKind(elements_kind.fast_smi_only, a); |
| 167 return a; |
| 168 } |
| 169 function construct_doubles() { |
| 170 var a = construct_smis(); |
| 171 a[0] = 1.5; |
| 172 assertKind(elements_kind.fast_double, a); |
| 173 return a; |
| 174 } |
| 175 function construct_objects() { |
| 176 var a = construct_smis(); |
| 177 a[0] = "one"; |
| 178 assertKind(elements_kind.fast, a); |
| 179 return a; |
| 180 } |
| 181 |
| 182 // Test crankshafted transition SMI->DOUBLE. |
| 183 function convert_to_double(array) { |
| 184 array[1] = 2.5; |
| 185 assertKind(elements_kind.fast_double, array); |
| 186 assertEquals(2.5, array[1]); |
| 187 } |
| 188 var smis = construct_smis(); |
| 189 for (var i = 0; i < 3; i++) convert_to_double(smis); |
| 190 %OptimizeFunctionOnNextCall(convert_to_double); |
| 191 smis = construct_smis(); |
| 192 convert_to_double(smis); |
| 193 // Test crankshafted transitions SMI->FAST and DOUBLE->FAST. |
| 194 function convert_to_fast(array) { |
| 195 array[1] = "two"; |
| 196 assertKind(elements_kind.fast, array); |
| 197 assertEquals("two", array[1]); |
| 198 } |
| 199 smis = construct_smis(); |
| 200 for (var i = 0; i < 3; i++) convert_to_fast(smis); |
| 201 var doubles = construct_doubles(); |
| 202 for (var i = 0; i < 3; i++) convert_to_fast(doubles); |
| 203 smis = construct_smis(); |
| 204 doubles = construct_doubles(); |
| 205 %OptimizeFunctionOnNextCall(convert_to_fast); |
| 206 convert_to_fast(smis); |
| 207 convert_to_fast(doubles); |
| 208 // Test transition chain SMI->DOUBLE->FAST (crankshafted function will |
| 209 // transition to FAST directly). |
| 210 function convert_mixed(array, value, kind) { |
| 211 array[1] = value; |
| 212 assertKind(kind, array); |
| 213 assertEquals(value, array[1]); |
| 214 } |
| 215 smis = construct_smis(); |
| 216 for (var i = 0; i < 3; i++) { |
| 217 convert_mixed(smis, 1.5, elements_kind.fast_double); |
| 218 } |
| 219 doubles = construct_doubles(); |
| 220 for (var i = 0; i < 3; i++) { |
| 221 convert_mixed(doubles, "three", elements_kind.fast); |
| 222 } |
| 223 smis = construct_smis(); |
| 224 doubles = construct_doubles(); |
| 225 %OptimizeFunctionOnNextCall(convert_mixed); |
| 226 convert_mixed(smis, 1, elements_kind.fast); |
| 227 convert_mixed(doubles, 1, elements_kind.fast); |
| 228 assertTrue(%HaveSameMap(smis, doubles)); |
166 } | 229 } |
167 var smis = [1, 2, 3]; | |
168 var strings = [0, 0, 0]; strings[0] = "one"; | |
169 var doubles = [0, 0, 0]; doubles[0] = 1.5; | |
170 assertKind(support_smi_only_arrays | |
171 ? elements_kind.fast_double | |
172 : elements_kind.fast, | |
173 doubles); | |
174 for (var i = 0; i < 3; i++) { | |
175 polymorphic(smis, elements_kind.fast_smi_only); | |
176 } | |
177 for (var i = 0; i < 3; i++) { | |
178 polymorphic(strings, elements_kind.fast); | |
179 } | |
180 for (var i = 0; i < 3; i++) { | |
181 polymorphic(doubles, i == 0 && support_smi_only_arrays | |
182 ? elements_kind.fast_double | |
183 : elements_kind.fast); | |
184 } | |
185 | |
186 /* Element transitions have not been implemented in crankshaft yet. | |
187 %OptimizeFunctionOnNextCall(polymorphic); | |
188 polymorphic(smis, elements_kind.fast_smi_only); | |
189 polymorphic(strings, elements_kind.fast); | |
190 polymorphic(doubles, elements_kind.fast); | |
191 | 230 |
192 // Crankshaft support for smi-only elements in dynamic array literals. | 231 // Crankshaft support for smi-only elements in dynamic array literals. |
193 function get(foo) { return foo; } // Used to generate dynamic values. | 232 function get(foo) { return foo; } // Used to generate dynamic values. |
194 | 233 |
195 function crankshaft_test() { | 234 function crankshaft_test() { |
196 var a = [get(1), get(2), get(3)]; | 235 var a = [get(1), get(2), get(3)]; |
197 assertKind(elements_kind.fast_smi_only, a); | 236 assertKind(elements_kind.fast_smi_only, a); |
198 var b = [get(1), get(2), get("three")]; | 237 var b = [get(1), get(2), get("three")]; |
199 assertKind(elements_kind.fast, b); | 238 assertKind(elements_kind.fast, b); |
200 var c = [get(1), get(2), get(3.5)]; | 239 var c = [get(1), get(2), get(3.5)]; |
201 // The full code generator doesn't support conversion to fast_double | 240 // The full code generator doesn't support conversion to fast_double |
202 // yet. Crankshaft does, but only with --smi-only-arrays support. | 241 // yet. Crankshaft does, but only with --smi-only-arrays support. |
203 if ((%GetOptimizationStatus(crankshaft_test) & 1) && | 242 if ((%GetOptimizationStatus(crankshaft_test) & 1) && |
204 support_smi_only_arrays) { | 243 support_smi_only_arrays) { |
205 assertKind(elements_kind.fast_double, c); | 244 assertKind(elements_kind.fast_double, c); |
206 } else { | 245 } else { |
207 assertKind(elements_kind.fast, c); | 246 assertKind(elements_kind.fast, c); |
208 } | 247 } |
209 } | 248 } |
210 for (var i = 0; i < 3; i++) { | 249 for (var i = 0; i < 3; i++) { |
211 crankshaft_test(); | 250 crankshaft_test(); |
212 } | 251 } |
213 %OptimizeFunctionOnNextCall(crankshaft_test); | 252 %OptimizeFunctionOnNextCall(crankshaft_test); |
214 crankshaft_test(); | 253 crankshaft_test(); |
215 */ | 254 |
216 | 255 |
217 // Elements_kind transitions for arrays. | 256 // Elements_kind transitions for arrays. |
218 | 257 |
219 // A map can have three different elements_kind transitions: SMI->DOUBLE, | 258 // A map can have three different elements_kind transitions: SMI->DOUBLE, |
220 // DOUBLE->OBJECT, and SMI->OBJECT. No matter in which order these three are | 259 // DOUBLE->OBJECT, and SMI->OBJECT. No matter in which order these three are |
221 // created, they must always end up with the same FAST map. | 260 // created, they must always end up with the same FAST map. |
222 | 261 |
223 // This test is meaningless without FAST_SMI_ONLY_ELEMENTS. | 262 // This test is meaningless without FAST_SMI_ONLY_ELEMENTS. |
224 if (support_smi_only_arrays) { | 263 if (support_smi_only_arrays) { |
225 // Preparation: create one pair of identical objects for each case. | 264 // Preparation: create one pair of identical objects for each case. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 f[0] = 1.5; | 304 f[0] = 1.5; |
266 assertKind(elements_kind.fast_double, f); | 305 assertKind(elements_kind.fast_double, f); |
267 assertFalse(%HaveSameMap(e, f)); | 306 assertFalse(%HaveSameMap(e, f)); |
268 f[0] = "bar"; | 307 f[0] = "bar"; |
269 assertKind(elements_kind.fast, f); | 308 assertKind(elements_kind.fast, f); |
270 assertTrue(%HaveSameMap(e, f)); | 309 assertTrue(%HaveSameMap(e, f)); |
271 } | 310 } |
272 | 311 |
273 // Throw away type information in the ICs for next stress run. | 312 // Throw away type information in the ICs for next stress run. |
274 gc(); | 313 gc(); |
OLD | NEW |