Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 17 matching lines...) Expand all Loading... | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef Handle_h | 31 #ifndef Handle_h |
| 32 #define Handle_h | 32 #define Handle_h |
| 33 | 33 |
| 34 #include "heap/Heap.h" | 34 #include "heap/Heap.h" |
| 35 #include "heap/ThreadState.h" | 35 #include "heap/ThreadState.h" |
| 36 #include "heap/Visitor.h" | 36 #include "heap/Visitor.h" |
| 37 | 37 |
| 38 #include "wtf/Ptr.h" | |
| 39 #include "wtf/RefCounted.h" | |
| 40 | |
| 38 namespace WebCore { | 41 namespace WebCore { |
| 39 | 42 |
| 40 template<typename T> class Member; | 43 template<typename T> class Member; |
| 41 | 44 |
| 42 class PersistentNode { | 45 class PersistentNode { |
| 43 public: | 46 public: |
| 44 explicit PersistentNode(TraceCallback trace) : m_trace(trace) { } | 47 explicit PersistentNode(TraceCallback trace) : m_trace(trace) { } |
| 45 | 48 |
| 46 virtual ~PersistentNode() { } | 49 virtual ~PersistentNode() { } |
| 47 | 50 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 | 170 |
| 168 Persistent(const Persistent& other) : m_raw(other) { } | 171 Persistent(const Persistent& other) : m_raw(other) { } |
| 169 | 172 |
| 170 template<typename U> | 173 template<typename U> |
| 171 Persistent(const Persistent<U>& other) : m_raw(other) { } | 174 Persistent(const Persistent<U>& other) : m_raw(other) { } |
| 172 | 175 |
| 173 template<typename U> | 176 template<typename U> |
| 174 Persistent(const Member<U>& other) : m_raw(other) { } | 177 Persistent(const Member<U>& other) : m_raw(other) { } |
| 175 | 178 |
| 176 template<typename U> | 179 template<typename U> |
| 180 Persistent(const Ptr<U>& other) : m_raw(other.get()) { } | |
| 181 | |
| 182 template<typename U> | |
| 177 Persistent& operator=(U* other) | 183 Persistent& operator=(U* other) |
| 178 { | 184 { |
| 179 m_raw = other; | 185 m_raw = other; |
| 180 return *this; | 186 return *this; |
| 181 } | 187 } |
| 182 | 188 |
| 183 virtual ~Persistent() | 189 virtual ~Persistent() |
| 184 { | 190 { |
| 185 m_raw = 0; | 191 m_raw = 0; |
| 186 } | 192 } |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 198 T* result = m_raw; | 204 T* result = m_raw; |
| 199 m_raw = 0; | 205 m_raw = 0; |
| 200 return result; | 206 return result; |
| 201 } | 207 } |
| 202 | 208 |
| 203 T& operator*() const { return *m_raw; } | 209 T& operator*() const { return *m_raw; } |
| 204 | 210 |
| 205 bool operator!() const { return !m_raw; } | 211 bool operator!() const { return !m_raw; } |
| 206 | 212 |
| 207 operator T*() const { return m_raw; } | 213 operator T*() const { return m_raw; } |
| 214 operator Ptr<T>() const { return Ptr<T>(m_raw); } | |
| 208 | 215 |
| 209 T* operator->() const { return *this; } | 216 T* operator->() const { return *this; } |
| 210 | 217 |
| 211 Persistent& operator=(std::nullptr_t) | 218 Persistent& operator=(std::nullptr_t) |
| 212 { | 219 { |
| 213 m_raw = 0; | 220 m_raw = 0; |
| 214 return *this; | 221 return *this; |
| 215 } | 222 } |
| 216 | 223 |
| 217 Persistent& operator=(const Persistent& other) | 224 Persistent& operator=(const Persistent& other) |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 397 // Comparison operators between (Weak)Members and Persistents | 404 // Comparison operators between (Weak)Members and Persistents |
| 398 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons t Member<U>& b) { return a.get() == b.get(); } | 405 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons t Member<U>& b) { return a.get() == b.get(); } |
| 399 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons t Member<U>& b) { return a.get() != b.get(); } | 406 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons t Member<U>& b) { return a.get() != b.get(); } |
| 400 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons t Persistent<U>& b) { return a.get() == b.get(); } | 407 template<typename T, typename U> inline bool operator==(const Member<T>& a, cons t Persistent<U>& b) { return a.get() == b.get(); } |
| 401 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons t Persistent<U>& b) { return a.get() != b.get(); } | 408 template<typename T, typename U> inline bool operator!=(const Member<T>& a, cons t Persistent<U>& b) { return a.get() != b.get(); } |
| 402 template<typename T, typename U> inline bool operator==(const Persistent<T>& a, const Member<U>& b) { return a.get() == b.get(); } | 409 template<typename T, typename U> inline bool operator==(const Persistent<T>& a, const Member<U>& b) { return a.get() == b.get(); } |
| 403 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a, const Member<U>& b) { return a.get() != b.get(); } | 410 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a, const Member<U>& b) { return a.get() != b.get(); } |
| 404 template<typename T, typename U> inline bool operator==(const Persistent<T>& a, const Persistent<U>& b) { return a.get() == b.get(); } | 411 template<typename T, typename U> inline bool operator==(const Persistent<T>& a, const Persistent<U>& b) { return a.get() == b.get(); } |
| 405 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a, const Persistent<U>& b) { return a.get() != b.get(); } | 412 template<typename T, typename U> inline bool operator!=(const Persistent<T>& a, const Persistent<U>& b) { return a.get() != b.get(); } |
| 406 | 413 |
| 414 // Template aliases for the transition period where we want to support | |
| 415 // both reference counting and garbage collection based on the | |
| 416 // enable_oilpan compile-time flag. | |
| 417 // | |
| 418 // With clang we can use c++11 template aliases which is really what | |
| 419 // we want. For GCC and MSVC we simulate the template aliases with | |
| 420 // stylized macros until we can use template aliases. | |
| 421 #if ENABLE_OILPAN | |
|
Vyacheslav Egorov (Chromium)
2014/01/15 14:21:10
Should not this be #if ENABLE(OILPAN) ?
Mads Ager (chromium)
2014/01/15 14:51:14
Yes, thanks.
| |
| 422 | |
| 423 #if COMPILER(CLANG) | |
|
Vyacheslav Egorov (Chromium)
2014/01/15 14:21:10
While this is indeed very robust compared to defin
Mads Ager (chromium)
2014/01/15 14:51:14
I agree with that assessment. The reason for using
| |
| 424 template<typename T> using PassRefPtrWillBePtr = Ptr<T>; | |
|
jbroman
2014/01/15 14:37:09
Why use template aliases on Clang if we're still g
Mads Ager (chromium)
2014/01/15 14:51:14
To keep us honest so that we cannot do anything na
| |
| 425 template<typename T> using RefCountedWillBeGarbageCollected = GarbageCollected<T >; | |
| 426 template<typename T> using RefCountedWillBeGarbageCollectedFinalized = GarbageCo llectedFinalized<T>; | |
| 427 template<typename T> using RefPtrWillBePersistent = Persistent<T>; | |
| 428 template<typename T> using RefPtrWillBePtr = Ptr<T>; | |
| 429 template<typename T> using RefPtrWillBeMember = Member<T>; | |
| 430 template<typename T> using PtrWillBeMember = Member<T>; | |
| 431 template<typename T> using PtrWillBeWeakMember = WeakMember<T>; | |
| 432 template<typename T> using OwnPtrWillBeMember = Member<T>; | |
| 433 template<typename T> using PassOwnPtrWillBePtr = Ptr<T>; | |
| 434 template<typename T> using NoBaseWillBeGarbageCollected = GarbageCollected<T>; | |
| 435 template<typename T> using NoBaseWillBeGarbageCollectedFinalized = GarbageCollec tedFinalized<T>; | |
| 436 #else // !COMPILER(CLANG) | |
| 437 #define PassRefPtrWillBePtr Ptr | |
|
Vyacheslav Egorov (Chromium)
2014/01/15 14:21:10
There are two lists which might be a hassle to kee
Mads Ager (chromium)
2014/01/15 14:51:14
That can be done and it sounds like a good idea. I
| |
| 438 #define RefCountedWillBeGarbageCollected GarbageCollected | |
| 439 #define RefCountedWillBeGarbageCollectedFinalized GarbageCollectedFinalized | |
| 440 #define RefPtrWillBePersistent Persistent | |
| 441 #define RefPtrWillBePtr Ptr | |
| 442 #define RefPtrWillBeMember Member | |
| 443 #define PtrWillBeMember Member | |
| 444 #define PtrWillBeWeakMember WeakMember | |
| 445 #define OwnPtrWillBeMember Member | |
| 446 #define PassOwnPtrWillBePtr Ptr | |
| 447 #define NoBaseWillBeGarbageCollected GarbageCollected | |
| 448 #define NoBaseWillBeGarbageCollectedFinalized GarbageCollectedFinalized | |
| 449 #endif // COMPILER(CLANG) | |
| 450 | |
| 451 template<typename T> PassRefPtrWillBePtr<T> adoptRefWillBeNoop(T* ptr) { return PassRefPtrWillBePtr<T>(ptr); } | |
| 452 template<typename T> PassOwnPtrWillBePtr<T> adoptPtrWillBeNoop(T* ptr) { return PassOwnPtrWillBePtr<T>(ptr); } | |
| 453 | |
| 454 #else // !ENABLE_OILPAN | |
| 455 | |
| 456 template<typename T> | |
| 457 class DummyBase { | |
| 458 public: | |
| 459 DummyBase() { } | |
| 460 ~DummyBase() { } | |
| 461 }; | |
| 462 | |
| 463 #if COMPILER(CLANG) | |
| 464 template<typename T> using PassRefPtrWillBePtr = PassRefPtr<T>; | |
| 465 template<typename T> using RefCountedWillBeGarbageCollected = RefCounted<T>; | |
| 466 template<typename T> using RefCountedWillBeGarbageCollectedFinalized = RefCounte d<T>; | |
| 467 template<typename T> using RefPtrWillBePersistent = RefPtr<T>; | |
| 468 template<typename T> using RefPtrWillBePtr = RefPtr<T>; | |
| 469 template<typename T> using RefPtrWillBeMember = RefPtr<T>; | |
| 470 template<typename T> using PtrWillBeMember = Ptr<T>; | |
| 471 template<typename T> using PtrWillBeWeakMember = Ptr<T>; | |
| 472 template<typename T> using OwnPtrWillBeMember = OwnPtr<T>; | |
| 473 template<typename T> using PassOwnPtrWillBePtr = PassOwnPtr<T>; | |
| 474 template<typename T> using NoBaseWillBeGarbageCollected = DummyBase<T>; | |
| 475 template<typename T> using NoBaseWillBeGarbageCollectedFinalized = DummyBase<T>; | |
| 476 #else // !COMPILER(CLANG) | |
| 477 #define PassRefPtrWillBePtr PassRefPtr | |
| 478 #define RefCountedWillBeGarbageCollected RefCounted | |
| 479 #define RefCountedWillBeGarbageCollectedFinalized RefCounted | |
| 480 #define RefPtrWillBePersistent RefPtr | |
| 481 #define RefPtrWillBePtr RefPtr | |
| 482 #define RefPtrWillBeMember RefPtr | |
| 483 #define PtrWillBeMember Ptr | |
| 484 #define PtrWillBeWeakMember Ptr | |
| 485 #define OwnPtrWillBeMember OwnPtr | |
| 486 #define PassOwnPtrWillBePtr PassOwnPtr | |
| 487 #define NoBaseWillBeGarbageCollected DummyBase | |
| 488 #define NoBaseWillBeGarbageCollectedFinalized DummyBase | |
| 489 #endif // COMPILER(CLANG) | |
| 490 | |
| 491 template<typename T> PassRefPtr<T> adoptRefWillBeNoop(T* ptr) { return adoptRef( ptr); } | |
|
jbroman
2014/01/15 14:37:09
nit: Above this is declared as returning PassRefPt
Mads Ager (chromium)
2014/01/15 14:51:14
Yes, that was a typo that happened to be the right
| |
| 492 template<typename T> PassOwnPtrWillBePtr<T> adoptPtrWillBeNoop(T* ptr) { return adoptPtr(ptr); } | |
| 493 | |
| 494 #endif // ENABLE_OILPAN | |
| 495 | |
| 407 } // namespace WebCore | 496 } // namespace WebCore |
| 408 | 497 |
| 409 namespace WTF { | 498 namespace WTF { |
| 410 | 499 |
| 411 template <typename T> struct VectorTraits<WebCore::Member<T> > : VectorTraitsBas e<false, WebCore::Member<T> > { | 500 template <typename T> struct VectorTraits<WebCore::Member<T> > : VectorTraitsBas e<false, WebCore::Member<T> > { |
| 412 static const bool needsDestruction = false; | 501 static const bool needsDestruction = false; |
| 413 static const bool canInitializeWithMemset = true; | 502 static const bool canInitializeWithMemset = true; |
| 414 static const bool canMoveWithMemcpy = true; | 503 static const bool canMoveWithMemcpy = true; |
| 415 }; | 504 }; |
| 416 | 505 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 508 }; | 597 }; |
| 509 | 598 |
| 510 template<typename Key, typename Value, typename Extractor, typename Traits, type name KeyTraits> | 599 template<typename Key, typename Value, typename Extractor, typename Traits, type name KeyTraits> |
| 511 struct IsWeak<WebCore::HeapHashTableBacking<Key, Value, Extractor, Traits, KeyTr aits> > { | 600 struct IsWeak<WebCore::HeapHashTableBacking<Key, Value, Extractor, Traits, KeyTr aits> > { |
| 512 static const bool value = Traits::isWeak; | 601 static const bool value = Traits::isWeak; |
| 513 }; | 602 }; |
| 514 | 603 |
| 515 } // namespace WTF | 604 } // namespace WTF |
| 516 | 605 |
| 517 #endif | 606 #endif |
| OLD | NEW |