Commit 86ddf6ee authored by tkent@chromium.org's avatar tkent@chromium.org

Oilpan: Fix ParamStorageTraits for RawPtr<T>.

RawPtr<> can be used for off-heap classes.  e.g. RawPtrWillBeMember<OffHeap>
So, we should check if T is on-heap for ParamStorageTraits<RawPtr<T>>.

This CL also introduces IsGarbageCollectedType<T> struct to simplify on-heap
class check.

BUG=

Review URL: https://codereview.chromium.org/322343002

git-svn-id: svn://svn.chromium.org/blink/trunk@175951 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent f89f0432
...@@ -69,31 +69,34 @@ struct IsGarbageCollectedMixin { ...@@ -69,31 +69,34 @@ struct IsGarbageCollectedMixin {
static bool const value = (sizeof(TrueType) == sizeof(hasAdjustAndMark<T>(0))) && (sizeof(TrueType) == sizeof(hasIsAlive<T>(0))); static bool const value = (sizeof(TrueType) == sizeof(hasAdjustAndMark<T>(0))) && (sizeof(TrueType) == sizeof(hasIsAlive<T>(0)));
}; };
#define COMPILE_ASSERT_IS_GARBAGE_COLLECTED(T, ErrorMessage) \ template <typename T>
do { \ struct IsGarbageCollectedType {
typedef typename WTF::RemoveConst<T>::Type NonConstType; \ typedef typename WTF::RemoveConst<T>::Type NonConstType;
typedef WTF::IsSubclassOfTemplate<NonConstType, GarbageCollected> GarbageCollectedSubclass; \ typedef WTF::IsSubclassOfTemplate<NonConstType, GarbageCollected> GarbageCollectedSubclass;
typedef IsGarbageCollectedMixin<NonConstType> GarbageCollectedMixinSubclass; \ typedef IsGarbageCollectedMixin<NonConstType> GarbageCollectedMixinSubclass;
typedef WTF::IsSubclassOfTemplate3<NonConstType, HeapHashSet> HeapHashSetSubclass; \ typedef WTF::IsSubclassOfTemplate3<NonConstType, HeapHashSet> HeapHashSetSubclass;
typedef WTF::IsSubclassOfTemplate3<NonConstType, HeapLinkedHashSet> HeapLinkedHashSetSubclass; \ typedef WTF::IsSubclassOfTemplate3<NonConstType, HeapLinkedHashSet> HeapLinkedHashSetSubclass;
typedef WTF::IsSubclassOfTemplateTypenameSizeTypename<NonConstType, HeapListHashSet> HeapListHashSetSubclass; \ typedef WTF::IsSubclassOfTemplateTypenameSizeTypename<NonConstType, HeapListHashSet> HeapListHashSetSubclass;
typedef WTF::IsSubclassOfTemplate5<NonConstType, HeapHashMap> HeapHashMapSubclass; \ typedef WTF::IsSubclassOfTemplate5<NonConstType, HeapHashMap> HeapHashMapSubclass;
typedef WTF::IsSubclassOfTemplateTypenameSize<NonConstType, HeapVector> HeapVectorSubclass; \ typedef WTF::IsSubclassOfTemplateTypenameSize<NonConstType, HeapVector> HeapVectorSubclass;
typedef WTF::IsSubclassOfTemplateTypenameSize<NonConstType, HeapDeque> HeapDequeSubclass; \ typedef WTF::IsSubclassOfTemplateTypenameSize<NonConstType, HeapDeque> HeapDequeSubclass;
typedef WTF::IsSubclassOfTemplate3<NonConstType, HeapHashCountedSet> HeapHashCountedSetSubclass; \ typedef WTF::IsSubclassOfTemplate3<NonConstType, HeapHashCountedSet> HeapHashCountedSetSubclass;
typedef WTF::IsSubclassOfTemplate<NonConstType, HeapTerminatedArray> HeapTerminatedArraySubclass; \ typedef WTF::IsSubclassOfTemplate<NonConstType, HeapTerminatedArray> HeapTerminatedArraySubclass;
COMPILE_ASSERT(GarbageCollectedSubclass::value || \ static const bool value =
GarbageCollectedMixinSubclass::value || \ GarbageCollectedSubclass::value
HeapHashSetSubclass::value || \ || GarbageCollectedMixinSubclass::value
HeapLinkedHashSetSubclass::value || \ || HeapHashSetSubclass::value
HeapListHashSetSubclass::value || \ || HeapLinkedHashSetSubclass::value
HeapHashMapSubclass::value || \ || HeapListHashSetSubclass::value
HeapVectorSubclass::value || \ || HeapHashMapSubclass::value
HeapDequeSubclass::value || \ || HeapVectorSubclass::value
HeapHashCountedSetSubclass::value || \ || HeapDequeSubclass::value
HeapTerminatedArraySubclass::value, \ || HeapHashCountedSetSubclass::value
ErrorMessage); \ || HeapTerminatedArraySubclass::value;
} while (0) };
#define COMPILE_ASSERT_IS_GARBAGE_COLLECTED(T, ErrorMessage) \
COMPILE_ASSERT(IsGarbageCollectedType<T>::value, ErrorMessage)
template<typename T> class Member; template<typename T> class Member;
...@@ -1160,31 +1163,28 @@ struct NeedsTracing<ListHashSetNode<T, WebCore::HeapListHashSetAllocator<T, inli ...@@ -1160,31 +1163,28 @@ struct NeedsTracing<ListHashSetNode<T, WebCore::HeapListHashSetAllocator<T, inli
// For wtf/Functional.h // For wtf/Functional.h
template<typename T, bool isGarbageCollected> struct PointerParamStorageTraits; template<typename T, bool isGarbageCollected> struct PointerParamStorageTraits;
template<typename T> struct PointerParamStorageTraits<T*, false> { template<typename T>
struct PointerParamStorageTraits<T*, false> {
typedef T* StorageType; typedef T* StorageType;
static StorageType wrap(T* value) { return value; } static StorageType wrap(T* value) { return value; }
static T* unwrap(const StorageType& value) { return value; } static T* unwrap(const StorageType& value) { return value; }
}; };
template<typename T> struct PointerParamStorageTraits<T*, true> { template<typename T>
struct PointerParamStorageTraits<T*, true> {
typedef WebCore::CrossThreadPersistent<T> StorageType; typedef WebCore::CrossThreadPersistent<T> StorageType;
static StorageType wrap(T* value) { return value; } static StorageType wrap(T* value) { return value; }
static T* unwrap(const StorageType& value) { return value.get(); } static T* unwrap(const StorageType& value) { return value.get(); }
}; };
// FIXME: This doesn't support collections and const types. See template<typename T>
// COMPILE_ASSERT_IS_GARBAGE_COLLECTED. struct ParamStorageTraits<T*> : public PointerParamStorageTraits<T*, WebCore::IsGarbageCollectedType<T>::value> {
template<typename T> struct ParamStorageTraits<T*> : public PointerParamStorageTraits<T*, WTF::IsSubclassOfTemplate<T, WebCore::GarbageCollected>::value || WebCore::IsGarbageCollectedMixin<T>::value> {
}; };
// We assume RawPtr<T> is used only for garbage-collected types. template<typename T>
template<typename T> struct ParamStorageTraits<RawPtr<T> > { struct ParamStorageTraits<RawPtr<T> > : public PointerParamStorageTraits<T*, WebCore::IsGarbageCollectedType<T>::value> {
typedef WebCore::CrossThreadPersistent<T> StorageType;
static StorageType wrap(RawPtr<T> value) { return value.get(); }
static T* unwrap(const StorageType& value) { return value.get(); }
}; };
} // namespace WTF } // namespace WTF
......
...@@ -341,6 +341,7 @@ public: ...@@ -341,6 +341,7 @@ public:
bool operator==(const OffHeapInt& other) const { return other.value() == value(); } bool operator==(const OffHeapInt& other) const { return other.value() == value(); }
unsigned hash() { return IntHash<int>::hash(m_x); } unsigned hash() { return IntHash<int>::hash(m_x); }
void voidFunction() { }
protected: protected:
OffHeapInt(int x) : m_x(x) { } OffHeapInt(int x) : m_x(x) { }
...@@ -3989,6 +3990,8 @@ TEST(HeapTest, Bind) ...@@ -3989,6 +3990,8 @@ TEST(HeapTest, Bind)
Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); Heap::collectGarbage(ThreadState::NoHeapPointersOnStack);
// The closure should have a persistent handle to the Bar. // The closure should have a persistent handle to the Bar.
EXPECT_EQ(2u, Bar::s_live); EXPECT_EQ(2u, Bar::s_live);
// RawPtr<OffHeapInt> should not make Persistent.
Closure closure3 = bind(&OffHeapInt::voidFunction, RawPtr<OffHeapInt>(OffHeapInt::create(1).get()));
UseMixin::s_traceCount = 0; UseMixin::s_traceCount = 0;
Mixin* mixin = UseMixin::create(); Mixin* mixin = UseMixin::create();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment