Title: [174116] trunk/Source/WTF
Revision
174116
Author
[email protected]
Date
2014-09-30 12:50:01 -0700 (Tue, 30 Sep 2014)

Log Message

Get the STRING_STATS codepath compiling again, and add calls to ref/deref
https://bugs.webkit.org/show_bug.cgi?id=137259

Reviewed by Andreas Kling.

* wtf/text/StringImpl.cpp:
(WTF::StringStats::removeString):
(WTF::StringStats::printStats):
(WTF::StringImpl::~StringImpl):
* wtf/text/StringImpl.h:
(WTF::StringImpl::StringImpl):
(WTF::StringImpl::isSubString):
(WTF::StringImpl::ref):
(WTF::StringImpl::deref):
(WTF::StringStats::addUpconvertedString): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (174115 => 174116)


--- trunk/Source/WTF/ChangeLog	2014-09-30 19:48:09 UTC (rev 174115)
+++ trunk/Source/WTF/ChangeLog	2014-09-30 19:50:01 UTC (rev 174116)
@@ -1,3 +1,21 @@
+2014-09-30  Anders Carlsson  <[email protected]>
+
+        Get the STRING_STATS codepath compiling again, and add calls to ref/deref
+        https://bugs.webkit.org/show_bug.cgi?id=137259
+
+        Reviewed by Andreas Kling.
+
+        * wtf/text/StringImpl.cpp:
+        (WTF::StringStats::removeString):
+        (WTF::StringStats::printStats):
+        (WTF::StringImpl::~StringImpl):
+        * wtf/text/StringImpl.h:
+        (WTF::StringImpl::StringImpl):
+        (WTF::StringImpl::isSubString):
+        (WTF::StringImpl::ref):
+        (WTF::StringImpl::deref):
+        (WTF::StringStats::addUpconvertedString): Deleted.
+
 2014-09-30  Daniel Bates  <[email protected]>
 
         REGRESSION (r172532): JSBase.h declares NSMapTable functions that are SPI

Modified: trunk/Source/WTF/wtf/text/StringImpl.cpp (174115 => 174116)


--- trunk/Source/WTF/wtf/text/StringImpl.cpp	2014-09-30 19:48:09 UTC (rev 174115)
+++ trunk/Source/WTF/wtf/text/StringImpl.cpp	2014-09-30 19:50:01 UTC (rev 174116)
@@ -36,7 +36,7 @@
 #include <wtf/unicode/CharacterNames.h>
 #include <wtf/unicode/UTF8.h>
 
-#ifdef STRING_STATS
+#if STRING_STATS
 #include <unistd.h>
 #include <wtf/DataLog.h>
 #endif
@@ -45,27 +45,21 @@
 
 using namespace Unicode;
 
-COMPILE_ASSERT(sizeof(StringImpl) == 2 * sizeof(int) + 2 * sizeof(void*), StringImpl_should_stay_small);
+static_assert(sizeof(StringImpl) == 2 * sizeof(int) + 2 * sizeof(void*), "StringImpl should stay small");
 
-#ifdef STRING_STATS
+#if STRING_STATS
 StringStats StringImpl::m_stringStats;
 
-unsigned StringStats::s_stringRemovesTillPrintStats = StringStats::s_printStringStatsFrequency;
+std::atomic<unsigned> StringStats::s_stringRemovesTillPrintStats(s_printStringStatsFrequency);
 
-void StringStats::removeString(StringImpl* string)
+void StringStats::removeString(StringImpl& string)
 {
-    unsigned length = string->length();
-    bool isSubString = string->isSubString();
+    unsigned length = string.length();
+    bool isSubString = string.isSubString();
 
     --m_totalNumberStrings;
 
-    if (string->has16BitShadow()) {
-        --m_numberUpconvertedStrings;
-        if (!isSubString)
-            m_totalUpconvertedData -= length;
-    }
-
-    if (string->is8Bit()) {
+    if (string.is8Bit()) {
         --m_number8BitStrings;
         if (!isSubString)
             m_total8BitData -= length;
@@ -88,22 +82,21 @@
     unsigned long long totalNumberCharacters = m_total8BitData + m_total16BitData;
     double percent8Bit = m_totalNumberStrings ? ((double)m_number8BitStrings * 100) / (double)m_totalNumberStrings : 0.0;
     double average8bitLength = m_number8BitStrings ? (double)m_total8BitData / (double)m_number8BitStrings : 0.0;
-    dataLogF("%8u (%5.2f%%) 8 bit        %12llu chars  %12llu bytes  avg length %6.1f\n", m_number8BitStrings, percent8Bit, m_total8BitData, m_total8BitData, average8bitLength);
+    dataLogF("%8u (%5.2f%%) 8 bit        %12llu chars  %12llu bytes  avg length %6.1f\n", m_number8BitStrings.load(), percent8Bit, m_total8BitData.load(), m_total8BitData.load(), average8bitLength);
 
     double percent16Bit = m_totalNumberStrings ? ((double)m_number16BitStrings * 100) / (double)m_totalNumberStrings : 0.0;
     double average16bitLength = m_number16BitStrings ? (double)m_total16BitData / (double)m_number16BitStrings : 0.0;
-    dataLogF("%8u (%5.2f%%) 16 bit       %12llu chars  %12llu bytes  avg length %6.1f\n", m_number16BitStrings, percent16Bit, m_total16BitData, m_total16BitData * 2, average16bitLength);
+    dataLogF("%8u (%5.2f%%) 16 bit       %12llu chars  %12llu bytes  avg length %6.1f\n", m_number16BitStrings.load(), percent16Bit, m_total16BitData.load(), m_total16BitData * 2, average16bitLength);
 
-    double percentUpconverted = m_totalNumberStrings ? ((double)m_numberUpconvertedStrings * 100) / (double)m_number8BitStrings : 0.0;
-    double averageUpconvertedLength = m_numberUpconvertedStrings ? (double)m_totalUpconvertedData / (double)m_numberUpconvertedStrings : 0.0;
-    dataLogF("%8u (%5.2f%%) upconverted  %12llu chars  %12llu bytes  avg length %6.1f\n", m_numberUpconvertedStrings, percentUpconverted, m_totalUpconvertedData, m_totalUpconvertedData * 2, averageUpconvertedLength);
-
     double averageLength = m_totalNumberStrings ? (double)totalNumberCharacters / (double)m_totalNumberStrings : 0.0;
-    unsigned long long totalDataBytes = m_total8BitData + (m_total16BitData + m_totalUpconvertedData) * 2;
-    dataLogF("%8u Total                 %12llu chars  %12llu bytes  avg length %6.1f\n", m_totalNumberStrings, totalNumberCharacters, totalDataBytes, averageLength);
-    unsigned long long totalSavedBytes = m_total8BitData - m_totalUpconvertedData;
+    unsigned long long totalDataBytes = m_total8BitData + m_total16BitData * 2;
+    dataLogF("%8u Total                 %12llu chars  %12llu bytes  avg length %6.1f\n", m_totalNumberStrings.load(), totalNumberCharacters, totalDataBytes, averageLength);
+    unsigned long long totalSavedBytes = m_total8BitData;
     double percentSavings = totalSavedBytes ? ((double)totalSavedBytes * 100) / (double)(totalDataBytes + totalSavedBytes) : 0.0;
     dataLogF("         Total savings %12llu bytes (%5.2f%%)\n", totalSavedBytes, percentSavings);
+
+    dataLogF("%8u StringImpl::ref calls\n", m_refCalls.load());
+    dataLogF("%8u StringImpl::deref calls\n", m_derefCalls.load());
 }
 #endif
 
@@ -112,7 +105,7 @@
 {
     ASSERT(!isStatic());
 
-    STRING_STATS_REMOVE_STRING(this);
+    STRING_STATS_REMOVE_STRING(*this);
 
     if (isAtomic() && m_length)
         AtomicString::remove(this);

Modified: trunk/Source/WTF/wtf/text/StringImpl.h (174115 => 174116)


--- trunk/Source/WTF/wtf/text/StringImpl.h	2014-09-30 19:48:09 UTC (rev 174115)
+++ trunk/Source/WTF/wtf/text/StringImpl.h	2014-09-30 19:50:01 UTC (rev 174116)
@@ -66,10 +66,10 @@
 typedef bool (*CharacterMatchFunctionPtr)(UChar);
 typedef bool (*IsWhiteSpaceFunctionPtr)(UChar);
 
-// Define STRING_STATS to turn on run time statistics of string sizes and memory usage
-#undef STRING_STATS
+// Define STRING_STATS to 1 turn on run time statistics of string sizes and memory usage
+#define STRING_STATS 0
 
-#ifdef STRING_STATS
+#if STRING_STATS
 struct StringStats {
     inline void add8BitString(unsigned length, bool isSubString = false)
     {
@@ -87,33 +87,29 @@
             m_total16BitData += length;
     }
 
-    inline void addUpconvertedString(unsigned length)
-    {
-        ++m_numberUpconvertedStrings;
-        m_totalUpconvertedData += length;
-    }
-
-    void removeString(StringImpl*);
+    void removeString(StringImpl&);
     void printStats();
 
     static const unsigned s_printStringStatsFrequency = 5000;
-    static unsigned s_stringRemovesTillPrintStats;
+    static std::atomic<unsigned> s_stringRemovesTillPrintStats;
 
-    unsigned m_totalNumberStrings;
-    unsigned m_number8BitStrings;
-    unsigned m_number16BitStrings;
-    unsigned m_numberUpconvertedStrings;
-    unsigned long long m_total8BitData;
-    unsigned long long m_total16BitData;
-    unsigned long long m_totalUpconvertedData;
+    std::atomic<unsigned> m_refCalls;
+    std::atomic<unsigned> m_derefCalls;
+
+    std::atomic<unsigned> m_totalNumberStrings;
+    std::atomic<unsigned> m_number8BitStrings;
+    std::atomic<unsigned> m_number16BitStrings;
+    std::atomic<unsigned long long> m_total8BitData;
+    std::atomic<unsigned long long> m_total16BitData;
 };
 
 #define STRING_STATS_ADD_8BIT_STRING(length) StringImpl::stringStats().add8BitString(length)
 #define STRING_STATS_ADD_8BIT_STRING2(length, isSubString) StringImpl::stringStats().add8BitString(length, isSubString)
 #define STRING_STATS_ADD_16BIT_STRING(length) StringImpl::stringStats().add16BitString(length)
 #define STRING_STATS_ADD_16BIT_STRING2(length, isSubString) StringImpl::stringStats().add16BitString(length, isSubString)
-#define STRING_STATS_ADD_UPCONVERTED_STRING(length) StringImpl::stringStats().addUpconvertedString(length)
 #define STRING_STATS_REMOVE_STRING(string) StringImpl::stringStats().removeString(string)
+#define STRING_STATS_REF_STRING(string) ++StringImpl::stringStats().m_refCalls;
+#define STRING_STATS_DEREF_STRING(string) ++StringImpl::stringStats().m_derefCalls;
 #else
 #define STRING_STATS_ADD_8BIT_STRING(length) ((void)0)
 #define STRING_STATS_ADD_8BIT_STRING2(length, isSubString) ((void)0)
@@ -121,6 +117,8 @@
 #define STRING_STATS_ADD_16BIT_STRING2(length, isSubString) ((void)0)
 #define STRING_STATS_ADD_UPCONVERTED_STRING(length) ((void)0)
 #define STRING_STATS_REMOVE_STRING(string) ((void)0)
+#define STRING_STATS_REF_STRING(string) ((void)0)
+#define STRING_STATS_DEREF_STRING(string) ((void)0)
 #endif
 
 class StringImpl {
@@ -213,7 +211,7 @@
         ASSERT(m_data16);
         ASSERT(m_length);
 
-        STRING_STATS_ADD_16BIT_STRING(0);
+        STRING_STATS_ADD_16BIT_STRING(m_length);
     }
 
     StringImpl(const LChar* characters, unsigned length, ConstructWithoutCopyingTag)
@@ -225,7 +223,7 @@
         ASSERT(m_data8);
         ASSERT(m_length);
 
-        STRING_STATS_ADD_8BIT_STRING(0);
+        STRING_STATS_ADD_8BIT_STRING(m_length);
     }
 
     // Create a StringImpl adopting ownership of the provided buffer (BufferOwned)
@@ -469,8 +467,8 @@
             m_hashAndFlags &= ~s_hashFlagIsAtomic;
     }
 
-#ifdef STRING_STATS
-    bool isSubString() const { return  bufferOwnership() == BufferSubstring; }
+#if STRING_STATS
+    bool isSubString() const { return bufferOwnership() == BufferSubstring; }
 #endif
 
     static WTF_EXPORT_STRING_API CString utf8ForCharacters(const UChar* characters, unsigned length, ConversionMode = LenientConversion);
@@ -542,12 +540,18 @@
     inline void ref()
     {
         ASSERT(!isCompilationThread());
+
+        STRING_STATS_REF_STRING(*this);
+
         m_refCount += s_refCountIncrement;
     }
 
     inline void deref()
     {
-        ASSERT(!isCompilationThread());        
+        ASSERT(!isCompilationThread());
+
+        STRING_STATS_DEREF_STRING(*this);
+
         unsigned tempRefCount = m_refCount - s_refCountIncrement;
         if (!tempRefCount) {
             StringImpl::destroy(this);
@@ -699,7 +703,7 @@
     WTF_EXPORT_STRING_API operator NSString*();
 #endif
 
-#ifdef STRING_STATS
+#if STRING_STATS
     ALWAYS_INLINE static StringStats& stringStats() { return m_stringStats; }
 #endif
 
@@ -787,7 +791,7 @@
     static const unsigned s_hashFlagDidReportCost = 1u << 3;
     static const unsigned s_hashMaskBufferOwnership = 1u | (1u << 1);
 
-#ifdef STRING_STATS
+#if STRING_STATS
     WTF_EXPORTDATA static StringStats m_stringStats;
 #endif
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to