Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(817)

Side by Side Diff: third_party/WebKit/Source/platform/heap/WrapperVisitor.h

Issue 2728203002: Remove WRAPPER_VISITOR_SPECIAL_CLASSES (Closed)
Patch Set: Add macro and update documentation Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 WrapperVisitor_h 5 #ifndef WrapperVisitor_h
6 #define WrapperVisitor_h 6 #define WrapperVisitor_h
7 7
8 #include "platform/PlatformExport.h" 8 #include "platform/PlatformExport.h"
9 #include "wtf/Allocator.h" 9 #include "wtf/Allocator.h"
10 10
11 namespace v8 { 11 namespace v8 {
12 class Value; 12 class Value;
13 template <class T> 13 template <class T>
14 class PersistentBase; 14 class PersistentBase;
15 } 15 }
16 16
17 namespace blink { 17 namespace blink {
18 18
19 template <typename T> 19 template <typename T>
20 class TraceTrait; 20 class TraceTrait;
21 template <typename T> 21 template <typename T>
22 class Member; 22 class Member;
23 class ScriptWrappable; 23 class ScriptWrappable;
24 template <typename T> 24 template <typename T>
25 class TraceWrapperV8Reference; 25 class TraceWrapperV8Reference;
26 class TraceWrapperBase; 26 class TraceWrapperBase;
27 template <typename T> 27 template <typename T>
28 class TraceWrapperMember; 28 class TraceWrapperMember;
29 29
30 // Only add a special class here if the class cannot derive from
31 // TraceWrapperBase.
32 #define WRAPPER_VISITOR_SPECIAL_CLASSES(V) \
33 V(ElementRareData) \
34 V(NodeListsNodeData) \
35 V(NodeMutationObserverData) \
36 V(NodeRareData)
37
38 #define FORWARD_DECLARE_SPECIAL_CLASSES(className) class className;
39
40 WRAPPER_VISITOR_SPECIAL_CLASSES(FORWARD_DECLARE_SPECIAL_CLASSES);
41
42 #undef FORWARD_DECLARE_SPECIAL_CLASSES
43
44 /** 30 /**
45 * Declares non-virtual traceWrappers method. Should be used on 31 * Declares non-virtual traceWrappers method. Should be used on
46 * non-ScriptWrappable classes which should participate in wrapper tracing (e.g. 32 * non-ScriptWrappable classes which should participate in wrapper tracing (e.g.
47 * NodeRareData): 33 * StyleEngine):
48 * 34 *
49 * class NodeRareData { 35 * class StyleEngine: public TraceWrapperBase {
50 * public: 36 * public:
51 * DECLARE_TRACE_WRAPPERS(); 37 * DECLARE_TRACE_WRAPPERS();
52 * } 38 * }
53 */ 39 */
54 #define DECLARE_TRACE_WRAPPERS() \ 40 #define DECLARE_TRACE_WRAPPERS() \
55 void traceWrappers(const WrapperVisitor* visitor) const 41 void traceWrappers(const WrapperVisitor* visitor) const
56 42
57 /** 43 /**
44 * Declares markAndDispatchTraceWrappers and non-virtual traceWrappers methods.
45 * Use this on non-TraceWrapperBase classes that participate in wrapper tracing
46 * (e.g. NodeRareData):
47 *
48 * class NodeRareData {
49 * public:
jbroman 2017/03/07 17:46:10 nit: here (and above): "public:" should be indente
adithyas 2017/03/07 18:40:46 Fixed both.
50 * DECLARE_TRACE_WRAPPERS_WITHOUT_BASE();
51 * }
52 */
53 #define DECLARE_TRACE_WRAPPERS_WITHOUT_BASE() \
54 void markAndDispatchTraceWrappers(const WrapperVisitor* visitor) const { \
55 traceWrappers(visitor); \
56 } \
57 DECLARE_TRACE_WRAPPERS()
58
59 /**
58 * Declares virtual traceWrappers method. It is used in ScriptWrappable, can be 60 * Declares virtual traceWrappers method. It is used in ScriptWrappable, can be
59 * used to override the method in the subclasses, and can be used by 61 * used to override the method in the subclasses, and can be used by
60 * non-ScriptWrappable classes which expect to be inherited. 62 * non-ScriptWrappable classes which expect to be inherited.
61 */ 63 */
62 #define DECLARE_VIRTUAL_TRACE_WRAPPERS() virtual DECLARE_TRACE_WRAPPERS() 64 #define DECLARE_VIRTUAL_TRACE_WRAPPERS() virtual DECLARE_TRACE_WRAPPERS()
63 65
64 /** 66 /**
65 * Provides definition of traceWrappers method. Custom code will usually call 67 * Provides definition of traceWrappers method. Custom code will usually call
66 * visitor->traceWrappers with all objects which could contribute to the set of 68 * visitor->traceWrappers with all objects which could contribute to the set of
67 * reachable wrappers: 69 * reachable wrappers:
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 template <typename T> 145 template <typename T>
144 void traceWrappersWithManualWriteBarrier(const T* traceable) const { 146 void traceWrappersWithManualWriteBarrier(const T* traceable) const {
145 traceWrappers(traceable); 147 traceWrappers(traceable);
146 } 148 }
147 149
148 virtual void traceWrappers( 150 virtual void traceWrappers(
149 const TraceWrapperV8Reference<v8::Value>&) const = 0; 151 const TraceWrapperV8Reference<v8::Value>&) const = 0;
150 virtual void markWrapper(const v8::PersistentBase<v8::Value>*) const = 0; 152 virtual void markWrapper(const v8::PersistentBase<v8::Value>*) const = 0;
151 153
152 virtual void dispatchTraceWrappers(const TraceWrapperBase*) const = 0; 154 virtual void dispatchTraceWrappers(const TraceWrapperBase*) const = 0;
153 #define DECLARE_DISPATCH_TRACE_WRAPPERS(ClassName) \
154 virtual void dispatchTraceWrappers(const ClassName*) const = 0;
155
156 WRAPPER_VISITOR_SPECIAL_CLASSES(DECLARE_DISPATCH_TRACE_WRAPPERS);
157
158 #undef DECLARE_DISPATCH_TRACE_WRAPPERS
159 155
160 virtual bool markWrapperHeader(HeapObjectHeader*) const = 0; 156 virtual bool markWrapperHeader(HeapObjectHeader*) const = 0;
161 157
162 virtual void markWrappersInAllWorlds(const ScriptWrappable*) const = 0; 158 virtual void markWrappersInAllWorlds(const ScriptWrappable*) const = 0;
163 159
164 void markWrappersInAllWorlds(const void*) const {
165 // Empty handler used for WRAPPER_VISITOR_SPECIAL_CLASSES. These types
166 // don't require marking wrappers in all worlds, so just nop on those.
167 }
168
169 template <typename T> 160 template <typename T>
170 ALWAYS_INLINE void markAndPushToMarkingDeque(const T* traceable) const { 161 ALWAYS_INLINE void markAndPushToMarkingDeque(const T* traceable) const {
171 if (pushToMarkingDeque(TraceTrait<T>::traceMarkedWrapper, 162 if (pushToMarkingDeque(TraceTrait<T>::traceMarkedWrapper,
172 TraceTrait<T>::heapObjectHeader, 163 TraceTrait<T>::heapObjectHeader,
173 WrapperVisitor::missedWriteBarrier<T>, traceable)) { 164 WrapperVisitor::missedWriteBarrier<T>, traceable)) {
174 TraceTrait<T>::markWrapperNoTracing(this, traceable); 165 TraceTrait<T>::markWrapperNoTracing(this, traceable);
175 } 166 }
176 } 167 }
177 168
178 protected: 169 protected:
179 // Returns true if pushing to the marking deque was successful. 170 // Returns true if pushing to the marking deque was successful.
180 virtual bool pushToMarkingDeque( 171 virtual bool pushToMarkingDeque(
181 void (*traceWrappersCallback)(const WrapperVisitor*, const void*), 172 void (*traceWrappersCallback)(const WrapperVisitor*, const void*),
182 HeapObjectHeader* (*heapObjectHeaderCallback)(const void*), 173 HeapObjectHeader* (*heapObjectHeaderCallback)(const void*),
183 void (*missedWriteBarrierCallback)(void), 174 void (*missedWriteBarrierCallback)(void),
184 const void*) const = 0; 175 const void*) const = 0;
185 }; 176 };
186 177
187 #define SPECIALIZE_WRAPPER_TRACING_MARK_TRAIT(ClassName) \
188 template <> \
189 class CanTraceWrappers<ClassName, false> { \
190 public: \
191 static const bool value = true; \
192 };
193
194 WRAPPER_VISITOR_SPECIAL_CLASSES(SPECIALIZE_WRAPPER_TRACING_MARK_TRAIT)
195
196 #undef SPECIALIZE_WRAPPER_TRACING_MARK_TRAIT
197
198 } // namespace blink 178 } // namespace blink
199 179
200 #endif // WrapperVisitor_h 180 #endif // WrapperVisitor_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698