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

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

Issue 2748103002: [wrapper-tracing] Redesign dispatching on non-inheriting cases (Closed)
Patch Set: Addressed comment 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
« no previous file with comments | « third_party/WebKit/Source/platform/heap/TraceTraits.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 23 matching lines...) Expand all
34 * 34 *
35 * class StyleEngine: public TraceWrapperBase { 35 * class StyleEngine: public TraceWrapperBase {
36 * public: 36 * public:
37 * DECLARE_TRACE_WRAPPERS(); 37 * DECLARE_TRACE_WRAPPERS();
38 * }; 38 * };
39 */ 39 */
40 #define DECLARE_TRACE_WRAPPERS() \ 40 #define DECLARE_TRACE_WRAPPERS() \
41 void traceWrappers(const WrapperVisitor* visitor) const 41 void traceWrappers(const WrapperVisitor* visitor) const
42 42
43 /** 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:
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 /**
60 * Declares virtual traceWrappers method. It is used in ScriptWrappable, can be 44 * Declares virtual traceWrappers method. It is used in ScriptWrappable, can be
61 * used to override the method in the subclasses, and can be used by 45 * used to override the method in the subclasses, and can be used by
62 * non-ScriptWrappable classes which expect to be inherited. 46 * non-ScriptWrappable classes which expect to be inherited.
63 */ 47 */
64 #define DECLARE_VIRTUAL_TRACE_WRAPPERS() virtual DECLARE_TRACE_WRAPPERS() 48 #define DECLARE_VIRTUAL_TRACE_WRAPPERS() virtual DECLARE_TRACE_WRAPPERS()
65 49
66 /** 50 /**
67 * Provides definition of traceWrappers method. Custom code will usually call 51 * Provides definition of traceWrappers method. Custom code will usually call
68 * visitor->traceWrappers with all objects which could contribute to the set of 52 * visitor->traceWrappers with all objects which could contribute to the set of
69 * reachable wrappers: 53 * reachable wrappers:
70 * 54 *
71 * DEFINE_TRACE_WRAPPERS(NodeRareData) 55 * DEFINE_TRACE_WRAPPERS(NodeRareData)
72 * { 56 * {
73 * visitor->traceWrappers(m_nodeLists); 57 * visitor->traceWrappers(m_nodeLists);
74 * visitor->traceWrappers(m_mutationObserverData); 58 * visitor->traceWrappers(m_mutationObserverData);
75 * } 59 * }
76 */ 60 */
77 #define DEFINE_TRACE_WRAPPERS(T) \ 61 #define DEFINE_TRACE_WRAPPERS(T) \
78 void T::traceWrappers(const WrapperVisitor* visitor) const 62 void T::traceWrappers(const WrapperVisitor* visitor) const
79 63
80 #define DECLARE_TRACE_WRAPPERS_AFTER_DISPATCH() \ 64 #define DECLARE_TRACE_WRAPPERS_AFTER_DISPATCH() \
81 void traceWrappersAfterDispatch(const WrapperVisitor*) const 65 void traceWrappersAfterDispatch(const WrapperVisitor*) const
82 66
83 #define DEFINE_TRACE_WRAPPERS_AFTER_DISPATCH(T) \ 67 #define DEFINE_TRACE_WRAPPERS_AFTER_DISPATCH(T) \
84 void T::traceWrappersAfterDispatch(const WrapperVisitor* visitor) const 68 void T::traceWrappersAfterDispatch(const WrapperVisitor* visitor) const
85 69
86 #define DEFINE_INLINE_TRACE_WRAPPERS() DECLARE_TRACE_WRAPPERS() 70 #define DEFINE_INLINE_TRACE_WRAPPERS() DECLARE_TRACE_WRAPPERS()
87 #define DEFINE_INLINE_VIRTUAL_TRACE_WRAPPERS() DECLARE_VIRTUAL_TRACE_WRAPPERS() 71 #define DEFINE_INLINE_VIRTUAL_TRACE_WRAPPERS() DECLARE_VIRTUAL_TRACE_WRAPPERS()
88 72
73 #define DEFINE_TRAIT_FOR_TRACE_WRAPPERS(ClassName) \
74 template <> \
75 inline void TraceTrait<ClassName>::traceMarkedWrapper( \
76 const WrapperVisitor* visitor, const void* t) { \
77 const ClassName* traceable = ToWrapperTracingType(t); \
78 DCHECK(heapObjectHeader(t)->isWrapperHeaderMarked()); \
79 traceable->traceWrappers(visitor); \
80 }
81
89 // ########################################################################### 82 // ###########################################################################
90 // TODO(hlopko): Get rid of virtual calls using CRTP 83 // TODO(hlopko): Get rid of virtual calls using CRTP
91 class PLATFORM_EXPORT WrapperVisitor { 84 class PLATFORM_EXPORT WrapperVisitor {
92 USING_FAST_MALLOC(WrapperVisitor); 85 USING_FAST_MALLOC(WrapperVisitor);
93 86
94 public: 87 public:
95 template <typename T> 88 template <typename T>
96 static NOINLINE void missedWriteBarrier() { 89 static NOINLINE void missedWriteBarrier() {
97 NOTREACHED(); 90 NOTREACHED();
98 } 91 }
99 92
100 template <typename T> 93 template <typename T>
101 void traceWrappers(const T* traceable) const { 94 void traceWrappers(const T* traceable) const {
102 static_assert(sizeof(T), "T must be fully defined"); 95 static_assert(sizeof(T), "T must be fully defined");
103 static_assert(CanTraceWrappers<T>::value,
104 "T should be able to trace wrappers. See "
105 "dispatchTraceWrappers in WrapperVisitor.h");
106 96
107 if (!traceable) { 97 if (!traceable) {
108 return; 98 return;
109 } 99 }
110 100
111 if (TraceTrait<T>::heapObjectHeader(traceable)->isWrapperHeaderMarked()) { 101 if (TraceTrait<T>::heapObjectHeader(traceable)->isWrapperHeaderMarked()) {
112 return; 102 return;
113 } 103 }
114 104
115 markAndPushToMarkingDeque(traceable); 105 markAndPushToMarkingDeque(traceable);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 139
150 virtual void traceWrappers( 140 virtual void traceWrappers(
151 const TraceWrapperV8Reference<v8::Value>&) const = 0; 141 const TraceWrapperV8Reference<v8::Value>&) const = 0;
152 virtual void markWrapper(const v8::PersistentBase<v8::Value>*) const = 0; 142 virtual void markWrapper(const v8::PersistentBase<v8::Value>*) const = 0;
153 143
154 virtual void dispatchTraceWrappers(const TraceWrapperBase*) const = 0; 144 virtual void dispatchTraceWrappers(const TraceWrapperBase*) const = 0;
155 145
156 virtual bool markWrapperHeader(HeapObjectHeader*) const = 0; 146 virtual bool markWrapperHeader(HeapObjectHeader*) const = 0;
157 147
158 virtual void markWrappersInAllWorlds(const ScriptWrappable*) const = 0; 148 virtual void markWrappersInAllWorlds(const ScriptWrappable*) const = 0;
149 void markWrappersInAllWorlds(const TraceWrapperBase*) const {
150 // TraceWrapperBase cannot point to V8 and thus doesn't need to
151 // mark wrappers.
152 }
159 153
160 template <typename T> 154 template <typename T>
161 ALWAYS_INLINE void markAndPushToMarkingDeque(const T* traceable) const { 155 ALWAYS_INLINE void markAndPushToMarkingDeque(const T* traceable) const {
162 if (pushToMarkingDeque(TraceTrait<T>::traceMarkedWrapper, 156 if (pushToMarkingDeque(TraceTrait<T>::traceMarkedWrapper,
163 TraceTrait<T>::heapObjectHeader, 157 TraceTrait<T>::heapObjectHeader,
164 WrapperVisitor::missedWriteBarrier<T>, traceable)) { 158 WrapperVisitor::missedWriteBarrier<T>, traceable)) {
165 TraceTrait<T>::markWrapperNoTracing(this, traceable); 159 TraceTrait<T>::markWrapperNoTracing(this, traceable);
166 } 160 }
167 } 161 }
168 162
169 protected: 163 protected:
170 // Returns true if pushing to the marking deque was successful. 164 // Returns true if pushing to the marking deque was successful.
171 virtual bool pushToMarkingDeque( 165 virtual bool pushToMarkingDeque(
172 void (*traceWrappersCallback)(const WrapperVisitor*, const void*), 166 void (*traceWrappersCallback)(const WrapperVisitor*, const void*),
173 HeapObjectHeader* (*heapObjectHeaderCallback)(const void*), 167 HeapObjectHeader* (*heapObjectHeaderCallback)(const void*),
174 void (*missedWriteBarrierCallback)(void), 168 void (*missedWriteBarrierCallback)(void),
175 const void*) const = 0; 169 const void*) const = 0;
176 }; 170 };
177 171
178 } // namespace blink 172 } // namespace blink
179 173
180 #endif // WrapperVisitor_h 174 #endif // WrapperVisitor_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/heap/TraceTraits.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698