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 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 virtual bool ensureMarked(const void*) = 0; | 621 virtual bool ensureMarked(const void*) = 0; |
621 | 622 |
622 #if ENABLE(GC_PROFILE_MARKING) | 623 #if ENABLE(GC_PROFILE_MARKING) |
623 void setHostInfo(void* object, const String& name) | 624 void setHostInfo(void* object, const String& name) |
624 { | 625 { |
625 m_hostObject = object; | 626 m_hostObject = object; |
626 m_hostName = name; | 627 m_hostName = name; |
627 } | 628 } |
628 #endif | 629 #endif |
629 | 630 |
630 inline bool canTraceEagerly() const { return m_traceDepth < kMaxEagerTraceDe
pth; } | 631 inline static bool canTraceEagerly() |
631 inline void incrementTraceDepth() { m_traceDepth++; } | 632 { |
632 inline void decrementTraceDepth() { ASSERT(m_traceDepth > 0); m_traceDepth--
; } | 633 ASSERT(m_stackFrameDepth); |
| 634 return m_stackFrameDepth->isSafeToRecurse(); |
| 635 } |
| 636 |
| 637 inline static void configureEagerTraceLimit() |
| 638 { |
| 639 if (!m_stackFrameDepth) |
| 640 m_stackFrameDepth = new StackFrameDepth; |
| 641 m_stackFrameDepth->configureLimit(); |
| 642 } |
633 | 643 |
634 inline bool isGlobalMarkingVisitor() const { return m_isGlobalMarkingVisitor
; } | 644 inline bool isGlobalMarkingVisitor() const { return m_isGlobalMarkingVisitor
; } |
635 | 645 |
636 #if ENABLE(ASSERT) | 646 #if ENABLE(ASSERT) |
637 virtual void setAllowMarkingForHashTableWeakProcessing(bool) { } | 647 virtual void setAllowMarkingForHashTableWeakProcessing(bool) { } |
638 #endif | 648 #endif |
639 | 649 |
640 protected: | 650 protected: |
641 explicit Visitor(VisitorType type) | 651 explicit Visitor(VisitorType type) |
642 : m_isGlobalMarkingVisitor(type == GlobalMarkingVisitorType) | 652 : m_isGlobalMarkingVisitor(type == GlobalMarkingVisitorType) |
643 { | 653 { } |
644 m_traceDepth = 0; | |
645 } | |
646 | 654 |
647 virtual void registerWeakCellWithCallback(void**, WeakPointerCallback) = 0; | 655 virtual void registerWeakCellWithCallback(void**, WeakPointerCallback) = 0; |
648 #if ENABLE(GC_PROFILE_MARKING) | 656 #if ENABLE(GC_PROFILE_MARKING) |
649 virtual void recordObjectGraphEdge(const void*) | 657 virtual void recordObjectGraphEdge(const void*) |
650 { | 658 { |
651 ASSERT_NOT_REACHED(); | 659 ASSERT_NOT_REACHED(); |
652 } | 660 } |
653 | 661 |
654 void* m_hostObject; | 662 void* m_hostObject; |
655 String m_hostName; | 663 String m_hostName; |
656 #endif | 664 #endif |
657 | 665 |
658 #if ENABLE(ASSERT) | 666 #if ENABLE(ASSERT) |
659 virtual void checkMarkingAllowed() { } | 667 virtual void checkMarkingAllowed() { } |
660 #endif | 668 #endif |
661 | 669 |
662 private: | 670 private: |
663 static Visitor* fromHelper(VisitorHelper<Visitor>* helper) { return static_c
ast<Visitor*>(helper); } | 671 static Visitor* fromHelper(VisitorHelper<Visitor>* helper) { return static_c
ast<Visitor*>(helper); } |
| 672 static StackFrameDepth* m_stackFrameDepth; |
664 | 673 |
665 // The maximum depth of eager, unrolled trace() calls that is | |
666 // considered safe and allowed. | |
667 const int kMaxEagerTraceDepth = 100; | |
668 | |
669 static int m_traceDepth; | |
670 bool m_isGlobalMarkingVisitor; | 674 bool m_isGlobalMarkingVisitor; |
671 }; | 675 }; |
672 | 676 |
673 // We trace vectors by using the trace trait on each element, which means you | 677 // We trace vectors by using the trace trait on each element, which means you |
674 // can have vectors of general objects (not just pointers to objects) that can | 678 // can have vectors of general objects (not just pointers to objects) that can |
675 // be traced. | 679 // be traced. |
676 template<typename T, size_t N> | 680 template<typename T, size_t N> |
677 struct OffHeapCollectionTraceTrait<WTF::Vector<T, N, WTF::DefaultAllocator> > { | 681 struct OffHeapCollectionTraceTrait<WTF::Vector<T, N, WTF::DefaultAllocator> > { |
678 typedef WTF::Vector<T, N, WTF::DefaultAllocator> Vector; | 682 typedef WTF::Vector<T, N, WTF::DefaultAllocator> Vector; |
679 | 683 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 // | 727 // |
724 // If the trait allows it, invoke the trace callback right here on the | 728 // If the trait allows it, invoke the trace callback right here on the |
725 // not-yet-marked object. | 729 // not-yet-marked object. |
726 if (TraceEagerlyTrait<T>::value) { | 730 if (TraceEagerlyTrait<T>::value) { |
727 // Protect against too deep trace call chains, and the | 731 // Protect against too deep trace call chains, and the |
728 // unbounded system stack usage they can bring about. | 732 // unbounded system stack usage they can bring about. |
729 // | 733 // |
730 // Assert against deep stacks so as to flush them out, | 734 // Assert against deep stacks so as to flush them out, |
731 // but test and appropriately handle them should they occur | 735 // but test and appropriately handle them should they occur |
732 // in release builds. | 736 // in release builds. |
733 ASSERT(visitor->canTraceEagerly()); | 737 // FIXME: visitor->isMarked(t) exception is to allow empty trace() |
| 738 // calls from HashTable weak processing. Remove the condition once |
| 739 // it is refactored. |
| 740 ASSERT(visitor->canTraceEagerly() || visitor->isMarked(t)); |
734 if (LIKELY(visitor->canTraceEagerly())) { | 741 if (LIKELY(visitor->canTraceEagerly())) { |
735 if (visitor->ensureMarked(t)) { | 742 if (visitor->ensureMarked(t)) { |
736 visitor->incrementTraceDepth(); | |
737 TraceTrait<T>::trace(visitor, const_cast<T*>(t)); | 743 TraceTrait<T>::trace(visitor, const_cast<T*>(t)); |
738 visitor->decrementTraceDepth(); | |
739 } | 744 } |
740 return; | 745 return; |
741 } | 746 } |
742 } | 747 } |
743 visitor->mark(const_cast<T*>(t), &TraceTrait<T>::trace); | 748 visitor->mark(const_cast<T*>(t), &TraceTrait<T>::trace); |
744 } | 749 } |
745 | 750 |
746 #if ENABLE(ASSERT) | 751 #if ENABLE(ASSERT) |
747 static void checkGCInfo(const T* t) | 752 static void checkGCInfo(const T* t) |
748 { | 753 { |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
930 struct GCInfoTrait { | 935 struct GCInfoTrait { |
931 static size_t index() | 936 static size_t index() |
932 { | 937 { |
933 return GCInfoAtBase<typename GetGarbageCollectedBase<T>::type>::index(); | 938 return GCInfoAtBase<typename GetGarbageCollectedBase<T>::type>::index(); |
934 } | 939 } |
935 }; | 940 }; |
936 | 941 |
937 } | 942 } |
938 | 943 |
939 #endif | 944 #endif |
OLD | NEW |