| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef Persistent_h | 5 #ifndef Persistent_h |
| 6 #define Persistent_h | 6 #define Persistent_h |
| 7 | 7 |
| 8 #include "platform/heap/Heap.h" | 8 #include "platform/heap/Heap.h" |
| 9 #include "platform/heap/Member.h" | 9 #include "platform/heap/Member.h" |
| 10 #include "platform/heap/PersistentNode.h" | 10 #include "platform/heap/PersistentNode.h" |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 &PersistentBase::tracePersistent>::trampoline; | 218 &PersistentBase::tracePersistent>::trampoline; |
| 219 if (crossThreadnessConfiguration == CrossThreadPersistentConfiguration) { | 219 if (crossThreadnessConfiguration == CrossThreadPersistentConfiguration) { |
| 220 ProcessHeap::crossThreadPersistentRegion().allocatePersistentNode( | 220 ProcessHeap::crossThreadPersistentRegion().allocatePersistentNode( |
| 221 m_persistentNode, this, traceCallback); | 221 m_persistentNode, this, traceCallback); |
| 222 return; | 222 return; |
| 223 } | 223 } |
| 224 ThreadState* state = ThreadStateFor<ThreadingTrait<T>::Affinity>::state(); | 224 ThreadState* state = ThreadStateFor<ThreadingTrait<T>::Affinity>::state(); |
| 225 ASSERT(state->checkThread()); | 225 ASSERT(state->checkThread()); |
| 226 m_persistentNode = state->getPersistentRegion()->allocatePersistentNode( | 226 m_persistentNode = state->getPersistentRegion()->allocatePersistentNode( |
| 227 this, traceCallback); | 227 this, traceCallback); |
| 228 #if ENABLE(ASSERT) | 228 #if DCHECK_IS_ON() |
| 229 m_state = state; | 229 m_state = state; |
| 230 #endif | 230 #endif |
| 231 } | 231 } |
| 232 | 232 |
| 233 void uninitialize() { | 233 void uninitialize() { |
| 234 // TODO(haraken): This is a short-term hack to prevent use-after-frees | 234 // TODO(haraken): This is a short-term hack to prevent use-after-frees |
| 235 // during a shutdown sequence. | 235 // during a shutdown sequence. |
| 236 // 1) blink::shutdown() frees the underlying storage for persistent nodes. | 236 // 1) blink::shutdown() frees the underlying storage for persistent nodes. |
| 237 // 2) ~MessageLoop() destructs some Chromium-side objects that hold | 237 // 2) ~MessageLoop() destructs some Chromium-side objects that hold |
| 238 // Persistent. It touches the underlying storage and crashes. | 238 // Persistent. It touches the underlying storage and crashes. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 weaknessConfiguration, crossThreadnessConfiguration>; | 307 weaknessConfiguration, crossThreadnessConfiguration>; |
| 308 Base* persistent = reinterpret_cast<Base*>(persistentPointer); | 308 Base* persistent = reinterpret_cast<Base*>(persistentPointer); |
| 309 T* object = persistent->get(); | 309 T* object = persistent->get(); |
| 310 if (object && !ObjectAliveTrait<T>::isHeapObjectAlive(object)) | 310 if (object && !ObjectAliveTrait<T>::isHeapObjectAlive(object)) |
| 311 persistent->clear(); | 311 persistent->clear(); |
| 312 } | 312 } |
| 313 | 313 |
| 314 // m_raw is accessed most, so put it at the first field. | 314 // m_raw is accessed most, so put it at the first field. |
| 315 T* m_raw; | 315 T* m_raw; |
| 316 PersistentNode* m_persistentNode = nullptr; | 316 PersistentNode* m_persistentNode = nullptr; |
| 317 #if ENABLE(ASSERT) | 317 #if DCHECK_IS_ON() |
| 318 ThreadState* m_state = nullptr; | 318 ThreadState* m_state = nullptr; |
| 319 #endif | |
| 320 #if DCHECK_IS_ON() | |
| 321 const ThreadState* m_creationThreadState; | 319 const ThreadState* m_creationThreadState; |
| 322 #endif | 320 #endif |
| 323 }; | 321 }; |
| 324 | 322 |
| 325 // Persistent is a way to create a strong pointer from an off-heap object | 323 // Persistent is a way to create a strong pointer from an off-heap object |
| 326 // to another on-heap object. As long as the Persistent handle is alive | 324 // to another on-heap object. As long as the Persistent handle is alive |
| 327 // the GC will keep the object pointed to alive. The Persistent handle is | 325 // the GC will keep the object pointed to alive. The Persistent handle is |
| 328 // always a GC root from the point of view of the GC. | 326 // always a GC root from the point of view of the GC. |
| 329 // | 327 // |
| 330 // We have to construct and destruct Persistent in the same thread. | 328 // We have to construct and destruct Persistent in the same thread. |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 NO_SANITIZE_ADDRESS | 608 NO_SANITIZE_ADDRESS |
| 611 void initialize() { | 609 void initialize() { |
| 612 // FIXME: Derive affinity based on the collection. | 610 // FIXME: Derive affinity based on the collection. |
| 613 ThreadState* state = ThreadState::current(); | 611 ThreadState* state = ThreadState::current(); |
| 614 ASSERT(state->checkThread()); | 612 ASSERT(state->checkThread()); |
| 615 m_persistentNode = state->getPersistentRegion()->allocatePersistentNode( | 613 m_persistentNode = state->getPersistentRegion()->allocatePersistentNode( |
| 616 this, | 614 this, |
| 617 TraceMethodDelegate<PersistentHeapCollectionBase<Collection>, | 615 TraceMethodDelegate<PersistentHeapCollectionBase<Collection>, |
| 618 &PersistentHeapCollectionBase< | 616 &PersistentHeapCollectionBase< |
| 619 Collection>::tracePersistent>::trampoline); | 617 Collection>::tracePersistent>::trampoline); |
| 620 #if ENABLE(ASSERT) | 618 #if DCHECK_IS_ON() |
| 621 m_state = state; | 619 m_state = state; |
| 622 #endif | 620 #endif |
| 623 } | 621 } |
| 624 | 622 |
| 625 void uninitialize() { | 623 void uninitialize() { |
| 626 if (!m_persistentNode) | 624 if (!m_persistentNode) |
| 627 return; | 625 return; |
| 628 ThreadState* state = ThreadState::current(); | 626 ThreadState* state = ThreadState::current(); |
| 629 ASSERT(state->checkThread()); | 627 ASSERT(state->checkThread()); |
| 630 // Persistent handle must be created and destructed in the same thread. | 628 // Persistent handle must be created and destructed in the same thread. |
| 631 ASSERT(m_state == state); | 629 ASSERT(m_state == state); |
| 632 state->freePersistentNode(m_persistentNode); | 630 state->freePersistentNode(m_persistentNode); |
| 633 m_persistentNode = nullptr; | 631 m_persistentNode = nullptr; |
| 634 } | 632 } |
| 635 | 633 |
| 636 PersistentNode* m_persistentNode; | 634 PersistentNode* m_persistentNode; |
| 637 #if ENABLE(ASSERT) | 635 #if DCHECK_IS_ON() |
| 638 ThreadState* m_state; | 636 ThreadState* m_state; |
| 639 #endif | 637 #endif |
| 640 }; | 638 }; |
| 641 | 639 |
| 642 template <typename KeyArg, | 640 template <typename KeyArg, |
| 643 typename MappedArg, | 641 typename MappedArg, |
| 644 typename HashArg = typename DefaultHash<KeyArg>::Hash, | 642 typename HashArg = typename DefaultHash<KeyArg>::Hash, |
| 645 typename KeyTraitsArg = HashTraits<KeyArg>, | 643 typename KeyTraitsArg = HashTraits<KeyArg>, |
| 646 typename MappedTraitsArg = HashTraits<MappedArg>> | 644 typename MappedTraitsArg = HashTraits<MappedArg>> |
| 647 class PersistentHeapHashMap | 645 class PersistentHeapHashMap |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 static blink::CrossThreadPersistent<T> Unwrap( | 818 static blink::CrossThreadPersistent<T> Unwrap( |
| 821 const blink::CrossThreadWeakPersistent<T>& wrapped) { | 819 const blink::CrossThreadWeakPersistent<T>& wrapped) { |
| 822 blink::CrossThreadPersistentRegion::LockScope persistentLock( | 820 blink::CrossThreadPersistentRegion::LockScope persistentLock( |
| 823 blink::ProcessHeap::crossThreadPersistentRegion()); | 821 blink::ProcessHeap::crossThreadPersistentRegion()); |
| 824 return blink::CrossThreadPersistent<T>(wrapped.get()); | 822 return blink::CrossThreadPersistent<T>(wrapped.get()); |
| 825 } | 823 } |
| 826 }; | 824 }; |
| 827 } | 825 } |
| 828 | 826 |
| 829 #endif // Persistent_h | 827 #endif // Persistent_h |
| OLD | NEW |