[llvm-commits] [vmkit] r50146 - in /vmkit/trunk/lib/JnJVM/VMCore: JavaConstantPool.cpp JavaJIT.cpp JavaJIT.h JavaJITInitialise.cpp JavaJITOpcodes.cpp JavaMetaJIT.cpp JavaRuntimeJIT.cpp Jnjvm.cpp JnjvmModuleProvider.cpp
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Wed Apr 23 01:19:08 PDT 2008
Author: geoffray
Date: Wed Apr 23 03:19:08 2008
New Revision: 50146
URL: http://llvm.org/viewvc/llvm-project?rev=50146&view=rev
Log:
Use C++-like vtables. One can disable it with -DWITHOUT_VTABLE.
Modified:
vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.cpp
vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp
vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.h
vmkit/trunk/lib/JnJVM/VMCore/JavaJITInitialise.cpp
vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp
vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp
vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp
vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp
vmkit/trunk/lib/JnJVM/VMCore/JnjvmModuleProvider.cpp
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.cpp?rev=50146&r1=50145&r2=50146&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.cpp Wed Apr 23 03:19:08 2008
@@ -411,9 +411,6 @@
meth = cl->lookupMethodDontThrow(utf8, sign->keyName, isStatic(access), false);
if (meth) { // don't throw if no meth, the exception will be thrown just in time
if (meth->llvmFunction) {
- if (meth->llvmFunction->hasNotBeenReadFromBitcode()) {
- meth->classDef->isolate->functionDefs->hash(meth->llvmFunction, meth);
- }
ctpRes[index] = (void*)meth->llvmFunction;
return (llvm::Function*)ctpRes[index];
}
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp?rev=50146&r1=50145&r2=50146&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp Wed Apr 23 03:19:08 2008
@@ -99,6 +99,94 @@
return stack.size();
}
+void JavaJIT::invokeVirtual(uint16 index) {
+
+ JavaCtpInfo* ctpInfo = compilingClass->ctpInfo;
+ CommonClass* cl = 0;
+ JavaMethod* meth = 0;
+ ctpInfo->infoOfMethod(index, ACC_VIRTUAL, cl, meth);
+
+ if ((cl && isFinal(cl->access)) ||
+ (meth && (isFinal(meth->access) || isPrivate(meth->access))))
+ return invokeSpecial(index);
+
+#ifndef WITHOUT_VTABLE
+ Constant* zero = mvm::jit::constantZero;
+ Signdef* signature = ctpInfo->infoOfInterfaceOrVirtualMethod(index);
+ std::vector<Value*> args; // size = [signature->nbIn + 3];
+
+ FunctionType::param_iterator it = signature->virtualType->param_end();
+ makeArgs(it, index, args, signature->nbIn + 1);
+
+ JITVerifyNull(args[0]);
+
+ std::vector<Value*> indexes; //[3];
+ indexes.push_back(zero);
+ indexes.push_back(zero);
+ Value* VTPtr = GetElementPtrInst::Create(args[0], indexes.begin(),
+ indexes.end(), "", currentBlock);
+
+ Value* VT = new LoadInst(VTPtr, "", currentBlock);
+ std::vector<Value*> indexes2; //[3];
+ if (meth) {
+ indexes2.push_back(meth->offset);
+ } else {
+ compilingClass->isolate->protectModule->lock();
+ GlobalVariable* gv =
+ new GlobalVariable(Type::Int32Ty, false, GlobalValue::ExternalLinkage,
+ zero, "", compilingClass->isolate->module);
+ compilingClass->isolate->protectModule->unlock();
+
+ // set is volatile
+ Value* val = new LoadInst(gv, "", true, currentBlock);
+ Value * cmp = new ICmpInst(ICmpInst::ICMP_NE, val, zero, "", currentBlock);
+ BasicBlock* ifTrue = createBasicBlock("true vtable");
+ BasicBlock* ifFalse = createBasicBlock("false vtable");
+ BasicBlock* endBlock = createBasicBlock("end vtable");
+ PHINode * node = llvm::PHINode::Create(Type::Int32Ty, "", endBlock);
+ llvm::BranchInst::Create(ifTrue, ifFalse, cmp, currentBlock);
+
+ currentBlock = ifTrue;
+ node->addIncoming(val, currentBlock);
+ llvm::BranchInst::Create(endBlock, currentBlock);
+
+ currentBlock = ifFalse;
+ std::vector<Value*> Args;
+ Args.push_back(args[0]);
+ Module* M = compilingClass->isolate->module;
+ Args.push_back(new LoadInst(compilingClass->llvmVar(M), "", currentBlock));
+ mvm::jit::protectConstants();//->lock();
+ Constant* CI = ConstantInt::get(Type::Int32Ty, index);
+ Args.push_back(CI);
+ mvm::jit::unprotectConstants();//->unlock();
+ Args.push_back(gv);
+ val = invoke(vtableLookupLLVM, Args, "", currentBlock);
+ node->addIncoming(val, currentBlock);
+ llvm::BranchInst::Create(endBlock, currentBlock);
+
+ currentBlock = endBlock;
+ indexes2.push_back(node);
+ }
+
+ Value* FuncPtr = GetElementPtrInst::Create(VT, indexes2.begin(),
+ indexes2.end(), "",
+ currentBlock);
+
+ Value* Func = new LoadInst(FuncPtr, "", currentBlock);
+ Func = new BitCastInst(Func, signature->virtualTypePtr, "", currentBlock);
+ Value* val = invoke(Func, args, "", currentBlock);
+ const llvm::Type* retType = signature->virtualType->getReturnType();
+ if (retType != Type::VoidTy) {
+ push(val, signature->ret->funcs);
+ if (retType == Type::DoubleTy || retType == Type::Int64Ty) {
+ push(mvm::jit::constantZero, AssessorDesc::dInt);
+ }
+ }
+#else
+ return invokeInterfaceOrVirtual(index);
+#endif
+}
+
std::pair<llvm::Value*, const AssessorDesc*> JavaJIT::popPair() {
std::pair<Value*, const AssessorDesc*> ret = stack.back();
stack.pop_back();
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.h?rev=50146&r1=50145&r2=50146&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.h Wed Apr 23 03:19:08 2008
@@ -176,6 +176,7 @@
// methods invoke
void makeArgs(llvm::FunctionType::param_iterator it,
uint32 index, std::vector<llvm::Value*>& result, uint32 nb);
+ void invokeVirtual(uint16 index);
void invokeInterfaceOrVirtual(uint16 index);
void invokeSpecial(uint16 index);
void invokeStatic(uint16 index);
@@ -255,6 +256,9 @@
#endif
static llvm::Function* initialiseObjectLLVM;
static llvm::Function* newLookupLLVM;
+#ifndef WITHOUT_VTABLE
+ static llvm::Function* vtableLookupLLVM;
+#endif
static llvm::Function* instanceOfLLVM;
static llvm::Function* aquireObjectLLVM;
static llvm::Function* releaseObjectLLVM;
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaJITInitialise.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaJITInitialise.cpp?rev=50146&r1=50145&r2=50146&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaJITInitialise.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaJITInitialise.cpp Wed Apr 23 03:19:08 2008
@@ -71,7 +71,8 @@
const llvm::Type* Pty = mvm::jit::ptrType;
std::vector<const llvm::Type*> objectFields;
- objectFields.push_back(Pty); // VT
+ objectFields.push_back(
+ PointerType::getUnqual(PointerType::getUnqual(Type::Int32Ty))); // VT
objectFields.push_back(Pty); // Class
objectFields.push_back(Pty); // Lock
JavaObject::llvmType =
@@ -345,6 +346,21 @@
"newLookup",
module);
}
+
+#ifndef WITHOUT_VTABLE
+ // Create vtableLookupLLVM
+ {
+ std::vector<const Type*> args;
+ args.push_back(JavaObject::llvmType); // obj
+ args.push_back(mvm::jit::ptrType); // cl
+ args.push_back(Type::Int32Ty); // index
+ args.push_back(PointerType::getUnqual(Type::Int32Ty)); // vtable index
+ const FunctionType* type = FunctionType::get(Type::Int32Ty, args, false);
+
+ vtableLookupLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
+ "vtableLookup", module);
+ }
+#endif
// Create fieldLookupLLVM
{
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp?rev=50146&r1=50145&r2=50146&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp Wed Apr 23 03:19:08 2008
@@ -1724,14 +1724,7 @@
case INVOKEVIRTUAL : {
uint16 index = readU2(bytecodes, i);
- JavaCtpInfo* ctpInfo = compilingClass->ctpInfo;
- CommonClass* cl = 0;
- JavaMethod* meth = 0;
- ctpInfo->infoOfMethod(index, ACC_VIRTUAL, cl, meth);
- if ((cl && isFinal(cl->access)) || (meth && isFinal(meth->access)))
- invokeSpecial(index);
- else
- invokeInterfaceOrVirtual(index);
+ invokeVirtual(index);
break;
}
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp?rev=50146&r1=50145&r2=50146&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp Wed Apr 23 03:19:08 2008
@@ -171,12 +171,14 @@
va_end(ap);
}
+#ifndef WITHOUT_VTABLE
VirtualTable* allocateVT(Class* cl, std::vector<JavaMethod*>::iterator meths) {
if (meths == cl->virtualMethods.end()) {
uint64 size = cl->virtualTableSize;
VirtualTable* VT = (VirtualTable*)malloc(size * sizeof(void*));
if (cl->super) {
- memcpy(VT, cl->super->VT, cl->super->virtualTableSize * sizeof(void*));
+ Class* super = (Class*)cl->super;
+ memcpy(VT, super->virtualVT, cl->super->virtualTableSize * sizeof(void*));
} else {
memcpy(VT, JavaObject::VT, VT_SIZE);
}
@@ -203,18 +205,22 @@
return VT;
}
}
-
+#endif
VirtualTable* JavaJIT::makeVT(Class* cl, bool stat) {
VirtualTable* res = 0;
+#ifndef WITHOUT_VTABLE
if (stat) {
+#endif
res = (VirtualTable*)malloc(VT_SIZE);
memcpy(res, JavaObject::VT, VT_SIZE);
+#ifndef WITHOUT_VTABLE
} else {
res = allocateVT(cl, cl->virtualMethods.begin());
}
+#endif
#ifdef WITH_TRACER
const Type* type = stat ? cl->staticType : cl->virtualType;
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp?rev=50146&r1=50145&r2=50146&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp Wed Apr 23 03:19:08 2008
@@ -41,6 +41,9 @@
llvm::Function* JavaJIT::javaObjectTracerLLVM = 0;
llvm::Function* JavaJIT::virtualLookupLLVM = 0;
llvm::Function* JavaJIT::fieldLookupLLVM = 0;
+#ifndef WITHOUT_VTABLE
+llvm::Function* JavaJIT::vtableLookupLLVM = 0;
+#endif
llvm::Function* JavaJIT::UTF8AconsLLVM = 0;
llvm::Function* JavaJIT::Int8AconsLLVM = 0;
llvm::Function* JavaJIT::Int32AconsLLVM = 0;
@@ -242,6 +245,27 @@
return cl;
}
+#ifndef WITHOUT_VTABLE
+extern "C" uint32 vtableLookup(JavaObject* obj, Class* caller, uint32 index,
+ uint32* offset) {
+ CommonClass* cl = 0;
+ const UTF8* utf8 = 0;
+ Signdef* sign = 0;
+
+ caller->ctpInfo->resolveInterfaceOrMethod(index, cl, utf8, sign);
+ JavaMethod* dmeth = cl->lookupMethodDontThrow(utf8, sign->keyName, false,
+ true);
+ if (!dmeth) {
+ // Arg, it should have been an invoke interface.... Perform the lookup
+ // on the object class and do not update offset.
+ dmeth = obj->classOf->lookupMethod(utf8, sign->keyName, false, true);
+ return (uint32)(dmeth->offset->getZExtValue());
+ }
+ *offset = (uint32)(dmeth->offset->getZExtValue());
+ return *offset;
+}
+#endif
+
#ifdef MULTIPLE_VM
extern "C" void initialisationCheck(CommonClass* cl) {
cl->isolate->initialiseClass(cl);
Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp?rev=50146&r1=50145&r2=50146&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Wed Apr 23 03:19:08 2008
@@ -176,7 +176,7 @@
if (super == 0) {
cl->depth = 0;
cl->display.push_back(cl);
- cl->virtualTableSize = VT_SIZE;
+ cl->virtualTableSize = VT_SIZE / sizeof(void*);
} else {
cl->super = loadName(super, classLoader, true, false, true);
int depth = cl->super->depth;
@@ -795,6 +795,7 @@
method->printString(),
method->classDef->isolate->module);
method->classDef->isolate->protectModule->unlock();
+ method->classDef->isolate->functionDefs->hash(method->llvmFunction, method);
return method;
}
Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmModuleProvider.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmModuleProvider.cpp?rev=50146&r1=50145&r2=50146&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmModuleProvider.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmModuleProvider.cpp Wed Apr 23 03:19:08 2008
@@ -22,7 +22,6 @@
using namespace llvm;
using namespace jnjvm;
-#include <iostream>
static JavaMethod* staticLookup(Class* caller, uint32 index) {
JavaCtpInfo* ctpInfo = caller->ctpInfo;
@@ -66,6 +65,12 @@
void* val = meth->compiledPtr();
if (F->isDeclaration())
mvm::jit::executionEngine->updateGlobalMapping(F, val);
+
+ if (meth->offset) {
+ uint64_t offset = meth->offset->getZExtValue();
+ ((void**)meth->classDef->virtualVT)[offset] = val;
+ }
+
return false;
}
More information about the llvm-commits
mailing list