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" |
11 #include "wtf/TypeTraits.h" | 11 #include "wtf/TypeTraits.h" |
12 | 12 |
13 namespace blink { | 13 namespace blink { |
14 | 14 |
15 template <typename T> | 15 template <typename T> |
16 class GarbageCollected; | 16 class GarbageCollected; |
17 class InlinedGlobalMarkingVisitor; | |
18 class TraceWrapperBase; | 17 class TraceWrapperBase; |
19 | 18 |
20 // GC_PLUGIN_IGNORE is used to make the plugin ignore a particular class or | 19 // GC_PLUGIN_IGNORE is used to make the plugin ignore a particular class or |
21 // field when checking for proper usage. When using GC_PLUGIN_IGNORE | 20 // field when checking for proper usage. When using GC_PLUGIN_IGNORE |
22 // a bug-number should be provided as an argument where the bug describes | 21 // a bug-number should be provided as an argument where the bug describes |
23 // what needs to happen to remove the GC_PLUGIN_IGNORE again. | 22 // what needs to happen to remove the GC_PLUGIN_IGNORE again. |
24 #if COMPILER(CLANG) | 23 #if COMPILER(CLANG) |
25 #define GC_PLUGIN_IGNORE(bug) \ | 24 #define GC_PLUGIN_IGNORE(bug) \ |
26 __attribute__((annotate("blink_gc_plugin_ignore"))) | 25 __attribute__((annotate("blink_gc_plugin_ignore"))) |
27 #else | 26 #else |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 // With the helper, as long as we are using Member<B>, TypeTrait<B> will | 65 // With the helper, as long as we are using Member<B>, TypeTrait<B> will |
67 // dispatch adjustAndMark dynamically to find collect addr of the object header. | 66 // dispatch adjustAndMark dynamically to find collect addr of the object header. |
68 // Note that this is only enabled for Member<B>. For Member<A> which we can | 67 // Note that this is only enabled for Member<B>. For Member<A> which we can |
69 // compute the object header addr statically, this dynamic dispatch is not used. | 68 // compute the object header addr statically, this dynamic dispatch is not used. |
70 // | 69 // |
71 class PLATFORM_EXPORT GarbageCollectedMixin { | 70 class PLATFORM_EXPORT GarbageCollectedMixin { |
72 public: | 71 public: |
73 typedef int IsGarbageCollectedMixinMarker; | 72 typedef int IsGarbageCollectedMixinMarker; |
74 virtual void adjustAndMark(Visitor*) const = 0; | 73 virtual void adjustAndMark(Visitor*) const = 0; |
75 virtual void trace(Visitor*) {} | 74 virtual void trace(Visitor*) {} |
76 virtual void adjustAndMark(InlinedGlobalMarkingVisitor) const = 0; | |
77 virtual void trace(InlinedGlobalMarkingVisitor); | |
78 virtual bool isHeapObjectAlive() const = 0; | 75 virtual bool isHeapObjectAlive() const = 0; |
79 }; | 76 }; |
80 | 77 |
81 #define DEFINE_GARBAGE_COLLECTED_MIXIN_METHODS(VISITOR, TYPE) \ | 78 #define DEFINE_GARBAGE_COLLECTED_MIXIN_METHODS(VISITOR, TYPE) \ |
82 public: \ | 79 public: \ |
83 void adjustAndMark(VISITOR visitor) const override { \ | 80 void adjustAndMark(VISITOR visitor) const override { \ |
84 typedef WTF::IsSubclassOfTemplate<typename std::remove_const<TYPE>::type, \ | 81 typedef WTF::IsSubclassOfTemplate<typename std::remove_const<TYPE>::type, \ |
85 blink::GarbageCollected> \ | 82 blink::GarbageCollected> \ |
86 IsSubclassOfGarbageCollected; \ | 83 IsSubclassOfGarbageCollected; \ |
87 static_assert( \ | 84 static_assert( \ |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 // upon construction, two GarbageCollectedMixinConstructorMarker constructors | 145 // upon construction, two GarbageCollectedMixinConstructorMarker constructors |
149 // will run -- one for A (first) and another for B (secondly). Only | 146 // will run -- one for A (first) and another for B (secondly). Only |
150 // the second one should leave the forbidden GC scope. This is realized by | 147 // the second one should leave the forbidden GC scope. This is realized by |
151 // recording the address of B's GarbageCollectedMixinConstructorMarker | 148 // recording the address of B's GarbageCollectedMixinConstructorMarker |
152 // when the "operator new" for B runs, and leaving the forbidden GC scope | 149 // when the "operator new" for B runs, and leaving the forbidden GC scope |
153 // when the constructor of the recorded GarbageCollectedMixinConstructorMarker | 150 // when the constructor of the recorded GarbageCollectedMixinConstructorMarker |
154 // runs. | 151 // runs. |
155 #define USING_GARBAGE_COLLECTED_MIXIN(TYPE) \ | 152 #define USING_GARBAGE_COLLECTED_MIXIN(TYPE) \ |
156 IS_GARBAGE_COLLECTED_TYPE(); \ | 153 IS_GARBAGE_COLLECTED_TYPE(); \ |
157 DEFINE_GARBAGE_COLLECTED_MIXIN_METHODS(blink::Visitor*, TYPE) \ | 154 DEFINE_GARBAGE_COLLECTED_MIXIN_METHODS(blink::Visitor*, TYPE) \ |
158 DEFINE_GARBAGE_COLLECTED_MIXIN_METHODS(blink::InlinedGlobalMarkingVisitor, \ | |
159 TYPE) \ | |
160 DEFINE_GARBAGE_COLLECTED_MIXIN_CONSTRUCTOR_MARKER(TYPE) \ | 155 DEFINE_GARBAGE_COLLECTED_MIXIN_CONSTRUCTOR_MARKER(TYPE) \ |
161 public: \ | 156 public: \ |
162 bool isHeapObjectAlive() const override { \ | 157 bool isHeapObjectAlive() const override { \ |
163 return ThreadHeap::isHeapObjectAlive(this); \ | 158 return ThreadHeap::isHeapObjectAlive(this); \ |
164 } \ | 159 } \ |
165 \ | 160 \ |
166 private: | 161 private: |
167 | 162 |
168 // An empty class with a constructor that's arranged invoked when all derived | 163 // An empty class with a constructor that's arranged invoked when all derived |
169 // constructors of a mixin instance have completed and it is safe to allow GCs | 164 // constructors of a mixin instance have completed and it is safe to allow GCs |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 static FalseType isSizeofKnown(...); | 281 static FalseType isSizeofKnown(...); |
287 static T& t; | 282 static T& t; |
288 | 283 |
289 public: | 284 public: |
290 static const bool value = sizeof(TrueType) == sizeof(isSizeofKnown(&t)); | 285 static const bool value = sizeof(TrueType) == sizeof(isSizeofKnown(&t)); |
291 }; | 286 }; |
292 | 287 |
293 } // namespace blink | 288 } // namespace blink |
294 | 289 |
295 #endif | 290 #endif |
OLD | NEW |