Skip to content

Commit 5e755c6

Browse files
targosCommit Bot
authored andcommitted
[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/+/1893346 Reviewed-by: Peter Marshall <[email protected]> Commit-Queue: Michaël Zasso <[email protected]> Cr-Commit-Position: refs/heads/master@{#64709}
1 parent c4c302d commit 5e755c6

4 files changed

Lines changed: 115 additions & 65 deletions

File tree

src/objects/dictionary-inl.h

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77

88
#include "src/objects/dictionary.h"
99

10+
#include "src/execution/isolate-utils-inl.h"
1011
#include "src/numbers/hash-seed-inl.h"
1112
#include "src/objects/hash-table-inl.h"
13+
#include "src/objects/objects-inl.h"
1214
#include "src/objects/oddball.h"
1315
#include "src/objects/property-cell-inl.h"
1416

@@ -27,10 +29,66 @@ template <typename Derived, typename Shape>
2729
Dictionary<Derived, Shape>::Dictionary(Address ptr)
2830
: HashTable<Derived, Shape>(ptr) {}
2931

32+
template <typename Derived, typename Shape>
33+
Object Dictionary<Derived, Shape>::ValueAt(InternalIndex entry) {
34+
Isolate* isolate = GetIsolateForPtrCompr(*this);
35+
return ValueAt(isolate, entry);
36+
}
37+
38+
template <typename Derived, typename Shape>
39+
Object Dictionary<Derived, Shape>::ValueAt(Isolate* isolate,
40+
InternalIndex entry) {
41+
return this->get(isolate, DerivedHashTable::EntryToIndex(entry) +
42+
Derived::kEntryValueIndex);
43+
}
44+
45+
template <typename Derived, typename Shape>
46+
void Dictionary<Derived, Shape>::ValueAtPut(InternalIndex entry, Object value) {
47+
this->set(DerivedHashTable::EntryToIndex(entry) + Derived::kEntryValueIndex,
48+
value);
49+
}
50+
51+
template <typename Derived, typename Shape>
52+
PropertyDetails Dictionary<Derived, Shape>::DetailsAt(InternalIndex entry) {
53+
return Shape::DetailsAt(Derived::cast(*this), entry);
54+
}
55+
56+
template <typename Derived, typename Shape>
57+
void Dictionary<Derived, Shape>::DetailsAtPut(Isolate* isolate,
58+
InternalIndex entry,
59+
PropertyDetails value) {
60+
Shape::DetailsAtPut(isolate, Derived::cast(*this), entry, value);
61+
}
62+
3063
template <typename Derived, typename Shape>
3164
BaseNameDictionary<Derived, Shape>::BaseNameDictionary(Address ptr)
3265
: Dictionary<Derived, Shape>(ptr) {}
3366

67+
template <typename Derived, typename Shape>
68+
void BaseNameDictionary<Derived, Shape>::SetNextEnumerationIndex(int index) {
69+
DCHECK_NE(0, index);
70+
this->set(kNextEnumerationIndexIndex, Smi::FromInt(index));
71+
}
72+
73+
template <typename Derived, typename Shape>
74+
int BaseNameDictionary<Derived, Shape>::NextEnumerationIndex() {
75+
return Smi::ToInt(this->get(kNextEnumerationIndexIndex));
76+
}
77+
78+
template <typename Derived, typename Shape>
79+
void BaseNameDictionary<Derived, Shape>::SetHash(int hash) {
80+
DCHECK(PropertyArray::HashField::is_valid(hash));
81+
this->set(kObjectHashIndex, Smi::FromInt(hash));
82+
}
83+
84+
template <typename Derived, typename Shape>
85+
int BaseNameDictionary<Derived, Shape>::Hash() const {
86+
Object hash_obj = this->get(kObjectHashIndex);
87+
int hash = Smi::ToInt(hash_obj);
88+
DCHECK(PropertyArray::HashField::is_valid(hash));
89+
return hash;
90+
}
91+
3492
GlobalDictionary::GlobalDictionary(Address ptr)
3593
: BaseNameDictionary<GlobalDictionary, GlobalDictionaryShape>(ptr) {
3694
SLOW_DCHECK(IsGlobalDictionary());
@@ -91,6 +149,26 @@ void Dictionary<Derived, Shape>::SetEntry(Isolate* isolate, InternalIndex entry,
91149
if (Shape::kHasDetails) DetailsAtPut(isolate, entry, details);
92150
}
93151

152+
template <typename Key>
153+
template <typename Dictionary>
154+
PropertyDetails BaseDictionaryShape<Key>::DetailsAt(Dictionary dict,
155+
InternalIndex entry) {
156+
STATIC_ASSERT(Dictionary::kEntrySize == 3);
157+
DCHECK(entry.is_found());
158+
return PropertyDetails(Smi::cast(dict.get(Dictionary::EntryToIndex(entry) +
159+
Dictionary::kEntryDetailsIndex)));
160+
}
161+
162+
template <typename Key>
163+
template <typename Dictionary>
164+
void BaseDictionaryShape<Key>::DetailsAtPut(Isolate* isolate, Dictionary dict,
165+
InternalIndex entry,
166+
PropertyDetails value) {
167+
STATIC_ASSERT(Dictionary::kEntrySize == 3);
168+
dict.set(Dictionary::EntryToIndex(entry) + Dictionary::kEntryDetailsIndex,
169+
value.AsSmi());
170+
}
171+
94172
Object GlobalDictionaryShape::Unwrap(Object object) {
95173
return PropertyCell::cast(object).name();
96174
}

src/objects/dictionary.h

Lines changed: 12 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,18 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) Dictionary
3131
public:
3232
using Key = typename Shape::Key;
3333
// Returns the value at entry.
34-
Object ValueAt(InternalIndex entry) {
35-
Isolate* isolate = GetIsolateForPtrCompr(*this);
36-
return ValueAt(isolate, entry);
37-
}
38-
Object ValueAt(Isolate* isolate, InternalIndex entry) {
39-
return this->get(isolate, DerivedHashTable::EntryToIndex(entry) +
40-
Derived::kEntryValueIndex);
41-
}
34+
inline Object ValueAt(InternalIndex entry);
35+
inline Object ValueAt(Isolate* isolate, InternalIndex entry);
4236

4337
// Set the value for entry.
44-
void ValueAtPut(InternalIndex entry, Object value) {
45-
this->set(DerivedHashTable::EntryToIndex(entry) + Derived::kEntryValueIndex,
46-
value);
47-
}
38+
inline void ValueAtPut(InternalIndex entry, Object value);
4839

4940
// Returns the property details for the property at entry.
50-
PropertyDetails DetailsAt(InternalIndex entry) {
51-
return Shape::DetailsAt(Derived::cast(*this), entry);
52-
}
41+
inline PropertyDetails DetailsAt(InternalIndex entry);
5342

5443
// Set the details for entry.
55-
void DetailsAtPut(Isolate* isolate, InternalIndex entry,
56-
PropertyDetails value) {
57-
Shape::DetailsAtPut(isolate, Derived::cast(*this), entry, value);
58-
}
44+
inline void DetailsAtPut(Isolate* isolate, InternalIndex entry,
45+
PropertyDetails value);
5946

6047
// Delete a property from the dictionary.
6148
V8_WARN_UNUSED_RESULT static Handle<Derived> DeleteEntry(
@@ -104,21 +91,11 @@ class BaseDictionaryShape : public BaseShape<Key> {
10491
public:
10592
static const bool kHasDetails = true;
10693
template <typename Dictionary>
107-
static inline PropertyDetails DetailsAt(Dictionary dict,
108-
InternalIndex entry) {
109-
STATIC_ASSERT(Dictionary::kEntrySize == 3);
110-
DCHECK(entry.is_found());
111-
return PropertyDetails(Smi::cast(dict.get(Dictionary::EntryToIndex(entry) +
112-
Dictionary::kEntryDetailsIndex)));
113-
}
94+
static inline PropertyDetails DetailsAt(Dictionary dict, InternalIndex entry);
11495

11596
template <typename Dictionary>
11697
static inline void DetailsAtPut(Isolate* isolate, Dictionary dict,
117-
InternalIndex entry, PropertyDetails value) {
118-
STATIC_ASSERT(Dictionary::kEntrySize == 3);
119-
dict.set(Dictionary::EntryToIndex(entry) + Dictionary::kEntryDetailsIndex,
120-
value.AsSmi());
121-
}
98+
InternalIndex entry, PropertyDetails value);
12299
};
123100

124101
class NameDictionaryShape : public BaseDictionaryShape<Handle<Name>> {
@@ -146,26 +123,11 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) BaseNameDictionary
146123
static const int kEntryValueIndex = 1;
147124

148125
// Accessors for next enumeration index.
149-
void SetNextEnumerationIndex(int index) {
150-
DCHECK_NE(0, index);
151-
this->set(kNextEnumerationIndexIndex, Smi::FromInt(index));
152-
}
126+
inline void SetNextEnumerationIndex(int index);
127+
inline int NextEnumerationIndex();
153128

154-
int NextEnumerationIndex() {
155-
return Smi::ToInt(this->get(kNextEnumerationIndexIndex));
156-
}
157-
158-
void SetHash(int hash) {
159-
DCHECK(PropertyArray::HashField::is_valid(hash));
160-
this->set(kObjectHashIndex, Smi::FromInt(hash));
161-
}
162-
163-
int Hash() const {
164-
Object hash_obj = this->get(kObjectHashIndex);
165-
int hash = Smi::ToInt(hash_obj);
166-
DCHECK(PropertyArray::HashField::is_valid(hash));
167-
return hash;
168-
}
129+
inline void SetHash(int hash);
130+
inline int Hash() const;
169131

170132
// Creates a new dictionary.
171133
V8_WARN_UNUSED_RESULT static Handle<Derived> New(

src/objects/hash-table-inl.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "src/objects/hash-table.h"
99

10+
#include "src/execution/isolate-utils-inl.h"
1011
#include "src/heap/heap.h"
1112
#include "src/objects/fixed-array-inl.h"
1213
#include "src/objects/heap-object-inl.h"
@@ -182,6 +183,17 @@ bool HashTable<Derived, Shape>::ToKey(Isolate* isolate, InternalIndex entry,
182183
return true;
183184
}
184185

186+
template <typename Derived, typename Shape>
187+
Object HashTable<Derived, Shape>::KeyAt(InternalIndex entry) {
188+
Isolate* isolate = GetIsolateForPtrCompr(*this);
189+
return KeyAt(isolate, entry);
190+
}
191+
192+
template <typename Derived, typename Shape>
193+
Object HashTable<Derived, Shape>::KeyAt(Isolate* isolate, InternalIndex entry) {
194+
return get(isolate, EntryToIndex(entry) + kEntryKeyIndex);
195+
}
196+
185197
template <typename Derived, typename Shape>
186198
void HashTable<Derived, Shape>::set_key(int index, Object value) {
187199
DCHECK(!IsEphemeronHashTable());
@@ -195,6 +207,16 @@ void HashTable<Derived, Shape>::set_key(int index, Object value,
195207
FixedArray::set(index, value, mode);
196208
}
197209

210+
template <typename Derived, typename Shape>
211+
void HashTable<Derived, Shape>::SetCapacity(int capacity) {
212+
// To scale a computed hash code to fit within the hash table, we
213+
// use bit-wise AND with a mask, so the capacity must be positive
214+
// and non-zero.
215+
DCHECK_GT(capacity, 0);
216+
DCHECK_LE(capacity, kMaxCapacity);
217+
set(kCapacityIndex, Smi::FromInt(capacity));
218+
}
219+
198220
template <typename KeyT>
199221
bool BaseShape<KeyT>::IsKey(ReadOnlyRoots roots, Object key) {
200222
return IsLive(roots, key);

src/objects/hash-table.h

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,8 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) HashTable
153153
inline bool ToKey(Isolate* isolate, InternalIndex entry, Object* out_k);
154154

155155
// Returns the key at entry.
156-
Object KeyAt(InternalIndex entry) {
157-
Isolate* isolate = GetIsolateForPtrCompr(*this);
158-
return KeyAt(isolate, entry);
159-
}
160-
Object KeyAt(Isolate* isolate, InternalIndex entry) {
161-
return get(isolate, EntryToIndex(entry) + kEntryKeyIndex);
162-
}
156+
inline Object KeyAt(InternalIndex entry);
157+
inline Object KeyAt(Isolate* isolate, InternalIndex entry);
163158

164159
static const int kElementsStartIndex = kPrefixStartIndex + Shape::kPrefixSize;
165160
static const int kEntrySize = Shape::kEntrySize;
@@ -230,14 +225,7 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) HashTable
230225
kMaxRegularHeapObjectSize);
231226

232227
// Sets the capacity of the hash table.
233-
void SetCapacity(int capacity) {
234-
// To scale a computed hash code to fit within the hash table, we
235-
// use bit-wise AND with a mask, so the capacity must be positive
236-
// and non-zero.
237-
DCHECK_GT(capacity, 0);
238-
DCHECK_LE(capacity, kMaxCapacity);
239-
set(kCapacityIndex, Smi::FromInt(capacity));
240-
}
228+
inline void SetCapacity(int capacity);
241229

242230
// Returns _expected_ if one of entries given by the first _probe_ probes is
243231
// equal to _expected_. Otherwise, returns the entry given by the probe

0 commit comments

Comments
 (0)