Changeset 121677 in webkit


Ignore:
Timestamp:
Jul 2, 2012 7:18:25 AM (12 years ago)
Author:
commit-queue@webkit.org
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 <alexeif@chromium.org> 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):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r121676 r121677  
     12012-07-02  Alexei Filippov  <alexeif@chromium.org>
     2
     3        Web Inspector: replace recursion with a stack in DOM nodes snapshot traversal.
     4        https://bugs.webkit.org/show_bug.cgi?id=89889
     5
     6        Number of DOM nodes native snapshots can handle was limited
     7        by the process stack size because of recursion used to traverse the nodes.
     8        The patch changes the recursion to a stack based algorithm.
     9
     10        Reviewed by Yury Semikhatsky.
     11
     12        * dom/MemoryInstrumentation.h:
     13        (MemoryInstrumentation):
     14        (InstrumentedPointerBase):
     15        (WebCore::MemoryInstrumentation::InstrumentedPointerBase::~InstrumentedPointerBase):
     16        (InstrumentedPointer):
     17        (WebCore::MemoryInstrumentation::InstrumentedPointer::InstrumentedPointer):
     18        (WebCore::MemoryInstrumentation::reportInstrumentedPointer):
     19        (WebCore):
     20        (WebCore::::process):
     21        * inspector/InspectorMemoryAgent.cpp:
     22        (WebCore):
     23
    1242012-07-02  Taiju Tsuiki  <tzik@chromium.org>
    225
  • trunk/Source/WebCore/dom/MemoryInstrumentation.h

    r121658 r121677  
    3434#include <wtf/Forward.h>
    3535#include <wtf/OwnPtr.h>
     36#include <wtf/PassOwnPtr.h>
    3637#include <wtf/RefPtr.h>
    3738
     
    6364    template <typename HashMapType> void reportHashMap(const HashMapType&, ObjectType);
    6465
     66protected:
     67    class InstrumentedPointerBase {
     68    public:
     69        virtual ~InstrumentedPointerBase() { }
     70
     71        virtual void process(MemoryInstrumentation*) = 0;
     72    };
     73
    6574private:
    6675    friend class MemoryObjectInfo;
    6776
     77    template <typename T>
     78    class InstrumentedPointer : public InstrumentedPointerBase {
     79    public:
     80        explicit InstrumentedPointer(const T* pointer) : m_pointer(pointer) { }
     81
     82        virtual void process(MemoryInstrumentation*) OVERRIDE;
     83
     84    private:
     85        const T* m_pointer;
     86    };
     87
    6888    virtual void reportString(ObjectType, const String&) = 0;
    6989    virtual void countObjectSize(ObjectType, size_t) = 0;
     90    virtual void deferInstrumentedPointer(PassOwnPtr<InstrumentedPointerBase>) = 0;
    7091    virtual bool visited(const void*) = 0;
    7192};
     
    128149    if (!object || visited(object))
    129150        return;
    130     MemoryObjectInfo memoryObjectInfo(this);
    131     object->reportMemoryUsage(&memoryObjectInfo);
    132     countObjectSize(memoryObjectInfo.objectType(), memoryObjectInfo.objectSize());
     151    deferInstrumentedPointer(adoptPtr(new InstrumentedPointer<T>(object)));
    133152}
    134153
     
    142161}
    143162
    144 
    145163template<typename HashMapType>
    146164void MemoryInstrumentation::reportHashMap(const HashMapType& hashMap, ObjectType objectType)
     
    150168}
    151169
     170template<typename T>
     171void MemoryInstrumentation::InstrumentedPointer<T>::process(MemoryInstrumentation* memoryInstrumentation)
     172{
     173    MemoryObjectInfo memoryObjectInfo(memoryInstrumentation);
     174    m_pointer->reportMemoryUsage(&memoryObjectInfo);
     175    memoryInstrumentation->countObjectSize(memoryObjectInfo.objectType(), memoryObjectInfo.objectSize());
     176}
     177
    152178} // namespace WebCore
    153179
  • trunk/Source/WebCore/inspector/InspectorMemoryAgent.cpp

    r121658 r121677  
    5555#include <wtf/ArrayBufferView.h>
    5656#include <wtf/HashSet.h>
     57#include <wtf/OwnPtr.h>
     58#include <wtf/PassOwnPtr.h>
     59#include <wtf/Vector.h>
    5760#include <wtf/text/StringBuilder.h>
    5861#include <wtf/text/StringImpl.h>
     
    457460    }
    458461
     462    void processDeferredInstrumentedPointers()
     463    {
     464        while (!m_deferredInstrumentedPointers.isEmpty()) {
     465            OwnPtr<InstrumentedPointerBase> pointer = m_deferredInstrumentedPointers.last().release();
     466            m_deferredInstrumentedPointers.removeLast();
     467            pointer->process(this);
     468        }
     469    }
     470
    459471private:
    460472    virtual void reportString(ObjectType objectType, const String& string)
     
    465477    }
    466478
    467     virtual void countObjectSize(ObjectType objectType, size_t size)
     479    virtual void countObjectSize(ObjectType objectType, size_t size) OVERRIDE
    468480    {
    469481        ASSERT(objectType >= 0 && objectType < LastTypeEntry);
     
    471483    }
    472484
    473     virtual bool visited(const void* object)
     485    virtual void deferInstrumentedPointer(PassOwnPtr<InstrumentedPointerBase> pointer) OVERRIDE
     486    {
     487        m_deferredInstrumentedPointers.append(pointer);
     488    }
     489
     490    virtual bool visited(const void* object) OVERRIDE
    474491    {
    475492        return !m_visitedObjects.add(object).isNewEntry;
    476493    }
     494
    477495    size_t m_totalSizes[LastTypeEntry];
    478496    VisitedObjects& m_visitedObjects;
     497    Vector<OwnPtr<InstrumentedPointerBase> > m_deferredInstrumentedPointers;
    479498};
    480499
     
    487506    }
    488507
    489     virtual void visitNode(Node* node)
     508    virtual void visitNode(Node* node) OVERRIDE
    490509    {
    491510        if (node->document() && node->document()->frame() && m_page != node->document()->frame()->page())
     
    493512
    494513        m_domMemoryUsage.reportInstrumentedPointer(node);
     514        m_domMemoryUsage.processDeferredInstrumentedPointers();
    495515    }
    496516
Note: See TracChangeset for help on using the changeset viewer.