| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef Handle_h | 31 #ifndef Handle_h |
| 32 #define Handle_h | 32 #define Handle_h |
| 33 | 33 |
| 34 #include "platform/heap/Heap.h" | |
| 35 #include "platform/heap/ThreadState.h" | 34 #include "platform/heap/ThreadState.h" |
| 36 #include "platform/heap/Visitor.h" | 35 #include "platform/heap/Visitor.h" |
| 37 #include "wtf/Functional.h" | 36 #include "wtf/Functional.h" |
| 38 #include "wtf/HashFunctions.h" | 37 #include "wtf/HashFunctions.h" |
| 39 #include "wtf/Locker.h" | 38 #include "wtf/Locker.h" |
| 40 #include "wtf/RawPtr.h" | 39 #include "wtf/RawPtr.h" |
| 41 #include "wtf/RefCounted.h" | 40 #include "wtf/RefCounted.h" |
| 42 #include "wtf/TypeTraits.h" | 41 #include "wtf/TypeTraits.h" |
| 43 | 42 |
| 43 // Classes that contain heap references but aren't themselves heap |
| 44 // allocated, have some extra macros available which allows their use |
| 45 // to be restricted to cases where the garbage collector is able |
| 46 // to discover their heap references. |
| 47 // |
| 48 // STACK_ALLOCATED(): Use if the object is only stack allocated. Heap objects |
| 49 // should be in Members but you do not need the trace method as they are on |
| 50 // the stack. (Down the line these might turn in to raw pointers, but for |
| 51 // now Members indicates that we have thought about them and explicitly |
| 52 // taken care of them.) |
| 53 // |
| 54 // DISALLOW_ALLOCATION(): Cannot be allocated with new operators but can |
| 55 // be a part object. If it has Members you need a trace method and the |
| 56 // containing object needs to call that trace method. |
| 57 // |
| 58 // ALLOW_ONLY_INLINE_ALLOCATION(): Allows only placement new operator. |
| 59 // This disallows general allocation of this object but allows to put |
| 60 // the object as a value object in collections. If these have Members you |
| 61 // need to have a trace method. That trace method will be called |
| 62 // automatically by the Heap collections. |
| 63 // |
| 64 #define DISALLOW_ALLOCATION() \ |
| 65 private: \ |
| 66 void* operator new(size_t) = delete; \ |
| 67 void* operator new(size_t, NotNullTag, void*) = delete; \ |
| 68 void* operator new(size_t, void*) = delete; |
| 69 |
| 70 #define ALLOW_ONLY_INLINE_ALLOCATION()
\ |
| 71 public:
\ |
| 72 void* operator new(size_t, NotNullTag, void* location) { return location
; } \ |
| 73 void* operator new(size_t, void* location) { return location; }
\ |
| 74 private:
\ |
| 75 void* operator new(size_t) = delete; |
| 76 |
| 77 #define STATIC_ONLY(Type) \ |
| 78 private: \ |
| 79 Type() = delete; |
| 80 |
| 81 // These macros insert annotations that the Blink GC plugin for clang uses for |
| 82 // verification. STACK_ALLOCATED is used to declare that objects of this type |
| 83 // are always stack allocated. GC_PLUGIN_IGNORE is used to make the plugin |
| 84 // ignore a particular class or field when checking for proper usage. When using |
| 85 // GC_PLUGIN_IGNORE a bug-number should be provided as an argument where the |
| 86 // bug describes what needs to happen to remove the GC_PLUGIN_IGNORE again. |
| 87 #if COMPILER(CLANG) |
| 88 #define STACK_ALLOCATED() \ |
| 89 private: \ |
| 90 __attribute__((annotate("blink_stack_allocated"))) \ |
| 91 void* operator new(size_t) = delete; \ |
| 92 void* operator new(size_t, NotNullTag, void*) = delete; \ |
| 93 void* operator new(size_t, void*) = delete; |
| 94 |
| 95 #else |
| 96 #define STACK_ALLOCATED() DISALLOW_ALLOCATION() |
| 97 #endif |
| 98 |
| 44 namespace blink { | 99 namespace blink { |
| 45 | 100 |
| 46 template<typename T> class HeapTerminatedArray; | 101 template<typename T> class HeapTerminatedArray; |
| 47 | 102 |
| 48 template<typename T> class Member; | 103 template<typename T> class Member; |
| 49 | 104 |
| 50 class PersistentNode { | 105 class PersistentNode { |
| 51 public: | 106 public: |
| 52 explicit PersistentNode(TraceCallback trace) | 107 explicit PersistentNode(TraceCallback trace) |
| 53 : m_trace(trace) | 108 : m_trace(trace) |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 // Persistent handles must not be used to contain pointers | 258 // Persistent handles must not be used to contain pointers |
| 204 // between objects that are in the managed heap. They are only | 259 // between objects that are in the managed heap. They are only |
| 205 // meant to point to managed heap objects from variables/members | 260 // meant to point to managed heap objects from variables/members |
| 206 // outside the managed heap. | 261 // outside the managed heap. |
| 207 // | 262 // |
| 208 // A Persistent is always a GC root from the point of view of | 263 // A Persistent is always a GC root from the point of view of |
| 209 // the garbage collector. | 264 // the garbage collector. |
| 210 // | 265 // |
| 211 // We have to construct and destruct Persistent with default RootsAccessor in | 266 // We have to construct and destruct Persistent with default RootsAccessor in |
| 212 // the same thread. | 267 // the same thread. |
| 213 template<typename T, typename RootsAccessor /* = ThreadLocalPersistents<Threadin
gTrait<T>::Affinity > */ > | 268 template<typename T, typename RootsAccessor = ThreadLocalPersistents<ThreadingTr
ait<T>::Affinity > > |
| 214 class Persistent : public PersistentBase<RootsAccessor, Persistent<T, RootsAcces
sor> > { | 269 class Persistent : public PersistentBase<RootsAccessor, Persistent<T, RootsAcces
sor> > { |
| 215 WTF_DISALLOW_CONSTRUCTION_FROM_ZERO(Persistent); | 270 WTF_DISALLOW_CONSTRUCTION_FROM_ZERO(Persistent); |
| 216 WTF_DISALLOW_ZERO_ASSIGNMENT(Persistent); | 271 WTF_DISALLOW_ZERO_ASSIGNMENT(Persistent); |
| 217 public: | 272 public: |
| 218 Persistent() : m_raw(0) { } | 273 Persistent() : m_raw(0) { } |
| 219 | 274 |
| 220 Persistent(std::nullptr_t) : m_raw(0) { } | 275 Persistent(std::nullptr_t) : m_raw(0) { } |
| 221 | 276 |
| 222 Persistent(T* raw) : m_raw(raw) | 277 Persistent(T* raw) : m_raw(raw) |
| 223 { | 278 { |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 struct ParamStorageTraits<T*> : public PointerParamStorageTraits<T*, false> { | 787 struct ParamStorageTraits<T*> : public PointerParamStorageTraits<T*, false> { |
| 733 }; | 788 }; |
| 734 | 789 |
| 735 template<typename T> | 790 template<typename T> |
| 736 struct ParamStorageTraits<RawPtr<T> > : public PointerParamStorageTraits<T*, fal
se> { | 791 struct ParamStorageTraits<RawPtr<T> > : public PointerParamStorageTraits<T*, fal
se> { |
| 737 }; | 792 }; |
| 738 | 793 |
| 739 } // namespace WTF | 794 } // namespace WTF |
| 740 | 795 |
| 741 #endif | 796 #endif |
| OLD | NEW |