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/Deque.h" | 38 #include "wtf/Deque.h" |
38 #include "wtf/Forward.h" | 39 #include "wtf/Forward.h" |
39 #include "wtf/HashMap.h" | 40 #include "wtf/HashMap.h" |
40 #include "wtf/HashTraits.h" | 41 #include "wtf/HashTraits.h" |
41 #include "wtf/InstanceCounter.h" | 42 #include "wtf/InstanceCounter.h" |
42 #include "wtf/OwnPtr.h" | 43 #include "wtf/OwnPtr.h" |
43 #include "wtf/RefPtr.h" | 44 #include "wtf/RefPtr.h" |
44 #include "wtf/TypeTraits.h" | 45 #include "wtf/TypeTraits.h" |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 virtual bool ensureMarked(const void*) = 0; | 606 virtual bool ensureMarked(const void*) = 0; |
606 | 607 |
607 #if ENABLE(GC_PROFILE_MARKING) | 608 #if ENABLE(GC_PROFILE_MARKING) |
608 void setHostInfo(void* object, const String& name) | 609 void setHostInfo(void* object, const String& name) |
609 { | 610 { |
610 m_hostObject = object; | 611 m_hostObject = object; |
611 m_hostName = name; | 612 m_hostName = name; |
612 } | 613 } |
613 #endif | 614 #endif |
614 | 615 |
615 inline bool canTraceEagerly() const { return m_traceDepth < kMaxEagerTraceDe
pth; } | 616 inline bool canTraceEagerly() const |
616 inline void incrementTraceDepth() { m_traceDepth++; } | 617 { |
617 inline void decrementTraceDepth() { ASSERT(m_traceDepth > 0); m_traceDepth--
; } | 618 ASSERT(m_stackFrameDepth); |
| 619 return m_stackFrameDepth->isSafeToRecurse(); |
| 620 } |
| 621 |
| 622 inline void configureEagerTraceLimit() |
| 623 { |
| 624 if (!m_stackFrameDepth) |
| 625 m_stackFrameDepth = new StackFrameDepth; |
| 626 m_stackFrameDepth->configureLimit(); |
| 627 } |
618 | 628 |
619 inline bool isGlobalMarkingVisitor() const { return m_isGlobalMarkingVisitor
; } | 629 inline bool isGlobalMarkingVisitor() const { return m_isGlobalMarkingVisitor
; } |
620 | 630 |
621 protected: | 631 protected: |
622 explicit Visitor(VisitorType type) | 632 explicit Visitor(VisitorType type) |
623 : m_isGlobalMarkingVisitor(type == GlobalMarkingVisitorType) | 633 : m_isGlobalMarkingVisitor(type == GlobalMarkingVisitorType) |
624 { | 634 { } |
625 m_traceDepth = 0; | |
626 } | |
627 | 635 |
628 virtual void registerWeakCellWithCallback(void**, WeakPointerCallback) = 0; | 636 virtual void registerWeakCellWithCallback(void**, WeakPointerCallback) = 0; |
629 #if ENABLE(GC_PROFILE_MARKING) | 637 #if ENABLE(GC_PROFILE_MARKING) |
630 virtual void recordObjectGraphEdge(const void*) | 638 virtual void recordObjectGraphEdge(const void*) |
631 { | 639 { |
632 ASSERT_NOT_REACHED(); | 640 ASSERT_NOT_REACHED(); |
633 } | 641 } |
634 | 642 |
635 void* m_hostObject; | 643 void* m_hostObject; |
636 String m_hostName; | 644 String m_hostName; |
637 #endif | 645 #endif |
638 | 646 |
639 private: | 647 private: |
640 static Visitor* fromHelper(VisitorHelper<Visitor>* helper) { return static_c
ast<Visitor*>(helper); } | 648 static Visitor* fromHelper(VisitorHelper<Visitor>* helper) { return static_c
ast<Visitor*>(helper); } |
| 649 static StackFrameDepth* m_stackFrameDepth; |
641 | 650 |
642 // The maximum depth of eager, unrolled trace() calls that is | |
643 // considered safe and allowed. | |
644 const int kMaxEagerTraceDepth = 100; | |
645 | |
646 static int m_traceDepth; | |
647 bool m_isGlobalMarkingVisitor; | 651 bool m_isGlobalMarkingVisitor; |
648 }; | 652 }; |
649 | 653 |
650 // We trace vectors by using the trace trait on each element, which means you | 654 // We trace vectors by using the trace trait on each element, which means you |
651 // can have vectors of general objects (not just pointers to objects) that can | 655 // can have vectors of general objects (not just pointers to objects) that can |
652 // be traced. | 656 // be traced. |
653 template<typename T, size_t N> | 657 template<typename T, size_t N> |
654 struct OffHeapCollectionTraceTrait<WTF::Vector<T, N, WTF::DefaultAllocator> > { | 658 struct OffHeapCollectionTraceTrait<WTF::Vector<T, N, WTF::DefaultAllocator> > { |
655 typedef WTF::Vector<T, N, WTF::DefaultAllocator> Vector; | 659 typedef WTF::Vector<T, N, WTF::DefaultAllocator> Vector; |
656 | 660 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 if (TraceEagerlyTrait<T>::value) { | 707 if (TraceEagerlyTrait<T>::value) { |
704 // Protect against too deep trace call chains, and the | 708 // Protect against too deep trace call chains, and the |
705 // unbounded system stack usage they can bring about. | 709 // unbounded system stack usage they can bring about. |
706 // | 710 // |
707 // Assert against deep stacks so as to flush them out, | 711 // Assert against deep stacks so as to flush them out, |
708 // but test and appropriately handle them should they occur | 712 // but test and appropriately handle them should they occur |
709 // in release builds. | 713 // in release builds. |
710 ASSERT(visitor->canTraceEagerly()); | 714 ASSERT(visitor->canTraceEagerly()); |
711 if (LIKELY(visitor->canTraceEagerly())) { | 715 if (LIKELY(visitor->canTraceEagerly())) { |
712 if (visitor->ensureMarked(t)) { | 716 if (visitor->ensureMarked(t)) { |
713 visitor->incrementTraceDepth(); | |
714 TraceTrait<T>::trace(visitor, const_cast<T*>(t)); | 717 TraceTrait<T>::trace(visitor, const_cast<T*>(t)); |
715 visitor->decrementTraceDepth(); | |
716 } | 718 } |
717 return; | 719 return; |
718 } | 720 } |
719 } | 721 } |
720 visitor->mark(const_cast<T*>(t), &TraceTrait<T>::trace); | 722 visitor->mark(const_cast<T*>(t), &TraceTrait<T>::trace); |
721 } | 723 } |
722 | 724 |
723 #if ENABLE(ASSERT) | 725 #if ENABLE(ASSERT) |
724 static void checkGCInfo(const T* t) | 726 static void checkGCInfo(const T* t) |
725 { | 727 { |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
906 struct GCInfoTrait { | 908 struct GCInfoTrait { |
907 static size_t index() | 909 static size_t index() |
908 { | 910 { |
909 return GCInfoAtBase<typename GetGarbageCollectedBase<T>::type>::index(); | 911 return GCInfoAtBase<typename GetGarbageCollectedBase<T>::type>::index(); |
910 } | 912 } |
911 }; | 913 }; |
912 | 914 |
913 } | 915 } |
914 | 916 |
915 #endif | 917 #endif |
OLD | NEW |