From cb46971aa392e5f6073733e7333ee1efba490179 Mon Sep 17 00:00:00 2001 From: "ishell@chromium.org" Date: Thu, 24 Apr 2014 14:59:09 +0000 Subject: [PATCH] NameDictionary's key type is now Handle instead of Name*. R=yangguo@chromium.org Review URL: https://codereview.chromium.org/252383006 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20947 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/arm/stub-cache-arm.cc | 2 +- src/arm64/stub-cache-arm64.cc | 2 +- src/ia32/stub-cache-ia32.cc | 2 +- src/mips/stub-cache-mips.cc | 2 +- src/objects-inl.h | 16 ++++----- src/objects.cc | 79 ++++++++++++++++++++++++------------------- src/objects.h | 17 ++++++---- src/runtime.cc | 4 +-- src/stub-cache.cc | 2 +- src/x64/stub-cache-x64.cc | 2 +- 10 files changed, 71 insertions(+), 57 deletions(-) diff --git a/src/arm/stub-cache-arm.cc b/src/arm/stub-cache-arm.cc index 250b27d..e7d9368 100644 --- a/src/arm/stub-cache-arm.cc +++ b/src/arm/stub-cache-arm.cc @@ -893,7 +893,7 @@ Register StubCompiler::CheckPrototypes(Handle type, name = factory()->InternalizeString(Handle::cast(name)); } ASSERT(current.is_null() || - current->property_dictionary()->FindEntry(*name) == + current->property_dictionary()->FindEntry(name) == NameDictionary::kNotFound); GenerateDictionaryNegativeLookup(masm(), miss, reg, name, diff --git a/src/arm64/stub-cache-arm64.cc b/src/arm64/stub-cache-arm64.cc index f6efccd..66f7303 100644 --- a/src/arm64/stub-cache-arm64.cc +++ b/src/arm64/stub-cache-arm64.cc @@ -844,7 +844,7 @@ Register StubCompiler::CheckPrototypes(Handle type, name = factory()->InternalizeString(Handle::cast(name)); } ASSERT(current.is_null() || - (current->property_dictionary()->FindEntry(*name) == + (current->property_dictionary()->FindEntry(name) == NameDictionary::kNotFound)); GenerateDictionaryNegativeLookup(masm(), miss, reg, name, diff --git a/src/ia32/stub-cache-ia32.cc b/src/ia32/stub-cache-ia32.cc index 49a40da..45d9b93 100644 --- a/src/ia32/stub-cache-ia32.cc +++ b/src/ia32/stub-cache-ia32.cc @@ -878,7 +878,7 @@ Register StubCompiler::CheckPrototypes(Handle type, name = factory()->InternalizeString(Handle::cast(name)); } ASSERT(current.is_null() || - current->property_dictionary()->FindEntry(*name) == + current->property_dictionary()->FindEntry(name) == NameDictionary::kNotFound); GenerateDictionaryNegativeLookup(masm(), miss, reg, name, diff --git a/src/mips/stub-cache-mips.cc b/src/mips/stub-cache-mips.cc index db926b3..f09eb57 100644 --- a/src/mips/stub-cache-mips.cc +++ b/src/mips/stub-cache-mips.cc @@ -885,7 +885,7 @@ Register StubCompiler::CheckPrototypes(Handle type, name = factory()->InternalizeString(Handle::cast(name)); } ASSERT(current.is_null() || - current->property_dictionary()->FindEntry(*name) == + current->property_dictionary()->FindEntry(name) == NameDictionary::kNotFound); GenerateDictionaryNegativeLookup(masm(), miss, reg, name, diff --git a/src/objects-inl.h b/src/objects-inl.h index bc20132..741621e 100644 --- a/src/objects-inl.h +++ b/src/objects-inl.h @@ -6648,7 +6648,7 @@ Handle NumberDictionaryShape::AsHandle(Isolate* isolate, uint32_t key) { } -bool NameDictionaryShape::IsMatch(Name* key, Object* other) { +bool NameDictionaryShape::IsMatch(Handle key, Object* other) { // We know that all entries in a hash table had their hash keys created. // Use that knowledge to have fast failure. if (key->Hash() != Name::cast(other)->Hash()) return false; @@ -6656,26 +6656,26 @@ bool NameDictionaryShape::IsMatch(Name* key, Object* other) { } -uint32_t NameDictionaryShape::Hash(Name* key) { +uint32_t NameDictionaryShape::Hash(Handle key) { return key->Hash(); } -uint32_t NameDictionaryShape::HashForObject(Name* key, Object* other) { +uint32_t NameDictionaryShape::HashForObject(Handle key, Object* other) { return Name::cast(other)->Hash(); } -MaybeObject* NameDictionaryShape::AsObject(Heap* heap, Name* key) { +MaybeObject* NameDictionaryShape::AsObject(Heap* heap, Handle key) { ASSERT(key->IsUniqueName()); - return key; + return *key; } -Handle NameDictionaryShape::AsHandle(Isolate* isolate, Name* key) { +Handle NameDictionaryShape::AsHandle(Isolate* isolate, + Handle key) { ASSERT(key->IsUniqueName()); - // TODO(ishell): Convert Name* to Handle to avoid re-wrapping here. - return handle(key, isolate); + return key; } diff --git a/src/objects.cc b/src/objects.cc index a1c8a90..6cd0484 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -660,7 +660,7 @@ void JSObject::SetNormalizedProperty(Handle object, Handle::cast(name)); } - int entry = property_dictionary->FindEntry(*name); + int entry = property_dictionary->FindEntry(name); if (entry == NameDictionary::kNotFound) { Handle store_value = value; if (object->IsGlobalObject()) { @@ -705,7 +705,7 @@ Handle JSObject::DeleteNormalizedProperty(Handle object, ASSERT(!object->HasFastProperties()); Isolate* isolate = object->GetIsolate(); Handle dictionary(object->property_dictionary()); - int entry = dictionary->FindEntry(*name); + int entry = dictionary->FindEntry(name); if (entry != NameDictionary::kNotFound) { // If we have a global object set the cell to the hole. if (object->IsGlobalObject()) { @@ -728,7 +728,7 @@ Handle JSObject::DeleteNormalizedProperty(Handle object, Handle deleted(dictionary->DeleteProperty(entry, mode), isolate); if (*deleted == isolate->heap()->true_value()) { Handle new_properties = - NameDictionary::Shrink(dictionary, *name); + NameDictionary::Shrink(dictionary, name); object->set_properties(*new_properties); } return deleted; @@ -1924,7 +1924,7 @@ void JSObject::AddSlowProperty(Handle object, Handle dict(object->property_dictionary()); if (object->IsGlobalObject()) { // In case name is an orphaned property reuse the cell. - int entry = dict->FindEntry(*name); + int entry = dict->FindEntry(name); if (entry != NameDictionary::kNotFound) { Handle cell(PropertyCell::cast(dict->ValueAt(entry))); PropertyCell::SetValueInferType(cell, value); @@ -2054,7 +2054,7 @@ static void ReplaceSlowProperty(Handle object, Handle value, PropertyAttributes attributes) { NameDictionary* dictionary = object->property_dictionary(); - int old_index = dictionary->FindEntry(*name); + int old_index = dictionary->FindEntry(name); int new_enumeration_index = 0; // 0 means "Use the next available index." if (old_index != -1) { // All calls to ReplaceSlowProperty have had all transitions removed. @@ -14627,8 +14627,17 @@ Handle HashTable::New( } -// Find entry for key otherwise return kNotFound. +// TODO(ishell): Remove this when all the callers are handlified. int NameDictionary::FindEntry(Name* key) { + DisallowHeapAllocation no_allocation; + Isolate* isolate = key->GetIsolate(); + HandleScope scope(isolate); + return FindEntry(handle(key, isolate)); +} + + +// Find entry for key otherwise return kNotFound. +int NameDictionary::FindEntry(Handle key) { if (!key->IsUniqueName()) { return DerivedHashTable::FindEntry(key); } @@ -14651,16 +14660,16 @@ int NameDictionary::FindEntry(Name* key) { int index = EntryToIndex(entry); Object* element = get(index); if (element->IsUndefined()) break; // Empty entry. - if (key == element) return entry; + if (*key == element) return entry; if (!element->IsUniqueName() && !element->IsTheHole() && - Name::cast(element)->Equals(key)) { + Name::cast(element)->Equals(*key)) { // Replace a key that is a non-internalized string by the equivalent // internalized string for faster further lookups. - set(index, key); + set(index, *key); return entry; } - ASSERT(element->IsTheHole() || !Name::cast(element)->Equals(key)); + ASSERT(element->IsTheHole() || !Name::cast(element)->Equals(*key)); entry = NextProbe(entry, count++, capacity); } return kNotFound; @@ -14877,7 +14886,7 @@ template class HashTable; template class HashTable, Object*>; -template class Dictionary; +template class Dictionary >; template class Dictionary:: Allocate(Heap* heap, int at_least_space_for, PretenureFlag pretenure); -template MaybeObject* Dictionary:: +template MaybeObject* +Dictionary >:: Allocate(Heap* heap, int n, PretenureFlag pretenure); template Handle -Dictionary:: +Dictionary >:: New(Isolate* isolate, int n, PretenureFlag pretenure); template Handle @@ -14919,8 +14929,8 @@ Dictionary:: SlowReverseLookup(Object* value); template Object* -Dictionary::SlowReverseLookup( - Object*); +Dictionary >:: + SlowReverseLookup(Object* value); template void Dictionary:: @@ -14932,12 +14942,12 @@ Dictionary:: uint32_t>::SortMode); template Object* -Dictionary::DeleteProperty( +Dictionary >::DeleteProperty( int, JSObject::DeleteMode); template Handle -Dictionary::DeleteProperty( - Handle >, +Dictionary >::DeleteProperty( + Handle > >, int, JSObject::DeleteMode); @@ -14955,34 +14965,35 @@ Dictionary:: JSObject::DeleteMode); template Handle -HashTable:: +HashTable >:: New(Isolate*, int, MinimumCapacity, PretenureFlag); template Handle -HashTable:: - Shrink(Handle, Name* n); +HashTable >:: + Shrink(Handle, Handle); template Handle HashTable:: Shrink(Handle, uint32_t); -template void Dictionary:: +template void Dictionary >:: CopyKeysTo( FixedArray*, int, PropertyAttributes, - Dictionary::SortMode); + Dictionary< + NameDictionary, NameDictionaryShape, Handle >::SortMode); template int -Dictionary:: +Dictionary >:: NumberOfElementsFilterAttributes(PropertyAttributes); template MaybeObject* -Dictionary::Add( - Name*, Object*, PropertyDetails); +Dictionary >::Add( + Handle, Object*, PropertyDetails); template MaybeObject* -Dictionary:: +Dictionary >:: GenerateNewEnumerationIndices(); template int @@ -15006,8 +15017,8 @@ Dictionary:: EnsureCapacity(int, uint32_t); template MaybeObject* -Dictionary:: - EnsureCapacity(int, Name*); +Dictionary >:: + EnsureCapacity(int, Handle); template MaybeObject* Dictionary:: @@ -15018,15 +15029,15 @@ Dictionary:: AddEntry(uint32_t, Object*, PropertyDetails, uint32_t); template MaybeObject* -Dictionary::AddEntry( - Name*, Object*, PropertyDetails, uint32_t); +Dictionary >::AddEntry( + Handle, Object*, PropertyDetails, uint32_t); template int Dictionary:: NumberOfEnumElements(); template -int Dictionary:: +int Dictionary >:: NumberOfEnumElements(); template @@ -15039,7 +15050,7 @@ Handle NameDictionary::AddNameEntry(Handle dict, Handle value, PropertyDetails details) { CALL_HEAP_FUNCTION(dict->GetIsolate(), - dict->Add(*name, *value, details), + dict->Add(name, *value, details), NameDictionary); } @@ -15477,7 +15488,7 @@ Handle JSGlobalObject::EnsurePropertyCell( Handle global, Handle name) { ASSERT(!global->HasFastProperties()); - int entry = global->property_dictionary()->FindEntry(*name); + int entry = global->property_dictionary()->FindEntry(name); if (entry == NameDictionary::kNotFound) { Isolate* isolate = global->GetIsolate(); Handle cell = isolate->factory()->NewPropertyCell( diff --git a/src/objects.h b/src/objects.h index 37eb139..5f695db 100644 --- a/src/objects.h +++ b/src/objects.h @@ -4119,14 +4119,14 @@ class Dictionary: public HashTable { }; -class NameDictionaryShape : public BaseShape { +class NameDictionaryShape : public BaseShape > { public: - static inline bool IsMatch(Name* key, Object* other); - static inline uint32_t Hash(Name* key); - static inline uint32_t HashForObject(Name* key, Object* object); + static inline bool IsMatch(Handle key, Object* other); + static inline uint32_t Hash(Handle key); + static inline uint32_t HashForObject(Handle key, Object* object); MUST_USE_RESULT static inline MaybeObject* AsObject(Heap* heap, - Name* key); - static inline Handle AsHandle(Isolate* isolate, Name* key); + Handle key); + static inline Handle AsHandle(Isolate* isolate, Handle key); static const int kPrefixSize = 2; static const int kEntrySize = 3; static const bool kIsEnumerable = true; @@ -4135,7 +4135,7 @@ class NameDictionaryShape : public BaseShape { class NameDictionary: public Dictionary { + Handle > { public: static inline NameDictionary* cast(Object* obj) { ASSERT(obj->IsDictionary()); @@ -4149,6 +4149,9 @@ class NameDictionary: public Dictionary key); + + // TODO(ishell): Remove this when all the callers are handlified. int FindEntry(Name* key); // TODO(mstarzinger): Temporary wrapper until handlified. diff --git a/src/runtime.cc b/src/runtime.cc index 42535be..c908780 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -3074,7 +3074,7 @@ RUNTIME_FUNCTION(Runtime_FunctionSetReadOnlyPrototype) { } else { // Dictionary properties. // Directly manipulate the property details. DisallowHeapAllocation no_gc; - int entry = function->property_dictionary()->FindEntry(*name); + int entry = function->property_dictionary()->FindEntry(name); ASSERT(entry != NameDictionary::kNotFound); PropertyDetails details = function->property_dictionary()->DetailsAt(entry); PropertyDetails new_details( @@ -15138,7 +15138,7 @@ void Runtime::InitializeIntrinsicFunctionNames(Isolate* isolate, const Runtime::Function* Runtime::FunctionForName(Handle name) { Heap* heap = name->GetHeap(); - int entry = heap->intrinsic_function_names()->FindEntry(*name); + int entry = heap->intrinsic_function_names()->FindEntry(name); if (entry != kNotFound) { Object* smi_index = heap->intrinsic_function_names()->ValueAt(entry); int function_index = Smi::cast(smi_index)->value(); diff --git a/src/stub-cache.cc b/src/stub-cache.cc index 87cdf42..28a4977 100644 --- a/src/stub-cache.cc +++ b/src/stub-cache.cc @@ -891,7 +891,7 @@ void LoadStubCompiler::NonexistentHandlerFrontend(Handle type, name = factory()->InternalizeString(Handle::cast(name)); } ASSERT(last.is_null() || - last->property_dictionary()->FindEntry(*name) == + last->property_dictionary()->FindEntry(name) == NameDictionary::kNotFound); GenerateDictionaryNegativeLookup(masm(), &miss, holder, name, scratch2(), scratch3()); diff --git a/src/x64/stub-cache-x64.cc b/src/x64/stub-cache-x64.cc index 3fe64ac..cf62f6e 100644 --- a/src/x64/stub-cache-x64.cc +++ b/src/x64/stub-cache-x64.cc @@ -796,7 +796,7 @@ Register StubCompiler::CheckPrototypes(Handle type, name = factory()->InternalizeString(Handle::cast(name)); } ASSERT(current.is_null() || - current->property_dictionary()->FindEntry(*name) == + current->property_dictionary()->FindEntry(name) == NameDictionary::kNotFound); GenerateDictionaryNegativeLookup(masm(), miss, reg, name, -- 2.7.4