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