Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(375)

Side by Side Diff: Source/platform/heap/Handle.h

Issue 1120893003: Oilpan: Put all TraceTraits into TraceTraits.h (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/platform/heap/BUILD.gn ('k') | Source/platform/heap/Heap.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 16 matching lines...) Expand all
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #ifndef Handle_h 31 #ifndef Handle_h
32 #define Handle_h 32 #define Handle_h
33 33
34 #include "platform/heap/Heap.h" 34 #include "platform/heap/Heap.h"
35 #include "platform/heap/InlinedGlobalMarkingVisitor.h" 35 #include "platform/heap/InlinedGlobalMarkingVisitor.h"
36 #include "platform/heap/ThreadState.h" 36 #include "platform/heap/ThreadState.h"
37 #include "platform/heap/TraceTraits.h"
37 #include "platform/heap/Visitor.h" 38 #include "platform/heap/Visitor.h"
38 #include "wtf/Functional.h" 39 #include "wtf/Functional.h"
39 #include "wtf/HashFunctions.h" 40 #include "wtf/HashFunctions.h"
40 #include "wtf/Locker.h" 41 #include "wtf/Locker.h"
41 #include "wtf/RawPtr.h" 42 #include "wtf/RawPtr.h"
42 #include "wtf/RefCounted.h" 43 #include "wtf/RefCounted.h"
43 #include "wtf/TypeTraits.h" 44 #include "wtf/TypeTraits.h"
44 45
45 namespace blink { 46 namespace blink {
46 47
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 void clear() { m_raw = nullptr; } 583 void clear() { m_raw = nullptr; }
583 584
584 585
585 protected: 586 protected:
586 T* m_raw; 587 T* m_raw;
587 588
588 template<bool x, WTF::WeakHandlingFlag y, WTF::ShouldWeakPointersBeMarkedStr ongly z, typename U, typename V> friend struct CollectionBackingTraceTrait; 589 template<bool x, WTF::WeakHandlingFlag y, WTF::ShouldWeakPointersBeMarkedStr ongly z, typename U, typename V> friend struct CollectionBackingTraceTrait;
589 friend class Visitor; 590 friend class Visitor;
590 }; 591 };
591 592
592 template<typename T, bool needsTracing>
593 struct TraceIfEnabled;
594
595 template<typename T>
596 struct TraceIfEnabled<T, false> {
597 template<typename VisitorDispatcher>
598 static void trace(VisitorDispatcher, T*) { }
599 };
600
601 template<typename T>
602 struct TraceIfEnabled<T, true> {
603 template<typename VisitorDispatcher>
604 static void trace(VisitorDispatcher visitor, T* t)
605 {
606 visitor->trace(*t);
607 }
608 };
609
610 template <typename T> struct RemoveHeapPointerWrapperTypes {
611 using Type = typename WTF::RemoveTemplate<typename WTF::RemoveTemplate<typen ame WTF::RemoveTemplate<T, Member>::Type, WeakMember>::Type, RawPtr>::Type;
612 };
613
614 // FIXME: Oilpan: TraceIfNeeded should be implemented ala:
615 // NeedsTracing<T>::value || IsWeakMember<T>::value. It should not need to test
616 // raw pointer types. To remove these tests, we may need support for
617 // instantiating a template with a RawPtrOrMember'ish template.
618 template<typename T>
619 struct TraceIfNeeded : public TraceIfEnabled<T, WTF::NeedsTracing<T>::value || I sGarbageCollectedType<typename RemoveHeapPointerWrapperTypes<typename WTF::Remov ePointer<T>::Type>::Type>::value> { };
620
621 // This trace trait for std::pair will null weak members if their referent is
622 // collected. If you have a collection that contain weakness it does not remove
623 // entries from the collection that contain nulled weak members.
624 template<typename T, typename U>
625 class TraceTrait<std::pair<T, U>> {
626 public:
627 static const bool firstNeedsTracing = WTF::NeedsTracing<T>::value || WTF::Is Weak<T>::value;
628 static const bool secondNeedsTracing = WTF::NeedsTracing<U>::value || WTF::I sWeak<U>::value;
629 template<typename VisitorDispatcher>
630 static void trace(VisitorDispatcher visitor, std::pair<T, U>* pair)
631 {
632 TraceIfEnabled<T, firstNeedsTracing>::trace(visitor, &pair->first);
633 TraceIfEnabled<U, secondNeedsTracing>::trace(visitor, &pair->second);
634 }
635 };
636
637 // WeakMember is similar to Member in that it is used to point to other oilpan 593 // WeakMember is similar to Member in that it is used to point to other oilpan
638 // heap allocated objects. 594 // heap allocated objects.
639 // However instead of creating a strong pointer to the object, the WeakMember cr eates 595 // However instead of creating a strong pointer to the object, the WeakMember cr eates
640 // a weak pointer, which does not keep the pointee alive. Hence if all pointers to 596 // a weak pointer, which does not keep the pointee alive. Hence if all pointers to
641 // to a heap allocated object are weak the object will be garbage collected. At the 597 // to a heap allocated object are weak the object will be garbage collected. At the
642 // time of GC the weak pointers will automatically be set to null. 598 // time of GC the weak pointers will automatically be set to null.
643 template<typename T> 599 template<typename T>
644 class WeakMember : public Member<T> { 600 class WeakMember : public Member<T> {
645 public: 601 public:
646 WeakMember() : Member<T>() { } 602 WeakMember() : Member<T>() { }
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 template<typename T> 1034 template<typename T>
1079 struct ParamStorageTraits<RawPtr<T>> : public PointerParamStorageTraits<T*, blin k::IsGarbageCollectedType<T>::value> { 1035 struct ParamStorageTraits<RawPtr<T>> : public PointerParamStorageTraits<T*, blin k::IsGarbageCollectedType<T>::value> {
1080 }; 1036 };
1081 1037
1082 template<typename T> 1038 template<typename T>
1083 PassRefPtr<T> adoptRef(blink::RefCountedGarbageCollected<T>*) = delete; 1039 PassRefPtr<T> adoptRef(blink::RefCountedGarbageCollected<T>*) = delete;
1084 1040
1085 } // namespace WTF 1041 } // namespace WTF
1086 1042
1087 #endif 1043 #endif
OLDNEW
« no previous file with comments | « Source/platform/heap/BUILD.gn ('k') | Source/platform/heap/Heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698