Title: [121677] trunk/Source/WebCore
Revision
121677
Author
[email protected]
Date
2012-07-02 07:18:25 -0700 (Mon, 02 Jul 2012)

Log Message

Web Inspector: replace recursion with a stack in DOM nodes snapshot traversal.
https://bugs.webkit.org/show_bug.cgi?id=89889

Number of DOM nodes native snapshots can handle was limited
by the process stack size because of recursion used to traverse the nodes.
The patch changes the recursion to a stack based algorithm.

Patch by Alexei Filippov <[email protected]> on 2012-07-02
Reviewed by Yury Semikhatsky.

* dom/MemoryInstrumentation.h:
(MemoryInstrumentation):
(InstrumentedPointerBase):
(WebCore::MemoryInstrumentation::InstrumentedPointerBase::~InstrumentedPointerBase):
(InstrumentedPointer):
(WebCore::MemoryInstrumentation::InstrumentedPointer::InstrumentedPointer):
(WebCore::MemoryInstrumentation::reportInstrumentedPointer):
(WebCore):
(WebCore::::process):
* inspector/InspectorMemoryAgent.cpp:
(WebCore):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (121676 => 121677)


--- trunk/Source/WebCore/ChangeLog	2012-07-02 14:12:04 UTC (rev 121676)
+++ trunk/Source/WebCore/ChangeLog	2012-07-02 14:18:25 UTC (rev 121677)
@@ -1,3 +1,26 @@
+2012-07-02  Alexei Filippov  <[email protected]>
+
+        Web Inspector: replace recursion with a stack in DOM nodes snapshot traversal.
+        https://bugs.webkit.org/show_bug.cgi?id=89889
+
+        Number of DOM nodes native snapshots can handle was limited
+        by the process stack size because of recursion used to traverse the nodes.
+        The patch changes the recursion to a stack based algorithm.
+
+        Reviewed by Yury Semikhatsky.
+
+        * dom/MemoryInstrumentation.h:
+        (MemoryInstrumentation):
+        (InstrumentedPointerBase):
+        (WebCore::MemoryInstrumentation::InstrumentedPointerBase::~InstrumentedPointerBase):
+        (InstrumentedPointer):
+        (WebCore::MemoryInstrumentation::InstrumentedPointer::InstrumentedPointer):
+        (WebCore::MemoryInstrumentation::reportInstrumentedPointer):
+        (WebCore):
+        (WebCore::::process):
+        * inspector/InspectorMemoryAgent.cpp:
+        (WebCore):
+
 2012-07-02  Taiju Tsuiki  <[email protected]>
 
         Web Inspector: Add requestFileContent command and fileContentReceived event

Modified: trunk/Source/WebCore/dom/MemoryInstrumentation.h (121676 => 121677)


--- trunk/Source/WebCore/dom/MemoryInstrumentation.h	2012-07-02 14:12:04 UTC (rev 121676)
+++ trunk/Source/WebCore/dom/MemoryInstrumentation.h	2012-07-02 14:18:25 UTC (rev 121677)
@@ -33,6 +33,7 @@
 
 #include <wtf/Forward.h>
 #include <wtf/OwnPtr.h>
+#include <wtf/PassOwnPtr.h>
 #include <wtf/RefPtr.h>
 
 namespace WebCore {
@@ -62,11 +63,31 @@
     }
     template <typename HashMapType> void reportHashMap(const HashMapType&, ObjectType);
 
+protected:
+    class InstrumentedPointerBase {
+    public:
+        virtual ~InstrumentedPointerBase() { }
+
+        virtual void process(MemoryInstrumentation*) = 0;
+    };
+
 private:
     friend class MemoryObjectInfo;
 
+    template <typename T>
+    class InstrumentedPointer : public InstrumentedPointerBase {
+    public:
+        explicit InstrumentedPointer(const T* pointer) : m_pointer(pointer) { }
+
+        virtual void process(MemoryInstrumentation*) OVERRIDE;
+
+    private:
+        const T* m_pointer;
+    };
+
     virtual void reportString(ObjectType, const String&) = 0;
     virtual void countObjectSize(ObjectType, size_t) = 0;
+    virtual void deferInstrumentedPointer(PassOwnPtr<InstrumentedPointerBase>) = 0;
     virtual bool visited(const void*) = 0;
 };
 
@@ -127,9 +148,7 @@
 {
     if (!object || visited(object))
         return;
-    MemoryObjectInfo memoryObjectInfo(this);
-    object->reportMemoryUsage(&memoryObjectInfo);
-    countObjectSize(memoryObjectInfo.objectType(), memoryObjectInfo.objectSize());
+    deferInstrumentedPointer(adoptPtr(new InstrumentedPointer<T>(object)));
 }
 
 template<typename T>
@@ -141,7 +160,6 @@
     object.reportMemoryUsage(&memoryObjectInfo);
 }
 
-
 template<typename HashMapType>
 void MemoryInstrumentation::reportHashMap(const HashMapType& hashMap, ObjectType objectType)
 {
@@ -149,6 +167,14 @@
     countObjectSize(objectType, size);
 }
 
+template<typename T>
+void MemoryInstrumentation::InstrumentedPointer<T>::process(MemoryInstrumentation* memoryInstrumentation)
+{
+    MemoryObjectInfo memoryObjectInfo(memoryInstrumentation);
+    m_pointer->reportMemoryUsage(&memoryObjectInfo);
+    memoryInstrumentation->countObjectSize(memoryObjectInfo.objectType(), memoryObjectInfo.objectSize());
+}
+
 } // namespace WebCore
 
 #endif // !defined(MemoryInstrumentation_h)

Modified: trunk/Source/WebCore/inspector/InspectorMemoryAgent.cpp (121676 => 121677)


--- trunk/Source/WebCore/inspector/InspectorMemoryAgent.cpp	2012-07-02 14:12:04 UTC (rev 121676)
+++ trunk/Source/WebCore/inspector/InspectorMemoryAgent.cpp	2012-07-02 14:18:25 UTC (rev 121677)
@@ -54,6 +54,9 @@
 #include <wtf/ArrayBuffer.h>
 #include <wtf/ArrayBufferView.h>
 #include <wtf/HashSet.h>
+#include <wtf/OwnPtr.h>
+#include <wtf/PassOwnPtr.h>
+#include <wtf/Vector.h>
 #include <wtf/text/StringBuilder.h>
 #include <wtf/text/StringImpl.h>
 #include <wtf/text/WTFString.h>
@@ -456,6 +459,15 @@
         return dom.release();
     }
 
+    void processDeferredInstrumentedPointers()
+    {
+        while (!m_deferredInstrumentedPointers.isEmpty()) {
+            OwnPtr<InstrumentedPointerBase> pointer = m_deferredInstrumentedPointers.last().release();
+            m_deferredInstrumentedPointers.removeLast();
+            pointer->process(this);
+        }
+    }
+
 private:
     virtual void reportString(ObjectType objectType, const String& string)
     {
@@ -464,18 +476,25 @@
         countObjectSize(objectType, stringSize(string.impl()));
     }
 
-    virtual void countObjectSize(ObjectType objectType, size_t size)
+    virtual void countObjectSize(ObjectType objectType, size_t size) OVERRIDE
     {
         ASSERT(objectType >= 0 && objectType < LastTypeEntry);
         m_totalSizes[objectType] += size;
     }
 
-    virtual bool visited(const void* object)
+    virtual void deferInstrumentedPointer(PassOwnPtr<InstrumentedPointerBase> pointer) OVERRIDE
     {
+        m_deferredInstrumentedPointers.append(pointer);
+    }
+
+    virtual bool visited(const void* object) OVERRIDE
+    {
         return !m_visitedObjects.add(object).isNewEntry;
     }
+
     size_t m_totalSizes[LastTypeEntry];
     VisitedObjects& m_visitedObjects;
+    Vector<OwnPtr<InstrumentedPointerBase> > m_deferredInstrumentedPointers;
 };
 
 class DOMTreesIterator : public NodeWrapperVisitor {
@@ -486,12 +505,13 @@
     {
     }
 
-    virtual void visitNode(Node* node)
+    virtual void visitNode(Node* node) OVERRIDE
     {
         if (node->document() && node->document()->frame() && m_page != node->document()->frame()->page())
             return;
 
         m_domMemoryUsage.reportInstrumentedPointer(node);
+        m_domMemoryUsage.processDeferredInstrumentedPointers();
     }
 
     void visitBindings()
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to