Index: test/mjsunit/allocation-site-info.js |
diff --git a/test/mjsunit/allocation-site-info.js b/test/mjsunit/allocation-site-info.js |
index 9b1f4bd3555d25eebffaf229537a81ba86753451..626696be15828ea10f66ba2f153a71824f84c0b1 100644 |
--- a/test/mjsunit/allocation-site-info.js |
+++ b/test/mjsunit/allocation-site-info.js |
@@ -383,4 +383,114 @@ if (support_smi_only_arrays) { |
instanceof_check(realmBArray); |
assertUnoptimized(instanceof_check); |
+ |
+ // Case: make sure nested arrays benefit from allocation site feedback as |
+ // well. |
+ (function() { |
+ // Make sure we handle nested arrays |
+ function get_nested_literal() { |
+ var literal = [[1,2,3,4], [2], [3]]; |
+ return literal; |
+ } |
+ |
+ obj = get_nested_literal(); |
+ assertKind(elements_kind.fast, obj); |
+ obj[0][0] = 3.5; |
+ obj[2][0] = "hello"; |
+ obj = get_nested_literal(); |
+ assertKind(elements_kind.fast_double, obj[0]); |
+ assertKind(elements_kind.fast_smi_only, obj[1]); |
+ assertKind(elements_kind.fast, obj[2]); |
+ |
+ // A more complex nested literal case. |
+ function get_deep_nested_literal() { |
+ var literal = [[1], [[2], "hello"], 3, [4]]; |
+ return literal; |
+ } |
+ |
+ obj = get_deep_nested_literal(); |
+ assertKind(elements_kind.fast_smi_only, obj[1][0]); |
+ obj[0][0] = 3.5; |
+ obj[1][0][0] = "goodbye"; |
+ assertKind(elements_kind.fast_double, obj[0]); |
+ assertKind(elements_kind.fast, obj[1][0]); |
+ |
+ obj = get_deep_nested_literal(); |
+ assertKind(elements_kind.fast_double, obj[0]); |
+ assertKind(elements_kind.fast, obj[1][0]); |
+ })(); |
+ |
+ |
+ // Make sure object literals with array fields benefit from the type feedback |
+ // that allocation mementos provide. |
+ (function() { |
+ // A literal in an object |
+ function get_object_literal() { |
+ var literal = { |
+ array: [1,2,3], |
+ data: 3.5 |
+ }; |
+ return literal; |
+ } |
+ |
+ obj = get_object_literal(); |
+ assertKind(elements_kind.fast_smi_only, obj.array); |
+ obj.array[1] = 3.5; |
+ assertKind(elements_kind.fast_double, obj.array); |
+ obj = get_object_literal(); |
+ assertKind(elements_kind.fast_double, obj.array); |
+ |
+ function get_nested_object_literal() { |
+ var literal = { |
+ array: [[1],[2],[3]], |
+ data: 3.5 |
+ }; |
+ return literal; |
+ } |
+ |
+ obj = get_nested_object_literal(); |
+ assertKind(elements_kind.fast, obj.array); |
+ assertKind(elements_kind.fast_smi_only, obj.array[1]); |
+ obj.array[1][0] = 3.5; |
+ assertKind(elements_kind.fast_double, obj.array[1]); |
+ obj = get_nested_object_literal(); |
+ assertKind(elements_kind.fast_double, obj.array[1]); |
+ |
+ %OptimizeFunctionOnNextCall(get_nested_object_literal); |
+ get_nested_object_literal(); |
+ obj = get_nested_object_literal(); |
+ assertKind(elements_kind.fast_double, obj.array[1]); |
+ |
+ // Make sure we handle nested arrays |
+ function get_nested_literal() { |
+ var literal = [[1,2,3,4], [2], [3]]; |
+ return literal; |
+ } |
+ |
+ obj = get_nested_literal(); |
+ assertKind(elements_kind.fast, obj); |
+ obj[0][0] = 3.5; |
+ obj[2][0] = "hello"; |
+ obj = get_nested_literal(); |
+ assertKind(elements_kind.fast_double, obj[0]); |
+ assertKind(elements_kind.fast_smi_only, obj[1]); |
+ assertKind(elements_kind.fast, obj[2]); |
+ |
+ // A more complex nested literal case. |
+ function get_deep_nested_literal() { |
+ var literal = [[1], [[2], "hello"], 3, [4]]; |
+ return literal; |
+ } |
+ |
+ obj = get_deep_nested_literal(); |
+ assertKind(elements_kind.fast_smi_only, obj[1][0]); |
+ obj[0][0] = 3.5; |
+ obj[1][0][0] = "goodbye"; |
+ assertKind(elements_kind.fast_double, obj[0]); |
+ assertKind(elements_kind.fast, obj[1][0]); |
+ |
+ obj = get_deep_nested_literal(); |
+ assertKind(elements_kind.fast_double, obj[0]); |
+ assertKind(elements_kind.fast, obj[1][0]); |
+ })(); |
} |