Changeset 128300 in webkit


Ignore:
Timestamp:
Sep 12, 2012 5:50:10 AM (12 years ago)
Author:
loislo@chromium.org
Message:

Web Inspector: NMI move String* instrumentation to wtf.
https://bugs.webkit.org/show_bug.cgi?id=96405

Reviewed by Yury Semikhatsky.

This instrumentation is solving the problem with substrings and removes traits based code which is hard to upstream.

Source/WebCore:

  • dom/WebCoreMemoryInstrumentation.cpp:

(WebCore):

  • dom/WebCoreMemoryInstrumentation.h:

(WebCore):

Source/WebKit/chromium:

Tested by webkit_unit_tests.

  • tests/MemoryInstrumentationTest.cpp:

(WebCore::TEST):

Source/WTF:

Tested by webkit_unit_tests.

  • wtf/text/AtomicString.h:

(AtomicString):
(WTF::AtomicString::reportMemoryUsage):

  • wtf/text/StringImpl.h:

(StringImpl):
(WTF::StringImpl::reportMemoryUsage):

  • wtf/text/WTFString.h:

(String):
(WTF::String::reportMemoryUsage):

Location:
trunk/Source
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r128284 r128300  
     12012-09-12  Ilya Tikhonovsky  <loislo@chromium.org>
     2
     3        Web Inspector: NMI move String* instrumentation to wtf.
     4        https://bugs.webkit.org/show_bug.cgi?id=96405
     5
     6        Reviewed by Yury Semikhatsky.
     7
     8        This instrumentation is solving the problem with substrings and removes traits based code which is hard to upstream.
     9
     10        Tested by webkit_unit_tests.
     11
     12        * wtf/text/AtomicString.h:
     13        (AtomicString):
     14        (WTF::AtomicString::reportMemoryUsage):
     15        * wtf/text/StringImpl.h:
     16        (StringImpl):
     17        (WTF::StringImpl::reportMemoryUsage):
     18        * wtf/text/WTFString.h:
     19        (String):
     20        (WTF::String::reportMemoryUsage):
     21
    1222012-09-12  Sheriff Bot  <webkit.review.bot@gmail.com>
    223
  • trunk/Source/WTF/wtf/MemoryInstrumentation.h

    r128284 r128300  
    4444typedef const char* MemoryObjectType;
    4545
    46 class GenericMemoryTypes {
    47 public:
    48     static MemoryObjectType Undefined;
    49 };
    50 
    5146enum MemoryOwningType {
    5247    byPointer,
     
    6661    template <typename T> void addRootObject(const T& t)
    6762    {
    68         addInstrumentedObject(t, GenericMemoryTypes::Undefined);
     63        addInstrumentedObject(t, 0);
    6964        processDeferredInstrumentedPointers();
    7065    }
     
    185180        if (!m_objectSize) {
    186181            m_objectSize = actualSize ? actualSize : sizeof(T);
    187             if (objectType != GenericMemoryTypes::Undefined)
     182            if (objectType)
    188183                m_objectType = objectType;
    189184        }
     
    198193public:
    199194    template<typename T>
    200     MemoryClassInfo(MemoryObjectInfo* memoryObjectInfo, const T*, MemoryObjectType objectType = GenericMemoryTypes::Undefined, size_t actualSize = 0)
     195    MemoryClassInfo(MemoryObjectInfo* memoryObjectInfo, const T*, MemoryObjectType objectType = 0, size_t actualSize = 0)
    201196        : m_memoryObjectInfo(memoryObjectInfo)
    202197        , m_memoryInstrumentation(memoryObjectInfo->memoryInstrumentation())
  • trunk/Source/WTF/wtf/text/AtomicString.h

    r128284 r128300  
    155155    void show() const;
    156156#endif
     157
     158    template<typename MemoryObjectInfo>
     159    void reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
     160    {
     161        typename MemoryObjectInfo::ClassInfo info(memoryObjectInfo, this);
     162        info.addInstrumentedMember(m_string);
     163    }
     164
    157165private:
    158166    // The explicit constructors with AtomicString::ConstructFromLiteral must be used for literals.
  • trunk/Source/WTF/wtf/text/StringImpl.h

    r128284 r128300  
    715715    ALWAYS_INLINE static StringStats& stringStats() { return m_stringStats; }
    716716#endif
     717
     718    template<typename MemoryObjectInfo>
     719    void reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
     720    {
     721        size_t selfSize = sizeof(StringImpl);
     722
     723        // Count size used by internal buffer but skip strings that were constructed from literals.
     724        if ((m_hashAndFlags & BufferInternal) && !hasTerminatingNullCharacter())
     725            // Three cases are covered here:
     726            // 1) a normal 8-bit string with internal storage (BufferInternal)
     727            // 2) a normal 16-bit string with internal storage (BufferInternal)
     728            // 3) empty unique string with length = 0 (BufferInternal)
     729            selfSize += m_length * (m_hashAndFlags & s_hashFlag8BitBuffer ? sizeof(LChar) : sizeof(UChar));
     730
     731        typename MemoryObjectInfo::ClassInfo info(memoryObjectInfo, this, 0, selfSize);
     732
     733        if (m_hashAndFlags & BufferSubstring)
     734            info.addInstrumentedMember(m_substringBuffer);
     735        else if (m_hashAndFlags & s_hashFlagHas16BitShadow) // Substring never has its own shadow.
     736            info.addRawBuffer(m_copyData16, (m_length + (hasTerminatingNullCharacter() ? 1 : 0)) * sizeof(UChar));
     737    }
     738
    717739private:
    718740    // This number must be at least 2 to avoid sharing empty, null as well as 1 character strings from SmallStrings.
  • trunk/Source/WTF/wtf/text/WTFString.h

    r128284 r128300  
    454454            return 0;
    455455        return (*m_impl)[index];
     456    }
     457
     458    template<typename MemoryObjectInfo>
     459    void reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
     460    {
     461        typename MemoryObjectInfo::ClassInfo info(memoryObjectInfo, this);
     462        info.addInstrumentedMember(m_impl);
    456463    }
    457464
  • trunk/Source/WebCore/ChangeLog

    r128298 r128300  
     12012-09-12  Ilya Tikhonovsky  <loislo@chromium.org>
     2
     3
     4        Web Inspector: NMI move String* instrumentation to wtf.
     5        https://bugs.webkit.org/show_bug.cgi?id=96405
     6
     7        Reviewed by Yury Semikhatsky.
     8
     9        This instrumentation is solving the problem with substrings and removes traits based code which is hard to upstream.
     10
     11        * dom/WebCoreMemoryInstrumentation.cpp:
     12        (WebCore):
     13        * dom/WebCoreMemoryInstrumentation.h:
     14        (WebCore):
     15
    1162012-08-20  Philippe Normand  <pnormand@igalia.com>
    217
  • trunk/Source/WebCore/dom/WebCoreMemoryInstrumentation.cpp

    r128284 r128300  
    3838namespace WebCore {
    3939
    40 MemoryObjectType GenericMemoryTypes::Undefined = 0;
    41 
    4240MemoryObjectType WebCoreMemoryTypes::Page = "Page";
    4341MemoryObjectType WebCoreMemoryTypes::DOM = "Page.DOM";
     
    5856MemoryObjectType WebCoreMemoryTypes::CachedResourceXSLT = "MemoryCache.XSLT";
    5957
    60 template<> void MemoryInstrumentationTraits::addInstrumentedObject<String>(MemoryInstrumentation* instrumentation, const String* const& string, MemoryObjectType ownerObjectType, MemoryOwningType owningType)
    61 {
    62     MemoryInstrumentationTraits::addInstrumentedObject<const String>(instrumentation, string, ownerObjectType, owningType);
    63 }
    64 
    65 template<> void MemoryInstrumentationTraits::addInstrumentedObject<const String>(MemoryInstrumentation* instrumentation, const String* const& string, MemoryObjectType ownerObjectType, MemoryOwningType owningType)
    66 {
    67     if (!string || instrumentation->visited(string))
    68         return;
    69     if (owningType == byPointer)
    70         instrumentation->countObjectSize(ownerObjectType, sizeof(String));
    71     instrumentation->addInstrumentedObject(string->impl(), ownerObjectType);
    72 }
    73 
    74 template<> void MemoryInstrumentationTraits::addInstrumentedObject<StringImpl>(MemoryInstrumentation* instrumentation, const StringImpl* const& stringImpl, MemoryObjectType ownerObjectType, MemoryOwningType owningType)
    75 {
    76     MemoryInstrumentationTraits::addInstrumentedObject<const StringImpl>(instrumentation, stringImpl, ownerObjectType, owningType);
    77 }
    78 
    79 template<> void MemoryInstrumentationTraits::addInstrumentedObject<const StringImpl>(MemoryInstrumentation* instrumentation, const StringImpl* const& stringImpl, MemoryObjectType ownerObjectType, MemoryOwningType)
    80 {
    81     if (!stringImpl || instrumentation->visited(stringImpl))
    82         return;
    83     instrumentation->countObjectSize(ownerObjectType, stringImpl->sizeInBytes());
    84 }
    85 
    8658template<> void MemoryInstrumentationTraits::addInstrumentedObject<KURL>(MemoryInstrumentation* instrumentation, const KURL* const& url, MemoryObjectType ownerObjectType, MemoryOwningType owningType)
    8759{
     
    10072}
    10173
    102 template<> void MemoryInstrumentationTraits::addInstrumentedObject<AtomicString>(MemoryInstrumentation* instrumentation, const AtomicString* const& atomicString, MemoryObjectType ownerObjectType, MemoryOwningType owningType)
    103 {
    104     MemoryInstrumentationTraits::addInstrumentedObject<const AtomicString>(instrumentation, atomicString, ownerObjectType, owningType);
    105 }
    106 
    107 template<> void MemoryInstrumentationTraits::addInstrumentedObject<const AtomicString>(MemoryInstrumentation* instrumentation, const AtomicString* const& atomicString, MemoryObjectType ownerObjectType, MemoryOwningType owningType)
    108 {
    109     MemoryInstrumentationTraits::addInstrumentedObject<const String>(instrumentation, reinterpret_cast<const String* const>(atomicString), ownerObjectType, owningType);
    110 }
    111 
    11274} // namespace WebCore
  • trunk/Source/WebCore/dom/WebCoreMemoryInstrumentation.h

    r128284 r128300  
    4343template<> void MemoryInstrumentationTraits::addInstrumentedObject<const KURL>(MemoryInstrumentation*, const KURL* const&, MemoryObjectType, MemoryOwningType);
    4444
    45 template<> void MemoryInstrumentationTraits::addInstrumentedObject<String>(MemoryInstrumentation*, const String* const&, MemoryObjectType, MemoryOwningType);
    46 template<> void MemoryInstrumentationTraits::addInstrumentedObject<const String>(MemoryInstrumentation*, const String* const&, MemoryObjectType, MemoryOwningType);
    47 
    48 template<> void MemoryInstrumentationTraits::addInstrumentedObject<StringImpl>(MemoryInstrumentation*, const StringImpl* const&, MemoryObjectType, MemoryOwningType);
    49 template<> void MemoryInstrumentationTraits::addInstrumentedObject<const StringImpl>(MemoryInstrumentation*, const StringImpl* const&, MemoryObjectType, MemoryOwningType);
    50 
    51 template<> void MemoryInstrumentationTraits::addInstrumentedObject<AtomicString>(MemoryInstrumentation*, const AtomicString* const&, MemoryObjectType, MemoryOwningType);
    52 template<> void MemoryInstrumentationTraits::addInstrumentedObject<const AtomicString>(MemoryInstrumentation*, const AtomicString* const&, MemoryObjectType, MemoryOwningType);
    53 
    54 
    5545// Link time guards with no body.
    5646template<> void MemoryInstrumentationTraits::addObject<KURL>(MemoryInstrumentation*, const KURL* const&, MemoryObjectType, MemoryOwningType);
    5747template<> void MemoryInstrumentationTraits::addObject<const KURL>(MemoryInstrumentation*, const KURL* const&, MemoryObjectType, MemoryOwningType);
    58 
    59 template<> void MemoryInstrumentationTraits::addObject<String>(MemoryInstrumentation*, const String* const&, MemoryObjectType, MemoryOwningType);
    60 template<> void MemoryInstrumentationTraits::addObject<const String>(MemoryInstrumentation*, const String* const&, MemoryObjectType, MemoryOwningType);
    61 
    62 template<> void MemoryInstrumentationTraits::addObject<StringImpl>(MemoryInstrumentation*, const StringImpl* const&, MemoryObjectType, MemoryOwningType);
    63 template<> void MemoryInstrumentationTraits::addObject<const StringImpl>(MemoryInstrumentation*, const StringImpl* const&, MemoryObjectType, MemoryOwningType);
    64 
    65 template<> void MemoryInstrumentationTraits::addObject<AtomicString>(MemoryInstrumentation*, const AtomicString* const&, MemoryObjectType, MemoryOwningType);
    66 template<> void MemoryInstrumentationTraits::addObject<const AtomicString>(MemoryInstrumentation*, const AtomicString* const&, MemoryObjectType, MemoryOwningType);
    6748
    6849class WebCoreMemoryTypes {
  • trunk/Source/WebCore/inspector/MemoryInstrumentationImpl.cpp

    r128284 r128300  
    5353void MemoryInstrumentationImpl::countObjectSize(MemoryObjectType objectType, size_t size)
    5454{
    55     ASSERT(objectType != GenericMemoryTypes::Undefined);
     55    ASSERT(objectType);
    5656    TypeToSizeMap::AddResult result = m_totalSizes.add(objectType, size);
    5757    if (!result.isNewEntry)
  • trunk/Source/WebCore/platform/SharedBuffer.cpp

    r128284 r128300  
    251251void SharedBuffer::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
    252252{
    253     MemoryClassInfo info(memoryObjectInfo, this, GenericMemoryTypes::Undefined);
     253    MemoryClassInfo info(memoryObjectInfo, this);
    254254    info.addVector(m_buffer);
    255255    info.addVector(m_segments);
  • trunk/Source/WebKit/chromium/ChangeLog

    r128299 r128300  
     12012-09-12  Ilya Tikhonovsky  <loislo@chromium.org>
     2
     3        Web Inspector: NMI move String* instrumentation to wtf.
     4        https://bugs.webkit.org/show_bug.cgi?id=96405
     5
     6        Reviewed by Yury Semikhatsky.
     7
     8        This instrumentation is solving the problem with substrings and removes traits based code which is hard to upstream.
     9
     10        Tested by webkit_unit_tests.
     11
     12        * tests/MemoryInstrumentationTest.cpp:
     13        (WebCore::TEST):
     14
    1152012-09-12  Philippe Liard  <pliard@google.com>
    216
  • trunk/Source/WebKit/chromium/tests/MemoryInstrumentationTest.cpp

    r128284 r128300  
    180180    void reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
    181181    {
    182         MemoryClassInfo info(memoryObjectInfo, this, GenericMemoryTypes::Undefined);
     182        MemoryClassInfo info(memoryObjectInfo, this);
    183183    }
    184184    int m_data;
     
    246246    MemoryInstrumentationImpl impl(visitedObjects);
    247247    StringOwnerInstrumented stringOwnerInstrumented;
     248    stringOwnerInstrumented.m_name.characters(); // Force 16bit shadow creation.
    248249    impl.addRootObject(stringOwnerInstrumented);
    249     EXPECT_EQ(stringOwnerInstrumented.m_name.impl()->sizeInBytes(), impl.reportedSizeForAllTypes());
     250    EXPECT_EQ(sizeof(StringImpl) + stringOwnerInstrumented.m_name.length() * 2, impl.reportedSizeForAllTypes());
    250251    EXPECT_EQ(2, visitedObjects.size());
    251252}
Note: See TracChangeset for help on using the changeset viewer.