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

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

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: Created 5 years 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 /* 1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 namespace blink { 49 namespace blink {
50 50
51 enum WeaknessPersistentConfiguration { 51 enum WeaknessPersistentConfiguration {
52 NonWeakPersistentConfiguration, 52 NonWeakPersistentConfiguration,
53 WeakPersistentConfiguration 53 WeakPersistentConfiguration
54 }; 54 };
55 55
56 enum CrossThreadnessPersistentConfiguration { 56 enum CrossThreadnessPersistentConfiguration {
57 SingleThreadPersistentConfiguration, 57 SingleThreadPersistentConfiguration,
58 CrossThreadPersistentConfiguration 58 CrossThreadPersistentConfiguration,
59 XThreadPersistentConfiguration
59 }; 60 };
60 61
61 template<typename T, WeaknessPersistentConfiguration weaknessConfiguration, Cros sThreadnessPersistentConfiguration crossThreadnessConfiguration> 62 template<typename T, WeaknessPersistentConfiguration weaknessConfiguration, Cros sThreadnessPersistentConfiguration crossThreadnessConfiguration>
62 class PersistentBase { 63 class PersistentBase {
63 public: 64 public:
64 PersistentBase() : m_raw(nullptr) 65 PersistentBase() : m_raw(nullptr)
65 { 66 {
66 initialize(); 67 initialize();
67 } 68 }
68 69
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 } 201 }
201 202
202 NO_LAZY_SWEEP_SANITIZE_ADDRESS 203 NO_LAZY_SWEEP_SANITIZE_ADDRESS
203 void initialize() 204 void initialize()
204 { 205 {
205 ASSERT(!m_persistentNode); 206 ASSERT(!m_persistentNode);
206 if (!m_raw) 207 if (!m_raw)
207 return; 208 return;
208 209
209 TraceCallback traceCallback = TraceMethodDelegate<PersistentBase<T, weak nessConfiguration, crossThreadnessConfiguration>, &PersistentBase<T, weaknessCon figuration, crossThreadnessConfiguration>::trace>::trampoline; 210 TraceCallback traceCallback = TraceMethodDelegate<PersistentBase<T, weak nessConfiguration, crossThreadnessConfiguration>, &PersistentBase<T, weaknessCon figuration, crossThreadnessConfiguration>::trace>::trampoline;
210 if (crossThreadnessConfiguration == CrossThreadPersistentConfiguration) { 211 if (crossThreadnessConfiguration == XThreadPersistentConfiguration) {
212 BasePage* page = pageFromObject(m_raw);
213 if (!page)
214 return;
215 m_persistentNode = page->heap()->threadState()->xThreadPersistentReg ion()->allocatePersistentNode(this, traceCallback);
216 } else if (crossThreadnessConfiguration == CrossThreadPersistentConfigur ation) {
211 m_persistentNode = ThreadState::crossThreadPersistentRegion().alloca tePersistentNode(this, traceCallback); 217 m_persistentNode = ThreadState::crossThreadPersistentRegion().alloca tePersistentNode(this, traceCallback);
212 } else { 218 } else {
213 ThreadState* state = ThreadStateFor<ThreadingTrait<T>::Affinity>::st ate(); 219 ThreadState* state = ThreadStateFor<ThreadingTrait<T>::Affinity>::st ate();
214 ASSERT(state->checkThread()); 220 ASSERT(state->checkThread());
215 m_persistentNode = state->persistentRegion()->allocatePersistentNode (this, traceCallback); 221 m_persistentNode = state->persistentRegion()->allocatePersistentNode (this, traceCallback);
216 #if ENABLE(ASSERT) 222 #if ENABLE(ASSERT)
217 m_state = state; 223 m_state = state;
218 #endif 224 #endif
219 } 225 }
220 } 226 }
221 227
222 void uninitialize() 228 void uninitialize()
223 { 229 {
224 if (!m_persistentNode) 230 if (!m_persistentNode)
225 return; 231 return;
226 232
227 if (crossThreadnessConfiguration == CrossThreadPersistentConfiguration) { 233 if (crossThreadnessConfiguration == XThreadPersistentConfiguration) {
234 BasePage* page = pageFromObject(m_raw);
235 ASSERT(page);
236 page->heap()->threadState()->xThreadPersistentRegion()->freePersiste ntNode(m_persistentNode);
237 } else if (crossThreadnessConfiguration == CrossThreadPersistentConfigur ation) {
228 ThreadState::crossThreadPersistentRegion().freePersistentNode(m_pers istentNode); 238 ThreadState::crossThreadPersistentRegion().freePersistentNode(m_pers istentNode);
229 } else { 239 } else {
230 ThreadState* state = ThreadStateFor<ThreadingTrait<T>::Affinity>::st ate(); 240 ThreadState* state = ThreadStateFor<ThreadingTrait<T>::Affinity>::st ate();
231 ASSERT(state->checkThread()); 241 ASSERT(state->checkThread());
232 // Persistent handle must be created and destructed in the same thre ad. 242 // Persistent handle must be created and destructed in the same thre ad.
233 ASSERT(m_state == state); 243 ASSERT(m_state == state);
234 state->persistentRegion()->freePersistentNode(m_persistentNode); 244 state->persistentRegion()->freePersistentNode(m_persistentNode);
235 } 245 }
236 m_persistentNode = nullptr; 246 m_persistentNode = nullptr;
237 } 247 }
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 } 513 }
504 514
505 template<typename U> 515 template<typename U>
506 CrossThreadWeakPersistent& operator=(const RawPtr<U>& other) 516 CrossThreadWeakPersistent& operator=(const RawPtr<U>& other)
507 { 517 {
508 Parent::operator=(other); 518 Parent::operator=(other);
509 return *this; 519 return *this;
510 } 520 }
511 }; 521 };
512 522
523 template<typename T>
524 class XThreadPersistent : public PersistentBase<T, NonWeakPersistentConfiguratio n, XThreadPersistentConfiguration> {
525 typedef PersistentBase<T, NonWeakPersistentConfiguration, XThreadPersistentC onfiguration> Parent;
526 public:
527 XThreadPersistent() : Parent() { }
528 XThreadPersistent(std::nullptr_t) : Parent(nullptr) { }
529 XThreadPersistent(T* raw) : Parent(raw) { }
530 XThreadPersistent(T& raw) : Parent(raw) { }
531 XThreadPersistent(const XThreadPersistent& other) : Parent(other) { }
532 template<typename U>
533 XThreadPersistent(const XThreadPersistent<U>& other) : Parent(other) { }
534 template<typename U>
535 XThreadPersistent(const Member<U>& other) : Parent(other) { }
536 template<typename U>
537 XThreadPersistent(const RawPtr<U>& other) : Parent(other.get()) { }
538
539 template<typename U>
540 XThreadPersistent& operator=(U* other)
541 {
542 Parent::operator=(other);
543 return *this;
544 }
545
546 XThreadPersistent& operator=(std::nullptr_t)
547 {
548 Parent::operator=(nullptr);
549 return *this;
550 }
551
552 XThreadPersistent& operator=(const XThreadPersistent& other)
553 {
554 Parent::operator=(other);
555 return *this;
556 }
557
558 template<typename U>
559 XThreadPersistent& operator=(const XThreadPersistent<U>& other)
560 {
561 Parent::operator=(other);
562 return *this;
563 }
564
565 template<typename U>
566 XThreadPersistent& operator=(const Member<U>& other)
567 {
568 Parent::operator=(other);
569 return *this;
570 }
571
572 template<typename U>
573 XThreadPersistent& operator=(const RawPtr<U>& other)
574 {
575 Parent::operator=(other);
576 return *this;
577 }
578 };
579
513 template<typename Collection> 580 template<typename Collection>
514 class PersistentHeapCollectionBase : public Collection { 581 class PersistentHeapCollectionBase : public Collection {
515 // We overload the various new and delete operators with using the WTF Parti tionAllocator to ensure persistent 582 // We overload the various new and delete operators with using the WTF Parti tionAllocator to ensure persistent
516 // heap collections are always allocated off-heap. This allows persistent co llections to be used in 583 // heap collections are always allocated off-heap. This allows persistent co llections to be used in
517 // DEFINE_STATIC_LOCAL et. al. 584 // DEFINE_STATIC_LOCAL et. al.
518 WTF_USE_ALLOCATOR(PersistentHeapCollectionBase, WTF::PartitionAllocator); 585 WTF_USE_ALLOCATOR(PersistentHeapCollectionBase, WTF::PartitionAllocator);
519 public: 586 public:
520 PersistentHeapCollectionBase() 587 PersistentHeapCollectionBase()
521 { 588 {
522 initialize(); 589 initialize();
(...skipping 947 matching lines...) Expand 10 before | Expand all | Expand 10 after
1470 static_assert(sizeof(T), "T must be fully defined"); 1537 static_assert(sizeof(T), "T must be fully defined");
1471 using StorageType = T*; 1538 using StorageType = T*;
1472 1539
1473 static StorageType wrap(T* value) { return value; } 1540 static StorageType wrap(T* value) { return value; }
1474 static T* unwrap(const StorageType& value) { return value; } 1541 static T* unwrap(const StorageType& value) { return value; }
1475 }; 1542 };
1476 1543
1477 template<typename T> 1544 template<typename T>
1478 struct PointerParamStorageTraits<T*, true> { 1545 struct PointerParamStorageTraits<T*, true> {
1479 static_assert(sizeof(T), "T must be fully defined"); 1546 static_assert(sizeof(T), "T must be fully defined");
1480 using StorageType = blink::CrossThreadPersistent<T>; 1547 using StorageType = blink::XThreadPersistent<T>;
1481 1548
1482 static StorageType wrap(T* value) { return value; } 1549 static StorageType wrap(T* value) { return value; }
1483 static T* unwrap(const StorageType& value) { return value.get(); } 1550 static T* unwrap(const StorageType& value) { return value.get(); }
1484 }; 1551 };
1485 1552
1486 template<typename T> 1553 template<typename T>
1487 struct ParamStorageTraits<T*> : public PointerParamStorageTraits<T*, blink::IsGa rbageCollectedType<T>::value> { 1554 struct ParamStorageTraits<T*> : public PointerParamStorageTraits<T*, blink::IsGa rbageCollectedType<T>::value> {
1488 static_assert(sizeof(T), "T must be fully defined"); 1555 static_assert(sizeof(T), "T must be fully defined");
1489 }; 1556 };
1490 1557
(...skipping 13 matching lines...) Expand all
1504 // TODO(sof): extend WTF::FunctionWrapper call overloading to also handle (C rossThread)WeakPersistent. 1571 // TODO(sof): extend WTF::FunctionWrapper call overloading to also handle (C rossThread)WeakPersistent.
1505 static T* unwrap(const StorageType& value) { return value.get(); } 1572 static T* unwrap(const StorageType& value) { return value.get(); }
1506 }; 1573 };
1507 1574
1508 template<typename T> 1575 template<typename T>
1509 PassRefPtr<T> adoptRef(blink::RefCountedGarbageCollected<T>*) = delete; 1576 PassRefPtr<T> adoptRef(blink::RefCountedGarbageCollected<T>*) = delete;
1510 1577
1511 } // namespace WTF 1578 } // namespace WTF
1512 1579
1513 #endif 1580 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698