Skip to content

Commit

Permalink
deps: V8: backport 5e755c6ee6d3
Browse files Browse the repository at this point in the history
Original commit message:

    [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}

Refs: v8/v8@5e755c6

Backport-PR-URL: #30513
PR-URL: #30020
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Jiawen Geng <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
  • Loading branch information
targos authored and MylesBorins committed Nov 21, 2019
1 parent fe99841 commit 9c356ba
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 62 deletions.
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

# Reset this number to 0 on major V8 upgrades.
# Increment by one for each non-official patch applied to deps/v8.
'v8_embedder_string': '-node.16',
'v8_embedder_string': '-node.17',

##### V8 defaults for Node.js #####

Expand Down
73 changes: 73 additions & 0 deletions deps/v8/src/objects/dictionary-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -27,10 +29,62 @@ 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(int entry) {
Isolate* isolate = GetIsolateForPtrCompr(*this);
return ValueAt(isolate, entry);
}

template <typename Derived, typename Shape>
Object Dictionary<Derived, Shape>::ValueAt(Isolate* isolate, int entry) {
return this->get(isolate, DerivedHashTable::EntryToIndex(entry) + 1);
}

template <typename Derived, typename Shape>
void Dictionary<Derived, Shape>::ValueAtPut(int entry, Object value) {
this->set(DerivedHashTable::EntryToIndex(entry) + 1, value);
}

template <typename Derived, typename Shape>
PropertyDetails Dictionary<Derived, Shape>::DetailsAt(int entry) {
return Shape::DetailsAt(Derived::cast(*this), entry);
}

template <typename Derived, typename Shape>
void Dictionary<Derived, Shape>::DetailsAtPut(Isolate* isolate, int 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());
Expand Down Expand Up @@ -90,6 +144,25 @@ void Dictionary<Derived, Shape>::SetEntry(Isolate* isolate, int entry,
if (Shape::kHasDetails) DetailsAtPut(isolate, entry, details);
}

template <typename Key>
template <typename Dictionary>
PropertyDetails BaseDictionaryShape<Key>::DetailsAt(Dictionary dict,
int entry) {
STATIC_ASSERT(Dictionary::kEntrySize == 3);
DCHECK_GE(entry, 0); // Not found is -1, which is not caught by get().
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,
int 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();
}
Expand Down
57 changes: 11 additions & 46 deletions deps/v8/src/objects/dictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,17 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) Dictionary
public:
using Key = typename Shape::Key;
// Returns the value at entry.
Object ValueAt(int entry) {
Isolate* isolate = GetIsolateForPtrCompr(*this);
return ValueAt(isolate, entry);
}
Object ValueAt(Isolate* isolate, int entry) {
return this->get(isolate, DerivedHashTable::EntryToIndex(entry) + 1);
}
inline Object ValueAt(int entry);
inline Object ValueAt(Isolate* isolate, int entry);

// Set the value for entry.
void ValueAtPut(int entry, Object value) {
this->set(DerivedHashTable::EntryToIndex(entry) + 1, value);
}
inline void ValueAtPut(int entry, Object value);

// Returns the property details for the property at entry.
PropertyDetails DetailsAt(int entry) {
return Shape::DetailsAt(Derived::cast(*this), entry);
}
inline PropertyDetails DetailsAt(int entry);

// Set the details for entry.
void DetailsAtPut(Isolate* isolate, int entry, PropertyDetails value) {
Shape::DetailsAtPut(isolate, Derived::cast(*this), entry, value);
}
inline void DetailsAtPut(Isolate* isolate, int entry, PropertyDetails value);

// Delete a property from the dictionary.
V8_WARN_UNUSED_RESULT static Handle<Derived> DeleteEntry(
Expand Down Expand Up @@ -100,20 +89,11 @@ class BaseDictionaryShape : public BaseShape<Key> {
public:
static const bool kHasDetails = true;
template <typename Dictionary>
static inline PropertyDetails DetailsAt(Dictionary dict, int entry) {
STATIC_ASSERT(Dictionary::kEntrySize == 3);
DCHECK_GE(entry, 0); // Not found is -1, which is not caught by get().
return PropertyDetails(Smi::cast(dict.get(Dictionary::EntryToIndex(entry) +
Dictionary::kEntryDetailsIndex)));
}
static inline PropertyDetails DetailsAt(Dictionary dict, int entry);

template <typename Dictionary>
static inline void DetailsAtPut(Isolate* isolate, Dictionary dict, int entry,
PropertyDetails value) {
STATIC_ASSERT(Dictionary::kEntrySize == 3);
dict.set(Dictionary::EntryToIndex(entry) + Dictionary::kEntryDetailsIndex,
value.AsSmi());
}
PropertyDetails value);
};

class NameDictionaryShape : public BaseDictionaryShape<Handle<Name>> {
Expand Down Expand Up @@ -141,26 +121,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(
Expand Down
22 changes: 22 additions & 0 deletions deps/v8/src/objects/hash-table-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -178,6 +179,17 @@ bool HashTable<Derived, Shape>::ToKey(Isolate* isolate, int entry,
return true;
}

template <typename Derived, typename Shape>
Object HashTable<Derived, Shape>::KeyAt(int entry) {
Isolate* isolate = GetIsolateForPtrCompr(*this);
return KeyAt(isolate, entry);
}

template <typename Derived, typename Shape>
Object HashTable<Derived, Shape>::KeyAt(Isolate* isolate, int entry) {
return get(isolate, EntryToIndex(entry) + kEntryKeyIndex);
}

template <typename Derived, typename Shape>
void HashTable<Derived, Shape>::set_key(int index, Object value) {
DCHECK(!IsEphemeronHashTable());
Expand All @@ -191,6 +203,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);
Expand Down
18 changes: 3 additions & 15 deletions deps/v8/src/objects/hash-table.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,8 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) HashTable
inline bool ToKey(Isolate* isolate, int entry, Object* out_k);

// Returns the key at entry.
Object KeyAt(int entry) {
Isolate* isolate = GetIsolateForPtrCompr(*this);
return KeyAt(isolate, entry);
}
Object KeyAt(Isolate* isolate, int entry) {
return get(isolate, EntryToIndex(entry) + kEntryKeyIndex);
}
inline Object KeyAt(int entry);
inline Object KeyAt(Isolate* isolate, int entry);

static const int kElementsStartIndex = kPrefixStartIndex + Shape::kPrefixSize;
static const int kEntrySize = Shape::kEntrySize;
Expand Down Expand Up @@ -239,14 +234,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
Expand Down

0 comments on commit 9c356ba

Please sign in to comment.