Changeset 137911 in webkit


Ignore:
Timestamp:
Dec 17, 2012 8:31:14 AM (11 years ago)
Author:
loislo@chromium.org
Message:

Web Inspector: Native Memory Instrumentation: MemoryInstrumentation doesn't detect reportMemoryUsage method defined in a base class.
https://bugs.webkit.org/show_bug.cgi?id=105026

Reviewed by Yury Semikhatsky.

Old SFINAE test was replaced with new one based on this article:
http://stackoverflow.com/questions/1966362/sfinae-to-check-for-inherited-member-functions

Source/WTF:

  • wtf/MemoryInstrumentation.h:

(MemoryInstrumentation):
(yes):
(IsInstrumented):
(no):
(WTF::MemoryInstrumentation::IsInstrumented::BaseMixin::reportMemoryUsage):
(WTF::MemoryInstrumentation::selectInstrumentationMethod):
(InstrumentationSelector):
(WTF):
(WTF::::reportObjectMemoryUsage):

Tools:

New test which covers this problem was added.

  • TestWebKitAPI/Tests/WTF/MemoryInstrumentationTest.cpp:
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r137893 r137911  
     12012-12-17  Ilya Tikhonovsky  <loislo@chromium.org>
     2
     3        Web Inspector: Native Memory Instrumentation: MemoryInstrumentation doesn't detect reportMemoryUsage method defined in a base class.
     4        https://bugs.webkit.org/show_bug.cgi?id=105026
     5
     6        Reviewed by Yury Semikhatsky.
     7
     8        Old SFINAE test was replaced with new one based on this article:
     9        http://stackoverflow.com/questions/1966362/sfinae-to-check-for-inherited-member-functions
     10
     11        * wtf/MemoryInstrumentation.h:
     12        (MemoryInstrumentation):
     13        (yes):
     14        (IsInstrumented):
     15        (no):
     16        (WTF::MemoryInstrumentation::IsInstrumented::BaseMixin::reportMemoryUsage):
     17        (WTF::MemoryInstrumentation::selectInstrumentationMethod):
     18        (InstrumentationSelector):
     19        (WTF):
     20        (WTF::::reportObjectMemoryUsage):
     21
    1222012-12-17  Ilya Tikhonovsky  <loislo@chromium.org>
    223
  • trunk/Source/WTF/wtf/MemoryInstrumentation.h

    r137893 r137911  
    117117    template<typename T> friend void reportMemoryUsage(const T*, MemoryObjectInfo*);
    118118
    119     template<typename T> static void selectInstrumentationMethod(const T* object, MemoryObjectInfo* memoryObjectInfo)
    120     {
    121         // If there is reportMemoryUsage method on the object, call it.
    122         // Otherwise count only object's self size.
    123         reportObjectMemoryUsage<T, void (T::*)(MemoryObjectInfo*) const>(object, memoryObjectInfo, 0);
    124     }
    125 
    126     template<typename Type, Type Ptr> struct MemberHelperStruct;
    127     template<typename T, typename Type>
    128     static void reportObjectMemoryUsage(const T* object, MemoryObjectInfo* memoryObjectInfo,  MemberHelperStruct<Type, &T::reportMemoryUsage>*)
    129     {
    130         object->reportMemoryUsage(memoryObjectInfo);
    131     }
    132 
    133     template<typename T, typename Type>
    134     static void reportObjectMemoryUsage(const T* object, MemoryObjectInfo* memoryObjectInfo, ...)
    135     {
    136         callReportObjectInfo(memoryObjectInfo, object, 0, sizeof(T));
    137     }
     119    template <typename Type>
     120    class IsInstrumented {
     121        class yes {
     122            char m;
     123        };
     124
     125        class no {
     126            yes m[2];
     127        };
     128
     129        struct BaseMixin {
     130            void reportMemoryUsage(MemoryObjectInfo*) const { }
     131        };
     132
     133#if COMPILER(MSVC)
     134#pragma warning(push)
     135#pragma warning(disable: 4624) // Disable warning: destructor could not be generated because a base class destructor is inaccessible.
     136#endif
     137        struct Base : public Type, public BaseMixin { };
     138#if COMPILER(MSVC)
     139#pragma warning(pop)
     140#endif
     141
     142        template <typename T, T t> class Helper { };
     143
     144        template <typename U> static no deduce(U*, Helper<void (BaseMixin::*)(MemoryObjectInfo*) const, &U::reportMemoryUsage>* = 0);
     145        static yes deduce(...);
     146
     147    public:
     148        static const bool result = sizeof(yes) == sizeof(deduce((Base*)(0)));
     149
     150    };
     151
     152    template <int>
     153    struct InstrumentationSelector {
     154        template <typename T> static void reportObjectMemoryUsage(const T*, MemoryObjectInfo*);
     155    };
     156
    138157    WTF_EXPORT_PRIVATE static void callReportObjectInfo(MemoryObjectInfo*, const void* pointer, MemoryObjectType, size_t objectSize);
    139158
     
    189208    MemoryInstrumentationClient* m_client;
    190209};
     210
     211template <>
     212template <typename T>
     213void MemoryInstrumentation::InstrumentationSelector<true>::reportObjectMemoryUsage(const T* object, MemoryObjectInfo* memoryObjectInfo)
     214{
     215    object->reportMemoryUsage(memoryObjectInfo);
     216}
     217
     218template <>
     219template <typename T>
     220void MemoryInstrumentation::InstrumentationSelector<false>::reportObjectMemoryUsage(const T* object, MemoryObjectInfo* memoryObjectInfo)
     221{
     222    callReportObjectInfo(memoryObjectInfo, object, 0, sizeof(T));
     223}
    191224
    192225class MemoryClassInfo {
     
    225258void reportMemoryUsage(const T* object, MemoryObjectInfo* memoryObjectInfo)
    226259{
    227     MemoryInstrumentation::selectInstrumentationMethod<T>(object, memoryObjectInfo);
     260    MemoryInstrumentation::InstrumentationSelector<MemoryInstrumentation::IsInstrumented<T>::result>::reportObjectMemoryUsage(object, memoryObjectInfo);
    228261}
    229262
  • trunk/Tools/ChangeLog

    r137908 r137911  
     12012-12-17  Ilya Tikhonovsky  <loislo@chromium.org>
     2
     3        Web Inspector: Native Memory Instrumentation: MemoryInstrumentation doesn't detect reportMemoryUsage method defined in a base class.
     4        https://bugs.webkit.org/show_bug.cgi?id=105026
     5
     6        Reviewed by Yury Semikhatsky.
     7
     8        Old SFINAE test was replaced with new one based on this article:
     9        http://stackoverflow.com/questions/1966362/sfinae-to-check-for-inherited-member-functions
     10
     11        New test which covers this problem was added.
     12
     13        * TestWebKitAPI/Tests/WTF/MemoryInstrumentationTest.cpp:
     14
    1152012-12-17  Anthony Scian  <ascian@rim.com>
    216
  • trunk/Tools/TestWebKitAPI/Tests/WTF/MemoryInstrumentationTest.cpp

    r137893 r137911  
    873873    EXPECT_EQ(1, client.linkCount());
    874874}
     875
     876class DerivedClass : public Instrumented {
     877public:
     878    size_t m_member;
     879};
     880
     881TEST(MemoryInstrumentationTest, detectBaseClassInstrumentation)
     882{
     883    OwnPtr<DerivedClass> instance = adoptPtr(new DerivedClass());
     884
     885    InstrumentationTestHelper helper;
     886    helper.addRootObject(instance.get(), TestType);
     887    EXPECT_EQ(sizeof(Instrumented) + sizeof(NotInstrumented), helper.reportedSizeForAllTypes());
     888    EXPECT_EQ(2u, helper.visitedObjects());
     889}
     890
    875891} // namespace
    876892
Note: See TracChangeset for help on using the changeset viewer.