<!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>[192590] trunk/Source/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/192590">192590</a></dd>
<dt>Author</dt> <dd>fpizlo@apple.com</dd>
<dt>Date</dt> <dd>2015-11-18 15:05:34 -0800 (Wed, 18 Nov 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>Implement the B3 equivalent of FTLCompile
https://bugs.webkit.org/show_bug.cgi?id=151370
Reviewed by Benjamin Poulain.
This adds a B3 version of FTLCompile and gets the data structures related to installing an FTL
compilation (i.e. the finalizer and JITCode) to be aware of B3. That requires stubbing a lot of stuff
out and also simplifying a lot of code around having everything inside a single contiguous chunk of
JIT code rather than some opaque JIT code handles plus miscellaneous side-codes. This compiles but
crashes because lowering isn't done yet.
* JavaScriptCore.xcodeproj/project.pbxproj:
* b3/B3Procedure.cpp:
(JSC::B3::Procedure::addDataSection):
(JSC::B3::Procedure::calleeSaveRegisters):
(JSC::B3::Procedure::addValueIndex):
* b3/B3Procedure.h:
(JSC::B3::Procedure::code):
* ftl/FTLB3Compile.cpp: Added.
(JSC::FTL::compile):
* ftl/FTLCompile.cpp:
(JSC::FTL::mmAllocateDataSection):
* ftl/FTLExceptionHandlerManager.cpp:
(JSC::FTL::ExceptionHandlerManager::callOperationExceptionTarget):
(JSC::FTL::ExceptionHandlerManager::lazySlowPathExceptionTarget):
(JSC::FTL::ExceptionHandlerManager::getByIdOSRExit):
* ftl/FTLJITCode.cpp:
(JSC::FTL::JITCode::~JITCode):
(JSC::FTL::JITCode::initializeB3Code):
(JSC::FTL::JITCode::initializeExitThunks):
(JSC::FTL::JITCode::addDataSection):
(JSC::FTL::JITCode::initializeAddressForCall):
(JSC::FTL::JITCode::initializeArityCheckEntrypoint):
(JSC::FTL::JITCode::addressForCall):
(JSC::FTL::JITCode::contains):
(JSC::FTL::JITCode::exitThunks):
(JSC::FTL::JITCode::ftl):
* ftl/FTLJITCode.h:
(JSC::FTL::JITCode::b3Code):
(JSC::FTL::JITCode::handles):
(JSC::FTL::JITCode::dataSections):
* ftl/FTLJITFinalizer.cpp:
(JSC::FTL::JITFinalizer::codeSize):
(JSC::FTL::JITFinalizer::finalizeFunction):
* ftl/FTLJITFinalizer.h:
* ftl/FTLLink.cpp:
(JSC::FTL::link):
* ftl/FTLOSRExit.cpp:
(JSC::FTL::OSRExit::codeLocationForRepatch):
(JSC::FTL::OSRExit::gatherRegistersToSpillForCallIfException):</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreJavaScriptCorexcodeprojprojectpbxproj">trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceJavaScriptCoreb3B3Procedurecpp">trunk/Source/JavaScriptCore/b3/B3Procedure.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreb3B3Procedureh">trunk/Source/JavaScriptCore/b3/B3Procedure.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreftlFTLCompilecpp">trunk/Source/JavaScriptCore/ftl/FTLCompile.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreftlFTLExceptionHandlerManagercpp">trunk/Source/JavaScriptCore/ftl/FTLExceptionHandlerManager.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreftlFTLJITCodecpp">trunk/Source/JavaScriptCore/ftl/FTLJITCode.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreftlFTLJITCodeh">trunk/Source/JavaScriptCore/ftl/FTLJITCode.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreftlFTLJITFinalizercpp">trunk/Source/JavaScriptCore/ftl/FTLJITFinalizer.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreftlFTLJITFinalizerh">trunk/Source/JavaScriptCore/ftl/FTLJITFinalizer.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreftlFTLLinkcpp">trunk/Source/JavaScriptCore/ftl/FTLLink.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreftlFTLOSRExitcpp">trunk/Source/JavaScriptCore/ftl/FTLOSRExit.cpp</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreftlFTLB3Compilecpp">trunk/Source/JavaScriptCore/ftl/FTLB3Compile.cpp</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (192589 => 192590)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2015-11-18 23:04:36 UTC (rev 192589)
+++ trunk/Source/JavaScriptCore/ChangeLog        2015-11-18 23:05:34 UTC (rev 192590)
</span><span class="lines">@@ -1,3 +1,56 @@
</span><ins>+2015-11-18 Filip Pizlo <fpizlo@apple.com>
+
+ Implement the B3 equivalent of FTLCompile
+ https://bugs.webkit.org/show_bug.cgi?id=151370
+
+ Reviewed by Benjamin Poulain.
+
+ This adds a B3 version of FTLCompile and gets the data structures related to installing an FTL
+ compilation (i.e. the finalizer and JITCode) to be aware of B3. That requires stubbing a lot of stuff
+ out and also simplifying a lot of code around having everything inside a single contiguous chunk of
+ JIT code rather than some opaque JIT code handles plus miscellaneous side-codes. This compiles but
+ crashes because lowering isn't done yet.
+
+ * JavaScriptCore.xcodeproj/project.pbxproj:
+ * b3/B3Procedure.cpp:
+ (JSC::B3::Procedure::addDataSection):
+ (JSC::B3::Procedure::calleeSaveRegisters):
+ (JSC::B3::Procedure::addValueIndex):
+ * b3/B3Procedure.h:
+ (JSC::B3::Procedure::code):
+ * ftl/FTLB3Compile.cpp: Added.
+ (JSC::FTL::compile):
+ * ftl/FTLCompile.cpp:
+ (JSC::FTL::mmAllocateDataSection):
+ * ftl/FTLExceptionHandlerManager.cpp:
+ (JSC::FTL::ExceptionHandlerManager::callOperationExceptionTarget):
+ (JSC::FTL::ExceptionHandlerManager::lazySlowPathExceptionTarget):
+ (JSC::FTL::ExceptionHandlerManager::getByIdOSRExit):
+ * ftl/FTLJITCode.cpp:
+ (JSC::FTL::JITCode::~JITCode):
+ (JSC::FTL::JITCode::initializeB3Code):
+ (JSC::FTL::JITCode::initializeExitThunks):
+ (JSC::FTL::JITCode::addDataSection):
+ (JSC::FTL::JITCode::initializeAddressForCall):
+ (JSC::FTL::JITCode::initializeArityCheckEntrypoint):
+ (JSC::FTL::JITCode::addressForCall):
+ (JSC::FTL::JITCode::contains):
+ (JSC::FTL::JITCode::exitThunks):
+ (JSC::FTL::JITCode::ftl):
+ * ftl/FTLJITCode.h:
+ (JSC::FTL::JITCode::b3Code):
+ (JSC::FTL::JITCode::handles):
+ (JSC::FTL::JITCode::dataSections):
+ * ftl/FTLJITFinalizer.cpp:
+ (JSC::FTL::JITFinalizer::codeSize):
+ (JSC::FTL::JITFinalizer::finalizeFunction):
+ * ftl/FTLJITFinalizer.h:
+ * ftl/FTLLink.cpp:
+ (JSC::FTL::link):
+ * ftl/FTLOSRExit.cpp:
+ (JSC::FTL::OSRExit::codeLocationForRepatch):
+ (JSC::FTL::OSRExit::gatherRegistersToSpillForCallIfException):
+
</ins><span class="cx"> 2015-11-18 Saam barati <sbarati@apple.com>
</span><span class="cx">
</span><span class="cx"> There is a bug when default parameter values are mixed with destructuring parameter values
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreJavaScriptCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj (192589 => 192590)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj        2015-11-18 23:04:36 UTC (rev 192589)
+++ trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj        2015-11-18 23:05:34 UTC (rev 192590)
</span><span class="lines">@@ -530,6 +530,7 @@
</span><span class="cx">                 0FB3878E1BFBC44D00E3AB1E /* AirBlockWorklist.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FB3878B1BFBC44D00E3AB1E /* AirBlockWorklist.h */; };
</span><span class="cx">                 0FB3878F1BFBC44D00E3AB1E /* AirOptimizeBlockOrder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FB3878C1BFBC44D00E3AB1E /* AirOptimizeBlockOrder.cpp */; };
</span><span class="cx">                 0FB387901BFBC44D00E3AB1E /* AirOptimizeBlockOrder.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FB3878D1BFBC44D00E3AB1E /* AirOptimizeBlockOrder.h */; };
</span><ins>+                0FB387921BFD31A100E3AB1E /* FTLB3Compile.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FB387911BFD31A100E3AB1E /* FTLB3Compile.cpp */; };
</ins><span class="cx">                 0FB438A319270B1D00E1FBC9 /* StructureSet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FB438A219270B1D00E1FBC9 /* StructureSet.cpp */; };
</span><span class="cx">                 0FB4FB731BC843140025CA5A /* FTLLazySlowPath.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FB4FB701BC843140025CA5A /* FTLLazySlowPath.cpp */; };
</span><span class="cx">                 0FB4FB741BC843140025CA5A /* FTLLazySlowPath.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FB4FB711BC843140025CA5A /* FTLLazySlowPath.h */; };
</span><span class="lines">@@ -2582,6 +2583,7 @@
</span><span class="cx">                 0FB3878B1BFBC44D00E3AB1E /* AirBlockWorklist.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AirBlockWorklist.h; path = b3/air/AirBlockWorklist.h; sourceTree = "<group>"; };
</span><span class="cx">                 0FB3878C1BFBC44D00E3AB1E /* AirOptimizeBlockOrder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = AirOptimizeBlockOrder.cpp; path = b3/air/AirOptimizeBlockOrder.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 0FB3878D1BFBC44D00E3AB1E /* AirOptimizeBlockOrder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AirOptimizeBlockOrder.h; path = b3/air/AirOptimizeBlockOrder.h; sourceTree = "<group>"; };
</span><ins>+                0FB387911BFD31A100E3AB1E /* FTLB3Compile.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = FTLB3Compile.cpp; path = ftl/FTLB3Compile.cpp; sourceTree = "<group>"; };
</ins><span class="cx">                 0FB438A219270B1D00E1FBC9 /* StructureSet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StructureSet.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 0FB4B51016B3A964003F696B /* DFGMinifiedID.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DFGMinifiedID.h; path = dfg/DFGMinifiedID.h; sourceTree = "<group>"; };
</span><span class="cx">                 0FB4B51916B62772003F696B /* DFGAllocator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DFGAllocator.h; path = dfg/DFGAllocator.h; sourceTree = "<group>"; };
</span><span class="lines">@@ -4354,6 +4356,7 @@
</span><span class="cx">                                 0FEA0A1A1708B00700BB722C /* FTLAbstractHeapRepository.h */,
</span><span class="cx">                                 0F485323187DFDEC0083B687 /* FTLAvailableRecovery.cpp */,
</span><span class="cx">                                 0F485324187DFDEC0083B687 /* FTLAvailableRecovery.h */,
</span><ins>+                                0FB387911BFD31A100E3AB1E /* FTLB3Compile.cpp */,
</ins><span class="cx">                                 269D636D1BFBE5D000101B1D /* FTLB3Output.h */,
</span><span class="cx">                                 0FEA09FE170513DB00BB722C /* FTLCapabilities.cpp */,
</span><span class="cx">                                 0FEA09FF170513DB00BB722C /* FTLCapabilities.h */,
</span><span class="lines">@@ -8720,6 +8723,7 @@
</span><span class="cx">                                 E3D239C81B829C1C00BBEF67 /* JSModuleEnvironment.cpp in Sources */,
</span><span class="cx">                                 E318CBC01B8AEF5100A2929D /* JSModuleNamespaceObject.cpp in Sources */,
</span><span class="cx">                                 E39DA4A61B7E8B7C0084F33A /* JSModuleRecord.cpp in Sources */,
</span><ins>+                                0FB387921BFD31A100E3AB1E /* FTLB3Compile.cpp in Sources */,
</ins><span class="cx">                                 E33E8D1C1B9013C300346B52 /* JSNativeStdFunction.cpp in Sources */,
</span><span class="cx">                                 A72700900DAC6BBC00E548D7 /* JSNotAnObject.cpp in Sources */,
</span><span class="cx">                                 147F39D4107EC37600427A48 /* JSObject.cpp in Sources */,
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreb3B3Procedurecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/b3/B3Procedure.cpp (192589 => 192590)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/b3/B3Procedure.cpp        2015-11-18 23:04:36 UTC (rev 192589)
+++ trunk/Source/JavaScriptCore/b3/B3Procedure.cpp        2015-11-18 23:05:34 UTC (rev 192590)
</span><span class="lines">@@ -148,6 +148,11 @@
</span><span class="cx"> return result;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+const RegisterAtOffsetList& Procedure::calleeSaveRegisters()
+{
+ return code().calleeSaveRegisters();
+}
+
</ins><span class="cx"> size_t Procedure::addValueIndex()
</span><span class="cx"> {
</span><span class="cx"> if (m_valueIndexFreeList.isEmpty()) {
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreb3B3Procedureh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/b3/B3Procedure.h (192589 => 192590)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/b3/B3Procedure.h        2015-11-18 23:04:36 UTC (rev 192589)
+++ trunk/Source/JavaScriptCore/b3/B3Procedure.h        2015-11-18 23:05:34 UTC (rev 192590)
</span><span class="lines">@@ -31,6 +31,7 @@
</span><span class="cx"> #include "B3Origin.h"
</span><span class="cx"> #include "B3Type.h"
</span><span class="cx"> #include "PureNaN.h"
</span><ins>+#include "RegisterAtOffsetList.h"
</ins><span class="cx"> #include <wtf/Bag.h>
</span><span class="cx"> #include <wtf/FastMalloc.h>
</span><span class="cx"> #include <wtf/Noncopyable.h>
</span><span class="lines">@@ -222,6 +223,8 @@
</span><span class="cx">
</span><span class="cx"> Air::Code& code() { return *m_code; }
</span><span class="cx">
</span><ins>+ const RegisterAtOffsetList& calleeSaveRegisters();
+
</ins><span class="cx"> private:
</span><span class="cx"> friend class BlockInsertionSet;
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreftlFTLB3Compilecpp"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/ftl/FTLB3Compile.cpp (0 => 192590)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ftl/FTLB3Compile.cpp         (rev 0)
+++ trunk/Source/JavaScriptCore/ftl/FTLB3Compile.cpp        2015-11-18 23:05:34 UTC (rev 192590)
</span><span class="lines">@@ -0,0 +1,98 @@
</span><ins>+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "FTLCompile.h"
+
+#if ENABLE(FTL_JIT) && FTL_USES_B3
+
+#include "B3Generate.h"
+#include "B3ProcedureInlines.h"
+#include "CodeBlockWithJITType.h"
+#include "CCallHelpers.h"
+#include "DFGCommon.h"
+#include "DFGGraphSafepoint.h"
+#include "DFGOperations.h"
+#include "DataView.h"
+#include "Disassembler.h"
+#include "FTLExceptionHandlerManager.h"
+#include "FTLExitThunkGenerator.h"
+#include "FTLInlineCacheSize.h"
+#include "FTLJITCode.h"
+#include "FTLThunks.h"
+#include "FTLUnwindInfo.h"
+#include "JITSubGenerator.h"
+#include "LinkBuffer.h"
+#include "ScratchRegisterAllocator.h"
+
+namespace JSC { namespace FTL {
+
+using namespace DFG;
+
+void compile(State& state, Safepoint::Result& safepointResult)
+{
+ Graph& graph = state.graph;
+ CodeBlock* codeBlock = graph.m_codeBlock;
+ VM& vm = graph.m_vm;
+
+ {
+ GraphSafepoint safepoint(state.graph, safepointResult);
+
+ B3::prepareForGeneration(*state.proc);
+ }
+
+ if (safepointResult.didGetCancelled())
+ return;
+ RELEASE_ASSERT(!state.graph.m_vm.heap.isCollecting());
+
+ if (state.allocationFailed)
+ return;
+
+ std::unique_ptr<RegisterAtOffsetList> registerOffsets =
+ std::make_unique<RegisterAtOffsetList>(state.proc->calleeSaveRegisters());
+ if (shouldDumpDisassembly()) {
+ dataLog("Unwind info for ", CodeBlockWithJITType(state.graph.m_codeBlock, JITCode::FTLJIT), ":\n");
+ dataLog(" ", *registerOffsets, "\n");
+ }
+ state.graph.m_codeBlock->setCalleeSaveRegisters(WTF::move(registerOffsets));
+
+ CCallHelpers jit(&vm, codeBlock);
+ B3::generate(*state.proc, jit);
+
+ state.finalizer->b3CodeLinkBuffer = std::make_unique<LinkBuffer>(
+ vm, jit, codeBlock, JITCompilationCanFail);
+ if (state.finalizer->b3CodeLinkBuffer->didFailToAllocate()) {
+ state.allocationFailed = true;
+ return;
+ }
+
+ state.generatedFunction = bitwise_cast<GeneratedFunction>(
+ state.finalizer->b3CodeLinkBuffer->entrypoint().executableAddress());
+}
+
+} } // namespace JSC::FTL
+
+#endif // ENABLE(FTL_JIT) && FTL_USES_B3
+
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoreftlFTLCompilecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ftl/FTLCompile.cpp (192589 => 192590)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ftl/FTLCompile.cpp        2015-11-18 23:04:36 UTC (rev 192589)
+++ trunk/Source/JavaScriptCore/ftl/FTLCompile.cpp        2015-11-18 23:05:34 UTC (rev 192590)
</span><span class="lines">@@ -28,7 +28,7 @@
</span><span class="cx"> #include "config.h"
</span><span class="cx"> #include "FTLCompile.h"
</span><span class="cx">
</span><del>-#if ENABLE(FTL_JIT)
</del><ins>+#if ENABLE(FTL_JIT) && !FTL_USES_B3
</ins><span class="cx">
</span><span class="cx"> #include "CodeBlockWithJITType.h"
</span><span class="cx"> #include "CCallHelpers.h"
</span><span class="lines">@@ -1318,5 +1318,5 @@
</span><span class="cx">
</span><span class="cx"> } } // namespace JSC::FTL
</span><span class="cx">
</span><del>-#endif // ENABLE(FTL_JIT)
</del><ins>+#endif // ENABLE(FTL_JIT) && FTL_USES_B3
</ins><span class="cx">
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreftlFTLExceptionHandlerManagercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ftl/FTLExceptionHandlerManager.cpp (192589 => 192590)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ftl/FTLExceptionHandlerManager.cpp        2015-11-18 23:04:36 UTC (rev 192589)
+++ trunk/Source/JavaScriptCore/ftl/FTLExceptionHandlerManager.cpp        2015-11-18 23:05:34 UTC (rev 192590)
</span><span class="lines">@@ -46,6 +46,11 @@
</span><span class="cx">
</span><span class="cx"> CodeLocationLabel ExceptionHandlerManager::callOperationExceptionTarget(uint32_t stackmapRecordIndex)
</span><span class="cx"> {
</span><ins>+#if FTL_USES_B3
+ UNUSED_PARAM(stackmapRecordIndex);
+ RELEASE_ASSERT_NOT_REACHED();
+ return CodeLocationLabel();
+#else // FTL_USES_B3
</ins><span class="cx"> auto findResult = m_map.find(stackmapRecordIndex);
</span><span class="cx"> if (findResult == m_map.end())
</span><span class="cx"> return CodeLocationLabel();
</span><span class="lines">@@ -55,10 +60,16 @@
</span><span class="cx"> OSRExitCompilationInfo& info = m_state.finalizer->osrExit[osrExitIndex];
</span><span class="cx"> RELEASE_ASSERT(info.m_callOperationExceptionOSRExitEntrance.isSet());
</span><span class="cx"> return m_state.finalizer->exitThunksLinkBuffer->locationOf(info.m_callOperationExceptionOSRExitEntrance);
</span><ins>+#endif // FTL_USES_B3
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> CodeLocationLabel ExceptionHandlerManager::lazySlowPathExceptionTarget(uint32_t stackmapRecordIndex)
</span><span class="cx"> {
</span><ins>+#if FTL_USES_B3
+ UNUSED_PARAM(stackmapRecordIndex);
+ RELEASE_ASSERT_NOT_REACHED();
+ return CodeLocationLabel();
+#else // FTL_USES_B3
</ins><span class="cx"> auto findResult = m_map.find(stackmapRecordIndex);
</span><span class="cx"> if (findResult == m_map.end())
</span><span class="cx"> return CodeLocationLabel();
</span><span class="lines">@@ -68,6 +79,7 @@
</span><span class="cx"> OSRExitCompilationInfo& info = m_state.finalizer->osrExit[osrExitIndex];
</span><span class="cx"> RELEASE_ASSERT(info.m_thunkLabel.isSet());
</span><span class="cx"> return m_state.finalizer->exitThunksLinkBuffer->locationOf(info.m_thunkLabel);
</span><ins>+#endif // FTL_USES_B3
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> OSRExit* ExceptionHandlerManager::getByIdOSRExit(uint32_t stackmapRecordIndex)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreftlFTLJITCodecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ftl/FTLJITCode.cpp (192589 => 192590)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ftl/FTLJITCode.cpp        2015-11-18 23:04:36 UTC (rev 192589)
+++ trunk/Source/JavaScriptCore/ftl/FTLJITCode.cpp        2015-11-18 23:05:34 UTC (rev 192590)
</span><span class="lines">@@ -42,14 +42,25 @@
</span><span class="cx"> if (FTL::shouldDumpDisassembly()) {
</span><span class="cx"> dataLog("Destroying FTL JIT code at ");
</span><span class="cx"> CommaPrinter comma;
</span><ins>+#if FTL_USES_B3
+ dataLog(comma, m_b3Code);
+ dataLog(comma, m_arityCheckEntrypoint);
+#else
</ins><span class="cx"> for (auto& handle : m_handles)
</span><span class="cx"> dataLog(comma, pointerDump(handle.get()));
</span><span class="cx"> dataLog(comma, pointerDump(m_arityCheckEntrypoint.executableMemory()));
</span><span class="cx"> dataLog(comma, pointerDump(m_exitThunks.executableMemory()));
</span><span class="cx"> dataLog("\n");
</span><ins>+#endif
</ins><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+#if FTL_USES_B3
+void JITCode::initializeB3Code(CodeRef b3Code)
+{
+ m_b3Code = b3Code;
+}
+#else // FTL_USES_B3
</ins><span class="cx"> void JITCode::initializeExitThunks(CodeRef exitThunks)
</span><span class="cx"> {
</span><span class="cx"> m_exitThunks = exitThunks;
</span><span class="lines">@@ -64,15 +75,16 @@
</span><span class="cx"> {
</span><span class="cx"> m_dataSections.append(dataSection);
</span><span class="cx"> }
</span><ins>+#endif // FTL_USES_B3
</ins><span class="cx">
</span><del>-void JITCode::initializeArityCheckEntrypoint(CodeRef entrypoint)
</del><ins>+void JITCode::initializeAddressForCall(CodePtr address)
</ins><span class="cx"> {
</span><del>- m_arityCheckEntrypoint = entrypoint;
</del><ins>+ m_addressForCall = address;
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-void JITCode::initializeAddressForCall(CodePtr address)
</del><ins>+void JITCode::initializeArityCheckEntrypoint(CodeRef entrypoint)
</ins><span class="cx"> {
</span><del>- m_addressForCall = address;
</del><ins>+ m_arityCheckEntrypoint = entrypoint;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> JITCode::CodePtr JITCode::addressForCall(ArityCheckMode arityCheck)
</span><span class="lines">@@ -121,10 +133,12 @@
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+#if !FTL_USES_B3
</ins><span class="cx"> JITCode::CodePtr JITCode::exitThunks()
</span><span class="cx"> {
</span><span class="cx"> return m_exitThunks.code();
</span><span class="cx"> }
</span><ins>+#endif
</ins><span class="cx">
</span><span class="cx"> JITCode* JITCode::ftl()
</span><span class="cx"> {
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreftlFTLJITCodeh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ftl/FTLJITCode.h (192589 => 192590)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ftl/FTLJITCode.h        2015-11-18 23:04:36 UTC (rev 192589)
+++ trunk/Source/JavaScriptCore/ftl/FTLJITCode.h        2015-11-18 23:05:34 UTC (rev 192590)
</span><span class="lines">@@ -58,28 +58,36 @@
</span><span class="cx"> public:
</span><span class="cx"> JITCode();
</span><span class="cx"> ~JITCode();
</span><del>-
</del><ins>+
</ins><span class="cx"> CodePtr addressForCall(ArityCheckMode) override;
</span><span class="cx"> void* executableAddressAtOffset(size_t offset) override;
</span><span class="cx"> void* dataAddressAtOffset(size_t offset) override;
</span><span class="cx"> unsigned offsetOf(void* pointerIntoCode) override;
</span><span class="cx"> size_t size() override;
</span><span class="cx"> bool contains(void*) override;
</span><del>-
</del><ins>+
+#if FTL_USES_B3
+ void initializeB3Code(CodeRef);
+#else
</ins><span class="cx"> void initializeExitThunks(CodeRef);
</span><span class="cx"> void addHandle(PassRefPtr<ExecutableMemoryHandle>);
</span><span class="cx"> void addDataSection(PassRefPtr<DataSection>);
</span><ins>+#endif
+ void initializeAddressForCall(CodePtr);
</ins><span class="cx"> void initializeArityCheckEntrypoint(CodeRef);
</span><del>- void initializeAddressForCall(CodePtr);
</del><span class="cx">
</span><span class="cx"> void validateReferences(const TrackedReferences&) override;
</span><span class="cx">
</span><span class="cx"> RegisterSet liveRegistersToPreserveAtExceptionHandlingCallSite(CodeBlock*, CallSiteIndex) override;
</span><del>-
</del><ins>+
+#if FTL_USES_B3
+ CodeRef b3Code() const { return m_b3Code; }
+#else
</ins><span class="cx"> const Vector<RefPtr<ExecutableMemoryHandle>>& handles() const { return m_handles; }
</span><span class="cx"> const Vector<RefPtr<DataSection>>& dataSections() const { return m_dataSections; }
</span><span class="cx">
</span><span class="cx"> CodePtr exitThunks();
</span><ins>+#endif
</ins><span class="cx">
</span><span class="cx"> JITCode* ftl() override;
</span><span class="cx"> DFG::CommonData* dfgCommon() override;
</span><span class="lines">@@ -91,11 +99,17 @@
</span><span class="cx"> Vector<std::unique_ptr<LazySlowPath>> lazySlowPaths;
</span><span class="cx">
</span><span class="cx"> private:
</span><ins>+ CodePtr m_addressForCall;
+#if FTL_USES_B3
+ CodeRef m_b3Code;
+#else
</ins><span class="cx"> Vector<RefPtr<DataSection>> m_dataSections;
</span><span class="cx"> Vector<RefPtr<ExecutableMemoryHandle>> m_handles;
</span><del>- CodePtr m_addressForCall;
</del><ins>+#endif
</ins><span class="cx"> CodeRef m_arityCheckEntrypoint;
</span><ins>+#if !FTL_USES_B3
</ins><span class="cx"> CodeRef m_exitThunks;
</span><ins>+#endif
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> } } // namespace JSC::FTL
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreftlFTLJITFinalizercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ftl/FTLJITFinalizer.cpp (192589 => 192590)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ftl/FTLJITFinalizer.cpp        2015-11-18 23:04:36 UTC (rev 192589)
+++ trunk/Source/JavaScriptCore/ftl/FTLJITFinalizer.cpp        2015-11-18 23:05:34 UTC (rev 192590)
</span><span class="lines">@@ -49,19 +49,24 @@
</span><span class="cx"> size_t JITFinalizer::codeSize()
</span><span class="cx"> {
</span><span class="cx"> size_t result = 0;
</span><del>-
</del><ins>+
+#if FTL_USES_B3
+ if (b3CodeLinkBuffer)
+ result += b3CodeLinkBuffer->size();
+#else // FTL_USES_B3
</ins><span class="cx"> if (exitThunksLinkBuffer)
</span><span class="cx"> result += exitThunksLinkBuffer->size();
</span><del>- if (entrypointLinkBuffer)
- result += entrypointLinkBuffer->size();
</del><span class="cx"> if (sideCodeLinkBuffer)
</span><span class="cx"> result += sideCodeLinkBuffer->size();
</span><span class="cx"> if (handleExceptionsLinkBuffer)
</span><span class="cx"> result += handleExceptionsLinkBuffer->size();
</span><del>-
</del><span class="cx"> for (unsigned i = jitCode->handles().size(); i--;)
</span><span class="cx"> result += jitCode->handles()[i]->sizeInBytes();
</span><ins>+#endif // FTL_USES_B3
</ins><span class="cx">
</span><ins>+ if (entrypointLinkBuffer)
+ result += entrypointLinkBuffer->size();
+
</ins><span class="cx"> return result;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -73,11 +78,25 @@
</span><span class="cx">
</span><span class="cx"> bool JITFinalizer::finalizeFunction()
</span><span class="cx"> {
</span><ins>+#if FTL_USES_B3
+ for (OSRExitCompilationInfo& info : osrExit) {
+ b3CodeLinkBuffer->link(
+ info.m_thunkJump,
+ CodeLocationLabel(
+ m_plan.vm.getCTIStub(osrExitGenerationThunkGenerator).code()));
+ }
+
+ jitCode->initializeB3Code(
+ FINALIZE_DFG_CODE(
+ *b3CodeLinkBuffer,
+ ("FTL B3 code for %s", toCString(CodeBlockWithJITType(m_plan.codeBlock, JITCode::FTLJIT)).data())));
+
+#else // FTL_USES_B3
</ins><span class="cx"> for (unsigned i = jitCode->handles().size(); i--;) {
</span><span class="cx"> MacroAssembler::cacheFlush(
</span><span class="cx"> jitCode->handles()[i]->start(), jitCode->handles()[i]->sizeInBytes());
</span><span class="cx"> }
</span><del>-
</del><ins>+
</ins><span class="cx"> if (exitThunksLinkBuffer) {
</span><span class="cx"> for (unsigned i = 0; i < osrExit.size(); ++i) {
</span><span class="cx"> OSRExitCompilationInfo& info = osrExit[i];
</span><span class="lines">@@ -124,6 +143,7 @@
</span><span class="cx"> *outOfLineCodeInfos[i].m_linkBuffer,
</span><span class="cx"> ("FTL out of line code for %s", outOfLineCodeInfos[i].m_codeDescription)).executableMemory());
</span><span class="cx"> }
</span><ins>+#endif // FTL_USES_B3
</ins><span class="cx">
</span><span class="cx"> jitCode->initializeArityCheckEntrypoint(
</span><span class="cx"> FINALIZE_DFG_CODE(
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreftlFTLJITFinalizerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ftl/FTLJITFinalizer.h (192589 => 192590)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ftl/FTLJITFinalizer.h        2015-11-18 23:04:36 UTC (rev 192589)
+++ trunk/Source/JavaScriptCore/ftl/FTLJITFinalizer.h        2015-11-18 23:05:34 UTC (rev 192590)
</span><span class="lines">@@ -60,11 +60,21 @@
</span><span class="cx"> bool finalize() override;
</span><span class="cx"> bool finalizeFunction() override;
</span><span class="cx">
</span><ins>+#if FTL_USES_B3
+ std::unique_ptr<LinkBuffer> b3CodeLinkBuffer;
+#endif
+
+ // Eventually, we can get rid of this with B3.
+ std::unique_ptr<LinkBuffer> entrypointLinkBuffer;
+
+#if !FTL_USES_B3
+ // In B3, we can do all of this directly in the B3 code. That includes slow paths and exception handlers.
</ins><span class="cx"> std::unique_ptr<LinkBuffer> exitThunksLinkBuffer;
</span><del>- std::unique_ptr<LinkBuffer> entrypointLinkBuffer;
</del><span class="cx"> std::unique_ptr<LinkBuffer> sideCodeLinkBuffer;
</span><span class="cx"> std::unique_ptr<LinkBuffer> handleExceptionsLinkBuffer;
</span><span class="cx"> Vector<OutOfLineCodeInfo> outOfLineCodeInfos;
</span><ins>+#endif
+
</ins><span class="cx"> Vector<OSRExitCompilationInfo> osrExit;
</span><span class="cx"> Vector<CCallHelpers::Jump> lazySlowPathGeneratorJumps;
</span><span class="cx"> GeneratedFunction function;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreftlFTLLinkcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ftl/FTLLink.cpp (192589 => 192590)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ftl/FTLLink.cpp        2015-11-18 23:04:36 UTC (rev 192589)
+++ trunk/Source/JavaScriptCore/ftl/FTLLink.cpp        2015-11-18 23:05:34 UTC (rev 192590)
</span><span class="lines">@@ -143,8 +143,11 @@
</span><span class="cx"> dumpContext.dump(out, prefix);
</span><span class="cx"> compilation->addDescription(Profiler::OriginStack(), out.toCString());
</span><span class="cx"> out.reset();
</span><del>-
</del><ins>+
</ins><span class="cx"> out.print(" Disassembly:\n");
</span><ins>+#if FTL_USES_B3
+ out.print(" <not implemented yet>\n");
+#else
</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="lines">@@ -154,6 +157,7 @@
</span><span class="cx"> MacroAssemblerCodePtr(handle->start()), handle->sizeInBytes(),
</span><span class="cx"> " ", out, LLVMSubset);
</span><span class="cx"> }
</span><ins>+#endif
</ins><span class="cx"> compilation->addDescription(Profiler::OriginStack(), out.toCString());
</span><span class="cx"> out.reset();
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreftlFTLOSRExitcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ftl/FTLOSRExit.cpp (192589 => 192590)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ftl/FTLOSRExit.cpp        2015-11-18 23:04:36 UTC (rev 192589)
+++ trunk/Source/JavaScriptCore/ftl/FTLOSRExit.cpp        2015-11-18 23:05:34 UTC (rev 192590)
</span><span class="lines">@@ -137,10 +137,17 @@
</span><span class="cx">
</span><span class="cx"> CodeLocationJump OSRExit::codeLocationForRepatch(CodeBlock* ftlCodeBlock) const
</span><span class="cx"> {
</span><ins>+#if FTL_USES_B3
</ins><span class="cx"> return CodeLocationJump(
</span><span class="cx"> reinterpret_cast<char*>(
</span><ins>+ ftlCodeBlock->jitCode()->ftl()->b3Code().code().dataLocation()) +
+ m_patchableCodeOffset);
+#else // FTL_USES_B3
+ return CodeLocationJump(
+ reinterpret_cast<char*>(
</ins><span class="cx"> ftlCodeBlock->jitCode()->ftl()->exitThunks().dataLocation()) +
</span><span class="cx"> m_patchableCodeOffset);
</span><ins>+#endif // FTL_USES_B3
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void OSRExit::gatherRegistersToSpillForCallIfException(StackMaps& stackmaps, StackMaps::Record& record)
</span></span></pre>
</div>
</div>
</body>
</html>