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 16 matching lines...) Expand all Loading... | |
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 ThreadState_h | 31 #ifndef ThreadState_h |
32 #define ThreadState_h | 32 #define ThreadState_h |
33 | 33 |
34 #include "platform/PlatformExport.h" | 34 #include "platform/PlatformExport.h" |
35 #include "platform/heap/AddressSanitizer.h" | 35 #include "platform/heap/AddressSanitizer.h" |
36 #include "public/platform/WebThread.h" | 36 #include "public/platform/WebThread.h" |
37 #include "wtf/HashMap.h" | |
37 #include "wtf/HashSet.h" | 38 #include "wtf/HashSet.h" |
38 #include "wtf/OwnPtr.h" | 39 #include "wtf/OwnPtr.h" |
39 #include "wtf/PassOwnPtr.h" | 40 #include "wtf/PassOwnPtr.h" |
40 #include "wtf/ThreadSpecific.h" | 41 #include "wtf/ThreadSpecific.h" |
41 #include "wtf/Threading.h" | 42 #include "wtf/Threading.h" |
42 #include "wtf/ThreadingPrimitives.h" | 43 #include "wtf/ThreadingPrimitives.h" |
43 #include "wtf/Vector.h" | 44 #include "wtf/Vector.h" |
44 | 45 |
45 #if ENABLE(GC_PROFILE_HEAP) | |
46 #include "wtf/HashMap.h" | |
47 #endif | |
48 | |
49 namespace blink { | 46 namespace blink { |
50 | 47 |
51 class BaseHeap; | 48 class BaseHeap; |
52 class BaseHeapPage; | 49 class BaseHeapPage; |
53 class FinalizedHeapObjectHeader; | 50 class FinalizedHeapObjectHeader; |
54 struct GCInfo; | 51 struct GCInfo; |
55 class HeapContainsCache; | 52 class HeapContainsCache; |
56 class HeapObjectHeader; | 53 class HeapObjectHeader; |
57 class PageMemory; | 54 class PageMemory; |
58 class PersistentNode; | 55 class PersistentNode; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 class Class; \ | 121 class Class; \ |
125 } \ | 122 } \ |
126 namespace blink { \ | 123 namespace blink { \ |
127 template<> struct ThreadingTrait<Namespace::Class> { \ | 124 template<> struct ThreadingTrait<Namespace::Class> { \ |
128 static const ThreadAffinity Affinity = AnyThread; \ | 125 static const ThreadAffinity Affinity = AnyThread; \ |
129 }; \ | 126 }; \ |
130 } | 127 } |
131 | 128 |
132 template<typename U> class ThreadingTrait<const U> : public ThreadingTrait<U> { }; | 129 template<typename U> class ThreadingTrait<const U> : public ThreadingTrait<U> { }; |
133 | 130 |
131 // Declare that a class has a pre-finalizer function. The function can access | |
132 // other garbarge-collected members. However we must not allocate | |
haraken
2014/10/03 06:00:32
Slightly clearer:
(a) The function can access gar
tkent
2014/10/03 06:34:01
(A), (b), (c), and (d) are correct. I should add
haraken
2014/10/03 06:39:18
Agreed.
| |
133 // garbage-collected objects, and must not change content of Member<> and | |
134 // Persistent<>. | |
135 // See ThreadState::registerObjectWithPreFinalizer. | |
136 // | |
137 // Usage: | |
138 // | |
139 // class Foo : GarbageCollected<Foo> { | |
140 // USING_PRE_FINALIZATION_CALLBACK(Foo, dispose); | |
141 // public: | |
142 // Foo() .... | |
143 // private: | |
144 // Member<Bar> m_bar; | |
145 // }; | |
146 // | |
147 // void Foo::dispose() | |
148 // { | |
149 // m_bar->... | |
150 // } | |
151 #define USING_PRE_FINALIZATION_CALLBACK(Class, method) \ | |
haraken
2014/10/03 06:00:31
USING_PRE_FINALIZATION_CALLBACK => USING_PRE_FINAL
tkent
2014/10/06 01:25:53
Done.
| |
152 public: \ | |
153 static bool willFinalizeDeadGarbageCollectedObject(void* object, Visitor& vi sitor) \ | |
tkent
2014/10/03 05:34:26
wrong indentation. will fix.
haraken
2014/10/03 06:00:31
willFinalizeDeadGarbageCollectedObject => invokePr
tkent
2014/10/03 06:34:01
Yeah, it's inconsistent with other names in this p
haraken
2014/10/03 06:39:18
I don't have a strong opinion here, but I guess in
tkent
2014/10/06 01:25:53
Done.
| |
154 { \ | |
155 Class* self = reinterpret_cast<Class*>(object); \ | |
156 if (visitor.isAlive(self)) \ | |
157 return false; \ | |
158 self->method(); \ | |
159 return true; \ | |
160 } \ | |
161 private: \ | |
162 void method() | |
Erik Corry
2014/10/03 09:13:26
To my mind, declaring the method in the macro like
tkent
2014/10/06 01:25:53
Removed the hidden declaration.
| |
163 | |
134 // List of typed heaps. The list is used to generate the implementation | 164 // List of typed heaps. The list is used to generate the implementation |
135 // of typed heap related methods. | 165 // of typed heap related methods. |
136 // | 166 // |
137 // To create a new typed heap add a H(<ClassName>) to the | 167 // To create a new typed heap add a H(<ClassName>) to the |
138 // FOR_EACH_TYPED_HEAP macro below. | 168 // FOR_EACH_TYPED_HEAP macro below. |
139 #define FOR_EACH_TYPED_HEAP(H) \ | 169 #define FOR_EACH_TYPED_HEAP(H) \ |
140 H(Node) | 170 H(Node) |
141 | 171 |
142 #define TypedHeapEnumName(Type) Type##Heap, | 172 #define TypedHeapEnumName(Type) Type##Heap, |
143 #define TypedHeapEnumNameNonFinalized(Type) Type##HeapNonFinalized, | 173 #define TypedHeapEnumNameNonFinalized(Type) Type##HeapNonFinalized, |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
622 | 652 |
623 void getStats(HeapStats&); | 653 void getStats(HeapStats&); |
624 HeapStats& stats() { return m_stats; } | 654 HeapStats& stats() { return m_stats; } |
625 HeapStats& statsAfterLastGC() { return m_statsAfterLastGC; } | 655 HeapStats& statsAfterLastGC() { return m_statsAfterLastGC; } |
626 | 656 |
627 void setupHeapsForTermination(); | 657 void setupHeapsForTermination(); |
628 | 658 |
629 void registerSweepingTask(); | 659 void registerSweepingTask(); |
630 void unregisterSweepingTask(); | 660 void unregisterSweepingTask(); |
631 | 661 |
662 // Request to call a pref-finalize function of the target object before the | |
haraken
2014/10/03 06:00:31
pre-finalizer
tkent
2014/10/06 01:25:53
Done.
| |
663 // object is destructed. The class T must have | |
664 // USING_PRE_FINALIZATION_CALLBACK(). The argument should be |*this|. | |
665 // Registering a lot of objects affects GC performance. We should register | |
666 // an object only if the object really requires pre-finalizer, and we should | |
667 // unregister the object if pre-finalizer is unnecessary. | |
668 template<typename T> | |
669 void registerObjectWithPreFinalizer(T& target) | |
haraken
2014/10/03 06:00:31
registerObjectWithPreFinalizer => registerPreFinal
tkent
2014/10/06 01:25:53
Done.
| |
670 { | |
671 ASSERT(!m_objectsWithPreFinalizer.contains(&target)); | |
haraken
2014/10/03 06:00:31
Shall we add ASSERT(!isSweepInProgress()) ?
tkent
2014/10/06 01:25:53
Done.
| |
672 m_objectsWithPreFinalizer.add(&target, &T::willFinalizeDeadGarbageCollec tedObject); | |
673 } | |
674 // Cancel above requests. The argument should be |*this|. This function is | |
675 // ignored if it is called in pre-finalizer functions. | |
676 template<typename T> | |
677 void unregisterObjectWithPreFinalizer(T& target) | |
haraken
2014/10/03 06:00:32
unregisterObjectWithPreFinalizer => unregisterPreF
tkent
2014/10/06 01:25:53
Done.
| |
678 { | |
679 ASSERT(&T::willFinalizeDeadGarbageCollectedObject); | |
680 unregisterObjectWithPreFinalizerInternal(&target); | |
681 } | |
682 | |
632 Mutex& sweepMutex() { return m_sweepMutex; } | 683 Mutex& sweepMutex() { return m_sweepMutex; } |
633 | 684 |
634 private: | 685 private: |
635 explicit ThreadState(); | 686 explicit ThreadState(); |
636 ~ThreadState(); | 687 ~ThreadState(); |
637 | 688 |
638 friend class SafePointBarrier; | 689 friend class SafePointBarrier; |
639 friend class SafePointAwareMutexLocker; | 690 friend class SafePointAwareMutexLocker; |
640 | 691 |
641 void enterSafePoint(StackState, void*); | 692 void enterSafePoint(StackState, void*); |
(...skipping 18 matching lines...) Expand all Loading... | |
660 // to sweep away any objects that are left on this heap. | 711 // to sweep away any objects that are left on this heap. |
661 // We assert that nothing must remain after this cleanup. | 712 // We assert that nothing must remain after this cleanup. |
662 // If assertion does not hold we crash as we are potentially | 713 // If assertion does not hold we crash as we are potentially |
663 // in the dangling pointer situation. | 714 // in the dangling pointer situation. |
664 void cleanup(); | 715 void cleanup(); |
665 void cleanupPages(); | 716 void cleanupPages(); |
666 | 717 |
667 void setLowCollectionRate(bool value) { m_lowCollectionRate = value; } | 718 void setLowCollectionRate(bool value) { m_lowCollectionRate = value; } |
668 | 719 |
669 void waitUntilSweepersDone(); | 720 void waitUntilSweepersDone(); |
721 void unregisterObjectWithPreFinalizerInternal(void*); | |
722 void invokePreFinalizer(Visitor&); | |
haraken
2014/10/03 06:00:32
invokePreFinalizer => invokePreFinalizers ?
tkent
2014/10/06 01:25:53
Done.
| |
670 | 723 |
671 static WTF::ThreadSpecific<ThreadState*>* s_threadSpecific; | 724 static WTF::ThreadSpecific<ThreadState*>* s_threadSpecific; |
672 static SafePointBarrier* s_safePointBarrier; | 725 static SafePointBarrier* s_safePointBarrier; |
673 | 726 |
674 // This variable is flipped to true after all threads are stoped | 727 // This variable is flipped to true after all threads are stoped |
675 // and outermost GC has started. | 728 // and outermost GC has started. |
676 static bool s_inGC; | 729 static bool s_inGC; |
677 | 730 |
678 // We can't create a static member of type ThreadState here | 731 // We can't create a static member of type ThreadState here |
679 // because it will introduce global constructor and destructor. | 732 // because it will introduce global constructor and destructor. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
711 bool m_isTerminating; | 764 bool m_isTerminating; |
712 | 765 |
713 bool m_lowCollectionRate; | 766 bool m_lowCollectionRate; |
714 | 767 |
715 OwnPtr<blink::WebThread> m_sweeperThread; | 768 OwnPtr<blink::WebThread> m_sweeperThread; |
716 int m_numberOfSweeperTasks; | 769 int m_numberOfSweeperTasks; |
717 Mutex m_sweepMutex; | 770 Mutex m_sweepMutex; |
718 ThreadCondition m_sweepThreadCondition; | 771 ThreadCondition m_sweepThreadCondition; |
719 | 772 |
720 CallbackStack* m_weakCallbackStack; | 773 CallbackStack* m_weakCallbackStack; |
774 HashMap<void*, bool (*)(void*, Visitor&)> m_objectsWithPreFinalizer; | |
haraken
2014/10/03 06:00:32
m_objectsWithPreFinalizer => m_preFinalizers ?
tkent
2014/10/06 01:25:53
Done.
| |
721 | 775 |
722 #if defined(ADDRESS_SANITIZER) | 776 #if defined(ADDRESS_SANITIZER) |
723 void* m_asanFakeStack; | 777 void* m_asanFakeStack; |
724 #endif | 778 #endif |
725 }; | 779 }; |
726 | 780 |
727 template<ThreadAffinity affinity> class ThreadStateFor; | 781 template<ThreadAffinity affinity> class ThreadStateFor; |
728 | 782 |
729 template<> class ThreadStateFor<MainThreadOnly> { | 783 template<> class ThreadStateFor<MainThreadOnly> { |
730 public: | 784 public: |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
847 // whether the page is part of a terminting thread or | 901 // whether the page is part of a terminting thread or |
848 // if the page is traced after being terminated (orphaned). | 902 // if the page is traced after being terminated (orphaned). |
849 uintptr_t m_terminating : 1; | 903 uintptr_t m_terminating : 1; |
850 uintptr_t m_tracedAfterOrphaned : 1; | 904 uintptr_t m_tracedAfterOrphaned : 1; |
851 uintptr_t m_promptlyFreedSize : 17; // == blinkPageSizeLog2 | 905 uintptr_t m_promptlyFreedSize : 17; // == blinkPageSizeLog2 |
852 }; | 906 }; |
853 | 907 |
854 } | 908 } |
855 | 909 |
856 #endif // ThreadState_h | 910 #endif // ThreadState_h |
OLD | NEW |