| 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 adjustAndMarkAndTraceWrapper(const WrapperVisitor*) const = 0; |
| 81 virtual void adjustAndMarkWrapperNoTracing(const WrapperVisitor*) const = 0; |
| 82 virtual void adjustAndTraceMarkedWrapper(const WrapperVisitor*) const = 0; |
| 81 virtual bool isHeapObjectAlive() const = 0; | 83 virtual bool isHeapObjectAlive() const = 0; |
| 82 virtual HeapObjectHeader* adjustAndGetHeapObjectHeader() const = 0; | 84 virtual HeapObjectHeader* adjustAndGetHeapObjectHeader() const = 0; |
| 83 }; | 85 }; |
| 84 | 86 |
| 85 #define DEFINE_GARBAGE_COLLECTED_MIXIN_METHODS(VISITOR, TYPE) \ | 87 #define DEFINE_GARBAGE_COLLECTED_MIXIN_METHODS(VISITOR, TYPE) \ |
| 86 public: \ | 88 public: \ |
| 87 void adjustAndMark(VISITOR visitor) const override { \ | 89 void adjustAndMark(VISITOR visitor) const override { \ |
| 88 typedef WTF::IsSubclassOfTemplate<typename std::remove_const<TYPE>::type, \ | 90 typedef WTF::IsSubclassOfTemplate<typename std::remove_const<TYPE>::type, \ |
| 89 blink::GarbageCollected> \ | 91 blink::GarbageCollected> \ |
| 90 IsSubclassOfGarbageCollected; \ | 92 IsSubclassOfGarbageCollected; \ |
| 91 static_assert( \ | 93 static_assert( \ |
| 92 IsSubclassOfGarbageCollected::value, \ | 94 IsSubclassOfGarbageCollected::value, \ |
| 93 "only garbage collected objects can have garbage collected mixins"); \ | 95 "only garbage collected objects can have garbage collected mixins"); \ |
| 94 if (TraceEagerlyTrait<TYPE>::value) { \ | 96 if (TraceEagerlyTrait<TYPE>::value) { \ |
| 95 if (visitor->ensureMarked(static_cast<const TYPE*>(this))) \ | 97 if (visitor->ensureMarked(static_cast<const TYPE*>(this))) \ |
| 96 TraceTrait<TYPE>::trace(visitor, const_cast<TYPE*>(this)); \ | 98 TraceTrait<TYPE>::trace(visitor, const_cast<TYPE*>(this)); \ |
| 97 return; \ | 99 return; \ |
| 98 } \ | 100 } \ |
| 99 visitor->mark(static_cast<const TYPE*>(this), \ | 101 visitor->mark(static_cast<const TYPE*>(this), \ |
| 100 &blink::TraceTrait<TYPE>::trace); \ | 102 &blink::TraceTrait<TYPE>::trace); \ |
| 101 } \ | 103 } \ |
| 102 \ | 104 \ |
| 103 private: | 105 private: |
| 104 | 106 |
| 105 #define DEFINE_GARBAGE_COLLECTED_MIXIN_WRAPPER_METHODS(TYPE) \ | 107 #define DEFINE_GARBAGE_COLLECTED_MIXIN_WRAPPER_METHODS(TYPE) \ |
| 106 public: \ | 108 private: \ |
| 107 void adjustAndMarkWrapper(const WrapperVisitor* visitor) const override { \ | 109 typedef WTF::IsSubclassOfTemplate<typename std::remove_const<TYPE>::type, \ |
| 108 typedef WTF::IsSubclassOfTemplate<typename std::remove_const<TYPE>::type, \ | 110 blink::GarbageCollected> \ |
| 109 blink::GarbageCollected> \ | 111 IsSubclassOfGarbageCollected; \ |
| 110 IsSubclassOfGarbageCollected; \ | 112 \ |
| 111 static_assert( \ | 113 public: \ |
| 112 IsSubclassOfGarbageCollected::value, \ | 114 void adjustAndMarkAndTraceWrapper(const WrapperVisitor* visitor) \ |
| 113 "only garbage collected objects can have garbage collected mixins"); \ | 115 const override { \ |
| 114 AdjustAndMarkTrait<TYPE>::markWrapper(visitor, \ | 116 static_assert( \ |
| 115 static_cast<const TYPE*>(this)); \ | 117 IsSubclassOfGarbageCollected::value, \ |
| 116 } \ | 118 "only garbage collected objects can have garbage collected mixins"); \ |
| 117 HeapObjectHeader* adjustAndGetHeapObjectHeader() const override { \ | 119 return AdjustAndMarkTrait<TYPE>::markAndTraceWrapper( \ |
| 118 typedef WTF::IsSubclassOfTemplate<typename std::remove_const<TYPE>::type, \ | 120 visitor, static_cast<const TYPE*>(this)); \ |
| 119 blink::GarbageCollected> \ | 121 } \ |
| 120 IsSubclassOfGarbageCollected; \ | 122 void adjustAndMarkWrapperNoTracing(const WrapperVisitor* visitor) \ |
| 121 static_assert( \ | 123 const override { \ |
| 122 IsSubclassOfGarbageCollected::value, \ | 124 static_assert( \ |
| 123 "only garbage collected objects can have garbage collected mixins"); \ | 125 IsSubclassOfGarbageCollected::value, \ |
| 124 return AdjustAndMarkTrait<TYPE>::heapObjectHeader( \ | 126 "only garbage collected objects can have garbage collected mixins"); \ |
| 125 static_cast<const TYPE*>(this)); \ | 127 return AdjustAndMarkTrait<TYPE>::markWrapperNoTracing( \ |
| 126 } \ | 128 visitor, static_cast<const TYPE*>(this)); \ |
| 127 \ | 129 } \ |
| 130 void adjustAndTraceMarkedWrapper(const WrapperVisitor* visitor) \ |
| 131 const override { \ |
| 132 static_assert( \ |
| 133 IsSubclassOfGarbageCollected::value, \ |
| 134 "only garbage collected objects can have garbage collected mixins"); \ |
| 135 AdjustAndMarkTrait<TYPE>::traceMarkedWrapper( \ |
| 136 visitor, static_cast<const TYPE*>(this)); \ |
| 137 } \ |
| 138 HeapObjectHeader* adjustAndGetHeapObjectHeader() const override { \ |
| 139 static_assert( \ |
| 140 IsSubclassOfGarbageCollected::value, \ |
| 141 "only garbage collected objects can have garbage collected mixins"); \ |
| 142 return AdjustAndMarkTrait<TYPE>::heapObjectHeader( \ |
| 143 static_cast<const TYPE*>(this)); \ |
| 144 } \ |
| 145 \ |
| 128 private: | 146 private: |
| 129 | 147 |
| 130 // A C++ object's vptr will be initialized to its leftmost base's vtable after | 148 // 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 | 149 // 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, | 150 // 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 | 151 // 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 | 152 // 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. | 153 // 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 | 154 // It is consequently not safe to allow any GCs while these objects are under |
| 137 // (sub constructor) construction. | 155 // (sub constructor) construction. |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 static FalseType isSizeofKnown(...); | 342 static FalseType isSizeofKnown(...); |
| 325 static T& t; | 343 static T& t; |
| 326 | 344 |
| 327 public: | 345 public: |
| 328 static const bool value = sizeof(TrueType) == sizeof(isSizeofKnown(&t)); | 346 static const bool value = sizeof(TrueType) == sizeof(isSizeofKnown(&t)); |
| 329 }; | 347 }; |
| 330 | 348 |
| 331 } // namespace blink | 349 } // namespace blink |
| 332 | 350 |
| 333 #endif | 351 #endif |
| OLD | NEW |