OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef HEAP_STUBS_H_ |
| 6 #define HEAP_STUBS_H_ |
| 7 |
| 8 #include "stddef.h" |
| 9 |
| 10 #define WTF_MAKE_FAST_ALLOCATED \ |
| 11 public: \ |
| 12 void* operator new(size_t, void* p); \ |
| 13 void* operator new[](size_t, void* p); \ |
| 14 void* operator new(size_t size); \ |
| 15 private: \ |
| 16 typedef int __thisIsHereToForceASemicolonAfterThisMacro |
| 17 |
| 18 namespace WTF { |
| 19 |
| 20 template<typename T> class RefCounted { }; |
| 21 |
| 22 template<typename T> class RawPtr { |
| 23 public: |
| 24 operator T*() const { return 0; } |
| 25 T* operator->() { return 0; } |
| 26 }; |
| 27 |
| 28 template<typename T> class RefPtr { |
| 29 public: |
| 30 ~RefPtr() { } |
| 31 operator T*() const { return 0; } |
| 32 T* operator->() { return 0; } |
| 33 }; |
| 34 |
| 35 template<typename T> class OwnPtr { |
| 36 public: |
| 37 ~OwnPtr() { } |
| 38 operator T*() const { return 0; } |
| 39 T* operator->() { return 0; } |
| 40 }; |
| 41 |
| 42 class DefaultAllocator { |
| 43 public: |
| 44 static const bool isGarbageCollected = false; |
| 45 }; |
| 46 |
| 47 template<typename T> |
| 48 struct VectorTraits { |
| 49 static const bool needsDestruction = true; |
| 50 }; |
| 51 |
| 52 template<size_t inlineCapacity, bool isGarbageCollected, bool tNeedsDestruction> |
| 53 class VectorDestructorBase { |
| 54 public: |
| 55 ~VectorDestructorBase() {} |
| 56 }; |
| 57 |
| 58 template<size_t inlineCapacity> |
| 59 class VectorDestructorBase<inlineCapacity, true, false> {}; |
| 60 |
| 61 template<> |
| 62 class VectorDestructorBase<0, true, true> {}; |
| 63 |
| 64 template< |
| 65 typename T, |
| 66 size_t inlineCapacity = 0, |
| 67 typename Allocator = DefaultAllocator> |
| 68 class Vector : public VectorDestructorBase<inlineCapacity, |
| 69 Allocator::isGarbageCollected, |
| 70 VectorTraits<T>::needsDestruction> { |
| 71 public: |
| 72 size_t size(); |
| 73 T& operator[](size_t); |
| 74 }; |
| 75 |
| 76 template< |
| 77 typename T, |
| 78 size_t inlineCapacity = 0, |
| 79 typename Allocator = DefaultAllocator> |
| 80 class Deque {}; |
| 81 |
| 82 template< |
| 83 typename ValueArg, |
| 84 typename HashArg = void, |
| 85 typename TraitsArg = void, |
| 86 typename Allocator = DefaultAllocator> |
| 87 class HashSet {}; |
| 88 |
| 89 template< |
| 90 typename ValueArg, |
| 91 typename HashArg = void, |
| 92 typename TraitsArg = void, |
| 93 typename Allocator = DefaultAllocator> |
| 94 class ListHashSet {}; |
| 95 |
| 96 template< |
| 97 typename ValueArg, |
| 98 typename HashArg = void, |
| 99 typename TraitsArg = void, |
| 100 typename Allocator = DefaultAllocator> |
| 101 class LinkedHashSet {}; |
| 102 |
| 103 template< |
| 104 typename ValueArg, |
| 105 typename HashArg = void, |
| 106 typename TraitsArg = void, |
| 107 typename Allocator = DefaultAllocator> |
| 108 class HashCountedSet {}; |
| 109 |
| 110 template< |
| 111 typename KeyArg, |
| 112 typename MappedArg, |
| 113 typename HashArg = void, |
| 114 typename KeyTraitsArg = void, |
| 115 typename MappedTraitsArg = void, |
| 116 typename Allocator = DefaultAllocator> |
| 117 class HashMap {}; |
| 118 |
| 119 } |
| 120 |
| 121 namespace blink { |
| 122 |
| 123 using namespace WTF; |
| 124 |
| 125 #define DISALLOW_ALLOCATION() \ |
| 126 private: \ |
| 127 void* operator new(size_t) = delete; \ |
| 128 void* operator new(size_t, void*) = delete; |
| 129 |
| 130 #define STACK_ALLOCATED() \ |
| 131 private: \ |
| 132 __attribute__((annotate("blink_stack_allocated"))) \ |
| 133 void* operator new(size_t) = delete; \ |
| 134 void* operator new(size_t, void*) = delete; |
| 135 |
| 136 #define ALLOW_ONLY_INLINE_ALLOCATION() \ |
| 137 public: \ |
| 138 void* operator new(size_t, void*); \ |
| 139 private: \ |
| 140 void* operator new(size_t) = delete; |
| 141 |
| 142 #define GC_PLUGIN_IGNORE(bug) \ |
| 143 __attribute__((annotate("blink_gc_plugin_ignore"))) |
| 144 |
| 145 #define USING_GARBAGE_COLLECTED_MIXIN(type) \ |
| 146 public: \ |
| 147 virtual void adjustAndMark(Visitor*) const override { } \ |
| 148 virtual bool isHeapObjectAlive(Visitor*) const override { return 0; } |
| 149 |
| 150 #define EAGERLY_FINALIZED() typedef int IsEagerlyFinalizedMarker |
| 151 |
| 152 template<typename T> class GarbageCollected { }; |
| 153 |
| 154 template<typename T> |
| 155 class GarbageCollectedFinalized : public GarbageCollected<T> { }; |
| 156 |
| 157 template<typename T> class Member { |
| 158 public: |
| 159 operator T*() const { return 0; } |
| 160 T* operator->() { return 0; } |
| 161 bool operator!() const { return false; } |
| 162 }; |
| 163 |
| 164 template<typename T> class WeakMember { |
| 165 public: |
| 166 operator T*() const { return 0; } |
| 167 T* operator->() { return 0; } |
| 168 bool operator!() const { return false; } |
| 169 }; |
| 170 |
| 171 template<typename T> class Persistent { |
| 172 public: |
| 173 operator T*() const { return 0; } |
| 174 T* operator->() { return 0; } |
| 175 bool operator!() const { return false; } |
| 176 }; |
| 177 |
| 178 class HeapAllocator { |
| 179 public: |
| 180 static const bool isGarbageCollected = true; |
| 181 }; |
| 182 |
| 183 template<typename T, size_t inlineCapacity = 0> |
| 184 class HeapVector : public Vector<T, inlineCapacity, HeapAllocator> { }; |
| 185 |
| 186 template<typename T, size_t inlineCapacity = 0> |
| 187 class HeapDeque : public Vector<T, inlineCapacity, HeapAllocator> { }; |
| 188 |
| 189 template<typename T> |
| 190 class HeapHashSet : public HashSet<T, void, void, HeapAllocator> { }; |
| 191 |
| 192 template<typename T> |
| 193 class HeapListHashSet : public ListHashSet<T, void, void, HeapAllocator> { }; |
| 194 |
| 195 template<typename T> |
| 196 class HeapLinkedHashSet : public LinkedHashSet<T, void, void, HeapAllocator> { |
| 197 }; |
| 198 |
| 199 template<typename T> |
| 200 class HeapHashCountedSet : public HashCountedSet<T, void, void, HeapAllocator> { |
| 201 }; |
| 202 |
| 203 template<typename K, typename V> |
| 204 class HeapHashMap : public HashMap<K, V, void, void, void, HeapAllocator> { }; |
| 205 |
| 206 template<typename T> |
| 207 class PersistentHeapVector : public Vector<T, 0, HeapAllocator> { }; |
| 208 |
| 209 template <typename Derived> |
| 210 class VisitorHelper { |
| 211 public: |
| 212 template<typename T> |
| 213 void trace(const T&); |
| 214 }; |
| 215 |
| 216 class Visitor : public VisitorHelper<Visitor> { |
| 217 public: |
| 218 template<typename T, void (T::*method)(Visitor*)> |
| 219 void registerWeakMembers(const T* obj); |
| 220 }; |
| 221 |
| 222 class InlinedGlobalMarkingVisitor |
| 223 : public VisitorHelper<InlinedGlobalMarkingVisitor> { |
| 224 public: |
| 225 InlinedGlobalMarkingVisitor* operator->() { return this; } |
| 226 |
| 227 template<typename T, void (T::*method)(Visitor*)> |
| 228 void registerWeakMembers(const T* obj); |
| 229 }; |
| 230 |
| 231 class GarbageCollectedMixin { |
| 232 public: |
| 233 virtual void adjustAndMark(Visitor*) const = 0; |
| 234 virtual bool isHeapObjectAlive(Visitor*) const = 0; |
| 235 virtual void trace(Visitor*) { } |
| 236 }; |
| 237 |
| 238 template<typename T> |
| 239 struct TraceIfNeeded { |
| 240 static void trace(Visitor*, T*); |
| 241 }; |
| 242 |
| 243 // blink::ScriptWrappable receives special treatment |
| 244 // so as to allow it to be used together with GarbageCollected<T>, |
| 245 // even when its user-declared destructor is provided. |
| 246 // As it is with Oilpan disabled. |
| 247 class ScriptWrappable { |
| 248 public: |
| 249 ~ScriptWrappable() { /* user-declared, thus, non-trivial */ } |
| 250 }; |
| 251 |
| 252 } |
| 253 |
| 254 namespace WTF { |
| 255 |
| 256 template<typename T> |
| 257 struct VectorTraits<blink::Member<T> > { |
| 258 static const bool needsDestruction = false; |
| 259 }; |
| 260 |
| 261 } |
| 262 |
| 263 #endif |
OLD | NEW |