From 3ce912038edf1b7cb04931ce4fbd6c82167ae568 Mon Sep 17 00:00:00 2001 From: "ishell@chromium.org" Date: Fri, 25 Apr 2014 13:35:03 +0000 Subject: [PATCH] ObjectHashTable's key and WeakHashTable's key types are now Handle instead of Object*. R=yangguo@chromium.org Review URL: https://codereview.chromium.org/257853003 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20982 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/mark-compact.cc | 2 +- src/objects-inl.h | 29 ++++++++++++++++---------- src/objects.cc | 46 +++++++++++++++++++++++++++++++++++------- src/objects.h | 44 +++++++++++++++++++++++----------------- test/cctest/test-dictionary.cc | 4 ++-- 5 files changed, 86 insertions(+), 39 deletions(-) diff --git a/src/mark-compact.cc b/src/mark-compact.cc index 414c70f..744f5bc 100644 --- a/src/mark-compact.cc +++ b/src/mark-compact.cc @@ -3670,7 +3670,7 @@ void MarkCompactCollector::EvacuateNewSpaceAndCandidates() { WeakHashTable* table = WeakHashTable::cast(heap_->weak_object_to_code_table()); table->Iterate(&updating_visitor); - table->Rehash(heap_->undefined_value()); + table->Rehash(heap_->isolate()->factory()->undefined_value()); } // Update pointers from external string table. diff --git a/src/objects-inl.h b/src/objects-inl.h index 6537251..54dbd5e 100644 --- a/src/objects-inl.h +++ b/src/objects-inl.h @@ -6683,47 +6683,54 @@ void NameDictionary::DoGenerateNewEnumerationIndices( } -bool ObjectHashTableShape::IsMatch(Object* key, Object* other) { +bool ObjectHashTableShape::IsMatch(Handle key, Object* other) { return key->SameValue(other); } -uint32_t ObjectHashTableShape::Hash(Object* key) { +uint32_t ObjectHashTableShape::Hash(Handle key) { return Smi::cast(key->GetHash())->value(); } -uint32_t ObjectHashTableShape::HashForObject(Object* key, Object* other) { +uint32_t ObjectHashTableShape::HashForObject(Handle key, + Object* other) { return Smi::cast(other->GetHash())->value(); } -MaybeObject* ObjectHashTableShape::AsObject(Heap* heap, Object* key) { +MaybeObject* ObjectHashTableShape::AsObject(Heap* heap, Handle key) { + return *key; +} + + +Handle ObjectHashTableShape::AsHandle(Isolate* isolate, + Handle key) { return key; } Handle ObjectHashTable::Shrink( Handle table, Handle key) { - return DerivedHashTable::Shrink(table, *key); + return DerivedHashTable::Shrink(table, key); } template -bool WeakHashTableShape::IsMatch(Object* key, Object* other) { +bool WeakHashTableShape::IsMatch(Handle key, Object* other) { return key->SameValue(other); } template -uint32_t WeakHashTableShape::Hash(Object* key) { - intptr_t hash = reinterpret_cast(key); +uint32_t WeakHashTableShape::Hash(Handle key) { + intptr_t hash = reinterpret_cast(*key); return (uint32_t)(hash & 0xFFFFFFFF); } template -uint32_t WeakHashTableShape::HashForObject(Object* key, +uint32_t WeakHashTableShape::HashForObject(Handle key, Object* other) { intptr_t hash = reinterpret_cast(other); return (uint32_t)(hash & 0xFFFFFFFF); @@ -6731,8 +6738,8 @@ uint32_t WeakHashTableShape::HashForObject(Object* key, template -MaybeObject* WeakHashTableShape::AsObject(Heap* heap, - Object* key) { +Handle WeakHashTableShape::AsHandle(Isolate* isolate, + Handle key) { return key; } diff --git a/src/objects.cc b/src/objects.cc index 6f7315e..3a19b57 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -14855,9 +14855,11 @@ template class HashTable; -template class HashTable; +template class HashTable >; -template class HashTable, Object*>; +template class HashTable, Handle >; template class Dictionary >; @@ -16137,6 +16139,21 @@ Object* ObjectHashTable::Lookup(Object* key) { } +// TODO(ishell): Try to remove this when FindEntry(Object* key) is removed +int ObjectHashTable::FindEntry(Handle key) { + return DerivedHashTable::FindEntry(key); +} + + +// TODO(ishell): Remove this when all the callers are handlified. +int ObjectHashTable::FindEntry(Object* key) { + DisallowHeapAllocation no_allocation; + Isolate* isolate = GetIsolate(); + HandleScope scope(isolate); + return FindEntry(handle(key, isolate)); +} + + Handle ObjectHashTable::Put(Handle table, Handle key, Handle value) { @@ -16147,7 +16164,7 @@ Handle ObjectHashTable::Put(Handle table, // Make sure the key object has an identity hash code. Handle hash = Object::GetOrCreateHash(key, isolate); - int entry = table->FindEntry(*key); + int entry = table->FindEntry(key); // Check whether to perform removal operation. if (value->IsTheHole()) { @@ -16163,7 +16180,7 @@ Handle ObjectHashTable::Put(Handle table, } // Check whether the hash table should be extended. - table = EnsureCapacity(table, 1, *key); + table = EnsureCapacity(table, 1, key); table->AddEntry(table->FindInsertionEntry(Handle::cast(hash)->value()), *key, *value); @@ -16193,11 +16210,26 @@ Object* WeakHashTable::Lookup(Object* key) { } +// TODO(ishell): Try to remove this when FindEntry(Object* key) is removed +int WeakHashTable::FindEntry(Handle key) { + return DerivedHashTable::FindEntry(key); +} + + +// TODO(ishell): Remove this when all the callers are handlified. +int WeakHashTable::FindEntry(Object* key) { + DisallowHeapAllocation no_allocation; + Isolate* isolate = GetIsolate(); + HandleScope scope(isolate); + return FindEntry(handle(key, isolate)); +} + + Handle WeakHashTable::Put(Handle table, Handle key, Handle value) { ASSERT(table->IsKey(*key)); - int entry = table->FindEntry(*key); + int entry = table->FindEntry(key); // Key is already in table, just overwrite value. if (entry != kNotFound) { table->set(EntryToValueIndex(entry), *value); @@ -16205,9 +16237,9 @@ Handle WeakHashTable::Put(Handle table, } // Check whether the hash table should be extended. - table = EnsureCapacity(table, 1, *key, TENURED); + table = EnsureCapacity(table, 1, key, TENURED); - table->AddEntry(table->FindInsertionEntry(table->Hash(*key)), key, value); + table->AddEntry(table->FindInsertionEntry(table->Hash(key)), key, value); return table; } diff --git a/src/objects.h b/src/objects.h index 067cf45..8bcf8b9 100644 --- a/src/objects.h +++ b/src/objects.h @@ -3667,8 +3667,7 @@ class HashTable: public FixedArray { // Wrapper methods inline uint32_t Hash(Key key) { if (Shape::UsesSeed) { - return Shape::SeededHash(key, - GetHeap()->HashSeed()); + return Shape::SeededHash(key, GetHeap()->HashSeed()); } else { return Shape::Hash(key); } @@ -3676,8 +3675,7 @@ class HashTable: public FixedArray { inline uint32_t HashForObject(Key key, Object* object) { if (Shape::UsesSeed) { - return Shape::SeededHashForObject(key, - GetHeap()->HashSeed(), object); + return Shape::SeededHashForObject(key, GetHeap()->HashSeed(), object); } else { return Shape::HashForObject(key, object); } @@ -4237,13 +4235,14 @@ class UnseededNumberDictionary }; -class ObjectHashTableShape : public BaseShape { +class ObjectHashTableShape : public BaseShape > { public: - static inline bool IsMatch(Object* key, Object* other); - static inline uint32_t Hash(Object* key); - static inline uint32_t HashForObject(Object* 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, - Object* key); + Handle key); + static inline Handle AsHandle(Isolate* isolate, Handle key); static const int kPrefixSize = 0; static const int kEntrySize = 2; }; @@ -4253,9 +4252,9 @@ class ObjectHashTableShape : public BaseShape { // using the identity hash of the key for hashing purposes. class ObjectHashTable: public HashTable { + Handle > { typedef HashTable< - ObjectHashTable, ObjectHashTableShape, Object*> DerivedHashTable; + ObjectHashTable, ObjectHashTableShape, Handle > DerivedHashTable; public: static inline ObjectHashTable* cast(Object* obj) { ASSERT(obj->IsHashTable()); @@ -4271,6 +4270,10 @@ class ObjectHashTable: public HashTable key); + // TODO(ishell): Remove this when all the callers are handlified. + int FindEntry(Object* key); + // Adds (or overwrites) the value associated with the given key. Mapping a // key to the hole value causes removal of the whole entry. static Handle Put(Handle table, @@ -4469,13 +4472,12 @@ class OrderedHashMap:public OrderedHashTable< template -class WeakHashTableShape : public BaseShape { +class WeakHashTableShape : public BaseShape > { public: - static inline bool IsMatch(Object* key, Object* other); - static inline uint32_t Hash(Object* key); - static inline uint32_t HashForObject(Object* key, Object* object); - MUST_USE_RESULT static inline MaybeObject* AsObject(Heap* heap, - Object* key); + static inline bool IsMatch(Handle key, Object* other); + static inline uint32_t Hash(Handle key); + static inline uint32_t HashForObject(Handle key, Object* object); + static inline Handle AsHandle(Isolate* isolate, Handle key); static const int kPrefixSize = 0; static const int kEntrySize = entrysize; }; @@ -4486,7 +4488,9 @@ class WeakHashTableShape : public BaseShape { // embedded in optimized code to dependent code lists. class WeakHashTable: public HashTable, - Object*> { + Handle > { + typedef HashTable< + WeakHashTable, WeakHashTableShape<2>, Handle > DerivedHashTable; public: static inline WeakHashTable* cast(Object* obj) { ASSERT(obj->IsHashTable()); @@ -4497,6 +4501,10 @@ class WeakHashTable: public HashTable key); + // TODO(ishell): Remove this when all the callers are handlified. + int FindEntry(Object* key); + // Adds (or overwrites) the value associated with the given key. Mapping a // key to the hole value causes removal of the whole entry. MUST_USE_RESULT static Handle Put(Handle table, diff --git a/test/cctest/test-dictionary.cc b/test/cctest/test-dictionary.cc index 8e218b5..a40f282 100644 --- a/test/cctest/test-dictionary.cc +++ b/test/cctest/test-dictionary.cc @@ -140,7 +140,7 @@ TEST(HashTableRehash) { for (int i = 0; i < capacity - 1; i++) { t->insert(i, i * i, i); } - t->Rehash(Smi::FromInt(0)); + t->Rehash(handle(Smi::FromInt(0), isolate)); for (int i = 0; i < capacity - 1; i++) { CHECK_EQ(i, t->lookup(i * i)); } @@ -153,7 +153,7 @@ TEST(HashTableRehash) { for (int i = 0; i < capacity / 2; i++) { t->insert(i, i * i, i); } - t->Rehash(Smi::FromInt(0)); + t->Rehash(handle(Smi::FromInt(0), isolate)); for (int i = 0; i < capacity / 2; i++) { CHECK_EQ(i, t->lookup(i * i)); } -- 2.7.4