| 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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 #endif | 172 #endif |
| 173 }; | 173 }; |
| 174 | 174 |
| 175 template<typename T> class TraceTrait<const T> : public TraceTrait<T> { }; | 175 template<typename T> class TraceTrait<const T> : public TraceTrait<T> { }; |
| 176 | 176 |
| 177 template<typename Collection> | 177 template<typename Collection> |
| 178 struct OffHeapCollectionTraceTrait; | 178 struct OffHeapCollectionTraceTrait; |
| 179 | 179 |
| 180 template<typename T> | 180 template<typename T> |
| 181 struct ObjectAliveTrait { | 181 struct ObjectAliveTrait { |
| 182 static bool isAlive(Visitor*, T); | 182 static bool isAlive(Visitor*, T*); |
| 183 }; | |
| 184 | |
| 185 template<typename T> | |
| 186 struct ObjectAliveTrait<Member<T> > { | |
| 187 static bool isAlive(Visitor*, const Member<T>&); | |
| 188 }; | 183 }; |
| 189 | 184 |
| 190 // Visitor is used to traverse the Blink object graph. Used for the | 185 // Visitor is used to traverse the Blink object graph. Used for the |
| 191 // marking phase of the mark-sweep garbage collector. | 186 // marking phase of the mark-sweep garbage collector. |
| 192 // | 187 // |
| 193 // Pointers are marked and pushed on the marking stack by calling the | 188 // Pointers are marked and pushed on the marking stack by calling the |
| 194 // |mark| method with the pointer as an argument. | 189 // |mark| method with the pointer as an argument. |
| 195 // | 190 // |
| 196 // Pointers within objects are traced by calling the |trace| methods | 191 // Pointers within objects are traced by calling the |trace| methods |
| 197 // with the object as an argument. Tracing objects will mark all of the | 192 // with the object as an argument. Tracing objects will mark all of the |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 // run on the thread performing garbage collection. Therefore, all | 354 // run on the thread performing garbage collection. Therefore, all |
| 360 // threads are stopped during weak cell callbacks. | 355 // threads are stopped during weak cell callbacks. |
| 361 template<typename T> | 356 template<typename T> |
| 362 void registerWeakCell(T** cell) | 357 void registerWeakCell(T** cell) |
| 363 { | 358 { |
| 364 registerWeakCell(reinterpret_cast<void**>(cell), &handleWeakCell<T>); | 359 registerWeakCell(reinterpret_cast<void**>(cell), &handleWeakCell<T>); |
| 365 } | 360 } |
| 366 | 361 |
| 367 virtual bool isMarked(const void*) = 0; | 362 virtual bool isMarked(const void*) = 0; |
| 368 | 363 |
| 369 template<typename T> inline bool isAlive(T obj) { return ObjectAliveTrait<T>
::isAlive(this, obj); } | 364 template<typename T> inline bool isAlive(T* obj) |
| 365 { |
| 366 return ObjectAliveTrait<T>::isAlive(this, obj); |
| 367 } |
| 370 template<typename T> inline bool isAlive(const Member<T>& member) | 368 template<typename T> inline bool isAlive(const Member<T>& member) |
| 371 { | 369 { |
| 372 return isAlive(member.get()); | 370 return isAlive(member.get()); |
| 373 } | 371 } |
| 374 | 372 |
| 375 #ifndef NDEBUG | 373 #ifndef NDEBUG |
| 376 void checkGCInfo(const void*, const GCInfo*); | 374 void checkGCInfo(const void*, const GCInfo*); |
| 377 #endif | 375 #endif |
| 378 | 376 |
| 379 // Macro to declare methods needed for each typed heap. | 377 // Macro to declare methods needed for each typed heap. |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 #ifndef NDEBUG | 516 #ifndef NDEBUG |
| 519 static void checkGCInfo(Visitor*, const T*) { } | 517 static void checkGCInfo(Visitor*, const T*) { } |
| 520 #endif | 518 #endif |
| 521 }; | 519 }; |
| 522 | 520 |
| 523 template<typename T, bool = NeedsAdjustAndMark<T>::value> class DefaultObjectAli
veTrait; | 521 template<typename T, bool = NeedsAdjustAndMark<T>::value> class DefaultObjectAli
veTrait; |
| 524 | 522 |
| 525 template<typename T> | 523 template<typename T> |
| 526 class DefaultObjectAliveTrait<T, false> { | 524 class DefaultObjectAliveTrait<T, false> { |
| 527 public: | 525 public: |
| 528 static bool isAlive(Visitor* visitor, T obj) | 526 static bool isAlive(Visitor* visitor, T* obj) |
| 529 { | 527 { |
| 530 return visitor->isMarked(obj); | 528 return visitor->isMarked(obj); |
| 531 } | 529 } |
| 532 }; | 530 }; |
| 533 | 531 |
| 534 template<typename T> | 532 template<typename T> |
| 535 class DefaultObjectAliveTrait<T, true> { | 533 class DefaultObjectAliveTrait<T, true> { |
| 536 public: | 534 public: |
| 537 static bool isAlive(Visitor* visitor, T obj) | 535 static bool isAlive(Visitor* visitor, T* obj) |
| 538 { | 536 { |
| 539 return obj->isAlive(visitor); | 537 return obj->isAlive(visitor); |
| 540 } | 538 } |
| 541 }; | 539 }; |
| 542 | 540 |
| 543 template<typename T> bool ObjectAliveTrait<T>::isAlive(Visitor* visitor, T obj) | 541 template<typename T> bool ObjectAliveTrait<T>::isAlive(Visitor* visitor, T* obj) |
| 544 { | 542 { |
| 545 return DefaultObjectAliveTrait<T>::isAlive(visitor, obj); | 543 return DefaultObjectAliveTrait<T>::isAlive(visitor, obj); |
| 546 } | 544 } |
| 547 template<typename T> bool ObjectAliveTrait<Member<T> >::isAlive(Visitor* visitor
, const Member<T>& obj) | |
| 548 { | |
| 549 return visitor->isMarked(obj.get()); | |
| 550 } | |
| 551 | 545 |
| 552 // The GarbageCollectedMixin interface and helper macro | 546 // The GarbageCollectedMixin interface and helper macro |
| 553 // USING_GARBAGE_COLLECTED_MIXIN can be used to automatically define | 547 // USING_GARBAGE_COLLECTED_MIXIN can be used to automatically define |
| 554 // TraceTrait/ObjectAliveTrait on non-leftmost deriving classes | 548 // TraceTrait/ObjectAliveTrait on non-leftmost deriving classes |
| 555 // which need to be garbage collected. | 549 // which need to be garbage collected. |
| 556 // | 550 // |
| 557 // Consider the following case: | 551 // Consider the following case: |
| 558 // class B {}; | 552 // class B {}; |
| 559 // class A : public GarbageCollected, public B {}; | 553 // class A : public GarbageCollected, public B {}; |
| 560 // | 554 // |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 struct GCInfoTrait { | 619 struct GCInfoTrait { |
| 626 static const GCInfo* get() | 620 static const GCInfo* get() |
| 627 { | 621 { |
| 628 return GCInfoAtBase<typename GetGarbageCollectedBase<T>::type>::get(); | 622 return GCInfoAtBase<typename GetGarbageCollectedBase<T>::type>::get(); |
| 629 } | 623 } |
| 630 }; | 624 }; |
| 631 | 625 |
| 632 } | 626 } |
| 633 | 627 |
| 634 #endif | 628 #endif |
| OLD | NEW |