[vmkit-commits] [vmkit] r134923 - in /vmkit/trunk: ./ include/j3/ lib/J3/Classpath/ lib/J3/Compiler/ lib/J3/LLVMRuntime/ lib/J3/VMCore/ lib/Mvm/Compiler/ tools/ tools/precompiler/ tools/precompiler/trainer/
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Mon Jul 11 14:28:04 PDT 2011
Author: geoffray
Date: Mon Jul 11 16:28:04 2011
New Revision: 134923
URL: http://llvm.org/viewvc/llvm-project?rev=134923&view=rev
Log:
Add a precompiler tool that precompiles bootstrap classes used when running a program.
Added:
vmkit/trunk/tools/precompiler/
vmkit/trunk/tools/precompiler/Makefile (with props)
vmkit/trunk/tools/precompiler/Precompiler.cpp
vmkit/trunk/tools/precompiler/trainer/
vmkit/trunk/tools/precompiler/trainer/HelloWorld.java
vmkit/trunk/tools/precompiler/trainer/Makefile (with props)
Modified:
vmkit/trunk/Makefile.common.in
vmkit/trunk/include/j3/J3Intrinsics.h
vmkit/trunk/include/j3/JavaAOTCompiler.h
vmkit/trunk/include/j3/JavaJITCompiler.h
vmkit/trunk/include/j3/JavaLLVMCompiler.h
vmkit/trunk/lib/J3/Classpath/JavaUpcalls.cpp
vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp
vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp
vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp
vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp
vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp
vmkit/trunk/lib/J3/LLVMRuntime/runtime-single.ll
vmkit/trunk/lib/J3/VMCore/JavaClass.cpp
vmkit/trunk/lib/J3/VMCore/JavaClass.h
vmkit/trunk/lib/J3/VMCore/JavaConstantPool.cpp
vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp
vmkit/trunk/lib/J3/VMCore/Reader.h
vmkit/trunk/lib/Mvm/Compiler/JIT.cpp
vmkit/trunk/tools/Makefile
Modified: vmkit/trunk/Makefile.common.in
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/Makefile.common.in?rev=134923&r1=134922&r2=134923&view=diff
==============================================================================
--- vmkit/trunk/Makefile.common.in (original)
+++ vmkit/trunk/Makefile.common.in Mon Jul 11 16:28:04 2011
@@ -20,9 +20,7 @@
# Define BYTECODE_LIBRARY before including LLVM's Makefile.common to get
# dependencies right.
-ifeq ($(MODULE_WITH_GC), 1)
- BYTECODE_LIBRARY = 1
-endif
+BYTECODE_LIBRARY = 1
ifeq ($(BUILD_FRAMETABLE), 1)
BUILT_SOURCES = FrametablesSymbols.inc FrametablesExterns.inc
Modified: vmkit/trunk/include/j3/J3Intrinsics.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/J3Intrinsics.h?rev=134923&r1=134922&r2=134923&view=diff
==============================================================================
--- vmkit/trunk/include/j3/J3Intrinsics.h (original)
+++ vmkit/trunk/include/j3/J3Intrinsics.h Mon Jul 11 16:28:04 2011
@@ -35,7 +35,9 @@
const llvm::Type* JavaClassType;
const llvm::Type* JavaClassArrayType;
const llvm::Type* JavaClassPrimitiveType;
- const llvm::Type* ConstantPoolType;
+ const llvm::Type* ClassBytesType;
+ const llvm::Type* JavaConstantPoolType;
+ const llvm::Type* ResolvedConstantPoolType;
const llvm::Type* CodeLineInfoType;
const llvm::Type* UTF8Type;
const llvm::Type* JavaMethodType;
Modified: vmkit/trunk/include/j3/JavaAOTCompiler.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/JavaAOTCompiler.h?rev=134923&r1=134922&r2=134923&view=diff
==============================================================================
--- vmkit/trunk/include/j3/JavaAOTCompiler.h (original)
+++ vmkit/trunk/include/j3/JavaAOTCompiler.h Mon Jul 11 16:28:04 2011
@@ -16,6 +16,8 @@
class ArrayObject;
class Attribut;
+class ClassBytes;
+class JnjvmBootstrapLoader;
using mvm::UTF8;
@@ -48,6 +50,7 @@
virtual llvm::Value* addCallback(Class* cl, uint16 index, Signdef* sign,
bool stat, llvm::BasicBlock* insert);
+ virtual llvm::Function* getMethod(JavaMethod* meth);
virtual void makeVT(Class* cl);
virtual void makeIMT(Class* cl);
@@ -64,7 +67,7 @@
virtual llvm::Constant* getString(JavaString* str);
virtual llvm::Constant* getStringPtr(JavaString** str);
- virtual llvm::Constant* getConstantPool(JavaConstantPool* ctp);
+ virtual llvm::Constant* getResolvedConstantPool(JavaConstantPool* ctp);
virtual llvm::Constant* getNativeFunction(JavaMethod* meth, void* natPtr);
virtual void setMethod(llvm::Function* func, void* ptr, const char* name);
@@ -93,6 +96,9 @@
llvm::Constant* CreateConstantFromJavaClass(CommonClass* cl);
llvm::Constant* CreateConstantForBaseObject(CommonClass* cl);
llvm::Constant* CreateConstantFromJavaObject(JavaObject* obj);
+ llvm::Constant* CreateConstantFromClassBytes(ClassBytes* bytes);
+ llvm::Constant* CreateConstantFromJavaConstantPool(JavaConstantPool* ctp);
+ void AddInitializerToClass(llvm::GlobalVariable* varGV, CommonClass* classDef);
llvm::Constant* getUTF8(const UTF8* val);
template<typename T>
@@ -103,29 +109,30 @@
llvm::Constant* CreateConstantFromObjectArray(const ArrayObject* val);
- std::map<const CommonClass*, llvm::Constant*> nativeClasses;
+ std::map<CommonClass*, llvm::GlobalVariable*> nativeClasses;
std::map<const ClassArray*, llvm::GlobalVariable*> arrayClasses;
std::map<const CommonClass*, llvm::Constant*> javaClasses;
std::map<const JavaVirtualTable*, llvm::Constant*> virtualTables;
std::map<const Class*, llvm::Constant*> staticInstances;
- std::map<const JavaConstantPool*, llvm::Constant*> constantPools;
+ std::map<const JavaConstantPool*, llvm::Constant*> resolvedConstantPools;
std::map<const JavaString*, llvm::Constant*> strings;
std::map<const JavaMethod*, llvm::Constant*> nativeFunctions;
std::map<const UTF8*, llvm::Constant*> utf8s;
std::map<const Class*, llvm::Constant*> virtualMethods;
std::map<const JavaObject*, llvm::Constant*> finalObjects;
std::map<const llvm::Constant*, JavaObject*> reverseFinalObjects;
+ std::vector<JavaMethod*> toCompile;
typedef std::map<const JavaObject*, llvm::Constant*>::iterator
final_object_iterator;
typedef std::map<const llvm::Constant*, JavaObject*>::iterator
reverse_final_object_iterator;
-
+
typedef std::map<const Class*, llvm::Constant*>::iterator
method_iterator;
- typedef std::map<const CommonClass*, llvm::Constant*>::iterator
+ typedef std::map<CommonClass*, llvm::GlobalVariable*>::iterator
native_class_iterator;
typedef std::map<const ClassArray*, llvm::GlobalVariable*>::iterator
@@ -141,8 +148,8 @@
static_instance_iterator;
typedef std::map<const JavaConstantPool*, llvm::Constant*>::iterator
- constant_pool_iterator;
-
+ resolved_constant_pool_iterator;
+
typedef std::map<const JavaString*, llvm::Constant*>::iterator
string_iterator;
@@ -166,6 +173,7 @@
bool generateStubs;
bool assumeCompiled;
bool compileRT;
+ bool precompile;
std::vector<std::string>* clinits;
@@ -178,10 +186,12 @@
void compileFile(Jnjvm* vm, const char* name);
void compileClass(Class* cl);
+ void compileClassLoader(JnjvmBootstrapLoader* loader);
void generateMain(const char* name, bool jit);
private:
void compileAllStubs(Signdef* sign);
+ llvm::Function* getMethodOrStub(JavaMethod* meth);
};
} // end namespace j3
Modified: vmkit/trunk/include/j3/JavaJITCompiler.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/JavaJITCompiler.h?rev=134923&r1=134922&r2=134923&view=diff
==============================================================================
--- vmkit/trunk/include/j3/JavaJITCompiler.h (original)
+++ vmkit/trunk/include/j3/JavaJITCompiler.h Mon Jul 11 16:28:04 2011
@@ -70,7 +70,7 @@
virtual llvm::Constant* getString(JavaString* str);
virtual llvm::Constant* getStringPtr(JavaString** str);
- virtual llvm::Constant* getConstantPool(JavaConstantPool* ctp);
+ virtual llvm::Constant* getResolvedConstantPool(JavaConstantPool* ctp);
virtual llvm::Constant* getNativeFunction(JavaMethod* meth, void* natPtr);
virtual void setMethod(llvm::Function* func, void* ptr, const char* name);
Modified: vmkit/trunk/include/j3/JavaLLVMCompiler.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/JavaLLVMCompiler.h?rev=134923&r1=134922&r2=134923&view=diff
==============================================================================
--- vmkit/trunk/include/j3/JavaLLVMCompiler.h (original)
+++ vmkit/trunk/include/j3/JavaLLVMCompiler.h Mon Jul 11 16:28:04 2011
@@ -123,7 +123,7 @@
void resolveVirtualClass(Class* cl);
void resolveStaticClass(Class* cl);
- llvm::Function* getMethod(JavaMethod* meth);
+ virtual llvm::Function* getMethod(JavaMethod* meth);
void initialiseAssessorInfo();
std::map<const char, LLVMAssessorInfo> AssessorInfo;
@@ -192,7 +192,7 @@
virtual llvm::Constant* getString(JavaString* str) = 0;
virtual llvm::Constant* getStringPtr(JavaString** str) = 0;
- virtual llvm::Constant* getConstantPool(JavaConstantPool* ctp) = 0;
+ virtual llvm::Constant* getResolvedConstantPool(JavaConstantPool* ctp) = 0;
virtual llvm::Constant* getNativeFunction(JavaMethod* meth, void* natPtr) = 0;
virtual void setMethod(llvm::Function* func, void* ptr, const char* name) = 0;
Modified: vmkit/trunk/lib/J3/Classpath/JavaUpcalls.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Classpath/JavaUpcalls.cpp?rev=134923&r1=134922&r2=134923&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Classpath/JavaUpcalls.cpp (original)
+++ vmkit/trunk/lib/J3/Classpath/JavaUpcalls.cpp Mon Jul 11 16:28:04 2011
@@ -31,7 +31,6 @@
using namespace j3;
-#ifndef ISOLATE_SHARING
Class* Classpath::newThread;
Class* Classpath::newVMThread;
JavaField* Classpath::assocThread;
@@ -226,8 +225,6 @@
JavaMethod* Classpath::EnqueueReference;
Class* Classpath::newReference;
-#endif
-
void Classpath::CreateJavaThread(Jnjvm* vm, JavaThread* myth,
const char* thName, JavaObject* Group) {
JavaObjectVMThread* vmth = NULL;
Modified: vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp?rev=134923&r1=134922&r2=134923&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp Mon Jul 11 16:28:04 2011
@@ -38,8 +38,8 @@
VTType = PointerType::getUnqual(module->getTypeByName("VT"));
LLVMContext& Context = module->getContext();
- ConstantPoolType = ptrPtrType;
-
+ ResolvedConstantPoolType = ptrPtrType;
+
JavaObjectType =
PointerType::getUnqual(module->getTypeByName("JavaObject"));
@@ -54,6 +54,10 @@
PointerType::getUnqual(module->getTypeByName("JavaClassArray"));
JavaClassType =
PointerType::getUnqual(module->getTypeByName("JavaClass"));
+ ClassBytesType =
+ PointerType::getUnqual(module->getTypeByName("ClassBytes"));
+ JavaConstantPoolType =
+ PointerType::getUnqual(module->getTypeByName("JavaConstantPool"));
JavaArrayUInt8Type =
PointerType::getUnqual(module->getTypeByName("ArrayUInt8"));
Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=134923&r1=134922&r2=134923&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Mon Jul 11 16:28:04 2011
@@ -39,7 +39,7 @@
bool JavaAOTCompiler::isCompiling(const CommonClass* cl) const {
if (cl->isClass()) {
// A class is being static compiled if owner class is not null.
- return cl->asClass()->getOwnerClass() != 0;
+ return precompile || (cl->asClass()->getOwnerClass() != 0);
} else if (cl->isArray()) {
// Only compile an aray if we are compiling rt.jar.
return compileRT;
@@ -50,6 +50,20 @@
}
}
+void JavaAOTCompiler::AddInitializerToClass(GlobalVariable* varGV, CommonClass* classDef) {
+ if (classDef->isClass() && isCompiling(classDef)) {
+ Constant* C = CreateConstantFromClass(classDef->asClass());
+ varGV->setInitializer(C);
+ } else if (classDef->isArray()) {
+ Constant* C = CreateConstantFromClassArray(classDef->asArrayClass());
+ varGV->setInitializer(C);
+ } else if (classDef->isPrimitive()) {
+ Constant* C =
+ CreateConstantFromClassPrimitive(classDef->asPrimitiveClass());
+ varGV->setInitializer(C);
+ }
+}
+
Constant* JavaAOTCompiler::getNativeClass(CommonClass* classDef) {
if (classDef->isClass() || isCompiling(classDef) || assumeCompiled) {
@@ -74,20 +88,11 @@
nativeClasses.insert(std::make_pair(classDef, varGV));
- if (classDef->isClass() && isCompiling(classDef)) {
- Constant* C = CreateConstantFromClass(classDef->asClass());
- varGV->setInitializer(C);
- } else if (classDef->isArray()) {
- Constant* C = CreateConstantFromClassArray(classDef->asArrayClass());
- varGV->setInitializer(C);
- } else if (classDef->isPrimitive()) {
- Constant* C =
- CreateConstantFromClassPrimitive(classDef->asPrimitiveClass());
- varGV->setInitializer(C);
+ if (!precompile) {
+ AddInitializerToClass(varGV, classDef);
}
return varGV;
-
} else {
return I->second;
}
@@ -114,19 +119,79 @@
return 0;
}
-Constant* JavaAOTCompiler::getConstantPool(JavaConstantPool* ctp) {
- llvm::Constant* varGV = 0;
- constant_pool_iterator End = constantPools.end();
- constant_pool_iterator I = constantPools.find(ctp);
+Constant* JavaAOTCompiler::CreateConstantFromJavaConstantPool(JavaConstantPool* ctp) {
+ const StructType* STy =
+ dyn_cast<StructType>(JavaIntrinsics.JavaConstantPoolType->getContainedType(0));
+ Module& Mod = *getLLVMModule();
+
+ std::vector<Constant*> Elemts;
+
+ // Class
+ Elemts.push_back(getNativeClass(ctp->classDef));
+
+ // ctpSize
+ Elemts.push_back(ConstantInt::get(Type::getInt32Ty(getLLVMContext()), ctp->ctpSize));
+
+ // ctpType
+ const ArrayType* ATy = ArrayType::get(Type::getInt8Ty(getLLVMContext()), ctp->ctpSize);
+ std::vector<Constant*> Vals;
+ for (uint32 i = 0; i < ctp->ctpSize; ++i) {
+ Vals.push_back(ConstantInt::get(Type::getInt8Ty(getLLVMContext()), ctp->ctpType[i]));
+ }
+
+ Constant* Array = ConstantArray::get(ATy, Vals);
+ GlobalVariable* varGV = new GlobalVariable(Mod, Array->getType(), false,
+ GlobalValue::InternalLinkage,
+ Array, "");
+
+ Array = ConstantExpr::getBitCast(
+ varGV, PointerType::getUnqual(Type::getInt8Ty(getLLVMContext())));
+ Elemts.push_back(Array);
+
+ // ctpDef
+ ATy = ArrayType::get(Type::getInt32Ty(getLLVMContext()), ctp->ctpSize);
+ Vals.clear();
+ for (uint32 i = 0; i < ctp->ctpSize; ++i) {
+ Vals.push_back(ConstantInt::get(Type::getInt32Ty(getLLVMContext()), ctp->ctpDef[i]));
+ }
+
+ Array = ConstantArray::get(ATy, Vals);
+ varGV = new GlobalVariable(Mod, Array->getType(), false,
+ GlobalValue::InternalLinkage,
+ Array, "");
+
+ Array = ConstantExpr::getBitCast(
+ varGV, PointerType::getUnqual(Type::getInt32Ty(getLLVMContext())));
+
+ Elemts.push_back(Array);
+
+ // ctpRes
+ Elemts.push_back(getResolvedConstantPool(ctp));
+
+ return ConstantStruct::get(STy, Elemts);
+}
+
+Constant* JavaAOTCompiler::getResolvedConstantPool(JavaConstantPool* ctp) {
+ resolved_constant_pool_iterator End = resolvedConstantPools.end();
+ resolved_constant_pool_iterator I = resolvedConstantPools.find(ctp);
if (I == End) {
- const Type* Ty = JavaIntrinsics.ConstantPoolType->getContainedType(0);
Module& Mod = *getLLVMModule();
+
+ const ArrayType* ATy = ArrayType::get(JavaIntrinsics.ptrType, ctp->ctpSize);
+ std::vector<Constant*> Vals;
+ for (uint32 i = 0; i < ctp->ctpSize; ++i) {
+ Vals.push_back(Constant::getNullValue(JavaIntrinsics.ptrType));
+ }
+
+ Constant* Array = ConstantArray::get(ATy, Vals);
+ GlobalVariable* varGV = new GlobalVariable(Mod, Array->getType(), false,
+ GlobalValue::InternalLinkage,
+ Array, "");
+
+ Array = ConstantExpr::getBitCast(varGV, JavaIntrinsics.ResolvedConstantPoolType);
- varGV = new GlobalVariable(Mod, Ty, false,
- GlobalValue::InternalLinkage,
- Constant::getNullValue(Ty), "");
- constantPools.insert(std::make_pair(ctp, varGV));
- return varGV;
+ resolvedConstantPools.insert(std::make_pair(ctp, Array));
+ return Array;
} else {
return I->second;
}
@@ -197,33 +262,38 @@
}
Constant* JavaAOTCompiler::getJavaClass(CommonClass* cl) {
- java_class_iterator End = javaClasses.end();
- java_class_iterator I = javaClasses.find(cl);
- if (I == End) {
- final_object_iterator End = finalObjects.end();
- final_object_iterator I = finalObjects.find(cl->delegatee[0]);
+ Class* javaClass = cl->classLoader->bootstrapLoader->upcalls->newClass;
+ LLVMClassInfo* LCI = getClassInfo(javaClass);
+ const llvm::Type* Ty = LCI->getVirtualType();
+
+ if (useCooperativeGC()) {
+ return Constant::getNullValue(JavaIntrinsics.JavaObjectType);
+ } else {
+ java_class_iterator End = javaClasses.end();
+ java_class_iterator I = javaClasses.find(cl);
if (I == End) {
+ final_object_iterator End = finalObjects.end();
+ final_object_iterator I = finalObjects.find(cl->delegatee[0]);
+ if (I == End) {
+
+ Module& Mod = *getLLVMModule();
+
+ GlobalVariable* varGV =
+ new GlobalVariable(Mod, Ty->getContainedType(0), false,
+ GlobalValue::InternalLinkage, 0, "");
+
+ Constant* res = ConstantExpr::getCast(Instruction::BitCast, varGV,
+ JavaIntrinsics.JavaObjectType);
- Class* javaClass = cl->classLoader->bootstrapLoader->upcalls->newClass;
- LLVMClassInfo* LCI = getClassInfo(javaClass);
- const llvm::Type* Ty = LCI->getVirtualType();
- Module& Mod = *getLLVMModule();
-
- GlobalVariable* varGV =
- new GlobalVariable(Mod, Ty->getContainedType(0), false,
- GlobalValue::InternalLinkage, 0, "");
-
- Constant* res = ConstantExpr::getCast(Instruction::BitCast, varGV,
- JavaIntrinsics.JavaObjectType);
-
- javaClasses.insert(std::make_pair(cl, res));
- varGV->setInitializer(CreateConstantFromJavaClass(cl));
- return res;
+ javaClasses.insert(std::make_pair(cl, res));
+ varGV->setInitializer(CreateConstantFromJavaClass(cl));
+ return res;
+ } else {
+ return I->second;
+ }
} else {
return I->second;
}
- } else {
- return I->second;
}
}
@@ -389,8 +459,8 @@
Attribut* attribut = field.lookupAttribut(Attribut::constantAttribut);
- if (!attribut) {
- if (cl->getStaticInstance() != NULL) {
+ if (attribut == NULL) {
+ if ((cl->getStaticInstance() != NULL) && !useCooperativeGC()) {
if (type->isPrimitive()) {
const PrimitiveTypedef* prim = (const PrimitiveTypedef*)type;
if (prim->isBool() || prim->isByte()) {
@@ -454,12 +524,16 @@
} else {
Elts.push_back(ConstantInt::get(Ty, (uint64)ctpInfo->IntegerAt(idx)));
}
- } else if (type->isReference()){
- const UTF8* utf8 = ctpInfo->UTF8At(ctpInfo->ctpDef[idx]);
- JavaString* obj = ctpInfo->resolveString(utf8, idx);
- Constant* C = getString(obj);
- C = ConstantExpr::getBitCast(C, JavaIntrinsics.JavaObjectType);
- Elts.push_back(C);
+ } else if (type->isReference()) {
+ if (useCooperativeGC()) {
+ Elts.push_back(JavaIntrinsics.JavaObjectNullConstant);
+ } else {
+ const UTF8* utf8 = ctpInfo->UTF8At(ctpInfo->ctpDef[idx]);
+ JavaString* obj = ctpInfo->resolveString(utf8, idx);
+ Constant* C = getString(obj);
+ C = ConstantExpr::getBitCast(C, JavaIntrinsics.JavaObjectType);
+ Elts.push_back(C);
+ }
} else {
fprintf(stderr, "Implement me");
abort();
@@ -565,6 +639,7 @@
}
Constant* JavaAOTCompiler::CreateConstantForBaseObject(CommonClass* cl) {
+ assert(!useCooperativeGC());
const StructType* STy =
dyn_cast<StructType>(JavaIntrinsics.JavaObjectType->getContainedType(0));
@@ -581,6 +656,7 @@
}
Constant* JavaAOTCompiler::CreateConstantFromJavaClass(CommonClass* cl) {
+ assert(!useCooperativeGC());
Class* javaClass = cl->classLoader->bootstrapLoader->upcalls->newClass;
LLVMClassInfo* LCI = getClassInfo(javaClass);
const StructType* STy =
@@ -610,6 +686,7 @@
}
Constant* JavaAOTCompiler::CreateConstantFromJavaObject(JavaObject* obj) {
+ assert(!useCooperativeGC());
CommonClass* cl = JavaObject::getClass(obj);
if (cl->isArray()) {
@@ -716,6 +793,7 @@
}
Constant* JavaAOTCompiler::CreateConstantFromJavaString(JavaString* str) {
+ assert(!useCooperativeGC());
Class* cl = JavaObject::getClass(str)->asClass();
LLVMClassInfo* LCI = getClassInfo(cl);
const StructType* STy =
@@ -944,11 +1022,11 @@
MethodElts.push_back(ConstantInt::get(Type::getInt8Ty(getLLVMContext()), method.canBeInlined));
// code
- if (isAbstract(method.access)) {
+ if (isAbstract(method.access)
+ || (precompile && getMethodInfo(&method)->getMethod()->hasExternalWeakLinkage())) {
MethodElts.push_back(Constant::getNullValue(JavaIntrinsics.ptrType));
} else {
- LLVMMethodInfo* LMI = getMethodInfo(&method);
- Function* func = LMI->getMethod();
+ Function* func = getMethod(&method);
MethodElts.push_back(ConstantExpr::getCast(Instruction::BitCast, func,
JavaIntrinsics.ptrType));
}
@@ -1151,10 +1229,20 @@
ClassElts.push_back(Constant::getNullValue(JavaIntrinsics.ptrType));
// bytes
- ClassElts.push_back(Constant::getNullValue(JavaIntrinsics.JavaArrayUInt8Type));
+ Constant* bytes = CreateConstantFromClassBytes(cl->bytes);
+ GlobalVariable* varGV = new GlobalVariable(*getLLVMModule(), bytes->getType(), false,
+ GlobalValue::InternalLinkage,
+ bytes, "");
+
+ bytes = ConstantExpr::getBitCast(varGV, JavaIntrinsics.ClassBytesType);
+ ClassElts.push_back(bytes);
// ctpInfo
- ClassElts.push_back(Constant::getNullValue(JavaIntrinsics.ptrType));
+ Constant* ctpInfo = CreateConstantFromJavaConstantPool(cl->ctpInfo);
+ varGV = new GlobalVariable(*getLLVMModule(), ctpInfo->getType(), false,
+ GlobalValue::InternalLinkage,
+ ctpInfo, "");
+ ClassElts.push_back(varGV);
// attributs
if (cl->nbAttributs) {
@@ -1229,8 +1317,30 @@
return ConstantStruct::get(STy, ClassElts);
}
+Constant* JavaAOTCompiler::CreateConstantFromClassBytes(ClassBytes* bytes) {
+ std::vector<const Type*> Elemts;
+ const ArrayType* ATy = ArrayType::get(Type::getInt8Ty(getLLVMContext()), bytes->size);
+ Elemts.push_back(Type::getInt32Ty(getLLVMContext()));
+ Elemts.push_back(ATy);
+
+ const StructType* STy = StructType::get(getLLVMContext(), Elemts);
+
+ std::vector<Constant*> Cts;
+ Cts.push_back(ConstantInt::get(Type::getInt32Ty(getLLVMContext()), bytes->size));
+
+ std::vector<Constant*> Vals;
+ for (uint32 i = 0; i < bytes->size; ++i) {
+ Vals.push_back(ConstantInt::get(Type::getInt8Ty(getLLVMContext()), bytes->elements[i]));
+ }
+
+ Cts.push_back(ConstantArray::get(ATy, Vals));
+
+ return ConstantStruct::get(STy, Cts);
+}
+
template<typename T>
Constant* JavaAOTCompiler::CreateConstantFromIntArray(const T* val, const Type* Ty) {
+ assert(!useCooperativeGC());
std::vector<const Type*> Elemts;
const ArrayType* ATy = ArrayType::get(Ty, T::getSize(val));
Elemts.push_back(JavaIntrinsics.JavaObjectType->getContainedType(0));
@@ -1257,6 +1367,7 @@
template<typename T>
Constant* JavaAOTCompiler::CreateConstantFromFPArray(const T* val, const Type* Ty) {
+ assert(!useCooperativeGC());
std::vector<const Type*> Elemts;
const ArrayType* ATy = ArrayType::get(Ty, T::getSize(val));
Elemts.push_back(JavaIntrinsics.JavaObjectType->getContainedType(0));
@@ -1282,6 +1393,7 @@
}
Constant* JavaAOTCompiler::CreateConstantFromObjectArray(const ArrayObject* val) {
+ assert(!useCooperativeGC());
std::vector<const Type*> Elemts;
const llvm::Type* Ty = JavaIntrinsics.JavaObjectType;
const ArrayType* ATy = ArrayType::get(Ty, ArrayObject::getSize(val));
@@ -1357,6 +1469,25 @@
}
}
+Function* JavaAOTCompiler::getMethodOrStub(JavaMethod* meth) {
+ assert(!isStatic(meth->access));
+ // TODO: check if llvm Function is populated instead of checking code is NULL
+ if (precompile && (meth->code == NULL)) {
+ LLVMSignatureInfo* LSI = getSignatureInfo(meth->getSignature());
+ return LSI->getVirtualStub();
+ } else {
+ return getMethod(meth);
+ }
+}
+
+Function* JavaAOTCompiler::getMethod(JavaMethod* meth) {
+ Function* func = getMethodInfo(meth)->getMethod();
+ if (func->hasExternalWeakLinkage()) {
+ toCompile.push_back(meth);
+ }
+ return func;
+}
+
Constant* JavaAOTCompiler::CreateConstantFromVT(JavaVirtualTable* VT) {
CommonClass* classDef = VT->cl;
uint32 size = classDef->isClass() ? classDef->asClass()->virtualTableSize :
@@ -1376,8 +1507,7 @@
Function* Finalizer = 0;
JavaMethod* meth = (JavaMethod*)(RealVT->destructor);
if (meth) {
- LLVMMethodInfo* LMI = getMethodInfo(meth);
- Finalizer = LMI->getMethod();
+ Finalizer = getMethodOrStub(meth);
}
Elemts.push_back(Finalizer ?
@@ -1499,8 +1629,7 @@
Imeth->type,
false, true, 0);
assert(meth && "No method found");
- LLVMMethodInfo* LMI = getMethodInfo(meth);
- Function* func = LMI->getMethod();
+ Function* func = getMethodOrStub(meth);
IElemts.push_back(ConstantExpr::getBitCast(func, PTy));
} else if (size > 1) {
std::vector<JavaMethod*> methods;
@@ -1521,8 +1650,7 @@
if (SameMethod) {
assert(methods[0] && "No method found");
- LLVMMethodInfo* LMI = getMethodInfo(methods[0]);
- Function* func = LMI->getMethod();
+ Function* func = getMethodOrStub(methods[0]);
IElemts.push_back(ConstantExpr::getBitCast(func, PTy));
} else {
@@ -1541,8 +1669,7 @@
JavaMethod* Cmeth = *it;
assert(Cmeth && "No method found");
- LLVMMethodInfo* LMI = getMethodInfo(Cmeth);
- Function* func = LMI->getMethod();
+ Function* func = getMethodOrStub(Cmeth);
InternalElemts.push_back(
ConstantExpr::getBitCast(getMethodInClass(Imeth), PTy));
InternalElemts.push_back(ConstantExpr::getBitCast(func, PTy));
@@ -1577,8 +1704,7 @@
// methods
for (uint32 i = JavaVirtualTable::getFirstJavaMethodIndex(); i < size; ++i) {
JavaMethod* meth = ((JavaMethod**)RealVT)[i];
- LLVMMethodInfo* LMI = getMethodInfo(meth);
- Function* F = LMI->getMethod();
+ Function* F = getMethodOrStub(meth);
if (isAbstract(meth->access)) {
Elemts.push_back(Constant::getNullValue(PTy));
} else {
@@ -1591,20 +1717,13 @@
return Array;
}
-namespace mvm {
- llvm::FunctionPass* createEscapeAnalysisPass(llvm::Function*);
-}
-
-namespace j3 {
- llvm::FunctionPass* createLowerConstantCallsPass();
-}
-
JavaAOTCompiler::JavaAOTCompiler(const std::string& ModuleID) :
JavaLLVMCompiler(ModuleID) {
generateStubs = true;
assumeCompiled = false;
compileRT = false;
+ precompile = false;
std::vector<const llvm::Type*> llvmArgs;
llvmArgs.push_back(JavaIntrinsics.ptrType); // class loader.
@@ -1662,7 +1781,7 @@
fprintf(stderr, "Number of static instances : %llu\n",
(unsigned long long int) staticInstances.size());
fprintf(stderr, "Number of constant pools : %llu\n",
- (unsigned long long int) constantPools.size());
+ (unsigned long long int) resolvedConstantPools.size());
fprintf(stderr, "Number of strings : %llu\n",
(unsigned long long int) strings.size());
fprintf(stderr, "Number of native functions : %llu\n",
@@ -1752,8 +1871,7 @@
for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) {
JavaMethod& meth = cl->virtualMethods[i];
if (!isAbstract(meth.access)) {
- LLVMMethodInfo* LMI = getMethodInfo(&meth);
- Function* func = LMI->getMethod();
+ Function* func = getMethod(&meth);
func->addFnAttr(Attribute::NoInline);
}
}
@@ -1761,8 +1879,7 @@
for (uint32 i = 0; i < cl->nbStaticMethods; ++i) {
JavaMethod& meth = cl->staticMethods[i];
if (!isAbstract(meth.access)) {
- LLVMMethodInfo* LMI = getMethodInfo(&meth);
- Function* func = LMI->getMethod();
+ Function* func = getMethod(&meth);
func->addFnAttr(Attribute::NoInline);
}
}
@@ -1786,7 +1903,6 @@
}
if (!cl->super) VT->destructor = 0;
-
}
void JavaAOTCompiler::makeIMT(Class* cl) {
@@ -1807,7 +1923,6 @@
const UTF8* methCl = 0;
ctpInfo->nameOfStaticOrSpecialMethod(index, methCl, name, signature);
-
fprintf(stderr, "Warning: emitting a callback from %s (%s.%s)\n",
UTF8Buffer(cl->name).cString(), UTF8Buffer(methCl).cString(),
UTF8Buffer(name).cString());
@@ -1923,52 +2038,36 @@
M->addJavaPasses();
- // First resolve everyone so that there can not be unknown references in
- // constant pools.
- for (std::vector<Class*>::iterator i = classes.begin(),
- e = classes.end(); i != e; ++i) {
- Class* cl = *i;
- cl->resolveClass();
- cl->setOwnerClass(JavaThread::get());
-
- for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) {
- LLVMMethodInfo* LMI = M->getMethodInfo(&cl->virtualMethods[i]);
- LMI->getMethod();
- }
-
- for (uint32 i = 0; i < cl->nbStaticMethods; ++i) {
- LLVMMethodInfo* LMI = M->getMethodInfo(&cl->staticMethods[i]);
- LMI->getMethod();
- }
+ // First resolve everyone so that there can not be unknown references in
+ // constant pools.
+ for (std::vector<Class*>::iterator i = classes.begin(),
+ e = classes.end(); i != e; ++i) {
+ Class* cl = *i;
+ cl->resolveClass();
+ cl->setOwnerClass(JavaThread::get());
+
+ for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) {
+ M->getMethod(&cl->virtualMethods[i]);
+ }
+ for (uint32 i = 0; i < cl->nbStaticMethods; ++i) {
+ M->getMethod(&cl->staticMethods[i]);
}
- if (!M->clinits->empty()) {
- vm->loadBootstrap();
+ }
- for (std::vector<std::string>::iterator i = M->clinits->begin(),
- e = M->clinits->end(); i != e; ++i) {
-
- if (i->at(i->length() - 1) == '*') {
- for (std::vector<Class*>::iterator ii = classes.begin(),
- ee = classes.end(); ii != ee; ++ii) {
- Class* cl = *ii;
- if (!strncmp(UTF8Buffer(cl->name).cString(), i->c_str(),
- i->length() - 1)) {
- TRY {
- cl->asClass()->initialiseClass(vm);
- } CATCH {
- fprintf(stderr, "Error when initializing %s\n",
- UTF8Buffer(cl->name).cString());
- abort();
- } END_CATCH;
- }
- }
- } else {
+ if (!M->clinits->empty()) {
+ vm->loadBootstrap();
- const UTF8* name = bootstrapLoader->asciizConstructUTF8(i->c_str());
- CommonClass* cl = bootstrapLoader->lookupClass(name);
- if (cl && cl->isClass()) {
+ for (std::vector<std::string>::iterator i = M->clinits->begin(),
+ e = M->clinits->end(); i != e; ++i) {
+
+ if (i->at(i->length() - 1) == '*') {
+ for (std::vector<Class*>::iterator ii = classes.begin(),
+ ee = classes.end(); ii != ee; ++ii) {
+ Class* cl = *ii;
+ if (!strncmp(UTF8Buffer(cl->name).cString(), i->c_str(),
+ i->length() - 1)) {
TRY {
cl->asClass()->initialiseClass(vm);
} CATCH {
@@ -1976,88 +2075,102 @@
UTF8Buffer(cl->name).cString());
abort();
} END_CATCH;
- } else {
- fprintf(stderr, "Class %s does not exist or is an array class.\n",
- i->c_str());
}
}
- }
- bootstrapLoader->setCompiler(M);
- }
-
- for (std::vector<Class*>::iterator i = classes.begin(), e = classes.end();
- i != e; ++i) {
- Class* cl = *i;
- cl->setOwnerClass(JavaThread::get());
- }
-
- for (std::vector<Class*>::iterator i = classes.begin(), e = classes.end();
- i != e; ++i) {
- Class* cl = *i;
- M->compileClass(cl);
- }
+ } else {
- } else {
- M->addJavaPasses();
- char* realName = (char*)allocator.Allocate(size + 1);
- if (size > 6 && !strcmp(&name[size - 6], ".class")) {
- memcpy(realName, name, size - 6);
- realName[size - 6] = 0;
- } else {
- memcpy(realName, name, size + 1);
- }
-
- const UTF8* utf8 = bootstrapLoader->asciizConstructUTF8(realName);
- UserClass* cl = bootstrapLoader->loadName(utf8, true, true, NULL);
-
- if (!M->clinits->empty()) {
- vm->loadBootstrap();
- cl->initialiseClass(vm);
- bootstrapLoader->setCompiler(M);
+ const UTF8* name = bootstrapLoader->asciizConstructUTF8(i->c_str());
+ CommonClass* cl = bootstrapLoader->lookupClass(name);
+ if (cl && cl->isClass()) {
+ TRY {
+ cl->asClass()->initialiseClass(vm);
+ } CATCH {
+ fprintf(stderr, "Error when initializing %s\n",
+ UTF8Buffer(cl->name).cString());
+ abort();
+ } END_CATCH;
+ } else {
+ fprintf(stderr, "Class %s does not exist or is an array class.\n",
+ i->c_str());
+ }
+ }
}
-
+ bootstrapLoader->setCompiler(M);
+ }
+
+ for (std::vector<Class*>::iterator i = classes.begin(), e = classes.end();
+ i != e; ++i) {
+ Class* cl = *i;
cl->setOwnerClass(JavaThread::get());
- cl->resolveInnerOuterClasses();
- for (uint32 i = 0; i < cl->nbInnerClasses; ++i) {
- cl->innerClasses[i]->setOwnerClass(JavaThread::get());
- M->compileClass(cl->innerClasses[i]);
- }
+ }
+
+ for (std::vector<Class*>::iterator i = classes.begin(), e = classes.end();
+ i != e; ++i) {
+ Class* cl = *i;
M->compileClass(cl);
}
-
- if (M->compileRT) {
- // Make sure that if we compile RT, the native classes are emitted.
- M->getNativeClass(bootstrapLoader->upcalls->OfVoid);
- M->getNativeClass(bootstrapLoader->upcalls->OfBool);
- M->getNativeClass(bootstrapLoader->upcalls->OfByte);
- M->getNativeClass(bootstrapLoader->upcalls->OfChar);
- M->getNativeClass(bootstrapLoader->upcalls->OfShort);
- M->getNativeClass(bootstrapLoader->upcalls->OfInt);
- M->getNativeClass(bootstrapLoader->upcalls->OfFloat);
- M->getNativeClass(bootstrapLoader->upcalls->OfLong);
- M->getNativeClass(bootstrapLoader->upcalls->OfDouble);
- // Also do not allow inling of some functions.
+ } else {
+ M->addJavaPasses();
+ char* realName = (char*)allocator.Allocate(size + 1);
+ if (size > 6 && !strcmp(&name[size - 6], ".class")) {
+ memcpy(realName, name, size - 6);
+ realName[size - 6] = 0;
+ } else {
+ memcpy(realName, name, size + 1);
+ }
+
+ const UTF8* utf8 = bootstrapLoader->asciizConstructUTF8(realName);
+ UserClass* cl = bootstrapLoader->loadName(utf8, true, true, NULL);
+
+ if (!M->clinits->empty()) {
+ vm->loadBootstrap();
+ cl->initialiseClass(vm);
+ bootstrapLoader->setCompiler(M);
+ }
+
+ cl->setOwnerClass(JavaThread::get());
+ cl->resolveInnerOuterClasses();
+ for (uint32 i = 0; i < cl->nbInnerClasses; ++i) {
+ cl->innerClasses[i]->setOwnerClass(JavaThread::get());
+ M->compileClass(cl->innerClasses[i]);
+ }
+ M->compileClass(cl);
+ }
+
+ if (M->compileRT) {
+ // Make sure that if we compile RT, the native classes are emitted.
+ M->getNativeClass(bootstrapLoader->upcalls->OfVoid);
+ M->getNativeClass(bootstrapLoader->upcalls->OfBool);
+ M->getNativeClass(bootstrapLoader->upcalls->OfByte);
+ M->getNativeClass(bootstrapLoader->upcalls->OfChar);
+ M->getNativeClass(bootstrapLoader->upcalls->OfShort);
+ M->getNativeClass(bootstrapLoader->upcalls->OfInt);
+ M->getNativeClass(bootstrapLoader->upcalls->OfFloat);
+ M->getNativeClass(bootstrapLoader->upcalls->OfLong);
+ M->getNativeClass(bootstrapLoader->upcalls->OfDouble);
+
+ // Also do not allow inling of some functions.
#define SET_INLINE(NAME) { \
- const UTF8* name = bootstrapLoader->asciizConstructUTF8(NAME); \
- Class* cl = (Class*)bootstrapLoader->lookupClass(name); \
- if (cl) M->setNoInline(cl); }
-
- SET_INLINE("java/util/concurrent/atomic/AtomicReferenceFieldUpdater")
- SET_INLINE("java/util/concurrent/atomic/AtomicReferenceFieldUpdater"
- "$AtomicReferenceFieldUpdaterImpl")
- SET_INLINE("java/util/concurrent/atomic/AtomicIntegerFieldUpdater")
- SET_INLINE("java/util/concurrent/atomic/AtomicIntegerFieldUpdater"
- "$AtomicIntegerFieldUpdaterImpl")
- SET_INLINE("java/util/concurrent/atomic/AtomicLongFieldUpdater")
- SET_INLINE("java/util/concurrent/atomic/AtomicLongFieldUpdater"
- "$CASUpdater")
- SET_INLINE("java/util/concurrent/atomic/AtomicLongFieldUpdater"
- "$LockedUpdater")
+ const UTF8* name = bootstrapLoader->asciizConstructUTF8(NAME); \
+ Class* cl = (Class*)bootstrapLoader->lookupClass(name); \
+ if (cl) M->setNoInline(cl); }
+
+ SET_INLINE("java/util/concurrent/atomic/AtomicReferenceFieldUpdater")
+ SET_INLINE("java/util/concurrent/atomic/AtomicReferenceFieldUpdater"
+ "$AtomicReferenceFieldUpdaterImpl")
+ SET_INLINE("java/util/concurrent/atomic/AtomicIntegerFieldUpdater")
+ SET_INLINE("java/util/concurrent/atomic/AtomicIntegerFieldUpdater"
+ "$AtomicIntegerFieldUpdaterImpl")
+ SET_INLINE("java/util/concurrent/atomic/AtomicLongFieldUpdater")
+ SET_INLINE("java/util/concurrent/atomic/AtomicLongFieldUpdater"
+ "$CASUpdater")
+ SET_INLINE("java/util/concurrent/atomic/AtomicLongFieldUpdater"
+ "$LockedUpdater")
#undef SET_INLINE
- }
+ }
- M->CreateStaticInitializer();
+ M->CreateStaticInitializer();
end:
@@ -2072,6 +2185,42 @@
vm->waitForExit();
}
+void JavaAOTCompiler::compileClassLoader(JnjvmBootstrapLoader* loader) {
+ loader->setCompiler(this);
+ compileRT = true;
+ precompile = true;
+ addJavaPasses();
+
+ for (ClassMap::iterator i = loader->getClasses()->map.begin(),
+ e = loader->getClasses()->map.end(); i!= e; ++i) {
+ getNativeClass(i->second);
+ if (i->second->isClass()) {
+ Class* cl = i->second->asClass();
+ for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) {
+ JavaMethod& meth = cl->virtualMethods[i];
+ if (meth.code != NULL) parseFunction(&meth);
+ }
+
+ for (uint32 i = 0; i < cl->nbStaticMethods; ++i) {
+ JavaMethod& meth = cl->staticMethods[i];
+ if (meth.code != NULL) parseFunction(&meth);
+ }
+ }
+ }
+
+ while (!toCompile.empty()) {
+ JavaMethod* meth = toCompile.back();
+ toCompile.pop_back();
+ getNativeClass(meth->classDef);
+ parseFunction(meth);
+ }
+
+ for (native_class_iterator i = nativeClasses.begin(),
+ e = nativeClasses.end(); i != e; ++i) {
+ AddInitializerToClass(i->second, i->first);
+ }
+}
+
/// compileAllStubs - Compile all the native -> Java stubs.
/// TODO: Once LLVM supports va_arg, enable AP.
///
Modified: vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp?rev=134923&r1=134922&r2=134923&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp Mon Jul 11 16:28:04 2011
@@ -236,7 +236,7 @@
return GetElementPtrInst::Create(mutatorThreadPtr, GEP, GEP + 3, "", currentBlock);
}
-llvm::Value* JavaJIT::getDoYieldPtr(llvm::Value* mutatorThreadPtr) {
+llvm::Value* JavaJIT::getDoYieldPtr(llvm::Value* mutatorThreadPtr) {
Value* GEP[3] = { intrinsics->constantZero,
intrinsics->OffsetThreadInMutatorThreadConstant,
intrinsics->OffsetDoYieldInThreadConstant };
@@ -1195,14 +1195,14 @@
uint8 type = ctpInfo->typeAt(index);
if (type == JavaConstantPool::ConstantString) {
- if (TheCompiler->isStaticCompiling()) {
+ if (TheCompiler->isStaticCompiling() && !TheCompiler->useCooperativeGC()) {
const UTF8* utf8 = ctpInfo->UTF8At(ctpInfo->ctpDef[index]);
JavaString* str = *(compilingClass->classLoader->UTF8ToStr(utf8));
Value* val = TheCompiler->getString(str);
push(val, false, upcalls->newString);
} else {
JavaString** str = (JavaString**)ctpInfo->ctpRes[index];
- if (str) {
+ if ((str != NULL) && !TheCompiler->isStaticCompiling()) {
Value* val = TheCompiler->getStringPtr(str);
val = new LoadInst(val, "", currentBlock);
push(val, false, upcalls->newString);
@@ -1468,11 +1468,7 @@
ctpInfo->nameOfStaticOrSpecialMethod(index, cl, name, signature);
LLVMSignatureInfo* LSI = TheCompiler->getSignatureInfo(signature);
const llvm::FunctionType* virtualType = LSI->getVirtualType();
- llvm::Instruction* val = 0;
-
- if (!meth) {
- meth = ctpInfo->infoOfStaticOrSpecialMethod(index, ACC_VIRTUAL, signature);
- }
+ meth = ctpInfo->infoOfStaticOrSpecialMethod(index, ACC_VIRTUAL, signature);
Value* func = 0;
bool needsInit = false;
@@ -1502,6 +1498,7 @@
return;
}
+ llvm::Instruction* val = 0;
if (meth && canBeInlined(meth)) {
val = invokeInline(meth, args);
} else {
@@ -1598,7 +1595,7 @@
// This makes unswitch loop very unhappy time-wise, but makes GVN happy
// number-wise. IMO, it's better to have this than Unswitch.
JavaConstantPool* ctp = compilingClass->ctpInfo;
- Value* CTP = TheCompiler->getConstantPool(ctp);
+ Value* CTP = TheCompiler->getResolvedConstantPool(ctp);
Value* Cl = TheCompiler->getNativeClass(compilingClass);
std::vector<Value*> Args;
@@ -2139,8 +2136,8 @@
Args.push_back(targetObject);
Args.push_back(Meth);
Args.push_back(Index);
- Value* node =
- invoke(intrinsics->ResolveInterfaceFunction, Args, "", currentBlock);
+ Value* node = invoke(intrinsics->ResolveInterfaceFunction,
+ Args, "invokeinterface", currentBlock);
node = new BitCastInst(node, virtualPtrType, "", currentBlock);
#endif
Modified: vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp?rev=134923&r1=134922&r2=134923&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp Mon Jul 11 16:28:04 2011
@@ -100,12 +100,12 @@
return ConstantExpr::getIntToPtr(CI, Ty);
}
-Constant* JavaJITCompiler::getConstantPool(JavaConstantPool* ctp) {
+Constant* JavaJITCompiler::getResolvedConstantPool(JavaConstantPool* ctp) {
void* ptr = ctp->ctpRes;
assert(ptr && "No constant pool found");
ConstantInt* CI = ConstantInt::get(Type::getInt64Ty(getLLVMContext()),
uint64_t(ptr));
- return ConstantExpr::getIntToPtr(CI, JavaIntrinsics.ConstantPoolType);
+ return ConstantExpr::getIntToPtr(CI, JavaIntrinsics.ResolvedConstantPoolType);
}
Constant* JavaJITCompiler::getMethodInClass(JavaMethod* meth) {
@@ -449,7 +449,7 @@
}
}
// Load the constant pool.
- Value* CTP = getConstantPool(ctpInfo);
+ Value* CTP = getResolvedConstantPool(ctpInfo);
Value* Index = ConstantInt::get(Type::getInt32Ty(insert->getContext()),
index);
Value* func = GetElementPtrInst::Create(CTP, Index, "", insert);
Modified: vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp?rev=134923&r1=134922&r2=134923&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp Mon Jul 11 16:28:04 2011
@@ -591,7 +591,7 @@
// Lock here because we are called by arbitrary code
mvm::MvmModule::protectIR();
std::vector<const llvm::Type*> Args;
- Args.push_back(Compiler->getIntrinsics()->ConstantPoolType); // ctp
+ Args.push_back(Compiler->getIntrinsics()->ResolvedConstantPoolType); // ctp
Args.push_back(getVirtualPtrType());
Args.push_back(Compiler->getIntrinsics()->JavaObjectType);
Args.push_back(Compiler->AssessorInfo[I_LONG].llvmTypePtr);
@@ -608,7 +608,7 @@
// Lock here because we are called by arbitrary code
mvm::MvmModule::protectIR();
std::vector<const llvm::Type*> Args;
- Args.push_back(Compiler->getIntrinsics()->ConstantPoolType); // ctp
+ Args.push_back(Compiler->getIntrinsics()->ResolvedConstantPoolType); // ctp
Args.push_back(getStaticPtrType());
Args.push_back(Compiler->AssessorInfo[I_LONG].llvmTypePtr);
LLVMAssessorInfo& LAI =
Modified: vmkit/trunk/lib/J3/LLVMRuntime/runtime-single.ll
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/LLVMRuntime/runtime-single.ll?rev=134923&r1=134922&r2=134923&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/LLVMRuntime/runtime-single.ll (original)
+++ vmkit/trunk/lib/J3/LLVMRuntime/runtime-single.ll Mon Jul 11 16:28:04 2011
@@ -5,8 +5,9 @@
%JavaCommonClass = type { [1 x %JavaObject*], i16,
%JavaClass**, i16, %UTF8*, %JavaClass*, i8*, %VT* }
+%ClassBytes = type { i32, i8* }
%JavaClass = type { %JavaCommonClass, i32, i32, [1 x %TaskClassMirror],
%JavaField*, i16, %JavaField*, i16, %JavaMethod*, i16,
- %JavaMethod*, i16, i8*, %ArrayUInt8*, i8*, %Attribut*,
+ %JavaMethod*, i16, i8*, %ClassBytes*, %JavaConstantPool*, %Attribut*,
i16, %JavaClass**, i16, %JavaClass*, i16, i8, i8, i32, i32 }
Modified: vmkit/trunk/lib/J3/VMCore/JavaClass.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaClass.cpp?rev=134923&r1=134922&r2=134923&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaClass.cpp (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaClass.cpp Mon Jul 11 16:28:04 2011
@@ -605,7 +605,7 @@
} else {
InitStaticField((uint64)ctpInfo->IntegerAt(idx));
}
- } else if (type->isReference()){
+ } else if (type->isReference()) {
const UTF8* utf8 = ctpInfo->UTF8At(ctpInfo->ctpDef[idx]);
InitStaticField((JavaObject*)ctpInfo->resolveString(utf8, idx));
} else {
Modified: vmkit/trunk/lib/J3/VMCore/JavaClass.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaClass.h?rev=134923&r1=134922&r2=134923&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaClass.h (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaClass.h Mon Jul 11 16:28:04 2011
@@ -848,7 +848,7 @@
Virtual
};
- /// constructMethod - Create a new method.
+ /// initialise - Create a new method.
///
void initialise(Class* cl, const UTF8* name, const UTF8* type, uint16 access);
Modified: vmkit/trunk/lib/J3/VMCore/JavaConstantPool.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaConstantPool.cpp?rev=134923&r1=134922&r2=134923&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaConstantPool.cpp (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaConstantPool.cpp Mon Jul 11 16:28:04 2011
@@ -290,6 +290,8 @@
temp = loader->loadName(name, resolve, false, NULL);
}
ctpRes[index] = temp;
+ } else if (resolve && temp->isClass()) {
+ temp->asClass()->resolveClass();
}
return temp;
}
@@ -303,9 +305,14 @@
temp = loader->lookupClassOrArray(name);
}
- if (!temp && classDef->classLoader->getCompiler()->isStaticCompiling()) {
- temp = loadClass(index);
+ if (classDef->classLoader->getCompiler()->isStaticCompiling()) {
+ if (temp == NULL) {
+ temp = loadClass(index, true);
+ } else if (temp->isClass()) {
+ temp->asClass()->resolveClass();
+ }
}
+
return temp;
}
Modified: vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp?rev=134923&r1=134922&r2=134923&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp (original)
+++ vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp Mon Jul 11 16:28:04 2011
@@ -1198,6 +1198,10 @@
JavaField& field = realCl->staticFields[i];
JCL->hashUTF8->insert(field.name);
JCL->hashUTF8->insert(field.type);
+ if (field.getSignature()->isReference()
+ && (field.lookupAttribut(Attribut::constantAttribut) != NULL)) {
+ field.InitStaticField(JCL->getIsolate());
+ }
}
for (uint32 i = 0; i< realCl->nbVirtualFields; ++i) {
@@ -1207,9 +1211,9 @@
}
}
- if (!cl->isPrimitive())
+ if (!cl->isPrimitive()) {
JCL->getClasses()->map.insert(std::make_pair(cl->name, cl));
-
+ }
}
extern "C" void vmjcGetClassArray(JnjvmClassLoader* JCL, ClassArray** ptr,
Modified: vmkit/trunk/lib/J3/VMCore/Reader.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Reader.h?rev=134923&r1=134922&r2=134923&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/Reader.h (original)
+++ vmkit/trunk/lib/J3/VMCore/Reader.h Mon Jul 11 16:28:04 2011
@@ -41,8 +41,6 @@
class Reader {
public:
- // bytes - Pointer to a reference array. The array is not manipulated directly
- // in order to support copying GC.
ClassBytes* bytes;
uint32 min;
uint32 cursor;
Modified: vmkit/trunk/lib/Mvm/Compiler/JIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Compiler/JIT.cpp?rev=134923&r1=134922&r2=134923&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/Compiler/JIT.cpp (original)
+++ vmkit/trunk/lib/Mvm/Compiler/JIT.cpp Mon Jul 11 16:28:04 2011
@@ -316,10 +316,6 @@
void MvmModule::runPasses(llvm::Function* func,
llvm::FunctionPassManager* pm) {
- // Take the lock because the pass manager will call materializeFunction.
- // Our implementation of materializeFunction requires that the lock is held
- // by the caller. This is due to LLVM's JIT subsystem where the call to
- // materializeFunction is guarded.
pm->run(*func);
}
Modified: vmkit/trunk/tools/Makefile
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/Makefile?rev=134923&r1=134922&r2=134923&view=diff
==============================================================================
--- vmkit/trunk/tools/Makefile (original)
+++ vmkit/trunk/tools/Makefile Mon Jul 11 16:28:04 2011
@@ -10,7 +10,7 @@
include $(LEVEL)/Makefile.config
-PARALLEL_DIRS = j3 vmjc llcj
+PARALLEL_DIRS = j3 vmjc llcj precompiler
include $(LEVEL)/Makefile.common
Added: vmkit/trunk/tools/precompiler/Makefile
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/precompiler/Makefile?rev=134923&view=auto
==============================================================================
--- vmkit/trunk/tools/precompiler/Makefile (added)
+++ vmkit/trunk/tools/precompiler/Makefile Mon Jul 11 16:28:04 2011
@@ -0,0 +1,18 @@
+##===- tools/precompiler/Makefile --------------------------*- Makefile -*-===##
+#
+# The VMKit project
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+LEVEL = ../..
+
+include $(LEVEL)/Makefile.config
+
+TOOLNAME = precompiler
+USEDLIBS = Classpath.a J3.a J3Compiler.a Mvm.a MvmCompiler.a CommonThread.a FinalMMTk.a InlineMMTk.a
+BUILD_FRAMETABLE = 1
+LINK_COMPONENTS = jit nativecodegen scalaropts instrumentation ipa ipo asmparser linker bitwriter
+
+include $(LEVEL)/Makefile.common
Propchange: vmkit/trunk/tools/precompiler/Makefile
------------------------------------------------------------------------------
svn:executable = *
Added: vmkit/trunk/tools/precompiler/Precompiler.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/precompiler/Precompiler.cpp?rev=134923&view=auto
==============================================================================
--- vmkit/trunk/tools/precompiler/Precompiler.cpp (added)
+++ vmkit/trunk/tools/precompiler/Precompiler.cpp Mon Jul 11 16:28:04 2011
@@ -0,0 +1,88 @@
+//===------------------------ Precompiler.cpp -----------------------------===//
+// Run a program and emit code for classes loaded by the bootstrap loader -===//
+//
+// The VMKit project
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/ManagedStatic.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Bitcode/ReaderWriter.h"
+#include "llvm/Support/Signals.h"
+
+#include "MvmGC.h"
+#include "mvm/JIT.h"
+#include "mvm/MethodInfo.h"
+#include "mvm/Object.h"
+#include "mvm/VirtualMachine.h"
+#include "mvm/Threads/Thread.h"
+
+#include "j3/JavaAOTCompiler.h"
+#include "j3/JavaJITCompiler.h"
+#include "../../lib/J3/VMCore/JnjvmClassLoader.h"
+#include "../../lib/J3/VMCore/Jnjvm.h"
+
+#include <string>
+
+extern llvm::cl::opt<bool> StandardCompileOpts;
+
+using namespace j3;
+using namespace mvm;
+
+#include "FrametablesExterns.inc"
+
+CamlFrames* frametables[] = {
+ #include "FrametablesSymbols.inc"
+};
+
+int main(int argc, char **argv, char **envp) {
+ llvm::llvm_shutdown_obj X;
+
+ // Initialize base components.
+ MvmModule::initialise();
+ Collector::initialise();
+
+ // Tell the compiler to run all optimizations.
+ StandardCompileOpts = true;
+
+ // Create the allocator that will allocate the bootstrap loader and the JVM.
+ mvm::BumpPtrAllocator Allocator;
+ JavaJITCompiler* JIT = JavaJITCompiler::CreateCompiler("JIT");
+ JnjvmBootstrapLoader* loader = new(Allocator, "Bootstrap loader")
+ JnjvmBootstrapLoader(Allocator, JIT, true);
+ Jnjvm* vm = new(Allocator, "VM") Jnjvm(Allocator, (CamlFrames**)frametables, loader);
+
+ // Run the application.
+ vm->runApplication(argc, argv);
+ vm->waitForExit();
+
+ // Now AOT Compile all compiled methods.
+ JavaAOTCompiler* AOT = new JavaAOTCompiler("AOT");
+ AOT->compileClassLoader(loader);
+
+ AOT->printStats();
+
+ // Emit the bytecode in file.
+ std::string OutputFilename = "generated.bc";
+ std::string ErrorInfo;
+ std::auto_ptr<llvm::raw_ostream> Out
+ (new llvm::raw_fd_ostream(OutputFilename.c_str(), ErrorInfo,
+ llvm::raw_fd_ostream::F_Binary));
+ if (!ErrorInfo.empty()) {
+ llvm::errs() << ErrorInfo << '\n';
+ return 1;
+ }
+
+ // Make sure that the Out file gets unlinked from the disk if we get a
+ // SIGINT.
+ llvm::sys::RemoveFileOnSignal(llvm::sys::Path(OutputFilename));
+
+ llvm::WriteBitcodeToFile(AOT->getLLVMModule(), *Out);
+
+ return 0;
+}
Added: vmkit/trunk/tools/precompiler/trainer/HelloWorld.java
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/precompiler/trainer/HelloWorld.java?rev=134923&view=auto
==============================================================================
--- vmkit/trunk/tools/precompiler/trainer/HelloWorld.java (added)
+++ vmkit/trunk/tools/precompiler/trainer/HelloWorld.java Mon Jul 11 16:28:04 2011
@@ -0,0 +1,8 @@
+class HelloWorld {
+
+ public static final String str = "Hello World";
+
+ public static void main(String[] args) {
+ System.out.println(str);
+ }
+}
Added: vmkit/trunk/tools/precompiler/trainer/Makefile
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/precompiler/trainer/Makefile?rev=134923&view=auto
==============================================================================
--- vmkit/trunk/tools/precompiler/trainer/Makefile (added)
+++ vmkit/trunk/tools/precompiler/trainer/Makefile Mon Jul 11 16:28:04 2011
@@ -0,0 +1,24 @@
+##===- tools/precompiler/trainer/Makefile ------------------*- Makefile -*-===##
+#
+# The VMKit project
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+LEVEL = ../../..
+
+include $(LEVEL)/Makefile.config
+
+MODULE_WITH_GC = Precompiled
+
+BUILT_SOURCES = generated.bc
+
+include $(LEVEL)/Makefile.common
+
+PRECOMPILER := $(ToolDir)/precompiler$(EXEEXT)
+
+generated.bc: $(PRECOMPILER) HelloWorld.java
+ $(Echo) "Building precompiled bootstrap code"
+ $(Verb) javac HelloWorld.java
+ $(Verb) $(PRECOMPILER) -cp $$PWD HelloWorld
Propchange: vmkit/trunk/tools/precompiler/trainer/Makefile
------------------------------------------------------------------------------
svn:executable = *
More information about the vmkit-commits
mailing list