deps: V8: cherry-pick 95efbaf92a0d

Original commit message:

    [api] Delete usages of v8::HeapProfile::ObjectNameResolver

    ... and start deprecation of the class definition.

    Bug: 333672197
    Change-Id: I9517d09cd1e01b9893384cb9408d714affcefdee
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/7614327
    Commit-Queue: Igor Sheludko <ishell@chromium.org>
    Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
    Cr-Commit-Position: refs/heads/main@{#105492}

Refs: https://github.com/v8/v8/commit/95efbaf92a0db596df3d66b5e7087e8cf4b04a07
PR-URL: https://github.com/nodejs/node/pull/66020
Reviewed-By: Xuguang Mei <meixuguang@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
This commit is contained in:
Igor Sheludko authored and Antoine du Hamel committed 2026-09-18 17:46:44 +02:00
1 parent f8b7a2ff41
commit 870a366c49
7 files changed
+25 -235

No files matched your search

+1 -1
View File
@@ -43,7 +43,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.33',
'v8_embedder_string': '-node.34',
##### V8 defaults for Node.js #####
+3 -23
View File
@@ -1069,7 +1069,8 @@ class V8_EXPORT HeapProfiler {
*
* This interface will soon be deprecated in favour of ContextNameResolver.
*/
class ObjectNameResolver {
class V8_DEPRECATE_SOON("Use ContextNameResolver instead.")
ObjectNameResolver {
public:
/**
* Returns name to be used in the heap snapshot for given node. Returned
@@ -1127,24 +1128,13 @@ class V8_EXPORT HeapProfiler {
// NOLINTNEXTLINE
HeapSnapshotOptions() {}
// TODO(https://crbug.com/333672197): remove once ObjectNameResolver is
// removed.
ALLOW_COPY_AND_MOVE_WITH_DEPRECATED_FIELDS(HeapSnapshotOptions)
/**
* The control used to report intermediate progress to.
*/
ActivityControl* control = nullptr;
/**
* The resolver used by the snapshot generator to get names for V8 objects.
*/
V8_DEPRECATED("Use context_name_resolver callback instead.")
ObjectNameResolver* global_object_name_resolver = nullptr;
/**
* The resolver used by the snapshot generator to get names for v8::Context
* objects.
* In case both this and |global_object_name_resolver| callbacks are
* provided, this one will be used.
*/
ContextNameResolver* context_name_resolver = nullptr;
/**
@@ -1176,18 +1166,8 @@ class V8_EXPORT HeapProfiler {
*
* \returns the snapshot.
*/
V8_DEPRECATED("Use overload with ContextNameResolver* resolver instead.")
const HeapSnapshot* TakeHeapSnapshot(
ActivityControl* control, ObjectNameResolver* global_object_name_resolver,
bool hide_internals = true, bool capture_numeric_value = false);
const HeapSnapshot* TakeHeapSnapshot(ActivityControl* control,
ContextNameResolver* resolver,
bool hide_internals = true,
bool capture_numeric_value = false);
// TODO(333672197): remove this version once ObjectNameResolver* overload
// is removed.
const HeapSnapshot* TakeHeapSnapshot(ActivityControl* control,
std::nullptr_t resolver = nullptr,
ContextNameResolver* resolver = nullptr,
bool hide_internals = true,
bool capture_numeric_value = false);
-29
View File
@@ -11849,21 +11849,6 @@ const HeapSnapshot* HeapProfiler::TakeHeapSnapshot(
reinterpret_cast<i::HeapProfiler*>(this)->TakeSnapshot(options));
}
const HeapSnapshot* HeapProfiler::TakeHeapSnapshot(ActivityControl* control,
ObjectNameResolver* resolver,
bool hide_internals,
bool capture_numeric_value) {
HeapSnapshotOptions options;
options.control = control;
options.global_object_name_resolver = resolver;
options.snapshot_mode = hide_internals ? HeapSnapshotMode::kRegular
: HeapSnapshotMode::kExposeInternals;
options.numerics_mode = capture_numeric_value
? NumericsMode::kExposeNumericValues
: NumericsMode::kHideNumericValues;
return TakeHeapSnapshot(options);
}
const HeapSnapshot* HeapProfiler::TakeHeapSnapshot(
ActivityControl* control, ContextNameResolver* resolver,
bool hide_internals, bool capture_numeric_value) {
@@ -11878,20 +11863,6 @@ const HeapSnapshot* HeapProfiler::TakeHeapSnapshot(
return TakeHeapSnapshot(options);
}
const HeapSnapshot* HeapProfiler::TakeHeapSnapshot(ActivityControl* control,
std::nullptr_t resolver,
bool hide_internals,
bool capture_numeric_value) {
HeapSnapshotOptions options;
options.control = control;
options.snapshot_mode = hide_internals ? HeapSnapshotMode::kRegular
: HeapSnapshotMode::kExposeInternals;
options.numerics_mode = capture_numeric_value
? NumericsMode::kExposeNumericValues
: NumericsMode::kHideNumericValues;
return TakeHeapSnapshot(options);
}
std::vector<v8::Local<v8::Value>> HeapProfiler::GetDetachedJSWrapperObjects() {
return reinterpret_cast<i::HeapProfiler*>(this)
->GetDetachedJSWrapperObjects();
+6 -14
View File
@@ -146,13 +146,9 @@ HeapSnapshot* HeapProfiler::TakeSnapshot(
use_cpp_class_name.emplace(heap()->cpp_heap());
}
// Allow usages of v8::HeapProfiler::ObjectNameResolver for now.
// TODO(https://crbug.com/333672197): remove.
START_ALLOW_USE_DEPRECATED()
HeapSnapshotGenerator generator(
result, options.control, options.global_object_name_resolver,
options.context_name_resolver, heap(), options.stack_state);
END_ALLOW_USE_DEPRECATED()
HeapSnapshotGenerator generator(result, options.control,
options.context_name_resolver, heap(),
options.stack_state);
if (!generator.GenerateSnapshot()) {
delete result;
result = nullptr;
@@ -186,13 +182,9 @@ void HeapProfiler::WriteSnapshotToDiskAfterGC(HeapSnapshotMode snapshot_mode) {
v8::HeapProfiler::HeapSnapshotOptions options;
std::unique_ptr<HeapSnapshot> result(
new HeapSnapshot(this, snapshot_mode, options.numerics_mode));
// Allow usages of v8::HeapProfiler::ObjectNameResolver for now.
// TODO(https://crbug.com/333672197): remove.
START_ALLOW_USE_DEPRECATED()
HeapSnapshotGenerator generator(
result.get(), options.control, options.global_object_name_resolver,
options.context_name_resolver, heap(), options.stack_state);
END_ALLOW_USE_DEPRECATED()
HeapSnapshotGenerator generator(result.get(), options.control,
options.context_name_resolver, heap(),
options.stack_state);
if (!generator.GenerateSnapshotAfterGC()) return;
i::FileOutputStream stream(filename.c_str());
if (stream.IsOpen()) {
+11 -37
View File
@@ -823,18 +823,16 @@ void HeapObjectsMap::RemoveDeadEntries() {
entries_map_.occupancy());
}
V8HeapExplorer::V8HeapExplorer(
HeapSnapshot* snapshot, SnapshottingProgressReportingInterface* progress,
v8::HeapProfiler::ObjectNameResolver* resolver,
v8::HeapProfiler::ContextNameResolver* context_resolver)
V8HeapExplorer::V8HeapExplorer(HeapSnapshot* snapshot,
SnapshottingProgressReportingInterface* progress,
v8::HeapProfiler::ContextNameResolver* resolver)
: heap_(snapshot->profiler()->heap_object_map()->heap()),
snapshot_(snapshot),
names_(snapshot_->profiler()->names()),
heap_object_map_(snapshot_->profiler()->heap_object_map()),
progress_(progress),
generator_(nullptr),
global_object_name_resolver_(resolver),
native_context_name_resolver_(context_resolver) {}
native_context_name_resolver_(resolver) {}
HeapEntry* V8HeapExplorer::AllocateEntry(HeapThing ptr) {
return AddEntry(
@@ -3020,9 +3018,7 @@ class NativeContextEnumerator : public RootVisitor {
V8HeapExplorer::TemporaryNativeContextTags
V8HeapExplorer::CollectTemporaryNativeContextTags() {
if (!global_object_name_resolver_ && !native_context_name_resolver_) {
return {};
}
if (!native_context_name_resolver_) return {};
Isolate* isolate = heap_->isolate();
TemporaryNativeContextTags native_context_tags;
@@ -3030,33 +3026,12 @@ V8HeapExplorer::CollectTemporaryNativeContextTags() {
NativeContextEnumerator enumerator(
isolate, [this, isolate, &native_context_tags](
DirectHandle<NativeContext> native_context) {
if (native_context_name_resolver_) {
v8::Local<v8::Context> context = Utils::ToLocal(native_context);
if (const char* tag =
native_context_name_resolver_->GetName(context)) {
native_context_tags.emplace_back(
Global<v8::Context>(reinterpret_cast<v8::Isolate*>(isolate),
context),
tag);
native_context_tags.back().first.SetWeak();
}
return;
}
DirectHandle<JSObject> global(native_context->global_object(), isolate);
if (const char* tag =
global_object_name_resolver_->GetName(Utils::ToLocal(global))) {
native_context_tags.emplace_back(
Global<v8::Context>(reinterpret_cast<v8::Isolate*>(isolate),
Utils::ToLocal(native_context)),
tag);
native_context_tags.back().first.SetWeak();
return;
}
v8::Local<v8::Context> context = Utils::ToLocal(native_context);
const char* tag = native_context_name_resolver_->GetName(context);
native_context_tags.emplace_back(
Global<v8::Context>(reinterpret_cast<v8::Isolate*>(isolate),
Utils::ToLocal(native_context)),
nullptr);
context),
tag);
native_context_tags.back().first.SetWeak();
});
isolate->global_handles()->IterateAllRoots(&enumerator);
@@ -3364,12 +3339,11 @@ bool NativeObjectsExplorer::IterateAndExtractReferences(
HeapSnapshotGenerator::HeapSnapshotGenerator(
HeapSnapshot* snapshot, v8::ActivityControl* control,
v8::HeapProfiler::ObjectNameResolver* resolver,
v8::HeapProfiler::ContextNameResolver* context_resolver, Heap* heap,
v8::HeapProfiler::ContextNameResolver* resolver, Heap* heap,
cppgc::EmbedderStackState stack_state)
: snapshot_(snapshot),
control_(control),
v8_heap_explorer_(snapshot_, this, resolver, context_resolver),
v8_heap_explorer_(snapshot_, this, resolver),
dom_explorer_(snapshot_, this),
heap_(heap),
stack_state_(stack_state) {}
+4 -8
View File
@@ -413,8 +413,7 @@ class V8_EXPORT_PRIVATE V8HeapExplorer : public HeapEntriesAllocator {
public:
V8HeapExplorer(HeapSnapshot* snapshot,
SnapshottingProgressReportingInterface* progress,
v8::HeapProfiler::ObjectNameResolver* resolver,
v8::HeapProfiler::ContextNameResolver* context_resolver);
v8::HeapProfiler::ContextNameResolver* resolver);
~V8HeapExplorer() override = default;
V8HeapExplorer(const V8HeapExplorer&) = delete;
V8HeapExplorer& operator=(const V8HeapExplorer&) = delete;
@@ -610,7 +609,6 @@ class V8_EXPORT_PRIVATE V8HeapExplorer : public HeapEntriesAllocator {
native_context_tag_map_;
UnorderedHeapObjectMap<const char*> strong_gc_subroot_names_;
std::unordered_set<Tagged<NativeContext>, Object::Hasher> user_roots_;
v8::HeapProfiler::ObjectNameResolver* global_object_name_resolver_;
v8::HeapProfiler::ContextNameResolver* native_context_name_resolver_;
std::vector<bool> visited_fields_;
@@ -660,11 +658,9 @@ class HeapSnapshotGenerator : public SnapshottingProgressReportingInterface {
// their representations in heap snapshots.
using SmiEntriesMap = std::unordered_map<int, HeapEntry*>;
HeapSnapshotGenerator(
HeapSnapshot* snapshot, v8::ActivityControl* control,
v8::HeapProfiler::ObjectNameResolver* resolver,
v8::HeapProfiler::ContextNameResolver* context_name_resolver, Heap* heap,
cppgc::EmbedderStackState stack_state);
HeapSnapshotGenerator(HeapSnapshot* snapshot, v8::ActivityControl* control,
v8::HeapProfiler::ContextNameResolver* resolver,
Heap* heap, cppgc::EmbedderStackState stack_state);
HeapSnapshotGenerator(const HeapSnapshotGenerator&) = delete;
HeapSnapshotGenerator& operator=(const HeapSnapshotGenerator&) = delete;
bool GenerateSnapshot();
-123
View File
@@ -2176,129 +2176,6 @@ TEST(DeleteHeapSnapshot) {
CHECK(!FindHeapSnapshot(heap_profiler, s3));
}
class NameResolver : public v8::HeapProfiler::ObjectNameResolver {
public:
const char* GetName(v8::Local<v8::Object> object) override {
return "Global object name";
}
};
TEST(GlobalObjectNameSimple) {
LocalContext env;
v8::HandleScope scope(env.isolate());
v8::HeapProfiler* heap_profiler = env.isolate()->GetHeapProfiler();
CompileRun("document = { URL:\"abcdefgh\" };");
// Allow usages of v8::HeapProfiler::ObjectNameResolver for now.
// TODO(https://crbug.com/333672197): remove.
START_ALLOW_USE_DEPRECATED()
NameResolver name_resolver;
const v8::HeapSnapshot* snapshot =
heap_profiler->TakeHeapSnapshot(nullptr, &name_resolver);
END_ALLOW_USE_DEPRECATED()
CHECK(ValidateSnapshot(snapshot));
const v8::HeapGraphNode* native_context = GetNativeContext(snapshot);
CHECK_NOT_NULL(native_context);
CHECK_EQ(std::string("system / NativeContext / Global object name"),
std::string(GetName(native_context)));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
CHECK_NOT_NULL(global);
CHECK_EQ(std::string("Object (global*) / Global object name"),
std::string(GetName(global)));
const v8::HeapGraphNode* global_proxy = GetProperty(
env.isolate(), global, v8::HeapGraphEdge::kInternal, "global_proxy");
CHECK_NOT_NULL(global_proxy);
CHECK_EQ(std::string("Object (global) / Global object name"),
std::string(GetName(global_proxy)));
}
TEST(GlobalObjectName) {
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope scope(isolate);
v8::Local<v8::FunctionTemplate> global_constructor =
v8::FunctionTemplate::New(isolate);
global_constructor->SetClassName(v8_str("MyGlobal"));
v8::Local<v8::ObjectTemplate> global_template =
v8::ObjectTemplate::New(isolate, global_constructor);
LocalContext env(isolate, nullptr, global_template);
v8::HeapProfiler* heap_profiler = env.isolate()->GetHeapProfiler();
CompileRun("document = { URL:\"abcdefgh\" };");
// Allow usages of v8::HeapProfiler::ObjectNameResolver for now.
// TODO(https://crbug.com/333672197): remove.
START_ALLOW_USE_DEPRECATED()
NameResolver name_resolver;
const v8::HeapSnapshot* snapshot =
heap_profiler->TakeHeapSnapshot(nullptr, &name_resolver);
END_ALLOW_USE_DEPRECATED()
CHECK(ValidateSnapshot(snapshot));
const v8::HeapGraphNode* native_context = GetNativeContext(snapshot);
CHECK_NOT_NULL(native_context);
CHECK_EQ(std::string("system / NativeContext / Global object name"),
std::string(GetName(native_context)));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot, false);
CHECK_NOT_NULL(global);
CHECK_EQ(std::string("MyGlobal (global*) / Global object name"),
std::string(GetName(global)));
const v8::HeapGraphNode* global_proxy = GetProperty(
env.isolate(), global, v8::HeapGraphEdge::kInternal, "global_proxy");
CHECK_NOT_NULL(global_proxy);
CHECK_EQ(std::string("MyGlobal (global) / Global object name"),
std::string(GetName(global_proxy)));
}
TEST(GlobalObjectNameDetached) {
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope scope(isolate);
v8::Local<v8::FunctionTemplate> global_constructor =
v8::FunctionTemplate::New(isolate);
global_constructor->SetClassName(v8_str("MyGlobal"));
v8::Local<v8::ObjectTemplate> global_template =
v8::ObjectTemplate::New(isolate, global_constructor);
LocalContext env(isolate, nullptr, global_template);
v8::HeapProfiler* heap_profiler = env.isolate()->GetHeapProfiler();
CompileRun("document = { URL:\"abcdefgh\" };");
env->DetachGlobal();
// Allow usages of v8::HeapProfiler::ObjectNameResolver for now.
// TODO(https://crbug.com/333672197): remove.
START_ALLOW_USE_DEPRECATED()
NameResolver name_resolver;
const v8::HeapSnapshot* snapshot =
heap_profiler->TakeHeapSnapshot(nullptr, &name_resolver);
END_ALLOW_USE_DEPRECATED()
CHECK(ValidateSnapshot(snapshot));
const v8::HeapGraphNode* native_context = GetNativeContext(snapshot);
CHECK_NOT_NULL(native_context);
CHECK_EQ(std::string("system / NativeContext / Global object name"),
std::string(GetName(native_context)));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot, false);
CHECK_NOT_NULL(global);
CHECK_EQ(std::string("MyGlobal (global*) / Global object name"),
std::string(GetName(global)));
const v8::HeapGraphNode* global_proxy = GetProperty(
env.isolate(), global, v8::HeapGraphEdge::kInternal, "global_proxy");
CHECK_NOT_NULL(global_proxy);
CHECK_EQ(std::string("Object (global) / <detached>"),
std::string(GetName(global_proxy)));
}
class ContextNameResolver : public v8::HeapProfiler::ContextNameResolver {
public:
const char* GetName(v8::Local<v8::Context> context) override {