<!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>[181887] trunk/Source</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/181887">181887</a></dd>
<dt>Author</dt> <dd>fpizlo@apple.com</dd>
<dt>Date</dt> <dd>2015-03-23 22:37:19 -0700 (Mon, 23 Mar 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>JSC should have a low-cost asynchronous disassembler
https://bugs.webkit.org/show_bug.cgi?id=142997

Reviewed by Mark Lam.
Source/JavaScriptCore:

        
This adds a JSC_asyncDisassembly option that disassembles on a thread. Disassembly
doesn't block execution. Some code will live a little longer because of this, since the
work tasks hold a ref to the code, but other than that there is basically no overhead.
        
At present, this isn't really a replacement for JSC_showDisassembly, since it doesn't
provide contextual IR information for Baseline and DFG disassemblies, and it doesn't do
the separate IR dumps for FTL. Using JSC_showDisassembly and friends along with
JSC_asyncDisassembly has bizarre behavior - so just choose one.
        
A simple way of understanding how great this is, is to run a small benchmark like
V8Spider/earley-boyer.
        
Performance without any disassembly flags: 60ms
Performance with JSC_showDisassembly=true: 477ms
Performance with JSC_asyncDisassembly=true: 65ms
        
So, the overhead of disassembly goes from 8x to 8%.
        
Note that JSC_asyncDisassembly=true does make it incorrect to run &quot;time&quot; as a way of
measuring benchmark performance. This is because at VM exit, we wait for all async
disassembly requests to finish. For example, for earley-boyer, we spend an extra ~130ms
after the benchmark completely finishes to finish the disassemblies. This small weirdness
should be OK for the intended use-cases, since all you have to do to get around it is to
measure the execution time of the benchmark payload rather than the end-to-end time of
launching the VM.

* assembler/LinkBuffer.cpp:
(JSC::LinkBuffer::finalizeCodeWithDisassembly):
* assembler/LinkBuffer.h:
(JSC::LinkBuffer::wasAlreadyDisassembled):
(JSC::LinkBuffer::didAlreadyDisassemble):
* dfg/DFGJITCompiler.cpp:
(JSC::DFG::JITCompiler::disassemble):
* dfg/DFGJITFinalizer.cpp:
(JSC::DFG::JITFinalizer::finalize):
(JSC::DFG::JITFinalizer::finalizeFunction):
* disassembler/Disassembler.cpp:
(JSC::disassembleAsynchronously):
(JSC::waitForAsynchronousDisassembly):
* disassembler/Disassembler.h:
* ftl/FTLCompile.cpp:
(JSC::FTL::mmAllocateDataSection):
* ftl/FTLLink.cpp:
(JSC::FTL::link):
* jit/JIT.cpp:
(JSC::JIT::privateCompile):
* jsc.cpp:
* runtime/Options.h:
* runtime/VM.cpp:
(JSC::VM::~VM):

Source/WTF:


* wtf/StringPrintStream.h:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreassemblerLinkBuffercpp">trunk/Source/JavaScriptCore/assembler/LinkBuffer.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreassemblerLinkBufferh">trunk/Source/JavaScriptCore/assembler/LinkBuffer.h</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGJITCompilercpp">trunk/Source/JavaScriptCore/dfg/DFGJITCompiler.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGJITFinalizercpp">trunk/Source/JavaScriptCore/dfg/DFGJITFinalizer.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoredisassemblerDisassemblercpp">trunk/Source/JavaScriptCore/disassembler/Disassembler.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoredisassemblerDisassemblerh">trunk/Source/JavaScriptCore/disassembler/Disassembler.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreftlFTLCompilecpp">trunk/Source/JavaScriptCore/ftl/FTLCompile.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreftlFTLLinkcpp">trunk/Source/JavaScriptCore/ftl/FTLLink.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorejitJITcpp">trunk/Source/JavaScriptCore/jit/JIT.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorejsccpp">trunk/Source/JavaScriptCore/jsc.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeOptionsh">trunk/Source/JavaScriptCore/runtime/Options.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeVMcpp">trunk/Source/JavaScriptCore/runtime/VM.cpp</a></li>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFwtfStringPrintStreamh">trunk/Source/WTF/wtf/StringPrintStream.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (181886 => 181887)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2015-03-24 01:48:54 UTC (rev 181886)
+++ trunk/Source/JavaScriptCore/ChangeLog        2015-03-24 05:37:19 UTC (rev 181887)
</span><span class="lines">@@ -1,3 +1,61 @@
</span><ins>+2015-03-23  Filip Pizlo  &lt;fpizlo@apple.com&gt;
+
+        JSC should have a low-cost asynchronous disassembler
+        https://bugs.webkit.org/show_bug.cgi?id=142997
+
+        Reviewed by Mark Lam.
+        
+        This adds a JSC_asyncDisassembly option that disassembles on a thread. Disassembly
+        doesn't block execution. Some code will live a little longer because of this, since the
+        work tasks hold a ref to the code, but other than that there is basically no overhead.
+        
+        At present, this isn't really a replacement for JSC_showDisassembly, since it doesn't
+        provide contextual IR information for Baseline and DFG disassemblies, and it doesn't do
+        the separate IR dumps for FTL. Using JSC_showDisassembly and friends along with
+        JSC_asyncDisassembly has bizarre behavior - so just choose one.
+        
+        A simple way of understanding how great this is, is to run a small benchmark like
+        V8Spider/earley-boyer.
+        
+        Performance without any disassembly flags: 60ms
+        Performance with JSC_showDisassembly=true: 477ms
+        Performance with JSC_asyncDisassembly=true: 65ms
+        
+        So, the overhead of disassembly goes from 8x to 8%.
+        
+        Note that JSC_asyncDisassembly=true does make it incorrect to run &quot;time&quot; as a way of
+        measuring benchmark performance. This is because at VM exit, we wait for all async
+        disassembly requests to finish. For example, for earley-boyer, we spend an extra ~130ms
+        after the benchmark completely finishes to finish the disassemblies. This small weirdness
+        should be OK for the intended use-cases, since all you have to do to get around it is to
+        measure the execution time of the benchmark payload rather than the end-to-end time of
+        launching the VM.
+
+        * assembler/LinkBuffer.cpp:
+        (JSC::LinkBuffer::finalizeCodeWithDisassembly):
+        * assembler/LinkBuffer.h:
+        (JSC::LinkBuffer::wasAlreadyDisassembled):
+        (JSC::LinkBuffer::didAlreadyDisassemble):
+        * dfg/DFGJITCompiler.cpp:
+        (JSC::DFG::JITCompiler::disassemble):
+        * dfg/DFGJITFinalizer.cpp:
+        (JSC::DFG::JITFinalizer::finalize):
+        (JSC::DFG::JITFinalizer::finalizeFunction):
+        * disassembler/Disassembler.cpp:
+        (JSC::disassembleAsynchronously):
+        (JSC::waitForAsynchronousDisassembly):
+        * disassembler/Disassembler.h:
+        * ftl/FTLCompile.cpp:
+        (JSC::FTL::mmAllocateDataSection):
+        * ftl/FTLLink.cpp:
+        (JSC::FTL::link):
+        * jit/JIT.cpp:
+        (JSC::JIT::privateCompile):
+        * jsc.cpp:
+        * runtime/Options.h:
+        * runtime/VM.cpp:
+        (JSC::VM::~VM):
+
</ins><span class="cx"> 2015-03-23  Dean Jackson  &lt;dino@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         ES7: Implement Array.prototype.includes
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreassemblerLinkBuffercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/assembler/LinkBuffer.cpp (181886 => 181887)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/assembler/LinkBuffer.cpp        2015-03-24 01:48:54 UTC (rev 181886)
+++ trunk/Source/JavaScriptCore/assembler/LinkBuffer.cpp        2015-03-24 05:37:19 UTC (rev 181887)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2012, 2013, 2014 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2012-2015 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -59,19 +59,28 @@
</span><span class="cx"> {
</span><span class="cx">     CodeRef result = finalizeCodeWithoutDisassembly();
</span><span class="cx"> 
</span><del>-#if ENABLE(DISASSEMBLER)
-    dataLogF(&quot;Generated JIT code for &quot;);
</del><ins>+    if (m_alreadyDisassembled)
+        return result;
+    
+    StringPrintStream out;
+    out.printf(&quot;Generated JIT code for &quot;);
</ins><span class="cx">     va_list argList;
</span><span class="cx">     va_start(argList, format);
</span><del>-    WTF::dataLogFV(format, argList);
</del><ins>+    out.vprintf(format, argList);
</ins><span class="cx">     va_end(argList);
</span><del>-    dataLogF(&quot;:\n&quot;);
</del><ins>+    out.printf(&quot;:\n&quot;);
+
+    out.printf(&quot;    Code at [%p, %p):\n&quot;, result.code().executableAddress(), static_cast&lt;char*&gt;(result.code().executableAddress()) + result.size());
</ins><span class="cx">     
</span><del>-    dataLogF(&quot;    Code at [%p, %p):\n&quot;, result.code().executableAddress(), static_cast&lt;char*&gt;(result.code().executableAddress()) + result.size());
</del><ins>+    CString header = out.toCString();
+    
+    if (Options::asyncDisassembly()) {
+        disassembleAsynchronously(header, result, m_size, &quot;    &quot;);
+        return result;
+    }
+    
+    dataLog(header);
</ins><span class="cx">     disassemble(result.code(), m_size, &quot;    &quot;, WTF::dataFile());
</span><del>-#else
-    UNUSED_PARAM(format);
-#endif // ENABLE(DISASSEMBLER)
</del><span class="cx">     
</span><span class="cx">     return result;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreassemblerLinkBufferh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/assembler/LinkBuffer.h (181886 => 181887)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/assembler/LinkBuffer.h        2015-03-24 01:48:54 UTC (rev 181886)
+++ trunk/Source/JavaScriptCore/assembler/LinkBuffer.h        2015-03-24 05:37:19 UTC (rev 181887)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2009, 2010, 2012, 2013, 2014 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2009, 2010, 2012-2015 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -254,6 +254,9 @@
</span><span class="cx">     {
</span><span class="cx">         return m_size;
</span><span class="cx">     }
</span><ins>+    
+    bool wasAlreadyDisassembled() const { return m_alreadyDisassembled; }
+    void didAlreadyDisassemble() { m_alreadyDisassembled = true; }
</ins><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx"> #if ENABLE(BRANCH_COMPACTION)
</span><span class="lines">@@ -310,6 +313,7 @@
</span><span class="cx"> #ifndef NDEBUG
</span><span class="cx">     bool m_completed;
</span><span class="cx"> #endif
</span><ins>+    bool m_alreadyDisassembled { false };
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> #define FINALIZE_CODE_IF(condition, linkBufferReference, dataLogFArgumentsForHeading)  \
</span><span class="lines">@@ -320,7 +324,7 @@
</span><span class="cx"> bool shouldShowDisassemblyFor(CodeBlock*);
</span><span class="cx"> 
</span><span class="cx"> #define FINALIZE_CODE_FOR(codeBlock, linkBufferReference, dataLogFArgumentsForHeading)  \
</span><del>-    FINALIZE_CODE_IF(shouldShowDisassemblyFor(codeBlock), linkBufferReference, dataLogFArgumentsForHeading)
</del><ins>+    FINALIZE_CODE_IF(shouldShowDisassemblyFor(codeBlock) || Options::asyncDisassembly(), linkBufferReference, dataLogFArgumentsForHeading)
</ins><span class="cx"> 
</span><span class="cx"> // Use this to finalize code, like so:
</span><span class="cx"> //
</span><span class="lines">@@ -339,10 +343,10 @@
</span><span class="cx"> // is true, so you can hide expensive disassembly-only computations inside there.
</span><span class="cx"> 
</span><span class="cx"> #define FINALIZE_CODE(linkBufferReference, dataLogFArgumentsForHeading)  \
</span><del>-    FINALIZE_CODE_IF(JSC::Options::showDisassembly(), linkBufferReference, dataLogFArgumentsForHeading)
</del><ins>+    FINALIZE_CODE_IF(JSC::Options::asyncDisassembly() || JSC::Options::showDisassembly(), linkBufferReference, dataLogFArgumentsForHeading)
</ins><span class="cx"> 
</span><span class="cx"> #define FINALIZE_DFG_CODE(linkBufferReference, dataLogFArgumentsForHeading)  \
</span><del>-    FINALIZE_CODE_IF((JSC::Options::showDisassembly() || Options::showDFGDisassembly()), linkBufferReference, dataLogFArgumentsForHeading)
</del><ins>+    FINALIZE_CODE_IF(JSC::Options::asyncDisassembly() || JSC::Options::showDisassembly() || Options::showDFGDisassembly(), linkBufferReference, dataLogFArgumentsForHeading)
</ins><span class="cx"> 
</span><span class="cx"> } // namespace JSC
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGJITCompilercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGJITCompiler.cpp (181886 => 181887)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGJITCompiler.cpp        2015-03-24 01:48:54 UTC (rev 181886)
+++ trunk/Source/JavaScriptCore/dfg/DFGJITCompiler.cpp        2015-03-24 05:37:19 UTC (rev 181887)
</span><span class="lines">@@ -454,8 +454,10 @@
</span><span class="cx"> 
</span><span class="cx"> void JITCompiler::disassemble(LinkBuffer&amp; linkBuffer)
</span><span class="cx"> {
</span><del>-    if (shouldShowDisassembly())
</del><ins>+    if (shouldShowDisassembly()) {
</ins><span class="cx">         m_disassembler-&gt;dump(linkBuffer);
</span><ins>+        linkBuffer.didAlreadyDisassemble();
+    }
</ins><span class="cx">     
</span><span class="cx">     if (m_graph.m_plan.compilation)
</span><span class="cx">         m_disassembler-&gt;reportToProfiler(m_graph.m_plan.compilation.get(), linkBuffer);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGJITFinalizercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGJITFinalizer.cpp (181886 => 181887)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGJITFinalizer.cpp        2015-03-24 01:48:54 UTC (rev 181886)
+++ trunk/Source/JavaScriptCore/dfg/DFGJITFinalizer.cpp        2015-03-24 05:37:19 UTC (rev 181887)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2013 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2013, 2015 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -29,6 +29,7 @@
</span><span class="cx"> #if ENABLE(DFG_JIT)
</span><span class="cx"> 
</span><span class="cx"> #include &quot;CodeBlock.h&quot;
</span><ins>+#include &quot;CodeBlockWithJITType.h&quot;
</ins><span class="cx"> #include &quot;DFGCommon.h&quot;
</span><span class="cx"> #include &quot;DFGPlan.h&quot;
</span><span class="cx"> #include &quot;JSCInlines.h&quot;
</span><span class="lines">@@ -56,7 +57,9 @@
</span><span class="cx"> bool JITFinalizer::finalize()
</span><span class="cx"> {
</span><span class="cx">     m_jitCode-&gt;initializeCodeRef(
</span><del>-        m_linkBuffer-&gt;finalizeCodeWithoutDisassembly(), MacroAssemblerCodePtr());
</del><ins>+        FINALIZE_DFG_CODE(*m_linkBuffer, (&quot;DFG JIT code for %s&quot;, toCString(CodeBlockWithJITType(m_plan.codeBlock.get(), JITCode::DFGJIT)).data())),
+        MacroAssemblerCodePtr());
+    
</ins><span class="cx">     m_plan.codeBlock-&gt;setJITCode(m_jitCode);
</span><span class="cx">     
</span><span class="cx">     finalizeCommon();
</span><span class="lines">@@ -68,7 +71,8 @@
</span><span class="cx"> {
</span><span class="cx">     RELEASE_ASSERT(!m_withArityCheck.isEmptyValue());
</span><span class="cx">     m_jitCode-&gt;initializeCodeRef(
</span><del>-        m_linkBuffer-&gt;finalizeCodeWithoutDisassembly(), m_withArityCheck);
</del><ins>+        FINALIZE_DFG_CODE(*m_linkBuffer, (&quot;DFG JIT code for %s&quot;, toCString(CodeBlockWithJITType(m_plan.codeBlock.get(), JITCode::DFGJIT)).data())),
+        m_withArityCheck);
</ins><span class="cx">     m_plan.codeBlock-&gt;setJITCode(m_jitCode);
</span><span class="cx">     
</span><span class="cx">     finalizeCommon();
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredisassemblerDisassemblercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/disassembler/Disassembler.cpp (181886 => 181887)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/disassembler/Disassembler.cpp        2015-03-24 01:48:54 UTC (rev 181886)
+++ trunk/Source/JavaScriptCore/disassembler/Disassembler.cpp        2015-03-24 05:37:19 UTC (rev 181887)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2012, 2013 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2012, 2013, 2015 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -28,6 +28,11 @@
</span><span class="cx"> 
</span><span class="cx"> #include &quot;MacroAssemblerCodeRef.h&quot;
</span><span class="cx"> #include &lt;wtf/DataLog.h&gt;
</span><ins>+#include &lt;wtf/Deque.h&gt;
+#include &lt;wtf/NeverDestroyed.h&gt;
+#include &lt;wtf/StringPrintStream.h&gt;
+#include &lt;wtf/Threading.h&gt;
+#include &lt;wtf/ThreadingPrimitives.h&gt;
</ins><span class="cx"> 
</span><span class="cx"> namespace JSC {
</span><span class="cx"> 
</span><span class="lines">@@ -39,5 +44,112 @@
</span><span class="cx">     out.printf(&quot;%sdisassembly not available for range %p...%p\n&quot;, prefix, codePtr.executableAddress(), static_cast&lt;char*&gt;(codePtr.executableAddress()) + size);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+namespace {
+
+// This is really a struct, except that it should be a class because that's what the WTF_* macros
+// expect.
+class DisassemblyTask {
+    WTF_MAKE_NONCOPYABLE(DisassemblyTask);
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    DisassemblyTask()
+    {
+    }
+    
+    ~DisassemblyTask()
+    {
+        if (header)
+            free(header); // free() because it would have been copied by strdup.
+    }
+    
+    char* header { nullptr };
+    MacroAssemblerCodeRef codeRef;
+    size_t size { 0 };
+    const char* prefix { nullptr };
+    InstructionSubsetHint subsetHint { MacroAssemblerSubset };
+};
+
+class AsynchronousDisassembler {
+public:
+    AsynchronousDisassembler()
+    {
+        createThread(&quot;Asynchronous Disassembler&quot;, [&amp;] () { run(); });
+    }
+    
+    void enqueue(std::unique_ptr&lt;DisassemblyTask&gt; task)
+    {
+        MutexLocker locker(m_lock);
+        m_queue.append(WTF::move(task));
+        m_condition.broadcast();
+    }
+    
+    void waitUntilEmpty()
+    {
+        MutexLocker locker(m_lock);
+        while (!m_queue.isEmpty() || m_working)
+            m_condition.wait(m_lock);
+    }
+    
+private:
+    NO_RETURN void run()
+    {
+        for (;;) {
+            std::unique_ptr&lt;DisassemblyTask&gt; task;
+            {
+                MutexLocker locker(m_lock);
+                m_working = false;
+                m_condition.broadcast();
+                while (m_queue.isEmpty())
+                    m_condition.wait(m_lock);
+                task = m_queue.takeFirst();
+                m_working = true;
+            }
+
+            dataLog(task-&gt;header);
+            disassemble(
+                task-&gt;codeRef.code(), task-&gt;size, task-&gt;prefix, WTF::dataFile(),
+                task-&gt;subsetHint);
+        }
+    }
+    
+    Mutex m_lock;
+    ThreadCondition m_condition;
+    Deque&lt;std::unique_ptr&lt;DisassemblyTask&gt;&gt; m_queue;
+    bool m_working { false };
+};
+
+bool hadAnyAsynchronousDisassembly = false;
+
+AsynchronousDisassembler&amp; asynchronousDisassembler()
+{
+    static NeverDestroyed&lt;AsynchronousDisassembler&gt; disassembler;
+    hadAnyAsynchronousDisassembly = true;
+    return disassembler.get();
+}
+
+} // anonymous namespace
+
+void disassembleAsynchronously(
+    const CString&amp; header, const MacroAssemblerCodeRef&amp; codeRef, size_t size, const char* prefix,
+    InstructionSubsetHint subsetHint)
+{
+    std::unique_ptr&lt;DisassemblyTask&gt; task = std::make_unique&lt;DisassemblyTask&gt;();
+    task-&gt;header = strdup(header.data()); // Yuck! We need this because CString does racy refcounting.
+    task-&gt;codeRef = codeRef;
+    task-&gt;size = size;
+    task-&gt;prefix = prefix;
+    task-&gt;subsetHint = subsetHint;
+    
+    asynchronousDisassembler().enqueue(WTF::move(task));
+}
+
+void waitForAsynchronousDisassembly()
+{
+    if (!hadAnyAsynchronousDisassembly)
+        return;
+    
+    asynchronousDisassembler().waitUntilEmpty();
+}
+
</ins><span class="cx"> } // namespace JSC
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredisassemblerDisassemblerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/disassembler/Disassembler.h (181886 => 181887)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/disassembler/Disassembler.h        2015-03-24 01:48:54 UTC (rev 181886)
+++ trunk/Source/JavaScriptCore/disassembler/Disassembler.h        2015-03-24 05:37:19 UTC (rev 181887)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2012, 2013 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2012, 2013, 2015 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -26,11 +26,14 @@
</span><span class="cx"> #ifndef Disassembler_h
</span><span class="cx"> #define Disassembler_h
</span><span class="cx"> 
</span><ins>+#include &lt;functional&gt;
</ins><span class="cx"> #include &lt;wtf/PrintStream.h&gt;
</span><ins>+#include &lt;wtf/text/CString.h&gt;
</ins><span class="cx"> 
</span><span class="cx"> namespace JSC {
</span><span class="cx"> 
</span><span class="cx"> class MacroAssemblerCodePtr;
</span><ins>+class MacroAssemblerCodeRef;
</ins><span class="cx"> 
</span><span class="cx"> enum InstructionSubsetHint { MacroAssemblerSubset, LLVMSubset };
</span><span class="cx"> 
</span><span class="lines">@@ -47,6 +50,14 @@
</span><span class="cx"> // the range of machine code addresses.
</span><span class="cx"> void disassemble(const MacroAssemblerCodePtr&amp;, size_t, const char* prefix, PrintStream&amp; out, InstructionSubsetHint = MacroAssemblerSubset);
</span><span class="cx"> 
</span><ins>+// Asynchronous disassembly. This happens on another thread, and calls the provided
+// callback when the disassembly is done.
+void disassembleAsynchronously(
+    const CString&amp; header, const MacroAssemblerCodeRef&amp;, size_t, const char* prefix,
+    InstructionSubsetHint = MacroAssemblerSubset);
+
+JS_EXPORT_PRIVATE void waitForAsynchronousDisassembly();
+
</ins><span class="cx"> } // namespace JSC
</span><span class="cx"> 
</span><span class="cx"> #endif // Disassembler_h
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreftlFTLCompilecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ftl/FTLCompile.cpp (181886 => 181887)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ftl/FTLCompile.cpp        2015-03-24 01:48:54 UTC (rev 181886)
+++ trunk/Source/JavaScriptCore/ftl/FTLCompile.cpp        2015-03-24 05:37:19 UTC (rev 181887)
</span><span class="lines">@@ -803,17 +803,27 @@
</span><span class="cx">             state, state.graph.m_codeBlock, state.jitCode.get(), state.generatedFunction,
</span><span class="cx">             recordMap, didSeeUnwindInfo);
</span><span class="cx">         
</span><del>-        if (shouldShowDisassembly()) {
</del><ins>+        if (shouldShowDisassembly() || Options::asyncDisassembly()) {
</ins><span class="cx">             for (unsigned i = 0; i &lt; state.jitCode-&gt;handles().size(); ++i) {
</span><span class="cx">                 if (state.codeSectionNames[i] != SECTION_NAME(&quot;text&quot;))
</span><span class="cx">                     continue;
</span><span class="cx">                 
</span><span class="cx">                 ExecutableMemoryHandle* handle = state.jitCode-&gt;handles()[i].get();
</span><del>-                dataLog(
</del><ins>+                
+                CString header = toCString(
</ins><span class="cx">                     &quot;Generated LLVM code after stackmap-based fix-up for &quot;,
</span><span class="cx">                     CodeBlockWithJITType(state.graph.m_codeBlock, JITCode::FTLJIT),
</span><span class="cx">                     &quot; in &quot;, state.graph.m_plan.mode, &quot; #&quot;, i, &quot;, &quot;,
</span><span class="cx">                     state.codeSectionNames[i], &quot;:\n&quot;);
</span><ins>+                
+                if (Options::asyncDisassembly()) {
+                    disassembleAsynchronously(
+                        header, MacroAssemblerCodeRef(handle), handle-&gt;sizeInBytes(), &quot;    &quot;,
+                        LLVMSubset);
+                    continue;
+                }
+                
+                dataLog(header);
</ins><span class="cx">                 disassemble(
</span><span class="cx">                     MacroAssemblerCodePtr(handle-&gt;start()), handle-&gt;sizeInBytes(),
</span><span class="cx">                     &quot;    &quot;, WTF::dataFile(), LLVMSubset);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreftlFTLLinkcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ftl/FTLLink.cpp (181886 => 181887)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ftl/FTLLink.cpp        2015-03-24 01:48:54 UTC (rev 181886)
+++ trunk/Source/JavaScriptCore/ftl/FTLLink.cpp        2015-03-24 05:37:19 UTC (rev 181887)
</span><span class="lines">@@ -131,10 +131,10 @@
</span><span class="cx">             if (state.codeSectionNames[i] != SECTION_NAME(&quot;text&quot;))
</span><span class="cx">                 continue;
</span><span class="cx">             
</span><del>-                ExecutableMemoryHandle* handle = state.jitCode-&gt;handles()[i].get();
-                disassemble(
-                    MacroAssemblerCodePtr(handle-&gt;start()), handle-&gt;sizeInBytes(),
-                    &quot;      &quot;, out, LLVMSubset);
</del><ins>+            ExecutableMemoryHandle* handle = state.jitCode-&gt;handles()[i].get();
+            disassemble(
+                MacroAssemblerCodePtr(handle-&gt;start()), handle-&gt;sizeInBytes(),
+                &quot;      &quot;, out, LLVMSubset);
</ins><span class="cx">         }
</span><span class="cx">         compilation-&gt;addDescription(Profiler::OriginStack(), out.toCString());
</span><span class="cx">         out.reset();
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorejitJITcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/jit/JIT.cpp (181886 => 181887)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/jit/JIT.cpp        2015-03-24 01:48:54 UTC (rev 181886)
+++ trunk/Source/JavaScriptCore/jit/JIT.cpp        2015-03-24 05:37:19 UTC (rev 181887)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2008, 2009, 2012, 2013, 2014 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2008, 2009, 2012-2015 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -31,6 +31,7 @@
</span><span class="cx"> 
</span><span class="cx"> #include &quot;ArityCheckFailReturnThunks.h&quot;
</span><span class="cx"> #include &quot;CodeBlock.h&quot;
</span><ins>+#include &quot;CodeBlockWithJITType.h&quot;
</ins><span class="cx"> #include &quot;DFGCapabilities.h&quot;
</span><span class="cx"> #include &quot;Interpreter.h&quot;
</span><span class="cx"> #include &quot;JITInlines.h&quot;
</span><span class="lines">@@ -682,14 +683,18 @@
</span><span class="cx">     if (m_codeBlock-&gt;codeType() == FunctionCode)
</span><span class="cx">         withArityCheck = patchBuffer.locationOf(arityCheck);
</span><span class="cx"> 
</span><del>-    if (Options::showDisassembly())
</del><ins>+    if (Options::showDisassembly()) {
</ins><span class="cx">         m_disassembler-&gt;dump(patchBuffer);
</span><ins>+        patchBuffer.didAlreadyDisassemble();
+    }
</ins><span class="cx">     if (m_compilation) {
</span><span class="cx">         m_disassembler-&gt;reportToProfiler(m_compilation.get(), patchBuffer);
</span><span class="cx">         m_vm-&gt;m_perBytecodeProfiler-&gt;addCompilation(m_compilation);
</span><span class="cx">     }
</span><span class="cx">     
</span><del>-    CodeRef result = patchBuffer.finalizeCodeWithoutDisassembly();
</del><ins>+    CodeRef result = FINALIZE_CODE(
+        patchBuffer,
+        (&quot;Baseline JIT code for %s&quot;, toCString(CodeBlockWithJITType(m_codeBlock, JITCode::BaselineJIT)).data()));
</ins><span class="cx">     
</span><span class="cx">     m_vm-&gt;machineCodeBytesPerBytecodeWordForBaselineJIT.add(
</span><span class="cx">         static_cast&lt;double&gt;(result.size()) /
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorejsccpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/jsc.cpp (181886 => 181887)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/jsc.cpp        2015-03-24 01:48:54 UTC (rev 181886)
+++ trunk/Source/JavaScriptCore/jsc.cpp        2015-03-24 05:37:19 UTC (rev 181887)
</span><span class="lines">@@ -28,6 +28,7 @@
</span><span class="cx"> #include &quot;CodeBlock.h&quot;
</span><span class="cx"> #include &quot;Completion.h&quot;
</span><span class="cx"> #include &quot;CopiedSpaceInlines.h&quot;
</span><ins>+#include &quot;Disassembler.h&quot;
</ins><span class="cx"> #include &quot;ExceptionHelpers.h&quot;
</span><span class="cx"> #include &quot;HeapStatistics.h&quot;
</span><span class="cx"> #include &quot;InitializeThreading.h&quot;
</span><span class="lines">@@ -104,6 +105,8 @@
</span><span class="cx"> 
</span><span class="cx"> NO_RETURN_WITH_VALUE static void jscExit(int status)
</span><span class="cx"> {
</span><ins>+    waitForAsynchronousDisassembly();
+    
</ins><span class="cx"> #if ENABLE(DFG_JIT)
</span><span class="cx">     if (DFG::isCrashing()) {
</span><span class="cx">         for (;;) {
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeOptionsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/Options.h (181886 => 181887)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/Options.h        2015-03-24 01:48:54 UTC (rev 181886)
+++ trunk/Source/JavaScriptCore/runtime/Options.h        2015-03-24 05:37:19 UTC (rev 181887)
</span><span class="lines">@@ -116,6 +116,7 @@
</span><span class="cx">     \
</span><span class="cx">     /* showDisassembly implies showDFGDisassembly. */ \
</span><span class="cx">     v(bool, showDisassembly, false) \
</span><ins>+    v(bool, asyncDisassembly, false) \
</ins><span class="cx">     v(bool, showDFGDisassembly, false) \
</span><span class="cx">     v(bool, showFTLDisassembly, false) \
</span><span class="cx">     v(bool, showAllDFGNodes, false) \
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeVMcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/VM.cpp (181886 => 181887)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/VM.cpp        2015-03-24 01:48:54 UTC (rev 181886)
+++ trunk/Source/JavaScriptCore/runtime/VM.cpp        2015-03-24 05:37:19 UTC (rev 181887)
</span><span class="lines">@@ -40,6 +40,7 @@
</span><span class="cx"> #include &quot;CustomGetterSetter.h&quot;
</span><span class="cx"> #include &quot;DFGLongLivedState.h&quot;
</span><span class="cx"> #include &quot;DFGWorklist.h&quot;
</span><ins>+#include &quot;Disassembler.h&quot;
</ins><span class="cx"> #include &quot;ErrorInstance.h&quot;
</span><span class="cx"> #include &quot;FTLThunks.h&quot;
</span><span class="cx"> #include &quot;FunctionConstructor.h&quot;
</span><span class="lines">@@ -305,6 +306,8 @@
</span><span class="cx">     }
</span><span class="cx"> #endif // ENABLE(DFG_JIT)
</span><span class="cx">     
</span><ins>+    waitForAsynchronousDisassembly();
+    
</ins><span class="cx">     // Clear this first to ensure that nobody tries to remove themselves from it.
</span><span class="cx">     m_perBytecodeProfiler = nullptr;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (181886 => 181887)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog        2015-03-24 01:48:54 UTC (rev 181886)
+++ trunk/Source/WTF/ChangeLog        2015-03-24 05:37:19 UTC (rev 181887)
</span><span class="lines">@@ -1,3 +1,12 @@
</span><ins>+2015-03-23  Filip Pizlo  &lt;fpizlo@apple.com&gt;
+
+        JSC should have a low-cost asynchronous disassembler
+        https://bugs.webkit.org/show_bug.cgi?id=142997
+
+        Reviewed by Mark Lam.
+
+        * wtf/StringPrintStream.h:
+
</ins><span class="cx"> 2015-03-22  Benjamin Poulain  &lt;benjamin@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         CSS Selectors: fix attribute case-insensitive matching of Contain and List
</span></span></pre></div>
<a id="trunkSourceWTFwtfStringPrintStreamh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/StringPrintStream.h (181886 => 181887)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/StringPrintStream.h        2015-03-24 01:48:54 UTC (rev 181886)
+++ trunk/Source/WTF/wtf/StringPrintStream.h        2015-03-24 05:37:19 UTC (rev 181887)
</span><span class="lines">@@ -37,7 +37,7 @@
</span><span class="cx">     WTF_EXPORT_PRIVATE StringPrintStream();
</span><span class="cx">     WTF_EXPORT_PRIVATE virtual ~StringPrintStream();
</span><span class="cx">     
</span><del>-    virtual void vprintf(const char* format, va_list) override WTF_ATTRIBUTE_PRINTF(2, 0);
</del><ins>+    WTF_EXPORT_PRIVATE virtual void vprintf(const char* format, va_list) override WTF_ATTRIBUTE_PRINTF(2, 0);
</ins><span class="cx">     
</span><span class="cx">     WTF_EXPORT_PRIVATE CString toCString();
</span><span class="cx">     WTF_EXPORT_PRIVATE String toString();
</span></span></pre>
</div>
</div>

</body>
</html>