[vmkit-commits] [vmkit] r59913 - in /vmkit/trunk/lib/JnJVM: LLVMRuntime/runtime-default.ll LLVMRuntime/runtime-isolate.ll VMCore/JavaJITOpcodes.cpp VMCore/JavaRuntimeJIT.cpp VMCore/JnjvmModule.cpp VMCore/JnjvmModule.h VMCore/LowerConstantCalls.cpp
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Sun Nov 23 09:27:40 PST 2008
Author: geoffray
Date: Sun Nov 23 11:27:39 2008
New Revision: 59913
URL: http://llvm.org/viewvc/llvm-project?rev=59913&view=rev
Log:
Do not resolve and load a class referenced by ANEWARRAY until
the opcode is actually executed.
Modified:
vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll
vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-isolate.ll
vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp
vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.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/LLVMRuntime/runtime-default.ll
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll?rev=59913&r1=59912&r2=59913&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll (original)
+++ vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll Sun Nov 23 11:27:39 2008
@@ -164,6 +164,9 @@
;;; class.
declare %JavaObject* @getClassDelegatee(%JavaClass*) readnone
+;;; getArrayClass - Get the array user class of the user class.
+declare %JavaClass* @getArrayClass(%JavaClass*, %JavaClass**) readnone
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Exception methods ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Modified: vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-isolate.ll
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-isolate.ll?rev=59913&r1=59912&r2=59913&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-isolate.ll (original)
+++ vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-isolate.ll Sun Nov 23 11:27:39 2008
@@ -32,6 +32,3 @@
;;; getJnjvmArrayClass - Get the array user class of the index, for the given
;;; isolate.
declare %JavaClass* @getJnjvmArrayClass(%Jnjvm*, i32) readnone
-
-;;; getArrayClass - Get the array user class of the user class.
-declare %JavaClass* @getArrayClass(%JavaClass*) readnone
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp?rev=59913&r1=59912&r2=59913&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp Sun Nov 23 11:27:39 2008
@@ -1831,9 +1831,6 @@
case NEWARRAY :
case ANEWARRAY : {
-#ifndef ISOLATE_SHARING
- UserClassArray* dcl = 0;
-#endif
ConstantInt* sizeElement = 0;
Value* TheVT = 0;
Value* valCl = 0;
@@ -1844,7 +1841,9 @@
#ifndef ISOLATE_SHARING
JnjvmBootstrapLoader* loader =
compilingClass->classLoader->bootstrapLoader;
- dcl = loader->getArrayClass(id);
+ UserClassArray* dcl = loader->getArrayClass(id);
+ valCl = module->getNativeClass(dcl);
+ valCl = new LoadInst(valCl, "", currentBlock);
#else
std::vector<Value*> args;
args.push_back(isolateLocal);
@@ -1857,28 +1856,15 @@
sizeElement = LAI.sizeInBytesConstant;
} else {
uint16 index = readU2(bytecodes, i);
-#ifndef ISOLATE_SHARING
- const UTF8* className =
- compilingClass->ctpInfo->resolveClassName(index);
-
- JnjvmClassLoader* JCL = compilingClass->classLoader;
- const UTF8* arrayName = JCL->constructArrayName(1, className);
-
- dcl = JCL->constructArray(arrayName);
-#else
-
valCl = getResolvedClass(index, false);
- valCl = CallInst::Create(module->GetArrayClassFunction, valCl,
- "", currentBlock);
-#endif
+ const llvm::Type* Ty = PointerType::getUnqual(module->JavaClassType);
+ Value* args[2]= { valCl, Constant::getNullValue(Ty) };
+ valCl = CallInst::Create(module->GetArrayClassFunction, args,
+ args + 2, "", currentBlock);
sizeElement = module->constantPtrSize;
}
-#ifndef ISOLATE_SHARING
- valCl = module->getNativeClass(dcl);
- valCl = new LoadInst(valCl, "", currentBlock);
- TheVT = module->getVirtualTable(dcl);
- TheVT = new LoadInst(TheVT, "", currentBlock);
-#endif
+ TheVT = CallInst::Create(module->GetVTFromClassFunction, valCl, "",
+ currentBlock);
llvm::Value* arg1 = popAsInt();
Value* cmp = new ICmpInst(ICmpInst::ICMP_SLT, arg1,
@@ -1929,7 +1915,6 @@
Value* size =
BinaryOperator::CreateAdd(module->JavaArraySizeConstant, mult,
"", currentBlock);
- assert(TheVT && "Not VT");
std::vector<Value*> args;
args.push_back(size);
args.push_back(TheVT);
@@ -2017,16 +2002,7 @@
BranchInst::Create(ifTrue, ifFalse, cmp, currentBlock);
currentBlock = ifFalse;
- Value* clVar = 0;
-#ifndef ISOLATE_SHARING
- CommonClass* dcl =
- compilingClass->ctpInfo->getMethodClassIfLoaded(index);
- if (dcl) {
- clVar = module->getNativeClass(dcl);
- clVar = new LoadInst(clVar, "", currentBlock);
- } else
-#endif
- clVar = getResolvedClass(index, false);
+ Value* clVar = getResolvedClass(index, false);
std::vector<Value*> args;
args.push_back(obj);
@@ -2058,20 +2034,8 @@
case INSTANCEOF : {
uint16 index = readU2(bytecodes, i);
-#ifndef ISOLATE_SHARING
- CommonClass* dcl =
- compilingClass->ctpInfo->getMethodClassIfLoaded(index);
-
- Value* clVar = 0;
- if (dcl) {
- clVar = module->getNativeClass(dcl);
- clVar = new LoadInst(clVar, "", currentBlock);
- } else {
- clVar = getResolvedClass(index, false);
- }
-#else
Value* clVar = getResolvedClass(index, false);
-#endif
+
std::vector<Value*> args;
args.push_back(pop());
args.push_back(clVar);
@@ -2102,19 +2066,7 @@
uint8 dim = readU1(bytecodes, i);
-#ifdef ISOLATE_SHARING
Value* valCl = getResolvedClass(index, true);
-#else
- JnjvmClassLoader* JCL = compilingClass->classLoader;
- const UTF8* className =
- compilingClass->ctpInfo->resolveClassName(index);
-
- UserClassArray* dcl = JCL->constructArray(className);
-
- compilingClass->ctpInfo->loadClass(index);
- Value* valCl = module->getNativeClass(dcl);
- valCl = new LoadInst(valCl, "", currentBlock);
-#endif
Value** args = (Value**)alloca(sizeof(Value*) * (dim + 2));
args[0] = valCl;
args[1] = ConstantInt::get(Type::Int32Ty, dim);
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp?rev=59913&r1=59912&r2=59913&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp Sun Nov 23 11:27:39 2008
@@ -176,14 +176,6 @@
return (void*)methodCl->getConstantPool();
}
-extern "C" UserClassArray* getArrayClass(UserCommonClass* cl) {
- JnjvmClassLoader* JCL = cl->classLoader;
- const UTF8* arrayName = JCL->constructArrayName(1, cl->getName());
-
- UserClassArray* dcl = JCL->constructArray(arrayName);
- return dcl;
-}
-
extern "C" UserConstantPool* specialCtpLookup(UserConstantPool* ctpInfo,
uint32 index,
UserConstantPool** res) {
@@ -355,6 +347,17 @@
return multiCallNewIntern(cl, len, dims, vm);
}
+extern "C" UserClassArray* getArrayClass(UserCommonClass* cl,
+ UserClassArray** dcl) {
+ JnjvmClassLoader* JCL = cl->classLoader;
+ cl->resolveClass();
+ const UTF8* arrayName = JCL->constructArrayName(1, cl->getName());
+
+ UserClassArray* result = JCL->constructArray(arrayName);
+ if (dcl) *dcl = result;
+ return result;
+}
+
extern "C" void JavaObjectAquire(JavaObject* obj) {
obj->acquire();
}
@@ -368,7 +371,8 @@
return obj->instanceOf(cl);
}
-extern "C" bool instantiationOfArray(UserCommonClass* cl1, UserClassArray* cl2) {
+extern "C" bool instantiationOfArray(UserCommonClass* cl1,
+ UserClassArray* cl2) {
return cl1->instantiationOfArray(cl2);
}
Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp?rev=59913&r1=59912&r2=59913&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp Sun Nov 23 11:27:39 2008
@@ -1086,6 +1086,8 @@
ClearExceptionFunction = module->getFunction("JavaThreadClearException");
+ GetArrayClassFunction = module->getFunction("getArrayClass");
+
#ifdef ISOLATE
StringLookupFunction = module->getFunction("stringLookup");
@@ -1098,7 +1100,6 @@
GetJnjvmArrayClassFunction = module->getFunction("getJnjvmArrayClass");
StaticCtpLookupFunction = module->getFunction("staticCtpLookup");
SpecialCtpLookupFunction = module->getFunction("specialCtpLookup");
- GetArrayClassFunction = module->getFunction("getArrayClass");
#endif
#endif
Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.h?rev=59913&r1=59912&r2=59913&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.h Sun Nov 23 11:27:39 2008
@@ -287,6 +287,7 @@
llvm::Function* ReleaseObjectFunction;
llvm::Function* GetConstantPoolAtFunction;
llvm::Function* MultiCallNewFunction;
+ llvm::Function* GetArrayClassFunction;
#ifdef ISOLATE
llvm::Function* StringLookupFunction;
@@ -298,7 +299,6 @@
llvm::Function* GetJnjvmArrayClassFunction;
llvm::Function* StaticCtpLookupFunction;
llvm::Function* SpecialCtpLookupFunction;
- llvm::Function* GetArrayClassFunction;
#endif
#endif
Modified: vmkit/trunk/lib/JnJVM/VMCore/LowerConstantCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/LowerConstantCalls.cpp?rev=59913&r1=59912&r2=59913&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/LowerConstantCalls.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/LowerConstantCalls.cpp Sun Nov 23 11:27:39 2008
@@ -145,10 +145,9 @@
CI->eraseFromParent();
} else if (V == module->GetVTFromClassFunction) {
Changed = true;
-#ifndef ISOLATE_SHARING
+
ConstantExpr* CE = getClass(module, Call);
if (CE) {
- Changed = true;
ConstantInt* C = (ConstantInt*)CE->getOperand(0);
Class* cl = (Class*)C->getZExtValue();
if (cl->isResolved()) {
@@ -156,10 +155,10 @@
VT = new LoadInst(VT, "", CI);
CI->replaceAllUsesWith(VT);
CI->eraseFromParent();
+ continue;
}
- continue;
}
-#endif
+
Value* val = Call.getArgument(0);
std::vector<Value*> indexes;
indexes.push_back(mvm::MvmModule::constantZero);
@@ -171,7 +170,7 @@
CI->eraseFromParent();
} else if (V == module->GetObjectSizeFromClassFunction) {
Changed = true;
-#ifndef ISOLATE_SHARING
+
ConstantExpr* CE = getClass(module, Call);
if (CE) {
ConstantInt* C = (ConstantInt*)CE->getOperand(0);
@@ -181,10 +180,10 @@
Value* Size = LCI->getVirtualSize();
CI->replaceAllUsesWith(Size);
CI->eraseFromParent();
+ continue;
}
- continue;
}
-#endif
+
Value* val = Call.getArgument(0);
std::vector<Value*> indexes;
indexes.push_back(mvm::MvmModule::constantZero);
@@ -512,6 +511,60 @@
CI->eraseFromParent();
BranchInst::Create(NBB, trueCl);
break;
+ } else if (V == module->GetArrayClassFunction) {
+ const llvm::Type* Ty = PointerType::getUnqual(module->JavaClassType);
+ Constant* nullValue = Constant::getNullValue(Ty);
+ // Check if we have already proceed this call.
+ if (Call.getArgument(1) == nullValue) {
+ Changed = true;
+ ConstantExpr* CE = getClass(module, Call);
+ if (CE) {
+ ConstantInt* C = (ConstantInt*)CE->getOperand(0);
+ Class* cl = (Class*)C->getZExtValue();
+ if (cl->isResolved()) {
+ JnjvmClassLoader* JCL = cl->classLoader;
+ const UTF8* arrayName = JCL->constructArrayName(1, cl->name);
+
+ UserCommonClass* dcl = JCL->constructArray(arrayName);
+ Value* valCl = module->getNativeClass(dcl);
+ valCl = new LoadInst(valCl, "", CI);
+ CI->replaceAllUsesWith(valCl);
+ CI->eraseFromParent();
+ continue;
+ }
+ }
+
+ BasicBlock* NBB = II->getParent()->splitBasicBlock(II);
+ I->getParent()->getTerminator()->eraseFromParent();
+
+ Constant* init = Constant::getNullValue(module->JavaClassType);
+ GlobalVariable* GV =
+ new GlobalVariable(module->JavaClassType, false,
+ GlobalValue::ExternalLinkage,
+ init, "", module);
+
+ Value* LoadedGV = new LoadInst(GV, "", CI);
+ Value* cmp = new ICmpInst(ICmpInst::ICMP_EQ, LoadedGV, init,
+ "", CI);
+
+ BasicBlock* OKBlock = BasicBlock::Create("", &F);
+ BasicBlock* NotOKBlock = BasicBlock::Create("", &F);
+ PHINode* node = PHINode::Create(module->JavaClassType, "", OKBlock);
+ node->addIncoming(LoadedGV, CI->getParent());
+
+ BranchInst::Create(NotOKBlock, OKBlock, cmp, CI);
+
+ Value* args[2] = { Call.getArgument(0), GV };
+ Value* res = CallInst::Create(module->GetArrayClassFunction, args,
+ args + 2, "", NotOKBlock);
+ BranchInst::Create(OKBlock, NotOKBlock);
+ node->addIncoming(res, NotOKBlock);
+
+ CI->replaceAllUsesWith(node);
+ CI->eraseFromParent();
+ BranchInst::Create(NBB, OKBlock);
+ break;
+ }
}
#ifdef ISOLATE_SHARING
More information about the vmkit-commits
mailing list