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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 Derived::fromHelper(this)->registerWeakCellWithCallback( | 236 Derived::fromHelper(this)->registerWeakCellWithCallback( |
237 reinterpret_cast<void**>( | 237 reinterpret_cast<void**>( |
238 const_cast<typename std::remove_const<T>::type**>(cell)), | 238 const_cast<typename std::remove_const<T>::type**>(cell)), |
239 &handleWeakCell<T>); | 239 &handleWeakCell<T>); |
240 } | 240 } |
241 | 241 |
242 template <typename T, void (T::*method)(Visitor*)> | 242 template <typename T, void (T::*method)(Visitor*)> |
243 void registerWeakMembers(const T* obj) { | 243 void registerWeakMembers(const T* obj) { |
244 registerWeakMembers(obj, &TraceMethodDelegate<T, method>::trampoline); | 244 registerWeakMembers(obj, &TraceMethodDelegate<T, method>::trampoline); |
245 } | 245 } |
| 246 |
246 void registerWeakMembers(const void* object, WeakCallback callback) { | 247 void registerWeakMembers(const void* object, WeakCallback callback) { |
247 Derived::fromHelper(this)->registerWeakMembers(object, object, callback); | 248 Derived::fromHelper(this)->registerWeakMembers(object, object, callback); |
248 } | 249 } |
249 | 250 |
| 251 template <typename T> |
| 252 void registerBackingStoreReference(T** slot) { |
| 253 Derived::fromHelper(this)->registerMovingObjectReference( |
| 254 reinterpret_cast<MovableReference*>(slot)); |
| 255 } |
| 256 |
| 257 template <typename T> |
| 258 void registerBackingStoreCallback(T* backingStore, |
| 259 MovingObjectCallback callback, |
| 260 void* callbackData) { |
| 261 Derived::fromHelper(this)->registerMovingObjectCallback( |
| 262 reinterpret_cast<MovableReference>(backingStore), callback, |
| 263 callbackData); |
| 264 } |
| 265 |
250 inline ThreadState* state() const { return m_state; } | 266 inline ThreadState* state() const { return m_state; } |
251 inline ThreadHeap& heap() const { return state()->heap(); } | 267 inline ThreadHeap& heap() const { return state()->heap(); } |
252 | 268 |
253 private: | 269 private: |
254 template <typename T> | 270 template <typename T> |
255 static void handleWeakCell(Visitor* self, void* object); | 271 static void handleWeakCell(Visitor* self, void* object); |
256 | 272 |
257 ThreadState* m_state; | 273 ThreadState* const m_state; |
258 }; | 274 }; |
259 | 275 |
260 // Visitor is used to traverse the Blink object graph. Used for the | 276 // Visitor is used to traverse the Blink object graph. Used for the |
261 // marking phase of the mark-sweep garbage collector. | 277 // marking phase of the mark-sweep garbage collector. |
262 // | 278 // |
263 // Pointers are marked and pushed on the marking stack by calling the | 279 // Pointers are marked and pushed on the marking stack by calling the |
264 // |mark| method with the pointer as an argument. | 280 // |mark| method with the pointer as an argument. |
265 // | 281 // |
266 // Pointers within objects are traced by calling the |trace| methods | 282 // Pointers within objects are traced by calling the |trace| methods |
267 // with the object as an argument. Tracing objects will mark all of the | 283 // with the object as an argument. Tracing objects will mark all of the |
268 // contained pointers and push them on the marking stack. | 284 // contained pointers and push them on the marking stack. |
269 class PLATFORM_EXPORT Visitor : public VisitorHelper<Visitor> { | 285 class PLATFORM_EXPORT Visitor : public VisitorHelper<Visitor> { |
270 public: | 286 public: |
271 friend class VisitorHelper<Visitor>; | 287 friend class VisitorHelper<Visitor>; |
272 friend class InlinedGlobalMarkingVisitor; | 288 friend class InlinedGlobalMarkingVisitor; |
273 | 289 |
274 enum MarkingMode { | 290 enum MarkingMode { |
275 // This is a default visitor. This is used for GCType=GCWithSweep | 291 // This is a default visitor. This is used for GCType=GCWithSweep |
276 // and GCType=GCWithoutSweep. | 292 // and GCType=GCWithoutSweep. |
277 GlobalMarking, | 293 GlobalMarking, |
278 // This visitor does not trace objects outside the heap of the | 294 // This visitor does not trace objects outside the heap of the |
279 // GCing thread. This is used for GCType=ThreadTerminationGC. | 295 // GCing thread. This is used for GCType=ThreadTerminationGC. |
280 ThreadLocalMarking, | 296 ThreadLocalMarking, |
281 // This visitor just marks objects and ignores weak processing. | 297 // This visitor just marks objects and ignores weak processing. |
282 // This is used for GCType=TakeSnapshot. | 298 // This is used for GCType=TakeSnapshot. |
283 SnapshotMarking, | 299 SnapshotMarking, |
284 // This visitor is used to trace objects during weak processing. | 300 // This visitor is used to trace objects during weak processing. |
285 // This visitor is allowed to trace only already marked objects. | 301 // This visitor is allowed to trace only already marked objects. |
286 WeakProcessing, | 302 WeakProcessing, |
| 303 // Perform global marking along with preparing for additional sweep |
| 304 // compaction of heap arenas afterwards. Compared to the GlobalMarking |
| 305 // visitor, this visitor will also register references to objects |
| 306 // that might be moved during arena compaction -- the compaction |
| 307 // pass will then fix up those references when the object move goes |
| 308 // ahead. |
| 309 GlobalMarkingWithCompaction, |
287 }; | 310 }; |
288 | 311 |
289 static std::unique_ptr<Visitor> create(ThreadState*, BlinkGC::GCType); | 312 static std::unique_ptr<Visitor> create(ThreadState*, BlinkGC::GCType); |
290 | 313 |
291 virtual ~Visitor(); | 314 virtual ~Visitor(); |
292 | 315 |
293 using VisitorHelper<Visitor>::mark; | 316 using VisitorHelper<Visitor>::mark; |
294 | 317 |
295 // This method marks an object and adds it to the set of objects | 318 // This method marks an object and adds it to the set of objects |
296 // that should have their trace method called. Since not all | 319 // that should have their trace method called. Since not all |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 | 360 |
338 virtual void registerWeakTable(const void*, | 361 virtual void registerWeakTable(const void*, |
339 EphemeronCallback, | 362 EphemeronCallback, |
340 EphemeronCallback) = 0; | 363 EphemeronCallback) = 0; |
341 #if ENABLE(ASSERT) | 364 #if ENABLE(ASSERT) |
342 virtual bool weakTableRegistered(const void*) = 0; | 365 virtual bool weakTableRegistered(const void*) = 0; |
343 #endif | 366 #endif |
344 | 367 |
345 virtual bool ensureMarked(const void*) = 0; | 368 virtual bool ensureMarked(const void*) = 0; |
346 | 369 |
| 370 virtual void registerMovingObjectReference(MovableReference*) = 0; |
| 371 |
| 372 virtual void registerMovingObjectCallback(MovableReference, |
| 373 MovingObjectCallback, |
| 374 void*) = 0; |
| 375 |
347 virtual void registerWeakCellWithCallback(void**, WeakCallback) = 0; | 376 virtual void registerWeakCellWithCallback(void**, WeakCallback) = 0; |
348 | 377 |
349 inline MarkingMode getMarkingMode() const { return m_markingMode; } | 378 inline MarkingMode getMarkingMode() const { return m_markingMode; } |
350 | 379 |
| 380 inline bool isGlobalMarking() const { |
| 381 return m_markingMode == GlobalMarking || |
| 382 m_markingMode == GlobalMarkingWithCompaction; |
| 383 } |
| 384 |
351 protected: | 385 protected: |
352 Visitor(ThreadState*, MarkingMode); | 386 Visitor(ThreadState*, MarkingMode); |
353 | 387 |
354 private: | 388 private: |
355 static Visitor* fromHelper(VisitorHelper<Visitor>* helper) { | 389 static Visitor* fromHelper(VisitorHelper<Visitor>* helper) { |
356 return static_cast<Visitor*>(helper); | 390 return static_cast<Visitor*>(helper); |
357 } | 391 } |
358 | 392 |
359 ThreadState* m_state; | |
360 const MarkingMode m_markingMode; | 393 const MarkingMode m_markingMode; |
361 }; | 394 }; |
362 | 395 |
363 } // namespace blink | 396 } // namespace blink |
364 | 397 |
365 #endif // Visitor_h | 398 #endif // Visitor_h |
OLD | NEW |