Commit 9a1ae938 authored by oliver@apple.com's avatar oliver@apple.com

fourthTier: JITCode should abstract exactly how the JIT code is structured and...

fourthTier: JITCode should abstract exactly how the JIT code is structured and where it was allocated
https://bugs.webkit.org/show_bug.cgi?id=113437

Reviewed by Mark Hahnenberg.

JITCode is now a virtual base class, which will allow different JITs to have radically
different memory allocation and management conventions in the future. It will also
make it easier to store JIT-specific meta-data in CodeBlock just by putting it into
an appropriate JITCode subclass.

For now there is one subclass, DirectJITCode, which just behaves like JITCode used to
behave.

* assembler/RepatchBuffer.h:
(JSC::RepatchBuffer::RepatchBuffer):
* bytecode/CodeBlock.cpp:
(JSC::CodeBlock::resetStubInternal):
(JSC::CodeBlock::bytecodeOffset):
(JSC::CodeBlock::codeOriginForReturn):
* bytecode/CodeBlock.h:
(JSC::CodeBlock::setJITCode):
(JSC::CodeBlock::getJITCode):
(JSC::CodeBlock::getJITType):
(CodeBlock):
* dfg/DFGDriver.cpp:
(JSC::DFG::compile):
(JSC::DFG::tryCompile):
(JSC::DFG::tryCompileFunction):
* dfg/DFGDriver.h:
(DFG):
(JSC::DFG::tryCompile):
(JSC::DFG::tryCompileFunction):
* dfg/DFGJITCompiler.cpp:
(JSC::DFG::JITCompiler::compile):
(JSC::DFG::JITCompiler::compileFunction):
* dfg/DFGJITCompiler.h:
(JITCompiler):
* dfg/DFGOSREntry.cpp:
(JSC::DFG::prepareOSREntry):
* dfg/DFGOSRExit.cpp:
(JSC::DFG::OSRExit::codeLocationForRepatch):
* dfg/DFGOSRExitCompiler32_64.cpp:
(JSC::DFG::OSRExitCompiler::compileExit):
* dfg/DFGOSRExitCompiler64.cpp:
(JSC::DFG::OSRExitCompiler::compileExit):
* dfg/DFGOperations.cpp:
* interpreter/Interpreter.cpp:
(JSC::Interpreter::execute):
(JSC::Interpreter::executeCall):
(JSC::Interpreter::executeConstruct):
* jit/JIT.cpp:
(JSC::JIT::privateCompile):
* jit/JIT.h:
(JSC::JIT::compile):
(JIT):
* jit/JITCode.cpp:
(JSC):
(JSC::JITCode::JITCode):
(JSC::JITCode::~JITCode):
(JSC::JITCode::execute):
(JSC::JITCode::hostFunction):
(JSC::DirectJITCode::DirectJITCode):
(JSC::DirectJITCode::~DirectJITCode):
(JSC::DirectJITCode::addressForCall):
(JSC::DirectJITCode::executableAddressAtOffset):
(JSC::DirectJITCode::dataAddressAtOffset):
(JSC::DirectJITCode::offsetOf):
(JSC::DirectJITCode::size):
(JSC::DirectJITCode::contains):
* jit/JITCode.h:
(JSC):
(JITCode):
(JSC::JITCode::bottomTierJIT):
(JSC::JITCode::topTierJIT):
(JSC::JITCode::nextTierJIT):
(JSC::JITCode::isOptimizingJIT):
(JSC::JITCode::isBaselineCode):
(JSC::JITCode::jitType):
(JSC::JITCode::jitTypeFor):
(JSC::JITCode::executableAddress):
(JSC::JITCode::start):
(JSC::JITCode::end):
(DirectJITCode):
* jit/JITDriver.h:
(JSC::jitCompileIfAppropriate):
(JSC::jitCompileFunctionIfAppropriate):
* jit/JITStubs.cpp:
(JSC::lazyLinkFor):
(JSC::DEFINE_STUB_FUNCTION):
* jit/ThunkGenerators.cpp:
(JSC::virtualForGenerator):
* llint/LLIntEntrypoints.cpp:
(JSC::LLInt::getFunctionEntrypoint):
(JSC::LLInt::getEvalEntrypoint):
(JSC::LLInt::getProgramEntrypoint):
* llint/LLIntEntrypoints.h:
(JSC):
(LLInt):
(JSC::LLInt::getEntrypoint):
* llint/LLIntSlowPaths.cpp:
(JSC::LLInt::jitCompileAndSetHeuristics):
(JSC::LLInt::entryOSR):
(JSC::LLInt::LLINT_SLOW_PATH_DECL):
* runtime/Executable.cpp:
(JSC::EvalExecutable::compileInternal):
(JSC::ProgramExecutable::compileInternal):
(JSC::FunctionExecutable::compileForCallInternal):
(JSC::FunctionExecutable::compileForConstructInternal):
* runtime/Executable.h:
(JSC::ExecutableBase::generatedJITCodeForCall):
(JSC::ExecutableBase::generatedJITCodeForConstruct):
(JSC::ExecutableBase::generatedJITCodeFor):
(ExecutableBase):
(JSC::ExecutableBase::hostCodeEntryFor):
(JSC::ExecutableBase::jsCodeEntryFor):
(JSC::ExecutableBase::jsCodeWithArityCheckEntryFor):
(JSC::NativeExecutable::create):
(JSC::NativeExecutable::finishCreation):
(JSC::EvalExecutable::generatedJITCode):
(JSC::ProgramExecutable::generatedJITCode):
* runtime/ExecutionHarness.h:
(JSC::prepareForExecution):
(JSC::prepareFunctionForExecution):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@153113 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 429afd29
2013-07-15 Oliver Hunt <oliver@apple.com>
Merge dfgFourthTier r147014
2013-03-27 Filip Pizlo <fpizlo@apple.com>
fourthTier: JITCode should abstract exactly how the JIT code is structured and where it was allocated
https://bugs.webkit.org/show_bug.cgi?id=113437
Reviewed by Mark Hahnenberg.
JITCode is now a virtual base class, which will allow different JITs to have radically
different memory allocation and management conventions in the future. It will also
make it easier to store JIT-specific meta-data in CodeBlock just by putting it into
an appropriate JITCode subclass.
For now there is one subclass, DirectJITCode, which just behaves like JITCode used to
behave.
* assembler/RepatchBuffer.h:
(JSC::RepatchBuffer::RepatchBuffer):
* bytecode/CodeBlock.cpp:
(JSC::CodeBlock::resetStubInternal):
(JSC::CodeBlock::bytecodeOffset):
(JSC::CodeBlock::codeOriginForReturn):
* bytecode/CodeBlock.h:
(JSC::CodeBlock::setJITCode):
(JSC::CodeBlock::getJITCode):
(JSC::CodeBlock::getJITType):
(CodeBlock):
* dfg/DFGDriver.cpp:
(JSC::DFG::compile):
(JSC::DFG::tryCompile):
(JSC::DFG::tryCompileFunction):
* dfg/DFGDriver.h:
(DFG):
(JSC::DFG::tryCompile):
(JSC::DFG::tryCompileFunction):
* dfg/DFGJITCompiler.cpp:
(JSC::DFG::JITCompiler::compile):
(JSC::DFG::JITCompiler::compileFunction):
* dfg/DFGJITCompiler.h:
(JITCompiler):
* dfg/DFGOSREntry.cpp:
(JSC::DFG::prepareOSREntry):
* dfg/DFGOSRExit.cpp:
(JSC::DFG::OSRExit::codeLocationForRepatch):
* dfg/DFGOSRExitCompiler32_64.cpp:
(JSC::DFG::OSRExitCompiler::compileExit):
* dfg/DFGOSRExitCompiler64.cpp:
(JSC::DFG::OSRExitCompiler::compileExit):
* dfg/DFGOperations.cpp:
* interpreter/Interpreter.cpp:
(JSC::Interpreter::execute):
(JSC::Interpreter::executeCall):
(JSC::Interpreter::executeConstruct):
* jit/JIT.cpp:
(JSC::JIT::privateCompile):
* jit/JIT.h:
(JSC::JIT::compile):
(JIT):
* jit/JITCode.cpp:
(JSC):
(JSC::JITCode::JITCode):
(JSC::JITCode::~JITCode):
(JSC::JITCode::execute):
(JSC::JITCode::hostFunction):
(JSC::DirectJITCode::DirectJITCode):
(JSC::DirectJITCode::~DirectJITCode):
(JSC::DirectJITCode::addressForCall):
(JSC::DirectJITCode::executableAddressAtOffset):
(JSC::DirectJITCode::dataAddressAtOffset):
(JSC::DirectJITCode::offsetOf):
(JSC::DirectJITCode::size):
(JSC::DirectJITCode::contains):
* jit/JITCode.h:
(JSC):
(JITCode):
(JSC::JITCode::bottomTierJIT):
(JSC::JITCode::topTierJIT):
(JSC::JITCode::nextTierJIT):
(JSC::JITCode::isOptimizingJIT):
(JSC::JITCode::isBaselineCode):
(JSC::JITCode::jitType):
(JSC::JITCode::jitTypeFor):
(JSC::JITCode::executableAddress):
(JSC::JITCode::start):
(JSC::JITCode::end):
(DirectJITCode):
* jit/JITDriver.h:
(JSC::jitCompileIfAppropriate):
(JSC::jitCompileFunctionIfAppropriate):
* jit/JITStubs.cpp:
(JSC::lazyLinkFor):
(JSC::DEFINE_STUB_FUNCTION):
* jit/ThunkGenerators.cpp:
(JSC::virtualForGenerator):
* llint/LLIntEntrypoints.cpp:
(JSC::LLInt::getFunctionEntrypoint):
(JSC::LLInt::getEvalEntrypoint):
(JSC::LLInt::getProgramEntrypoint):
* llint/LLIntEntrypoints.h:
(JSC):
(LLInt):
(JSC::LLInt::getEntrypoint):
* llint/LLIntSlowPaths.cpp:
(JSC::LLInt::jitCompileAndSetHeuristics):
(JSC::LLInt::entryOSR):
(JSC::LLInt::LLINT_SLOW_PATH_DECL):
* runtime/Executable.cpp:
(JSC::EvalExecutable::compileInternal):
(JSC::ProgramExecutable::compileInternal):
(JSC::FunctionExecutable::compileForCallInternal):
(JSC::FunctionExecutable::compileForConstructInternal):
* runtime/Executable.h:
(JSC::ExecutableBase::generatedJITCodeForCall):
(JSC::ExecutableBase::generatedJITCodeForConstruct):
(JSC::ExecutableBase::generatedJITCodeFor):
(ExecutableBase):
(JSC::ExecutableBase::hostCodeEntryFor):
(JSC::ExecutableBase::jsCodeEntryFor):
(JSC::ExecutableBase::jsCodeWithArityCheckEntryFor):
(JSC::NativeExecutable::create):
(JSC::NativeExecutable::finishCreation):
(JSC::EvalExecutable::generatedJITCode):
(JSC::ProgramExecutable::generatedJITCode):
* runtime/ExecutionHarness.h:
(JSC::prepareForExecution):
(JSC::prepareFunctionForExecution):
2013-07-24 Filip Pizlo <fpizlo@apple.com>
It should be possible to hijack IndexingHeader for things other than lengths
......
......@@ -1889,9 +1889,9 @@
034768DFFF38A50411DB9C8B /* Products */ = {
isa = PBXGroup;
children = (
932F5BD90822A1C700736975 /* JavaScriptCore.framework */,
932F5BE10822A1C700736975 /* jsc */,
0FF922CF14F46B130041A24E /* JSCLLIntOffsetsExtractor */,
932F5BD90822A1C700736975 /* JavaScriptCore.framework */,
141211200A48793C00480255 /* minidom */,
14BD59BF0A3E8F9000BAF59C /* testapi */,
6511230514046A4C002B101D /* testRegExp */,
......@@ -1905,36 +1905,36 @@
isa = PBXGroup;
children = (
8604F4F2143A6C4400B295F5 /* ChangeLog */,
A718F8211178EB4B002465A7 /* create_regex_tables */,
937B63CC09E766D200A671DD /* DerivedSources.make */,
A7C225CC139981F100FF1662 /* KeywordLookupGenerator.py */,
F692A8540255597D01FF60F7 /* create_hash_table */,
F5C290E60284F98E018635CA /* JavaScriptCorePrefix.h */,
A718F8211178EB4B002465A7 /* create_regex_tables */,
45E12D8806A49B0F00E9DF84 /* jsc.cpp */,
A767FF9F14F4502900789059 /* JSCTypedArrayStubs.h */,
F68EBB8C0255D4C601FF60F7 /* config.h */,
F5C290E60284F98E018635CA /* JavaScriptCorePrefix.h */,
A767FF9F14F4502900789059 /* JSCTypedArrayStubs.h */,
937B63CC09E766D200A671DD /* DerivedSources.make */,
A7C225CC139981F100FF1662 /* KeywordLookupGenerator.py */,
1432EBD70A34CAD400717B9F /* API */,
9688CB120ED12B4E001D649F /* assembler */,
969A078F0ED1D3AE00F1F681 /* bytecode */,
7E39D81D0EC38EFA003AF11A /* bytecompiler */,
1C90513E0BA9E8830081E9D0 /* Configurations */,
1480DB9A0DDC2231003CFDF2 /* debugger */,
0FF4272E158EBCCE004CB9FF /* disassembler */,
650FDF8D09D0FCA700769E54 /* Derived Sources */,
86EC9DB31328DF44002B2AD7 /* dfg */,
0FF4272E158EBCCE004CB9FF /* disassembler */,
0867D69AFE84028FC02AAC07 /* Frameworks */,
142E312A134FF0A600AFADB5 /* heap */,
1429D77A0ED20D7300B89619 /* interpreter */,
1429D92C0ED22D7000B89619 /* jit */,
0F46809C14BA7F4D00BFE272 /* llint */,
7E39D8370EC3A388003AF11A /* parser */,
034768DFFF38A50411DB9C8B /* Products */,
95AB831A0DA42C6900BC83F3 /* profiler */,
932FC3C20824BB70005B3C75 /* Resources */,
7EF6E0BB0EB7A1EC0079AFAF /* runtime */,
141211000A48772600480255 /* tests */,
8603CEF014C753EF00AE59E3 /* tools */,
86EAC48C0F93E8B9008EC948 /* yarr */,
1C90513E0BA9E8830081E9D0 /* Configurations */,
650FDF8D09D0FCA700769E54 /* Derived Sources */,
0867D69AFE84028FC02AAC07 /* Frameworks */,
034768DFFF38A50411DB9C8B /* Products */,
932FC3C20824BB70005B3C75 /* Resources */,
);
name = JavaScriptCore;
sourceTree = "<group>";
......@@ -2236,6 +2236,7 @@
1482B74B0A43032800517CFC /* JSStringRef.h */,
146AAB370B66A94400E55F16 /* JSStringRefCF.cpp */,
146AAB2A0B66A84900E55F16 /* JSStringRefCF.h */,
1A28D4A7177B71C80007FA3C /* JSStringRefPrivate.h */,
86E3C606167BAB87006D760A /* JSValue.h */,
86E3C60D167BAB87006D760A /* JSValue.mm */,
86E3C60E167BAB87006D760A /* JSValueInternal.h */,
......@@ -2255,7 +2256,6 @@
E124A8F60E555775003091F1 /* OpaqueJSString.cpp */,
E124A8F50E555775003091F1 /* OpaqueJSString.h */,
5DE3D0F40DD8DDFB00468714 /* WebKitAvailability.h */,
1A28D4A7177B71C80007FA3C /* JSStringRefPrivate.h */,
);
path = API;
sourceTree = "<group>";
......@@ -3038,7 +3038,6 @@
144836E7132DA7BE005BE785 /* ConservativeRoots.h in Headers */,
BC18C3F60E16F5CD00B34460 /* ConstructData.h in Headers */,
C2EAD2FC14F0249800A4B159 /* CopiedAllocator.h in Headers */,
1A28D4A8177B71C80007FA3C /* JSStringRefPrivate.h in Headers */,
C2C8D03014A3CEFC00578E65 /* CopiedBlock.h in Headers */,
C2FC9BD316644DFB00810D33 /* CopiedBlockInlines.h in Headers */,
C2EAA3FA149A835E00FCE112 /* CopiedSpace.h in Headers */,
......@@ -3243,6 +3242,7 @@
2600B5A7152BAAA70091EE5F /* JSStringJoiner.h in Headers */,
BC18C4280E16F5CD00B34460 /* JSStringRef.h in Headers */,
BC18C4290E16F5CD00B34460 /* JSStringRefCF.h in Headers */,
1A28D4A8177B71C80007FA3C /* JSStringRefPrivate.h in Headers */,
0F919D0D157EE0A2004A4E7D /* JSSymbolTableObject.h in Headers */,
BC18C42A0E16F5CD00B34460 /* JSType.h in Headers */,
6507D29E0E871E5E00D7D896 /* JSTypeInfo.h in Headers */,
......
......@@ -46,9 +46,9 @@ class RepatchBuffer {
public:
RepatchBuffer(CodeBlock* codeBlock)
{
JITCode& code = codeBlock->getJITCode();
m_start = code.start();
m_size = code.size();
RefPtr<JITCode> code = codeBlock->getJITCode();
m_start = code->start();
m_size = code->size();
ExecutableAllocator::makeWritable(m_start, m_size);
}
......
......@@ -2388,13 +2388,13 @@ void CodeBlock::resetStubInternal(RepatchBuffer& repatchBuffer, StructureStubInf
dataLog("Clearing structure cache (kind ", static_cast<int>(stubInfo.accessType), ") in ", *this, ".\n");
if (isGetByIdAccess(accessType)) {
if (getJITCode().jitType() == JITCode::DFGJIT)
if (getJITType() == JITCode::DFGJIT)
DFG::dfgResetGetByID(repatchBuffer, stubInfo);
else
JIT::resetPatchGetById(repatchBuffer, &stubInfo);
} else {
ASSERT(isPutByIdAccess(accessType));
if (getJITCode().jitType() == JITCode::DFGJIT)
if (getJITType() == JITCode::DFGJIT)
DFG::dfgResetPutByID(repatchBuffer, stubInfo);
else
JIT::resetPatchPutById(repatchBuffer, &stubInfo);
......@@ -2719,8 +2719,8 @@ unsigned CodeBlock::bytecodeOffset(ExecState* exec, ReturnAddressPtr returnAddre
if (!callIndices.size())
return 1;
if (getJITCode().getExecutableMemory()->contains(returnAddress.value())) {
unsigned callReturnOffset = getJITCode().offsetOf(returnAddress.value());
if (getJITCode()->contains(returnAddress.value())) {
unsigned callReturnOffset = getJITCode()->offsetOf(returnAddress.value());
CallReturnOffsetToBytecodeOffset* result =
binarySearch<CallReturnOffsetToBytecodeOffset, unsigned>(
callIndices, callIndices.size(), callReturnOffset, getCallReturnOffset);
......@@ -2753,7 +2753,7 @@ bool CodeBlock::codeOriginForReturn(ReturnAddressPtr returnAddress, CodeOrigin&
if (!hasCodeOrigins())
return false;
if (!getJITCode().getExecutableMemory()->contains(returnAddress.value())) {
if (!getJITCode()->contains(returnAddress.value())) {
ClosureCallStubRoutine* stub = findClosureCallForReturnPC(returnAddress);
ASSERT(stub);
if (!stub)
......@@ -2762,7 +2762,7 @@ bool CodeBlock::codeOriginForReturn(ReturnAddressPtr returnAddress, CodeOrigin&
return true;
}
unsigned offset = getJITCode().offsetOf(returnAddress.value());
unsigned offset = getJITCode()->offsetOf(returnAddress.value());
CodeOriginAtCallReturnOffset* entry =
tryBinarySearch<CodeOriginAtCallReturnOffset, unsigned>(
codeOrigins(), codeOrigins().size(), offset,
......
......@@ -426,21 +426,20 @@ public:
int argumentIndexAfterCapture(size_t argument);
#if ENABLE(JIT)
void setJITCode(const JITCode& code, MacroAssemblerCodePtr codeWithArityCheck)
void setJITCode(PassRefPtr<JITCode> code, MacroAssemblerCodePtr codeWithArityCheck)
{
m_jitCode = code;
m_jitCodeWithArityCheck = codeWithArityCheck;
#if ENABLE(DFG_JIT)
if (m_jitCode.jitType() == JITCode::DFGJIT) {
if (JITCode::jitTypeFor(m_jitCode) == JITCode::DFGJIT) {
createDFGDataIfNecessary();
m_vm->heap.m_dfgCodeBlocks.m_set.add(this);
}
#endif
}
JITCode& getJITCode() { return m_jitCode; }
PassRefPtr<JITCode> getJITCode() { return m_jitCode; }
MacroAssemblerCodePtr getJITCodeWithArityCheck() { return m_jitCodeWithArityCheck; }
JITCode::JITType getJITType() const { return m_jitCode.jitType(); }
ExecutableMemoryHandle* executableMemory() { return getJITCode().getExecutableMemory(); }
JITCode::JITType getJITType() const { return JITCode::jitTypeFor(m_jitCode); }
virtual JSObject* compileOptimized(ExecState*, JSScope*, unsigned bytecodeIndex) = 0;
void jettison();
enum JITCompilationResult { AlreadyCompiled, CouldNotCompile, CompiledSuccessfully };
......@@ -1188,7 +1187,7 @@ private:
Vector<StructureStubInfo> m_structureStubInfos;
Vector<ByValInfo> m_byValInfos;
Vector<CallLinkInfo> m_callLinkInfos;
JITCode m_jitCode;
RefPtr<JITCode> m_jitCode;
MacroAssemblerCodePtr m_jitCodeWithArityCheck;
SentinelLinkedList<CallLinkInfo, BasicRawSentinelNode<CallLinkInfo> > m_incomingCalls;
#endif
......
......@@ -62,7 +62,7 @@ unsigned getNumCompilations()
}
enum CompileMode { CompileFunction, CompileOther };
inline bool compile(CompileMode compileMode, ExecState* exec, CodeBlock* codeBlock, JITCode& jitCode, MacroAssemblerCodePtr* jitCodeWithArityCheck, unsigned osrEntryBytecodeIndex)
inline bool compile(CompileMode compileMode, ExecState* exec, CodeBlock* codeBlock, RefPtr<JITCode>& jitCode, MacroAssemblerCodePtr* jitCodeWithArityCheck, unsigned osrEntryBytecodeIndex)
{
SamplingRegion samplingRegion("DFG Compilation (Driver)");
......@@ -172,12 +172,12 @@ inline bool compile(CompileMode compileMode, ExecState* exec, CodeBlock* codeBlo
return result;
}
bool tryCompile(ExecState* exec, CodeBlock* codeBlock, JITCode& jitCode, unsigned bytecodeIndex)
bool tryCompile(ExecState* exec, CodeBlock* codeBlock, RefPtr<JITCode>& jitCode, unsigned bytecodeIndex)
{
return compile(CompileOther, exec, codeBlock, jitCode, 0, bytecodeIndex);
}
bool tryCompileFunction(ExecState* exec, CodeBlock* codeBlock, JITCode& jitCode, MacroAssemblerCodePtr& jitCodeWithArityCheck, unsigned bytecodeIndex)
bool tryCompileFunction(ExecState* exec, CodeBlock* codeBlock, RefPtr<JITCode>& jitCode, MacroAssemblerCodePtr& jitCodeWithArityCheck, unsigned bytecodeIndex)
{
return compile(CompileFunction, exec, codeBlock, jitCode, &jitCodeWithArityCheck, bytecodeIndex);
}
......
......@@ -41,11 +41,11 @@ namespace DFG {
JS_EXPORT_PRIVATE unsigned getNumCompilations();
#if ENABLE(DFG_JIT)
bool tryCompile(ExecState*, CodeBlock*, JITCode&, unsigned bytecodeIndex);
bool tryCompileFunction(ExecState*, CodeBlock*, JITCode&, MacroAssemblerCodePtr& jitCodeWithArityCheck, unsigned bytecodeIndex);
bool tryCompile(ExecState*, CodeBlock*, RefPtr<JITCode>&, unsigned bytecodeIndex);
bool tryCompileFunction(ExecState*, CodeBlock*, RefPtr<JITCode>&, MacroAssemblerCodePtr& jitCodeWithArityCheck, unsigned bytecodeIndex);
#else
inline bool tryCompile(ExecState*, CodeBlock*, JITCode&, unsigned) { return false; }
inline bool tryCompileFunction(ExecState*, CodeBlock*, JITCode&, MacroAssemblerCodePtr&, unsigned) { return false; }
inline bool tryCompile(ExecState*, CodeBlock*, RefPtr<JITCode>&, unsigned) { return false; }
inline bool tryCompileFunction(ExecState*, CodeBlock*, RefPtr<JITCode>&, MacroAssemblerCodePtr&, unsigned) { return false; }
#endif
} } // namespace JSC::DFG
......
......@@ -238,7 +238,7 @@ void JITCompiler::link(LinkBuffer& linkBuffer)
codeBlock()->saveCompilation(m_graph.m_compilation);
}
bool JITCompiler::compile(JITCode& entry)
bool JITCompiler::compile(RefPtr<JITCode>& entry)
{
SamplingRegion samplingRegion("DFG Backend");
......@@ -270,13 +270,13 @@ bool JITCompiler::compile(JITCode& entry)
if (m_graph.m_compilation)
m_disassembler->reportToProfiler(m_graph.m_compilation.get(), linkBuffer);
entry = JITCode(
entry = adoptRef(new DirectJITCode(
linkBuffer.finalizeCodeWithoutDisassembly(),
JITCode::DFGJIT);
JITCode::DFGJIT));
return true;
}
bool JITCompiler::compileFunction(JITCode& entry, MacroAssemblerCodePtr& entryWithArityCheck)
bool JITCompiler::compileFunction(RefPtr<JITCode>& entry, MacroAssemblerCodePtr& entryWithArityCheck)
{
SamplingRegion samplingRegion("DFG Backend");
......@@ -365,9 +365,9 @@ bool JITCompiler::compileFunction(JITCode& entry, MacroAssemblerCodePtr& entryWi
m_disassembler->reportToProfiler(m_graph.m_compilation.get(), linkBuffer);
entryWithArityCheck = linkBuffer.locationOf(arityCheck);
entry = JITCode(
entry = adoptRef(new DirectJITCode(
linkBuffer.finalizeCodeWithoutDisassembly(),
JITCode::DFGJIT);
JITCode::DFGJIT));
return true;
}
......
......@@ -245,8 +245,8 @@ class JITCompiler : public CCallHelpers {
public:
JITCompiler(Graph& dfg);
bool compile(JITCode& entry);
bool compileFunction(JITCode& entry, MacroAssemblerCodePtr& entryWithArityCheck);
bool compile(RefPtr<JITCode>& entry);
bool compileFunction(RefPtr<JITCode>& entry, MacroAssemblerCodePtr& entryWithArityCheck);
// Accessors for properties.
Graph& graph() { return m_graph; }
......
......@@ -156,7 +156,7 @@ void* prepareOSREntry(ExecState* exec, CodeBlock* codeBlock, unsigned bytecodeIn
// 5) Find and return the destination machine code address.
void* result = codeBlock->getJITCode().executableAddressAtOffset(entry->m_machineCodeOffset);
void* result = codeBlock->getJITCode()->executableAddressAtOffset(entry->m_machineCodeOffset);
#if ENABLE(JIT_VERBOSE_OSR)
dataLogF(" OSR returning machine code address %p.\n", result);
......
......@@ -62,7 +62,7 @@ MacroAssembler::Jump OSRExit::getPatchableCodeOffsetAsJump() const
CodeLocationJump OSRExit::codeLocationForRepatch(CodeBlock* dfgCodeBlock) const
{
return CodeLocationJump(dfgCodeBlock->getJITCode().dataAddressAtOffset(m_patchableCodeOffset));
return CodeLocationJump(dfgCodeBlock->getJITCode()->dataAddressAtOffset(m_patchableCodeOffset));
}
void OSRExit::correctJump(LinkBuffer& linkBuffer)
......
......@@ -646,7 +646,7 @@ void OSRExitCompiler::compileExit(const OSRExit& exit, const Operands<ValueRecov
ASSERT(mapping);
ASSERT(mapping->m_bytecodeIndex == returnBytecodeIndex);
void* jumpTarget = baselineCodeBlockForCaller->getJITCode().executableAddressAtOffset(mapping->m_machineCodeOffset);
void* jumpTarget = baselineCodeBlockForCaller->getJITCode()->executableAddressAtOffset(mapping->m_machineCodeOffset);
GPRReg callerFrameGPR;
if (inlineCallFrame->caller.inlineCallFrame) {
......@@ -757,7 +757,7 @@ void OSRExitCompiler::compileExit(const OSRExit& exit, const Operands<ValueRecov
ASSERT(mapping);
ASSERT(mapping->m_bytecodeIndex == exit.m_codeOrigin.bytecodeIndex);
void* jumpTarget = baselineCodeBlock->getJITCode().executableAddressAtOffset(mapping->m_machineCodeOffset);
void* jumpTarget = baselineCodeBlock->getJITCode()->executableAddressAtOffset(mapping->m_machineCodeOffset);
ASSERT(GPRInfo::regT2 != GPRInfo::cachedResultRegister && GPRInfo::regT2 != GPRInfo::cachedResultRegister2);
......
......@@ -610,7 +610,7 @@ void OSRExitCompiler::compileExit(const OSRExit& exit, const Operands<ValueRecov
ASSERT(mapping);
ASSERT(mapping->m_bytecodeIndex == returnBytecodeIndex);
void* jumpTarget = baselineCodeBlockForCaller->getJITCode().executableAddressAtOffset(mapping->m_machineCodeOffset);
void* jumpTarget = baselineCodeBlockForCaller->getJITCode()->executableAddressAtOffset(mapping->m_machineCodeOffset);
GPRReg callerFrameGPR;
if (inlineCallFrame->caller.inlineCallFrame) {
......@@ -700,7 +700,7 @@ void OSRExitCompiler::compileExit(const OSRExit& exit, const Operands<ValueRecov
ASSERT(mapping);
ASSERT(mapping->m_bytecodeIndex == exit.m_codeOrigin.bytecodeIndex);
void* jumpTarget = baselineCodeBlock->getJITCode().executableAddressAtOffset(mapping->m_machineCodeOffset);
void* jumpTarget = baselineCodeBlock->getJITCode()->executableAddressAtOffset(mapping->m_machineCodeOffset);
ASSERT(GPRInfo::regT1 != GPRInfo::cachedResultRegister);
......
......@@ -1107,7 +1107,7 @@ inline char* linkFor(ExecState* execCallee, CodeSpecializationKind kind)
MacroAssemblerCodePtr codePtr;
CodeBlock* codeBlock = 0;
if (executable->isHostFunction())
codePtr = executable->generatedJITCodeFor(kind).addressForCall();
codePtr = executable->generatedJITCodeFor(kind)->addressForCall();
else {
FunctionExecutable* functionExecutable = static_cast<FunctionExecutable*>(executable);
JSObject* error = functionExecutable->compileFor(execCallee, callee->scope(), kind);
......@@ -1119,7 +1119,7 @@ inline char* linkFor(ExecState* execCallee, CodeSpecializationKind kind)
if (execCallee->argumentCountIncludingThis() < static_cast<size_t>(codeBlock->numParameters()))
codePtr = functionExecutable->generatedJITCodeWithArityCheckFor(kind);
else
codePtr = functionExecutable->generatedJITCodeFor(kind).addressForCall();
codePtr = functionExecutable->generatedJITCodeFor(kind)->addressForCall();
}
CallLinkInfo& callLinkInfo = exec->codeBlock()->getCallLinkInfo(execCallee->returnPC());
if (!callLinkInfo.seenOnce())
......@@ -1184,7 +1184,7 @@ static bool attemptToOptimizeClosureCall(ExecState* execCallee, JSCell* calleeAs
return false;
ASSERT(callee->executable()->hasJITCodeForCall());
MacroAssemblerCodePtr codePtr = callee->executable()->generatedJITCodeForCall().addressForCall();
MacroAssemblerCodePtr codePtr = callee->executable()->generatedJITCodeForCall()->addressForCall();
CodeBlock* codeBlock;
if (callee->executable()->isHostFunction())
......
......@@ -948,7 +948,7 @@ failedJSONP:
#if ENABLE(LLINT_C_LOOP)
result = LLInt::CLoop::execute(newCallFrame, llint_program_prologue);
#elif ENABLE(JIT)
result = program->generatedJITCode().execute(&m_stack, newCallFrame, &vm);
result = program->generatedJITCode()->execute(&m_stack, newCallFrame, &vm);
#endif // ENABLE(JIT)
}
......@@ -1023,7 +1023,7 @@ JSValue Interpreter::executeCall(CallFrame* callFrame, JSObject* function, CallT
#if ENABLE(LLINT_C_LOOP)
result = LLInt::CLoop::execute(newCallFrame, llint_function_for_call_prologue);
#elif ENABLE(JIT)
result = callData.js.functionExecutable->generatedJITCodeForCall().execute(&m_stack, newCallFrame, &vm);
result = callData.js.functionExecutable->generatedJITCodeForCall()->execute(&m_stack, newCallFrame, &vm);
#endif // ENABLE(JIT)
} else
result = JSValue::decode(callData.native.function(newCallFrame));
......@@ -1101,7 +1101,7 @@ JSObject* Interpreter::executeConstruct(CallFrame* callFrame, JSObject* construc
#if ENABLE(LLINT_C_LOOP)
result = LLInt::CLoop::execute(newCallFrame, llint_function_for_construct_prologue);
#elif ENABLE(JIT)
result = constructData.js.functionExecutable->generatedJITCodeForConstruct().execute(&m_stack, newCallFrame, &vm);
result = constructData.js.functionExecutable->generatedJITCodeForConstruct()->execute(&m_stack, newCallFrame, &vm);
#endif // ENABLE(JIT)
} else
result = JSValue::decode(constructData.native.function(newCallFrame));
......@@ -1198,7 +1198,7 @@ JSValue Interpreter::execute(CallFrameClosure& closure)
#if ENABLE(LLINT_C_LOOP)
result = LLInt::CLoop::execute(closure.newCallFrame, llint_function_for_call_prologue);
#elif ENABLE(JIT)
result = closure.functionExecutable->generatedJITCodeForCall().execute(&m_stack, closure.newCallFrame, &vm);
result = closure.functionExecutable->generatedJITCodeForCall()->execute(&m_stack, closure.newCallFrame, &vm);
#endif // ENABLE(JIT)
}
......@@ -1297,7 +1297,7 @@ JSValue Interpreter::execute(EvalExecutable* eval, CallFrame* callFrame, JSValue
#if ENABLE(LLINT_C_LOOP)
result = LLInt::CLoop::execute(newCallFrame, llint_eval_prologue);
#elif ENABLE(JIT)
result = eval->generatedJITCode().execute(&m_stack, newCallFrame, &vm);
result = eval->generatedJITCode()->execute(&m_stack, newCallFrame, &vm);
#endif // ENABLE(JIT)
}
......
......@@ -562,7 +562,7 @@ ALWAYS_INLINE void PropertyStubCompilationInfo::copyToStubInfo(StructureStubInfo
}
}
JITCode JIT::privateCompile(CodePtr* functionEntryArityCheck, JITCompilationEffort effort)
PassRefPtr<JITCode> JIT::privateCompile(CodePtr* functionEntryArityCheck, JITCompilationEffort effort)
{
#if ENABLE(JIT_VERBOSE_OSR)
printf("Compiling JIT code!\n");
......@@ -692,7 +692,7 @@ JITCode JIT::privateCompile(CodePtr* functionEntryArityCheck, JITCompilationEffo
LinkBuffer patchBuffer(*m_vm, this, m_codeBlock, effort);
if (patchBuffer.didFailToAllocate())
return JITCode();
return PassRefPtr<JITCode>();
// Translate vPC offsets into addresses in JIT generated code, for switch tables.
for (unsigned i = 0; i < m_switches.size(); ++i) {
......@@ -799,7 +799,7 @@ JITCode JIT::privateCompile(CodePtr* functionEntryArityCheck, JITCompilationEffo
dataLogF("JIT generated code for %p at [%p, %p).\n", m_codeBlock, result.executableMemory()->start(), result.executableMemory()->end());
#endif
return JITCode(result, JITCode::BaselineJIT);
return adoptRef(new DirectJITCode(result, JITCode::BaselineJIT));
}
void JIT::linkFor(JSFunction* callee, CodeBlock* callerCodeBlock, CodeBlock* calleeCodeBlock, JIT::CodePtr code, CallLinkInfo* callLinkInfo, VM* vm, CodeSpecializationKind kind)
......
......@@ -302,7 +302,7 @@ namespace JSC {
static const int patchPutByIdDefaultOffset = 256;
public:
static JITCode compile(VM* vm, CodeBlock* codeBlock, JITCompilationEffort effort, CodePtr* functionEntryArityCheck = 0)
static PassRefPtr<JITCode> compile(VM* vm, CodeBlock* codeBlock, JITCompilationEffort effort, CodePtr* functionEntryArityCheck = 0)
{
return JIT(vm, codeBlock).privateCompile(functionEntryArityCheck, effort);
}
......@@ -407,7 +407,7 @@ namespace JSC {
void privateCompileMainPass();
void privateCompileLinkPass();
void privateCompileSlowCases();
JITCode privateCompile(CodePtr* functionEntryArityCheck, JITCompilationEffort);
PassRefPtr<JITCode> privateCompile(CodePtr* functionEntryArityCheck, JITCompilationEffort);
void privateCompileClosureCall(CallLinkInfo*, CodeBlock* calleeCodeBlock, Structure*, ExecutableBase*, MacroAssemblerCodePtr);
......
/*
* Copyright (C) 2008, 2012 Apple Inc. All rights reserved.
* Copyright (C) 2008, 2012, 2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -26,8 +26,76 @@
#include "config.h"
#include "JITCode.h"
#include "Operations.h"
#include <wtf/PrintStream.h>
namespace JSC {
JITCode::JITCode(JITType jitType)
: m_jitType(jitType)
{
}
JITCode::~JITCode()
{
}
JSValue JITCode::execute(JSStack* stack, CallFrame* callFrame, VM* vm)
{
JSValue result = JSValue::decode(ctiTrampoline(executableAddress(), stack, callFrame, 0, 0, vm));
return vm->exception ? jsNull() : result;
}
PassRefPtr<JITCode> JITCode::hostFunction(JITCode::CodeRef code)
{
return adoptRef(new DirectJITCode(code, HostCallThunk));
}
DirectJITCode::DirectJITCode(const JITCode::CodeRef ref, JITType jitType)
: JITCode(jitType)
, m_ref(ref)
{
}
DirectJITCode::~DirectJITCode()
{
}
JITCode::CodePtr DirectJITCode::addressForCall()
{
return m_ref.code();
}
void* DirectJITCode::executableAddressAtOffset(size_t offset)
{
return reinterpret_cast<char*>(m_ref.code().executableAddress()) + offset;
}
void* DirectJITCode::dataAddressAtOffset(size_t offset)
{
ASSERT(offset <= size()); // use <= instead of < because it is valid to ask for an address at the exclusive end of the code.
return reinterpret_cast<char*>(m_ref.code().dataLocation()) + offset;
}
unsigned DirectJITCode::offsetOf(void* pointerIntoCode)
{
intptr_t result = reinterpret_cast<intptr_t>(pointerIntoCode) - reinterpret_cast<intptr_t>(m_ref.code().executableAddress());
ASSERT(static_cast<intptr_t>(static_cast<unsigned>(result)) == result);
return static_cast<unsigned>(result);
}