Changeset 124017 in webkit


Ignore:
Timestamp:
Jul 30, 2012 5:59:12 AM (12 years ago)
Author:
yurys@chromium.org
Message:

Web Inspector: make MemoryInstrumentation methods private
https://bugs.webkit.org/show_bug.cgi?id=92379

Reviewed by Vsevolod Vlasov.

MemoryInstrumentation was refactored.

  • All reporting methods on MemoryInstrumentation except add*Object are private to enforce MemoryClassInfo usage.
  • MemoryInstrumentation::Add*Member methods renamed to Add*Object
  • String reporting is implemented directly in the MemoryInstrumentation, not in its descendants.
  • CMakeLists.txt:
  • GNUmakefile.list.am:
  • WebCore.gypi:
  • WebCore.vcproj/WebCore.vcproj:
  • WebCore.xcodeproj/project.pbxproj:
  • bindings/v8/ScriptProfiler.cpp:

(WebCore::ScriptProfiler::collectBindingMemoryInfo):

  • dom/MemoryInstrumentation.cpp: Added.

(WebCore):
(WebCore::MemoryInstrumentation::addString):

  • dom/MemoryInstrumentation.h:

(WebCore::MemoryInstrumentation::addInstrumentedObject):
(WebCore::MemoryInstrumentation::addObject):
(MemoryInstrumentation):
(InstrumentedPointerBase):
(WebCore::MemoryInstrumentation::InstrumentedPointerBase::~InstrumentedPointerBase):
(InstrumentedPointer):
(WebCore::MemoryInstrumentation::InstrumentedPointer::InstrumentedPointer):
(WebCore::MemoryInstrumentation::OwningTraits::addInstrumentedObject):
(WebCore::MemoryInstrumentation::OwningTraits::addObject):
(WebCore::MemoryInstrumentation::addInstrumentedObjectImpl):
(WebCore::MemoryClassInfo::addInstrumentedMember):
(WebCore::MemoryClassInfo::addMember):
(WebCore):
(WebCore::MemoryInstrumentation::addObjectImpl):
(WebCore::MemoryInstrumentation::addInstrumentedCollection):
(WebCore::MemoryInstrumentation::calculateContainerSize):

  • inspector/InspectorMemoryAgent.cpp:

(WebCore):

Location:
trunk/Source/WebCore
Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/CMakeLists.txt

    r123999 r124017  
    11061106    dom/IdTargetObserverRegistry.cpp
    11071107    dom/KeyboardEvent.cpp
     1108    dom/MemoryInstrumentation.cpp
    11081109    dom/MessageChannel.cpp
    11091110    dom/MessageEvent.cpp
  • trunk/Source/WebCore/ChangeLog

    r124016 r124017  
     12012-07-26  Yury Semikhatsky  <yurys@chromium.org>
     2
     3        Web Inspector: make MemoryInstrumentation methods private
     4        https://bugs.webkit.org/show_bug.cgi?id=92379
     5
     6        Reviewed by Vsevolod Vlasov.
     7
     8        MemoryInstrumentation was refactored.
     9        - All reporting methods on MemoryInstrumentation except add*Object are
     10          private to enforce MemoryClassInfo usage.
     11        - MemoryInstrumentation::Add*Member methods renamed to Add*Object
     12        - String reporting is implemented directly in the MemoryInstrumentation,
     13          not in its descendants.
     14
     15        * CMakeLists.txt:
     16        * GNUmakefile.list.am:
     17        * WebCore.gypi:
     18        * WebCore.vcproj/WebCore.vcproj:
     19        * WebCore.xcodeproj/project.pbxproj:
     20        * bindings/v8/ScriptProfiler.cpp:
     21        (WebCore::ScriptProfiler::collectBindingMemoryInfo):
     22        * dom/MemoryInstrumentation.cpp: Added.
     23        (WebCore):
     24        (WebCore::MemoryInstrumentation::addString):
     25        * dom/MemoryInstrumentation.h:
     26        (WebCore::MemoryInstrumentation::addInstrumentedObject):
     27        (WebCore::MemoryInstrumentation::addObject):
     28        (MemoryInstrumentation):
     29        (InstrumentedPointerBase):
     30        (WebCore::MemoryInstrumentation::InstrumentedPointerBase::~InstrumentedPointerBase):
     31        (InstrumentedPointer):
     32        (WebCore::MemoryInstrumentation::InstrumentedPointer::InstrumentedPointer):
     33        (WebCore::MemoryInstrumentation::OwningTraits::addInstrumentedObject):
     34        (WebCore::MemoryInstrumentation::OwningTraits::addObject):
     35        (WebCore::MemoryInstrumentation::addInstrumentedObjectImpl):
     36        (WebCore::MemoryClassInfo::addInstrumentedMember):
     37        (WebCore::MemoryClassInfo::addMember):
     38        (WebCore):
     39        (WebCore::MemoryInstrumentation::addObjectImpl):
     40        (WebCore::MemoryInstrumentation::addInstrumentedCollection):
     41        (WebCore::MemoryInstrumentation::calculateContainerSize):
     42        * inspector/InspectorMemoryAgent.cpp:
     43        (WebCore):
     44
    1452012-07-30  Alexander Pavlov  <apavlov@chromium.org>
    246
  • trunk/Source/WebCore/GNUmakefile.list.am

    r123966 r124017  
    19661966        Source/WebCore/dom/KeyboardEvent.cpp \
    19671967        Source/WebCore/dom/KeyboardEvent.h \
     1968        Source/WebCore/dom/MemoryInstrumentation.cpp \
    19681969        Source/WebCore/dom/MemoryInstrumentation.h \
    19691970        Source/WebCore/dom/MessageChannel.cpp \
  • trunk/Source/WebCore/Target.pri

    r123830 r124017  
    413413    dom/IdTargetObserverRegistry.cpp \
    414414    dom/KeyboardEvent.cpp \
     415    dom/MemoryInstrumentation.cpp \
    415416    dom/MessageChannel.cpp \
    416417    dom/MessageEvent.cpp \
  • trunk/Source/WebCore/WebCore.gypi

    r123969 r124017  
    52005200            'dom/IdTargetObserverRegistry.h',
    52015201            'dom/KeyboardEvent.cpp',
     5202            'dom/MemoryInstrumentation.cpp',
    52025203            'dom/MemoryInstrumentation.h',
    52035204            'dom/MessageChannel.cpp',
  • trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj

    r123830 r124017  
    5153251532                        </File>
    5153351533                        <File
     51534                                RelativePath="..\dom\MemoryInstrumentation.cpp"
     51535                                >
     51536                        </File>
     51537                        <File
    5153451538                                RelativePath="..\dom\MemoryInstrumentation.h"
    5153551539                                >
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r123830 r124017  
    61766176                F39BE95C12673BF400E0A674 /* ScriptArguments.h in Headers */ = {isa = PBXBuildFile; fileRef = F39BE95A12673BF400E0A674 /* ScriptArguments.h */; };
    61776177                F3ABFE0C130E9DA000E7F7D1 /* InstrumentingAgents.h in Headers */ = {isa = PBXBuildFile; fileRef = F3ABFE0B130E9DA000E7F7D1 /* InstrumentingAgents.h */; };
     6178                F3BFC9D315C177EC004244E5 /* MemoryInstrumentation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F3BFC9D215C177EC004244E5 /* MemoryInstrumentation.cpp */; };
    61786179                F3D461481161D53200CA0D09 /* JSErrorHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F3D461461161D53200CA0D09 /* JSErrorHandler.cpp */; };
    61796180                F3D461491161D53200CA0D09 /* JSErrorHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = F3D461471161D53200CA0D09 /* JSErrorHandler.h */; };
     
    1350013501                F39BE95A12673BF400E0A674 /* ScriptArguments.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptArguments.h; sourceTree = "<group>"; };
    1350113502                F3ABFE0B130E9DA000E7F7D1 /* InstrumentingAgents.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InstrumentingAgents.h; sourceTree = "<group>"; };
     13503                F3BFC9D215C177EC004244E5 /* MemoryInstrumentation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MemoryInstrumentation.cpp; sourceTree = "<group>"; };
    1350213504                F3D461461161D53200CA0D09 /* JSErrorHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSErrorHandler.cpp; sourceTree = "<group>"; };
    1350313505                F3D461471161D53200CA0D09 /* JSErrorHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSErrorHandler.h; sourceTree = "<group>"; };
     
    2157521577                                BC9A6145146859D9006057FD /* make_event_factory.pl */,
    2157621578                                BC9A6146146859D9006057FD /* make_names.pl */,
     21579                                F3BFC9D215C177EC004244E5 /* MemoryInstrumentation.cpp */,
    2157721580                                4F32BB1A14FA85AA00F6C1A3 /* MemoryInstrumentation.h */,
    2157821581                                E1ADECCD0E76AD8B004A1A5E /* MessageChannel.cpp */,
     
    2751527518                                BCB16C170979C3BD00467741 /* MemoryCache.cpp in Sources */,
    2751627519                                9FFE3E7A11B59C5D0037874E /* MemoryInfo.cpp in Sources */,
     27520                                F3BFC9D315C177EC004244E5 /* MemoryInstrumentation.cpp in Sources */,
    2751727521                                657EDA081385CB97004E0645 /* MemoryPressureHandler.cpp in Sources */,
    2751827522                                657EDA0B1385CBD8004E0645 /* MemoryPressureHandlerMac.mm in Sources */,
  • trunk/Source/WebCore/bindings/v8/ScriptProfiler.cpp

    r122717 r124017  
    224224{
    225225    V8BindingPerIsolateData* data = V8BindingPerIsolateData::current();
    226     instrumentation->addInstrumentedMember(data);
     226    instrumentation->addInstrumentedObject(data);
    227227}
    228228
  • trunk/Source/WebCore/dom/MemoryInstrumentation.h

    r123726 r124017  
    3131#ifndef MemoryInstrumentation_h
    3232#define MemoryInstrumentation_h
    33 #include <stdio.h>
    3433
    3534#include <wtf/Assertions.h>
     
    5655    };
    5756
    58     template <typename T> void addInstrumentedMember(const T& t)
    59     {
    60         OwningTraits<T>::addInstrumentedMember(this, t);
    61     }
    62 
    63     template <typename T> void addMember(const T& t, ObjectType objectType)
    64     {
    65         OwningTraits<T>::addMember(this, t, objectType);
    66     }
    67 
     57    template <typename T> void addInstrumentedObject(const T& t)
     58    {
     59        OwningTraits<T>::addInstrumentedObject(this, t);
     60    }
     61
     62    template <typename Container> static size_t calculateContainerSize(const Container&, bool contentOnly = false);
     63
     64protected:
     65    class InstrumentedPointerBase {
     66    public:
     67        virtual ~InstrumentedPointerBase() { }
     68        virtual void process(MemoryInstrumentation*) = 0;
     69    };
     70
     71    virtual void countObjectSize(ObjectType, size_t) = 0;
     72    virtual void deferInstrumentedPointer(PassOwnPtr<InstrumentedPointerBase>) = 0;
     73    virtual bool visited(const void*) = 0;
     74
     75private:
     76    template <typename T> friend class MemoryClassInfo;
     77    template <typename T> class InstrumentedPointer : public InstrumentedPointerBase {
     78    public:
     79        explicit InstrumentedPointer(const T* pointer) : m_pointer(pointer) { }
     80        virtual void process(MemoryInstrumentation*) OVERRIDE;
     81
     82    private:
     83        const T* m_pointer;
     84    };
     85
     86    template <typename T> void addObject(const T& t, ObjectType objectType)
     87    {
     88        OwningTraits<T>::addObject(this, t, objectType);
     89    }
     90    void addString(const String&, ObjectType);
    6891    template <typename HashMapType> void addHashMap(const HashMapType&, ObjectType, bool contentOnly = false);
    6992    template <typename HashSetType> void addHashSet(const HashSetType&, ObjectType, bool contentOnly = false);
     
    78101    }
    79102
    80 protected:
    81103    enum OwningType {
    82104        byPointer,
     
    86108    template <typename T>
    87109    struct OwningTraits { // Default byReference implementation.
    88         static void addInstrumentedMember(MemoryInstrumentation* instrumentation, const T& t) { instrumentation->addInstrumentedMemberImpl(&t, byReference); }
    89         static void addMember(MemoryInstrumentation* instrumentation, const T& t, MemoryInstrumentation::ObjectType objectType) { instrumentation->addMemberImpl(&t, objectType, byReference); }
     110        static void addInstrumentedObject(MemoryInstrumentation* instrumentation, const T& t) { instrumentation->addInstrumentedObjectImpl(&t, byReference); }
     111        static void addObject(MemoryInstrumentation* instrumentation, const T& t, MemoryInstrumentation::ObjectType objectType) { instrumentation->addObjectImpl(&t, objectType, byReference); }
    90112    };
    91113
    92114    template <typename T>
    93115    struct OwningTraits<T*> { // Custom byPointer implementation.
    94         static void addInstrumentedMember(MemoryInstrumentation* instrumentation, const T* const& t) { instrumentation->addInstrumentedMemberImpl(t, byPointer); }
    95         static void addMember(MemoryInstrumentation* instrumentation, const T* const& t, MemoryInstrumentation::ObjectType objectType) { instrumentation->addMemberImpl(t, objectType, byPointer); }
    96     };
    97 
    98     template <typename T> void addInstrumentedMemberImpl(const T* const&, OwningType);
    99     template <typename T> void addInstrumentedMemberImpl(const OwnPtr<T>* const& object, MemoryInstrumentation::OwningType owningType) { addInstrumentedMemberImpl(object->get(), owningType); }
    100     template <typename T> void addInstrumentedMemberImpl(const RefPtr<T>* const& object, MemoryInstrumentation::OwningType owningType) { addInstrumentedMemberImpl(object->get(), owningType); }
    101 
    102     template <typename T>
    103     void addMemberImpl(const T* const& object, ObjectType objectType, OwningType owningType)
    104     {
    105         if (!object || visited(object))
    106             return;
    107         if (owningType == byReference)
    108             return;
    109         countObjectSize(objectType, sizeof(T));
    110     }
    111 
    112     class InstrumentedPointerBase {
    113     public:
    114         virtual ~InstrumentedPointerBase() { }
    115 
    116         virtual void process(MemoryInstrumentation*) = 0;
    117     };
    118 
    119     template <typename Container>
    120     size_t calculateContainerSize(const Container& container, bool contentOnly = false)
    121     {
    122         return (contentOnly ? 0 : sizeof(container)) + container.capacity() * sizeof(typename Container::ValueType);
    123     }
    124 
    125 private:
    126     template <typename T> friend class MemoryClassInfo;
    127     template <typename T>
    128     class InstrumentedPointer : public InstrumentedPointerBase {
    129     public:
    130         explicit InstrumentedPointer(const T* pointer) : m_pointer(pointer) { }
    131 
    132         virtual void process(MemoryInstrumentation*) OVERRIDE;
    133 
    134     private:
    135         const T* m_pointer;
    136     };
    137 
    138     virtual void addString(const String&, ObjectType) = 0;
    139     virtual void countObjectSize(ObjectType, size_t) = 0;
    140     virtual void deferInstrumentedPointer(PassOwnPtr<InstrumentedPointerBase>) = 0;
    141     virtual bool visited(const void*) = 0;
     116        static void addInstrumentedObject(MemoryInstrumentation* instrumentation, const T* const& t) { instrumentation->addInstrumentedObjectImpl(t, byPointer); }
     117        static void addObject(MemoryInstrumentation* instrumentation, const T* const& t, MemoryInstrumentation::ObjectType objectType) { instrumentation->addObjectImpl(t, objectType, byPointer); }
     118    };
     119
     120    template <typename T> void addInstrumentedObjectImpl(const T* const&, OwningType);
     121    template <typename T> void addInstrumentedObjectImpl(const OwnPtr<T>* const&, OwningType);
     122    template <typename T> void addInstrumentedObjectImpl(const RefPtr<T>* const&, OwningType);
     123
     124    template <typename T> void addObjectImpl(const T* const&, ObjectType, OwningType);
    142125};
    143126
     
    171154};
    172155
    173 // Link time guard for string members. They produce link error is a string is reported via addMember.
    174 template <> void MemoryInstrumentation::addMemberImpl<AtomicString>(const AtomicString* const&, MemoryInstrumentation::ObjectType, MemoryInstrumentation::OwningType);
    175 template <> void MemoryInstrumentation::addMemberImpl<String>(const String* const&, MemoryInstrumentation::ObjectType, MemoryInstrumentation::OwningType);
    176 
    177 
    178 template <typename T>
    179 void MemoryInstrumentation::addInstrumentedMemberImpl(const T* const& object, MemoryInstrumentation::OwningType owningType)
    180 {
    181     if (!object || visited(object))
    182         return;
    183     if (owningType == byReference) {
    184         MemoryObjectInfo memoryObjectInfo(this);
    185         object->reportMemoryUsage(&memoryObjectInfo);
    186     } else
    187         deferInstrumentedPointer(adoptPtr(new InstrumentedPointer<T>(object)));
    188 }
    189 
    190 
    191156template <typename T>
    192157class MemoryClassInfo {
     
    202167    template <typename P> void visitBaseClass(const P* ptr) { ptr->P::reportMemoryUsage(m_memoryObjectInfo); }
    203168
    204     template <typename M> void addInstrumentedMember(const M& member) { m_memoryInstrumentation->addInstrumentedMember(member); }
    205     template <typename M> void addMember(const M& member) { m_memoryInstrumentation->addMember(member, m_objectType); }
     169    template <typename M> void addInstrumentedMember(const M& member) { m_memoryInstrumentation->addInstrumentedObject(member); }
     170    template <typename M> void addMember(const M& member) { m_memoryInstrumentation->addObject(member, m_objectType); }
    206171
    207172    template <typename HashMapType> void addHashMap(const HashMapType& map) { m_memoryInstrumentation->addHashMap(map, m_objectType, true); }
     
    222187};
    223188
     189template <typename T>
     190void MemoryInstrumentation::addInstrumentedObjectImpl(const T* const& object, OwningType owningType)
     191{
     192    if (!object || visited(object))
     193        return;
     194    if (owningType == byReference) {
     195        MemoryObjectInfo memoryObjectInfo(this);
     196        object->reportMemoryUsage(&memoryObjectInfo);
     197    } else
     198        deferInstrumentedPointer(adoptPtr(new InstrumentedPointer<T>(object)));
     199}
     200
     201template <typename T>
     202void MemoryInstrumentation::addInstrumentedObjectImpl(const OwnPtr<T>* const& object, OwningType owningType)
     203{
     204    addInstrumentedObjectImpl(object->get(), owningType);
     205}
     206
     207template <typename T>
     208void MemoryInstrumentation::addInstrumentedObjectImpl(const RefPtr<T>* const& object, OwningType owningType)
     209{
     210    addInstrumentedObjectImpl(object->get(), owningType);
     211}
     212
     213// Link time guard for string members. They produce link error is a string is reported via addObject.
     214template <> void MemoryInstrumentation::addObjectImpl<AtomicString>(const AtomicString* const&, MemoryInstrumentation::ObjectType, MemoryInstrumentation::OwningType);
     215template <> void MemoryInstrumentation::addObjectImpl<String>(const String* const&, MemoryInstrumentation::ObjectType, MemoryInstrumentation::OwningType);
     216
     217template <typename T>
     218void MemoryInstrumentation::addObjectImpl(const T* const& object, ObjectType objectType, OwningType owningType)
     219{
     220    if (!object || visited(object))
     221        return;
     222    if (owningType == byReference)
     223        return;
     224    countObjectSize(objectType, sizeof(T));
     225}
     226
    224227template<typename HashMapType>
    225228void MemoryInstrumentation::addHashMap(const HashMapType& hashMap, ObjectType objectType, bool contentOnly)
     
    246249    typename CollectionType::const_iterator end = collection.end();
    247250    for (typename CollectionType::const_iterator i = collection.begin(); i != end; ++i)
    248         addInstrumentedMember(*i);
     251        addInstrumentedObject(*i);
    249252}
    250253
     
    264267        return;
    265268    countObjectSize(objectType, calculateContainerSize(vector, contentOnly));
     269}
     270
     271template <typename Container>
     272size_t MemoryInstrumentation::calculateContainerSize(const Container& container, bool contentOnly)
     273{
     274    return (contentOnly ? 0 : sizeof(container)) + container.capacity() * sizeof(typename Container::ValueType);
    266275}
    267276
  • trunk/Source/WebCore/inspector/InspectorMemoryAgent.cpp

    r124006 r124017  
    486486
    487487private:
    488     virtual void addString(const String& string, ObjectType objectType)
    489     {
    490         if (string.isNull() || visited(string.impl()))
    491             return;
    492         countObjectSize(objectType, string.impl()->sizeInBytes());
    493     }
    494 
    495488    virtual void countObjectSize(ObjectType objectType, size_t size) OVERRIDE
    496489    {
     
    527520            return;
    528521
    529         m_domMemoryUsage.addInstrumentedMember(node);
     522        m_domMemoryUsage.addInstrumentedObject(node);
    530523        m_domMemoryUsage.processDeferredInstrumentedPointers();
    531524    }
     
    533526    void visitFrame(Frame* frame)
    534527    {
    535         m_domMemoryUsage.addInstrumentedMember(frame);
     528        m_domMemoryUsage.addInstrumentedObject(frame);
    536529        m_domMemoryUsage.processDeferredInstrumentedPointers();
    537530    }
Note: See TracChangeset for help on using the changeset viewer.