OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
8 #include "src/conversions.h" | 8 #include "src/conversions.h" |
9 #include "src/elements.h" | 9 #include "src/elements.h" |
10 #include "src/objects.h" | 10 #include "src/objects.h" |
(...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 return ElementsAccessorSubclass::GetKeyForIndexImpl(backing_store, index); | 866 return ElementsAccessorSubclass::GetKeyForIndexImpl(backing_store, index); |
867 } | 867 } |
868 | 868 |
869 private: | 869 private: |
870 DISALLOW_COPY_AND_ASSIGN(ElementsAccessorBase); | 870 DISALLOW_COPY_AND_ASSIGN(ElementsAccessorBase); |
871 }; | 871 }; |
872 | 872 |
873 | 873 |
874 // Super class for all fast element arrays. | 874 // Super class for all fast element arrays. |
875 template<typename FastElementsAccessorSubclass, | 875 template<typename FastElementsAccessorSubclass, |
876 typename KindTraits, | 876 typename KindTraits> |
877 int ElementSize> | |
878 class FastElementsAccessor | 877 class FastElementsAccessor |
879 : public ElementsAccessorBase<FastElementsAccessorSubclass, KindTraits> { | 878 : public ElementsAccessorBase<FastElementsAccessorSubclass, KindTraits> { |
880 public: | 879 public: |
881 explicit FastElementsAccessor(const char* name) | 880 explicit FastElementsAccessor(const char* name) |
882 : ElementsAccessorBase<FastElementsAccessorSubclass, | 881 : ElementsAccessorBase<FastElementsAccessorSubclass, |
883 KindTraits>(name) {} | 882 KindTraits>(name) {} |
884 protected: | 883 protected: |
885 friend class ElementsAccessorBase<FastElementsAccessorSubclass, KindTraits>; | 884 friend class ElementsAccessorBase<FastElementsAccessorSubclass, KindTraits>; |
886 friend class SloppyArgumentsElementsAccessor; | 885 friend class SloppyArgumentsElementsAccessor; |
887 | 886 |
(...skipping 21 matching lines...) Expand all Loading... |
909 // Check whether the backing store should be shrunk. | 908 // Check whether the backing store should be shrunk. |
910 if (length <= old_capacity) { | 909 if (length <= old_capacity) { |
911 if (array->HasFastSmiOrObjectElements()) { | 910 if (array->HasFastSmiOrObjectElements()) { |
912 backing_store = JSObject::EnsureWritableFastElements(array); | 911 backing_store = JSObject::EnsureWritableFastElements(array); |
913 } | 912 } |
914 if (2 * length <= old_capacity) { | 913 if (2 * length <= old_capacity) { |
915 // If more than half the elements won't be used, trim the array. | 914 // If more than half the elements won't be used, trim the array. |
916 if (length == 0) { | 915 if (length == 0) { |
917 array->initialize_elements(); | 916 array->initialize_elements(); |
918 } else { | 917 } else { |
919 int filler_size = (old_capacity - length) * ElementSize; | 918 isolate->heap()->RightTrimFixedArray<Heap::FROM_MUTATOR>( |
920 Address filler_start = backing_store->address() + | 919 *backing_store, old_capacity - length); |
921 BackingStore::OffsetOfElementAt(length); | |
922 array->GetHeap()->CreateFillerObjectAt(filler_start, filler_size); | |
923 | |
924 // We are storing the new length using release store after creating a | |
925 // filler for the left-over space to avoid races with the sweeper | |
926 // thread. | |
927 backing_store->synchronized_set_length(length); | |
928 } | 920 } |
929 } else { | 921 } else { |
930 // Otherwise, fill the unused tail with holes. | 922 // Otherwise, fill the unused tail with holes. |
931 int old_length = FastD2IChecked(array->length()->Number()); | 923 int old_length = FastD2IChecked(array->length()->Number()); |
932 for (int i = length; i < old_length; i++) { | 924 for (int i = length; i < old_length; i++) { |
933 Handle<BackingStore>::cast(backing_store)->set_the_hole(i); | 925 Handle<BackingStore>::cast(backing_store)->set_the_hole(i); |
934 } | 926 } |
935 } | 927 } |
936 return length_object; | 928 return length_object; |
937 } | 929 } |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1071 default: | 1063 default: |
1072 UNREACHABLE(); | 1064 UNREACHABLE(); |
1073 } | 1065 } |
1074 return FAST_HOLEY_ELEMENTS; | 1066 return FAST_HOLEY_ELEMENTS; |
1075 } | 1067 } |
1076 | 1068 |
1077 | 1069 |
1078 template<typename FastElementsAccessorSubclass, | 1070 template<typename FastElementsAccessorSubclass, |
1079 typename KindTraits> | 1071 typename KindTraits> |
1080 class FastSmiOrObjectElementsAccessor | 1072 class FastSmiOrObjectElementsAccessor |
1081 : public FastElementsAccessor<FastElementsAccessorSubclass, | 1073 : public FastElementsAccessor<FastElementsAccessorSubclass, KindTraits> { |
1082 KindTraits, | |
1083 kPointerSize> { | |
1084 public: | 1074 public: |
1085 explicit FastSmiOrObjectElementsAccessor(const char* name) | 1075 explicit FastSmiOrObjectElementsAccessor(const char* name) |
1086 : FastElementsAccessor<FastElementsAccessorSubclass, | 1076 : FastElementsAccessor<FastElementsAccessorSubclass, |
1087 KindTraits, | 1077 KindTraits>(name) {} |
1088 kPointerSize>(name) {} | |
1089 | 1078 |
1090 static void CopyElementsImpl(Handle<FixedArrayBase> from, | 1079 static void CopyElementsImpl(Handle<FixedArrayBase> from, |
1091 uint32_t from_start, | 1080 uint32_t from_start, |
1092 Handle<FixedArrayBase> to, | 1081 Handle<FixedArrayBase> to, |
1093 ElementsKind from_kind, | 1082 ElementsKind from_kind, |
1094 uint32_t to_start, | 1083 uint32_t to_start, |
1095 int packed_size, | 1084 int packed_size, |
1096 int copy_size) { | 1085 int copy_size) { |
1097 ElementsKind to_kind = KindTraits::Kind; | 1086 ElementsKind to_kind = KindTraits::Kind; |
1098 switch (from_kind) { | 1087 switch (from_kind) { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1192 explicit FastHoleyObjectElementsAccessor(const char* name) | 1181 explicit FastHoleyObjectElementsAccessor(const char* name) |
1193 : FastSmiOrObjectElementsAccessor< | 1182 : FastSmiOrObjectElementsAccessor< |
1194 FastHoleyObjectElementsAccessor, | 1183 FastHoleyObjectElementsAccessor, |
1195 ElementsKindTraits<FAST_HOLEY_ELEMENTS> >(name) {} | 1184 ElementsKindTraits<FAST_HOLEY_ELEMENTS> >(name) {} |
1196 }; | 1185 }; |
1197 | 1186 |
1198 | 1187 |
1199 template<typename FastElementsAccessorSubclass, | 1188 template<typename FastElementsAccessorSubclass, |
1200 typename KindTraits> | 1189 typename KindTraits> |
1201 class FastDoubleElementsAccessor | 1190 class FastDoubleElementsAccessor |
1202 : public FastElementsAccessor<FastElementsAccessorSubclass, | 1191 : public FastElementsAccessor<FastElementsAccessorSubclass, KindTraits> { |
1203 KindTraits, | |
1204 kDoubleSize> { | |
1205 public: | 1192 public: |
1206 explicit FastDoubleElementsAccessor(const char* name) | 1193 explicit FastDoubleElementsAccessor(const char* name) |
1207 : FastElementsAccessor<FastElementsAccessorSubclass, | 1194 : FastElementsAccessor<FastElementsAccessorSubclass, |
1208 KindTraits, | 1195 KindTraits>(name) {} |
1209 kDoubleSize>(name) {} | |
1210 | 1196 |
1211 static void SetFastElementsCapacityAndLength(Handle<JSObject> obj, | 1197 static void SetFastElementsCapacityAndLength(Handle<JSObject> obj, |
1212 uint32_t capacity, | 1198 uint32_t capacity, |
1213 uint32_t length) { | 1199 uint32_t length) { |
1214 JSObject::SetFastDoubleElementsCapacityAndLength(obj, capacity, length); | 1200 JSObject::SetFastDoubleElementsCapacityAndLength(obj, capacity, length); |
1215 } | 1201 } |
1216 | 1202 |
1217 protected: | 1203 protected: |
1218 static void CopyElementsImpl(Handle<FixedArrayBase> from, | 1204 static void CopyElementsImpl(Handle<FixedArrayBase> from, |
1219 uint32_t from_start, | 1205 uint32_t from_start, |
(...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1974 UNREACHABLE(); | 1960 UNREACHABLE(); |
1975 break; | 1961 break; |
1976 } | 1962 } |
1977 | 1963 |
1978 array->set_elements(*elms); | 1964 array->set_elements(*elms); |
1979 array->set_length(Smi::FromInt(number_of_elements)); | 1965 array->set_length(Smi::FromInt(number_of_elements)); |
1980 return array; | 1966 return array; |
1981 } | 1967 } |
1982 | 1968 |
1983 } } // namespace v8::internal | 1969 } } // namespace v8::internal |
OLD | NEW |