Commit 0008bc53 authored by loislo@chromium.org's avatar loislo@chromium.org
Browse files

Web Inspector: NMI: convert template versions of String*::reportMemoryUsage...

Web Inspector: NMI: convert template versions of String*::reportMemoryUsage functions to normal functions.
https://bugs.webkit.org/show_bug.cgi?id=96759

Reviewed by Yury Semikhatsky.

Now when MemoryInstrumentation.h is a part of WTF we can move reportMemoryUsage functions to cpp file.

* wtf/text/AtomicString.cpp:
(WTF::AtomicString::reportMemoryUsage):
(WTF):
* wtf/text/AtomicString.h:
(WTF):
(AtomicString):
* wtf/text/StringImpl.cpp:
(WTF::StringImpl::reportMemoryUsage):
(WTF):
* wtf/text/StringImpl.h:
(WTF):
(StringImpl):
* wtf/text/WTFString.cpp:
(WTF::String::reportMemoryUsage):
(WTF):
* wtf/text/WTFString.h:
(WTF):
(String):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@128609 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent e9866ba9
2012-09-14 Ilya Tikhonovsky <loislo@chromium.org>
Web Inspector: NMI: convert template versions of String*::reportMemoryUsage functions to normal functions.
https://bugs.webkit.org/show_bug.cgi?id=96759
Reviewed by Yury Semikhatsky.
Now when MemoryInstrumentation.h is a part of WTF we can move reportMemoryUsage functions to cpp file.
* wtf/text/AtomicString.cpp:
(WTF::AtomicString::reportMemoryUsage):
(WTF):
* wtf/text/AtomicString.h:
(WTF):
(AtomicString):
* wtf/text/StringImpl.cpp:
(WTF::StringImpl::reportMemoryUsage):
(WTF):
* wtf/text/StringImpl.h:
(WTF):
(StringImpl):
* wtf/text/WTFString.cpp:
(WTF::String::reportMemoryUsage):
(WTF):
* wtf/text/WTFString.h:
(WTF):
(String):
2012-09-14 Ilya Tikhonovsky <loislo@chromium.org>
Web Inspector: NMI: remove current traits helper class because it is customizing the instrumentation at a wrong place and is not necessary at the moment.
......
......@@ -26,6 +26,7 @@
#include "StringHash.h"
#include <wtf/HashSet.h>
#include <wtf/MemoryInstrumentation.h>
#include <wtf/Threading.h>
#include <wtf/WTFThreadData.h>
#include <wtf/unicode/UTF8.h>
......@@ -435,4 +436,10 @@ void AtomicString::show() const
}
#endif
void AtomicString::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
{
MemoryClassInfo info(memoryObjectInfo, this);
info.addInstrumentedMember(m_string);
}
} // namespace WTF
......@@ -35,6 +35,7 @@
namespace WTF {
struct AtomicStringHash;
class MemoryObjectInfo;
class AtomicString {
public:
......@@ -158,12 +159,7 @@ public:
void show() const;
#endif
template<typename MemoryObjectInfo>
void reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
{
typename MemoryObjectInfo::ClassInfo info(memoryObjectInfo, this);
info.addInstrumentedMember(m_string);
}
WTF_EXPORT_STRING_API void reportMemoryUsage(MemoryObjectInfo*) const;
private:
// The explicit constructors with AtomicString::ConstructFromLiteral must be used for literals.
......
......@@ -28,6 +28,7 @@
#include "AtomicString.h"
#include "StringBuffer.h"
#include "StringHash.h"
#include <wtf/MemoryInstrumentation.h>
#include <wtf/StdLibExtras.h>
#include <wtf/WTFThreadData.h>
#include <wtf/unicode/CharacterNames.h>
......@@ -1791,4 +1792,24 @@ size_t StringImpl::sizeInBytes() const
return size + sizeof(*this);
}
void StringImpl::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));
MemoryClassInfo 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));
}
} // namespace WTF
......@@ -60,6 +60,7 @@ template<typename CharacterType> struct HashAndCharactersTranslator;
struct HashAndUTF8CharactersTranslator;
struct LCharBufferTranslator;
struct CharBufferFromLiteralDataTranslator;
class MemoryObjectInfo;
struct SubstringTranslator;
struct UCharBufferTranslator;
......@@ -715,26 +716,7 @@ public:
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));
}
WTF_EXPORT_STRING_API void reportMemoryUsage(MemoryObjectInfo*) const;
private:
// This number must be at least 2 to avoid sharing empty, null as well as 1 character strings from SmallStrings.
......
......@@ -27,6 +27,7 @@
#include <wtf/ASCIICType.h>
#include <wtf/DataLog.h>
#include <wtf/MathExtras.h>
#include <wtf/MemoryInstrumentation.h>
#include <wtf/text/CString.h>
#include <wtf/StringExtras.h>
#include <wtf/Vector.h>
......@@ -820,6 +821,12 @@ String String::fromUTF8WithLatin1Fallback(const LChar* string, size_t size)
return utf8;
}
void String::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
{
MemoryClassInfo info(memoryObjectInfo, this);
info.addInstrumentedMember(m_impl);
}
// String Operations
static bool isCharacterAllowedInBase(UChar c, int base)
......
......@@ -58,6 +58,7 @@ namespace WebKit {
namespace WTF {
class CString;
class MemoryObjectInfo;
struct StringHash;
// Declarations of string operations
......@@ -455,12 +456,7 @@ public:
return (*m_impl)[index];
}
template<typename MemoryObjectInfo>
void reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
{
typename MemoryObjectInfo::ClassInfo info(memoryObjectInfo, this);
info.addInstrumentedMember(m_impl);
}
WTF_EXPORT_STRING_API void reportMemoryUsage(MemoryObjectInfo*) const;
private:
RefPtr<StringImpl> m_impl;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment