<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[174116] trunk/Source/WTF</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/174116">174116</a></dd>
<dt>Author</dt> <dd>andersca@apple.com</dd>
<dt>Date</dt> <dd>2014-09-30 12:50:01 -0700 (Tue, 30 Sep 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>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.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFwtftextStringImplcpp">trunk/Source/WTF/wtf/text/StringImpl.cpp</a></li>
<li><a href="#trunkSourceWTFwtftextStringImplh">trunk/Source/WTF/wtf/text/StringImpl.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (174115 => 174116)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,3 +1,21 @@
</span><ins>+2014-09-30  Anders Carlsson  &lt;andersca@apple.com&gt;
+
+        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.
+
</ins><span class="cx"> 2014-09-30  Daniel Bates  &lt;dabates@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         REGRESSION (r172532): JSBase.h declares NSMapTable functions that are SPI
</span></span></pre></div>
<a id="trunkSourceWTFwtftextStringImplcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/text/StringImpl.cpp (174115 => 174116)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -36,7 +36,7 @@
</span><span class="cx"> #include &lt;wtf/unicode/CharacterNames.h&gt;
</span><span class="cx"> #include &lt;wtf/unicode/UTF8.h&gt;
</span><span class="cx"> 
</span><del>-#ifdef STRING_STATS
</del><ins>+#if STRING_STATS
</ins><span class="cx"> #include &lt;unistd.h&gt;
</span><span class="cx"> #include &lt;wtf/DataLog.h&gt;
</span><span class="cx"> #endif
</span><span class="lines">@@ -45,27 +45,21 @@
</span><span class="cx"> 
</span><span class="cx"> using namespace Unicode;
</span><span class="cx"> 
</span><del>-COMPILE_ASSERT(sizeof(StringImpl) == 2 * sizeof(int) + 2 * sizeof(void*), StringImpl_should_stay_small);
</del><ins>+static_assert(sizeof(StringImpl) == 2 * sizeof(int) + 2 * sizeof(void*), &quot;StringImpl should stay small&quot;);
</ins><span class="cx"> 
</span><del>-#ifdef STRING_STATS
</del><ins>+#if STRING_STATS
</ins><span class="cx"> StringStats StringImpl::m_stringStats;
</span><span class="cx"> 
</span><del>-unsigned StringStats::s_stringRemovesTillPrintStats = StringStats::s_printStringStatsFrequency;
</del><ins>+std::atomic&lt;unsigned&gt; StringStats::s_stringRemovesTillPrintStats(s_printStringStatsFrequency);
</ins><span class="cx"> 
</span><del>-void StringStats::removeString(StringImpl* string)
</del><ins>+void StringStats::removeString(StringImpl&amp; string)
</ins><span class="cx"> {
</span><del>-    unsigned length = string-&gt;length();
-    bool isSubString = string-&gt;isSubString();
</del><ins>+    unsigned length = string.length();
+    bool isSubString = string.isSubString();
</ins><span class="cx"> 
</span><span class="cx">     --m_totalNumberStrings;
</span><span class="cx"> 
</span><del>-    if (string-&gt;has16BitShadow()) {
-        --m_numberUpconvertedStrings;
-        if (!isSubString)
-            m_totalUpconvertedData -= length;
-    }
-
-    if (string-&gt;is8Bit()) {
</del><ins>+    if (string.is8Bit()) {
</ins><span class="cx">         --m_number8BitStrings;
</span><span class="cx">         if (!isSubString)
</span><span class="cx">             m_total8BitData -= length;
</span><span class="lines">@@ -88,22 +82,21 @@
</span><span class="cx">     unsigned long long totalNumberCharacters = m_total8BitData + m_total16BitData;
</span><span class="cx">     double percent8Bit = m_totalNumberStrings ? ((double)m_number8BitStrings * 100) / (double)m_totalNumberStrings : 0.0;
</span><span class="cx">     double average8bitLength = m_number8BitStrings ? (double)m_total8BitData / (double)m_number8BitStrings : 0.0;
</span><del>-    dataLogF(&quot;%8u (%5.2f%%) 8 bit        %12llu chars  %12llu bytes  avg length %6.1f\n&quot;, m_number8BitStrings, percent8Bit, m_total8BitData, m_total8BitData, average8bitLength);
</del><ins>+    dataLogF(&quot;%8u (%5.2f%%) 8 bit        %12llu chars  %12llu bytes  avg length %6.1f\n&quot;, m_number8BitStrings.load(), percent8Bit, m_total8BitData.load(), m_total8BitData.load(), average8bitLength);
</ins><span class="cx"> 
</span><span class="cx">     double percent16Bit = m_totalNumberStrings ? ((double)m_number16BitStrings * 100) / (double)m_totalNumberStrings : 0.0;
</span><span class="cx">     double average16bitLength = m_number16BitStrings ? (double)m_total16BitData / (double)m_number16BitStrings : 0.0;
</span><del>-    dataLogF(&quot;%8u (%5.2f%%) 16 bit       %12llu chars  %12llu bytes  avg length %6.1f\n&quot;, m_number16BitStrings, percent16Bit, m_total16BitData, m_total16BitData * 2, average16bitLength);
</del><ins>+    dataLogF(&quot;%8u (%5.2f%%) 16 bit       %12llu chars  %12llu bytes  avg length %6.1f\n&quot;, m_number16BitStrings.load(), percent16Bit, m_total16BitData.load(), m_total16BitData * 2, average16bitLength);
</ins><span class="cx"> 
</span><del>-    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(&quot;%8u (%5.2f%%) upconverted  %12llu chars  %12llu bytes  avg length %6.1f\n&quot;, m_numberUpconvertedStrings, percentUpconverted, m_totalUpconvertedData, m_totalUpconvertedData * 2, averageUpconvertedLength);
-
</del><span class="cx">     double averageLength = m_totalNumberStrings ? (double)totalNumberCharacters / (double)m_totalNumberStrings : 0.0;
</span><del>-    unsigned long long totalDataBytes = m_total8BitData + (m_total16BitData + m_totalUpconvertedData) * 2;
-    dataLogF(&quot;%8u Total                 %12llu chars  %12llu bytes  avg length %6.1f\n&quot;, m_totalNumberStrings, totalNumberCharacters, totalDataBytes, averageLength);
-    unsigned long long totalSavedBytes = m_total8BitData - m_totalUpconvertedData;
</del><ins>+    unsigned long long totalDataBytes = m_total8BitData + m_total16BitData * 2;
+    dataLogF(&quot;%8u Total                 %12llu chars  %12llu bytes  avg length %6.1f\n&quot;, m_totalNumberStrings.load(), totalNumberCharacters, totalDataBytes, averageLength);
+    unsigned long long totalSavedBytes = m_total8BitData;
</ins><span class="cx">     double percentSavings = totalSavedBytes ? ((double)totalSavedBytes * 100) / (double)(totalDataBytes + totalSavedBytes) : 0.0;
</span><span class="cx">     dataLogF(&quot;         Total savings %12llu bytes (%5.2f%%)\n&quot;, totalSavedBytes, percentSavings);
</span><ins>+
+    dataLogF(&quot;%8u StringImpl::ref calls\n&quot;, m_refCalls.load());
+    dataLogF(&quot;%8u StringImpl::deref calls\n&quot;, m_derefCalls.load());
</ins><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="lines">@@ -112,7 +105,7 @@
</span><span class="cx"> {
</span><span class="cx">     ASSERT(!isStatic());
</span><span class="cx"> 
</span><del>-    STRING_STATS_REMOVE_STRING(this);
</del><ins>+    STRING_STATS_REMOVE_STRING(*this);
</ins><span class="cx"> 
</span><span class="cx">     if (isAtomic() &amp;&amp; m_length)
</span><span class="cx">         AtomicString::remove(this);
</span></span></pre></div>
<a id="trunkSourceWTFwtftextStringImplh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/text/StringImpl.h (174115 => 174116)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -66,10 +66,10 @@
</span><span class="cx"> typedef bool (*CharacterMatchFunctionPtr)(UChar);
</span><span class="cx"> typedef bool (*IsWhiteSpaceFunctionPtr)(UChar);
</span><span class="cx"> 
</span><del>-// Define STRING_STATS to turn on run time statistics of string sizes and memory usage
-#undef STRING_STATS
</del><ins>+// Define STRING_STATS to 1 turn on run time statistics of string sizes and memory usage
+#define STRING_STATS 0
</ins><span class="cx"> 
</span><del>-#ifdef STRING_STATS
</del><ins>+#if STRING_STATS
</ins><span class="cx"> struct StringStats {
</span><span class="cx">     inline void add8BitString(unsigned length, bool isSubString = false)
</span><span class="cx">     {
</span><span class="lines">@@ -87,33 +87,29 @@
</span><span class="cx">             m_total16BitData += length;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    inline void addUpconvertedString(unsigned length)
-    {
-        ++m_numberUpconvertedStrings;
-        m_totalUpconvertedData += length;
-    }
-
-    void removeString(StringImpl*);
</del><ins>+    void removeString(StringImpl&amp;);
</ins><span class="cx">     void printStats();
</span><span class="cx"> 
</span><span class="cx">     static const unsigned s_printStringStatsFrequency = 5000;
</span><del>-    static unsigned s_stringRemovesTillPrintStats;
</del><ins>+    static std::atomic&lt;unsigned&gt; s_stringRemovesTillPrintStats;
</ins><span class="cx"> 
</span><del>-    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;
</del><ins>+    std::atomic&lt;unsigned&gt; m_refCalls;
+    std::atomic&lt;unsigned&gt; m_derefCalls;
+
+    std::atomic&lt;unsigned&gt; m_totalNumberStrings;
+    std::atomic&lt;unsigned&gt; m_number8BitStrings;
+    std::atomic&lt;unsigned&gt; m_number16BitStrings;
+    std::atomic&lt;unsigned long long&gt; m_total8BitData;
+    std::atomic&lt;unsigned long long&gt; m_total16BitData;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> #define STRING_STATS_ADD_8BIT_STRING(length) StringImpl::stringStats().add8BitString(length)
</span><span class="cx"> #define STRING_STATS_ADD_8BIT_STRING2(length, isSubString) StringImpl::stringStats().add8BitString(length, isSubString)
</span><span class="cx"> #define STRING_STATS_ADD_16BIT_STRING(length) StringImpl::stringStats().add16BitString(length)
</span><span class="cx"> #define STRING_STATS_ADD_16BIT_STRING2(length, isSubString) StringImpl::stringStats().add16BitString(length, isSubString)
</span><del>-#define STRING_STATS_ADD_UPCONVERTED_STRING(length) StringImpl::stringStats().addUpconvertedString(length)
</del><span class="cx"> #define STRING_STATS_REMOVE_STRING(string) StringImpl::stringStats().removeString(string)
</span><ins>+#define STRING_STATS_REF_STRING(string) ++StringImpl::stringStats().m_refCalls;
+#define STRING_STATS_DEREF_STRING(string) ++StringImpl::stringStats().m_derefCalls;
</ins><span class="cx"> #else
</span><span class="cx"> #define STRING_STATS_ADD_8BIT_STRING(length) ((void)0)
</span><span class="cx"> #define STRING_STATS_ADD_8BIT_STRING2(length, isSubString) ((void)0)
</span><span class="lines">@@ -121,6 +117,8 @@
</span><span class="cx"> #define STRING_STATS_ADD_16BIT_STRING2(length, isSubString) ((void)0)
</span><span class="cx"> #define STRING_STATS_ADD_UPCONVERTED_STRING(length) ((void)0)
</span><span class="cx"> #define STRING_STATS_REMOVE_STRING(string) ((void)0)
</span><ins>+#define STRING_STATS_REF_STRING(string) ((void)0)
+#define STRING_STATS_DEREF_STRING(string) ((void)0)
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> class StringImpl {
</span><span class="lines">@@ -213,7 +211,7 @@
</span><span class="cx">         ASSERT(m_data16);
</span><span class="cx">         ASSERT(m_length);
</span><span class="cx"> 
</span><del>-        STRING_STATS_ADD_16BIT_STRING(0);
</del><ins>+        STRING_STATS_ADD_16BIT_STRING(m_length);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     StringImpl(const LChar* characters, unsigned length, ConstructWithoutCopyingTag)
</span><span class="lines">@@ -225,7 +223,7 @@
</span><span class="cx">         ASSERT(m_data8);
</span><span class="cx">         ASSERT(m_length);
</span><span class="cx"> 
</span><del>-        STRING_STATS_ADD_8BIT_STRING(0);
</del><ins>+        STRING_STATS_ADD_8BIT_STRING(m_length);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     // Create a StringImpl adopting ownership of the provided buffer (BufferOwned)
</span><span class="lines">@@ -469,8 +467,8 @@
</span><span class="cx">             m_hashAndFlags &amp;= ~s_hashFlagIsAtomic;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-#ifdef STRING_STATS
-    bool isSubString() const { return  bufferOwnership() == BufferSubstring; }
</del><ins>+#if STRING_STATS
+    bool isSubString() const { return bufferOwnership() == BufferSubstring; }
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     static WTF_EXPORT_STRING_API CString utf8ForCharacters(const UChar* characters, unsigned length, ConversionMode = LenientConversion);
</span><span class="lines">@@ -542,12 +540,18 @@
</span><span class="cx">     inline void ref()
</span><span class="cx">     {
</span><span class="cx">         ASSERT(!isCompilationThread());
</span><ins>+
+        STRING_STATS_REF_STRING(*this);
+
</ins><span class="cx">         m_refCount += s_refCountIncrement;
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     inline void deref()
</span><span class="cx">     {
</span><del>-        ASSERT(!isCompilationThread());        
</del><ins>+        ASSERT(!isCompilationThread());
+
+        STRING_STATS_DEREF_STRING(*this);
+
</ins><span class="cx">         unsigned tempRefCount = m_refCount - s_refCountIncrement;
</span><span class="cx">         if (!tempRefCount) {
</span><span class="cx">             StringImpl::destroy(this);
</span><span class="lines">@@ -699,7 +703,7 @@
</span><span class="cx">     WTF_EXPORT_STRING_API operator NSString*();
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-#ifdef STRING_STATS
</del><ins>+#if STRING_STATS
</ins><span class="cx">     ALWAYS_INLINE static StringStats&amp; stringStats() { return m_stringStats; }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="lines">@@ -787,7 +791,7 @@
</span><span class="cx">     static const unsigned s_hashFlagDidReportCost = 1u &lt;&lt; 3;
</span><span class="cx">     static const unsigned s_hashMaskBufferOwnership = 1u | (1u &lt;&lt; 1);
</span><span class="cx"> 
</span><del>-#ifdef STRING_STATS
</del><ins>+#if STRING_STATS
</ins><span class="cx">     WTF_EXPORTDATA static StringStats m_stringStats;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>