Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 | 46 |
| 47 namespace blink { | 47 namespace blink { |
| 48 | 48 |
| 49 template<typename T> class GarbageCollected; | 49 template<typename T> class GarbageCollected; |
| 50 class HeapObjectHeader; | 50 class HeapObjectHeader; |
| 51 class InlinedGlobalMarkingVisitor; | 51 class InlinedGlobalMarkingVisitor; |
| 52 template<typename T> class TraceTrait; | 52 template<typename T> class TraceTrait; |
| 53 template<typename T> class TraceEagerlyTrait; | 53 template<typename T> class TraceEagerlyTrait; |
| 54 class ThreadState; | 54 class ThreadState; |
| 55 class Visitor; | 55 class Visitor; |
| 56 class VisitorScope; | |
| 56 | 57 |
| 57 // The TraceMethodDelegate is used to convert a trace method for type T to a Tra ceCallback. | 58 // The TraceMethodDelegate is used to convert a trace method for type T to a Tra ceCallback. |
| 58 // This allows us to pass a type's trace method as a parameter to the Persistent Node | 59 // This allows us to pass a type's trace method as a parameter to the Persistent Node |
| 59 // constructor. The PersistentNode constructor needs the specific trace method d ue an issue | 60 // constructor. The PersistentNode constructor needs the specific trace method d ue an issue |
| 60 // with the Windows compiler which instantiates even unused variables. This caus es problems | 61 // with the Windows compiler which instantiates even unused variables. This caus es problems |
| 61 // in header files where we have only forward declarations of classes. | 62 // in header files where we have only forward declarations of classes. |
| 62 template<typename T, void (T::*method)(Visitor*)> | 63 template<typename T, void (T::*method)(Visitor*)> |
| 63 struct TraceMethodDelegate { | 64 struct TraceMethodDelegate { |
| 64 STATIC_ONLY(TraceMethodDelegate); | 65 STATIC_ONLY(TraceMethodDelegate); |
| 65 static void trampoline(Visitor* visitor, void* self) | 66 static void trampoline(Visitor* visitor, void* self) |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 #define DEFINE_INLINE_TRACE() DEFINE_INLINE_TRACE_IMPL(EMPTY_MACRO_ARGUMENT) | 117 #define DEFINE_INLINE_TRACE() DEFINE_INLINE_TRACE_IMPL(EMPTY_MACRO_ARGUMENT) |
| 117 #define DEFINE_INLINE_VIRTUAL_TRACE() DEFINE_INLINE_TRACE_IMPL(virtual) | 118 #define DEFINE_INLINE_VIRTUAL_TRACE() DEFINE_INLINE_TRACE_IMPL(virtual) |
| 118 | 119 |
| 119 // VisitorHelper contains common implementation of Visitor helper methods. | 120 // VisitorHelper contains common implementation of Visitor helper methods. |
| 120 // | 121 // |
| 121 // VisitorHelper avoids virtual methods by using CRTP. | 122 // VisitorHelper avoids virtual methods by using CRTP. |
| 122 // c.f. http://en.wikipedia.org/wiki/Curiously_Recurring_Template_Pattern | 123 // c.f. http://en.wikipedia.org/wiki/Curiously_Recurring_Template_Pattern |
| 123 template<typename Derived> | 124 template<typename Derived> |
| 124 class VisitorHelper { | 125 class VisitorHelper { |
| 125 public: | 126 public: |
| 127 VisitorHelper(VisitorScope* visitorScope) : m_visitorScope(visitorScope) {} | |
| 128 | |
| 126 // One-argument templated mark method. This uses the static type of | 129 // One-argument templated mark method. This uses the static type of |
| 127 // the argument to get the TraceTrait. By default, the mark method | 130 // the argument to get the TraceTrait. By default, the mark method |
| 128 // of the TraceTrait just calls the virtual two-argument mark method on this | 131 // of the TraceTrait just calls the virtual two-argument mark method on this |
| 129 // visitor, where the second argument is the static trace method of the trai t. | 132 // visitor, where the second argument is the static trace method of the trai t. |
| 130 template<typename T> | 133 template<typename T> |
| 131 void mark(T* t) | 134 void mark(T* t) |
| 132 { | 135 { |
| 133 static_assert(sizeof(T), "T must be fully defined"); | 136 static_assert(sizeof(T), "T must be fully defined"); |
| 134 static_assert(IsGarbageCollectedType<T>::value, "T needs to be a garbage collected object"); | 137 static_assert(IsGarbageCollectedType<T>::value, "T needs to be a garbage collected object"); |
| 135 if (!t) | 138 if (!t) |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 276 template<typename T, void (T::*method)(Visitor*)> | 279 template<typename T, void (T::*method)(Visitor*)> |
| 277 void registerWeakMembers(const T* obj) | 280 void registerWeakMembers(const T* obj) |
| 278 { | 281 { |
| 279 registerWeakMembers(obj, &TraceMethodDelegate<T, method>::trampoline); | 282 registerWeakMembers(obj, &TraceMethodDelegate<T, method>::trampoline); |
| 280 } | 283 } |
| 281 void registerWeakMembers(const void* object, WeakCallback callback) | 284 void registerWeakMembers(const void* object, WeakCallback callback) |
| 282 { | 285 { |
| 283 Derived::fromHelper(this)->registerWeakMembers(object, object, callback) ; | 286 Derived::fromHelper(this)->registerWeakMembers(object, object, callback) ; |
| 284 } | 287 } |
| 285 | 288 |
| 289 inline VisitorScope* visitorScope() const { return m_visitorScope; } | |
| 290 | |
| 286 private: | 291 private: |
| 287 template<typename T> | 292 template<typename T> |
| 288 static void handleWeakCell(Visitor* self, void* object); | 293 static void handleWeakCell(Visitor* self, void* object); |
| 294 | |
| 295 VisitorScope* m_visitorScope; | |
| 289 }; | 296 }; |
| 290 | 297 |
| 291 // Visitor is used to traverse the Blink object graph. Used for the | 298 // Visitor is used to traverse the Blink object graph. Used for the |
| 292 // marking phase of the mark-sweep garbage collector. | 299 // marking phase of the mark-sweep garbage collector. |
| 293 // | 300 // |
| 294 // Pointers are marked and pushed on the marking stack by calling the | 301 // Pointers are marked and pushed on the marking stack by calling the |
| 295 // |mark| method with the pointer as an argument. | 302 // |mark| method with the pointer as an argument. |
| 296 // | 303 // |
| 297 // Pointers within objects are traced by calling the |trace| methods | 304 // Pointers within objects are traced by calling the |trace| methods |
| 298 // with the object as an argument. Tracing objects will mark all of the | 305 // with the object as an argument. Tracing objects will mark all of the |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 367 virtual void registerWeakTable(const void*, EphemeronCallback, EphemeronCall back) = 0; | 374 virtual void registerWeakTable(const void*, EphemeronCallback, EphemeronCall back) = 0; |
| 368 #if ENABLE(ASSERT) | 375 #if ENABLE(ASSERT) |
| 369 virtual bool weakTableRegistered(const void*) = 0; | 376 virtual bool weakTableRegistered(const void*) = 0; |
| 370 #endif | 377 #endif |
| 371 | 378 |
| 372 virtual bool ensureMarked(const void*) = 0; | 379 virtual bool ensureMarked(const void*) = 0; |
| 373 | 380 |
| 374 inline MarkingMode markingMode() const { return m_markingMode; } | 381 inline MarkingMode markingMode() const { return m_markingMode; } |
| 375 | 382 |
| 376 protected: | 383 protected: |
| 377 explicit Visitor(MarkingMode markingMode) | 384 explicit Visitor(MarkingMode markingMode, VisitorScope* visitorScope) |
| 378 : m_markingMode(markingMode) | 385 : VisitorHelper(visitorScope) |
| 386 , m_markingMode(markingMode) | |
| 379 { } | 387 { } |
| 380 | 388 |
| 381 virtual void registerWeakCellWithCallback(void**, WeakCallback) = 0; | 389 virtual void registerWeakCellWithCallback(void**, WeakCallback) = 0; |
| 382 | 390 |
| 383 private: | 391 private: |
| 384 static Visitor* fromHelper(VisitorHelper<Visitor>* helper) { return static_c ast<Visitor*>(helper); } | 392 static Visitor* fromHelper(VisitorHelper<Visitor>* helper) { return static_c ast<Visitor*>(helper); } |
| 385 | 393 |
| 386 const MarkingMode m_markingMode; | 394 const MarkingMode m_markingMode; |
| 387 bool m_isGlobalMarkingVisitor; | 395 bool m_isGlobalMarkingVisitor; |
| 388 }; | 396 }; |
| 389 | 397 |
| 390 class VisitorScope final { | 398 class PLATFORM_EXPORT VisitorScope final { |
|
haraken
2016/02/29 11:17:45
Can we unify the VisitorScope and the Visitor into
keishi
2016/03/02 06:01:03
Created https://codereview.chromium.org/1753623002
| |
| 391 STACK_ALLOCATED(); | 399 STACK_ALLOCATED(); |
| 392 public: | 400 public: |
| 393 VisitorScope(ThreadState*, BlinkGC::GCType); | 401 VisitorScope(ThreadState*, BlinkGC::GCType); |
| 394 ~VisitorScope(); | 402 ~VisitorScope(); |
| 395 Visitor* visitor() const { return m_visitor.get(); } | 403 Visitor* visitor() const { return m_visitor.get(); } |
| 404 Heap& heap() const { return m_state->heap(); } | |
| 396 | 405 |
| 397 private: | 406 private: |
| 398 ThreadState* m_state; | 407 ThreadState* m_state; |
| 399 OwnPtr<Visitor> m_visitor; | 408 OwnPtr<Visitor> m_visitor; |
| 400 }; | 409 }; |
| 401 | 410 |
| 402 } // namespace blink | 411 } // namespace blink |
| 403 | 412 |
| 404 #endif // Visitor_h | 413 #endif // Visitor_h |
| OLD | NEW |