Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit daf3152

Browse filesBrowse files
joyeecheungdanielleadams
authored andcommitted
src: implement GetDetachedness() in MemoryRetainerNode
This allows us to mark weak/detached references in the heap snapshot. Also mark weak/detached BaseObject with Detachedness::kDetached so that the state of the reference can be displayed by frontend consuming the heap snapshot. PR-URL: #44803 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 7ca77dd commit daf3152
Copy full SHA for daf3152

File tree

Expand file treeCollapse file tree

6 files changed

+34
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

6 files changed

+34
-1
lines changed
Open diff view settings
Collapse file

‎src/base_object-inl.h‎

Copy file name to clipboardExpand all lines: src/base_object-inl.h
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ bool BaseObject::IsWeakOrDetached() const {
9292
return pd->wants_weak_jsobj || pd->is_detached;
9393
}
9494

95+
v8::EmbedderGraph::Node::Detachedness BaseObject::GetDetachedness() const {
96+
return IsWeakOrDetached() ? v8::EmbedderGraph::Node::Detachedness::kDetached
97+
: v8::EmbedderGraph::Node::Detachedness::kUnknown;
98+
}
99+
95100
template <int Field>
96101
void BaseObject::InternalFieldGet(
97102
v8::Local<v8::String> property,
Collapse file

‎src/base_object.h‎

Copy file name to clipboardExpand all lines: src/base_object.h
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ class BaseObject : public MemoryRetainer {
8585
// to it anymore.
8686
inline bool IsWeakOrDetached() const;
8787

88+
inline v8::EmbedderGraph::Node::Detachedness GetDetachedness() const override;
89+
8890
// Utility to create a FunctionTemplate with one internal field (used for
8991
// the `BaseObject*` pointer) and a constructor that initializes that field
9092
// to `nullptr`.
Collapse file

‎src/memory_tracker-inl.h‎

Copy file name to clipboardExpand all lines: src/memory_tracker-inl.h
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class MemoryRetainerNode : public v8::EmbedderGraph::Node {
3131

3232
name_ = retainer_->MemoryInfoName();
3333
size_ = retainer_->SelfSize();
34+
detachedness_ = retainer_->GetDetachedness();
3435
}
3536

3637
inline MemoryRetainerNode(MemoryTracker* tracker,
@@ -57,6 +58,9 @@ class MemoryRetainerNode : public v8::EmbedderGraph::Node {
5758
}
5859
return is_root_node_;
5960
}
61+
v8::EmbedderGraph::Node::Detachedness GetDetachedness() override {
62+
return detachedness_;
63+
}
6064

6165
private:
6266
friend class MemoryTracker;
@@ -73,6 +77,8 @@ class MemoryRetainerNode : public v8::EmbedderGraph::Node {
7377
bool is_root_node_ = false;
7478
std::string name_;
7579
size_t size_ = 0;
80+
v8::EmbedderGraph::Node::Detachedness detachedness_ =
81+
v8::EmbedderGraph::Node::Detachedness::kUnknown;
7682
};
7783

7884
void MemoryTracker::TrackFieldWithSize(const char* edge_name,
Collapse file

‎src/memory_tracker.h‎

Copy file name to clipboardExpand all lines: src/memory_tracker.h
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ class MemoryRetainer {
127127
}
128128

129129
virtual bool IsRootNode() const { return false; }
130+
virtual v8::EmbedderGraph::Node::Detachedness GetDetachedness() const {
131+
return v8::EmbedderGraph::Node::Detachedness::kUnknown;
132+
}
130133
};
131134

132135
class MemoryTracker {
Collapse file

‎test/common/heap.js‎

Copy file name to clipboardExpand all lines: test/common/heap.js
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,22 @@ class State {
142142
}
143143
}
144144
}
145+
146+
if (expectation.detachedness !== undefined) {
147+
const matchedNodes = rootNodes.filter(
148+
(node) => node.detachedness === expectation.detachedness);
149+
if (loose) {
150+
assert(matchedNodes.length >= rootNodes.length,
151+
`Expect to find at least ${rootNodes.length} with ` +
152+
`detachedness ${expectation.detachedness}, ` +
153+
`found ${matchedNodes.length}`);
154+
} else {
155+
assert.strictEqual(
156+
matchedNodes.length, rootNodes.length,
157+
`Expect to find ${rootNodes.length} with detachedness ` +
158+
`${expectation.detachedness}, found ${matchedNodes.length}`);
159+
}
160+
}
145161
}
146162
}
147163

Collapse file

‎test/pummel/test-heapdump-dns.js‎

Copy file name to clipboardExpand all lines: test/pummel/test-heapdump-dns.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ validateSnapshotNodes('Node / ChannelWrap', [
1313
{ node_name: 'Node / NodeAresTask::List', edge_name: 'task_list' },
1414
// `Node / ChannelWrap` (C++) -> `ChannelWrap` (JS)
1515
{ node_name: 'ChannelWrap', edge_name: 'wrapped' },
16-
]
16+
],
17+
detachedness: 2
1718
},
1819
]);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.