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 @@
#include "src/objects/dictionary.h"
#include "src/execution/isolate-utils-inl.h"
#include "src/numbers/hash-seed-inl.h"
#include "src/objects/hash-table-inl.h"
#include "src/objects/objects-inl.h"
#include "src/objects/oddball.h"
#include "src/objects/property-cell-inl.h"
......@@ -27,10 +29,66 @@ template <typename Derived, typename Shape>
Dictionary<Derived, Shape>::Dictionary(Address 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>
BaseNameDictionary<Derived, Shape>::BaseNameDictionary(Address 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)
: BaseNameDictionary<GlobalDictionary, GlobalDictionaryShape>(ptr) {
SLOW_DCHECK(IsGlobalDictionary());
......@@ -91,6 +149,26 @@ void Dictionary<Derived, Shape>::SetEntry(Isolate* isolate, InternalIndex entry,
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) {
return PropertyCell::cast(object).name();
}
......
......@@ -31,31 +31,18 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) Dictionary
public:
using Key = typename Shape::Key;
// Returns the value at entry.
Object ValueAt(InternalIndex entry) {
Isolate* isolate = GetIsolateForPtrCompr(*this);
return ValueAt(isolate, entry);
}
Object ValueAt(Isolate* isolate, InternalIndex entry) {
return this->get(isolate, DerivedHashTable::EntryToIndex(entry) +
Derived::kEntryValueIndex);
}
inline Object ValueAt(InternalIndex entry);
inline Object ValueAt(Isolate* isolate, InternalIndex entry);
// Set the value for entry.
void ValueAtPut(InternalIndex entry, Object value) {
this->set(DerivedHashTable::EntryToIndex(entry) + Derived::kEntryValueIndex,
value);
}
inline void ValueAtPut(InternalIndex entry, Object value);
// Returns the property details for the property at entry.
PropertyDetails DetailsAt(InternalIndex entry) {
return Shape::DetailsAt(Derived::cast(*this), entry);
}
inline PropertyDetails DetailsAt(InternalIndex entry);
// Set the details for entry.
void DetailsAtPut(Isolate* isolate, InternalIndex entry,
PropertyDetails value) {
Shape::DetailsAtPut(isolate, Derived::cast(*this), entry, value);
}
inline void DetailsAtPut(Isolate* isolate, InternalIndex entry,
PropertyDetails value);
// Delete a property from the dictionary.
V8_WARN_UNUSED_RESULT static Handle<Derived> DeleteEntry(
......@@ -104,21 +91,11 @@ class BaseDictionaryShape : public BaseShape<Key> {
public:
static const bool kHasDetails = true;
template <typename Dictionary>
static inline PropertyDetails 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)));
}
static inline PropertyDetails DetailsAt(Dictionary dict, InternalIndex entry);
template <typename Dictionary>
static inline void DetailsAtPut(Isolate* isolate, Dictionary dict,
InternalIndex entry, PropertyDetails value) {
STATIC_ASSERT(Dictionary::kEntrySize == 3);
dict.set(Dictionary::EntryToIndex(entry) + Dictionary::kEntryDetailsIndex,
value.AsSmi());
}
InternalIndex entry, PropertyDetails value);
};
class NameDictionaryShape : public BaseDictionaryShape<Handle<Name>> {
......@@ -146,26 +123,11 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) BaseNameDictionary
static const int kEntryValueIndex = 1;
// Accessors for next enumeration index.
void SetNextEnumerationIndex(int index) {
DCHECK_NE(0, index);
this->set(kNextEnumerationIndexIndex, Smi::FromInt(index));
}
inline void SetNextEnumerationIndex(int index);
inline int NextEnumerationIndex();
int NextEnumerationIndex() {
return Smi::ToInt(this->get(kNextEnumerationIndexIndex));
}
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;
}
inline void SetHash(int hash);
inline int Hash() const;
// Creates a new dictionary.
V8_WARN_UNUSED_RESULT static Handle<Derived> New(
......
......@@ -7,6 +7,7 @@
#include "src/objects/hash-table.h"
#include "src/execution/isolate-utils-inl.h"
#include "src/heap/heap.h"
#include "src/objects/fixed-array-inl.h"
#include "src/objects/heap-object-inl.h"
......@@ -182,6 +183,17 @@ bool HashTable<Derived, Shape>::ToKey(Isolate* isolate, InternalIndex entry,
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>
void HashTable<Derived, Shape>::set_key(int index, Object value) {
DCHECK(!IsEphemeronHashTable());
......@@ -195,6 +207,16 @@ void HashTable<Derived, Shape>::set_key(int index, Object value,
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>
bool BaseShape<KeyT>::IsKey(ReadOnlyRoots roots, Object key) {
return IsLive(roots, key);
......
......@@ -153,13 +153,8 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) HashTable
inline bool ToKey(Isolate* isolate, InternalIndex entry, Object* out_k);
// Returns the key at entry.
Object KeyAt(InternalIndex entry) {
Isolate* isolate = GetIsolateForPtrCompr(*this);
return KeyAt(isolate, entry);
}
Object KeyAt(Isolate* isolate, InternalIndex entry) {
return get(isolate, EntryToIndex(entry) + kEntryKeyIndex);
}
inline Object KeyAt(InternalIndex entry);
inline Object KeyAt(Isolate* isolate, InternalIndex entry);
static const int kElementsStartIndex = kPrefixStartIndex + Shape::kPrefixSize;
static const int kEntrySize = Shape::kEntrySize;
......@@ -230,14 +225,7 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) HashTable
kMaxRegularHeapObjectSize);
// Sets the capacity of the hash table.
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));
}
inline void SetCapacity(int capacity);
// Returns _expected_ if one of entries given by the first _probe_ probes is
// 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