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