Skip to content

Commit 0450133

Browse files
joyeecheungjuanarbol
authored andcommitted
deps: V8: backport 185f0fe09b72
Original commit message: [numbers] Refactor HashSeed as a lightweight view over ByteArray Instead of copying the seed and secrets into a struct with value fields, HashSeed now stores a pointer pointing either into the read-only ByteArray, or the static default seed for off-heap HashSeed::Default() calls. The underlying storage is always 8-byte aligned so we can cast it directly into a struct. Change-Id: I5896a7f2ae24296eb4c80b757a5d90ac70a34866 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/7609720 Reviewed-by: Leszek Swirski <leszeks@chromium.org> Commit-Queue: Joyee Cheung <joyee@igalia.com> Cr-Commit-Position: refs/heads/main@{#105531} Refs: v8/v8@185f0fe Co-authored-by: Joyee Cheung <joyeec9h3@gmail.com> PR-URL: nodejs-private/node-private#828
1 parent af22629 commit 0450133

File tree

16 files changed

+137
-79
lines changed

16 files changed

+137
-79
lines changed

common.gypi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
# Reset this number to 0 on major V8 upgrades.
4040
# Increment by one for each non-official patch applied to deps/v8.
41-
'v8_embedder_string': '-node.42',
41+
'v8_embedder_string': '-node.43',
4242

4343
##### V8 defaults for Node.js #####
4444

deps/v8/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,6 +1937,7 @@ filegroup(
19371937
"src/numbers/conversions.h",
19381938
"src/numbers/conversions-inl.h",
19391939
"src/numbers/hash-seed.h",
1940+
"src/numbers/hash-seed.cc",
19401941
"src/numbers/hash-seed-inl.h",
19411942
"src/numbers/ieee754.cc",
19421943
"src/numbers/ieee754.h",

deps/v8/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5598,6 +5598,7 @@ v8_source_set("v8_base_without_compiler") {
55985598
"src/logging/runtime-call-stats.cc",
55995599
"src/logging/tracing-flags.cc",
56005600
"src/numbers/conversions.cc",
5601+
"src/numbers/hash-seed.cc",
56015602
"src/numbers/ieee754.cc",
56025603
"src/numbers/math-random.cc",
56035604
"src/objects/abstract-code.cc",

deps/v8/src/DEPS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ specific_include_rules = {
135135
"heap\.cc": [
136136
"+third_party/rapidhash-v8/secret.h",
137137
],
138-
"hash-seed-inl\.h": [
138+
"hash-seed\.cc": [
139139
"+third_party/rapidhash-v8/secret.h",
140140
],
141141
}

deps/v8/src/heap/factory-base.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,9 @@ Handle<ProtectedWeakFixedArray> FactoryBase<Impl>::NewProtectedWeakFixedArray(
301301
}
302302

303303
template <typename Impl>
304-
Handle<ByteArray> FactoryBase<Impl>::NewByteArray(int length,
305-
AllocationType allocation) {
306-
return ByteArray::New(isolate(), length, allocation);
304+
Handle<ByteArray> FactoryBase<Impl>::NewByteArray(
305+
int length, AllocationType allocation, AllocationAlignment alignment) {
306+
return ByteArray::New(isolate(), length, allocation, alignment);
307307
}
308308

309309
template <typename Impl>
@@ -1241,8 +1241,8 @@ FactoryBase<Impl>::AllocateRawTwoByteInternalizedString(
12411241

12421242
template <typename Impl>
12431243
Tagged<HeapObject> FactoryBase<Impl>::AllocateRawArray(
1244-
int size, AllocationType allocation) {
1245-
Tagged<HeapObject> result = AllocateRaw(size, allocation);
1244+
int size, AllocationType allocation, AllocationAlignment alignment) {
1245+
Tagged<HeapObject> result = AllocateRaw(size, allocation, alignment);
12461246
if ((size >
12471247
isolate()->heap()->AsHeap()->MaxRegularHeapObjectSize(allocation)) &&
12481248
v8_flags.use_marking_progress_bar) {

deps/v8/src/heap/factory-base.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ class FactoryBase : public TorqueGeneratedFactory<Impl> {
197197

198198
// The function returns a pre-allocated empty byte array for length = 0.
199199
Handle<ByteArray> NewByteArray(
200-
int length, AllocationType allocation = AllocationType::kYoung);
200+
int length, AllocationType allocation = AllocationType::kYoung,
201+
AllocationAlignment alignment = kTaggedAligned);
201202

202203
// Allocates a trusted byte array in trusted space, initialized with zeros.
203204
Handle<TrustedByteArray> NewTrustedByteArray(
@@ -410,7 +411,9 @@ class FactoryBase : public TorqueGeneratedFactory<Impl> {
410411
static constexpr int kNumberToStringBufferSize = 32;
411412

412413
// Allocate memory for an uninitialized array (e.g., a FixedArray or similar).
413-
Tagged<HeapObject> AllocateRawArray(int size, AllocationType allocation);
414+
Tagged<HeapObject> AllocateRawArray(
415+
int size, AllocationType allocation,
416+
AllocationAlignment alignment = kTaggedAligned);
414417
Tagged<HeapObject> AllocateRawFixedArray(int length,
415418
AllocationType allocation);
416419
Tagged<HeapObject> AllocateRawWeakArrayList(int length,

deps/v8/src/heap/heap.cc

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@
127127
#include "src/tracing/trace-event.h"
128128
#include "src/utils/utils-inl.h"
129129
#include "src/utils/utils.h"
130-
#include "third_party/rapidhash-v8/secret.h"
131130

132131
#ifdef V8_ENABLE_CONSERVATIVE_STACK_SCANNING
133132
#include "src/heap/conservative-stack-visitor-inl.h"
@@ -5916,31 +5915,6 @@ void Heap::SetUpSpaces(LinearAllocationArea& new_allocation_info,
59165915
}
59175916
}
59185917

5919-
void Heap::InitializeHashSeed() {
5920-
DCHECK(!deserialization_complete_);
5921-
uint64_t new_hash_seed;
5922-
if (v8_flags.hash_seed == 0) {
5923-
int64_t rnd = isolate()->random_number_generator()->NextInt64();
5924-
new_hash_seed = static_cast<uint64_t>(rnd);
5925-
} else {
5926-
new_hash_seed = static_cast<uint64_t>(v8_flags.hash_seed);
5927-
}
5928-
5929-
Tagged<ByteArray> hash_seed = ReadOnlyRoots(this).hash_seed();
5930-
5931-
MemCopy(hash_seed->begin(), reinterpret_cast<uint8_t*>(&new_hash_seed),
5932-
kInt64Size);
5933-
5934-
#if V8_USE_DEFAULT_HASHER_SECRET
5935-
MemCopy(hash_seed->begin() + kInt64Size,
5936-
reinterpret_cast<const uint8_t*>(RAPIDHASH_DEFAULT_SECRET),
5937-
kInt64Size * 3);
5938-
#else
5939-
rapidhash_make_secret(new_hash_seed, reinterpret_cast<uint64_t*>(
5940-
hash_seed->begin() + kInt64Size));
5941-
#endif // V8_USE_DEFAULT_HASHER_SECRET
5942-
}
5943-
59445918
std::shared_ptr<v8::TaskRunner> Heap::GetForegroundTaskRunner(
59455919
TaskPriority priority) const {
59465920
return V8::GetCurrentPlatform()->GetForegroundTaskRunner(

deps/v8/src/heap/heap.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -691,9 +691,6 @@ class Heap final {
691691
// Prepares the heap, setting up for deserialization.
692692
void InitializeMainThreadLocalHeap(LocalHeap* main_thread_local_heap);
693693

694-
// (Re-)Initialize hash seed from flag or RNG.
695-
void InitializeHashSeed();
696-
697694
// Invoked once for the process from V8::Initialize.
698695
static void InitializeOncePerProcess();
699696

deps/v8/src/heap/setup-heap-internal.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "src/init/heap-symbols.h"
1717
#include "src/init/setup-isolate.h"
1818
#include "src/interpreter/interpreter.h"
19+
#include "src/numbers/hash-seed.h"
1920
#include "src/objects/arguments.h"
2021
#include "src/objects/call-site-info.h"
2122
#include "src/objects/cell-inl.h"
@@ -893,9 +894,10 @@ bool Heap::CreateImportantReadOnlyObjects() {
893894
// Hash seed for strings
894895

895896
Factory* factory = isolate()->factory();
896-
set_hash_seed(
897-
*factory->NewByteArray(kInt64Size * 4, AllocationType::kReadOnly));
898-
InitializeHashSeed();
897+
set_hash_seed(*factory->NewByteArray(HashSeed::kTotalSize,
898+
AllocationType::kReadOnly,
899+
AllocationAlignment::kDoubleAligned));
900+
HashSeed::InitializeRoots(isolate());
899901

900902
// Important strings and symbols
901903
for (const ConstantStringInit& entry : kImportantConstantStringTable) {

deps/v8/src/numbers/hash-seed-inl.h

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include "src/numbers/hash-seed.h"
99
#include "src/objects/fixed-array-inl.h"
1010
#include "src/roots/roots-inl.h"
11-
#include "third_party/rapidhash-v8/secret.h"
1211

1312
namespace v8 {
1413
namespace internal {
@@ -19,23 +18,13 @@ inline HashSeed::HashSeed(Isolate* isolate)
1918
inline HashSeed::HashSeed(LocalIsolate* isolate)
2019
: HashSeed(ReadOnlyRoots(isolate)) {}
2120

22-
inline HashSeed::HashSeed(ReadOnlyRoots roots) {
23-
// roots.hash_seed is not aligned
24-
MemCopy(&seed_, roots.hash_seed()->begin(), sizeof(seed_));
25-
MemCopy(secret_, roots.hash_seed()->begin() + sizeof(seed_), sizeof(secret_));
26-
}
27-
28-
inline HashSeed::HashSeed(uint64_t seed, const uint64_t secret[3])
29-
: seed_(seed),
30-
secret_{
31-
secret[0],
32-
secret[1],
33-
secret[2],
34-
} {}
35-
36-
inline HashSeed HashSeed::Default() {
37-
return HashSeed(0, RAPIDHASH_DEFAULT_SECRET);
38-
}
21+
inline HashSeed::HashSeed(ReadOnlyRoots roots)
22+
: data_(reinterpret_cast<const Data*>(roots.hash_seed()->begin())) {}
23+
24+
inline HashSeed HashSeed::Default() { return HashSeed(kDefaultData); }
25+
26+
inline uint64_t HashSeed::seed() const { return data_->seed; }
27+
inline const uint64_t* HashSeed::secret() const { return data_->secrets; }
3928

4029
} // namespace internal
4130
} // namespace v8

0 commit comments

Comments
 (0)