[vmkit-commits] [vmkit] r118780 - in /vmkit/branches/precise: include/j3/J3Intrinsics.h lib/J3/Compiler/J3Intrinsics.cpp lib/J3/Compiler/JavaJIT.cpp lib/J3/Compiler/JavaJIT.h lib/J3/LLVMRuntime/runtime-default.ll lib/J3/VMCore/JavaRuntimeJIT.cpp
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Wed Nov 10 23:29:23 PST 2010
Author: geoffray
Date: Thu Nov 11 01:29:23 2010
New Revision: 118780
URL: http://llvm.org/viewvc/llvm-project?rev=118780&view=rev
Log:
Fix interface calls, due to a bogus getTarget. Also add a debugging j3ResolveInterface runtime method. I should also test the performance of the runtime method compared to the inlined code.
Modified:
vmkit/branches/precise/include/j3/J3Intrinsics.h
vmkit/branches/precise/lib/J3/Compiler/J3Intrinsics.cpp
vmkit/branches/precise/lib/J3/Compiler/JavaJIT.cpp
vmkit/branches/precise/lib/J3/Compiler/JavaJIT.h
vmkit/branches/precise/lib/J3/LLVMRuntime/runtime-default.ll
vmkit/branches/precise/lib/J3/VMCore/JavaRuntimeJIT.cpp
Modified: vmkit/branches/precise/include/j3/J3Intrinsics.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/precise/include/j3/J3Intrinsics.h?rev=118780&r1=118779&r2=118780&view=diff
==============================================================================
--- vmkit/branches/precise/include/j3/J3Intrinsics.h (original)
+++ vmkit/branches/precise/include/j3/J3Intrinsics.h Thu Nov 11 01:29:23 2010
@@ -66,6 +66,7 @@
llvm::Function* ResolveVirtualStubFunction;
llvm::Function* ResolveSpecialStubFunction;
llvm::Function* ResolveStaticStubFunction;
+ llvm::Function* ResolveInterfaceFunction;
#ifndef WITHOUT_VTABLE
llvm::Function* VirtualLookupFunction;
Modified: vmkit/branches/precise/lib/J3/Compiler/J3Intrinsics.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/precise/lib/J3/Compiler/J3Intrinsics.cpp?rev=118780&r1=118779&r2=118780&view=diff
==============================================================================
--- vmkit/branches/precise/lib/J3/Compiler/J3Intrinsics.cpp (original)
+++ vmkit/branches/precise/lib/J3/Compiler/J3Intrinsics.cpp Thu Nov 11 01:29:23 2010
@@ -195,6 +195,7 @@
ResolveVirtualStubFunction = module->getFunction("j3ResolveVirtualStub");
ResolveStaticStubFunction = module->getFunction("j3ResolveStaticStub");
ResolveSpecialStubFunction = module->getFunction("j3ResolveSpecialStub");
+ ResolveInterfaceFunction = module->getFunction("j3ResolveInterface");
NullPointerExceptionFunction =
module->getFunction("j3NullPointerException");
Modified: vmkit/branches/precise/lib/J3/Compiler/JavaJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/precise/lib/J3/Compiler/JavaJIT.cpp?rev=118780&r1=118779&r2=118780&view=diff
==============================================================================
--- vmkit/branches/precise/lib/J3/Compiler/JavaJIT.cpp (original)
+++ vmkit/branches/precise/lib/J3/Compiler/JavaJIT.cpp Thu Nov 11 01:29:23 2010
@@ -202,8 +202,7 @@
Args.push_back(TheCompiler->getNativeClass(compilingClass));
Args.push_back(ConstantInt::get(Type::getInt32Ty(*llvmContext), index));
Args.push_back(GV);
- Value* targetObject = getTarget(virtualType->param_end(),
- signature->nbArguments + 1);
+ Value* targetObject = getTarget(signature);
Args.push_back(new LoadInst(
targetObject, "", TheCompiler->useCooperativeGC(), currentBlock));
load = invoke(intrinsics->VirtualLookupFunction, Args, "", currentBlock);
@@ -1472,8 +1471,16 @@
}
}
-Value* JavaJIT::getTarget(FunctionType::param_iterator it, uint32 nb) {
- return objectStack[currentStackIndex - nb];
+Value* JavaJIT::getTarget(Signdef* signature) {
+ int offset = 0;
+ Typedef* const* arguments = signature->getArgumentsType();
+ for (uint32 i = 0; i < signature->nbArguments; i++) {
+ if (arguments[i]->isDouble() || arguments[i]->isLong()) {
+ offset++;
+ }
+ offset++;
+ }
+ return objectStack[currentStackIndex - 1 - offset];
}
Instruction* JavaJIT::lowerMathOps(const UTF8* name,
@@ -2193,8 +2200,6 @@
const llvm::PointerType* virtualPtrType = LSI->getVirtualPtrType();
const llvm::Type* retType = virtualType->getReturnType();
- BasicBlock* endBlock = createBasicBlock("end interface invoke");
- PHINode * node = PHINode::Create(virtualPtrType, "", endBlock);
CommonClass* cl = 0;
JavaMethod* meth = 0;
@@ -2208,11 +2213,16 @@
intrinsics->JavaMethodType, 0, true);
}
- Value* targetObject = getTarget(virtualType->param_end(),
- signature->nbArguments + 1);
+ uint32_t tableIndex = InterfaceMethodTable::getIndex(name, signature->keyName);
+ Constant* Index = ConstantInt::get(Type::getInt32Ty(*llvmContext),
+ tableIndex);
+ Value* targetObject = getTarget(signature);
targetObject = new LoadInst(
targetObject, "", TheCompiler->useCooperativeGC(), currentBlock);
JITVerifyNull(targetObject);
+#if 1
+ BasicBlock* endBlock = createBasicBlock("end interface invoke");
+ PHINode * node = PHINode::Create(virtualPtrType, "", endBlock);
BasicBlock* label_bb = createBasicBlock("bb");
BasicBlock* label_bb4 = createBasicBlock("bb4");
@@ -2225,9 +2235,6 @@
Value* IMT = CallInst::Create(intrinsics->GetIMTFunction, VT, "",
currentBlock);
- uint32_t tableIndex = InterfaceMethodTable::getIndex(name, signature->keyName);
- Constant* Index = ConstantInt::get(Type::getInt32Ty(*llvmContext),
- tableIndex);
Value* indices[2] = { intrinsics->constantZero, Index };
Instruction* ptr_18 = GetElementPtrInst::Create(IMT, indices, indices + 2, "",
@@ -2308,10 +2315,17 @@
ptr_table_0_lcssa->addIncoming(ptr_37, currentBlock);
currentBlock = endBlock;
+#else
+ Value* Args[3] = { targetObject, Meth, Index };
+ Value* node = CallInst::Create(
+ intrinsics->ResolveInterfaceFunction, Args, Args + 3, "", currentBlock);
+ node = new BitCastInst(node, virtualPtrType, "", currentBlock);
+#endif
std::vector<Value*> args; // size = [signature->nbIn + 3];
FunctionType::param_iterator it = virtualType->param_end();
makeArgs(it, index, args, signature->nbArguments + 1);
+ JITVerifyNull(args[0]);
Value* ret = invoke(node, args, "", currentBlock);
if (retType != Type::getVoidTy(*llvmContext)) {
if (ret->getType() == intrinsics->JavaObjectType) {
Modified: vmkit/branches/precise/lib/J3/Compiler/JavaJIT.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/precise/lib/J3/Compiler/JavaJIT.h?rev=118780&r1=118779&r2=118780&view=diff
==============================================================================
--- vmkit/branches/precise/lib/J3/Compiler/JavaJIT.h (original)
+++ vmkit/branches/precise/lib/J3/Compiler/JavaJIT.h Thu Nov 11 01:29:23 2010
@@ -443,7 +443,7 @@
uint32 index, std::vector<llvm::Value*>& result, uint32 nb);
/// getTarget - Get the target object for invocation.
- llvm::Value* getTarget(llvm::FunctionType::param_iterator it, uint32 nb);
+ llvm::Value* getTarget(Signdef* signature);
/// invokeVirtual - Invoke a Java virtual method.
void invokeVirtual(uint16 index);
Modified: vmkit/branches/precise/lib/J3/LLVMRuntime/runtime-default.ll
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/precise/lib/J3/LLVMRuntime/runtime-default.ll?rev=118780&r1=118779&r2=118780&view=diff
==============================================================================
--- vmkit/branches/precise/lib/J3/LLVMRuntime/runtime-default.ll (original)
+++ vmkit/branches/precise/lib/J3/LLVMRuntime/runtime-default.ll Thu Nov 11 01:29:23 2010
@@ -192,6 +192,7 @@
declare i8* @j3ResolveVirtualStub(%JavaObject*)
declare i8* @j3ResolveSpecialStub()
declare i8* @j3ResolveStaticStub()
+declare i8* @j3ResolveInterface(%JavaObject*, %JavaMethod*, i32)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Exception methods ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Modified: vmkit/branches/precise/lib/J3/VMCore/JavaRuntimeJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/precise/lib/J3/VMCore/JavaRuntimeJIT.cpp?rev=118780&r1=118779&r2=118780&view=diff
==============================================================================
--- vmkit/branches/precise/lib/J3/VMCore/JavaRuntimeJIT.cpp (original)
+++ vmkit/branches/precise/lib/J3/VMCore/JavaRuntimeJIT.cpp Thu Nov 11 01:29:23 2010
@@ -648,8 +648,7 @@
uint32_t index = InterfaceMethodTable::getIndex(Virt->name, Virt->type);
if ((IMT->contents[index] & 1) == 0) {
IMT->contents[index] = (uintptr_t)result;
- } else {
-
+ } else {
JavaMethod* Imeth =
ctpCl->asClass()->lookupInterfaceMethodDontThrow(utf8, sign->keyName);
assert(Imeth && "Method not in hierarchy?");
@@ -746,6 +745,23 @@
return result;
}
+// Does not throw an exception.
+extern "C" void* j3ResolveInterface(JavaObject* obj, JavaMethod* meth, uint32_t index) {
+ uintptr_t result = NULL;
+ InterfaceMethodTable* IMT = JavaObject::getClass(obj)->virtualVT->IMT;
+ assert(JavaObject::instanceOf(obj, meth->classDef));
+ if ((IMT->contents[index] & 1) == 0) {
+ result = IMT->contents[index];
+ } else {
+ uintptr_t* table = (uintptr_t*)(IMT->contents[index] & ~1);
+ uint32 i = 0;
+ while (table[i] != (uintptr_t)meth) { i += 2; }
+ result = table[i + 1];
+ }
+ assert((result != NULL) && "Bad IMT");
+ return (void*)result;
+}
+
extern "C" void j3PrintMethodStart(JavaMethod* meth) {
fprintf(stderr, "[%p] executing %s.%s\n", (void*)mvm::Thread::get(),
UTF8Buffer(meth->classDef->name).cString(),
More information about the vmkit-commits
mailing list