Index: test/mjsunit/allocation-site-info.js |
diff --git a/test/mjsunit/allocation-site-info.js b/test/mjsunit/allocation-site-info.js |
index 3c8238710814be1beb7e55c3209fcd3840c898a5..d57fd321e43c4b71bcc2a827629ac403ed144bd7 100644 |
--- a/test/mjsunit/allocation-site-info.js |
+++ b/test/mjsunit/allocation-site-info.js |
@@ -26,7 +26,11 @@ |
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
// Flags: --allow-natives-syntax --smi-only-arrays --expose-gc |
-// Flags: --track-allocation-sites |
+// Flags: --track-allocation-sites --nooptimize-constructed-arrays |
+ |
+// TODO(mvstanton): remove --nooptimize-constructed-arrays and enable |
+// the constructed array code below when the feature is turned on |
+// by default. |
// Test element kind of objects. |
// Since --smi-only-arrays affects builtins, its default setting at compile |
@@ -36,6 +40,7 @@ |
// enabled, this test takes the appropriate code path to check smi-only arrays. |
support_smi_only_arrays = %HasFastSmiElements(new Array(1,2,3,4,5,6,7,8)); |
+optimize_constructed_arrays = false; |
if (support_smi_only_arrays) { |
print("Tests include smi-only arrays."); |
@@ -43,6 +48,12 @@ if (support_smi_only_arrays) { |
print("Tests do NOT include smi-only arrays."); |
} |
+if (optimize_constructed_arrays) { |
+ print("Tests include constructed array optimizations."); |
+} else { |
+ print("Tests do NOT include constructed array optimizations."); |
+} |
+ |
var elements_kind = { |
fast_smi_only : 'fast smi only elements', |
fast : 'fast elements', |
@@ -66,6 +77,11 @@ function getKind(obj) { |
if (%HasDictionaryElements(obj)) return elements_kind.dictionary; |
} |
+function isHoley(obj) { |
+ if (%HasFastHoleyElements(obj)) return true; |
+ return false; |
+} |
+ |
function assertKind(expected, obj, name_opt) { |
if (!support_smi_only_arrays && |
expected == elements_kind.fast_smi_only) { |
@@ -74,9 +90,45 @@ function assertKind(expected, obj, name_opt) { |
assertEquals(expected, getKind(obj), name_opt); |
} |
+function assertHoley(obj, name_opt) { |
+ assertEquals(true, isHoley(obj), name_opt); |
+} |
+ |
+function assertNotHoley(obj, name_opt) { |
+ assertEquals(false, isHoley(obj), name_opt); |
+} |
+ |
if (support_smi_only_arrays) { |
+ |
+ obj = []; |
+ assertNotHoley(obj); |
+ assertKind(elements_kind.fast_smi_only, obj); |
+ |
+ obj = [1, 2, 3]; |
+ assertNotHoley(obj); |
+ assertKind(elements_kind.fast_smi_only, obj); |
+ |
+ obj = new Array(); |
+ assertNotHoley(obj); |
+ assertKind(elements_kind.fast_smi_only, obj); |
+ |
+ obj = new Array(0); |
+ assertNotHoley(obj); |
+ assertKind(elements_kind.fast_smi_only, obj); |
+ |
+ obj = new Array(2); |
+ assertHoley(obj); |
+ assertKind(elements_kind.fast_smi_only, obj); |
+ |
+ obj = new Array(1,2,3); |
+ assertNotHoley(obj); |
+ assertKind(elements_kind.fast_smi_only, obj); |
+ |
+ obj = new Array(1, "hi", 2, undefined); |
+ assertNotHoley(obj); |
+ assertKind(elements_kind.fast, obj); |
+ |
function fastliteralcase(literal, value) { |
- // var literal = [1, 2, 3]; |
literal[0] = value; |
return literal; |
} |
@@ -104,7 +156,6 @@ if (support_smi_only_arrays) { |
// Verify that we will not pretransition the double->fast path. |
obj = fastliteralcase(get_standard_literal(), "elliot"); |
assertKind(elements_kind.fast, obj); |
- |
// This fails until we turn off optimistic transitions to the |
// most general elements kind seen on keyed stores. It's a goal |
// to turn it off, but for now we need it. |
@@ -123,4 +174,99 @@ if (support_smi_only_arrays) { |
assertKind(elements_kind.fast, obj); |
obj = fastliteralcase_smifast(2); |
assertKind(elements_kind.fast, obj); |
+ |
+ if (optimize_constructed_arrays) { |
+ function newarraycase_smidouble(value) { |
+ var a = new Array(); |
+ a[0] = value; |
+ return a; |
+ } |
+ |
+ // Case: new Array() as allocation site, smi->double |
+ obj = newarraycase_smidouble(1); |
+ assertKind(elements_kind.fast_smi_only, obj); |
+ obj = newarraycase_smidouble(1.5); |
+ assertKind(elements_kind.fast_double, obj); |
+ obj = newarraycase_smidouble(2); |
+ assertKind(elements_kind.fast_double, obj); |
+ |
+ function newarraycase_smiobj(value) { |
+ var a = new Array(); |
+ a[0] = value; |
+ return a; |
+ } |
+ |
+ // Case: new Array() as allocation site, smi->fast |
+ obj = newarraycase_smiobj(1); |
+ assertKind(elements_kind.fast_smi_only, obj); |
+ obj = newarraycase_smiobj("gloria"); |
+ assertKind(elements_kind.fast, obj); |
+ obj = newarraycase_smiobj(2); |
+ assertKind(elements_kind.fast, obj); |
+ |
+ function newarraycase_length_smidouble(value) { |
+ var a = new Array(3); |
+ a[0] = value; |
+ return a; |
+ } |
+ |
+ // Case: new Array(length) as allocation site |
+ obj = newarraycase_length_smidouble(1); |
+ assertKind(elements_kind.fast_smi_only, obj); |
+ obj = newarraycase_length_smidouble(1.5); |
+ assertKind(elements_kind.fast_double, obj); |
+ obj = newarraycase_length_smidouble(2); |
+ assertKind(elements_kind.fast_double, obj); |
+ |
+ // Try to continue the transition to fast object, but |
+ // we will not pretransition from double->fast, because |
+ // it may hurt performance ("poisoning"). |
+ obj = newarraycase_length_smidouble("coates"); |
+ assertKind(elements_kind.fast, obj); |
+ obj = newarraycase_length_smidouble(2.5); |
+ // However, because of optimistic transitions, we will |
+ // transition to the most general kind of elements kind found, |
+ // therefore I can't count on this assert yet. |
+ // assertKind(elements_kind.fast_double, obj); |
+ |
+ function newarraycase_length_smiobj(value) { |
+ var a = new Array(3); |
+ a[0] = value; |
+ return a; |
+ } |
+ |
+ // Case: new Array(<length>) as allocation site, smi->fast |
+ obj = newarraycase_length_smiobj(1); |
+ assertKind(elements_kind.fast_smi_only, obj); |
+ obj = newarraycase_length_smiobj("gloria"); |
+ assertKind(elements_kind.fast, obj); |
+ obj = newarraycase_length_smiobj(2); |
+ assertKind(elements_kind.fast, obj); |
+ |
+ function newarraycase_list_smidouble(value) { |
+ var a = new Array(1, 2, 3); |
+ a[0] = value; |
+ return a; |
+ } |
+ |
+ obj = newarraycase_list_smidouble(1); |
+ assertKind(elements_kind.fast_smi_only, obj); |
+ obj = newarraycase_list_smidouble(1.5); |
+ assertKind(elements_kind.fast_double, obj); |
+ obj = newarraycase_list_smidouble(2); |
+ assertKind(elements_kind.fast_double, obj); |
+ |
+ function newarraycase_list_smiobj(value) { |
+ var a = new Array(4, 5, 6); |
+ a[0] = value; |
+ return a; |
+ } |
+ |
+ obj = newarraycase_list_smiobj(1); |
+ assertKind(elements_kind.fast_smi_only, obj); |
+ obj = newarraycase_list_smiobj("coates"); |
+ assertKind(elements_kind.fast, obj); |
+ obj = newarraycase_list_smiobj(2); |
+ assertKind(elements_kind.fast, obj); |
+ } |
} |