Chromium Code Reviews| Index: Source/platform/heap/ThreadState.h |
| diff --git a/Source/platform/heap/ThreadState.h b/Source/platform/heap/ThreadState.h |
| index 2513756aae2b550b1871a7f1c07efebffb3c35b5..7ad0fab19443d8fb3fbb3a92ab3969818ada6103 100644 |
| --- a/Source/platform/heap/ThreadState.h |
| +++ b/Source/platform/heap/ThreadState.h |
| @@ -34,6 +34,7 @@ |
| #include "platform/PlatformExport.h" |
| #include "platform/heap/AddressSanitizer.h" |
| #include "public/platform/WebThread.h" |
| +#include "wtf/HashMap.h" |
| #include "wtf/HashSet.h" |
| #include "wtf/OwnPtr.h" |
| #include "wtf/PassOwnPtr.h" |
| @@ -42,10 +43,6 @@ |
| #include "wtf/ThreadingPrimitives.h" |
| #include "wtf/Vector.h" |
| -#if ENABLE(GC_PROFILE_HEAP) |
| -#include "wtf/HashMap.h" |
| -#endif |
| - |
| namespace blink { |
| class BaseHeap; |
| @@ -131,6 +128,41 @@ struct ThreadingTrait { |
| template<typename U> class ThreadingTrait<const U> : public ThreadingTrait<U> { }; |
| +// Declare that a class has a pre-finalizer function. The function is called in |
| +// the object's owner thread, and can access Member<>s to other |
| +// garbarge-collected objects allocated in the thread. However we must not |
| +// 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.
|
| +// Persistent<> pointers. |
| +// |
| +// See ThreadState::registerPreFinalizer. |
| +// |
| +// Usage: |
| +// |
| +// class Foo : GarbageCollected<Foo> { |
| +// USING_PRE_FINALIZER(Foo, dispose); |
| +// public: |
| +// Foo() .... |
| +// private: |
| +// void dispose(); |
| +// Member<Bar> m_bar; |
| +// }; |
| +// |
| +// void Foo::dispose() |
| +// { |
| +// m_bar->... |
| +// } |
| +#define USING_PRE_FINALIZER(Class, method) \ |
| + public: \ |
| + static bool invokePreFinalier(void* object, Visitor& visitor) \ |
|
haraken
2014/10/06 01:55:27
invokePreFinalier => invokePreFinalizer
tkent
2014/10/06 05:01:43
Done.
|
| + { \ |
| + Class* self = reinterpret_cast<Class*>(object); \ |
| + if (visitor.isAlive(self)) \ |
| + return false; \ |
| + self->method(); \ |
| + return true; \ |
| + } \ |
| + 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
|
| + |
| // List of typed heaps. The list is used to generate the implementation |
| // of typed heap related methods. |
| // |
| @@ -629,6 +661,28 @@ public: |
| void registerSweepingTask(); |
| void unregisterSweepingTask(); |
| + // 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.
|
| + // object is destructed. The class T must have USING_PRE_FINALIZER(). The |
| + // 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.
|
| + // performance. We should register an object only if the object really |
| + // requires pre-finalizer, and we should unregister the object if |
| + // pre-finalizer is unnecessary. |
| + template<typename T> |
| + void registerPreFinalizer(T& target) |
| + { |
| + ASSERT(!m_preFinalizers.contains(&target)); |
| + ASSERT(!isSweepInProgress()); |
| + m_preFinalizers.add(&target, &T::invokePreFinalier); |
| + } |
| + // Cancel above requests. The argument should be |*this|. This function is |
| + // ignored if it is called in pre-finalizer functions. |
| + template<typename T> |
| + void unregisterPreFinalizer(T& target) |
| + { |
| + ASSERT(&T::invokePreFinalier); |
| + unregisterPreFinalizerInternal(&target); |
| + } |
| + |
| Mutex& sweepMutex() { return m_sweepMutex; } |
| private: |
| @@ -667,6 +721,8 @@ private: |
| void setLowCollectionRate(bool value) { m_lowCollectionRate = value; } |
| void waitUntilSweepersDone(); |
| + void unregisterPreFinalizerInternal(void*); |
| + void invokePreFinalizers(Visitor&); |
| static WTF::ThreadSpecific<ThreadState*>* s_threadSpecific; |
| static SafePointBarrier* s_safePointBarrier; |
| @@ -718,6 +774,7 @@ private: |
| ThreadCondition m_sweepThreadCondition; |
| CallbackStack* m_weakCallbackStack; |
| + 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.
|
| #if defined(ADDRESS_SANITIZER) |
| void* m_asanFakeStack; |