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 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
679 return obj; | 679 return obj; |
680 } | 680 } |
681 | 681 |
682 MUST_USE_RESULT virtual MaybeObject* Delete(JSObject* obj, | 682 MUST_USE_RESULT virtual MaybeObject* Delete(JSObject* obj, |
683 uint32_t key, | 683 uint32_t key, |
684 JSReceiver::DeleteMode mode) = 0; | 684 JSReceiver::DeleteMode mode) = 0; |
685 | 685 |
686 MUST_USE_RESULT static MaybeObject* CopyElementsImpl(FixedArrayBase* from, | 686 MUST_USE_RESULT static MaybeObject* CopyElementsImpl(FixedArrayBase* from, |
687 uint32_t from_start, | 687 uint32_t from_start, |
688 FixedArrayBase* to, | 688 FixedArrayBase* to, |
689 ElementsKind to_kind, | 689 ElementsKind from_kind, |
690 uint32_t to_start, | 690 uint32_t to_start, |
691 int packed_size, | 691 int packed_size, |
692 int copy_size) { | 692 int copy_size) { |
693 UNREACHABLE(); | 693 UNREACHABLE(); |
694 return NULL; | 694 return NULL; |
695 } | 695 } |
696 | 696 |
697 MUST_USE_RESULT virtual MaybeObject* CopyElements(JSObject* from_holder, | 697 MUST_USE_RESULT virtual MaybeObject* CopyElements(JSObject* from_holder, |
698 uint32_t from_start, | 698 uint32_t from_start, |
699 FixedArrayBase* to, | 699 FixedArrayBase* to, |
700 ElementsKind to_kind, | 700 ElementsKind from_kind, |
701 uint32_t to_start, | 701 uint32_t to_start, |
702 int copy_size, | 702 int copy_size, |
703 FixedArrayBase* from) { | 703 FixedArrayBase* from) { |
704 int packed_size = kPackedSizeNotKnown; | 704 int packed_size = kPackedSizeNotKnown; |
705 if (from == NULL) { | 705 if (from == NULL) { |
706 from = from_holder->elements(); | 706 from = from_holder->elements(); |
707 } | 707 } |
708 | 708 |
709 if (from_holder) { | 709 if (from_holder) { |
710 ElementsKind elements_kind = from_holder->GetElementsKind(); | 710 bool is_packed = IsFastPackedElementsKind(from_kind) && |
711 bool is_packed = IsFastPackedElementsKind(elements_kind) && | |
712 from_holder->IsJSArray(); | 711 from_holder->IsJSArray(); |
713 if (is_packed) { | 712 if (is_packed) { |
714 packed_size = Smi::cast(JSArray::cast(from_holder)->length())->value(); | 713 packed_size = Smi::cast(JSArray::cast(from_holder)->length())->value(); |
715 if (copy_size >= 0 && packed_size > copy_size) { | 714 if (copy_size >= 0 && packed_size > copy_size) { |
716 packed_size = copy_size; | 715 packed_size = copy_size; |
717 } | 716 } |
718 } | 717 } |
719 } | 718 } |
720 return ElementsAccessorSubclass::CopyElementsImpl( | 719 return ElementsAccessorSubclass::CopyElementsImpl( |
721 from, from_start, to, to_kind, to_start, packed_size, copy_size); | 720 from, from_start, to, from_kind, to_start, packed_size, copy_size); |
722 } | 721 } |
723 | 722 |
724 MUST_USE_RESULT virtual MaybeObject* AddElementsToFixedArray( | 723 MUST_USE_RESULT virtual MaybeObject* AddElementsToFixedArray( |
725 Object* receiver, | 724 Object* receiver, |
726 JSObject* holder, | 725 JSObject* holder, |
727 FixedArray* to, | 726 FixedArray* to, |
728 FixedArrayBase* from) { | 727 FixedArrayBase* from) { |
729 int len0 = to->length(); | 728 int len0 = to->length(); |
730 #ifdef DEBUG | 729 #ifdef DEBUG |
731 if (FLAG_enable_slow_asserts) { | 730 if (FLAG_enable_slow_asserts) { |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1011 kPointerSize> { | 1010 kPointerSize> { |
1012 public: | 1011 public: |
1013 explicit FastSmiOrObjectElementsAccessor(const char* name) | 1012 explicit FastSmiOrObjectElementsAccessor(const char* name) |
1014 : FastElementsAccessor<FastElementsAccessorSubclass, | 1013 : FastElementsAccessor<FastElementsAccessorSubclass, |
1015 KindTraits, | 1014 KindTraits, |
1016 kPointerSize>(name) {} | 1015 kPointerSize>(name) {} |
1017 | 1016 |
1018 static MaybeObject* CopyElementsImpl(FixedArrayBase* from, | 1017 static MaybeObject* CopyElementsImpl(FixedArrayBase* from, |
1019 uint32_t from_start, | 1018 uint32_t from_start, |
1020 FixedArrayBase* to, | 1019 FixedArrayBase* to, |
1021 ElementsKind to_kind, | 1020 ElementsKind from_kind, |
1022 uint32_t to_start, | 1021 uint32_t to_start, |
1023 int packed_size, | 1022 int packed_size, |
1024 int copy_size) { | 1023 int copy_size) { |
1025 if (IsFastSmiOrObjectElementsKind(to_kind)) { | 1024 ElementsKind to_kind = KindTraits::Kind; |
1026 CopyObjectToObjectElements( | 1025 switch (from_kind) { |
1027 from, KindTraits::Kind, from_start, to, to_kind, to_start, copy_size); | 1026 case FAST_SMI_ELEMENTS: |
1028 } else if (IsFastDoubleElementsKind(to_kind)) { | 1027 case FAST_HOLEY_SMI_ELEMENTS: |
1029 if (IsFastSmiElementsKind(KindTraits::Kind)) { | 1028 case FAST_ELEMENTS: |
1030 if (IsFastPackedElementsKind(KindTraits::Kind) && | 1029 case FAST_HOLEY_ELEMENTS: |
1031 packed_size != kPackedSizeNotKnown) { | 1030 CopyObjectToObjectElements( |
1032 CopyPackedSmiToDoubleElements( | 1031 from, from_kind, from_start, to, to_kind, to_start, copy_size); |
1033 from, from_start, to, to_start, packed_size, copy_size); | 1032 return to->GetHeap()->undefined_value(); |
1034 } else { | 1033 case FAST_DOUBLE_ELEMENTS: |
1035 CopySmiToDoubleElements(from, from_start, to, to_start, copy_size); | 1034 case FAST_HOLEY_DOUBLE_ELEMENTS: |
1036 } | 1035 return CopyDoubleToObjectElements( |
1037 } else { | 1036 from, from_start, to, to_kind, to_start, copy_size); |
1038 CopyObjectToDoubleElements(from, from_start, to, to_start, copy_size); | 1037 case DICTIONARY_ELEMENTS: |
1038 CopyDictionaryToObjectElements( | |
1039 from, from_start, to, to_kind, to_start, copy_size); | |
1040 return to->GetHeap()->undefined_value(); | |
1041 case NON_STRICT_ARGUMENTS_ELEMENTS: { | |
1042 FixedArray* parameter_map = FixedArray::cast(from); | |
1043 FixedArrayBase* arguments = FixedArrayBase::cast(parameter_map->get(1)); | |
1044 ElementsKind from_kind = arguments->GetElementsKind(); | |
1045 return CopyElementsImpl(arguments, from_start, to, from_kind, | |
Michael Starzinger
2012/11/29 09:39:32
Are you sure this is correct? This seems to only c
Michael Starzinger
2012/11/29 10:17:45
I looked into this problem. The current situation
Toon Verwaest
2012/11/29 14:04:40
Done.
| |
1046 to_start, packed_size, copy_size); | |
1039 } | 1047 } |
1040 } else { | 1048 case EXTERNAL_BYTE_ELEMENTS: |
1041 UNREACHABLE(); | 1049 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: |
1050 case EXTERNAL_SHORT_ELEMENTS: | |
1051 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: | |
1052 case EXTERNAL_INT_ELEMENTS: | |
1053 case EXTERNAL_UNSIGNED_INT_ELEMENTS: | |
1054 case EXTERNAL_FLOAT_ELEMENTS: | |
1055 case EXTERNAL_DOUBLE_ELEMENTS: | |
1056 case EXTERNAL_PIXEL_ELEMENTS: | |
1057 UNREACHABLE(); | |
1042 } | 1058 } |
1043 return to->GetHeap()->undefined_value(); | 1059 return NULL; |
1044 } | 1060 } |
1045 | 1061 |
1046 | 1062 |
1047 static MaybeObject* SetFastElementsCapacityAndLength(JSObject* obj, | 1063 static MaybeObject* SetFastElementsCapacityAndLength(JSObject* obj, |
1048 uint32_t capacity, | 1064 uint32_t capacity, |
1049 uint32_t length) { | 1065 uint32_t length) { |
1050 JSObject::SetFastElementsCapacitySmiMode set_capacity_mode = | 1066 JSObject::SetFastElementsCapacitySmiMode set_capacity_mode = |
1051 obj->HasFastSmiElements() | 1067 obj->HasFastSmiElements() |
1052 ? JSObject::kAllowSmiElements | 1068 ? JSObject::kAllowSmiElements |
1053 : JSObject::kDontAllowSmiElements; | 1069 : JSObject::kDontAllowSmiElements; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1122 uint32_t capacity, | 1138 uint32_t capacity, |
1123 uint32_t length) { | 1139 uint32_t length) { |
1124 return obj->SetFastDoubleElementsCapacityAndLength(capacity, | 1140 return obj->SetFastDoubleElementsCapacityAndLength(capacity, |
1125 length); | 1141 length); |
1126 } | 1142 } |
1127 | 1143 |
1128 protected: | 1144 protected: |
1129 static MaybeObject* CopyElementsImpl(FixedArrayBase* from, | 1145 static MaybeObject* CopyElementsImpl(FixedArrayBase* from, |
1130 uint32_t from_start, | 1146 uint32_t from_start, |
1131 FixedArrayBase* to, | 1147 FixedArrayBase* to, |
1132 ElementsKind to_kind, | 1148 ElementsKind from_kind, |
1133 uint32_t to_start, | 1149 uint32_t to_start, |
1134 int packed_size, | 1150 int packed_size, |
1135 int copy_size) { | 1151 int copy_size) { |
1136 switch (to_kind) { | 1152 switch (from_kind) { |
1137 case FAST_SMI_ELEMENTS: | 1153 case FAST_SMI_ELEMENTS: |
1138 case FAST_ELEMENTS: | 1154 CopyPackedSmiToDoubleElements( |
1155 from, from_start, to, to_start, packed_size, copy_size); | |
1156 break; | |
1139 case FAST_HOLEY_SMI_ELEMENTS: | 1157 case FAST_HOLEY_SMI_ELEMENTS: |
1140 case FAST_HOLEY_ELEMENTS: | 1158 CopySmiToDoubleElements(from, from_start, to, to_start, copy_size); |
1141 return CopyDoubleToObjectElements( | 1159 break; |
1142 from, from_start, to, to_kind, to_start, copy_size); | |
1143 case FAST_DOUBLE_ELEMENTS: | 1160 case FAST_DOUBLE_ELEMENTS: |
1144 case FAST_HOLEY_DOUBLE_ELEMENTS: | 1161 case FAST_HOLEY_DOUBLE_ELEMENTS: |
1145 CopyDoubleToDoubleElements(from, from_start, to, to_start, copy_size); | 1162 CopyDoubleToDoubleElements(from, from_start, to, to_start, copy_size); |
1146 return from; | 1163 break; |
1147 default: | 1164 case FAST_ELEMENTS: |
1165 case FAST_HOLEY_ELEMENTS: | |
1166 CopyObjectToDoubleElements(from, from_start, to, to_start, copy_size); | |
1167 break; | |
1168 case DICTIONARY_ELEMENTS: | |
1169 CopyDictionaryToDoubleElements( | |
1170 from, from_start, to, to_start, copy_size); | |
1171 break; | |
1172 case NON_STRICT_ARGUMENTS_ELEMENTS: | |
1173 case EXTERNAL_BYTE_ELEMENTS: | |
1174 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: | |
1175 case EXTERNAL_SHORT_ELEMENTS: | |
1176 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: | |
1177 case EXTERNAL_INT_ELEMENTS: | |
1178 case EXTERNAL_UNSIGNED_INT_ELEMENTS: | |
1179 case EXTERNAL_FLOAT_ELEMENTS: | |
1180 case EXTERNAL_DOUBLE_ELEMENTS: | |
1181 case EXTERNAL_PIXEL_ELEMENTS: | |
1148 UNREACHABLE(); | 1182 UNREACHABLE(); |
1149 } | 1183 } |
1150 return to->GetHeap()->undefined_value(); | 1184 return to->GetHeap()->undefined_value(); |
1151 } | 1185 } |
1152 }; | 1186 }; |
1153 | 1187 |
1154 | 1188 |
1155 class FastPackedDoubleElementsAccessor | 1189 class FastPackedDoubleElementsAccessor |
1156 : public FastDoubleElementsAccessor< | 1190 : public FastDoubleElementsAccessor< |
1157 FastPackedDoubleElementsAccessor, | 1191 FastPackedDoubleElementsAccessor, |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1453 } else { | 1487 } else { |
1454 obj->set_elements(new_elements); | 1488 obj->set_elements(new_elements); |
1455 } | 1489 } |
1456 } | 1490 } |
1457 return heap->true_value(); | 1491 return heap->true_value(); |
1458 } | 1492 } |
1459 | 1493 |
1460 MUST_USE_RESULT static MaybeObject* CopyElementsImpl(FixedArrayBase* from, | 1494 MUST_USE_RESULT static MaybeObject* CopyElementsImpl(FixedArrayBase* from, |
1461 uint32_t from_start, | 1495 uint32_t from_start, |
1462 FixedArrayBase* to, | 1496 FixedArrayBase* to, |
1463 ElementsKind to_kind, | 1497 ElementsKind from_kind, |
1464 uint32_t to_start, | 1498 uint32_t to_start, |
1465 int packed_size, | 1499 int packed_size, |
1466 int copy_size) { | 1500 int copy_size) { |
1467 switch (to_kind) { | 1501 UNREACHABLE(); |
1468 case FAST_SMI_ELEMENTS: | 1502 return NULL; |
1469 case FAST_ELEMENTS: | |
1470 case FAST_HOLEY_SMI_ELEMENTS: | |
1471 case FAST_HOLEY_ELEMENTS: | |
1472 CopyDictionaryToObjectElements( | |
1473 from, from_start, to, to_kind, to_start, copy_size); | |
1474 return from; | |
1475 case FAST_DOUBLE_ELEMENTS: | |
1476 case FAST_HOLEY_DOUBLE_ELEMENTS: | |
1477 CopyDictionaryToDoubleElements( | |
1478 from, from_start, to, to_start, copy_size); | |
1479 return from; | |
1480 default: | |
1481 UNREACHABLE(); | |
1482 } | |
1483 return to->GetHeap()->undefined_value(); | |
1484 } | 1503 } |
1485 | 1504 |
1486 | 1505 |
1487 protected: | 1506 protected: |
1488 friend class ElementsAccessorBase<DictionaryElementsAccessor, | 1507 friend class ElementsAccessorBase<DictionaryElementsAccessor, |
1489 ElementsKindTraits<DICTIONARY_ELEMENTS> >; | 1508 ElementsKindTraits<DICTIONARY_ELEMENTS> >; |
1490 | 1509 |
1491 MUST_USE_RESULT virtual MaybeObject* Delete(JSObject* obj, | 1510 MUST_USE_RESULT virtual MaybeObject* Delete(JSObject* obj, |
1492 uint32_t key, | 1511 uint32_t key, |
1493 JSReceiver::DeleteMode mode) { | 1512 JSReceiver::DeleteMode mode) { |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1700 // the class for the most generalized ElementsKind subclass. | 1719 // the class for the most generalized ElementsKind subclass. |
1701 return FastHoleyObjectElementsAccessor::DeleteCommon(obj, key, mode); | 1720 return FastHoleyObjectElementsAccessor::DeleteCommon(obj, key, mode); |
1702 } | 1721 } |
1703 } | 1722 } |
1704 return obj->GetHeap()->true_value(); | 1723 return obj->GetHeap()->true_value(); |
1705 } | 1724 } |
1706 | 1725 |
1707 MUST_USE_RESULT static MaybeObject* CopyElementsImpl(FixedArrayBase* from, | 1726 MUST_USE_RESULT static MaybeObject* CopyElementsImpl(FixedArrayBase* from, |
1708 uint32_t from_start, | 1727 uint32_t from_start, |
1709 FixedArrayBase* to, | 1728 FixedArrayBase* to, |
1710 ElementsKind to_kind, | 1729 ElementsKind from_kind, |
1711 uint32_t to_start, | 1730 uint32_t to_start, |
1712 int packed_size, | 1731 int packed_size, |
1713 int copy_size) { | 1732 int copy_size) { |
1714 FixedArray* parameter_map = FixedArray::cast(from); | 1733 UNREACHABLE(); |
1715 FixedArrayBase* arguments = FixedArrayBase::cast(parameter_map->get(1)); | 1734 return NULL; |
1716 ElementsAccessor* accessor = ElementsAccessor::ForArray(arguments); | |
1717 return accessor->CopyElements(NULL, from_start, to, to_kind, | |
1718 to_start, copy_size, arguments); | |
1719 } | 1735 } |
1720 | 1736 |
1721 static uint32_t GetCapacityImpl(FixedArrayBase* backing_store) { | 1737 static uint32_t GetCapacityImpl(FixedArrayBase* backing_store) { |
1722 FixedArray* parameter_map = FixedArray::cast(backing_store); | 1738 FixedArray* parameter_map = FixedArray::cast(backing_store); |
1723 FixedArrayBase* arguments = FixedArrayBase::cast(parameter_map->get(1)); | 1739 FixedArrayBase* arguments = FixedArrayBase::cast(parameter_map->get(1)); |
1724 return Max(static_cast<uint32_t>(parameter_map->length() - 2), | 1740 return Max(static_cast<uint32_t>(parameter_map->length() - 2), |
1725 ForArray(arguments)->GetCapacity(arguments)); | 1741 ForArray(arguments)->GetCapacity(arguments)); |
1726 } | 1742 } |
1727 | 1743 |
1728 static uint32_t GetKeyForIndexImpl(FixedArrayBase* dict, | 1744 static uint32_t GetKeyForIndexImpl(FixedArrayBase* dict, |
(...skipping 25 matching lines...) Expand all Loading... | |
1754 ? Smi::cast(JSArray::cast(holder)->length())->value() | 1770 ? Smi::cast(JSArray::cast(holder)->length())->value() |
1755 : parameter_map->length(); | 1771 : parameter_map->length(); |
1756 return key < (length - 2) | 1772 return key < (length - 2) |
1757 ? parameter_map->get(key + 2) | 1773 ? parameter_map->get(key + 2) |
1758 : parameter_map->GetHeap()->the_hole_value(); | 1774 : parameter_map->GetHeap()->the_hole_value(); |
1759 } | 1775 } |
1760 }; | 1776 }; |
1761 | 1777 |
1762 | 1778 |
1763 ElementsAccessor* ElementsAccessor::ForArray(FixedArrayBase* array) { | 1779 ElementsAccessor* ElementsAccessor::ForArray(FixedArrayBase* array) { |
1764 switch (array->map()->instance_type()) { | 1780 return elements_accessors_[array->GetElementsKind()]; |
1765 case FIXED_ARRAY_TYPE: | |
1766 if (array->IsDictionary()) { | |
1767 return elements_accessors_[DICTIONARY_ELEMENTS]; | |
1768 } else { | |
1769 return elements_accessors_[FAST_HOLEY_ELEMENTS]; | |
1770 } | |
1771 case EXTERNAL_BYTE_ARRAY_TYPE: | |
1772 return elements_accessors_[EXTERNAL_BYTE_ELEMENTS]; | |
1773 case EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE: | |
1774 return elements_accessors_[EXTERNAL_UNSIGNED_BYTE_ELEMENTS]; | |
1775 case EXTERNAL_SHORT_ARRAY_TYPE: | |
1776 return elements_accessors_[EXTERNAL_SHORT_ELEMENTS]; | |
1777 case EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE: | |
1778 return elements_accessors_[EXTERNAL_UNSIGNED_SHORT_ELEMENTS]; | |
1779 case EXTERNAL_INT_ARRAY_TYPE: | |
1780 return elements_accessors_[EXTERNAL_INT_ELEMENTS]; | |
1781 case EXTERNAL_UNSIGNED_INT_ARRAY_TYPE: | |
1782 return elements_accessors_[EXTERNAL_UNSIGNED_INT_ELEMENTS]; | |
1783 case EXTERNAL_FLOAT_ARRAY_TYPE: | |
1784 return elements_accessors_[EXTERNAL_FLOAT_ELEMENTS]; | |
1785 case EXTERNAL_DOUBLE_ARRAY_TYPE: | |
1786 return elements_accessors_[EXTERNAL_DOUBLE_ELEMENTS]; | |
1787 case EXTERNAL_PIXEL_ARRAY_TYPE: | |
1788 return elements_accessors_[EXTERNAL_PIXEL_ELEMENTS]; | |
1789 default: | |
1790 UNREACHABLE(); | |
1791 return NULL; | |
1792 } | |
1793 } | 1781 } |
1794 | 1782 |
1795 | 1783 |
1796 void ElementsAccessor::InitializeOncePerProcess() { | 1784 void ElementsAccessor::InitializeOncePerProcess() { |
1797 static ElementsAccessor* accessor_array[] = { | 1785 static ElementsAccessor* accessor_array[] = { |
1798 #define ACCESSOR_ARRAY(Class, Kind, Store) new Class(#Kind), | 1786 #define ACCESSOR_ARRAY(Class, Kind, Store) new Class(#Kind), |
1799 ELEMENTS_LIST(ACCESSOR_ARRAY) | 1787 ELEMENTS_LIST(ACCESSOR_ARRAY) |
1800 #undef ACCESSOR_ARRAY | 1788 #undef ACCESSOR_ARRAY |
1801 }; | 1789 }; |
1802 | 1790 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1870 if (!maybe_obj->To(&new_backing_store)) return maybe_obj; | 1858 if (!maybe_obj->To(&new_backing_store)) return maybe_obj; |
1871 new_backing_store->set(0, length); | 1859 new_backing_store->set(0, length); |
1872 { MaybeObject* result = array->SetContent(new_backing_store); | 1860 { MaybeObject* result = array->SetContent(new_backing_store); |
1873 if (result->IsFailure()) return result; | 1861 if (result->IsFailure()) return result; |
1874 } | 1862 } |
1875 return array; | 1863 return array; |
1876 } | 1864 } |
1877 | 1865 |
1878 | 1866 |
1879 } } // namespace v8::internal | 1867 } } // namespace v8::internal |
OLD | NEW |