| 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 // compute the object header addr statically, this dynamic dispatch is not used. | 121 // compute the object header addr statically, this dynamic dispatch is not used. |
| 122 class PLATFORM_EXPORT GarbageCollectedMixin { | 122 class PLATFORM_EXPORT GarbageCollectedMixin { |
| 123 IS_GARBAGE_COLLECTED_TYPE(); | 123 IS_GARBAGE_COLLECTED_TYPE(); |
| 124 public: | 124 public: |
| 125 typedef int IsGarbageCollectedMixinMarker; | 125 typedef int IsGarbageCollectedMixinMarker; |
| 126 virtual void adjustAndMark(Visitor*) const = 0; | 126 virtual void adjustAndMark(Visitor*) const = 0; |
| 127 virtual void trace(Visitor*) { } | 127 virtual void trace(Visitor*) { } |
| 128 virtual void adjustAndMark(InlinedGlobalMarkingVisitor) const = 0; | 128 virtual void adjustAndMark(InlinedGlobalMarkingVisitor) const = 0; |
| 129 virtual void trace(InlinedGlobalMarkingVisitor); | 129 virtual void trace(InlinedGlobalMarkingVisitor); |
| 130 virtual bool isHeapObjectAlive() const = 0; | 130 virtual bool isHeapObjectAlive() const = 0; |
| 131 virtual HeapObjectHeader* heapObjectHeader() const = 0; |
| 131 }; | 132 }; |
| 132 | 133 |
| 133 #define DEFINE_GARBAGE_COLLECTED_MIXIN_METHODS(VISITOR, TYPE) \ | 134 #define DEFINE_GARBAGE_COLLECTED_MIXIN_METHODS(VISITOR, TYPE) \ |
| 134 public: \ | 135 public: \ |
| 135 void adjustAndMark(VISITOR visitor) const override \ | 136 void adjustAndMark(VISITOR visitor) const override \ |
| 136 { \ | 137 { \ |
| 137 typedef WTF::IsSubclassOfTemplate<typename WTF::RemoveConst<TYPE>::Type,
blink::GarbageCollected> IsSubclassOfGarbageCollected; \ | 138 typedef WTF::IsSubclassOfTemplate<typename WTF::RemoveConst<TYPE>::Type,
blink::GarbageCollected> IsSubclassOfGarbageCollected; \ |
| 138 static_assert(IsSubclassOfGarbageCollected::value, "only garbage collect
ed objects can have garbage collected mixins"); \ | 139 static_assert(IsSubclassOfGarbageCollected::value, "only garbage collect
ed objects can have garbage collected mixins"); \ |
| 139 if (TraceEagerlyTrait<TYPE>::value) { \ | 140 if (TraceEagerlyTrait<TYPE>::value) { \ |
| 140 if (visitor->ensureMarked(static_cast<const TYPE*>(this))) \ | 141 if (visitor->ensureMarked(static_cast<const TYPE*>(this))) \ |
| (...skipping 23 matching lines...) Expand all Loading... |
| 164 // GarbageCollectedMixinConstructorMarker's constructor takes care of | 165 // GarbageCollectedMixinConstructorMarker's constructor takes care of |
| 165 // this and the field is declared by way of USING_GARBAGE_COLLECTED_MIXIN(). | 166 // this and the field is declared by way of USING_GARBAGE_COLLECTED_MIXIN(). |
| 166 | 167 |
| 167 #define DEFINE_GARBAGE_COLLECTED_MIXIN_CONSTRUCTOR_MARKER(TYPE) \ | 168 #define DEFINE_GARBAGE_COLLECTED_MIXIN_CONSTRUCTOR_MARKER(TYPE) \ |
| 168 public: \ | 169 public: \ |
| 169 GC_PLUGIN_IGNORE("crbug.com/456823") NO_SANITIZE_UNRELATED_CAST \ | 170 GC_PLUGIN_IGNORE("crbug.com/456823") NO_SANITIZE_UNRELATED_CAST \ |
| 170 void* operator new(size_t size) \ | 171 void* operator new(size_t size) \ |
| 171 { \ | 172 { \ |
| 172 void* object = TYPE::allocateObject(size, IsEagerlyFinalizedType<TYPE>::
value); \ | 173 void* object = TYPE::allocateObject(size, IsEagerlyFinalizedType<TYPE>::
value); \ |
| 173 ThreadState* state = ThreadStateFor<ThreadingTrait<TYPE>::Affinity>::sta
te(); \ | 174 ThreadState* state = ThreadStateFor<ThreadingTrait<TYPE>::Affinity>::sta
te(); \ |
| 174 state->enterGCForbiddenScopeIfNeeded(&(reinterpret_cast<TYPE*>(object)->
m_mixinConstructorMarker)); \ | 175 state->startConstructingGCMixin(&(reinterpret_cast<TYPE*>(object)->m_mix
inConstructorMarker)); \ |
| 175 return object; \ | 176 return object; \ |
| 176 } \ | 177 } \ |
| 177 GarbageCollectedMixinConstructorMarker m_mixinConstructorMarker; \ | 178 GarbageCollectedMixinConstructorMarker m_mixinConstructorMarker; \ |
| 178 private: | 179 private: |
| 179 | 180 |
| 180 // Mixins that wrap/nest others requires extra handling: | 181 // Mixins that wrap/nest others requires extra handling: |
| 181 // | 182 // |
| 182 // class A : public GarbageCollected<A>, public GarbageCollectedMixin { | 183 // class A : public GarbageCollected<A>, public GarbageCollectedMixin { |
| 183 // USING_GARBAGE_COLLECTED_MIXIN(A); | 184 // USING_GARBAGE_COLLECTED_MIXIN(A); |
| 184 // ... | 185 // ... |
| (...skipping 13 matching lines...) Expand all Loading... |
| 198 // runs. | 199 // runs. |
| 199 #define USING_GARBAGE_COLLECTED_MIXIN(TYPE) \ | 200 #define USING_GARBAGE_COLLECTED_MIXIN(TYPE) \ |
| 200 DEFINE_GARBAGE_COLLECTED_MIXIN_METHODS(blink::Visitor*, TYPE) \ | 201 DEFINE_GARBAGE_COLLECTED_MIXIN_METHODS(blink::Visitor*, TYPE) \ |
| 201 DEFINE_GARBAGE_COLLECTED_MIXIN_METHODS(blink::InlinedGlobalMarkingVisitor, T
YPE) \ | 202 DEFINE_GARBAGE_COLLECTED_MIXIN_METHODS(blink::InlinedGlobalMarkingVisitor, T
YPE) \ |
| 202 DEFINE_GARBAGE_COLLECTED_MIXIN_CONSTRUCTOR_MARKER(TYPE) \ | 203 DEFINE_GARBAGE_COLLECTED_MIXIN_CONSTRUCTOR_MARKER(TYPE) \ |
| 203 public: \ | 204 public: \ |
| 204 bool isHeapObjectAlive() const override \ | 205 bool isHeapObjectAlive() const override \ |
| 205 { \ | 206 { \ |
| 206 return Heap::isHeapObjectAlive(this); \ | 207 return Heap::isHeapObjectAlive(this); \ |
| 207 } \ | 208 } \ |
| 209 HeapObjectHeader* heapObjectHeader() const override \ |
| 210 { \ |
| 211 return HeapObjectHeader::fromPayload(this); \ |
| 212 } \ |
| 208 private: | 213 private: |
| 209 | 214 |
| 210 #if ENABLE(OILPAN) | 215 #if ENABLE(OILPAN) |
| 211 #define WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(TYPE) USING_GARBAGE_COLLECTED_MIXI
N(TYPE) | 216 #define WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(TYPE) USING_GARBAGE_COLLECTED_MIXI
N(TYPE) |
| 212 #else | 217 #else |
| 213 #define WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(TYPE) | 218 #define WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(TYPE) |
| 214 #endif | 219 #endif |
| 215 | 220 |
| 216 // An empty class with a constructor that's arranged invoked when all derived co
nstructors | 221 // An empty class with a constructor that's arranged invoked when all derived co
nstructors |
| 217 // of a mixin instance have completed and it is safe to allow GCs again. See | 222 // of a mixin instance have completed and it is safe to allow GCs again. See |
| 218 // AllocateObjectTrait<> comment for more. | 223 // AllocateObjectTrait<> comment for more. |
| 219 // | 224 // |
| 220 // USING_GARBAGE_COLLECTED_MIXIN() declares a GarbageCollectedMixinConstructorMa
rker<> private | 225 // USING_GARBAGE_COLLECTED_MIXIN() declares a GarbageCollectedMixinConstructorMa
rker<> private |
| 221 // field. By following Blink convention of using the macro at the top of a class
declaration, | 226 // field. By following Blink convention of using the macro at the top of a class
declaration, |
| 222 // its constructor will run first. | 227 // its constructor will run first. |
| 223 class GarbageCollectedMixinConstructorMarker { | 228 class GarbageCollectedMixinConstructorMarker { |
| 224 public: | 229 public: |
| 225 GarbageCollectedMixinConstructorMarker() | 230 GarbageCollectedMixinConstructorMarker() |
| 226 { | 231 { |
| 227 // FIXME: if prompt conservative GCs are needed, forced GCs that | 232 // FIXME: if prompt conservative GCs are needed, forced GCs that |
| 228 // were denied while within this scope, could now be performed. | 233 // were denied while within this scope, could now be performed. |
| 229 // For now, assume the next out-of-line allocation request will | 234 // For now, assume the next out-of-line allocation request will |
| 230 // happen soon enough and take care of it. Mixin objects aren't | 235 // happen soon enough and take care of it. Mixin objects aren't |
| 231 // overly common. | 236 // overly common. |
| 232 ThreadState* state = ThreadState::current(); | 237 ThreadState* state = ThreadState::current(); |
| 233 state->leaveGCForbiddenScopeIfNeeded(this); | 238 state->finishConstructingGCMixin(this); |
| 234 } | 239 } |
| 235 }; | 240 }; |
| 236 | 241 |
| 237 // Base class for objects allocated in the Blink garbage-collected heap. | 242 // Base class for objects allocated in the Blink garbage-collected heap. |
| 238 // | 243 // |
| 239 // Defines a 'new' operator that allocates the memory in the heap. 'delete' | 244 // Defines a 'new' operator that allocates the memory in the heap. 'delete' |
| 240 // should not be called on objects that inherit from GarbageCollected. | 245 // should not be called on objects that inherit from GarbageCollected. |
| 241 // | 246 // |
| 242 // Instances of GarbageCollected will *NOT* get finalized. Their destructor | 247 // Instances of GarbageCollected will *NOT* get finalized. Their destructor |
| 243 // will not be called. Therefore, only classes that have trivial destructors | 248 // will not be called. Therefore, only classes that have trivial destructors |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 template<typename U, size_t sz = sizeof(U)> static TrueType isSizeofKnown(U*
); | 392 template<typename U, size_t sz = sizeof(U)> static TrueType isSizeofKnown(U*
); |
| 388 static FalseType isSizeofKnown(...); | 393 static FalseType isSizeofKnown(...); |
| 389 static T& t; | 394 static T& t; |
| 390 public: | 395 public: |
| 391 static const bool value = sizeof(TrueType) == sizeof(isSizeofKnown(&t)); | 396 static const bool value = sizeof(TrueType) == sizeof(isSizeofKnown(&t)); |
| 392 }; | 397 }; |
| 393 | 398 |
| 394 } // namespace blink | 399 } // namespace blink |
| 395 | 400 |
| 396 #endif | 401 #endif |
| OLD | NEW |