| 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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 // However, the TraceTrait can be specialized to use a different | 192 // However, the TraceTrait can be specialized to use a different |
| 193 // implementation. A common case where a TraceTrait specialization is | 193 // implementation. A common case where a TraceTrait specialization is |
| 194 // needed is when multiple inheritance leads to pointers that are not | 194 // needed is when multiple inheritance leads to pointers that are not |
| 195 // to the start of the object in the Blink garbage-collected heap. In | 195 // to the start of the object in the Blink garbage-collected heap. In |
| 196 // that case the pointer has to be adjusted before marking. | 196 // that case the pointer has to be adjusted before marking. |
| 197 template<typename T> | 197 template<typename T> |
| 198 class TraceTrait { | 198 class TraceTrait { |
| 199 public: | 199 public: |
| 200 // Default implementation of TraceTrait<T>::trace just statically | 200 // Default implementation of TraceTrait<T>::trace just statically |
| 201 // dispatches to the trace method of the class T. | 201 // dispatches to the trace method of the class T. |
| 202 template<typename TraceDispatcher> | 202 template<typename VisitorDispatcher> |
| 203 static void trace(TraceDispatcher visitor, void* self) | 203 static void trace(VisitorDispatcher visitor, void* self) |
| 204 { | 204 { |
| 205 TraceCompatibilityAdaptor<T>::trace(visitor, static_cast<T*>(self)); | 205 TraceCompatibilityAdaptor<T>::trace(visitor, static_cast<T*>(self)); |
| 206 } | 206 } |
| 207 | 207 |
| 208 static void mark(Visitor* visitor, const T* t) | 208 template<typename VisitorDispatcher> |
| 209 static void mark(VisitorDispatcher visitor, const T* t) |
| 209 { | 210 { |
| 210 DefaultTraceTrait<T>::mark(visitor, t); | 211 DefaultTraceTrait<T>::mark(visitor, t); |
| 211 } | 212 } |
| 212 | 213 |
| 213 #if ENABLE(ASSERT) | 214 #if ENABLE(ASSERT) |
| 214 static void checkGCInfo(const T* t) | 215 static void checkGCInfo(const T* t) |
| 215 { | 216 { |
| 216 DefaultTraceTrait<T>::checkGCInfo(t); | 217 DefaultTraceTrait<T>::checkGCInfo(t); |
| 217 } | 218 } |
| 218 #endif | 219 #endif |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 bool m_isGlobalMarkingVisitor; | 663 bool m_isGlobalMarkingVisitor; |
| 663 }; | 664 }; |
| 664 | 665 |
| 665 // We trace vectors by using the trace trait on each element, which means you | 666 // We trace vectors by using the trace trait on each element, which means you |
| 666 // can have vectors of general objects (not just pointers to objects) that can | 667 // can have vectors of general objects (not just pointers to objects) that can |
| 667 // be traced. | 668 // be traced. |
| 668 template<typename T, size_t N> | 669 template<typename T, size_t N> |
| 669 struct OffHeapCollectionTraceTrait<WTF::Vector<T, N, WTF::DefaultAllocator> > { | 670 struct OffHeapCollectionTraceTrait<WTF::Vector<T, N, WTF::DefaultAllocator> > { |
| 670 typedef WTF::Vector<T, N, WTF::DefaultAllocator> Vector; | 671 typedef WTF::Vector<T, N, WTF::DefaultAllocator> Vector; |
| 671 | 672 |
| 672 static void trace(Visitor* visitor, const Vector& vector) | 673 template<typename VisitorDispatcher> |
| 674 static void trace(VisitorDispatcher visitor, const Vector& vector) |
| 673 { | 675 { |
| 674 if (vector.isEmpty()) | 676 if (vector.isEmpty()) |
| 675 return; | 677 return; |
| 676 for (typename Vector::const_iterator it = vector.begin(), end = vector.e
nd(); it != end; ++it) | 678 for (typename Vector::const_iterator it = vector.begin(), end = vector.e
nd(); it != end; ++it) |
| 677 TraceTrait<T>::trace(visitor, const_cast<T*>(it)); | 679 TraceTrait<T>::trace(visitor, const_cast<T*>(it)); |
| 678 } | 680 } |
| 679 }; | 681 }; |
| 680 | 682 |
| 681 template<typename T, size_t N> | 683 template<typename T, size_t N> |
| 682 struct OffHeapCollectionTraceTrait<WTF::Deque<T, N> > { | 684 struct OffHeapCollectionTraceTrait<WTF::Deque<T, N> > { |
| 683 typedef WTF::Deque<T, N> Deque; | 685 typedef WTF::Deque<T, N> Deque; |
| 684 | 686 |
| 685 static void trace(Visitor* visitor, const Deque& deque) | 687 template<typename VisitorDispatcher> |
| 688 static void trace(VisitorDispatcher visitor, const Deque& deque) |
| 686 { | 689 { |
| 687 if (deque.isEmpty()) | 690 if (deque.isEmpty()) |
| 688 return; | 691 return; |
| 689 for (typename Deque::const_iterator it = deque.begin(), end = deque.end(
); it != end; ++it) | 692 for (typename Deque::const_iterator it = deque.begin(), end = deque.end(
); it != end; ++it) |
| 690 TraceTrait<T>::trace(visitor, const_cast<T*>(&(*it))); | 693 TraceTrait<T>::trace(visitor, const_cast<T*>(&(*it))); |
| 691 } | 694 } |
| 692 }; | 695 }; |
| 693 | 696 |
| 694 template<typename T, typename Traits = WTF::VectorTraits<T> > | 697 template<typename T, typename Traits = WTF::VectorTraits<T> > |
| 695 class HeapVectorBacking; | 698 class HeapVectorBacking; |
| 696 | 699 |
| 697 template<typename Table> | 700 template<typename Table> |
| 698 class HeapHashTableBacking { | 701 class HeapHashTableBacking { |
| 699 public: | 702 public: |
| 700 static void finalize(void* pointer); | 703 static void finalize(void* pointer); |
| 701 }; | 704 }; |
| 702 | 705 |
| 703 template<typename T> | 706 template<typename T> |
| 704 class DefaultTraceTrait<T, false> { | 707 class DefaultTraceTrait<T, false> { |
| 705 public: | 708 public: |
| 706 static void mark(Visitor* visitor, const T* t) | 709 template<typename VisitorDispatcher> |
| 710 static void mark(VisitorDispatcher visitor, const T* t) |
| 707 { | 711 { |
| 708 // Default mark method of the trait just calls the two-argument mark | 712 // Default mark method of the trait just calls the two-argument mark |
| 709 // method on the visitor. The second argument is the static trace method | 713 // method on the visitor. The second argument is the static trace method |
| 710 // of the trait, which by default calls the instance method | 714 // of the trait, which by default calls the instance method |
| 711 // trace(Visitor*) on the object. | 715 // trace(Visitor*) on the object. |
| 712 // | 716 // |
| 713 // If the trait allows it, invoke the trace callback right here on the | 717 // If the trait allows it, invoke the trace callback right here on the |
| 714 // not-yet-marked object. | 718 // not-yet-marked object. |
| 715 if (TraceEagerlyTrait<T>::value) { | 719 if (TraceEagerlyTrait<T>::value) { |
| 716 // Protect against too deep trace call chains, and the | 720 // Protect against too deep trace call chains, and the |
| (...skipping 19 matching lines...) Expand all Loading... |
| 736 static void checkGCInfo(const T* t) | 740 static void checkGCInfo(const T* t) |
| 737 { | 741 { |
| 738 assertObjectHasGCInfo(const_cast<T*>(t), GCInfoTrait<T>::get()); | 742 assertObjectHasGCInfo(const_cast<T*>(t), GCInfoTrait<T>::get()); |
| 739 } | 743 } |
| 740 #endif | 744 #endif |
| 741 }; | 745 }; |
| 742 | 746 |
| 743 template<typename T> | 747 template<typename T> |
| 744 class DefaultTraceTrait<T, true> { | 748 class DefaultTraceTrait<T, true> { |
| 745 public: | 749 public: |
| 746 static void mark(Visitor* visitor, const T* self) | 750 template<typename VisitorDispatcher> |
| 751 static void mark(VisitorDispatcher visitor, const T* self) |
| 747 { | 752 { |
| 748 if (!self) | 753 if (!self) |
| 749 return; | 754 return; |
| 750 | 755 |
| 751 // If you hit this ASSERT, it means that there is a dangling pointer | 756 // If you hit this ASSERT, it means that there is a dangling pointer |
| 752 // from a live thread heap to a dead thread heap. We must eliminate | 757 // from a live thread heap to a dead thread heap. We must eliminate |
| 753 // the dangling pointer. | 758 // the dangling pointer. |
| 754 // Release builds don't have the ASSERT, but it is OK because | 759 // Release builds don't have the ASSERT, but it is OK because |
| 755 // release builds will crash at the following self->adjustAndMark | 760 // release builds will crash at the following self->adjustAndMark |
| 756 // because all the entries of the orphaned heaps are zeroed out and | 761 // because all the entries of the orphaned heaps are zeroed out and |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 886 struct GCInfoTrait { | 891 struct GCInfoTrait { |
| 887 static const GCInfo* get() | 892 static const GCInfo* get() |
| 888 { | 893 { |
| 889 return GCInfoAtBase<typename GetGarbageCollectedBase<T>::type>::get(); | 894 return GCInfoAtBase<typename GetGarbageCollectedBase<T>::type>::get(); |
| 890 } | 895 } |
| 891 }; | 896 }; |
| 892 | 897 |
| 893 } | 898 } |
| 894 | 899 |
| 895 #endif | 900 #endif |
| OLD | NEW |