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

Side by Side Diff: sky/engine/platform/heap/Handle.h

Issue 678003003: Begin to remove heap/* (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « sky/engine/platform/TaskSynchronizer.cpp ('k') | sky/engine/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 27 matching lines...) Expand all
38 #include "wtf/HashFunctions.h" 38 #include "wtf/HashFunctions.h"
39 #include "wtf/Locker.h" 39 #include "wtf/Locker.h"
40 #include "wtf/RawPtr.h" 40 #include "wtf/RawPtr.h"
41 #include "wtf/RefCounted.h" 41 #include "wtf/RefCounted.h"
42 #include "wtf/TypeTraits.h" 42 #include "wtf/TypeTraits.h"
43 43
44 namespace blink { 44 namespace blink {
45 45
46 template<typename T> class HeapTerminatedArray; 46 template<typename T> class HeapTerminatedArray;
47 47
48 // Template to determine if a class is a GarbageCollectedMixin by checking if it
49 // has adjustAndMark and isAlive. We can't check directly if the class is a
50 // GarbageCollectedMixin because casting to it is potentially ambiguous.
51 template<typename T>
52 struct IsGarbageCollectedMixin {
53 typedef char TrueType;
54 struct FalseType {
55 char dummy[2];
56 };
57
58 #if COMPILER(MSVC)
59 template<typename U> static TrueType hasAdjustAndMark(char[&U::adjustAndMark != 0]);
60 template<typename U> static TrueType hasIsAlive(char[&U::isAlive != 0]);
61 #else
62 template<size_t> struct F;
63 template<typename U> static TrueType hasAdjustAndMark(F<sizeof(&U::adjustAnd Mark)>*);
64 template<typename U> static TrueType hasIsAlive(F<sizeof(&U::isAlive)>*);
65 #endif
66 template<typename U> static FalseType hasIsAlive(...);
67 template<typename U> static FalseType hasAdjustAndMark(...);
68
69 static bool const value = (sizeof(TrueType) == sizeof(hasAdjustAndMark<T>(0) )) && (sizeof(TrueType) == sizeof(hasIsAlive<T>(0)));
70 };
71
72 template <typename T>
73 struct IsGarbageCollectedType {
74 typedef char TrueType;
75 struct FalseType {
76 char dummy[2];
77 };
78
79 typedef typename WTF::RemoveConst<T>::Type NonConstType;
80 typedef WTF::IsSubclassOfTemplate<NonConstType, GarbageCollected> GarbageCol lectedSubclass;
81 typedef IsGarbageCollectedMixin<NonConstType> GarbageCollectedMixinSubclass;
82 typedef WTF::IsSubclassOfTemplate3<NonConstType, HeapHashSet> HeapHashSetSub class;
83 typedef WTF::IsSubclassOfTemplate3<NonConstType, HeapLinkedHashSet> HeapLink edHashSetSubclass;
84 typedef WTF::IsSubclassOfTemplateTypenameSizeTypename<NonConstType, HeapList HashSet> HeapListHashSetSubclass;
85 typedef WTF::IsSubclassOfTemplate5<NonConstType, HeapHashMap> HeapHashMapSub class;
86 typedef WTF::IsSubclassOfTemplateTypenameSize<NonConstType, HeapVector> Heap VectorSubclass;
87 typedef WTF::IsSubclassOfTemplateTypenameSize<NonConstType, HeapDeque> HeapD equeSubclass;
88 typedef WTF::IsSubclassOfTemplate3<NonConstType, HeapHashCountedSet> HeapHas hCountedSetSubclass;
89 typedef WTF::IsSubclassOfTemplate<NonConstType, HeapTerminatedArray> HeapTer minatedArraySubclass;
90
91 template<typename U, size_t inlineCapacity> static TrueType listHashSetNodeI sHeapAllocated(WTF::ListHashSetNode<U, HeapListHashSetAllocator<U, inlineCapacit y> >*);
92 static FalseType listHashSetNodeIsHeapAllocated(...);
93 static const bool isHeapAllocatedListHashSetNode = sizeof(TrueType) == sizeo f(listHashSetNodeIsHeapAllocated(reinterpret_cast<NonConstType*>(0)));
94
95 static const bool value =
96 GarbageCollectedSubclass::value
97 || GarbageCollectedMixinSubclass::value
98 || HeapHashSetSubclass::value
99 || HeapLinkedHashSetSubclass::value
100 || HeapListHashSetSubclass::value
101 || HeapHashMapSubclass::value
102 || HeapVectorSubclass::value
103 || HeapDequeSubclass::value
104 || HeapHashCountedSetSubclass::value
105 || HeapTerminatedArraySubclass::value
106 || isHeapAllocatedListHashSetNode;
107 };
108
109 #define COMPILE_ASSERT_IS_GARBAGE_COLLECTED(T, ErrorMessage) \
110 COMPILE_ASSERT(IsGarbageCollectedType<T>::value, ErrorMessage)
111
112 template<typename T> class Member; 48 template<typename T> class Member;
113 49
114 class PersistentNode { 50 class PersistentNode {
115 public: 51 public:
116 explicit PersistentNode(TraceCallback trace) 52 explicit PersistentNode(TraceCallback trace)
117 : m_trace(trace) 53 : m_trace(trace)
118 { 54 {
119 } 55 }
120 56
121 bool isAlive() { return m_trace; } 57 bool isAlive() { return m_trace; }
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 } 495 }
560 496
561 template<typename U> 497 template<typename U>
562 U* as() const 498 U* as() const
563 { 499 {
564 return static_cast<U*>(m_raw); 500 return static_cast<U*>(m_raw);
565 } 501 }
566 502
567 void trace(Visitor* visitor) 503 void trace(Visitor* visitor)
568 { 504 {
569 COMPILE_ASSERT_IS_GARBAGE_COLLECTED(T, NonGarbageCollectedObjectInPersis tent);
570 #if ENABLE(GC_PROFILE_MARKING) 505 #if ENABLE(GC_PROFILE_MARKING)
571 visitor->setHostInfo(this, m_tracingName.isEmpty() ? "Persistent" : m_tr acingName); 506 visitor->setHostInfo(this, m_tracingName.isEmpty() ? "Persistent" : m_tr acingName);
572 #endif 507 #endif
573 visitor->mark(m_raw); 508 visitor->mark(m_raw);
574 } 509 }
575 510
576 RawPtr<T> release() 511 RawPtr<T> release()
577 { 512 {
578 RawPtr<T> result = m_raw; 513 RawPtr<T> result = m_raw;
579 m_raw = 0; 514 m_raw = 0;
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 void swap(Member<T>& other) { std::swap(m_raw, other.m_raw); } 767 void swap(Member<T>& other) { std::swap(m_raw, other.m_raw); }
833 768
834 T* get() const { return m_raw; } 769 T* get() const { return m_raw; }
835 770
836 void clear() { m_raw = 0; } 771 void clear() { m_raw = 0; }
837 772
838 773
839 protected: 774 protected:
840 void verifyTypeIsGarbageCollected() const 775 void verifyTypeIsGarbageCollected() const
841 { 776 {
842 COMPILE_ASSERT_IS_GARBAGE_COLLECTED(T, NonGarbageCollectedObjectInMember );
843 } 777 }
844 778
845 T* m_raw; 779 T* m_raw;
846 780
847 template<bool x, WTF::WeakHandlingFlag y, WTF::ShouldWeakPointersBeMarkedStr ongly z, typename U, typename V> friend struct CollectionBackingTraceTrait; 781 template<bool x, WTF::WeakHandlingFlag y, WTF::ShouldWeakPointersBeMarkedStr ongly z, typename U, typename V> friend struct CollectionBackingTraceTrait;
848 friend class Visitor; 782 friend class Visitor;
849 }; 783 };
850 784
851 template<typename T> 785 template<typename T>
852 class TraceTrait<Member<T> > { 786 class TraceTrait<Member<T> > {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 829
896 template <typename T> struct RemoveHeapPointerWrapperTypes { 830 template <typename T> struct RemoveHeapPointerWrapperTypes {
897 typedef typename WTF::RemoveTemplate<typename WTF::RemoveTemplate<typename W TF::RemoveTemplate<T, Member>::Type, WeakMember>::Type, RawPtr>::Type Type; 831 typedef typename WTF::RemoveTemplate<typename WTF::RemoveTemplate<typename W TF::RemoveTemplate<T, Member>::Type, WeakMember>::Type, RawPtr>::Type Type;
898 }; 832 };
899 833
900 // FIXME: Oilpan: TraceIfNeeded should be implemented ala: 834 // FIXME: Oilpan: TraceIfNeeded should be implemented ala:
901 // NeedsTracing<T>::value || IsWeakMember<T>::value. It should not need to test 835 // NeedsTracing<T>::value || IsWeakMember<T>::value. It should not need to test
902 // raw pointer types. To remove these tests, we may need support for 836 // raw pointer types. To remove these tests, we may need support for
903 // instantiating a template with a RawPtrOrMember'ish template. 837 // instantiating a template with a RawPtrOrMember'ish template.
904 template<typename T> 838 template<typename T>
905 struct TraceIfNeeded : public TraceIfEnabled<T, WTF::NeedsTracing<T>::value || b link::IsGarbageCollectedType<typename RemoveHeapPointerWrapperTypes<typename WTF ::RemovePointer<T>::Type>::Type>::value> { }; 839 struct TraceIfNeeded : public TraceIfEnabled<T, false> { };
906 840
907 // This trace trait for std::pair will null weak members if their referent is 841 // This trace trait for std::pair will null weak members if their referent is
908 // collected. If you have a collection that contain weakness it does not remove 842 // collected. If you have a collection that contain weakness it does not remove
909 // entries from the collection that contain nulled weak members. 843 // entries from the collection that contain nulled weak members.
910 template<typename T, typename U> 844 template<typename T, typename U>
911 class TraceTrait<std::pair<T, U> > { 845 class TraceTrait<std::pair<T, U> > {
912 public: 846 public:
913 static const bool firstNeedsTracing = WTF::NeedsTracing<T>::value || WTF::Is Weak<T>::value; 847 static const bool firstNeedsTracing = WTF::NeedsTracing<T>::value || WTF::Is Weak<T>::value;
914 static const bool secondNeedsTracing = WTF::NeedsTracing<U>::value || WTF::I sWeak<U>::value; 848 static const bool secondNeedsTracing = WTF::NeedsTracing<U>::value || WTF::I sWeak<U>::value;
915 static void trace(Visitor* visitor, std::pair<T, U>* pair) 849 static void trace(Visitor* visitor, std::pair<T, U>* pair)
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
1392 1326
1393 template<typename T> 1327 template<typename T>
1394 struct PointerParamStorageTraits<T*, true> { 1328 struct PointerParamStorageTraits<T*, true> {
1395 typedef blink::CrossThreadPersistent<T> StorageType; 1329 typedef blink::CrossThreadPersistent<T> StorageType;
1396 1330
1397 static StorageType wrap(T* value) { return value; } 1331 static StorageType wrap(T* value) { return value; }
1398 static T* unwrap(const StorageType& value) { return value.get(); } 1332 static T* unwrap(const StorageType& value) { return value.get(); }
1399 }; 1333 };
1400 1334
1401 template<typename T> 1335 template<typename T>
1402 struct ParamStorageTraits<T*> : public PointerParamStorageTraits<T*, blink::IsGa rbageCollectedType<T>::value> { 1336 struct ParamStorageTraits<T*> : public PointerParamStorageTraits<T*, false> {
1403 }; 1337 };
1404 1338
1405 template<typename T> 1339 template<typename T>
1406 struct ParamStorageTraits<RawPtr<T> > : public PointerParamStorageTraits<T*, bli nk::IsGarbageCollectedType<T>::value> { 1340 struct ParamStorageTraits<RawPtr<T> > : public PointerParamStorageTraits<T*, fal se> {
1407 }; 1341 };
1408 1342
1409 } // namespace WTF 1343 } // namespace WTF
1410 1344
1411 #endif 1345 #endif
OLDNEW
« no previous file with comments | « sky/engine/platform/TaskSynchronizer.cpp ('k') | sky/engine/platform/heap/Heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698