Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2060)

Unified Diff: third_party/WebKit/Source/platform/heap/Persistent.h

Issue 2602263002: Lend LSan a hand and clear out singleton static persistents first. (Closed)
Patch Set: experiment: disable LSan-GCing during shutdown.. Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/heap/PersistentNode.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/platform/heap/Persistent.h
diff --git a/third_party/WebKit/Source/platform/heap/Persistent.h b/third_party/WebKit/Source/platform/heap/Persistent.h
index 794753c93dd8661116a915453cb52540a94db514..9b4581627dc03cecf380ee25928c2dcff2c7d0ec 100644
--- a/third_party/WebKit/Source/platform/heap/Persistent.h
+++ b/third_party/WebKit/Source/platform/heap/Persistent.h
@@ -33,6 +33,39 @@ enum CrossThreadnessPersistentConfiguration {
CrossThreadPersistentConfiguration
};
+// Auxillary template, probing if |void T::clear()| exists and is accessible.
+// Used to conditionally clear the contents of a static persistent.
+template <typename T>
+class CanClearPersistentReference {
+ typedef char YesType;
+ typedef struct NoType { char padding[8]; } NoType;
+
+ // Check if class T has public method "void clear()".
+ template <typename V>
+ static YesType checkHasClearMethod(
+ V* p,
+ typename std::enable_if<
+ std::is_same<decltype(p->clear()), void>::value>::type* = nullptr);
+ template <typename V>
+ static NoType checkHasClearMethod(...);
+
+ public:
+ static const bool value = sizeof(YesType) + sizeof(T) ==
+ sizeof(checkHasClearMethod<T>(nullptr)) + sizeof(T);
+};
+
+template <typename T, bool = CanClearPersistentReference<T>::value>
+class ClearStaticPersistentReference {
+ public:
+ static void clear(T*) {}
+};
+
+template <typename T>
+class ClearStaticPersistentReference<T, true> {
+ public:
+ static void clear(T* ptr) { ptr->clear(); }
+};
+
template <typename T,
WeaknessPersistentConfiguration weaknessConfiguration,
CrossThreadnessPersistentConfiguration crossThreadnessConfiguration>
@@ -157,8 +190,8 @@ class PersistentBase {
PersistentBase* registerAsStaticReference() {
if (m_persistentNode) {
ASSERT(ThreadState::current());
- ThreadState::current()->registerStaticPersistentNode(m_persistentNode,
- nullptr);
+ ThreadState::current()->registerStaticPersistentNode(
+ m_persistentNode, &PersistentBase::clearPersistentNode);
LEAK_SANITIZER_IGNORE_OBJECT(this);
}
return this;
@@ -191,6 +224,16 @@ class PersistentBase {
uninitialize();
}
+ // Used when the registered PersistentNode of this object is
+ // released during ThreadState shutdown, clearing the association.
+ static void clearPersistentNode(void* self,
+ ThreadState::ReleasePersistentMode mode) {
+ PersistentBase* persistent = reinterpret_cast<PersistentBase*>(self);
+ ClearStaticPersistentReference<T>::clear(persistent->get());
+ if (mode == ThreadState::ReleasePersistent)
+ persistent->uninitialize();
+ }
+
template <typename VisitorDispatcher>
void tracePersistent(VisitorDispatcher visitor) {
static_assert(sizeof(T), "T must be fully defined");
@@ -600,11 +643,13 @@ class PersistentHeapCollectionBase : public Collection {
// Used when the registered PersistentNode of this object is
// released during ThreadState shutdown, clearing the association.
- static void clearPersistentNode(void* self) {
+ static void clearPersistentNode(void* self,
+ ThreadState::ReleasePersistentMode mode) {
PersistentHeapCollectionBase<Collection>* collection =
- (reinterpret_cast<PersistentHeapCollectionBase<Collection>*>(self));
- collection->uninitialize();
+ reinterpret_cast<PersistentHeapCollectionBase<Collection>*>(self);
collection->clear();
+ if (mode == ThreadState::ReleasePersistent)
+ collection->uninitialize();
}
NO_SANITIZE_ADDRESS
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/heap/PersistentNode.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698