Commit ae53e491 authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[cleanup] Move GetMap to HashTable from Shape

The map of the HashTable is more a property of the HashTable than part
of its shape, so we can move its static map getter (for construction)
to to HashTable class itself.

Change-Id: I73f4aa7260d6ce749ef51961767fd37d1ab520e4
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2289782
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68805}
parent 4f50c554
...@@ -2511,7 +2511,7 @@ TNode<HeapObject> WeakCollectionsBuiltinsAssembler::AllocateTable( ...@@ -2511,7 +2511,7 @@ TNode<HeapObject> WeakCollectionsBuiltinsAssembler::AllocateTable(
AllocateFixedArray(HOLEY_ELEMENTS, length, kAllowLargeObjectAllocation)); AllocateFixedArray(HOLEY_ELEMENTS, length, kAllowLargeObjectAllocation));
TNode<Map> map = TNode<Map> map =
HeapConstant(EphemeronHashTableShape::GetMap(ReadOnlyRoots(isolate()))); HeapConstant(EphemeronHashTable::GetMap(ReadOnlyRoots(isolate())));
StoreMapNoWriteBarrier(table, map); StoreMapNoWriteBarrier(table, map);
StoreFixedArrayElement(table, EphemeronHashTable::kNumberOfElementsIndex, StoreFixedArrayElement(table, EphemeronHashTable::kNumberOfElementsIndex,
SmiConstant(0), SKIP_WRITE_BARRIER); SmiConstant(0), SKIP_WRITE_BARRIER);
...@@ -2695,7 +2695,7 @@ TNode<Word32T> WeakCollectionsBuiltinsAssembler::ShouldShrink( ...@@ -2695,7 +2695,7 @@ TNode<Word32T> WeakCollectionsBuiltinsAssembler::ShouldShrink(
TNode<IntPtrT> WeakCollectionsBuiltinsAssembler::ValueIndexFromKeyIndex( TNode<IntPtrT> WeakCollectionsBuiltinsAssembler::ValueIndexFromKeyIndex(
TNode<IntPtrT> key_index) { TNode<IntPtrT> key_index) {
return IntPtrAdd(key_index, return IntPtrAdd(key_index,
IntPtrConstant(EphemeronHashTableShape::kEntryValueIndex - IntPtrConstant(EphemeronHashTable::ShapeT::kEntryValueIndex -
EphemeronHashTable::kEntryKeyIndex)); EphemeronHashTable::kEntryKeyIndex));
} }
......
...@@ -177,7 +177,7 @@ Object GlobalDictionaryShape::Unwrap(Object object) { ...@@ -177,7 +177,7 @@ Object GlobalDictionaryShape::Unwrap(Object object) {
return PropertyCell::cast(object).name(); return PropertyCell::cast(object).name();
} }
Handle<Map> GlobalDictionaryShape::GetMap(ReadOnlyRoots roots) { Handle<Map> GlobalDictionary::GetMap(ReadOnlyRoots roots) {
return roots.global_dictionary_map_handle(); return roots.global_dictionary_map_handle();
} }
...@@ -190,7 +190,7 @@ Name NameDictionary::NameAt(const Isolate* isolate, InternalIndex entry) { ...@@ -190,7 +190,7 @@ Name NameDictionary::NameAt(const Isolate* isolate, InternalIndex entry) {
return Name::cast(KeyAt(isolate, entry)); return Name::cast(KeyAt(isolate, entry));
} }
Handle<Map> NameDictionaryShape::GetMap(ReadOnlyRoots roots) { Handle<Map> NameDictionary::GetMap(ReadOnlyRoots roots) {
return roots.name_dictionary_map_handle(); return roots.name_dictionary_map_handle();
} }
...@@ -269,11 +269,11 @@ Handle<Object> NumberDictionaryBaseShape::AsHandle(OffThreadIsolate* isolate, ...@@ -269,11 +269,11 @@ Handle<Object> NumberDictionaryBaseShape::AsHandle(OffThreadIsolate* isolate,
return isolate->factory()->NewNumberFromUint<AllocationType::kOld>(key); return isolate->factory()->NewNumberFromUint<AllocationType::kOld>(key);
} }
Handle<Map> NumberDictionaryShape::GetMap(ReadOnlyRoots roots) { Handle<Map> NumberDictionary::GetMap(ReadOnlyRoots roots) {
return roots.number_dictionary_map_handle(); return roots.number_dictionary_map_handle();
} }
Handle<Map> SimpleNumberDictionaryShape::GetMap(ReadOnlyRoots roots) { Handle<Map> SimpleNumberDictionary::GetMap(ReadOnlyRoots roots) {
return roots.simple_number_dictionary_map_handle(); return roots.simple_number_dictionary_map_handle();
} }
......
...@@ -114,7 +114,6 @@ class NameDictionaryShape : public BaseDictionaryShape<Handle<Name>> { ...@@ -114,7 +114,6 @@ class NameDictionaryShape : public BaseDictionaryShape<Handle<Name>> {
static inline Handle<Object> AsHandle(Isolate* isolate, Handle<Name> key); static inline Handle<Object> AsHandle(Isolate* isolate, Handle<Name> key);
static inline Handle<Object> AsHandle(OffThreadIsolate* isolate, static inline Handle<Object> AsHandle(OffThreadIsolate* isolate,
Handle<Name> key); Handle<Name> key);
static inline Handle<Map> GetMap(ReadOnlyRoots roots);
static const int kPrefixSize = 2; static const int kPrefixSize = 2;
static const int kEntrySize = 3; static const int kEntrySize = 3;
static const int kEntryValueIndex = 1; static const int kEntryValueIndex = 1;
...@@ -189,6 +188,8 @@ EXTERN_DECLARE_BASE_NAME_DICTIONARY(NameDictionary, NameDictionaryShape) ...@@ -189,6 +188,8 @@ EXTERN_DECLARE_BASE_NAME_DICTIONARY(NameDictionary, NameDictionaryShape)
class V8_EXPORT_PRIVATE NameDictionary class V8_EXPORT_PRIVATE NameDictionary
: public BaseNameDictionary<NameDictionary, NameDictionaryShape> { : public BaseNameDictionary<NameDictionary, NameDictionaryShape> {
public: public:
static inline Handle<Map> GetMap(ReadOnlyRoots roots);
DECL_CAST(NameDictionary) DECL_CAST(NameDictionary)
static const int kEntryValueIndex = 1; static const int kEntryValueIndex = 1;
...@@ -222,7 +223,6 @@ class V8_EXPORT_PRIVATE GlobalDictionaryShape : public NameDictionaryShape { ...@@ -222,7 +223,6 @@ class V8_EXPORT_PRIVATE GlobalDictionaryShape : public NameDictionaryShape {
static inline Object Unwrap(Object key); static inline Object Unwrap(Object key);
static inline bool IsKey(ReadOnlyRoots roots, Object k); static inline bool IsKey(ReadOnlyRoots roots, Object k);
static inline bool IsLive(ReadOnlyRoots roots, Object key); static inline bool IsLive(ReadOnlyRoots roots, Object key);
static inline Handle<Map> GetMap(ReadOnlyRoots roots);
}; };
EXTERN_DECLARE_BASE_NAME_DICTIONARY(GlobalDictionary, GlobalDictionaryShape) EXTERN_DECLARE_BASE_NAME_DICTIONARY(GlobalDictionary, GlobalDictionaryShape)
...@@ -230,6 +230,8 @@ EXTERN_DECLARE_BASE_NAME_DICTIONARY(GlobalDictionary, GlobalDictionaryShape) ...@@ -230,6 +230,8 @@ EXTERN_DECLARE_BASE_NAME_DICTIONARY(GlobalDictionary, GlobalDictionaryShape)
class V8_EXPORT_PRIVATE GlobalDictionary class V8_EXPORT_PRIVATE GlobalDictionary
: public BaseNameDictionary<GlobalDictionary, GlobalDictionaryShape> { : public BaseNameDictionary<GlobalDictionary, GlobalDictionaryShape> {
public: public:
static inline Handle<Map> GetMap(ReadOnlyRoots roots);
DECL_CAST(GlobalDictionary) DECL_CAST(GlobalDictionary)
inline Object ValueAt(InternalIndex entry); inline Object ValueAt(InternalIndex entry);
...@@ -262,8 +264,6 @@ class NumberDictionaryShape : public NumberDictionaryBaseShape { ...@@ -262,8 +264,6 @@ class NumberDictionaryShape : public NumberDictionaryBaseShape {
public: public:
static const int kPrefixSize = 1; static const int kPrefixSize = 1;
static const int kEntrySize = 3; static const int kEntrySize = 3;
static inline Handle<Map> GetMap(ReadOnlyRoots roots);
}; };
class SimpleNumberDictionaryShape : public NumberDictionaryBaseShape { class SimpleNumberDictionaryShape : public NumberDictionaryBaseShape {
...@@ -283,8 +283,6 @@ class SimpleNumberDictionaryShape : public NumberDictionaryBaseShape { ...@@ -283,8 +283,6 @@ class SimpleNumberDictionaryShape : public NumberDictionaryBaseShape {
PropertyDetails value) { PropertyDetails value) {
UNREACHABLE(); UNREACHABLE();
} }
static inline Handle<Map> GetMap(ReadOnlyRoots roots);
}; };
EXTERN_DECLARE_DICTIONARY(SimpleNumberDictionary, SimpleNumberDictionaryShape) EXTERN_DECLARE_DICTIONARY(SimpleNumberDictionary, SimpleNumberDictionaryShape)
...@@ -293,6 +291,8 @@ EXTERN_DECLARE_DICTIONARY(SimpleNumberDictionary, SimpleNumberDictionaryShape) ...@@ -293,6 +291,8 @@ EXTERN_DECLARE_DICTIONARY(SimpleNumberDictionary, SimpleNumberDictionaryShape)
class SimpleNumberDictionary class SimpleNumberDictionary
: public Dictionary<SimpleNumberDictionary, SimpleNumberDictionaryShape> { : public Dictionary<SimpleNumberDictionary, SimpleNumberDictionaryShape> {
public: public:
static inline Handle<Map> GetMap(ReadOnlyRoots roots);
DECL_CAST(SimpleNumberDictionary) DECL_CAST(SimpleNumberDictionary)
// Type specific at put (default NONE attributes is used when adding). // Type specific at put (default NONE attributes is used when adding).
V8_EXPORT_PRIVATE V8_WARN_UNUSED_RESULT static Handle<SimpleNumberDictionary> V8_EXPORT_PRIVATE V8_WARN_UNUSED_RESULT static Handle<SimpleNumberDictionary>
...@@ -313,6 +313,8 @@ EXTERN_DECLARE_DICTIONARY(NumberDictionary, NumberDictionaryShape) ...@@ -313,6 +313,8 @@ EXTERN_DECLARE_DICTIONARY(NumberDictionary, NumberDictionaryShape)
class NumberDictionary class NumberDictionary
: public Dictionary<NumberDictionary, NumberDictionaryShape> { : public Dictionary<NumberDictionary, NumberDictionaryShape> {
public: public:
static inline Handle<Map> GetMap(ReadOnlyRoots roots);
DECL_CAST(NumberDictionary) DECL_CAST(NumberDictionary)
DECL_PRINTER(NumberDictionary) DECL_PRINTER(NumberDictionary)
......
...@@ -36,7 +36,7 @@ ObjectHashTable::ObjectHashTable(Address ptr) ...@@ -36,7 +36,7 @@ ObjectHashTable::ObjectHashTable(Address ptr)
} }
EphemeronHashTable::EphemeronHashTable(Address ptr) EphemeronHashTable::EphemeronHashTable(Address ptr)
: ObjectHashTableBase<EphemeronHashTable, EphemeronHashTableShape>(ptr) { : ObjectHashTableBase<EphemeronHashTable, ObjectHashTableShape>(ptr) {
SLOW_DCHECK(IsEphemeronHashTable()); SLOW_DCHECK(IsEphemeronHashTable());
} }
...@@ -121,12 +121,14 @@ void HashTableBase::SetNumberOfDeletedElements(int nod) { ...@@ -121,12 +121,14 @@ void HashTableBase::SetNumberOfDeletedElements(int nod) {
set(kNumberOfDeletedElementsIndex, Smi::FromInt(nod)); set(kNumberOfDeletedElementsIndex, Smi::FromInt(nod));
} }
template <typename Key> // static
Handle<Map> BaseShape<Key>::GetMap(ReadOnlyRoots roots) { template <typename Derived, typename Shape>
Handle<Map> HashTable<Derived, Shape>::GetMap(ReadOnlyRoots roots) {
return roots.hash_table_map_handle(); return roots.hash_table_map_handle();
} }
Handle<Map> EphemeronHashTableShape::GetMap(ReadOnlyRoots roots) { // static
Handle<Map> EphemeronHashTable::GetMap(ReadOnlyRoots roots) {
return roots.ephemeron_hash_table_map_handle(); return roots.ephemeron_hash_table_map_handle();
} }
......
...@@ -60,7 +60,6 @@ template <typename KeyT> ...@@ -60,7 +60,6 @@ template <typename KeyT>
class V8_EXPORT_PRIVATE BaseShape { class V8_EXPORT_PRIVATE BaseShape {
public: public:
using Key = KeyT; using Key = KeyT;
static inline Handle<Map> GetMap(ReadOnlyRoots roots);
static const bool kNeedsHoleCheck = true; static const bool kNeedsHoleCheck = true;
static Object Unwrap(Object key) { return key; } static Object Unwrap(Object key) { return key; }
static inline bool IsKey(ReadOnlyRoots roots, Object key); static inline bool IsKey(ReadOnlyRoots roots, Object key);
...@@ -135,6 +134,8 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) HashTable ...@@ -135,6 +134,8 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) HashTable
AllocationType allocation = AllocationType::kYoung, AllocationType allocation = AllocationType::kYoung,
MinimumCapacity capacity_option = USE_DEFAULT_MINIMUM_CAPACITY); MinimumCapacity capacity_option = USE_DEFAULT_MINIMUM_CAPACITY);
static inline Handle<Map> GetMap(ReadOnlyRoots roots);
// Garbage collection support. // Garbage collection support.
void IteratePrefix(ObjectVisitor* visitor); void IteratePrefix(ObjectVisitor* visitor);
void IterateElements(ObjectVisitor* visitor); void IterateElements(ObjectVisitor* visitor);
...@@ -368,21 +369,17 @@ class V8_EXPORT_PRIVATE ObjectHashTable ...@@ -368,21 +369,17 @@ class V8_EXPORT_PRIVATE ObjectHashTable
ObjectHashTableBase<ObjectHashTable, ObjectHashTableShape>); ObjectHashTableBase<ObjectHashTable, ObjectHashTableShape>);
}; };
class EphemeronHashTableShape : public ObjectHashTableShape { EXTERN_DECLARE_OBJECT_BASE_HASH_TABLE(EphemeronHashTable, ObjectHashTableShape)
public:
static inline Handle<Map> GetMap(ReadOnlyRoots roots);
};
EXTERN_DECLARE_OBJECT_BASE_HASH_TABLE(EphemeronHashTable,
EphemeronHashTableShape)
// EphemeronHashTable is similar to ObjectHashTable but gets special treatment // EphemeronHashTable is similar to ObjectHashTable but gets special treatment
// by the GC. The GC treats its entries as ephemerons: both key and value are // 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 // weak references, however if the key is strongly reachable its corresponding
// value is also kept alive. // value is also kept alive.
class V8_EXPORT_PRIVATE EphemeronHashTable class V8_EXPORT_PRIVATE EphemeronHashTable
: public ObjectHashTableBase<EphemeronHashTable, EphemeronHashTableShape> { : public ObjectHashTableBase<EphemeronHashTable, ObjectHashTableShape> {
public: public:
static inline Handle<Map> GetMap(ReadOnlyRoots roots);
DECL_CAST(EphemeronHashTable) DECL_CAST(EphemeronHashTable)
DECL_PRINTER(EphemeronHashTable) DECL_PRINTER(EphemeronHashTable)
class BodyDescriptor; class BodyDescriptor;
...@@ -390,14 +387,14 @@ class V8_EXPORT_PRIVATE EphemeronHashTable ...@@ -390,14 +387,14 @@ class V8_EXPORT_PRIVATE EphemeronHashTable
protected: protected:
friend class MarkCompactCollector; friend class MarkCompactCollector;
friend class ScavengerCollector; friend class ScavengerCollector;
friend class HashTable<EphemeronHashTable, EphemeronHashTableShape>; friend class HashTable<EphemeronHashTable, ObjectHashTableShape>;
friend class ObjectHashTableBase<EphemeronHashTable, EphemeronHashTableShape>; friend class ObjectHashTableBase<EphemeronHashTable, ObjectHashTableShape>;
inline void set_key(int index, Object value); inline void set_key(int index, Object value);
inline void set_key(int index, Object value, WriteBarrierMode mode); inline void set_key(int index, Object value, WriteBarrierMode mode);
OBJECT_CONSTRUCTORS( OBJECT_CONSTRUCTORS(
EphemeronHashTable, EphemeronHashTable,
ObjectHashTableBase<EphemeronHashTable, EphemeronHashTableShape>); ObjectHashTableBase<EphemeronHashTable, ObjectHashTableShape>);
}; };
class ObjectHashSetShape : public ObjectHashTableShape { class ObjectHashSetShape : public ObjectHashTableShape {
......
...@@ -6641,7 +6641,7 @@ Handle<Derived> HashTable<Derived, Shape>::NewInternal( ...@@ -6641,7 +6641,7 @@ Handle<Derived> HashTable<Derived, Shape>::NewInternal(
auto* factory = isolate->factory(); auto* factory = isolate->factory();
int length = EntryToIndex(InternalIndex(capacity)); int length = EntryToIndex(InternalIndex(capacity));
Handle<FixedArray> array = factory->NewFixedArrayWithMap( Handle<FixedArray> array = factory->NewFixedArrayWithMap(
Shape::GetMap(ReadOnlyRoots(isolate)), length, allocation); Derived::GetMap(ReadOnlyRoots(isolate)), length, allocation);
Handle<Derived> table = Handle<Derived>::cast(array); Handle<Derived> table = Handle<Derived>::cast(array);
table->SetNumberOfElements(0); table->SetNumberOfElements(0);
...@@ -8358,8 +8358,7 @@ EXTERN_DEFINE_HASH_TABLE(CompilationCacheTable, CompilationCacheShape) ...@@ -8358,8 +8358,7 @@ EXTERN_DEFINE_HASH_TABLE(CompilationCacheTable, CompilationCacheShape)
EXTERN_DEFINE_HASH_TABLE(ObjectHashSet, ObjectHashSetShape) EXTERN_DEFINE_HASH_TABLE(ObjectHashSet, ObjectHashSetShape)
EXTERN_DEFINE_OBJECT_BASE_HASH_TABLE(ObjectHashTable, ObjectHashTableShape) EXTERN_DEFINE_OBJECT_BASE_HASH_TABLE(ObjectHashTable, ObjectHashTableShape)
EXTERN_DEFINE_OBJECT_BASE_HASH_TABLE(EphemeronHashTable, EXTERN_DEFINE_OBJECT_BASE_HASH_TABLE(EphemeronHashTable, ObjectHashTableShape)
EphemeronHashTableShape)
EXTERN_DEFINE_DICTIONARY(SimpleNumberDictionary, SimpleNumberDictionaryShape) EXTERN_DEFINE_DICTIONARY(SimpleNumberDictionary, SimpleNumberDictionaryShape)
EXTERN_DEFINE_DICTIONARY(NumberDictionary, NumberDictionaryShape) EXTERN_DEFINE_DICTIONARY(NumberDictionary, NumberDictionaryShape)
......
...@@ -72,7 +72,7 @@ uint32_t StringTableShape::HashForObject(ReadOnlyRoots roots, Object object) { ...@@ -72,7 +72,7 @@ uint32_t StringTableShape::HashForObject(ReadOnlyRoots roots, Object object) {
return String::cast(object).Hash(); return String::cast(object).Hash();
} }
Handle<Map> StringTableShape::GetMap(ReadOnlyRoots roots) { Handle<Map> StringTable::GetMap(ReadOnlyRoots roots) {
return roots.string_table_map_handle(); return roots.string_table_map_handle();
} }
......
...@@ -47,8 +47,6 @@ class V8_EXPORT_PRIVATE StringTableShape : public BaseShape<StringTableKey*> { ...@@ -47,8 +47,6 @@ class V8_EXPORT_PRIVATE StringTableShape : public BaseShape<StringTableKey*> {
static inline Handle<Object> AsHandle(Isolate* isolate, Key key); static inline Handle<Object> AsHandle(Isolate* isolate, Key key);
static inline Handle<Map> GetMap(ReadOnlyRoots roots);
static const int kPrefixSize = 0; static const int kPrefixSize = 0;
static const int kEntrySize = 1; static const int kEntrySize = 1;
}; };
...@@ -64,6 +62,8 @@ EXTERN_DECLARE_HASH_TABLE(StringTable, StringTableShape) ...@@ -64,6 +62,8 @@ EXTERN_DECLARE_HASH_TABLE(StringTable, StringTableShape)
class V8_EXPORT_PRIVATE StringTable class V8_EXPORT_PRIVATE StringTable
: public HashTable<StringTable, StringTableShape> { : public HashTable<StringTable, StringTableShape> {
public: public:
static inline Handle<Map> GetMap(ReadOnlyRoots roots);
// Find string in the string table. If it is not there yet, it is // Find string in the string table. If it is not there yet, it is
// added. The return value is the string found. // added. The return value is the string found.
static Handle<String> LookupString(Isolate* isolate, Handle<String> key); static Handle<String> LookupString(Isolate* isolate, Handle<String> key);
......
...@@ -35,7 +35,6 @@ RUNTIME_FUNCTION(Runtime_SetGrow) { ...@@ -35,7 +35,6 @@ RUNTIME_FUNCTION(Runtime_SetGrow) {
return ReadOnlyRoots(isolate).undefined_value(); return ReadOnlyRoots(isolate).undefined_value();
} }
RUNTIME_FUNCTION(Runtime_SetShrink) { RUNTIME_FUNCTION(Runtime_SetShrink) {
HandleScope scope(isolate); HandleScope scope(isolate);
DCHECK_EQ(1, args.length()); DCHECK_EQ(1, args.length());
...@@ -80,7 +79,7 @@ RUNTIME_FUNCTION(Runtime_WeakCollectionDelete) { ...@@ -80,7 +79,7 @@ RUNTIME_FUNCTION(Runtime_WeakCollectionDelete) {
#ifdef DEBUG #ifdef DEBUG
DCHECK(key->IsJSReceiver()); DCHECK(key->IsJSReceiver());
DCHECK(EphemeronHashTableShape::IsLive(ReadOnlyRoots(isolate), *key)); DCHECK(EphemeronHashTable::ShapeT::IsLive(ReadOnlyRoots(isolate), *key));
Handle<EphemeronHashTable> table( Handle<EphemeronHashTable> table(
EphemeronHashTable::cast(weak_collection->table()), isolate); EphemeronHashTable::cast(weak_collection->table()), isolate);
// Should only be called when shrinking the table is necessary. See // Should only be called when shrinking the table is necessary. See
...@@ -103,7 +102,7 @@ RUNTIME_FUNCTION(Runtime_WeakCollectionSet) { ...@@ -103,7 +102,7 @@ RUNTIME_FUNCTION(Runtime_WeakCollectionSet) {
#ifdef DEBUG #ifdef DEBUG
DCHECK(key->IsJSReceiver()); DCHECK(key->IsJSReceiver());
DCHECK(EphemeronHashTableShape::IsLive(ReadOnlyRoots(isolate), *key)); DCHECK(EphemeronHashTable::ShapeT::IsLive(ReadOnlyRoots(isolate), *key));
Handle<EphemeronHashTable> table( Handle<EphemeronHashTable> table(
EphemeronHashTable::cast(weak_collection->table()), isolate); EphemeronHashTable::cast(weak_collection->table()), isolate);
// Should only be called when rehashing or resizing the table is necessary. // Should only be called when rehashing or resizing the table is necessary.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment