Index: third_party/WebKit/Source/platform/heap/Handle.h |
diff --git a/third_party/WebKit/Source/platform/heap/Handle.h b/third_party/WebKit/Source/platform/heap/Handle.h |
index fd9415a02382af0ad0f35457dd7285cb41c122fa..7fa6060f4685b0252355dcf6d213e87c3b543baa 100644 |
--- a/third_party/WebKit/Source/platform/heap/Handle.h |
+++ b/third_party/WebKit/Source/platform/heap/Handle.h |
@@ -48,6 +48,9 @@ |
namespace blink { |
+template<typename T> class Member; |
+template<typename T> class UntracedMember; |
+ |
enum WeaknessPersistentConfiguration { |
NonWeakPersistentConfiguration, |
WeakPersistentConfiguration |
@@ -101,6 +104,14 @@ public: |
} |
template<typename U> |
+ PersistentBase(const UntracedMember<U>& other) : m_raw(other) |
+ { |
+ initialize(); |
+ checkPointer(); |
+ recordBacktrace(); |
+ } |
+ |
+ template<typename U> |
PersistentBase(const Member<U>& other) : m_raw(other) |
{ |
initialize(); |
@@ -176,6 +187,13 @@ public: |
} |
template<typename U> |
+ PersistentBase& operator=(const UntracedMember<U>& other) |
+ { |
+ assign(other); |
+ return *this; |
+ } |
+ |
+ template<typename U> |
PersistentBase& operator=(const Member<U>& other) |
{ |
assign(other); |
@@ -298,6 +316,8 @@ public: |
template<typename U> |
Persistent(const Persistent<U>& other) : Parent(other) { } |
template<typename U> |
+ Persistent(const UntracedMember<U>& other) : Parent(other) { } |
+ template<typename U> |
Persistent(const Member<U>& other) : Parent(other) { } |
template<typename U> |
Persistent(const RawPtr<U>& other) : Parent(other.get()) { } |
@@ -329,6 +349,13 @@ public: |
} |
template<typename U> |
+ Persistent& operator=(const UntracedMember<U>& other) |
+ { |
+ Parent::operator=(other); |
+ return *this; |
+ } |
+ |
+ template<typename U> |
Persistent& operator=(const Member<U>& other) |
{ |
Parent::operator=(other); |
@@ -425,6 +452,8 @@ public: |
template<typename U> |
CrossThreadPersistent(const CrossThreadPersistent<U>& other) : Parent(other) { } |
template<typename U> |
+ CrossThreadPersistent(const UntracedMember<U>& other) : Parent(other) { } |
+ template<typename U> |
CrossThreadPersistent(const Member<U>& other) : Parent(other) { } |
template<typename U> |
CrossThreadPersistent(const RawPtr<U>& other) : Parent(other.get()) { } |
@@ -456,6 +485,13 @@ public: |
} |
template<typename U> |
+ CrossThreadPersistent& operator=(const UntracedMember<U>& other) |
+ { |
+ Parent::operator=(other); |
+ return *this; |
+ } |
+ |
+ template<typename U> |
CrossThreadPersistent& operator=(const Member<U>& other) |
{ |
Parent::operator=(other); |
@@ -483,6 +519,8 @@ public: |
template<typename U> |
CrossThreadWeakPersistent(const CrossThreadWeakPersistent<U>& other) : Parent(other) { } |
template<typename U> |
+ CrossThreadWeakPersistent(const UntracedMember<U>& other) : Parent(other) { } |
+ template<typename U> |
CrossThreadWeakPersistent(const Member<U>& other) : Parent(other) { } |
template<typename U> |
CrossThreadWeakPersistent(const RawPtr<U>& other) : Parent(other.get()) { } |
@@ -514,6 +552,13 @@ public: |
} |
template<typename U> |
+ CrossThreadWeakPersistent& operator=(const UntracedMember<U>& other) |
+ { |
+ Parent::operator=(other); |
+ return *this; |
+ } |
+ |
+ template<typename U> |
CrossThreadWeakPersistent& operator=(const Member<U>& other) |
{ |
Parent::operator=(other); |
@@ -691,6 +736,12 @@ public: |
checkPointer(); |
} |
+ template<typename U> |
+ Member(const UntracedMember<U>& other) : m_raw(other) |
+ { |
+ checkPointer(); |
+ } |
+ |
Member(const Member& other) : m_raw(other) |
{ |
checkPointer(); |
@@ -735,6 +786,14 @@ public: |
} |
template<typename U> |
+ Member& operator=(const UntracedMember<U>& other) |
+ { |
+ m_raw = other; |
+ checkPointer(); |
+ return *this; |
+ } |
+ |
+ template<typename U> |
Member& operator=(U* other) |
{ |
m_raw = other; |
@@ -823,6 +882,9 @@ public: |
WeakMember(const Persistent<U>& other) : Member<T>(other) { } |
template<typename U> |
+ WeakMember(const UntracedMember<U>& other) : Member<T>(other) { } |
+ |
+ template<typename U> |
WeakMember(const Member<U>& other) : Member<T>(other) { } |
template<typename U> |
@@ -842,6 +904,14 @@ public: |
} |
template<typename U> |
+ WeakMember& operator=(const UntracedMember<U>& other) |
+ { |
+ this->m_raw = other; |
+ this->checkPointer(); |
+ return *this; |
+ } |
+ |
+ template<typename U> |
WeakMember& operator=(U* other) |
{ |
this->m_raw = other; |
@@ -869,15 +939,182 @@ private: |
template<typename Derived> friend class VisitorHelper; |
}; |
-// Comparison operators between (Weak)Members and Persistents |
+// UntracedMember is actually a raw pointer. |
+// It is allowed to store a pointer to an object on oilpan heap, |
+// and it is also allowed to store UntracedMember in off heap Vector. |
+// UntracedMember does not keep the pointee object alive, so if you use |
+// UntracedMember, you must guarantee that the pointee object is alive in |
+// some reason. |
+// TODO(peria): Enable to store UntracedMember in hash collections. (i.e. HashSet) |
+template<typename T> |
+class UntracedMember { |
haraken
2015/10/14 09:39:53
I'm just curious but would it be possible to make
peria
2015/10/15 02:13:15
Done.
|
+public: |
+ UntracedMember() : m_raw(nullptr) |
+ { |
+ } |
+ |
+ UntracedMember(std::nullptr_t) : m_raw(nullptr) |
+ { |
+ } |
+ |
+ UntracedMember(const UntracedMember& other) : m_raw(other) |
+ { |
+ checkPointer(); |
+ } |
+ |
+ template<typename U> |
+ UntracedMember(const UntracedMember<U>& other) : m_raw(other) |
+ { |
+ checkPointer(); |
+ } |
+ |
+ UntracedMember(T* raw) : m_raw(raw) |
+ { |
+ checkPointer(); |
+ } |
+ |
+ template<typename U> |
+ UntracedMember(const RawPtr<U>& other) : m_raw(other.get()) |
+ { |
+ checkPointer(); |
+ } |
+ |
+ template<typename U> |
+ UntracedMember(const Persistent<U>& other) : m_raw(other) |
+ { |
+ checkPointer(); |
+ } |
+ |
+ template<typename U> |
+ UntracedMember(const Member<U>& other) : m_raw(other) |
+ { |
+ checkPointer(); |
+ } |
+ |
+ UntracedMember(WTF::HashTableDeletedValueType) : m_raw(reinterpret_cast<T*>(-1)) |
+ { |
+ } |
+ |
+ bool isHashTableDeletedValue() const { return m_raw == reinterpret_cast<T*>(-1); } |
+ |
+ T* release() |
+ { |
+ T* result = m_raw; |
+ m_raw = nullptr; |
+ return result; |
+ } |
+ |
+ bool operator!() const { return !m_raw; } |
+ |
+ operator T*() const { return m_raw; } |
+ |
+ T* operator->() const { return m_raw; } |
+ T& operator*() const { return *m_raw; } |
+ template<typename U> |
+ operator RawPtr<U>() const { return m_raw; } |
+ |
+ template<typename U> |
+ UntracedMember& operator=(const UntracedMember<U>& other) |
+ { |
+ m_raw = other; |
+ checkPointer(); |
+ return *this; |
+ } |
+ |
+ template<typename U> |
+ UntracedMember& operator=(const Persistent<U>& other) |
+ { |
+ m_raw = other; |
+ checkPointer(); |
+ return *this; |
+ } |
+ |
+ template<typename U> |
+ UntracedMember& operator=(const Member<U>& other) |
+ { |
+ m_raw = other; |
+ checkPointer(); |
+ return *this; |
+ } |
+ |
+ template<typename U> |
+ UntracedMember& operator=(RawPtr<U> other) |
+ { |
+ m_raw = other; |
+ checkPointer(); |
+ return *this; |
+ } |
+ |
+ template<typename U> |
+ UntracedMember& operator=(U* other) |
+ { |
+ m_raw = other; |
+ checkPointer(); |
+ return *this; |
+ } |
+ |
+ UntracedMember& operator=(std::nullptr_t) |
+ { |
+ m_raw = nullptr; |
+ return *this; |
+ } |
+ |
+ void swap(UntracedMember<T>& other) |
+ { |
+ std::swap(m_raw, other.m_raw); |
+ checkPointer(); |
+ } |
+ |
+ T* get() const { return m_raw; } |
+ |
+ void clear() { m_raw = nullptr; } |
+ |
+ |
+protected: |
+ void checkPointer() |
+ { |
+#if ENABLE(ASSERT) |
+ if (!m_raw) |
+ return; |
+ |
+ // TODO(haraken): What we really want to check here is that the pointer |
+ // is a traceable object. In other words, the pointer is either of: |
+ // |
+ // (a) a pointer to the head of an on-heap object. |
+ // (b) a pointer to the head of an on-heap mixin object. |
+ // |
+ // We can check it by calling Heap::isHeapObjectAlive(m_raw), |
+ // but we cannot call it here because it requires to include T.h. |
+ // So we currently only try to implement the check for (a), but do |
+ // not insist that T's definition is in scope. |
+ if (IsFullyDefined<T>::value && !IsGarbageCollectedMixin<T>::value) |
+ ASSERT(HeapObjectHeader::fromPayload(m_raw)->checkHeader()); |
+#endif |
+ } |
+ |
+ T* m_raw; |
+}; |
+ |
+// Comparison operators between (Weak)Members, Persistents, and UntracedMembers. |
template<typename T, typename U> inline bool operator==(const Member<T>& a, const Member<U>& b) { return a.get() == b.get(); } |
template<typename T, typename U> inline bool operator!=(const Member<T>& a, const Member<U>& b) { return a.get() != b.get(); } |
+template<typename T, typename U> inline bool operator==(const UntracedMember<T>& a, const UntracedMember<U>& b) { return a.get() == b.get(); } |
+template<typename T, typename U> inline bool operator!=(const UntracedMember<T>& a, const UntracedMember<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(); } |
+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 Member<T>& a, const Persistent<U>& b) { return a.get() == b.get(); } |
template<typename T, typename U> inline bool operator!=(const Member<T>& a, const Persistent<U>& b) { return a.get() != b.get(); } |
template<typename T, typename U> inline bool operator==(const Persistent<T>& a, const Member<U>& b) { return a.get() == b.get(); } |
template<typename T, typename U> inline bool operator!=(const Persistent<T>& a, const Member<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(); } |
-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 Member<T>& a, const UntracedMember<U>& b) { return a.get() == b.get(); } |
+template<typename T, typename U> inline bool operator!=(const Member<T>& a, const UntracedMember<U>& b) { return a.get() != b.get(); } |
+template<typename T, typename U> inline bool operator==(const UntracedMember<T>& a, const Member<U>& b) { return a.get() == b.get(); } |
+template<typename T, typename U> inline bool operator!=(const UntracedMember<T>& a, const Member<U>& b) { return a.get() != b.get(); } |
+template<typename T, typename U> inline bool operator==(const UntracedMember<T>& a, const Persistent<U>& b) { return a.get() == b.get(); } |
+template<typename T, typename U> inline bool operator!=(const UntracedMember<T>& a, const Persistent<U>& b) { return a.get() != b.get(); } |
+template<typename T, typename U> inline bool operator==(const Persistent<T>& a, const UntracedMember<U>& b) { return a.get() == b.get(); } |
+template<typename T, typename U> inline bool operator!=(const Persistent<T>& a, const UntracedMember<U>& b) { return a.get() != b.get(); } |
template<typename T> |
class DummyBase { |
@@ -925,6 +1162,7 @@ public: |
#define RawPtrWillBePersistent blink::Persistent |
#define RawPtrWillBeWeakMember blink::WeakMember |
#define RawPtrWillBeWeakPersistent blink::WeakPersistent |
+#define RawPtrWillBeUntracedMember blink::UntracedMember |
#define OwnPtrWillBeCrossThreadPersistent blink::CrossThreadPersistent |
#define OwnPtrWillBeMember blink::Member |
#define OwnPtrWillBePersistent blink::Persistent |
@@ -1008,6 +1246,7 @@ template<typename T> T* adoptPtrWillBeNoop(T* ptr) |
#define RawPtrWillBePersistent WTF::RawPtr |
#define RawPtrWillBeWeakMember WTF::RawPtr |
#define RawPtrWillBeWeakPersistent WTF::RawPtr |
+#define RawPtrWillBeUntracedMember WTF::RawPtr |
#define OwnPtrWillBeCrossThreadPersistent WTF::OwnPtr |
#define OwnPtrWillBeMember WTF::OwnPtr |
#define OwnPtrWillBePersistent WTF::OwnPtr |
@@ -1198,6 +1437,13 @@ template <typename T> struct VectorTraits<blink::WeakMember<T>> : VectorTraitsBa |
static const bool canMoveWithMemcpy = true; |
}; |
+template <typename T> struct VectorTraits<blink::UntracedMember<T>> : VectorTraitsBase<blink::UntracedMember<T>> { |
+ static const bool needsDestruction = false; |
+ static const bool canInitializeWithMemset = true; |
+ static const bool canClearUnusedSlotsWithMemset = true; |
+ static const bool canMoveWithMemcpy = true; |
+}; |
+ |
template <typename T> struct VectorTraits<blink::HeapVector<T, 0>> : VectorTraitsBase<blink::HeapVector<T, 0>> { |
static const bool needsDestruction = false; |
static const bool canInitializeWithMemset = true; |
@@ -1289,6 +1535,32 @@ template<typename T> struct HashTraits<blink::WeakMember<T>> : SimpleClassHashTr |
} |
}; |
+template<typename T> struct HashTraits<blink::UntracedMember<T>> : SimpleClassHashTraits<blink::UntracedMember<T>> { |
+ static const bool needsDestruction = false; |
+ // FIXME: The distinction between PeekInType and PassInType is there for |
+ // the sake of the reference counting handles. When they are gone the two |
+ // types can be merged into PassInType. |
+ // FIXME: Implement proper const'ness for iterator types. |
+ using PeekInType = RawPtr<T>; |
+ using PassInType = RawPtr<T>; |
+ using IteratorGetType = blink::UntracedMember<T>*; |
+ using IteratorConstGetType = const blink::UntracedMember<T>*; |
+ using IteratorReferenceType = blink::UntracedMember<T>&; |
+ using IteratorConstReferenceType = const blink::UntracedMember<T>&; |
+ static IteratorReferenceType getToReferenceConversion(IteratorGetType x) { return *x; } |
+ static IteratorConstReferenceType getToReferenceConstConversion(IteratorConstGetType x) { return *x; } |
+ // FIXME: Similarly, there is no need for a distinction between PeekOutType |
+ // and PassOutType without reference counting. |
+ using PeekOutType = T*; |
+ using PassOutType = T*; |
+ |
+ template<typename U> |
+ static void store(const U& value, blink::UntracedMember<T>& storage) { storage = value; } |
+ |
+ static PeekOutType peek(const blink::UntracedMember<T>& value) { return value; } |
+ static PassOutType passOut(const blink::UntracedMember<T>& value) { return value; } |
+}; |
+ |
template<typename T> struct PtrHash<blink::Member<T>> : PtrHash<T*> { |
template<typename U> |
static unsigned hash(const U& key) { return PtrHash<T*>::hash(key); } |
@@ -1310,6 +1582,10 @@ template<typename T> struct DefaultHash<blink::WeakMember<T>> { |
using Hash = PtrHash<blink::WeakMember<T>>; |
}; |
+template<typename T> struct DefaultHash<blink::UntracedMember<T>> { |
+ using Hash = PtrHash<blink::UntracedMember<T>>; |
+}; |
+ |
template<typename T> |
struct NeedsTracing<blink::Member<T>> { |
static const bool value = true; |