| 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 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 Member() : m_raw(nullptr) | 559 Member() : m_raw(nullptr) |
| 560 { | 560 { |
| 561 } | 561 } |
| 562 | 562 |
| 563 Member(std::nullptr_t) : m_raw(nullptr) | 563 Member(std::nullptr_t) : m_raw(nullptr) |
| 564 { | 564 { |
| 565 } | 565 } |
| 566 | 566 |
| 567 Member(T* raw) : m_raw(raw) | 567 Member(T* raw) : m_raw(raw) |
| 568 { | 568 { |
| 569 // HashTable can store a special value to Member<> to represent | 569 checkPointer(); |
| 570 // a deleted entry. The special value is not aligned to the allocation | |
| 571 // granularity. The following ASSERT is checking that m_raw is either of
: | |
| 572 // - nullptr | |
| 573 // - a special value to represent a deleted entry of a HashTable | |
| 574 // - a valid pointer to the heap | |
| 575 ASSERT(!m_raw || reinterpret_cast<intptr_t>(m_raw) % allocationGranulari
ty || Heap::findPageFromAddress(m_raw)); | |
| 576 } | 570 } |
| 577 | 571 |
| 578 explicit Member(T& raw) : m_raw(&raw) | 572 explicit Member(T& raw) : m_raw(&raw) |
| 579 { | 573 { |
| 580 // See the comment above. | 574 checkPointer(); |
| 581 ASSERT(!m_raw || reinterpret_cast<intptr_t>(m_raw) % allocationGranulari
ty || Heap::findPageFromAddress(m_raw)); | |
| 582 } | 575 } |
| 583 | 576 |
| 584 template<typename U> | 577 template<typename U> |
| 585 Member(const RawPtr<U>& other) : m_raw(other.get()) | 578 Member(const RawPtr<U>& other) : m_raw(other.get()) |
| 586 { | 579 { |
| 580 checkPointer(); |
| 587 } | 581 } |
| 588 | 582 |
| 589 Member(WTF::HashTableDeletedValueType) : m_raw(reinterpret_cast<T*>(-1)) | 583 Member(WTF::HashTableDeletedValueType) : m_raw(reinterpret_cast<T*>(-1)) |
| 590 { | 584 { |
| 591 } | 585 } |
| 592 | 586 |
| 593 bool isHashTableDeletedValue() const { return m_raw == reinterpret_cast<T*>(
-1); } | 587 bool isHashTableDeletedValue() const { return m_raw == reinterpret_cast<T*>(
-1); } |
| 594 | 588 |
| 595 template<typename U> | 589 template<typename U> |
| 596 Member(const Persistent<U>& other) : m_raw(other) { } | 590 Member(const Persistent<U>& other) : m_raw(other) |
| 591 { |
| 592 checkPointer(); |
| 593 } |
| 597 | 594 |
| 598 Member(const Member& other) : m_raw(other) { } | 595 Member(const Member& other) : m_raw(other) |
| 596 { |
| 597 checkPointer(); |
| 598 } |
| 599 | 599 |
| 600 template<typename U> | 600 template<typename U> |
| 601 Member(const Member<U>& other) : m_raw(other) { } | 601 Member(const Member<U>& other) : m_raw(other) |
| 602 { |
| 603 checkPointer(); |
| 604 } |
| 602 | 605 |
| 603 T* release() | 606 T* release() |
| 604 { | 607 { |
| 605 T* result = m_raw; | 608 T* result = m_raw; |
| 606 m_raw = nullptr; | 609 m_raw = nullptr; |
| 607 return result; | 610 return result; |
| 608 } | 611 } |
| 609 | 612 |
| 610 bool operator!() const { return !m_raw; } | 613 bool operator!() const { return !m_raw; } |
| 611 | 614 |
| 612 operator T*() const { return m_raw; } | 615 operator T*() const { return m_raw; } |
| 613 | 616 |
| 614 T* operator->() const { return m_raw; } | 617 T* operator->() const { return m_raw; } |
| 615 T& operator*() const { return *m_raw; } | 618 T& operator*() const { return *m_raw; } |
| 616 template<typename U> | 619 template<typename U> |
| 617 operator RawPtr<U>() const { return m_raw; } | 620 operator RawPtr<U>() const { return m_raw; } |
| 618 | 621 |
| 619 template<typename U> | 622 template<typename U> |
| 620 Member& operator=(const Persistent<U>& other) | 623 Member& operator=(const Persistent<U>& other) |
| 621 { | 624 { |
| 622 m_raw = other; | 625 m_raw = other; |
| 626 checkPointer(); |
| 623 return *this; | 627 return *this; |
| 624 } | 628 } |
| 625 | 629 |
| 626 template<typename U> | 630 template<typename U> |
| 627 Member& operator=(const Member<U>& other) | 631 Member& operator=(const Member<U>& other) |
| 628 { | 632 { |
| 629 m_raw = other; | 633 m_raw = other; |
| 634 checkPointer(); |
| 630 return *this; | 635 return *this; |
| 631 } | 636 } |
| 632 | 637 |
| 633 template<typename U> | 638 template<typename U> |
| 634 Member& operator=(U* other) | 639 Member& operator=(U* other) |
| 635 { | 640 { |
| 636 m_raw = other; | 641 m_raw = other; |
| 642 checkPointer(); |
| 637 return *this; | 643 return *this; |
| 638 } | 644 } |
| 639 | 645 |
| 640 template<typename U> | 646 template<typename U> |
| 641 Member& operator=(RawPtr<U> other) | 647 Member& operator=(RawPtr<U> other) |
| 642 { | 648 { |
| 643 m_raw = other; | 649 m_raw = other; |
| 650 checkPointer(); |
| 644 return *this; | 651 return *this; |
| 645 } | 652 } |
| 646 | 653 |
| 647 Member& operator=(std::nullptr_t) | 654 Member& operator=(std::nullptr_t) |
| 648 { | 655 { |
| 649 m_raw = nullptr; | 656 m_raw = nullptr; |
| 650 return *this; | 657 return *this; |
| 651 } | 658 } |
| 652 | 659 |
| 653 void swap(Member<T>& other) { std::swap(m_raw, other.m_raw); } | 660 void swap(Member<T>& other) |
| 661 { |
| 662 std::swap(m_raw, other.m_raw); |
| 663 checkPointer(); |
| 664 } |
| 654 | 665 |
| 655 T* get() const { return m_raw; } | 666 T* get() const { return m_raw; } |
| 656 | 667 |
| 657 void clear() { m_raw = nullptr; } | 668 void clear() { m_raw = nullptr; } |
| 658 | 669 |
| 659 | 670 |
| 660 protected: | 671 protected: |
| 672 void checkPointer() |
| 673 { |
| 674 #if ENABLE(ASSERT) |
| 675 if (!m_raw) |
| 676 return; |
| 677 // HashTable can store a special value (which is not aligned to the |
| 678 // allocation granularity) to Member<> to represent a deleted entry. |
| 679 // Thus we treat a pointer that is not aligned to the granularity |
| 680 // as a valid pointer. |
| 681 if (reinterpret_cast<intptr_t>(m_raw) % allocationGranularity) |
| 682 return; |
| 683 |
| 684 // TODO(haraken): What we really want to check here is that the pointer |
| 685 // is a traceable object. In other words, the pointer is either of: |
| 686 // |
| 687 // (a) a pointer to the head of an on-heap object. |
| 688 // (b) a pointer to the head of an on-heap mixin object. |
| 689 // |
| 690 // We can check it by calling visitor->isHeapObjectAlive(m_raw), |
| 691 // but we cannot call it here because it requres to include T.h. |
| 692 // So we currently implement only the check for (a). |
| 693 if (!IsGarbageCollectedMixin<T>::value) |
| 694 HeapObjectHeader::fromPayload(m_raw)->checkHeader(); |
| 695 #endif |
| 696 } |
| 697 |
| 661 T* m_raw; | 698 T* m_raw; |
| 662 | 699 |
| 663 template<bool x, WTF::WeakHandlingFlag y, WTF::ShouldWeakPointersBeMarkedStr
ongly z, typename U, typename V> friend struct CollectionBackingTraceTrait; | 700 template<bool x, WTF::WeakHandlingFlag y, WTF::ShouldWeakPointersBeMarkedStr
ongly z, typename U, typename V> friend struct CollectionBackingTraceTrait; |
| 664 friend class Visitor; | 701 friend class Visitor; |
| 702 |
| 665 }; | 703 }; |
| 666 | 704 |
| 667 // WeakMember is similar to Member in that it is used to point to other oilpan | 705 // WeakMember is similar to Member in that it is used to point to other oilpan |
| 668 // heap allocated objects. | 706 // heap allocated objects. |
| 669 // However instead of creating a strong pointer to the object, the WeakMember cr
eates | 707 // However instead of creating a strong pointer to the object, the WeakMember cr
eates |
| 670 // a weak pointer, which does not keep the pointee alive. Hence if all pointers
to | 708 // a weak pointer, which does not keep the pointee alive. Hence if all pointers
to |
| 671 // to a heap allocated object are weak the object will be garbage collected. At
the | 709 // to a heap allocated object are weak the object will be garbage collected. At
the |
| 672 // time of GC the weak pointers will automatically be set to null. | 710 // time of GC the weak pointers will automatically be set to null. |
| 673 template<typename T> | 711 template<typename T> |
| 674 class WeakMember : public Member<T> { | 712 class WeakMember : public Member<T> { |
| 675 public: | 713 public: |
| 676 WeakMember() : Member<T>() { } | 714 WeakMember() : Member<T>() { } |
| 677 | 715 |
| 678 WeakMember(std::nullptr_t) : Member<T>(nullptr) { } | 716 WeakMember(std::nullptr_t) : Member<T>(nullptr) { } |
| 679 | 717 |
| 680 WeakMember(T* raw) : Member<T>(raw) { } | 718 WeakMember(T* raw) : Member<T>(raw) { } |
| 681 | 719 |
| 682 WeakMember(WTF::HashTableDeletedValueType x) : Member<T>(x) { } | 720 WeakMember(WTF::HashTableDeletedValueType x) : Member<T>(x) { } |
| 683 | 721 |
| 684 template<typename U> | 722 template<typename U> |
| 685 WeakMember(const Persistent<U>& other) : Member<T>(other) { } | 723 WeakMember(const Persistent<U>& other) : Member<T>(other) { } |
| 686 | 724 |
| 687 template<typename U> | 725 template<typename U> |
| 688 WeakMember(const Member<U>& other) : Member<T>(other) { } | 726 WeakMember(const Member<U>& other) : Member<T>(other) { } |
| 689 | 727 |
| 690 template<typename U> | 728 template<typename U> |
| 691 WeakMember& operator=(const Persistent<U>& other) | 729 WeakMember& operator=(const Persistent<U>& other) |
| 692 { | 730 { |
| 693 this->m_raw = other; | 731 this->m_raw = other; |
| 732 this->checkPointer(); |
| 694 return *this; | 733 return *this; |
| 695 } | 734 } |
| 696 | 735 |
| 697 template<typename U> | 736 template<typename U> |
| 698 WeakMember& operator=(const Member<U>& other) | 737 WeakMember& operator=(const Member<U>& other) |
| 699 { | 738 { |
| 700 this->m_raw = other; | 739 this->m_raw = other; |
| 740 this->checkPointer(); |
| 701 return *this; | 741 return *this; |
| 702 } | 742 } |
| 703 | 743 |
| 704 template<typename U> | 744 template<typename U> |
| 705 WeakMember& operator=(U* other) | 745 WeakMember& operator=(U* other) |
| 706 { | 746 { |
| 707 this->m_raw = other; | 747 this->m_raw = other; |
| 748 this->checkPointer(); |
| 708 return *this; | 749 return *this; |
| 709 } | 750 } |
| 710 | 751 |
| 711 template<typename U> | 752 template<typename U> |
| 712 WeakMember& operator=(const RawPtr<U>& other) | 753 WeakMember& operator=(const RawPtr<U>& other) |
| 713 { | 754 { |
| 714 this->m_raw = other; | 755 this->m_raw = other; |
| 756 this->checkPointer(); |
| 715 return *this; | 757 return *this; |
| 716 } | 758 } |
| 717 | 759 |
| 718 WeakMember& operator=(std::nullptr_t) | 760 WeakMember& operator=(std::nullptr_t) |
| 719 { | 761 { |
| 720 this->m_raw = nullptr; | 762 this->m_raw = nullptr; |
| 721 return *this; | 763 return *this; |
| 722 } | 764 } |
| 723 | 765 |
| 724 private: | 766 private: |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1138 struct ParamStorageTraits<RawPtr<T>> : public PointerParamStorageTraits<T*, blin
k::IsGarbageCollectedType<T>::value> { | 1180 struct ParamStorageTraits<RawPtr<T>> : public PointerParamStorageTraits<T*, blin
k::IsGarbageCollectedType<T>::value> { |
| 1139 static_assert(sizeof(T), "T must be fully defined"); | 1181 static_assert(sizeof(T), "T must be fully defined"); |
| 1140 }; | 1182 }; |
| 1141 | 1183 |
| 1142 template<typename T> | 1184 template<typename T> |
| 1143 PassRefPtr<T> adoptRef(blink::RefCountedGarbageCollected<T>*) = delete; | 1185 PassRefPtr<T> adoptRef(blink::RefCountedGarbageCollected<T>*) = delete; |
| 1144 | 1186 |
| 1145 } // namespace WTF | 1187 } // namespace WTF |
| 1146 | 1188 |
| 1147 #endif | 1189 #endif |
| OLD | NEW |