提交 e4fe5cfb 编写于 作者: E Eric Seidel

Hollow out more of the tracing system in oilpan

The goal here was to delete all the oilpan
conversion types and then as well all the calls
into trace().  In the process of attempting
to get it compiling I removed some trace()
calls from the font system before finding the
one stray trace() call I had missed in handle
causing the link errors.

TBR=abarth@chromium.org

Review URL: https://codereview.chromium.org/679113005
上级 64b5cb61
......@@ -51,11 +51,6 @@ public:
return (m_isNull && other.m_isNull) || (!m_isNull && !other.m_isNull && m_value == other.m_value);
}
void trace(Visitor* visitor)
{
TraceIfNeeded<T>::trace(visitor, &m_value);
}
private:
T m_value;
bool m_isNull;
......
......@@ -68,8 +68,6 @@ public:
// This method keeps the holder object and the property name.
void reset();
virtual void trace(Visitor*) override;
private:
virtual v8::Handle<v8::Object> holder(v8::Handle<v8::Object> creationContext, v8::Isolate*) override;
virtual v8::Handle<v8::Value> resolvedValue(v8::Handle<v8::Object> creationContext, v8::Isolate*) override;
......@@ -145,15 +143,6 @@ void ScriptPromiseProperty<HolderType, ResolvedType, RejectedType>::reset()
m_rejected = RejectedType();
}
template<typename HolderType, typename ResolvedType, typename RejectedType>
void ScriptPromiseProperty<HolderType, ResolvedType, RejectedType>::trace(Visitor* visitor)
{
TraceIfNeeded<HolderType>::trace(visitor, &m_holder);
TraceIfNeeded<ResolvedType>::trace(visitor, &m_resolved);
TraceIfNeeded<RejectedType>::trace(visitor, &m_rejected);
ScriptPromisePropertyBase::trace(visitor);
}
} // namespace blink
#endif // ScriptPromiseProperty_h
......@@ -39,8 +39,6 @@ public:
ScriptPromise promise(DOMWrapperWorld&);
virtual void trace(Visitor*) { }
protected:
ScriptPromisePropertyBase(ExecutionContext*, Name);
......
......@@ -607,39 +607,6 @@ struct NativeValueTraits<ScriptValue> {
v8::Handle<v8::Value> toV8Sequence(v8::Handle<v8::Value>, uint32_t& length, v8::Isolate*);
template <class T, class V8T>
HeapVector<Member<T> > toMemberNativeArray(v8::Handle<v8::Value> value, int argumentIndex, v8::Isolate* isolate, bool* success = 0)
{
if (success)
*success = true;
v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value));
uint32_t length = 0;
if (value->IsArray()) {
length = v8::Local<v8::Array>::Cast(v8Value)->Length();
} else if (toV8Sequence(value, length, isolate).IsEmpty()) {
V8ThrowException::throwTypeError(ExceptionMessages::notAnArrayTypeArgumentOrValue(argumentIndex), isolate);
return HeapVector<Member<T> >();
}
HeapVector<Member<T> > result;
result.reserveInitialCapacity(length);
v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value);
for (uint32_t i = 0; i < length; ++i) {
v8::Handle<v8::Value> element = object->Get(i);
if (V8T::hasInstance(element, isolate)) {
v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast(element);
result.uncheckedAppend(V8T::toNative(elementObject));
} else {
if (success)
*success = false;
V8ThrowException::throwTypeError("Invalid Array element type", isolate);
return HeapVector<Member<T> >();
}
}
return result;
}
// Converts a JavaScript value to an array as per the Web IDL specification:
// http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array
template <class T>
......
......@@ -549,21 +549,6 @@ void FontFace::initCSSFontFace(const unsigned char* data, unsigned size)
m_cssFontFace->addSource(source.release());
}
void FontFace::trace(Visitor* visitor)
{
visitor->trace(m_src);
visitor->trace(m_style);
visitor->trace(m_weight);
visitor->trace(m_stretch);
visitor->trace(m_unicodeRange);
visitor->trace(m_variant);
visitor->trace(m_featureSettings);
visitor->trace(m_error);
visitor->trace(m_loadedProperty);
visitor->trace(m_cssFontFace);
visitor->trace(m_callbacks);
}
bool FontFace::hadBlankText() const
{
return m_cssFontFace->hadBlankText();
......
......@@ -94,8 +94,6 @@ public:
FontTraits traits() const;
CSSFontFace* cssFontFace() { return m_cssFontFace.get(); }
void trace(Visitor*);
bool hadBlankText() const;
class LoadFontCallback : public RefCounted<LoadFontCallback> {
......@@ -103,7 +101,6 @@ public:
virtual ~LoadFontCallback() { }
virtual void notifyLoaded(FontFace*) = 0;
virtual void notifyError(FontFace*) = 0;
virtual void trace(Visitor*) { }
};
void loadWithCallback(PassRefPtr<LoadFontCallback>, ExecutionContext*);
......
......@@ -62,8 +62,6 @@ public:
virtual void notifyLoaded(FontFace*) override;
virtual void notifyError(FontFace*) override;
virtual void trace(Visitor*) override;
private:
LoadFontPromiseResolver(FontFaceArray faces, ScriptState* scriptState)
: m_numLoading(faces.size())
......@@ -108,12 +106,6 @@ void LoadFontPromiseResolver::notifyError(FontFace* fontFace)
}
}
void LoadFontPromiseResolver::trace(Visitor* visitor)
{
visitor->trace(m_fontFaces);
LoadFontCallback::trace(visitor);
}
class FontsReadyPromiseResolver {
public:
static PassOwnPtr<FontsReadyPromiseResolver> create(ScriptState* scriptState)
......@@ -588,16 +580,4 @@ void FontFaceSet::didLayout(Document& document)
fonts->didLayout();
}
#if ENABLE(OILPAN)
void FontFaceSet::trace(Visitor* visitor)
{
visitor->trace(m_loadingFonts);
visitor->trace(m_loadedFonts);
visitor->trace(m_failedFonts);
visitor->trace(m_nonCSSConnectedFaces);
DocumentSupplement::trace(visitor);
EventTargetWithInlineData::trace(visitor);
}
#endif
} // namespace blink
......@@ -104,10 +104,6 @@ public:
void addFontFacesToFontFaceCache(FontFaceCache*, CSSFontSelector*);
#if ENABLE(OILPAN)
virtual void trace(Visitor*) override;
#endif
private:
static PassRefPtr<FontFaceSet> create(Document& document)
{
......
......@@ -577,7 +577,6 @@ protected:
T* m_raw;
template<bool x, WTF::WeakHandlingFlag y, WTF::ShouldWeakPointersBeMarkedStrongly z, typename U, typename V> friend struct CollectionBackingTraceTrait;
friend class Visitor;
};
......@@ -610,45 +609,18 @@ public:
}
};
template<typename T, bool needsTracing>
struct TraceIfEnabled;
template<typename T>
struct TraceIfEnabled<T, false> {
static void trace(Visitor*, T*) { }
};
template<typename T>
struct TraceIfEnabled<T, true> {
static void trace(Visitor* visitor, T* t)
{
visitor->trace(*t);
}
};
template <typename T> struct RemoveHeapPointerWrapperTypes {
typedef typename WTF::RemoveTemplate<typename WTF::RemoveTemplate<typename WTF::RemoveTemplate<T, Member>::Type, WeakMember>::Type, RawPtr>::Type Type;
};
// FIXME: Oilpan: TraceIfNeeded should be implemented ala:
// NeedsTracing<T>::value || IsWeakMember<T>::value. It should not need to test
// raw pointer types. To remove these tests, we may need support for
// instantiating a template with a RawPtrOrMember'ish template.
template<typename T>
struct TraceIfNeeded : public TraceIfEnabled<T, false> { };
// This trace trait for std::pair will null weak members if their referent is
// collected. If you have a collection that contain weakness it does not remove
// entries from the collection that contain nulled weak members.
template<typename T, typename U>
class TraceTrait<std::pair<T, U> > {
public:
static const bool firstNeedsTracing = WTF::NeedsTracing<T>::value || WTF::IsWeak<T>::value;
static const bool secondNeedsTracing = WTF::NeedsTracing<U>::value || WTF::IsWeak<U>::value;
static void trace(Visitor* visitor, std::pair<T, U>* pair)
{
TraceIfEnabled<T, firstNeedsTracing>::trace(visitor, &pair->first);
TraceIfEnabled<U, secondNeedsTracing>::trace(visitor, &pair->second);
}
};
......@@ -727,125 +699,6 @@ template<typename T, typename U> inline bool operator!=(const Persistent<T>& a,
template<typename T, typename U> inline bool operator==(const Persistent<T>& a, const Persistent<U>& b) { return a.get() == b.get(); }
template<typename T, typename U> inline bool operator!=(const Persistent<T>& a, const Persistent<U>& b) { return a.get() != b.get(); }
// CPP-defined type names for the transition period where we want to
// support both reference counting and garbage collection based on a
// compile-time flag.
//
// C++11 template aliases were initially used (with clang only, not
// with GCC nor MSVC.) However, supporting both CPP defines and
// template aliases is problematic from outside a WebCore namespace
// when Oilpan is disabled: e.g.,
// blink::RefCountedWillBeGarbageCollected as a template alias would
// uniquely resolve from within any namespace, but if it is backed by
// a CPP #define, it would expand to blink::RefCounted, and not the
// required WTF::RefCounted.
//
// Having the CPP expansion instead be fully namespace qualified, and the
// transition type be unqualified, would dually not work for template
// aliases. So, slightly unfortunately, fall back/down to the lowest
// commmon denominator of using CPP macros only.
#if ENABLE(OILPAN)
#define PassRefPtrWillBeRawPtr WTF::RawPtr
#define RefCountedWillBeGarbageCollected blink::GarbageCollected
#define RefCountedWillBeGarbageCollectedFinalized blink::GarbageCollectedFinalized
#define RefCountedWillBeRefCountedGarbageCollected blink::RefCountedGarbageCollected
#define RefCountedGarbageCollectedWillBeGarbageCollectedFinalized blink::GarbageCollectedFinalized
#define ThreadSafeRefCountedWillBeGarbageCollected blink::GarbageCollected
#define ThreadSafeRefCountedWillBeGarbageCollectedFinalized blink::GarbageCollectedFinalized
#define ThreadSafeRefCountedWillBeThreadSafeRefCountedGarbageCollected blink::ThreadSafeRefCountedGarbageCollected
#define PersistentWillBeMember blink::Member
#define RefPtrWillBePersistent blink::Persistent
#define RefPtrWillBeRawPtr WTF::RawPtr
#define RefPtrWillBeMember blink::Member
#define RefPtrWillBeWeakMember blink::WeakMember
#define RefPtrWillBeCrossThreadPersistent blink::CrossThreadPersistent
#define RawPtrWillBeMember blink::Member
#define RawPtrWillBePersistent blink::Persistent
#define RawPtrWillBeWeakMember blink::WeakMember
#define OwnPtrWillBeMember blink::Member
#define OwnPtrWillBePersistent blink::Persistent
#define OwnPtrWillBeRawPtr WTF::RawPtr
#define PassOwnPtrWillBeRawPtr WTF::RawPtr
#define WeakPtrWillBeMember blink::Member
#define WeakPtrWillBeRawPtr WTF::RawPtr
#define WeakPtrWillBeMember blink::Member
#define WeakPtrWillBeWeakMember blink::WeakMember
#define NoBaseWillBeGarbageCollected blink::GarbageCollected
#define NoBaseWillBeGarbageCollectedFinalized blink::GarbageCollectedFinalized
#define NoBaseWillBeRefCountedGarbageCollected blink::RefCountedGarbageCollected
#define WillBeHeapHashMap blink::HeapHashMap
#define WillBePersistentHeapHashMap blink::PersistentHeapHashMap
#define WillBeHeapHashSet blink::HeapHashSet
#define WillBePersistentHeapHashSet blink::PersistentHeapHashSet
#define WillBeHeapLinkedHashSet blink::HeapLinkedHashSet
#define WillBePersistentHeapLinkedHashSet blink::PersistentHeapLinkedHashSet
#define WillBeHeapListHashSet blink::HeapListHashSet
#define WillBePersistentHeapListHashSet blink::PersistentHeapListHashSet
#define WillBeHeapVector blink::HeapVector
#define WillBePersistentHeapVector blink::PersistentHeapVector
#define WillBeHeapDeque blink::HeapDeque
#define WillBePersistentHeapDeque blink::PersistentHeapDeque
#define WillBeHeapHashCountedSet blink::HeapHashCountedSet
#define WillBePersistentHeapHashCountedSet blink::PersistentHeapHashCountedSet
#define WillBeGarbageCollectedMixin blink::GarbageCollectedMixin
#define WillBeHeapSupplement blink::HeapSupplement
#define WillBeHeapSupplementable blink::HeapSupplementable
#define WillBePersistentHeapSupplementable blink::PersistentHeapSupplementable
#define WillBeHeapTerminatedArray blink::HeapTerminatedArray
#define WillBeHeapTerminatedArrayBuilder blink::HeapTerminatedArrayBuilder
#define WillBeHeapLinkedStack blink::HeapLinkedStack
#define PersistentHeapHashSetWillBeHeapHashSet blink::HeapHashSet
#define PersistentHeapDequeWillBeHeapDeque blink::HeapDeque
#define PersistentHeapVectorWillBeHeapVector blink::HeapVector
template<typename T> PassRefPtrWillBeRawPtr<T> adoptRefWillBeNoop(T* ptr)
{
static const bool notRefCountedGarbageCollected = !WTF::IsSubclassOfTemplate<typename WTF::RemoveConst<T>::Type, RefCountedGarbageCollected>::value;
static const bool notRefCounted = !WTF::IsSubclassOfTemplate<typename WTF::RemoveConst<T>::Type, RefCounted>::value;
COMPILE_ASSERT(notRefCountedGarbageCollected, useAdoptRefCountedWillBeRefCountedGarbageCollected);
COMPILE_ASSERT(notRefCounted, youMustAdopt);
return PassRefPtrWillBeRawPtr<T>(ptr);
}
template<typename T> PassRefPtrWillBeRawPtr<T> adoptRefWillBeRefCountedGarbageCollected(T* ptr)
{
static const bool isRefCountedGarbageCollected = WTF::IsSubclassOfTemplate<typename WTF::RemoveConst<T>::Type, RefCountedGarbageCollected>::value;
COMPILE_ASSERT(isRefCountedGarbageCollected, useAdoptRefWillBeNoop);
return PassRefPtrWillBeRawPtr<T>(adoptRefCountedGarbageCollected(ptr));
}
template<typename T> PassRefPtrWillBeRawPtr<T> adoptRefWillBeThreadSafeRefCountedGarbageCollected(T* ptr)
{
static const bool isThreadSafeRefCountedGarbageCollected = WTF::IsSubclassOfTemplate<typename WTF::RemoveConst<T>::Type, ThreadSafeRefCountedGarbageCollected>::value;
COMPILE_ASSERT(isThreadSafeRefCountedGarbageCollected, useAdoptRefWillBeNoop);
return PassRefPtrWillBeRawPtr<T>(adoptRefCountedGarbageCollected(ptr));
}
template<typename T> PassOwnPtrWillBeRawPtr<T> adoptPtrWillBeNoop(T* ptr)
{
static const bool notRefCountedGarbageCollected = !WTF::IsSubclassOfTemplate<typename WTF::RemoveConst<T>::Type, RefCountedGarbageCollected>::value;
static const bool notRefCounted = !WTF::IsSubclassOfTemplate<typename WTF::RemoveConst<T>::Type, RefCounted>::value;
COMPILE_ASSERT(notRefCountedGarbageCollected, useAdoptRefCountedWillBeRefCountedGarbageCollected);
COMPILE_ASSERT(notRefCounted, youMustAdopt);
return PassOwnPtrWillBeRawPtr<T>(ptr);
}
template<typename T> T* adoptPtrWillBeRefCountedGarbageCollected(T* ptr)
{
static const bool isRefCountedGarbageCollected = WTF::IsSubclassOfTemplate<typename WTF::RemoveConst<T>::Type, RefCountedGarbageCollected>::value;
COMPILE_ASSERT(isRefCountedGarbageCollected, useAdoptRefWillBeNoop);
return adoptRefCountedGarbageCollected(ptr);
}
#define WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED // do nothing when oilpan is enabled.
#define DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(type) // do nothing
#define DECLARE_EMPTY_VIRTUAL_DESTRUCTOR_WILL_BE_REMOVED(type) // do nothing
#define DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(type) // do nothing
#define DEFINE_STATIC_REF_WILL_BE_PERSISTENT(type, name, arguments) \
static type* name = (new Persistent<type>(arguments))->get();
#else // !ENABLE(OILPAN)
template<typename T>
class DummyBase {
......@@ -854,66 +707,6 @@ public:
~DummyBase() { }
};
#define PassRefPtrWillBeRawPtr WTF::PassRefPtr
#define RefCountedWillBeGarbageCollected WTF::RefCounted
#define RefCountedWillBeGarbageCollectedFinalized WTF::RefCounted
#define RefCountedWillBeRefCountedGarbageCollected WTF::RefCounted
#define RefCountedGarbageCollectedWillBeGarbageCollectedFinalized blink::RefCountedGarbageCollected
#define ThreadSafeRefCountedWillBeGarbageCollected WTF::ThreadSafeRefCounted
#define ThreadSafeRefCountedWillBeGarbageCollectedFinalized WTF::ThreadSafeRefCounted
#define ThreadSafeRefCountedWillBeThreadSafeRefCountedGarbageCollected WTF::ThreadSafeRefCounted
#define PersistentWillBeMember blink::Persistent
#define RefPtrWillBePersistent WTF::RefPtr
#define RefPtrWillBeRawPtr WTF::RefPtr
#define RefPtrWillBeMember WTF::RefPtr
#define RefPtrWillBeWeakMember WTF::RefPtr
#define RefPtrWillBeCrossThreadPersistent WTF::RefPtr
#define RawPtrWillBeMember WTF::RawPtr
#define RawPtrWillBePersistent WTF::RawPtr
#define RawPtrWillBeWeakMember WTF::RawPtr
#define OwnPtrWillBeMember WTF::OwnPtr
#define OwnPtrWillBePersistent WTF::OwnPtr
#define OwnPtrWillBeRawPtr WTF::OwnPtr
#define PassOwnPtrWillBeRawPtr WTF::PassOwnPtr
#define WeakPtrWillBeMember WTF::WeakPtr
#define WeakPtrWillBeRawPtr WTF::WeakPtr
#define WeakPtrWillBeMember WTF::WeakPtr
#define WeakPtrWillBeWeakMember WTF::WeakPtr
#define NoBaseWillBeGarbageCollected blink::DummyBase
#define NoBaseWillBeGarbageCollectedFinalized blink::DummyBase
#define NoBaseWillBeRefCountedGarbageCollected blink::DummyBase
#define WillBeHeapHashMap WTF::HashMap
#define WillBePersistentHeapHashMap WTF::HashMap
#define WillBeHeapHashSet WTF::HashSet
#define WillBePersistentHeapHashSet WTF::HashSet
#define WillBeHeapLinkedHashSet WTF::LinkedHashSet
#define WillBePersistentLinkedHeapHashSet WTF::LinkedHashSet
#define WillBeHeapListHashSet WTF::ListHashSet
#define WillBePersistentListHeapHashSet WTF::ListHashSet
#define WillBeHeapVector WTF::Vector
#define WillBePersistentHeapVector WTF::Vector
#define WillBeHeapDeque WTF::Deque
#define WillBePersistentHeapDeque WTF::Deque
#define WillBeHeapHashCountedSet WTF::HashCountedSet
#define WillBePersistentHeapHashCountedSet WTF::HashCountedSet
#define WillBeGarbageCollectedMixin blink::DummyBase<void>
#define WillBeHeapSupplement blink::Supplement
#define WillBeHeapSupplementable blink::Supplementable
#define WillBePersistentHeapSupplementable blink::Supplementable
#define WillBeHeapTerminatedArray WTF::TerminatedArray
#define WillBeHeapTerminatedArrayBuilder WTF::TerminatedArrayBuilder
#define WillBeHeapLinkedStack WTF::LinkedStack
#define PersistentHeapHashSetWillBeHeapHashSet blink::PersistentHeapHashSet
#define PersistentHeapDequeWillBeHeapDeque blink::PersistentHeapDeque
#define PersistentHeapVectorWillBeHeapVector blink::PersistentHeapVector
template<typename T> PassRefPtrWillBeRawPtr<T> adoptRefWillBeNoop(T* ptr) { return adoptRef(ptr); }
template<typename T> PassRefPtrWillBeRawPtr<T> adoptRefWillBeRefCountedGarbageCollected(T* ptr) { return adoptRef(ptr); }
template<typename T> PassRefPtrWillBeRawPtr<T> adoptRefWillBeThreadSafeRefCountedGarbageCollected(T* ptr) { return adoptRef(ptr); }
template<typename T> PassOwnPtrWillBeRawPtr<T> adoptPtrWillBeNoop(T* ptr) { return adoptPtr(ptr); }
template<typename T> PassOwnPtrWillBeRawPtr<T> adoptPtrWillBeRefCountedGarbageCollected(T* ptr) { return adoptPtr(ptr); }
#define WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED WTF_MAKE_FAST_ALLOCATED
#define DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(type) \
public: \
......@@ -930,8 +723,6 @@ template<typename T> PassOwnPtrWillBeRawPtr<T> adoptPtrWillBeRefCountedGarbageCo
#define DEFINE_STATIC_REF_WILL_BE_PERSISTENT(type, name, arguments) \
DEFINE_STATIC_REF(type, name, arguments)
#endif // ENABLE(OILPAN)
} // namespace blink
namespace WTF {
......@@ -1026,11 +817,6 @@ template<typename T> struct HashTraits<blink::WeakMember<T> > : SimpleClassHashT
static PassOutType passOut(const blink::WeakMember<T>& value) { return value; }
static bool traceInCollection(blink::Visitor* visitor, blink::WeakMember<T>& weakMember, ShouldWeakPointersBeMarkedStrongly strongify)
{
if (strongify == WeakPointersActStrong) {
visitor->trace(reinterpret_cast<blink::Member<T>&>(weakMember)); // Strongified visit.
return false;
}
return !visitor->isAlive(weakMember);
}
};
......
......@@ -1632,7 +1632,6 @@ public:
template<typename T, typename Traits>
static void trace(Visitor* 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)
......@@ -1715,13 +1714,6 @@ private:
template<typename Value>
static void traceListHashSetValue(Visitor* visitor, Value& value)
{
// We use the default hash traits for the value in the node, because
// ListHashSet does not let you specify any specific ones.
// We don't allow ListHashSet of WeakMember, so we set that one false
// (there's an assert elsewhere), but we have to specify some value for the
// strongify template argument, so we specify WTF::WeakPointersActWeak,
// arbitrarily.
CollectionBackingTraceTrait<WTF::ShouldBeTraced<WTF::HashTraits<Value> >::value, WTF::NoWeakHandlingInCollections, WTF::WeakPointersActWeak, Value, WTF::HashTraits<Value> >::trace(visitor, value);
}
// The inline capacity is just a dummy template argument to match the off-heap
......@@ -2215,7 +2207,6 @@ template<ShouldWeakPointersBeMarkedStrongly strongify, typename T, typename Trai
struct TraceInCollectionTrait<NoWeakHandlingInCollections, strongify, T, Traits> {
static bool trace(blink::Visitor* visitor, T& t)
{
blink::TraceTrait<T>::trace(visitor, &t);
return false;
}
};
......@@ -2225,7 +2216,7 @@ template<ShouldWeakPointersBeMarkedStrongly strongify, typename T, typename Trai
struct TraceInCollectionTrait<WeakHandlingInCollections, strongify, T, Traits> {
static bool trace(blink::Visitor* visitor, T& t)
{
return Traits::traceInCollection(visitor, t, strongify);
return false;
}
};
......@@ -2234,20 +2225,6 @@ template<ShouldWeakPointersBeMarkedStrongly strongify, typename T, typename Trai
struct TraceInCollectionTrait<NoWeakHandlingInCollections, strongify, blink::HeapVectorBacking<T, Traits>, void> {
static bool trace(blink::Visitor* visitor, void* self)
{
// The allocator can oversize the allocation a little, according to
// the allocation granularity. The extra size is included in the
// payloadSize call below, since there is nowhere to store the
// originally allocated memory. This assert ensures that visiting the
// last bit of memory can't cause trouble.
COMPILE_ASSERT(!ShouldBeTraced<Traits>::value || sizeof(T) > blink::allocationGranularity || Traits::canInitializeWithMemset, HeapOverallocationCanCauseSpuriousVisits);
T* array = reinterpret_cast<T*>(self);
blink::FinalizedHeapObjectHeader* header = blink::FinalizedHeapObjectHeader::fromPayload(self);
// Use the payload size as recorded by the heap to determine how many
// elements to mark.
size_t length = header->payloadSize() / sizeof(T);
for (size_t i = 0; i < length; i++)
blink::CollectionBackingTraceTrait<ShouldBeTraced<Traits>::value, Traits::weakHandlingFlag, WeakPointersActStrong, T, Traits>::trace(visitor, array[i]);
return false;
}
};
......@@ -2259,13 +2236,6 @@ struct TraceInCollectionTrait<NoWeakHandlingInCollections, strongify, blink::Hea
typedef typename Table::ValueTraits Traits;
static bool trace(blink::Visitor* visitor, void* self)
{
Value* array = reinterpret_cast<Value*>(self);
blink::FinalizedHeapObjectHeader* header = blink::FinalizedHeapObjectHeader::fromPayload(self);
size_t length = header->payloadSize() / sizeof(Value);
for (size_t i = 0; i < length; i++) {
if (!HashTableHelper<Value, typename Table::ExtractorType, typename Table::KeyTraitsType>::isEmptyOrDeletedBucket(array[i]))
blink::CollectionBackingTraceTrait<ShouldBeTraced<Traits>::value, Traits::weakHandlingFlag, strongify, Value, Traits>::trace(visitor, array[i]);
}
return false;
}
};
......@@ -2281,19 +2251,6 @@ struct TraceInCollectionTrait<NoWeakHandlingInCollections, strongify, blink::Hea
typedef HashTable<Node*, U, V, W, X, Y, blink::HeapAllocator> Table;
static bool trace(blink::Visitor* visitor, void* self)
{
Node** array = reinterpret_cast<Node**>(self);
blink::FinalizedHeapObjectHeader* header = blink::FinalizedHeapObjectHeader::fromPayload(self);
size_t length = header->payloadSize() / sizeof(Node*);
for (size_t i = 0; i < length; i++) {
if (!HashTableHelper<Node*, typename Table::ExtractorType, typename Table::KeyTraitsType>::isEmptyOrDeletedBucket(array[i])) {
traceListHashSetValue(visitor, array[i]->m_value);
// Just mark the node without tracing because we already traced
// the contents, and there is no need to trace the next and
// prev fields since iterating over the hash table backing will
// find the whole chain.
visitor->markNoTracing(array[i]);
}
}
return false;
}
};
......@@ -2305,9 +2262,6 @@ template<ShouldWeakPointersBeMarkedStrongly strongify, typename Key, typename Va
struct TraceInCollectionTrait<NoWeakHandlingInCollections, strongify, KeyValuePair<Key, Value>, Traits> {
static bool trace(blink::Visitor* 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);
blink::CollectionBackingTraceTrait<ShouldBeTraced<typename Traits::ValueTraits>::value, NoWeakHandlingInCollections, strongify, Value, typename Traits::ValueTraits>::trace(visitor, self.value);
return false;
}
};
......@@ -2316,38 +2270,7 @@ template<ShouldWeakPointersBeMarkedStrongly strongify, typename Key, typename Va
struct TraceInCollectionTrait<WeakHandlingInCollections, strongify, KeyValuePair<Key, Value>, Traits> {
static bool trace(blink::Visitor* 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
// dead weak pointers on that side, and if there are we don't mark the
// value side (yet). Conversely if there is weakness on the value side
// we check that first and don't mark the key side yet if we find dead
// weak pointers.
// Corner case: If there is weakness on both the key and value side,
// and there are also strong pointers on the both sides then we could
// unexpectedly leak. The scenario is that the weak pointer on the key
// side is alive, which causes the strong pointer on the key side to be
// marked. If that then results in the object pointed to by the weak
// pointer on the value side being marked live, then the whole
// key-value entry is leaked. To avoid unexpected leaking, we disallow
// this case, but if you run into this assert, please reach out to Blink
// reviewers, and we may relax it.
const bool keyIsWeak = Traits::KeyTraits::weakHandlingFlag == WeakHandlingInCollections;
const bool valueIsWeak = Traits::ValueTraits::weakHandlingFlag == WeakHandlingInCollections;
const bool keyHasStrongRefs = ShouldBeTraced<typename Traits::KeyTraits>::value;
const bool valueHasStrongRefs = ShouldBeTraced<typename Traits::ValueTraits>::value;
COMPILE_ASSERT(!keyIsWeak || !valueIsWeak || !keyHasStrongRefs || !valueHasStrongRefs, ThisConfigurationWasDisallowedToAvoidUnexpectedLeaks);
if ((valueIsWeak && !keyIsWeak) || (valueIsWeak && keyIsWeak && !valueHasStrongRefs)) {
// Check value first.
bool deadWeakObjectsFoundOnValueSide = blink::CollectionBackingTraceTrait<ShouldBeTraced<typename Traits::ValueTraits>::value, Traits::ValueTraits::weakHandlingFlag, strongify, Value, typename Traits::ValueTraits>::trace(visitor, self.value);
if (deadWeakObjectsFoundOnValueSide)
return true;
return blink::CollectionBackingTraceTrait<ShouldBeTraced<typename Traits::KeyTraits>::value, Traits::KeyTraits::weakHandlingFlag, strongify, Key, typename Traits::KeyTraits>::trace(visitor, self.key);
}
// Check key first.
bool deadWeakObjectsFoundOnKeySide = blink::CollectionBackingTraceTrait<ShouldBeTraced<typename Traits::KeyTraits>::value, Traits::KeyTraits::weakHandlingFlag, strongify, Key, typename Traits::KeyTraits>::trace(visitor, self.key);
if (deadWeakObjectsFoundOnKeySide)
return true;
return blink::CollectionBackingTraceTrait<ShouldBeTraced<typename Traits::ValueTraits>::value, Traits::ValueTraits::weakHandlingFlag, strongify, Value, typename Traits::ValueTraits>::trace(visitor, self.value);
return false;
}
};
......@@ -2357,8 +2280,6 @@ template<ShouldWeakPointersBeMarkedStrongly strongify, typename Value, typename
struct TraceInCollectionTrait<NoWeakHandlingInCollections, strongify, LinkedHashSetNode<Value, Allocator>, Traits> {
static bool trace(blink::Visitor* visitor, LinkedHashSetNode<Value, Allocator>& self)
{
ASSERT(ShouldBeTraced<Traits>::value);
blink::TraceTrait<Value>::trace(visitor, &self.m_value);
return false;
}
};
......@@ -2367,7 +2288,7 @@ template<ShouldWeakPointersBeMarkedStrongly strongify, typename Value, typename
struct TraceInCollectionTrait<WeakHandlingInCollections, strongify, LinkedHashSetNode<Value, Allocator>, Traits> {
static bool trace(blink::Visitor* visitor, LinkedHashSetNode<Value, Allocator>& self)
{
return TraceInCollectionTrait<WeakHandlingInCollections, strongify, Value, typename Traits::ValueTraits>::trace(visitor, self.m_value);
return false;
}
};
......@@ -2377,12 +2298,6 @@ struct TraceInCollectionTrait<NoWeakHandlingInCollections, strongify, ListHashSe
typedef ListHashSetNode<Value, blink::HeapListHashSetAllocator<Value, inlineCapacity> > Node;
static bool trace(blink::Visitor* visitor, Node* node)
{
traceListHashSetValue(visitor, node->m_value);
// Just mark the node without tracing because we already traced the
// contents, and there is no need to trace the next and prev fields
// since iterating over the hash table backing will find the whole
// chain.
visitor->markNoTracing(node);
return false;
}
};
......@@ -2407,8 +2322,7 @@ template<bool needsTracing, WTF::WeakHandlingFlag weakHandlingFlag, WTF::ShouldW
struct CollectionBackingTraceTrait {
static bool trace(Visitor* visitor, T&t)
{
Visitor::verifyGarbageCollectedIfMember(reinterpret_cast<T*>(0));
return WTF::TraceInCollectionTrait<weakHandlingFlag, strongify, T, Traits>::trace(visitor, t);
return false;
}
};
......@@ -2443,19 +2357,9 @@ struct TraceTrait<HeapVectorBacking<T, Traits> > {
typedef HeapVectorBacking<T, Traits> Backing;
static void trace(Visitor* visitor, void* self)
{
COMPILE_ASSERT(!WTF::IsWeak<T>::value, WeDontSupportWeaknessInHeapVectorsOrDeques);
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)
{
visitor->mark(backing, &trace);
}
static void checkGCInfo(Visitor* visitor, const Backing* backing)
{
#if ENABLE(ASSERT)
visitor->checkGCInfo(const_cast<Backing*>(backing), GCInfoTrait<Backing>::get());
#endif
}
};
......@@ -2471,38 +2375,15 @@ struct TraceTrait<HeapHashTableBacking<Table> > {
typedef typename Table::ValueTraits Traits;
static void trace(Visitor* 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)
{
if (WTF::ShouldBeTraced<Traits>::value || Traits::weakHandlingFlag == WTF::WeakHandlingInCollections)
visitor->mark(backing, &trace);
else
visitor->markNoTracing(backing); // If we know the trace function will do nothing there is no need to call it.
}
static void checkGCInfo(Visitor* visitor, const Backing* backing)
{
#if ENABLE(ASSERT)
visitor->checkGCInfo(const_cast<Backing*>(backing), GCInfoTrait<Backing>::get());
#endif
}
};
template<typename Table>
void HeapHashTableBacking<Table>::finalize(void* pointer)
{
typedef typename Table::ValueType Value;
ASSERT(Table::ValueTraits::needsDestruction);
FinalizedHeapObjectHeader* header = FinalizedHeapObjectHeader::fromPayload(pointer);
// Use the payload size as recorded by the heap to determine how many
// elements to finalize.
size_t length = header->payloadSize() / sizeof(Value);
Value* table = reinterpret_cast<Value*>(pointer);
for (unsigned i = 0; i < length; i++) {
if (!Table::isEmptyOrDeletedBucket(table[i]))
table[i].~Value();
}
}
template<typename T, typename U, typename V, typename W, typename X>
......
......@@ -31,34 +31,6 @@
#include "config.h"
#include "platform/heap/Visitor.h"
#include "platform/heap/Handle.h"
#include "platform/heap/Heap.h"
namespace blink {
#if ENABLE(ASSERT)
void Visitor::checkGCInfo(const void* payload, const GCInfo* gcInfo)
{
FinalizedHeapObjectHeader::fromPayload(payload)->checkHeader();
#if !defined(COMPONENT_BUILD)
// On component builds we cannot compare the gcInfos as they are statically
// defined in each of the components and hence will not match.
BaseHeapPage* page = pageHeaderFromObject(payload);
ASSERT(page->orphaned() || FinalizedHeapObjectHeader::fromPayload(payload)->gcInfo() == gcInfo);
#endif
}
#define DEFINE_VISITOR_CHECK_MARKER(Type) \
void Visitor::checkGCInfo(const Type* payload, const GCInfo* gcInfo) \
{ \
HeapObjectHeader::fromPayload(payload)->checkHeader(); \
Type* object = const_cast<Type*>(payload); \
BaseHeapPage* page = pageHeaderFromObject(object); \
ASSERT(page->orphaned() || page->gcInfo() == gcInfo); \
}
FOR_EACH_TYPED_HEAP(DEFINE_VISITOR_CHECK_MARKER)
#undef DEFINE_VISITOR_CHECK_MARKER
#endif
}
......@@ -169,20 +169,11 @@ public:
// dispatches to the trace method of the class T.
static void trace(Visitor* visitor, void* self)
{
static_cast<T*>(self)->trace(visitor);
}
static void mark(Visitor* visitor, const T* t)
{
DefaultTraceTrait<T>::mark(visitor, t);
}
#if ENABLE(ASSERT)
static void checkGCInfo(Visitor* visitor, const T* t)
{
DefaultTraceTrait<T>::checkGCInfo(visitor, t);
}
#endif
};
template<typename T> class TraceTrait<const T> : public TraceTrait<T> { };
......@@ -216,7 +207,6 @@ public:
template<typename T>
static void verifyGarbageCollectedIfMember(Member<T>* t)
{
t->verifyTypeIsGarbageCollected();
}
// One-argument templated mark method. This uses the static type of
......@@ -226,21 +216,12 @@ public:
template<typename T>
void mark(T* t)
{
if (!t)
return;
#if ENABLE(ASSERT)
TraceTrait<T>::checkGCInfo(this, t);
#endif
TraceTrait<T>::mark(this, t);
reinterpret_cast<const Member<T>*>(0)->verifyTypeIsGarbageCollected();
}
// Member version of the one-argument templated trace method.
template<typename T>
void trace(const Member<T>& t)
{
mark(t.get());
}
// Fallback method used only when we need to trace raw pointers of T.
......@@ -248,13 +229,11 @@ public:
template<typename T>
void trace(const T* t)
{
mark(const_cast<T*>(t));
}
template<typename T>
void trace(T* t)
{
mark(t);
}
// WeakMember version of the templated trace method. It doesn't keep
......@@ -266,16 +245,11 @@ public:
template<typename T>
void trace(const WeakMember<T>& t)
{
// Check that we actually know the definition of T when tracing.
COMPILE_ASSERT(sizeof(T), WeNeedToKnowTheDefinitionOfTheTypeWeAreTracing);
registerWeakCell(const_cast<WeakMember<T>&>(t).cell());
reinterpret_cast<const Member<T>*>(0)->verifyTypeIsGarbageCollected();
}
template<typename T>
void traceInCollection(T& t, WTF::ShouldWeakPointersBeMarkedStrongly strongify)
{
HashTraits<T>::traceInCollection(this, t, strongify);
}
// Fallback trace method for part objects to allow individual trace methods
......@@ -289,25 +263,17 @@ public:
template<typename T>
void trace(const T& t)
{
if (WTF::IsPolymorphic<T>::value) {
intptr_t vtable = *reinterpret_cast<const intptr_t*>(&t);
if (!vtable)
return;
}
const_cast<T&>(t).trace(this);
}
// The following trace methods are for off-heap collections.
template<typename T, size_t inlineCapacity>
void trace(const Vector<T, inlineCapacity>& vector)
{
OffHeapCollectionTraceTrait<Vector<T, inlineCapacity, WTF::DefaultAllocator> >::trace(this, vector);
}
template<typename T, size_t N>
void trace(const Deque<T, N>& deque)
{
OffHeapCollectionTraceTrait<Deque<T, N> >::trace(this, deque);
}
#if !ENABLE(OILPAN)
......@@ -417,13 +383,8 @@ public:
return isAlive(ptr.get());
}
#if ENABLE(ASSERT)
void checkGCInfo(const void*, const GCInfo*);
#endif
// Macro to declare methods needed for each typed heap.
#define DECLARE_VISITOR_METHODS(Type) \
DEBUG_ONLY(void checkGCInfo(const Type*, const GCInfo*);) \
virtual void mark(const Type*, TraceCallback) = 0; \
virtual bool isMarked(const Type*) = 0;
......@@ -464,10 +425,6 @@ struct OffHeapCollectionTraceTrait<WTF::Vector<T, N, WTF::DefaultAllocator> > {
static void trace(Visitor* visitor, const Vector& vector)
{
if (vector.isEmpty())
return;
for (typename Vector::const_iterator it = vector.begin(), end = vector.end(); it != end; ++it)
TraceTrait<T>::trace(visitor, const_cast<T*>(it));
}
};
......@@ -477,10 +434,6 @@ struct OffHeapCollectionTraceTrait<WTF::Deque<T, N> > {
static void trace(Visitor* visitor, const Deque& deque)
{
if (deque.isEmpty())
return;
for (typename Deque::const_iterator it = deque.begin(), end = deque.end(); it != end; ++it)
TraceTrait<T>::trace(visitor, const_cast<T*>(&(*it)));
}
};
......@@ -498,19 +451,7 @@ class DefaultTraceTrait<T, false> {
public:
static void mark(Visitor* visitor, const T* t)
{
// Default mark method of the trait just calls the two-argument mark
// method on the visitor. The second argument is the static trace method
// of the trait, which by default calls the instance method
// trace(Visitor*) on the object.
visitor->mark(const_cast<T*>(t), &TraceTrait<T>::trace);
}
#if ENABLE(ASSERT)
static void checkGCInfo(Visitor* visitor, const T* t)
{
visitor->checkGCInfo(const_cast<T*>(t), GCInfoTrait<T>::get());
}
#endif
};
template<typename T>
......@@ -531,10 +472,6 @@ public:
}
self->adjustAndMark(visitor);
}
#if ENABLE(ASSERT)
static void checkGCInfo(Visitor*, const T*) { }
#endif
};
template<typename T, bool = NeedsAdjustAndMark<T>::value> class DefaultObjectAliveTrait;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册