OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 Persistent_h | 5 #ifndef Persistent_h |
6 #define Persistent_h | 6 #define Persistent_h |
7 | 7 |
8 #include "platform/heap/Heap.h" | 8 #include "platform/heap/Heap.h" |
9 #include "platform/heap/Member.h" | 9 #include "platform/heap/Member.h" |
10 #include "platform/heap/PersistentNode.h" | 10 #include "platform/heap/PersistentNode.h" |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 return; | 177 return; |
178 } | 178 } |
179 uninitialize(); | 179 uninitialize(); |
180 } | 180 } |
181 | 181 |
182 template<typename VisitorDispatcher> | 182 template<typename VisitorDispatcher> |
183 void tracePersistent(VisitorDispatcher visitor) | 183 void tracePersistent(VisitorDispatcher visitor) |
184 { | 184 { |
185 static_assert(sizeof(T), "T must be fully defined"); | 185 static_assert(sizeof(T), "T must be fully defined"); |
186 static_assert(IsGarbageCollectedType<T>::value, "T needs to be a garbage collected object"); | 186 static_assert(IsGarbageCollectedType<T>::value, "T needs to be a garbage collected object"); |
187 if (weaknessConfiguration == WeakPersistentConfiguration) | 187 if (weaknessConfiguration == WeakPersistentConfiguration) { |
188 visitor->registerWeakMembers(this, m_raw, handleWeakPersistent); | 188 if (crossThreadnessConfiguration == CrossThreadPersistentConfigurati on) |
189 else | 189 visitor->registerWeakCellWithCallback(reinterpret_cast<void**>(t his), handleWeakPersistent); |
190 else | |
191 visitor->registerWeakMembers(this, m_raw, handleWeakPersistent); | |
haraken
2016/06/29 00:41:54
Is there any reason you don't want to move this on
sof
2016/06/29 05:13:47
It would be untidy to do so, as Persistent<>s have
| |
192 } else { | |
190 visitor->mark(m_raw); | 193 visitor->mark(m_raw); |
194 } | |
191 } | 195 } |
192 | 196 |
193 NO_LAZY_SWEEP_SANITIZE_ADDRESS | 197 NO_LAZY_SWEEP_SANITIZE_ADDRESS |
194 void initialize() | 198 void initialize() |
195 { | 199 { |
196 ASSERT(!m_persistentNode); | 200 ASSERT(!m_persistentNode); |
197 if (!m_raw || isHashTableDeletedValue()) | 201 if (!m_raw || isHashTableDeletedValue()) |
198 return; | 202 return; |
199 | 203 |
200 TraceCallback traceCallback = TraceMethodDelegate<PersistentBase, &Persi stentBase::tracePersistent>::trampoline; | 204 TraceCallback traceCallback = TraceMethodDelegate<PersistentBase, &Persi stentBase::tracePersistent>::trampoline; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
239 // | 243 // |
240 // (a) a pointer to the head of an on-heap object. | 244 // (a) a pointer to the head of an on-heap object. |
241 // (b) a pointer to the head of an on-heap mixin object. | 245 // (b) a pointer to the head of an on-heap mixin object. |
242 // | 246 // |
243 // Otherwise, ThreadHeap::isHeapObjectAlive will crash when it calls | 247 // Otherwise, ThreadHeap::isHeapObjectAlive will crash when it calls |
244 // header->checkHeader(). | 248 // header->checkHeader(). |
245 ThreadHeap::isHeapObjectAlive(m_raw); | 249 ThreadHeap::isHeapObjectAlive(m_raw); |
246 #endif | 250 #endif |
247 } | 251 } |
248 | 252 |
249 static void handleWeakPersistent(Visitor* self, void* object) | 253 static void handleWeakPersistent(Visitor* self, void* persistentPointer) |
250 { | 254 { |
251 using Base = PersistentBase<typename std::remove_const<T>::type, weaknes sConfiguration, crossThreadnessConfiguration>; | 255 using Base = PersistentBase<typename std::remove_const<T>::type, weaknes sConfiguration, crossThreadnessConfiguration>; |
252 Base* persistent = reinterpret_cast<Base*>(object); | 256 Base* persistent = reinterpret_cast<Base*>(persistentPointer); |
253 if (persistent->get() && !ObjectAliveTrait<T>::isHeapObjectAlive(persist ent->get())) | 257 T* object = persistent->get(); |
258 if (object && !ObjectAliveTrait<T>::isHeapObjectAlive(object)) | |
254 persistent->clear(); | 259 persistent->clear(); |
255 } | 260 } |
256 | 261 |
257 // m_raw is accessed most, so put it at the first field. | 262 // m_raw is accessed most, so put it at the first field. |
258 T* m_raw; | 263 T* m_raw; |
259 PersistentNode* m_persistentNode = nullptr; | 264 PersistentNode* m_persistentNode = nullptr; |
260 #if ENABLE(ASSERT) | 265 #if ENABLE(ASSERT) |
261 ThreadState* m_state = nullptr; | 266 ThreadState* m_state = nullptr; |
262 #endif | 267 #endif |
263 }; | 268 }; |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
718 | 723 |
719 template <typename T> | 724 template <typename T> |
720 struct IsWeakReceiver<blink::WeakPersistent<T>> : std::true_type {}; | 725 struct IsWeakReceiver<blink::WeakPersistent<T>> : std::true_type {}; |
721 | 726 |
722 template <typename T> | 727 template <typename T> |
723 struct IsWeakReceiver<blink::CrossThreadWeakPersistent<T>> : std::true_type {}; | 728 struct IsWeakReceiver<blink::CrossThreadWeakPersistent<T>> : std::true_type {}; |
724 | 729 |
725 } | 730 } |
726 | 731 |
727 #endif // Persistent_h | 732 #endif // Persistent_h |
OLD | NEW |