Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Side by Side Diff: third_party/WebKit/Source/platform/heap/PersistentNode.cpp

Issue 1477023003: Refactor the Heap into ThreadHeap to prepare for per thread heaps Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactored Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 ASSERT(node->isUnused()); 42 ASSERT(node->isUnused());
43 } 43 }
44 slots->m_next = m_slots; 44 slots->m_next = m_slots;
45 m_slots = slots; 45 m_slots = slots;
46 } 46 }
47 47
48 // This function traces all PersistentNodes. If we encounter 48 // This function traces all PersistentNodes. If we encounter
49 // a PersistentNodeSlot that contains only freed PersistentNodes, 49 // a PersistentNodeSlot that contains only freed PersistentNodes,
50 // we delete the PersistentNodeSlot. This function rebuilds the free 50 // we delete the PersistentNodeSlot. This function rebuilds the free
51 // list of PersistentNodes. 51 // list of PersistentNodes.
52 void PersistentRegion::tracePersistentNodes(Visitor* visitor) 52 void PersistentRegion::tracePersistentNodes(Visitor* visitor, bool (*shouldTrace )(Visitor*, PersistentNode*))
53 { 53 {
54 m_freeListHead = nullptr; 54 m_freeListHead = nullptr;
55 int persistentCount = 0; 55 int persistentCount = 0;
56 PersistentNodeSlots** prevNext = &m_slots; 56 PersistentNodeSlots** prevNext = &m_slots;
57 PersistentNodeSlots* slots = m_slots; 57 PersistentNodeSlots* slots = m_slots;
58 while (slots) { 58 while (slots) {
59 PersistentNode* freeListNext = nullptr; 59 PersistentNode* freeListNext = nullptr;
60 PersistentNode* freeListLast = nullptr; 60 PersistentNode* freeListLast = nullptr;
61 int freeCount = 0; 61 int freeCount = 0;
62 for (int i = 0; i < PersistentNodeSlots::slotCount; ++i) { 62 for (int i = 0; i < PersistentNodeSlots::slotCount; ++i) {
63 PersistentNode* node = &slots->m_slot[i]; 63 PersistentNode* node = &slots->m_slot[i];
64 if (node->isUnused()) { 64 if (node->isUnused()) {
65 if (!freeListNext) 65 if (!freeListNext)
66 freeListLast = node; 66 freeListLast = node;
67 node->setFreeListNext(freeListNext); 67 node->setFreeListNext(freeListNext);
68 freeListNext = node; 68 freeListNext = node;
69 ++freeCount; 69 ++freeCount;
70 } else { 70 } else {
71 if (shouldTrace && !shouldTrace(visitor, node))
72 return;
haraken 2016/01/28 15:52:50 Shouldn't this be 'continue'?
keishi 2016/02/29 06:02:33 Done.
71 node->tracePersistentNode(visitor); 73 node->tracePersistentNode(visitor);
72 ++persistentCount; 74 ++persistentCount;
73 } 75 }
74 } 76 }
75 if (freeCount == PersistentNodeSlots::slotCount) { 77 if (freeCount == PersistentNodeSlots::slotCount) {
76 PersistentNodeSlots* deadSlots = slots; 78 PersistentNodeSlots* deadSlots = slots;
77 *prevNext = slots->m_next; 79 *prevNext = slots->m_next;
78 slots = slots->m_next; 80 slots = slots->m_next;
79 delete deadSlots; 81 delete deadSlots;
80 } else { 82 } else {
(...skipping 10 matching lines...) Expand all
91 ASSERT(persistentCount == m_persistentCount); 93 ASSERT(persistentCount == m_persistentCount);
92 } 94 }
93 95
94 namespace { 96 namespace {
95 class GCObject final : public GarbageCollected<GCObject> { 97 class GCObject final : public GarbageCollected<GCObject> {
96 public: 98 public:
97 DEFINE_INLINE_TRACE() { } 99 DEFINE_INLINE_TRACE() { }
98 }; 100 };
99 } 101 }
100 102
103 bool CrossThreadPersistentRegion::shouldTracePersistentNode(Visitor* visitor, Pe rsistentNode* node)
104 {
haraken 2016/01/28 15:52:50 Add ASSERT(!node->isUnused()).
keishi 2016/02/29 06:02:33 Done.
105 CrossThreadPersistent<GCObject>* persistent = reinterpret_cast<CrossThreadPe rsistent<GCObject>*>(node->self());
106 ASSERT(persistent);
107 Address rawObject = reinterpret_cast<Address>(persistent->get());
108 // TODO: Why do we need to return true?
haraken 2016/01/28 15:52:50 I wonder why as well :) This should return false.
keishi 2016/02/29 06:02:33 Thanks, looks like it was.
109 if (!rawObject)
110 return true;
111 return visitor->gcData()->threadState()->gcGroup()->threads().contains(Threa dState::forObject(rawObject));
haraken 2016/01/28 15:52:50 forObject => fromAddress (for consistency with Hea
keishi 2016/02/29 06:02:33 Done.
112 }
113
101 void CrossThreadPersistentRegion::prepareForThreadStateTermination(ThreadState* threadState) 114 void CrossThreadPersistentRegion::prepareForThreadStateTermination(ThreadState* threadState)
102 { 115 {
103 // For heaps belonging to a thread that's detaching, any cross-thread persis tents 116 // For heaps belonging to a thread that's detaching, any cross-thread persis tents
104 // pointing into them needs to be disabled. Do that by clearing out the unde rlying 117 // pointing into them needs to be disabled. Do that by clearing out the unde rlying
105 // heap reference. 118 // heap reference.
106 MutexLocker lock(m_mutex); 119 MutexLocker lock(m_mutex);
107 120
108 // TODO(sof): consider ways of reducing overhead. (e.g., tracking number of active 121 // TODO(sof): consider ways of reducing overhead. (e.g., tracking number of active
109 // CrossThreadPersistent<>s pointing into the heaps of each ThreadState and use that 122 // CrossThreadPersistent<>s pointing into the heaps of each ThreadState and use that
110 // count to bail out early.) 123 // count to bail out early.)
(...skipping 16 matching lines...) Expand all
127 if (page->orphaned()) 140 if (page->orphaned())
128 continue; 141 continue;
129 if (page->heap()->threadState() == threadState) 142 if (page->heap()->threadState() == threadState)
130 persistent->clear(); 143 persistent->clear();
131 } 144 }
132 slots = slots->m_next; 145 slots = slots->m_next;
133 } 146 }
134 } 147 }
135 148
136 } // namespace blink 149 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698