Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (153171 => 153172)
--- trunk/Source/_javascript_Core/ChangeLog 2013-07-25 04:00:39 UTC (rev 153171)
+++ trunk/Source/_javascript_Core/ChangeLog 2013-07-25 04:00:41 UTC (rev 153172)
@@ -1,3 +1,43 @@
+2013-05-18 Filip Pizlo <[email protected]>
+
+ FTL should force LLVM to use our own JIT memory allocator, and we shouldn't have to keep around an LLVMExecutionEngineRef to keep code alive
+ https://bugs.webkit.org/show_bug.cgi?id=113619
+
+ Reviewed by Geoffrey Garen.
+
+ This uses new API that I've exposed, which allows for memory manager callbacks
+ from within LLVM. LLVM may allocate multiple independent chunks of memory for
+ a module, and we track all of those in a Vector in FTL::JITCode.
+
+ * ftl/FTLCompile.cpp:
+ (JSC::FTL::mmAllocateCodeSection):
+ (FTL):
+ (JSC::FTL::mmAllocateDataSection):
+ (JSC::FTL::mmApplyPermissions):
+ (JSC::FTL::mmDestroy):
+ (JSC::FTL::compile):
+ * ftl/FTLJITCode.cpp:
+ (JSC::FTL::JITCode::JITCode):
+ (JSC::FTL::JITCode::~JITCode):
+ (JSC::FTL::JITCode::addHandle):
+ (FTL):
+ (JSC::FTL::JITCode::initializeCode):
+ * ftl/FTLJITCode.h:
+ (JITCode):
+ (JSC::FTL::JITCode::handles):
+ * ftl/FTLJITFinalizer.cpp:
+ (JSC::FTL::JITFinalizer::~JITFinalizer):
+ (JSC::FTL::JITFinalizer::finalizeFunction):
+ * ftl/FTLJITFinalizer.h:
+ (JSC::FTL::JITFinalizer::initializeEntrypointLinkBuffer):
+ (JITFinalizer):
+ * ftl/FTLLink.cpp:
+ (JSC::FTL::link):
+ * ftl/FTLState.cpp:
+ (JSC::FTL::State::State):
+ * ftl/FTLState.h:
+ (State):
+
2013-05-12 Filip Pizlo <[email protected]>
fourthTier: FTL shouldn't use FastISel and Small code model should be turned off for now
Modified: trunk/Source/_javascript_Core/ftl/FTLCompile.cpp (153171 => 153172)
--- trunk/Source/_javascript_Core/ftl/FTLCompile.cpp 2013-07-25 04:00:39 UTC (rev 153171)
+++ trunk/Source/_javascript_Core/ftl/FTLCompile.cpp 2013-07-25 04:00:41 UTC (rev 153172)
@@ -31,6 +31,7 @@
#include "CodeBlockWithJITType.h"
#include "DFGCCallHelpers.h"
#include "DFGCommon.h"
+#include "FTLJITCode.h"
#include "FTLLLVMHeaders.h"
#include "JITStubs.h"
#include "LinkBuffer.h"
@@ -39,6 +40,44 @@
using namespace DFG;
+static uint8_t* mmAllocateCodeSection(
+ void* opaqueState, uintptr_t size, unsigned alignment, unsigned sectionID)
+{
+ UNUSED_PARAM(sectionID);
+
+ State& state = *static_cast<State*>(opaqueState);
+
+ ASSERT(alignment <= jitAllocationGranule);
+
+ RefPtr<ExecutableMemoryHandle> result =
+ state.graph.m_vm.executableAllocator.allocate(
+ state.graph.m_vm, size, state.graph.m_codeBlock, JITCompilationMustSucceed);
+
+ state.jitCode->addHandle(result);
+
+ return static_cast<uint8_t*>(result->start());
+}
+
+static uint8_t* mmAllocateDataSection(
+ void* opaqueState, uintptr_t size, unsigned alignment, unsigned sectionID,
+ LLVMBool isReadOnly)
+{
+ // FIXME: fourthTier: FTL memory allocator should be able to allocate data
+ // sections in non-executable memory.
+ // https://bugs.webkit.org/show_bug.cgi?id=116189
+ UNUSED_PARAM(isReadOnly);
+ return mmAllocateCodeSection(opaqueState, size, alignment, sectionID);
+}
+
+static LLVMBool mmApplyPermissions(void*, char**)
+{
+ return false;
+}
+
+static void mmDestroy(void*)
+{
+}
+
void compile(State& state)
{
char* error = 0;
@@ -50,14 +89,18 @@
if (Options::useLLVMSmallCodeModel())
options.CodeModel = LLVMCodeModelSmall;
options.EnableFastISel = Options::enableLLVMFastISel();
+ options.MCJMM = LLVMCreateSimpleMCJITMemoryManager(
+ &state, mmAllocateCodeSection, mmAllocateDataSection, mmApplyPermissions, mmDestroy);
- if (LLVMCreateMCJITCompilerForModule(&state.engine, state.module, &options, sizeof(options), &error)) {
+ LLVMExecutionEngineRef engine;
+
+ if (LLVMCreateMCJITCompilerForModule(&engine, state.module, &options, sizeof(options), &error)) {
dataLog("FATAL: Could not create LLVM execution engine: ", error, "\n");
CRASH();
}
LLVMPassManagerRef pass = LLVMCreatePassManager();
- LLVMAddTargetData(LLVMGetExecutionEngineTargetData(state.engine), pass);
+ LLVMAddTargetData(LLVMGetExecutionEngineTargetData(engine), pass);
LLVMAddConstantPropagationPass(pass);
LLVMAddInstructionCombiningPass(pass);
LLVMAddPromoteMemoryToRegisterPass(pass);
@@ -69,13 +112,11 @@
if (DFG::shouldShowDisassembly() || DFG::verboseCompilationEnabled())
state.dumpState("after optimization");
- // FIXME: LLVM should use our own JIT memory allocator, and we shouldn't have to
- // keep around an LLVMExecutionEngineRef to keep code alive.
- // https://bugs.webkit.org/show_bug.cgi?id=113619
// FIXME: Need to add support for the case where JIT memory allocation failed.
// https://bugs.webkit.org/show_bug.cgi?id=113620
- state.generatedFunction = reinterpret_cast<GeneratedFunction>(LLVMGetPointerToGlobal(state.engine, state.function));
+ state.generatedFunction = reinterpret_cast<GeneratedFunction>(LLVMGetPointerToGlobal(engine, state.function));
LLVMDisposePassManager(pass);
+ LLVMDisposeExecutionEngine(engine);
}
} } // namespace JSC::FTL
Modified: trunk/Source/_javascript_Core/ftl/FTLJITCode.cpp (153171 => 153172)
--- trunk/Source/_javascript_Core/ftl/FTLJITCode.cpp 2013-07-25 04:00:39 UTC (rev 153171)
+++ trunk/Source/_javascript_Core/ftl/FTLJITCode.cpp 2013-07-25 04:00:41 UTC (rev 153172)
@@ -32,14 +32,11 @@
JITCode::JITCode()
: JSC::JITCode(FTLJIT)
- , m_engine(0)
{
}
JITCode::~JITCode()
{
- if (m_engine)
- LLVMDisposeExecutionEngine(m_engine);
}
void JITCode::initializeExitThunks(CodeRef exitThunks)
@@ -47,9 +44,13 @@
m_exitThunks = exitThunks;
}
-void JITCode::initializeCode(LLVMExecutionEngineRef engine, CodeRef entrypoint)
+void JITCode::addHandle(PassRefPtr<ExecutableMemoryHandle> handle)
{
- m_engine = engine;
+ m_handles.append(handle);
+}
+
+void JITCode::initializeCode(CodeRef entrypoint)
+{
m_entrypoint = entrypoint;
}
Modified: trunk/Source/_javascript_Core/ftl/FTLJITCode.h (153171 => 153172)
--- trunk/Source/_javascript_Core/ftl/FTLJITCode.h 2013-07-25 04:00:39 UTC (rev 153171)
+++ trunk/Source/_javascript_Core/ftl/FTLJITCode.h 2013-07-25 04:00:41 UTC (rev 153172)
@@ -50,8 +50,11 @@
bool contains(void*);
void initializeExitThunks(CodeRef);
- void initializeCode(LLVMExecutionEngineRef, CodeRef entrypoint);
+ void addHandle(PassRefPtr<ExecutableMemoryHandle>);
+ void initializeCode(CodeRef entrypoint);
+ const Vector<RefPtr<ExecutableMemoryHandle> >& handles() const { return m_handles; }
+
CodePtr exitThunks();
JITCode* ftl();
@@ -61,10 +64,7 @@
SegmentedVector<OSRExit, 8> osrExit;
private:
- // FIXME: LLVM should use our own JIT memory allocator, and we shouldn't have to
- // keep around an LLVMExecutionEngineRef to keep code alive.
- // https://bugs.webkit.org/show_bug.cgi?id=113619
- LLVMExecutionEngineRef m_engine;
+ Vector<RefPtr<ExecutableMemoryHandle> > m_handles;
CodeRef m_entrypoint;
CodeRef m_exitThunks;
};
Modified: trunk/Source/_javascript_Core/ftl/FTLJITFinalizer.cpp (153171 => 153172)
--- trunk/Source/_javascript_Core/ftl/FTLJITFinalizer.cpp 2013-07-25 04:00:39 UTC (rev 153171)
+++ trunk/Source/_javascript_Core/ftl/FTLJITFinalizer.cpp 2013-07-25 04:00:41 UTC (rev 153172)
@@ -42,8 +42,6 @@
JITFinalizer::~JITFinalizer()
{
- if (m_engine)
- LLVMDisposeExecutionEngine(m_engine);
}
bool JITFinalizer::finalize(RefPtr<JSC::JITCode>&)
@@ -54,6 +52,11 @@
bool JITFinalizer::finalizeFunction(RefPtr<JSC::JITCode>& entry, MacroAssemblerCodePtr& withArityCheck)
{
+ for (unsigned i = m_jitCode->handles().size(); i--;) {
+ MacroAssembler::cacheFlush(
+ m_jitCode->handles()[i]->start(), m_jitCode->handles()[i]->sizeInBytes());
+ }
+
if (m_exitThunksLinkBuffer) {
m_jitCode->initializeExitThunks(
FINALIZE_DFG_CODE(
@@ -63,14 +66,11 @@
withArityCheck = m_entrypointLinkBuffer->locationOf(m_arityCheck);
m_jitCode->initializeCode(
- m_engine,
FINALIZE_DFG_CODE(
*m_entrypointLinkBuffer,
("FTL entrypoint thunk for %s with LLVM generated code at %p", toCString(CodeBlockWithJITType(m_plan.codeBlock.get(), JITCode::FTLJIT)).data(), m_function)));
entry = m_jitCode;
- m_engine = 0; // We don't own it anymore.
-
return true;
}
Modified: trunk/Source/_javascript_Core/ftl/FTLJITFinalizer.h (153171 => 153172)
--- trunk/Source/_javascript_Core/ftl/FTLJITFinalizer.h 2013-07-25 04:00:39 UTC (rev 153171)
+++ trunk/Source/_javascript_Core/ftl/FTLJITFinalizer.h 2013-07-25 04:00:41 UTC (rev 153172)
@@ -52,10 +52,6 @@
{
m_entrypointLinkBuffer = buffer;
}
- void initializeCode(LLVMExecutionEngineRef engine)
- {
- m_engine = engine;
- }
void initializeFunction(GeneratedFunction function)
{
m_function = function;
@@ -75,7 +71,6 @@
private:
OwnPtr<LinkBuffer> m_exitThunksLinkBuffer;
OwnPtr<LinkBuffer> m_entrypointLinkBuffer;
- LLVMExecutionEngineRef m_engine;
MacroAssembler::Label m_arityCheck;
GeneratedFunction m_function;
RefPtr<JITCode> m_jitCode;
Modified: trunk/Source/_javascript_Core/ftl/FTLLink.cpp (153171 => 153172)
--- trunk/Source/_javascript_Core/ftl/FTLLink.cpp 2013-07-25 04:00:39 UTC (rev 153171)
+++ trunk/Source/_javascript_Core/ftl/FTLLink.cpp 2013-07-25 04:00:41 UTC (rev 153172)
@@ -122,7 +122,6 @@
linkBuffer->link(callArityCheck, state.graph.m_codeBlock->m_isConstructor ? cti_op_construct_arityCheck : cti_op_call_arityCheck);
state.finalizer->initializeEntrypointLinkBuffer(linkBuffer.release());
- state.finalizer->initializeCode(state.engine);
state.finalizer->initializeFunction(state.generatedFunction);
state.finalizer->initializeArityCheck(arityCheck);
state.finalizer->initializeJITCode(state.jitCode);
Modified: trunk/Source/_javascript_Core/ftl/FTLState.cpp (153171 => 153172)
--- trunk/Source/_javascript_Core/ftl/FTLState.cpp 2013-07-25 04:00:39 UTC (rev 153171)
+++ trunk/Source/_javascript_Core/ftl/FTLState.cpp 2013-07-25 04:00:41 UTC (rev 153172)
@@ -40,7 +40,6 @@
, module(0)
, function(0)
, jitCode(adoptRef(new JITCode()))
- , engine(0)
, generatedFunction(0)
{
finalizer = new JITFinalizer(graph.m_plan);
Modified: trunk/Source/_javascript_Core/ftl/FTLState.h (153171 => 153172)
--- trunk/Source/_javascript_Core/ftl/FTLState.h 2013-07-25 04:00:39 UTC (rev 153171)
+++ trunk/Source/_javascript_Core/ftl/FTLState.h 2013-07-25 04:00:41 UTC (rev 153172)
@@ -53,7 +53,6 @@
LValue function;
RefPtr<JITCode> jitCode;
Vector<OSRExitCompilationInfo> osrExit;
- LLVMExecutionEngineRef engine;
GeneratedFunction generatedFunction;
JITFinalizer* finalizer;