Commit 3774cd28 authored by fpizlo@apple.com's avatar fpizlo@apple.com

Code duplication for invoking the JIT and DFG should be reduced

https://bugs.webkit.org/show_bug.cgi?id=76117
<rdar://problem/10680189>

Rubber stamped by Geoff Garen.

* GNUmakefile.list.am:
* JavaScriptCore.xcodeproj/project.pbxproj:
* jit/JITDriver.h: Added.
(JSC::jitCompileIfAppropriate):
(JSC::jitCompileFunctionIfAppropriate):
* runtime/Executable.cpp:
(JSC::EvalExecutable::compileInternal):
(JSC::ProgramExecutable::compileInternal):
(JSC::FunctionExecutable::compileForCallInternal):
(JSC::FunctionExecutable::compileForConstructInternal):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@104774 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 0d82fbaa
2012-01-11 Filip Pizlo <fpizlo@apple.com>
Code duplication for invoking the JIT and DFG should be reduced
https://bugs.webkit.org/show_bug.cgi?id=76117
<rdar://problem/10680189>
Rubber stamped by Geoff Garen.
* GNUmakefile.list.am:
* JavaScriptCore.xcodeproj/project.pbxproj:
* jit/JITDriver.h: Added.
(JSC::jitCompileIfAppropriate):
(JSC::jitCompileFunctionIfAppropriate):
* runtime/Executable.cpp:
(JSC::EvalExecutable::compileInternal):
(JSC::ProgramExecutable::compileInternal):
(JSC::FunctionExecutable::compileForCallInternal):
(JSC::FunctionExecutable::compileForConstructInternal):
2012-01-11 Geoffrey Garen <ggaren@apple.com>
Bytecode dumping is broken for call opcodes (due to two new operands)
......@@ -268,6 +268,7 @@ javascriptcore_sources += \
Source/JavaScriptCore/jit/JITCall32_64.cpp \
Source/JavaScriptCore/jit/JITCall.cpp \
Source/JavaScriptCore/jit/JITCode.h \
Source/JavaScriptCore/jit/JITDriver.h \
Source/JavaScriptCore/jit/JIT.cpp \
Source/JavaScriptCore/jit/JIT.h \
Source/JavaScriptCore/jit/JITExceptions.cpp \
......
......@@ -60,6 +60,7 @@
0F0B83B914BCF95F00885B4F /* CallReturnOffsetToBytecodeOffset.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F0B83B814BCF95B00885B4F /* CallReturnOffsetToBytecodeOffset.h */; settings = {ATTRIBUTES = (Private, ); }; };
0F15F15F14B7A73E005DE37D /* CommonSlowPaths.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F15F15D14B7A73A005DE37D /* CommonSlowPaths.h */; settings = {ATTRIBUTES = (Private, ); }; };
0F16D726142C39C000CF784A /* BitVector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F16D724142C39A200CF784A /* BitVector.cpp */; };
0F21C26814BE5F6800ADC64B /* JITDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F21C26614BE5F5E00ADC64B /* JITDriver.h */; settings = {ATTRIBUTES = (Private, ); }; };
0F242DA713F3B1E8007ADD4C /* WeakReferenceHarvester.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F242DA513F3B1BB007ADD4C /* WeakReferenceHarvester.h */; settings = {ATTRIBUTES = (Private, ); }; };
0F2C556F14738F3100121E4F /* DFGCodeBlocks.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F2C556E14738F2E00121E4F /* DFGCodeBlocks.h */; settings = {ATTRIBUTES = (Private, ); }; };
0F2C557014738F3500121E4F /* DFGCodeBlocks.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F2C556D14738F2E00121E4F /* DFGCodeBlocks.cpp */; };
......@@ -827,6 +828,7 @@
0F0B83B814BCF95B00885B4F /* CallReturnOffsetToBytecodeOffset.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CallReturnOffsetToBytecodeOffset.h; sourceTree = "<group>"; };
0F15F15D14B7A73A005DE37D /* CommonSlowPaths.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CommonSlowPaths.h; sourceTree = "<group>"; };
0F16D724142C39A200CF784A /* BitVector.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BitVector.cpp; sourceTree = "<group>"; };
0F21C26614BE5F5E00ADC64B /* JITDriver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JITDriver.h; sourceTree = "<group>"; };
0F242DA513F3B1BB007ADD4C /* WeakReferenceHarvester.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WeakReferenceHarvester.h; sourceTree = "<group>"; };
0F2C556D14738F2E00121E4F /* DFGCodeBlocks.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DFGCodeBlocks.cpp; sourceTree = "<group>"; };
0F2C556E14738F2E00121E4F /* DFGCodeBlocks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DFGCodeBlocks.h; sourceTree = "<group>"; };
......@@ -1707,6 +1709,7 @@
86CC85A20EE79B7400288682 /* JITCall.cpp */,
146FE51111A710430087AE66 /* JITCall32_64.cpp */,
86CCEFDD0F413F8900FD7F9E /* JITCode.h */,
0F21C26614BE5F5E00ADC64B /* JITDriver.h */,
86CC85A00EE79A4700288682 /* JITInlineMethods.h */,
BCDD51E90FB8DF74004A8BDC /* JITOpcodes.cpp */,
A71236E41195F33C00BD2174 /* JITOpcodes32_64.cpp */,
......@@ -3021,6 +3024,7 @@
0F0B83B514BCF86200885B4F /* MethodCallLinkInfo.h in Headers */,
0F0B83B714BCF8E100885B4F /* GlobalResolveInfo.h in Headers */,
0F0B83B914BCF95F00885B4F /* CallReturnOffsetToBytecodeOffset.h in Headers */,
0F21C26814BE5F6800ADC64B /* JITDriver.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
/*
* Copyright (C) 2012 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.
*/
#ifndef JITDriver_h
#define JITDriver_h
#include <wtf/Platform.h>
#if ENABLE(JIT)
#include "BytecodeGenerator.h"
#include "DFGDriver.h"
#include "JIT.h"
namespace JSC {
template<typename CodeBlockType>
inline bool jitCompileIfAppropriate(ExecState* exec, OwnPtr<CodeBlockType>& codeBlock, JITCode& jitCode, JITCode::JITType jitType)
{
if (!exec->globalData().canUseJIT())
return true;
bool dfgCompiled = false;
if (jitType == JITCode::DFGJIT)
dfgCompiled = DFG::tryCompile(exec, codeBlock.get(), jitCode);
if (dfgCompiled) {
if (codeBlock->alternative())
codeBlock->alternative()->unlinkIncomingCalls();
} else {
if (codeBlock->alternative()) {
codeBlock = static_pointer_cast<CodeBlockType>(codeBlock->releaseAlternative());
return false;
}
jitCode = JIT::compile(&exec->globalData(), codeBlock.get());
}
#if !ENABLE(OPCODE_SAMPLING)
if (!BytecodeGenerator::dumpsGeneratedCode())
codeBlock->handleBytecodeDiscardingOpportunity();
#endif
codeBlock->setJITCode(jitCode, MacroAssemblerCodePtr());
return true;
}
inline bool jitCompileFunctionIfAppropriate(ExecState* exec, OwnPtr<FunctionCodeBlock>& codeBlock, JITCode& jitCode, MacroAssemblerCodePtr& jitCodeWithArityCheck, SharedSymbolTable*& symbolTable, JITCode::JITType jitType)
{
JSGlobalData& globalData = exec->globalData();
if (!globalData.canUseJIT())
return true;
bool dfgCompiled = false;
if (jitType == JITCode::DFGJIT)
dfgCompiled = DFG::tryCompileFunction(exec, codeBlock.get(), jitCode, jitCodeWithArityCheck);
if (dfgCompiled) {
if (codeBlock->alternative())
codeBlock->alternative()->unlinkIncomingCalls();
} else {
if (codeBlock->alternative()) {
codeBlock = static_pointer_cast<FunctionCodeBlock>(codeBlock->releaseAlternative());
symbolTable = codeBlock->sharedSymbolTable();
return false;
}
jitCode = JIT::compile(&globalData, codeBlock.get(), &jitCodeWithArityCheck);
}
#if !ENABLE(OPCODE_SAMPLING)
if (!BytecodeGenerator::dumpsGeneratedCode())
codeBlock->handleBytecodeDiscardingOpportunity();
#endif
codeBlock->setJITCode(jitCode, jitCodeWithArityCheck);
return true;
}
} // namespace JSC
#endif // ENABLE(JIT)
#endif // JITDriver_h
......@@ -30,6 +30,7 @@
#include "CodeBlock.h"
#include "DFGDriver.h"
#include "JIT.h"
#include "JITDriver.h"
#include "Parser.h"
#include "UStringBuilder.h"
#include "Vector.h"
......@@ -209,27 +210,8 @@ JSObject* EvalExecutable::compileInternal(ExecState* exec, ScopeChainNode* scope
}
#if ENABLE(JIT)
if (exec->globalData().canUseJIT()) {
bool dfgCompiled = false;
if (jitType == JITCode::DFGJIT)
dfgCompiled = DFG::tryCompile(exec, m_evalCodeBlock.get(), m_jitCodeForCall);
if (dfgCompiled)
ASSERT(!m_evalCodeBlock->alternative() || !m_evalCodeBlock->alternative()->hasIncomingCalls());
else {
if (m_evalCodeBlock->alternative()) {
// There is already an alternative piece of code compiled with a different
// JIT, so we can silently fail.
m_evalCodeBlock = static_pointer_cast<EvalCodeBlock>(m_evalCodeBlock->releaseAlternative());
return 0;
}
m_jitCodeForCall = JIT::compile(scopeChainNode->globalData, m_evalCodeBlock.get());
}
#if !ENABLE(OPCODE_SAMPLING)
if (!BytecodeGenerator::dumpsGeneratedCode())
m_evalCodeBlock->handleBytecodeDiscardingOpportunity();
#endif
m_evalCodeBlock->setJITCode(m_jitCodeForCall, MacroAssemblerCodePtr());
}
if (!jitCompileIfAppropriate(exec, m_evalCodeBlock, m_jitCodeForCall, jitType))
return 0;
#endif
#if ENABLE(JIT)
......@@ -354,26 +336,8 @@ JSObject* ProgramExecutable::compileInternal(ExecState* exec, ScopeChainNode* sc
}
#if ENABLE(JIT)
if (exec->globalData().canUseJIT()) {
bool dfgCompiled = false;
if (jitType == JITCode::DFGJIT)
dfgCompiled = DFG::tryCompile(exec, m_programCodeBlock.get(), m_jitCodeForCall);
if (dfgCompiled) {
if (m_programCodeBlock->alternative())
m_programCodeBlock->alternative()->unlinkIncomingCalls();
} else {
if (m_programCodeBlock->alternative()) {
m_programCodeBlock = static_pointer_cast<ProgramCodeBlock>(m_programCodeBlock->releaseAlternative());
return 0;
}
m_jitCodeForCall = JIT::compile(scopeChainNode->globalData, m_programCodeBlock.get());
}
#if !ENABLE(OPCODE_SAMPLING)
if (!BytecodeGenerator::dumpsGeneratedCode())
m_programCodeBlock->handleBytecodeDiscardingOpportunity();
#endif
m_programCodeBlock->setJITCode(m_jitCodeForCall, MacroAssemblerCodePtr());
}
if (!jitCompileIfAppropriate(exec, m_programCodeBlock, m_jitCodeForCall, jitType))
return 0;
#endif
#if ENABLE(JIT)
......@@ -540,29 +504,8 @@ JSObject* FunctionExecutable::compileForCallInternal(ExecState* exec, ScopeChain
m_symbolTable = m_codeBlockForCall->sharedSymbolTable();
#if ENABLE(JIT)
JSGlobalData* globalData = scopeChainNode->globalData;
if (globalData->canUseJIT()) {
bool dfgCompiled = false;
if (jitType == JITCode::DFGJIT)
dfgCompiled = DFG::tryCompileFunction(exec, m_codeBlockForCall.get(), m_jitCodeForCall, m_jitCodeForCallWithArityCheck);
if (dfgCompiled) {
if (m_codeBlockForCall->alternative())
m_codeBlockForCall->alternative()->unlinkIncomingCalls();
} else {
if (m_codeBlockForCall->alternative()) {
m_codeBlockForCall = static_pointer_cast<FunctionCodeBlock>(m_codeBlockForCall->releaseAlternative());
m_symbolTable = m_codeBlockForCall->sharedSymbolTable();
return 0;
}
m_jitCodeForCall = JIT::compile(globalData, m_codeBlockForCall.get(), &m_jitCodeForCallWithArityCheck);
}
#if !ENABLE(OPCODE_SAMPLING)
if (!BytecodeGenerator::dumpsGeneratedCode())
m_codeBlockForCall->handleBytecodeDiscardingOpportunity();
#endif
m_codeBlockForCall->setJITCode(m_jitCodeForCall, m_jitCodeForCallWithArityCheck);
}
if (!jitCompileFunctionIfAppropriate(exec, m_codeBlockForCall, m_jitCodeForCall, m_jitCodeForCallWithArityCheck, m_symbolTable, jitType))
return 0;
#endif
#if ENABLE(JIT)
......@@ -603,29 +546,8 @@ JSObject* FunctionExecutable::compileForConstructInternal(ExecState* exec, Scope
m_symbolTable = m_codeBlockForConstruct->sharedSymbolTable();
#if ENABLE(JIT)
JSGlobalData* globalData = scopeChainNode->globalData;
if (globalData->canUseJIT()) {
bool dfgCompiled = false;
if (jitType == JITCode::DFGJIT)
dfgCompiled = DFG::tryCompileFunction(exec, m_codeBlockForConstruct.get(), m_jitCodeForConstruct, m_jitCodeForConstructWithArityCheck);
if (dfgCompiled) {
if (m_codeBlockForConstruct->alternative())
m_codeBlockForConstruct->alternative()->unlinkIncomingCalls();
} else {
if (m_codeBlockForConstruct->alternative()) {
m_codeBlockForConstruct = static_pointer_cast<FunctionCodeBlock>(m_codeBlockForConstruct->releaseAlternative());
m_symbolTable = m_codeBlockForConstruct->sharedSymbolTable();
return 0;
}
m_jitCodeForConstruct = JIT::compile(globalData, m_codeBlockForConstruct.get(), &m_jitCodeForConstructWithArityCheck);
}
#if !ENABLE(OPCODE_SAMPLING)
if (!BytecodeGenerator::dumpsGeneratedCode())
m_codeBlockForConstruct->handleBytecodeDiscardingOpportunity();
#endif
m_codeBlockForConstruct->setJITCode(m_jitCodeForConstruct, m_jitCodeForConstructWithArityCheck);
}
if (!jitCompileFunctionIfAppropriate(exec, m_codeBlockForConstruct, m_jitCodeForConstruct, m_jitCodeForConstructWithArityCheck, m_symbolTable, jitType))
return 0;
#endif
#if ENABLE(JIT)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment