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 |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 // Test element kind of objects. | 31 // Test element kind of objects. |
32 // Since --smi-only-arrays affects builtins, its default setting at compile | 32 // Since --smi-only-arrays affects builtins, its default setting at compile |
33 // 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 |
34 // 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 |
35 // 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 |
36 // 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. |
37 | 37 |
38 // 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)); |
39 support_smi_only_arrays = true; | 39 support_smi_only_arrays = true; |
40 optimize_constructed_arrays = true; | |
41 | 40 |
42 if (support_smi_only_arrays) { | 41 if (support_smi_only_arrays) { |
43 print("Tests include smi-only arrays."); | 42 print("Tests include smi-only arrays."); |
44 } else { | 43 } else { |
45 print("Tests do NOT include smi-only arrays."); | 44 print("Tests do NOT include smi-only arrays."); |
46 } | 45 } |
47 | 46 |
48 if (optimize_constructed_arrays) { | |
49 print("Tests include constructed array optimizations."); | |
50 } else { | |
51 print("Tests do NOT include constructed array optimizations."); | |
52 } | |
53 | |
54 var elements_kind = { | 47 var elements_kind = { |
55 fast_smi_only : 'fast smi only elements', | 48 fast_smi_only : 'fast smi only elements', |
56 fast : 'fast elements', | 49 fast : 'fast elements', |
57 fast_double : 'fast double elements', | 50 fast_double : 'fast double elements', |
58 dictionary : 'dictionary elements', | 51 dictionary : 'dictionary elements', |
59 external_byte : 'external byte elements', | 52 external_byte : 'external byte elements', |
60 external_unsigned_byte : 'external unsigned byte elements', | 53 external_unsigned_byte : 'external unsigned byte elements', |
61 external_short : 'external short elements', | 54 external_short : 'external short elements', |
62 external_unsigned_short : 'external unsigned short elements', | 55 external_unsigned_short : 'external unsigned short elements', |
63 external_int : 'external int elements', | 56 external_int : 'external int elements', |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 | 173 |
181 obj = fastliteralcase_smifast(1); | 174 obj = fastliteralcase_smifast(1); |
182 assertKind(elements_kind.fast_smi_only, obj); | 175 assertKind(elements_kind.fast_smi_only, obj); |
183 obj = fastliteralcase_smifast("carter"); | 176 obj = fastliteralcase_smifast("carter"); |
184 assertKind(elements_kind.fast, obj); | 177 assertKind(elements_kind.fast, obj); |
185 obj = fastliteralcase_smifast(2); | 178 obj = fastliteralcase_smifast(2); |
186 // TODO(hpayer): bring the following assert back as soon as allocation | 179 // TODO(hpayer): bring the following assert back as soon as allocation |
187 // sites work again for fast literals | 180 // sites work again for fast literals |
188 //assertKind(elements_kind.fast, obj); | 181 //assertKind(elements_kind.fast, obj); |
189 | 182 |
190 if (optimize_constructed_arrays) { | 183 function newarraycase_smidouble(value) { |
191 function newarraycase_smidouble(value) { | 184 var a = new Array(); |
192 var a = new Array(); | 185 a[0] = value; |
193 a[0] = value; | 186 return a; |
194 return a; | 187 } |
195 } | |
196 | 188 |
197 // Case: new Array() as allocation site, smi->double | 189 // Case: new Array() as allocation site, smi->double |
198 obj = newarraycase_smidouble(1); | 190 obj = newarraycase_smidouble(1); |
199 assertKind(elements_kind.fast_smi_only, obj); | 191 assertKind(elements_kind.fast_smi_only, obj); |
200 obj = newarraycase_smidouble(1.5); | 192 obj = newarraycase_smidouble(1.5); |
201 assertKind(elements_kind.fast_double, obj); | 193 assertKind(elements_kind.fast_double, obj); |
202 obj = newarraycase_smidouble(2); | 194 obj = newarraycase_smidouble(2); |
203 assertKind(elements_kind.fast_double, obj); | 195 assertKind(elements_kind.fast_double, obj); |
204 | 196 |
205 function newarraycase_smiobj(value) { | 197 function newarraycase_smiobj(value) { |
206 var a = new Array(); | 198 var a = new Array(); |
207 a[0] = value; | 199 a[0] = value; |
208 return a; | 200 return a; |
209 } | 201 } |
210 | 202 |
211 // Case: new Array() as allocation site, smi->fast | 203 // Case: new Array() as allocation site, smi->fast |
212 obj = newarraycase_smiobj(1); | 204 obj = newarraycase_smiobj(1); |
213 assertKind(elements_kind.fast_smi_only, obj); | 205 assertKind(elements_kind.fast_smi_only, obj); |
214 obj = newarraycase_smiobj("gloria"); | 206 obj = newarraycase_smiobj("gloria"); |
215 assertKind(elements_kind.fast, obj); | 207 assertKind(elements_kind.fast, obj); |
216 obj = newarraycase_smiobj(2); | 208 obj = newarraycase_smiobj(2); |
217 assertKind(elements_kind.fast, obj); | 209 assertKind(elements_kind.fast, obj); |
218 | 210 |
219 function newarraycase_length_smidouble(value) { | 211 function newarraycase_length_smidouble(value) { |
220 var a = new Array(3); | 212 var a = new Array(3); |
221 a[0] = value; | 213 a[0] = value; |
222 return a; | 214 return a; |
223 } | 215 } |
224 | 216 |
225 // Case: new Array(length) as allocation site | 217 // Case: new Array(length) as allocation site |
226 obj = newarraycase_length_smidouble(1); | 218 obj = newarraycase_length_smidouble(1); |
227 assertKind(elements_kind.fast_smi_only, obj); | 219 assertKind(elements_kind.fast_smi_only, obj); |
228 obj = newarraycase_length_smidouble(1.5); | 220 obj = newarraycase_length_smidouble(1.5); |
229 assertKind(elements_kind.fast_double, obj); | 221 assertKind(elements_kind.fast_double, obj); |
230 obj = newarraycase_length_smidouble(2); | 222 obj = newarraycase_length_smidouble(2); |
231 assertKind(elements_kind.fast_double, obj); | 223 assertKind(elements_kind.fast_double, obj); |
232 | 224 |
233 // Try to continue the transition to fast object, but | 225 // Try to continue the transition to fast object, but |
234 // we will not pretransition from double->fast, because | 226 // we will not pretransition from double->fast, because |
235 // it may hurt performance ("poisoning"). | 227 // it may hurt performance ("poisoning"). |
236 obj = newarraycase_length_smidouble("coates"); | 228 obj = newarraycase_length_smidouble("coates"); |
237 assertKind(elements_kind.fast, obj); | 229 assertKind(elements_kind.fast, obj); |
238 obj = newarraycase_length_smidouble(2.5); | 230 obj = newarraycase_length_smidouble(2.5); |
239 // However, because of optimistic transitions, we will | 231 // However, because of optimistic transitions, we will |
240 // transition to the most general kind of elements kind found, | 232 // transition to the most general kind of elements kind found, |
241 // therefore I can't count on this assert yet. | 233 // therefore I can't count on this assert yet. |
242 // assertKind(elements_kind.fast_double, obj); | 234 // assertKind(elements_kind.fast_double, obj); |
243 | 235 |
244 function newarraycase_length_smiobj(value) { | 236 function newarraycase_length_smiobj(value) { |
245 var a = new Array(3); | 237 var a = new Array(3); |
246 a[0] = value; | 238 a[0] = value; |
247 return a; | 239 return a; |
248 } | 240 } |
249 | 241 |
250 // Case: new Array(<length>) as allocation site, smi->fast | 242 // Case: new Array(<length>) as allocation site, smi->fast |
251 obj = newarraycase_length_smiobj(1); | 243 obj = newarraycase_length_smiobj(1); |
252 assertKind(elements_kind.fast_smi_only, obj); | 244 assertKind(elements_kind.fast_smi_only, obj); |
253 obj = newarraycase_length_smiobj("gloria"); | 245 obj = newarraycase_length_smiobj("gloria"); |
254 assertKind(elements_kind.fast, obj); | 246 assertKind(elements_kind.fast, obj); |
255 obj = newarraycase_length_smiobj(2); | 247 obj = newarraycase_length_smiobj(2); |
256 assertKind(elements_kind.fast, obj); | 248 assertKind(elements_kind.fast, obj); |
257 | 249 |
258 function newarraycase_list_smidouble(value) { | 250 function newarraycase_list_smidouble(value) { |
259 var a = new Array(1, 2, 3); | 251 var a = new Array(1, 2, 3); |
260 a[0] = value; | 252 a[0] = value; |
261 return a; | 253 return a; |
262 } | 254 } |
263 | 255 |
264 obj = newarraycase_list_smidouble(1); | 256 obj = newarraycase_list_smidouble(1); |
265 assertKind(elements_kind.fast_smi_only, obj); | 257 assertKind(elements_kind.fast_smi_only, obj); |
266 obj = newarraycase_list_smidouble(1.5); | 258 obj = newarraycase_list_smidouble(1.5); |
267 assertKind(elements_kind.fast_double, obj); | 259 assertKind(elements_kind.fast_double, obj); |
268 obj = newarraycase_list_smidouble(2); | 260 obj = newarraycase_list_smidouble(2); |
269 assertKind(elements_kind.fast_double, obj); | 261 assertKind(elements_kind.fast_double, obj); |
270 | 262 |
271 function newarraycase_list_smiobj(value) { | 263 function newarraycase_list_smiobj(value) { |
272 var a = new Array(4, 5, 6); | 264 var a = new Array(4, 5, 6); |
273 a[0] = value; | 265 a[0] = value; |
274 return a; | 266 return a; |
275 } | 267 } |
276 | 268 |
277 obj = newarraycase_list_smiobj(1); | 269 obj = newarraycase_list_smiobj(1); |
278 assertKind(elements_kind.fast_smi_only, obj); | 270 assertKind(elements_kind.fast_smi_only, obj); |
279 obj = newarraycase_list_smiobj("coates"); | 271 obj = newarraycase_list_smiobj("coates"); |
280 assertKind(elements_kind.fast, obj); | 272 assertKind(elements_kind.fast, obj); |
281 obj = newarraycase_list_smiobj(2); | 273 obj = newarraycase_list_smiobj(2); |
282 assertKind(elements_kind.fast, obj); | 274 assertKind(elements_kind.fast, obj); |
283 | 275 |
284 function newarraycase_onearg(len, value) { | 276 function newarraycase_onearg(len, value) { |
285 var a = new Array(len); | 277 var a = new Array(len); |
286 a[0] = value; | 278 a[0] = value; |
287 return a; | 279 return a; |
288 } | 280 } |
289 | 281 |
290 obj = newarraycase_onearg(5, 3.5); | 282 obj = newarraycase_onearg(5, 3.5); |
291 assertKind(elements_kind.fast_double, obj); | 283 assertKind(elements_kind.fast_double, obj); |
292 obj = newarraycase_onearg(10, 5); | 284 obj = newarraycase_onearg(10, 5); |
293 assertKind(elements_kind.fast_double, obj); | 285 assertKind(elements_kind.fast_double, obj); |
294 obj = newarraycase_onearg(0, 5); | 286 obj = newarraycase_onearg(0, 5); |
295 assertKind(elements_kind.fast_double, obj); | 287 assertKind(elements_kind.fast_double, obj); |
296 // Now pass a length that forces the dictionary path. | 288 // Now pass a length that forces the dictionary path. |
297 obj = newarraycase_onearg(100000, 5); | 289 obj = newarraycase_onearg(100000, 5); |
298 assertKind(elements_kind.dictionary, obj); | 290 assertKind(elements_kind.dictionary, obj); |
299 assertTrue(obj.length == 100000); | 291 assertTrue(obj.length == 100000); |
300 | 292 |
301 // Verify that cross context calls work | 293 // Verify that cross context calls work |
302 var realmA = Realm.current(); | 294 var realmA = Realm.current(); |
303 var realmB = Realm.create(); | 295 var realmB = Realm.create(); |
304 assertEquals(0, realmA); | 296 assertEquals(0, realmA); |
305 assertEquals(1, realmB); | 297 assertEquals(1, realmB); |
306 | 298 |
307 function instanceof_check(type) { | 299 function instanceof_check(type) { |
308 assertTrue(new type() instanceof type); | 300 assertTrue(new type() instanceof type); |
309 assertTrue(new type(5) instanceof type); | 301 assertTrue(new type(5) instanceof type); |
310 assertTrue(new type(1,2,3) instanceof type); | 302 assertTrue(new type(1,2,3) instanceof type); |
311 } | 303 } |
312 | 304 |
313 var realmBArray = Realm.eval(realmB, "Array"); | 305 var realmBArray = Realm.eval(realmB, "Array"); |
314 instanceof_check(Array); | 306 instanceof_check(Array); |
315 instanceof_check(realmBArray); | 307 instanceof_check(realmBArray); |
316 %OptimizeFunctionOnNextCall(instanceof_check); | 308 %OptimizeFunctionOnNextCall(instanceof_check); |
317 instanceof_check(Array); | 309 instanceof_check(Array); |
318 assertTrue(2 != %GetOptimizationStatus(instanceof_check)); | 310 assertTrue(2 != %GetOptimizationStatus(instanceof_check)); |
319 instanceof_check(realmBArray); | 311 instanceof_check(realmBArray); |
320 assertTrue(1 != %GetOptimizationStatus(instanceof_check)); | 312 assertTrue(1 != %GetOptimizationStatus(instanceof_check)); |
321 } | |
322 } | 313 } |
OLD | NEW |