<!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>[38622] trunk/JavaScriptCore</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/38622">38622</a></dd>
<dt>Author</dt> <dd>ap@webkit.org</dd>
<dt>Date</dt> <dd>2008-11-20 10:11:14 -0800 (Thu, 20 Nov 2008)</dd>
</dl>

<h3>Log Message</h3>
<pre>        Reviewed by Darin Adler.

        https://bugs.webkit.org/show_bug.cgi?id=22364
        Crashes seen on Tiger buildbots due to worker threads exhausting pthread keys

        * runtime/Collector.cpp:
        (JSC::Heap::Heap):
        (JSC::Heap::destroy):
        (JSC::Heap::makeUsableFromMultipleThreads):
        (JSC::Heap::registerThread):
        * runtime/Collector.h:
        Pthread key for tracking threads is only created on request now, because this is a limited
        resource, and thread tracking is not needed for worker heaps, or for WebCore heap.

        * API/JSContextRef.cpp: (JSGlobalContextCreateInGroup): Call makeUsableFromMultipleThreads().

        * runtime/JSGlobalData.cpp: (JSC::JSGlobalData::sharedInstance): Ditto.

        * runtime/JSGlobalData.h: (JSC::JSGlobalData::makeUsableFromMultipleThreads): Just forward
        the call to Heap, which clients need not know about, ideally.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkJavaScriptCoreAPIJSContextRefcpp">trunk/JavaScriptCore/API/JSContextRef.cpp</a></li>
<li><a href="#trunkJavaScriptCoreChangeLog">trunk/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkJavaScriptCoreJavaScriptCorexcodeprojprojectpbxproj">trunk/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkJavaScriptCoreruntimeCollectorcpp">trunk/JavaScriptCore/runtime/Collector.cpp</a></li>
<li><a href="#trunkJavaScriptCoreruntimeCollectorh">trunk/JavaScriptCore/runtime/Collector.h</a></li>
<li><a href="#trunkJavaScriptCoreruntimeJSGlobalDatacpp">trunk/JavaScriptCore/runtime/JSGlobalData.cpp</a></li>
<li><a href="#trunkJavaScriptCoreruntimeJSGlobalDatah">trunk/JavaScriptCore/runtime/JSGlobalData.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkJavaScriptCoreAPIJSContextRefcpp"></a>
<div class="modfile"><h4>Modified: trunk/JavaScriptCore/API/JSContextRef.cpp (38621 => 38622)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/JavaScriptCore/API/JSContextRef.cpp        2008-11-20 17:38:50 UTC (rev 38621)
+++ trunk/JavaScriptCore/API/JSContextRef.cpp        2008-11-20 18:11:14 UTC (rev 38622)
</span><span class="lines">@@ -66,6 +66,10 @@
</span><span class="cx"> 
</span><span class="cx">     RefPtr&lt;JSGlobalData&gt; globalData = group ? PassRefPtr&lt;JSGlobalData&gt;(toJS(group)) : JSGlobalData::create();
</span><span class="cx"> 
</span><ins>+#if ENABLE(JSC_MULTIPLE_THREADS)
+    globalData-&gt;makeUsableFromMultipleThreads();
+#endif
+
</ins><span class="cx">     if (!globalObjectClass) {
</span><span class="cx">         JSGlobalObject* globalObject = new (globalData.get()) JSGlobalObject;
</span><span class="cx">         return JSGlobalContextRetain(toGlobalRef(globalObject-&gt;globalExec()));
</span></span></pre></div>
<a id="trunkJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/JavaScriptCore/ChangeLog (38621 => 38622)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/JavaScriptCore/ChangeLog        2008-11-20 17:38:50 UTC (rev 38621)
+++ trunk/JavaScriptCore/ChangeLog        2008-11-20 18:11:14 UTC (rev 38622)
</span><span class="lines">@@ -1,3 +1,26 @@
</span><ins>+2008-11-20  Alexey Proskuryakov  &lt;ap@webkit.org&gt;
+
+        Reviewed by Darin Adler.
+
+        https://bugs.webkit.org/show_bug.cgi?id=22364
+        Crashes seen on Tiger buildbots due to worker threads exhausting pthread keys
+
+        * runtime/Collector.cpp:
+        (JSC::Heap::Heap):
+        (JSC::Heap::destroy):
+        (JSC::Heap::makeUsableFromMultipleThreads):
+        (JSC::Heap::registerThread):
+        * runtime/Collector.h:
+        Pthread key for tracking threads is only created on request now, because this is a limited
+        resource, and thread tracking is not needed for worker heaps, or for WebCore heap.
+
+        * API/JSContextRef.cpp: (JSGlobalContextCreateInGroup): Call makeUsableFromMultipleThreads().
+
+        * runtime/JSGlobalData.cpp: (JSC::JSGlobalData::sharedInstance): Ditto.
+
+        * runtime/JSGlobalData.h: (JSC::JSGlobalData::makeUsableFromMultipleThreads): Just forward
+        the call to Heap, which clients need not know about, ideally.
+
</ins><span class="cx"> 2008-11-20  Geoffrey Garen  &lt;ggaren@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Reviewed by Sam Weinig.
</span></span></pre></div>
<a id="trunkJavaScriptCoreJavaScriptCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj (38621 => 38622)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj        2008-11-20 17:38:50 UTC (rev 38621)
+++ trunk/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj        2008-11-20 18:11:14 UTC (rev 38622)
</span><span class="lines">@@ -484,7 +484,7 @@
</span><span class="cx">                 51F0EB6105C86C6B00E6DF1B /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = &quot;&lt;absolute&gt;&quot;; };
</span><span class="cx">                 51F0EC0705C86C9A00E6DF1B /* libobjc.dylib */ = {isa = PBXFileReference; lastKnownFileType = &quot;compiled.mach-o.dylib&quot;; name = libobjc.dylib; path = /usr/lib/libobjc.dylib; sourceTree = &quot;&lt;absolute&gt;&quot;; };
</span><span class="cx">                 51F648D60BB4E2CA0033D760 /* RetainPtr.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = RetainPtr.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><del>-                5D53726D0E1C546B0021E549 /* Tracing.d */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.dtrace; path = Tracing.d; sourceTree = &quot;&lt;group&gt;&quot;; };
</del><ins>+                5D53726D0E1C546B0021E549 /* Tracing.d */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Tracing.d; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 5D53726E0E1C54880021E549 /* Tracing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Tracing.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 5D53727D0E1C55EC0021E549 /* TracingDtrace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TracingDtrace.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 5D5D8AD00E0D0EBE00F9C692 /* libedit.dylib */ = {isa = PBXFileReference; lastKnownFileType = &quot;compiled.mach-o.dylib&quot;; name = libedit.dylib; path = /usr/lib/libedit.dylib; sourceTree = &quot;&lt;absolute&gt;&quot;; };
</span><span class="lines">@@ -554,7 +554,7 @@
</span><span class="cx">                 930754CE08B0F74500AB3056 /* pcre_tables.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = pcre_tables.cpp; sourceTree = &quot;&lt;group&gt;&quot;; tabWidth = 8; };
</span><span class="cx">                 930754E908B0F78500AB3056 /* pcre_exec.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = pcre_exec.cpp; sourceTree = &quot;&lt;group&gt;&quot;; tabWidth = 8; };
</span><span class="cx">                 9322A00306C341D3009067BB /* libicucore.dylib */ = {isa = PBXFileReference; lastKnownFileType = &quot;compiled.mach-o.dylib&quot;; name = libicucore.dylib; path = /usr/lib/libicucore.dylib; sourceTree = &quot;&lt;absolute&gt;&quot;; };
</span><del>-                932F5BD80822A1C700736975 /* Info.plist */ = {isa = PBXFileReference; indentWidth = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = &quot;&lt;group&gt;&quot;; tabWidth = 8; usesTabs = 1; };
</del><ins>+                932F5BD80822A1C700736975 /* Info.plist */ = {isa = PBXFileReference; indentWidth = 4; lastKnownFileType = text.xml; path = Info.plist; sourceTree = &quot;&lt;group&gt;&quot;; tabWidth = 8; usesTabs = 1; };
</ins><span class="cx">                 932F5BD90822A1C700736975 /* JavaScriptCore.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = JavaScriptCore.framework; sourceTree = BUILT_PRODUCTS_DIR; };
</span><span class="cx">                 932F5BE10822A1C700736975 /* jsc */ = {isa = PBXFileReference; explicitFileType = &quot;compiled.mach-o.executable&quot;; includeInIndex = 0; path = jsc; sourceTree = BUILT_PRODUCTS_DIR; };
</span><span class="cx">                 93303FE80E6A72B500786E6A /* SmallStrings.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SmallStrings.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -1709,7 +1709,6 @@
</span><span class="cx">                 0867D690FE84028FC02AAC07 /* Project object */ = {
</span><span class="cx">                         isa = PBXProject;
</span><span class="cx">                         buildConfigurationList = 149C277108902AFE008A9EFC /* Build configuration list for PBXProject &quot;JavaScriptCore&quot; */;
</span><del>-                        compatibilityVersion = &quot;Xcode 2.4&quot;;
</del><span class="cx">                         hasScannedForEncodings = 1;
</span><span class="cx">                         mainGroup = 0867D691FE84028FC02AAC07 /* JavaScriptCore */;
</span><span class="cx">                         productRefGroup = 034768DFFF38A50411DB9C8B /* Products */;
</span></span></pre></div>
<a id="trunkJavaScriptCoreruntimeCollectorcpp"></a>
<div class="modfile"><h4>Modified: trunk/JavaScriptCore/runtime/Collector.cpp (38621 => 38622)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/JavaScriptCore/runtime/Collector.cpp        2008-11-20 17:38:50 UTC (rev 38621)
+++ trunk/JavaScriptCore/runtime/Collector.cpp        2008-11-20 18:11:14 UTC (rev 38622)
</span><span class="lines">@@ -121,17 +121,12 @@
</span><span class="cx">     : m_markListSet(0)
</span><span class="cx"> #if ENABLE(JSC_MULTIPLE_THREADS)
</span><span class="cx">     , m_registeredThreads(0)
</span><ins>+    , m_currentThreadRegistrar(0)
</ins><span class="cx"> #endif
</span><span class="cx">     , m_globalData(globalData)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(globalData);
</span><span class="cx"> 
</span><del>-#if ENABLE(JSC_MULTIPLE_THREADS)
-    int error = pthread_key_create(&amp;m_currentThreadRegistrar, unregisterThread);
-    if (error)
-        CRASH();
-#endif
-
</del><span class="cx">     memset(&amp;primaryHeap, 0, sizeof(CollectorHeap));
</span><span class="cx">     memset(&amp;numberHeap, 0, sizeof(CollectorHeap));
</span><span class="cx"> }
</span><span class="lines">@@ -165,11 +160,13 @@
</span><span class="cx">     freeHeap(&amp;numberHeap);
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(JSC_MULTIPLE_THREADS)
</span><ins>+    if (m_currentThreadRegistrar) {
</ins><span class="cx"> #ifndef NDEBUG
</span><del>-    int error =
</del><ins>+        int error =
</ins><span class="cx"> #endif
</span><del>-        pthread_key_delete(m_currentThreadRegistrar);
-    ASSERT(!error);
</del><ins>+            pthread_key_delete(m_currentThreadRegistrar);
+        ASSERT(!error);
+    }
</ins><span class="cx"> 
</span><span class="cx">     MutexLocker registeredThreadsLock(m_registeredThreadsMutex);
</span><span class="cx">     for (Heap::Thread* t = m_registeredThreads; t;) {
</span><span class="lines">@@ -478,9 +475,19 @@
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void Heap::makeUsableFromMultipleThreads()
+{
+    if (m_currentThreadRegistrar)
+        return;
+
+    int error = pthread_key_create(&amp;m_currentThreadRegistrar, unregisterThread);
+    if (error)
+        CRASH();
+}
+
</ins><span class="cx"> void Heap::registerThread()
</span><span class="cx"> {
</span><del>-    if (pthread_getspecific(m_currentThreadRegistrar))
</del><ins>+    if (!m_currentThreadRegistrar || pthread_getspecific(m_currentThreadRegistrar))
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     pthread_setspecific(m_currentThreadRegistrar, this);
</span></span></pre></div>
<a id="trunkJavaScriptCoreruntimeCollectorh"></a>
<div class="modfile"><h4>Modified: trunk/JavaScriptCore/runtime/Collector.h (38621 => 38622)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/JavaScriptCore/runtime/Collector.h        2008-11-20 17:38:50 UTC (rev 38621)
+++ trunk/JavaScriptCore/runtime/Collector.h        2008-11-20 18:11:14 UTC (rev 38622)
</span><span class="lines">@@ -145,6 +145,8 @@
</span><span class="cx">         HashSet&lt;ArgList*&gt;* m_markListSet;
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(JSC_MULTIPLE_THREADS)
</span><ins>+        void makeUsableFromMultipleThreads();
+
</ins><span class="cx">         static void unregisterThread(void*);
</span><span class="cx">         void unregisterThread();
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkJavaScriptCoreruntimeJSGlobalDatacpp"></a>
<div class="modfile"><h4>Modified: trunk/JavaScriptCore/runtime/JSGlobalData.cpp (38621 => 38622)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/JavaScriptCore/runtime/JSGlobalData.cpp        2008-11-20 17:38:50 UTC (rev 38621)
+++ trunk/JavaScriptCore/runtime/JSGlobalData.cpp        2008-11-20 18:11:14 UTC (rev 38622)
</span><span class="lines">@@ -165,8 +165,12 @@
</span><span class="cx"> JSGlobalData&amp; JSGlobalData::sharedInstance()
</span><span class="cx"> {
</span><span class="cx">     JSGlobalData*&amp; instance = sharedInstanceInternal();
</span><del>-    if (!instance)
</del><ins>+    if (!instance) {
</ins><span class="cx">         instance = new JSGlobalData(true);
</span><ins>+#if ENABLE(JSC_MULTIPLE_THREADS)
+        instance-&gt;makeUsableFromMultipleThreads();
+#endif
+    }
</ins><span class="cx">     return *instance;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkJavaScriptCoreruntimeJSGlobalDatah"></a>
<div class="modfile"><h4>Modified: trunk/JavaScriptCore/runtime/JSGlobalData.h (38621 => 38622)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/JavaScriptCore/runtime/JSGlobalData.h        2008-11-20 17:38:50 UTC (rev 38621)
+++ trunk/JavaScriptCore/runtime/JSGlobalData.h        2008-11-20 18:11:14 UTC (rev 38622)
</span><span class="lines">@@ -63,6 +63,11 @@
</span><span class="cx">         static PassRefPtr&lt;JSGlobalData&gt; createLeaked();
</span><span class="cx">         ~JSGlobalData();
</span><span class="cx"> 
</span><ins>+#if ENABLE(JSC_MULTIPLE_THREADS)
+        // Will start tracking threads that use the heap, which is resource-heavy.
+        void makeUsableFromMultipleThreads() { heap.makeUsableFromMultipleThreads(); }
+#endif
+
</ins><span class="cx">         Interpreter* interpreter;
</span><span class="cx"> 
</span><span class="cx">         JSValue* exception;
</span></span></pre>
</div>
</div>

</body>
</html>