summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorharaken <haraken@chromium.org>2015-12-07 17:57:06 -0800
committerCommit bot <commit-bot@chromium.org>2015-12-08 01:58:08 +0000
commitc604dae85fa7627e407ccd0dbe6017ea90704e0e (patch)
treef242fa985e5d343a8614eb3d7de25a80b93dd626
parent33c52dde3a9c355c6b21fc7725e200cda19c29a5 (diff)
downloadchromium_src-c604dae85fa7627e407ccd0dbe6017ea90704e0e.zip
chromium_src-c604dae85fa7627e407ccd0dbe6017ea90704e0e.tar.gz
chromium_src-c604dae85fa7627e407ccd0dbe6017ea90704e0e.tar.bz2
Revert of Release Oilpan heap singletons prior to LSan leak detection. (patchset #8 id:140001 of https://codereview.chromium.org/1491253004/ )
Reason for revert: This caused compile errors on Oilpan + no-LSan bots. http://build.chromium.org/p/chromium.webkit/builders/WebKit%20Linux%20Oilpan/builds/31816 It doesn't seem to be trivial to fix the error, so let me revert. Original issue's description: > Release Oilpan heap singletons prior to LSan leak detection. > > Make Oilpan and LSan cooperate better. As Persistent<> references > created via DEFINE_STATIC_LOCAL() and similar will be reachable to > LSan's leak detection pass, the objects they refer to outside of > the Oilpan heap will be reported as leaking. > > (This is in contrast to what happens in the non-Oilpan setting, > where the (leaked) pointer created via DEFINE_STATIC_LOCAL() is > stored in a local "static"; such non-global references are not > considered roots to LSan and hence the objects reachable from > those will not be reported as leaking.) > > Address the problem on the Oilpan side by having such "static" > Persistent<>ly-held singletons be registered and tracked such > that we're able to release them all just before shutting down > and performing an extra round of GCs. Leaving a cleaner heap > for LSan to work over. And to report no leaks over, ideally. > > As part of the changes needed to support this for Oilpan, > wtf/LeakAnnotations.h offerings has been renamed and changed > a bit: > > * WTF_ANNOTATE_MEMORY_LEAK_SCOPE => LEAK_SANITIZER_DISABLED_SCOPE. > (but see LeakAnnotations.h for macro to use local to wtf/.) > * WTF_ANNOTATE_IGNORE_OBJECT_PTR => LEAK_SANITIZER_IGNORE_OBJECT. > * LEAK_SANITIZER_REGISTER_STATIC_LOCAL(). > > R=haraken > BUG=567257 > > Committed: https://crrev.com/5699ffefdcb17f5150f0d9342d21f73b3e8958b7 > Cr-Commit-Position: refs/heads/master@{#363591} TBR=oilpan-reviews@chromium.org,sigbjornf@opera.com NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=567257 Review URL: https://codereview.chromium.org/1505003003 Cr-Commit-Position: refs/heads/master@{#363701}
-rw-r--r--third_party/WebKit/Source/bindings/core/v8/RejectedPromises.h4
-rw-r--r--third_party/WebKit/Source/bindings/core/v8/V8Initializer.cpp2
-rw-r--r--third_party/WebKit/Source/core/css/CSSDefaultStyleSheets.cpp2
-rw-r--r--third_party/WebKit/Source/core/css/CSSPrimitiveValue.cpp26
-rw-r--r--third_party/WebKit/Source/core/fetch/Resource.cpp6
-rw-r--r--third_party/WebKit/Source/core/html/forms/EmailInputType.cpp2
-rw-r--r--third_party/WebKit/Source/core/style/ComputedStyle.h2
-rw-r--r--third_party/WebKit/Source/platform/WebThreadSupportingGC.cpp3
-rw-r--r--third_party/WebKit/Source/platform/heap/Handle.h59
-rw-r--r--third_party/WebKit/Source/platform/heap/ThreadState.cpp33
-rw-r--r--third_party/WebKit/Source/platform/heap/ThreadState.h18
-rw-r--r--third_party/WebKit/Source/web/WebKit.cpp15
-rw-r--r--third_party/WebKit/Source/wtf/BitVector.cpp2
-rw-r--r--third_party/WebKit/Source/wtf/LeakAnnotations.h99
-rw-r--r--third_party/WebKit/Source/wtf/StdLibExtras.h24
-rw-r--r--third_party/WebKit/Source/wtf/text/StringImpl.cpp2
16 files changed, 47 insertions, 252 deletions
diff --git a/third_party/WebKit/Source/bindings/core/v8/RejectedPromises.h b/third_party/WebKit/Source/bindings/core/v8/RejectedPromises.h
index 9dc62c4..a839fc9 100644
--- a/third_party/WebKit/Source/bindings/core/v8/RejectedPromises.h
+++ b/third_party/WebKit/Source/bindings/core/v8/RejectedPromises.h
@@ -26,6 +26,7 @@ public:
return adoptRefWillBeNoop(new RejectedPromises);
}
+ RejectedPromises();
void dispose();
DECLARE_TRACE();
@@ -37,9 +38,8 @@ public:
private:
class Message;
- RejectedPromises();
-
using MessageQueue = WillBeHeapDeque<OwnPtrWillBeMember<Message>>;
+
PassOwnPtrWillBeRawPtr<MessageQueue> createMessageQueue();
void processQueueNow(PassOwnPtrWillBeRawPtr<MessageQueue>);
diff --git a/third_party/WebKit/Source/bindings/core/v8/V8Initializer.cpp b/third_party/WebKit/Source/bindings/core/v8/V8Initializer.cpp
index 0d9cb78..c611209 100644
--- a/third_party/WebKit/Source/bindings/core/v8/V8Initializer.cpp
+++ b/third_party/WebKit/Source/bindings/core/v8/V8Initializer.cpp
@@ -192,7 +192,7 @@ namespace {
static RejectedPromises& rejectedPromisesOnMainThread()
{
ASSERT(isMainThread());
- DEFINE_STATIC_LOCAL(RefPtrWillBePersistent<RejectedPromises>, rejectedPromises, (RejectedPromises::create()));
+ DEFINE_STATIC_LOCAL(RefPtrWillBePersistent<RejectedPromises>, rejectedPromises, (adoptRefWillBeNoop(new RejectedPromises())));
return *rejectedPromises;
}
diff --git a/third_party/WebKit/Source/core/css/CSSDefaultStyleSheets.cpp b/third_party/WebKit/Source/core/css/CSSDefaultStyleSheets.cpp
index 6eaed6ed..ad829bc 100644
--- a/third_party/WebKit/Source/core/css/CSSDefaultStyleSheets.cpp
+++ b/third_party/WebKit/Source/core/css/CSSDefaultStyleSheets.cpp
@@ -68,7 +68,7 @@ static PassRefPtrWillBeRawPtr<StyleSheetContents> parseUASheet(const String& str
sheet->parseString(str);
// User Agent stylesheets are parsed once for the lifetime of the renderer
// process and are intentionally leaked.
- LEAK_SANITIZER_IGNORE_OBJECT(sheet.get());
+ WTF_ANNOTATE_LEAKING_OBJECT_PTR(sheet.get());
return sheet.release();
}
diff --git a/third_party/WebKit/Source/core/css/CSSPrimitiveValue.cpp b/third_party/WebKit/Source/core/css/CSSPrimitiveValue.cpp
index 83ba6ad..de14f7a 100644
--- a/third_party/WebKit/Source/core/css/CSSPrimitiveValue.cpp
+++ b/third_party/WebKit/Source/core/css/CSSPrimitiveValue.cpp
@@ -158,33 +158,9 @@ bool CSSPrimitiveValue::colorIsDerivedFromElement() const
}
using CSSTextCache = WillBePersistentHeapHashMap<RawPtrWillBeWeakMember<const CSSPrimitiveValue>, String>;
-
-#if ENABLE(OILPAN) && defined(LEAK_SANITIZER)
-
-namespace {
-// With LSan, wrap the persistent cache so that the registration of the
-// (per-thread) static reference can be done.
-class CSSTextCacheWrapper {
-public:
- CSSTextCacheWrapper()
- {
- m_cache.registerAsStaticReference();
- }
-
- operator CSSTextCache&() { return m_cache; }
-
-private:
- CSSTextCache m_cache;
-};
-
-}
-#else
-using CSSTextCacheWrapper = CSSTextCache;
-#endif
-
static CSSTextCache& cssTextCache()
{
- AtomicallyInitializedStaticReference(ThreadSpecific<CSSTextCacheWrapper>, cache, new ThreadSpecific<CSSTextCacheWrapper>);
+ AtomicallyInitializedStaticReference(ThreadSpecific<CSSTextCache>, cache, new ThreadSpecific<CSSTextCache>());
return *cache;
}
diff --git a/third_party/WebKit/Source/core/fetch/Resource.cpp b/third_party/WebKit/Source/core/fetch/Resource.cpp
index 2898d9e..3681150 100644
--- a/third_party/WebKit/Source/core/fetch/Resource.cpp
+++ b/third_party/WebKit/Source/core/fetch/Resource.cpp
@@ -997,12 +997,6 @@ ResourcePriority Resource::priorityFromClients()
Resource::ResourceCallback* Resource::ResourceCallback::callbackHandler()
{
- // Oilpan + LSan: as the callbackHandler() singleton is used by Resource
- // and ResourcePtr finalizers, it cannot be released upon shutdown in
- // preparation for leak detection.
- //
- // Keep it out of LSan's reach instead.
- LEAK_SANITIZER_DISABLED_SCOPE;
DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<ResourceCallback>, callbackHandler, (adoptPtrWillBeNoop(new ResourceCallback)));
return callbackHandler.get();
}
diff --git a/third_party/WebKit/Source/core/html/forms/EmailInputType.cpp b/third_party/WebKit/Source/core/html/forms/EmailInputType.cpp
index 9494e68..3a0865e 100644
--- a/third_party/WebKit/Source/core/html/forms/EmailInputType.cpp
+++ b/third_party/WebKit/Source/core/html/forms/EmailInputType.cpp
@@ -141,7 +141,7 @@ bool EmailInputType::isValidEmailAddress(const String& address)
if (!addressLength)
return false;
- LEAK_SANITIZER_DISABLED_SCOPE;
+ WTF_ANNOTATE_SCOPED_MEMORY_LEAK;
DEFINE_STATIC_LOCAL(const ScriptRegexp, regExp, (emailPattern, TextCaseInsensitive));
int matchLength;
diff --git a/third_party/WebKit/Source/core/style/ComputedStyle.h b/third_party/WebKit/Source/core/style/ComputedStyle.h
index 4c288f2..da23091 100644
--- a/third_party/WebKit/Source/core/style/ComputedStyle.h
+++ b/third_party/WebKit/Source/core/style/ComputedStyle.h
@@ -78,7 +78,6 @@
#include "platform/text/UnicodeBidi.h"
#include "platform/transforms/TransformOperations.h"
#include "wtf/Forward.h"
-#include "wtf/LeakAnnotations.h"
#include "wtf/OwnPtr.h"
#include "wtf/RefCounted.h"
#include "wtf/StdLibExtras.h"
@@ -352,7 +351,6 @@ private:
static PassRefPtr<ComputedStyle> createInitialStyle();
static inline ComputedStyle* initialStyle()
{
- LEAK_SANITIZER_DISABLED_SCOPE;
DEFINE_STATIC_REF(ComputedStyle, s_initialStyle, (ComputedStyle::createInitialStyle()));
return s_initialStyle;
}
diff --git a/third_party/WebKit/Source/platform/WebThreadSupportingGC.cpp b/third_party/WebKit/Source/platform/WebThreadSupportingGC.cpp
index d622a6e..bf50fd6 100644
--- a/third_party/WebKit/Source/platform/WebThreadSupportingGC.cpp
+++ b/third_party/WebKit/Source/platform/WebThreadSupportingGC.cpp
@@ -54,9 +54,6 @@ void WebThreadSupportingGC::initialize()
void WebThreadSupportingGC::shutdown()
{
-#if defined(LEAK_SANITIZER)
- ThreadState::current()->releaseStaticPersistentNodes();
-#endif
// Ensure no posted tasks will run from this point on.
m_gcTaskRunner.clear();
diff --git a/third_party/WebKit/Source/platform/heap/Handle.h b/third_party/WebKit/Source/platform/heap/Handle.h
index f96bfc6..9ef17de 100644
--- a/third_party/WebKit/Source/platform/heap/Handle.h
+++ b/third_party/WebKit/Source/platform/heap/Handle.h
@@ -46,10 +46,6 @@
#include "wtf/RefCounted.h"
#include "wtf/TypeTraits.h"
-#if defined(LEAK_SANITIZER)
-#include "wtf/LeakAnnotations.h"
-#endif
-
namespace blink {
enum WeaknessPersistentConfiguration {
@@ -187,17 +183,6 @@ public:
return *this;
}
-#if defined(LEAK_SANITIZER)
- PersistentBase* registerAsStaticReference()
- {
- if (m_persistentNode) {
- ASSERT(ThreadState::current());
- ThreadState::current()->registerStaticPersistentNode(m_persistentNode);
- LEAK_SANITIZER_IGNORE_OBJECT(this);
- }
- return this;
- }
-#endif
private:
NO_LAZY_SWEEP_SANITIZE_ADDRESS
@@ -560,20 +545,7 @@ public:
visitor->trace(*static_cast<Collection*>(this));
}
-#if defined(LEAK_SANITIZER)
- PersistentHeapCollectionBase* registerAsStaticReference()
- {
- if (m_persistentNode) {
- ASSERT(ThreadState::current());
- ThreadState::current()->registerStaticPersistentNode(m_persistentNode);
- LEAK_SANITIZER_IGNORE_OBJECT(this);
- }
- return this;
- }
-#endif
-
private:
-
NO_LAZY_SWEEP_SANITIZE_ADDRESS
void initialize()
{
@@ -1095,7 +1067,7 @@ template<typename T> T* adoptPtrWillBeNoop(T* ptr)
#define DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(type) // do nothing
#define DEFINE_STATIC_REF_WILL_BE_PERSISTENT(type, name, arguments) \
- static type* name = *(new Persistent<type>(arguments))->registerAsStaticReference();
+ static type* name = (new Persistent<type>(arguments))->get();
#else // !ENABLE(OILPAN)
@@ -1294,35 +1266,6 @@ private:
CrossThreadWeakPersistent<T> m_value;
};
-// LEAK_SANITIZER_DISABLED_SCOPE: all allocations made in the current scope
-// will be exempted from LSan consideration.
-//
-// TODO(sof): move this to wtf/LeakAnnotations.h (LeakSanitizer.h?) once
-// wtf/ can freely call upon Oilpan functionality.
-#if defined(LEAK_SANITIZER)
-class LeakSanitizerDisableScope {
- STACK_ALLOCATED();
- WTF_MAKE_NONCOPYABLE(LeakSanitizerDisableScope);
-public:
- LeakSanitizerDisableScope()
- {
- __lsan_disable();
- if (ThreadState::current())
- ThreadState::current()->enterStaticReferenceRegistrationDisabledScope();
- }
-
- ~LeakSanitizerDisableScope()
- {
- __lsan_enable();
- if (ThreadState::current())
- ThreadState::current()->leaveStaticReferenceRegistrationDisabledScope();
- }
-};
-#define LEAK_SANITIZER_DISABLED_SCOPE LeakSanitizerDisableScope lsanDisabledScope
-#else
-#define LEAK_SANITIZER_DISABLED_SCOPE
-#endif
-
} // namespace blink
namespace WTF {
diff --git a/third_party/WebKit/Source/platform/heap/ThreadState.cpp b/third_party/WebKit/Source/platform/heap/ThreadState.cpp
index 7432d6b..3124668 100644
--- a/third_party/WebKit/Source/platform/heap/ThreadState.cpp
+++ b/third_party/WebKit/Source/platform/heap/ThreadState.cpp
@@ -104,9 +104,6 @@ ThreadState::ThreadState()
#if defined(ADDRESS_SANITIZER)
, m_asanFakeStack(__asan_get_current_fake_stack())
#endif
-#if defined(LEAK_SANITIZER)
- , m_disabledStaticPersistentsRegistration(0)
-#endif
{
ASSERT(checkThread());
ASSERT(!**s_threadSpecific);
@@ -1306,36 +1303,6 @@ void ThreadState::removeInterruptor(BlinkGCInterruptor* interruptor)
}
}
-#if defined(LEAK_SANITIZER)
-void ThreadState::registerStaticPersistentNode(PersistentNode* node)
-{
- if (m_disabledStaticPersistentsRegistration)
- return;
-
- ASSERT(!m_staticPersistents.contains(node));
- m_staticPersistents.add(node);
-}
-
-void ThreadState::releaseStaticPersistentNodes()
-{
- for (PersistentNode* node : m_staticPersistents)
- persistentRegion()->freePersistentNode(node);
-
- m_staticPersistents.clear();
-}
-
-void ThreadState::enterStaticReferenceRegistrationDisabledScope()
-{
- m_disabledStaticPersistentsRegistration++;
-}
-
-void ThreadState::leaveStaticReferenceRegistrationDisabledScope()
-{
- ASSERT(m_disabledStaticPersistentsRegistration);
- m_disabledStaticPersistentsRegistration--;
-}
-#endif
-
ThreadState::AttachedThreadStateSet& ThreadState::attachedThreads()
{
DEFINE_STATIC_LOCAL(AttachedThreadStateSet, threads, ());
diff --git a/third_party/WebKit/Source/platform/heap/ThreadState.h b/third_party/WebKit/Source/platform/heap/ThreadState.h
index 2e8e081..d071e25 100644
--- a/third_party/WebKit/Source/platform/heap/ThreadState.h
+++ b/third_party/WebKit/Source/platform/heap/ThreadState.h
@@ -56,7 +56,6 @@ class CrossThreadPersistentRegion;
struct GCInfo;
class GarbageCollectedMixinConstructorMarker;
class HeapObjectHeader;
-class PersistentNode;
class PersistentRegion;
class BaseHeap;
class SafePointAwareMutexLocker;
@@ -509,14 +508,6 @@ public:
size_t threadStackSize();
#endif
-#if defined(LEAK_SANITIZER)
- void registerStaticPersistentNode(PersistentNode*);
- void releaseStaticPersistentNodes();
-
- void enterStaticReferenceRegistrationDisabledScope();
- void leaveStaticReferenceRegistrationDisabledScope();
-#endif
-
private:
enum SnapshotType {
HeapSnapshot,
@@ -659,15 +650,6 @@ private:
void* m_asanFakeStack;
#endif
-#if defined(LEAK_SANITIZER)
- // PersistentNodes that are stored in static references;
- // references we have to clear before initiating LSan's leak detection.
- HashSet<PersistentNode*> m_staticPersistents;
-
- // Count that controls scoped disabling of persistent registration.
- size_t m_disabledStaticPersistentsRegistration;
-#endif
-
// Ideally we want to allocate an array of size |gcInfoTableMax| but it will
// waste memory. Thus we limit the array size to 2^8 and share one entry
// with multiple types of vectors. This won't be an issue in practice,
diff --git a/third_party/WebKit/Source/web/WebKit.cpp b/third_party/WebKit/Source/web/WebKit.cpp
index f6375b0..c892d8b 100644
--- a/third_party/WebKit/Source/web/WebKit.cpp
+++ b/third_party/WebKit/Source/web/WebKit.cpp
@@ -195,21 +195,6 @@ void initializeWithoutV8(Platform* platform)
void shutdown()
{
-#if defined(LEAK_SANITIZER)
- // If LSan is about to perform leak detection, release all the registered
- // static Persistent<> root references to global caches that Blink keeps,
- // followed by GCs to clear out all they referred to. A full v8 GC cycle
- // is needed to flush out all garbage.
- //
- // This is not needed for caches over non-Oilpan objects, as they're
- // not scanned by LSan due to being held in non-global storage
- // ("static" references inside functions/methods.)
- if (ThreadState* threadState = ThreadState::current()) {
- threadState->releaseStaticPersistentNodes();
- Heap::collectAllGarbage();
- }
-#endif
-
// currentThread() is null if we are running on a thread without a message loop.
if (Platform::current()->currentThread()) {
Platform::current()->unregisterMemoryDumpProvider(WebCacheMemoryDumpProvider::instance());
diff --git a/third_party/WebKit/Source/wtf/BitVector.cpp b/third_party/WebKit/Source/wtf/BitVector.cpp
index 939875e..0aaf1d4 100644
--- a/third_party/WebKit/Source/wtf/BitVector.cpp
+++ b/third_party/WebKit/Source/wtf/BitVector.cpp
@@ -77,7 +77,7 @@ BitVector::OutOfLineBits* BitVector::OutOfLineBits::create(size_t numBits)
{
// Because of the way BitVector stores the pointer, memory tools
// will erroneously report a leak here.
- WTF_INTERNAL_LEAK_SANITIZER_DISABLED_SCOPE;
+ WTF_ANNOTATE_SCOPED_MEMORY_LEAK;
numBits = (numBits + bitsInPointer() - 1) & ~(bitsInPointer() - 1);
size_t size = sizeof(OutOfLineBits) + sizeof(uintptr_t) * (numBits / bitsInPointer());
void* allocation = Partitions::bufferMalloc(size, WTF_HEAP_PROFILER_TYPE_NAME(OutOfLineBits));
diff --git a/third_party/WebKit/Source/wtf/LeakAnnotations.h b/third_party/WebKit/Source/wtf/LeakAnnotations.h
index 446992d..f330e17 100644
--- a/third_party/WebKit/Source/wtf/LeakAnnotations.h
+++ b/third_party/WebKit/Source/wtf/LeakAnnotations.h
@@ -32,22 +32,32 @@
#ifndef WTF_LeakAnnotations_h
#define WTF_LeakAnnotations_h
-// This file defines macros for working with LeakSanitizer, allowing memory
-// and allocations to be registered as exempted from LSan consideration.
+// This file defines macros which can be used to annotate intentional memory
+// leaks. Support for annotations is implemented in HeapChecker and
+// LeakSanitizer. Annotated objects will be treated as a source of live
+// pointers, i.e. any heap objects reachable by following pointers from an
+// annotated object will not be reported as leaks.
//
-// LSan exempted memory will be treated as a source of live pointers,
-// i.e. heap objects reachable by following pointers from an exempted
-// object will not be reported as leaks.
+// WTF_ANNOTATE_SCOPED_MEMORY_LEAK: all allocations made in the current scope
+// will be annotated as leaks.
+// WTF_ANNOTATE_LEAKING_OBJECT_PTR(X): the heap object referenced by pointer X
+// will be annotated as a leak.
//
+// Note that HeapChecker will report a fatal error if an object which has been
+// annotated with ANNOTATE_LEAKING_OBJECT_PTR is later deleted (but
+// LeakSanitizer won't).
+
#include "wtf/Noncopyable.h"
-#if USE(LEAK_SANITIZER)
-#include "wtf/AddressSanitizer.h"
-#include "wtf/TypeTraits.h"
-#endif
namespace WTF {
#if USE(LEAK_SANITIZER)
+extern "C" {
+void __lsan_disable();
+void __lsan_enable();
+void __lsan_ignore_object(const void* p);
+} // extern "C"
+
class LeakSanitizerDisabler {
WTF_MAKE_NONCOPYABLE(LeakSanitizerDisabler);
public:
@@ -62,75 +72,18 @@ public:
}
};
-// WTF_INTERNAL_LEAK_SANITIZER_DISABLED_SCOPE: all allocations made in the
-// current scope will be exempted from LSan consideration. Only to be
-// used internal to wtf/, Blink should use LEAK_SANITIZER_DISABLED_SCOPE
-// elsewhere.
-//
-// TODO(sof): once layering rules allow wtf/ to make use of the Oilpan
-// infrastructure, remove this macro.
-#define WTF_INTERNAL_LEAK_SANITIZER_DISABLED_SCOPE \
+#define WTF_ANNOTATE_SCOPED_MEMORY_LEAK \
WTF::LeakSanitizerDisabler leakSanitizerDisabler; static_cast<void>(0)
-// LEAK_SANITIZER_IGNORE_OBJECT(X): the heap object referenced by pointer X
-// will be ignored by LSan.
-#define LEAK_SANITIZER_IGNORE_OBJECT(X) __lsan_ignore_object(X)
-
-// If the object pointed to by the static local is on the Oilpan heap, a strong
-// Persistent<> is created to keep the pointed-to heap object alive. This makes
-// both the Persistent<> and the heap object _reachable_ by LeakSanitizer's leak
-// detection pass. We do not want these intentional leaks to be reported by LSan,
-// hence the static local is registered with Oilpan
-// (see RegisterStaticLocalReference<> below.)
-//
-// Upon Blink shutdown, all the registered statics are released and a final round
-// of GCs are performed to sweep out their now-unreachable object graphs. The end
-// result being a tidied heap that the LeakSanitizer can then scan to report real leaks.
-//
-// The CanRegisterStaticLocalReference<> and RegisterStaticLocalReference<> templates
-// arrange for this -- for a class type T, a registerStatic() implementation is
-// provided if "T* T::registerAsStaticReference(T*)" is a method on T
-// (inherited or otherwise.)
-//
-// An empty, trivial registerStatic() method is provided for all other class types T.
-template<typename T>
-class CanRegisterStaticLocalReference {
- typedef char YesType;
- typedef struct NoType {
- char padding[8];
- } NoType;
-
- // Check if class T has public method "T* registerAsStaticReference()".
- template<typename V> static YesType checkHasRegisterAsStaticReferenceMethod(V* p, typename EnableIf<IsSubclass<V, typename std::remove_pointer<decltype(p->registerAsStaticReference())>::type>::value>::Type* = 0);
- template<typename V> static NoType checkHasRegisterAsStaticReferenceMethod(...);
-
-public:
- static const bool value = sizeof(YesType) + sizeof(T) == sizeof(checkHasRegisterAsStaticReferenceMethod<T>(nullptr)) + sizeof(T);
-};
+#define WTF_ANNOTATE_LEAKING_OBJECT_PTR(X) \
+ WTF::__lsan_ignore_object(X)
-template<typename T, bool = CanRegisterStaticLocalReference<T>::value>
-class RegisterStaticLocalReference {
-public:
- static T* registerStatic(T* ptr)
- {
- return ptr;
- }
-};
+#else // USE(LEAK_SANITIZER)
-template<typename T>
-class RegisterStaticLocalReference<T, true> {
-public:
- static T* registerStatic(T* ptr)
- {
- return static_cast<T*>(ptr->registerAsStaticReference());
- }
-};
+// If Leak Sanitizer is not being used, the annotations should be no-ops.
+#define WTF_ANNOTATE_SCOPED_MEMORY_LEAK
+#define WTF_ANNOTATE_LEAKING_OBJECT_PTR(X)
-#define LEAK_SANITIZER_REGISTER_STATIC_LOCAL(Type, Object) WTF::RegisterStaticLocalReference<Type>::registerStatic(Object)
-#else
-#define WTF_INTERNAL_LEAK_SANITIZER_DISABLED_SCOPE
-#define LEAK_SANITIZER_IGNORE_OBJECT
-#define LEAK_SANITIZER_REGISTER_STATIC_LOCAL(Type, Object) Object
#endif // USE(LEAK_SANITIZER)
} // namespace WTF
diff --git a/third_party/WebKit/Source/wtf/StdLibExtras.h b/third_party/WebKit/Source/wtf/StdLibExtras.h
index 623fd15..62acd85 100644
--- a/third_party/WebKit/Source/wtf/StdLibExtras.h
+++ b/third_party/WebKit/Source/wtf/StdLibExtras.h
@@ -29,7 +29,6 @@
#include "wtf/Assertions.h"
#include "wtf/CPU.h"
#include "wtf/CheckedArithmetic.h"
-#include "wtf/LeakAnnotations.h"
#include <cstddef>
#if ENABLE(ASSERT)
@@ -59,30 +58,31 @@ private:
};
#endif
-// Use DEFINE_STATIC_LOCAL() to declare and define a static local variable (static T;)
-// so that it is leaked and its destructors are not called at exit.
-//
-// To cooperate with leak detection, the objects held onto by these local statics
-// will in some cases have to be finalized prior to leak checking. This only applies
-// to static references to Oilpan heap objects and what they transitively hold on to.
-// LEAK_SANITIZER_REGISTER_STATIC_LOCAL() takes care of the details.
-//
+// Use this to declare and define a static local variable (static T;) so that
+// it is leaked so that its destructors are not called at exit.
+#ifndef DEFINE_STATIC_LOCAL
+
#if ENABLE(ASSERT)
#define DEFINE_STATIC_LOCAL(type, name, arguments) \
static StaticLocalVerifier name##StaticLocalVerifier; \
- ASSERT(name##StaticLocalVerifier.isNotRacy()); \
- static type& name = *LEAK_SANITIZER_REGISTER_STATIC_LOCAL(type, new type arguments)
+ ASSERT(name##StaticLocalVerifier.isNotRacy()); \
+ static type& name = *new type arguments
#else
#define DEFINE_STATIC_LOCAL(type, name, arguments) \
- static type& name = *LEAK_SANITIZER_REGISTER_STATIC_LOCAL(type, new type arguments)
+ static type& name = *new type arguments
+#endif
+
#endif
+
// Use this to declare and define a static local pointer to a ref-counted object so that
// it is leaked so that the object's destructors are not called at exit.
// This macro should be used with ref-counted objects rather than DEFINE_STATIC_LOCAL macro,
// as this macro does not lead to an extra memory allocation.
+#ifndef DEFINE_STATIC_REF
#define DEFINE_STATIC_REF(type, name, arguments) \
static type* name = PassRefPtr<type>(arguments).leakRef();
+#endif
/*
* The reinterpret_cast<Type1*>([pointer to Type2]) expressions - where
diff --git a/third_party/WebKit/Source/wtf/text/StringImpl.cpp b/third_party/WebKit/Source/wtf/text/StringImpl.cpp
index 2163aaf..64bae95 100644
--- a/third_party/WebKit/Source/wtf/text/StringImpl.cpp
+++ b/third_party/WebKit/Source/wtf/text/StringImpl.cpp
@@ -361,7 +361,7 @@ StringImpl* StringImpl::createStatic(const char* string, unsigned length, unsign
RELEASE_ASSERT(length <= ((std::numeric_limits<unsigned>::max() - sizeof(StringImpl)) / sizeof(LChar)));
size_t size = sizeof(StringImpl) + length * sizeof(LChar);
- WTF_INTERNAL_LEAK_SANITIZER_DISABLED_SCOPE;
+ WTF_ANNOTATE_SCOPED_MEMORY_LEAK;
StringImpl* impl = static_cast<StringImpl*>(Partitions::bufferMalloc(size, "WTF::StringImpl"));
LChar* data = reinterpret_cast<LChar*>(impl + 1);