From ca7feba733a57d41a61680cc69ab277b93131168 Mon Sep 17 00:00:00 2001 From: verwaest Date: Tue, 7 Jul 2015 04:52:51 -0700 Subject: [PATCH] Index -> Entry and Key -> Index in elements.[cc|h] BUG=v8:4137 LOG=n Review URL: https://codereview.chromium.org/1224643004 Cr-Commit-Position: refs/heads/master@{#29514} --- src/elements.cc | 398 +++++++++++++++++++++++------------------------ src/elements.h | 65 ++++---- src/lookup-inl.h | 3 +- 3 files changed, 230 insertions(+), 236 deletions(-) diff --git a/src/elements.cc b/src/elements.cc index 6395e8fa79..750b1174bf 100644 --- a/src/elements.cc +++ b/src/elements.cc @@ -123,13 +123,13 @@ ELEMENTS_LIST(ELEMENTS_TRAITS) #undef ELEMENTS_TRAITS -static bool HasKey(Handle array, Handle key_handle) { +static bool HasIndex(Handle array, Handle index_handle) { DisallowHeapAllocation no_gc; - Object* key = *key_handle; + Object* index = *index_handle; int len0 = array->length(); for (int i = 0; i < len0; i++) { Object* element = array->get(i); - if (key->KeyEquals(element)) return true; + if (index->KeyEquals(element)) return true; } return false; } @@ -542,69 +542,71 @@ class ElementsAccessorBase : public ElementsAccessor { ElementsAccessorSubclass::ValidateImpl(holder); } - virtual bool HasElement(Handle holder, uint32_t key, + virtual bool HasElement(Handle holder, uint32_t index, Handle backing_store) final { - return ElementsAccessorSubclass::GetIndexForKeyImpl(*holder, *backing_store, - key) != kMaxUInt32; + return ElementsAccessorSubclass::GetEntryForIndexImpl( + *holder, *backing_store, index) != kMaxUInt32; } - virtual Handle Get(Handle holder, uint32_t key, + virtual Handle Get(Handle holder, uint32_t index, Handle backing_store) final { if (!IsExternalArrayElementsKind(ElementsTraits::Kind) && FLAG_trace_js_array_abuse) { - CheckArrayAbuse(holder, "elements read", key); + CheckArrayAbuse(holder, "elements read", index); } if (IsExternalArrayElementsKind(ElementsTraits::Kind) && FLAG_trace_external_array_abuse) { - CheckArrayAbuse(holder, "external elements read", key); + CheckArrayAbuse(holder, "external elements read", index); } - return ElementsAccessorSubclass::GetImpl(holder, key, backing_store); + return ElementsAccessorSubclass::GetImpl(holder, index, backing_store); } - static Handle GetImpl(Handle obj, uint32_t key, + static Handle GetImpl(Handle obj, uint32_t index, Handle backing_store) { - if (key < ElementsAccessorSubclass::GetCapacityImpl(*obj, *backing_store)) { - return BackingStore::get(Handle::cast(backing_store), key); + if (index < + ElementsAccessorSubclass::GetCapacityImpl(*obj, *backing_store)) { + return BackingStore::get(Handle::cast(backing_store), + index); } else { return backing_store->GetIsolate()->factory()->the_hole_value(); } } - virtual void Set(FixedArrayBase* backing_store, uint32_t key, + virtual void Set(FixedArrayBase* backing_store, uint32_t index, Object* value) final { - ElementsAccessorSubclass::SetImpl(backing_store, key, value); + ElementsAccessorSubclass::SetImpl(backing_store, index, value); } - static void SetImpl(FixedArrayBase* backing_store, uint32_t key, + static void SetImpl(FixedArrayBase* backing_store, uint32_t index, Object* value) { - BackingStore::cast(backing_store)->SetValue(key, value); + BackingStore::cast(backing_store)->SetValue(index, value); } virtual void Reconfigure(Handle object, - Handle store, uint32_t index, + Handle store, uint32_t entry, Handle value, PropertyAttributes attributes) final { - ElementsAccessorSubclass::ReconfigureImpl(object, store, index, value, + ElementsAccessorSubclass::ReconfigureImpl(object, store, entry, value, attributes); } static void ReconfigureImpl(Handle object, - Handle store, uint32_t index, + Handle store, uint32_t entry, Handle value, PropertyAttributes attributes) { UNREACHABLE(); } - virtual void Add(Handle object, uint32_t index, + virtual void Add(Handle object, uint32_t entry, Handle value, PropertyAttributes attributes, uint32_t new_capacity) final { - ElementsAccessorSubclass::AddImpl(object, index, value, attributes, + ElementsAccessorSubclass::AddImpl(object, entry, value, attributes, new_capacity); } - static void AddImpl(Handle object, uint32_t index, + static void AddImpl(Handle object, uint32_t entry, Handle value, PropertyAttributes attributes, uint32_t new_capacity) { UNREACHABLE(); @@ -678,8 +680,8 @@ class ElementsAccessorBase : public ElementsAccessor { ElementsAccessorSubclass::GrowCapacityAndConvertImpl(object, capacity); } - virtual void Delete(Handle obj, uint32_t index) final { - ElementsAccessorSubclass::DeleteImpl(obj, index); + virtual void Delete(Handle obj, uint32_t entry) final { + ElementsAccessorSubclass::DeleteImpl(obj, entry); } static void CopyElementsImpl(FixedArrayBase* from, uint32_t from_start, @@ -755,10 +757,11 @@ class ElementsAccessorBase : public ElementsAccessor { // Compute how many elements are not in other. uint32_t extra = 0; for (uint32_t y = 0; y < len1; y++) { - if (ElementsAccessorSubclass::HasIndexImpl(*from, y)) { - uint32_t key = ElementsAccessorSubclass::GetKeyForIndexImpl(*from, y); + if (ElementsAccessorSubclass::HasEntryImpl(*from, y)) { + uint32_t index = + ElementsAccessorSubclass::GetIndexForEntryImpl(*from, y); Handle value = - ElementsAccessorSubclass::GetImpl(receiver, key, from); + ElementsAccessorSubclass::GetImpl(receiver, index, from); DCHECK(!value->IsTheHole()); DCHECK(!value->IsAccessorPair()); @@ -766,7 +769,7 @@ class ElementsAccessorBase : public ElementsAccessor { if (filter == FixedArray::NON_SYMBOL_KEYS && value->IsSymbol()) { continue; } - if (!HasKey(to, value)) { + if (!HasIndex(to, value)) { extra++; } } @@ -788,24 +791,25 @@ class ElementsAccessorBase : public ElementsAccessor { } } // Fill in the extra values. - uint32_t index = 0; + uint32_t entry = 0; for (uint32_t y = 0; y < len1; y++) { - if (ElementsAccessorSubclass::HasIndexImpl(*from, y)) { - uint32_t key = ElementsAccessorSubclass::GetKeyForIndexImpl(*from, y); + if (ElementsAccessorSubclass::HasEntryImpl(*from, y)) { + uint32_t index = + ElementsAccessorSubclass::GetIndexForEntryImpl(*from, y); Handle value = - ElementsAccessorSubclass::GetImpl(receiver, key, from); + ElementsAccessorSubclass::GetImpl(receiver, index, from); DCHECK(!value->IsAccessorPair()); DCHECK(!value->IsExecutableAccessorInfo()); if (filter == FixedArray::NON_SYMBOL_KEYS && value->IsSymbol()) { continue; } - if (!value->IsTheHole() && !HasKey(to, value)) { - result->set(len0 + index, *value); - index++; + if (!value->IsTheHole() && !HasIndex(to, value)) { + result->set(len0 + entry, *value); + entry++; } } } - DCHECK(extra == index); + DCHECK(extra == entry); return result; } @@ -818,49 +822,40 @@ class ElementsAccessorBase : public ElementsAccessor { return ElementsAccessorSubclass::GetCapacityImpl(holder, backing_store); } - static bool HasIndexImpl(FixedArrayBase* backing_store, uint32_t index) { + static bool HasEntryImpl(FixedArrayBase* backing_store, uint32_t entry) { return true; } - virtual bool HasIndex(FixedArrayBase* backing_store, uint32_t index) final { - return ElementsAccessorSubclass::HasIndexImpl(backing_store, index); + static uint32_t GetIndexForEntryImpl(FixedArrayBase* backing_store, + uint32_t entry) { + return entry; } - static uint32_t GetKeyForIndexImpl(FixedArrayBase* backing_store, - uint32_t index) { - return index; - } - - virtual uint32_t GetKeyForIndex(FixedArrayBase* backing_store, - uint32_t index) final { - return ElementsAccessorSubclass::GetKeyForIndexImpl(backing_store, index); - } - - static uint32_t GetIndexForKeyImpl(JSObject* holder, - FixedArrayBase* backing_store, - uint32_t key) { - return key < ElementsAccessorSubclass::GetCapacityImpl(holder, - backing_store) && - !BackingStore::cast(backing_store)->is_the_hole(key) - ? key + static uint32_t GetEntryForIndexImpl(JSObject* holder, + FixedArrayBase* backing_store, + uint32_t index) { + return index < ElementsAccessorSubclass::GetCapacityImpl(holder, + backing_store) && + !BackingStore::cast(backing_store)->is_the_hole(index) + ? index : kMaxUInt32; } - virtual uint32_t GetIndexForKey(JSObject* holder, - FixedArrayBase* backing_store, - uint32_t key) final { - return ElementsAccessorSubclass::GetIndexForKeyImpl(holder, backing_store, - key); + virtual uint32_t GetEntryForIndex(JSObject* holder, + FixedArrayBase* backing_store, + uint32_t index) final { + return ElementsAccessorSubclass::GetEntryForIndexImpl(holder, backing_store, + index); } static PropertyDetails GetDetailsImpl(FixedArrayBase* backing_store, - uint32_t index) { + uint32_t entry) { return PropertyDetails(NONE, DATA, 0, PropertyCellType::kNoCell); } virtual PropertyDetails GetDetails(FixedArrayBase* backing_store, - uint32_t index) final { - return ElementsAccessorSubclass::GetDetailsImpl(backing_store, index); + uint32_t entry) final { + return ElementsAccessorSubclass::GetDetailsImpl(backing_store, entry); } private: @@ -888,13 +883,13 @@ class DictionaryElementsAccessor if (dict->requires_slow_elements()) { // Find last non-deletable element in range of elements to be // deleted and adjust range accordingly. - for (int i = 0; i < capacity; i++) { + for (int entry = 0; entry < capacity; entry++) { DisallowHeapAllocation no_gc; - Object* key = dict->KeyAt(i); - if (key->IsNumber()) { - uint32_t number = static_cast(key->Number()); + Object* index = dict->KeyAt(entry); + if (index->IsNumber()) { + uint32_t number = static_cast(index->Number()); if (length <= number && number < old_length) { - PropertyDetails details = dict->DetailsAt(i); + PropertyDetails details = dict->DetailsAt(entry); if (!details.IsConfigurable()) length = number + 1; } } @@ -909,12 +904,12 @@ class DictionaryElementsAccessor // Remove elements that should be deleted. int removed_entries = 0; Handle the_hole_value = isolate->factory()->the_hole_value(); - for (int i = 0; i < capacity; i++) { - Object* key = dict->KeyAt(i); - if (key->IsNumber()) { - uint32_t number = static_cast(key->Number()); + for (int entry = 0; entry < capacity; entry++) { + Object* index = dict->KeyAt(entry); + if (index->IsNumber()) { + uint32_t number = static_cast(index->Number()); if (length <= number && number < old_length) { - dict->SetEntry(i, the_hole_value, the_hole_value); + dict->SetEntry(entry, the_hole_value, the_hole_value); removed_entries++; } } @@ -937,51 +932,52 @@ class DictionaryElementsAccessor } - static void DeleteImpl(Handle obj, uint32_t index) { - // TODO(verwaest): Remove reliance on key in Shrink. + static void DeleteImpl(Handle obj, uint32_t entry) { + // TODO(verwaest): Remove reliance on index in Shrink. Handle dict( SeededNumberDictionary::cast(obj->elements())); - uint32_t key = GetKeyForIndexImpl(*dict, index); - Handle result = SeededNumberDictionary::DeleteProperty(dict, index); + uint32_t index = GetIndexForEntryImpl(*dict, entry); + Handle result = SeededNumberDictionary::DeleteProperty(dict, entry); USE(result); DCHECK(result->IsTrue()); - Handle new_elements = SeededNumberDictionary::Shrink(dict, key); + Handle new_elements = + SeededNumberDictionary::Shrink(dict, index); obj->set_elements(*new_elements); } - static Handle GetImpl(Handle obj, uint32_t key, + static Handle GetImpl(Handle obj, uint32_t index, Handle store) { Handle backing_store = Handle::cast(store); Isolate* isolate = backing_store->GetIsolate(); - int entry = backing_store->FindEntry(key); + int entry = backing_store->FindEntry(index); if (entry != SeededNumberDictionary::kNotFound) { return handle(backing_store->ValueAt(entry), isolate); } return isolate->factory()->the_hole_value(); } - static void SetImpl(FixedArrayBase* store, uint32_t key, Object* value) { + static void SetImpl(FixedArrayBase* store, uint32_t index, Object* value) { SeededNumberDictionary* dictionary = SeededNumberDictionary::cast(store); - int entry = dictionary->FindEntry(key); + int entry = dictionary->FindEntry(index); DCHECK_NE(SeededNumberDictionary::kNotFound, entry); dictionary->ValueAtPut(entry, value); } static void ReconfigureImpl(Handle object, - Handle store, uint32_t index, + Handle store, uint32_t entry, Handle value, PropertyAttributes attributes) { SeededNumberDictionary* dictionary = SeededNumberDictionary::cast(*store); if (attributes != NONE) dictionary->set_requires_slow_elements(); - dictionary->ValueAtPut(index, *value); - PropertyDetails details = dictionary->DetailsAt(index); + dictionary->ValueAtPut(entry, *value); + PropertyDetails details = dictionary->DetailsAt(entry); details = PropertyDetails(attributes, DATA, details.dictionary_index(), PropertyCellType::kNoCell); - dictionary->DetailsAtPut(index, details); + dictionary->DetailsAtPut(entry, details); } - static void AddImpl(Handle object, uint32_t index, + static void AddImpl(Handle object, uint32_t entry, Handle value, PropertyAttributes attributes, uint32_t new_capacity) { PropertyDetails details(attributes, DATA, 0, PropertyCellType::kNoCell); @@ -990,41 +986,41 @@ class DictionaryElementsAccessor ? JSObject::NormalizeElements(object) : handle(SeededNumberDictionary::cast(object->elements())); Handle new_dictionary = - SeededNumberDictionary::AddNumberEntry(dictionary, index, value, + SeededNumberDictionary::AddNumberEntry(dictionary, entry, value, details); if (attributes != NONE) new_dictionary->set_requires_slow_elements(); if (dictionary.is_identical_to(new_dictionary)) return; object->set_elements(*new_dictionary); } - static bool HasIndexImpl(FixedArrayBase* store, uint32_t index) { + static bool HasEntryImpl(FixedArrayBase* store, uint32_t entry) { DisallowHeapAllocation no_gc; SeededNumberDictionary* dict = SeededNumberDictionary::cast(store); - Object* key = dict->KeyAt(index); - return !key->IsTheHole(); + Object* index = dict->KeyAt(entry); + return !index->IsTheHole(); } - static uint32_t GetKeyForIndexImpl(FixedArrayBase* store, uint32_t index) { + static uint32_t GetIndexForEntryImpl(FixedArrayBase* store, uint32_t entry) { DisallowHeapAllocation no_gc; SeededNumberDictionary* dict = SeededNumberDictionary::cast(store); uint32_t result = 0; - CHECK(dict->KeyAt(index)->ToArrayIndex(&result)); + CHECK(dict->KeyAt(entry)->ToArrayIndex(&result)); return result; } - static uint32_t GetIndexForKeyImpl(JSObject* holder, FixedArrayBase* store, - uint32_t key) { + static uint32_t GetEntryForIndexImpl(JSObject* holder, FixedArrayBase* store, + uint32_t index) { DisallowHeapAllocation no_gc; SeededNumberDictionary* dict = SeededNumberDictionary::cast(store); - int entry = dict->FindEntry(key); + int entry = dict->FindEntry(index); return entry == SeededNumberDictionary::kNotFound ? kMaxUInt32 : static_cast(entry); } static PropertyDetails GetDetailsImpl(FixedArrayBase* backing_store, - uint32_t index) { - return SeededNumberDictionary::cast(backing_store)->DetailsAt(index); + uint32_t entry) { + return SeededNumberDictionary::cast(backing_store)->DetailsAt(entry); } }; @@ -1041,13 +1037,13 @@ class FastElementsAccessor typedef typename KindTraits::BackingStore BackingStore; - static void DeleteCommon(Handle obj, uint32_t index, + static void DeleteCommon(Handle obj, uint32_t entry, Handle store) { DCHECK(obj->HasFastSmiOrObjectElements() || obj->HasFastDoubleElements() || obj->HasFastArgumentsElements()); Handle backing_store = Handle::cast(store); - backing_store->set_the_hole(index); + backing_store->set_the_hole(entry); // TODO(verwaest): Move this out of elements.cc. // If an old space backing store is larger than a certain size and @@ -1063,8 +1059,8 @@ class FastElementsAccessor } else { length = static_cast(store->length()); } - if ((index > 0 && backing_store->is_the_hole(index - 1)) || - (index + 1 < length && backing_store->is_the_hole(index + 1))) { + if ((entry > 0 && backing_store->is_the_hole(entry - 1)) || + (entry + 1 < length && backing_store->is_the_hole(entry + 1))) { int num_used = 0; for (int i = 0; i < backing_store->length(); ++i) { if (!backing_store->is_the_hole(i)) ++num_used; @@ -1078,17 +1074,17 @@ class FastElementsAccessor } static void ReconfigureImpl(Handle object, - Handle store, uint32_t index, + Handle store, uint32_t entry, Handle value, PropertyAttributes attributes) { Handle dictionary = JSObject::NormalizeElements(object); - index = dictionary->FindEntry(index); - DictionaryElementsAccessor::ReconfigureImpl(object, dictionary, index, + entry = dictionary->FindEntry(entry); + DictionaryElementsAccessor::ReconfigureImpl(object, dictionary, entry, value, attributes); } - static void AddImpl(Handle object, uint32_t index, + static void AddImpl(Handle object, uint32_t entry, Handle value, PropertyAttributes attributes, uint32_t new_capacity) { DCHECK_EQ(NONE, attributes); @@ -1110,10 +1106,10 @@ class FastElementsAccessor JSObject::EnsureWritableFastElements(object); } } - FastElementsAccessorSubclass::SetImpl(object->elements(), index, *value); + FastElementsAccessorSubclass::SetImpl(object->elements(), entry, *value); } - static void DeleteImpl(Handle obj, uint32_t index) { + static void DeleteImpl(Handle obj, uint32_t entry) { ElementsKind kind = KindTraits::Kind; if (IsFastPackedElementsKind(kind)) { JSObject::TransitionElementsKind(obj, GetHoleyElementsKind(kind)); @@ -1121,11 +1117,11 @@ class FastElementsAccessor if (IsFastSmiOrObjectElementsKind(KindTraits::Kind)) { JSObject::EnsureWritableFastElements(obj); } - DeleteCommon(obj, index, handle(obj->elements())); + DeleteCommon(obj, entry, handle(obj->elements())); } - static bool HasIndexImpl(FixedArrayBase* backing_store, uint32_t index) { - return !BackingStore::cast(backing_store)->is_the_hole(index); + static bool HasEntryImpl(FixedArrayBase* backing_store, uint32_t entry) { + return !BackingStore::cast(backing_store)->is_the_hole(entry); } static void ValidateContents(Handle holder, int length) { @@ -1342,17 +1338,18 @@ class TypedElementsAccessor typedef typename ElementsKindTraits::BackingStore BackingStore; typedef TypedElementsAccessor AccessorClass; - static Handle GetImpl(Handle obj, uint32_t key, + static Handle GetImpl(Handle obj, uint32_t index, Handle backing_store) { - if (key < AccessorClass::GetCapacityImpl(*obj, *backing_store)) { - return BackingStore::get(Handle::cast(backing_store), key); + if (index < AccessorClass::GetCapacityImpl(*obj, *backing_store)) { + return BackingStore::get(Handle::cast(backing_store), + index); } else { return backing_store->GetIsolate()->factory()->undefined_value(); } } static PropertyDetails GetDetailsImpl(FixedArrayBase* backing_store, - uint32_t index) { + uint32_t entry) { return PropertyDetails(DONT_DELETE, DATA, 0, PropertyCellType::kNoCell); } @@ -1362,15 +1359,15 @@ class TypedElementsAccessor UNREACHABLE(); } - static void DeleteImpl(Handle obj, uint32_t index) { + static void DeleteImpl(Handle obj, uint32_t entry) { UNREACHABLE(); } - static uint32_t GetIndexForKeyImpl(JSObject* holder, - FixedArrayBase* backing_store, - uint32_t key) { - return key < AccessorClass::GetCapacityImpl(holder, backing_store) - ? key + static uint32_t GetEntryForIndexImpl(JSObject* holder, + FixedArrayBase* backing_store, + uint32_t index) { + return index < AccessorClass::GetCapacityImpl(holder, backing_store) + ? index : kMaxUInt32; } @@ -1409,30 +1406,30 @@ class SloppyArgumentsElementsAccessor : ElementsAccessorBase(name) {} - static Handle GetImpl(Handle obj, uint32_t key, + static Handle GetImpl(Handle obj, uint32_t index, Handle parameters) { Isolate* isolate = obj->GetIsolate(); Handle parameter_map = Handle::cast(parameters); - Handle probe(GetParameterMapArg(*parameter_map, key), isolate); + Handle probe(GetParameterMapArg(*parameter_map, index), isolate); if (!probe->IsTheHole()) { DisallowHeapAllocation no_gc; Context* context = Context::cast(parameter_map->get(0)); - int context_index = Handle::cast(probe)->value(); - DCHECK(!context->get(context_index)->IsTheHole()); - return handle(context->get(context_index), isolate); + int context_entry = Handle::cast(probe)->value(); + DCHECK(!context->get(context_entry)->IsTheHole()); + return handle(context->get(context_entry), isolate); } else { // Object is not mapped, defer to the arguments. Handle arguments(FixedArray::cast(parameter_map->get(1)), isolate); - Handle result = ArgumentsAccessor::GetImpl(obj, key, arguments); + Handle result = ArgumentsAccessor::GetImpl(obj, index, arguments); // Elements of the arguments object in slow mode might be slow aliases. if (result->IsAliasedArgumentsEntry()) { DisallowHeapAllocation no_gc; AliasedArgumentsEntry* entry = AliasedArgumentsEntry::cast(*result); Context* context = Context::cast(parameter_map->get(0)); - int context_index = entry->aliased_context_slot(); - DCHECK(!context->get(context_index)->IsTheHole()); - return handle(context->get(context_index), isolate); + int context_entry = entry->aliased_context_slot(); + DCHECK(!context->get(context_entry)->IsTheHole()); + return handle(context->get(context_entry), isolate); } else { return result; } @@ -1444,17 +1441,17 @@ class SloppyArgumentsElementsAccessor UNREACHABLE(); } - static void SetImpl(FixedArrayBase* store, uint32_t key, Object* value) { + static void SetImpl(FixedArrayBase* store, uint32_t index, Object* value) { FixedArray* parameter_map = FixedArray::cast(store); - Object* probe = GetParameterMapArg(parameter_map, key); + Object* probe = GetParameterMapArg(parameter_map, index); if (!probe->IsTheHole()) { Context* context = Context::cast(parameter_map->get(0)); - int context_index = Smi::cast(probe)->value(); - DCHECK(!context->get(context_index)->IsTheHole()); - context->set(context_index, value); + int context_entry = Smi::cast(probe)->value(); + DCHECK(!context->get(context_entry)->IsTheHole()); + context->set(context_entry, value); } else { FixedArray* arguments = FixedArray::cast(parameter_map->get(1)); - ArgumentsAccessor::SetImpl(arguments, key, value); + ArgumentsAccessor::SetImpl(arguments, index, value); } } @@ -1472,70 +1469,71 @@ class SloppyArgumentsElementsAccessor ArgumentsAccessor::GetCapacityImpl(holder, arguments); } - static bool HasIndexImpl(FixedArrayBase* parameters, uint32_t index) { + static bool HasEntryImpl(FixedArrayBase* parameters, uint32_t entry) { FixedArray* parameter_map = FixedArray::cast(parameters); uint32_t length = parameter_map->length() - 2; - if (index < length) { - return !GetParameterMapArg(parameter_map, index)->IsTheHole(); + if (entry < length) { + return !GetParameterMapArg(parameter_map, entry)->IsTheHole(); } FixedArrayBase* arguments = FixedArrayBase::cast(parameter_map->get(1)); - return ArgumentsAccessor::HasIndexImpl(arguments, index - length); + return ArgumentsAccessor::HasEntryImpl(arguments, entry - length); } - static uint32_t GetKeyForIndexImpl(FixedArrayBase* parameters, - uint32_t index) { + static uint32_t GetIndexForEntryImpl(FixedArrayBase* parameters, + uint32_t entry) { FixedArray* parameter_map = FixedArray::cast(parameters); uint32_t length = parameter_map->length() - 2; - if (index < length) return index; + if (entry < length) return entry; FixedArray* arguments = FixedArray::cast(parameter_map->get(1)); - return ArgumentsAccessor::GetKeyForIndexImpl(arguments, index - length); + return ArgumentsAccessor::GetIndexForEntryImpl(arguments, entry - length); } - static uint32_t GetIndexForKeyImpl(JSObject* holder, - FixedArrayBase* parameters, uint32_t key) { + static uint32_t GetEntryForIndexImpl(JSObject* holder, + FixedArrayBase* parameters, + uint32_t index) { FixedArray* parameter_map = FixedArray::cast(parameters); - Object* probe = GetParameterMapArg(parameter_map, key); - if (!probe->IsTheHole()) return key; + Object* probe = GetParameterMapArg(parameter_map, index); + if (!probe->IsTheHole()) return index; FixedArray* arguments = FixedArray::cast(parameter_map->get(1)); - uint32_t index = - ArgumentsAccessor::GetIndexForKeyImpl(holder, arguments, key); - if (index == kMaxUInt32) return index; - return (parameter_map->length() - 2) + index; + uint32_t entry = + ArgumentsAccessor::GetEntryForIndexImpl(holder, arguments, index); + if (entry == kMaxUInt32) return entry; + return (parameter_map->length() - 2) + entry; } static PropertyDetails GetDetailsImpl(FixedArrayBase* parameters, - uint32_t index) { + uint32_t entry) { FixedArray* parameter_map = FixedArray::cast(parameters); uint32_t length = parameter_map->length() - 2; - if (index < length) { + if (entry < length) { return PropertyDetails(NONE, DATA, 0, PropertyCellType::kNoCell); } - index -= length; + entry -= length; FixedArray* arguments = FixedArray::cast(parameter_map->get(1)); - return ArgumentsAccessor::GetDetailsImpl(arguments, index); + return ArgumentsAccessor::GetDetailsImpl(arguments, entry); } - static Object* GetParameterMapArg(FixedArray* parameter_map, uint32_t key) { + static Object* GetParameterMapArg(FixedArray* parameter_map, uint32_t index) { uint32_t length = parameter_map->length() - 2; - return key < length - ? parameter_map->get(key + 2) + return index < length + ? parameter_map->get(index + 2) : Object::cast(parameter_map->GetHeap()->the_hole_value()); } - static void DeleteImpl(Handle obj, uint32_t index) { + static void DeleteImpl(Handle obj, uint32_t entry) { FixedArray* parameter_map = FixedArray::cast(obj->elements()); uint32_t length = static_cast(parameter_map->length()) - 2; - if (index < length) { + if (entry < length) { // TODO(kmillikin): We could check if this was the last aliased // parameter, and revert to normal elements in that case. That // would enable GC of the context. - parameter_map->set_the_hole(index + 2); + parameter_map->set_the_hole(entry + 2); } else { SloppyArgumentsElementsAccessorSubclass::DeleteFromArguments( - obj, index - length); + obj, entry - length); } } }; @@ -1551,20 +1549,21 @@ class SlowSloppyArgumentsElementsAccessor SlowSloppyArgumentsElementsAccessor, DictionaryElementsAccessor, ElementsKindTraits >(name) {} - static void DeleteFromArguments(Handle obj, uint32_t index) { + static void DeleteFromArguments(Handle obj, uint32_t entry) { Handle parameter_map(FixedArray::cast(obj->elements())); Handle dict( SeededNumberDictionary::cast(parameter_map->get(1))); - // TODO(verwaest): Remove reliance on key in Shrink. - uint32_t key = GetKeyForIndexImpl(*dict, index); - Handle result = SeededNumberDictionary::DeleteProperty(dict, index); + // TODO(verwaest): Remove reliance on index in Shrink. + uint32_t index = GetIndexForEntryImpl(*dict, entry); + Handle result = SeededNumberDictionary::DeleteProperty(dict, entry); USE(result); DCHECK(result->IsTrue()); - Handle new_elements = SeededNumberDictionary::Shrink(dict, key); + Handle new_elements = + SeededNumberDictionary::Shrink(dict, index); parameter_map->set(1, *new_elements); } - static void AddImpl(Handle object, uint32_t key, + static void AddImpl(Handle object, uint32_t index, Handle value, PropertyAttributes attributes, uint32_t new_capacity) { Handle parameter_map(FixedArray::cast(object->elements())); @@ -1576,7 +1575,8 @@ class SlowSloppyArgumentsElementsAccessor : JSObject::NormalizeElements(object); PropertyDetails details(attributes, DATA, 0, PropertyCellType::kNoCell); Handle new_dictionary = - SeededNumberDictionary::AddNumberEntry(dictionary, key, value, details); + SeededNumberDictionary::AddNumberEntry(dictionary, index, value, + details); if (attributes != NONE) new_dictionary->set_requires_slow_elements(); if (*dictionary != *new_dictionary) { FixedArray::cast(object->elements())->set(1, *new_dictionary); @@ -1584,38 +1584,38 @@ class SlowSloppyArgumentsElementsAccessor } static void ReconfigureImpl(Handle object, - Handle store, uint32_t index, + Handle store, uint32_t entry, Handle value, PropertyAttributes attributes) { Handle parameter_map = Handle::cast(store); uint32_t length = parameter_map->length() - 2; - if (index < length) { - Object* probe = parameter_map->get(index + 2); + if (entry < length) { + Object* probe = parameter_map->get(entry + 2); DCHECK(!probe->IsTheHole()); Context* context = Context::cast(parameter_map->get(0)); - int context_index = Smi::cast(probe)->value(); - DCHECK(!context->get(context_index)->IsTheHole()); - context->set(context_index, *value); + int context_entry = Smi::cast(probe)->value(); + DCHECK(!context->get(context_entry)->IsTheHole()); + context->set(context_entry, *value); // Redefining attributes of an aliased element destroys fast aliasing. - parameter_map->set_the_hole(index + 2); + parameter_map->set_the_hole(entry + 2); // For elements that are still writable we re-establish slow aliasing. if ((attributes & READ_ONLY) == 0) { Isolate* isolate = store->GetIsolate(); - value = isolate->factory()->NewAliasedArgumentsEntry(context_index); + value = isolate->factory()->NewAliasedArgumentsEntry(context_entry); } PropertyDetails details(attributes, DATA, 0, PropertyCellType::kNoCell); Handle arguments( SeededNumberDictionary::cast(parameter_map->get(1))); - arguments = SeededNumberDictionary::AddNumberEntry(arguments, index, + arguments = SeededNumberDictionary::AddNumberEntry(arguments, entry, value, details); parameter_map->set(1, *arguments); } else { Handle arguments( FixedArrayBase::cast(parameter_map->get(1))); DictionaryElementsAccessor::ReconfigureImpl( - object, arguments, index - length, value, attributes); + object, arguments, entry - length, value, attributes); } } }; @@ -1632,13 +1632,13 @@ class FastSloppyArgumentsElementsAccessor FastHoleyObjectElementsAccessor, ElementsKindTraits >(name) {} - static void DeleteFromArguments(Handle obj, uint32_t index) { + static void DeleteFromArguments(Handle obj, uint32_t entry) { FixedArray* parameter_map = FixedArray::cast(obj->elements()); Handle arguments(FixedArray::cast(parameter_map->get(1))); - FastHoleyObjectElementsAccessor::DeleteCommon(obj, index, arguments); + FastHoleyObjectElementsAccessor::DeleteCommon(obj, entry, arguments); } - static void AddImpl(Handle object, uint32_t key, + static void AddImpl(Handle object, uint32_t index, Handle value, PropertyAttributes attributes, uint32_t new_capacity) { DCHECK_EQ(NONE, attributes); @@ -1649,21 +1649,21 @@ class FastSloppyArgumentsElementsAccessor static_cast(old_elements->length()) < new_capacity) { GrowCapacityAndConvertImpl(object, new_capacity); } - SetImpl(object->elements(), key, *value); + SetImpl(object->elements(), index, *value); } static void ReconfigureImpl(Handle object, - Handle store, uint32_t index, + Handle store, uint32_t entry, Handle value, PropertyAttributes attributes) { Handle dictionary = JSObject::NormalizeElements(object); FixedArray::cast(*store)->set(1, *dictionary); uint32_t length = static_cast(store->length()) - 2; - if (index >= length) { - index = dictionary->FindEntry(index - length) + length; + if (entry >= length) { + entry = dictionary->FindEntry(entry - length) + length; } - SlowSloppyArgumentsElementsAccessor::ReconfigureImpl(object, store, index, + SlowSloppyArgumentsElementsAccessor::ReconfigureImpl(object, store, entry, value, attributes); } @@ -1749,7 +1749,7 @@ void ElementsAccessorBase:: } // namespace -void CheckArrayAbuse(Handle obj, const char* op, uint32_t key, +void CheckArrayAbuse(Handle obj, const char* op, uint32_t index, bool allow_appending) { DisallowHeapAllocation no_allocation; Object* raw_length = NULL; @@ -1768,10 +1768,10 @@ void CheckArrayAbuse(Handle obj, const char* op, uint32_t key, int32_t int32_length = DoubleToInt32(n); uint32_t compare_length = static_cast(int32_length); if (allow_appending) compare_length++; - if (key >= compare_length) { + if (index >= compare_length) { PrintF("[OOB %s %s (%s length = %d, element accessed = %d) in ", elements_type, op, elements_type, static_cast(int32_length), - static_cast(key)); + static_cast(index)); TraceTopFrame(obj->GetIsolate()); PrintF("]\n"); } @@ -1844,8 +1844,8 @@ MaybeHandle ArrayConstructInitializeElements(Handle array, case FAST_HOLEY_SMI_ELEMENTS: case FAST_SMI_ELEMENTS: { Handle smi_elms = Handle::cast(elms); - for (int index = 0; index < number_of_elements; index++) { - smi_elms->set(index, (*args)[index], SKIP_WRITE_BARRIER); + for (int entry = 0; entry < number_of_elements; entry++) { + smi_elms->set(entry, (*args)[entry], SKIP_WRITE_BARRIER); } break; } @@ -1854,8 +1854,8 @@ MaybeHandle ArrayConstructInitializeElements(Handle array, DisallowHeapAllocation no_gc; WriteBarrierMode mode = elms->GetWriteBarrierMode(no_gc); Handle object_elms = Handle::cast(elms); - for (int index = 0; index < number_of_elements; index++) { - object_elms->set(index, (*args)[index], mode); + for (int entry = 0; entry < number_of_elements; entry++) { + object_elms->set(entry, (*args)[entry], mode); } break; } @@ -1863,8 +1863,8 @@ MaybeHandle ArrayConstructInitializeElements(Handle array, case FAST_DOUBLE_ELEMENTS: { Handle double_elms = Handle::cast(elms); - for (int index = 0; index < number_of_elements; index++) { - double_elms->set(index, (*args)[index]->Number()); + for (int entry = 0; entry < number_of_elements; entry++) { + double_elms->set(entry, (*args)[entry]->Number()); } break; } diff --git a/src/elements.h b/src/elements.h index 6fe1955999..9005096a1e 100644 --- a/src/elements.h +++ b/src/elements.h @@ -26,32 +26,28 @@ class ElementsAccessor { // is found. virtual void Validate(Handle obj) = 0; - // Returns true if a holder contains an element with the specified key + // Returns true if a holder contains an element with the specified index // without iterating up the prototype chain. The caller can optionally pass // in the backing store to use for the check, which must be compatible with // the ElementsKind of the ElementsAccessor. If backing_store is NULL, the // holder->elements() is used as the backing store. - virtual bool HasElement( - Handle holder, - uint32_t key, - Handle backing_store) = 0; + virtual bool HasElement(Handle holder, uint32_t index, + Handle backing_store) = 0; - inline bool HasElement( - Handle holder, - uint32_t key) { - return HasElement(holder, key, handle(holder->elements())); + inline bool HasElement(Handle holder, uint32_t index) { + return HasElement(holder, index, handle(holder->elements())); } - // Returns the element with the specified key or undefined if there is no such - // element. This method doesn't iterate up the prototype chain. The caller - // can optionally pass in the backing store to use for the check, which must - // be compatible with the ElementsKind of the ElementsAccessor. If + // Returns the element with the specified index or undefined if there is no + // such element. This method doesn't iterate up the prototype chain. The + // caller can optionally pass in the backing store to use for the check, which + // must be compatible with the ElementsKind of the ElementsAccessor. If // backing_store is NULL, the holder->elements() is used as the backing store. - virtual Handle Get(Handle holder, uint32_t key, + virtual Handle Get(Handle holder, uint32_t index, Handle backing_store) = 0; - inline Handle Get(Handle holder, uint32_t key) { - return Get(holder, key, handle(holder->elements())); + inline Handle Get(Handle holder, uint32_t index) { + return Get(holder, index, handle(holder->elements())); } // Modifies the length data property as specified for JSArrays and resizes the @@ -62,7 +58,7 @@ class ElementsAccessor { virtual void SetLength(Handle holder, uint32_t new_length) = 0; // Deletes an element in an object. - virtual void Delete(Handle holder, uint32_t index) = 0; + virtual void Delete(Handle holder, uint32_t entry) = 0; // If kCopyToEnd is specified as the copy_size to CopyElements, it copies all // of elements from source after source_start to the destination array. @@ -123,13 +119,13 @@ class ElementsAccessor { static void InitializeOncePerProcess(); static void TearDown(); - virtual void Set(FixedArrayBase* backing_store, uint32_t key, + virtual void Set(FixedArrayBase* backing_store, uint32_t index, Object* value) = 0; virtual void Reconfigure(Handle object, - Handle backing_store, uint32_t index, + Handle backing_store, uint32_t entry, Handle value, PropertyAttributes attributes) = 0; - virtual void Add(Handle object, uint32_t index, + virtual void Add(Handle object, uint32_t entry, Handle value, PropertyAttributes attributes, uint32_t new_capacity) = 0; @@ -141,22 +137,19 @@ class ElementsAccessor { virtual uint32_t GetCapacity(JSObject* holder, FixedArrayBase* backing_store) = 0; - // Element handlers distinguish between indexes and keys when they manipulate - // elements. Indexes refer to elements in terms of their location in the - // underlying storage's backing store representation, and are between 0 and - // GetCapacity. Keys refer to elements in terms of the value that would be - // specified in JavaScript to access the element. In most implementations, - // keys are equivalent to indexes, and GetKeyForIndex returns the same value - // it is passed. In the NumberDictionary ElementsAccessor, GetKeyForIndex maps - // the index to a key using the KeyAt method on the NumberDictionary. - virtual uint32_t GetKeyForIndex(FixedArrayBase* backing_store, - uint32_t index) = 0; - virtual uint32_t GetIndexForKey(JSObject* holder, - FixedArrayBase* backing_store, - uint32_t key) = 0; + // Element handlers distinguish between entries and indices when they + // manipulate elements. Entries refer to elements in terms of their location + // in the underlying storage's backing store representation, and are between 0 + // and GetCapacity. Indices refer to elements in terms of the value that would + // be specified in JavaScript to access the element. In most implementations, + // indices are equivalent to entries. In the NumberDictionary + // ElementsAccessor, entries are mapped to an index using the KeyAt method on + // the NumberDictionary. + virtual uint32_t GetEntryForIndex(JSObject* holder, + FixedArrayBase* backing_store, + uint32_t index) = 0; virtual PropertyDetails GetDetails(FixedArrayBase* backing_store, - uint32_t index) = 0; - virtual bool HasIndex(FixedArrayBase* backing_store, uint32_t key) = 0; + uint32_t entry) = 0; private: static ElementsAccessor** elements_accessors_; @@ -165,7 +158,7 @@ class ElementsAccessor { DISALLOW_COPY_AND_ASSIGN(ElementsAccessor); }; -void CheckArrayAbuse(Handle obj, const char* op, uint32_t key, +void CheckArrayAbuse(Handle obj, const char* op, uint32_t index, bool allow_appending = false); MUST_USE_RESULT MaybeHandle ArrayConstructInitializeElements( diff --git a/src/lookup-inl.h b/src/lookup-inl.h index 421cc08d91..3df2194d3f 100644 --- a/src/lookup-inl.h +++ b/src/lookup-inl.h @@ -74,7 +74,8 @@ LookupIterator::State LookupIterator::LookupInHolder(Map* const map, ElementsAccessor* accessor = js_object->GetElementsAccessor(); FixedArrayBase* backing_store = js_object->elements(); - number_ = accessor->GetIndexForKey(js_object, backing_store, index_); + number_ = + accessor->GetEntryForIndex(js_object, backing_store, index_); if (number_ == kMaxUInt32) return NOT_FOUND; property_details_ = accessor->GetDetails(backing_store, number_); }