diff --git a/src/builtins/builtins-collections-gen.cc b/src/builtins/builtins-collections-gen.cc index 73701a6343..a3fb802238 100644 --- a/src/builtins/builtins-collections-gen.cc +++ b/src/builtins/builtins-collections-gen.cc @@ -1967,7 +1967,7 @@ class WeakCollectionsBuiltinsAssembler : public BaseCollectionsAssembler { TNode CreateIdentityHash(TNode receiver); TNode EntryMask(TNode capacity); - // Builds code that finds the ObjectHashTable entry for a {key} using the + // Builds code that finds the EphemeronHashTable entry for a {key} using the // comparison code generated by {key_compare}. The key index is returned if // the {key} is found. typedef std::function entry_key, Label* if_same)> @@ -1976,12 +1976,13 @@ class WeakCollectionsBuiltinsAssembler : public BaseCollectionsAssembler { TNode entry_mask, const KeyComparator& key_compare); - // Builds code that finds an ObjectHashTable entry available for a new entry. + // Builds code that finds an EphemeronHashTable entry available for a new + // entry. TNode FindKeyIndexForInsertion(TNode table, TNode key_hash, TNode entry_mask); - // Builds code that finds the ObjectHashTable entry with key that matches + // Builds code that finds the EphemeronHashTable entry with key that matches // {key} and returns the entry's key index. If {key} cannot be found, jumps to // {if_not_found}. TNode FindKeyIndexForKey(TNode table, TNode key, @@ -2011,13 +2012,13 @@ class WeakCollectionsBuiltinsAssembler : public BaseCollectionsAssembler { void WeakCollectionsBuiltinsAssembler::AddEntry( TNode table, TNode key_index, TNode key, TNode value, TNode number_of_elements) { - // See ObjectHashTable::AddEntry(). + // See EphemeronHashTable::AddEntry(). TNode value_index = ValueIndexFromKeyIndex(key_index); StoreFixedArrayElement(table, key_index, key); StoreFixedArrayElement(table, value_index, value); // See HashTableBase::ElementAdded(). - StoreFixedArrayElement(table, ObjectHashTable::kNumberOfElementsIndex, + StoreFixedArrayElement(table, EphemeronHashTable::kNumberOfElementsIndex, SmiFromIntPtr(number_of_elements), SKIP_WRITE_BARRIER); } @@ -2034,14 +2035,15 @@ TNode WeakCollectionsBuiltinsAssembler::AllocateTable( TNode table = AllocateFixedArray(HOLEY_ELEMENTS, length, kAllowLargeObjectAllocation); - Heap::RootListIndex map_root_index = - static_cast(ObjectHashTableShape::GetMapRootIndex()); + Heap::RootListIndex map_root_index = static_cast( + EphemeronHashTableShape::GetMapRootIndex()); StoreMapNoWriteBarrier(table, map_root_index); - StoreFixedArrayElement(table, ObjectHashTable::kNumberOfElementsIndex, + StoreFixedArrayElement(table, EphemeronHashTable::kNumberOfElementsIndex, SmiConstant(0), SKIP_WRITE_BARRIER); - StoreFixedArrayElement(table, ObjectHashTable::kNumberOfDeletedElementsIndex, + StoreFixedArrayElement(table, + EphemeronHashTable::kNumberOfDeletedElementsIndex, SmiConstant(0), SKIP_WRITE_BARRIER); - StoreFixedArrayElement(table, ObjectHashTable::kCapacityIndex, + StoreFixedArrayElement(table, EphemeronHashTable::kCapacityIndex, SmiFromIntPtr(capacity), SKIP_WRITE_BARRIER); TNode start = KeyIndexFromEntry(IntPtrConstant(0)); @@ -2126,22 +2128,22 @@ TNode WeakCollectionsBuiltinsAssembler::KeyIndexFromEntry( // See HashTable::KeyAt(). // (entry * kEntrySize) + kElementsStartIndex + kEntryKeyIndex return IntPtrAdd( - IntPtrMul(entry, IntPtrConstant(ObjectHashTable::kEntrySize)), - IntPtrConstant(ObjectHashTable::kElementsStartIndex + - ObjectHashTable::kEntryKeyIndex)); + IntPtrMul(entry, IntPtrConstant(EphemeronHashTable::kEntrySize)), + IntPtrConstant(EphemeronHashTable::kElementsStartIndex + + EphemeronHashTable::kEntryKeyIndex)); } TNode WeakCollectionsBuiltinsAssembler::LoadNumberOfElements( TNode table, int offset) { - TNode number_of_elements = SmiUntag(CAST( - LoadFixedArrayElement(table, ObjectHashTable::kNumberOfElementsIndex))); + TNode number_of_elements = SmiUntag(CAST(LoadFixedArrayElement( + table, EphemeronHashTable::kNumberOfElementsIndex))); return IntPtrAdd(number_of_elements, IntPtrConstant(offset)); } TNode WeakCollectionsBuiltinsAssembler::LoadNumberOfDeleted( TNode table, int offset) { TNode number_of_deleted = SmiUntag(CAST(LoadFixedArrayElement( - table, ObjectHashTable::kNumberOfDeletedElementsIndex))); + table, EphemeronHashTable::kNumberOfDeletedElementsIndex))); return IntPtrAdd(number_of_deleted, IntPtrConstant(offset)); } @@ -2153,7 +2155,7 @@ TNode WeakCollectionsBuiltinsAssembler::LoadTable( TNode WeakCollectionsBuiltinsAssembler::LoadTableCapacity( TNode table) { return SmiUntag( - CAST(LoadFixedArrayElement(table, ObjectHashTable::kCapacityIndex))); + CAST(LoadFixedArrayElement(table, EphemeronHashTable::kCapacityIndex))); } TNode WeakCollectionsBuiltinsAssembler::InsufficientCapacityToAdd( @@ -2177,16 +2179,17 @@ TNode WeakCollectionsBuiltinsAssembler::InsufficientCapacityToAdd( void WeakCollectionsBuiltinsAssembler::RemoveEntry( TNode table, TNode key_index, TNode number_of_elements) { - // See ObjectHashTable::RemoveEntry(). + // See EphemeronHashTable::RemoveEntry(). TNode value_index = ValueIndexFromKeyIndex(key_index); StoreFixedArrayElement(table, key_index, TheHoleConstant()); StoreFixedArrayElement(table, value_index, TheHoleConstant()); // See HashTableBase::ElementRemoved(). TNode number_of_deleted = LoadNumberOfDeleted(table, 1); - StoreFixedArrayElement(table, ObjectHashTable::kNumberOfElementsIndex, + StoreFixedArrayElement(table, EphemeronHashTable::kNumberOfElementsIndex, SmiFromIntPtr(number_of_elements), SKIP_WRITE_BARRIER); - StoreFixedArrayElement(table, ObjectHashTable::kNumberOfDeletedElementsIndex, + StoreFixedArrayElement(table, + EphemeronHashTable::kNumberOfDeletedElementsIndex, SmiFromIntPtr(number_of_deleted), SKIP_WRITE_BARRIER); } @@ -2216,8 +2219,8 @@ TNode WeakCollectionsBuiltinsAssembler::ShouldShrink( TNode WeakCollectionsBuiltinsAssembler::ValueIndexFromKeyIndex( TNode key_index) { return IntPtrAdd(key_index, - IntPtrConstant(ObjectHashTableShape::kEntryValueIndex - - ObjectHashTable::kEntryKeyIndex)); + IntPtrConstant(EphemeronHashTableShape::kEntryValueIndex - + EphemeronHashTable::kEntryKeyIndex)); } TF_BUILTIN(WeakMapConstructor, WeakCollectionsBuiltinsAssembler) { @@ -2291,7 +2294,7 @@ TF_BUILTIN(WeakMapHas, WeakCollectionsBuiltinsAssembler) { } // Helper that removes the entry with a given key from the backing store -// (ObjectHashTable) of a WeakMap or WeakSet. +// (EphemeronHashTable) of a WeakMap or WeakSet. TF_BUILTIN(WeakCollectionDelete, WeakCollectionsBuiltinsAssembler) { TNode context = CAST(Parameter(Descriptor::kContext)); TNode collection = CAST(Parameter(Descriptor::kCollection)); @@ -2320,8 +2323,8 @@ TF_BUILTIN(WeakCollectionDelete, WeakCollectionsBuiltinsAssembler) { SmiTag(hash))); } -// Helper that sets the key and value to the backing store (ObjectHashTable) of -// a WeakMap or WeakSet. +// Helper that sets the key and value to the backing store (EphemeronHashTable) +// of a WeakMap or WeakSet. TF_BUILTIN(WeakCollectionSet, WeakCollectionsBuiltinsAssembler) { TNode context = CAST(Parameter(Descriptor::kContext)); TNode collection = CAST(Parameter(Descriptor::kCollection)); diff --git a/src/heap/mark-compact.cc b/src/heap/mark-compact.cc index f49ff86717..a55e870e7d 100644 --- a/src/heap/mark-compact.cc +++ b/src/heap/mark-compact.cc @@ -1859,16 +1859,17 @@ void MarkCompactCollector::ProcessWeakCollections() { JSWeakCollection* weak_collection = reinterpret_cast(weak_collection_obj); DCHECK(non_atomic_marking_state()->IsBlackOrGrey(weak_collection)); - if (weak_collection->table()->IsHashTable()) { - ObjectHashTable* table = ObjectHashTable::cast(weak_collection->table()); + if (weak_collection->table()->IsEphemeronHashTable()) { + EphemeronHashTable* table = + EphemeronHashTable::cast(weak_collection->table()); for (int i = 0; i < table->Capacity(); i++) { HeapObject* heap_object = HeapObject::cast(table->KeyAt(i)); if (non_atomic_marking_state()->IsBlackOrGrey(heap_object)) { Object** key_slot = - table->RawFieldOfElementAt(ObjectHashTable::EntryToIndex(i)); + table->RawFieldOfElementAt(EphemeronHashTable::EntryToIndex(i)); RecordSlot(table, key_slot, *key_slot); - Object** value_slot = - table->RawFieldOfElementAt(ObjectHashTable::EntryToValueIndex(i)); + Object** value_slot = table->RawFieldOfElementAt( + EphemeronHashTable::EntryToValueIndex(i)); if (V8_UNLIKELY(FLAG_track_retaining_path) && (*value_slot)->IsHeapObject()) { heap()->AddEphemeralRetainer(heap_object, @@ -1889,8 +1890,9 @@ void MarkCompactCollector::ClearWeakCollections() { JSWeakCollection* weak_collection = reinterpret_cast(weak_collection_obj); DCHECK(non_atomic_marking_state()->IsBlackOrGrey(weak_collection)); - if (weak_collection->table()->IsHashTable()) { - ObjectHashTable* table = ObjectHashTable::cast(weak_collection->table()); + if (weak_collection->table()->IsEphemeronHashTable()) { + EphemeronHashTable* table = + EphemeronHashTable::cast(weak_collection->table()); for (int i = 0; i < table->Capacity(); i++) { HeapObject* key = HeapObject::cast(table->KeyAt(i)); if (!non_atomic_marking_state()->IsBlackOrGrey(key)) { diff --git a/src/objects-inl.h b/src/objects-inl.h index 63b2f09943..240e75a6b4 100644 --- a/src/objects-inl.h +++ b/src/objects-inl.h @@ -505,6 +505,8 @@ bool HeapObject::IsMapCache() const { return IsHashTable(); } bool HeapObject::IsObjectHashTable() const { return IsHashTable(); } +bool HeapObject::IsEphemeronHashTable() const { return IsHashTable(); } + bool HeapObject::IsOrderedHashSet() const { return map() == GetHeap()->ordered_hash_set_map(); } @@ -597,6 +599,7 @@ CAST_ACCESSOR(BoilerplateDescription) CAST_ACCESSOR(Cell) CAST_ACCESSOR(ConstantElementsPair) CAST_ACCESSOR(DescriptorArray) +CAST_ACCESSOR(EphemeronHashTable) CAST_ACCESSOR(EnumCache) CAST_ACCESSOR(FeedbackCell) CAST_ACCESSOR(Foreign) @@ -3311,10 +3314,6 @@ Handle ObjectHashTableShape::AsHandle(Isolate* isolate, return key; } -Handle ObjectHashTable::Shrink(Handle table) { - return DerivedHashTable::Shrink(table); -} - Relocatable::Relocatable(Isolate* isolate) { isolate_ = isolate; prev_ = isolate->relocatable_top(); diff --git a/src/objects.cc b/src/objects.cc index d8d73cfd4e..6bf38a1579 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -18000,23 +18000,24 @@ Object* Dictionary::SlowReverseLookup(Object* value) { return isolate->heap()->undefined_value(); } - -Object* ObjectHashTable::Lookup(Isolate* isolate, Handle key, - int32_t hash) { +template +Object* ObjectHashTableBase::Lookup(Isolate* isolate, + Handle key, + int32_t hash) { DisallowHeapAllocation no_gc; - DCHECK(IsKey(isolate, *key)); + DCHECK(this->IsKey(isolate, *key)); - int entry = FindEntry(isolate, key, hash); + int entry = this->FindEntry(isolate, key, hash); if (entry == kNotFound) return isolate->heap()->the_hole_value(); - return get(EntryToIndex(entry) + 1); + return this->get(Derived::EntryToIndex(entry) + 1); } - -Object* ObjectHashTable::Lookup(Handle key) { +template +Object* ObjectHashTableBase::Lookup(Handle key) { DisallowHeapAllocation no_gc; - Isolate* isolate = GetIsolate(); - DCHECK(IsKey(isolate, *key)); + Isolate* isolate = this->GetIsolate(); + DCHECK(this->IsKey(isolate, *key)); // If the object does not have an identity hash, it was never used as a key. Object* hash = key->GetHash(); @@ -18026,18 +18027,21 @@ Object* ObjectHashTable::Lookup(Handle key) { return Lookup(isolate, key, Smi::ToInt(hash)); } -Object* ObjectHashTable::ValueAt(int entry) { - return get(EntryToValueIndex(entry)); +template +Object* ObjectHashTableBase::Lookup(Handle key, + int32_t hash) { + return Lookup(this->GetIsolate(), key, hash); } -Object* ObjectHashTable::Lookup(Handle key, int32_t hash) { - return Lookup(GetIsolate(), key, hash); +template +Object* ObjectHashTableBase::ValueAt(int entry) { + return this->get(EntryToValueIndex(entry)); } - -Handle ObjectHashTable::Put(Handle table, - Handle key, - Handle value) { +template +Handle ObjectHashTableBase::Put(Handle table, + Handle key, + Handle value) { Isolate* isolate = table->GetIsolate(); DCHECK(table->IsKey(isolate, *key)); DCHECK(!value->IsTheHole(isolate)); @@ -18045,14 +18049,14 @@ Handle ObjectHashTable::Put(Handle table, // Make sure the key object has an identity hash code. int32_t hash = key->GetOrCreateHash(isolate)->value(); - return Put(table, key, value, hash); + return ObjectHashTableBase::Put(table, key, value, hash); } - -Handle ObjectHashTable::Put(Handle table, - Handle key, - Handle value, - int32_t hash) { +template +Handle ObjectHashTableBase::Put(Handle table, + Handle key, + Handle value, + int32_t hash) { Isolate* isolate = table->GetIsolate(); DCHECK(table->IsKey(isolate, *key)); DCHECK(!value->IsTheHole(isolate)); @@ -18061,7 +18065,7 @@ Handle ObjectHashTable::Put(Handle table, // Key is already in table, just overwrite value. if (entry != kNotFound) { - table->set(EntryToIndex(entry) + 1, *value); + table->set(Derived::EntryToIndex(entry) + 1, *value); return table; } @@ -18086,15 +18090,14 @@ Handle ObjectHashTable::Put(Handle table, } // Check whether the hash table should be extended. - table = EnsureCapacity(table, 1); + table = Derived::EnsureCapacity(table, 1); table->AddEntry(table->FindInsertionEntry(hash), *key, *value); return table; } - -Handle ObjectHashTable::Remove(Handle table, - Handle key, - bool* was_present) { +template +Handle ObjectHashTableBase::Remove( + Handle table, Handle key, bool* was_present) { DCHECK(table->IsKey(table->GetIsolate(), *key)); Object* hash = key->GetHash(); @@ -18106,11 +18109,10 @@ Handle ObjectHashTable::Remove(Handle table, return Remove(table, key, was_present, Smi::ToInt(hash)); } - -Handle ObjectHashTable::Remove(Handle table, - Handle key, - bool* was_present, - int32_t hash) { +template +Handle ObjectHashTableBase::Remove( + Handle table, Handle key, bool* was_present, + int32_t hash) { Isolate* isolate = table->GetIsolate(); DCHECK(table->IsKey(isolate, *key)); @@ -18122,21 +18124,22 @@ Handle ObjectHashTable::Remove(Handle table, *was_present = true; table->RemoveEntry(entry); - return Shrink(table); + return Derived::Shrink(table); } - -void ObjectHashTable::AddEntry(int entry, Object* key, Object* value) { - set(EntryToIndex(entry), key); - set(EntryToIndex(entry) + 1, value); - ElementAdded(); +template +void ObjectHashTableBase::AddEntry(int entry, Object* key, + Object* value) { + this->set(Derived::EntryToIndex(entry), key); + this->set(Derived::EntryToIndex(entry) + 1, value); + this->ElementAdded(); } - -void ObjectHashTable::RemoveEntry(int entry) { - set_the_hole(EntryToIndex(entry)); - set_the_hole(EntryToIndex(entry) + 1); - ElementRemoved(); +template +void ObjectHashTableBase::RemoveEntry(int entry) { + this->set_the_hole(Derived::EntryToIndex(entry)); + this->set_the_hole(Derived::EntryToIndex(entry) + 1); + this->ElementRemoved(); } @@ -18168,7 +18171,7 @@ void JSMap::Clear(Handle map) { void JSWeakCollection::Initialize(Handle weak_collection, Isolate* isolate) { - Handle table = ObjectHashTable::New(isolate, 0); + Handle table = EphemeronHashTable::New(isolate, 0); weak_collection->set_table(*table); } @@ -18177,11 +18180,11 @@ void JSWeakCollection::Set(Handle weak_collection, Handle key, Handle value, int32_t hash) { DCHECK(key->IsJSReceiver() || key->IsSymbol()); - Handle table( - ObjectHashTable::cast(weak_collection->table())); + Handle table( + EphemeronHashTable::cast(weak_collection->table())); DCHECK(table->IsKey(table->GetIsolate(), *key)); - Handle new_table = - ObjectHashTable::Put(table, key, value, hash); + Handle new_table = + EphemeronHashTable::Put(table, key, value, hash); weak_collection->set_table(*new_table); if (*table != *new_table) { // Zap the old table since we didn't record slots for its elements. @@ -18193,12 +18196,12 @@ void JSWeakCollection::Set(Handle weak_collection, bool JSWeakCollection::Delete(Handle weak_collection, Handle key, int32_t hash) { DCHECK(key->IsJSReceiver() || key->IsSymbol()); - Handle table( - ObjectHashTable::cast(weak_collection->table())); + Handle table( + EphemeronHashTable::cast(weak_collection->table())); DCHECK(table->IsKey(table->GetIsolate(), *key)); bool was_present = false; - Handle new_table = - ObjectHashTable::Remove(table, key, &was_present, hash); + Handle new_table = + EphemeronHashTable::Remove(table, key, &was_present, hash); weak_collection->set_table(*new_table); if (*table != *new_table) { // Zap the old table since we didn't record slots for its elements. @@ -18210,7 +18213,7 @@ bool JSWeakCollection::Delete(Handle weak_collection, Handle JSWeakCollection::GetEntries(Handle holder, int max_entries) { Isolate* isolate = holder->GetIsolate(); - Handle table(ObjectHashTable::cast(holder->table())); + Handle table(EphemeronHashTable::cast(holder->table())); if (max_entries == 0 || max_entries > table->NumberOfElements()) { max_entries = table->NumberOfElements(); } @@ -18870,6 +18873,12 @@ template class HashTable; template class HashTable; +template class HashTable; + +template class ObjectHashTableBase; + +template class ObjectHashTableBase; + template class Dictionary; template class Dictionary; diff --git a/src/objects.h b/src/objects.h index 54d0d82df4..92552b4e08 100644 --- a/src/objects.h +++ b/src/objects.h @@ -1054,6 +1054,7 @@ template inline bool Is(Object* obj); V(DeoptimizationData) \ V(DependentCode) \ V(DescriptorArray) \ + V(EphemeronHashTable) \ V(EnumCache) \ V(External) \ V(ExternalOneByteString) \ diff --git a/src/objects/hash-table.h b/src/objects/hash-table.h index 8268ad3bc4..9b8c2bc6ff 100644 --- a/src/objects/hash-table.h +++ b/src/objects/hash-table.h @@ -269,19 +269,9 @@ class ObjectHashTableShape : public BaseShape> { static const bool kNeedsHoleCheck = false; }; -// ObjectHashTable maps keys that are arbitrary objects to object values by -// using the identity hash of the key for hashing purposes. -class ObjectHashTable - : public HashTable { - typedef HashTable DerivedHashTable; - +template +class ObjectHashTableBase : public HashTable { public: - DECL_CAST(ObjectHashTable) - - // Attempt to shrink hash table after removal of key. - V8_WARN_UNUSED_RESULT static inline Handle Shrink( - Handle table); - // Looks up the value associated with the given key. The hole value is // returned in case the key is not present. Object* Lookup(Handle key); @@ -292,31 +282,51 @@ class ObjectHashTable Object* ValueAt(int entry); // Adds (or overwrites) the value associated with the given key. - static Handle Put(Handle table, - Handle key, Handle value); - static Handle Put(Handle table, - Handle key, Handle value, - int32_t hash); + static Handle Put(Handle table, Handle key, + Handle value); + static Handle Put(Handle table, Handle key, + Handle value, int32_t hash); // Returns an ObjectHashTable (possibly |table|) where |key| has been removed. - static Handle Remove(Handle table, - Handle key, bool* was_present); - static Handle Remove(Handle table, - Handle key, bool* was_present, - int32_t hash); + static Handle Remove(Handle table, Handle key, + bool* was_present); + static Handle Remove(Handle table, Handle key, + bool* was_present, int32_t hash); // Returns the index to the value of an entry. static inline int EntryToValueIndex(int entry) { - return EntryToIndex(entry) + ObjectHashTableShape::kEntryValueIndex; + return HashTable::EntryToIndex(entry) + + Shape::kEntryValueIndex; } protected: - friend class MarkCompactCollector; - void AddEntry(int entry, Object* key, Object* value); void RemoveEntry(int entry); }; +// ObjectHashTable maps keys that are arbitrary objects to object values by +// using the identity hash of the key for hashing purposes. +class ObjectHashTable + : public ObjectHashTableBase { + public: + DECL_CAST(ObjectHashTable) +}; + +typedef ObjectHashTableShape EphemeronHashTableShape; + +// EphemeronHashTable is similar to ObjectHashTable but gets special treatment +// by the GC. The GC treats its entries as ephemerons: both key and value are +// weak references, however if the key is strongly reachable its corresponding +// value is also kept alive. +class EphemeronHashTable + : public ObjectHashTableBase { + public: + DECL_CAST(EphemeronHashTable) + + protected: + friend class MarkCompactCollector; +}; + class ObjectHashSetShape : public ObjectHashTableShape { public: static const int kPrefixSize = 0; diff --git a/src/profiler/heap-snapshot-generator.cc b/src/profiler/heap-snapshot-generator.cc index 3f3974015c..830fb70405 100644 --- a/src/profiler/heap-snapshot-generator.cc +++ b/src/profiler/heap-snapshot-generator.cc @@ -1038,7 +1038,7 @@ void V8HeapExplorer::ExtractJSCollectionReferences(int entry, void V8HeapExplorer::ExtractJSWeakCollectionReferences(int entry, JSWeakCollection* obj) { if (obj->table()->IsHashTable()) { - ObjectHashTable* table = ObjectHashTable::cast(obj->table()); + EphemeronHashTable* table = EphemeronHashTable::cast(obj->table()); TagFixedArraySubType(table, JS_WEAK_COLLECTION_SUB_TYPE); } SetInternalReference(obj, entry, "table", obj->table(), @@ -1361,11 +1361,11 @@ void V8HeapExplorer::ExtractFixedArrayReferences(int entry, FixedArray* array) { } switch (it->second) { case JS_WEAK_COLLECTION_SUB_TYPE: { - ObjectHashTable* table = ObjectHashTable::cast(array); + EphemeronHashTable* table = EphemeronHashTable::cast(array); for (int i = 0, capacity = table->Capacity(); i < capacity; ++i) { - int key_index = - ObjectHashTable::EntryToIndex(i) + ObjectHashTable::kEntryKeyIndex; - int value_index = ObjectHashTable::EntryToValueIndex(i); + int key_index = EphemeronHashTable::EntryToIndex(i) + + EphemeronHashTable::kEntryKeyIndex; + int value_index = EphemeronHashTable::EntryToValueIndex(i); Object* key = table->get(key_index); Object* value = table->get(value_index); SetWeakReference(table, entry, key_index, key, diff --git a/src/runtime/runtime-collections.cc b/src/runtime/runtime-collections.cc index ff765bfd2a..793122e14d 100644 --- a/src/runtime/runtime-collections.cc +++ b/src/runtime/runtime-collections.cc @@ -98,9 +98,9 @@ RUNTIME_FUNCTION(Runtime_WeakCollectionDelete) { #ifdef DEBUG DCHECK(key->IsJSReceiver()); - DCHECK(ObjectHashTableShape::IsLive(isolate, *key)); - Handle table( - ObjectHashTable::cast(weak_collection->table())); + DCHECK(EphemeronHashTableShape::IsLive(isolate, *key)); + Handle table( + EphemeronHashTable::cast(weak_collection->table())); // Should only be called when shrinking the table is necessary. See // HashTable::Shrink(). DCHECK(table->NumberOfElements() - 1 <= (table->Capacity() >> 2) && @@ -130,11 +130,11 @@ RUNTIME_FUNCTION(Runtime_WeakCollectionSet) { #ifdef DEBUG DCHECK(key->IsJSReceiver()); - DCHECK(ObjectHashTableShape::IsLive(isolate, *key)); - Handle table( - ObjectHashTable::cast(weak_collection->table())); + DCHECK(EphemeronHashTableShape::IsLive(isolate, *key)); + Handle table( + EphemeronHashTable::cast(weak_collection->table())); // Should only be called when rehashing or resizing the table is necessary. - // See ObjectHashTable::Put() and HashTable::HasSufficientCapacityToAdd(). + // See EphemeronHashTable::Put() and HashTable::HasSufficientCapacityToAdd(). DCHECK((table->NumberOfDeletedElements() << 1) > table->NumberOfElements() || !table->HasSufficientCapacityToAdd(1)); #endif diff --git a/test/cctest/test-weakmaps.cc b/test/cctest/test-weakmaps.cc index 14bc042871..20f1bdb68b 100644 --- a/test/cctest/test-weakmaps.cc +++ b/test/cctest/test-weakmaps.cc @@ -85,14 +85,14 @@ TEST(Weakness) { int32_t object_hash = object->GetOrCreateHash(isolate)->value(); JSWeakCollection::Set(weakmap, object, smi, object_hash); } - CHECK_EQ(2, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); + CHECK_EQ(2, EphemeronHashTable::cast(weakmap->table())->NumberOfElements()); // Force a full GC. CcTest::CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); CHECK_EQ(0, NumberOfWeakCalls); - CHECK_EQ(2, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); + CHECK_EQ(2, EphemeronHashTable::cast(weakmap->table())->NumberOfElements()); CHECK_EQ( - 0, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements()); + 0, EphemeronHashTable::cast(weakmap->table())->NumberOfDeletedElements()); // Make the global reference to the key weak. std::pair*, int> handle_and_id(&key, 1234); @@ -103,9 +103,9 @@ TEST(Weakness) { CcTest::CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); CHECK_EQ(1, NumberOfWeakCalls); - CHECK_EQ(0, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); - CHECK_EQ(2, - ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements()); + CHECK_EQ(0, EphemeronHashTable::cast(weakmap->table())->NumberOfElements()); + CHECK_EQ( + 2, EphemeronHashTable::cast(weakmap->table())->NumberOfDeletedElements()); } @@ -117,7 +117,7 @@ TEST(Shrinking) { Handle weakmap = isolate->factory()->NewJSWeakMap(); // Check initial capacity. - CHECK_EQ(32, ObjectHashTable::cast(weakmap->table())->Capacity()); + CHECK_EQ(32, EphemeronHashTable::cast(weakmap->table())->Capacity()); // Fill up weak map to trigger capacity change. { @@ -132,19 +132,20 @@ TEST(Shrinking) { } // Check increased capacity. - CHECK_EQ(128, ObjectHashTable::cast(weakmap->table())->Capacity()); + CHECK_EQ(128, EphemeronHashTable::cast(weakmap->table())->Capacity()); // Force a full GC. - CHECK_EQ(32, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); + CHECK_EQ(32, EphemeronHashTable::cast(weakmap->table())->NumberOfElements()); CHECK_EQ( - 0, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements()); + 0, EphemeronHashTable::cast(weakmap->table())->NumberOfDeletedElements()); CcTest::CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); - CHECK_EQ(0, ObjectHashTable::cast(weakmap->table())->NumberOfElements()); + CHECK_EQ(0, EphemeronHashTable::cast(weakmap->table())->NumberOfElements()); CHECK_EQ( - 32, ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements()); + 32, + EphemeronHashTable::cast(weakmap->table())->NumberOfDeletedElements()); // Check shrunk capacity. - CHECK_EQ(32, ObjectHashTable::cast(weakmap->table())->Capacity()); + CHECK_EQ(32, EphemeronHashTable::cast(weakmap->table())->Capacity()); } diff --git a/test/cctest/test-weaksets.cc b/test/cctest/test-weaksets.cc index 5d8e27dd5c..16e13f0ac3 100644 --- a/test/cctest/test-weaksets.cc +++ b/test/cctest/test-weaksets.cc @@ -53,7 +53,7 @@ static Handle AllocateJSWeakSet(Isolate* isolate) { // Do not leak handles for the hash table, it would make entries strong. { HandleScope scope(isolate); - Handle table = ObjectHashTable::New(isolate, 1); + Handle table = EphemeronHashTable::New(isolate, 1); weakset->set_table(*table); } return weakset; @@ -96,14 +96,14 @@ TEST(WeakSet_Weakness) { int32_t hash = key->GetOrCreateHash(isolate)->value(); JSWeakCollection::Set(weakset, key, smi, hash); } - CHECK_EQ(1, ObjectHashTable::cast(weakset->table())->NumberOfElements()); + CHECK_EQ(1, EphemeronHashTable::cast(weakset->table())->NumberOfElements()); // Force a full GC. CcTest::CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); CHECK_EQ(0, NumberOfWeakCalls); - CHECK_EQ(1, ObjectHashTable::cast(weakset->table())->NumberOfElements()); + CHECK_EQ(1, EphemeronHashTable::cast(weakset->table())->NumberOfElements()); CHECK_EQ( - 0, ObjectHashTable::cast(weakset->table())->NumberOfDeletedElements()); + 0, EphemeronHashTable::cast(weakset->table())->NumberOfDeletedElements()); // Make the global reference to the key weak. std::pair*, int> handle_and_id(&key, 1234); @@ -114,9 +114,9 @@ TEST(WeakSet_Weakness) { CcTest::CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); CHECK_EQ(1, NumberOfWeakCalls); - CHECK_EQ(0, ObjectHashTable::cast(weakset->table())->NumberOfElements()); + CHECK_EQ(0, EphemeronHashTable::cast(weakset->table())->NumberOfElements()); CHECK_EQ( - 1, ObjectHashTable::cast(weakset->table())->NumberOfDeletedElements()); + 1, EphemeronHashTable::cast(weakset->table())->NumberOfDeletedElements()); } @@ -128,7 +128,7 @@ TEST(WeakSet_Shrinking) { Handle weakset = AllocateJSWeakSet(isolate); // Check initial capacity. - CHECK_EQ(32, ObjectHashTable::cast(weakset->table())->Capacity()); + CHECK_EQ(32, EphemeronHashTable::cast(weakset->table())->Capacity()); // Fill up weak set to trigger capacity change. { @@ -143,19 +143,20 @@ TEST(WeakSet_Shrinking) { } // Check increased capacity. - CHECK_EQ(128, ObjectHashTable::cast(weakset->table())->Capacity()); + CHECK_EQ(128, EphemeronHashTable::cast(weakset->table())->Capacity()); // Force a full GC. - CHECK_EQ(32, ObjectHashTable::cast(weakset->table())->NumberOfElements()); + CHECK_EQ(32, EphemeronHashTable::cast(weakset->table())->NumberOfElements()); CHECK_EQ( - 0, ObjectHashTable::cast(weakset->table())->NumberOfDeletedElements()); + 0, EphemeronHashTable::cast(weakset->table())->NumberOfDeletedElements()); CcTest::CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); - CHECK_EQ(0, ObjectHashTable::cast(weakset->table())->NumberOfElements()); + CHECK_EQ(0, EphemeronHashTable::cast(weakset->table())->NumberOfElements()); CHECK_EQ( - 32, ObjectHashTable::cast(weakset->table())->NumberOfDeletedElements()); + 32, + EphemeronHashTable::cast(weakset->table())->NumberOfDeletedElements()); // Check shrunk capacity. - CHECK_EQ(32, ObjectHashTable::cast(weakset->table())->Capacity()); + CHECK_EQ(32, EphemeronHashTable::cast(weakset->table())->Capacity()); }