| 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 #define DEFINE_INLINE_TRACE() DEFINE_INLINE_TRACE_IMPL(EMPTY_MACRO_ARGUMENT) | 114 #define DEFINE_INLINE_TRACE() DEFINE_INLINE_TRACE_IMPL(EMPTY_MACRO_ARGUMENT) |
| 115 #define DEFINE_INLINE_VIRTUAL_TRACE() DEFINE_INLINE_TRACE_IMPL(virtual) | 115 #define DEFINE_INLINE_VIRTUAL_TRACE() DEFINE_INLINE_TRACE_IMPL(virtual) |
| 116 | 116 |
| 117 // VisitorHelper contains common implementation of Visitor helper methods. | 117 // VisitorHelper contains common implementation of Visitor helper methods. |
| 118 // | 118 // |
| 119 // VisitorHelper avoids virtual methods by using CRTP. | 119 // VisitorHelper avoids virtual methods by using CRTP. |
| 120 // c.f. http://en.wikipedia.org/wiki/Curiously_Recurring_Template_Pattern | 120 // c.f. http://en.wikipedia.org/wiki/Curiously_Recurring_Template_Pattern |
| 121 template<typename Derived> | 121 template<typename Derived> |
| 122 class VisitorHelper { | 122 class VisitorHelper { |
| 123 public: | 123 public: |
| 124 VisitorHelper() : m_threadState(ThreadState::current()) {} |
| 125 |
| 124 // One-argument templated mark method. This uses the static type of | 126 // One-argument templated mark method. This uses the static type of |
| 125 // the argument to get the TraceTrait. By default, the mark method | 127 // 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 | 128 // 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. | 129 // visitor, where the second argument is the static trace method of the trai
t. |
| 128 template<typename T> | 130 template<typename T> |
| 129 void mark(T* t) | 131 void mark(T* t) |
| 130 { | 132 { |
| 131 static_assert(sizeof(T), "T must be fully defined"); | 133 static_assert(sizeof(T), "T must be fully defined"); |
| 132 static_assert(IsGarbageCollectedType<T>::value, "T needs to be a garbage
collected object"); | 134 static_assert(IsGarbageCollectedType<T>::value, "T needs to be a garbage
collected object"); |
| 133 if (!t) | 135 if (!t) |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 template<typename T, void (T::*method)(Visitor*)> | 276 template<typename T, void (T::*method)(Visitor*)> |
| 275 void registerWeakMembers(const T* obj) | 277 void registerWeakMembers(const T* obj) |
| 276 { | 278 { |
| 277 registerWeakMembers(obj, &TraceMethodDelegate<T, method>::trampoline); | 279 registerWeakMembers(obj, &TraceMethodDelegate<T, method>::trampoline); |
| 278 } | 280 } |
| 279 void registerWeakMembers(const void* object, WeakCallback callback) | 281 void registerWeakMembers(const void* object, WeakCallback callback) |
| 280 { | 282 { |
| 281 Derived::fromHelper(this)->registerWeakMembers(object, object, callback)
; | 283 Derived::fromHelper(this)->registerWeakMembers(object, object, callback)
; |
| 282 } | 284 } |
| 283 | 285 |
| 286 inline ThreadState* threadState() const { return m_threadState; } |
| 287 |
| 284 private: | 288 private: |
| 285 template<typename T> | 289 template<typename T> |
| 286 static void handleWeakCell(Visitor* self, void* object); | 290 static void handleWeakCell(Visitor* self, void* object); |
| 291 |
| 292 ThreadState* m_threadState; |
| 287 }; | 293 }; |
| 288 | 294 |
| 289 // Visitor is used to traverse the Blink object graph. Used for the | 295 // Visitor is used to traverse the Blink object graph. Used for the |
| 290 // marking phase of the mark-sweep garbage collector. | 296 // marking phase of the mark-sweep garbage collector. |
| 291 // | 297 // |
| 292 // Pointers are marked and pushed on the marking stack by calling the | 298 // Pointers are marked and pushed on the marking stack by calling the |
| 293 // |mark| method with the pointer as an argument. | 299 // |mark| method with the pointer as an argument. |
| 294 // | 300 // |
| 295 // Pointers within objects are traced by calling the |trace| methods | 301 // Pointers within objects are traced by calling the |trace| methods |
| 296 // with the object as an argument. Tracing objects will mark all of the | 302 // with the object as an argument. Tracing objects will mark all of the |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 static const String get() | 397 static const String get() |
| 392 { | 398 { |
| 393 return WTF::extractTypeNameFromFunctionName(WTF::extractNameFunction<T>(
)); | 399 return WTF::extractTypeNameFromFunctionName(WTF::extractNameFunction<T>(
)); |
| 394 } | 400 } |
| 395 }; | 401 }; |
| 396 #endif | 402 #endif |
| 397 | 403 |
| 398 } // namespace blink | 404 } // namespace blink |
| 399 | 405 |
| 400 #endif // Visitor_h | 406 #endif // Visitor_h |
| OLD | NEW |