OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdlib.h> | 5 #include <stdlib.h> |
6 #include <utility> | 6 #include <utility> |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 SNPrintF(buffer, "%s%d", str, suffix); | 56 SNPrintF(buffer, "%s%d", str, suffix); |
57 return MakeString(buffer.start()); | 57 return MakeString(buffer.start()); |
58 } | 58 } |
59 | 59 |
60 | 60 |
61 static Handle<AccessorPair> CreateAccessorPair(bool with_getter, | 61 static Handle<AccessorPair> CreateAccessorPair(bool with_getter, |
62 bool with_setter) { | 62 bool with_setter) { |
63 Isolate* isolate = CcTest::i_isolate(); | 63 Isolate* isolate = CcTest::i_isolate(); |
64 Factory* factory = isolate->factory(); | 64 Factory* factory = isolate->factory(); |
65 Handle<AccessorPair> pair = factory->NewAccessorPair(); | 65 Handle<AccessorPair> pair = factory->NewAccessorPair(); |
| 66 Handle<String> empty_string = factory->empty_string(); |
66 if (with_getter) { | 67 if (with_getter) { |
67 pair->set_getter(*factory->NewFunction(factory->empty_string())); | 68 Handle<JSFunction> func = factory->NewFunction(empty_string); |
| 69 pair->set_getter(*func); |
68 } | 70 } |
69 if (with_setter) { | 71 if (with_setter) { |
70 pair->set_setter(*factory->NewFunction(factory->empty_string())); | 72 Handle<JSFunction> func = factory->NewFunction(empty_string); |
| 73 pair->set_setter(*func); |
71 } | 74 } |
72 return pair; | 75 return pair; |
73 } | 76 } |
74 | 77 |
75 | 78 |
76 static bool EqualDetails(DescriptorArray* descriptors, int descriptor, | 79 static bool EqualDetails(DescriptorArray* descriptors, int descriptor, |
77 PropertyType type, PropertyAttributes attributes, | 80 PropertyType type, PropertyAttributes attributes, |
78 Representation representation, int field_index = -1) { | 81 Representation representation, int field_index = -1) { |
79 PropertyDetails details = descriptors->GetDetails(descriptor); | 82 PropertyDetails details = descriptors->GetDetails(descriptor); |
80 if (details.type() != type) return false; | 83 if (details.type() != type) return false; |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 CHECK(!map->is_deprecated()); | 439 CHECK(!map->is_deprecated()); |
437 CHECK(map->is_stable()); | 440 CHECK(map->is_stable()); |
438 CHECK(expectations.Check(*map)); | 441 CHECK(expectations.Check(*map)); |
439 | 442 |
440 expectations.SetDataField(0, NONE, Representation::None(), none_type); | 443 expectations.SetDataField(0, NONE, Representation::None(), none_type); |
441 | 444 |
442 CHECK(!new_map->is_deprecated()); | 445 CHECK(!new_map->is_deprecated()); |
443 CHECK(new_map->is_stable()); | 446 CHECK(new_map->is_stable()); |
444 CHECK(expectations.Check(*new_map)); | 447 CHECK(expectations.Check(*new_map)); |
445 | 448 |
446 CHECK_EQ(*new_map, *Map::ReconfigureProperty(map, 0, kData, NONE, | 449 Handle<Map> new_map2 = Map::ReconfigureProperty( |
447 Representation::None(), | 450 map, 0, kData, NONE, Representation::None(), none_type, FORCE_FIELD); |
448 none_type, FORCE_FIELD)); | 451 CHECK_EQ(*new_map, *new_map2); |
449 | 452 |
450 Handle<Object> value(Smi::FromInt(0), isolate); | 453 Handle<Object> value(Smi::FromInt(0), isolate); |
451 Handle<Map> prepared_map = Map::PrepareForDataProperty(new_map, 0, value); | 454 Handle<Map> prepared_map = Map::PrepareForDataProperty(new_map, 0, value); |
452 // None to Smi generalization is trivial, map does not change. | 455 // None to Smi generalization is trivial, map does not change. |
453 CHECK_EQ(*new_map, *prepared_map); | 456 CHECK_EQ(*new_map, *prepared_map); |
454 | 457 |
455 expectations.SetDataField(0, NONE, Representation::Smi(), any_type); | 458 expectations.SetDataField(0, NONE, Representation::Smi(), any_type); |
456 CHECK(prepared_map->is_stable()); | 459 CHECK(prepared_map->is_stable()); |
457 CHECK(expectations.Check(*prepared_map)); | 460 CHECK(expectations.Check(*prepared_map)); |
458 | 461 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 CHECK(!new_map->is_dictionary_map()); | 567 CHECK(!new_map->is_dictionary_map()); |
565 CHECK(expectations.Check(*new_map)); | 568 CHECK(expectations.Check(*new_map)); |
566 } | 569 } |
567 | 570 |
568 Handle<Map> active_map = maps[kPropCount - 1]; | 571 Handle<Map> active_map = maps[kPropCount - 1]; |
569 CHECK(!active_map->is_deprecated()); | 572 CHECK(!active_map->is_deprecated()); |
570 | 573 |
571 // Update all deprecated maps and check that they are now the same. | 574 // Update all deprecated maps and check that they are now the same. |
572 CHECK_EQ(*active_map, *Map::Update(map)); | 575 CHECK_EQ(*active_map, *Map::Update(map)); |
573 for (int i = 0; i < kPropCount; i++) { | 576 for (int i = 0; i < kPropCount; i++) { |
574 CHECK_EQ(*active_map, *Map::Update(maps[i])); | 577 Handle<Map> updated_map = Map::Update(maps[i]); |
| 578 CHECK_EQ(*active_map, *updated_map); |
575 } | 579 } |
576 } | 580 } |
577 | 581 |
578 | 582 |
579 static void TestGeneralizeRepresentationTrivial( | 583 static void TestGeneralizeRepresentationTrivial( |
580 Representation from_representation, Handle<HeapType> from_type, | 584 Representation from_representation, Handle<HeapType> from_type, |
581 Representation to_representation, Handle<HeapType> to_type, | 585 Representation to_representation, Handle<HeapType> to_type, |
582 Representation expected_representation, Handle<HeapType> expected_type, | 586 Representation expected_representation, Handle<HeapType> expected_type, |
583 bool expected_field_type_dependency = true) { | 587 bool expected_field_type_dependency = true) { |
584 Isolate* isolate = CcTest::i_isolate(); | 588 Isolate* isolate = CcTest::i_isolate(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 info.HasAbortedDueToDependencyChange()); | 621 info.HasAbortedDueToDependencyChange()); |
618 | 622 |
619 info.RollbackDependencies(); // Properly cleanup compilation info. | 623 info.RollbackDependencies(); // Properly cleanup compilation info. |
620 | 624 |
621 CHECK_EQ(*map, *new_map); | 625 CHECK_EQ(*map, *new_map); |
622 CHECK(!new_map->is_deprecated()); | 626 CHECK(!new_map->is_deprecated()); |
623 CHECK(!new_map->is_dictionary_map()); | 627 CHECK(!new_map->is_dictionary_map()); |
624 CHECK(expectations.Check(*new_map)); | 628 CHECK(expectations.Check(*new_map)); |
625 } | 629 } |
626 | 630 |
627 CHECK_EQ(*map, *Map::Update(map)); | 631 Handle<Map> updated_map = Map::Update(map); |
| 632 CHECK_EQ(*map, *updated_map); |
628 } | 633 } |
629 | 634 |
630 | 635 |
631 TEST(GeneralizeRepresentationSmiToDouble) { | 636 TEST(GeneralizeRepresentationSmiToDouble) { |
632 CcTest::InitializeVM(); | 637 CcTest::InitializeVM(); |
633 v8::HandleScope scope(CcTest::isolate()); | 638 v8::HandleScope scope(CcTest::isolate()); |
634 Isolate* isolate = CcTest::i_isolate(); | 639 Isolate* isolate = CcTest::i_isolate(); |
635 Handle<HeapType> any_type = HeapType::Any(isolate); | 640 Handle<HeapType> any_type = HeapType::Any(isolate); |
636 | 641 |
637 TestGeneralizeRepresentation(Representation::Smi(), any_type, | 642 TestGeneralizeRepresentation(Representation::Smi(), any_type, |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
825 CHECK(!new_map->is_dictionary_map()); | 830 CHECK(!new_map->is_dictionary_map()); |
826 CHECK(expectations.Check(*new_map)); | 831 CHECK(expectations.Check(*new_map)); |
827 } | 832 } |
828 | 833 |
829 Handle<Map> active_map = maps[kPropCount - 1]; | 834 Handle<Map> active_map = maps[kPropCount - 1]; |
830 CHECK(!active_map->is_deprecated()); | 835 CHECK(!active_map->is_deprecated()); |
831 | 836 |
832 // Update all deprecated maps and check that they are now the same. | 837 // Update all deprecated maps and check that they are now the same. |
833 CHECK_EQ(*active_map, *Map::Update(map)); | 838 CHECK_EQ(*active_map, *Map::Update(map)); |
834 for (int i = 0; i < kPropCount; i++) { | 839 for (int i = 0; i < kPropCount; i++) { |
835 CHECK_EQ(*active_map, *Map::Update(maps[i])); | 840 Handle<Map> updated_map = Map::Update(maps[i]); |
| 841 CHECK_EQ(*active_map, *updated_map); |
836 } | 842 } |
837 } | 843 } |
838 | 844 |
839 | 845 |
840 //////////////////////////////////////////////////////////////////////////////// | 846 //////////////////////////////////////////////////////////////////////////////// |
841 // A set of tests for attribute reconfiguration case. | 847 // A set of tests for attribute reconfiguration case. |
842 // | 848 // |
843 | 849 |
844 // This test ensures that representation/field type generalization is correctly | 850 // This test ensures that representation/field type generalization is correctly |
845 // propagated from one branch of transition tree (|map2|) to another (|map|). | 851 // propagated from one branch of transition tree (|map2|) to another (|map|). |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
914 CHECK(map->is_deprecated()); | 920 CHECK(map->is_deprecated()); |
915 CHECK(!info.HasAbortedDueToDependencyChange()); | 921 CHECK(!info.HasAbortedDueToDependencyChange()); |
916 info.RollbackDependencies(); // Properly cleanup compilation info. | 922 info.RollbackDependencies(); // Properly cleanup compilation info. |
917 CHECK_NE(*map, *new_map); | 923 CHECK_NE(*map, *new_map); |
918 | 924 |
919 CHECK(!new_map->is_deprecated()); | 925 CHECK(!new_map->is_deprecated()); |
920 CHECK(!new_map->is_dictionary_map()); | 926 CHECK(!new_map->is_dictionary_map()); |
921 CHECK(expectations.Check(*new_map)); | 927 CHECK(expectations.Check(*new_map)); |
922 | 928 |
923 // Update deprecated |map|, it should become |new_map|. | 929 // Update deprecated |map|, it should become |new_map|. |
924 CHECK_EQ(*new_map, *Map::Update(map)); | 930 Handle<Map> updated_map = Map::Update(map); |
| 931 CHECK_EQ(*new_map, *updated_map); |
925 } | 932 } |
926 | 933 |
927 | 934 |
928 // This test ensures that trivial representation/field type generalization | 935 // This test ensures that trivial representation/field type generalization |
929 // (from HeapObject to HeapObject) is correctly propagated from one branch of | 936 // (from HeapObject to HeapObject) is correctly propagated from one branch of |
930 // transition tree (|map2|) to another (|map|). | 937 // transition tree (|map2|) to another (|map|). |
931 // | 938 // |
932 // + - p2B - p3 - p4: |map2| | 939 // + - p2B - p3 - p4: |map2| |
933 // | | 940 // | |
934 // {} - p0 - p1 - p2A - p3 - p4: |map| | 941 // {} - p0 - p1 - p2A - p3 - p4: |map| |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1003 CHECK(!map->is_deprecated()); | 1010 CHECK(!map->is_deprecated()); |
1004 CHECK_EQ(*map, *new_map); | 1011 CHECK_EQ(*map, *new_map); |
1005 CHECK_EQ(expected_field_type_dependency, | 1012 CHECK_EQ(expected_field_type_dependency, |
1006 info.HasAbortedDueToDependencyChange()); | 1013 info.HasAbortedDueToDependencyChange()); |
1007 info.RollbackDependencies(); // Properly cleanup compilation info. | 1014 info.RollbackDependencies(); // Properly cleanup compilation info. |
1008 | 1015 |
1009 CHECK(!new_map->is_deprecated()); | 1016 CHECK(!new_map->is_deprecated()); |
1010 CHECK(!new_map->is_dictionary_map()); | 1017 CHECK(!new_map->is_dictionary_map()); |
1011 CHECK(expectations.Check(*new_map)); | 1018 CHECK(expectations.Check(*new_map)); |
1012 | 1019 |
1013 CHECK_EQ(*new_map, *Map::Update(map)); | 1020 Handle<Map> updated_map = Map::Update(map); |
| 1021 CHECK_EQ(*new_map, *updated_map); |
1014 } | 1022 } |
1015 | 1023 |
1016 | 1024 |
1017 TEST(ReconfigureDataFieldAttribute_GeneralizeRepresentationSmiToDouble) { | 1025 TEST(ReconfigureDataFieldAttribute_GeneralizeRepresentationSmiToDouble) { |
1018 CcTest::InitializeVM(); | 1026 CcTest::InitializeVM(); |
1019 v8::HandleScope scope(CcTest::isolate()); | 1027 v8::HandleScope scope(CcTest::isolate()); |
1020 Isolate* isolate = CcTest::i_isolate(); | 1028 Isolate* isolate = CcTest::i_isolate(); |
1021 Handle<HeapType> any_type = HeapType::Any(isolate); | 1029 Handle<HeapType> any_type = HeapType::Any(isolate); |
1022 | 1030 |
1023 TestReconfigureDataFieldAttribute_GeneralizeRepresentation( | 1031 TestReconfigureDataFieldAttribute_GeneralizeRepresentation( |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1108 void Check(Handle<Map> map, Handle<Map> new_map, | 1116 void Check(Handle<Map> map, Handle<Map> new_map, |
1109 const Expectations& expectations) { | 1117 const Expectations& expectations) { |
1110 CHECK(map->is_deprecated()); | 1118 CHECK(map->is_deprecated()); |
1111 CHECK_NE(*map, *new_map); | 1119 CHECK_NE(*map, *new_map); |
1112 | 1120 |
1113 CHECK(!new_map->is_deprecated()); | 1121 CHECK(!new_map->is_deprecated()); |
1114 CHECK(!new_map->is_dictionary_map()); | 1122 CHECK(!new_map->is_dictionary_map()); |
1115 CHECK(expectations.Check(*new_map)); | 1123 CHECK(expectations.Check(*new_map)); |
1116 | 1124 |
1117 // Update deprecated |map|, it should become |new_map|. | 1125 // Update deprecated |map|, it should become |new_map|. |
1118 CHECK_EQ(*new_map, *Map::Update(map)); | 1126 Handle<Map> updated_map = Map::Update(map); |
| 1127 CHECK_EQ(*new_map, *updated_map); |
1119 } | 1128 } |
1120 }; | 1129 }; |
1121 | 1130 |
1122 | 1131 |
1123 // Checks that given |map| is NOT deprecated, equals to given |new_map| and | 1132 // Checks that given |map| is NOT deprecated, equals to given |new_map| and |
1124 // matches expectations. | 1133 // matches expectations. |
1125 struct CheckSameMap { | 1134 struct CheckSameMap { |
1126 void Check(Handle<Map> map, Handle<Map> new_map, | 1135 void Check(Handle<Map> map, Handle<Map> new_map, |
1127 const Expectations& expectations) { | 1136 const Expectations& expectations) { |
1128 CHECK(!map->is_deprecated()); | 1137 CHECK(!map->is_deprecated()); |
1129 CHECK_EQ(*map, *new_map); | 1138 CHECK_EQ(*map, *new_map); |
1130 | 1139 |
1131 CHECK(!new_map->is_deprecated()); | 1140 CHECK(!new_map->is_deprecated()); |
1132 CHECK(!new_map->is_dictionary_map()); | 1141 CHECK(!new_map->is_dictionary_map()); |
1133 CHECK(expectations.Check(*new_map)); | 1142 CHECK(expectations.Check(*new_map)); |
1134 | 1143 |
1135 // Update deprecated |map|, it should become |new_map|. | 1144 // Update deprecated |map|, it should become |new_map|. |
1136 CHECK_EQ(*new_map, *Map::Update(map)); | 1145 Handle<Map> updated_map = Map::Update(map); |
| 1146 CHECK_EQ(*new_map, *updated_map); |
1137 } | 1147 } |
1138 }; | 1148 }; |
1139 | 1149 |
1140 | 1150 |
1141 // Checks that given |map| is NOT deprecated, and |new_map| is a result of | 1151 // Checks that given |map| is NOT deprecated, and |new_map| is a result of |
1142 // copy-generalize-all-representations. | 1152 // copy-generalize-all-representations. |
1143 struct CheckCopyGeneralizeAllRepresentations { | 1153 struct CheckCopyGeneralizeAllRepresentations { |
1144 void Check(Handle<Map> map, Handle<Map> new_map, Expectations& expectations) { | 1154 void Check(Handle<Map> map, Handle<Map> new_map, Expectations& expectations) { |
1145 CHECK(!map->is_deprecated()); | 1155 CHECK(!map->is_deprecated()); |
1146 CHECK_NE(*map, *new_map); | 1156 CHECK_NE(*map, *new_map); |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1541 CHECK(expectations.Check(*new_map2)); | 1551 CHECK(expectations.Check(*new_map2)); |
1542 } | 1552 } |
1543 } | 1553 } |
1544 | 1554 |
1545 Handle<Map> active_map = maps[kPropCount - 1]; | 1555 Handle<Map> active_map = maps[kPropCount - 1]; |
1546 CHECK(!active_map->is_deprecated()); | 1556 CHECK(!active_map->is_deprecated()); |
1547 | 1557 |
1548 // Update all deprecated maps and check that they are now the same. | 1558 // Update all deprecated maps and check that they are now the same. |
1549 CHECK_EQ(*active_map, *Map::Update(map)); | 1559 CHECK_EQ(*active_map, *Map::Update(map)); |
1550 for (int i = 0; i < kPropCount; i++) { | 1560 for (int i = 0; i < kPropCount; i++) { |
1551 CHECK_EQ(*active_map, *Map::Update(maps[i])); | 1561 Handle<Map> updated_map = Map::Update(maps[i]); |
| 1562 CHECK_EQ(*active_map, *updated_map); |
1552 } | 1563 } |
1553 } | 1564 } |
1554 | 1565 |
1555 | 1566 |
1556 TEST(ElementsKindTransitionFromMapOwningDescriptor) { | 1567 TEST(ElementsKindTransitionFromMapOwningDescriptor) { |
1557 CcTest::InitializeVM(); | 1568 CcTest::InitializeVM(); |
1558 v8::HandleScope scope(CcTest::isolate()); | 1569 v8::HandleScope scope(CcTest::isolate()); |
1559 Isolate* isolate = CcTest::i_isolate(); | 1570 Isolate* isolate = CcTest::i_isolate(); |
1560 Handle<HeapType> any_type = HeapType::Any(isolate); | 1571 Handle<HeapType> any_type = HeapType::Any(isolate); |
1561 Handle<HeapType> value_type = | 1572 Handle<HeapType> value_type = |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1848 : descriptor_(descriptor), | 1859 : descriptor_(descriptor), |
1849 representation_(representation), | 1860 representation_(representation), |
1850 attributes_(attributes), | 1861 attributes_(attributes), |
1851 heap_type_(heap_type) {} | 1862 heap_type_(heap_type) {} |
1852 | 1863 |
1853 void Check(Expectations& expectations2, Handle<Map> map1, Handle<Map> map2) { | 1864 void Check(Expectations& expectations2, Handle<Map> map1, Handle<Map> map2) { |
1854 CHECK(!map2->is_deprecated()); | 1865 CHECK(!map2->is_deprecated()); |
1855 | 1866 |
1856 CHECK(map1->is_deprecated()); | 1867 CHECK(map1->is_deprecated()); |
1857 CHECK_NE(*map1, *map2); | 1868 CHECK_NE(*map1, *map2); |
1858 CHECK_EQ(*map2, *Map::Update(map1)); | 1869 Handle<Map> updated_map = Map::Update(map1); |
| 1870 CHECK_EQ(*map2, *updated_map); |
1859 | 1871 |
1860 expectations2.SetDataField(descriptor_, representation_, heap_type_); | 1872 expectations2.SetDataField(descriptor_, representation_, heap_type_); |
1861 CHECK(expectations2.Check(*map2)); | 1873 CHECK(expectations2.Check(*map2)); |
1862 } | 1874 } |
1863 }; | 1875 }; |
1864 | 1876 |
1865 | 1877 |
1866 // Checks that existing transition was taken as is. | 1878 // Checks that existing transition was taken as is. |
1867 struct SameMapChecker { | 1879 struct SameMapChecker { |
1868 void Check(Expectations& expectations, Handle<Map> map1, Handle<Map> map2) { | 1880 void Check(Expectations& expectations, Handle<Map> map1, Handle<Map> map2) { |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2008 Handle<AccessorPair> pair = CreateAccessorPair(true, true); | 2020 Handle<AccessorPair> pair = CreateAccessorPair(true, true); |
2009 TransitionToAccessorConstantOperator transition_op(pair); | 2021 TransitionToAccessorConstantOperator transition_op(pair); |
2010 | 2022 |
2011 SameMapChecker checker; | 2023 SameMapChecker checker; |
2012 TestTransitionTo(transition_op, transition_op, checker); | 2024 TestTransitionTo(transition_op, transition_op, checker); |
2013 } | 2025 } |
2014 | 2026 |
2015 | 2027 |
2016 // TODO(ishell): add this test once IS_ACCESSOR_FIELD_SUPPORTED is supported. | 2028 // TODO(ishell): add this test once IS_ACCESSOR_FIELD_SUPPORTED is supported. |
2017 // TEST(TransitionAccessorConstantToAnotherAccessorConstant) | 2029 // TEST(TransitionAccessorConstantToAnotherAccessorConstant) |
OLD | NEW |