| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 } | 66 } |
| 67 Persistent<DummyGCBase>* persistent = reinterpret_cast<Persistent<DummyGCBas
e>*>(self); | 67 Persistent<DummyGCBase>* persistent = reinterpret_cast<Persistent<DummyGCBas
e>*>(self); |
| 68 persistent->clear(); | 68 persistent->clear(); |
| 69 ASSERT(persistentNode->isUnused()); | 69 ASSERT(persistentNode->isUnused()); |
| 70 } | 70 } |
| 71 | 71 |
| 72 // This function traces all PersistentNodes. If we encounter | 72 // This function traces all PersistentNodes. If we encounter |
| 73 // a PersistentNodeSlot that contains only freed PersistentNodes, | 73 // a PersistentNodeSlot that contains only freed PersistentNodes, |
| 74 // we delete the PersistentNodeSlot. This function rebuilds the free | 74 // we delete the PersistentNodeSlot. This function rebuilds the free |
| 75 // list of PersistentNodes. | 75 // list of PersistentNodes. |
| 76 void PersistentRegion::tracePersistentNodes(Visitor* visitor) | 76 void PersistentRegion::tracePersistentNodes(Visitor* visitor, ShouldTraceCallbac
k shouldTrace) |
| 77 { | 77 { |
| 78 size_t debugMarkedObjectSize = ProcessHeap::totalMarkedObjectSize(); | 78 size_t debugMarkedObjectSize = ProcessHeap::totalMarkedObjectSize(); |
| 79 base::debug::Alias(&debugMarkedObjectSize); | 79 base::debug::Alias(&debugMarkedObjectSize); |
| 80 | 80 |
| 81 m_freeListHead = nullptr; | 81 m_freeListHead = nullptr; |
| 82 int persistentCount = 0; | 82 int persistentCount = 0; |
| 83 PersistentNodeSlots** prevNext = &m_slots; | 83 PersistentNodeSlots** prevNext = &m_slots; |
| 84 PersistentNodeSlots* slots = m_slots; | 84 PersistentNodeSlots* slots = m_slots; |
| 85 while (slots) { | 85 while (slots) { |
| 86 PersistentNode* freeListNext = nullptr; | 86 PersistentNode* freeListNext = nullptr; |
| 87 PersistentNode* freeListLast = nullptr; | 87 PersistentNode* freeListLast = nullptr; |
| 88 int freeCount = 0; | 88 int freeCount = 0; |
| 89 for (int i = 0; i < PersistentNodeSlots::slotCount; ++i) { | 89 for (int i = 0; i < PersistentNodeSlots::slotCount; ++i) { |
| 90 PersistentNode* node = &slots->m_slot[i]; | 90 PersistentNode* node = &slots->m_slot[i]; |
| 91 if (node->isUnused()) { | 91 if (node->isUnused()) { |
| 92 if (!freeListNext) | 92 if (!freeListNext) |
| 93 freeListLast = node; | 93 freeListLast = node; |
| 94 node->setFreeListNext(freeListNext); | 94 node->setFreeListNext(freeListNext); |
| 95 freeListNext = node; | 95 freeListNext = node; |
| 96 ++freeCount; | 96 ++freeCount; |
| 97 } else { | 97 } else { |
| 98 ++persistentCount; |
| 99 if (!shouldTrace(visitor, node)) |
| 100 continue; |
| 98 node->tracePersistentNode(visitor); | 101 node->tracePersistentNode(visitor); |
| 99 ++persistentCount; | |
| 100 debugMarkedObjectSize = ProcessHeap::totalMarkedObjectSize(); | 102 debugMarkedObjectSize = ProcessHeap::totalMarkedObjectSize(); |
| 101 } | 103 } |
| 102 } | 104 } |
| 103 if (freeCount == PersistentNodeSlots::slotCount) { | 105 if (freeCount == PersistentNodeSlots::slotCount) { |
| 104 PersistentNodeSlots* deadSlots = slots; | 106 PersistentNodeSlots* deadSlots = slots; |
| 105 *prevNext = slots->m_next; | 107 *prevNext = slots->m_next; |
| 106 slots = slots->m_next; | 108 slots = slots->m_next; |
| 107 delete deadSlots; | 109 delete deadSlots; |
| 108 } else { | 110 } else { |
| 109 if (freeListLast) { | 111 if (freeListLast) { |
| 110 ASSERT(freeListNext); | 112 ASSERT(freeListNext); |
| 111 ASSERT(!freeListLast->freeListNext()); | 113 ASSERT(!freeListLast->freeListNext()); |
| 112 freeListLast->setFreeListNext(m_freeListHead); | 114 freeListLast->setFreeListNext(m_freeListHead); |
| 113 m_freeListHead = freeListNext; | 115 m_freeListHead = freeListNext; |
| 114 } | 116 } |
| 115 prevNext = &slots->m_next; | 117 prevNext = &slots->m_next; |
| 116 slots = slots->m_next; | 118 slots = slots->m_next; |
| 117 } | 119 } |
| 118 } | 120 } |
| 119 ASSERT(persistentCount == m_persistentCount); | 121 ASSERT(persistentCount == m_persistentCount); |
| 120 } | 122 } |
| 121 | 123 |
| 124 bool CrossThreadPersistentRegion::shouldTracePersistentNode(Visitor* visitor, Pe
rsistentNode* node) |
| 125 { |
| 126 CrossThreadPersistent<DummyGCBase>* persistent = reinterpret_cast<CrossThrea
dPersistent<DummyGCBase>*>(node->self()); |
| 127 ASSERT(persistent); |
| 128 Address rawObject = reinterpret_cast<Address>(persistent->get()); |
| 129 if (!rawObject) |
| 130 return false; |
| 131 return &visitor->heap() == &ThreadState::fromObject(rawObject)->heap(); |
| 132 } |
| 133 |
| 122 void CrossThreadPersistentRegion::prepareForThreadStateTermination(ThreadState*
threadState) | 134 void CrossThreadPersistentRegion::prepareForThreadStateTermination(ThreadState*
threadState) |
| 123 { | 135 { |
| 124 // For heaps belonging to a thread that's detaching, any cross-thread persis
tents | 136 // For heaps belonging to a thread that's detaching, any cross-thread persis
tents |
| 125 // pointing into them needs to be disabled. Do that by clearing out the unde
rlying | 137 // pointing into them needs to be disabled. Do that by clearing out the unde
rlying |
| 126 // heap reference. | 138 // heap reference. |
| 127 MutexLocker lock(m_mutex); | 139 MutexLocker lock(m_mutex); |
| 128 | 140 |
| 129 // TODO(sof): consider ways of reducing overhead. (e.g., tracking number of
active | 141 // TODO(sof): consider ways of reducing overhead. (e.g., tracking number of
active |
| 130 // CrossThreadPersistent<>s pointing into the heaps of each ThreadState and
use that | 142 // CrossThreadPersistent<>s pointing into the heaps of each ThreadState and
use that |
| 131 // count to bail out early.) | 143 // count to bail out early.) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 148 if (page->orphaned()) | 160 if (page->orphaned()) |
| 149 continue; | 161 continue; |
| 150 if (page->arena()->getThreadState() == threadState) | 162 if (page->arena()->getThreadState() == threadState) |
| 151 persistent->clear(); | 163 persistent->clear(); |
| 152 } | 164 } |
| 153 slots = slots->m_next; | 165 slots = slots->m_next; |
| 154 } | 166 } |
| 155 } | 167 } |
| 156 | 168 |
| 157 } // namespace blink | 169 } // namespace blink |
| OLD | NEW |