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 "platform/heap/PersistentNode.h" | 5 #include "platform/heap/PersistentNode.h" |
6 | 6 |
7 #include "platform/heap/Handle.h" | 7 #include "platform/heap/Handle.h" |
8 | 8 |
9 namespace blink { | 9 namespace blink { |
10 | 10 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 DCHECK(persistent); | 128 DCHECK(persistent); |
129 DCHECK(!persistent->isHashTableDeletedValue()); | 129 DCHECK(!persistent->isHashTableDeletedValue()); |
130 Address rawObject = reinterpret_cast<Address>(persistent->get()); | 130 Address rawObject = reinterpret_cast<Address>(persistent->get()); |
131 if (!rawObject) | 131 if (!rawObject) |
132 return false; | 132 return false; |
133 return &visitor->heap() == &ThreadState::fromObject(rawObject)->heap(); | 133 return &visitor->heap() == &ThreadState::fromObject(rawObject)->heap(); |
134 } | 134 } |
135 | 135 |
136 void CrossThreadPersistentRegion::prepareForThreadStateTermination( | 136 void CrossThreadPersistentRegion::prepareForThreadStateTermination( |
137 ThreadState* threadState) { | 137 ThreadState* threadState) { |
138 // For heaps belonging to a thread that's detaching, any cross-thread persiste
nts | 138 // For heaps belonging to a thread that's detaching, any cross-thread |
139 // pointing into them needs to be disabled. Do that by clearing out the underl
ying | 139 // persistents pointing into them needs to be disabled. Do that by clearing |
140 // heap reference. | 140 // out the underlying heap reference. |
141 MutexLocker lock(m_mutex); | 141 MutexLocker lock(m_mutex); |
142 | 142 |
143 // TODO(sof): consider ways of reducing overhead. (e.g., tracking number of ac
tive | 143 // TODO(sof): consider ways of reducing overhead. (e.g., tracking number of |
144 // CrossThreadPersistent<>s pointing into the heaps of each ThreadState and us
e that | 144 // active CrossThreadPersistent<>s pointing into the heaps of each ThreadState |
145 // count to bail out early.) | 145 // and use that count to bail out early.) |
146 PersistentNodeSlots* slots = m_persistentRegion->m_slots; | 146 PersistentNodeSlots* slots = m_persistentRegion->m_slots; |
147 while (slots) { | 147 while (slots) { |
148 for (int i = 0; i < PersistentNodeSlots::slotCount; ++i) { | 148 for (int i = 0; i < PersistentNodeSlots::slotCount; ++i) { |
149 if (slots->m_slot[i].isUnused()) | 149 if (slots->m_slot[i].isUnused()) |
150 continue; | 150 continue; |
151 | 151 |
152 // 'self' is in use, containing the cross-thread persistent wrapper object
. | 152 // 'self' is in use, containing the cross-thread persistent wrapper |
| 153 // object. |
153 CrossThreadPersistent<DummyGCBase>* persistent = | 154 CrossThreadPersistent<DummyGCBase>* persistent = |
154 reinterpret_cast<CrossThreadPersistent<DummyGCBase>*>( | 155 reinterpret_cast<CrossThreadPersistent<DummyGCBase>*>( |
155 slots->m_slot[i].self()); | 156 slots->m_slot[i].self()); |
156 ASSERT(persistent); | 157 ASSERT(persistent); |
157 void* rawObject = persistent->atomicGet(); | 158 void* rawObject = persistent->atomicGet(); |
158 if (!rawObject) | 159 if (!rawObject) |
159 continue; | 160 continue; |
160 BasePage* page = pageFromObject(rawObject); | 161 BasePage* page = pageFromObject(rawObject); |
161 ASSERT(page); | 162 ASSERT(page); |
162 // The main thread will upon detach just mark its heap pages as orphaned, | 163 // The main thread will upon detach just mark its heap pages as orphaned, |
163 // but not invalidate its CrossThreadPersistent<>s. | 164 // but not invalidate its CrossThreadPersistent<>s. |
164 if (page->orphaned()) | 165 if (page->orphaned()) |
165 continue; | 166 continue; |
166 if (page->arena()->getThreadState() == threadState) { | 167 if (page->arena()->getThreadState() == threadState) { |
167 persistent->clear(); | 168 persistent->clear(); |
168 ASSERT(slots->m_slot[i].isUnused()); | 169 ASSERT(slots->m_slot[i].isUnused()); |
169 } | 170 } |
170 } | 171 } |
171 slots = slots->m_next; | 172 slots = slots->m_next; |
172 } | 173 } |
173 } | 174 } |
174 | 175 |
175 } // namespace blink | 176 } // namespace blink |
OLD | NEW |