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 14 matching lines...) Expand all Loading... | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #ifndef Visitor_h | 31 #ifndef Visitor_h |
32 #define Visitor_h | 32 #define Visitor_h |
33 | 33 |
34 #include "platform/PlatformExport.h" | 34 #include "platform/PlatformExport.h" |
35 #include "platform/heap/StackFrameDepth.h" | |
35 #include "platform/heap/ThreadState.h" | 36 #include "platform/heap/ThreadState.h" |
36 #include "wtf/Assertions.h" | 37 #include "wtf/Assertions.h" |
37 #include "wtf/Atomics.h" | 38 #include "wtf/Atomics.h" |
38 #include "wtf/Deque.h" | 39 #include "wtf/Deque.h" |
39 #include "wtf/Forward.h" | 40 #include "wtf/Forward.h" |
40 #include "wtf/HashMap.h" | 41 #include "wtf/HashMap.h" |
41 #include "wtf/HashTraits.h" | 42 #include "wtf/HashTraits.h" |
42 #include "wtf/InstanceCounter.h" | 43 #include "wtf/InstanceCounter.h" |
43 #include "wtf/OwnPtr.h" | 44 #include "wtf/OwnPtr.h" |
44 #include "wtf/RefPtr.h" | 45 #include "wtf/RefPtr.h" |
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
619 virtual bool ensureMarked(const void*) = 0; | 620 virtual bool ensureMarked(const void*) = 0; |
620 | 621 |
621 #if ENABLE(GC_PROFILE_MARKING) | 622 #if ENABLE(GC_PROFILE_MARKING) |
622 void setHostInfo(void* object, const String& name) | 623 void setHostInfo(void* object, const String& name) |
623 { | 624 { |
624 m_hostObject = object; | 625 m_hostObject = object; |
625 m_hostName = name; | 626 m_hostName = name; |
626 } | 627 } |
627 #endif | 628 #endif |
628 | 629 |
629 inline bool canTraceEagerly() const { return m_traceDepth < kMaxEagerTraceDe pth; } | 630 inline static bool canTraceEagerly() |
630 inline void incrementTraceDepth() { m_traceDepth++; } | 631 { |
631 inline void decrementTraceDepth() { ASSERT(m_traceDepth > 0); m_traceDepth-- ; } | 632 ASSERT(m_stackFrameDepth); |
633 return m_stackFrameDepth->isSafeToRecurse(); | |
634 } | |
635 | |
636 inline static void configureEagerTraceLimit() | |
637 { | |
638 if (!m_stackFrameDepth) | |
639 m_stackFrameDepth = new StackFrameDepth; | |
640 m_stackFrameDepth->configureLimit(); | |
641 } | |
632 | 642 |
633 inline bool isGlobalMarkingVisitor() const { return m_isGlobalMarkingVisitor ; } | 643 inline bool isGlobalMarkingVisitor() const { return m_isGlobalMarkingVisitor ; } |
634 | 644 |
635 protected: | 645 protected: |
636 explicit Visitor(VisitorType type) | 646 explicit Visitor(VisitorType type) |
637 : m_isGlobalMarkingVisitor(type == GlobalMarkingVisitorType) | 647 : m_isGlobalMarkingVisitor(type == GlobalMarkingVisitorType) |
638 { | 648 { } |
639 m_traceDepth = 0; | |
640 } | |
641 | 649 |
642 virtual void registerWeakCellWithCallback(void**, WeakPointerCallback) = 0; | 650 virtual void registerWeakCellWithCallback(void**, WeakPointerCallback) = 0; |
643 #if ENABLE(GC_PROFILE_MARKING) | 651 #if ENABLE(GC_PROFILE_MARKING) |
644 virtual void recordObjectGraphEdge(const void*) | 652 virtual void recordObjectGraphEdge(const void*) |
645 { | 653 { |
646 ASSERT_NOT_REACHED(); | 654 ASSERT_NOT_REACHED(); |
647 } | 655 } |
648 | 656 |
649 void* m_hostObject; | 657 void* m_hostObject; |
650 String m_hostName; | 658 String m_hostName; |
651 #endif | 659 #endif |
652 | 660 |
653 private: | 661 private: |
654 static Visitor* fromHelper(VisitorHelper<Visitor>* helper) { return static_c ast<Visitor*>(helper); } | 662 static Visitor* fromHelper(VisitorHelper<Visitor>* helper) { return static_c ast<Visitor*>(helper); } |
663 static StackFrameDepth* m_stackFrameDepth; | |
655 | 664 |
656 // The maximum depth of eager, unrolled trace() calls that is | |
657 // considered safe and allowed. | |
658 const int kMaxEagerTraceDepth = 100; | |
659 | |
660 static int m_traceDepth; | |
661 bool m_isGlobalMarkingVisitor; | 665 bool m_isGlobalMarkingVisitor; |
662 }; | 666 }; |
663 | 667 |
664 // We trace vectors by using the trace trait on each element, which means you | 668 // We trace vectors by using the trace trait on each element, which means you |
665 // can have vectors of general objects (not just pointers to objects) that can | 669 // can have vectors of general objects (not just pointers to objects) that can |
666 // be traced. | 670 // be traced. |
667 template<typename T, size_t N> | 671 template<typename T, size_t N> |
668 struct OffHeapCollectionTraceTrait<WTF::Vector<T, N, WTF::DefaultAllocator> > { | 672 struct OffHeapCollectionTraceTrait<WTF::Vector<T, N, WTF::DefaultAllocator> > { |
669 typedef WTF::Vector<T, N, WTF::DefaultAllocator> Vector; | 673 typedef WTF::Vector<T, N, WTF::DefaultAllocator> Vector; |
670 | 674 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
714 // | 718 // |
715 // If the trait allows it, invoke the trace callback right here on the | 719 // If the trait allows it, invoke the trace callback right here on the |
716 // not-yet-marked object. | 720 // not-yet-marked object. |
717 if (TraceEagerlyTrait<T>::value) { | 721 if (TraceEagerlyTrait<T>::value) { |
718 // Protect against too deep trace call chains, and the | 722 // Protect against too deep trace call chains, and the |
719 // unbounded system stack usage they can bring about. | 723 // unbounded system stack usage they can bring about. |
720 // | 724 // |
721 // Assert against deep stacks so as to flush them out, | 725 // Assert against deep stacks so as to flush them out, |
722 // but test and appropriately handle them should they occur | 726 // but test and appropriately handle them should they occur |
723 // in release builds. | 727 // in release builds. |
724 ASSERT(visitor->canTraceEagerly()); | 728 ASSERT(visitor->canTraceEagerly() || visitor->isMarked(t)); |
haraken
2015/01/14 05:29:57
visitor->isMarked(t) is just for weak processing i
sof
2015/01/14 07:03:43
Yes, an explanatory comment of the RHS of "||" wou
| |
725 if (LIKELY(visitor->canTraceEagerly())) { | 729 if (LIKELY(visitor->canTraceEagerly())) { |
726 if (visitor->ensureMarked(t)) { | 730 if (visitor->ensureMarked(t)) { |
727 visitor->incrementTraceDepth(); | |
728 TraceTrait<T>::trace(visitor, const_cast<T*>(t)); | 731 TraceTrait<T>::trace(visitor, const_cast<T*>(t)); |
729 visitor->decrementTraceDepth(); | |
730 } | 732 } |
731 return; | 733 return; |
732 } | 734 } |
733 } | 735 } |
734 visitor->mark(const_cast<T*>(t), &TraceTrait<T>::trace); | 736 visitor->mark(const_cast<T*>(t), &TraceTrait<T>::trace); |
735 } | 737 } |
736 | 738 |
737 #if ENABLE(ASSERT) | 739 #if ENABLE(ASSERT) |
738 static void checkGCInfo(const T* t) | 740 static void checkGCInfo(const T* t) |
739 { | 741 { |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
921 struct GCInfoTrait { | 923 struct GCInfoTrait { |
922 static size_t index() | 924 static size_t index() |
923 { | 925 { |
924 return GCInfoAtBase<typename GetGarbageCollectedBase<T>::type>::index(); | 926 return GCInfoAtBase<typename GetGarbageCollectedBase<T>::type>::index(); |
925 } | 927 } |
926 }; | 928 }; |
927 | 929 |
928 } | 930 } |
929 | 931 |
930 #endif | 932 #endif |
OLD | NEW |