Title: [132397] trunk/Source/WebCore
Revision
132397
Author
[email protected]
Date
2012-10-24 14:02:09 -0700 (Wed, 24 Oct 2012)

Log Message

[V8] ActiveDOMObjectEpilogueVisitor is unnecessary and can be deleted
https://bugs.webkit.org/show_bug.cgi?id=100208

Reviewed by Eric Seidel.

Rather than clearing and re-establishing the weak callback for
ActiveDOMObjects during every GC, this patch puts all the
ActiveDOMObjects with pending activity into an object group with a live
object, causing them not to be garbage collected.

In addition to simplifying this code, this patch makes the patch in
https://bugs.webkit.org/show_bug.cgi?id=100175 much easier because
V8GCController no longer needs to know how to configure the weak
callbacks for these objects.

* bindings/v8/V8GCController.cpp:
(WebCore::ActiveDOMObjectPrologueVisitor::ActiveDOMObjectPrologueVisitor):
(ActiveDOMObjectPrologueVisitor):
(WebCore::ActiveDOMObjectPrologueVisitor::visitDOMWrapper):
(WebCore::V8GCController::majorGCPrologue):
(WebCore::V8GCController::majorGCEpilogue):
* bindings/v8/V8PerIsolateData.cpp:
(WebCore::V8PerIsolateData::V8PerIsolateData):
* bindings/v8/V8PerIsolateData.h:
(WebCore::V8PerIsolateData::liveRoot):
(V8PerIsolateData):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (132396 => 132397)


--- trunk/Source/WebCore/ChangeLog	2012-10-24 20:49:23 UTC (rev 132396)
+++ trunk/Source/WebCore/ChangeLog	2012-10-24 21:02:09 UTC (rev 132397)
@@ -1,3 +1,32 @@
+2012-10-24  Adam Barth  <[email protected]>
+
+        [V8] ActiveDOMObjectEpilogueVisitor is unnecessary and can be deleted
+        https://bugs.webkit.org/show_bug.cgi?id=100208
+
+        Reviewed by Eric Seidel.
+
+        Rather than clearing and re-establishing the weak callback for
+        ActiveDOMObjects during every GC, this patch puts all the
+        ActiveDOMObjects with pending activity into an object group with a live
+        object, causing them not to be garbage collected.
+
+        In addition to simplifying this code, this patch makes the patch in
+        https://bugs.webkit.org/show_bug.cgi?id=100175 much easier because
+        V8GCController no longer needs to know how to configure the weak
+        callbacks for these objects.
+
+        * bindings/v8/V8GCController.cpp:
+        (WebCore::ActiveDOMObjectPrologueVisitor::ActiveDOMObjectPrologueVisitor):
+        (ActiveDOMObjectPrologueVisitor):
+        (WebCore::ActiveDOMObjectPrologueVisitor::visitDOMWrapper):
+        (WebCore::V8GCController::majorGCPrologue):
+        (WebCore::V8GCController::majorGCEpilogue):
+        * bindings/v8/V8PerIsolateData.cpp:
+        (WebCore::V8PerIsolateData::V8PerIsolateData):
+        * bindings/v8/V8PerIsolateData.h:
+        (WebCore::V8PerIsolateData::liveRoot):
+        (V8PerIsolateData):
+
 2012-10-24  Brady Eidson  <[email protected]>
 
         Add a strategy for loader customization.

Modified: trunk/Source/WebCore/bindings/v8/V8GCController.cpp (132396 => 132397)


--- trunk/Source/WebCore/bindings/v8/V8GCController.cpp	2012-10-24 20:49:23 UTC (rev 132396)
+++ trunk/Source/WebCore/bindings/v8/V8GCController.cpp	2012-10-24 21:02:09 UTC (rev 132397)
@@ -81,6 +81,11 @@
 template<typename T>
 class ActiveDOMObjectPrologueVisitor : public DOMWrapperMap<T>::Visitor {
 public:
+    explicit ActiveDOMObjectPrologueVisitor(Vector<v8::Persistent<v8::Value> >* liveObjects)
+        : m_liveObjects(liveObjects)
+    {
+    }
+
     void visitDOMWrapper(DOMDataStore*, T* object, v8::Persistent<v8::Object> wrapper)
     {
         WrapperTypeInfo* typeInfo = V8DOMWrapper::domWrapperType(wrapper);  
@@ -91,53 +96,17 @@
             // implementation can't tell the difference.
             MessagePort* port = reinterpret_cast<MessagePort*>(object);
             if (port->isEntangled() || port->hasPendingActivity())
-                wrapper.ClearWeak();
+                m_liveObjects->append(wrapper);
             return;
         }
 
         ActiveDOMObject* activeDOMObject = typeInfo->toActiveDOMObject(wrapper);
         if (activeDOMObject && activeDOMObject->hasPendingActivity())
-            wrapper.ClearWeak();
+            m_liveObjects->append(wrapper);
     }
-};
 
-template<typename T>
-class ActiveDOMObjectEpilogueVisitor : public DOMWrapperMap<T>::Visitor {
-public:
-    explicit ActiveDOMObjectEpilogueVisitor(v8::WeakReferenceCallback callback)
-        : m_callback(callback)
-    {
-    }
-
-    void visitDOMWrapper(DOMDataStore*, T* object, v8::Persistent<v8::Object> wrapper)
-    {
-        WrapperTypeInfo* typeInfo = V8DOMWrapper::domWrapperType(wrapper);
-
-        if (V8MessagePort::info.equals(typeInfo)) {
-            // We marked this port as reachable in ActiveDOMObjectPrologueVisitor.
-            // Undo this now since the port could be not reachable in the future
-            // if it gets disentangled (and also ActiveDOMObjectPrologueVisitor
-            // expects to see all handles marked as weak).
-            MessagePort* port = reinterpret_cast<MessagePort*>(object);
-            if ((!wrapper.IsWeak() && !wrapper.IsNearDeath()) || port->hasPendingActivity())
-                wrapper.MakeWeak(port, m_callback);
-            return;
-        }
-
-        ActiveDOMObject* activeDOMObject = typeInfo->toActiveDOMObject(wrapper);
-        if (activeDOMObject && activeDOMObject->hasPendingActivity()) {
-            ASSERT(!wrapper.IsWeak());
-            // NOTE: To re-enable weak status of the active object we use
-            // |object| from the map and not |activeDOMObject|. The latter
-            // may be a different pointer (in case ActiveDOMObject is not
-            // the main base class of the object's class) and pointer
-            // identity is required by DOM map functions.
-            wrapper.MakeWeak(object, m_callback);
-        }
-    }
-
 private:
-    v8::WeakReferenceCallback m_callback;
+    Vector<v8::Persistent<v8::Value> >* m_liveObjects;
 };
 
 class ObjectVisitor : public DOMWrapperMap<void>::Visitor {
@@ -262,10 +231,13 @@
 
     v8::HandleScope scope;
 
-    ActiveDOMObjectPrologueVisitor<void> activeObjectVisitor;
+    Vector<v8::Persistent<v8::Value> > liveObjects;
+    liveObjects.append(V8PerIsolateData::current()->ensureLiveRoot());
+    ActiveDOMObjectPrologueVisitor<void> activeObjectVisitor(&liveObjects);
     visitActiveDOMObjects(&activeObjectVisitor);
-    ActiveDOMObjectPrologueVisitor<Node> activeNodeVisitor;
+    ActiveDOMObjectPrologueVisitor<Node> activeNodeVisitor(&liveObjects);
     visitActiveDOMNodes(&activeNodeVisitor);
+    v8::V8::AddObjectGroup(liveObjects.data(), liveObjects.size());
 
     NodeVisitor nodeVisitor;
     visitAllDOMNodes(&nodeVisitor);
@@ -304,11 +276,6 @@
 {
     v8::HandleScope scope;
 
-    ActiveDOMObjectEpilogueVisitor<void> activeObjectVisitor(&DOMDataStore::weakActiveDOMObjectCallback);
-    visitActiveDOMObjects(&activeObjectVisitor);
-    ActiveDOMObjectEpilogueVisitor<Node> activeNodeVisitor(&DOMDataStore::weakNodeCallback);
-    visitActiveDOMNodes(&activeNodeVisitor);
-
 #if PLATFORM(CHROMIUM)
     // The GC can happen on multiple threads in case of dedicated workers which run in-process.
     {

Modified: trunk/Source/WebCore/bindings/v8/V8PerIsolateData.cpp (132396 => 132397)


--- trunk/Source/WebCore/bindings/v8/V8PerIsolateData.cpp	2012-10-24 20:49:23 UTC (rev 132396)
+++ trunk/Source/WebCore/bindings/v8/V8PerIsolateData.cpp	2012-10-24 21:02:09 UTC (rev 132397)
@@ -69,6 +69,13 @@
         create(isolate);
 }
 
+v8::Persistent<v8::Value> V8PerIsolateData::ensureLiveRoot()
+{
+    if (m_liveRoot.isEmpty())
+        m_liveRoot.set(v8::Null());
+    return m_liveRoot.get();
+}
+
 void V8PerIsolateData::dispose(v8::Isolate* isolate)
 {
     void* data = ""

Modified: trunk/Source/WebCore/bindings/v8/V8PerIsolateData.h (132396 => 132397)


--- trunk/Source/WebCore/bindings/v8/V8PerIsolateData.h	2012-10-24 20:49:23 UTC (rev 132396)
+++ trunk/Source/WebCore/bindings/v8/V8PerIsolateData.h	2012-10-24 21:02:09 UTC (rev 132397)
@@ -78,6 +78,8 @@
     StringCache* stringCache() { return m_stringCache.get(); }
     IntegerCache* integerCache() { return m_integerCache.get(); }
 
+    v8::Persistent<v8::Value> ensureLiveRoot();
+
 #if ENABLE(INSPECTOR)
     void visitExternalStrings(ExternalStringVisitor*);
 #endif
@@ -142,6 +144,7 @@
     DOMDataStore* m_domDataStore;
 
     OwnPtr<V8HiddenPropertyName> m_hiddenPropertyName;
+    ScopedPersistent<v8::Value> m_liveRoot;
     ScopedPersistent<v8::Context> m_auxiliaryContext;
 
     bool m_constructorMode;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to