Chromium Code Reviews| Index: Source/platform/heap/Visitor.h |
| diff --git a/Source/platform/heap/Visitor.h b/Source/platform/heap/Visitor.h |
| index 2195a5d925ab47c979963fd89ea03349a9d0d40b..cac9c51e379142141c7fbc57ef931ae032976362 100644 |
| --- a/Source/platform/heap/Visitor.h |
| +++ b/Source/platform/heap/Visitor.h |
| @@ -236,9 +236,22 @@ public: |
| mark(t.get()); |
| } |
| + template<typename T> |
| + void trace(Member<T>& t) |
|
haraken
2014/06/06 08:03:02
Just help me understand: Why do we have both const
Erik Corry
2014/06/06 08:47:35
We have to have a const and non-const version for
|
| + { |
| + t.verifyTypeIsGarbageCollected(); |
| + mark(t.get()); |
| + } |
| + |
| // Fallback method used only when we need to trace raw pointers of T. |
| // This is the case when a member is a union where we do not support members. |
| template<typename T> |
| + void trace(const T* t) |
| + { |
| + mark(const_cast<T*>(t)); |
| + } |
| + |
| + template<typename T> |
| void trace(T* t) |
| { |
| mark(t); |
| @@ -246,16 +259,30 @@ public: |
| // WeakMember version of the templated trace method. It doesn't keep |
| // the traced thing alive, but will write null to the WeakMember later |
| - // if the pointed-to object is dead. |
| + // if the pointed-to object is dead. It's lying for this to be const, |
| + // but the overloading resolver prioritizes constness too high when |
| + // picking the correct overload, so all these trace methods have to have |
| + // the same constness on their argument to allow the type to decide. |
|
haraken
2014/06/06 08:03:02
I agree that we need a const version of trace(cons
Erik Corry
2014/06/06 08:47:35
If you have only const methods to choose between t
|
| template<typename T> |
| void trace(const WeakMember<T>& t) |
| { |
| - registerWeakCell(t.cell()); |
| + registerWeakCell(const_cast<WeakMember<T>&>(t).cell()); |
| } |
| - // Fallback trace method for part objects to allow individual |
| - // trace methods to trace through a part object with |
| - // visitor->trace(m_partObject). |
| + template<typename T> |
| + void traceInCollection(T& t, ShouldWeakPointersBeMarkedStrongly strongify) |
| + { |
| + HashTraits<T>::traceInCollection(this, t, strongify); |
| + } |
| + |
| + // Fallback trace method for part objects to allow individual trace methods |
| + // to trace through a part object with visitor->trace(m_partObject). This |
| + // takes a const argument, because otherwise it will match too eagerly: a |
| + // non-const argument would match a non-const Vector<T>& argument better |
| + // than the specialization that takes const Vector<T>&. For a similar reason, |
| + // the other specializations take a const argument even though they are |
| + // usually used with non-const arguments, otherwise this function would match |
| + // too well. |
| template<typename T> |
| void trace(const T& t) |
| { |
| @@ -264,15 +291,15 @@ public: |
| // The following trace methods are for off-heap collections. |
| template<typename T, size_t inlineCapacity> |
| - void trace(const Vector<T, inlineCapacity, WTF::DefaultAllocator>& vector) |
| + void trace(const Vector<T, inlineCapacity>& vector) |
| { |
| OffHeapCollectionTraceTrait<Vector<T, inlineCapacity, WTF::DefaultAllocator> >::trace(this, vector); |
| } |
| template<typename T, typename U, typename V> |
| - void trace(const HashSet<T, U, V, WTF::DefaultAllocator>& hashSet) |
| + void trace(const HashSet<T, U, V>& hashSet) |
| { |
| - OffHeapCollectionTraceTrait<HashSet<T, U, V, WTF::DefaultAllocator> >::trace(this, hashSet); |
| + OffHeapCollectionTraceTrait<HashSet<T, U, V> >::trace(this, hashSet); |
| } |
| template<typename T, size_t inlineCapacity, typename U> |
| @@ -348,6 +375,15 @@ public: |
| #endif |
| } |
| + template<typename T> |
| + void trace(WeakPtr<T>&) |
| + { |
| +#if ENABLE(OILPAN) |
| + // WeakPtrs should never be traced. |
| + ASSERT_NOT_REACHED(); |
| +#endif |
| + } |
| + |
| // This method marks an object and adds it to the set of objects |
| // that should have their trace method called. Since not all |
| // objects have vtables we have to have the callback as an |
| @@ -468,8 +504,10 @@ struct OffHeapCollectionTraceTrait<WTF::HashSet<T, HashFunctions, Traits, WTF::D |
| return; |
| if (WTF::ShouldBeTraced<Traits>::value) { |
| HashSet& iterSet = const_cast<HashSet&>(set); |
| - for (typename HashSet::iterator it = iterSet.begin(), end = iterSet.end(); it != end; ++it) |
| - CollectionBackingTraceTrait<WTF::ShouldBeTraced<Traits>::value, Traits::isWeak, WeakPointersActWeak, T, Traits>::trace(visitor, *it); |
| + for (typename HashSet::iterator it = iterSet.begin(), end = iterSet.end(); it != end; ++it) { |
| + const T& t = *it; |
| + CollectionBackingTraceTrait<WTF::ShouldBeTraced<Traits>::value, Traits::isWeak, WeakPointersActWeak, T, Traits>::trace(visitor, const_cast<T&>(t)); |
| + } |
| } |
| COMPILE_ASSERT(!Traits::isWeak, WeakOffHeapCollectionsConsideredDangerous0); |
| } |