Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / heap / Visitor.h
1 /*
2  * Copyright (C) 2013 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
29  */
30
31 #ifndef Visitor_h
32 #define Visitor_h
33
34 #include "heap/HeapExport.h"
35 #include "heap/ThreadState.h"
36 #include "wtf/Assertions.h"
37 #include "wtf/Deque.h"
38 #include "wtf/Forward.h"
39 #include "wtf/HashMap.h"
40 #include "wtf/HashSet.h"
41 #include "wtf/HashTraits.h"
42 #include "wtf/ListHashSet.h"
43 #include "wtf/OwnPtr.h"
44 #include "wtf/RefPtr.h"
45 #include "wtf/TypeTraits.h"
46
47 #ifndef NDEBUG
48 #define DEBUG_ONLY(x) x
49 #else
50 #define DEBUG_ONLY(x)
51 #endif
52
53 namespace WebCore {
54
55 class FinalizedHeapObjectHeader;
56 template<typename T> class GarbageCollectedFinalized;
57 class HeapObjectHeader;
58 template<typename T> class Member;
59 template<typename T> class WeakMember;
60 class Visitor;
61
62 template<bool needsTracing, bool isWeak, bool markWeakMembersStrongly, typename T, typename Traits> struct CollectionBackingTraceTrait;
63
64 // The TraceMethodDelegate is used to convert a trace method for type T to a TraceCallback.
65 // This allows us to pass a type's trace method as a parameter to the PersistentNode
66 // constructor. The PersistentNode constructor needs the specific trace method due an issue
67 // with the Windows compiler which instantiates even unused variables. This causes problems
68 // in header files where we have only forward declarations of classes.
69 template<typename T, void (T::*method)(Visitor*)>
70 struct TraceMethodDelegate {
71     static void trampoline(Visitor* visitor, void* self) { (reinterpret_cast<T*>(self)->*method)(visitor); }
72 };
73
74 // GCInfo contains meta-data associated with objects allocated in the
75 // Blink heap. This meta-data consists of a function pointer used to
76 // trace the pointers in the object during garbage collection, an
77 // indication of whether or not the object needs a finalization
78 // callback, and a function pointer used to finalize the object when
79 // the garbage collector determines that the object is no longer
80 // reachable. There is a GCInfo struct for each class that directly
81 // inherits from GarbageCollected or GarbageCollectedFinalized.
82 struct GCInfo {
83     bool hasFinalizer() const { return m_nonTrivialFinalizer; }
84     TraceCallback m_trace;
85     FinalizationCallback m_finalize;
86     bool m_nonTrivialFinalizer;
87 };
88
89 // The FinalizerTraitImpl specifies how to finalize objects. Object
90 // that inherit from GarbageCollectedFinalized are finalized by
91 // calling their 'finalize' method which by default will call the
92 // destructor on the object.
93 template<typename T, bool isGarbageCollectedFinalized>
94 struct FinalizerTraitImpl;
95
96 template<typename T>
97 struct FinalizerTraitImpl<T, true> {
98     static void finalize(void* obj) { static_cast<T*>(obj)->finalizeGarbageCollectedObject(); };
99 };
100
101 template<typename T>
102 struct FinalizerTraitImpl<T, false> {
103     static void finalize(void* obj) { };
104 };
105
106 // The FinalizerTrait is used to determine if a type requires
107 // finalization and what finalization means.
108 //
109 // By default classes that inherit from GarbageCollectedFinalized need
110 // finalization and finalization means calling the 'finalize' method
111 // of the object. The FinalizerTrait can be specialized if the default
112 // behavior is not desired.
113 template<typename T>
114 struct FinalizerTrait {
115     static const bool nonTrivialFinalizer = WTF::IsSubclassOfTemplate<T, GarbageCollectedFinalized>::value;
116     static void finalize(void* obj) { FinalizerTraitImpl<T, nonTrivialFinalizer>::finalize(obj); }
117 };
118
119 // Trait to get the GCInfo structure for types that have their
120 // instances allocated in the Blink garbage-collected heap.
121 template<typename T> struct GCInfoTrait;
122
123 template<typename T> class GarbageCollected;
124 class GarbageCollectedMixin;
125 template<typename T, bool = WTF::IsSubclassOfTemplate<T, GarbageCollected>::value> class NeedsAdjustAndMark;
126
127 template<typename T>
128 class NeedsAdjustAndMark<T, true> {
129 public:
130     static const bool value = false;
131 };
132
133 template<typename T>
134 class NeedsAdjustAndMark<T, false> {
135 public:
136     static const bool value = WTF::IsSubclass<T, GarbageCollectedMixin>::value;
137 };
138
139 template<typename T, bool = NeedsAdjustAndMark<T>::value> class DefaultTraceTrait;
140
141 // The TraceTrait is used to specify how to mark an object pointer and
142 // how to trace all of the pointers in the object.
143 //
144 // By default, the 'trace' method implemented on an object itself is
145 // used to trace the pointers to other heap objects inside the object.
146 //
147 // However, the TraceTrait can be specialized to use a different
148 // implementation. A common case where a TraceTrait specialization is
149 // needed is when multiple inheritance leads to pointers that are not
150 // to the start of the object in the Blink garbage-collected heap. In
151 // that case the pointer has to be adjusted before marking.
152 template<typename T>
153 class TraceTrait {
154 public:
155     // Default implementation of TraceTrait<T>::trace just statically
156     // dispatches to the trace method of the class T.
157     static void trace(Visitor* visitor, void* self)
158     {
159         static_cast<T*>(self)->trace(visitor);
160     }
161
162     static void mark(Visitor* visitor, const T* t)
163     {
164         DefaultTraceTrait<T>::mark(visitor, t);
165     }
166
167 #ifndef NDEBUG
168     static void checkGCInfo(Visitor* visitor, const T* t)
169     {
170         DefaultTraceTrait<T>::checkGCInfo(visitor, t);
171     }
172 #endif
173 };
174
175 template<typename T> class TraceTrait<const T> : public TraceTrait<T> { };
176
177 template<typename Collection>
178 struct OffHeapCollectionTraceTrait;
179
180 template<typename T>
181 struct ObjectAliveTrait {
182     static bool isAlive(Visitor*, T);
183 };
184
185 template<typename T>
186 struct ObjectAliveTrait<Member<T> > {
187     static bool isAlive(Visitor*, const Member<T>&);
188 };
189
190 // Visitor is used to traverse the Blink object graph. Used for the
191 // marking phase of the mark-sweep garbage collector.
192 //
193 // Pointers are marked and pushed on the marking stack by calling the
194 // |mark| method with the pointer as an argument.
195 //
196 // Pointers within objects are traced by calling the |trace| methods
197 // with the object as an argument. Tracing objects will mark all of the
198 // contained pointers and push them on the marking stack.
199 class HEAP_EXPORT Visitor {
200 public:
201     virtual ~Visitor() { }
202
203     // One-argument templated mark method. This uses the static type of
204     // the argument to get the TraceTrait. By default, the mark method
205     // of the TraceTrait just calls the virtual two-argument mark method on this
206     // visitor, where the second argument is the static trace method of the trait.
207     template<typename T>
208     void mark(T* t)
209     {
210         if (!t)
211             return;
212 #ifndef NDEBUG
213         TraceTrait<T>::checkGCInfo(this, t);
214 #endif
215         TraceTrait<T>::mark(this, t);
216     }
217
218     // Member version of the one-argument templated trace method.
219     template<typename T>
220     void trace(const Member<T>& t)
221     {
222         mark(t.get());
223     }
224
225     // Fallback method used only when we need to trace raw pointers of T.
226     // This is the case when a member is a union where we do not support members.
227     template<typename T>
228     void trace(T* t)
229     {
230         mark(t);
231     }
232
233     // WeakMember version of the templated trace method. It doesn't keep
234     // the traced thing alive, but will write null to the WeakMember later
235     // if the pointed-to object is dead.
236     template<typename T>
237     void trace(const WeakMember<T>& t)
238     {
239         registerWeakCell(t.cell());
240     }
241
242     // Fallback trace method for part objects to allow individual
243     // trace methods to trace through a part object with
244     // visitor->trace(m_partObject).
245     template<typename T>
246     void trace(const T& t)
247     {
248         const_cast<T&>(t).trace(this);
249     }
250
251     // The following mark methods are for off-heap collections.
252     template<typename T, size_t inlineCapacity>
253     void trace(const Vector<T, inlineCapacity, WTF::DefaultAllocator>& vector)
254     {
255         OffHeapCollectionTraceTrait<Vector<T, inlineCapacity, WTF::DefaultAllocator> >::trace(this, vector);
256     }
257
258     template<typename T, typename U, typename V>
259     void trace(const HashSet<T, U, V, WTF::DefaultAllocator>& hashSet)
260     {
261         OffHeapCollectionTraceTrait<HashSet<T, U, V, WTF::DefaultAllocator> >::trace(this, hashSet);
262     }
263
264     template<typename T, size_t inlineCapacity, typename U>
265     void trace(const ListHashSet<T, inlineCapacity, U>& hashSet)
266     {
267         OffHeapCollectionTraceTrait<ListHashSet<T, inlineCapacity, U> >::trace(this, hashSet);
268     }
269
270     template<typename T, size_t N>
271     void trace(const Deque<T, N>& deque)
272     {
273         OffHeapCollectionTraceTrait<Deque<T, N> >::trace(this, deque);
274     }
275
276     template<typename T, typename U, typename V, typename W, typename X>
277     void trace(const HashMap<T, U, V, W, X, WTF::DefaultAllocator>& map)
278     {
279         OffHeapCollectionTraceTrait<HashMap<T, U, V, W, X, WTF::DefaultAllocator> >::trace(this, map);
280     }
281
282     // OwnPtrs that are traced are treated as part objects and the
283     // trace method of the owned object is called.
284     template<typename T>
285     void trace(const OwnPtr<T>& t)
286     {
287         if (t)
288             t->trace(this);
289     }
290
291     // This trace method is to trace a RefPtrWillBeMember when ENABLE(OILPAN)
292     // is not enabled.
293     // Remove this once we remove RefPtrWillBeMember.
294     template<typename T>
295     void trace(const RefPtr<T>&)
296     {
297 #if ENABLE(OILPAN)
298         // RefPtrs should never be traced.
299         ASSERT_NOT_REACHED();
300 #endif
301     }
302
303 #if !ENABLE(OILPAN)
304     // Similarly, this trace method is to trace a RawPtrWillBeMember
305     // when ENABLE(OILPAN) is not enabled.
306     // Remove this once we remove RawPtrWillBeMember.
307     template<typename T>
308     void trace(const RawPtr<T>&)
309     {
310     }
311 #endif
312
313     // This method marks an object and adds it to the set of objects
314     // that should have their trace method called. Since not all
315     // objects have vtables we have to have the callback as an
316     // explicit argument, but we can use the templated one-argument
317     // mark method above to automatically provide the callback
318     // function.
319     virtual void mark(const void*, TraceCallback) = 0;
320
321     // Used to mark objects during conservative scanning.
322     virtual void mark(HeapObjectHeader*, TraceCallback) = 0;
323     virtual void mark(FinalizedHeapObjectHeader*, TraceCallback) = 0;
324
325     // If the object calls this during the regular trace callback, then the
326     // WeakPointerCallback argument may be called later, when the strong roots
327     // have all been found. The WeakPointerCallback will normally use isAlive
328     // to find out whether some pointers are pointing to dying objects. When
329     // the WeakPointerCallback is done the object must have purged all pointers
330     // to objects where isAlive returned false. In the weak callback it is not
331     // allowed to touch other objects (except using isAlive) or to allocate on
332     // the GC heap. Note that even removing things from HeapHashSet or
333     // HeapHashMap can cause an allocation if the backing store resizes, but
334     // these collections know to remove WeakMember elements safely.
335     //
336     // The weak pointer callbacks are run on the thread that owns the
337     // object and other threads are not stopped during the
338     // callbacks. Since isAlive is used in the callback to determine
339     // if objects pointed to are alive it is crucial that the object
340     // pointed to belong to the same thread as the object receiving
341     // the weak callback. Since other threads have been resumed the
342     // mark bits are not valid for objects from other threads.
343     virtual void registerWeakMembers(const void* object, WeakPointerCallback callback) { registerWeakMembers(object, object, callback); }
344     virtual void registerWeakMembers(const void*, const void*, WeakPointerCallback) = 0;
345
346     template<typename T, void (T::*method)(Visitor*)>
347     void registerWeakMembers(const T* obj)
348     {
349         registerWeakMembers(obj, &TraceMethodDelegate<T, method>::trampoline);
350     }
351
352     // For simple cases where you just want to zero out a cell when the thing
353     // it is pointing at is garbage, you can use this. This will register a
354     // callback for each cell that needs to be zeroed, so if you have a lot of
355     // weak cells in your object you should still consider using
356     // registerWeakMembers above.
357     //
358     // In contrast to registerWeakMembers, the weak cell callbacks are
359     // run on the thread performing garbage collection. Therefore, all
360     // threads are stopped during weak cell callbacks.
361     template<typename T>
362     void registerWeakCell(T** cell)
363     {
364         registerWeakCell(reinterpret_cast<void**>(cell), &handleWeakCell<T>);
365     }
366
367     virtual bool isMarked(const void*) = 0;
368
369     template<typename T> inline bool isAlive(T obj) { return ObjectAliveTrait<T>::isAlive(this, obj); }
370     template<typename T> inline bool isAlive(const Member<T>& member)
371     {
372         return isAlive(member.get());
373     }
374
375 #ifndef NDEBUG
376     void checkGCInfo(const void*, const GCInfo*);
377 #endif
378
379     // Macro to declare methods needed for each typed heap.
380 #define DECLARE_VISITOR_METHODS(Type)                                  \
381     DEBUG_ONLY(void checkGCInfo(const Type*, const GCInfo*);)          \
382     virtual void mark(const Type*, TraceCallback) = 0;                 \
383     virtual bool isMarked(const Type*) = 0;
384
385     FOR_EACH_TYPED_HEAP(DECLARE_VISITOR_METHODS)
386 #undef DECLARE_VISITOR_METHODS
387
388 protected:
389     virtual void registerWeakCell(void**, WeakPointerCallback) = 0;
390
391 private:
392     template<typename T>
393     static void handleWeakCell(Visitor* self, void* obj)
394     {
395         T** cell = reinterpret_cast<T**>(obj);
396         if (*cell && !self->isAlive(*cell))
397             *cell = 0;
398     }
399 };
400
401 template<typename T, typename HashFunctions, typename Traits>
402 struct OffHeapCollectionTraceTrait<WTF::HashSet<T, HashFunctions, Traits, WTF::DefaultAllocator> > {
403     typedef WTF::HashSet<T, HashFunctions, Traits, WTF::DefaultAllocator> HashSet;
404
405     static void trace(Visitor* visitor, const HashSet& set)
406     {
407         if (set.isEmpty())
408             return;
409         if (WTF::ShouldBeTraced<Traits>::value) {
410             HashSet& iterSet = const_cast<HashSet&>(set);
411             for (typename HashSet::iterator it = iterSet.begin(), end = iterSet.end(); it != end; ++it)
412                 CollectionBackingTraceTrait<WTF::ShouldBeTraced<Traits>::value, Traits::isWeak, false, T, Traits>::mark(visitor, *it);
413         }
414         COMPILE_ASSERT(!Traits::isWeak, WeakOffHeapCollectionsConsideredDangerous0);
415     }
416 };
417
418 template<typename T, size_t inlineCapacity, typename HashFunctions>
419 struct OffHeapCollectionTraceTrait<WTF::ListHashSet<T, inlineCapacity, HashFunctions> > {
420     typedef WTF::ListHashSet<T, inlineCapacity, HashFunctions> ListHashSet;
421
422     static void trace(Visitor* visitor, const ListHashSet& set)
423     {
424         if (set.isEmpty())
425             return;
426         ListHashSet& iterSet = const_cast<ListHashSet&>(set);
427         for (typename ListHashSet::iterator it = iterSet.begin(), end = iterSet.end(); it != end; ++it)
428             visitor->trace(*it);
429     }
430 };
431
432 template<typename Key, typename Value, typename HashFunctions, typename KeyTraits, typename ValueTraits>
433 struct OffHeapCollectionTraceTrait<WTF::HashMap<Key, Value, HashFunctions, KeyTraits, ValueTraits, WTF::DefaultAllocator> > {
434     typedef WTF::HashMap<Key, Value, HashFunctions, KeyTraits, ValueTraits, WTF::DefaultAllocator> HashMap;
435
436     static void trace(Visitor* visitor, const HashMap& map)
437     {
438         if (map.isEmpty())
439             return;
440         if (WTF::ShouldBeTraced<KeyTraits>::value || WTF::ShouldBeTraced<ValueTraits>::value) {
441             HashMap& iterMap = const_cast<HashMap&>(map);
442             for (typename HashMap::iterator it = iterMap.begin(), end = iterMap.end(); it != end; ++it) {
443                 CollectionBackingTraceTrait<WTF::ShouldBeTraced<KeyTraits>::value, KeyTraits::isWeak, false, Key, KeyTraits>::mark(visitor, it->key);
444                 CollectionBackingTraceTrait<WTF::ShouldBeTraced<ValueTraits>::value, ValueTraits::isWeak, false, Value, ValueTraits>::mark(visitor, it->value);
445             }
446         }
447         COMPILE_ASSERT(!KeyTraits::isWeak, WeakOffHeapCollectionsConsideredDangerous1);
448         COMPILE_ASSERT(!ValueTraits::isWeak, WeakOffHeapCollectionsConsideredDangerous2);
449     }
450 };
451
452 // We trace vectors by using the trace trait on each element, which means you
453 // can have vectors of general objects (not just pointers to objects) that can
454 // be traced.
455 template<typename T, size_t N>
456 struct OffHeapCollectionTraceTrait<WTF::Vector<T, N, WTF::DefaultAllocator> > {
457     typedef WTF::Vector<T, N, WTF::DefaultAllocator> Vector;
458
459     static void trace(Visitor* visitor, const Vector& vector)
460     {
461         if (vector.isEmpty())
462             return;
463         for (typename Vector::const_iterator it = vector.begin(), end = vector.end(); it != end; ++it)
464             TraceTrait<T>::trace(visitor, const_cast<T*>(it));
465     }
466 };
467
468 template<typename T, size_t N>
469 struct OffHeapCollectionTraceTrait<WTF::Deque<T, N> > {
470     typedef WTF::Deque<T, N> Deque;
471
472     static void trace(Visitor* visitor, const Deque& deque)
473     {
474         if (deque.isEmpty())
475             return;
476         for (typename Deque::const_iterator it = deque.begin(), end = deque.end(); it != end; ++it)
477             TraceTrait<T>::trace(visitor, const_cast<T*>(&(*it)));
478     }
479 };
480
481 template<typename T, typename Traits = WTF::VectorTraits<T> >
482 class HeapVectorBacking;
483 template<typename Key, typename Value, typename Extractor, typename Traits, typename KeyTraits>
484 class HeapHashTableBacking;
485
486 template<typename T>
487 class DefaultTraceTrait<T, false> {
488 public:
489     static void mark(Visitor* visitor, const T* t)
490     {
491         // Default mark method of the trait just calls the two-argument mark
492         // method on the visitor. The second argument is the static trace method
493         // of the trait, which by default calls the instance method
494         // trace(Visitor*) on the object.
495         visitor->mark(const_cast<T*>(t), &TraceTrait<T>::trace);
496     }
497
498 #ifndef NDEBUG
499     static void checkGCInfo(Visitor* visitor, const T* t)
500     {
501         visitor->checkGCInfo(const_cast<T*>(t), GCInfoTrait<T>::get());
502     }
503 #endif
504 };
505
506 template<typename T>
507 class DefaultTraceTrait<T, true> {
508 public:
509     static void mark(Visitor* visitor, const T* self)
510     {
511         self->adjustAndMark(visitor);
512     }
513
514 #ifndef NDEBUG
515     static void checkGCInfo(Visitor*, const T*) { }
516 #endif
517 };
518
519 template<typename T, bool = NeedsAdjustAndMark<T>::value> class DefaultObjectAliveTrait;
520
521 template<typename T>
522 class DefaultObjectAliveTrait<T, false> {
523 public:
524     static bool isAlive(Visitor* visitor, T obj)
525     {
526         return visitor->isMarked(obj);
527     }
528 };
529
530 template<typename T>
531 class DefaultObjectAliveTrait<T, true> {
532 public:
533     static bool isAlive(Visitor* visitor, T obj)
534     {
535         return obj->isAlive(visitor);
536     }
537 };
538
539 template<typename T> bool ObjectAliveTrait<T>::isAlive(Visitor* visitor, T obj)
540 {
541     return DefaultObjectAliveTrait<T>::isAlive(visitor, obj);
542 }
543 template<typename T> bool ObjectAliveTrait<Member<T> >::isAlive(Visitor* visitor, const Member<T>& obj)
544 {
545     return visitor->isMarked(obj.get());
546 }
547
548 // The GarbageCollectedMixin interface and helper macro
549 // USING_GARBAGE_COLLECTED_MIXIN can be used to automatically define
550 // TraceTrait/ObjectAliveTrait on non-leftmost deriving classes
551 // which need to be garbage collected.
552 //
553 // Consider the following case:
554 // class B {};
555 // class A : public GarbageCollected, public B {};
556 //
557 // We can't correctly handle "Member<B> p = &a" as we can't compute addr of
558 // object header statically. This can be solved by using GarbageCollectedMixin:
559 // class B : public GarbageCollectedMixin {};
560 // class A : public GarbageCollected, public B {
561 //   USING_GARBAGE_COLLECTED_MIXIN(A)
562 // };
563 //
564 // With the helper, as long as we are using Member<B>, TypeTrait<B> will
565 // dispatch adjustAndMark dynamically to find collect addr of the object header.
566 // Note that this is only enabled for Member<B>. For Member<A> which we can
567 // compute the object header addr statically, this dynamic dispatch is not used.
568
569 class GarbageCollectedMixin {
570 public:
571     virtual void adjustAndMark(Visitor*) const = 0;
572     virtual bool isAlive(Visitor*) const = 0;
573 };
574
575 #define USING_GARBAGE_COLLECTED_MIXIN(TYPE) \
576 public: \
577     virtual void adjustAndMark(Visitor* visitor) const OVERRIDE \
578     { \
579         typedef WTF::IsSubclassOfTemplate<TYPE, WebCore::GarbageCollected> IsSubclassOfGarbageCollected; \
580         COMPILE_ASSERT(IsSubclassOfGarbageCollected::value, OnlyGarbageCollectedObjectsCanHaveGarbageCollectedMixins); \
581         visitor->mark(this, &TraceTrait<TYPE>::trace);\
582     } \
583     virtual bool isAlive(Visitor* visitor) const OVERRIDE \
584     { \
585         return visitor->isAlive(this); \
586     }
587
588 #if ENABLE(OILPAN)
589 #define WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(TYPE) USING_GARBAGE_COLLECTED_MIXIN(TYPE)
590 #else
591 #define WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(TYPE)
592 #endif
593
594 template<typename T>
595 struct GCInfoAtBase {
596     static const GCInfo* get()
597     {
598         static const GCInfo gcInfo = {
599             TraceTrait<T>::trace,
600             FinalizerTrait<T>::finalize,
601             FinalizerTrait<T>::nonTrivialFinalizer,
602         };
603         return &gcInfo;
604     }
605 };
606
607 template<typename T> class GarbageCollected;
608 template<typename T, bool = WTF::IsSubclassOfTemplate<T, GarbageCollected>::value> struct GetGarbageCollectedBase;
609
610 template<typename T>
611 struct GetGarbageCollectedBase<T, true> {
612     typedef typename T::GarbageCollectedBase type;
613 };
614
615 template<typename T>
616 struct GetGarbageCollectedBase<T, false> {
617     typedef T type;
618 };
619
620 template<typename T>
621 struct GCInfoTrait {
622     static const GCInfo* get()
623     {
624         return GCInfoAtBase<typename GetGarbageCollectedBase<T>::type>::get();
625     }
626 };
627
628 }
629
630 #endif