| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef TraceTraits_h | 5 #ifndef TraceTraits_h |
| 6 #define TraceTraits_h | 6 #define TraceTraits_h |
| 7 | 7 |
| 8 #include "platform/heap/GCInfo.h" | 8 #include "platform/heap/GCInfo.h" |
| 9 #include "platform/heap/Heap.h" | 9 #include "platform/heap/Heap.h" |
| 10 #include "platform/heap/InlinedGlobalMarkingVisitor.h" | 10 #include "platform/heap/InlinedGlobalMarkingVisitor.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 namespace blink { | 23 namespace blink { |
| 24 | 24 |
| 25 template<typename T> class CrossThreadPersistent; | 25 template<typename T> class CrossThreadPersistent; |
| 26 template<typename T> struct GCInfoTrait; | 26 template<typename T> struct GCInfoTrait; |
| 27 class HeapObjectHeader; | 27 class HeapObjectHeader; |
| 28 template<typename T> class Member; | 28 template<typename T> class Member; |
| 29 template<typename T> class TraceTrait; | 29 template<typename T> class TraceTrait; |
| 30 template<typename T> class WeakMember; | 30 template<typename T> class WeakMember; |
| 31 | 31 |
| 32 template<typename T, bool = NeedsAdjustAndMark<T>::value> class DefaultTraceTrai
t; | 32 template<typename T, bool = NeedsAdjustAndMark<T>::value> class AdjustAndMarkTra
it; |
| 33 | 33 |
| 34 template<typename T> | 34 template<typename T> |
| 35 class DefaultTraceTrait<T, false> { | 35 class AdjustAndMarkTrait<T, false> { |
| 36 public: | 36 public: |
| 37 template<typename VisitorDispatcher> | 37 template<typename VisitorDispatcher> |
| 38 static void mark(VisitorDispatcher visitor, const T* t) | 38 static void mark(VisitorDispatcher visitor, const T* t) |
| 39 { | 39 { |
| 40 #if ENABLE(ASSERT) | 40 #if ENABLE(ASSERT) |
| 41 assertObjectHasGCInfo(const_cast<T*>(t), GCInfoTrait<T>::index()); | 41 assertObjectHasGCInfo(const_cast<T*>(t), GCInfoTrait<T>::index()); |
| 42 #endif | 42 #endif |
| 43 // Default mark method of the trait just calls the two-argument mark | 43 // Default mark method of the trait just calls the two-argument mark |
| 44 // method on the visitor. The second argument is the static trace method | 44 // method on the visitor. The second argument is the static trace method |
| 45 // of the trait, which by default calls the instance method | 45 // of the trait, which by default calls the instance method |
| (...skipping 20 matching lines...) Expand all Loading... |
| 66 TraceTrait<T>::trace(visitor, const_cast<T*>(t)); | 66 TraceTrait<T>::trace(visitor, const_cast<T*>(t)); |
| 67 } | 67 } |
| 68 return; | 68 return; |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 visitor->mark(const_cast<T*>(t), &TraceTrait<T>::trace); | 71 visitor->mark(const_cast<T*>(t), &TraceTrait<T>::trace); |
| 72 } | 72 } |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 template<typename T> | 75 template<typename T> |
| 76 class DefaultTraceTrait<T, true> { | 76 class AdjustAndMarkTrait<T, true> { |
| 77 public: | 77 public: |
| 78 template<typename VisitorDispatcher> | 78 template<typename VisitorDispatcher> |
| 79 static void mark(VisitorDispatcher visitor, const T* self) | 79 static void mark(VisitorDispatcher visitor, const T* self) |
| 80 { | 80 { |
| 81 if (!self) | 81 if (!self) |
| 82 return; | 82 return; |
| 83 | 83 |
| 84 // If you hit this ASSERT, it means that there is a dangling pointer | 84 // If you hit this ASSERT, it means that there is a dangling pointer |
| 85 // from a live thread heap to a dead thread heap. We must eliminate | 85 // from a live thread heap to a dead thread heap. We must eliminate |
| 86 // the dangling pointer. | 86 // the dangling pointer. |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 // that case the pointer has to be adjusted before marking. | 141 // that case the pointer has to be adjusted before marking. |
| 142 template<typename T> | 142 template<typename T> |
| 143 class TraceTrait { | 143 class TraceTrait { |
| 144 public: | 144 public: |
| 145 static void trace(Visitor*, void* self); | 145 static void trace(Visitor*, void* self); |
| 146 static void trace(InlinedGlobalMarkingVisitor, void* self); | 146 static void trace(InlinedGlobalMarkingVisitor, void* self); |
| 147 | 147 |
| 148 template<typename VisitorDispatcher> | 148 template<typename VisitorDispatcher> |
| 149 static void mark(VisitorDispatcher visitor, const T* t) | 149 static void mark(VisitorDispatcher visitor, const T* t) |
| 150 { | 150 { |
| 151 DefaultTraceTrait<T>::mark(visitor, t); | 151 AdjustAndMarkTrait<T>::mark(visitor, t); |
| 152 } | 152 } |
| 153 }; | 153 }; |
| 154 | 154 |
| 155 template<typename T> class TraceTrait<const T> : public TraceTrait<T> { }; | 155 template<typename T> class TraceTrait<const T> : public TraceTrait<T> { }; |
| 156 | 156 |
| 157 template<typename T> | 157 template<typename T> |
| 158 void TraceTrait<T>::trace(Visitor* visitor, void* self) | 158 void TraceTrait<T>::trace(Visitor* visitor, void* self) |
| 159 { | 159 { |
| 160 if (visitor->isGlobalMarkingVisitor()) { | 160 if (visitor->isGlobalMarkingVisitor()) { |
| 161 // Switch to inlined global marking dispatch. | 161 // Switch to inlined global marking dispatch. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 179 static void trace(VisitorDispatcher visitor, void* self) | 179 static void trace(VisitorDispatcher visitor, void* self) |
| 180 { | 180 { |
| 181 static_assert(!WTF::IsWeak<T>::value, "weakness in HeapVectors and Deque
s are not supported"); | 181 static_assert(!WTF::IsWeak<T>::value, "weakness in HeapVectors and Deque
s are not supported"); |
| 182 if (WTF::ShouldBeTraced<Traits>::value) | 182 if (WTF::ShouldBeTraced<Traits>::value) |
| 183 WTF::TraceInCollectionTrait<WTF::NoWeakHandlingInCollections, WTF::W
eakPointersActWeak, HeapVectorBacking<T, Traits>, void>::trace(visitor, self); | 183 WTF::TraceInCollectionTrait<WTF::NoWeakHandlingInCollections, WTF::W
eakPointersActWeak, HeapVectorBacking<T, Traits>, void>::trace(visitor, self); |
| 184 } | 184 } |
| 185 | 185 |
| 186 template<typename VisitorDispatcher> | 186 template<typename VisitorDispatcher> |
| 187 static void mark(VisitorDispatcher visitor, const Backing* backing) | 187 static void mark(VisitorDispatcher visitor, const Backing* backing) |
| 188 { | 188 { |
| 189 DefaultTraceTrait<Backing>::mark(visitor, backing); | 189 AdjustAndMarkTrait<Backing>::mark(visitor, backing); |
| 190 } | 190 } |
| 191 }; | 191 }; |
| 192 | 192 |
| 193 // The trace trait for the heap hashtable backing is used when we find a | 193 // The trace trait for the heap hashtable backing is used when we find a |
| 194 // direct pointer to the backing from the conservative stack scanner. This | 194 // direct pointer to the backing from the conservative stack scanner. This |
| 195 // normally indicates that there is an ongoing iteration over the table, and so | 195 // normally indicates that there is an ongoing iteration over the table, and so |
| 196 // we disable weak processing of table entries. When the backing is found | 196 // we disable weak processing of table entries. When the backing is found |
| 197 // through the owning hash table we mark differently, in order to do weak | 197 // through the owning hash table we mark differently, in order to do weak |
| 198 // processing. | 198 // processing. |
| 199 template<typename Table> | 199 template<typename Table> |
| 200 struct TraceTrait<HeapHashTableBacking<Table>> { | 200 struct TraceTrait<HeapHashTableBacking<Table>> { |
| 201 using Backing = HeapHashTableBacking<Table>; | 201 using Backing = HeapHashTableBacking<Table>; |
| 202 using Traits = typename Table::ValueTraits; | 202 using Traits = typename Table::ValueTraits; |
| 203 | 203 |
| 204 template<typename VisitorDispatcher> | 204 template<typename VisitorDispatcher> |
| 205 static void trace(VisitorDispatcher visitor, void* self) | 205 static void trace(VisitorDispatcher visitor, void* self) |
| 206 { | 206 { |
| 207 if (WTF::ShouldBeTraced<Traits>::value || Traits::weakHandlingFlag == WT
F::WeakHandlingInCollections) | 207 if (WTF::ShouldBeTraced<Traits>::value || Traits::weakHandlingFlag == WT
F::WeakHandlingInCollections) |
| 208 WTF::TraceInCollectionTrait<WTF::NoWeakHandlingInCollections, WTF::W
eakPointersActStrong, Backing, void>::trace(visitor, self); | 208 WTF::TraceInCollectionTrait<WTF::NoWeakHandlingInCollections, WTF::W
eakPointersActStrong, Backing, void>::trace(visitor, self); |
| 209 } | 209 } |
| 210 | 210 |
| 211 template<typename VisitorDispatcher> | 211 template<typename VisitorDispatcher> |
| 212 static void mark(VisitorDispatcher visitor, const Backing* backing) | 212 static void mark(VisitorDispatcher visitor, const Backing* backing) |
| 213 { | 213 { |
| 214 DefaultTraceTrait<Backing>::mark(visitor, backing); | 214 AdjustAndMarkTrait<Backing>::mark(visitor, backing); |
| 215 } | 215 } |
| 216 }; | 216 }; |
| 217 | 217 |
| 218 // This trace trait for std::pair will null weak members if their referent is | 218 // This trace trait for std::pair will null weak members if their referent is |
| 219 // collected. If you have a collection that contain weakness it does not remove | 219 // collected. If you have a collection that contain weakness it does not remove |
| 220 // entries from the collection that contain nulled weak members. | 220 // entries from the collection that contain nulled weak members. |
| 221 template<typename T, typename U> | 221 template<typename T, typename U> |
| 222 class TraceTrait<std::pair<T, U>> { | 222 class TraceTrait<std::pair<T, U>> { |
| 223 public: | 223 public: |
| 224 static const bool firstNeedsTracing = WTF::NeedsTracing<T>::value || WTF::Is
Weak<T>::value; | 224 static const bool firstNeedsTracing = WTF::NeedsTracing<T>::value || WTF::Is
Weak<T>::value; |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 // since iterating over the hash table backing will find the whole | 541 // since iterating over the hash table backing will find the whole |
| 542 // chain. | 542 // chain. |
| 543 visitor->markNoTracing(node); | 543 visitor->markNoTracing(node); |
| 544 return false; | 544 return false; |
| 545 } | 545 } |
| 546 }; | 546 }; |
| 547 | 547 |
| 548 } // namespace WTF | 548 } // namespace WTF |
| 549 | 549 |
| 550 #endif | 550 #endif |
| OLD | NEW |