[vmkit-commits] [vmkit] r104551 - in /vmkit/trunk: include/j3/ include/mvm/ lib/J3/Compiler/ lib/J3/VMCore/ lib/Mvm/Compiler/ lib/Mvm/Runtime/
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Mon May 24 13:47:31 PDT 2010
Author: geoffray
Date: Mon May 24 15:47:31 2010
New Revision: 104551
URL: http://llvm.org/viewvc/llvm-project?rev=104551&view=rev
Log:
Provide to each JavaJITModule an execution engine.
Modified:
vmkit/trunk/include/j3/JavaAOTCompiler.h
vmkit/trunk/include/j3/JavaJITCompiler.h
vmkit/trunk/include/j3/JavaLLVMCompiler.h
vmkit/trunk/include/j3/LLVMMaterializer.h
vmkit/trunk/include/mvm/JIT.h
vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp
vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp
vmkit/trunk/lib/J3/Compiler/JavaLLVMCompiler.cpp
vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp
vmkit/trunk/lib/J3/Compiler/LLVMMaterializer.cpp
vmkit/trunk/lib/J3/Compiler/LowerConstantCalls.cpp
vmkit/trunk/lib/J3/VMCore/JavaClass.cpp
vmkit/trunk/lib/J3/VMCore/JavaMetaJIT.cpp
vmkit/trunk/lib/J3/VMCore/JavaTypes.h
vmkit/trunk/lib/Mvm/Compiler/InlineMalloc.cpp
vmkit/trunk/lib/Mvm/Compiler/JIT.cpp
vmkit/trunk/lib/Mvm/Runtime/Object.cpp
Modified: vmkit/trunk/include/j3/JavaAOTCompiler.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/JavaAOTCompiler.h?rev=104551&r1=104550&r2=104551&view=diff
==============================================================================
--- vmkit/trunk/include/j3/JavaAOTCompiler.h (original)
+++ vmkit/trunk/include/j3/JavaAOTCompiler.h Mon May 24 15:47:31 2010
@@ -40,6 +40,11 @@
fprintf(stderr, "Can not materiale a function in AOT mode.");
abort();
}
+
+ virtual void* GenerateStub(llvm::Function* F) {
+ // Do nothing in case of AOT.
+ return NULL;
+ }
virtual llvm::Value* addCallback(Class* cl, uint16 index, Signdef* sign,
bool stat, llvm::BasicBlock* insert);
Modified: vmkit/trunk/include/j3/JavaJITCompiler.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/JavaJITCompiler.h?rev=104551&r1=104550&r2=104551&view=diff
==============================================================================
--- vmkit/trunk/include/j3/JavaJITCompiler.h (original)
+++ vmkit/trunk/include/j3/JavaJITCompiler.h Mon May 24 15:47:31 2010
@@ -10,20 +10,44 @@
#ifndef J3_JIT_COMPILER_H
#define J3_JIT_COMPILER_H
+#include "llvm/ExecutionEngine/ExecutionEngine.h"
+#include "llvm/ExecutionEngine/JITEventListener.h"
#include "j3/JavaLLVMCompiler.h"
namespace j3 {
+class JavaJITCompiler;
+
+class JavaJITListener : public llvm::JITEventListener {
+ JavaJITCompiler* TheCompiler;
+public:
+ JavaJITListener(JavaJITCompiler* Compiler) {
+ TheCompiler = Compiler;
+ }
+
+ virtual void NotifyFunctionEmitted(
+ const llvm::Function &F,
+ void *Code,
+ size_t Size,
+ const llvm::JITEventListener::EmittedFunctionDetails &Details);
+};
+
class JavaJITCompiler : public JavaLLVMCompiler {
public:
bool EmitFunctionName;
+ JavaJITListener listener;
+ llvm::ExecutionEngine* executionEngine;
+ llvm::GCStrategy* TheGCStrategy;
- JavaJITCompiler(const std::string &ModuleID);
+ JavaJITCompiler(const std::string &ModuleID, bool trusted = false);
+ ~JavaJITCompiler();
virtual bool isStaticCompiling() {
return false;
}
+
+ virtual void* GenerateStub(llvm::Function* F);
virtual bool emitFunctionName() {
return EmitFunctionName;
@@ -80,10 +104,10 @@
virtual uintptr_t getPointerOrStub(JavaMethod& meth, int side);
virtual JavaCompiler* Create(const std::string& ModuleID) {
- return new JavaJ3LazyJITCompiler(ModuleID);
+ return new JavaJ3LazyJITCompiler(ModuleID, false);
}
- JavaJ3LazyJITCompiler(const std::string& ModuleID);
+ JavaJ3LazyJITCompiler(const std::string& ModuleID, bool trusted);
};
} // end namespace j3
Modified: vmkit/trunk/include/j3/JavaLLVMCompiler.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/JavaLLVMCompiler.h?rev=104551&r1=104550&r2=104551&view=diff
==============================================================================
--- vmkit/trunk/include/j3/JavaLLVMCompiler.h (original)
+++ vmkit/trunk/include/j3/JavaLLVMCompiler.h Mon May 24 15:47:31 2010
@@ -49,8 +49,6 @@
llvm::DIFactory* DebugFactory;
J3Intrinsics JavaIntrinsics;
- void addJavaPasses(bool trusted = false);
-
private:
bool enabledException;
bool cooperativeGC;
@@ -58,8 +56,8 @@
virtual void makeVT(Class* cl) = 0;
virtual void makeIMT(Class* cl) = 0;
- std::map<llvm::Function*, JavaMethod*> functions;
- typedef std::map<llvm::Function*, JavaMethod*>::iterator function_iterator;
+ std::map<const llvm::Function*, JavaMethod*> functions;
+ typedef std::map<const llvm::Function*, JavaMethod*>::iterator function_iterator;
std::map<JavaMethod*, LLVMMethodInfo*> method_infos;
typedef std::map<JavaMethod*, LLVMMethodInfo*>::iterator method_info_iterator;
@@ -81,6 +79,8 @@
virtual bool isStaticCompiling() = 0;
virtual bool emitFunctionName() = 0;
+ virtual void* GenerateStub(llvm::Function* F) = 0;
+ void addJavaPasses(bool trusted);
llvm::DIFactory* getDebugFactory() {
return DebugFactory;
@@ -118,7 +118,7 @@
virtual ~JavaLLVMCompiler();
- JavaMethod* getJavaMethod(llvm::Function*);
+ JavaMethod* getJavaMethod(const llvm::Function&);
llvm::MDNode* GetDbgSubprogram(JavaMethod* meth);
void resolveVirtualClass(Class* cl);
Modified: vmkit/trunk/include/j3/LLVMMaterializer.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/LLVMMaterializer.h?rev=104551&r1=104550&r2=104551&view=diff
==============================================================================
--- vmkit/trunk/include/j3/LLVMMaterializer.h (original)
+++ vmkit/trunk/include/j3/LLVMMaterializer.h Mon May 24 15:47:31 2010
@@ -41,10 +41,10 @@
virtual uintptr_t getPointerOrStub(JavaMethod& meth, int side);
virtual JavaCompiler* Create(const std::string& ModuleID) {
- return new JavaLLVMLazyJITCompiler(ModuleID);
+ return new JavaLLVMLazyJITCompiler(ModuleID, false);
}
- JavaLLVMLazyJITCompiler(const std::string& ModuleID);
+ JavaLLVMLazyJITCompiler(const std::string& ModuleID, bool trusted);
virtual ~JavaLLVMLazyJITCompiler();
Modified: vmkit/trunk/include/mvm/JIT.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/JIT.h?rev=104551&r1=104550&r2=104551&view=diff
==============================================================================
--- vmkit/trunk/include/mvm/JIT.h (original)
+++ vmkit/trunk/include/mvm/JIT.h Mon May 24 15:47:31 2010
@@ -176,8 +176,10 @@
class MvmModule {
-public:
+private:
static llvm::ExecutionEngine* executionEngine;
+
+public:
static llvm::GCStrategy* TheGCStrategy;
static mvm::LockRecursive protectEngine;
static llvm::Module *globalModule;
@@ -209,6 +211,16 @@
JITMethodInfo(llvm::GCFunctionInfo* GFI) : GCInfo(GFI) {}
};
+class MvmJITMethodInfo : public JITMethodInfo {
+ const llvm::Function* Func;
+public:
+ virtual void print(void* ip, void* addr);
+ MvmJITMethodInfo(llvm::GCFunctionInfo* GFI, const llvm::Function* F) :
+ JITMethodInfo(GFI) {
+ Func = F;
+ MethodType = 0;
+ }
+};
} // end namespace mvm
Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=104551&r1=104550&r2=104551&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Mon May 24 15:47:31 2010
@@ -1629,7 +1629,6 @@
ObjectPrinter = Function::Create(FTy, GlobalValue::ExternalLinkage,
"printJavaObject", getLLVMModule());
- addJavaPasses();
}
void JavaAOTCompiler::printStats() {
@@ -1953,6 +1952,8 @@
}
extractFiles(bytes, M, bootstrapLoader, classes);
+ // Now that we know if we can trust this compiler, add the Java passes.
+ M->addJavaPasses(M->compileRT);
// First resolve everyone so that there can not be unknown references in
Modified: vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp?rev=104551&r1=104550&r2=104551&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp Mon May 24 15:47:31 2010
@@ -17,7 +17,6 @@
#include "llvm/CodeGen/GCStrategy.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
-#include "llvm/ExecutionEngine/JITEventListener.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/Debug.h"
@@ -70,82 +69,75 @@
}
-class JavaJITListener : public llvm::JITEventListener {
- JavaMethod* currentCompiledMethod;
- llvm::Function* currentCompiledFunction;
-public:
- virtual void NotifyFunctionEmitted(const Function &F,
+void JavaJITListener::NotifyFunctionEmitted(const Function &F,
void *Code, size_t Size,
const EmittedFunctionDetails &Details) {
- if (currentCompiledMethod && currentCompiledFunction == &F) {
- Jnjvm* vm = JavaThread::get()->getJVM();
- mvm::BumpPtrAllocator& Alloc =
- currentCompiledMethod->classDef->classLoader->allocator;
- llvm::GCFunctionInfo* GFI = 0;
- if (F.hasGC()) {
- GCStrategy::iterator I = mvm::MvmModule::TheGCStrategy->end();
- I--;
- // TODO: see why this is not true in a non- LLVM lazy mode.
- while (&(*I)->getFunction() != &F) {
- assert(I != mvm::MvmModule::TheGCStrategy->begin() && "No GC info");
- I--;
- }
- assert(&(*I)->getFunction() == &F &&
- "GC Info and method do not correspond");
- GFI = *I;
+
+ // The following could be changed to an assert when -load-bc supports
+ // the verifier.
+ if (F.getParent() != TheCompiler->getLLVMModule()) return;
+
+ Jnjvm* vm = JavaThread::get()->getJVM();
+ mvm::BumpPtrAllocator& Alloc = TheCompiler->allocator;
+ llvm::GCFunctionInfo* GFI = 0;
+
+ if (F.hasGC()) {
+ if (TheCompiler->TheGCStrategy == NULL) {
+ assert(mvm::MvmModule::TheGCStrategy != NULL && "No GC strategy");
+ TheCompiler->TheGCStrategy = mvm::MvmModule::TheGCStrategy;
+ mvm::MvmModule::TheGCStrategy = NULL;
+ }
+ GCStrategy::iterator I = TheCompiler->TheGCStrategy->end();
+ I--;
+ while (&(*I)->getFunction() != &F) {
+ // This happens when the compilation of a function was post-poned.
+ assert(I != TheCompiler->TheGCStrategy->begin() && "No GC info");
+ I--;
+ }
+ assert(&(*I)->getFunction() == &F &&
+ "GC Info and method do not correspond");
+ GFI = *I;
+ }
+
+ JavaMethod* meth = TheCompiler->getJavaMethod(F);
+ if (meth == NULL) {
+ // This is a stub.
+ mvm::MvmJITMethodInfo* MI = new(Alloc, "JITMethodInfo")
+ mvm::MvmJITMethodInfo(GFI, &F);
+ vm->RuntimeFunctions.addMethodInfo(MI, Code,
+ (void*)((uintptr_t)Code + Size));
+ } else {
+ JavaJITMethodInfo* MI = new(Alloc, "JavaJITMethodInfo")
+ JavaJITMethodInfo(GFI, meth);
+ vm->RuntimeFunctions.addMethodInfo(MI, Code,
+ (void*)((uintptr_t)Code + Size));
+ uint32 infoLength = Details.LineStarts.size();
+ meth->codeInfoLength = infoLength;
+ if (infoLength > 0) {
+ mvm::BumpPtrAllocator& JavaAlloc = meth->classDef->classLoader->allocator;
+ CodeLineInfo* infoTable =
+ new(JavaAlloc, "CodeLineInfo") CodeLineInfo[infoLength];
+ for (uint32 i = 0; i < infoLength; ++i) {
+ DebugLoc DL = Details.LineStarts[i].Loc;
+ uint32_t first = DL.getLine();
+ uint32_t second = DL.getCol();
+ assert(second == 0 && "Wrong column number");
+ infoTable[i].address = Details.LineStarts[i].Address;
+ infoTable[i].lineNumber = meth->codeInfo[first].lineNumber;
+ infoTable[i].bytecodeIndex = meth->codeInfo[first].bytecodeIndex;
+ infoTable[i].ctpIndex = meth->codeInfo[first].ctpIndex;
+ infoTable[i].bytecode = meth->codeInfo[first].bytecode;
}
- JavaJITMethodInfo* MI = new(Alloc, "JavaJITMethodInfo")
- JavaJITMethodInfo(GFI, currentCompiledMethod);
- vm->RuntimeFunctions.addMethodInfo(MI, Code,
- (void*)((uintptr_t)Code + Size));
- uint32 infoLength = Details.LineStarts.size();
- currentCompiledMethod->codeInfoLength = infoLength;
- if (infoLength) {
- CodeLineInfo* infoTable =
- new(Alloc, "CodeLineInfo") CodeLineInfo[infoLength];
- for (uint32 i = 0; i < infoLength; ++i) {
- DebugLoc DL = Details.LineStarts[i].Loc;
- uint32_t first = DL.getLine();
- uint32_t second = DL.getCol();
- assert(second == 0 && "Wrong column number");
- infoTable[i].address = Details.LineStarts[i].Address;
- infoTable[i].lineNumber =
- currentCompiledMethod->codeInfo[first].lineNumber;
- infoTable[i].bytecodeIndex =
- currentCompiledMethod->codeInfo[first].bytecodeIndex;
- infoTable[i].ctpIndex =
- currentCompiledMethod->codeInfo[first].ctpIndex;
- infoTable[i].bytecode =
- currentCompiledMethod->codeInfo[first].bytecode;
- }
- delete[] currentCompiledMethod->codeInfo;
- currentCompiledMethod->codeInfo = infoTable;
- } else {
- if (currentCompiledMethod->codeInfo) {
- delete[] currentCompiledMethod->codeInfo;
- }
+ delete[] meth->codeInfo;
+ meth->codeInfo = infoTable;
+ } else {
+ if (meth->codeInfo != NULL) {
+ delete[] meth->codeInfo;
+ meth->codeInfo = NULL;
}
}
}
-
- void setCurrentCompiledMethod(JavaMethod* meth, llvm::Function* func) {
- assert(currentCompiledMethod == NULL && "Recursive compilation detected");
- currentCompiledMethod = meth;
- currentCompiledFunction = func;
- }
-
- void clearCurrentCompiledMethod() {
- currentCompiledMethod = NULL;
- currentCompiledFunction = NULL;
- }
-
- JavaJITListener() {
- currentCompiledMethod = NULL;
- currentCompiledFunction = NULL;
- }
-};
-
-static JavaJITListener* JITListener = 0;
+}
Constant* JavaJITCompiler::getNativeClass(CommonClass* classDef) {
const llvm::Type* Ty = classDef->isClass() ? JavaIntrinsics.JavaClassType :
@@ -260,29 +252,32 @@
return ConstantExpr::getIntToPtr(CI, valPtrType);
}
-JavaJITCompiler::JavaJITCompiler(const std::string &ModuleID) :
- JavaLLVMCompiler(ModuleID) {
+JavaJITCompiler::JavaJITCompiler(const std::string &ModuleID, bool trusted) :
+ JavaLLVMCompiler(ModuleID), listener(this) {
#if DEBUG
EmitFunctionName = true;
#else
EmitFunctionName = false;
#endif
-
- mvm::MvmModule::protectEngine.lock();
- mvm::MvmModule::executionEngine->addModule(TheModule);
- mvm::MvmModule::protectEngine.unlock();
-
- // The first JIT Compiler initialises JITListener and is trusted wrt.
- // safe points.
- bool trusted = (JITListener == NULL);
+ // Protect IR for the GC.
+ mvm::MvmModule::protectIR();
+ executionEngine = ExecutionEngine::createJIT(TheModule, 0,
+ 0, llvm::CodeGenOpt::Default, false);
+ TheGCStrategy = mvm::MvmModule::TheGCStrategy;
+ mvm::MvmModule::TheGCStrategy = NULL;
+ mvm::MvmModule::unprotectIR();
+
+ executionEngine->RegisterJITEventListener(&listener);
+
addJavaPasses(trusted);
+}
- if (!JITListener) {
- JITListener = new JavaJITListener();
- mvm::MvmModule::executionEngine->RegisterJITEventListener(JITListener);
- }
+JavaJITCompiler::~JavaJITCompiler() {
+ executionEngine->removeModule(TheModule);
+ delete executionEngine;
+ // ~JavaLLVMCompiler will delete the module.
}
#ifdef SERVICE
@@ -413,19 +408,26 @@
Function* func = getMethodInfo(meth)->getMethod();
func->setName(name);
assert(ptr && "No value given");
- mvm::MvmModule::executionEngine->updateGlobalMapping(func, ptr);
+ executionEngine->updateGlobalMapping(func, ptr);
func->setLinkage(GlobalValue::ExternalLinkage);
}
void* JavaJITCompiler::materializeFunction(JavaMethod* meth) {
mvm::MvmModule::protectIR();
Function* func = parseFunction(meth);
- JITListener->setCurrentCompiledMethod(meth, func);
- void* res = mvm::MvmModule::executionEngine->getPointerToGlobal(func);
- JITListener->clearCurrentCompiledMethod();
+ void* res = executionEngine->getPointerToGlobal(func);
+ // Now that it's compiled, we don't need the IR anymore
func->deleteBody();
mvm::MvmModule::unprotectIR();
+ return res;
+}
+void* JavaJITCompiler::GenerateStub(llvm::Function* F) {
+ mvm::MvmModule::protectIR();
+ void* res = executionEngine->getPointerToGlobal(F);
+ // Now that it's compiled, we don't need the IR anymore
+ F->deleteBody();
+ mvm::MvmModule::unprotectIR();
return res;
}
@@ -494,8 +496,9 @@
return (meth == NULL || meth->code == NULL);
}
-JavaJ3LazyJITCompiler::JavaJ3LazyJITCompiler(const std::string& ModuleID)
- : JavaJITCompiler(ModuleID) {}
+JavaJ3LazyJITCompiler::JavaJ3LazyJITCompiler(const std::string& ModuleID,
+ bool trusted)
+ : JavaJITCompiler(ModuleID, trusted) {}
static llvm::cl::opt<bool> LLVMLazy("llvm-lazy",
@@ -503,9 +506,9 @@
cl::init(false));
JavaJITCompiler* JavaJITCompiler::CreateCompiler(const std::string& ModuleID) {
+ // This is called for the first compiler.
if (LLVMLazy) {
- mvm::MvmModule::executionEngine->DisableLazyCompilation(false);
- return new JavaLLVMLazyJITCompiler(ModuleID);
+ return new JavaLLVMLazyJITCompiler(ModuleID, true);
}
- return new JavaJ3LazyJITCompiler(ModuleID);
+ return new JavaJ3LazyJITCompiler(ModuleID, true);
}
Modified: vmkit/trunk/lib/J3/Compiler/JavaLLVMCompiler.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaLLVMCompiler.cpp?rev=104551&r1=104550&r2=104551&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaLLVMCompiler.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaLLVMCompiler.cpp Mon May 24 15:47:31 2010
@@ -79,9 +79,9 @@
return func;
}
-JavaMethod* JavaLLVMCompiler::getJavaMethod(llvm::Function* F) {
+JavaMethod* JavaLLVMCompiler::getJavaMethod(const llvm::Function& F) {
function_iterator E = functions.end();
- function_iterator I = functions.find(F);
+ function_iterator I = functions.find(&F);
if (I == E) return 0;
return I->second;
}
Modified: vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp?rev=104551&r1=104550&r2=104551&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp Mon May 24 15:47:31 2010
@@ -12,7 +12,6 @@
#include "llvm/Constants.h"
#include "llvm/Instructions.h"
#include "llvm/Module.h"
-#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/Support/MutexGuard.h"
#include "llvm/Target/TargetData.h"
@@ -137,7 +136,7 @@
Function* LLVMMethodInfo::getMethod() {
if (!methodFunction) {
JnjvmClassLoader* JCL = methodDef->classDef->classLoader;
- if (Compiler->emitFunctionName()) {
+ if (true) {//Compiler->emitFunctionName()) {
const UTF8* jniConsClName = methodDef->classDef->name;
const UTF8* jniConsName = methodDef->name;
const UTF8* jniConsType = methodDef->type;
@@ -173,12 +172,8 @@
}
Compiler->functions.insert(std::make_pair(methodFunction, methodDef));
- if (Compiler != JCL->getCompiler()) {
- if (mvm::MvmModule::executionEngine && methodDef->code) {
- methodFunction->setLinkage(GlobalValue::ExternalLinkage);
- mvm::MvmModule::executionEngine->updateGlobalMapping(methodFunction,
- methodDef->code);
- }
+ if (Compiler != JCL->getCompiler() && methodDef->code) {
+ Compiler->setMethod(methodDef, methodDef->code, methodFunction->getName().data());
}
}
return methodFunction;
@@ -656,12 +651,7 @@
mvm::MvmModule::protectIR();
if (!virtualBufFunction) {
virtualBufFunction = createFunctionCallBuf(true);
- if (!Compiler->isStaticCompiling()) {
- signature->setVirtualCallBuf((intptr_t)
- mvm::MvmModule::executionEngine->getPointerToGlobal(virtualBufFunction));
- // Now that it's compiled, we don't need the IR anymore
- virtualBufFunction->deleteBody();
- }
+ signature->setVirtualCallBuf(Compiler->GenerateStub(virtualBufFunction));
}
mvm::MvmModule::unprotectIR();
return virtualBufFunction;
@@ -673,12 +663,7 @@
mvm::MvmModule::protectIR();
if (!virtualAPFunction) {
virtualAPFunction = createFunctionCallAP(true);
- if (!Compiler->isStaticCompiling()) {
- signature->setVirtualCallAP((intptr_t)
- mvm::MvmModule::executionEngine->getPointerToGlobal(virtualAPFunction));
- // Now that it's compiled, we don't need the IR anymore
- virtualAPFunction->deleteBody();
- }
+ signature->setVirtualCallAP(Compiler->GenerateStub(virtualAPFunction));
}
mvm::MvmModule::unprotectIR();
return virtualAPFunction;
@@ -690,12 +675,7 @@
mvm::MvmModule::protectIR();
if (!staticBufFunction) {
staticBufFunction = createFunctionCallBuf(false);
- if (!Compiler->isStaticCompiling()) {
- signature->setStaticCallBuf((intptr_t)
- mvm::MvmModule::executionEngine->getPointerToGlobal(staticBufFunction));
- // Now that it's compiled, we don't need the IR anymore
- staticBufFunction->deleteBody();
- }
+ signature->setStaticCallBuf(Compiler->GenerateStub(staticBufFunction));
}
mvm::MvmModule::unprotectIR();
return staticBufFunction;
@@ -707,12 +687,7 @@
mvm::MvmModule::protectIR();
if (!staticAPFunction) {
staticAPFunction = createFunctionCallAP(false);
- if (!Compiler->isStaticCompiling()) {
- signature->setStaticCallAP((intptr_t)
- mvm::MvmModule::executionEngine->getPointerToGlobal(staticAPFunction));
- // Now that it's compiled, we don't need the IR anymore
- staticAPFunction->deleteBody();
- }
+ signature->setStaticCallAP(Compiler->GenerateStub(staticAPFunction));
}
mvm::MvmModule::unprotectIR();
return staticAPFunction;
@@ -724,12 +699,7 @@
mvm::MvmModule::protectIR();
if (!staticStubFunction) {
staticStubFunction = createFunctionStub(false, false);
- if (!Compiler->isStaticCompiling()) {
- signature->setStaticCallStub((intptr_t)
- mvm::MvmModule::executionEngine->getPointerToGlobal(staticStubFunction));
- // Now that it's compiled, we don't need the IR anymore
- staticStubFunction->deleteBody();
- }
+ signature->setStaticCallStub(Compiler->GenerateStub(staticStubFunction));
}
mvm::MvmModule::unprotectIR();
return staticStubFunction;
@@ -741,12 +711,7 @@
mvm::MvmModule::protectIR();
if (!specialStubFunction) {
specialStubFunction = createFunctionStub(true, false);
- if (!Compiler->isStaticCompiling()) {
- signature->setSpecialCallStub((intptr_t)
- mvm::MvmModule::executionEngine->getPointerToGlobal(specialStubFunction));
- // Now that it's compiled, we don't need the IR anymore
- specialStubFunction->deleteBody();
- }
+ signature->setSpecialCallStub(Compiler->GenerateStub(specialStubFunction));
}
mvm::MvmModule::unprotectIR();
return specialStubFunction;
@@ -758,12 +723,7 @@
mvm::MvmModule::protectIR();
if (!virtualStubFunction) {
virtualStubFunction = createFunctionStub(false, true);
- if (!Compiler->isStaticCompiling()) {
- signature->setVirtualCallStub((intptr_t)
- mvm::MvmModule::executionEngine->getPointerToGlobal(virtualStubFunction));
- // Now that it's compiled, we don't need the IR anymore
- virtualStubFunction->deleteBody();
- }
+ signature->setVirtualCallStub(Compiler->GenerateStub(virtualStubFunction));
}
mvm::MvmModule::unprotectIR();
return virtualStubFunction;
Modified: vmkit/trunk/lib/J3/Compiler/LLVMMaterializer.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/LLVMMaterializer.cpp?rev=104551&r1=104550&r2=104551&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/LLVMMaterializer.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/LLVMMaterializer.cpp Mon May 24 15:47:31 2010
@@ -27,9 +27,11 @@
using namespace j3;
-JavaLLVMLazyJITCompiler::JavaLLVMLazyJITCompiler(const std::string& ModuleID)
- : JavaJITCompiler(ModuleID) {
- TheMaterializer = new LLVMMaterializer(TheModule, this);
+JavaLLVMLazyJITCompiler::JavaLLVMLazyJITCompiler(const std::string& ModuleID,
+ bool trusted)
+ : JavaJITCompiler(ModuleID, trusted) {
+ TheMaterializer = new LLVMMaterializer(TheModule, this);
+ executionEngine->DisableLazyCompilation(false);
}
JavaLLVMLazyJITCompiler::~JavaLLVMLazyJITCompiler() {
@@ -39,7 +41,7 @@
void* JavaLLVMLazyJITCompiler::loadMethod(void* handle, const char* symbol) {
Function* F = mvm::MvmModule::globalModule->getFunction(symbol);
if (F) {
- void* res = mvm::MvmModule::executionEngine->getPointerToFunctionOrStub(F);
+ void* res = executionEngine->getPointerToFunctionOrStub(F);
return res;
}
@@ -48,10 +50,9 @@
uintptr_t JavaLLVMLazyJITCompiler::getPointerOrStub(JavaMethod& meth,
int side) {
- ExecutionEngine* EE = mvm::MvmModule::executionEngine;
LLVMMethodInfo* LMI = getMethodInfo(&meth);
Function* func = LMI->getMethod();
- return (uintptr_t)EE->getPointerToFunctionOrStub(func);
+ return (uintptr_t)executionEngine->getPointerToFunctionOrStub(func);
}
static JavaMethod* staticLookup(CallbackInfo& F) {
@@ -112,7 +113,7 @@
// Because we are materializing a function here, we must release the
// JIT lock and get the global vmkit lock to be thread-safe.
// This prevents jitting the function while someone else is doing it.
- mvm::MvmModule::executionEngine->lock.release();
+ Comp->executionEngine->lock.release();
mvm::MvmModule::protectIR();
// Don't use hasNotBeenReadFromBitcode: materializeFunction is called
@@ -126,7 +127,7 @@
return false;
}
- if (mvm::MvmModule::executionEngine->getPointerToGlobalIfAvailable(F)) {
+ if (Comp->executionEngine->getPointerToGlobalIfAvailable(F)) {
mvm::MvmModule::unprotectIR();
// TODO: Is this still valid?
// Reacquire and go back to the JIT function.
@@ -134,7 +135,7 @@
return false;
}
- JavaMethod* meth = Comp->getJavaMethod(F);
+ JavaMethod* meth = Comp->getJavaMethod(*F);
if (!meth) {
// It's a callback
@@ -167,7 +168,7 @@
// mvm::MvmModule::executionEngine->lock.acquire();
if (F->isDeclaration())
- mvm::MvmModule::executionEngine->updateGlobalMapping(F, val);
+ Comp->executionEngine->updateGlobalMapping(F, val);
return false;
}
Modified: vmkit/trunk/lib/J3/Compiler/LowerConstantCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/LowerConstantCalls.cpp?rev=104551&r1=104550&r2=104551&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/LowerConstantCalls.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/LowerConstantCalls.cpp Mon May 24 15:47:31 2010
@@ -126,7 +126,7 @@
LLVMContext* Context = &F.getContext();
bool Changed = false;
J3Intrinsics* intrinsics = TheCompiler->getIntrinsics();
- JavaMethod* meth = TheCompiler->getJavaMethod(&F);
+ JavaMethod* meth = TheCompiler->getJavaMethod(F);
assert(meth && "Method not registered");
for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; BI++) {
BasicBlock *Cur = BI;
Modified: vmkit/trunk/lib/J3/VMCore/JavaClass.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaClass.cpp?rev=104551&r1=104550&r2=104551&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaClass.cpp (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaClass.cpp Mon May 24 15:47:31 2010
@@ -1811,9 +1811,8 @@
}
uint16 JavaMethod::lookupLineNumber(uintptr_t ip) {
- for(uint16 i = 0; i < codeInfoLength; ++i) {
+ for(uint16 i = 1; i < codeInfoLength; ++i) {
if (codeInfo[i].address > ip) {
- assert(i > 0 && "Wrong ip address for method");
return codeInfo[i - 1].lineNumber;
}
}
@@ -1822,9 +1821,8 @@
}
uint16 JavaMethod::lookupCtpIndex(uintptr_t ip) {
- for(uint16 i = 0; i < codeInfoLength; ++i) {
+ for(uint16 i = 1; i < codeInfoLength; ++i) {
if (codeInfo[i].address > ip) {
- assert(i > 0 && "Wrong ip address for method");
return codeInfo[i - 1].ctpIndex;
}
}
Modified: vmkit/trunk/lib/J3/VMCore/JavaMetaJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaMetaJIT.cpp?rev=104551&r1=104550&r2=104551&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaMetaJIT.cpp (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaMetaJIT.cpp Mon May 24 15:47:31 2010
@@ -178,6 +178,7 @@
meth = objCl->lookupMethodDontThrow(name, type, false, true, &cl); \
} \
assert(meth && "No method found"); \
+ assert(objCl->isAssignableFrom(meth->classDef) && "Wrong type"); \
void* func = meth->compiledPtr(); \
FUNC_TYPE_VIRTUAL_BUF call = (FUNC_TYPE_VIRTUAL_BUF)sign->getVirtualCallBuf(); \
JavaThread* th = JavaThread::get(); \
Modified: vmkit/trunk/lib/J3/VMCore/JavaTypes.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaTypes.h?rev=104551&r1=104550&r2=104551&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaTypes.h (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaTypes.h Mon May 24 15:47:31 2010
@@ -372,32 +372,32 @@
return _staticCallStub;
}
- void setStaticCallBuf(intptr_t code) {
- _staticCallBuf = code;
+ void setStaticCallBuf(void* code) {
+ _staticCallBuf = (intptr_t)code;
}
- void setVirtualCallBuf(intptr_t code) {
- _virtualCallBuf = code;
+ void setVirtualCallBuf(void* code) {
+ _virtualCallBuf = (intptr_t)code;
}
- void setStaticCallAP(intptr_t code) {
- _staticCallAP = code;
+ void setStaticCallAP(void* code) {
+ _staticCallAP = (intptr_t)code;
}
- void setVirtualCallAP(intptr_t code) {
- _virtualCallAP = code;
+ void setVirtualCallAP(void* code) {
+ _virtualCallAP = (intptr_t)code;
}
- void setVirtualCallStub(intptr_t code) {
- _virtualCallStub = code;
+ void setVirtualCallStub(void* code) {
+ _virtualCallStub = (intptr_t)code;
}
- void setSpecialCallStub(intptr_t code) {
- _specialCallStub = code;
+ void setSpecialCallStub(void* code) {
+ _specialCallStub = (intptr_t)code;
}
- void setStaticCallStub(intptr_t code) {
- _staticCallStub = code;
+ void setStaticCallStub(void* code) {
+ _staticCallStub = (intptr_t)code;
}
//===----------------------------------------------------------------------===//
Modified: vmkit/trunk/lib/Mvm/Compiler/InlineMalloc.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Compiler/InlineMalloc.cpp?rev=104551&r1=104550&r2=104551&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/Compiler/InlineMalloc.cpp (original)
+++ vmkit/trunk/lib/Mvm/Compiler/InlineMalloc.cpp Mon May 24 15:47:31 2010
@@ -52,8 +52,8 @@
CallSite Call = CallSite::get(I);
Instruction* CI = Call.getInstruction();
if (CI) {
- Function* F = Call.getCalledFunction();
- if (F == Malloc) {
+ Function* Temp = Call.getCalledFunction();
+ if (Temp == Malloc) {
if (dyn_cast<Constant>(Call.getArgument(0))) {
InlineFunctionInfo IFI(NULL, mvm::MvmModule::TheTargetData);
Changed |= InlineFunction(Call, IFI);
Modified: vmkit/trunk/lib/Mvm/Compiler/JIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Compiler/JIT.cpp?rev=104551&r1=104550&r2=104551&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/Compiler/JIT.cpp (original)
+++ vmkit/trunk/lib/Mvm/Compiler/JIT.cpp Mon May 24 15:47:31 2010
@@ -76,17 +76,6 @@
return LLVM_HOSTTRIPLE;
}
-class MvmJITMethodInfo : public JITMethodInfo {
- const llvm::Function* Func;
-public:
- virtual void print(void* ip, void* addr);
- MvmJITMethodInfo(llvm::GCFunctionInfo* GFI, const llvm::Function* F) :
- JITMethodInfo(GFI) {
- Func = F;
- MethodType = 0;
- }
-};
-
void MvmJITMethodInfo::print(void* ip, void* addr) {
fprintf(stderr, "; %p in %s LLVM method\n", ip, Func->getName().data());
}
@@ -96,26 +85,22 @@
virtual void NotifyFunctionEmitted(const Function &F,
void *Code, size_t Size,
const EmittedFunctionDetails &Details) {
- // Functions compiled in the global module are MMTk functions and the
- // interfaces with VMKit.
- if (F.getParent() == MvmModule::globalModule) {
- llvm::GCFunctionInfo* GFI = 0;
- // We know the last GC info is for this method.
- if (F.hasGC()) {
- // Only the interface functions have GC informations.
- GCStrategy::iterator I = mvm::MvmModule::TheGCStrategy->end();
- I--;
- DEBUG(errs() << (*I)->getFunction().getName() << '\n');
- DEBUG(errs() << F.getName() << '\n');
- assert(&(*I)->getFunction() == &F &&
- "GC Info and method do not correspond");
- GFI = *I;
- }
- MethodInfo* MI =
- new(*MvmModule::Allocator, "MvmJITMethodInfo") MvmJITMethodInfo(GFI, &F);
- VirtualMachine::SharedRuntimeFunctions.addMethodInfo(MI, Code,
- (void*)((uintptr_t)Code + Size));
+ assert(F.getParent() == MvmModule::globalModule);
+ llvm::GCFunctionInfo* GFI = 0;
+ // We know the last GC info is for this method.
+ if (F.hasGC()) {
+ GCStrategy::iterator I = mvm::MvmModule::TheGCStrategy->end();
+ I--;
+ DEBUG(errs() << (*I)->getFunction().getName() << '\n');
+ DEBUG(errs() << F.getName() << '\n');
+ assert(&(*I)->getFunction() == &F &&
+ "GC Info and method do not correspond");
+ GFI = *I;
}
+ MethodInfo* MI =
+ new(*MvmModule::Allocator, "MvmJITMethodInfo") MvmJITMethodInfo(GFI, &F);
+ VirtualMachine::SharedRuntimeFunctions.addMethodInfo(MI, Code,
+ (void*)((uintptr_t)Code + Size));
}
};
@@ -346,9 +331,7 @@
// Our implementation of materializeFunction requires that the lock is held
// by the caller. This is due to LLVM's JIT subsystem where the call to
// materializeFunction is guarded.
- if (executionEngine) executionEngine->lock.acquire();
pm->run(*func);
- if (executionEngine) executionEngine->lock.release();
}
static void addPass(FunctionPassManager *PM, Pass *P) {
@@ -463,15 +446,11 @@
// We protect the creation of IR with the executionEngine lock because
// codegen'ing a function may also create IR objects.
void MvmModule::protectIR() {
- if (executionEngine) {
- protectEngine.lock();
- }
+ protectEngine.lock();
}
void MvmModule::unprotectIR() {
- if (executionEngine) {
- protectEngine.unlock();
- }
+ protectEngine.unlock();
}
void JITMethodInfo::scan(void* TL, void* ip, void* addr) {
Modified: vmkit/trunk/lib/Mvm/Runtime/Object.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/Object.cpp?rev=104551&r1=104550&r2=104551&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/Runtime/Object.cpp (original)
+++ vmkit/trunk/lib/Mvm/Runtime/Object.cpp Mon May 24 15:47:31 2010
@@ -77,7 +77,8 @@
while (true) {
vm->FinalizationQueueLock.acquire();
if (vm->CurrentFinalizedIndex != 0) {
- res = vm->ToBeFinalized[--vm->CurrentFinalizedIndex];
+ res = vm->ToBeFinalized[vm->CurrentFinalizedIndex - 1];
+ --vm->CurrentFinalizedIndex;
}
vm->FinalizationQueueLock.release();
if (!res) break;
@@ -112,7 +113,8 @@
while (true) {
vm->ToEnqueueLock.acquire();
if (vm->ToEnqueueIndex != 0) {
- res = vm->ToEnqueue[--vm->ToEnqueueIndex];
+ res = vm->ToEnqueue[vm->ToEnqueueIndex - 1];
+ --vm->ToEnqueueIndex;
}
vm->ToEnqueueLock.release();
if (!res) break;
More information about the vmkit-commits
mailing list