[vmkit-commits] [vmkit] r59243 - in /vmkit/trunk/lib/JnJVM/VMCore: JavaClass.cpp JavaClass.h JavaJIT.cpp JavaJITOpcodes.cpp Jnjvm.cpp JnjvmModuleProvider.cpp LowerConstantCalls.cpp
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Thu Nov 13 06:29:09 PST 2008
Author: geoffray
Date: Thu Nov 13 08:29:08 2008
New Revision: 59243
URL: http://llvm.org/viewvc/llvm-project?rev=59243&view=rev
Log:
Simplify code generation.
Modified:
vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp
vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h
vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp
vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp
vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp
vmkit/trunk/lib/JnJVM/VMCore/JnjvmModuleProvider.cpp
vmkit/trunk/lib/JnJVM/VMCore/LowerConstantCalls.cpp
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp?rev=59243&r1=59242&r2=59243&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Thu Nov 13 08:29:08 2008
@@ -698,6 +698,16 @@
}
}
+JavaObject* UserClass::allocateStaticInstance(Jnjvm* vm) {
+ JavaObject* val =
+ (JavaObject*)vm->gcAllocator.allocateManagedObject(getStaticSize(),
+ getStaticVT());
+ val->initialise(this);
+ setStaticInstance(val);
+ return val;
+}
+
+
JavaMethod* CommonClass::constructMethod(JavaMethod& method,
const UTF8* name,
const UTF8* type, uint32 access) {
@@ -887,7 +897,13 @@
cl->loadParents();
cl->acquire();
cl->status = prepared;
- classLoader->getModule()->resolveVirtualClass(cl);
+ JnjvmModule *Mod = classLoader->getModule();
+ Mod->resolveVirtualClass(cl);
+ Mod->resolveStaticClass(cl);
+#ifndef ISOLATE
+ // Allocate now so that compiled code can reference it.
+ cl->allocateStaticInstance(JavaThread::get()->getJVM());
+#endif
cl->status = resolved;
}
release();
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h?rev=59243&r1=59242&r2=59243&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Thu Nov 13 08:29:08 2008
@@ -509,6 +509,10 @@
bool isReady() {
return status == ready;
}
+
+ bool isReadyForCompilation() {
+ return isReady();
+ }
bool isInitializing() {
return status >= inClinit;
@@ -539,6 +543,10 @@
return getCurrentTaskClassMirror().status == ready;
}
+ bool isReadyForCompilation() {
+ return false;
+ }
+
bool isInitializing() {
return getCurrentTaskClassMirror().status >= inClinit;
}
@@ -677,7 +685,10 @@
#endif
#endif
-
+
+ /// allocateStaticInstance - Allocate the static instance of this class.
+ ///
+ JavaObject* allocateStaticInstance(Jnjvm* vm);
/// Class - Create a class in the given virtual machine and with the given
/// name.
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp?rev=59243&r1=59242&r2=59243&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp Thu Nov 13 08:29:08 2008
@@ -1675,51 +1675,32 @@
Value* JavaJIT::getResolvedClass(uint16 index, bool clinit, bool doThrow) {
- Value* node = getConstantPoolAt(index, module->ClassLookupFunction,
- module->JavaClassType, 0, doThrow);
-
- if (clinit)
- return invoke(module->InitialisationCheckFunction, node, "",
- currentBlock);
- else
- return node;
-}
-
-void JavaJIT::invokeNew(uint16 index) {
JavaConstantPool* ctpInfo = compilingClass->ctpInfo;
-
Class* cl = (Class*)(ctpInfo->getMethodClassIfLoaded(index));
- Value* Size = 0;
- Value* VT = 0;
- Value* Cl = 0;
- if (!cl || !cl->isResolved()) {
- Cl = getResolvedClass(index, true);
- Size = CallInst::Create(module->GetObjectSizeFromClassFunction, Cl,
- "", currentBlock);
- VT = CallInst::Create(module->GetVTFromClassFunction, Cl, "",
- currentBlock);
+ Value* node = 0;
+ if (cl && cl->isResolved()) {
+ node = module->getNativeClass(cl);
+ node = new LoadInst(node, "", currentBlock);
} else {
- LLVMClassInfo* LCI = module->getClassInfo(cl);
- Size = LCI->getVirtualSize();
-#ifndef ISOLATE_SHARING
- VT = module->getVirtualTable(cl);
- VT = new LoadInst(VT, "", currentBlock);
- Cl = module->getNativeClass(cl);
- Cl = new LoadInst(Cl, "", currentBlock);
- if (!cl->isReady()) {
- Cl = invoke(module->InitialisationCheckFunction, Cl, "",
- currentBlock);
- CallInst::Create(module->ForceInitialisationCheckFunction, Cl, "",
- currentBlock);
- }
-#else
- Cl = getResolvedClass(index, true);
- CallInst::Create(module->ForceInitialisationCheckFunction, Cl, "",
- currentBlock);
- VT = CallInst::Create(module->GetVTFromClassFunction, Cl, "",
- currentBlock);
-#endif
+ node = getConstantPoolAt(index, module->ClassLookupFunction,
+ module->JavaClassType, 0, doThrow);
}
+
+ if (!(!clinit || (cl && (cl->isReadyForCompilation() ||
+ compilingClass->subclassOf(cl)))))
+ return invoke(module->InitialisationCheckFunction, node, "",
+ currentBlock);
+ else
+ return node;
+}
+
+void JavaJIT::invokeNew(uint16 index) {
+
+ Value* Cl = getResolvedClass(index, true);
+ Value* Size = CallInst::Create(module->GetObjectSizeFromClassFunction, Cl,
+ "", currentBlock);
+ Value* VT = CallInst::Create(module->GetVTFromClassFunction, Cl, "",
+ currentBlock);
std::vector<Value*> args;
args.push_back(Size);
args.push_back(VT);
@@ -1783,38 +1764,20 @@
LLVMFieldInfo* LFI = module->getFieldInfo(field);
const Type* type = 0;
if (stat) {
-
-#ifndef ISOLATE_SHARING
- if (module->isStaticCompiling()) {
- // Do an initialization check first.
- Value* Cl = module->getNativeClass(field->classDef);
- Cl = new LoadInst(Cl, "", currentBlock);
+ type = LCI->getStaticType();
+ Value* Cl = module->getNativeClass(field->classDef);
+ Cl = new LoadInst(Cl, "", currentBlock);
+ if (!(compilingClass->subclassOf(field->classDef)) &&
+ !(compilingClass->isReadyForCompilation())) {
Cl = invoke(module->InitialisationCheckFunction, Cl, "",
currentBlock);
- CallInst::Create(module->ForceInitialisationCheckFunction, Cl, "",
- currentBlock);
- object = CallInst::Create(module->GetStaticInstanceFunction, Cl, "",
- currentBlock);
- type = LCI->getStaticType();
- return fieldGetter(this, type, object, LFI->getOffset());
- }
-
- if (field->classDef->isReady()) {
- Value* Cl = module->getNativeClass(field->classDef);
- Cl = new LoadInst(Cl, "", currentBlock);
- object = CallInst::Create(module->GetStaticInstanceFunction, Cl, "",
- currentBlock);
- type = LCI->getStaticType();
- return fieldGetter(this, type, object, LFI->getOffset());
}
-#else
- // In a multi environment, we always need to get the ptr in the constant
- // pool. Therefore, we do nothing here.
-#endif
+ object = CallInst::Create(module->GetStaticInstanceFunction, Cl, "",
+ currentBlock);
} else {
type = LCI->getVirtualType();
- return fieldGetter(this, type, object, LFI->getOffset());
}
+ return fieldGetter(this, type, object, LFI->getOffset());
}
const Type* Pty = module->arrayPtrType;
Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp?rev=59243&r1=59242&r2=59243&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp Thu Nov 13 08:29:08 2008
@@ -1934,6 +1934,7 @@
Value* size =
BinaryOperator::CreateAdd(module->JavaObjectSizeConstant, mult,
"", currentBlock);
+ assert(TheVT && "Not VT");
std::vector<Value*> args;
args.push_back(size);
args.push_back(TheVT);
@@ -2007,10 +2008,6 @@
case CHECKCAST : {
uint16 index = readU2(bytecodes, i);
-#ifndef ISOLATE_SHARING
- CommonClass* dcl =
- compilingClass->ctpInfo->getMethodClassIfLoaded(index);
-#endif
Value* obj = top();
@@ -2025,6 +2022,8 @@
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);
@@ -2089,33 +2088,15 @@
case MONITORENTER : {
Value* obj = pop();
-#ifdef SERVICE_VM
- if (ServiceDomain::isLockableDomain(compilingClass->isolate))
- invoke(module->AquireObjectInSharedDomainFunction, obj, "",
- currentBlock);
- else
- invoke(module->AquireObjectFunction, obj, "",
- currentBlock);
-#else
JITVerifyNull(obj);
monitorEnter(obj);
-#endif
break;
}
case MONITOREXIT : {
Value* obj = pop();
-#ifdef SERVICE_VM
- if (ServiceDomain::isLockableDomain(compilingClass->isolate))
- invoke(module->ReleaseObjectInSharedDomainFunction, obj, "",
- currentBlock);
- else
- invoke(module->ReleaseObjectFunction, obj, "",
- currentBlock);
-#else
JITVerifyNull(obj);
monitorExit(obj);
-#endif
break;
}
Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp?rev=59243&r1=59242&r2=59243&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Thu Nov 13 08:29:08 2008
@@ -157,26 +157,30 @@
// in textual order, as though they were a single block, except that
// final static variables and fields of interfaces whose values are
// compile-time constants are initialized first.
-
-
- UserClass* cl = (UserClass*)this;
- cl->resolveStaticClass();
-
-
+
PRINT_DEBUG(JNJVM_LOAD, 0, COLOR_NORMAL, "; ", 0);
PRINT_DEBUG(JNJVM_LOAD, 0, LIGHT_GREEN, "clinit ", 0);
PRINT_DEBUG(JNJVM_LOAD, 0, COLOR_NORMAL, "%s\n", printString());
-
- JavaObject* val =
- (JavaObject*)vm->gcAllocator.allocateManagedObject(cl->getStaticSize(),
- cl->getStaticVT());
- val->initialise(cl);
+
+
+ UserClass* cl = (UserClass*)this;
+
+#if defined(ISOLATE) || defined(ISOLATE_SHARING)
+ // Isolate environments allocate the static instance on their own, not when
+ // the class is being resolved.
+ JavaObject* val = cl->allocateStaticInstance(vm);
+#else
+ // Single environment allocates the static instance during resolution, so
+ // that compiled code can access it directly (with an initialization
+ // check just before the access)
+ JavaObject* val = cl->getStaticInstance();
+#endif
+
JavaField* fields = cl->getStaticFields();
for (uint32 i = 0; i < cl->nbStaticFields; ++i) {
fields[i].initField(val, vm);
}
- cl->setStaticInstance(val);
JavaMethod* meth = lookupMethodDontThrow(vm->bootstrapLoader->clinitName,
Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmModuleProvider.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmModuleProvider.cpp?rev=59243&r1=59242&r2=59243&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmModuleProvider.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmModuleProvider.cpp Thu Nov 13 08:29:08 2008
@@ -231,6 +231,8 @@
Function* func = mod->JavaObjectAllocateFunction;
addPass(PM, mvm::createEscapeAnalysisPass(func));
+
+ // Do not do GVN after this pass: initialization checks could be removed.
addPass(PM, mvm::createLowerConstantCallsPass());
// Run instcombine after redundancy elimination to exploit opportunities
@@ -242,8 +244,6 @@
addPass(PM, createAggressiveDCEPass()); // Delete dead instructions
addPass(PM, createCFGSimplificationPass()); // Merge & remove BBs
- addPass(PM, mvm::createLowerForcedCallsPass());
-
}
JnjvmModuleProvider::JnjvmModuleProvider(JnjvmModule *m) {
Modified: vmkit/trunk/lib/JnJVM/VMCore/LowerConstantCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/LowerConstantCalls.cpp?rev=59243&r1=59242&r2=59243&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/LowerConstantCalls.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/LowerConstantCalls.cpp Thu Nov 13 08:29:08 2008
@@ -22,7 +22,6 @@
using namespace llvm;
using namespace jnjvm;
-#include <iostream>
namespace mvm {
class VISIBILITY_HIDDEN LowerConstantCalls : public FunctionPass {
@@ -36,6 +35,34 @@
char LowerConstantCalls::ID = 0;
static RegisterPass<LowerConstantCalls> X("LowerConstantCalls",
"Lower Constant calls");
+
+
+static ConstantExpr* getClass(JnjvmModule* Mod, CallSite& Call) {
+ ConstantExpr* CE = 0;
+ if (Mod->isStaticCompiling()) {
+ LoadInst* LI = dyn_cast<LoadInst>(Call.getArgument(0));
+ if (!LI) {
+ PHINode* node = dyn_cast<PHINode>(Call.getArgument(0));
+ if (node) {
+ LI = dyn_cast<LoadInst>(node->getIncomingValue(0));
+ }
+ }
+
+ if (LI) {
+ GlobalVariable* GV = dyn_cast<GlobalVariable>(LI->getOperand(0));
+ CE = dyn_cast<ConstantExpr>(GV->getInitializer());
+ }
+ } else {
+ CE = dyn_cast<ConstantExpr>(Call.getArgument(0));
+ if (!CE) {
+ // It has to be a phi for intialization check.
+ PHINode* node = dyn_cast<PHINode>(Call.getArgument(0));
+ if (node) CE = dyn_cast<ConstantExpr>(node->getIncomingValue(0));
+ }
+ }
+ return CE;
+}
+
bool LowerConstantCalls::runOnFunction(Function& F) {
JnjvmModule* module = (JnjvmModule*)F.getParent();
bool Changed = false;
@@ -86,6 +113,21 @@
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()) {
+ Value* VT = module->getVirtualTable(cl);
+ VT = new LoadInst(VT, "", CI);
+ CI->replaceAllUsesWith(VT);
+ CI->eraseFromParent();
+ }
+ continue;
+ }
+#endif
Value* val = Call.getArgument(0);
std::vector<Value*> indexes;
indexes.push_back(mvm::MvmModule::constantZero);
@@ -97,6 +139,20 @@
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);
+ Class* cl = (Class*)C->getZExtValue();
+ if (cl->isResolved()) {
+ LLVMClassInfo* LCI = module->getClassInfo(cl);
+ Value* Size = LCI->getVirtualSize();
+ CI->replaceAllUsesWith(Size);
+ CI->eraseFromParent();
+ }
+ continue;
+ }
+#endif
Value* val = Call.getArgument(0);
std::vector<Value*> indexes;
indexes.push_back(mvm::MvmModule::constantZero);
@@ -231,8 +287,9 @@
} else if (V == module->GetStaticInstanceFunction) {
Changed = true;
#if !defined(ISOLATE_SHARING) && !defined(ISOLATE)
- ConstantExpr* CE = dyn_cast<ConstantExpr>(Call.getArgument(0));
- assert(CE && "Wrong use of GetStaticInstanceFunction");
+ ConstantExpr* CE = getClass(module, Call);
+ assert(CE && "Wrong use if GetStaticInstanceFunction");
+
ConstantInt* C = (ConstantInt*)CE->getOperand(0);
Class* cl = (Class*)C->getZExtValue();
@@ -240,6 +297,7 @@
Replace = new LoadInst(Replace, "", CI);
CI->replaceAllUsesWith(Replace);
CI->eraseFromParent();
+
#elif defined(ISOLATE)
std::vector<Value*> GEP;
GEP.push_back(module->constantZero);
@@ -509,6 +567,7 @@
CI->eraseFromParent();
}
#endif
+
}
}
}
More information about the vmkit-commits
mailing list