From 81060c32da9f9c1a356a238c7d5bd5e614594cdc Mon Sep 17 00:00:00 2001 From: Michael Lippautz Date: Tue, 11 Dec 2018 22:02:28 +0100 Subject: [PATCH] [api] Allow label annotations for PersistentValueMapBase Allows adding a label to strong retainers in PersistentValueMapBase and its subclasses. These labels show up in DevTools and enable identifying strong retainers of objects. R: ulan@chromium.org Change-Id: Id5e19507c40e44688c82a4caec89449b563a0e8b Reviewed-on: https://chromium-review.googlesource.com/c/1372069 Reviewed-by: Ulan Degenbaev Commit-Queue: Michael Lippautz Cr-Commit-Position: refs/heads/master@{#58177} --- include/v8-util.h | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/include/v8-util.h b/include/v8-util.h index 475026fe2c..7f12ead16b 100644 --- a/include/v8-util.h +++ b/include/v8-util.h @@ -287,7 +287,10 @@ class PersistentValueMapBase { } protected: - explicit PersistentValueMapBase(Isolate* isolate) : isolate_(isolate) {} + explicit PersistentValueMapBase(Isolate* isolate) + : isolate_(isolate), label_(nullptr) {} + PersistentValueMapBase(Isolate* isolate, const char* label) + : isolate_(isolate), label_(label) {} ~PersistentValueMapBase() { Clear(); } @@ -329,6 +332,10 @@ class PersistentValueMapBase { p.Reset(); } + void AnnotateStrongRetainer(Global* persistent) { + persistent->AnnotateStrongRetainer(label_); + } + private: PersistentValueMapBase(PersistentValueMapBase&); void operator=(PersistentValueMapBase&); @@ -345,6 +352,7 @@ class PersistentValueMapBase { Isolate* isolate_; typename Traits::Impl impl_; + const char* label_; }; @@ -353,6 +361,8 @@ class PersistentValueMap : public PersistentValueMapBase { public: explicit PersistentValueMap(Isolate* isolate) : PersistentValueMapBase(isolate) {} + PersistentValueMap(Isolate* isolate, const char* label) + : PersistentValueMapBase(isolate, label) {} typedef typename PersistentValueMapBase::PersistentValueReference @@ -380,7 +390,9 @@ class PersistentValueMap : public PersistentValueMapBase { * by the Traits class. */ Global SetUnique(const K& key, Global* persistent) { - if (Traits::kCallbackType != kNotWeak) { + if (Traits::kCallbackType == kNotWeak) { + this->AnnotateStrongRetainer(persistent); + } else { WeakCallbackType callback_type = Traits::kCallbackType == kWeakWithInternalFields ? WeakCallbackType::kInternalFields @@ -425,6 +437,8 @@ class GlobalValueMap : public PersistentValueMapBase { public: explicit GlobalValueMap(Isolate* isolate) : PersistentValueMapBase(isolate) {} + GlobalValueMap(Isolate* isolate, const char* label) + : PersistentValueMapBase(isolate, label) {} typedef typename PersistentValueMapBase::PersistentValueReference @@ -452,7 +466,9 @@ class GlobalValueMap : public PersistentValueMapBase { * by the Traits class. */ Global SetUnique(const K& key, Global* persistent) { - if (Traits::kCallbackType != kNotWeak) { + if (Traits::kCallbackType == kNotWeak) { + this->AnnotateStrongRetainer(persistent); + } else { WeakCallbackType callback_type = Traits::kCallbackType == kWeakWithInternalFields ? WeakCallbackType::kInternalFields