Skip to content

Commit

Permalink
src: track memory retainer fields
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
gireeshpunathil authored and addaleax committed Mar 1, 2019
1 parent 2a74a1e commit 1abe1d1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/memory_tracker-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,13 @@ void MemoryTracker::Track(const MemoryRetainer* retainer,
PopNode();
}

void MemoryTracker::TrackInlineField(const MemoryRetainer* retainer,
const char* edge_name) {
Track(retainer, edge_name);
CHECK(CurrentNode());
CurrentNode()->size_ -= retainer->SelfSize();
}

MemoryRetainerNode* MemoryTracker::CurrentNode() const {
if (node_stack_.empty()) return nullptr;
return node_stack_.top();
Expand Down
11 changes: 11 additions & 0 deletions src/memory_tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,17 @@ class MemoryTracker {
inline void Track(const MemoryRetainer* retainer,
const char* edge_name = nullptr);

// Useful for parents that do not wish to perform manual
// adjustments to its `SelfSize()` when embedding retainer
// objects inline.
// Put a memory container into the graph, create an edge from
// the current node if there is one on the stack - there should
// be one, of the container object which the current field is part of.
// Reduce the size of memory from the container so as to avoid
// duplication in accounting.
inline void TrackInlineField(const MemoryRetainer* retainer,
const char* edge_name = nullptr);

inline v8::EmbedderGraph* graph() { return graph_; }
inline v8::Isolate* isolate() { return isolate_; }

Expand Down

0 comments on commit 1abe1d1

Please sign in to comment.