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 |
| 11 namespace { |
| 12 |
| 13 class DummyGCBase final : public GarbageCollected<DummyGCBase> { |
| 14 public: |
| 15 DEFINE_INLINE_TRACE() { } |
| 16 }; |
| 17 |
| 18 } |
| 19 |
11 PersistentRegion::~PersistentRegion() | 20 PersistentRegion::~PersistentRegion() |
12 { | 21 { |
13 PersistentNodeSlots* slots = m_slots; | 22 PersistentNodeSlots* slots = m_slots; |
14 while (slots) { | 23 while (slots) { |
15 PersistentNodeSlots* deadSlots = slots; | 24 PersistentNodeSlots* deadSlots = slots; |
16 slots = slots->m_next; | 25 slots = slots->m_next; |
17 delete deadSlots; | 26 delete deadSlots; |
18 } | 27 } |
19 } | 28 } |
20 | 29 |
(...skipping 17 matching lines...) Expand all Loading... |
38 for (int i = 0; i < PersistentNodeSlots::slotCount; ++i) { | 47 for (int i = 0; i < PersistentNodeSlots::slotCount; ++i) { |
39 PersistentNode* node = &slots->m_slot[i]; | 48 PersistentNode* node = &slots->m_slot[i]; |
40 node->setFreeListNext(m_freeListHead); | 49 node->setFreeListNext(m_freeListHead); |
41 m_freeListHead = node; | 50 m_freeListHead = node; |
42 ASSERT(node->isUnused()); | 51 ASSERT(node->isUnused()); |
43 } | 52 } |
44 slots->m_next = m_slots; | 53 slots->m_next = m_slots; |
45 m_slots = slots; | 54 m_slots = slots; |
46 } | 55 } |
47 | 56 |
| 57 void PersistentRegion::releasePersistentNode(PersistentNode* persistentNode, Thr
eadState::PersistentClearCallback callback) |
| 58 { |
| 59 ASSERT(!persistentNode->isUnused()); |
| 60 // 'self' is in use, containing the persistent wrapper object. |
| 61 void* self = persistentNode->self(); |
| 62 if (callback) { |
| 63 (*callback)(self); |
| 64 ASSERT(persistentNode->isUnused()); |
| 65 return; |
| 66 } |
| 67 Persistent<DummyGCBase>* persistent = reinterpret_cast<Persistent<DummyGCBas
e>*>(self); |
| 68 persistent->clear(); |
| 69 ASSERT(persistentNode->isUnused()); |
| 70 } |
| 71 |
48 // This function traces all PersistentNodes. If we encounter | 72 // This function traces all PersistentNodes. If we encounter |
49 // a PersistentNodeSlot that contains only freed PersistentNodes, | 73 // a PersistentNodeSlot that contains only freed PersistentNodes, |
50 // we delete the PersistentNodeSlot. This function rebuilds the free | 74 // we delete the PersistentNodeSlot. This function rebuilds the free |
51 // list of PersistentNodes. | 75 // list of PersistentNodes. |
52 void PersistentRegion::tracePersistentNodes(Visitor* visitor, ShouldTraceCallbac
k shouldTrace) | 76 void PersistentRegion::tracePersistentNodes(Visitor* visitor, ShouldTraceCallbac
k shouldTrace) |
53 { | 77 { |
54 size_t debugMarkedObjectSize = ProcessHeap::totalMarkedObjectSize(); | 78 size_t debugMarkedObjectSize = ProcessHeap::totalMarkedObjectSize(); |
55 base::debug::Alias(&debugMarkedObjectSize); | 79 base::debug::Alias(&debugMarkedObjectSize); |
56 | 80 |
57 m_freeListHead = nullptr; | 81 m_freeListHead = nullptr; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 freeListLast->setFreeListNext(m_freeListHead); | 114 freeListLast->setFreeListNext(m_freeListHead); |
91 m_freeListHead = freeListNext; | 115 m_freeListHead = freeListNext; |
92 } | 116 } |
93 prevNext = &slots->m_next; | 117 prevNext = &slots->m_next; |
94 slots = slots->m_next; | 118 slots = slots->m_next; |
95 } | 119 } |
96 } | 120 } |
97 ASSERT(persistentCount == m_persistentCount); | 121 ASSERT(persistentCount == m_persistentCount); |
98 } | 122 } |
99 | 123 |
100 namespace { | |
101 class GCObject final : public GarbageCollected<GCObject> { | |
102 public: | |
103 DEFINE_INLINE_TRACE() { } | |
104 }; | |
105 } | |
106 | |
107 bool CrossThreadPersistentRegion::shouldTracePersistentNode(Visitor* visitor, Pe
rsistentNode* node) | 124 bool CrossThreadPersistentRegion::shouldTracePersistentNode(Visitor* visitor, Pe
rsistentNode* node) |
108 { | 125 { |
109 CrossThreadPersistent<GCObject>* persistent = reinterpret_cast<CrossThreadPe
rsistent<GCObject>*>(node->self()); | 126 CrossThreadPersistent<DummyGCBase>* persistent = reinterpret_cast<CrossThrea
dPersistent<DummyGCBase>*>(node->self()); |
110 ASSERT(persistent); | 127 ASSERT(persistent); |
111 Address rawObject = reinterpret_cast<Address>(persistent->get()); | 128 Address rawObject = reinterpret_cast<Address>(persistent->get()); |
112 if (!rawObject) | 129 if (!rawObject) |
113 return false; | 130 return false; |
114 return &visitor->heap() == &ThreadState::fromObject(rawObject)->heap(); | 131 return &visitor->heap() == &ThreadState::fromObject(rawObject)->heap(); |
115 } | 132 } |
116 | 133 |
117 void CrossThreadPersistentRegion::prepareForThreadStateTermination(ThreadState*
threadState) | 134 void CrossThreadPersistentRegion::prepareForThreadStateTermination(ThreadState*
threadState) |
118 { | 135 { |
119 // 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 |
120 // 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 |
121 // heap reference. | 138 // heap reference. |
122 MutexLocker lock(m_mutex); | 139 MutexLocker lock(m_mutex); |
123 | 140 |
124 // 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 |
125 // 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 |
126 // count to bail out early.) | 143 // count to bail out early.) |
127 PersistentNodeSlots* slots = m_persistentRegion->m_slots; | 144 PersistentNodeSlots* slots = m_persistentRegion->m_slots; |
128 while (slots) { | 145 while (slots) { |
129 for (int i = 0; i < PersistentNodeSlots::slotCount; ++i) { | 146 for (int i = 0; i < PersistentNodeSlots::slotCount; ++i) { |
130 if (slots->m_slot[i].isUnused()) | 147 if (slots->m_slot[i].isUnused()) |
131 continue; | 148 continue; |
132 | 149 |
133 // 'self' is in use, containing the cross-thread persistent wrapper
object. | 150 // 'self' is in use, containing the cross-thread persistent wrapper
object. |
134 CrossThreadPersistent<GCObject>* persistent = reinterpret_cast<Cross
ThreadPersistent<GCObject>*>(slots->m_slot[i].self()); | 151 CrossThreadPersistent<DummyGCBase>* persistent = reinterpret_cast<Cr
ossThreadPersistent<DummyGCBase>*>(slots->m_slot[i].self()); |
135 ASSERT(persistent); | 152 ASSERT(persistent); |
136 void* rawObject = persistent->atomicGet(); | 153 void* rawObject = persistent->atomicGet(); |
137 if (!rawObject) | 154 if (!rawObject) |
138 continue; | 155 continue; |
139 BasePage* page = pageFromObject(rawObject); | 156 BasePage* page = pageFromObject(rawObject); |
140 ASSERT(page); | 157 ASSERT(page); |
141 // The main thread will upon detach just mark its heap pages as orph
aned, | 158 // The main thread will upon detach just mark its heap pages as orph
aned, |
142 // but not invalidate its CrossThreadPersistent<>s. | 159 // but not invalidate its CrossThreadPersistent<>s. |
143 if (page->orphaned()) | 160 if (page->orphaned()) |
144 continue; | 161 continue; |
145 if (page->arena()->getThreadState() == threadState) | 162 if (page->arena()->getThreadState() == threadState) |
146 persistent->clear(); | 163 persistent->clear(); |
147 } | 164 } |
148 slots = slots->m_next; | 165 slots = slots->m_next; |
149 } | 166 } |
150 } | 167 } |
151 | 168 |
152 } // namespace blink | 169 } // namespace blink |
OLD | NEW |