Index: Source/platform/heap/ThreadState.h |
diff --git a/Source/platform/heap/ThreadState.h b/Source/platform/heap/ThreadState.h |
index 2513756aae2b550b1871a7f1c07efebffb3c35b5..dfd4076afb2e169e9eb56653dbb03a1e80ea86fe 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,39 @@ struct ThreadingTrait { |
template<typename U> class ThreadingTrait<const U> : public ThreadingTrait<U> { }; |
+// Declare that a class has a pre-finalizer function. The function can access |
+// 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.
|
+// garbage-collected objects, and must not change content of Member<> and |
+// Persistent<>. |
+// See ThreadState::registerObjectWithPreFinalizer. |
+// |
+// Usage: |
+// |
+// class Foo : GarbageCollected<Foo> { |
+// USING_PRE_FINALIZATION_CALLBACK(Foo, dispose); |
+// public: |
+// Foo() .... |
+// private: |
+// Member<Bar> m_bar; |
+// }; |
+// |
+// void Foo::dispose() |
+// { |
+// m_bar->... |
+// } |
+#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.
|
+ public: \ |
+ static bool willFinalizeDeadGarbageCollectedObject(void* object, Visitor& visitor) \ |
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.
|
+ { \ |
+ Class* self = reinterpret_cast<Class*>(object); \ |
+ if (visitor.isAlive(self)) \ |
+ return false; \ |
+ self->method(); \ |
+ return true; \ |
+ } \ |
+ private: \ |
+ 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.
|
+ |
// List of typed heaps. The list is used to generate the implementation |
// of typed heap related methods. |
// |
@@ -629,6 +659,27 @@ public: |
void registerSweepingTask(); |
void unregisterSweepingTask(); |
+ // 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.
|
+ // object is destructed. The class T must have |
+ // USING_PRE_FINALIZATION_CALLBACK(). The argument should be |*this|. |
+ // Registering a lot of objects affects GC 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 registerObjectWithPreFinalizer(T& target) |
haraken
2014/10/03 06:00:31
registerObjectWithPreFinalizer => registerPreFinal
tkent
2014/10/06 01:25:53
Done.
|
+ { |
+ 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.
|
+ m_objectsWithPreFinalizer.add(&target, &T::willFinalizeDeadGarbageCollectedObject); |
+ } |
+ // Cancel above requests. The argument should be |*this|. This function is |
+ // ignored if it is called in pre-finalizer functions. |
+ template<typename T> |
+ void unregisterObjectWithPreFinalizer(T& target) |
haraken
2014/10/03 06:00:32
unregisterObjectWithPreFinalizer => unregisterPreF
tkent
2014/10/06 01:25:53
Done.
|
+ { |
+ ASSERT(&T::willFinalizeDeadGarbageCollectedObject); |
+ unregisterObjectWithPreFinalizerInternal(&target); |
+ } |
+ |
Mutex& sweepMutex() { return m_sweepMutex; } |
private: |
@@ -667,6 +718,8 @@ private: |
void setLowCollectionRate(bool value) { m_lowCollectionRate = value; } |
void waitUntilSweepersDone(); |
+ void unregisterObjectWithPreFinalizerInternal(void*); |
+ void invokePreFinalizer(Visitor&); |
haraken
2014/10/03 06:00:32
invokePreFinalizer => invokePreFinalizers ?
tkent
2014/10/06 01:25:53
Done.
|
static WTF::ThreadSpecific<ThreadState*>* s_threadSpecific; |
static SafePointBarrier* s_safePointBarrier; |
@@ -718,6 +771,7 @@ private: |
ThreadCondition m_sweepThreadCondition; |
CallbackStack* m_weakCallbackStack; |
+ 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.
|
#if defined(ADDRESS_SANITIZER) |
void* m_asanFakeStack; |