2011-04-04 Geoffrey Garen <ggaren@apple.com>
authorggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Apr 2011 20:40:35 +0000 (20:40 +0000)
committerggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Apr 2011 20:40:35 +0000 (20:40 +0000)
        Reviewed by Oliver Hunt.

        Renamed Finalizer => WeakHandleOwner (in preparation for adding a reachability callback)
        https://bugs.webkit.org/show_bug.cgi?id=57775

        Also renamed noFinalizer => emptyWeakOwner, since this is really an
        optimization for a weak owner with empty callbacks.

        * collector/handles/HandleHeap.cpp:
        (JSC::HandleHeap::clearWeakPointers): Updated for renames. Removed
        redundant initialization of m_nextToFinalize. Moved deletion check inside
        weak owner check, since the weak owner can't delete the node if there is
        no weak owner!

        * collector/handles/HandleHeap.h:
        (JSC::WeakHandleOwner::~WeakHandleOwner):
        (JSC::HandleHeap::makeWeak): Updated for renames.

        (JSC::HandleHeap::hasWeakOwner): Changed getFinalizer to hasWeakOwner,
        to clarify this function's role in assertions.

        (JSC::HandleHeap::Node::Node):
        (JSC::HandleHeap::Node::makeWeak):
        (JSC::HandleHeap::Node::isWeak):
        (JSC::HandleHeap::Node::weakOwner):
        (JSC::HandleHeap::Node::weakOwnerContext):
        (JSC::HandleHeap::Node::emptyWeakOwner):
        * interpreter/RegisterFile.cpp:
        (JSC::RegisterFile::globalObjectCollectedNotifier):
        * interpreter/RegisterFile.h:
        * runtime/WeakGCMap.h:
        * runtime/WeakGCPtr.h:
        (JSC::WeakGCPtr::WeakGCPtr):
        (JSC::WeakGCPtr::set): Updated for renames.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@82866 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/collector/handles/HandleHeap.cpp
Source/JavaScriptCore/collector/handles/HandleHeap.h
Source/JavaScriptCore/interpreter/RegisterFile.cpp
Source/JavaScriptCore/interpreter/RegisterFile.h
Source/JavaScriptCore/runtime/WeakGCMap.h
Source/JavaScriptCore/runtime/WeakGCPtr.h

index 1c7c682..ee92fce 100644 (file)
@@ -1,3 +1,40 @@
+2011-04-04  Geoffrey Garen  <ggaren@apple.com>
+
+        Reviewed by Oliver Hunt.
+
+        Renamed Finalizer => WeakHandleOwner (in preparation for adding a reachability callback)
+        https://bugs.webkit.org/show_bug.cgi?id=57775
+        
+        Also renamed noFinalizer => emptyWeakOwner, since this is really an
+        optimization for a weak owner with empty callbacks.
+
+        * collector/handles/HandleHeap.cpp:
+        (JSC::HandleHeap::clearWeakPointers): Updated for renames. Removed
+        redundant initialization of m_nextToFinalize. Moved deletion check inside
+        weak owner check, since the weak owner can't delete the node if there is
+        no weak owner!
+
+        * collector/handles/HandleHeap.h:
+        (JSC::WeakHandleOwner::~WeakHandleOwner):
+        (JSC::HandleHeap::makeWeak): Updated for renames.
+
+        (JSC::HandleHeap::hasWeakOwner): Changed getFinalizer to hasWeakOwner,
+        to clarify this function's role in assertions.
+
+        (JSC::HandleHeap::Node::Node):
+        (JSC::HandleHeap::Node::makeWeak):
+        (JSC::HandleHeap::Node::isWeak):
+        (JSC::HandleHeap::Node::weakOwner):
+        (JSC::HandleHeap::Node::weakOwnerContext):
+        (JSC::HandleHeap::Node::emptyWeakOwner):
+        * interpreter/RegisterFile.cpp:
+        (JSC::RegisterFile::globalObjectCollectedNotifier):
+        * interpreter/RegisterFile.h:
+        * runtime/WeakGCMap.h:
+        * runtime/WeakGCPtr.h:
+        (JSC::WeakGCPtr::WeakGCPtr):
+        (JSC::WeakGCPtr::set): Updated for renames.
+
 2011-04-04  Oliver Hunt  <oliver@apple.com>
 
         Fix WinCE build.
index dad6137..e359568 100644 (file)
@@ -86,12 +86,11 @@ void HandleHeap::clearWeakPointers()
         if (Heap::isMarked(cell))
             continue;
 
-        m_nextToFinalize = node->next();
-        if (Finalizer* finalizer = node->finalizer())
-            finalizer->finalize(Handle<Unknown>::wrapSlot(node->slot()), node->finalizerContext());
-
-        if (m_nextToFinalize != node->next()) // Finalizer deallocated node.
-            continue;
+        if (WeakHandleOwner* weakOwner = node->weakOwner()) {
+            weakOwner->finalize(Handle<Unknown>::wrapSlot(node->slot()), node->weakOwnerContext());
+            if (m_nextToFinalize != node->next()) // Owner deallocated node.
+                continue;
+        }
 
         *node->slot() = JSValue();
         SentinelLinkedList<Node>::remove(node);
index 45dc59b..2725504 100644 (file)
@@ -38,10 +38,10 @@ class JSGlobalData;
 class JSValue;
 class HeapRootMarker;
 
-class Finalizer {
+class WeakHandleOwner {
 public:
     virtual void finalize(Handle<Unknown>, void*) = 0;
-    virtual ~Finalizer() {}
+    virtual ~WeakHandleOwner() {}
 };
 
 class HandleHeap {
@@ -53,7 +53,7 @@ public:
     HandleSlot allocate();
     void deallocate(HandleSlot);
 
-    void makeWeak(HandleSlot, Finalizer* = 0, void* context = 0);
+    void makeWeak(HandleSlot, WeakHandleOwner* = 0, void* context = 0);
 
     void markStrongHandles(HeapRootMarker&);
     void updateAfterMark();
@@ -64,10 +64,7 @@ public:
     void writeBarrier(HandleSlot, const JSValue&);
 
 #if !ASSERT_DISABLED
-    Finalizer* getFinalizer(HandleSlot handle)
-    {
-        return toNode(handle)->finalizer();
-    }
+    bool hasWeakOwner(HandleSlot, WeakHandleOwner*);
 #endif
 
     unsigned protectedGlobalObjectCount();
@@ -81,11 +78,11 @@ private:
         HandleSlot slot();
         HandleHeap* handleHeap();
 
-        void makeWeak(Finalizer*, void* context);
+        void makeWeak(WeakHandleOwner*, void* context);
         bool isWeak();
         
-        Finalizer* finalizer();
-        void* finalizerContext();
+        WeakHandleOwner* weakOwner();
+        void* weakOwnerContext();
 
         void setPrev(Node*);
         Node* prev();
@@ -94,12 +91,12 @@ private:
         Node* next();
 
     private:
-        Finalizer* noFinalizer();
+        WeakHandleOwner* emptyWeakOwner();
 
         JSValue m_value;
         HandleHeap* m_handleHeap;
-        Finalizer* m_finalizer;
-        void* m_finalizerContext;
+        WeakHandleOwner* m_weakOwner;
+        void* m_weakOwnerContext;
         Node* m_prev;
         Node* m_next;
     };
@@ -160,28 +157,35 @@ inline void HandleHeap::deallocate(HandleSlot handle)
     m_freeList.push(node);
 }
 
-inline void HandleHeap::makeWeak(HandleSlot handle, Finalizer* finalizer, void* context)
+inline void HandleHeap::makeWeak(HandleSlot handle, WeakHandleOwner* weakOwner, void* context)
 {
     Node* node = toNode(handle);
     SentinelLinkedList<Node>::remove(node);
-    node->makeWeak(finalizer, context);
+    node->makeWeak(weakOwner, context);
     if (handle->isCell() && *handle)
         m_weakList.push(node);
     else
         m_immediateList.push(node);
 }
 
+#if !ASSERT_DISABLED
+inline bool HandleHeap::hasWeakOwner(HandleSlot handle, WeakHandleOwner* weakOwner)
+{
+    return toNode(handle)->weakOwner() == weakOwner;
+}
+#endif
+
 inline HandleHeap::Node::Node(HandleHeap* handleHeap)
     : m_handleHeap(handleHeap)
-    , m_finalizer(0)
-    , m_finalizerContext(0)
+    , m_weakOwner(0)
+    , m_weakOwnerContext(0)
 {
 }
 
 inline HandleHeap::Node::Node(WTF::SentinelTag)
     : m_handleHeap(0)
-    , m_finalizer(0)
-    , m_finalizerContext(0)
+    , m_weakOwner(0)
+    , m_weakOwnerContext(0)
 {
 }
 
@@ -195,26 +199,26 @@ inline HandleHeap* HandleHeap::Node::handleHeap()
     return m_handleHeap;
 }
 
-inline void HandleHeap::Node::makeWeak(Finalizer* finalizer, void* context)
+inline void HandleHeap::Node::makeWeak(WeakHandleOwner* weakOwner, void* context)
 {
-    m_finalizer = finalizer ? finalizer : noFinalizer();
-    m_finalizerContext = context;
+    m_weakOwner = weakOwner ? weakOwner : emptyWeakOwner();
+    m_weakOwnerContext = context;
 }
 
 inline bool HandleHeap::Node::isWeak()
 {
-    return m_finalizer; // True for noFinalizer().
+    return m_weakOwner; // True for emptyWeakOwner().
 }
 
-inline Finalizer* HandleHeap::Node::finalizer()
+inline WeakHandleOwner* HandleHeap::Node::weakOwner()
 {
-    return m_finalizer == noFinalizer() ? 0 : m_finalizer;
+    return m_weakOwner == emptyWeakOwner() ? 0 : m_weakOwner; // 0 for emptyWeakOwner().
 }
 
-inline void* HandleHeap::Node::finalizerContext()
+inline void* HandleHeap::Node::weakOwnerContext()
 {
-    ASSERT(finalizer());
-    return m_finalizerContext;
+    ASSERT(weakOwner());
+    return m_weakOwnerContext;
 }
 
 inline void HandleHeap::Node::setPrev(Node* prev)
@@ -237,9 +241,11 @@ inline HandleHeap::Node* HandleHeap::Node::next()
     return m_next;
 }
 
-inline Finalizer* HandleHeap::Node::noFinalizer()
+// Sentinel to indicate that a node is weak, but its owner has no meaningful
+// callbacks. This allows us to optimize by skipping such nodes.
+inline WeakHandleOwner* HandleHeap::Node::emptyWeakOwner()
 {
-    return reinterpret_cast<Finalizer*>(-1); // Sentinel to indicate a node is weak but has no real finalizer.
+    return reinterpret_cast<WeakHandleOwner*>(-1);
 }
 
 }
index b3a87e5..835ab78 100644 (file)
@@ -75,7 +75,7 @@ void RegisterFile::setGlobalObject(JSGlobalObject* globalObject)
     m_globalObject.set(globalObject->globalData(), globalObject, RegisterFile::globalObjectCollectedNotifier());
 }
 
-class GlobalObjectNotifier : public Finalizer {
+class GlobalObjectNotifier : public WeakHandleOwner {
 public:
     void finalize(Handle<Unknown> value, void*)
     {
@@ -84,7 +84,7 @@ public:
     }
 };
 
-Finalizer* RegisterFile::globalObjectCollectedNotifier()
+WeakHandleOwner* RegisterFile::globalObjectCollectedNotifier()
 {
     // This will leak alas, but we only create one of them, and it doesn't
     // take up any significant amount of space.
index 4d04085..ea59f45 100644 (file)
@@ -135,7 +135,7 @@ namespace JSC {
         static size_t committedByteCount();
         static void initializeThreading();
 
-        static Finalizer* globalObjectCollectedNotifier();
+        static WeakHandleOwner* globalObjectCollectedNotifier();
 
         Register* const * addressOfEnd() const
         {
index 2a3a3ad..a730b97 100644 (file)
@@ -34,7 +34,7 @@ namespace JSC {
 
 // A HashMap for GC'd values that removes entries when the associated value
 // dies.
-template<typename KeyType, typename MappedType> class WeakGCMap : private Finalizer {
+template<typename KeyType, typename MappedType> class WeakGCMap : private WeakHandleOwner {
     WTF_MAKE_FAST_ALLOCATED;
     WTF_MAKE_NONCOPYABLE(WeakGCMap);
 
index 3f87b83..5c89a51 100644 (file)
@@ -43,16 +43,16 @@ public:
     {
     }
     
-    WeakGCPtr(JSGlobalData& globalData, Finalizer* finalizer = 0, void* context = 0)
+    WeakGCPtr(JSGlobalData& globalData, WeakHandleOwner* weakOwner = 0, void* context = 0)
         : m_slot(globalData.allocateGlobalHandle())
     {
-        HandleHeap::heapFor(m_slot)->makeWeak(m_slot, finalizer, context);
+        HandleHeap::heapFor(m_slot)->makeWeak(m_slot, weakOwner, context);
     }
     
-    WeakGCPtr(JSGlobalData& globalData, ExternalType value, Finalizer* finalizer = 0, void* context = 0)
+    WeakGCPtr(JSGlobalData& globalData, ExternalType value, WeakHandleOwner* weakOwner = 0, void* context = 0)
         : m_slot(globalData.allocateGlobalHandle())
     {
-        HandleHeap::heapFor(m_slot)->makeWeak(m_slot, finalizer, context);
+        HandleHeap::heapFor(m_slot)->makeWeak(m_slot, weakOwner, context);
         internalSet(value);
     }
 
@@ -77,13 +77,13 @@ public:
         HandleHeap::heapFor(m_slot)->deallocate(m_slot);
     }
 
-    void set(JSGlobalData& globalData, ExternalType value, Finalizer* finalizer)
+    void set(JSGlobalData& globalData, ExternalType value, WeakHandleOwner* weakOwner)
     {
         if (!this->m_slot) {
             this->m_slot = globalData.allocateGlobalHandle();
-            HandleHeap::heapFor(this->m_slot)->makeWeak(this->m_slot, finalizer, 0);
-        } else
-            ASSERT(HandleHeap::heapFor(this->m_slot)->getFinalizer(this->m_slot) == finalizer);
+            HandleHeap::heapFor(this->m_slot)->makeWeak(this->m_slot, weakOwner);
+        }
+        ASSERT(HandleHeap::heapFor(this->m_slot)->hasWeakOwner(this->m_slot, weakOwner));
         this->internalSet(value);
     }