Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(535)

Side by Side Diff: Source/platform/heap/Visitor.h

Issue 827723002: Reland: Templatize visitor arguments for TraceTrait mark and trace methods. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebased Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/platform/heap/HeapTest.cpp ('k') | Source/wtf/Deque.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 // However, the TraceTrait can be specialized to use a different 187 // However, the TraceTrait can be specialized to use a different
188 // implementation. A common case where a TraceTrait specialization is 188 // implementation. A common case where a TraceTrait specialization is
189 // needed is when multiple inheritance leads to pointers that are not 189 // needed is when multiple inheritance leads to pointers that are not
190 // to the start of the object in the Blink garbage-collected heap. In 190 // to the start of the object in the Blink garbage-collected heap. In
191 // that case the pointer has to be adjusted before marking. 191 // that case the pointer has to be adjusted before marking.
192 template<typename T> 192 template<typename T>
193 class TraceTrait { 193 class TraceTrait {
194 public: 194 public:
195 // Default implementation of TraceTrait<T>::trace just statically 195 // Default implementation of TraceTrait<T>::trace just statically
196 // dispatches to the trace method of the class T. 196 // dispatches to the trace method of the class T.
197 template<typename TraceDispatcher> 197 template<typename VisitorDispatcher>
198 static void trace(TraceDispatcher visitor, void* self) 198 static void trace(VisitorDispatcher visitor, void* self)
199 { 199 {
200 TraceCompatibilityAdaptor<T>::trace(visitor, static_cast<T*>(self)); 200 TraceCompatibilityAdaptor<T>::trace(visitor, static_cast<T*>(self));
201 } 201 }
202 202
203 static void mark(Visitor* visitor, const T* t) 203 template<typename VisitorDispatcher>
204 static void mark(VisitorDispatcher visitor, const T* t)
204 { 205 {
205 DefaultTraceTrait<T>::mark(visitor, t); 206 DefaultTraceTrait<T>::mark(visitor, t);
206 } 207 }
207 208
208 #if ENABLE(ASSERT) 209 #if ENABLE(ASSERT)
209 static void checkGCInfo(const T* t) 210 static void checkGCInfo(const T* t)
210 { 211 {
211 DefaultTraceTrait<T>::checkGCInfo(t); 212 DefaultTraceTrait<T>::checkGCInfo(t);
212 } 213 }
213 #endif 214 #endif
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 bool m_isGlobalMarkingVisitor; 647 bool m_isGlobalMarkingVisitor;
647 }; 648 };
648 649
649 // We trace vectors by using the trace trait on each element, which means you 650 // We trace vectors by using the trace trait on each element, which means you
650 // can have vectors of general objects (not just pointers to objects) that can 651 // can have vectors of general objects (not just pointers to objects) that can
651 // be traced. 652 // be traced.
652 template<typename T, size_t N> 653 template<typename T, size_t N>
653 struct OffHeapCollectionTraceTrait<WTF::Vector<T, N, WTF::DefaultAllocator> > { 654 struct OffHeapCollectionTraceTrait<WTF::Vector<T, N, WTF::DefaultAllocator> > {
654 typedef WTF::Vector<T, N, WTF::DefaultAllocator> Vector; 655 typedef WTF::Vector<T, N, WTF::DefaultAllocator> Vector;
655 656
656 static void trace(Visitor* visitor, const Vector& vector) 657 template<typename VisitorDispatcher>
658 static void trace(VisitorDispatcher visitor, const Vector& vector)
657 { 659 {
658 if (vector.isEmpty()) 660 if (vector.isEmpty())
659 return; 661 return;
660 for (typename Vector::const_iterator it = vector.begin(), end = vector.e nd(); it != end; ++it) 662 for (typename Vector::const_iterator it = vector.begin(), end = vector.e nd(); it != end; ++it)
661 TraceTrait<T>::trace(visitor, const_cast<T*>(it)); 663 TraceTrait<T>::trace(visitor, const_cast<T*>(it));
662 } 664 }
663 }; 665 };
664 666
665 template<typename T, size_t N> 667 template<typename T, size_t N>
666 struct OffHeapCollectionTraceTrait<WTF::Deque<T, N> > { 668 struct OffHeapCollectionTraceTrait<WTF::Deque<T, N> > {
667 typedef WTF::Deque<T, N> Deque; 669 typedef WTF::Deque<T, N> Deque;
668 670
669 static void trace(Visitor* visitor, const Deque& deque) 671 template<typename VisitorDispatcher>
672 static void trace(VisitorDispatcher visitor, const Deque& deque)
670 { 673 {
671 if (deque.isEmpty()) 674 if (deque.isEmpty())
672 return; 675 return;
673 for (typename Deque::const_iterator it = deque.begin(), end = deque.end( ); it != end; ++it) 676 for (typename Deque::const_iterator it = deque.begin(), end = deque.end( ); it != end; ++it)
674 TraceTrait<T>::trace(visitor, const_cast<T*>(&(*it))); 677 TraceTrait<T>::trace(visitor, const_cast<T*>(&(*it)));
675 } 678 }
676 }; 679 };
677 680
678 template<typename T, typename Traits = WTF::VectorTraits<T> > 681 template<typename T, typename Traits = WTF::VectorTraits<T> >
679 class HeapVectorBacking; 682 class HeapVectorBacking;
680 683
681 template<typename Table> 684 template<typename Table>
682 class HeapHashTableBacking { 685 class HeapHashTableBacking {
683 public: 686 public:
684 static void finalize(void* pointer); 687 static void finalize(void* pointer);
685 }; 688 };
686 689
687 template<typename T> 690 template<typename T>
688 class DefaultTraceTrait<T, false> { 691 class DefaultTraceTrait<T, false> {
689 public: 692 public:
690 static void mark(Visitor* visitor, const T* t) 693 template<typename VisitorDispatcher>
694 static void mark(VisitorDispatcher visitor, const T* t)
691 { 695 {
692 // Default mark method of the trait just calls the two-argument mark 696 // Default mark method of the trait just calls the two-argument mark
693 // method on the visitor. The second argument is the static trace method 697 // method on the visitor. The second argument is the static trace method
694 // of the trait, which by default calls the instance method 698 // of the trait, which by default calls the instance method
695 // trace(Visitor*) on the object. 699 // trace(Visitor*) on the object.
696 // 700 //
697 // If the trait allows it, invoke the trace callback right here on the 701 // If the trait allows it, invoke the trace callback right here on the
698 // not-yet-marked object. 702 // not-yet-marked object.
699 if (TraceEagerlyTrait<T>::value) { 703 if (TraceEagerlyTrait<T>::value) {
700 // Protect against too deep trace call chains, and the 704 // Protect against too deep trace call chains, and the
(...skipping 19 matching lines...) Expand all
720 static void checkGCInfo(const T* t) 724 static void checkGCInfo(const T* t)
721 { 725 {
722 assertObjectHasGCInfo(const_cast<T*>(t), GCInfoTrait<T>::index()); 726 assertObjectHasGCInfo(const_cast<T*>(t), GCInfoTrait<T>::index());
723 } 727 }
724 #endif 728 #endif
725 }; 729 };
726 730
727 template<typename T> 731 template<typename T>
728 class DefaultTraceTrait<T, true> { 732 class DefaultTraceTrait<T, true> {
729 public: 733 public:
730 static void mark(Visitor* visitor, const T* self) 734 template<typename VisitorDispatcher>
735 static void mark(VisitorDispatcher visitor, const T* self)
731 { 736 {
732 if (!self) 737 if (!self)
733 return; 738 return;
734 739
735 // If you hit this ASSERT, it means that there is a dangling pointer 740 // If you hit this ASSERT, it means that there is a dangling pointer
736 // from a live thread heap to a dead thread heap. We must eliminate 741 // from a live thread heap to a dead thread heap. We must eliminate
737 // the dangling pointer. 742 // the dangling pointer.
738 // Release builds don't have the ASSERT, but it is OK because 743 // Release builds don't have the ASSERT, but it is OK because
739 // release builds will crash at the following self->adjustAndMark 744 // release builds will crash at the following self->adjustAndMark
740 // because all the entries of the orphaned heaps are zeroed out and 745 // because all the entries of the orphaned heaps are zeroed out and
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 struct GCInfoTrait { 889 struct GCInfoTrait {
885 static size_t index() 890 static size_t index()
886 { 891 {
887 return GCInfoAtBase<typename GetGarbageCollectedBase<T>::type>::index(); 892 return GCInfoAtBase<typename GetGarbageCollectedBase<T>::type>::index();
888 } 893 }
889 }; 894 };
890 895
891 } 896 }
892 897
893 #endif 898 #endif
OLDNEW
« no previous file with comments | « Source/platform/heap/HeapTest.cpp ('k') | Source/wtf/Deque.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698