Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/elements.cc

Issue 208313012: FastElementsAccessor::SetLengthWithoutNormalize() handlified. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 766 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 } 777 }
778 778
779 MUST_USE_RESULT static MaybeObject* SetFastElementsCapacityAndLength( 779 MUST_USE_RESULT static MaybeObject* SetFastElementsCapacityAndLength(
780 JSObject* obj, 780 JSObject* obj,
781 int capacity, 781 int capacity,
782 int length) { 782 int length) {
783 UNIMPLEMENTED(); 783 UNIMPLEMENTED();
784 return obj; 784 return obj;
785 } 785 }
786 786
787 // TODO(ishell): Temporary wrapper until handlified.
788 MUST_USE_RESULT static Handle<FixedArray> SetFastElementsCapacityAndLength(
789 Handle<JSObject> obj,
790 int capacity,
791 int length) {
792 CALL_HEAP_FUNCTION(obj->GetIsolate(),
793 SetFastElementsCapacityAndLength(*obj, capacity, length),
794 FixedArray);
795 }
796
787 MUST_USE_RESULT virtual Handle<Object> Delete( 797 MUST_USE_RESULT virtual Handle<Object> Delete(
788 Handle<JSObject> obj, 798 Handle<JSObject> obj,
789 uint32_t key, 799 uint32_t key,
790 JSReceiver::DeleteMode mode) V8_OVERRIDE = 0; 800 JSReceiver::DeleteMode mode) V8_OVERRIDE = 0;
791 801
792 MUST_USE_RESULT static MaybeObject* CopyElementsImpl(FixedArrayBase* from, 802 MUST_USE_RESULT static MaybeObject* CopyElementsImpl(FixedArrayBase* from,
793 uint32_t from_start, 803 uint32_t from_start,
794 FixedArrayBase* to, 804 FixedArrayBase* to,
795 ElementsKind from_kind, 805 ElementsKind from_kind,
796 uint32_t to_start, 806 uint32_t to_start,
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 : ElementsAccessorBase<FastElementsAccessorSubclass, 981 : ElementsAccessorBase<FastElementsAccessorSubclass,
972 KindTraits>(name) {} 982 KindTraits>(name) {}
973 protected: 983 protected:
974 friend class ElementsAccessorBase<FastElementsAccessorSubclass, KindTraits>; 984 friend class ElementsAccessorBase<FastElementsAccessorSubclass, KindTraits>;
975 friend class SloppyArgumentsElementsAccessor; 985 friend class SloppyArgumentsElementsAccessor;
976 986
977 typedef typename KindTraits::BackingStore BackingStore; 987 typedef typename KindTraits::BackingStore BackingStore;
978 988
979 // Adjusts the length of the fast backing store or returns the new length or 989 // Adjusts the length of the fast backing store or returns the new length or
980 // undefined in case conversion to a slow backing store should be performed. 990 // undefined in case conversion to a slow backing store should be performed.
981 static MaybeObject* SetLengthWithoutNormalize(FixedArrayBase* backing_store, 991 static Handle<Object> SetLengthWithoutNormalize(
982 JSArray* array, 992 Handle<FixedArrayBase> backing_store,
983 Object* length_object, 993 Handle<JSArray> array,
984 uint32_t length) { 994 Handle<Object> length_object,
995 uint32_t length) {
996 Isolate* isolate = array->GetIsolate();
985 uint32_t old_capacity = backing_store->length(); 997 uint32_t old_capacity = backing_store->length();
986 Object* old_length = array->length(); 998 Handle<Object> old_length(array->length(), isolate);
987 bool same_or_smaller_size = old_length->IsSmi() && 999 bool same_or_smaller_size = old_length->IsSmi() &&
988 static_cast<uint32_t>(Smi::cast(old_length)->value()) >= length; 1000 static_cast<uint32_t>(Handle<Smi>::cast(old_length)->value()) >= length;
989 ElementsKind kind = array->GetElementsKind(); 1001 ElementsKind kind = array->GetElementsKind();
990 1002
991 if (!same_or_smaller_size && IsFastElementsKind(kind) && 1003 if (!same_or_smaller_size && IsFastElementsKind(kind) &&
992 !IsFastHoleyElementsKind(kind)) { 1004 !IsFastHoleyElementsKind(kind)) {
993 kind = GetHoleyElementsKind(kind); 1005 kind = GetHoleyElementsKind(kind);
994 MaybeObject* maybe_obj = array->TransitionElementsKind(kind); 1006 JSObject::TransitionElementsKind(array, kind);
995 if (maybe_obj->IsFailure()) return maybe_obj;
996 } 1007 }
997 1008
998 // Check whether the backing store should be shrunk. 1009 // Check whether the backing store should be shrunk.
999 if (length <= old_capacity) { 1010 if (length <= old_capacity) {
1000 if (array->HasFastSmiOrObjectElements()) { 1011 if (array->HasFastSmiOrObjectElements()) {
1001 MaybeObject* maybe_obj = array->EnsureWritableFastElements(); 1012 backing_store = JSObject::EnsureWritableFastElements(array);
1002 if (!maybe_obj->To(&backing_store)) return maybe_obj;
1003 } 1013 }
1004 if (2 * length <= old_capacity) { 1014 if (2 * length <= old_capacity) {
1005 // If more than half the elements won't be used, trim the array. 1015 // If more than half the elements won't be used, trim the array.
1006 if (length == 0) { 1016 if (length == 0) {
1007 array->initialize_elements(); 1017 array->initialize_elements();
1008 } else { 1018 } else {
1009 backing_store->set_length(length); 1019 backing_store->set_length(length);
1010 Address filler_start = backing_store->address() + 1020 Address filler_start = backing_store->address() +
1011 BackingStore::OffsetOfElementAt(length); 1021 BackingStore::OffsetOfElementAt(length);
1012 int filler_size = (old_capacity - length) * ElementSize; 1022 int filler_size = (old_capacity - length) * ElementSize;
1013 array->GetHeap()->CreateFillerObjectAt(filler_start, filler_size); 1023 array->GetHeap()->CreateFillerObjectAt(filler_start, filler_size);
1014 } 1024 }
1015 } else { 1025 } else {
1016 // Otherwise, fill the unused tail with holes. 1026 // Otherwise, fill the unused tail with holes.
1017 int old_length = FastD2IChecked(array->length()->Number()); 1027 int old_length = FastD2IChecked(array->length()->Number());
1018 for (int i = length; i < old_length; i++) { 1028 for (int i = length; i < old_length; i++) {
1019 BackingStore::cast(backing_store)->set_the_hole(i); 1029 Handle<BackingStore>::cast(backing_store)->set_the_hole(i);
1020 } 1030 }
1021 } 1031 }
1022 return length_object; 1032 return length_object;
1023 } 1033 }
1024 1034
1025 // Check whether the backing store should be expanded. 1035 // Check whether the backing store should be expanded.
1026 uint32_t min = JSObject::NewElementsCapacity(old_capacity); 1036 uint32_t min = JSObject::NewElementsCapacity(old_capacity);
1027 uint32_t new_capacity = length > min ? length : min; 1037 uint32_t new_capacity = length > min ? length : min;
1028 if (!array->ShouldConvertToSlowElements(new_capacity)) { 1038 if (!array->ShouldConvertToSlowElements(new_capacity)) {
1029 MaybeObject* result = FastElementsAccessorSubclass:: 1039 FastElementsAccessorSubclass::
1030 SetFastElementsCapacityAndLength(array, new_capacity, length); 1040 SetFastElementsCapacityAndLength(array, new_capacity, length);
1031 if (result->IsFailure()) return result;
1032 array->ValidateElements(); 1041 array->ValidateElements();
1033 return length_object; 1042 return length_object;
1034 } 1043 }
1035 1044
1036 // Request conversion to slow elements. 1045 // Request conversion to slow elements.
1037 return array->GetHeap()->undefined_value(); 1046 return isolate->factory()->undefined_value();
1038 }
1039
1040 // TODO(ishell): Temporary wrapper until handlified.
1041 static Handle<Object> SetLengthWithoutNormalize(
1042 Handle<FixedArrayBase> backing_store,
1043 Handle<JSArray> array,
1044 Handle<Object> length_object,
1045 uint32_t length) {
1046 CALL_HEAP_FUNCTION(array->GetIsolate(),
1047 SetLengthWithoutNormalize(
1048 *backing_store, *array, *length_object, length),
1049 Object);
1050 } 1047 }
1051 1048
1052 static Handle<Object> DeleteCommon(Handle<JSObject> obj, 1049 static Handle<Object> DeleteCommon(Handle<JSObject> obj,
1053 uint32_t key, 1050 uint32_t key,
1054 JSReceiver::DeleteMode mode) { 1051 JSReceiver::DeleteMode mode) {
1055 ASSERT(obj->HasFastSmiOrObjectElements() || 1052 ASSERT(obj->HasFastSmiOrObjectElements() ||
1056 obj->HasFastDoubleElements() || 1053 obj->HasFastDoubleElements() ||
1057 obj->HasFastArgumentsElements()); 1054 obj->HasFastArgumentsElements());
1058 Isolate* isolate = obj->GetIsolate(); 1055 Isolate* isolate = obj->GetIsolate();
1059 Heap* heap = obj->GetHeap(); 1056 Heap* heap = obj->GetHeap();
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1237 uint32_t capacity, 1234 uint32_t capacity,
1238 uint32_t length) { 1235 uint32_t length) {
1239 JSObject::SetFastElementsCapacitySmiMode set_capacity_mode = 1236 JSObject::SetFastElementsCapacitySmiMode set_capacity_mode =
1240 obj->HasFastSmiElements() 1237 obj->HasFastSmiElements()
1241 ? JSObject::kAllowSmiElements 1238 ? JSObject::kAllowSmiElements
1242 : JSObject::kDontAllowSmiElements; 1239 : JSObject::kDontAllowSmiElements;
1243 return obj->SetFastElementsCapacityAndLength(capacity, 1240 return obj->SetFastElementsCapacityAndLength(capacity,
1244 length, 1241 length,
1245 set_capacity_mode); 1242 set_capacity_mode);
1246 } 1243 }
1244
1245 // TODO(ishell): Temporary wrapper until handlified.
1246 static Handle<FixedArray> SetFastElementsCapacityAndLength(
1247 Handle<JSObject> obj,
1248 int capacity,
1249 int length) {
1250 CALL_HEAP_FUNCTION(obj->GetIsolate(),
1251 SetFastElementsCapacityAndLength(*obj, capacity, length),
1252 FixedArray);
1253 }
1247 }; 1254 };
1248 1255
1249 1256
1250 class FastPackedSmiElementsAccessor 1257 class FastPackedSmiElementsAccessor
1251 : public FastSmiOrObjectElementsAccessor< 1258 : public FastSmiOrObjectElementsAccessor<
1252 FastPackedSmiElementsAccessor, 1259 FastPackedSmiElementsAccessor,
1253 ElementsKindTraits<FAST_SMI_ELEMENTS> > { 1260 ElementsKindTraits<FAST_SMI_ELEMENTS> > {
1254 public: 1261 public:
1255 explicit FastPackedSmiElementsAccessor(const char* name) 1262 explicit FastPackedSmiElementsAccessor(const char* name)
1256 : FastSmiOrObjectElementsAccessor< 1263 : FastSmiOrObjectElementsAccessor<
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 KindTraits, 1314 KindTraits,
1308 kDoubleSize>(name) {} 1315 kDoubleSize>(name) {}
1309 1316
1310 static MaybeObject* SetFastElementsCapacityAndLength(JSObject* obj, 1317 static MaybeObject* SetFastElementsCapacityAndLength(JSObject* obj,
1311 uint32_t capacity, 1318 uint32_t capacity,
1312 uint32_t length) { 1319 uint32_t length) {
1313 return obj->SetFastDoubleElementsCapacityAndLength(capacity, 1320 return obj->SetFastDoubleElementsCapacityAndLength(capacity,
1314 length); 1321 length);
1315 } 1322 }
1316 1323
1324 // TODO(ishell): Temporary wrapper until handlified.
1325 static Handle<FixedArray> SetFastElementsCapacityAndLength(
1326 Handle<JSObject> obj,
1327 int capacity,
1328 int length) {
1329 CALL_HEAP_FUNCTION(obj->GetIsolate(),
1330 SetFastElementsCapacityAndLength(*obj, capacity, length),
1331 FixedArray);
1332 }
1333
1317 protected: 1334 protected:
1318 static MaybeObject* CopyElementsImpl(FixedArrayBase* from, 1335 static MaybeObject* CopyElementsImpl(FixedArrayBase* from,
1319 uint32_t from_start, 1336 uint32_t from_start,
1320 FixedArrayBase* to, 1337 FixedArrayBase* to,
1321 ElementsKind from_kind, 1338 ElementsKind from_kind,
1322 uint32_t to_start, 1339 uint32_t to_start,
1323 int packed_size, 1340 int packed_size,
1324 int copy_size) { 1341 int copy_size) {
1325 switch (from_kind) { 1342 switch (from_kind) {
1326 case FAST_SMI_ELEMENTS: 1343 case FAST_SMI_ELEMENTS:
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after
2095 UNREACHABLE(); 2112 UNREACHABLE();
2096 break; 2113 break;
2097 } 2114 }
2098 2115
2099 array->set_elements(*elms); 2116 array->set_elements(*elms);
2100 array->set_length(Smi::FromInt(number_of_elements)); 2117 array->set_length(Smi::FromInt(number_of_elements));
2101 return array; 2118 return array;
2102 } 2119 }
2103 2120
2104 } } // namespace v8::internal 2121 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698