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

Side by Side Diff: src/elements.cc

Issue 1802733002: Move elements normalization to the ElementsAccessor (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 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
« no previous file with comments | « src/elements.h ('k') | src/objects.h » ('j') | 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 // 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/elements.h" 5 #include "src/elements.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/factory.h" 9 #include "src/factory.h"
10 #include "src/messages.h" 10 #include "src/messages.h"
(...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 // intentionally to avoid ArrayConcat() builtin performance degradation. 828 // intentionally to avoid ArrayConcat() builtin performance degradation.
829 // 829 //
830 // Details: The idea is that allocations actually happen only in case of 830 // Details: The idea is that allocations actually happen only in case of
831 // copying from object with fast double elements to object with object 831 // copying from object with fast double elements to object with object
832 // elements. In all the other cases there are no allocations performed and 832 // elements. In all the other cases there are no allocations performed and
833 // handle creation causes noticeable performance degradation of the builtin. 833 // handle creation causes noticeable performance degradation of the builtin.
834 ElementsAccessorSubclass::CopyElementsImpl( 834 ElementsAccessorSubclass::CopyElementsImpl(
835 from, from_start, *to, from_kind, to_start, packed_size, copy_size); 835 from, from_start, *to, from_kind, to_start, packed_size, copy_size);
836 } 836 }
837 837
838 Handle<SeededNumberDictionary> Normalize(Handle<JSObject> object) final {
839 return ElementsAccessorSubclass::NormalizeImpl(object,
840 handle(object->elements()));
841 }
842
843 static Handle<SeededNumberDictionary> NormalizeImpl(
844 Handle<JSObject> object, Handle<FixedArrayBase> elements) {
845 UNREACHABLE();
846 return Handle<SeededNumberDictionary>();
847 }
848
838 void CollectElementIndices(Handle<JSObject> object, 849 void CollectElementIndices(Handle<JSObject> object,
839 Handle<FixedArrayBase> backing_store, 850 Handle<FixedArrayBase> backing_store,
840 KeyAccumulator* keys, uint32_t range, 851 KeyAccumulator* keys, uint32_t range,
841 PropertyFilter filter, uint32_t offset) final { 852 PropertyFilter filter, uint32_t offset) final {
842 if (filter & ONLY_ALL_CAN_READ) return; 853 if (filter & ONLY_ALL_CAN_READ) return;
843 ElementsAccessorSubclass::CollectElementIndicesImpl( 854 ElementsAccessorSubclass::CollectElementIndicesImpl(
844 object, backing_store, keys, range, filter, offset); 855 object, backing_store, keys, range, filter, offset);
845 } 856 }
846 857
847 static void CollectElementIndicesImpl(Handle<JSObject> object, 858 static void CollectElementIndicesImpl(Handle<JSObject> object,
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
1261 typename KindTraits> 1272 typename KindTraits>
1262 class FastElementsAccessor 1273 class FastElementsAccessor
1263 : public ElementsAccessorBase<FastElementsAccessorSubclass, KindTraits> { 1274 : public ElementsAccessorBase<FastElementsAccessorSubclass, KindTraits> {
1264 public: 1275 public:
1265 explicit FastElementsAccessor(const char* name) 1276 explicit FastElementsAccessor(const char* name)
1266 : ElementsAccessorBase<FastElementsAccessorSubclass, 1277 : ElementsAccessorBase<FastElementsAccessorSubclass,
1267 KindTraits>(name) {} 1278 KindTraits>(name) {}
1268 1279
1269 typedef typename KindTraits::BackingStore BackingStore; 1280 typedef typename KindTraits::BackingStore BackingStore;
1270 1281
1282 static Handle<SeededNumberDictionary> NormalizeImpl(
1283 Handle<JSObject> object, Handle<FixedArrayBase> store) {
1284 Isolate* isolate = store->GetIsolate();
1285 ElementsKind kind = FastElementsAccessorSubclass::kind();
1286
1287 // Ensure that notifications fire if the array or object prototypes are
1288 // normalizing.
1289 if (IsFastSmiOrObjectElementsKind(kind)) {
1290 isolate->UpdateArrayProtectorOnNormalizeElements(object);
1291 }
1292
1293 int capacity = object->GetFastElementsUsage();
1294 Handle<SeededNumberDictionary> dictionary =
1295 SeededNumberDictionary::New(isolate, capacity);
1296
1297 PropertyDetails details = PropertyDetails::Empty();
1298 bool used_as_prototype = object->map()->is_prototype_map();
1299 int j = 0;
1300 for (int i = 0; j < capacity; i++) {
1301 if (IsHoleyElementsKind(kind)) {
1302 if (BackingStore::cast(*store)->is_the_hole(i)) continue;
1303 }
1304 Handle<Object> value = FastElementsAccessorSubclass::GetImpl(*store, i);
1305 dictionary = SeededNumberDictionary::AddNumberEntry(
1306 dictionary, i, value, details, used_as_prototype);
1307 j++;
1308 }
1309 return dictionary;
1310 }
1311
1271 static void DeleteAtEnd(Handle<JSObject> obj, 1312 static void DeleteAtEnd(Handle<JSObject> obj,
1272 Handle<BackingStore> backing_store, uint32_t entry) { 1313 Handle<BackingStore> backing_store, uint32_t entry) {
1273 uint32_t length = static_cast<uint32_t>(backing_store->length()); 1314 uint32_t length = static_cast<uint32_t>(backing_store->length());
1274 Heap* heap = obj->GetHeap(); 1315 Heap* heap = obj->GetHeap();
1275 for (; entry > 0; entry--) { 1316 for (; entry > 0; entry--) {
1276 if (!backing_store->is_the_hole(entry - 1)) break; 1317 if (!backing_store->is_the_hole(entry - 1)) break;
1277 } 1318 }
1278 if (entry == 0) { 1319 if (entry == 0) {
1279 FixedArray* empty = heap->empty_fixed_array(); 1320 FixedArray* empty = heap->empty_fixed_array();
1280 if (obj->HasFastArgumentsElements()) { 1321 if (obj->HasFastArgumentsElements()) {
(...skipping 1078 matching lines...) Expand 10 before | Expand all | Expand 10 after
2359 : public SloppyArgumentsElementsAccessor< 2400 : public SloppyArgumentsElementsAccessor<
2360 FastSloppyArgumentsElementsAccessor, FastHoleyObjectElementsAccessor, 2401 FastSloppyArgumentsElementsAccessor, FastHoleyObjectElementsAccessor,
2361 ElementsKindTraits<FAST_SLOPPY_ARGUMENTS_ELEMENTS> > { 2402 ElementsKindTraits<FAST_SLOPPY_ARGUMENTS_ELEMENTS> > {
2362 public: 2403 public:
2363 explicit FastSloppyArgumentsElementsAccessor(const char* name) 2404 explicit FastSloppyArgumentsElementsAccessor(const char* name)
2364 : SloppyArgumentsElementsAccessor< 2405 : SloppyArgumentsElementsAccessor<
2365 FastSloppyArgumentsElementsAccessor, 2406 FastSloppyArgumentsElementsAccessor,
2366 FastHoleyObjectElementsAccessor, 2407 FastHoleyObjectElementsAccessor,
2367 ElementsKindTraits<FAST_SLOPPY_ARGUMENTS_ELEMENTS> >(name) {} 2408 ElementsKindTraits<FAST_SLOPPY_ARGUMENTS_ELEMENTS> >(name) {}
2368 2409
2410 static Handle<SeededNumberDictionary> NormalizeImpl(
2411 Handle<JSObject> object, Handle<FixedArrayBase> elements) {
2412 FixedArray* parameter_map = FixedArray::cast(*elements);
2413 Handle<FixedArray> arguments(FixedArray::cast(parameter_map->get(1)));
2414 return FastHoleyObjectElementsAccessor::NormalizeImpl(object, arguments);
2415 }
2416
2369 static void DeleteFromArguments(Handle<JSObject> obj, uint32_t entry) { 2417 static void DeleteFromArguments(Handle<JSObject> obj, uint32_t entry) {
2370 FixedArray* parameter_map = FixedArray::cast(obj->elements()); 2418 FixedArray* parameter_map = FixedArray::cast(obj->elements());
2371 Handle<FixedArray> arguments(FixedArray::cast(parameter_map->get(1))); 2419 Handle<FixedArray> arguments(FixedArray::cast(parameter_map->get(1)));
2372 FastHoleyObjectElementsAccessor::DeleteCommon(obj, entry, arguments); 2420 FastHoleyObjectElementsAccessor::DeleteCommon(obj, entry, arguments);
2373 } 2421 }
2374 2422
2375 static void AddImpl(Handle<JSObject> object, uint32_t index, 2423 static void AddImpl(Handle<JSObject> object, uint32_t index,
2376 Handle<Object> value, PropertyAttributes attributes, 2424 Handle<Object> value, PropertyAttributes attributes,
2377 uint32_t new_capacity) { 2425 uint32_t new_capacity) {
2378 DCHECK_EQ(NONE, attributes); 2426 DCHECK_EQ(NONE, attributes);
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
2581 2629
2582 class FastStringWrapperElementsAccessor 2630 class FastStringWrapperElementsAccessor
2583 : public StringWrapperElementsAccessor< 2631 : public StringWrapperElementsAccessor<
2584 FastStringWrapperElementsAccessor, FastHoleyObjectElementsAccessor, 2632 FastStringWrapperElementsAccessor, FastHoleyObjectElementsAccessor,
2585 ElementsKindTraits<FAST_STRING_WRAPPER_ELEMENTS>> { 2633 ElementsKindTraits<FAST_STRING_WRAPPER_ELEMENTS>> {
2586 public: 2634 public:
2587 explicit FastStringWrapperElementsAccessor(const char* name) 2635 explicit FastStringWrapperElementsAccessor(const char* name)
2588 : StringWrapperElementsAccessor< 2636 : StringWrapperElementsAccessor<
2589 FastStringWrapperElementsAccessor, FastHoleyObjectElementsAccessor, 2637 FastStringWrapperElementsAccessor, FastHoleyObjectElementsAccessor,
2590 ElementsKindTraits<FAST_STRING_WRAPPER_ELEMENTS>>(name) {} 2638 ElementsKindTraits<FAST_STRING_WRAPPER_ELEMENTS>>(name) {}
2639
2640 static Handle<SeededNumberDictionary> NormalizeImpl(
2641 Handle<JSObject> object, Handle<FixedArrayBase> elements) {
2642 return FastHoleyObjectElementsAccessor::NormalizeImpl(object, elements);
2643 }
2591 }; 2644 };
2592 2645
2593 class SlowStringWrapperElementsAccessor 2646 class SlowStringWrapperElementsAccessor
2594 : public StringWrapperElementsAccessor< 2647 : public StringWrapperElementsAccessor<
2595 SlowStringWrapperElementsAccessor, DictionaryElementsAccessor, 2648 SlowStringWrapperElementsAccessor, DictionaryElementsAccessor,
2596 ElementsKindTraits<SLOW_STRING_WRAPPER_ELEMENTS>> { 2649 ElementsKindTraits<SLOW_STRING_WRAPPER_ELEMENTS>> {
2597 public: 2650 public:
2598 explicit SlowStringWrapperElementsAccessor(const char* name) 2651 explicit SlowStringWrapperElementsAccessor(const char* name)
2599 : StringWrapperElementsAccessor< 2652 : StringWrapperElementsAccessor<
2600 SlowStringWrapperElementsAccessor, DictionaryElementsAccessor, 2653 SlowStringWrapperElementsAccessor, DictionaryElementsAccessor,
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
2814 } 2867 }
2815 } 2868 }
2816 2869
2817 DCHECK(j == result_len); 2870 DCHECK(j == result_len);
2818 return result_array; 2871 return result_array;
2819 } 2872 }
2820 2873
2821 ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL; 2874 ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL;
2822 } // namespace internal 2875 } // namespace internal
2823 } // namespace v8 2876 } // namespace v8
OLDNEW
« no previous file with comments | « src/elements.h ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698