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.
10 #define WTF_MAKE_FAST_ALLOCATED \
12 void* operator new(size_t, void* p); \
13 void* operator new[](size_t, void* p); \
14 void* operator new(size_t size); \
16 typedef int __thisIsHereToForceASemicolonAfterThisMacro
20 template<typename T
> class RefCounted
{ };
22 template<typename T
> class RawPtr
{
24 operator T
*() const { return 0; }
25 T
* operator->() { return 0; }
28 template<typename T
> class RefPtr
{
31 operator T
*() const { return 0; }
32 T
* operator->() { return 0; }
35 template<typename T
> class OwnPtr
{
38 operator T
*() const { return 0; }
39 T
* operator->() { return 0; }
42 class DefaultAllocator
{
44 static const bool isGarbageCollected
= false;
49 static const bool needsDestruction
= true;
52 template<size_t inlineCapacity
, bool isGarbageCollected
, bool tNeedsDestruction
>
53 class VectorDestructorBase
{
55 ~VectorDestructorBase() {}
58 template<size_t inlineCapacity
>
59 class VectorDestructorBase
<inlineCapacity
, true, false> {};
62 class VectorDestructorBase
<0, true, true> {};
66 size_t inlineCapacity
= 0,
67 typename Allocator
= DefaultAllocator
>
68 class Vector
: public VectorDestructorBase
<inlineCapacity
,
69 Allocator::isGarbageCollected
,
70 VectorTraits
<T
>::needsDestruction
> {
73 T
& operator[](size_t);
78 size_t inlineCapacity
= 0,
79 typename Allocator
= DefaultAllocator
>
84 typename HashArg
= void,
85 typename TraitsArg
= void,
86 typename Allocator
= DefaultAllocator
>
91 typename HashArg
= void,
92 typename TraitsArg
= void,
93 typename Allocator
= DefaultAllocator
>
98 typename HashArg
= void,
99 typename TraitsArg
= void,
100 typename Allocator
= DefaultAllocator
>
101 class LinkedHashSet
{};
105 typename HashArg
= void,
106 typename TraitsArg
= void,
107 typename Allocator
= DefaultAllocator
>
108 class HashCountedSet
{};
113 typename HashArg
= void,
114 typename KeyTraitsArg
= void,
115 typename MappedTraitsArg
= void,
116 typename Allocator
= DefaultAllocator
>
125 #define DISALLOW_ALLOCATION() \
127 void* operator new(size_t) = delete; \
128 void* operator new(size_t, void*) = delete;
130 #define STACK_ALLOCATED() \
132 __attribute__((annotate("blink_stack_allocated"))) \
133 void* operator new(size_t) = delete; \
134 void* operator new(size_t, void*) = delete;
136 #define ALLOW_ONLY_INLINE_ALLOCATION() \
138 void* operator new(size_t, void*); \
140 void* operator new(size_t) = delete;
142 #define GC_PLUGIN_IGNORE(bug) \
143 __attribute__((annotate("blink_gc_plugin_ignore")))
145 #define USING_GARBAGE_COLLECTED_MIXIN(type) \
147 virtual void adjustAndMark(Visitor*) const override { } \
148 virtual bool isHeapObjectAlive(Visitor*) const override { return 0; }
150 template<typename T
> class GarbageCollected
{ };
153 class GarbageCollectedFinalized
: public GarbageCollected
<T
> { };
155 template<typename T
> class Member
{
157 operator T
*() const { return 0; }
158 T
* operator->() { return 0; }
159 bool operator!() const { return false; }
162 template<typename T
> class WeakMember
{
164 operator T
*() const { return 0; }
165 T
* operator->() { return 0; }
166 bool operator!() const { return false; }
169 template<typename T
> class Persistent
{
171 operator T
*() const { return 0; }
172 T
* operator->() { return 0; }
173 bool operator!() const { return false; }
176 class HeapAllocator
{
178 static const bool isGarbageCollected
= true;
181 template<typename T
, size_t inlineCapacity
= 0>
182 class HeapVector
: public Vector
<T
, inlineCapacity
, HeapAllocator
> { };
184 template<typename T
, size_t inlineCapacity
= 0>
185 class HeapDeque
: public Vector
<T
, inlineCapacity
, HeapAllocator
> { };
188 class HeapHashSet
: public HashSet
<T
, void, void, HeapAllocator
> { };
191 class HeapListHashSet
: public ListHashSet
<T
, void, void, HeapAllocator
> { };
194 class HeapLinkedHashSet
: public LinkedHashSet
<T
, void, void, HeapAllocator
> {
198 class HeapHashCountedSet
: public HashCountedSet
<T
, void, void, HeapAllocator
> {
201 template<typename K
, typename V
>
202 class HeapHashMap
: public HashMap
<K
, V
, void, void, void, HeapAllocator
> { };
205 class PersistentHeapVector
: public Vector
<T
, 0, HeapAllocator
> { };
207 template <typename Derived
>
208 class VisitorHelper
{
211 void trace(const T
&);
214 class Visitor
: public VisitorHelper
<Visitor
> {
216 template<typename T
, void (T::*method
)(Visitor
*)>
217 void registerWeakMembers(const T
* obj
);
220 class InlinedGlobalMarkingVisitor
221 : public VisitorHelper
<InlinedGlobalMarkingVisitor
> {
223 InlinedGlobalMarkingVisitor
* operator->() { return this; }
225 template<typename T
, void (T::*method
)(Visitor
*)>
226 void registerWeakMembers(const T
* obj
);
229 class GarbageCollectedMixin
{
231 virtual void adjustAndMark(Visitor
*) const = 0;
232 virtual bool isHeapObjectAlive(Visitor
*) const = 0;
233 virtual void trace(Visitor
*) { }
237 struct TraceIfNeeded
{
238 static void trace(Visitor
*, T
*);
241 // blink::ScriptWrappable receives special treatment
242 // so as to allow it to be used together with GarbageCollected<T>,
243 // even when its user-declared destructor is provided.
244 // As it is with Oilpan disabled.
245 class ScriptWrappable
{
247 ~ScriptWrappable() { /* user-declared, thus, non-trivial */ }
255 struct VectorTraits
<blink::Member
<T
> > {
256 static const bool needsDestruction
= false;