Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / platform / heap / Handle.h
1 /*
2  * Copyright (C) 2014 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 Handle_h
32 #define Handle_h
33
34 #include "platform/heap/Heap.h"
35 #include "platform/heap/ThreadState.h"
36 #include "platform/heap/Visitor.h"
37 #include "wtf/HashFunctions.h"
38 #include "wtf/Locker.h"
39 #include "wtf/RawPtr.h"
40 #include "wtf/RefCounted.h"
41 #include "wtf/TypeTraits.h"
42
43 namespace WebCore {
44
45 template<typename T> class HeapTerminatedArray;
46
47 // Template to determine if a class is a GarbageCollectedMixin by checking if it
48 // has adjustAndMark and isAlive. We can't check directly if the class is a
49 // GarbageCollectedMixin because casting to it is potentially ambiguous.
50 template<typename T>
51 struct IsGarbageCollectedMixin {
52     typedef char TrueType;
53     struct FalseType {
54         char dummy[2];
55     };
56
57 #if COMPILER(MSVC)
58     template<typename U> static TrueType hasAdjustAndMark(char[&U::adjustAndMark != 0]);
59     template<typename U> static TrueType hasIsAlive(char[&U::isAlive != 0]);
60 #else
61     template<size_t> struct F;
62     template<typename U> static TrueType hasAdjustAndMark(F<sizeof(&U::adjustAndMark)>*);
63     template<typename U> static TrueType hasIsAlive(F<sizeof(&U::isAlive)>*);
64 #endif
65     template<typename U> static FalseType hasIsAlive(...);
66     template<typename U> static FalseType hasAdjustAndMark(...);
67
68     static bool const value = (sizeof(TrueType) == sizeof(hasAdjustAndMark<T>(0))) && (sizeof(TrueType) == sizeof(hasIsAlive<T>(0)));
69 };
70
71 #define COMPILE_ASSERT_IS_GARBAGE_COLLECTED(T, ErrorMessage)                                                          \
72     do {                                                                                                              \
73         typedef typename WTF::RemoveConst<T>::Type NonConstType;                                                      \
74         typedef WTF::IsSubclassOfTemplate<NonConstType, GarbageCollected> GarbageCollectedSubclass;                   \
75         typedef IsGarbageCollectedMixin<NonConstType> GarbageCollectedMixinSubclass;                                  \
76         typedef WTF::IsSubclassOfTemplate3<NonConstType, HeapHashSet> HeapHashSetSubclass;                            \
77         typedef WTF::IsSubclassOfTemplate3<NonConstType, HeapLinkedHashSet> HeapLinkedHashSetSubclass;                \
78         typedef WTF::IsSubclassOfTemplateTypenameSizeTypename<NonConstType, HeapListHashSet> HeapListHashSetSubclass; \
79         typedef WTF::IsSubclassOfTemplate5<NonConstType, HeapHashMap> HeapHashMapSubclass;                            \
80         typedef WTF::IsSubclassOfTemplateTypenameSize<NonConstType, HeapVector> HeapVectorSubclass;                   \
81         typedef WTF::IsSubclassOfTemplateTypenameSize<NonConstType, HeapDeque> HeapDequeSubclass;                     \
82         typedef WTF::IsSubclassOfTemplate3<NonConstType, HeapHashCountedSet> HeapHashCountedSetSubclass;              \
83         typedef WTF::IsSubclassOfTemplate<NonConstType, HeapTerminatedArray> HeapTerminatedArraySubclass;             \
84         COMPILE_ASSERT(GarbageCollectedSubclass::value ||                                                             \
85             GarbageCollectedMixinSubclass::value ||                                                                   \
86             HeapHashSetSubclass::value ||                                                                             \
87             HeapLinkedHashSetSubclass::value ||                                                                       \
88             HeapListHashSetSubclass::value ||                                                                         \
89             HeapHashMapSubclass::value ||                                                                             \
90             HeapVectorSubclass::value ||                                                                              \
91             HeapDequeSubclass::value ||                                                                               \
92             HeapHashCountedSetSubclass::value ||                                                                      \
93             HeapTerminatedArraySubclass::value,                                                                       \
94             ErrorMessage);                                                                                            \
95     } while (0)
96
97 template<typename T> class Member;
98
99 class PersistentNode {
100 public:
101     explicit PersistentNode(TraceCallback trace)
102         : m_trace(trace)
103     {
104     }
105
106     bool isAlive() { return m_trace; }
107
108     virtual ~PersistentNode()
109     {
110         ASSERT(isAlive());
111         m_trace = 0;
112     }
113
114     // Ideally the trace method should be virtual and automatically dispatch
115     // to the most specific implementation. However having a virtual method
116     // on PersistentNode leads to too eager template instantiation with MSVC
117     // which leads to include cycles.
118     // Instead we call the constructor with a TraceCallback which knows the
119     // type of the most specific child and calls trace directly. See
120     // TraceMethodDelegate in Visitor.h for how this is done.
121     void trace(Visitor* visitor)
122     {
123         m_trace(visitor, this);
124     }
125
126 protected:
127     TraceCallback m_trace;
128
129 private:
130     PersistentNode* m_next;
131     PersistentNode* m_prev;
132
133     template<typename RootsAccessor, typename Owner> friend class PersistentBase;
134     friend class PersistentAnchor;
135     friend class ThreadState;
136 };
137
138 // RootsAccessor for Persistent that provides access to thread-local list
139 // of persistent handles. Can only be used to create handles that
140 // are constructed and destructed on the same thread.
141 template<ThreadAffinity Affinity>
142 class ThreadLocalPersistents {
143 public:
144     static PersistentNode* roots() { return state()->roots(); }
145
146     // No locking required. Just check that we are at the right thread.
147     class Lock {
148     public:
149         Lock() { state()->checkThread(); }
150     };
151
152 private:
153     static ThreadState* state() { return ThreadStateFor<Affinity>::state(); }
154 };
155
156 // RootsAccessor for Persistent that provides synchronized access to global
157 // list of persistent handles. Can be used for persistent handles that are
158 // passed between threads.
159 class GlobalPersistents {
160 public:
161     static PersistentNode* roots() { return ThreadState::globalRoots(); }
162
163     class Lock {
164     public:
165         Lock() : m_locker(ThreadState::globalRootsMutex()) { }
166     private:
167         MutexLocker m_locker;
168     };
169 };
170
171 // Base class for persistent handles. RootsAccessor specifies which list to
172 // link resulting handle into. Owner specifies the class containing trace
173 // method.
174 template<typename RootsAccessor, typename Owner>
175 class PersistentBase : public PersistentNode {
176 public:
177     ~PersistentBase()
178     {
179         typename RootsAccessor::Lock lock;
180         ASSERT(m_roots == RootsAccessor::roots()); // Check that the thread is using the same roots list.
181         ASSERT(isAlive());
182         ASSERT(m_next->isAlive());
183         ASSERT(m_prev->isAlive());
184         m_next->m_prev = m_prev;
185         m_prev->m_next = m_next;
186     }
187
188 protected:
189     inline PersistentBase()
190         : PersistentNode(TraceMethodDelegate<Owner, &Owner::trace>::trampoline)
191 #ifndef NDEBUG
192         , m_roots(RootsAccessor::roots())
193 #endif
194     {
195         typename RootsAccessor::Lock lock;
196         m_prev = RootsAccessor::roots();
197         m_next = m_prev->m_next;
198         m_prev->m_next = this;
199         m_next->m_prev = this;
200     }
201
202     inline explicit PersistentBase(const PersistentBase& otherref)
203         : PersistentNode(otherref.m_trace)
204 #ifndef NDEBUG
205         , m_roots(RootsAccessor::roots())
206 #endif
207     {
208         typename RootsAccessor::Lock lock;
209         ASSERT(otherref.m_roots == m_roots); // Handles must belong to the same list.
210         PersistentBase* other = const_cast<PersistentBase*>(&otherref);
211         m_prev = other;
212         m_next = other->m_next;
213         other->m_next = this;
214         m_next->m_prev = this;
215     }
216
217     inline PersistentBase& operator=(const PersistentBase& otherref) { return *this; }
218
219 #ifndef NDEBUG
220 private:
221     PersistentNode* m_roots;
222 #endif
223 };
224
225 // A dummy Persistent handle that ensures the list of persistents is never null.
226 // This removes a test from a hot path.
227 class PersistentAnchor : public PersistentNode {
228 public:
229     void trace(Visitor* visitor)
230     {
231         for (PersistentNode* current = m_next; current != this; current = current->m_next)
232             current->trace(visitor);
233     }
234
235     virtual ~PersistentAnchor()
236     {
237         // FIXME: oilpan: Ideally we should have no left-over persistents at this point. However currently there is a
238         // large number of objects leaked when we tear down the main thread. Since some of these might contain a
239         // persistent or e.g. be RefCountedGarbageCollected we cannot guarantee there are no remaining Persistents at
240         // this point.
241     }
242
243 private:
244     PersistentAnchor() : PersistentNode(TraceMethodDelegate<PersistentAnchor, &PersistentAnchor::trace>::trampoline)
245     {
246         m_next = this;
247         m_prev = this;
248     }
249
250     friend class ThreadState;
251 };
252
253 #ifndef NDEBUG
254     // For global persistent handles we cannot check that the
255     // pointer is in the heap because that would involve
256     // inspecting the heap of running threads.
257 #define ASSERT_IS_VALID_PERSISTENT_POINTER(pointer) \
258     bool isGlobalPersistent = WTF::IsSubclass<RootsAccessor, GlobalPersistents>::value; \
259     ASSERT(!pointer || isGlobalPersistent || ThreadStateFor<ThreadingTrait<T>::Affinity>::state()->contains(pointer))
260 #else
261 #define ASSERT_IS_VALID_PERSISTENT_POINTER(pointer)
262 #endif
263
264 template<typename T>
265 class CrossThreadPersistent;
266
267 // Persistent handles are used to store pointers into the
268 // managed heap. As long as the Persistent handle is alive
269 // the GC will keep the object pointed to alive. Persistent
270 // handles can be stored in objects and they are not scoped.
271 // Persistent handles must not be used to contain pointers
272 // between objects that are in the managed heap. They are only
273 // meant to point to managed heap objects from variables/members
274 // outside the managed heap.
275 //
276 // A Persistent is always a GC root from the point of view of
277 // the garbage collector.
278 //
279 // We have to construct and destruct Persistent with default RootsAccessor in
280 // the same thread.
281 template<typename T, typename RootsAccessor /* = ThreadLocalPersistents<ThreadingTrait<T>::Affinity > */ >
282 class Persistent : public PersistentBase<RootsAccessor, Persistent<T, RootsAccessor> > {
283     WTF_DISALLOW_CONSTRUCTION_FROM_ZERO(Persistent);
284     WTF_DISALLOW_ZERO_ASSIGNMENT(Persistent);
285 public:
286     Persistent() : m_raw(0) { }
287
288     Persistent(std::nullptr_t) : m_raw(0) { }
289
290     Persistent(T* raw) : m_raw(raw)
291     {
292         ASSERT_IS_VALID_PERSISTENT_POINTER(m_raw);
293     }
294
295     explicit Persistent(T& raw) : m_raw(&raw)
296     {
297         ASSERT_IS_VALID_PERSISTENT_POINTER(m_raw);
298     }
299
300     Persistent(const Persistent& other) : m_raw(other) { }
301
302     template<typename U>
303     Persistent(const Persistent<U, RootsAccessor>& other) : m_raw(other) { }
304
305     template<typename U>
306     Persistent(const Member<U>& other) : m_raw(other) { }
307
308     template<typename U>
309     Persistent(const RawPtr<U>& other) : m_raw(other.get()) { }
310
311     template<typename U>
312     Persistent& operator=(U* other)
313     {
314         m_raw = other;
315         return *this;
316     }
317
318     Persistent& operator=(std::nullptr_t)
319     {
320         m_raw = 0;
321         return *this;
322     }
323
324     void clear() { m_raw = 0; }
325
326     virtual ~Persistent()
327     {
328         m_raw = 0;
329     }
330
331     template<typename U>
332     U* as() const
333     {
334         return static_cast<U*>(m_raw);
335     }
336
337     void trace(Visitor* visitor)
338     {
339         COMPILE_ASSERT_IS_GARBAGE_COLLECTED(T, NonGarbageCollectedObjectInPersistent);
340 #if ENABLE(GC_TRACING)
341         visitor->setHostInfo(this, "Persistent");
342 #endif
343         visitor->mark(m_raw);
344     }
345
346     T* release()
347     {
348         T* result = m_raw;
349         m_raw = 0;
350         return result;
351     }
352
353     T& operator*() const { return *m_raw; }
354
355     bool operator!() const { return !m_raw; }
356
357     operator T*() const { return m_raw; }
358     operator RawPtr<T>() const { return m_raw; }
359
360     T* operator->() const { return *this; }
361
362     Persistent& operator=(const Persistent& other)
363     {
364         m_raw = other;
365         return *this;
366     }
367
368     template<typename U>
369     Persistent& operator=(const Persistent<U, RootsAccessor>& other)
370     {
371         m_raw = other;
372         return *this;
373     }
374
375     template<typename U>
376     Persistent& operator=(const Member<U>& other)
377     {
378         m_raw = other;
379         return *this;
380     }
381
382     template<typename U>
383     Persistent& operator=(const RawPtr<U>& other)
384     {
385         m_raw = other;
386         return *this;
387     }
388
389     T* get() const { return m_raw; }
390
391 private:
392     T* m_raw;
393
394     friend class CrossThreadPersistent<T>;
395 };
396
397 // Unlike Persistent, we can destruct a CrossThreadPersistent in a thread
398 // different from the construction thread.
399 template<typename T>
400 class CrossThreadPersistent : public Persistent<T, GlobalPersistents> {
401     WTF_DISALLOW_CONSTRUCTION_FROM_ZERO(CrossThreadPersistent);
402     WTF_DISALLOW_ZERO_ASSIGNMENT(CrossThreadPersistent);
403 public:
404     CrossThreadPersistent(T* raw) : Persistent<T, GlobalPersistents>(raw) { }
405
406     using Persistent<T, GlobalPersistents>::operator=;
407 };
408
409 // FIXME: derive affinity based on the collection.
410 template<typename Collection, ThreadAffinity Affinity = AnyThread>
411 class PersistentHeapCollectionBase
412     : public Collection
413     , public PersistentBase<ThreadLocalPersistents<Affinity>, PersistentHeapCollectionBase<Collection, Affinity> > {
414     // We overload the various new and delete operators with using the WTF DefaultAllocator to ensure persistent
415     // heap collections are always allocated off-heap. This allows persistent collections to be used in
416     // DEFINE_STATIC_LOCAL et. al.
417     WTF_USE_ALLOCATOR(PersistentHeapCollectionBase, WTF::DefaultAllocator);
418 public:
419     PersistentHeapCollectionBase() { }
420
421     template<typename OtherCollection>
422     PersistentHeapCollectionBase(const OtherCollection& other) : Collection(other) { }
423
424     void trace(Visitor* visitor) { visitor->trace(*static_cast<Collection*>(this)); }
425 };
426
427 template<
428     typename KeyArg,
429     typename MappedArg,
430     typename HashArg = typename DefaultHash<KeyArg>::Hash,
431     typename KeyTraitsArg = HashTraits<KeyArg>,
432     typename MappedTraitsArg = HashTraits<MappedArg> >
433 class PersistentHeapHashMap : public PersistentHeapCollectionBase<HeapHashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg> > { };
434
435 template<
436     typename ValueArg,
437     typename HashArg = typename DefaultHash<ValueArg>::Hash,
438     typename TraitsArg = HashTraits<ValueArg> >
439 class PersistentHeapHashSet : public PersistentHeapCollectionBase<HeapHashSet<ValueArg, HashArg, TraitsArg> > { };
440
441 template<
442     typename ValueArg,
443     typename HashArg = typename DefaultHash<ValueArg>::Hash,
444     typename TraitsArg = HashTraits<ValueArg> >
445 class PersistentHeapLinkedHashSet : public PersistentHeapCollectionBase<HeapLinkedHashSet<ValueArg, HashArg, TraitsArg> > { };
446
447 template<
448     typename ValueArg,
449     size_t inlineCapacity = 0,
450     typename HashArg = typename DefaultHash<ValueArg>::Hash>
451 class PersistentHeapListHashSet : public PersistentHeapCollectionBase<HeapListHashSet<ValueArg, inlineCapacity, HashArg> > { };
452
453 template<typename T, typename U, typename V>
454 class PersistentHeapHashCountedSet : public PersistentHeapCollectionBase<HeapHashCountedSet<T, U, V> > { };
455
456 template<typename T, size_t inlineCapacity = 0>
457 class PersistentHeapVector : public PersistentHeapCollectionBase<HeapVector<T, inlineCapacity> > {
458 public:
459     PersistentHeapVector() { }
460
461     template<size_t otherCapacity>
462     PersistentHeapVector(const HeapVector<T, otherCapacity>& other)
463         : PersistentHeapCollectionBase<HeapVector<T, inlineCapacity> >(other)
464     {
465     }
466 };
467
468 template<typename T, size_t inlineCapacity = 0>
469 class PersistentHeapDeque : public PersistentHeapCollectionBase<HeapDeque<T, inlineCapacity> > {
470 public:
471     PersistentHeapDeque() { }
472
473     template<size_t otherCapacity>
474     PersistentHeapDeque(const HeapDeque<T, otherCapacity>& other)
475         : PersistentHeapCollectionBase<HeapDeque<T, inlineCapacity> >(other)
476     {
477     }
478 };
479
480 // Members are used in classes to contain strong pointers to other oilpan heap
481 // allocated objects.
482 // All Member fields of a class must be traced in the class' trace method.
483 // During the mark phase of the GC all live objects are marked as live and
484 // all Member fields of a live object will be traced marked as live as well.
485 template<typename T>
486 class Member {
487     WTF_DISALLOW_CONSTRUCTION_FROM_ZERO(Member);
488     WTF_DISALLOW_ZERO_ASSIGNMENT(Member);
489 public:
490     Member() : m_raw(0)
491     {
492     }
493
494     Member(std::nullptr_t) : m_raw(0)
495     {
496     }
497
498     Member(T* raw) : m_raw(raw)
499     {
500     }
501
502     explicit Member(T& raw) : m_raw(&raw)
503     {
504     }
505
506     template<typename U>
507     Member(const RawPtr<U>& other) : m_raw(other.get())
508     {
509     }
510
511     Member(WTF::HashTableDeletedValueType) : m_raw(reinterpret_cast<T*>(-1))
512     {
513     }
514
515     bool isHashTableDeletedValue() const { return m_raw == reinterpret_cast<T*>(-1); }
516
517     template<typename U>
518     Member(const Persistent<U>& other) : m_raw(other) { }
519
520     Member(const Member& other) : m_raw(other) { }
521
522     template<typename U>
523     Member(const Member<U>& other) : m_raw(other) { }
524
525     // FIXME: Oilpan: Get rid of these ASAP; this is only here to make
526     // Node hierarchy transition easier.
527     template<typename U>
528     Member(const PassRefPtr<U>& other) : m_raw(other.get()) { }
529
530     template<typename U>
531     Member(const RefPtr<U>& other) : m_raw(other.get()) { }
532
533     T* release()
534     {
535         T* result = m_raw;
536         m_raw = 0;
537         return result;
538     }
539
540     template<typename U>
541     U* as() const
542     {
543         return static_cast<U*>(m_raw);
544     }
545
546     bool operator!() const { return !m_raw; }
547
548     operator T*() const { return m_raw; }
549
550     T* operator->() const { return m_raw; }
551     T& operator*() const { return *m_raw; }
552     operator RawPtr<T>() const { return m_raw; }
553
554     template<typename U>
555     Member& operator=(const Persistent<U>& other)
556     {
557         m_raw = other;
558         return *this;
559     }
560
561     template<typename U>
562     Member& operator=(const Member<U>& other)
563     {
564         m_raw = other;
565         return *this;
566     }
567
568     template<typename U>
569     Member& operator=(U* other)
570     {
571         m_raw = other;
572         return *this;
573     }
574
575     template<typename U>
576     Member& operator=(RawPtr<U> other)
577     {
578         m_raw = other;
579         return *this;
580     }
581
582     Member& operator=(std::nullptr_t)
583     {
584         m_raw = 0;
585         return *this;
586     }
587
588     void swap(Member<T>& other) { std::swap(m_raw, other.m_raw); }
589
590     T* get() const { return m_raw; }
591
592     void clear() { m_raw = 0; }
593
594
595     // FIXME: Oilpan: Remove this ASAP. Only here to make Node transition easier.
596     template<typename U>
597     operator PassRefPtr<U>() { return PassRefPtr<U>(m_raw); }
598
599 protected:
600     void verifyTypeIsGarbageCollected() const
601     {
602         COMPILE_ASSERT_IS_GARBAGE_COLLECTED(T, NonGarbageCollectedObjectInMember);
603     }
604
605     T* m_raw;
606
607     template<bool x, bool y, ShouldWeakPointersBeMarkedStrongly z, typename U, typename V> friend struct CollectionBackingTraceTrait;
608     friend class Visitor;
609 };
610
611 template<typename T>
612 class TraceTrait<Member<T> > {
613 public:
614     static void trace(Visitor* visitor, void* self)
615     {
616         TraceTrait<T>::mark(visitor, *static_cast<Member<T>*>(self));
617     }
618 };
619
620 // TraceTrait to allow compilation of trace method bodies when oilpan is disabled.
621 // This should never be called, but is needed to compile.
622 template<typename T>
623 class TraceTrait<RefPtr<T> > {
624 public:
625     static void trace(Visitor*, void*)
626     {
627         ASSERT_NOT_REACHED();
628     }
629 };
630
631 template<typename T>
632 class TraceTrait<OwnPtr<T> > {
633 public:
634     static void trace(Visitor* visitor, OwnPtr<T>* ptr)
635     {
636         TraceTrait<T>::trace(visitor, ptr->get());
637     }
638 };
639
640 template<bool needsTracing, typename T>
641 struct StdPairHelper;
642
643 template<typename T>
644 struct StdPairHelper<false, T>  {
645     static void trace(Visitor*, T*) { }
646 };
647
648 template<typename T>
649 struct StdPairHelper<true, T> {
650     static void trace(Visitor* visitor, T* t)
651     {
652         visitor->trace(*t);
653     }
654 };
655
656 // This trace trait for std::pair will null weak members if their referent is
657 // collected. If you have a collection that contain weakness it does not remove
658 // entries from the collection that contain nulled weak members.
659 template<typename T, typename U>
660 class TraceTrait<std::pair<T, U> > {
661 public:
662     static const bool firstNeedsTracing = WTF::NeedsTracing<T>::value || WTF::IsWeak<T>::value;
663     static const bool secondNeedsTracing = WTF::NeedsTracing<U>::value || WTF::IsWeak<U>::value;
664     static void trace(Visitor* visitor, std::pair<T, U>* pair)
665     {
666         StdPairHelper<firstNeedsTracing, T>::trace(visitor, &pair->first);
667         StdPairHelper<secondNeedsTracing, U>::trace(visitor, &pair->second);
668     }
669 };
670
671 // WeakMember is similar to Member in that it is used to point to other oilpan
672 // heap allocated objects.
673 // However instead of creating a strong pointer to the object, the WeakMember creates
674 // a weak pointer, which does not keep the pointee alive. Hence if all pointers to
675 // to a heap allocated object are weak the object will be garbage collected. At the
676 // time of GC the weak pointers will automatically be set to null.
677 template<typename T>
678 class WeakMember : public Member<T> {
679     WTF_DISALLOW_CONSTRUCTION_FROM_ZERO(WeakMember);
680     WTF_DISALLOW_ZERO_ASSIGNMENT(WeakMember);
681 public:
682     WeakMember() : Member<T>() { }
683
684     WeakMember(std::nullptr_t) : Member<T>(nullptr) { }
685
686     WeakMember(T* raw) : Member<T>(raw) { }
687
688     WeakMember(WTF::HashTableDeletedValueType x) : Member<T>(x) { }
689
690     template<typename U>
691     WeakMember(const Persistent<U>& other) : Member<T>(other) { }
692
693     template<typename U>
694     WeakMember(const Member<U>& other) : Member<T>(other) { }
695
696     template<typename U>
697     WeakMember& operator=(const Persistent<U>& other)
698     {
699         this->m_raw = other;
700         return *this;
701     }
702
703     template<typename U>
704     WeakMember& operator=(const Member<U>& other)
705     {
706         this->m_raw = other;
707         return *this;
708     }
709
710     template<typename U>
711     WeakMember& operator=(U* other)
712     {
713         this->m_raw = other;
714         return *this;
715     }
716
717     template<typename U>
718     WeakMember& operator=(const RawPtr<U>& other)
719     {
720         this->m_raw = other;
721         return *this;
722     }
723
724     WeakMember& operator=(std::nullptr_t)
725     {
726         this->m_raw = 0;
727         return *this;
728     }
729
730 private:
731     T** cell() const { return const_cast<T**>(&this->m_raw); }
732
733     friend class Visitor;
734 };
735
736 // Comparison operators between (Weak)Members and Persistents
737 template<typename T, typename U> inline bool operator==(const Member<T>& a, const Member<U>& b) { return a.get() == b.get(); }
738 template<typename T, typename U> inline bool operator!=(const Member<T>& a, const Member<U>& b) { return a.get() != b.get(); }
739 template<typename T, typename U> inline bool operator==(const Member<T>& a, const Persistent<U>& b) { return a.get() == b.get(); }
740 template<typename T, typename U> inline bool operator!=(const Member<T>& a, const Persistent<U>& b) { return a.get() != b.get(); }
741 template<typename T, typename U> inline bool operator==(const Persistent<T>& a, const Member<U>& b) { return a.get() == b.get(); }
742 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a, const Member<U>& b) { return a.get() != b.get(); }
743 template<typename T, typename U> inline bool operator==(const Persistent<T>& a, const Persistent<U>& b) { return a.get() == b.get(); }
744 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a, const Persistent<U>& b) { return a.get() != b.get(); }
745
746 // FIXME: Oilpan: Get rid of these ASAP; only here to make Node transition easier.
747 template<typename T, typename U> inline bool operator==(const Member<T>& a, const RefPtr<U>& b) { return a.get() == b.get(); }
748 template<typename T, typename U> inline bool operator!=(const Member<T>& a, const RefPtr<U>& b) { return a.get() != b.get(); }
749 template<typename T, typename U> inline bool operator==(const RefPtr<T>& a, const Member<U>& b) { return a.get() == b.get(); }
750 template<typename T, typename U> inline bool operator!=(const RefPtr<T>& a, const Member<U>& b) { return a.get() != b.get(); }
751 template<typename T, typename U> inline bool operator==(const Member<T>& a, const PassRefPtr<U>& b) { return a.get() == b.get(); }
752 template<typename T, typename U> inline bool operator!=(const Member<T>& a, const PassRefPtr<U>& b) { return a.get() != b.get(); }
753 template<typename T, typename U> inline bool operator==(const PassRefPtr<T>& a, const Member<U>& b) { return a.get() == b.get(); }
754 template<typename T, typename U> inline bool operator!=(const PassRefPtr<T>& a, const Member<U>& b) { return a.get() != b.get(); }
755
756 // CPP-defined type names for the transition period where we want to
757 // support both reference counting and garbage collection based on a
758 // compile-time flag.
759 //
760 // C++11 template aliases were initially used (with clang only, not
761 // with GCC nor MSVC.) However, supporting both CPP defines and
762 // template aliases is problematic from outside a WebCore namespace
763 // when Oilpan is disabled: e.g.,
764 // WebCore::RefCountedWillBeGarbageCollected as a template alias would
765 // uniquely resolve from within any namespace, but if it is backed by
766 // a CPP #define, it would expand to WebCore::RefCounted, and not the
767 // required WTF::RefCounted.
768 //
769 // Having the CPP expansion instead be fully namespace qualified, and the
770 // transition type be unqualified, would dually not work for template
771 // aliases. So, slightly unfortunately, fall back/down to the lowest
772 // commmon denominator of using CPP macros only.
773 #if ENABLE(OILPAN)
774 #define PassRefPtrWillBeRawPtr WTF::RawPtr
775 #define RefCountedWillBeGarbageCollected WebCore::GarbageCollected
776 #define RefCountedWillBeGarbageCollectedFinalized WebCore::GarbageCollectedFinalized
777 #define RefCountedWillBeRefCountedGarbageCollected WebCore::RefCountedGarbageCollected
778 #define ThreadSafeRefCountedWillBeGarbageCollected WebCore::GarbageCollected
779 #define ThreadSafeRefCountedWillBeGarbageCollectedFinalized WebCore::GarbageCollectedFinalized
780 #define ThreadSafeRefCountedWillBeThreadSafeRefCountedGarbageCollected WebCore::ThreadSafeRefCountedGarbageCollected
781 #define TreeSharedWillBeRefCountedGarbageCollected WebCore::RefCountedGarbageCollected
782 #define PersistentWillBeMember WebCore::Member
783 #define RefPtrWillBePersistent WebCore::Persistent
784 #define RefPtrWillBeRawPtr WTF::RawPtr
785 #define RefPtrWillBeMember WebCore::Member
786 #define RefPtrWillBeCrossThreadPersistent WebCore::CrossThreadPersistent
787 #define RawPtrWillBeMember WebCore::Member
788 #define RawPtrWillBeWeakMember WebCore::WeakMember
789 #define OwnPtrWillBeMember WebCore::Member
790 #define OwnPtrWillBePersistent WebCore::Persistent
791 #define OwnPtrWillBeRawPtr WTF::RawPtr
792 #define PassOwnPtrWillBeRawPtr WTF::RawPtr
793 #define WeakPtrWillBeRawPtr WTF::RawPtr
794 #define WeakPtrWillBeWeakMember WebCore::WeakMember
795 #define NoBaseWillBeGarbageCollected WebCore::GarbageCollected
796 #define NoBaseWillBeGarbageCollectedFinalized WebCore::GarbageCollectedFinalized
797 #define WillBeHeapHashMap WebCore::HeapHashMap
798 #define WillBePersistentHeapHashMap WebCore::PersistentHeapHashMap
799 #define WillBeHeapHashSet WebCore::HeapHashSet
800 #define WillBePersistentHeapHashSet WebCore::PersistentHeapHashSet
801 #define WillBeHeapLinkedHashSet WebCore::HeapLinkedHashSet
802 #define WillBePersistentHeapLinkedHashSet WebCore::PersistentHeapLinkedHashSet
803 #define WillBeHeapListHashSet WebCore::HeapListHashSet
804 #define WillBePersistentHeapListHashSet WebCore::PersistentHeapListHashSet
805 #define WillBeHeapVector WebCore::HeapVector
806 #define WillBePersistentHeapVector WebCore::PersistentHeapVector
807 #define WillBeHeapDeque WebCore::HeapDeque
808 #define WillBePersistentHeapDeque WebCore::PersistentHeapDeque
809 #define WillBeHeapHashCountedSet WebCore::HeapHashCountedSet
810 #define WillBePersistentHeapHashCountedSet WebCore::PersistentHeapHashCountedSet
811 #define WillBeGarbageCollectedMixin WebCore::GarbageCollectedMixin
812 #define WillBeHeapSupplement WebCore::HeapSupplement
813 #define WillBeHeapSupplementable WebCore::HeapSupplementable
814 #define WillBeHeapTerminatedArray WebCore::HeapTerminatedArray
815 #define WillBeHeapTerminatedArrayBuilder WebCore::HeapTerminatedArrayBuilder
816 #define WillBeHeapLinkedStack WebCore::HeapLinkedStack
817
818 template<typename T> PassRefPtrWillBeRawPtr<T> adoptRefWillBeNoop(T* ptr)
819 {
820     static const bool notRefCountedGarbageCollected = !WTF::IsSubclassOfTemplate<T, RefCountedGarbageCollected>::value;
821     static const bool notRefCounted = !WTF::IsSubclassOfTemplate<T, RefCounted>::value;
822     COMPILE_ASSERT(notRefCountedGarbageCollected, useAdoptRefCountedWillBeRefCountedGarbageCollected);
823     COMPILE_ASSERT(notRefCounted, youMustAdopt);
824     return PassRefPtrWillBeRawPtr<T>(ptr);
825 }
826
827 template<typename T> PassRefPtrWillBeRawPtr<T> adoptRefWillBeRefCountedGarbageCollected(T* ptr)
828 {
829     static const bool isRefCountedGarbageCollected = WTF::IsSubclassOfTemplate<T, RefCountedGarbageCollected>::value;
830     COMPILE_ASSERT(isRefCountedGarbageCollected, useAdoptRefWillBeNoop);
831     return PassRefPtrWillBeRawPtr<T>(adoptRefCountedGarbageCollected(ptr));
832 }
833
834 template<typename T> PassRefPtrWillBeRawPtr<T> adoptRefWillBeThreadSafeRefCountedGarbageCollected(T* ptr)
835 {
836     static const bool isThreadSafeRefCountedGarbageCollected = WTF::IsSubclassOfTemplate<T, ThreadSafeRefCountedGarbageCollected>::value;
837     COMPILE_ASSERT(isThreadSafeRefCountedGarbageCollected, useAdoptRefWillBeNoop);
838     return PassRefPtrWillBeRawPtr<T>(adoptRefCountedGarbageCollected(ptr));
839 }
840
841 template<typename T> PassOwnPtrWillBeRawPtr<T> adoptPtrWillBeNoop(T* ptr)
842 {
843     static const bool notRefCountedGarbageCollected = !WTF::IsSubclassOfTemplate<T, RefCountedGarbageCollected>::value;
844     static const bool notRefCounted = !WTF::IsSubclassOfTemplate<T, RefCounted>::value;
845     COMPILE_ASSERT(notRefCountedGarbageCollected, useAdoptRefCountedWillBeRefCountedGarbageCollected);
846     COMPILE_ASSERT(notRefCounted, youMustAdopt);
847     return PassOwnPtrWillBeRawPtr<T>(ptr);
848 }
849
850 #define WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED // do nothing when oilpan is enabled.
851 #define DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(type) // do nothing
852 #define DECLARE_EMPTY_VIRTUAL_DESTRUCTOR_WILL_BE_REMOVED(type) // do nothing
853 #define DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(type) // do nothing
854
855 #define DEFINE_STATIC_REF_WILL_BE_PERSISTENT(type, name, arguments) \
856     DEFINE_STATIC_LOCAL(Persistent<type>, name, arguments)
857
858 #else // !ENABLE(OILPAN)
859
860 template<typename T>
861 class DummyBase {
862 public:
863     DummyBase() { }
864     ~DummyBase() { }
865 };
866
867 #define PassRefPtrWillBeRawPtr WTF::PassRefPtr
868 #define RefCountedWillBeGarbageCollected WTF::RefCounted
869 #define RefCountedWillBeGarbageCollectedFinalized WTF::RefCounted
870 #define RefCountedWillBeRefCountedGarbageCollected WTF::RefCounted
871 #define ThreadSafeRefCountedWillBeGarbageCollected WTF::ThreadSafeRefCounted
872 #define ThreadSafeRefCountedWillBeGarbageCollectedFinalized WTF::ThreadSafeRefCounted
873 #define ThreadSafeRefCountedWillBeThreadSafeRefCountedGarbageCollected WTF::ThreadSafeRefCounted
874 #define TreeSharedWillBeRefCountedGarbageCollected WebCore::TreeShared
875 #define PersistentWillBeMember WebCore::Persistent
876 #define RefPtrWillBePersistent WTF::RefPtr
877 #define RefPtrWillBeRawPtr WTF::RefPtr
878 #define RefPtrWillBeMember WTF::RefPtr
879 #define RefPtrWillBeCrossThreadPersistent WTF::RefPtr
880 #define RawPtrWillBeMember WTF::RawPtr
881 #define RawPtrWillBeWeakMember WTF::RawPtr
882 #define OwnPtrWillBeMember WTF::OwnPtr
883 #define OwnPtrWillBePersistent WTF::OwnPtr
884 #define OwnPtrWillBeRawPtr WTF::OwnPtr
885 #define PassOwnPtrWillBeRawPtr WTF::PassOwnPtr
886 #define WeakPtrWillBeRawPtr WTF::WeakPtr
887 #define WeakPtrWillBeWeakMember WTF::WeakPtr
888 #define NoBaseWillBeGarbageCollected WebCore::DummyBase
889 #define NoBaseWillBeGarbageCollectedFinalized WebCore::DummyBase
890 #define WillBeHeapHashMap WTF::HashMap
891 #define WillBePersistentHeapHashMap WTF::HashMap
892 #define WillBeHeapHashSet WTF::HashSet
893 #define WillBePersistentHeapHashSet WTF::HashSet
894 #define WillBeHeapLinkedHashSet WTF::LinkedHashSet
895 #define WillBePersistentLinkedHeapHashSet WTF::LinkedHashSet
896 #define WillBeHeapListHashSet WTF::ListHashSet
897 #define WillBePersistentListHeapHashSet WTF::ListHashSet
898 #define WillBeHeapVector WTF::Vector
899 #define WillBePersistentHeapVector WTF::Vector
900 #define WillBeHeapDeque WTF::Deque
901 #define WillBePersistentHeapDeque WTF::Deque
902 #define WillBeHeapHeapCountedSet WTF::HeapCountedSet
903 #define WillBePersistentHeapHeapCountedSet WTF::HeapCountedSet
904 #define WillBeGarbageCollectedMixin WebCore::DummyBase<void>
905 #define WillBeHeapSupplement WebCore::Supplement
906 #define WillBeHeapSupplementable WebCore::Supplementable
907 #define WillBeHeapTerminatedArray WTF::TerminatedArray
908 #define WillBeHeapTerminatedArrayBuilder WTF::TerminatedArrayBuilder
909 #define WillBeHeapLinkedStack WTF::LinkedStack
910
911 template<typename T> PassRefPtrWillBeRawPtr<T> adoptRefWillBeNoop(T* ptr) { return adoptRef(ptr); }
912 template<typename T> PassRefPtrWillBeRawPtr<T> adoptRefWillBeRefCountedGarbageCollected(T* ptr) { return adoptRef(ptr); }
913 template<typename T> PassRefPtrWillBeRawPtr<T> adoptRefWillBeThreadSafeRefCountedGarbageCollected(T* ptr) { return adoptRef(ptr); }
914 template<typename T> PassOwnPtrWillBeRawPtr<T> adoptPtrWillBeNoop(T* ptr) { return adoptPtr(ptr); }
915
916 #define WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED WTF_MAKE_FAST_ALLOCATED
917 #define DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(type) \
918     public:                                            \
919         ~type();                                       \
920     private:
921 #define DECLARE_EMPTY_VIRTUAL_DESTRUCTOR_WILL_BE_REMOVED(type) \
922     public:                                                    \
923         virtual ~type();                                       \
924     private:
925
926 #define DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(type) \
927     type::~type() { }
928
929 #define DEFINE_STATIC_REF_WILL_BE_PERSISTENT(type, name, arguments) \
930     DEFINE_STATIC_REF(type, name, arguments)
931
932 #endif // ENABLE(OILPAN)
933
934 } // namespace WebCore
935
936 namespace WTF {
937
938 template <typename T> struct VectorTraits<WebCore::Member<T> > : VectorTraitsBase<WebCore::Member<T> > {
939     static const bool needsDestruction = false;
940     static const bool canInitializeWithMemset = true;
941     static const bool canMoveWithMemcpy = true;
942 };
943
944 template <typename T> struct VectorTraits<WebCore::WeakMember<T> > : VectorTraitsBase<WebCore::WeakMember<T> > {
945     static const bool needsDestruction = false;
946     static const bool canInitializeWithMemset = true;
947     static const bool canMoveWithMemcpy = true;
948 };
949
950 template <typename T> struct VectorTraits<WebCore::HeapVector<T, 0> > : VectorTraitsBase<WebCore::HeapVector<T, 0> > {
951     static const bool needsDestruction = false;
952     static const bool canInitializeWithMemset = true;
953     static const bool canMoveWithMemcpy = true;
954 };
955
956 template <typename T> struct VectorTraits<WebCore::HeapDeque<T, 0> > : VectorTraitsBase<WebCore::HeapDeque<T, 0> > {
957     static const bool needsDestruction = false;
958     static const bool canInitializeWithMemset = true;
959     static const bool canMoveWithMemcpy = true;
960 };
961
962 template <typename T, size_t inlineCapacity> struct VectorTraits<WebCore::HeapVector<T, inlineCapacity> > : VectorTraitsBase<WebCore::HeapVector<T, inlineCapacity> > {
963     static const bool needsDestruction = VectorTraits<T>::needsDestruction;
964     static const bool canInitializeWithMemset = VectorTraits<T>::canInitializeWithMemset;
965     static const bool canMoveWithMemcpy = VectorTraits<T>::canMoveWithMemcpy;
966 };
967
968 template <typename T, size_t inlineCapacity> struct VectorTraits<WebCore::HeapDeque<T, inlineCapacity> > : VectorTraitsBase<WebCore::HeapDeque<T, inlineCapacity> > {
969     static const bool needsDestruction = VectorTraits<T>::needsDestruction;
970     static const bool canInitializeWithMemset = VectorTraits<T>::canInitializeWithMemset;
971     static const bool canMoveWithMemcpy = VectorTraits<T>::canMoveWithMemcpy;
972 };
973
974 template<typename T> struct HashTraits<WebCore::Member<T> > : SimpleClassHashTraits<WebCore::Member<T> > {
975     static const bool needsDestruction = false;
976     // FIXME: The distinction between PeekInType and PassInType is there for
977     // the sake of the reference counting handles. When they are gone the two
978     // types can be merged into PassInType.
979     // FIXME: Implement proper const'ness for iterator types. Requires support
980     // in the marking Visitor.
981     typedef RawPtr<T> PeekInType;
982     typedef RawPtr<T> PassInType;
983     typedef WebCore::Member<T>* IteratorGetType;
984     typedef const WebCore::Member<T>* IteratorConstGetType;
985     typedef WebCore::Member<T>& IteratorReferenceType;
986     typedef T* const IteratorConstReferenceType;
987     static IteratorReferenceType getToReferenceConversion(IteratorGetType x) { return *x; }
988     static IteratorConstReferenceType getToReferenceConstConversion(IteratorConstGetType x) { return x->get(); }
989     // FIXME: Similarly, there is no need for a distinction between PeekOutType
990     // and PassOutType without reference counting.
991     typedef T* PeekOutType;
992     typedef T* PassOutType;
993
994     template<typename U>
995     static void store(const U& value, WebCore::Member<T>& storage) { storage = value; }
996
997     static PeekOutType peek(const WebCore::Member<T>& value) { return value; }
998     static PassOutType passOut(const WebCore::Member<T>& value) { return value; }
999 };
1000
1001 template<typename T> struct HashTraits<WebCore::WeakMember<T> > : SimpleClassHashTraits<WebCore::WeakMember<T> > {
1002     static const bool needsDestruction = false;
1003     // FIXME: The distinction between PeekInType and PassInType is there for
1004     // the sake of the reference counting handles. When they are gone the two
1005     // types can be merged into PassInType.
1006     // FIXME: Implement proper const'ness for iterator types. Requires support
1007     // in the marking Visitor.
1008     typedef RawPtr<T> PeekInType;
1009     typedef RawPtr<T> PassInType;
1010     typedef WebCore::WeakMember<T>* IteratorGetType;
1011     typedef const WebCore::WeakMember<T>* IteratorConstGetType;
1012     typedef WebCore::WeakMember<T>& IteratorReferenceType;
1013     typedef T* const IteratorConstReferenceType;
1014     static IteratorReferenceType getToReferenceConversion(IteratorGetType x) { return *x; }
1015     static IteratorConstReferenceType getToReferenceConstConversion(IteratorConstGetType x) { return x->get(); }
1016     // FIXME: Similarly, there is no need for a distinction between PeekOutType
1017     // and PassOutType without reference counting.
1018     typedef T* PeekOutType;
1019     typedef T* PassOutType;
1020
1021     template<typename U>
1022     static void store(const U& value, WebCore::WeakMember<T>& storage) { storage = value; }
1023
1024     static PeekOutType peek(const WebCore::WeakMember<T>& value) { return value; }
1025     static PassOutType passOut(const WebCore::WeakMember<T>& value) { return value; }
1026 };
1027
1028 template<typename T> struct PtrHash<WebCore::Member<T> > : PtrHash<T*> {
1029     template<typename U>
1030     static unsigned hash(const U& key) { return PtrHash<T*>::hash(key); }
1031     static bool equal(T* a, const WebCore::Member<T>& b) { return a == b; }
1032     static bool equal(const WebCore::Member<T>& a, T* b) { return a == b; }
1033     template<typename U, typename V>
1034     static bool equal(const U& a, const V& b) { return a == b; }
1035 };
1036
1037 template<typename T> struct PtrHash<WebCore::WeakMember<T> > : PtrHash<WebCore::Member<T> > {
1038 };
1039
1040 template<typename P> struct PtrHash<WebCore::Persistent<P> > : PtrHash<P*> {
1041     using PtrHash<P*>::hash;
1042     static unsigned hash(const RefPtr<P>& key) { return hash(key.get()); }
1043     using PtrHash<P*>::equal;
1044     static bool equal(const RefPtr<P>& a, const RefPtr<P>& b) { return a == b; }
1045     static bool equal(P* a, const RefPtr<P>& b) { return a == b; }
1046     static bool equal(const RefPtr<P>& a, P* b) { return a == b; }
1047 };
1048
1049 // PtrHash is the default hash for hash tables with members.
1050 template<typename T> struct DefaultHash<WebCore::Member<T> > {
1051     typedef PtrHash<WebCore::Member<T> > Hash;
1052 };
1053
1054 template<typename T> struct DefaultHash<WebCore::WeakMember<T> > {
1055     typedef PtrHash<WebCore::WeakMember<T> > Hash;
1056 };
1057
1058 template<typename T> struct DefaultHash<WebCore::Persistent<T> > {
1059     typedef PtrHash<WebCore::Persistent<T> > Hash;
1060 };
1061
1062 template<typename T>
1063 struct NeedsTracing<WebCore::Member<T> > {
1064     static const bool value = true;
1065 };
1066
1067 template<typename T>
1068 struct IsWeak<WebCore::WeakMember<T> > {
1069     static const bool value = true;
1070 };
1071
1072 template<typename Table>
1073 struct IsWeak<WebCore::HeapHashTableBacking<Table> > {
1074     static const bool value = Table::ValueTraits::isWeak;
1075 };
1076
1077 template<typename T> inline T* getPtr(const WebCore::Member<T>& p)
1078 {
1079     return p.get();
1080 }
1081
1082 template<typename T, typename U>
1083 struct NeedsTracing<std::pair<T, U> > {
1084     static const bool value = NeedsTracing<T>::value || NeedsTracing<U>::value || IsWeak<T>::value || IsWeak<U>::value;
1085 };
1086
1087 template<typename T>
1088 struct NeedsTracing<OwnPtr<T> > {
1089     static const bool value = NeedsTracing<T>::value;
1090 };
1091
1092 // We define specialization of the NeedsTracing trait for off heap collections
1093 // since we don't support tracing them.
1094 template<typename T, size_t N>
1095 struct NeedsTracing<Vector<T, N> > {
1096     static const bool value = false;
1097 };
1098
1099 template<typename T, size_t N>
1100 struct NeedsTracing<Deque<T, N> > {
1101     static const bool value = false;
1102 };
1103
1104 template<typename T, typename U, typename V>
1105 struct NeedsTracing<HashCountedSet<T, U, V> > {
1106     static const bool value = false;
1107 };
1108
1109 template<typename T, typename U, typename V>
1110 struct NeedsTracing<HashSet<T, U, V> > {
1111     static const bool value = false;
1112 };
1113
1114 template<typename T, size_t U, typename V>
1115 struct NeedsTracing<ListHashSet<T, U, V> > {
1116     static const bool value = false;
1117 };
1118
1119 template<typename T, typename U, typename V>
1120 struct NeedsTracing<LinkedHashSet<T, U, V> > {
1121     static const bool value = false;
1122 };
1123
1124 template<typename T, typename U, typename V, typename W, typename X>
1125 struct NeedsTracing<HashMap<T, U, V, W, X> > {
1126     static const bool value = false;
1127 };
1128
1129 template<typename T, size_t inlineCapacity>
1130 struct NeedsTracing<ListHashSetNode<T, WebCore::HeapListHashSetAllocator<T, inlineCapacity> > *> {
1131     // All heap allocated node pointers need visiting to keep the nodes alive,
1132     // regardless of whether they contain pointers to other heap allocated
1133     // objects.
1134     static const bool value = true;
1135 };
1136
1137 } // namespace WTF
1138
1139 #endif