Skip to content

Commit c5fe3a2

Browse files
committed
deps: V8: cherry-pick 1a7d55a9a427
Original commit message: Merged: [runtime] Fix sorted order of DescriptorArray entries Revision: 518d67ad652fc24b7eb03e48bb342f952d4ccf74 This is a reland of the previous merge which addresses the cctest link failure in component build mode. BUG=chromium:1133527 NOTRY=true NOPRESUBMIT=true NOTREECHECKS=true [email protected] Change-Id: Icbbc69fd5403fd0c2ab6d07d4340292b2b8c72b9 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2504264 Reviewed-by: Toon Verwaest <[email protected]> Cr-Commit-Position: refs/branch-heads/8.6@{#40} Cr-Branched-From: a64aed2333abf49e494d2a5ce24bbd14fff19f60-refs/heads/8.6.395@{#1} Cr-Branched-From: a626bc036236c9bf92ac7b87dc40c9e538b087e3-refs/heads/master@{#69472} Refs: v8/v8@1a7d55a PR-URL: #38275 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Shelley Vohr <[email protected]>
1 parent 7dd68ac commit c5fe3a2

16 files changed

+490
-38
lines changed

common.gypi

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
# Reset this number to 0 on major V8 upgrades.
3838
# Increment by one for each non-official patch applied to deps/v8.
39-
'v8_embedder_string': '-node.52',
39+
'v8_embedder_string': '-node.53',
4040

4141
##### V8 defaults for Node.js #####
4242

deps/v8/src/codegen/code-stub-assembler.cc

+10-9
Original file line numberDiff line numberDiff line change
@@ -1801,12 +1801,13 @@ TNode<IntPtrT> CodeStubAssembler::LoadJSReceiverIdentityHash(
18011801
return var_hash.value();
18021802
}
18031803

1804-
TNode<Uint32T> CodeStubAssembler::LoadNameHashField(SloppyTNode<Name> name) {
1805-
CSA_ASSERT(this, IsName(name));
1806-
return LoadObjectField<Uint32T>(name, Name::kHashFieldOffset);
1804+
TNode<Uint32T> CodeStubAssembler::LoadNameHashAssumeComputed(TNode<Name> name) {
1805+
TNode<Uint32T> hash_field = LoadNameHashField(name);
1806+
CSA_ASSERT(this, IsClearWord32(hash_field, Name::kHashNotComputedMask));
1807+
return Unsigned(Word32Shr(hash_field, Int32Constant(Name::kHashShift)));
18071808
}
18081809

1809-
TNode<Uint32T> CodeStubAssembler::LoadNameHash(SloppyTNode<Name> name,
1810+
TNode<Uint32T> CodeStubAssembler::LoadNameHash(TNode<Name> name,
18101811
Label* if_hash_not_computed) {
18111812
TNode<Uint32T> hash_field = LoadNameHashField(name);
18121813
if (if_hash_not_computed != nullptr) {
@@ -1994,13 +1995,13 @@ TNode<T> CodeStubAssembler::LoadArrayElement(TNode<Array> array,
19941995
}
19951996
}
19961997

1997-
template TNode<MaybeObject>
1998+
template V8_EXPORT_PRIVATE TNode<MaybeObject>
19981999
CodeStubAssembler::LoadArrayElement<TransitionArray>(TNode<TransitionArray>,
19992000
int, Node*, int,
20002001
ParameterMode,
20012002
LoadSensitivity);
20022003

2003-
template TNode<MaybeObject>
2004+
template V8_EXPORT_PRIVATE TNode<MaybeObject>
20042005
CodeStubAssembler::LoadArrayElement<DescriptorArray>(TNode<DescriptorArray>,
20052006
int, Node*, int,
20062007
ParameterMode,
@@ -8063,7 +8064,7 @@ void CodeStubAssembler::LookupBinary(TNode<Name> unique_name,
80638064
TNode<Uint32T> limit =
80648065
Unsigned(Int32Sub(NumberOfEntries<Array>(array), Int32Constant(1)));
80658066
TVARIABLE(Uint32T, var_high, limit);
8066-
TNode<Uint32T> hash = LoadNameHashField(unique_name);
8067+
TNode<Uint32T> hash = LoadNameHashAssumeComputed(unique_name);
80678068
CSA_ASSERT(this, Word32NotEqual(hash, Int32Constant(0)));
80688069

80698070
// Assume non-empty array.
@@ -8081,7 +8082,7 @@ void CodeStubAssembler::LookupBinary(TNode<Name> unique_name,
80818082
TNode<Uint32T> sorted_key_index = GetSortedKeyIndex<Array>(array, mid);
80828083
TNode<Name> mid_name = GetKey<Array>(array, sorted_key_index);
80838084

8084-
TNode<Uint32T> mid_hash = LoadNameHashField(mid_name);
8085+
TNode<Uint32T> mid_hash = LoadNameHashAssumeComputed(mid_name);
80858086

80868087
Label mid_greater(this), mid_less(this), merge(this);
80878088
Branch(Uint32GreaterThanOrEqual(mid_hash, hash), &mid_greater, &mid_less);
@@ -8108,7 +8109,7 @@ void CodeStubAssembler::LookupBinary(TNode<Name> unique_name,
81088109
TNode<Uint32T> sort_index =
81098110
GetSortedKeyIndex<Array>(array, var_low.value());
81108111
TNode<Name> current_name = GetKey<Array>(array, sort_index);
8111-
TNode<Uint32T> current_hash = LoadNameHashField(current_name);
8112+
TNode<Uint32T> current_hash = LoadNameHashAssumeComputed(current_name);
81128113
GotoIf(Word32NotEqual(current_hash, hash), if_not_found);
81138114
Label next(this);
81148115
GotoIf(TaggedNotEqual(current_name, unique_name), &next);

deps/v8/src/codegen/code-stub-assembler.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -1353,13 +1353,12 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
13531353
// Check if the map is set for slow properties.
13541354
TNode<BoolT> IsDictionaryMap(SloppyTNode<Map> map);
13551355

1356-
// Load the hash field of a name as an uint32 value.
1357-
TNode<Uint32T> LoadNameHashField(SloppyTNode<Name> name);
1358-
// Load the hash value of a name as an uint32 value.
1356+
// Load the Name::hash() value of a name as an uint32 value.
13591357
// If {if_hash_not_computed} label is specified then it also checks if
13601358
// hash is actually computed.
1361-
TNode<Uint32T> LoadNameHash(SloppyTNode<Name> name,
1359+
TNode<Uint32T> LoadNameHash(TNode<Name> name,
13621360
Label* if_hash_not_computed = nullptr);
1361+
TNode<Uint32T> LoadNameHashAssumeComputed(TNode<Name> name);
13631362

13641363
// Load length field of a String object as Smi value.
13651364
TNode<Smi> LoadStringLengthAsSmi(TNode<String> string);

deps/v8/src/diagnostics/objects-debug.cc

+4-2
Original file line numberDiff line numberDiff line change
@@ -1667,12 +1667,13 @@ bool DescriptorArray::IsSortedNoDuplicates(int valid_entries) {
16671667
uint32_t current = 0;
16681668
for (int i = 0; i < number_of_descriptors(); i++) {
16691669
Name key = GetSortedKey(i);
1670+
CHECK(key.HasHashCode());
16701671
if (key == current_key) {
16711672
Print();
16721673
return false;
16731674
}
16741675
current_key = key;
1675-
uint32_t hash = GetSortedKey(i).Hash();
1676+
uint32_t hash = key.hash();
16761677
if (hash < current) {
16771678
Print();
16781679
return false;
@@ -1691,7 +1692,8 @@ bool TransitionArray::IsSortedNoDuplicates(int valid_entries) {
16911692

16921693
for (int i = 0; i < number_of_transitions(); i++) {
16931694
Name key = GetSortedKey(i);
1694-
uint32_t hash = key.Hash();
1695+
CHECK(key.HasHashCode());
1696+
uint32_t hash = key.hash();
16951697
PropertyKind kind = kData;
16961698
PropertyAttributes attributes = NONE;
16971699
if (!TransitionsAccessor::IsSpecialTransition(key.GetReadOnlyRoots(),

deps/v8/src/objects/descriptor-array-inl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ void DescriptorArray::Append(Descriptor* desc) {
226226

227227
for (insertion = descriptor_number; insertion > 0; --insertion) {
228228
Name key = GetSortedKey(insertion - 1);
229-
if (key.Hash() <= hash) break;
229+
if (key.hash() <= hash) break;
230230
SetSortedKey(insertion, GetSortedKeyIndex(insertion - 1));
231231
}
232232

deps/v8/src/objects/descriptor-array.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class DescriptorArray
113113
int slack = 0);
114114

115115
// Sort the instance descriptors by the hash codes of their keys.
116-
void Sort();
116+
V8_EXPORT_PRIVATE void Sort();
117117

118118
// Search the instance descriptors for given name.
119119
V8_INLINE InternalIndex Search(Name name, int number_of_own_descriptors);

deps/v8/src/objects/fixed-array-inl.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -212,15 +212,15 @@ int BinarySearch(T* array, Name name, int valid_entries,
212212
DCHECK(search_mode == ALL_ENTRIES || out_insertion_index == nullptr);
213213
int low = 0;
214214
int high = array->number_of_entries() - 1;
215-
uint32_t hash = name.hash_field();
215+
uint32_t hash = name.hash();
216216
int limit = high;
217217

218218
DCHECK(low <= high);
219219

220220
while (low != high) {
221221
int mid = low + (high - low) / 2;
222222
Name mid_name = array->GetSortedKey(mid);
223-
uint32_t mid_hash = mid_name.hash_field();
223+
uint32_t mid_hash = mid_name.hash();
224224

225225
if (mid_hash >= hash) {
226226
high = mid;
@@ -232,7 +232,7 @@ int BinarySearch(T* array, Name name, int valid_entries,
232232
for (; low <= limit; ++low) {
233233
int sort_index = array->GetSortedKeyIndex(low);
234234
Name entry = array->GetKey(InternalIndex(sort_index));
235-
uint32_t current_hash = entry.hash_field();
235+
uint32_t current_hash = entry.hash();
236236
if (current_hash != hash) {
237237
if (search_mode == ALL_ENTRIES && out_insertion_index != nullptr) {
238238
*out_insertion_index = sort_index + (current_hash > hash ? 0 : 1);
@@ -259,12 +259,12 @@ template <SearchMode search_mode, typename T>
259259
int LinearSearch(T* array, Name name, int valid_entries,
260260
int* out_insertion_index) {
261261
if (search_mode == ALL_ENTRIES && out_insertion_index != nullptr) {
262-
uint32_t hash = name.hash_field();
262+
uint32_t hash = name.hash();
263263
int len = array->number_of_entries();
264264
for (int number = 0; number < len; number++) {
265265
int sorted_index = array->GetSortedKeyIndex(number);
266266
Name entry = array->GetKey(InternalIndex(sorted_index));
267-
uint32_t current_hash = entry.hash_field();
267+
uint32_t current_hash = entry.hash();
268268
if (current_hash > hash) {
269269
*out_insertion_index = sorted_index;
270270
return T::kNotFound;

deps/v8/src/objects/name-inl.h

+6
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ uint32_t Name::Hash() {
9494
return String::cast(*this).ComputeAndSetHash();
9595
}
9696

97+
uint32_t Name::hash() const {
98+
uint32_t field = hash_field();
99+
DCHECK(IsHashFieldComputed(field));
100+
return field >> kHashShift;
101+
}
102+
97103
DEF_GETTER(Name, IsInterestingSymbol, bool) {
98104
return IsSymbol(isolate) && Symbol::cast(*this).is_interesting_symbol();
99105
}

deps/v8/src/objects/name.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,15 @@ class Name : public TorqueGeneratedName<Name, PrimitiveHeapObject> {
2323
// Tells whether the hash code has been computed.
2424
inline bool HasHashCode();
2525

26-
// Returns a hash value used for the property table
26+
// Returns a hash value used for the property table. Ensures that the hash
27+
// value is computed.
28+
// TODO(ishell): rename to EnsureHash().
2729
inline uint32_t Hash();
2830

31+
// Returns a hash value used for the property table (same as Hash()), assumes
32+
// the hash is already computed.
33+
inline uint32_t hash() const;
34+
2935
// Equality operations.
3036
inline bool Equals(Name other);
3137
inline static bool Equals(Isolate* isolate, Handle<Name> one,

deps/v8/src/objects/objects.cc

+7-7
Original file line numberDiff line numberDiff line change
@@ -4355,16 +4355,16 @@ void DescriptorArray::Sort() {
43554355
// Reset sorting since the descriptor array might contain invalid pointers.
43564356
for (int i = 0; i < len; ++i) SetSortedKey(i, i);
43574357
// Bottom-up max-heap construction.
4358-
// Index of the last node with children
4358+
// Index of the last node with children.
43594359
const int max_parent_index = (len / 2) - 1;
43604360
for (int i = max_parent_index; i >= 0; --i) {
43614361
int parent_index = i;
4362-
const uint32_t parent_hash = GetSortedKey(i).Hash();
4362+
const uint32_t parent_hash = GetSortedKey(i).hash();
43634363
while (parent_index <= max_parent_index) {
43644364
int child_index = 2 * parent_index + 1;
4365-
uint32_t child_hash = GetSortedKey(child_index).Hash();
4365+
uint32_t child_hash = GetSortedKey(child_index).hash();
43664366
if (child_index + 1 < len) {
4367-
uint32_t right_child_hash = GetSortedKey(child_index + 1).Hash();
4367+
uint32_t right_child_hash = GetSortedKey(child_index + 1).hash();
43684368
if (right_child_hash > child_hash) {
43694369
child_index++;
43704370
child_hash = right_child_hash;
@@ -4383,13 +4383,13 @@ void DescriptorArray::Sort() {
43834383
SwapSortedKeys(0, i);
43844384
// Shift down the new top element.
43854385
int parent_index = 0;
4386-
const uint32_t parent_hash = GetSortedKey(parent_index).Hash();
4386+
const uint32_t parent_hash = GetSortedKey(parent_index).hash();
43874387
const int max_parent_index = (i / 2) - 1;
43884388
while (parent_index <= max_parent_index) {
43894389
int child_index = parent_index * 2 + 1;
4390-
uint32_t child_hash = GetSortedKey(child_index).Hash();
4390+
uint32_t child_hash = GetSortedKey(child_index).hash();
43914391
if (child_index + 1 < i) {
4392-
uint32_t right_child_hash = GetSortedKey(child_index + 1).Hash();
4392+
uint32_t right_child_hash = GetSortedKey(child_index + 1).hash();
43934393
if (right_child_hash > child_hash) {
43944394
child_index++;
43954395
child_hash = right_child_hash;

deps/v8/src/objects/transitions-inl.h

+8
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,20 @@ int TransitionArray::SearchNameForTesting(Name name, int* out_insertion_index) {
169169
return SearchName(name, out_insertion_index);
170170
}
171171

172+
Map TransitionArray::SearchAndGetTargetForTesting(
173+
PropertyKind kind, Name name, PropertyAttributes attributes) {
174+
return SearchAndGetTarget(kind, name, attributes);
175+
}
176+
172177
int TransitionArray::SearchSpecial(Symbol symbol, int* out_insertion_index) {
173178
return SearchName(symbol, out_insertion_index);
174179
}
175180

176181
int TransitionArray::SearchName(Name name, int* out_insertion_index) {
177182
DCHECK(name.IsUniqueName());
183+
// The name is taken from DescriptorArray, so it must already has a computed
184+
// hash.
185+
DCHECK(name.HasHashCode());
178186
return internal::Search<ALL_ENTRIES>(this, name, number_of_entries(),
179187
out_insertion_index);
180188
}

deps/v8/src/objects/transitions.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -619,8 +619,8 @@ void TransitionArray::Sort() {
619619
temp_kind = details.kind();
620620
temp_attributes = details.attributes();
621621
}
622-
int cmp = CompareKeys(temp_key, temp_key.Hash(), temp_kind,
623-
temp_attributes, key, key.Hash(), kind, attributes);
622+
int cmp = CompareKeys(temp_key, temp_key.hash(), temp_kind,
623+
temp_attributes, key, key.hash(), kind, attributes);
624624
if (cmp > 0) {
625625
SetKey(j + 1, temp_key);
626626
SetRawTarget(j + 1, temp_target);

deps/v8/src/objects/transitions.h

+8-5
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ class V8_EXPORT_PRIVATE TransitionsAccessor {
143143
return encoding_;
144144
}
145145

146+
inline TransitionArray transitions();
147+
146148
private:
147149
friend class MarkCompactCollector; // For HasSimpleTransitionTo.
148150
friend class TransitionArray;
@@ -175,8 +177,6 @@ class V8_EXPORT_PRIVATE TransitionsAccessor {
175177
void TraverseTransitionTreeInternal(TraverseCallback callback, void* data,
176178
DisallowHeapAllocation* no_gc);
177179

178-
inline TransitionArray transitions();
179-
180180
Isolate* isolate_;
181181
Handle<Map> map_handle_;
182182
Map map_;
@@ -231,7 +231,7 @@ class TransitionArray : public WeakFixedArray {
231231
V8_EXPORT_PRIVATE bool IsSortedNoDuplicates(int valid_entries = -1);
232232
#endif
233233

234-
void Sort();
234+
V8_EXPORT_PRIVATE void Sort();
235235

236236
void PrintInternal(std::ostream& os);
237237

@@ -260,6 +260,9 @@ class TransitionArray : public WeakFixedArray {
260260
inline int SearchNameForTesting(Name name,
261261
int* out_insertion_index = nullptr);
262262

263+
inline Map SearchAndGetTargetForTesting(PropertyKind kind, Name name,
264+
PropertyAttributes attributes);
265+
263266
private:
264267
friend class Factory;
265268
friend class MarkCompactCollector;
@@ -296,8 +299,8 @@ class TransitionArray : public WeakFixedArray {
296299
int Search(PropertyKind kind, Name name, PropertyAttributes attributes,
297300
int* out_insertion_index = nullptr);
298301

299-
Map SearchAndGetTarget(PropertyKind kind, Name name,
300-
PropertyAttributes attributes);
302+
V8_EXPORT_PRIVATE Map SearchAndGetTarget(PropertyKind kind, Name name,
303+
PropertyAttributes attributes);
301304

302305
// Search a non-property transition (like elements kind, observe or frozen
303306
// transitions).

deps/v8/test/cctest/BUILD.gn

+1
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ v8_source_set("cctest_sources") {
204204
"test-debug.cc",
205205
"test-decls.cc",
206206
"test-deoptimization.cc",
207+
"test-descriptor-array.cc",
207208
"test-dictionary.cc",
208209
"test-diy-fp.cc",
209210
"test-double.cc",

0 commit comments

Comments
 (0)