[llvm-commits] [vmkit] r51860 - in /vmkit/trunk/lib/JnJVM/VMCore: JavaJITOpcodes.cpp JavaRuntimeJIT.cpp Jnjvm.cpp JnjvmModule.cpp JnjvmModule.h LowerConstantCalls.cpp
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Sun Jun 1 15:47:00 PDT 2008
Author: geoffray
Date: Sun Jun 1 17:47:00 2008
New Revision: 51860
URL: http://llvm.org/viewvc/llvm-project?rev=51860&view=rev
Log:
Inline runtime type checks after executing LLVM optimization passes.
Modified:
vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp
vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp
vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp
vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp
vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.h
vmkit/trunk/lib/JnJVM/VMCore/LowerConstantCalls.cpp
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp?rev=51860&r1=51859&r2=51860&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp Sun Jun 1 17:47:00 2008
@@ -1981,11 +1981,8 @@
args.begin(), args.end(),
"", currentBlock);
- cmp = new ICmpInst(ICmpInst::ICMP_EQ, call,
- mvm::jit::constantZero, "", currentBlock);
-
BasicBlock* ex = createBasicBlock("false checkcast");
- BranchInst::Create(ex, ifTrue, cmp, currentBlock);
+ BranchInst::Create(ifTrue, ex, call, currentBlock);
std::vector<Value*> exArgs;
exArgs.push_back(obj);
@@ -2020,8 +2017,10 @@
std::vector<Value*> args;
args.push_back(pop());
args.push_back(clVar);
- push(CallInst::Create(JnjvmModule::InstanceOfFunction, args.begin(),
- args.end(), "", currentBlock),
+ Value* val = CallInst::Create(JnjvmModule::InstanceOfFunction,
+ args.begin(), args.end(), "",
+ currentBlock);
+ push(new ZExtInst(val, Type::Int32Ty, "", currentBlock),
AssessorDesc::dInt);
break;
}
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp?rev=51860&r1=51859&r2=51860&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp Sun Jun 1 17:47:00 2008
@@ -312,10 +312,22 @@
}
#endif
-extern "C" bool JavaObjectInstanceOf(JavaObject* obj, CommonClass* cl) {
+extern "C" bool instanceOf(JavaObject* obj, CommonClass* cl) {
return obj->instanceOf(cl);
}
+extern "C" bool instantiationOfArray(CommonClass* cl1, ClassArray* cl2) {
+ return cl1->instantiationOfArray(cl2);
+}
+
+extern "C" bool implements(CommonClass* cl1, CommonClass* cl2) {
+ return cl1->implements(cl2);
+}
+
+extern "C" bool isAssignableFrom(CommonClass* cl1, CommonClass* cl2) {
+ return cl1->isAssignableFrom(cl2);
+}
+
extern "C" void* JavaThreadGetException() {
return JavaThread::getException();
}
Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp?rev=51860&r1=51859&r2=51860&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Sun Jun 1 17:47:00 2008
@@ -179,17 +179,17 @@
JavaObject* classLoader = cl->classLoader;
if (super == 0) {
cl->depth = 0;
- cl->display.push_back(cl);
+ cl->display = (CommonClass**)malloc(sizeof(CommonClass*));
+ cl->display[0] = cl;
cl->virtualTableSize = VT_SIZE / sizeof(void*);
} else {
cl->super = loadName(super, classLoader, true, false, true);
- int depth = cl->super->depth;
- cl->depth = depth + 1;
+ int depth = cl->super->depth + 1;
+ cl->depth = depth;
cl->virtualTableSize = cl->super->virtualTableSize;
- for (uint32 i = 0; i < cl->super->display.size(); ++i) {
- cl->display.push_back(cl->super->display[i]);
- }
- cl->display.push_back(cl);
+ cl->display = (CommonClass**)malloc((depth + 1) * sizeof(CommonClass*));
+ memcpy(cl->display, cl->super->display, depth * sizeof(CommonClass*));
+ cl->display[cl->depth] = cl;
}
for (int i = 0; i < nbI; i++)
Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp?rev=51860&r1=51859&r2=51860&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp Sun Jun 1 17:47:00 2008
@@ -54,6 +54,8 @@
llvm::GlobalVariable* JnjvmModule::ArrayObjectVirtualTableGV;
llvm::ConstantInt* JnjvmModule::OffsetObjectSizeInClassConstant;
llvm::ConstantInt* JnjvmModule::OffsetVTInClassConstant;
+llvm::ConstantInt* JnjvmModule::OffsetDepthInClassConstant;
+llvm::ConstantInt* JnjvmModule::OffsetDisplayInClassConstant;
const llvm::Type* JnjvmModule::JavaClassType;
const llvm::Type* JnjvmModule::VTType;
llvm::ConstantInt* JnjvmModule::JavaArrayElementsOffsetConstant;
@@ -90,6 +92,12 @@
llvm::Function* JnjvmModule::ForceInitialisationCheckFunction = 0;
llvm::Function* JnjvmModule::ClassLookupFunction = 0;
llvm::Function* JnjvmModule::InstanceOfFunction = 0;
+llvm::Function* JnjvmModule::IsAssignableFromFunction = 0;
+llvm::Function* JnjvmModule::ImplementsFunction = 0;
+llvm::Function* JnjvmModule::InstantiationOfArrayFunction = 0;
+llvm::Function* JnjvmModule::GetDepthFunction = 0;
+llvm::Function* JnjvmModule::GetDisplayFunction = 0;
+llvm::Function* JnjvmModule::GetClassInDisplayFunction = 0;
llvm::Function* JnjvmModule::AquireObjectFunction = 0;
llvm::Function* JnjvmModule::ReleaseObjectFunction = 0;
llvm::Function* JnjvmModule::MultiCallNewFunction = 0;
@@ -950,7 +958,13 @@
GetObjectSizeFromClassFunction = module->getFunction("getObjectSizeFromClass");
GetClassDelegateeFunction = module->getFunction("getClassDelegatee");
- InstanceOfFunction = module->getFunction("JavaObjectInstanceOf");
+ InstanceOfFunction = module->getFunction("instanceOf");
+ IsAssignableFromFunction = module->getFunction("isAssignableFrom");
+ ImplementsFunction = module->getFunction("implements");
+ InstantiationOfArrayFunction = module->getFunction("instantiationOfArray");
+ GetDepthFunction = module->getFunction("getDepth");
+ GetDisplayFunction = module->getFunction("getDisplay");
+ GetClassInDisplayFunction = module->getFunction("getClassInDisplay");
AquireObjectFunction = module->getFunction("JavaObjectAquire");
ReleaseObjectFunction = module->getFunction("JavaObjectRelease");
@@ -1037,13 +1051,16 @@
cons, "",
module);
- OffsetObjectSizeInClassConstant = mvm::jit::constantOne;
- OffsetVTInClassConstant = mvm::jit::constantTwo;
JavaArrayElementsOffsetConstant = mvm::jit::constantTwo;
JavaArraySizeOffsetConstant = mvm::jit::constantOne;
JavaObjectLockOffsetConstant = mvm::jit::constantTwo;
- JavaObjectClassOffsetConstant = mvm::jit::constantOne;
+ JavaObjectClassOffsetConstant = mvm::jit::constantOne;
+ OffsetObjectSizeInClassConstant = mvm::jit::constantOne;
+ OffsetVTInClassConstant = mvm::jit::constantTwo;
+ OffsetDisplayInClassConstant = mvm::jit::constantThree;
+ OffsetDepthInClassConstant = mvm::jit::constantFour;
+
LLVMAssessorInfo::initialise();
}
Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.h?rev=51860&r1=51859&r2=51860&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.h Sun Jun 1 17:47:00 2008
@@ -299,6 +299,12 @@
static llvm::Function* VirtualLookupFunction;
#endif
static llvm::Function* InstanceOfFunction;
+ static llvm::Function* IsAssignableFromFunction;
+ static llvm::Function* ImplementsFunction;
+ static llvm::Function* InstantiationOfArrayFunction;
+ static llvm::Function* GetDepthFunction;
+ static llvm::Function* GetClassInDisplayFunction;
+ static llvm::Function* GetDisplayFunction;
static llvm::Function* AquireObjectFunction;
static llvm::Function* ReleaseObjectFunction;
#ifdef SERVICE_VM
@@ -322,6 +328,8 @@
static llvm::Function* GetObjectSizeFromClassFunction;
static llvm::ConstantInt* OffsetObjectSizeInClassConstant;
static llvm::ConstantInt* OffsetVTInClassConstant;
+ static llvm::ConstantInt* OffsetDepthInClassConstant;
+ static llvm::ConstantInt* OffsetDisplayInClassConstant;
static llvm::Constant* JavaClassNullConstant;
Modified: vmkit/trunk/lib/JnJVM/VMCore/LowerConstantCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/LowerConstantCalls.cpp?rev=51860&r1=51859&r2=51860&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/LowerConstantCalls.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/LowerConstantCalls.cpp Sun Jun 1 17:47:00 2008
@@ -102,10 +102,131 @@
Value* Size = new LoadInst(SizePtr, "", CI);
CI->replaceAllUsesWith(Size);
CI->eraseFromParent();
- }
- else if (V == jnjvm::JnjvmModule::ForceInitialisationCheckFunction) {
+ } else if (V == jnjvm::JnjvmModule::ForceInitialisationCheckFunction) {
+ Changed = true;
+ CI->eraseFromParent();
+ } else if (V == jnjvm::JnjvmModule::GetDepthFunction) {
+ Changed = true;
+ Value* val = CI->getOperand(1);
+ std::vector<Value*> indexes;
+ indexes.push_back(mvm::jit::constantZero);
+ indexes.push_back(JnjvmModule::OffsetDepthInClassConstant);
+ Value* DepthPtr = GetElementPtrInst::Create(val, indexes.begin(),
+ indexes.end(), "", CI);
+ Value* Depth = new LoadInst(DepthPtr, "", CI);
+ CI->replaceAllUsesWith(Depth);
+ CI->eraseFromParent();
+ } else if (V == jnjvm::JnjvmModule::GetDisplayFunction) {
+ Changed = true;
+ Value* val = CI->getOperand(1);
+ std::vector<Value*> indexes;
+ indexes.push_back(mvm::jit::constantZero);
+ indexes.push_back(JnjvmModule::OffsetDisplayInClassConstant);
+ Value* DisplayPtr = GetElementPtrInst::Create(val, indexes.begin(),
+ indexes.end(), "", CI);
+ Value* Display = new LoadInst(DisplayPtr, "", CI);
+ CI->replaceAllUsesWith(Display);
+ CI->eraseFromParent();
+ } else if (V == jnjvm::JnjvmModule::GetClassInDisplayFunction) {
Changed = true;
+ Value* val = CI->getOperand(1);
+ Value* depth = CI->getOperand(2);
+ Value* ClassPtr = GetElementPtrInst::Create(val, depth, "", CI);
+ Value* Class = new LoadInst(ClassPtr, "", CI);
+ CI->replaceAllUsesWith(Class);
CI->eraseFromParent();
+ } else if (V == jnjvm::JnjvmModule::InstanceOfFunction) {
+ ConstantExpr* CE = dyn_cast<ConstantExpr>(CI->getOperand(2));
+ if (CE) {
+ ConstantInt* C = (ConstantInt*)CE->getOperand(0);
+ CommonClass* cl = (CommonClass*)C->getZExtValue();
+ Changed = true;
+ BasicBlock* NBB = II->getParent()->splitBasicBlock(II);
+ I->getParent()->getTerminator()->eraseFromParent();
+ Value* obj = CI->getOperand(1);
+ Instruction* cmp = new ICmpInst(ICmpInst::ICMP_EQ, obj,
+ JnjvmModule::JavaObjectNullConstant,
+ "", CI);
+ BasicBlock* ifTrue = BasicBlock::Create("", &F);
+ BasicBlock* ifFalse = BasicBlock::Create("", &F);
+ BranchInst::Create(ifTrue, ifFalse, cmp, CI);
+ PHINode* node = PHINode::Create(Type::Int1Ty, "", ifTrue);
+ node->addIncoming(ConstantInt::getFalse(), CI->getParent());
+ Value* objCl = CallInst::Create(JnjvmModule::GetClassFunction, obj,
+ "", ifFalse);
+
+ if (isInterface(cl->access)) {
+ std::vector<Value*> args;
+ args.push_back(objCl);
+ args.push_back(CE);
+ Value* res = CallInst::Create(JnjvmModule::ImplementsFunction,
+ args.begin(), args.end(), "",
+ ifFalse);
+ node->addIncoming(res, ifFalse);
+ BranchInst::Create(ifTrue, ifFalse);
+ } else {
+ cmp = new ICmpInst(ICmpInst::ICMP_EQ, objCl, CE, "", ifFalse);
+ BasicBlock* notEquals = BasicBlock::Create("", &F);
+ BranchInst::Create(ifTrue, notEquals, cmp, ifFalse);
+ node->addIncoming(ConstantInt::getTrue(), ifFalse);
+
+ if (cl->status < readed) {
+ std::vector<Value*> args;
+ args.push_back(objCl);
+ args.push_back(CE);
+ cmp = CallInst::Create(JnjvmModule::IsAssignableFromFunction,
+ args.begin(), args.end(), "", notEquals);
+ node->addIncoming(cmp, notEquals);
+ BranchInst::Create(ifTrue, notEquals);
+ } else if (cl->isArray) {
+ std::vector<Value*> args;
+ args.push_back(objCl);
+ args.push_back(CE);
+ Value* res =
+ CallInst::Create(JnjvmModule::InstantiationOfArrayFunction,
+ args.begin(), args.end(), "", notEquals);
+ node->addIncoming(res, notEquals);
+ BranchInst::Create(ifTrue, notEquals);
+ } else {
+ Value* depthCl;
+ if (cl->isResolved()) {
+ depthCl = ConstantInt::get(Type::Int32Ty, cl->depth);
+ } else {
+ depthCl = CallInst::Create(JnjvmModule::GetDepthFunction,
+ CE, "", notEquals);
+ }
+ Value* depthClObj = CallInst::Create(JnjvmModule::GetDepthFunction,
+ objCl, "", notEquals);
+ Value* cmp = new ICmpInst(ICmpInst::ICMP_ULE, depthCl, depthClObj, "",
+ notEquals);
+
+ BasicBlock* supDepth = BasicBlock::Create("superior depth", &F);
+
+ BranchInst::Create(supDepth, ifTrue, cmp, notEquals);
+ node->addIncoming(ConstantInt::getFalse(), notEquals);
+
+ Value* inDisplay =
+ CallInst::Create(JnjvmModule::GetDisplayFunction, objCl,
+ "", supDepth);
+
+ std::vector<Value*> args;
+ args.push_back(inDisplay);
+ args.push_back(depthCl);
+ Value* clInDisplay =
+ CallInst::Create(JnjvmModule::GetClassInDisplayFunction,
+ args.begin(), args.end(), "", supDepth);
+
+ cmp = new ICmpInst(ICmpInst::ICMP_EQ, clInDisplay, CE, "",
+ supDepth);
+ BranchInst::Create(ifTrue, supDepth);
+ node->addIncoming(cmp, supDepth);
+ }
+ }
+ CI->replaceAllUsesWith(node);
+ CI->eraseFromParent();
+ BranchInst::Create(NBB, ifTrue);
+ break;
+ }
}
#ifdef MULTIPLE_GC
else if (V == jnjvm::JnjvmModule::GetCollectorFunction) {
More information about the llvm-commits
mailing list