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

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

Issue 827723002: Reland: Templatize visitor arguments for TraceTrait mark and trace methods. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebased Created 5 years, 12 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 | « no previous file | Source/platform/heap/HeapTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/heap/Heap.h
diff --git a/Source/platform/heap/Heap.h b/Source/platform/heap/Heap.h
index d38311352861476dd2cdb577e0d8340b3976ad74..10187f5a50ddedfc1d89b8cf9455fe151d32fdd7 100644
--- a/Source/platform/heap/Heap.h
+++ b/Source/platform/heap/Heap.h
@@ -1462,25 +1462,29 @@ public:
return ThreadState::current()->isAllocationAllowed();
}
- static void markNoTracing(Visitor* visitor, const void* t) { visitor->markNoTracing(t); }
+ template<typename VisitorDispatcher>
+ static void markNoTracing(VisitorDispatcher visitor, const void* t) { visitor->markNoTracing(t); }
- template<typename T, typename Traits>
- static void trace(Visitor* visitor, T& t)
+ template<typename VisitorDispatcher, typename T, typename Traits>
+ static void trace(VisitorDispatcher visitor, T& t)
{
CollectionBackingTraceTrait<WTF::ShouldBeTraced<Traits>::value, Traits::weakHandlingFlag, WTF::WeakPointersActWeak, T, Traits>::trace(visitor, t);
}
- static void registerDelayedMarkNoTracing(Visitor* visitor, const void* object)
+ template<typename VisitorDispatcher>
+ static void registerDelayedMarkNoTracing(VisitorDispatcher visitor, const void* object)
{
visitor->registerDelayedMarkNoTracing(object);
}
- static void registerWeakMembers(Visitor* visitor, const void* closure, const void* object, WeakPointerCallback callback)
+ template<typename VisitorDispatcher>
+ static void registerWeakMembers(VisitorDispatcher visitor, const void* closure, const void* object, WeakPointerCallback callback)
{
visitor->registerWeakMembers(closure, object, callback);
}
- static void registerWeakTable(Visitor* visitor, const void* closure, EphemeronCallback iterationCallback, EphemeronCallback iterationDoneCallback)
+ template<typename VisitorDispatcher>
+ static void registerWeakTable(VisitorDispatcher visitor, const void* closure, EphemeronCallback iterationCallback, EphemeronCallback iterationDoneCallback)
{
visitor->registerWeakTable(closure, iterationCallback, iterationDoneCallback);
}
@@ -2037,7 +2041,8 @@ namespace WTF {
// weak elements.
template<ShouldWeakPointersBeMarkedStrongly strongify, typename T, typename Traits>
struct TraceInCollectionTrait<NoWeakHandlingInCollections, strongify, T, Traits> {
- static bool trace(blink::Visitor* visitor, T& t)
+ template<typename VisitorDispatcher>
+ static bool trace(VisitorDispatcher visitor, T& t)
{
blink::TraceTrait<T>::trace(visitor, &t);
return false;
@@ -2046,7 +2051,8 @@ struct TraceInCollectionTrait<NoWeakHandlingInCollections, strongify, T, Traits>
template<ShouldWeakPointersBeMarkedStrongly strongify, typename T, typename Traits>
struct TraceInCollectionTrait<NoWeakHandlingInCollections, strongify, blink::Member<T>, Traits> {
- static bool trace(blink::Visitor* visitor, blink::Member<T>& t)
+ template<typename VisitorDispatcher>
+ static bool trace(VisitorDispatcher visitor, blink::Member<T>& t)
{
blink::TraceTrait<T>::mark(visitor, const_cast<typename RemoveConst<T>::Type*>(t.get()));
return false;
@@ -2056,7 +2062,8 @@ struct TraceInCollectionTrait<NoWeakHandlingInCollections, strongify, blink::Mem
// Catch-all for things that have HashTrait support for tracing with weakness.
template<ShouldWeakPointersBeMarkedStrongly strongify, typename T, typename Traits>
struct TraceInCollectionTrait<WeakHandlingInCollections, strongify, T, Traits> {
- static bool trace(blink::Visitor* visitor, T& t)
+ template<typename VisitorDispatcher>
+ static bool trace(VisitorDispatcher visitor, T& t)
{
return Traits::traceInCollection(visitor, t, strongify);
}
@@ -2065,7 +2072,8 @@ struct TraceInCollectionTrait<WeakHandlingInCollections, strongify, T, Traits> {
// Vector backing that needs marking. We don't support weak members in vectors.
template<ShouldWeakPointersBeMarkedStrongly strongify, typename T, typename Traits>
struct TraceInCollectionTrait<NoWeakHandlingInCollections, strongify, blink::HeapVectorBacking<T, Traits>, void> {
- static bool trace(blink::Visitor* visitor, void* self)
+ template<typename VisitorDispatcher>
+ static bool trace(VisitorDispatcher visitor, void* self)
{
// The allocator can oversize the allocation a little, according to
// the allocation granularity. The extra size is included in the
@@ -2090,7 +2098,9 @@ template<ShouldWeakPointersBeMarkedStrongly strongify, typename Table>
struct TraceInCollectionTrait<NoWeakHandlingInCollections, strongify, blink::HeapHashTableBacking<Table>, void> {
using Value = typename Table::ValueType;
using Traits = typename Table::ValueTraits;
- static bool trace(blink::Visitor* visitor, void* self)
+
+ template<typename VisitorDispatcher>
+ static bool trace(VisitorDispatcher visitor, void* self)
{
Value* array = reinterpret_cast<Value*>(self);
blink::HeapObjectHeader* header = blink::HeapObjectHeader::fromPayload(self);
@@ -2112,7 +2122,9 @@ template<ShouldWeakPointersBeMarkedStrongly strongify, typename NodeContents, si
struct TraceInCollectionTrait<NoWeakHandlingInCollections, strongify, blink::HeapHashTableBacking<HashTable<ListHashSetNode<NodeContents, blink::HeapListHashSetAllocator<T, inlineCapacity>>*, U, V, W, X, Y, blink::HeapAllocator>>, void> {
using Node = ListHashSetNode<NodeContents, blink::HeapListHashSetAllocator<T, inlineCapacity>>;
using Table = HashTable<Node*, U, V, W, X, Y, blink::HeapAllocator>;
- static bool trace(blink::Visitor* visitor, void* self)
+
+ template<typename VisitorDispatcher>
+ static bool trace(VisitorDispatcher visitor, void* self)
{
Node** array = reinterpret_cast<Node**>(self);
blink::HeapObjectHeader* header = blink::HeapObjectHeader::fromPayload(self);
@@ -2136,7 +2148,8 @@ struct TraceInCollectionTrait<NoWeakHandlingInCollections, strongify, blink::Hea
// one with weak handling.
template<ShouldWeakPointersBeMarkedStrongly strongify, typename Key, typename Value, typename Traits>
struct TraceInCollectionTrait<NoWeakHandlingInCollections, strongify, KeyValuePair<Key, Value>, Traits> {
- static bool trace(blink::Visitor* visitor, KeyValuePair<Key, Value>& self)
+ template<typename VisitorDispatcher>
+ static bool trace(VisitorDispatcher visitor, KeyValuePair<Key, Value>& self)
{
ASSERT(ShouldBeTraced<Traits>::value);
blink::CollectionBackingTraceTrait<ShouldBeTraced<typename Traits::KeyTraits>::value, NoWeakHandlingInCollections, strongify, Key, typename Traits::KeyTraits>::trace(visitor, self.key);
@@ -2147,7 +2160,8 @@ struct TraceInCollectionTrait<NoWeakHandlingInCollections, strongify, KeyValuePa
template<ShouldWeakPointersBeMarkedStrongly strongify, typename Key, typename Value, typename Traits>
struct TraceInCollectionTrait<WeakHandlingInCollections, strongify, KeyValuePair<Key, Value>, Traits> {
- static bool trace(blink::Visitor* visitor, KeyValuePair<Key, Value>& self)
+ template<typename VisitorDispatcher>
+ static bool trace(VisitorDispatcher visitor, KeyValuePair<Key, Value>& self)
{
// This is the core of the ephemeron-like functionality. If there is
// weakness on the key side then we first check whether there are
@@ -2188,7 +2202,8 @@ struct TraceInCollectionTrait<WeakHandlingInCollections, strongify, KeyValuePair
// template.
template<ShouldWeakPointersBeMarkedStrongly strongify, typename Value, typename Allocator, typename Traits>
struct TraceInCollectionTrait<NoWeakHandlingInCollections, strongify, LinkedHashSetNode<Value, Allocator>, Traits> {
- static bool trace(blink::Visitor* visitor, LinkedHashSetNode<Value, Allocator>& self)
+ template<typename VisitorDispatcher>
+ static bool trace(VisitorDispatcher visitor, LinkedHashSetNode<Value, Allocator>& self)
{
ASSERT(ShouldBeTraced<Traits>::value);
return TraceInCollectionTrait<NoWeakHandlingInCollections, strongify, Value, typename Traits::ValueTraits>::trace(visitor, self.m_value);
@@ -2197,7 +2212,8 @@ struct TraceInCollectionTrait<NoWeakHandlingInCollections, strongify, LinkedHash
template<ShouldWeakPointersBeMarkedStrongly strongify, typename Value, typename Allocator, typename Traits>
struct TraceInCollectionTrait<WeakHandlingInCollections, strongify, LinkedHashSetNode<Value, Allocator>, Traits> {
- static bool trace(blink::Visitor* visitor, LinkedHashSetNode<Value, Allocator>& self)
+ template<typename VisitorDispatcher>
+ static bool trace(VisitorDispatcher visitor, LinkedHashSetNode<Value, Allocator>& self)
{
return TraceInCollectionTrait<WeakHandlingInCollections, strongify, Value, typename Traits::ValueTraits>::trace(visitor, self.m_value);
}
@@ -2208,7 +2224,9 @@ struct TraceInCollectionTrait<WeakHandlingInCollections, strongify, LinkedHashSe
template<ShouldWeakPointersBeMarkedStrongly strongify, typename Value, size_t inlineCapacity, typename Traits>
struct TraceInCollectionTrait<NoWeakHandlingInCollections, strongify, ListHashSetNode<Value, blink::HeapListHashSetAllocator<Value, inlineCapacity>>*, Traits> {
using Node = ListHashSetNode<Value, blink::HeapListHashSetAllocator<Value, inlineCapacity>>;
- static bool trace(blink::Visitor* visitor, Node* node)
+
+ template<typename VisitorDispatcher>
+ static bool trace(VisitorDispatcher visitor, Node* node)
{
traceListHashSetValue(visitor, node->m_value);
// Just mark the node without tracing because we already traced the
@@ -2231,7 +2249,8 @@ namespace blink {
// We do nothing, even if WTF::WeakPointersActStrong.
template<WTF::ShouldWeakPointersBeMarkedStrongly strongify, typename T, typename Traits>
struct CollectionBackingTraceTrait<false, WTF::NoWeakHandlingInCollections, strongify, T, Traits> {
- static bool trace(Visitor*, T&) { return false; }
+ template<typename VisitorDispatcher>
+ static bool trace(VisitorDispatcher, T&) { return false; }
};
template<typename T>
@@ -2249,7 +2268,8 @@ static void verifyGarbageCollectedIfMember(Member<T>* t)
// both.
template<bool needsTracing, WTF::WeakHandlingFlag weakHandlingFlag, WTF::ShouldWeakPointersBeMarkedStrongly strongify, typename T, typename Traits>
struct CollectionBackingTraceTrait {
- static bool trace(Visitor* visitor, T&t)
+ template<typename VisitorDispatcher>
+ static bool trace(VisitorDispatcher visitor, T&t)
{
verifyGarbageCollectedIfMember(reinterpret_cast<T*>(0));
return WTF::TraceInCollectionTrait<weakHandlingFlag, strongify, T, Traits>::trace(visitor, t);
@@ -2276,7 +2296,8 @@ template<typename T> struct WeakHandlingHashTraits : WTF::SimpleClassHashTraits<
// suddenly disappear during iteration. Returns true if weak pointers to
// dead objects were found: In this case any strong pointers were not yet
// traced and the entry should be removed from the collection.
- static bool traceInCollection(Visitor* visitor, T& t, WTF::ShouldWeakPointersBeMarkedStrongly strongify)
+ template<typename VisitorDispatcher>
+ static bool traceInCollection(VisitorDispatcher visitor, T& t, WTF::ShouldWeakPointersBeMarkedStrongly strongify)
{
return t.traceInCollection(visitor, strongify);
}
@@ -2285,13 +2306,17 @@ template<typename T> struct WeakHandlingHashTraits : WTF::SimpleClassHashTraits<
template<typename T, typename Traits>
struct TraceTrait<HeapVectorBacking<T, Traits>> {
using Backing = HeapVectorBacking<T, Traits>;
- static void trace(Visitor* visitor, void* self)
+
+ template<typename VisitorDispatcher>
+ static void trace(VisitorDispatcher visitor, void* self)
{
static_assert(!WTF::IsWeak<T>::value, "weakness in HeapVectors and Deques are not supported");
if (WTF::ShouldBeTraced<Traits>::value)
WTF::TraceInCollectionTrait<WTF::NoWeakHandlingInCollections, WTF::WeakPointersActWeak, HeapVectorBacking<T, Traits>, void>::trace(visitor, self);
}
- static void mark(Visitor* visitor, const Backing* backing)
+
+ template<typename VisitorDispatcher>
+ static void mark(VisitorDispatcher visitor, const Backing* backing)
{
visitor->mark(backing, &trace);
}
@@ -2313,12 +2338,16 @@ template<typename Table>
struct TraceTrait<HeapHashTableBacking<Table>> {
using Backing = HeapHashTableBacking<Table>;
using Traits = typename Table::ValueTraits;
- static void trace(Visitor* visitor, void* self)
+
+ template<typename VisitorDispatcher>
+ static void trace(VisitorDispatcher visitor, void* self)
{
if (WTF::ShouldBeTraced<Traits>::value || Traits::weakHandlingFlag == WTF::WeakHandlingInCollections)
WTF::TraceInCollectionTrait<WTF::NoWeakHandlingInCollections, WTF::WeakPointersActStrong, Backing, void>::trace(visitor, self);
}
- static void mark(Visitor* visitor, const Backing* backing)
+
+ template<typename VisitorDispatcher>
+ static void mark(VisitorDispatcher visitor, const Backing* backing)
{
if (WTF::ShouldBeTraced<Traits>::value || Traits::weakHandlingFlag == WTF::WeakHandlingInCollections)
visitor->mark(backing, &trace);
« no previous file with comments | « no previous file | Source/platform/heap/HeapTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698