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

Side by Side Diff: third_party/WebKit/Source/wtf/LeakAnnotations.h

Issue 1491253004: Release Oilpan heap singletons prior to LSan leak detection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move static-local ref registration to wtf/LeakAnnotations.h Created 5 years 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * Copyright (C) 2013 Samsung Electronics. All rights reserved. 3 * Copyright (C) 2013 Samsung Electronics. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 14 matching lines...) Expand all
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32 #ifndef WTF_LeakAnnotations_h 32 #ifndef WTF_LeakAnnotations_h
33 #define WTF_LeakAnnotations_h 33 #define WTF_LeakAnnotations_h
34 34
35 // This file defines macros which can be used to annotate intentional memory 35 // This file defines macros for working with LeakSanitizer, allowing memory
36 // leaks. Support for annotations is implemented in HeapChecker and 36 // and allocations to be registered as exempted from LSan consideration.
37 // LeakSanitizer. Annotated objects will be treated as a source of live
38 // pointers, i.e. any heap objects reachable by following pointers from an
39 // annotated object will not be reported as leaks.
40 // 37 //
41 // WTF_ANNOTATE_SCOPED_MEMORY_LEAK: all allocations made in the current scope 38 // LSan exempted memory will be treated as a source of live pointers,
42 // will be annotated as leaks. 39 // i.e. heap objects reachable by following pointers from an exempted
43 // WTF_ANNOTATE_LEAKING_OBJECT_PTR(X): the heap object referenced by pointer X 40 // object will not be reported as leaks.
44 // will be annotated as a leak.
45 // 41 //
46 // Note that HeapChecker will report a fatal error if an object which has been
47 // annotated with ANNOTATE_LEAKING_OBJECT_PTR is later deleted (but
48 // LeakSanitizer won't).
49
50 #include "wtf/Noncopyable.h" 42 #include "wtf/Noncopyable.h"
43 #if USE(LEAK_SANITIZER)
44 #include "wtf/TypeTraits.h"
45 #endif
51 46
52 namespace WTF { 47 namespace WTF {
53 48
54 #if USE(LEAK_SANITIZER) 49 #if USE(LEAK_SANITIZER)
55 extern "C" { 50 extern "C" {
56 void __lsan_disable(); 51 void __lsan_disable();
57 void __lsan_enable(); 52 void __lsan_enable();
58 void __lsan_ignore_object(const void* p); 53 void __lsan_ignore_object(const void* p);
59 } // extern "C" 54 } // extern "C"
60 55
61 class LeakSanitizerDisabler { 56 class LeakSanitizerDisabler {
62 WTF_MAKE_NONCOPYABLE(LeakSanitizerDisabler); 57 WTF_MAKE_NONCOPYABLE(LeakSanitizerDisabler);
63 public: 58 public:
64 LeakSanitizerDisabler() 59 LeakSanitizerDisabler()
65 { 60 {
66 __lsan_disable(); 61 __lsan_disable();
67 } 62 }
68 63
69 ~LeakSanitizerDisabler() 64 ~LeakSanitizerDisabler()
70 { 65 {
71 __lsan_enable(); 66 __lsan_enable();
72 } 67 }
73 }; 68 };
74 69
75 #define WTF_ANNOTATE_SCOPED_MEMORY_LEAK \ 70 // LEAK_MEMORY_LEAK_SCOPE: all allocations made in the current scope
71 // will be exempted from LSan consideration.
72 #define WTF_ANNOTATE_LEAK_SCOPE \
76 WTF::LeakSanitizerDisabler leakSanitizerDisabler; static_cast<void>(0) 73 WTF::LeakSanitizerDisabler leakSanitizerDisabler; static_cast<void>(0)
77 74
78 #define WTF_ANNOTATE_LEAKING_OBJECT_PTR(X) \ 75 // WTF_ANNOTATE_LEAK_IGNORE_OBJECT(X): the heap object referenced by pointer X
79 WTF::__lsan_ignore_object(X) 76 // will be ignored by LSan.
77 //
78 #define WTF_ANNOTATE_LEAK_IGNORE_OBJECT(X) WTF::__lsan_ignore_object(X)
80 79
81 #else // USE(LEAK_SANITIZER) 80 // If the object pointed to by the static local is on the Oilpan heap, a strong
81 // Persistent<> is created to keep the pointed-to heap object alive. This makes
82 // both the Persistent<> and the heap object _reachable_ by LeakSanitizer's leak
83 // detection pass. We do not want these intentional leaks to be reported by LSan ,
84 // hence the static local is registered with Oilpan
85 // (see RegisterStaticLocalReference<> below.)
86 //
87 // Upon Blink shutdown, all the registered statics are released and a final roun d
88 // of GCs are performed to sweep out their now-unreachable object graphs. The en d
89 // result being a tidied heap that the LeakSanitizer can then scan to report rea l leaks.
90 //
91 // The CanRegisterStaticLocalReference<> and RegisterStaticLocalReference<> temp lates
92 // arrange for this -- for a class type T, a registerStatic() implementation is
93 // provided if "T* T::registerAsStaticReference(T*)" is a method on T
94 // (inherited or otherwise.)
95 //
96 // An empty, trivial registerStatic() method is provided for all other class typ es T.
97 template<typename T>
98 class CanRegisterStaticLocalReference {
99 typedef char YesType;
100 typedef struct NoType {
101 char padding[8];
102 } NoType;
82 103
83 // If Leak Sanitizer is not being used, the annotations should be no-ops. 104 // Check if class T has public method "T* registerAsStaticReference()".
84 #define WTF_ANNOTATE_SCOPED_MEMORY_LEAK 105 template<typename V> static YesType checkHasRegisterAsStaticReferenceMethod( V* p, typename EnableIf<IsSubclass<V, typename std::remove_pointer<decltype(p->r egisterAsStaticReference())>::type>::value>::Type* = 0);
85 #define WTF_ANNOTATE_LEAKING_OBJECT_PTR(X) 106 template<typename V> static NoType checkHasRegisterAsStaticReferenceMethod(. ..);
107
108 public:
109 static const bool value = sizeof(YesType) + sizeof(T) == sizeof(checkHasRegi sterAsStaticReferenceMethod<T>(nullptr)) + sizeof(T);
110 };
111
112 template<typename T, bool = CanRegisterStaticLocalReference<T>::value>
113 class RegisterStaticLocalReference {
114 public:
115 static T* registerStatic(T* ptr)
116 {
117 return ptr;
118 }
119 };
120
121 template<typename T>
122 class RegisterStaticLocalReference<T, true> {
123 public:
124 static T* registerStatic(T* ptr)
125 {
126 return static_cast<T*>(ptr->registerAsStaticReference());
127 }
128 };
129
130 #define WTF_ANNOTATE_LEAK_REGISTER_STATIC_LOCAL(Type, Object) WTF::RegisterStati cLocalReference<Type>::registerStatic(Object)
131
132 #else
133
134 #define WTF_ANNOTATE_LEAK_SCOPE
135 #define WTF_ANNOTATE_LEAK_IGNORE_OBJECT(X)
136 #define WTF_ANNOTATE_LEAK_REGISTER_STATIC_LOCAL(Type, Object) Object
haraken 2015/12/06 23:56:21 It's a bit confusing to have four macros to annota
86 137
87 #endif // USE(LEAK_SANITIZER) 138 #endif // USE(LEAK_SANITIZER)
88 139
89 } // namespace WTF 140 } // namespace WTF
90 141
91 #endif // WTF_LeakAnnotations_h 142 #endif // WTF_LeakAnnotations_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698