OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "config.h" | 5 #include "config.h" |
6 #include "platform/heap/PersistentNode.h" | 6 #include "platform/heap/PersistentNode.h" |
7 | 7 |
8 #include "platform/heap/Handle.h" | 8 #include "platform/heap/Handle.h" |
9 | 9 |
10 namespace blink { | 10 namespace blink { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 freeListLast->setFreeListNext(m_freeListHead); | 85 freeListLast->setFreeListNext(m_freeListHead); |
86 m_freeListHead = freeListNext; | 86 m_freeListHead = freeListNext; |
87 } | 87 } |
88 prevNext = &slots->m_next; | 88 prevNext = &slots->m_next; |
89 slots = slots->m_next; | 89 slots = slots->m_next; |
90 } | 90 } |
91 } | 91 } |
92 ASSERT(persistentCount == m_persistentCount); | 92 ASSERT(persistentCount == m_persistentCount); |
93 } | 93 } |
94 | 94 |
| 95 namespace { |
| 96 class GCObject final : public GarbageCollected<GCObject> { |
| 97 public: |
| 98 DEFINE_INLINE_TRACE() { } |
| 99 }; |
| 100 } |
| 101 |
95 void CrossThreadPersistentRegion::prepareForThreadStateTermination(ThreadState*
threadState) | 102 void CrossThreadPersistentRegion::prepareForThreadStateTermination(ThreadState*
threadState) |
96 { | 103 { |
97 // For heaps belonging to a thread that's detaching, any cross-thread persis
tents | 104 // For heaps belonging to a thread that's detaching, any cross-thread persis
tents |
98 // pointing into them needs to be disabled. Do that by clearing out the unde
rlying | 105 // pointing into them needs to be disabled. Do that by clearing out the unde
rlying |
99 // heap reference. | 106 // heap reference. |
100 MutexLocker lock(m_mutex); | 107 MutexLocker lock(m_mutex); |
101 | 108 |
102 class Object; | |
103 using GCObject = GarbageCollected<Object>; | |
104 | |
105 // TODO(sof): consider ways of reducing overhead. (e.g., tracking number of
active | 109 // TODO(sof): consider ways of reducing overhead. (e.g., tracking number of
active |
106 // CrossThreadPersistent<>s pointing into the heaps of each ThreadState and
use that | 110 // CrossThreadPersistent<>s pointing into the heaps of each ThreadState and
use that |
107 // count to bail out early.) | 111 // count to bail out early.) |
108 PersistentNodeSlots* slots = m_persistentRegion->m_slots; | 112 PersistentNodeSlots* slots = m_persistentRegion->m_slots; |
109 while (slots) { | 113 while (slots) { |
110 for (int i = 0; i < PersistentNodeSlots::slotCount; ++i) { | 114 for (int i = 0; i < PersistentNodeSlots::slotCount; ++i) { |
111 if (slots->m_slot[i].isUnused()) | 115 if (slots->m_slot[i].isUnused()) |
112 continue; | 116 continue; |
113 | 117 |
114 // 'self' is in use, containing the cross-thread persistent wrapper
object. | 118 // 'self' is in use, containing the cross-thread persistent wrapper
object. |
115 CrossThreadPersistent<GCObject>* persistent = reinterpret_cast<Cross
ThreadPersistent<GCObject>*>(slots->m_slot[i].self()); | 119 CrossThreadPersistent<GCObject>* persistent = reinterpret_cast<Cross
ThreadPersistent<GCObject>*>(slots->m_slot[i].self()); |
116 ASSERT(persistent); | 120 ASSERT(persistent); |
117 void* rawObject = persistent->get(); | 121 void* rawObject = persistent->get(); |
118 if (!rawObject) | 122 if (!rawObject) |
119 continue; | 123 continue; |
120 BasePage* page = pageFromObject(rawObject); | 124 BasePage* page = pageFromObject(rawObject); |
121 ASSERT(page); | 125 ASSERT(page); |
122 // The main thread will upon detach just mark its heap pages as orph
aned, | 126 // The main thread will upon detach just mark its heap pages as orph
aned, |
123 // but not invalidate its CrossThreadPersistent<>s. | 127 // but not invalidate its CrossThreadPersistent<>s. |
124 if (page->orphaned()) | 128 if (page->orphaned()) |
125 continue; | 129 continue; |
126 if (page->heap()->threadState() == threadState) | 130 if (page->heap()->threadState() == threadState) |
127 persistent->clear(); | 131 persistent->clear(); |
128 } | 132 } |
129 slots = slots->m_next; | 133 slots = slots->m_next; |
130 } | 134 } |
131 } | 135 } |
132 | 136 |
133 } // namespace blink | 137 } // namespace blink |
OLD | NEW |