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* m_state; |
258 }; | 274 }; |
259 | 275 |
(...skipping 17 matching lines...) Expand all Loading... |
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 GlobalMarkCompacting, |
287 }; | 304 }; |
288 | 305 |
289 static std::unique_ptr<Visitor> create(ThreadState*, BlinkGC::GCType); | 306 static std::unique_ptr<Visitor> create(ThreadState*, BlinkGC::GCType); |
290 | 307 |
291 virtual ~Visitor(); | 308 virtual ~Visitor(); |
292 | 309 |
293 using VisitorHelper<Visitor>::mark; | 310 using VisitorHelper<Visitor>::mark; |
294 | 311 |
295 // This method marks an object and adds it to the set of objects | 312 // This method marks an object and adds it to the set of objects |
296 // that should have their trace method called. Since not all | 313 // that should have their trace method called. Since not all |
297 // objects have vtables we have to have the callback as an | 314 // objects have vtables we have to have the callback as an |
298 // explicit argument, but we can use the templated one-argument | 315 // explicit argument, but we can use the templated one-argument |
299 // mark method above to automatically provide the callback | 316 // mark method above to automatically provide the callback |
300 // function. | 317 // function. |
301 virtual void mark(const void*, TraceCallback) = 0; | 318 virtual void mark(const void*, TraceCallback) = 0; |
302 | 319 |
303 // Used to mark objects during conservative scanning. | 320 // Used to mark objects during conservative scanning. |
304 virtual void markHeader(HeapObjectHeader*, TraceCallback) = 0; | 321 virtual void markHeader(HeapObjectHeader*, TraceCallback) = 0; |
305 | 322 |
306 // Used to delay the marking of objects until the usual marking | 323 // Used to delay the marking of objects until the usual marking |
307 // including emphemeron iteration is done. This is used to delay | 324 // including emphemeron iteration is done. This is used to delay |
308 // the marking of collection backing stores until we know if they | 325 // the marking of collection backing stores until we know if they |
309 // are reachable from locations other than the collection front | 326 // are reachable from locations other than the collection front |
310 // object. If collection backings are reachable from other | 327 // object. If collection backings are reachable from other |
311 // locations we strongify them to avoid issues with iterators and | 328 // locations we strongify them to avoid issues with iterators and |
312 // weak processing. | 329 // weak processing. |
313 virtual void registerDelayedMarkNoTracing(const void*) = 0; | 330 // A pointer to the location holding the backing store reference |
| 331 // is passed in. This is done so as to potentially allow that |
| 332 // location to be updated by the garbage collector. |
| 333 virtual void registerDelayedMarkNoTracing(void**) = 0; |
314 | 334 |
315 // If the object calls this during the regular trace callback, then the | 335 // If the object calls this during the regular trace callback, then the |
316 // WeakCallback argument may be called later, when the strong roots | 336 // WeakCallback argument may be called later, when the strong roots |
317 // have all been found. The WeakCallback will normally use isAlive | 337 // have all been found. The WeakCallback will normally use isAlive |
318 // to find out whether some pointers are pointing to dying objects. When | 338 // to find out whether some pointers are pointing to dying objects. When |
319 // the WeakCallback is done the object must have purged all pointers | 339 // the WeakCallback is done the object must have purged all pointers |
320 // to objects where isAlive returned false. In the weak callback it is not | 340 // to objects where isAlive returned false. In the weak callback it is not |
321 // allowed to do anything that adds or extends the object graph (e.g., | 341 // allowed to do anything that adds or extends the object graph (e.g., |
322 // allocate a new object, add a new reference revive a dead object etc.) | 342 // allocate a new object, add a new reference revive a dead object etc.) |
323 // Clearing out pointers to other heap objects is allowed, however. Note | 343 // Clearing out pointers to other heap objects is allowed, however. Note |
(...skipping 13 matching lines...) Expand all Loading... |
337 | 357 |
338 virtual void registerWeakTable(const void*, | 358 virtual void registerWeakTable(const void*, |
339 EphemeronCallback, | 359 EphemeronCallback, |
340 EphemeronCallback) = 0; | 360 EphemeronCallback) = 0; |
341 #if ENABLE(ASSERT) | 361 #if ENABLE(ASSERT) |
342 virtual bool weakTableRegistered(const void*) = 0; | 362 virtual bool weakTableRegistered(const void*) = 0; |
343 #endif | 363 #endif |
344 | 364 |
345 virtual bool ensureMarked(const void*) = 0; | 365 virtual bool ensureMarked(const void*) = 0; |
346 | 366 |
| 367 virtual void registerMovingObjectReference(MovableReference*) = 0; |
| 368 |
| 369 virtual void registerMovingObjectCallback(MovableReference, |
| 370 MovingObjectCallback, |
| 371 void*) = 0; |
| 372 |
347 virtual void registerWeakCellWithCallback(void**, WeakCallback) = 0; | 373 virtual void registerWeakCellWithCallback(void**, WeakCallback) = 0; |
348 | 374 |
349 inline MarkingMode getMarkingMode() const { return m_markingMode; } | 375 inline MarkingMode getMarkingMode() const { return m_markingMode; } |
350 | 376 |
| 377 inline bool isGlobalMarking() const { |
| 378 return m_markingMode == GlobalMarking || |
| 379 m_markingMode == GlobalMarkCompacting; |
| 380 } |
| 381 |
| 382 void setMarkCompactionMode() { m_markingMode = GlobalMarkCompacting; } |
| 383 |
351 protected: | 384 protected: |
352 Visitor(ThreadState*, MarkingMode); | 385 Visitor(ThreadState*, MarkingMode); |
353 | 386 |
354 private: | 387 private: |
355 static Visitor* fromHelper(VisitorHelper<Visitor>* helper) { | 388 static Visitor* fromHelper(VisitorHelper<Visitor>* helper) { |
356 return static_cast<Visitor*>(helper); | 389 return static_cast<Visitor*>(helper); |
357 } | 390 } |
358 | 391 |
359 ThreadState* m_state; | 392 ThreadState* m_state; |
360 const MarkingMode m_markingMode; | 393 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 |