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

Side by Side Diff: third_party/WebKit/Source/platform/heap/Persistent.h

Issue 2257333003: Check thread is attached when creating a Persistent (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 state->freePersistentNode(m_persistentNode); 239 state->freePersistentNode(m_persistentNode);
240 m_persistentNode = nullptr; 240 m_persistentNode = nullptr;
241 } 241 }
242 242
243 void checkPointer() 243 void checkPointer()
244 { 244 {
245 #if DCHECK_IS_ON() 245 #if DCHECK_IS_ON()
246 if (!m_raw || isHashTableDeletedValue()) 246 if (!m_raw || isHashTableDeletedValue())
247 return; 247 return;
248 248
249 if (crossThreadnessConfiguration != CrossThreadPersistentConfiguration & & m_creationThreadState) { 249 if (crossThreadnessConfiguration != CrossThreadPersistentConfiguration) {
250 ThreadState* current = ThreadState::current(); 250 ThreadState* current = ThreadState::current();
251 DCHECK(current); 251 DCHECK(current);
252 // m_creationThreadState may be null when this is used in a heap
253 // collection which initialized the Persistent with memset and the
254 // constructor wasn't called.
255 if (m_creationThreadState) {
haraken 2016/08/19 06:31:31 Maybe would it be worth distinguishing the two cas
252 // Member should point to objects that belong in the same Thread Heap. 256 // Member should point to objects that belong in the same Thread Heap.
253 DCHECK_EQ(&ThreadState::fromObject(m_raw)->heap(), &m_creationTh readState->heap()); 257 DCHECK_EQ(&ThreadState::fromObject(m_raw)->heap(), &m_creationTh readState->heap());
254 // Member should point to objects that belong in the same Thread Heap. 258 // Member should point to objects that belong in the same Thread Heap.
255 DCHECK_EQ(&current->heap(), &m_creationThreadState->heap()); 259 DCHECK_EQ(&current->heap(), &m_creationThreadState->heap());
260 }
256 } 261 }
257 262
258 #if defined(ADDRESS_SANITIZER) 263 #if defined(ADDRESS_SANITIZER)
259 // ThreadHeap::isHeapObjectAlive(m_raw) checks that m_raw is a traceable 264 // ThreadHeap::isHeapObjectAlive(m_raw) checks that m_raw is a traceable
260 // object. In other words, it checks that the pointer is either of: 265 // object. In other words, it checks that the pointer is either of:
261 // 266 //
262 // (a) a pointer to the head of an on-heap object. 267 // (a) a pointer to the head of an on-heap object.
263 // (b) a pointer to the head of an on-heap mixin object. 268 // (b) a pointer to the head of an on-heap mixin object.
264 // 269 //
265 // Otherwise, ThreadHeap::isHeapObjectAlive will crash when it calls 270 // Otherwise, ThreadHeap::isHeapObjectAlive will crash when it calls
266 // header->checkHeader(). 271 // header->checkHeader().
267 ThreadHeap::isHeapObjectAlive(m_raw); 272 ThreadHeap::isHeapObjectAlive(m_raw);
268 #endif 273 #endif
269 #endif 274 #endif
270 } 275 }
271 276
272 void saveCreationThreadHeap() 277 void saveCreationThreadHeap()
273 { 278 {
274 #if DCHECK_IS_ON() 279 #if DCHECK_IS_ON()
275 if (crossThreadnessConfiguration == CrossThreadPersistentConfiguration) 280 if (crossThreadnessConfiguration == CrossThreadPersistentConfiguration) {
276 m_creationThreadState = nullptr; 281 m_creationThreadState = nullptr;
277 else 282 } else {
278 m_creationThreadState = ThreadState::current(); 283 m_creationThreadState = ThreadState::current();
284 DCHECK(m_creationThreadState);
285 }
279 #endif 286 #endif
280 } 287 }
281 288
282 static void handleWeakPersistent(Visitor* self, void* persistentPointer) 289 static void handleWeakPersistent(Visitor* self, void* persistentPointer)
283 { 290 {
284 using Base = PersistentBase<typename std::remove_const<T>::type, weaknes sConfiguration, crossThreadnessConfiguration>; 291 using Base = PersistentBase<typename std::remove_const<T>::type, weaknes sConfiguration, crossThreadnessConfiguration>;
285 Base* persistent = reinterpret_cast<Base*>(persistentPointer); 292 Base* persistent = reinterpret_cast<Base*>(persistentPointer);
286 T* object = persistent->get(); 293 T* object = persistent->get();
287 if (object && !ObjectAliveTrait<T>::isHeapObjectAlive(object)) 294 if (object && !ObjectAliveTrait<T>::isHeapObjectAlive(object))
288 persistent->clear(); 295 persistent->clear();
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 762
756 template <typename T> 763 template <typename T>
757 struct IsWeakReceiver<blink::WeakPersistent<T>> : std::true_type {}; 764 struct IsWeakReceiver<blink::WeakPersistent<T>> : std::true_type {};
758 765
759 template <typename T> 766 template <typename T>
760 struct IsWeakReceiver<blink::CrossThreadWeakPersistent<T>> : std::true_type {}; 767 struct IsWeakReceiver<blink::CrossThreadWeakPersistent<T>> : std::true_type {};
761 768
762 } 769 }
763 770
764 #endif // Persistent_h 771 #endif // Persistent_h
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698