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

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

Issue 623033002: Oilpan: Add support of pre-finalization callback to Oilpan infrastructure. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: apply review comments Created 6 years, 2 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 | Annotate | Revision Log
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 16 matching lines...) Expand all
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
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 is called in
132 // the object's owner thread, and can access Member<>s to other
133 // garbarge-collected objects allocated in the thread. However we must not
134 // allocate new garbage-collected objects, and must not update Member<> and
haraken 2014/10/06 01:55:27 , and => nor
tkent 2014/10/06 05:01:43 Done.
135 // Persistent<> pointers.
136 //
137 // See ThreadState::registerPreFinalizer.
138 //
139 // Usage:
140 //
141 // class Foo : GarbageCollected<Foo> {
142 // USING_PRE_FINALIZER(Foo, dispose);
143 // public:
144 // Foo() ....
145 // private:
146 // void dispose();
147 // Member<Bar> m_bar;
148 // };
149 //
150 // void Foo::dispose()
151 // {
152 // m_bar->...
153 // }
154 #define USING_PRE_FINALIZER(Class, method) \
155 public: \
156 static bool invokePreFinalier(void* object, Visitor& visitor) \
haraken 2014/10/06 01:55:27 invokePreFinalier => invokePreFinalizer
tkent 2014/10/06 05:01:43 Done.
157 { \
158 Class* self = reinterpret_cast<Class*>(object); \
159 if (visitor.isAlive(self)) \
160 return false; \
161 self->method(); \
162 return true; \
163 } \
164 typedef char UsingPreFinazlizerMacroNeedsTrailingSemiColon
haraken 2014/10/06 01:55:27 What's this?
tkent 2014/10/06 05:01:43 This is an idiom to make ';' after USING_PRE_FINAL
165
134 // List of typed heaps. The list is used to generate the implementation 166 // List of typed heaps. The list is used to generate the implementation
135 // of typed heap related methods. 167 // of typed heap related methods.
136 // 168 //
137 // To create a new typed heap add a H(<ClassName>) to the 169 // To create a new typed heap add a H(<ClassName>) to the
138 // FOR_EACH_TYPED_HEAP macro below. 170 // FOR_EACH_TYPED_HEAP macro below.
139 #define FOR_EACH_TYPED_HEAP(H) \ 171 #define FOR_EACH_TYPED_HEAP(H) \
140 H(Node) 172 H(Node)
141 173
142 #define TypedHeapEnumName(Type) Type##Heap, 174 #define TypedHeapEnumName(Type) Type##Heap,
143 #define TypedHeapEnumNameNonFinalized(Type) Type##HeapNonFinalized, 175 #define TypedHeapEnumNameNonFinalized(Type) Type##HeapNonFinalized,
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 654
623 void getStats(HeapStats&); 655 void getStats(HeapStats&);
624 HeapStats& stats() { return m_stats; } 656 HeapStats& stats() { return m_stats; }
625 HeapStats& statsAfterLastGC() { return m_statsAfterLastGC; } 657 HeapStats& statsAfterLastGC() { return m_statsAfterLastGC; }
626 658
627 void setupHeapsForTermination(); 659 void setupHeapsForTermination();
628 660
629 void registerSweepingTask(); 661 void registerSweepingTask();
630 void unregisterSweepingTask(); 662 void unregisterSweepingTask();
631 663
664 // Request to call a pref-finalizer function of the target object before the
haraken 2014/10/06 01:55:27 a pref-finalizer function => a pre-finalizer
tkent 2014/10/06 05:01:43 Done.
665 // object is destructed. The class T must have USING_PRE_FINALIZER(). The
666 // argument should be |*this|. Registering a lot of objects affects GC
haraken 2014/10/06 01:55:27 Would it be possible to define registerPreFinalize
tkent 2014/10/06 05:01:43 It's not impossible, however I think it's not an i
haraken 2014/10/06 05:26:42 Makes sense.
667 // performance. We should register an object only if the object really
668 // requires pre-finalizer, and we should unregister the object if
669 // pre-finalizer is unnecessary.
670 template<typename T>
671 void registerPreFinalizer(T& target)
672 {
673 ASSERT(!m_preFinalizers.contains(&target));
674 ASSERT(!isSweepInProgress());
675 m_preFinalizers.add(&target, &T::invokePreFinalier);
676 }
677 // Cancel above requests. The argument should be |*this|. This function is
678 // ignored if it is called in pre-finalizer functions.
679 template<typename T>
680 void unregisterPreFinalizer(T& target)
681 {
682 ASSERT(&T::invokePreFinalier);
683 unregisterPreFinalizerInternal(&target);
684 }
685
632 Mutex& sweepMutex() { return m_sweepMutex; } 686 Mutex& sweepMutex() { return m_sweepMutex; }
633 687
634 private: 688 private:
635 explicit ThreadState(); 689 explicit ThreadState();
636 ~ThreadState(); 690 ~ThreadState();
637 691
638 friend class SafePointBarrier; 692 friend class SafePointBarrier;
639 friend class SafePointAwareMutexLocker; 693 friend class SafePointAwareMutexLocker;
640 694
641 void enterSafePoint(StackState, void*); 695 void enterSafePoint(StackState, void*);
(...skipping 18 matching lines...) Expand all
660 // to sweep away any objects that are left on this heap. 714 // to sweep away any objects that are left on this heap.
661 // We assert that nothing must remain after this cleanup. 715 // We assert that nothing must remain after this cleanup.
662 // If assertion does not hold we crash as we are potentially 716 // If assertion does not hold we crash as we are potentially
663 // in the dangling pointer situation. 717 // in the dangling pointer situation.
664 void cleanup(); 718 void cleanup();
665 void cleanupPages(); 719 void cleanupPages();
666 720
667 void setLowCollectionRate(bool value) { m_lowCollectionRate = value; } 721 void setLowCollectionRate(bool value) { m_lowCollectionRate = value; }
668 722
669 void waitUntilSweepersDone(); 723 void waitUntilSweepersDone();
724 void unregisterPreFinalizerInternal(void*);
725 void invokePreFinalizers(Visitor&);
670 726
671 static WTF::ThreadSpecific<ThreadState*>* s_threadSpecific; 727 static WTF::ThreadSpecific<ThreadState*>* s_threadSpecific;
672 static SafePointBarrier* s_safePointBarrier; 728 static SafePointBarrier* s_safePointBarrier;
673 729
674 // This variable is flipped to true after all threads are stoped 730 // This variable is flipped to true after all threads are stoped
675 // and outermost GC has started. 731 // and outermost GC has started.
676 static bool s_inGC; 732 static bool s_inGC;
677 733
678 // We can't create a static member of type ThreadState here 734 // We can't create a static member of type ThreadState here
679 // because it will introduce global constructor and destructor. 735 // because it will introduce global constructor and destructor.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 bool m_isTerminating; 767 bool m_isTerminating;
712 768
713 bool m_lowCollectionRate; 769 bool m_lowCollectionRate;
714 770
715 OwnPtr<blink::WebThread> m_sweeperThread; 771 OwnPtr<blink::WebThread> m_sweeperThread;
716 int m_numberOfSweeperTasks; 772 int m_numberOfSweeperTasks;
717 Mutex m_sweepMutex; 773 Mutex m_sweepMutex;
718 ThreadCondition m_sweepThreadCondition; 774 ThreadCondition m_sweepThreadCondition;
719 775
720 CallbackStack* m_weakCallbackStack; 776 CallbackStack* m_weakCallbackStack;
777 HashMap<void*, bool (*)(void*, Visitor&)> m_preFinalizers;
haraken 2014/10/06 01:55:28 Can we add an assertion to verify that m_preFinali
tkent 2014/10/06 05:01:43 Done.
721 778
722 #if defined(ADDRESS_SANITIZER) 779 #if defined(ADDRESS_SANITIZER)
723 void* m_asanFakeStack; 780 void* m_asanFakeStack;
724 #endif 781 #endif
725 }; 782 };
726 783
727 template<ThreadAffinity affinity> class ThreadStateFor; 784 template<ThreadAffinity affinity> class ThreadStateFor;
728 785
729 template<> class ThreadStateFor<MainThreadOnly> { 786 template<> class ThreadStateFor<MainThreadOnly> {
730 public: 787 public:
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 // whether the page is part of a terminting thread or 904 // whether the page is part of a terminting thread or
848 // if the page is traced after being terminated (orphaned). 905 // if the page is traced after being terminated (orphaned).
849 uintptr_t m_terminating : 1; 906 uintptr_t m_terminating : 1;
850 uintptr_t m_tracedAfterOrphaned : 1; 907 uintptr_t m_tracedAfterOrphaned : 1;
851 uintptr_t m_promptlyFreedSize : 17; // == blinkPageSizeLog2 908 uintptr_t m_promptlyFreedSize : 17; // == blinkPageSizeLog2
852 }; 909 };
853 910
854 } 911 }
855 912
856 #endif // ThreadState_h 913 #endif // ThreadState_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698