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

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

Issue 2625363002: Simplify visitor marking mode tracking. (Closed)
Patch Set: HeapTest compilation fix Created 3 years, 11 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 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 template <typename VisitorDispatcher> \ 126 template <typename VisitorDispatcher> \
127 inline void traceAfterDispatchImpl(VisitorDispatcher visitor) 127 inline void traceAfterDispatchImpl(VisitorDispatcher visitor)
128 128
129 #define EMPTY_MACRO_ARGUMENT 129 #define EMPTY_MACRO_ARGUMENT
130 130
131 #define DECLARE_TRACE() DECLARE_TRACE_IMPL(EMPTY_MACRO_ARGUMENT) 131 #define DECLARE_TRACE() DECLARE_TRACE_IMPL(EMPTY_MACRO_ARGUMENT)
132 #define DECLARE_VIRTUAL_TRACE() DECLARE_TRACE_IMPL(virtual) 132 #define DECLARE_VIRTUAL_TRACE() DECLARE_TRACE_IMPL(virtual)
133 #define DEFINE_INLINE_TRACE() DEFINE_INLINE_TRACE_IMPL(EMPTY_MACRO_ARGUMENT) 133 #define DEFINE_INLINE_TRACE() DEFINE_INLINE_TRACE_IMPL(EMPTY_MACRO_ARGUMENT)
134 #define DEFINE_INLINE_VIRTUAL_TRACE() DEFINE_INLINE_TRACE_IMPL(virtual) 134 #define DEFINE_INLINE_VIRTUAL_TRACE() DEFINE_INLINE_TRACE_IMPL(virtual)
135 135
136 enum class VisitorMarkingMode {
137 // This is a default visitor. This is used for GCType=GCWithSweep
138 // and GCType=GCWithoutSweep.
139 GlobalMarking,
140 // This visitor does not trace objects outside the heap of the
141 // GCing thread. This is used for GCType=ThreadTerminationGC.
142 ThreadLocalMarking,
143 // This visitor just marks objects and ignores weak processing.
144 // This is used for GCType=TakeSnapshot.
145 SnapshotMarking,
146 // This visitor is used to trace objects during weak processing.
147 // This visitor is allowed to trace only already marked objects.
148 WeakProcessing,
149 // Perform global marking along with preparing for additional sweep
150 // compaction of heap arenas afterwards. Compared to the GlobalMarking
151 // visitor, this visitor will also register references to objects
152 // that might be moved during arena compaction -- the compaction
153 // pass will then fix up those references when the object move goes
154 // ahead.
155 GlobalMarkingWithCompaction,
156 };
157
136 // VisitorHelper contains common implementation of Visitor helper methods. 158 // VisitorHelper contains common implementation of Visitor helper methods.
137 // 159 //
138 // VisitorHelper avoids virtual methods by using CRTP. 160 // VisitorHelper avoids virtual methods by using CRTP.
139 // c.f. http://en.wikipedia.org/wiki/Curiously_Recurring_Template_Pattern 161 // c.f. http://en.wikipedia.org/wiki/Curiously_Recurring_Template_Pattern
140 template <typename Derived> 162 template <typename Derived>
141 class VisitorHelper { 163 class VisitorHelper {
142 public: 164 public:
143 VisitorHelper(ThreadState* state) : m_state(state) {} 165 VisitorHelper(ThreadState* state, VisitorMarkingMode markingMode)
166 : m_state(state), m_markingMode(markingMode) {}
144 167
145 // One-argument templated mark method. This uses the static type of 168 // One-argument templated mark method. This uses the static type of
146 // the argument to get the TraceTrait. By default, the mark method 169 // the argument to get the TraceTrait. By default, the mark method
147 // of the TraceTrait just calls the virtual two-argument mark method on this 170 // of the TraceTrait just calls the virtual two-argument mark method on this
148 // visitor, where the second argument is the static trace method of the trait. 171 // visitor, where the second argument is the static trace method of the trait.
149 template <typename T> 172 template <typename T>
150 void mark(T* t) { 173 void mark(T* t) {
151 static_assert(sizeof(T), "T must be fully defined"); 174 static_assert(sizeof(T), "T must be fully defined");
152 static_assert(IsGarbageCollectedType<T>::value, 175 static_assert(IsGarbageCollectedType<T>::value,
153 "T needs to be a garbage collected object"); 176 "T needs to be a garbage collected object");
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 MovingObjectCallback callback, 291 MovingObjectCallback callback,
269 void* callbackData) { 292 void* callbackData) {
270 Derived::fromHelper(this)->registerMovingObjectCallback( 293 Derived::fromHelper(this)->registerMovingObjectCallback(
271 reinterpret_cast<MovableReference>(backingStore), callback, 294 reinterpret_cast<MovableReference>(backingStore), callback,
272 callbackData); 295 callbackData);
273 } 296 }
274 297
275 inline ThreadState* state() const { return m_state; } 298 inline ThreadState* state() const { return m_state; }
276 inline ThreadHeap& heap() const { return state()->heap(); } 299 inline ThreadHeap& heap() const { return state()->heap(); }
277 300
301 inline VisitorMarkingMode getMarkingMode() const { return m_markingMode; }
302
303 inline bool isGlobalMarking() const {
304 return m_markingMode == VisitorMarkingMode::GlobalMarking ||
305 m_markingMode == VisitorMarkingMode::GlobalMarkingWithCompaction;
306 }
307
278 private: 308 private:
279 template <typename T> 309 template <typename T>
280 static void handleWeakCell(Visitor* self, void* object); 310 static void handleWeakCell(Visitor* self, void* object);
281 311
282 ThreadState* const m_state; 312 ThreadState* const m_state;
313 const VisitorMarkingMode m_markingMode;
283 }; 314 };
284 315
285 // Visitor is used to traverse the Blink object graph. Used for the 316 // Visitor is used to traverse the Blink object graph. Used for the
286 // marking phase of the mark-sweep garbage collector. 317 // marking phase of the mark-sweep garbage collector.
287 // 318 //
288 // Pointers are marked and pushed on the marking stack by calling the 319 // Pointers are marked and pushed on the marking stack by calling the
289 // |mark| method with the pointer as an argument. 320 // |mark| method with the pointer as an argument.
290 // 321 //
291 // Pointers within objects are traced by calling the |trace| methods 322 // Pointers within objects are traced by calling the |trace| methods
292 // with the object as an argument. Tracing objects will mark all of the 323 // with the object as an argument. Tracing objects will mark all of the
293 // contained pointers and push them on the marking stack. 324 // contained pointers and push them on the marking stack.
294 class PLATFORM_EXPORT Visitor : public VisitorHelper<Visitor> { 325 class PLATFORM_EXPORT Visitor : public VisitorHelper<Visitor> {
295 public: 326 public:
296 friend class VisitorHelper<Visitor>; 327 friend class VisitorHelper<Visitor>;
297 friend class InlinedGlobalMarkingVisitor; 328 friend class InlinedGlobalMarkingVisitor;
298 329
299 enum MarkingMode { 330 static std::unique_ptr<Visitor> create(ThreadState*, VisitorMarkingMode);
300 // This is a default visitor. This is used for GCType=GCWithSweep
301 // and GCType=GCWithoutSweep.
302 GlobalMarking,
303 // This visitor does not trace objects outside the heap of the
304 // GCing thread. This is used for GCType=ThreadTerminationGC.
305 ThreadLocalMarking,
306 // This visitor just marks objects and ignores weak processing.
307 // This is used for GCType=TakeSnapshot.
308 SnapshotMarking,
309 // This visitor is used to trace objects during weak processing.
310 // This visitor is allowed to trace only already marked objects.
311 WeakProcessing,
312 // Perform global marking along with preparing for additional sweep
313 // compaction of heap arenas afterwards. Compared to the GlobalMarking
314 // visitor, this visitor will also register references to objects
315 // that might be moved during arena compaction -- the compaction
316 // pass will then fix up those references when the object move goes
317 // ahead.
318 GlobalMarkingWithCompaction,
319 };
320
321 static std::unique_ptr<Visitor> create(ThreadState*, MarkingMode);
322 331
323 virtual ~Visitor(); 332 virtual ~Visitor();
324 333
325 using VisitorHelper<Visitor>::mark; 334 using VisitorHelper<Visitor>::mark;
326 335
327 // This method marks an object and adds it to the set of objects 336 // This method marks an object and adds it to the set of objects
328 // that should have their trace method called. Since not all 337 // that should have their trace method called. Since not all
329 // objects have vtables we have to have the callback as an 338 // objects have vtables we have to have the callback as an
330 // explicit argument, but we can use the templated one-argument 339 // explicit argument, but we can use the templated one-argument
331 // mark method above to automatically provide the callback 340 // mark method above to automatically provide the callback
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 virtual bool ensureMarked(const void*) = 0; 386 virtual bool ensureMarked(const void*) = 0;
378 387
379 virtual void registerMovingObjectReference(MovableReference*) = 0; 388 virtual void registerMovingObjectReference(MovableReference*) = 0;
380 389
381 virtual void registerMovingObjectCallback(MovableReference, 390 virtual void registerMovingObjectCallback(MovableReference,
382 MovingObjectCallback, 391 MovingObjectCallback,
383 void*) = 0; 392 void*) = 0;
384 393
385 virtual void registerWeakCellWithCallback(void**, WeakCallback) = 0; 394 virtual void registerWeakCellWithCallback(void**, WeakCallback) = 0;
386 395
387 inline MarkingMode getMarkingMode() const { return m_markingMode; }
388
389 inline bool isGlobalMarking() const {
390 return m_markingMode == GlobalMarking ||
391 m_markingMode == GlobalMarkingWithCompaction;
392 }
393
394 protected: 396 protected:
395 Visitor(ThreadState*, MarkingMode); 397 Visitor(ThreadState*, VisitorMarkingMode);
396 398
397 private: 399 private:
398 static Visitor* fromHelper(VisitorHelper<Visitor>* helper) { 400 static Visitor* fromHelper(VisitorHelper<Visitor>* helper) {
399 return static_cast<Visitor*>(helper); 401 return static_cast<Visitor*>(helper);
400 } 402 }
401
402 const MarkingMode m_markingMode;
403 }; 403 };
404 404
405 } // namespace blink 405 } // namespace blink
406 406
407 #endif // Visitor_h 407 #endif // Visitor_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/heap/ThreadState.cpp ('k') | third_party/WebKit/Source/platform/heap/Visitor.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698