| 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 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 | 56 |
| 57 private: | 57 private: |
| 58 bool m_safelyInitialized; | 58 bool m_safelyInitialized; |
| 59 ThreadIdentifier m_thread; | 59 ThreadIdentifier m_thread; |
| 60 }; | 60 }; |
| 61 #endif | 61 #endif |
| 62 | 62 |
| 63 namespace blink { | 63 namespace blink { |
| 64 template <typename T> | 64 template <typename T> |
| 65 class Persistent; | 65 class Persistent; |
| 66 |
| 67 class ScriptWrappable; |
| 66 }; | 68 }; |
| 67 | 69 |
| 68 template <typename T, | 70 template <typename T, |
| 69 bool = WTF::IsGarbageCollectedType<T>::value && | 71 bool = WTF::IsGarbageCollectedType<T>::value && |
| 70 !WTF::IsPersistentReferenceType<T>::value> | 72 !WTF::IsPersistentReferenceType<T>::value> |
| 71 class StaticLocalWrapper { | 73 class StaticLocalWrapper { |
| 72 public: | 74 public: |
| 73 using WrapType = T; | 75 using WrapType = T; |
| 74 | 76 |
| 75 static T& unwrap(T* singleton) { return *singleton; } | 77 static T& unwrap(T* singleton) { return *singleton; } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 105 // wrapped up by an off-heap Persistent<T> reference to the object, keeping | 107 // wrapped up by an off-heap Persistent<T> reference to the object, keeping |
| 106 // it alive across GCs. | 108 // it alive across GCs. |
| 107 // | 109 // |
| 108 // To cooperate with leak detection(LSan) for Blink garbage collected objects, | 110 // 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 | 111 // 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 | 112 // 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 | 113 // 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 | 114 // LEAK_SANITIZER_REGISTER_STATIC_LOCAL() use, it taking care of the grungy |
| 113 // details. | 115 // details. |
| 114 // | 116 // |
| 115 #define DEFINE_STATIC_LOCAL(Type, Name, Arguments) \ | 117 #define DEFINE_STATIC_LOCAL(Type, Name, Arguments) \ |
| 116 DEFINE_STATIC_LOCAL_CHECK_THREADSAFE_ACCESS(Name); \ | 118 DEFINE_STATIC_LOCAL_CHECK_THREADSAFE_ACCESS(Name); \ |
| 117 using WrappedTypeFor##Name = StaticLocalWrapper<Type>::WrapType; \ | 119 using WrappedTypeFor##Name = StaticLocalWrapper<Type>::WrapType; \ |
| 118 static WrappedTypeFor##Name* WrappedInstanceFor##Name = \ | 120 static_assert( \ |
| 119 LEAK_SANITIZER_REGISTER_STATIC_LOCAL( \ | 121 !WTF::IsPersistentReferenceType<WrappedTypeFor##Name>::value || \ |
| 120 WrappedTypeFor##Name, new WrappedTypeFor##Name Arguments); \ | 122 !WTF::IsSubclass<WTF::RemoveTemplate<WrappedTypeFor##Name, \ |
| 123 blink::Persistent>::type, \ |
| 124 blink::ScriptWrappable>::value, \ |
| 125 "It is unsafe to keep a static local singleton to a " \ |
| 126 "ScriptWrappable-derived object"); \ |
| 127 static WrappedTypeFor##Name* WrappedInstanceFor##Name = \ |
| 128 LEAK_SANITIZER_REGISTER_STATIC_LOCAL( \ |
| 129 WrappedTypeFor##Name, new WrappedTypeFor##Name Arguments); \ |
| 121 Type& Name = StaticLocalWrapper<Type>::unwrap(WrappedInstanceFor##Name); | 130 Type& Name = StaticLocalWrapper<Type>::unwrap(WrappedInstanceFor##Name); |
| 122 | 131 |
| 123 // Use this to declare and define a static local pointer to a ref-counted object | 132 // 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 | 133 // 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 | 134 // 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 | 135 // DEFINE_STATIC_LOCAL macro, as this macro does not lead to an extra memory |
| 127 // allocation. | 136 // allocation. |
| 128 #define DEFINE_STATIC_REF(type, name, arguments) \ | 137 #define DEFINE_STATIC_REF(type, name, arguments) \ |
| 129 static type* name = PassRefPtr<type>(arguments).leakRef(); | 138 static type* name = PassRefPtr<type>(arguments).leakRef(); |
| 130 | 139 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 enum NotNullTag { NotNull }; | 248 enum NotNullTag { NotNull }; |
| 240 inline void* operator new(size_t, NotNullTag, void* location) { | 249 inline void* operator new(size_t, NotNullTag, void* location) { |
| 241 DCHECK(location); | 250 DCHECK(location); |
| 242 return location; | 251 return location; |
| 243 } | 252 } |
| 244 | 253 |
| 245 using WTF::bitwiseCast; | 254 using WTF::bitwiseCast; |
| 246 using WTF::safeCast; | 255 using WTF::safeCast; |
| 247 | 256 |
| 248 #endif // WTF_StdLibExtras_h | 257 #endif // WTF_StdLibExtras_h |
| OLD | NEW |