<!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 "time" 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 <fpizlo@apple.com>
+
+ 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 "time" 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 <dino@apple.com>
</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("Generated JIT code for ");
</del><ins>+ if (m_alreadyDisassembled)
+ return result;
+
+ StringPrintStream out;
+ out.printf("Generated JIT code for ");
</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(":\n");
</del><ins>+ out.printf(":\n");
+
+ out.printf(" Code at [%p, %p):\n", result.code().executableAddress(), static_cast<char*>(result.code().executableAddress()) + result.size());
</ins><span class="cx">
</span><del>- dataLogF(" Code at [%p, %p):\n", result.code().executableAddress(), static_cast<char*>(result.code().executableAddress()) + result.size());
</del><ins>+ CString header = out.toCString();
+
+ if (Options::asyncDisassembly()) {
+ disassembleAsynchronously(header, result, m_size, " ");
+ return result;
+ }
+
+ dataLog(header);
</ins><span class="cx"> disassemble(result.code(), m_size, " ", 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& linkBuffer)
</span><span class="cx"> {
</span><del>- if (shouldShowDisassembly())
</del><ins>+ if (shouldShowDisassembly()) {
</ins><span class="cx"> m_disassembler->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->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 "CodeBlock.h"
</span><ins>+#include "CodeBlockWithJITType.h"
</ins><span class="cx"> #include "DFGCommon.h"
</span><span class="cx"> #include "DFGPlan.h"
</span><span class="cx"> #include "JSCInlines.h"
</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->initializeCodeRef(
</span><del>- m_linkBuffer->finalizeCodeWithoutDisassembly(), MacroAssemblerCodePtr());
</del><ins>+ FINALIZE_DFG_CODE(*m_linkBuffer, ("DFG JIT code for %s", toCString(CodeBlockWithJITType(m_plan.codeBlock.get(), JITCode::DFGJIT)).data())),
+ MacroAssemblerCodePtr());
+
</ins><span class="cx"> m_plan.codeBlock->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->initializeCodeRef(
</span><del>- m_linkBuffer->finalizeCodeWithoutDisassembly(), m_withArityCheck);
</del><ins>+ FINALIZE_DFG_CODE(*m_linkBuffer, ("DFG JIT code for %s", toCString(CodeBlockWithJITType(m_plan.codeBlock.get(), JITCode::DFGJIT)).data())),
+ m_withArityCheck);
</ins><span class="cx"> m_plan.codeBlock->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 "MacroAssemblerCodeRef.h"
</span><span class="cx"> #include <wtf/DataLog.h>
</span><ins>+#include <wtf/Deque.h>
+#include <wtf/NeverDestroyed.h>
+#include <wtf/StringPrintStream.h>
+#include <wtf/Threading.h>
+#include <wtf/ThreadingPrimitives.h>
</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("%sdisassembly not available for range %p...%p\n", prefix, codePtr.executableAddress(), static_cast<char*>(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("Asynchronous Disassembler", [&] () { run(); });
+ }
+
+ void enqueue(std::unique_ptr<DisassemblyTask> 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<DisassemblyTask> 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->header);
+ disassemble(
+ task->codeRef.code(), task->size, task->prefix, WTF::dataFile(),
+ task->subsetHint);
+ }
+ }
+
+ Mutex m_lock;
+ ThreadCondition m_condition;
+ Deque<std::unique_ptr<DisassemblyTask>> m_queue;
+ bool m_working { false };
+};
+
+bool hadAnyAsynchronousDisassembly = false;
+
+AsynchronousDisassembler& asynchronousDisassembler()
+{
+ static NeverDestroyed<AsynchronousDisassembler> disassembler;
+ hadAnyAsynchronousDisassembly = true;
+ return disassembler.get();
+}
+
+} // anonymous namespace
+
+void disassembleAsynchronously(
+ const CString& header, const MacroAssemblerCodeRef& codeRef, size_t size, const char* prefix,
+ InstructionSubsetHint subsetHint)
+{
+ std::unique_ptr<DisassemblyTask> task = std::make_unique<DisassemblyTask>();
+ task->header = strdup(header.data()); // Yuck! We need this because CString does racy refcounting.
+ task->codeRef = codeRef;
+ task->size = size;
+ task->prefix = prefix;
+ task->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 <functional>
</ins><span class="cx"> #include <wtf/PrintStream.h>
</span><ins>+#include <wtf/text/CString.h>
</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&, size_t, const char* prefix, PrintStream& 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& header, const MacroAssemblerCodeRef&, 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 < state.jitCode->handles().size(); ++i) {
</span><span class="cx"> if (state.codeSectionNames[i] != SECTION_NAME("text"))
</span><span class="cx"> continue;
</span><span class="cx">
</span><span class="cx"> ExecutableMemoryHandle* handle = state.jitCode->handles()[i].get();
</span><del>- dataLog(
</del><ins>+
+ CString header = toCString(
</ins><span class="cx"> "Generated LLVM code after stackmap-based fix-up for ",
</span><span class="cx"> CodeBlockWithJITType(state.graph.m_codeBlock, JITCode::FTLJIT),
</span><span class="cx"> " in ", state.graph.m_plan.mode, " #", i, ", ",
</span><span class="cx"> state.codeSectionNames[i], ":\n");
</span><ins>+
+ if (Options::asyncDisassembly()) {
+ disassembleAsynchronously(
+ header, MacroAssemblerCodeRef(handle), handle->sizeInBytes(), " ",
+ LLVMSubset);
+ continue;
+ }
+
+ dataLog(header);
</ins><span class="cx"> disassemble(
</span><span class="cx"> MacroAssemblerCodePtr(handle->start()), handle->sizeInBytes(),
</span><span class="cx"> " ", 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("text"))
</span><span class="cx"> continue;
</span><span class="cx">
</span><del>- ExecutableMemoryHandle* handle = state.jitCode->handles()[i].get();
- disassemble(
- MacroAssemblerCodePtr(handle->start()), handle->sizeInBytes(),
- " ", out, LLVMSubset);
</del><ins>+ ExecutableMemoryHandle* handle = state.jitCode->handles()[i].get();
+ disassemble(
+ MacroAssemblerCodePtr(handle->start()), handle->sizeInBytes(),
+ " ", out, LLVMSubset);
</ins><span class="cx"> }
</span><span class="cx"> compilation->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 "ArityCheckFailReturnThunks.h"
</span><span class="cx"> #include "CodeBlock.h"
</span><ins>+#include "CodeBlockWithJITType.h"
</ins><span class="cx"> #include "DFGCapabilities.h"
</span><span class="cx"> #include "Interpreter.h"
</span><span class="cx"> #include "JITInlines.h"
</span><span class="lines">@@ -682,14 +683,18 @@
</span><span class="cx"> if (m_codeBlock->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->dump(patchBuffer);
</span><ins>+ patchBuffer.didAlreadyDisassemble();
+ }
</ins><span class="cx"> if (m_compilation) {
</span><span class="cx"> m_disassembler->reportToProfiler(m_compilation.get(), patchBuffer);
</span><span class="cx"> m_vm->m_perBytecodeProfiler->addCompilation(m_compilation);
</span><span class="cx"> }
</span><span class="cx">
</span><del>- CodeRef result = patchBuffer.finalizeCodeWithoutDisassembly();
</del><ins>+ CodeRef result = FINALIZE_CODE(
+ patchBuffer,
+ ("Baseline JIT code for %s", toCString(CodeBlockWithJITType(m_codeBlock, JITCode::BaselineJIT)).data()));
</ins><span class="cx">
</span><span class="cx"> m_vm->machineCodeBytesPerBytecodeWordForBaselineJIT.add(
</span><span class="cx"> static_cast<double>(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 "CodeBlock.h"
</span><span class="cx"> #include "Completion.h"
</span><span class="cx"> #include "CopiedSpaceInlines.h"
</span><ins>+#include "Disassembler.h"
</ins><span class="cx"> #include "ExceptionHelpers.h"
</span><span class="cx"> #include "HeapStatistics.h"
</span><span class="cx"> #include "InitializeThreading.h"
</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 "CustomGetterSetter.h"
</span><span class="cx"> #include "DFGLongLivedState.h"
</span><span class="cx"> #include "DFGWorklist.h"
</span><ins>+#include "Disassembler.h"
</ins><span class="cx"> #include "ErrorInstance.h"
</span><span class="cx"> #include "FTLThunks.h"
</span><span class="cx"> #include "FunctionConstructor.h"
</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 <fpizlo@apple.com>
+
+ 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 <benjamin@webkit.org>
</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>