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 18namespace WTF { 19 20template<typename T> class RefCounted { }; 21 22template<typename T> class RawPtr { 23public: 24 operator T*() const { return 0; } 25 T* operator->() { return 0; } 26}; 27 28template<typename T> class RefPtr { 29public: 30 ~RefPtr() { } 31 operator T*() const { return 0; } 32 T* operator->() { return 0; } 33}; 34 35template<typename T> class OwnPtr { 36public: 37 ~OwnPtr() { } 38 operator T*() const { return 0; } 39 T* operator->() { return 0; } 40}; 41 42class DefaultAllocator { 43public: 44 static const bool isGarbageCollected = false; 45}; 46 47template<typename T> 48struct VectorTraits { 49 static const bool needsDestruction = true; 50}; 51 52template<size_t inlineCapacity, bool isGarbageCollected, bool tNeedsDestruction> 53class VectorDestructorBase { 54public: 55 ~VectorDestructorBase() {} 56}; 57 58template<size_t inlineCapacity> 59class VectorDestructorBase<inlineCapacity, true, false> {}; 60 61template<> 62class VectorDestructorBase<0, true, true> {}; 63 64template< 65 typename T, 66 size_t inlineCapacity = 0, 67 typename Allocator = DefaultAllocator> 68class Vector : public VectorDestructorBase<inlineCapacity, 69 Allocator::isGarbageCollected, 70 VectorTraits<T>::needsDestruction> { 71public: 72 size_t size(); 73 T& operator[](size_t); 74}; 75 76template< 77 typename T, 78 size_t inlineCapacity = 0, 79 typename Allocator = DefaultAllocator> 80class Deque {}; 81 82template< 83 typename ValueArg, 84 typename HashArg = void, 85 typename TraitsArg = void, 86 typename Allocator = DefaultAllocator> 87class HashSet {}; 88 89template< 90 typename ValueArg, 91 typename HashArg = void, 92 typename TraitsArg = void, 93 typename Allocator = DefaultAllocator> 94class ListHashSet {}; 95 96template< 97 typename ValueArg, 98 typename HashArg = void, 99 typename TraitsArg = void, 100 typename Allocator = DefaultAllocator> 101class LinkedHashSet {}; 102 103template< 104 typename ValueArg, 105 typename HashArg = void, 106 typename TraitsArg = void, 107 typename Allocator = DefaultAllocator> 108class HashCountedSet {}; 109 110template< 111 typename KeyArg, 112 typename MappedArg, 113 typename HashArg = void, 114 typename KeyTraitsArg = void, 115 typename MappedTraitsArg = void, 116 typename Allocator = DefaultAllocator> 117class HashMap {}; 118 119} 120 121namespace blink { 122 123using 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 {} \ 148 virtual bool isAlive(Visitor*) const { return 0; } 149 150template<typename T> class GarbageCollected { }; 151 152template<typename T> 153class GarbageCollectedFinalized : public GarbageCollected<T> { }; 154 155template<typename T> class Member { 156public: 157 operator T*() const { return 0; } 158 T* operator->() { return 0; } 159 bool operator!() const { return false; } 160}; 161 162template<typename T> class WeakMember { 163public: 164 operator T*() const { return 0; } 165 T* operator->() { return 0; } 166 bool operator!() const { return false; } 167}; 168 169template<typename T> class Persistent { 170public: 171 operator T*() const { return 0; } 172 T* operator->() { return 0; } 173 bool operator!() const { return false; } 174}; 175 176class HeapAllocator { 177public: 178 static const bool isGarbageCollected = true; 179}; 180 181template<typename T, size_t inlineCapacity = 0> 182class HeapVector : public Vector<T, inlineCapacity, HeapAllocator> { }; 183 184template<typename T, size_t inlineCapacity = 0> 185class HeapDeque : public Vector<T, inlineCapacity, HeapAllocator> { }; 186 187template<typename T> 188class HeapHashSet : public HashSet<T, void, void, HeapAllocator> { }; 189 190template<typename T> 191class HeapListHashSet : public ListHashSet<T, void, void, HeapAllocator> { }; 192 193template<typename T> 194class HeapLinkedHashSet : public LinkedHashSet<T, void, void, HeapAllocator> { 195}; 196 197template<typename T> 198class HeapHashCountedSet : public HashCountedSet<T, void, void, HeapAllocator> { 199}; 200 201template<typename K, typename V> 202class HeapHashMap : public HashMap<K, V, void, void, void, HeapAllocator> { }; 203 204template<typename T> 205class PersistentHeapVector : public Vector<T, 0, HeapAllocator> { }; 206 207class Visitor { 208public: 209 template<typename T> 210 void trace(const T&); 211 212 template<typename T, void (T::*method)(Visitor*)> 213 void registerWeakMembers(const T* obj); 214}; 215 216class GarbageCollectedMixin { 217 virtual void adjustAndMark(Visitor*) const = 0; 218 virtual bool isAlive(Visitor*) const = 0; 219 virtual void trace(Visitor*) { } 220}; 221 222template<typename T> 223struct TraceIfNeeded { 224 static void trace(Visitor*, T*); 225}; 226 227// blink::ScriptWrappable receives special treatment 228// so as to allow it to be used together with GarbageCollected<T>, 229// even when its user-declared destructor is provided. 230// As it is with Oilpan disabled. 231class ScriptWrappable { 232public: 233 ~ScriptWrappable() { /* user-declared, thus, non-trivial */ } 234}; 235 236} 237 238namespace WTF { 239 240template<typename T> 241struct VectorTraits<blink::Member<T> > { 242 static const bool needsDestruction = false; 243}; 244 245} 246 247#endif 248