Revision f230a1cf deps/v8/test/mjsunit/allocation-site-info.js
deps/v8/test/mjsunit/allocation-site-info.js | ||
---|---|---|
35 | 35 |
// in this test case. Depending on whether smi-only arrays are actually |
36 | 36 |
// enabled, this test takes the appropriate code path to check smi-only arrays. |
37 | 37 |
|
38 |
// Reset the GC stress mode to be off. Needed because AllocationMementos only |
|
39 |
// live for one gc, so a gc that happens in certain fragile areas of the test |
|
40 |
// can break assumptions. |
|
41 |
%SetFlags("--gc-interval=-1") |
|
42 |
|
|
38 | 43 |
// support_smi_only_arrays = %HasFastSmiElements(new Array(1,2,3,4,5,6,7,8)); |
39 | 44 |
support_smi_only_arrays = true; |
40 | 45 |
|
... | ... | |
150 | 155 |
// Verify that we will not pretransition the double->fast path. |
151 | 156 |
obj = fastliteralcase(get_standard_literal(), "elliot"); |
152 | 157 |
assertKind(elements_kind.fast, obj); |
153 |
// This fails until we turn off optimistic transitions to the |
|
154 |
// most general elements kind seen on keyed stores. It's a goal |
|
155 |
// to turn it off, but for now we need it. |
|
156 |
// obj = fastliteralcase(3); |
|
157 |
// assertKind(elements_kind.fast_double, obj); |
|
158 |
obj = fastliteralcase(get_standard_literal(), 3); |
|
159 |
assertKind(elements_kind.fast, obj); |
|
158 | 160 |
|
159 | 161 |
// Make sure this works in crankshafted code too. |
160 | 162 |
%OptimizeFunctionOnNextCall(get_standard_literal); |
161 | 163 |
get_standard_literal(); |
162 | 164 |
obj = get_standard_literal(); |
163 |
assertKind(elements_kind.fast_double, obj);
|
|
165 |
assertKind(elements_kind.fast, obj); |
|
164 | 166 |
|
165 | 167 |
function fastliteralcase_smifast(value) { |
166 | 168 |
var literal = [1, 2, 3, 4]; |
... | ... | |
231 | 233 |
obj = newarraycase_length_smidouble(2); |
232 | 234 |
assertKind(elements_kind.fast_double, obj); |
233 | 235 |
|
234 |
// Try to continue the transition to fast object, but |
|
235 |
// we will not pretransition from double->fast, because |
|
236 |
// it may hurt performance ("poisoning"). |
|
236 |
// Try to continue the transition to fast object. This won't work for |
|
237 |
// constructed arrays because constructor dispatch is done on the |
|
238 |
// elements kind, and a DOUBLE array constructor won't create an allocation |
|
239 |
// memento. |
|
237 | 240 |
obj = newarraycase_length_smidouble("coates"); |
238 | 241 |
assertKind(elements_kind.fast, obj); |
239 |
obj = newarraycase_length_smidouble(2.5); |
|
240 |
// However, because of optimistic transitions, we will |
|
241 |
// transition to the most general kind of elements kind found, |
|
242 |
// therefore I can't count on this assert yet. |
|
243 |
// assertKind(elements_kind.fast_double, obj); |
|
242 |
obj = newarraycase_length_smidouble(2); |
|
243 |
assertKind(elements_kind.fast_double, obj); |
|
244 | 244 |
|
245 | 245 |
function newarraycase_length_smiobj(value) { |
246 | 246 |
var a = new Array(3); |
... | ... | |
379 | 379 |
|
380 | 380 |
instanceof_check(realmBArray); |
381 | 381 |
assertUnoptimized(instanceof_check); |
382 |
|
|
383 |
// Case: make sure nested arrays benefit from allocation site feedback as |
|
384 |
// well. |
|
385 |
(function() { |
|
386 |
// Make sure we handle nested arrays |
|
387 |
function get_nested_literal() { |
|
388 |
var literal = [[1,2,3,4], [2], [3]]; |
|
389 |
return literal; |
|
390 |
} |
|
391 |
|
|
392 |
obj = get_nested_literal(); |
|
393 |
assertKind(elements_kind.fast, obj); |
|
394 |
obj[0][0] = 3.5; |
|
395 |
obj[2][0] = "hello"; |
|
396 |
obj = get_nested_literal(); |
|
397 |
assertKind(elements_kind.fast_double, obj[0]); |
|
398 |
assertKind(elements_kind.fast_smi_only, obj[1]); |
|
399 |
assertKind(elements_kind.fast, obj[2]); |
|
400 |
|
|
401 |
// A more complex nested literal case. |
|
402 |
function get_deep_nested_literal() { |
|
403 |
var literal = [[1], [[2], "hello"], 3, [4]]; |
|
404 |
return literal; |
|
405 |
} |
|
406 |
|
|
407 |
obj = get_deep_nested_literal(); |
|
408 |
assertKind(elements_kind.fast_smi_only, obj[1][0]); |
|
409 |
obj[0][0] = 3.5; |
|
410 |
obj[1][0][0] = "goodbye"; |
|
411 |
assertKind(elements_kind.fast_double, obj[0]); |
|
412 |
assertKind(elements_kind.fast, obj[1][0]); |
|
413 |
|
|
414 |
obj = get_deep_nested_literal(); |
|
415 |
assertKind(elements_kind.fast_double, obj[0]); |
|
416 |
assertKind(elements_kind.fast, obj[1][0]); |
|
417 |
})(); |
|
418 |
|
|
419 |
|
|
420 |
// Make sure object literals with array fields benefit from the type feedback |
|
421 |
// that allocation mementos provide. |
|
422 |
(function() { |
|
423 |
// A literal in an object |
|
424 |
function get_object_literal() { |
|
425 |
var literal = { |
|
426 |
array: [1,2,3], |
|
427 |
data: 3.5 |
|
428 |
}; |
|
429 |
return literal; |
|
430 |
} |
|
431 |
|
|
432 |
obj = get_object_literal(); |
|
433 |
assertKind(elements_kind.fast_smi_only, obj.array); |
|
434 |
obj.array[1] = 3.5; |
|
435 |
assertKind(elements_kind.fast_double, obj.array); |
|
436 |
obj = get_object_literal(); |
|
437 |
assertKind(elements_kind.fast_double, obj.array); |
|
438 |
|
|
439 |
function get_nested_object_literal() { |
|
440 |
var literal = { |
|
441 |
array: [[1],[2],[3]], |
|
442 |
data: 3.5 |
|
443 |
}; |
|
444 |
return literal; |
|
445 |
} |
|
446 |
|
|
447 |
obj = get_nested_object_literal(); |
|
448 |
assertKind(elements_kind.fast, obj.array); |
|
449 |
assertKind(elements_kind.fast_smi_only, obj.array[1]); |
|
450 |
obj.array[1][0] = 3.5; |
|
451 |
assertKind(elements_kind.fast_double, obj.array[1]); |
|
452 |
obj = get_nested_object_literal(); |
|
453 |
assertKind(elements_kind.fast_double, obj.array[1]); |
|
454 |
|
|
455 |
%OptimizeFunctionOnNextCall(get_nested_object_literal); |
|
456 |
get_nested_object_literal(); |
|
457 |
obj = get_nested_object_literal(); |
|
458 |
assertKind(elements_kind.fast_double, obj.array[1]); |
|
459 |
|
|
460 |
// Make sure we handle nested arrays |
|
461 |
function get_nested_literal() { |
|
462 |
var literal = [[1,2,3,4], [2], [3]]; |
|
463 |
return literal; |
|
464 |
} |
|
465 |
|
|
466 |
obj = get_nested_literal(); |
|
467 |
assertKind(elements_kind.fast, obj); |
|
468 |
obj[0][0] = 3.5; |
|
469 |
obj[2][0] = "hello"; |
|
470 |
obj = get_nested_literal(); |
|
471 |
assertKind(elements_kind.fast_double, obj[0]); |
|
472 |
assertKind(elements_kind.fast_smi_only, obj[1]); |
|
473 |
assertKind(elements_kind.fast, obj[2]); |
|
474 |
|
|
475 |
// A more complex nested literal case. |
|
476 |
function get_deep_nested_literal() { |
|
477 |
var literal = [[1], [[2], "hello"], 3, [4]]; |
|
478 |
return literal; |
|
479 |
} |
|
480 |
|
|
481 |
obj = get_deep_nested_literal(); |
|
482 |
assertKind(elements_kind.fast_smi_only, obj[1][0]); |
|
483 |
obj[0][0] = 3.5; |
|
484 |
obj[1][0][0] = "goodbye"; |
|
485 |
assertKind(elements_kind.fast_double, obj[0]); |
|
486 |
assertKind(elements_kind.fast, obj[1][0]); |
|
487 |
|
|
488 |
obj = get_deep_nested_literal(); |
|
489 |
assertKind(elements_kind.fast_double, obj[0]); |
|
490 |
assertKind(elements_kind.fast, obj[1][0]); |
|
491 |
})(); |
|
382 | 492 |
} |
Also available in: Unified diff