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

Unified Diff: Source/platform/heap/Visitor.h

Issue 319593004: Oilpan:Allow custom handling of classes that contain weak pointers that are embedded in collections. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Remove 'typename' that Win compiler does not like Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/platform/heap/HeapTest.cpp ('k') | Source/wtf/HashTable.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/heap/Visitor.h
diff --git a/Source/platform/heap/Visitor.h b/Source/platform/heap/Visitor.h
index 2195a5d925ab47c979963fd89ea03349a9d0d40b..15ec4047efd05d7e9dfec7f2ff92904d096cca11 100644
--- a/Source/platform/heap/Visitor.h
+++ b/Source/platform/heap/Visitor.h
@@ -71,7 +71,7 @@ enum ShouldWeakPointersBeMarkedStrongly {
WeakPointersActWeak
};
-template<bool needsTracing, bool isWeak, ShouldWeakPointersBeMarkedStrongly strongify, typename T, typename Traits> struct CollectionBackingTraceTrait;
+template<bool needsTracing, WTF::WeakHandlingFlag weakHandlingFlag, ShouldWeakPointersBeMarkedStrongly strongify, typename T, typename Traits> struct CollectionBackingTraceTrait;
// The TraceMethodDelegate is used to convert a trace method for type T to a TraceCallback.
// This allows us to pass a type's trace method as a parameter to the PersistentNode
@@ -239,6 +239,12 @@ public:
// 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 +252,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.
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 +284,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>
@@ -468,10 +488,12 @@ 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::weakHandlingFlag, WeakPointersActWeak, T, Traits>::trace(visitor, const_cast<T&>(t));
+ }
}
- COMPILE_ASSERT(!Traits::isWeak, WeakOffHeapCollectionsConsideredDangerous0);
+ COMPILE_ASSERT(Traits::weakHandlingFlag == WTF::NoWeakHandlingInCollections, WeakOffHeapCollectionsConsideredDangerous0);
}
};
@@ -514,12 +536,12 @@ struct OffHeapCollectionTraceTrait<WTF::HashMap<Key, Value, HashFunctions, KeyTr
if (WTF::ShouldBeTraced<KeyTraits>::value || WTF::ShouldBeTraced<ValueTraits>::value) {
HashMap& iterMap = const_cast<HashMap&>(map);
for (typename HashMap::iterator it = iterMap.begin(), end = iterMap.end(); it != end; ++it) {
- CollectionBackingTraceTrait<WTF::ShouldBeTraced<KeyTraits>::value, KeyTraits::isWeak, WeakPointersActWeak, typename HashMap::KeyType, KeyTraits>::trace(visitor, it->key);
- CollectionBackingTraceTrait<WTF::ShouldBeTraced<ValueTraits>::value, ValueTraits::isWeak, WeakPointersActWeak, typename HashMap::MappedType, ValueTraits>::trace(visitor, it->value);
+ CollectionBackingTraceTrait<WTF::ShouldBeTraced<KeyTraits>::value, KeyTraits::weakHandlingFlag, WeakPointersActWeak, typename HashMap::KeyType, KeyTraits>::trace(visitor, it->key);
+ CollectionBackingTraceTrait<WTF::ShouldBeTraced<ValueTraits>::value, ValueTraits::weakHandlingFlag, WeakPointersActWeak, typename HashMap::MappedType, ValueTraits>::trace(visitor, it->value);
}
}
- COMPILE_ASSERT(!KeyTraits::isWeak, WeakOffHeapCollectionsConsideredDangerous1);
- COMPILE_ASSERT(!ValueTraits::isWeak, WeakOffHeapCollectionsConsideredDangerous2);
+ COMPILE_ASSERT(KeyTraits::weakHandlingFlag == WTF::NoWeakHandlingInCollections, WeakOffHeapCollectionsConsideredDangerous1);
+ COMPILE_ASSERT(ValueTraits::weakHandlingFlag == WTF::NoWeakHandlingInCollections, WeakOffHeapCollectionsConsideredDangerous2);
}
};
« no previous file with comments | « Source/platform/heap/HeapTest.cpp ('k') | Source/wtf/HashTable.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698