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

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: Add a FIXME 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
« no previous file with comments | « Source/platform/heap/HeapTest.cpp ('k') | Source/platform/heap/ThreadState.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
Erik Corry 2014/10/06 12:39:18 garbarge -> garbage
tkent 2014/10/07 05:10:08 will fix.
134 // allocate new garbage-collected objects, nor update Member<> and Persistent<>
135 // pointers.
136 //
137 // This feature is similar to the HeapHashMap<WeakMember<Foo>, OwnPtr<Disposer>>
138 // idiom. The difference between this and the idiom is that pre-finalizer
139 // function is called whenever an object is destructed with this feature. The
140 // HeapHashMap<WeakMember...> idiom requires an assumption that the HeapHashMap
141 // outlives objects pointed by WeakMembers.
Erik Corry 2014/10/06 12:39:18 This does not make sense to me. I'm also not happ
haraken 2014/10/06 12:54:05 We're just planning to remove the weak hash maps t
tkent 2014/10/07 05:10:08 The latter. I'll update the comment.
142 // FIXME: Replace all of the HeapHashMap<WeakMember<Foo>, OwnPtr<Disposer>>
143 // idiom usages with the pre-finalizer.
144 //
145 // See ThreadState::registerPreFinalizer.
146 //
147 // Usage:
148 //
149 // class Foo : GarbageCollected<Foo> {
150 // USING_PRE_FINALIZER(Foo, dispose);
151 // public:
152 // Foo()
153 // {
154 // ThreadState::current()->registerPreFinalizer(*this);
155 // }
156 // private:
157 // void dispose();
158 // Member<Bar> m_bar;
159 // };
160 //
161 // void Foo::dispose()
162 // {
163 // m_bar->...
164 // }
165 #define USING_PRE_FINALIZER(Class, method) \
166 public: \
167 static bool invokePreFinalizer(void* object, Visitor& visitor) \
168 { \
169 Class* self = reinterpret_cast<Class*>(object); \
170 if (visitor.isAlive(self)) \
171 return false; \
172 self->method(); \
173 return true; \
174 } \
175 typedef char UsingPreFinazlizerMacroNeedsTrailingSemiColon
176
134 // List of typed heaps. The list is used to generate the implementation 177 // List of typed heaps. The list is used to generate the implementation
135 // of typed heap related methods. 178 // of typed heap related methods.
136 // 179 //
137 // To create a new typed heap add a H(<ClassName>) to the 180 // To create a new typed heap add a H(<ClassName>) to the
138 // FOR_EACH_TYPED_HEAP macro below. 181 // FOR_EACH_TYPED_HEAP macro below.
139 #define FOR_EACH_TYPED_HEAP(H) \ 182 #define FOR_EACH_TYPED_HEAP(H) \
140 H(Node) 183 H(Node)
141 184
142 #define TypedHeapEnumName(Type) Type##Heap, 185 #define TypedHeapEnumName(Type) Type##Heap,
143 #define TypedHeapEnumNameNonFinalized(Type) Type##HeapNonFinalized, 186 #define TypedHeapEnumNameNonFinalized(Type) Type##HeapNonFinalized,
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 665
623 void getStats(HeapStats&); 666 void getStats(HeapStats&);
624 HeapStats& stats() { return m_stats; } 667 HeapStats& stats() { return m_stats; }
625 HeapStats& statsAfterLastGC() { return m_statsAfterLastGC; } 668 HeapStats& statsAfterLastGC() { return m_statsAfterLastGC; }
626 669
627 void setupHeapsForTermination(); 670 void setupHeapsForTermination();
628 671
629 void registerSweepingTask(); 672 void registerSweepingTask();
630 void unregisterSweepingTask(); 673 void unregisterSweepingTask();
631 674
675 // Request to call a pref-finalizer of the target object before the object
676 // is destructed. The class T must have USING_PRE_FINALIZER(). The
677 // argument should be |*this|. Registering a lot of objects affects GC
678 // performance. We should register an object only if the object really
679 // requires pre-finalizer, and we should unregister the object if
680 // pre-finalizer is unnecessary.
681 template<typename T>
682 void registerPreFinalizer(T& target)
683 {
684 ASSERT(!m_preFinalizers.contains(&target));
685 ASSERT(!isSweepInProgress());
686 m_preFinalizers.add(&target, &T::invokePreFinalizer);
687 }
688
689 // Cancel above requests. The argument should be |*this|. This function is
690 // ignored if it is called in pre-finalizer functions.
691 template<typename T>
692 void unregisterPreFinalizer(T& target)
693 {
694 ASSERT(&T::invokePreFinalizer);
695 unregisterPreFinalizerInternal(&target);
696 }
697
632 Mutex& sweepMutex() { return m_sweepMutex; } 698 Mutex& sweepMutex() { return m_sweepMutex; }
633 699
634 private: 700 private:
635 explicit ThreadState(); 701 explicit ThreadState();
636 ~ThreadState(); 702 ~ThreadState();
637 703
638 friend class SafePointBarrier; 704 friend class SafePointBarrier;
639 friend class SafePointAwareMutexLocker; 705 friend class SafePointAwareMutexLocker;
640 706
641 void enterSafePoint(StackState, void*); 707 void enterSafePoint(StackState, void*);
(...skipping 18 matching lines...) Expand all
660 // to sweep away any objects that are left on this heap. 726 // to sweep away any objects that are left on this heap.
661 // We assert that nothing must remain after this cleanup. 727 // We assert that nothing must remain after this cleanup.
662 // If assertion does not hold we crash as we are potentially 728 // If assertion does not hold we crash as we are potentially
663 // in the dangling pointer situation. 729 // in the dangling pointer situation.
664 void cleanup(); 730 void cleanup();
665 void cleanupPages(); 731 void cleanupPages();
666 732
667 void setLowCollectionRate(bool value) { m_lowCollectionRate = value; } 733 void setLowCollectionRate(bool value) { m_lowCollectionRate = value; }
668 734
669 void waitUntilSweepersDone(); 735 void waitUntilSweepersDone();
736 void unregisterPreFinalizerInternal(void*);
737 void invokePreFinalizers(Visitor&);
670 738
671 static WTF::ThreadSpecific<ThreadState*>* s_threadSpecific; 739 static WTF::ThreadSpecific<ThreadState*>* s_threadSpecific;
672 static SafePointBarrier* s_safePointBarrier; 740 static SafePointBarrier* s_safePointBarrier;
673 741
674 // This variable is flipped to true after all threads are stoped 742 // This variable is flipped to true after all threads are stoped
675 // and outermost GC has started. 743 // and outermost GC has started.
676 static bool s_inGC; 744 static bool s_inGC;
677 745
678 // We can't create a static member of type ThreadState here 746 // We can't create a static member of type ThreadState here
679 // because it will introduce global constructor and destructor. 747 // because it will introduce global constructor and destructor.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 bool m_isTerminating; 779 bool m_isTerminating;
712 780
713 bool m_lowCollectionRate; 781 bool m_lowCollectionRate;
714 782
715 OwnPtr<blink::WebThread> m_sweeperThread; 783 OwnPtr<blink::WebThread> m_sweeperThread;
716 int m_numberOfSweeperTasks; 784 int m_numberOfSweeperTasks;
717 Mutex m_sweepMutex; 785 Mutex m_sweepMutex;
718 ThreadCondition m_sweepThreadCondition; 786 ThreadCondition m_sweepThreadCondition;
719 787
720 CallbackStack* m_weakCallbackStack; 788 CallbackStack* m_weakCallbackStack;
789 HashMap<void*, bool (*)(void*, Visitor&)> m_preFinalizers;
721 790
722 #if defined(ADDRESS_SANITIZER) 791 #if defined(ADDRESS_SANITIZER)
723 void* m_asanFakeStack; 792 void* m_asanFakeStack;
724 #endif 793 #endif
725 }; 794 };
726 795
727 template<ThreadAffinity affinity> class ThreadStateFor; 796 template<ThreadAffinity affinity> class ThreadStateFor;
728 797
729 template<> class ThreadStateFor<MainThreadOnly> { 798 template<> class ThreadStateFor<MainThreadOnly> {
730 public: 799 public:
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 // whether the page is part of a terminting thread or 916 // whether the page is part of a terminting thread or
848 // if the page is traced after being terminated (orphaned). 917 // if the page is traced after being terminated (orphaned).
849 uintptr_t m_terminating : 1; 918 uintptr_t m_terminating : 1;
850 uintptr_t m_tracedAfterOrphaned : 1; 919 uintptr_t m_tracedAfterOrphaned : 1;
851 uintptr_t m_promptlyFreedSize : 17; // == blinkPageSizeLog2 920 uintptr_t m_promptlyFreedSize : 17; // == blinkPageSizeLog2
852 }; 921 };
853 922
854 } 923 }
855 924
856 #endif // ThreadState_h 925 #endif // ThreadState_h
OLDNEW
« no previous file with comments | « Source/platform/heap/HeapTest.cpp ('k') | Source/platform/heap/ThreadState.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698