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

Side by Side Diff: Source/platform/heap/PersistentNode.h

Issue 1265103003: Invalidate cross-thread persistents on heap termination. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: simplify the invalidation as ref-clearing Created 5 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « Source/platform/heap/HeapTest.cpp ('k') | Source/platform/heap/PersistentNode.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef PersistentNode_h 5 #ifndef PersistentNode_h
6 #define PersistentNode_h 6 #define PersistentNode_h
7 7
8 #include "platform/PlatformExport.h" 8 #include "platform/PlatformExport.h"
9 #include "platform/heap/ThreadState.h" 9 #include "platform/heap/ThreadState.h"
10 #include "wtf/Assertions.h" 10 #include "wtf/Assertions.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 PersistentNode* node = reinterpret_cast<PersistentNode*>(m_self); 70 PersistentNode* node = reinterpret_cast<PersistentNode*>(m_self);
71 ASSERT(!node || node->isUnused()); 71 ASSERT(!node || node->isUnused());
72 return node; 72 return node;
73 } 73 }
74 74
75 bool isUnused() const 75 bool isUnused() const
76 { 76 {
77 return !m_trace; 77 return !m_trace;
78 } 78 }
79 79
80 void* self() const
81 {
82 return m_self;
83 }
84
80 private: 85 private:
81 // If this PersistentNode is in use: 86 // If this PersistentNode is in use:
82 // - m_self points to the corresponding Persistent handle. 87 // - m_self points to the corresponding Persistent handle.
83 // - m_trace points to the trace method. 88 // - m_trace points to the trace method.
84 // If this PersistentNode is freed: 89 // If this PersistentNode is freed:
85 // - m_self points to the next freed PersistentNode. 90 // - m_self points to the next freed PersistentNode.
86 // - m_trace is nullptr. 91 // - m_trace is nullptr.
87 void* m_self; 92 void* m_self;
88 TraceCallback m_trace; 93 TraceCallback m_trace;
89 }; 94 };
90 95
91 struct PersistentNodeSlots final { 96 struct PersistentNodeSlots final {
92 private: 97 private:
93 static const int slotCount = 256; 98 static const int slotCount = 256;
94 PersistentNodeSlots* m_next; 99 PersistentNodeSlots* m_next;
95 PersistentNode m_slot[slotCount]; 100 PersistentNode m_slot[slotCount];
96 friend class PersistentRegion; 101 friend class PersistentRegion;
102 friend class CrossThreadPersistentRegion;
97 }; 103 };
98 104
99 // PersistentRegion provides a region of PersistentNodes. PersistentRegion 105 // PersistentRegion provides a region of PersistentNodes. PersistentRegion
100 // holds a linked list of PersistentNodeSlots, each of which stores 106 // holds a linked list of PersistentNodeSlots, each of which stores
101 // a predefined number of PersistentNodes. You can call allocatePersistentNode/ 107 // a predefined number of PersistentNodes. You can call allocatePersistentNode/
102 // freePersistentNode to allocate/free a PersistentNode on the region. 108 // freePersistentNode to allocate/free a PersistentNode on the region.
103 class PLATFORM_EXPORT PersistentRegion final { 109 class PLATFORM_EXPORT PersistentRegion final {
104 public: 110 public:
105 PersistentRegion() 111 PersistentRegion()
106 : m_freeListHead(nullptr) 112 : m_freeListHead(nullptr)
(...skipping 25 matching lines...) Expand all
132 persistentNode->setFreeListNext(m_freeListHead); 138 persistentNode->setFreeListNext(m_freeListHead);
133 m_freeListHead = persistentNode; 139 m_freeListHead = persistentNode;
134 #if ENABLE(ASSERT) 140 #if ENABLE(ASSERT)
135 --m_persistentCount; 141 --m_persistentCount;
136 #endif 142 #endif
137 } 143 }
138 void tracePersistentNodes(Visitor*); 144 void tracePersistentNodes(Visitor*);
139 int numberOfPersistents(); 145 int numberOfPersistents();
140 146
141 private: 147 private:
148 friend CrossThreadPersistentRegion;
149
142 void ensurePersistentNodeSlots(void*, TraceCallback); 150 void ensurePersistentNodeSlots(void*, TraceCallback);
143 151
144 PersistentNode* m_freeListHead; 152 PersistentNode* m_freeListHead;
145 PersistentNodeSlots* m_slots; 153 PersistentNodeSlots* m_slots;
146 #if ENABLE(ASSERT) 154 #if ENABLE(ASSERT)
147 int m_persistentCount; 155 int m_persistentCount;
148 #endif 156 #endif
149 }; 157 };
150 158
151 class CrossThreadPersistentRegion final { 159 class CrossThreadPersistentRegion final {
(...skipping 11 matching lines...) Expand all
163 MutexLocker lock(m_mutex); 171 MutexLocker lock(m_mutex);
164 m_persistentRegion->freePersistentNode(persistentNode); 172 m_persistentRegion->freePersistentNode(persistentNode);
165 } 173 }
166 174
167 void tracePersistentNodes(Visitor* visitor) 175 void tracePersistentNodes(Visitor* visitor)
168 { 176 {
169 MutexLocker lock(m_mutex); 177 MutexLocker lock(m_mutex);
170 m_persistentRegion->tracePersistentNodes(visitor); 178 m_persistentRegion->tracePersistentNodes(visitor);
171 } 179 }
172 180
181 void prepareForThreadStateTermination(ThreadState*);
182
173 private: 183 private:
174 // We don't make CrossThreadPersistentRegion inherit from PersistentRegion 184 // We don't make CrossThreadPersistentRegion inherit from PersistentRegion
175 // because we don't want to virtualize performance-sensitive methods 185 // because we don't want to virtualize performance-sensitive methods
176 // such as PersistentRegion::allocate/freePersistentNode. 186 // such as PersistentRegion::allocate/freePersistentNode.
177 OwnPtr<PersistentRegion> m_persistentRegion; 187 OwnPtr<PersistentRegion> m_persistentRegion;
178 Mutex m_mutex; 188 Mutex m_mutex;
179 }; 189 };
180 190
181 } // namespace blink 191 } // namespace blink
182 192
183 #endif 193 #endif
OLDNEW
« no previous file with comments | « Source/platform/heap/HeapTest.cpp ('k') | Source/platform/heap/PersistentNode.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698