From 6e60ab744e6a1371aa514cb5b6a5cedceb2a706b Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Tue, 11 Mar 2025 20:02:17 +0100 Subject: [PATCH] src: annotate BaseObjects in the heap snapshots correctly This fixes two issues in the BaseObject views in the heap snapshots: 1. BaseObjects are not conceptually roots when the environment and the realms are also showing up in the heap snapshot. Rather, they should be considered being held alive by the BaseObjectList in the realms, which are in turn held alive by Environment. The actual root from the containment view should be the Environment instead. 2. The concept of DOM detaching does not really apply to Node.js wrappers, and it's confusing to connect that with the weakness or detachment (native weakness) of BaseObjects. To avoid the confusion, just restore to the default detachedness for them. PR-URL: https://github.com/nodejs/node/pull/57417 Reviewed-By: James M Snell Reviewed-By: Chengzhong Wu --- src/base_object-inl.h | 5 ----- src/base_object.cc | 4 ---- src/base_object.h | 3 --- 3 files changed, 12 deletions(-) diff --git a/src/base_object-inl.h b/src/base_object-inl.h index 6f731b17fe0..cc60ddddb03 100644 --- a/src/base_object-inl.h +++ b/src/base_object-inl.h @@ -125,11 +125,6 @@ bool BaseObject::IsWeakOrDetached() const { return pd->wants_weak_jsobj || pd->is_detached; } -v8::EmbedderGraph::Node::Detachedness BaseObject::GetDetachedness() const { - return IsWeakOrDetached() ? v8::EmbedderGraph::Node::Detachedness::kDetached - : v8::EmbedderGraph::Node::Detachedness::kUnknown; -} - template void BaseObject::InternalFieldGet( const v8::FunctionCallbackInfo& args) { diff --git a/src/base_object.cc b/src/base_object.cc index 593fce4382a..404e2aa8c88 100644 --- a/src/base_object.cc +++ b/src/base_object.cc @@ -161,10 +161,6 @@ Local BaseObject::WrappedObject() const { return object(); } -bool BaseObject::IsRootNode() const { - return !persistent_handle_.IsWeak(); -} - bool BaseObject::IsNotIndicativeOfMemoryLeakAtExit() const { return IsWeakOrDetached(); } diff --git a/src/base_object.h b/src/base_object.h index f5b791187ec..da49eacb647 100644 --- a/src/base_object.h +++ b/src/base_object.h @@ -105,8 +105,6 @@ class BaseObject : public MemoryRetainer { // to it anymore. inline bool IsWeakOrDetached() const; - inline v8::EmbedderGraph::Node::Detachedness GetDetachedness() const override; - // Utility to create a FunctionTemplate with one internal field (used for // the `BaseObject*` pointer) and a constructor that initializes that field // to `nullptr`. @@ -192,7 +190,6 @@ class BaseObject : public MemoryRetainer { private: v8::Local WrappedObject() const override; - bool IsRootNode() const override; void DeleteMe(); // persistent_handle_ needs to be at a fixed offset from the start of the