Commit 5e755c6e authored by Michaël Zasso's avatar Michaël Zasso Committed by Commit Bot

[objects] Move functions to inline headers

This moves a series of functions from dictionary.h and hash-table.h
to resp. dictionary-inl.h and hash-table-inl.h.
The functions that were moved all somehow use other functions that
are defined in -inl.h files.

This change fixes the Node.js Windows builds.

Change-Id: I0bbf0222beb3619a5e6f1fb451bc78691025de65
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1893346Reviewed-by: 's avatarPeter Marshall <petermarshall@chromium.org>
Commit-Queue: Michaël Zasso <mic.besace@gmail.com>
Cr-Commit-Position: refs/heads/master@{#64709}
parent c4c302d1
...@@ -7,8 +7,10 @@ ...@@ -7,8 +7,10 @@
#include "src/objects/dictionary.h" #include "src/objects/dictionary.h"
#include "src/execution/isolate-utils-inl.h"
#include "src/numbers/hash-seed-inl.h" #include "src/numbers/hash-seed-inl.h"
#include "src/objects/hash-table-inl.h" #include "src/objects/hash-table-inl.h"
#include "src/objects/objects-inl.h"
#include "src/objects/oddball.h" #include "src/objects/oddball.h"
#include "src/objects/property-cell-inl.h" #include "src/objects/property-cell-inl.h"
...@@ -27,10 +29,66 @@ template <typename Derived, typename Shape> ...@@ -27,10 +29,66 @@ template <typename Derived, typename Shape>
Dictionary<Derived, Shape>::Dictionary(Address ptr) Dictionary<Derived, Shape>::Dictionary(Address ptr)
: HashTable<Derived, Shape>(ptr) {} : HashTable<Derived, Shape>(ptr) {}
template <typename Derived, typename Shape>
Object Dictionary<Derived, Shape>::ValueAt(InternalIndex entry) {
Isolate* isolate = GetIsolateForPtrCompr(*this);
return ValueAt(isolate, entry);
}
template <typename Derived, typename Shape>
Object Dictionary<Derived, Shape>::ValueAt(Isolate* isolate,
InternalIndex entry) {
return this->get(isolate, DerivedHashTable::EntryToIndex(entry) +
Derived::kEntryValueIndex);
}
template <typename Derived, typename Shape>
void Dictionary<Derived, Shape>::ValueAtPut(InternalIndex entry, Object value) {
this->set(DerivedHashTable::EntryToIndex(entry) + Derived::kEntryValueIndex,
value);
}
template <typename Derived, typename Shape>
PropertyDetails Dictionary<Derived, Shape>::DetailsAt(InternalIndex entry) {
return Shape::DetailsAt(Derived::cast(*this), entry);
}
template <typename Derived, typename Shape>
void Dictionary<Derived, Shape>::DetailsAtPut(Isolate* isolate,
InternalIndex entry,
PropertyDetails value) {
Shape::DetailsAtPut(isolate, Derived::cast(*this), entry, value);
}
template <typename Derived, typename Shape> template <typename Derived, typename Shape>
BaseNameDictionary<Derived, Shape>::BaseNameDictionary(Address ptr) BaseNameDictionary<Derived, Shape>::BaseNameDictionary(Address ptr)
: Dictionary<Derived, Shape>(ptr) {} : Dictionary<Derived, Shape>(ptr) {}
template <typename Derived, typename Shape>
void BaseNameDictionary<Derived, Shape>::SetNextEnumerationIndex(int index) {
DCHECK_NE(0, index);
this->set(kNextEnumerationIndexIndex, Smi::FromInt(index));
}
template <typename Derived, typename Shape>
int BaseNameDictionary<Derived, Shape>::NextEnumerationIndex() {
return Smi::ToInt(this->get(kNextEnumerationIndexIndex));
}
template <typename Derived, typename Shape>
void BaseNameDictionary<Derived, Shape>::SetHash(int hash) {
DCHECK(PropertyArray::HashField::is_valid(hash));
this->set(kObjectHashIndex, Smi::FromInt(hash));
}
template <typename Derived, typename Shape>
int BaseNameDictionary<Derived, Shape>::Hash() const {
Object hash_obj = this->get(kObjectHashIndex);
int hash = Smi::ToInt(hash_obj);
DCHECK(PropertyArray::HashField::is_valid(hash));
return hash;
}
GlobalDictionary::GlobalDictionary(Address ptr) GlobalDictionary::GlobalDictionary(Address ptr)
: BaseNameDictionary<GlobalDictionary, GlobalDictionaryShape>(ptr) { : BaseNameDictionary<GlobalDictionary, GlobalDictionaryShape>(ptr) {
SLOW_DCHECK(IsGlobalDictionary()); SLOW_DCHECK(IsGlobalDictionary());
...@@ -91,6 +149,26 @@ void Dictionary<Derived, Shape>::SetEntry(Isolate* isolate, InternalIndex entry, ...@@ -91,6 +149,26 @@ void Dictionary<Derived, Shape>::SetEntry(Isolate* isolate, InternalIndex entry,
if (Shape::kHasDetails) DetailsAtPut(isolate, entry, details); if (Shape::kHasDetails) DetailsAtPut(isolate, entry, details);
} }
template <typename Key>
template <typename Dictionary>
PropertyDetails BaseDictionaryShape<Key>::DetailsAt(Dictionary dict,
InternalIndex entry) {
STATIC_ASSERT(Dictionary::kEntrySize == 3);
DCHECK(entry.is_found());
return PropertyDetails(Smi::cast(dict.get(Dictionary::EntryToIndex(entry) +
Dictionary::kEntryDetailsIndex)));
}
template <typename Key>
template <typename Dictionary>
void BaseDictionaryShape<Key>::DetailsAtPut(Isolate* isolate, Dictionary dict,
InternalIndex entry,
PropertyDetails value) {
STATIC_ASSERT(Dictionary::kEntrySize == 3);
dict.set(Dictionary::EntryToIndex(entry) + Dictionary::kEntryDetailsIndex,
value.AsSmi());
}
Object GlobalDictionaryShape::Unwrap(Object object) { Object GlobalDictionaryShape::Unwrap(Object object) {
return PropertyCell::cast(object).name(); return PropertyCell::cast(object).name();
} }
......
...@@ -31,31 +31,18 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) Dictionary ...@@ -31,31 +31,18 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) Dictionary
public: public:
using Key = typename Shape::Key; using Key = typename Shape::Key;
// Returns the value at entry. // Returns the value at entry.
Object ValueAt(InternalIndex entry) { inline Object ValueAt(InternalIndex entry);
Isolate* isolate = GetIsolateForPtrCompr(*this); inline Object ValueAt(Isolate* isolate, InternalIndex entry);
return ValueAt(isolate, entry);
}
Object ValueAt(Isolate* isolate, InternalIndex entry) {
return this->get(isolate, DerivedHashTable::EntryToIndex(entry) +
Derived::kEntryValueIndex);
}
// Set the value for entry. // Set the value for entry.
void ValueAtPut(InternalIndex entry, Object value) { inline void ValueAtPut(InternalIndex entry, Object value);
this->set(DerivedHashTable::EntryToIndex(entry) + Derived::kEntryValueIndex,
value);
}
// Returns the property details for the property at entry. // Returns the property details for the property at entry.
PropertyDetails DetailsAt(InternalIndex entry) { inline PropertyDetails DetailsAt(InternalIndex entry);
return Shape::DetailsAt(Derived::cast(*this), entry);
}
// Set the details for entry. // Set the details for entry.
void DetailsAtPut(Isolate* isolate, InternalIndex entry, inline void DetailsAtPut(Isolate* isolate, InternalIndex entry,
PropertyDetails value) { PropertyDetails value);
Shape::DetailsAtPut(isolate, Derived::cast(*this), entry, value);
}
// Delete a property from the dictionary. // Delete a property from the dictionary.
V8_WARN_UNUSED_RESULT static Handle<Derived> DeleteEntry( V8_WARN_UNUSED_RESULT static Handle<Derived> DeleteEntry(
...@@ -104,21 +91,11 @@ class BaseDictionaryShape : public BaseShape<Key> { ...@@ -104,21 +91,11 @@ class BaseDictionaryShape : public BaseShape<Key> {
public: public:
static const bool kHasDetails = true; static const bool kHasDetails = true;
template <typename Dictionary> template <typename Dictionary>
static inline PropertyDetails DetailsAt(Dictionary dict, static inline PropertyDetails DetailsAt(Dictionary dict, InternalIndex entry);
InternalIndex entry) {
STATIC_ASSERT(Dictionary::kEntrySize == 3);
DCHECK(entry.is_found());
return PropertyDetails(Smi::cast(dict.get(Dictionary::EntryToIndex(entry) +
Dictionary::kEntryDetailsIndex)));
}
template <typename Dictionary> template <typename Dictionary>
static inline void DetailsAtPut(Isolate* isolate, Dictionary dict, static inline void DetailsAtPut(Isolate* isolate, Dictionary dict,
InternalIndex entry, PropertyDetails value) { InternalIndex entry, PropertyDetails value);
STATIC_ASSERT(Dictionary::kEntrySize == 3);
dict.set(Dictionary::EntryToIndex(entry) + Dictionary::kEntryDetailsIndex,
value.AsSmi());
}
}; };
class NameDictionaryShape : public BaseDictionaryShape<Handle<Name>> { class NameDictionaryShape : public BaseDictionaryShape<Handle<Name>> {
...@@ -146,26 +123,11 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) BaseNameDictionary ...@@ -146,26 +123,11 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) BaseNameDictionary
static const int kEntryValueIndex = 1; static const int kEntryValueIndex = 1;
// Accessors for next enumeration index. // Accessors for next enumeration index.
void SetNextEnumerationIndex(int index) { inline void SetNextEnumerationIndex(int index);
DCHECK_NE(0, index); inline int NextEnumerationIndex();
this->set(kNextEnumerationIndexIndex, Smi::FromInt(index));
}
int NextEnumerationIndex() { inline void SetHash(int hash);
return Smi::ToInt(this->get(kNextEnumerationIndexIndex)); inline int Hash() const;
}
void SetHash(int hash) {
DCHECK(PropertyArray::HashField::is_valid(hash));
this->set(kObjectHashIndex, Smi::FromInt(hash));
}
int Hash() const {
Object hash_obj = this->get(kObjectHashIndex);
int hash = Smi::ToInt(hash_obj);
DCHECK(PropertyArray::HashField::is_valid(hash));
return hash;
}
// Creates a new dictionary. // Creates a new dictionary.
V8_WARN_UNUSED_RESULT static Handle<Derived> New( V8_WARN_UNUSED_RESULT static Handle<Derived> New(
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "src/objects/hash-table.h" #include "src/objects/hash-table.h"
#include "src/execution/isolate-utils-inl.h"
#include "src/heap/heap.h" #include "src/heap/heap.h"
#include "src/objects/fixed-array-inl.h" #include "src/objects/fixed-array-inl.h"
#include "src/objects/heap-object-inl.h" #include "src/objects/heap-object-inl.h"
...@@ -182,6 +183,17 @@ bool HashTable<Derived, Shape>::ToKey(Isolate* isolate, InternalIndex entry, ...@@ -182,6 +183,17 @@ bool HashTable<Derived, Shape>::ToKey(Isolate* isolate, InternalIndex entry,
return true; return true;
} }
template <typename Derived, typename Shape>
Object HashTable<Derived, Shape>::KeyAt(InternalIndex entry) {
Isolate* isolate = GetIsolateForPtrCompr(*this);
return KeyAt(isolate, entry);
}
template <typename Derived, typename Shape>
Object HashTable<Derived, Shape>::KeyAt(Isolate* isolate, InternalIndex entry) {
return get(isolate, EntryToIndex(entry) + kEntryKeyIndex);
}
template <typename Derived, typename Shape> template <typename Derived, typename Shape>
void HashTable<Derived, Shape>::set_key(int index, Object value) { void HashTable<Derived, Shape>::set_key(int index, Object value) {
DCHECK(!IsEphemeronHashTable()); DCHECK(!IsEphemeronHashTable());
...@@ -195,6 +207,16 @@ void HashTable<Derived, Shape>::set_key(int index, Object value, ...@@ -195,6 +207,16 @@ void HashTable<Derived, Shape>::set_key(int index, Object value,
FixedArray::set(index, value, mode); FixedArray::set(index, value, mode);
} }
template <typename Derived, typename Shape>
void HashTable<Derived, Shape>::SetCapacity(int capacity) {
// To scale a computed hash code to fit within the hash table, we
// use bit-wise AND with a mask, so the capacity must be positive
// and non-zero.
DCHECK_GT(capacity, 0);
DCHECK_LE(capacity, kMaxCapacity);
set(kCapacityIndex, Smi::FromInt(capacity));
}
template <typename KeyT> template <typename KeyT>
bool BaseShape<KeyT>::IsKey(ReadOnlyRoots roots, Object key) { bool BaseShape<KeyT>::IsKey(ReadOnlyRoots roots, Object key) {
return IsLive(roots, key); return IsLive(roots, key);
......
...@@ -153,13 +153,8 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) HashTable ...@@ -153,13 +153,8 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) HashTable
inline bool ToKey(Isolate* isolate, InternalIndex entry, Object* out_k); inline bool ToKey(Isolate* isolate, InternalIndex entry, Object* out_k);
// Returns the key at entry. // Returns the key at entry.
Object KeyAt(InternalIndex entry) { inline Object KeyAt(InternalIndex entry);
Isolate* isolate = GetIsolateForPtrCompr(*this); inline Object KeyAt(Isolate* isolate, InternalIndex entry);
return KeyAt(isolate, entry);
}
Object KeyAt(Isolate* isolate, InternalIndex entry) {
return get(isolate, EntryToIndex(entry) + kEntryKeyIndex);
}
static const int kElementsStartIndex = kPrefixStartIndex + Shape::kPrefixSize; static const int kElementsStartIndex = kPrefixStartIndex + Shape::kPrefixSize;
static const int kEntrySize = Shape::kEntrySize; static const int kEntrySize = Shape::kEntrySize;
...@@ -230,14 +225,7 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) HashTable ...@@ -230,14 +225,7 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) HashTable
kMaxRegularHeapObjectSize); kMaxRegularHeapObjectSize);
// Sets the capacity of the hash table. // Sets the capacity of the hash table.
void SetCapacity(int capacity) { inline void SetCapacity(int capacity);
// To scale a computed hash code to fit within the hash table, we
// use bit-wise AND with a mask, so the capacity must be positive
// and non-zero.
DCHECK_GT(capacity, 0);
DCHECK_LE(capacity, kMaxCapacity);
set(kCapacityIndex, Smi::FromInt(capacity));
}
// Returns _expected_ if one of entries given by the first _probe_ probes is // Returns _expected_ if one of entries given by the first _probe_ probes is
// equal to _expected_. Otherwise, returns the entry given by the probe // equal to _expected_. Otherwise, returns the entry given by the probe
......
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