Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 GarbageCollected_h | 5 #ifndef GarbageCollected_h |
| 6 #define GarbageCollected_h | 6 #define GarbageCollected_h |
| 7 | 7 |
| 8 #include "platform/heap/ThreadState.h" | 8 #include "platform/heap/ThreadState.h" |
| 9 #include "wtf/Allocator.h" | 9 #include "wtf/Allocator.h" |
| 10 #include "wtf/Assertions.h" | 10 #include "wtf/Assertions.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 // Note that this is only enabled for Member<B>. For Member<A> which we can | 70 // Note that this is only enabled for Member<B>. For Member<A> which we can |
| 71 // compute the object header addr statically, this dynamic dispatch is not used. | 71 // compute the object header addr statically, this dynamic dispatch is not used. |
| 72 // | 72 // |
| 73 class PLATFORM_EXPORT GarbageCollectedMixin { | 73 class PLATFORM_EXPORT GarbageCollectedMixin { |
| 74 public: | 74 public: |
| 75 typedef int IsGarbageCollectedMixinMarker; | 75 typedef int IsGarbageCollectedMixinMarker; |
| 76 virtual void adjustAndMark(Visitor*) const = 0; | 76 virtual void adjustAndMark(Visitor*) const = 0; |
| 77 virtual void trace(Visitor*) {} | 77 virtual void trace(Visitor*) {} |
| 78 virtual void adjustAndMark(InlinedGlobalMarkingVisitor) const = 0; | 78 virtual void adjustAndMark(InlinedGlobalMarkingVisitor) const = 0; |
| 79 virtual void trace(InlinedGlobalMarkingVisitor); | 79 virtual void trace(InlinedGlobalMarkingVisitor); |
| 80 virtual void adjustAndMarkWrapper(const WrapperVisitor*) const = 0; | 80 virtual void adjustAndFullyMarkAndTraceWrapper( |
| 81 const WrapperVisitor*) const = 0; | |
| 82 virtual void adjustAndMarkWrapperHeaderOnly(const WrapperVisitor*) const = 0; | |
| 83 virtual void adjustAndFinishMarkAndTraceMarkedWrapper( | |
| 84 const WrapperVisitor*) const = 0; | |
| 81 virtual bool isHeapObjectAlive() const = 0; | 85 virtual bool isHeapObjectAlive() const = 0; |
| 82 virtual HeapObjectHeader* adjustAndGetHeapObjectHeader() const = 0; | 86 virtual HeapObjectHeader* adjustAndGetHeapObjectHeader() const = 0; |
| 83 }; | 87 }; |
| 84 | 88 |
| 85 #define DEFINE_GARBAGE_COLLECTED_MIXIN_METHODS(VISITOR, TYPE) \ | 89 #define DEFINE_GARBAGE_COLLECTED_MIXIN_METHODS(VISITOR, TYPE) \ |
| 86 public: \ | 90 public: \ |
| 87 void adjustAndMark(VISITOR visitor) const override { \ | 91 void adjustAndMark(VISITOR visitor) const override { \ |
| 88 typedef WTF::IsSubclassOfTemplate<typename std::remove_const<TYPE>::type, \ | 92 typedef WTF::IsSubclassOfTemplate<typename std::remove_const<TYPE>::type, \ |
| 89 blink::GarbageCollected> \ | 93 blink::GarbageCollected> \ |
| 90 IsSubclassOfGarbageCollected; \ | 94 IsSubclassOfGarbageCollected; \ |
| 91 static_assert( \ | 95 static_assert( \ |
| 92 IsSubclassOfGarbageCollected::value, \ | 96 IsSubclassOfGarbageCollected::value, \ |
| 93 "only garbage collected objects can have garbage collected mixins"); \ | 97 "only garbage collected objects can have garbage collected mixins"); \ |
| 94 if (TraceEagerlyTrait<TYPE>::value) { \ | 98 if (TraceEagerlyTrait<TYPE>::value) { \ |
| 95 if (visitor->ensureMarked(static_cast<const TYPE*>(this))) \ | 99 if (visitor->ensureMarked(static_cast<const TYPE*>(this))) \ |
| 96 TraceTrait<TYPE>::trace(visitor, const_cast<TYPE*>(this)); \ | 100 TraceTrait<TYPE>::trace(visitor, const_cast<TYPE*>(this)); \ |
| 97 return; \ | 101 return; \ |
| 98 } \ | 102 } \ |
| 99 visitor->mark(static_cast<const TYPE*>(this), \ | 103 visitor->mark(static_cast<const TYPE*>(this), \ |
| 100 &blink::TraceTrait<TYPE>::trace); \ | 104 &blink::TraceTrait<TYPE>::trace); \ |
| 101 } \ | 105 } \ |
| 102 \ | 106 \ |
| 103 private: | 107 private: |
| 104 | 108 |
| 105 #define DEFINE_GARBAGE_COLLECTED_MIXIN_WRAPPER_METHODS(TYPE) \ | 109 #define DEFINE_GARBAGE_COLLECTED_MIXIN_WRAPPER_METHODS(TYPE) \ |
| 106 public: \ | 110 private: \ |
| 107 void adjustAndMarkWrapper(const WrapperVisitor* visitor) const override { \ | 111 typedef WTF::IsSubclassOfTemplate<typename std::remove_const<TYPE>::type, \ |
| 108 typedef WTF::IsSubclassOfTemplate<typename std::remove_const<TYPE>::type, \ | 112 blink::GarbageCollected> \ |
| 109 blink::GarbageCollected> \ | 113 IsSubclassOfGarbageCollected; \ |
| 110 IsSubclassOfGarbageCollected; \ | 114 \ |
| 111 static_assert( \ | 115 public: \ |
| 112 IsSubclassOfGarbageCollected::value, \ | 116 void adjustAndFullyMarkAndTraceWrapper(const WrapperVisitor* visitor) \ |
|
Michael Lippautz
2016/12/20 15:10:30
Ideally we could use covariant return types here.
| |
| 113 "only garbage collected objects can have garbage collected mixins"); \ | 117 const override { \ |
| 114 AdjustAndMarkTrait<TYPE>::markWrapper(visitor, \ | 118 static_assert( \ |
| 115 static_cast<const TYPE*>(this)); \ | 119 IsSubclassOfGarbageCollected::value, \ |
| 116 } \ | 120 "only garbage collected objects can have garbage collected mixins"); \ |
| 117 HeapObjectHeader* adjustAndGetHeapObjectHeader() const override { \ | 121 return AdjustAndMarkTrait<TYPE>::fullyMarkAndTraceWrapper( \ |
| 118 typedef WTF::IsSubclassOfTemplate<typename std::remove_const<TYPE>::type, \ | 122 visitor, static_cast<const TYPE*>(this)); \ |
| 119 blink::GarbageCollected> \ | 123 } \ |
| 120 IsSubclassOfGarbageCollected; \ | 124 void adjustAndMarkWrapperHeaderOnly(const WrapperVisitor* visitor) \ |
| 121 static_assert( \ | 125 const override { \ |
| 122 IsSubclassOfGarbageCollected::value, \ | 126 static_assert( \ |
| 123 "only garbage collected objects can have garbage collected mixins"); \ | 127 IsSubclassOfGarbageCollected::value, \ |
| 124 return AdjustAndMarkTrait<TYPE>::heapObjectHeader( \ | 128 "only garbage collected objects can have garbage collected mixins"); \ |
| 125 static_cast<const TYPE*>(this)); \ | 129 return AdjustAndMarkTrait<TYPE>::markWrapperHeaderOnly( \ |
| 126 } \ | 130 visitor, static_cast<const TYPE*>(this)); \ |
| 127 \ | 131 } \ |
| 132 void adjustAndFinishMarkAndTraceMarkedWrapper(const WrapperVisitor* visitor) \ | |
| 133 const override { \ | |
| 134 static_assert( \ | |
| 135 IsSubclassOfGarbageCollected::value, \ | |
| 136 "only garbage collected objects can have garbage collected mixins"); \ | |
| 137 AdjustAndMarkTrait<TYPE>::finishMarkAndTraceMarkedWrapper( \ | |
| 138 visitor, static_cast<const TYPE*>(this)); \ | |
| 139 } \ | |
| 140 HeapObjectHeader* adjustAndGetHeapObjectHeader() const override { \ | |
| 141 static_assert( \ | |
| 142 IsSubclassOfGarbageCollected::value, \ | |
| 143 "only garbage collected objects can have garbage collected mixins"); \ | |
| 144 return AdjustAndMarkTrait<TYPE>::heapObjectHeader( \ | |
| 145 static_cast<const TYPE*>(this)); \ | |
| 146 } \ | |
| 147 \ | |
| 128 private: | 148 private: |
| 129 | 149 |
| 130 // A C++ object's vptr will be initialized to its leftmost base's vtable after | 150 // A C++ object's vptr will be initialized to its leftmost base's vtable after |
| 131 // the constructors of all its subclasses have run, so if a subclass constructor | 151 // the constructors of all its subclasses have run, so if a subclass constructor |
| 132 // tries to access any of the vtbl entries of its leftmost base prematurely, | 152 // tries to access any of the vtbl entries of its leftmost base prematurely, |
| 133 // it'll find an as-yet incorrect vptr and fail. Which is exactly what a | 153 // it'll find an as-yet incorrect vptr and fail. Which is exactly what a |
| 134 // garbage collector will try to do if it tries to access the leftmost base | 154 // garbage collector will try to do if it tries to access the leftmost base |
| 135 // while one of the subclass constructors of a GC mixin object triggers a GC. | 155 // while one of the subclass constructors of a GC mixin object triggers a GC. |
| 136 // It is consequently not safe to allow any GCs while these objects are under | 156 // It is consequently not safe to allow any GCs while these objects are under |
| 137 // (sub constructor) construction. | 157 // (sub constructor) construction. |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 324 static FalseType isSizeofKnown(...); | 344 static FalseType isSizeofKnown(...); |
| 325 static T& t; | 345 static T& t; |
| 326 | 346 |
| 327 public: | 347 public: |
| 328 static const bool value = sizeof(TrueType) == sizeof(isSizeofKnown(&t)); | 348 static const bool value = sizeof(TrueType) == sizeof(isSizeofKnown(&t)); |
| 329 }; | 349 }; |
| 330 | 350 |
| 331 } // namespace blink | 351 } // namespace blink |
| 332 | 352 |
| 333 #endif | 353 #endif |
| OLD | NEW |