| 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 #define DEFINE_INLINE_TRACE() DEFINE_INLINE_TRACE_IMPL(EMPTY_MACRO_ARGUMENT) | 112 #define DEFINE_INLINE_TRACE() DEFINE_INLINE_TRACE_IMPL(EMPTY_MACRO_ARGUMENT) |
| 113 #define DEFINE_INLINE_VIRTUAL_TRACE() DEFINE_INLINE_TRACE_IMPL(virtual) | 113 #define DEFINE_INLINE_VIRTUAL_TRACE() DEFINE_INLINE_TRACE_IMPL(virtual) |
| 114 | 114 |
| 115 // VisitorHelper contains common implementation of Visitor helper methods. | 115 // VisitorHelper contains common implementation of Visitor helper methods. |
| 116 // | 116 // |
| 117 // VisitorHelper avoids virtual methods by using CRTP. | 117 // VisitorHelper avoids virtual methods by using CRTP. |
| 118 // c.f. http://en.wikipedia.org/wiki/Curiously_Recurring_Template_Pattern | 118 // c.f. http://en.wikipedia.org/wiki/Curiously_Recurring_Template_Pattern |
| 119 template<typename Derived> | 119 template<typename Derived> |
| 120 class VisitorHelper { | 120 class VisitorHelper { |
| 121 public: | 121 public: |
| 122 VisitorHelper(ThreadState* state) : m_state(state) { } |
| 123 |
| 122 // One-argument templated mark method. This uses the static type of | 124 // One-argument templated mark method. This uses the static type of |
| 123 // the argument to get the TraceTrait. By default, the mark method | 125 // the argument to get the TraceTrait. By default, the mark method |
| 124 // of the TraceTrait just calls the virtual two-argument mark method on this | 126 // of the TraceTrait just calls the virtual two-argument mark method on this |
| 125 // visitor, where the second argument is the static trace method of the trai
t. | 127 // visitor, where the second argument is the static trace method of the trai
t. |
| 126 template<typename T> | 128 template<typename T> |
| 127 void mark(T* t) | 129 void mark(T* t) |
| 128 { | 130 { |
| 129 static_assert(sizeof(T), "T must be fully defined"); | 131 static_assert(sizeof(T), "T must be fully defined"); |
| 130 static_assert(IsGarbageCollectedType<T>::value, "T needs to be a garbage
collected object"); | 132 static_assert(IsGarbageCollectedType<T>::value, "T needs to be a garbage
collected object"); |
| 131 if (!t) | 133 if (!t) |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 template<typename T, void (T::*method)(Visitor*)> | 216 template<typename T, void (T::*method)(Visitor*)> |
| 215 void registerWeakMembers(const T* obj) | 217 void registerWeakMembers(const T* obj) |
| 216 { | 218 { |
| 217 registerWeakMembers(obj, &TraceMethodDelegate<T, method>::trampoline); | 219 registerWeakMembers(obj, &TraceMethodDelegate<T, method>::trampoline); |
| 218 } | 220 } |
| 219 void registerWeakMembers(const void* object, WeakCallback callback) | 221 void registerWeakMembers(const void* object, WeakCallback callback) |
| 220 { | 222 { |
| 221 Derived::fromHelper(this)->registerWeakMembers(object, object, callback)
; | 223 Derived::fromHelper(this)->registerWeakMembers(object, object, callback)
; |
| 222 } | 224 } |
| 223 | 225 |
| 226 inline ThreadState* state() const { return m_state; } |
| 227 inline ThreadHeap& heap() const { return state()->heap(); } |
| 228 |
| 224 private: | 229 private: |
| 225 template<typename T> | 230 template<typename T> |
| 226 static void handleWeakCell(Visitor* self, void* object); | 231 static void handleWeakCell(Visitor* self, void* object); |
| 232 |
| 233 ThreadState* m_state; |
| 227 }; | 234 }; |
| 228 | 235 |
| 229 // Visitor is used to traverse the Blink object graph. Used for the | 236 // Visitor is used to traverse the Blink object graph. Used for the |
| 230 // marking phase of the mark-sweep garbage collector. | 237 // marking phase of the mark-sweep garbage collector. |
| 231 // | 238 // |
| 232 // Pointers are marked and pushed on the marking stack by calling the | 239 // Pointers are marked and pushed on the marking stack by calling the |
| 233 // |mark| method with the pointer as an argument. | 240 // |mark| method with the pointer as an argument. |
| 234 // | 241 // |
| 235 // Pointers within objects are traced by calling the |trace| methods | 242 // Pointers within objects are traced by calling the |trace| methods |
| 236 // with the object as an argument. Tracing objects will mark all of the | 243 // with the object as an argument. Tracing objects will mark all of the |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 | 313 |
| 307 virtual void registerWeakTable(const void*, EphemeronCallback, EphemeronCall
back) = 0; | 314 virtual void registerWeakTable(const void*, EphemeronCallback, EphemeronCall
back) = 0; |
| 308 #if ENABLE(ASSERT) | 315 #if ENABLE(ASSERT) |
| 309 virtual bool weakTableRegistered(const void*) = 0; | 316 virtual bool weakTableRegistered(const void*) = 0; |
| 310 #endif | 317 #endif |
| 311 | 318 |
| 312 virtual bool ensureMarked(const void*) = 0; | 319 virtual bool ensureMarked(const void*) = 0; |
| 313 | 320 |
| 314 inline MarkingMode getMarkingMode() const { return m_markingMode; } | 321 inline MarkingMode getMarkingMode() const { return m_markingMode; } |
| 315 | 322 |
| 316 inline ThreadHeap& heap() const { return m_state->heap(); } | |
| 317 | |
| 318 protected: | 323 protected: |
| 319 Visitor(ThreadState*, MarkingMode); | 324 Visitor(ThreadState*, MarkingMode); |
| 320 | 325 |
| 321 virtual void registerWeakCellWithCallback(void**, WeakCallback) = 0; | 326 virtual void registerWeakCellWithCallback(void**, WeakCallback) = 0; |
| 322 | 327 |
| 323 private: | 328 private: |
| 324 static Visitor* fromHelper(VisitorHelper<Visitor>* helper) { return static_c
ast<Visitor*>(helper); } | 329 static Visitor* fromHelper(VisitorHelper<Visitor>* helper) { return static_c
ast<Visitor*>(helper); } |
| 325 | 330 |
| 326 ThreadState* m_state; | 331 ThreadState* m_state; |
| 327 const MarkingMode m_markingMode; | 332 const MarkingMode m_markingMode; |
| 328 }; | 333 }; |
| 329 | 334 |
| 330 } // namespace blink | 335 } // namespace blink |
| 331 | 336 |
| 332 #endif // Visitor_h | 337 #endif // Visitor_h |
| OLD | NEW |