Changeset 124570 in webkit


Ignore:
Timestamp:
Aug 3, 2012 12:33:45 AM (12 years ago)
Author:
loislo@chromium.org
Message:

Web Inspector: extend test coverage for nmi code and fix 2 bugs.
https://bugs.webkit.org/show_bug.cgi?id=92994

Reviewed by Yury Semikhatsky.

1) owner object type propagation.
If a class with object-type DOM has an instrumented member with object-type Other then it has to be recorded as DOM.
Sample: We have SharedBuffer class and we don't know the object-type for it but we know that it is owned by an object with object-type CachedResourceImage.

2) the first member of an instrumented non virtual class was skipped even if it was reported properly.
it happened because the first member has the same address as it's owner

Source/WebCore:

  • dom/MemoryInstrumentation.h:

(WebCore::MemoryInstrumentation::addRootObject):
(WebCore::MemoryInstrumentation::InstrumentedPointer::InstrumentedPointer):
(InstrumentedPointer):
(WebCore::MemoryInstrumentation::addInstrumentedObject):
(MemoryInstrumentation):
(WebCore::MemoryInstrumentation::OwningTraits::addInstrumentedObject):
(WebCore::MemoryObjectInfo::MemoryObjectInfo):
(WebCore::MemoryObjectInfo::reportObjectInfo):
(WebCore::MemoryClassInfo::addInstrumentedMember):
(WebCore::MemoryInstrumentation::addInstrumentedObjectImpl):
(WebCore::MemoryInstrumentation::addObjectImpl):
(WebCore::MemoryInstrumentation::addInstrumentedCollection):
(WebCore::::process):

Source/WebKit/chromium:

  • tests/MemoryInstrumentationTest.cpp:

(WebCore::TEST):
(WebCore):
(InstrumentedOther):
(WebCore::InstrumentedOther::InstrumentedOther):
(WebCore::InstrumentedOther::reportMemoryUsage):
(InstrumentedDOM):
(WebCore::InstrumentedDOM::InstrumentedDOM):
(WebCore::InstrumentedDOM::reportMemoryUsage):
(NonVirtualInstrumented):
(WebCore::NonVirtualInstrumented::reportMemoryUsage):

Location:
trunk/Source
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r124566 r124570  
     12012-08-02  Ilya Tikhonovsky  <loislo@chromium.org>
     2
     3        Web Inspector: extend test coverage for nmi code and fix 2 bugs.
     4        https://bugs.webkit.org/show_bug.cgi?id=92994
     5
     6        Reviewed by Yury Semikhatsky.
     7
     8        1) owner object type propagation.
     9        If a class with object-type DOM has an instrumented member with object-type Other then it has to be recorded as DOM.
     10        Sample: We have SharedBuffer class and we don't know the object-type for it but we know that it is owned by an object with object-type CachedResourceImage.
     11
     12        2) the first member of an instrumented non virtual class was skipped even if it was reported properly.
     13        it happened because the first member has the same address as it's owner
     14
     15        * dom/MemoryInstrumentation.h:
     16        (WebCore::MemoryInstrumentation::addRootObject):
     17        (WebCore::MemoryInstrumentation::InstrumentedPointer::InstrumentedPointer):
     18        (InstrumentedPointer):
     19        (WebCore::MemoryInstrumentation::addInstrumentedObject):
     20        (MemoryInstrumentation):
     21        (WebCore::MemoryInstrumentation::OwningTraits::addInstrumentedObject):
     22        (WebCore::MemoryObjectInfo::MemoryObjectInfo):
     23        (WebCore::MemoryObjectInfo::reportObjectInfo):
     24        (WebCore::MemoryClassInfo::addInstrumentedMember):
     25        (WebCore::MemoryInstrumentation::addInstrumentedObjectImpl):
     26        (WebCore::MemoryInstrumentation::addObjectImpl):
     27        (WebCore::MemoryInstrumentation::addInstrumentedCollection):
     28        (WebCore::::process):
     29
    1302012-08-03  Kentaro Hara  <haraken@chromium.org>
    231
  • trunk/Source/WebCore/dom/MemoryInstrumentation.h

    r124452 r124570  
    5858    template <typename T> void addRootObject(const T& t)
    5959    {
    60         addInstrumentedObject(t);
     60        addInstrumentedObject(t, Other);
    6161        processDeferredInstrumentedPointers();
    6262    }
     
    8080    template <typename T> class InstrumentedPointer : public InstrumentedPointerBase {
    8181    public:
    82         explicit InstrumentedPointer(const T* pointer) : m_pointer(pointer) { }
     82        explicit InstrumentedPointer(const T* pointer, ObjectType objectType) : m_pointer(pointer), m_objectType(objectType) { }
    8383        virtual void process(MemoryInstrumentation*) OVERRIDE;
    8484
    8585    private:
    8686        const T* m_pointer;
     87        const ObjectType m_objectType;
    8788    };
    8889
     
    9293    }
    9394    void addString(const String&, ObjectType);
    94     template <typename T> void addInstrumentedObject(const T& t) { OwningTraits<T>::addInstrumentedObject(this, t); }
     95    template <typename T> void addInstrumentedObject(const T& t, ObjectType objectType) { OwningTraits<T>::addInstrumentedObject(this, t, objectType); }
     96
    9597    template <typename HashMapType> void addHashMap(const HashMapType&, ObjectType, bool contentOnly = false);
    9698    template <typename HashSetType> void addHashSet(const HashSetType&, ObjectType, bool contentOnly = false);
     
    112114    template <typename T>
    113115    struct OwningTraits { // Default byReference implementation.
    114         static void addInstrumentedObject(MemoryInstrumentation* instrumentation, const T& t) { instrumentation->addInstrumentedObjectImpl(&t, byReference); }
     116        static void addInstrumentedObject(MemoryInstrumentation* instrumentation, const T& t, ObjectType objectType) { instrumentation->addInstrumentedObjectImpl(&t, objectType, byReference); }
    115117        static void addObject(MemoryInstrumentation* instrumentation, const T& t, ObjectType objectType) { instrumentation->addObjectImpl(&t, objectType, byReference); }
    116118    };
     
    118120    template <typename T>
    119121    struct OwningTraits<T*> { // Custom byPointer implementation.
    120         static void addInstrumentedObject(MemoryInstrumentation* instrumentation, const T* const& t) { instrumentation->addInstrumentedObjectImpl(t, byPointer); }
     122        static void addInstrumentedObject(MemoryInstrumentation* instrumentation, const T* const& t, ObjectType objectType) { instrumentation->addInstrumentedObjectImpl(t, objectType, byPointer); }
    121123        static void addObject(MemoryInstrumentation* instrumentation, const T* const& t, ObjectType objectType) { instrumentation->addObjectImpl(t, objectType, byPointer); }
    122124    };
    123125
    124     template <typename T> void addInstrumentedObjectImpl(const T* const&, OwningType);
    125     template <typename T> void addInstrumentedObjectImpl(const DataRef<T>* const&, OwningType);
    126     template <typename T> void addInstrumentedObjectImpl(const OwnPtr<T>* const&, OwningType);
    127     template <typename T> void addInstrumentedObjectImpl(const RefPtr<T>* const&, OwningType);
     126    template <typename T> void addInstrumentedObjectImpl(const T* const&, ObjectType, OwningType);
     127    template <typename T> void addInstrumentedObjectImpl(const DataRef<T>* const&, ObjectType, OwningType);
     128    template <typename T> void addInstrumentedObjectImpl(const OwnPtr<T>* const&, ObjectType, OwningType);
     129    template <typename T> void addInstrumentedObjectImpl(const RefPtr<T>* const&, ObjectType, OwningType);
    128130
    129131    template <typename T> void addObjectImpl(const T* const&, ObjectType, OwningType);
     
    135137class MemoryObjectInfo {
    136138public:
    137     explicit MemoryObjectInfo(MemoryInstrumentation* memoryInstrumentation)
     139    MemoryObjectInfo(MemoryInstrumentation* memoryInstrumentation, MemoryInstrumentation::ObjectType objectType)
    138140        : m_memoryInstrumentation(memoryInstrumentation)
    139         , m_objectType(MemoryInstrumentation::Other)
     141        , m_objectType(objectType)
    140142        , m_objectSize(0)
    141      { }
     143    { }
    142144
    143145    MemoryInstrumentation::ObjectType objectType() const { return m_objectType; }
     
    151153    template <typename T> void reportObjectInfo(const T*, MemoryInstrumentation::ObjectType objectType)
    152154    {
    153         if (m_objectType != MemoryInstrumentation::Other)
    154             return;
    155         m_objectType = objectType;
    156         m_objectSize = sizeof(T);
     155        if (!m_objectSize) {
     156            m_objectSize = sizeof(T);
     157            if (objectType != MemoryInstrumentation::Other)
     158                m_objectType = objectType;
     159        }
    157160    }
    158161
     
    175178    template <typename P> void visitBaseClass(const P* ptr) { ptr->P::reportMemoryUsage(m_memoryObjectInfo); }
    176179
    177     template <typename M> void addInstrumentedMember(const M& member) { m_memoryInstrumentation->addInstrumentedObject(member); }
     180    template <typename M> void addInstrumentedMember(const M& member) { m_memoryInstrumentation->addInstrumentedObject(member, m_objectType); }
    178181    template <typename M> void addMember(const M& member) { m_memoryInstrumentation->addObject(member, m_objectType); }
    179182
     
    199202
    200203template <typename T>
    201 void MemoryInstrumentation::addInstrumentedObjectImpl(const T* const& object, OwningType owningType)
    202 {
    203     if (!object || visited(object))
    204         return;
     204void MemoryInstrumentation::addInstrumentedObjectImpl(const T* const& object, ObjectType objectType, OwningType owningType)
     205{
    205206    if (owningType == byReference) {
    206         MemoryObjectInfo memoryObjectInfo(this);
     207        MemoryObjectInfo memoryObjectInfo(this, objectType);
    207208        object->reportMemoryUsage(&memoryObjectInfo);
    208     } else
    209         deferInstrumentedPointer(adoptPtr(new InstrumentedPointer<T>(object)));
    210 }
    211 
    212 template <typename T>
    213 void MemoryInstrumentation::addInstrumentedObjectImpl(const DataRef<T>* const& object, OwningType)
    214 {
    215     addInstrumentedObjectImpl(object->get(), byPointer);
    216 }
    217 
    218 template <typename T>
    219 void MemoryInstrumentation::addInstrumentedObjectImpl(const OwnPtr<T>* const& object, OwningType)
    220 {
    221     addInstrumentedObjectImpl(object->get(), byPointer);
    222 }
    223 
    224 template <typename T>
    225 void MemoryInstrumentation::addInstrumentedObjectImpl(const RefPtr<T>* const& object, OwningType)
    226 {
    227     addInstrumentedObjectImpl(object->get(), byPointer);
    228 }
    229 
    230 template <typename T>
    231 void MemoryInstrumentation::addObjectImpl(const DataRef<T>* const& object, ObjectType objectType, OwningType)
    232 {
     209    } else {
     210        if (!object || visited(object))
     211            return;
     212        deferInstrumentedPointer(adoptPtr(new InstrumentedPointer<T>(object, objectType)));
     213    }
     214}
     215
     216template <typename T>
     217void MemoryInstrumentation::addInstrumentedObjectImpl(const DataRef<T>* const& object, ObjectType objectType, OwningType owningType)
     218{
     219    if (owningType == byPointer)
     220        countObjectSize(objectType, sizeof(DataRef<T>));
     221    addInstrumentedObjectImpl(object->get(), objectType, byPointer);
     222}
     223
     224template <typename T>
     225void MemoryInstrumentation::addInstrumentedObjectImpl(const OwnPtr<T>* const& object, ObjectType objectType, OwningType owningType)
     226{
     227    if (owningType == byPointer)
     228        countObjectSize(objectType, sizeof(OwnPtr<T>));
     229    addInstrumentedObjectImpl(object->get(), objectType, byPointer);
     230}
     231
     232template <typename T>
     233void MemoryInstrumentation::addInstrumentedObjectImpl(const RefPtr<T>* const& object, ObjectType objectType, OwningType owningType)
     234{
     235    if (owningType == byPointer)
     236        countObjectSize(objectType, sizeof(RefPtr<T>));
     237    addInstrumentedObjectImpl(object->get(), objectType, byPointer);
     238}
     239
     240template <typename T>
     241void MemoryInstrumentation::addObjectImpl(const DataRef<T>* const& object, ObjectType objectType, OwningType owningType)
     242{
     243    if (owningType == byPointer)
     244        countObjectSize(objectType, sizeof(DataRef<T>));
    233245    addObjectImpl(object->get(), objectType, byPointer);
    234246}
    235247
    236248template <typename T>
    237 void MemoryInstrumentation::addObjectImpl(const OwnPtr<T>* const& object, ObjectType objectType, OwningType)
    238 {
     249void MemoryInstrumentation::addObjectImpl(const OwnPtr<T>* const& object, ObjectType objectType, OwningType owningType)
     250{
     251    if (owningType == byPointer)
     252        countObjectSize(objectType, sizeof(RefPtr<T>));
    239253    addObjectImpl(object->get(), objectType, byPointer);
    240254}
    241255
    242256template <typename T>
    243 void MemoryInstrumentation::addObjectImpl(const RefPtr<T>* const& object, ObjectType objectType, OwningType)
    244 {
     257void MemoryInstrumentation::addObjectImpl(const RefPtr<T>* const& object, ObjectType objectType, OwningType owningType)
     258{
     259    if (owningType == byPointer)
     260        countObjectSize(objectType, sizeof(RefPtr<T>));
    245261    addObjectImpl(object->get(), objectType, byPointer);
    246262}
     
    284300    typename CollectionType::const_iterator end = collection.end();
    285301    for (typename CollectionType::const_iterator i = collection.begin(); i != end; ++i)
    286         addInstrumentedObject(*i);
     302        addInstrumentedObject(*i, objectType);
    287303}
    288304
     
    313329void MemoryInstrumentation::InstrumentedPointer<T>::process(MemoryInstrumentation* memoryInstrumentation)
    314330{
    315     MemoryObjectInfo memoryObjectInfo(memoryInstrumentation);
     331    MemoryObjectInfo memoryObjectInfo(memoryInstrumentation, m_objectType);
    316332    m_pointer->reportMemoryUsage(&memoryObjectInfo);
    317333    memoryInstrumentation->countObjectSize(memoryObjectInfo.objectType(), memoryObjectInfo.objectSize());
  • trunk/Source/WebKit/chromium/ChangeLog

    r124561 r124570  
     12012-08-02  Ilya Tikhonovsky  <loislo@chromium.org>
     2
     3        Web Inspector: extend test coverage for nmi code and fix 2 bugs.
     4        https://bugs.webkit.org/show_bug.cgi?id=92994
     5
     6        Reviewed by Yury Semikhatsky.
     7
     8        1) owner object type propagation.
     9        If a class with object-type DOM has an instrumented member with object-type Other then it has to be recorded as DOM.
     10        Sample: We have SharedBuffer class and we don't know the object-type for it but we know that it is owned by an object with object-type CachedResourceImage.
     11
     12        2) the first member of an instrumented non virtual class was skipped even if it was reported properly.
     13        it happened because the first member has the same address as it's owner
     14
     15        * tests/MemoryInstrumentationTest.cpp:
     16        (WebCore::TEST):
     17        (WebCore):
     18        (InstrumentedOther):
     19        (WebCore::InstrumentedOther::InstrumentedOther):
     20        (WebCore::InstrumentedOther::reportMemoryUsage):
     21        (InstrumentedDOM):
     22        (WebCore::InstrumentedDOM::InstrumentedDOM):
     23        (WebCore::InstrumentedDOM::reportMemoryUsage):
     24        (NonVirtualInstrumented):
     25        (WebCore::NonVirtualInstrumented::reportMemoryUsage):
     26
    1272012-08-02  Alec Flett  <alecflett@chromium.org>
    228
  • trunk/Source/WebKit/chromium/tests/MemoryInstrumentationTest.cpp

    r124452 r124570  
    7070    impl.addRootObject(instrumented);
    7171    EXPECT_EQ(sizeof(NotInstrumented), impl.reportedSizeForAllTypes());
    72     EXPECT_EQ(2, visitedObjects.size());
     72    EXPECT_EQ(1, visitedObjects.size());
    7373}
    7474
     
    9999        impl.addRootObject(instrumented);
    100100        EXPECT_EQ(sizeof(NotInstrumented), impl.reportedSizeForAllTypes());
    101         EXPECT_EQ(2, visitedObjects.size());
     101        EXPECT_EQ(1, visitedObjects.size());
    102102    }
    103103}
     
    168168    impl.addRootObject(instrumentedWithOwnPtr);
    169169    EXPECT_EQ(2 * sizeof(NotInstrumented), impl.reportedSizeForAllTypes());
    170     EXPECT_EQ(3, visitedObjects.size());
     170    EXPECT_EQ(2, visitedObjects.size());
     171}
     172
     173class InstrumentedOther {
     174public:
     175    InstrumentedOther() : m_data(0) { }
     176
     177    void reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
     178    {
     179        MemoryClassInfo<InstrumentedOther> info(memoryObjectInfo, this, MemoryInstrumentation::Other);
     180    }
     181    int m_data;
     182};
     183
     184class InstrumentedDOM {
     185public:
     186    InstrumentedDOM() : m_instrumentedOther(adoptPtr(new InstrumentedOther)) { }
     187
     188    void reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
     189    {
     190        MemoryClassInfo<InstrumentedDOM> info(memoryObjectInfo, this, MemoryInstrumentation::DOM);
     191        info.addInstrumentedMember(m_instrumentedOther);
     192    }
     193    OwnPtr<InstrumentedOther> m_instrumentedOther;
     194};
     195
     196TEST(MemoryInstrumentationTest, ownerTypePropagation)
     197{
     198    VisitedObjects visitedObjects;
     199    MemoryInstrumentationImpl impl(visitedObjects);
     200    OwnPtr<InstrumentedDOM> instrumentedDOM(adoptPtr(new InstrumentedDOM));
     201    impl.addRootObject(instrumentedDOM);
     202    EXPECT_EQ(sizeof(InstrumentedDOM) + sizeof(InstrumentedOther), impl.reportedSizeForAllTypes());
     203    EXPECT_EQ(sizeof(InstrumentedDOM) + sizeof(InstrumentedOther), impl.totalSize(MemoryInstrumentation::DOM));
     204    EXPECT_EQ(2, visitedObjects.size());
     205}
     206
     207class NonVirtualInstrumented {
     208public:
     209    void reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
     210    {
     211        MemoryClassInfo<NonVirtualInstrumented> info(memoryObjectInfo, this, MemoryInstrumentation::DOM);
     212        info.addInstrumentedMember(m_instrumented);
     213    }
     214
     215    Instrumented m_instrumented;
     216};
     217
     218TEST(MemoryInstrumentationTest, visitFirstMemberInNonVirtualClass)
     219{
     220    VisitedObjects visitedObjects;
     221    MemoryInstrumentationImpl impl(visitedObjects);
     222    NonVirtualInstrumented nonVirtualInstrumented;
     223    impl.addRootObject(&nonVirtualInstrumented);
     224    EXPECT_EQ(sizeof(NonVirtualInstrumented) + sizeof(NotInstrumented), impl.reportedSizeForAllTypes());
     225    EXPECT_EQ(2, visitedObjects.size());
    171226}
    172227
Note: See TracChangeset for help on using the changeset viewer.