From 9ce8ef405b766d87cb79316ddfbce4fcbdeb241a Mon Sep 17 00:00:00 2001 From: Toon Verwaest Date: Thu, 24 Apr 2025 15:57:17 +0200 Subject: [PATCH] deps: V8: backport 8901c793e439 Original commit message: [compiler] Stop collecting array and object prototypes We can check in O(1) whether an object is either Object.prototype or Array.prototype by directly comparing it with the objects, so there's no need to collect them. Change-Id: Iadedf8b05cae3d67191fb4836c186620dc009118 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/6487694 Commit-Queue: Toon Verwaest Reviewed-by: Igor Sheludko Commit-Queue: Igor Sheludko Auto-Submit: Toon Verwaest Cr-Commit-Position: refs/heads/main@{#99894} Refs: https://github.com/v8/v8/commit/8901c793e4392dfea261bcbf9c679e2978847d4d Co-authored-by: inoway46 PR-URL: https://github.com/nodejs/node/pull/66089 Reviewed-By: Antoine du Hamel --- common.gypi | 2 +- deps/v8/src/compiler/heap-refs.cc | 2 -- deps/v8/src/compiler/js-heap-broker.cc | 34 +++----------------------- deps/v8/src/compiler/js-heap-broker.h | 16 ++++-------- 4 files changed, 9 insertions(+), 45 deletions(-) diff --git a/common.gypi b/common.gypi index 151e92c1583..609172e4693 100644 --- a/common.gypi +++ b/common.gypi @@ -42,7 +42,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.54', + 'v8_embedder_string': '-node.55', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/src/compiler/heap-refs.cc b/deps/v8/src/compiler/heap-refs.cc index 7a470132d7f..5d4ef93a016 100644 --- a/deps/v8/src/compiler/heap-refs.cc +++ b/deps/v8/src/compiler/heap-refs.cc @@ -1039,8 +1039,6 @@ void JSHeapBroker::InitializeAndStartSerializing( refs_ = zone()->New(kInitialRefsBucketCount, AddressMatcher(), zone()); - CollectArrayAndObjectPrototypes(); - SetTargetNativeContextRef(target_native_context); } diff --git a/deps/v8/src/compiler/js-heap-broker.cc b/deps/v8/src/compiler/js-heap-broker.cc index 3a7949ce8e4..f766e1273a0 100644 --- a/deps/v8/src/compiler/js-heap-broker.cc +++ b/deps/v8/src/compiler/js-heap-broker.cc @@ -47,7 +47,6 @@ JSHeapBroker::JSHeapBroker(Isolate* isolate, Zone* broker_zone, refs_(zone()->New(kMinimalRefsBucketCount, AddressMatcher(), zone())), root_index_map_(isolate), - array_and_object_prototypes_(zone()), tracing_enabled_(tracing_enabled), code_kind_(code_kind), feedback_(zone()), @@ -118,28 +117,6 @@ void JSHeapBroker::SetTargetNativeContextRef( target_native_context_ = MakeRef(this, *native_context); } -void JSHeapBroker::CollectArrayAndObjectPrototypes() { - DisallowGarbageCollection no_gc; - CHECK_EQ(mode(), kSerializing); - CHECK(array_and_object_prototypes_.empty()); - - Tagged maybe_context = isolate()->heap()->native_contexts_list(); - while (!IsUndefined(maybe_context, isolate())) { - Tagged context = Cast(maybe_context); - Tagged array_prot = - context->get(Context::INITIAL_ARRAY_PROTOTYPE_INDEX); - Tagged object_prot = - context->get(Context::INITIAL_OBJECT_PROTOTYPE_INDEX); - array_and_object_prototypes_.emplace( - CanonicalPersistentHandle(Cast(array_prot))); - array_and_object_prototypes_.emplace( - CanonicalPersistentHandle(Cast(object_prot))); - maybe_context = context->next_context_link(); - } - - CHECK(!array_and_object_prototypes_.empty()); -} - StringRef JSHeapBroker::GetTypedArrayStringTag(ElementsKind kind) { DCHECK(IsTypedArrayOrRabGsabTypedArrayElementsKind(kind)); switch (kind) { @@ -159,14 +136,9 @@ bool JSHeapBroker::IsArrayOrObjectPrototype(JSObjectRef object) const { } bool JSHeapBroker::IsArrayOrObjectPrototype(Handle object) const { - if (mode() == kDisabled) { - return isolate()->IsInCreationContext( - *object, Context::INITIAL_ARRAY_PROTOTYPE_INDEX) || - object->map(isolate_)->instance_type() == JS_OBJECT_PROTOTYPE_TYPE; - } - CHECK(!array_and_object_prototypes_.empty()); - return array_and_object_prototypes_.find(object) != - array_and_object_prototypes_.end(); + return isolate()->IsInCreationContext( + *object, Context::INITIAL_ARRAY_PROTOTYPE_INDEX) || + object->map(isolate_)->instance_type() == JS_OBJECT_PROTOTYPE_TYPE; } ObjectData* JSHeapBroker::TryGetOrCreateData(Tagged object, diff --git a/deps/v8/src/compiler/js-heap-broker.h b/deps/v8/src/compiler/js-heap-broker.h index 52677f517f5..aaee5131b23 100644 --- a/deps/v8/src/compiler/js-heap-broker.h +++ b/deps/v8/src/compiler/js-heap-broker.h @@ -285,12 +285,11 @@ class V8_EXPORT_PRIVATE JSHeapBroker { if (Tagged heap_object; TryCast(object, &heap_object)) { RootIndex root_index; - // CollectArrayAndObjectPrototypes calls this function often with T equal - // to JSObject. The root index map only contains immortal, immutable - // objects; it never contains any instances of type JSObject, since - // JSObjects must exist within a NativeContext, and NativeContexts can be - // created and destroyed. Thus, we can skip the lookup in the root index - // map for those values and save a little time. + // The root index map only contains immortal, immutable objects; it never + // contains any instances of type JSObject, since JSObjects must exist + // within a NativeContext, and NativeContexts can be created and + // destroyed. Thus, we can skip the lookup in the root index map for those + // values and save a little time. if constexpr (std::is_convertible_v) { DCHECK(!root_index_map_.Lookup(heap_object, &root_index)); } else if (root_index_map_.Lookup(heap_object, &root_index)) { @@ -428,8 +427,6 @@ class V8_EXPORT_PRIVATE JSHeapBroker { ProcessedFeedback const& ReadFeedbackForTemplateObject( FeedbackSource const& source); - void CollectArrayAndObjectPrototypes(); - void set_persistent_handles( std::unique_ptr persistent_handles) { DCHECK_NULL(ph_); @@ -457,9 +454,6 @@ class V8_EXPORT_PRIVATE JSHeapBroker { OptionalNativeContextRef target_native_context_; RefsMap* refs_; RootIndexMap root_index_map_; - ZoneUnorderedSet, IndirectHandle::hash, - IndirectHandle::equal_to> - array_and_object_prototypes_; BrokerMode mode_ = kDisabled; bool const tracing_enabled_; CodeKind const code_kind_;