Chromium Code Reviews| Index: third_party/WebKit/Source/platform/heap/Persistent.h |
| diff --git a/third_party/WebKit/Source/platform/heap/Persistent.h b/third_party/WebKit/Source/platform/heap/Persistent.h |
| index 420d487cb2c0af301e3f82d17f3616d228fb6d22..2f775069f96d8dc5c238baab4bb54418ea4cc43e 100644 |
| --- a/third_party/WebKit/Source/platform/heap/Persistent.h |
| +++ b/third_party/WebKit/Source/platform/heap/Persistent.h |
| @@ -39,28 +39,33 @@ class PersistentBase { |
| public: |
| PersistentBase() : m_raw(nullptr) |
| { |
| + saveCreationThreadHeap(); |
| initialize(); |
| } |
| PersistentBase(std::nullptr_t) : m_raw(nullptr) |
| { |
| + saveCreationThreadHeap(); |
| initialize(); |
| } |
| PersistentBase(T* raw) : m_raw(raw) |
| { |
| + saveCreationThreadHeap(); |
| initialize(); |
| checkPointer(); |
| } |
| PersistentBase(T& raw) : m_raw(&raw) |
| { |
| + saveCreationThreadHeap(); |
| initialize(); |
| checkPointer(); |
| } |
| PersistentBase(const PersistentBase& other) : m_raw(other) |
| { |
| + saveCreationThreadHeap(); |
| initialize(); |
| checkPointer(); |
| } |
| @@ -68,6 +73,7 @@ public: |
| template<typename U> |
| PersistentBase(const PersistentBase<U, weaknessConfiguration, crossThreadnessConfiguration>& other) : m_raw(other) |
| { |
| + saveCreationThreadHeap(); |
| initialize(); |
| checkPointer(); |
| } |
| @@ -75,12 +81,14 @@ public: |
| template<typename U> |
| PersistentBase(const Member<U>& other) : m_raw(other) |
| { |
| + saveCreationThreadHeap(); |
| initialize(); |
| checkPointer(); |
| } |
| PersistentBase(WTF::HashTableDeletedValueType) : m_raw(reinterpret_cast<T*>(-1)) |
| { |
| + saveCreationThreadHeap(); |
| initialize(); |
| checkPointer(); |
| } |
| @@ -234,10 +242,21 @@ private: |
| void checkPointer() |
| { |
| -#if ENABLE(ASSERT) && defined(ADDRESS_SANITIZER) |
| +#if DCHECK_IS_ON() |
| if (!m_raw || isHashTableDeletedValue()) |
| return; |
| + if (crossThreadnessConfiguration != CrossThreadPersistentConfiguration) { |
| + DCHECK(m_creationThreadHeap); |
| + ThreadState* current = ThreadState::current(); |
| + DCHECK(current); |
| + if (current) { |
|
haraken
2016/08/17 11:14:24
Remove this if check.
keishi
2016/08/17 13:07:24
Done.
|
| + DCHECK_EQ(&ThreadState::fromObject(m_raw)->heap(), m_creationThreadHeap); |
|
haraken
2016/08/17 11:14:24
Add a developer-friendly comment to help them unde
keishi
2016/08/17 13:07:24
Done.
|
| + DCHECK_EQ(¤t->heap(), m_creationThreadHeap); |
| + } |
| + } |
| + |
| +#if defined(ADDRESS_SANITIZER) |
| // ThreadHeap::isHeapObjectAlive(m_raw) checks that m_raw is a traceable |
| // object. In other words, it checks that the pointer is either of: |
| // |
| @@ -248,6 +267,20 @@ private: |
| // header->checkHeader(). |
| ThreadHeap::isHeapObjectAlive(m_raw); |
| #endif |
| +#endif |
| + } |
| + |
| + void saveCreationThreadHeap() |
| + { |
| +#if DCHECK_IS_ON() |
| + if (crossThreadnessConfiguration != CrossThreadPersistentConfiguration) { |
| + ThreadState* current = ThreadState::current(); |
| + DCHECK(current); |
| + m_creationThreadHeap = &ThreadState::current()->heap(); |
|
haraken
2016/08/17 11:14:24
ThreadState::current() => current
keishi
2016/08/17 13:07:24
Done.
|
| + } else { |
| + m_creationThreadHeap = nullptr; |
| + } |
| +#endif |
| } |
| static void handleWeakPersistent(Visitor* self, void* persistentPointer) |
| @@ -265,6 +298,9 @@ private: |
| #if ENABLE(ASSERT) |
| ThreadState* m_state = nullptr; |
| #endif |
| +#if DCHECK_IS_ON() |
| + const ThreadHeap* m_creationThreadHeap; |
| +#endif |
| }; |
| // Persistent is a way to create a strong pointer from an off-heap object |