Skip to content

Commit 1abe1d1

Browse files
gireeshpunathiladdaleax
authored andcommitted
src: track memory retainer fields
If retainers are embedded in retainers, direct tracking those lead to double tracking. Instead, use a special tracker that adjusts the tracking for the container object. PR-URL: #26161 Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 2a74a1e commit 1abe1d1

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/memory_tracker-inl.h

+7
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,13 @@ void MemoryTracker::Track(const MemoryRetainer* retainer,
241241
PopNode();
242242
}
243243

244+
void MemoryTracker::TrackInlineField(const MemoryRetainer* retainer,
245+
const char* edge_name) {
246+
Track(retainer, edge_name);
247+
CHECK(CurrentNode());
248+
CurrentNode()->size_ -= retainer->SelfSize();
249+
}
250+
244251
MemoryRetainerNode* MemoryTracker::CurrentNode() const {
245252
if (node_stack_.empty()) return nullptr;
246253
return node_stack_.top();

src/memory_tracker.h

+11
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,17 @@ class MemoryTracker {
197197
inline void Track(const MemoryRetainer* retainer,
198198
const char* edge_name = nullptr);
199199

200+
// Useful for parents that do not wish to perform manual
201+
// adjustments to its `SelfSize()` when embedding retainer
202+
// objects inline.
203+
// Put a memory container into the graph, create an edge from
204+
// the current node if there is one on the stack - there should
205+
// be one, of the container object which the current field is part of.
206+
// Reduce the size of memory from the container so as to avoid
207+
// duplication in accounting.
208+
inline void TrackInlineField(const MemoryRetainer* retainer,
209+
const char* edge_name = nullptr);
210+
200211
inline v8::EmbedderGraph* graph() { return graph_; }
201212
inline v8::Isolate* isolate() { return isolate_; }
202213

0 commit comments

Comments
 (0)