OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #ifndef WTF_StdLibExtras_h | 26 #ifndef WTF_StdLibExtras_h |
27 #define WTF_StdLibExtras_h | 27 #define WTF_StdLibExtras_h |
28 | 28 |
| 29 #include <cstddef> |
29 #include "base/numerics/safe_conversions.h" | 30 #include "base/numerics/safe_conversions.h" |
| 31 #include "wtf/Allocator.h" |
30 #include "wtf/Assertions.h" | 32 #include "wtf/Assertions.h" |
31 #include "wtf/CPU.h" | 33 #include "wtf/CPU.h" |
32 #include "wtf/LeakAnnotations.h" | 34 #include "wtf/LeakAnnotations.h" |
33 #include "wtf/TypeTraits.h" | 35 #include "wtf/TypeTraits.h" |
34 #include <cstddef> | |
35 | 36 |
36 #if DCHECK_IS_ON() | 37 #if DCHECK_IS_ON() |
37 #include "wtf/Noncopyable.h" | 38 #include "wtf/Noncopyable.h" |
38 #include "wtf/Threading.h" | 39 #include "wtf/Threading.h" |
39 | 40 |
40 class WTF_EXPORT StaticLocalVerifier { | 41 class WTF_EXPORT StaticLocalVerifier { |
41 WTF_MAKE_NONCOPYABLE(StaticLocalVerifier); | 42 WTF_MAKE_NONCOPYABLE(StaticLocalVerifier); |
42 | 43 |
43 public: | 44 public: |
44 StaticLocalVerifier() | 45 StaticLocalVerifier() |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 // wrapped up by an off-heap Persistent<T> reference to the object, keeping | 106 // wrapped up by an off-heap Persistent<T> reference to the object, keeping |
106 // it alive across GCs. | 107 // it alive across GCs. |
107 // | 108 // |
108 // To cooperate with leak detection(LSan) for Blink garbage collected objects, | 109 // To cooperate with leak detection(LSan) for Blink garbage collected objects, |
109 // the objects owned by persistent local statics will in some cases have to be | 110 // the objects owned by persistent local statics will in some cases have to be |
110 // finalized prior to leak checking. This only applies to static references to | 111 // finalized prior to leak checking. This only applies to static references to |
111 // Blink heap objects and what they transitively hold on to. Hence the | 112 // Blink heap objects and what they transitively hold on to. Hence the |
112 // LEAK_SANITIZER_REGISTER_STATIC_LOCAL() use, it taking care of the grungy | 113 // LEAK_SANITIZER_REGISTER_STATIC_LOCAL() use, it taking care of the grungy |
113 // details. | 114 // details. |
114 // | 115 // |
115 #define DEFINE_STATIC_LOCAL(Type, Name, Arguments) \ | 116 |
116 DEFINE_STATIC_LOCAL_CHECK_THREADSAFE_ACCESS(Name); \ | 117 #define DEFINE_STATIC_LOCAL(Type, Name, Arguments) \ |
117 using WrappedTypeFor##Name = StaticLocalWrapper<Type>::WrapType; \ | 118 STATIC_ALLOCATED_SINGLETON() \ |
118 static WrappedTypeFor##Name* WrappedInstanceFor##Name = \ | 119 static StaticLocalWrapper<Type>::WrapType* WrappedInstanceFor##Name = \ |
119 LEAK_SANITIZER_REGISTER_STATIC_LOCAL( \ | 120 LEAK_SANITIZER_REGISTER_STATIC_LOCAL( \ |
120 WrappedTypeFor##Name, new WrappedTypeFor##Name Arguments); \ | 121 StaticLocalWrapper<Type>::WrapType, \ |
121 Type& Name = StaticLocalWrapper<Type>::unwrap(WrappedInstanceFor##Name); | 122 new StaticLocalWrapper<Type>::WrapType Arguments); \ |
| 123 DEFINE_STATIC_LOCAL_CHECK_THREADSAFE_ACCESS(Name); \ |
| 124 Type& Name = StaticLocalWrapper<Type>::unwrap(WrappedInstanceFor##Name) |
| 125 |
| 126 // Static local singletons that embed ScriptWrappable-derived objects are |
| 127 // problematic (see issue 688569). The clang GC plugin issues warnings |
| 128 // when encountering such singletons. If you cannot avoid introducing |
| 129 // the static local and can prove that the ScriptWrappable reference is |
| 130 // safe, you may use ALLOW_UNSAFE_SINGLETON() to disable the clang GC |
| 131 // plugin check. See issue 688569 for more details. |
| 132 // |
| 133 #define ALLOW_UNSAFE_SINGLETON() GC_PLUGIN_IGNORE("crbug.com/688569") |
122 | 134 |
123 // Use this to declare and define a static local pointer to a ref-counted object | 135 // Use this to declare and define a static local pointer to a ref-counted object |
124 // so that it is leaked so that the object's destructors are not called at | 136 // so that it is leaked so that the object's destructors are not called at |
125 // exit. This macro should be used with ref-counted objects rather than | 137 // exit. This macro should be used with ref-counted objects rather than |
126 // DEFINE_STATIC_LOCAL macro, as this macro does not lead to an extra memory | 138 // DEFINE_STATIC_LOCAL macro, as this macro does not lead to an extra memory |
127 // allocation. | 139 // allocation. |
128 #define DEFINE_STATIC_REF(type, name, arguments) \ | 140 #define DEFINE_STATIC_REF(type, name, arguments) \ |
129 static type* name = PassRefPtr<type>(arguments).leakRef(); | 141 static type* name = PassRefPtr<type>(arguments).leakRef(); |
130 | 142 |
131 /* | 143 /* |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 enum NotNullTag { NotNull }; | 251 enum NotNullTag { NotNull }; |
240 inline void* operator new(size_t, NotNullTag, void* location) { | 252 inline void* operator new(size_t, NotNullTag, void* location) { |
241 DCHECK(location); | 253 DCHECK(location); |
242 return location; | 254 return location; |
243 } | 255 } |
244 | 256 |
245 using WTF::bitwiseCast; | 257 using WTF::bitwiseCast; |
246 using WTF::safeCast; | 258 using WTF::safeCast; |
247 | 259 |
248 #endif // WTF_StdLibExtras_h | 260 #endif // WTF_StdLibExtras_h |
OLD | NEW |