Web Inspector: NMI move String* instrumentation to wtf.
authorloislo@chromium.org <loislo@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 12 Sep 2012 09:13:23 +0000 (09:13 +0000)
committerloislo@chromium.org <loislo@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 12 Sep 2012 09:13:23 +0000 (09:13 +0000)
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):

* dom/WebCoreMemoryInstrumentation.cpp:
(WebCore):
* dom/WebCoreMemoryInstrumentation.h:
(WebCore):
* inspector/MemoryInstrumentationImpl.cpp:
(WebCore::MemoryInstrumentationImpl::countObjectSize):
* platform/SharedBuffer.cpp:
(WebCore::SharedBuffer::reportMemoryUsage):

Source/WebKit/chromium:

Tested by webkit_unit_tests.

* tests/MemoryInstrumentationTest.cpp:
(WebCore::InstrumentedUndefined::reportMemoryUsage):
(WebCore::TEST):

Source/WTF:

Tested by webkit_unit_tests.

* wtf/MemoryInstrumentation.h:
(WebCore):
(WebCore::MemoryInstrumentation::addRootObject):
(WebCore::MemoryObjectInfo::reportObjectInfo):
(WebCore::MemoryClassInfo::MemoryClassInfo):
* wtf/text/AtomicString.h:
(AtomicString):
(WTF::AtomicString::reportMemoryUsage):
* wtf/text/StringImpl.h:
(StringImpl):
(WTF::StringImpl::reportMemoryUsage):
* wtf/text/WTFString.h:
(String):
(WTF::String::reportMemoryUsage):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@128279 268f45cc-cd09-0410-ab3c-d52691b4dbfc

12 files changed:
Source/WTF/ChangeLog
Source/WTF/wtf/MemoryInstrumentation.h
Source/WTF/wtf/text/AtomicString.h
Source/WTF/wtf/text/StringImpl.h
Source/WTF/wtf/text/WTFString.h
Source/WebCore/ChangeLog
Source/WebCore/dom/WebCoreMemoryInstrumentation.cpp
Source/WebCore/dom/WebCoreMemoryInstrumentation.h
Source/WebCore/inspector/MemoryInstrumentationImpl.cpp
Source/WebCore/platform/SharedBuffer.cpp
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/tests/MemoryInstrumentationTest.cpp

index f6bb871..19ab7ab 100644 (file)
@@ -1,3 +1,29 @@
+2012-09-12  Ilya Tikhonovsky  <loislo@chromium.org>
+
+        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.
+
+        Tested by webkit_unit_tests.
+
+        * wtf/MemoryInstrumentation.h:
+        (WebCore):
+        (WebCore::MemoryInstrumentation::addRootObject):
+        (WebCore::MemoryObjectInfo::reportObjectInfo):
+        (WebCore::MemoryClassInfo::MemoryClassInfo):
+        * wtf/text/AtomicString.h:
+        (AtomicString):
+        (WTF::AtomicString::reportMemoryUsage):
+        * wtf/text/StringImpl.h:
+        (StringImpl):
+        (WTF::StringImpl::reportMemoryUsage):
+        * wtf/text/WTFString.h:
+        (String):
+        (WTF::String::reportMemoryUsage):
+
 2012-09-11  Michael Saboff  <msaboff@apple.com>
 
         Build fixed for http://trac.webkit.org/changeset/128243
index ac67fff..a253c4c 100644 (file)
@@ -43,11 +43,6 @@ class MemoryInstrumentation;
 
 typedef const char* MemoryObjectType;
 
-class GenericMemoryTypes {
-public:
-    static MemoryObjectType Undefined;
-};
-
 enum MemoryOwningType {
     byPointer,
     byReference
@@ -65,7 +60,7 @@ public:
 
     template <typename T> void addRootObject(const T& t)
     {
-        addInstrumentedObject(t, GenericMemoryTypes::Undefined);
+        addInstrumentedObject(t, 0);
         processDeferredInstrumentedPointers();
     }
 
@@ -184,7 +179,7 @@ private:
     {
         if (!m_objectSize) {
             m_objectSize = actualSize ? actualSize : sizeof(T);
-            if (objectType != GenericMemoryTypes::Undefined)
+            if (!objectType)
                 m_objectType = objectType;
         }
     }
@@ -197,7 +192,7 @@ private:
 class MemoryClassInfo {
 public:
     template<typename T>
-    MemoryClassInfo(MemoryObjectInfo* memoryObjectInfo, const T*, MemoryObjectType objectType = GenericMemoryTypes::Undefined, size_t actualSize = 0)
+    MemoryClassInfo(MemoryObjectInfo* memoryObjectInfo, const T*, MemoryObjectType objectType = 0, size_t actualSize = 0)
         : m_memoryObjectInfo(memoryObjectInfo)
         , m_memoryInstrumentation(memoryObjectInfo->memoryInstrumentation())
     {
index efd4e2e..9b3c93e 100644 (file)
@@ -154,6 +154,14 @@ public:
 #ifndef NDEBUG
     void show() const;
 #endif
+
+    template<typename MemoryObjectInfo>
+    void reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
+    {
+        typename MemoryObjectInfo::ClassInfo info(memoryObjectInfo, this);
+        info.addInstrumentedMember(m_string);
+    }
+    
 private:
     // The explicit constructors with AtomicString::ConstructFromLiteral must be used for literals.
     AtomicString(ASCIILiteral);
index cd7e10c..a18f694 100644 (file)
@@ -714,6 +714,28 @@ public:
 #ifdef STRING_STATS
     ALWAYS_INLINE static StringStats& stringStats() { return m_stringStats; }
 #endif
+
+    template<typename MemoryObjectInfo>
+    void reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
+    {
+        size_t selfSize = sizeof(StringImpl);
+
+        // Count size used by internal buffer but skip strings that were constructed from literals.
+        if ((m_hashAndFlags & BufferInternal) && !hasTerminatingNullCharacter())
+            // Three cases are covered here:
+            // 1) a normal 8-bit string with internal storage (BufferInternal)
+            // 2) a normal 16-bit string with internal storage (BufferInternal)
+            // 3) empty unique string with length = 0 (BufferInternal)
+            selfSize += m_length * (m_hashAndFlags & s_hashFlag8BitBuffer ? sizeof(LChar) : sizeof(UChar));
+
+        typename MemoryObjectInfo::ClassInfo info(memoryObjectInfo, this, 0, selfSize);
+
+        if (m_hashAndFlags & BufferSubstring)
+            info.addInstrumentedMember(m_substringBuffer);
+        else if (m_hashAndFlags & s_hashFlagHas16BitShadow) // Substring never has its own shadow.
+            info.addRawBuffer(m_copyData16, (m_length + (hasTerminatingNullCharacter() ? 1 : 0)) * sizeof(UChar));
+    }
+
 private:
     // This number must be at least 2 to avoid sharing empty, null as well as 1 character strings from SmallStrings.
     static const unsigned s_copyCharsInlineCutOff = 20;
index 636db9c..b7bd96c 100644 (file)
@@ -455,6 +455,13 @@ public:
         return (*m_impl)[index];
     }
 
+    template<typename MemoryObjectInfo>
+    void reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
+    {
+        typename MemoryObjectInfo::ClassInfo info(memoryObjectInfo, this);
+        info.addInstrumentedMember(m_impl);
+    }
+
 private:
     RefPtr<StringImpl> m_impl;
 };
index 73c028c..4903149 100644 (file)
@@ -1,3 +1,26 @@
+2012-09-12  Ilya Tikhonovsky  <loislo@chromium.org>
+
+        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.
+
+        * dom/WebCoreMemoryInstrumentation.cpp:
+        (WebCore):
+        * dom/WebCoreMemoryInstrumentation.h:
+        (WebCore):
+
+        * dom/WebCoreMemoryInstrumentation.cpp:
+        (WebCore):
+        * dom/WebCoreMemoryInstrumentation.h:
+        (WebCore):
+        * inspector/MemoryInstrumentationImpl.cpp:
+        (WebCore::MemoryInstrumentationImpl::countObjectSize):
+        * platform/SharedBuffer.cpp:
+        (WebCore::SharedBuffer::reportMemoryUsage):
+
 2012-09-12  Kenneth Rohde Christiansen  <kenneth@webkit.org>
 
         Unreviewed EFL build fix.
index 4ce0df2..7491f27 100644 (file)
@@ -37,8 +37,6 @@
 
 namespace WebCore {
 
-MemoryObjectType GenericMemoryTypes::Undefined = 0;
-
 MemoryObjectType WebCoreMemoryTypes::Page = "Page";
 MemoryObjectType WebCoreMemoryTypes::DOM = "Page.DOM";
 MemoryObjectType WebCoreMemoryTypes::CSS = "Page.CSS";
@@ -57,32 +55,6 @@ MemoryObjectType WebCoreMemoryTypes::CachedResourceSVG = "MemoryCache.SVG";
 MemoryObjectType WebCoreMemoryTypes::CachedResourceShader = "MemoryCache.Shader";
 MemoryObjectType WebCoreMemoryTypes::CachedResourceXSLT = "MemoryCache.XSLT";
 
-template<> void MemoryInstrumentationTraits::addInstrumentedObject<String>(MemoryInstrumentation* instrumentation, const String* const& string, MemoryObjectType ownerObjectType, MemoryOwningType owningType)
-{
-    MemoryInstrumentationTraits::addInstrumentedObject<const String>(instrumentation, string, ownerObjectType, owningType);
-}
-
-template<> void MemoryInstrumentationTraits::addInstrumentedObject<const String>(MemoryInstrumentation* instrumentation, const String* const& string, MemoryObjectType ownerObjectType, MemoryOwningType owningType)
-{
-    if (!string || instrumentation->visited(string))
-        return;
-    if (owningType == byPointer)
-        instrumentation->countObjectSize(ownerObjectType, sizeof(String));
-    instrumentation->addInstrumentedObject(string->impl(), ownerObjectType);
-}
-
-template<> void MemoryInstrumentationTraits::addInstrumentedObject<StringImpl>(MemoryInstrumentation* instrumentation, const StringImpl* const& stringImpl, MemoryObjectType ownerObjectType, MemoryOwningType owningType)
-{
-    MemoryInstrumentationTraits::addInstrumentedObject<const StringImpl>(instrumentation, stringImpl, ownerObjectType, owningType);
-}
-
-template<> void MemoryInstrumentationTraits::addInstrumentedObject<const StringImpl>(MemoryInstrumentation* instrumentation, const StringImpl* const& stringImpl, MemoryObjectType ownerObjectType, MemoryOwningType)
-{
-    if (!stringImpl || instrumentation->visited(stringImpl))
-        return;
-    instrumentation->countObjectSize(ownerObjectType, stringImpl->sizeInBytes());
-}
-
 template<> void MemoryInstrumentationTraits::addInstrumentedObject<KURL>(MemoryInstrumentation* instrumentation, const KURL* const& url, MemoryObjectType ownerObjectType, MemoryOwningType owningType)
 {
     MemoryInstrumentationTraits::addInstrumentedObject<const KURL>(instrumentation, url, ownerObjectType, owningType);
@@ -99,14 +71,4 @@ template<> void MemoryInstrumentationTraits::addInstrumentedObject<const KURL>(M
         instrumentation->addInstrumentedObject(url->innerURL(), ownerObjectType);
 }
 
-template<> void MemoryInstrumentationTraits::addInstrumentedObject<AtomicString>(MemoryInstrumentation* instrumentation, const AtomicString* const& atomicString, MemoryObjectType ownerObjectType, MemoryOwningType owningType)
-{
-    MemoryInstrumentationTraits::addInstrumentedObject<const AtomicString>(instrumentation, atomicString, ownerObjectType, owningType);
-}
-
-template<> void MemoryInstrumentationTraits::addInstrumentedObject<const AtomicString>(MemoryInstrumentation* instrumentation, const AtomicString* const& atomicString, MemoryObjectType ownerObjectType, MemoryOwningType owningType)
-{
-    MemoryInstrumentationTraits::addInstrumentedObject<const String>(instrumentation, reinterpret_cast<const String* const>(atomicString), ownerObjectType, owningType);
-}
-
 } // namespace WebCore
index 9d68854..20bf33a 100644 (file)
@@ -42,29 +42,10 @@ class KURL;
 template<> void MemoryInstrumentationTraits::addInstrumentedObject<KURL>(MemoryInstrumentation*, const KURL* const&, MemoryObjectType, MemoryOwningType);
 template<> void MemoryInstrumentationTraits::addInstrumentedObject<const KURL>(MemoryInstrumentation*, const KURL* const&, MemoryObjectType, MemoryOwningType);
 
-template<> void MemoryInstrumentationTraits::addInstrumentedObject<String>(MemoryInstrumentation*, const String* const&, MemoryObjectType, MemoryOwningType);
-template<> void MemoryInstrumentationTraits::addInstrumentedObject<const String>(MemoryInstrumentation*, const String* const&, MemoryObjectType, MemoryOwningType);
-
-template<> void MemoryInstrumentationTraits::addInstrumentedObject<StringImpl>(MemoryInstrumentation*, const StringImpl* const&, MemoryObjectType, MemoryOwningType);
-template<> void MemoryInstrumentationTraits::addInstrumentedObject<const StringImpl>(MemoryInstrumentation*, const StringImpl* const&, MemoryObjectType, MemoryOwningType);
-
-template<> void MemoryInstrumentationTraits::addInstrumentedObject<AtomicString>(MemoryInstrumentation*, const AtomicString* const&, MemoryObjectType, MemoryOwningType);
-template<> void MemoryInstrumentationTraits::addInstrumentedObject<const AtomicString>(MemoryInstrumentation*, const AtomicString* const&, MemoryObjectType, MemoryOwningType);
-
-
 // Link time guards with no body.
 template<> void MemoryInstrumentationTraits::addObject<KURL>(MemoryInstrumentation*, const KURL* const&, MemoryObjectType, MemoryOwningType);
 template<> void MemoryInstrumentationTraits::addObject<const KURL>(MemoryInstrumentation*, const KURL* const&, MemoryObjectType, MemoryOwningType);
 
-template<> void MemoryInstrumentationTraits::addObject<String>(MemoryInstrumentation*, const String* const&, MemoryObjectType, MemoryOwningType);
-template<> void MemoryInstrumentationTraits::addObject<const String>(MemoryInstrumentation*, const String* const&, MemoryObjectType, MemoryOwningType);
-
-template<> void MemoryInstrumentationTraits::addObject<StringImpl>(MemoryInstrumentation*, const StringImpl* const&, MemoryObjectType, MemoryOwningType);
-template<> void MemoryInstrumentationTraits::addObject<const StringImpl>(MemoryInstrumentation*, const StringImpl* const&, MemoryObjectType, MemoryOwningType);
-
-template<> void MemoryInstrumentationTraits::addObject<AtomicString>(MemoryInstrumentation*, const AtomicString* const&, MemoryObjectType, MemoryOwningType);
-template<> void MemoryInstrumentationTraits::addObject<const AtomicString>(MemoryInstrumentation*, const AtomicString* const&, MemoryObjectType, MemoryOwningType);
-
 class WebCoreMemoryTypes {
 public:
     static MemoryObjectType Page;
index 47a91d5..946888c 100644 (file)
@@ -52,7 +52,7 @@ void MemoryInstrumentationImpl::processDeferredInstrumentedPointers()
 
 void MemoryInstrumentationImpl::countObjectSize(MemoryObjectType objectType, size_t size)
 {
-    ASSERT(objectType != GenericMemoryTypes::Undefined);
+    ASSERT(objectType);
     TypeToSizeMap::AddResult result = m_totalSizes.add(objectType, size);
     if (!result.isNewEntry)
         result.iterator->second += size;
index d674ea8..b9dd3a3 100644 (file)
@@ -250,7 +250,7 @@ const Vector<char>& SharedBuffer::buffer() const
 
 void SharedBuffer::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
 {
-    MemoryClassInfo info(memoryObjectInfo, this, GenericMemoryTypes::Undefined);
+    MemoryClassInfo info(memoryObjectInfo, this);
     info.addVector(m_buffer);
     info.addVector(m_segments);
     for (unsigned i = 0; i < m_segments.size(); ++i)
index 6801d3e..8e3c58a 100644 (file)
@@ -1,3 +1,18 @@
+2012-09-12  Ilya Tikhonovsky  <loislo@chromium.org>
+
+        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.
+
+        Tested by webkit_unit_tests.
+
+        * tests/MemoryInstrumentationTest.cpp:
+        (WebCore::InstrumentedUndefined::reportMemoryUsage):
+        (WebCore::TEST):
+
 2012-09-12  Jochen Eisinger  <jochen@chromium.org>
 
         [chromium] consumable user gesture count off for input events
index 51b200a..e0f0705 100644 (file)
@@ -179,7 +179,7 @@ public:
 
     void reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
     {
-        MemoryClassInfo info(memoryObjectInfo, this, GenericMemoryTypes::Undefined);
+        MemoryClassInfo info(memoryObjectInfo, this);
     }
     int m_data;
 };
@@ -245,8 +245,9 @@ TEST(MemoryInstrumentationTest, visitStrings)
     VisitedObjects visitedObjects;
     MemoryInstrumentationImpl impl(visitedObjects);
     StringOwnerInstrumented stringOwnerInstrumented;
+    stringOwnerInstrumented.m_name.characters(); // Force 16bit shadow creation.
     impl.addRootObject(stringOwnerInstrumented);
-    EXPECT_EQ(stringOwnerInstrumented.m_name.impl()->sizeInBytes(), impl.reportedSizeForAllTypes());
+    EXPECT_EQ(sizeof(StringImpl) + stringOwnerInstrumented.m_name.length() * 2, impl.reportedSizeForAllTypes());
     EXPECT_EQ(2, visitedObjects.size());
 }