[vmkit-commits] [vmkit] r58604 - in /vmkit/branches/release_024: include/mvm/ lib/JnJVM/Classpath/ lib/JnJVM/LLVMRuntime/ lib/JnJVM/VMCore/ lib/N3/VMCore/ tools/ tools/jnjvm/ tools/vmjc/ tools/vmkit/
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Mon Nov 3 02:20:57 PST 2008
Author: geoffray
Date: Mon Nov 3 04:20:55 2008
New Revision: 58604
URL: http://llvm.org/viewvc/llvm-project?rev=58604&view=rev
Log:
Merge from trunk for llvm 2.4 release sync.
Added:
vmkit/branches/release_024/include/mvm/CompilationUnit.h
- copied unchanged from r58603, vmkit/trunk/include/mvm/CompilationUnit.h
vmkit/branches/release_024/tools/vmjc/
- copied from r58603, vmkit/trunk/tools/vmjc/
vmkit/branches/release_024/tools/vmjc/Makefile
- copied unchanged from r58603, vmkit/trunk/tools/vmjc/Makefile
vmkit/branches/release_024/tools/vmjc/vmjc.cpp
- copied unchanged from r58603, vmkit/trunk/tools/vmjc/vmjc.cpp
Modified:
vmkit/branches/release_024/include/mvm/Allocator.h
vmkit/branches/release_024/include/mvm/VirtualMachine.h
vmkit/branches/release_024/lib/JnJVM/Classpath/Classpath.cpp
vmkit/branches/release_024/lib/JnJVM/Classpath/ClasspathReflect.h
vmkit/branches/release_024/lib/JnJVM/Classpath/ClasspathVMClass.cpp
vmkit/branches/release_024/lib/JnJVM/Classpath/ClasspathVMRuntime.cpp
vmkit/branches/release_024/lib/JnJVM/LLVMRuntime/runtime-default.ll
vmkit/branches/release_024/lib/JnJVM/VMCore/JavaCache.cpp
vmkit/branches/release_024/lib/JnJVM/VMCore/JavaCache.h
vmkit/branches/release_024/lib/JnJVM/VMCore/JavaClass.cpp
vmkit/branches/release_024/lib/JnJVM/VMCore/JavaClass.h
vmkit/branches/release_024/lib/JnJVM/VMCore/JavaConstantPool.cpp
vmkit/branches/release_024/lib/JnJVM/VMCore/JavaInitialise.cpp
vmkit/branches/release_024/lib/JnJVM/VMCore/JavaJIT.cpp
vmkit/branches/release_024/lib/JnJVM/VMCore/JavaJIT.h
vmkit/branches/release_024/lib/JnJVM/VMCore/JavaJITOpcodes.cpp
vmkit/branches/release_024/lib/JnJVM/VMCore/JavaMetaJIT.cpp
vmkit/branches/release_024/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp
vmkit/branches/release_024/lib/JnJVM/VMCore/JavaThread.cpp
vmkit/branches/release_024/lib/JnJVM/VMCore/JavaThread.h
vmkit/branches/release_024/lib/JnJVM/VMCore/JavaTypes.cpp
vmkit/branches/release_024/lib/JnJVM/VMCore/JavaUpcalls.cpp
vmkit/branches/release_024/lib/JnJVM/VMCore/JavaUpcalls.h
vmkit/branches/release_024/lib/JnJVM/VMCore/Jni.cpp
vmkit/branches/release_024/lib/JnJVM/VMCore/Jnjvm.cpp
vmkit/branches/release_024/lib/JnJVM/VMCore/Jnjvm.h
vmkit/branches/release_024/lib/JnJVM/VMCore/JnjvmClassLoader.cpp
vmkit/branches/release_024/lib/JnJVM/VMCore/JnjvmClassLoader.h
vmkit/branches/release_024/lib/JnJVM/VMCore/JnjvmModule.cpp
vmkit/branches/release_024/lib/JnJVM/VMCore/JnjvmModule.h
vmkit/branches/release_024/lib/JnJVM/VMCore/JnjvmModuleProvider.cpp
vmkit/branches/release_024/lib/JnJVM/VMCore/LowerConstantCalls.cpp
vmkit/branches/release_024/lib/JnJVM/VMCore/NativeUtil.cpp
vmkit/branches/release_024/lib/JnJVM/VMCore/Reader.cpp
vmkit/branches/release_024/lib/JnJVM/VMCore/Reader.h
vmkit/branches/release_024/lib/JnJVM/VMCore/VirtualTables.cpp
vmkit/branches/release_024/lib/JnJVM/VMCore/Zip.h
vmkit/branches/release_024/lib/N3/VMCore/CLIJit.cpp
vmkit/branches/release_024/lib/N3/VMCore/N3.h
vmkit/branches/release_024/lib/N3/VMCore/N3Initialise.cpp
vmkit/branches/release_024/lib/N3/VMCore/Opcodes.cpp
vmkit/branches/release_024/lib/N3/VMCore/VirtualMachine.h
vmkit/branches/release_024/tools/Makefile
vmkit/branches/release_024/tools/jnjvm/Main.cpp
vmkit/branches/release_024/tools/vmkit/CommandLine.cpp
vmkit/branches/release_024/tools/vmkit/CommandLine.h
vmkit/branches/release_024/tools/vmkit/Launcher.cpp
Modified: vmkit/branches/release_024/include/mvm/Allocator.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/include/mvm/Allocator.h?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/include/mvm/Allocator.h (original)
+++ vmkit/branches/release_024/include/mvm/Allocator.h Mon Nov 3 04:20:55 2008
@@ -232,6 +232,10 @@
void operator delete(void* ptr) {
free(ptr);
}
+
+ void* operator new [](size_t sz, BumpPtrAllocator& allocator) {
+ return allocator.Allocate(sz);
+ }
};
} // end namespace mvm
Modified: vmkit/branches/release_024/include/mvm/VirtualMachine.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/include/mvm/VirtualMachine.h?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/include/mvm/VirtualMachine.h (original)
+++ vmkit/branches/release_024/include/mvm/VirtualMachine.h Mon Nov 3 04:20:55 2008
@@ -15,6 +15,7 @@
#ifndef MVM_VIRTUALMACHINE_H
#define MVM_VIRTUALMACHINE_H
+#include "mvm/CompilationUnit.h"
#include "mvm/Object.h"
namespace mvm {
@@ -29,12 +30,16 @@
/// runApplication - Run an application. The application name is in
/// the arguments, hence it is the virtual machine's job to parse them.
virtual void runApplication(int argc, char** argv) = 0;
+
+ /// compile - Compile a given file to LLVM.
+ virtual void compile(const char* name) = 0;
+
- static void initialiseJVM();
- static VirtualMachine* createJVM();
+ static CompilationUnit* initialiseJVM(bool staticCompilation = false);
+ static VirtualMachine* createJVM(CompilationUnit* C = 0);
- static void initialiseCLIVM();
- static VirtualMachine* createCLIVM();
+ static CompilationUnit* initialiseCLIVM();
+ static VirtualMachine* createCLIVM(CompilationUnit* C = 0);
};
Modified: vmkit/branches/release_024/lib/JnJVM/Classpath/Classpath.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/JnJVM/Classpath/Classpath.cpp?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/JnJVM/Classpath/Classpath.cpp (original)
+++ vmkit/branches/release_024/lib/JnJVM/Classpath/Classpath.cpp Mon Nov 3 04:20:55 2008
@@ -32,9 +32,9 @@
verifyNull(Cl);
Jnjvm* vm = JavaThread::get()->isolate;
UserCommonClass* cl = NativeUtil::resolvedImplClass(vm, Cl, true);
- UserClass* methodCl = 0;
- if (cl->lookupMethodDontThrow(Jnjvm::clinitName, Jnjvm::clinitType, true,
- false, methodCl))
+ if (cl->lookupMethodDontThrow(vm->bootstrapLoader->clinitName,
+ vm->bootstrapLoader->clinitType, true,
+ false, 0))
return true;
return false;
Modified: vmkit/branches/release_024/lib/JnJVM/Classpath/ClasspathReflect.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/JnJVM/Classpath/ClasspathReflect.h?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/JnJVM/Classpath/ClasspathReflect.h (original)
+++ vmkit/branches/release_024/lib/JnJVM/Classpath/ClasspathReflect.h Mon Nov 3 04:20:55 2008
@@ -37,7 +37,7 @@
obj->pd->MARK_AND_TRACE;
obj->signers->MARK_AND_TRACE;
obj->constructor->MARK_AND_TRACE;
- obj->vmdata->classLoader->MARK_AND_TRACE;
+ if (obj->vmdata) obj->vmdata->classLoader->MARK_AND_TRACE;
}
};
@@ -54,7 +54,8 @@
obj->JavaObject::CALL_TRACER;
obj->name->MARK_AND_TRACE;
obj->declaringClass->MARK_AND_TRACE;
- obj->slot->classDef->classLoader->MARK_AND_TRACE;
+ // No need to see if classDef != NULL, it must be.
+ if (obj->slot) obj->slot->classDef->classLoader->MARK_AND_TRACE;
}
};
@@ -72,7 +73,7 @@
obj->JavaObject::CALL_TRACER;
obj->name->MARK_AND_TRACE;
obj->declaringClass->MARK_AND_TRACE;
- obj->slot->classDef->classLoader->MARK_AND_TRACE;
+ if (obj->slot) obj->slot->classDef->classLoader->MARK_AND_TRACE;
}
};
@@ -87,7 +88,7 @@
static void STATIC_TRACER(JavaObjectConstructor) {
obj->JavaObject::CALL_TRACER;
obj->clazz->MARK_AND_TRACE;
- obj->slot->classDef->classLoader->MARK_AND_TRACE;
+ if (obj->slot) obj->slot->classDef->classLoader->MARK_AND_TRACE;
}
};
Modified: vmkit/branches/release_024/lib/JnJVM/Classpath/ClasspathVMClass.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/JnJVM/Classpath/ClasspathVMClass.cpp?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/JnJVM/Classpath/ClasspathVMClass.cpp (original)
+++ vmkit/branches/release_024/lib/JnJVM/Classpath/ClasspathVMClass.cpp Mon Nov 3 04:20:55 2008
@@ -295,14 +295,11 @@
jclass Cl) {
Jnjvm* vm = JavaThread::get()->isolate;
UserCommonClass* cl = NativeUtil::resolvedImplClass(vm, Cl, false);
- std::vector<UserClass*> * interfaces = cl->getInterfaces();
ArrayObject* ret =
- (ArrayObject*)vm->upcalls->classArrayClass->doNew(interfaces->size(), vm);
- sint32 index = 0;
- for (std::vector<UserClass*>::iterator i = interfaces->begin(),
- e = interfaces->end(); i != e; ++i, ++index) {
- UserClass* klass = *i;
- ret->elements[index] = klass->getClassDelegatee(vm);
+ (ArrayObject*)vm->upcalls->classArrayClass->doNew(cl->nbInterfaces, vm);
+ for (uint16 i = 0; i < cl->nbInterfaces; ++i) {
+ UserClass* klass = cl->interfaces[i];
+ ret->elements[i] = klass->getClassDelegatee(vm);
}
return (jobject)ret;
}
@@ -337,13 +334,11 @@
UserClass* cl = NativeUtil::resolvedImplClass(vm, Cl, false)->asClass();
if (cl) {
cl->resolveInnerOuterClasses();
- std::vector<UserClass*>* innerClasses = cl->getInnerClasses();
UserClassArray* array = vm->upcalls->constructorArrayClass;
- ArrayObject* res = (ArrayObject*)array->doNew(innerClasses->size(), vm);
- uint32 index = 0;
- for (std::vector<UserClass*>::iterator i = innerClasses->begin(),
- e = innerClasses->end(); i!= e; i++) {
- res->elements[index++] = (*i)->getClassDelegatee(vm);
+ ArrayObject* res = (ArrayObject*)array->doNew(cl->nbInnerClasses, vm);
+ for (uint16 i = 0; i < cl->nbInnerClasses; ++i) {
+ UserClass* klass = cl->innerClasses[i];
+ res->elements[i] = klass->getClassDelegatee(vm);
}
return (jobject)res;
}
Modified: vmkit/branches/release_024/lib/JnJVM/Classpath/ClasspathVMRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/JnJVM/Classpath/ClasspathVMRuntime.cpp?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/JnJVM/Classpath/ClasspathVMRuntime.cpp (original)
+++ vmkit/branches/release_024/lib/JnJVM/Classpath/ClasspathVMRuntime.cpp Mon Nov 3 04:20:55 2008
@@ -44,17 +44,18 @@
const UTF8* utf8Lib = strLib->value;
uint32 stLib = strLib->offset;
sint32 lgLib = strLib->count;
- sint32 lgPre = vm->prelib->size;
- sint32 lgPost = vm->postlib->size;
+ sint32 lgPre = vm->bootstrapLoader->prelib->size;
+ sint32 lgPost = vm->bootstrapLoader->postlib->size;
uint32 size = (uint32)(lgPre + lgLib + lgPost);
ArrayUInt16* array = (ArrayUInt16*)vm->upcalls->ArrayOfChar->doNew(size, vm);
uint16* elements = array->elements;
- memmove(elements, vm->prelib->elements, lgPre * sizeof(uint16));
+ memmove(elements, vm->bootstrapLoader->prelib->elements,
+ lgPre * sizeof(uint16));
memmove(&(elements[lgPre]), &(utf8Lib->elements[stLib]),
lgLib * sizeof(uint16));
- memmove(&(elements[lgPre + lgLib]), vm->postlib->elements,
+ memmove(&(elements[lgPre + lgLib]), vm->bootstrapLoader->postlib->elements,
lgPost * sizeof(uint16));
return (jobject)(vm->UTF8ToStr((const UTF8*)array));
@@ -72,12 +73,14 @@
jobject _loader) {
JavaString* str = (JavaString*)_str;
Jnjvm* vm = JavaThread::get()->isolate;
-
+ JnjvmClassLoader* loader =
+ JnjvmClassLoader::getJnjvmLoaderFromJavaObject((JavaObject*)_loader, vm);
+
char* buf = str->strToAsciiz();
void* res = dlopen(buf, RTLD_LAZY | RTLD_LOCAL);
if (res != 0) {
- vm->nativeLibs.push_back(res);
+ loader->nativeLibs.push_back(res);
onLoad_t onLoad = (onLoad_t)(intptr_t)dlsym(res, "JNI_OnLoad");
if (onLoad) onLoad(&vm->javavmEnv, 0);
return 1;
Modified: vmkit/branches/release_024/lib/JnJVM/LLVMRuntime/runtime-default.ll
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/JnJVM/LLVMRuntime/runtime-default.ll?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/JnJVM/LLVMRuntime/runtime-default.ll (original)
+++ vmkit/branches/release_024/lib/JnJVM/LLVMRuntime/runtime-default.ll Mon Nov 3 04:20:55 2008
@@ -50,10 +50,8 @@
;;;;; Constant calls for Jnjvm runtime internal objects field accesses ;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;; initialisationCheck - Checks if the class has been initialized and
-;;; initializes if not. This is used for initialization barriers in an isolate
-;;; environment, and in some specific scenario in a single environment.
-declare %JavaClass* @initialisationCheck(%JavaClass*) readnone
+;;; jnjvmRuntimeInitialiseClass - Initialises the class.
+declare %JavaClass* @jnjvmRuntimeInitialiseClass(%JavaClass*) readnone
;;; arrayLength - Get the length of an array.
declare i32 @arrayLength(%JavaObject*) readnone
@@ -95,6 +93,11 @@
;;; specific methods.
declare %JavaObject* @multiCallNew(%JavaClass*, i32, ...)
+;;; initialisationCheck - Checks if the class has been initialized and
+;;; initializes if not. This is used for initialization barriers in an isolate
+;;; environment, and in some specific scenario in a single environment.
+declare %JavaClass* @initialisationCheck(%JavaClass*) readnone
+
;;; forceInitialisationCheck - Force to check initialization. The difference
;;; between this function and the initialisationCheck function is that the
;;; latter is readnone and can thus be removed. This function is removed
Modified: vmkit/branches/release_024/lib/JnJVM/VMCore/JavaCache.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/JnJVM/VMCore/JavaCache.cpp?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/JnJVM/VMCore/JavaCache.cpp (original)
+++ vmkit/branches/release_024/lib/JnJVM/VMCore/JavaCache.cpp Mon Nov 3 04:20:55 2008
@@ -48,7 +48,7 @@
#endif
}
-Enveloppe::Enveloppe(UserConstantPool* ctp, uint32 i) {
+void Enveloppe::initialise(UserConstantPool* ctp, uint32 i) {
mvm::BumpPtrAllocator& allocator = ctp->classDef->classLoader->allocator;
firstCache = new(allocator) CacheNode(this);
ctpInfo = ctp;
Modified: vmkit/branches/release_024/lib/JnJVM/VMCore/JavaCache.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/JnJVM/VMCore/JavaCache.h?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/JnJVM/VMCore/JavaCache.h (original)
+++ vmkit/branches/release_024/lib/JnJVM/VMCore/JavaCache.h Mon Nov 3 04:20:55 2008
@@ -88,7 +88,13 @@
/// Enveloppe - Allocates the linked list with the given constant pool info
/// at the given index, so as the resolution process knows which interface
/// method the invokeinterface bytecode references.
- Enveloppe(UserConstantPool* info, uint32 index);
+ Enveloppe(UserConstantPool* info, uint32 index) {
+ initialise(info, index);
+ }
+
+ Enveloppe() {}
+
+ void initialise(UserConstantPool* info, uint32 index);
};
Modified: vmkit/branches/release_024/lib/JnJVM/VMCore/JavaClass.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/JnJVM/VMCore/JavaClass.cpp?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/JnJVM/VMCore/JavaClass.cpp (original)
+++ vmkit/branches/release_024/lib/JnJVM/VMCore/JavaClass.cpp Mon Nov 3 04:20:55 2008
@@ -41,7 +41,7 @@
const UTF8* Attribut::sourceFileAttribut = 0;
CommonClass* ClassArray::SuperArray;
-std::vector<Class*> ClassArray::InterfacesArray;
+Class** ClassArray::InterfacesArray;
Attribut::Attribut(const UTF8* name, uint32 length,
uint32 offset) {
@@ -53,9 +53,8 @@
}
Attribut* Class::lookupAttribut(const UTF8* key ) {
- for (std::vector<Attribut*>::iterator i = attributs.begin(),
- e = attributs.end(); i!= e; ++i) {
- Attribut* cur = *i;
+ for (uint32 i = 0; i < nbAttributs; ++i) {
+ Attribut* cur = &(attributs[i]);
if (cur->name->equals(key)) return cur;
}
@@ -63,9 +62,8 @@
}
Attribut* JavaField::lookupAttribut(const UTF8* key ) {
- for (std::vector<Attribut*>::iterator i = attributs.begin(),
- e = attributs.end(); i!= e;++i) {
- Attribut* cur = *i;
+ for (uint32 i = 0; i < nbAttributs; ++i) {
+ Attribut* cur = &(attributs[i]);
if (cur->name->equals(key)) return cur;
}
@@ -73,22 +71,14 @@
}
Attribut* JavaMethod::lookupAttribut(const UTF8* key ) {
- for (std::vector<Attribut*>::iterator i = attributs.begin(),
- e = attributs.end(); i!= e; ++i) {
- Attribut* cur = *i;
+ for (uint32 i = 0; i < nbAttributs; ++i) {
+ Attribut* cur = &(attributs[i]);
if (cur->name->equals(key)) return cur;
}
return 0;
}
-bool CommonClass::FieldCmp::operator<(const CommonClass::FieldCmp &cmp) const {
- if (name->lessThan(cmp.name)) return true;
- else if (cmp.name->lessThan(name)) return false;
- else return type->lessThan(cmp.type);
-}
-
-
CommonClass::~CommonClass() {
classLoader->allocator.Deallocate(display);
}
@@ -96,48 +86,50 @@
CommonClass::CommonClass() {
display = 0;
virtualVT = 0;
+ nbVirtualFields = 0;
+ nbStaticFields = 0;
+ nbVirtualMethods = 0;
+ nbStaticMethods = 0;
+ nbInterfaces = 0;
+ access = 0;
}
-Class::Class() {
+Class::Class() : CommonClass() {
ctpInfo = 0;
staticVT = 0;
JInfo = 0;
outerClass = 0;
innerOuterResolved = false;
+ nbInnerClasses = 0;
}
Class::~Class() {
- for (std::vector<Attribut*>::iterator i = attributs.begin(),
- e = attributs.end(); i!= e; ++i) {
- Attribut* cur = *i;
+ for (uint32 i = 0; i < nbAttributs; ++i) {
+ Attribut* cur = &(attributs[i]);
cur->~Attribut();
classLoader->allocator.Deallocate(cur);
}
- for (field_iterator i = staticFields.begin(),
- e = staticFields.end(); i!= e; ++i) {
- JavaField* cur = i->second;
+ for (uint32 i = 0; i < nbStaticFields; ++i) {
+ JavaField* cur = &(staticFields[i]);
cur->~JavaField();
classLoader->allocator.Deallocate(cur);
}
- for (field_iterator i = virtualFields.begin(),
- e = virtualFields.end(); i!= e; ++i) {
- JavaField* cur = i->second;
+ for (uint32 i = 0; i < nbVirtualFields; ++i) {
+ JavaField* cur = &(virtualFields[i]);
cur->~JavaField();
classLoader->allocator.Deallocate(cur);
}
- for (method_iterator i = virtualMethods.begin(),
- e = virtualMethods.end(); i!= e; ++i) {
- JavaMethod* cur = i->second;
+ for (uint32 i = 0; i < nbVirtualMethods; ++i) {
+ JavaMethod* cur = &(virtualMethods[i]);
cur->~JavaMethod();
classLoader->allocator.Deallocate(cur);
}
- for (method_iterator i = staticMethods.begin(),
- e = staticMethods.end(); i!= e; ++i) {
- JavaMethod* cur = i->second;
+ for (uint32 i = 0; i < nbStaticMethods; ++i) {
+ JavaMethod* cur = &(staticMethods[i]);
cur->~JavaMethod();
classLoader->allocator.Deallocate(cur);
}
@@ -156,9 +148,8 @@
}
JavaField::~JavaField() {
- for (std::vector<Attribut*>::iterator i = attributs.begin(),
- e = attributs.end(); i!= e; ++i) {
- Attribut* cur = *i;
+ for (uint32 i = 0; i < nbAttributs; ++i) {
+ Attribut* cur = &(attributs[i]);
cur->~Attribut();
classDef->classLoader->allocator.Deallocate(cur);
}
@@ -166,16 +157,14 @@
JavaMethod::~JavaMethod() {
- for (std::vector<Attribut*>::iterator i = attributs.begin(),
- e = attributs.end(); i!= e; ++i) {
- Attribut* cur = *i;
+ for (uint32 i = 0; i < nbAttributs; ++i) {
+ Attribut* cur = &(attributs[i]);
cur->~Attribut();
classDef->classLoader->allocator.Deallocate(cur);
}
-
- for (std::vector<Enveloppe*>::iterator i = caches.begin(),
- e = caches.end(); i!= e; ++i) {
- Enveloppe* cur = *i;
+
+ for (uint32 i = 0; i < nbEnveloppes; ++i) {
+ Enveloppe* cur = &(enveloppes[i]);
cur->~Enveloppe();
classDef->classLoader->allocator.Deallocate(cur);
}
@@ -271,11 +260,22 @@
CommonClass::CommonClass(JnjvmClassLoader* loader, const UTF8* n,
bool isArray) {
name = n;
- this->virtualVT = 0;
- this->status = loaded;
- this->classLoader = loader;
- this->array = isArray;
- this->primitive = false;
+ virtualVT = 0;
+ status = loaded;
+ classLoader = loader;
+ array = isArray;
+ primitive = false;
+ nbVirtualMethods = 0;
+ nbStaticMethods = 0;
+ nbStaticFields = 0;
+ nbVirtualFields = 0;
+ nbInterfaces = 0;
+ interfaces = 0;
+ virtualMethods = 0;
+ staticMethods = 0;
+ virtualFields = 0;
+ staticFields = 0;
+ access = 0;
#if !defined(ISOLATE) && !defined(ISOLATE_SHARING)
this->delegatee = 0;
#endif
@@ -302,6 +302,7 @@
outerClass = 0;
innerOuterResolved = false;
display = 0;
+ nbInnerClasses = 0;
#if !defined(ISOLATE) && !defined(ISOLATE_SHARING)
_staticInstance = 0;
#endif
@@ -313,6 +314,7 @@
_baseClass = base;
super = ClassArray::SuperArray;
interfaces = ClassArray::InterfacesArray;
+ nbInterfaces = 2;
depth = 1;
display = (CommonClass**)loader->allocator.Allocate(2 * sizeof(CommonClass*));
display[0] = ClassArray::SuperArray;
@@ -413,18 +415,26 @@
const UTF8* type,
bool isStatic,
bool recurse,
- Class*& methodCl) {
+ Class** methodCl) {
- CommonClass::FieldCmp CC(name, type);
- CommonClass::method_map* map = isStatic ? getStaticMethods() :
- getVirtualMethods();
- CommonClass::method_iterator End = map->end();
- CommonClass::method_iterator I = map->find(CC);
- if (I != End) {
- methodCl = (Class*)this;
- return I->second;
+ JavaMethod* methods = 0;
+ uint32 nb = 0;
+ if (isStatic) {
+ methods = getStaticMethods();
+ nb = nbStaticMethods;
+ } else {
+ methods = getVirtualMethods();
+ nb = nbVirtualMethods;
}
+ for (uint32 i = 0; i < nb; ++i) {
+ JavaMethod& res = methods[i];
+ if (res.name->equals(name) && res.type->equals(type)) {
+ if (methodCl) *methodCl = (Class*)this;
+ return &res;
+ }
+ }
+
JavaMethod *cur = 0;
if (recurse) {
@@ -432,11 +442,10 @@
recurse, methodCl);
if (cur) return cur;
if (isStatic) {
- std::vector<Class*>* interfaces = getInterfaces();
- for (std::vector<Class*>::iterator i = interfaces->begin(),
- e = interfaces->end(); i!= e; i++) {
- cur = (*i)->lookupMethodDontThrow(name, type, isStatic, recurse,
- methodCl);
+ for (uint16 i = 0; i < nbInterfaces; ++i) {
+ Class* I = interfaces[i];
+ cur = I->lookupMethodDontThrow(name, type, isStatic, recurse,
+ methodCl);
if (cur) return cur;
}
}
@@ -447,7 +456,7 @@
JavaMethod* CommonClass::lookupMethod(const UTF8* name, const UTF8* type,
bool isStatic, bool recurse,
- Class*& methodCl) {
+ Class** methodCl) {
JavaMethod* res = lookupMethodDontThrow(name, type, isStatic, recurse,
methodCl);
if (!res) {
@@ -459,18 +468,25 @@
JavaField*
CommonClass::lookupFieldDontThrow(const UTF8* name, const UTF8* type,
bool isStatic, bool recurse,
- CommonClass*& definingClass) {
-
- CommonClass::FieldCmp CC(name, type);
- CommonClass::field_map* map = isStatic ? getStaticFields() :
- getVirtualFields();
- CommonClass::field_iterator End = map->end();
- CommonClass::field_iterator I = map->find(CC);
- if (I != End) {
- definingClass = this;
- return I->second;
+ CommonClass** definingClass) {
+ JavaField* fields = 0;
+ uint32 nb = 0;
+ if (isStatic) {
+ fields = getStaticFields();
+ nb = nbStaticFields;
+ } else {
+ fields = getVirtualFields();
+ nb = nbVirtualFields;
}
+ for (uint32 i = 0; i < nb; ++i) {
+ JavaField& res = fields[i];
+ if (res.name->equals(name) && res.type->equals(type)) {
+ if (definingClass) *definingClass = this;
+ return &res;
+ }
+ }
+
JavaField *cur = 0;
if (recurse) {
@@ -478,11 +494,10 @@
recurse, definingClass);
if (cur) return cur;
if (isStatic) {
- std::vector<Class*>* interfaces = getInterfaces();
- for (std::vector<Class*>::iterator i = interfaces->begin(),
- e = interfaces->end(); i!= e; i++) {
- cur = (*i)->lookupFieldDontThrow(name, type, isStatic, recurse,
- definingClass);
+ for (uint16 i = 0; i < nbInterfaces; ++i) {
+ Class* I = interfaces[i];
+ cur = I->lookupFieldDontThrow(name, type, isStatic, recurse,
+ definingClass);
if (cur) return cur;
}
}
@@ -493,7 +508,7 @@
JavaField* CommonClass::lookupField(const UTF8* name, const UTF8* type,
bool isStatic, bool recurse,
- CommonClass*& definingClass) {
+ CommonClass** definingClass) {
JavaField* res = lookupFieldDontThrow(name, type, isStatic, recurse,
definingClass);
@@ -505,7 +520,8 @@
JavaObject* UserClass::doNew(Jnjvm* vm) {
assert(this && "No class when allocating.");
- assert(this->isReady() && "Uninitialized class when allocating.");
+ assert((this->isReady() || classLoader->getModule()->isStaticCompiling())
+ && "Uninitialized class when allocating.");
JavaObject* res =
(JavaObject*)vm->gcAllocator.allocateManagedObject(getVirtualSize(),
getVirtualVT());
@@ -522,7 +538,7 @@
if (getSuper()->inheritName(Tname)) return true;
}
- for (uint32 i = 0; i < interfaces.size(); ++i) {
+ for (uint32 i = 0; i < nbInterfaces; ++i) {
if (interfaces[i]->inheritName(Tname)) return true;
}
return false;
@@ -555,10 +571,10 @@
bool UserCommonClass::implements(UserCommonClass* cl) {
if (this == cl) return true;
else {
- for (std::vector<UserClass*>::iterator i = interfaces.begin(),
- e = interfaces.end(); i!= e; i++) {
- if (*i == cl) return true;
- else if ((*i)->implements(cl)) return true;
+ for (uint16 i = 0; i < nbInterfaces; ++i) {
+ Class* I = interfaces[i];
+ if (I == cl) return true;
+ else if (I->implements(cl)) return true;
}
if (super) {
return super->implements(cl);
@@ -604,12 +620,51 @@
}
}
+void JavaField::InitField(JavaObject* obj, uint64 val) {
+
+ Typedef* type = getSignature();
+ if (!type->isPrimitive()) {
+ ((sint32*)((uint64)obj + ptrOffset))[0] = (sint32)val;
+ return;
+ }
+
+ PrimitiveTypedef* prim = (PrimitiveTypedef*)type;
+ if (prim->isLong()) {
+ ((sint64*)((uint64)obj + ptrOffset))[0] = val;
+ } else if (prim->isInt()) {
+ ((sint32*)((uint64)obj + ptrOffset))[0] = (sint32)val;
+ } else if (prim->isChar()) {
+ ((uint16*)((uint64)obj + ptrOffset))[0] = (uint16)val;
+ } else if (prim->isShort()) {
+ ((sint16*)((uint64)obj + ptrOffset))[0] = (sint16)val;
+ } else if (prim->isByte()) {
+ ((sint8*)((uint64)obj + ptrOffset))[0] = (sint8)val;
+ } else if (prim->isBool()) {
+ ((uint8*)((uint64)obj + ptrOffset))[0] = (uint8)val;
+ } else {
+ // 0 value for everything else
+ ((sint32*)((uint64)obj + ptrOffset))[0] = (sint32)val;
+ }
+}
+
+void JavaField::InitField(JavaObject* obj, JavaObject* val) {
+ ((JavaObject**)((uint64)obj + ptrOffset))[0] = val;
+}
+
+void JavaField::InitField(JavaObject* obj, double val) {
+ ((double*)((uint64)obj + ptrOffset))[0] = val;
+}
+
+void JavaField::InitField(JavaObject* obj, float val) {
+ ((float*)((uint64)obj + ptrOffset))[0] = val;
+}
+
void JavaField::initField(JavaObject* obj, Jnjvm* vm) {
const Typedef* type = getSignature();
Attribut* attribut = lookupAttribut(Attribut::constantAttribut);
if (!attribut) {
- JnjvmModule::InitField(this, obj);
+ InitField(obj);
} else {
Reader reader(attribut, classDef->bytes);
JavaConstantPool * ctpInfo = classDef->ctpInfo;
@@ -617,18 +672,17 @@
if (type->isPrimitive()) {
UserCommonClass* cl = type->assocClass(vm->bootstrapLoader);
if (cl == vm->upcalls->OfLong) {
- JnjvmModule::InitField(this, obj, (uint64)ctpInfo->LongAt(idx));
+ InitField(obj, (uint64)ctpInfo->LongAt(idx));
} else if (cl == vm->upcalls->OfDouble) {
- JnjvmModule::InitField(this, obj, ctpInfo->DoubleAt(idx));
+ InitField(obj, ctpInfo->DoubleAt(idx));
} else if (cl == vm->upcalls->OfFloat) {
- JnjvmModule::InitField(this, obj, ctpInfo->FloatAt(idx));
+ InitField(obj, ctpInfo->FloatAt(idx));
} else {
- JnjvmModule::InitField(this, obj, (uint64)ctpInfo->IntegerAt(idx));
+ InitField(obj, (uint64)ctpInfo->IntegerAt(idx));
}
} else if (type->isReference()){
const UTF8* utf8 = ctpInfo->UTF8At(ctpInfo->ctpDef[idx]);
- JnjvmModule::InitField(this, obj,
- (JavaObject*)ctpInfo->resolveString(utf8, idx));
+ InitField(obj, (JavaObject*)ctpInfo->resolveString(utf8, idx));
} else {
JavaThread::get()->isolate->
unknownError("unknown constant %s\n", type->printString());
@@ -636,68 +690,57 @@
}
}
-JavaMethod* CommonClass::constructMethod(const UTF8* name,
+JavaMethod* CommonClass::constructMethod(JavaMethod& method,
+ const UTF8* name,
const UTF8* type, uint32 access) {
- method_map& map = isStatic(access) ? staticMethods : virtualMethods;
- FieldCmp CC(name, type);
- method_iterator End = map.end();
- method_iterator I = map.find(CC);
- if (I == End) {
- JavaMethod* method = new(classLoader->allocator) JavaMethod();
- method->name = name;
- method->type = type;
- method->classDef = (Class*)this;
- method->_signature = 0;
- method->code = 0;
- method->access = access;
- method->canBeInlined = false;
- method->offset = 0;
- method->JInfo = 0;
- map.insert(std::make_pair(CC, method));
- return method;
- } else {
- return I->second;
- }
+ method.name = name;
+ method.type = type;
+ method.classDef = (Class*)this;
+ method._signature = 0;
+ method.code = 0;
+ method.access = access;
+ method.canBeInlined = false;
+ method.offset = 0;
+ method.JInfo = 0;
+ method.enveloppes = 0;
+ return &method;
}
-JavaField* CommonClass::constructField(const UTF8* name,
+JavaField* CommonClass::constructField(JavaField& field,
+ const UTF8* name,
const UTF8* type, uint32 access) {
- field_map& map = isStatic(access) ? staticFields : virtualFields;
- FieldCmp CC(name, type);
- field_iterator End = map.end();
- field_iterator I = map.find(CC);
- if (I == End) {
- JavaField* field = new(classLoader->allocator) JavaField();
- field->name = name;
- field->type = type;
- field->classDef = (Class*)this;
- field->_signature = 0;
- field->ptrOffset = 0;
- field->access = access;
- field->JInfo = 0;
- map.insert(std::make_pair(CC, field));
- return field;
- } else {
- return I->second;
- }
+ field.name = name;
+ field.type = type;
+ field.classDef = (Class*)this;
+ field._signature = 0;
+ field.ptrOffset = 0;
+ field.access = access;
+ field.JInfo = 0;
+ return &field;
}
void Class::readParents(Reader& reader) {
- unsigned short int superEntry = reader.readU2();
- const UTF8* super = superEntry ?
+ uint16 superEntry = reader.readU2();
+ const UTF8* superUTF8 = superEntry ?
ctpInfo->resolveClassName(superEntry) : 0;
- unsigned short int nbI = reader.readU2();
- superUTF8 = super;
+ uint16 nbI = reader.readU2();
+ // Use the super field to store the UTF8. since the field is never
+ // used before actually loading the super, this is harmless.
+ super = (Class*)superUTF8;
+
+ // Use the regular interface array to store the UTF8s. Since this array
+ // is never used before actually loading the interfaces, this is harmless.
+ interfaces = (Class**)
+ classLoader->allocator.Allocate(nbI * sizeof(Class*));
+ nbInterfaces = nbI;
for (int i = 0; i < nbI; i++)
- interfacesUTF8.push_back(ctpInfo->resolveClassName(reader.readU2()));
+ interfaces[i] = (Class*)ctpInfo->resolveClassName(reader.readU2());
}
void UserClass::loadParents() {
- std::vector<const UTF8*>* interfacesUTF8 = getInterfacesUTF8();
- unsigned nbI = interfacesUTF8->size();
- const UTF8* superUTF8 = getSuperUTF8();
+ const UTF8* superUTF8 = (const UTF8*)super;
if (superUTF8 == 0) {
depth = 0;
display = (CommonClass**)
@@ -713,48 +756,70 @@
display[depth] = this;
}
- for (unsigned i = 0; i < nbI; i++)
- interfaces.push_back((UserClass*)classLoader->loadName((*interfacesUTF8)[i],
- true, true));
+ for (unsigned i = 0; i < nbInterfaces; i++)
+ interfaces[i] =
+ ((UserClass*)classLoader->loadName((const UTF8*)interfaces[i],
+ true, true));
}
-void Class::readAttributs(Reader& reader, std::vector<Attribut*>& attr) {
- unsigned short int nba = reader.readU2();
+Attribut* Class::readAttributs(Reader& reader, uint16& size) {
+ uint16 nba = reader.readU2();
+ Attribut* attributs = new(classLoader->allocator) Attribut[nba];
+
for (int i = 0; i < nba; i++) {
const UTF8* attName = ctpInfo->UTF8At(reader.readU2());
uint32 attLen = reader.readU4();
- Attribut* att = new(classLoader->allocator) Attribut(attName, attLen,
- reader.cursor);
- attr.push_back(att);
+ Attribut& att = attributs[i];
+ att.start = reader.cursor;
+ att.nbb = attLen;
+ att.name = attName;
reader.seek(attLen, Reader::SeekCur);
}
+
+ size = nba;
+ return attributs;
}
void Class::readFields(Reader& reader) {
uint16 nbFields = reader.readU2();
- uint32 sindex = 0;
- uint32 vindex = 0;
+ virtualFields = new (classLoader->allocator) JavaField[nbFields];
+ staticFields = virtualFields + nbFields;
for (int i = 0; i < nbFields; i++) {
uint16 access = reader.readU2();
const UTF8* name = ctpInfo->UTF8At(reader.readU2());
const UTF8* type = ctpInfo->UTF8At(reader.readU2());
- JavaField* field = constructField(name, type, access);
- isStatic(access) ?
- field->num = sindex++ :
- field->num = vindex++;
- readAttributs(reader, field->attributs);
+ JavaField* field = 0;
+ if (isStatic(access)) {
+ --staticFields;
+ field = constructField(staticFields[0], name, type, access);
+ ++nbStaticFields;
+ } else {
+ field = constructField(virtualFields[nbVirtualFields], name, type, access);
+ ++nbVirtualFields;
+ }
+ field->attributs = readAttributs(reader, field->nbAttributs);
}
}
void Class::readMethods(Reader& reader) {
uint16 nbMethods = reader.readU2();
+ virtualMethods = new(classLoader->allocator) JavaMethod[nbMethods];
+ staticMethods = virtualMethods + nbMethods;
for (int i = 0; i < nbMethods; i++) {
uint16 access = reader.readU2();
const UTF8* name = ctpInfo->UTF8At(reader.readU2());
const UTF8* type = ctpInfo->UTF8At(reader.readU2());
- JavaMethod* meth = constructMethod(name, type, access);
- readAttributs(reader, meth->attributs);
+ JavaMethod* meth = 0;
+ if (isStatic(access)) {
+ --staticMethods;
+ meth = constructMethod(staticMethods[0], name, type, access);
+ ++nbStaticMethods;
+ } else {
+ meth = constructMethod(virtualMethods[nbVirtualMethods], name, type, access);
+ ++nbVirtualMethods;
+ }
+ meth->attributs = readAttributs(reader, meth->nbAttributs);
}
}
@@ -769,8 +834,8 @@
if (magic != Jnjvm::Magic) {
JavaThread::get()->isolate->classFormatError("bad magic number %p", magic);
}
- minor = reader.readU2();
- major = reader.readU2();
+ /* uint16 minor = */ reader.readU2();
+ /* uint16 major = */ reader.readU2();
uint32 ctpSize = reader.readU2();
ctpInfo = new(classLoader->allocator, ctpSize) JavaConstantPool(this, reader,
ctpSize);
@@ -790,7 +855,7 @@
readParents(reader);
readFields(reader);
readMethods(reader);
- readAttributs(reader, attributs);
+ attributs = readAttributs(reader, nbAttributs);
}
#ifndef ISOLATE_SHARING
@@ -814,7 +879,7 @@
cl->loadParents();
cl->acquire();
cl->status = prepared;
- classLoader->TheModule->resolveVirtualClass(cl);
+ classLoader->getModule()->resolveVirtualClass(cl);
cl->status = resolved;
}
release();
@@ -839,7 +904,7 @@
Attribut* attribut = lookupAttribut(Attribut::innerClassesAttribut);
if (attribut != 0) {
Reader reader(attribut, getBytes());
-
+ uint16 temp = 0;
uint16 nbi = reader.readU2();
for (uint16 i = 0; i < nbi; ++i) {
uint16 inner = reader.readU2();
@@ -853,8 +918,12 @@
if (clInner == this) {
outerClass = clOuter;
} else if (clOuter == this) {
+ if (!temp) {
+ innerClasses = (Class**)
+ classLoader->allocator.Allocate(nbi * sizeof(Class*));
+ }
clInner->setInnerAccess(accessFlags);
- innerClasses.push_back(clInner);
+ innerClasses[nbInnerClasses++] = clInner;
}
}
}
@@ -864,11 +933,11 @@
void CommonClass::getDeclaredConstructors(std::vector<JavaMethod*>& res,
bool publicOnly) {
- for (CommonClass::method_iterator i = virtualMethods.begin(),
- e = virtualMethods.end(); i != e; ++i) {
- JavaMethod* meth = i->second;
+ for (uint32 i = 0; i < nbVirtualMethods; ++i) {
+ JavaMethod* meth = &virtualMethods[i];
bool pub = isPublic(meth->access);
- if (meth->name->equals(Jnjvm::initName) && (!publicOnly || pub)) {
+ if (meth->name->equals(classLoader->bootstrapLoader->initName) &&
+ (!publicOnly || pub)) {
res.push_back(meth);
}
}
@@ -876,20 +945,20 @@
void CommonClass::getDeclaredMethods(std::vector<JavaMethod*>& res,
bool publicOnly) {
- for (CommonClass::method_iterator i = virtualMethods.begin(),
- e = virtualMethods.end(); i != e; ++i) {
- JavaMethod* meth = i->second;
+ for (uint32 i = 0; i < nbVirtualMethods; ++i) {
+ JavaMethod* meth = &virtualMethods[i];
bool pub = isPublic(meth->access);
- if (!(meth->name->equals(Jnjvm::initName)) && (!publicOnly || pub)) {
+ if (!(meth->name->equals(classLoader->bootstrapLoader->initName)) &&
+ (!publicOnly || pub)) {
res.push_back(meth);
}
}
- for (CommonClass::method_iterator i = staticMethods.begin(),
- e = staticMethods.end(); i != e; ++i) {
- JavaMethod* meth = i->second;
+ for (uint32 i = 0; i < nbStaticMethods; ++i) {
+ JavaMethod* meth = &staticMethods[i];
bool pub = isPublic(meth->access);
- if (!(meth->name->equals(Jnjvm::clinitName)) && (!publicOnly || pub)) {
+ if (!(meth->name->equals(classLoader->bootstrapLoader->clinitName)) &&
+ (!publicOnly || pub)) {
res.push_back(meth);
}
}
@@ -897,17 +966,15 @@
void CommonClass::getDeclaredFields(std::vector<JavaField*>& res,
bool publicOnly) {
- for (CommonClass::field_iterator i = virtualFields.begin(),
- e = virtualFields.end(); i != e; ++i) {
- JavaField* field = i->second;
+ for (uint32 i = 0; i < nbVirtualFields; ++i) {
+ JavaField* field = &virtualFields[i];
if (!publicOnly || isPublic(field->access)) {
res.push_back(field);
}
}
- for (CommonClass::field_iterator i = staticFields.begin(),
- e = staticFields.end(); i != e; ++i) {
- JavaField* field = i->second;
+ for (uint32 i = 0; i < nbStaticFields; ++i) {
+ JavaField* field = &staticFields[i];
if (!publicOnly || isPublic(field->access)) {
res.push_back(field);
}
@@ -915,5 +982,5 @@
}
void Class::resolveStaticClass() {
- classLoader->TheModule->resolveStaticClass((Class*)this);
+ classLoader->getModule()->resolveStaticClass((Class*)this);
}
Modified: vmkit/branches/release_024/lib/JnJVM/VMCore/JavaClass.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/JnJVM/VMCore/JavaClass.h?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/JnJVM/VMCore/JavaClass.h (original)
+++ vmkit/branches/release_024/lib/JnJVM/VMCore/JavaClass.h Mon Nov 3 04:20:55 2008
@@ -10,7 +10,6 @@
#ifndef JNJVM_JAVA_CLASS_H
#define JNJVM_JAVA_CLASS_H
-#include <map>
#include <vector>
#include "types.h"
@@ -82,6 +81,7 @@
/// Attribut - Create an attribut at the given length and offset.
///
Attribut(const UTF8* name, uint32 length, uint32 offset);
+ Attribut() {}
/// codeAttribut - The "Code" JVM attribut. This is a method attribut for
/// finding the bytecode of a method in the .class file.
@@ -126,26 +126,6 @@
#ifdef ISOLATE_SHARING
friend class UserCommonClass;
#endif
-private:
-
-
-/// FieldCmp - Internal class for field and method lookup in a class.
-///
-class FieldCmp {
-public:
-
- /// name - The name of the field/method
- ///
- const UTF8* name;
-
- /// type - The type of the field/method.
- ///
- const UTF8* type;
-
- FieldCmp(const UTF8* n, const UTF8* t) : name(n), type(t) {}
-
- bool operator<(const FieldCmp &cmp) const;
-};
public:
@@ -169,13 +149,12 @@
///
VirtualTable* virtualVT;
- /// display - The class hierarchy of supers for this class. Array classes
- /// do not need it.
+ /// display - The class hierarchy of supers for this class.
///
CommonClass** display;
/// depth - The depth of this class in its class hierarchy.
- /// display[depth] contains the class. Array classes do not need it.
+ /// display[depth] contains the class.
///
uint32 depth;
@@ -255,12 +234,14 @@
/// interfaces - The interfaces this class implements.
///
- std::vector<Class*> interfaces;
+ Class** interfaces;
- std::vector<Class*> * getInterfaces() {
- return &interfaces;
+ Class** getInterfaces() {
+ return interfaces;
}
+ uint16 nbInterfaces;
+
/// name - The name of the class.
///
const UTF8* name;
@@ -277,22 +258,6 @@
return super;
}
- /// superUTF8 - The name of the parent of this class.
- ///
- const UTF8* superUTF8;
-
- const UTF8* getSuperUTF8() {
- return superUTF8;
- }
-
- /// interfacesUTF8 - The names of the interfaces this class implements.
- ///
- std::vector<const UTF8*> interfacesUTF8;
-
- std::vector<const UTF8*>* getInterfacesUTF8() {
- return &interfacesUTF8;
- }
-
/// lockVar - When multiple threads want to load/resolve/initialize a class,
/// they must be synchronized so that these steps are only performed once
/// for a given class.
@@ -312,49 +277,40 @@
JavaObject* delegatee;
#endif
-
- typedef std::map<const FieldCmp, JavaField*, std::less<FieldCmp> >::iterator
- field_iterator;
-
- typedef std::map<const FieldCmp, JavaField*, std::less<FieldCmp> >
- field_map;
-
/// virtualFields - List of all the virtual fields defined in this class.
/// This does not contain non-redefined super fields.
- field_map virtualFields;
-
+ JavaField* virtualFields;
+ uint16 nbVirtualFields;
+
/// staticFields - List of all the static fields defined in this class.
///
- field_map staticFields;
-
- typedef std::map<const FieldCmp, JavaMethod*, std::less<FieldCmp> >::iterator
- method_iterator;
-
- typedef std::map<const FieldCmp, JavaMethod*, std::less<FieldCmp> >
- method_map;
+ JavaField* staticFields;
+ uint16 nbStaticFields;
/// virtualMethods - List of all the virtual methods defined by this class.
/// This does not contain non-redefined super methods.
- method_map virtualMethods;
+ JavaMethod* virtualMethods;
+ uint16 nbVirtualMethods;
/// staticMethods - List of all the static methods defined by this class.
///
- method_map staticMethods;
+ JavaMethod* staticMethods;
+ uint16 nbStaticMethods;
- field_map* getStaticFields() { return &staticFields; }
- field_map* getVirtualFields() { return &virtualFields; }
- method_map* getStaticMethods() { return &staticMethods; }
- method_map* getVirtualMethods() { return &virtualMethods; }
+ JavaField* getStaticFields() { return staticFields; }
+ JavaField* getVirtualFields() { return virtualFields; }
+ JavaMethod* getStaticMethods() { return staticMethods; }
+ JavaMethod* getVirtualMethods() { return virtualMethods; }
- /// constructMethod - Add a new method in this class method map.
+ /// constructMethod - Create a new method.
///
- JavaMethod* constructMethod(const UTF8* name, const UTF8* type,
- uint32 access);
+ JavaMethod* constructMethod(JavaMethod& method, const UTF8* name,
+ const UTF8* type, uint32 access);
- /// constructField - Add a new field in this class field map.
+ /// constructField - Create a new field.
///
- JavaField* constructField(const UTF8* name, const UTF8* type,
- uint32 access);
+ JavaField* constructField(JavaField& field, const UTF8* name,
+ const UTF8* type, uint32 access);
/// printClassName - Adds a string representation of this class in the
/// given buffer.
@@ -396,24 +352,24 @@
/// Do not throw if the method is not found.
///
JavaMethod* lookupMethodDontThrow(const UTF8* name, const UTF8* type,
- bool isStatic, bool recurse, Class*& cl);
+ bool isStatic, bool recurse, Class** cl);
/// lookupMethod - Lookup a method and throw an exception if not found.
///
JavaMethod* lookupMethod(const UTF8* name, const UTF8* type, bool isStatic,
- bool recurse, Class*& cl);
+ bool recurse, Class** cl);
/// lookupFieldDontThrow - Lookup a field in the field map of this class. Do
/// not throw if the field is not found.
///
JavaField* lookupFieldDontThrow(const UTF8* name, const UTF8* type,
bool isStatic, bool recurse,
- CommonClass*& definingClass);
+ CommonClass** definingClass);
/// lookupField - Lookup a field and throw an exception if not found.
///
JavaField* lookupField(const UTF8* name, const UTF8* type, bool isStatic,
- bool recurse, CommonClass*& definingClass);
+ bool recurse, CommonClass** definingClass);
/// print - Print the class for debugging purposes.
///
@@ -509,7 +465,7 @@
void getDeclaredConstructors(std::vector<JavaMethod*>& res, bool publicOnly);
void getDeclaredMethods(std::vector<JavaMethod*>& res, bool publicOnly);
void getDeclaredFields(std::vector<JavaField*>& res, bool publicOnly);
- void setInterfaces(std::vector<Class*> I) {
+ void setInterfaces(Class** I) {
interfaces = I;
}
void setSuper(CommonClass* S) {
@@ -517,6 +473,10 @@
}
UserClassPrimitive* toPrimitive(Jnjvm* vm) const;
+
+ CommonClass* getInternal() {
+ return this;
+ }
};
@@ -529,10 +489,6 @@
static UserClassPrimitive* byteIdToPrimitive(char id, Classpath* upcalls);
- void* operator new(size_t sz, mvm::BumpPtrAllocator& allocator) {
- return allocator.Allocate(sz);
- }
-
};
@@ -542,18 +498,6 @@
class Class : public CommonClass {
public:
- /// VT - The virtual table of this class.
- ///
- static VirtualTable* VT;
-
- /// minor - The minor version of this class.
- ///
- unsigned int minor;
-
- /// major - The major version of this class.
- ///
- unsigned int major;
-
/// bytes - The .class file of this class.
///
ArrayUInt8* bytes;
@@ -564,21 +508,31 @@
/// attributs - JVM attributes of this class.
///
- std::vector<Attribut*> attributs;
+ Attribut* attributs;
+ uint16 nbAttributs;
#if !defined(ISOLATE) && !defined(ISOLATE_SHARING)
/// innerClasses - The inner classes of this class.
///
- std::vector<Class*> innerClasses;
+ Class** innerClasses;
+ uint16 nbInnerClasses;
/// outerClass - The outer class, if this class is an inner class.
///
Class* outerClass;
+
+ Class* getOuterClass() {
+ return outerClass;
+ }
+
+ Class** getInnerClasses() {
+ return innerClasses;
+ }
#endif
/// innerAccess - The access of this class, if this class is an inner class.
///
- uint32 innerAccess;
+ uint16 innerAccess;
void setInnerAccess(uint32 access) {
innerAccess = access;
@@ -662,7 +616,7 @@
/// readAttributs - Reads the attributs of the class.
///
- void readAttributs(Reader& reader, std::vector<Attribut*> & attr);
+ Attribut* readAttributs(Reader& reader, uint16& size);
/// readFields - Reads the fields of the class.
///
@@ -687,16 +641,6 @@
void resolveInnerOuterClasses();
-#ifndef ISOLATE_SHARING
- Class* getOuterClass() {
- return outerClass;
- }
-
- std::vector<Class*>* getInnerClasses() {
- return &innerClasses;
- }
-#endif
-
mvm::JITInfo* JInfo;
template<typename Ty>
Ty *getInfo() {
@@ -716,8 +660,10 @@
///
class ClassArray : public CommonClass {
- /// Reader is a friend because it allocates arrays without a vm.
+ /// Reader and Jnjvm are friends because they may allocate arrays without
+ /// a vm.
friend class Reader;
+ friend class Jnjvm;
private:
/// doNew - Allocate a new array with the given allocator.
///
@@ -726,10 +672,6 @@
public:
- /// VT - The virtual table of array classes.
- ///
- static VirtualTable* VT;
-
/// _baseClass - The base class of the array, or null if not resolved.
///
CommonClass* _baseClass;
@@ -776,7 +718,7 @@
virtual void TRACER;
static CommonClass* SuperArray;
- static std::vector<Class*> InterfacesArray;
+ static Class** InterfacesArray;
};
/// JavaMethod - This class represents Java methods.
@@ -803,16 +745,18 @@
/// access - Java access type of this method (e.g. private, public...).
///
- unsigned int access;
+ uint16 access;
/// attributs - List of Java attributs of this method.
///
- std::vector<Attribut*> attributs;
+ Attribut* attributs;
+ uint16 nbAttributs;
/// caches - List of caches in this method. For all invokeinterface bytecode
/// there is a corresponding cache.
///
- std::vector<Enveloppe*> caches;
+ Enveloppe* enveloppes;
+ uint16 nbEnveloppes;
/// classDef - The Java class where the method is defined.
///
@@ -942,6 +886,14 @@
/// _signature - The signature of the field. Null if not resolved.
///
Typedef* _signature;
+
+ /// InitField - Set an initial value to the field of an object.
+ ///
+ void InitField(JavaObject* obj, uint64 val = 0);
+ void InitField(JavaObject* obj, JavaObject* val);
+ void InitField(JavaObject* obj, double val);
+ void InitField(JavaObject* obj, float val);
+
public:
/// ~JavaField - Destroy the field as well as its attributs.
@@ -950,7 +902,7 @@
/// access - The Java access type of this field (e.g. public, private).
///
- unsigned int access;
+ uint16 access;
/// name - The name of the field.
///
@@ -962,7 +914,8 @@
/// attributs - List of Java attributs for this field.
///
- std::vector<Attribut*> attributs;
+ Attribut* attributs;
+ uint16 nbAttributs;
/// classDef - The class where the field is defined.
///
@@ -975,7 +928,7 @@
/// num - The index of the field in the field list.
///
- uint32 num;
+ uint16 num;
/// getSignature - Get the signature of this field, resolving it if
/// necessary.
Modified: vmkit/branches/release_024/lib/JnJVM/VMCore/JavaConstantPool.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/JnJVM/VMCore/JavaConstantPool.cpp?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/JnJVM/VMCore/JavaConstantPool.cpp (original)
+++ vmkit/branches/release_024/lib/JnJVM/VMCore/JavaConstantPool.cpp Mon Nov 3 04:20:55 2008
@@ -306,8 +306,8 @@
assert(loader && "Class has no loader?");
const UTF8* name = UTF8At(ctpDef[index]);
temp = loader->lookupClass(name);
- if (!temp)
- temp = JnjvmClassLoader::bootstrapLoader->lookupClass(name);
+ if (!temp && loader != loader->bootstrapLoader)
+ temp = loader->bootstrapLoader->lookupClass(name);
}
#endif
return temp;
@@ -365,10 +365,9 @@
const UTF8* utf8 = UTF8At(ctpDef[ntIndex] >> 16);
cl = getMethodClassIfLoaded(entry >> 16);
if (cl && cl->status >= classRead) {
- Class* methodCl = 0;
// lookup the method
meth = cl->lookupMethodDontThrow(utf8, sign->keyName, isStatic(access),
- false, methodCl);
+ false, 0);
}
}
@@ -410,12 +409,11 @@
CommonClass* cl = getMethodClassIfLoaded(entry >> 16);
if (cl && cl->status >= classRead) {
// lookup the method
- Class* methodCl = 0;
meth = cl->lookupMethodDontThrow(utf8, sign->keyName, isStatic(access),
- false, methodCl);
+ false, 0);
if (meth) {
// don't throw if no meth, the exception will be thrown just in time
- JnjvmModule* M = classDef->classLoader->TheModule;
+ JnjvmModule* M = classDef->classLoader->getModule();
void* F = M->getMethod(meth);
return F;
}
@@ -473,9 +471,8 @@
const UTF8* utf8 = UTF8At(ctpDef[ntIndex] >> 16);
CommonClass* cl = getMethodClassIfLoaded(entry >> 16);
if (cl && cl->status >= resolved) {
- CommonClass* fieldCl = 0;
JavaField* field = cl->lookupFieldDontThrow(utf8, sign->keyName, stat,
- true, fieldCl);
+ true, 0);
// don't throw if no field, the exception will be thrown just in time
if (field) {
if (!stat) {
Modified: vmkit/branches/release_024/lib/JnJVM/VMCore/JavaInitialise.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/JnJVM/VMCore/JavaInitialise.cpp?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/JnJVM/VMCore/JavaInitialise.cpp (original)
+++ vmkit/branches/release_024/lib/JnJVM/VMCore/JavaInitialise.cpp Mon Nov 3 04:20:55 2008
@@ -7,28 +7,12 @@
//
//===----------------------------------------------------------------------===//
-#include <vector>
-
-#include "mvm/Allocator.h"
#include "mvm/VirtualMachine.h"
-#include "mvm/Threads/Locks.h"
-#include "mvm/Threads/Thread.h"
#include "JavaArray.h"
-#include "JavaCache.h"
-#include "JavaClass.h"
-#include "JavaConstantPool.h"
-#include "JavaJIT.h"
#include "JavaObject.h"
-#include "JavaString.h"
#include "JavaThread.h"
-#include "JavaTypes.h"
-#include "JavaUpcalls.h"
#include "Jnjvm.h"
-#include "JnjvmModuleProvider.h"
-#include "NativeUtil.h"
-#include "LockedMap.h"
-#include "Zip.h"
#ifdef SERVICE_VM
#include "ServiceDomain.h"
@@ -47,8 +31,6 @@
X fake; \
X::VT = ((void**)(void*)(&fake))[0]; }
- INIT(Class);
- INIT(ClassArray);
INIT(JavaThread);
INIT(Jnjvm);
INIT(JnjvmBootstrapLoader);
@@ -79,174 +61,29 @@
#undef INIT
}
-void Jnjvm::initialiseStatics() {
-
#ifdef ISOLATE_SHARING
- if (!JnjvmSharedLoader::sharedLoader) {
- JnjvmSharedLoader::sharedLoader = JnjvmSharedLoader::createSharedLoader();
- }
-#endif
-
- JnjvmBootstrapLoader* JCL = bootstrapLoader = gc_new(JnjvmBootstrapLoader)(0);
-
- // Create the name of char arrays.
- const UTF8* utf8OfChar = JCL->asciizConstructUTF8("[C");
+mvm::CompilationUnit* mvm::VirtualMachine::initialiseJVM(bool sc) {
+ initialiseVT();
+ JnjvmSharedLoader::sharedLoader = JnjvmSharedLoader::createSharedLoader();
+ return JnjvmSharedLoader::sharedLoader;
+}
- // Create the base class of char arrays.
- JCL->upcalls->OfChar = UPCALL_PRIMITIVE_CLASS(JCL, "char", 2);
-
- // Create the char array.
- JCL->upcalls->ArrayOfChar = JCL->constructArray(utf8OfChar,
- JCL->upcalls->OfChar);
-
- // Alright, now we can repair the damage: set the class to the UTF8s created
- // and set the array class of UTF8s.
- ((UTF8*)utf8OfChar)->classOf = JCL->upcalls->ArrayOfChar;
- ((UTF8*)JCL->upcalls->OfChar->name)->classOf = JCL->upcalls->ArrayOfChar;
- JCL->hashUTF8->array = JCL->upcalls->ArrayOfChar;
-
- // Create the byte array, so that bytes for classes can be created.
- JCL->upcalls->OfByte = UPCALL_PRIMITIVE_CLASS(JCL, "byte", 1);
- JCL->upcalls->ArrayOfByte =
- JCL->constructArray(JCL->asciizConstructUTF8("[B"), JCL->upcalls->OfByte);
-
- // Now we can create the super and interfaces of arrays.
- JCL->InterfacesArray.push_back(
- JCL->loadName(JCL->asciizConstructUTF8("java/lang/Cloneable"), false,
- false));
-
- JCL->InterfacesArray.push_back(
- JCL->loadName(JCL->asciizConstructUTF8("java/io/Serializable"), false,
- false));
-
- JCL->SuperArray =
- JCL->loadName(JCL->asciizConstructUTF8("java/lang/Object"), false,
- false);
-
-#ifdef ISOLATE_SHARING
- if (!ClassArray::SuperArray) {
- ClassArray::SuperArray = JCL->SuperArray->classDef;
- ClassArray::InterfacesArray.push_back((Class*)JCL->InterfacesArray[0]->classDef);
- ClassArray::InterfacesArray.push_back((Class*)JCL->InterfacesArray[1]->classDef);
- }
+mvm::VirtualMachine* mvm::VirtualMachine::createJVM(mvm::CompilationUnit* C) {
+ JnjvmBootstraLoader* bootstrapLoader = gc_new(JnjvmBootstrapLoader)(false);
+ Jnjvm* vm = gc_new(Jnjvm)(bootstrapLoader);
+ return vm;
+}
#else
- ClassArray::SuperArray = JCL->SuperArray;
- ClassArray::InterfacesArray = JCL->InterfacesArray;
-#endif
-
- // And repair the damage: set the interfaces and super of array classes already
- // created.
- JCL->upcalls->ArrayOfChar->setInterfaces(JCL->InterfacesArray);
- JCL->upcalls->ArrayOfChar->setSuper(JCL->SuperArray);
- JCL->upcalls->ArrayOfByte->setInterfaces(JCL->InterfacesArray);
- JCL->upcalls->ArrayOfByte->setSuper(JCL->SuperArray);
-
- // Yay, create the other primitive types.
- JCL->upcalls->OfBool = UPCALL_PRIMITIVE_CLASS(JCL, "boolean", 1);
- JCL->upcalls->OfShort = UPCALL_PRIMITIVE_CLASS(JCL, "short", 2);
- JCL->upcalls->OfInt = UPCALL_PRIMITIVE_CLASS(JCL, "int", 4);
- JCL->upcalls->OfLong = UPCALL_PRIMITIVE_CLASS(JCL, "long", 8);
- JCL->upcalls->OfFloat = UPCALL_PRIMITIVE_CLASS(JCL, "float", 4);
- JCL->upcalls->OfDouble = UPCALL_PRIMITIVE_CLASS(JCL, "double", 8);
- JCL->upcalls->OfVoid = UPCALL_PRIMITIVE_CLASS(JCL, "void", 0);
-
- // And finally create the primitive arrays.
- JCL->upcalls->ArrayOfInt =
- JCL->constructArray(JCL->asciizConstructUTF8("[I"), JCL->upcalls->OfInt);
-
- JCL->upcalls->ArrayOfBool =
- JCL->constructArray(JCL->asciizConstructUTF8("[Z"), JCL->upcalls->OfBool);
-
- JCL->upcalls->ArrayOfLong =
- JCL->constructArray(JCL->asciizConstructUTF8("[J"), JCL->upcalls->OfLong);
- JCL->upcalls->ArrayOfFloat =
- JCL->constructArray(JCL->asciizConstructUTF8("[F"), JCL->upcalls->OfFloat);
-
- JCL->upcalls->ArrayOfDouble =
- JCL->constructArray(JCL->asciizConstructUTF8("[D"), JCL->upcalls->OfDouble);
-
- JCL->upcalls->ArrayOfShort =
- JCL->constructArray(JCL->asciizConstructUTF8("[S"), JCL->upcalls->OfShort);
-
- JCL->upcalls->ArrayOfString =
- JCL->constructArray(JCL->asciizConstructUTF8("[Ljava/lang/String;"));
-
- JCL->upcalls->ArrayOfObject =
- JCL->constructArray(JCL->asciizConstructUTF8("[Ljava/lang/Object;"));
-
-
- Attribut::codeAttribut = JCL->asciizConstructUTF8("Code");
- Attribut::exceptionsAttribut = JCL->asciizConstructUTF8("Exceptions");
- Attribut::constantAttribut = JCL->asciizConstructUTF8("ConstantValue");
- Attribut::lineNumberTableAttribut =
- JCL->asciizConstructUTF8("LineNumberTable");
- Attribut::innerClassesAttribut = JCL->asciizConstructUTF8("InnerClasses");
- Attribut::sourceFileAttribut = JCL->asciizConstructUTF8("SourceFile");
-
- Jnjvm::initName = JCL->asciizConstructUTF8("<init>");
- Jnjvm::clinitName = JCL->asciizConstructUTF8("<clinit>");
- Jnjvm::clinitType = JCL->asciizConstructUTF8("()V");
- Jnjvm::runName = JCL->asciizConstructUTF8("run");
- Jnjvm::prelib = JCL->asciizConstructUTF8("lib");
-#if defined(__MACH__)
- Jnjvm::postlib = JCL->asciizConstructUTF8(".dylib");
-#else
- Jnjvm::postlib = JCL->asciizConstructUTF8(".so");
-#endif
- Jnjvm::mathName = JCL->asciizConstructUTF8("java/lang/Math");
- Jnjvm::NoClassDefFoundError =
- JCL->asciizConstructUTF8("java/lang/NoClassDefFoundError");
-
-#define DEF_UTF8(var) \
- Jnjvm::var = JCL->asciizConstructUTF8(#var)
-
- DEF_UTF8(abs);
- DEF_UTF8(sqrt);
- DEF_UTF8(sin);
- DEF_UTF8(cos);
- DEF_UTF8(tan);
- DEF_UTF8(asin);
- DEF_UTF8(acos);
- DEF_UTF8(atan);
- DEF_UTF8(atan2);
- DEF_UTF8(exp);
- DEF_UTF8(log);
- DEF_UTF8(pow);
- DEF_UTF8(ceil);
- DEF_UTF8(floor);
- DEF_UTF8(rint);
- DEF_UTF8(cbrt);
- DEF_UTF8(cosh);
- DEF_UTF8(expm1);
- DEF_UTF8(hypot);
- DEF_UTF8(log10);
- DEF_UTF8(log1p);
- DEF_UTF8(sinh);
- DEF_UTF8(tanh);
- DEF_UTF8(finalize);
-
-#undef DEF_UTF8
+mvm::CompilationUnit*
+mvm::VirtualMachine::initialiseJVM(bool staticCompilation) {
+ initialiseVT();
+ return gc_new(JnjvmBootstrapLoader)(staticCompilation);
}
-void mvm::VirtualMachine::initialiseJVM() {
-#ifndef ISOLATE_SHARING
- if (!JnjvmClassLoader::bootstrapLoader) {
- initialiseVT();
- Jnjvm::initialiseStatics();
- JnjvmClassLoader::bootstrapLoader = Jnjvm::bootstrapLoader;
- }
-#else
- initialiseVT();
-#endif
+mvm::VirtualMachine* mvm::VirtualMachine::createJVM(mvm::CompilationUnit* C) {
+ Jnjvm* vm = gc_new(Jnjvm)((JnjvmBootstrapLoader*)C);
+ return vm;
}
-mvm::VirtualMachine* mvm::VirtualMachine::createJVM() {
-#ifdef SERVICE_VM
- ServiceDomain* vm = ServiceDomain::allocateService();
- vm->startExecution();
-#else
- Jnjvm* vm = gc_new(Jnjvm)(0);
#endif
- return vm;
-}
Modified: vmkit/branches/release_024/lib/JnJVM/VMCore/JavaJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/JnJVM/VMCore/JavaJIT.cpp?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/JnJVM/VMCore/JavaJIT.cpp (original)
+++ vmkit/branches/release_024/lib/JnJVM/VMCore/JavaJIT.cpp Mon Nov 3 04:20:55 2008
@@ -50,6 +50,12 @@
using namespace jnjvm;
using namespace llvm;
+bool JavaJIT::canBeInlined(JavaMethod* meth) {
+ return (meth->canBeInlined &&
+ meth != compilingMethod && inlineMethods[meth] == 0 &&
+ meth->classDef->classLoader == compilingClass->classLoader);
+}
+
void JavaJIT::invokeVirtual(uint16 index) {
JavaConstantPool* ctpInfo = compilingClass->ctpInfo;
@@ -70,9 +76,33 @@
const llvm::FunctionType* virtualType = LSI->getVirtualType();
FunctionType::param_iterator it = virtualType->param_end();
makeArgs(it, index, args, signature->args.size() + 1);
+ const llvm::Type* retType = virtualType->getReturnType();
+
+ JITVerifyNull(args[0]);
+ BasicBlock* endBlock = 0;
+ PHINode* node = 0;
+ if (meth && !isAbstract(meth->access) && canBeInlined(meth)) {
+ Value* cl = CallInst::Create(module->GetClassFunction, args[0], "",
+ currentBlock);
+ Value* cl2 = module->getNativeClass((Class*)cl);
+ cl2 = new LoadInst(cl2, "", currentBlock);
+ Value* test = new ICmpInst(ICmpInst::ICMP_EQ, cl, cl2, "", currentBlock);
+
+ BasicBlock* trueBlock = createBasicBlock("true virtual invoke");
+ BasicBlock* falseBlock = createBasicBlock("false virtual invoke");
+ endBlock = createBasicBlock("end virtual invoke");
+ BranchInst::Create(trueBlock, falseBlock, test, currentBlock);
+ currentBlock = trueBlock;
+ Value* res = invokeInline(meth, args);
+ BranchInst::Create(endBlock, currentBlock);
+ if (retType != Type::VoidTy) {
+ node = PHINode::Create(virtualType->getReturnType(), "", endBlock);
+ node->addIncoming(res, currentBlock);
+ }
+ currentBlock = falseBlock;
+ }
- JITVerifyNull(args[0]);
Value* VT = CallInst::Create(module->GetVTFunction, args[0], "",
currentBlock);
@@ -94,7 +124,7 @@
Type::Int32Ty, args[0], true);
indexes2.push_back(val);
#ifdef ISOLATE_SHARING
- Value* mul = BinaryOperator::createMul(val, module->constantMinusOne,
+ Value* mul = BinaryOperator::CreateMul(val, module->constantMinusOne,
"", currentBlock);
indexesCtp.push_back(mul);
#endif
@@ -117,7 +147,15 @@
#endif
Value* val = invoke(Func, args, "", currentBlock);
- const llvm::Type* retType = virtualType->getReturnType();
+ if (endBlock) {
+ if (node) {
+ node->addIncoming(val, currentBlock);
+ val = node;
+ }
+ BranchInst::Create(endBlock, currentBlock);
+ currentBlock = endBlock;
+ }
+
if (retType != Type::VoidTy) {
push(val, retTypedef->isUnsigned());
if (retType == Type::DoubleTy || retType == Type::Int64Ty) {
@@ -143,11 +181,19 @@
natPtr = natPtr ? natPtr :
NativeUtil::nativeLookup(compilingClass, compilingMethod, jnjvm);
+ if (!natPtr && !module->isStaticCompiling()) {
+ fprintf(stderr, "Native function %s not found. Probably "
+ "not implemented by JnJVM?\n", compilingMethod->printString());
+ JavaJIT::printBacktrace();
+ JavaThread::get()->isolate->unknownError("can not find native method %s",
+ compilingMethod->printString());
+ }
Function* func = llvmFunction;
if (jnjvm) {
- module->executionEngine->addGlobalMapping(func, natPtr);
+ if (!module->isStaticCompiling())
+ module->executionEngine->addGlobalMapping(func, natPtr);
return llvmFunction;
}
@@ -230,7 +276,9 @@
val, "", currentBlock);
nativeArgs.push_back(res);
#else
- nativeArgs.push_back(module->getJavaClass(compilingClass, this));
+ Value* cl = module->getJavaClass(compilingClass);
+ cl= new LoadInst(cl, "", currentBlock);
+ nativeArgs.push_back(cl);
#endif
index = 2;
} else {
@@ -242,15 +290,10 @@
nativeArgs.push_back(i);
}
-
- LLVMSignatureInfo* LSI =
- module->getSignatureInfo(compilingMethod->getSignature());
- const llvm::Type* valPtrType = LSI->getNativePtrType();
- Value* valPtr =
- ConstantExpr::getIntToPtr(ConstantInt::get(Type::Int64Ty, (uint64)natPtr),
- valPtrType);
+ Value* nativeFunc = module->getNativeFunction(compilingMethod, natPtr);
+ nativeFunc = new LoadInst(nativeFunc, "", currentBlock);
- Value* result = llvm::CallInst::Create(valPtr, nativeArgs.begin(),
+ Value* result = llvm::CallInst::Create(nativeFunc, nativeArgs.begin(),
nativeArgs.end(), "", currentBlock);
if (returnType != Type::VoidTy)
@@ -309,7 +352,7 @@
// The compare and swap did not pass, look if it's a thin lock
Value* thinMask = ConstantInt::get(Type::Int32Ty, 0x80000000);
- Value* isThin = BinaryOperator::createAnd(atomic, thinMask, "",
+ Value* isThin = BinaryOperator::CreateAnd(atomic, thinMask, "",
currentBlock);
cmp = new ICmpInst(ICmpInst::ICMP_EQ, isThin, module->constantZero, "",
currentBlock);
@@ -320,7 +363,7 @@
currentBlock = ThinLockBB;
Value* idMask = ConstantInt::get(Type::Int32Ty, 0x7FFFFF00);
Value* cptMask = ConstantInt::get(Type::Int32Ty, 0xFF);
- Value* IdInLock = BinaryOperator::createAnd(atomic, idMask, "", currentBlock);
+ Value* IdInLock = BinaryOperator::CreateAnd(atomic, idMask, "", currentBlock);
Value* owner = new ICmpInst(ICmpInst::ICMP_EQ, threadId, IdInLock, "",
currentBlock);
@@ -330,7 +373,7 @@
currentBlock = OwnerBB;
// OK, we are the owner, now check if the counter will overflow.
- Value* count = BinaryOperator::createAnd(atomic, cptMask, "", currentBlock);
+ Value* count = BinaryOperator::CreateAnd(atomic, cptMask, "", currentBlock);
cmp = new ICmpInst(ICmpInst::ICMP_ULT, count, cptMask, "", currentBlock);
BasicBlock* IncCounterBB = createBasicBlock("Increment counter");
@@ -340,7 +383,7 @@
currentBlock = IncCounterBB;
// The counter will not overflow, increment it.
- Value* Add = BinaryOperator::createAdd(module->constantOne, atomic, "",
+ Value* Add = BinaryOperator::CreateAdd(module->constantOne, atomic, "",
currentBlock);
new StoreInst(Add, lockPtr, false, currentBlock);
BranchInst::Create(OK, currentBlock);
@@ -392,7 +435,7 @@
currentBlock = NotLockedOnceBB;
// Look if the lock is thin.
Value* thinMask = ConstantInt::get(Type::Int32Ty, 0x80000000);
- Value* isThin = BinaryOperator::createAnd(lock, thinMask, "",
+ Value* isThin = BinaryOperator::CreateAnd(lock, thinMask, "",
currentBlock);
cmp = new ICmpInst(ICmpInst::ICMP_EQ, isThin, module->constantZero, "",
currentBlock);
@@ -402,7 +445,7 @@
currentBlock = ThinLockBB;
// Decrement the counter.
- Value* Sub = BinaryOperator::createSub(lock, module->constantOne, "",
+ Value* Sub = BinaryOperator::CreateSub(lock, module->constantOne, "",
currentBlock);
new StoreInst(Sub, lockPtr, false, currentBlock);
BranchInst::Create(EndUnlock, currentBlock);
@@ -445,7 +488,8 @@
obj = llvmFunction->arg_begin();
} else {
#ifndef ISOLATE_SHARING
- obj = module->getStaticInstance(compilingClass, this);
+ obj = module->getStaticInstance(compilingClass);
+ obj = new LoadInst(obj, "", currentBlock);
#else
obj = getStaticInstanceCtp();
#endif
@@ -469,7 +513,8 @@
obj = llvmFunction->arg_begin();
} else {
#ifndef ISOLATE_SHARING
- obj = module->getStaticInstance(compilingClass, this);
+ obj = module->getStaticInstance(compilingClass);
+ obj = new LoadInst(obj, "", currentBlock);
#else
obj = getStaticInstanceCtp();
#endif
@@ -488,8 +533,7 @@
}
-Instruction* JavaJIT::inlineCompile(Function* parentFunction,
- BasicBlock*& curBB,
+Instruction* JavaJIT::inlineCompile(BasicBlock*& curBB,
BasicBlock* endExBlock,
std::vector<Value*>& args) {
PRINT_DEBUG(JNJVM_COMPILE, 1, COLOR_NORMAL, "inline compile %s\n",
@@ -515,12 +559,10 @@
LLVMMethodInfo* LMI = module->getMethodInfo(compilingMethod);
assert(LMI);
Function* func = LMI->getMethod();
- llvmFunction = parentFunction;
returnType = func->getReturnType();
endBlock = createBasicBlock("end");
- llvmFunction = parentFunction;
currentBlock = curBB;
endExceptionBlock = 0;
@@ -615,7 +657,7 @@
#endif
exploreOpcodes(&compilingClass->bytes->elements[start], codeLen);
-
+ nbEnveloppes = 0;
if (returnType != Type::VoidTy) {
endNode = llvm::PHINode::Create(returnType, "", endBlock);
@@ -655,7 +697,7 @@
PRINT_DEBUG(JNJVM_COMPILE, 1, COLOR_NORMAL, "compiling %s\n",
compilingMethod->printString());
-
+
Attribut* codeAtt = compilingMethod->lookupAttribut(Attribut::codeAttribut);
if (!codeAtt) {
@@ -790,8 +832,10 @@
unsigned nbe = readExceptionTable(reader);
exploreOpcodes(&compilingClass->bytes->elements[start], codeLen);
-
-
+ compilingMethod->enveloppes =
+ new (compilingClass->classLoader->allocator) Enveloppe[nbEnveloppes];
+ compilingMethod->nbEnveloppes = nbEnveloppes;
+ nbEnveloppes = 0;
endBlock = createBasicBlock("end");
@@ -811,9 +855,17 @@
pred_iterator PE = pred_end(endBlock);
if (PI == PE && returnType != Type::VoidTy) {
Instruction* I = currentBlock->getTerminator();
- assert(isa<UnreachableInst>(I) && "non terminator before buggy return");
- I->eraseFromParent();
- BranchInst::Create(endBlock, currentBlock);
+
+ assert((isa<UnreachableInst>(I) || isa<InvokeInst>(I)) &&
+ "Malformed end Java block");
+
+ if (isa<UnreachableInst>(I)) {
+ I->eraseFromParent();
+ BranchInst::Create(endBlock, currentBlock);
+ } else if (InvokeInst* II = dyn_cast<InvokeInst>(I)) {
+ II->setNormalDest(endBlock);
+ }
+
endNode->addIncoming(Constant::getNullValue(returnType),
currentBlock);
}
@@ -885,7 +937,7 @@
PRINT_DEBUG(JNJVM_COMPILE, 1, COLOR_NORMAL, "--> end compiling %s\n",
compilingMethod->printString());
- if (nbe == 0 && codeLen < 50)
+ if (nbe == 0 && codeLen < 50 && !callsStackWalker)
compilingMethod->canBeInlined = false;
return llvmFunction;
@@ -917,7 +969,8 @@
argsSync.push_back(llvmFunction->arg_begin());
} else {
#ifndef ISOLATE_SHARING
- Value* arg = module->getStaticInstance(compilingClass, this);
+ Value* arg = module->getStaticInstance(compilingClass);
+ arg = new LoadInst(arg, "", currentBlock);
#else
Value* arg = getStaticInstanceCtp();
#endif
@@ -1085,7 +1138,8 @@
isolateLocal, "", currentBlock);
#else
assert(cur->catchClass);
- cl = module->getNativeClass(cur->catchClass, this);
+ cl = module->getNativeClass(cur->catchClass);
+ cl = new LoadInst(cl, "", currentBlock);
#endif
Value* cmp = llvm::CallInst::Create(module->CompareExceptionFunction, cl, "",
currentBlock);
@@ -1158,7 +1212,8 @@
const UTF8* utf8 = ctpInfo->UTF8At(ctpInfo->ctpDef[index]);
JavaString* str = compilingClass->classLoader->UTF8ToStr(utf8);
- Value* val = module->getString(str, this);
+ Value* val = module->getString(str);
+ val = new LoadInst(val, "", currentBlock);
push(val, false);
#endif
@@ -1178,7 +1233,9 @@
#if !defined(ISOLATE)
if (ctpInfo->ctpRes[index]) {
CommonClass* cl = (CommonClass*)(ctpInfo->ctpRes[index]);
- push(module->getJavaClass(cl, this), false);
+ Value* Val = module->getJavaClass(cl);
+ Val = new LoadInst(Val, "", currentBlock);
+ push(Val, false);
} else {
#endif
Value* val = getResolvedClass(index, false);
@@ -1394,13 +1451,14 @@
Instruction* JavaJIT::lowerMathOps(const UTF8* name,
std::vector<Value*>& args) {
- if (name->equals(Jnjvm::abs)) {
+ JnjvmBootstrapLoader* loader = compilingClass->classLoader->bootstrapLoader;
+ if (name->equals(loader->abs)) {
const Type* Ty = args[0]->getType();
if (Ty == Type::Int32Ty) {
Constant* const_int32_9 = module->constantZero;
ConstantInt* const_int32_10 = module->constantMinusOne;
BinaryOperator* int32_tmpneg =
- BinaryOperator::create(Instruction::Sub, const_int32_9, args[0],
+ BinaryOperator::Create(Instruction::Sub, const_int32_9, args[0],
"tmpneg", currentBlock);
ICmpInst* int1_abscond =
new ICmpInst(ICmpInst::ICMP_SGT, args[0], const_int32_10, "abscond",
@@ -1412,7 +1470,7 @@
ConstantInt* const_int64_10 = module->constantLongMinusOne;
BinaryOperator* int64_tmpneg =
- BinaryOperator::create(Instruction::Sub, const_int64_9, args[0],
+ BinaryOperator::Create(Instruction::Sub, const_int64_9, args[0],
"tmpneg", currentBlock);
ICmpInst* int1_abscond = new ICmpInst(ICmpInst::ICMP_SGT, args[0],
@@ -1428,71 +1486,71 @@
return llvm::CallInst::Create(module->func_llvm_fabs_f64, args[0],
"tmp1", currentBlock);
}
- } else if (name->equals(Jnjvm::sqrt)) {
+ } else if (name->equals(loader->sqrt)) {
return llvm::CallInst::Create(module->func_llvm_sqrt_f64, args[0],
"tmp1", currentBlock);
- } else if (name->equals(Jnjvm::sin)) {
+ } else if (name->equals(loader->sin)) {
return llvm::CallInst::Create(module->func_llvm_sin_f64, args[0],
"tmp1", currentBlock);
- } else if (name->equals(Jnjvm::cos)) {
+ } else if (name->equals(loader->cos)) {
return llvm::CallInst::Create(module->func_llvm_cos_f64, args[0],
"tmp1", currentBlock);
- } else if (name->equals(Jnjvm::tan)) {
+ } else if (name->equals(loader->tan)) {
return llvm::CallInst::Create(module->func_llvm_tan_f64, args[0],
"tmp1", currentBlock);
- } else if (name->equals(Jnjvm::asin)) {
+ } else if (name->equals(loader->asin)) {
return llvm::CallInst::Create(module->func_llvm_asin_f64, args[0],
"tmp1", currentBlock);
- } else if (name->equals(Jnjvm::acos)) {
+ } else if (name->equals(loader->acos)) {
return llvm::CallInst::Create(module->func_llvm_acos_f64, args[0],
"tmp1", currentBlock);
- } else if (name->equals(Jnjvm::atan)) {
+ } else if (name->equals(loader->atan)) {
return llvm::CallInst::Create(module->func_llvm_atan_f64, args[0],
"tmp1", currentBlock);
- } else if (name->equals(Jnjvm::atan2)) {
+ } else if (name->equals(loader->atan2)) {
return llvm::CallInst::Create(module->func_llvm_atan2_f64,
args.begin(), args.end(), "tmp1",
currentBlock);
- } else if (name->equals(Jnjvm::exp)) {
+ } else if (name->equals(loader->exp)) {
return llvm::CallInst::Create(module->func_llvm_exp_f64, args[0],
"tmp1", currentBlock);
- } else if (name->equals(Jnjvm::log)) {
+ } else if (name->equals(loader->log)) {
return llvm::CallInst::Create(module->func_llvm_log_f64, args[0],
"tmp1", currentBlock);
- } else if (name->equals(Jnjvm::pow)) {
+ } else if (name->equals(loader->pow)) {
return llvm::CallInst::Create(module->func_llvm_pow_f64, args.begin(),
args.end(), "tmp1", currentBlock);
- } else if (name->equals(Jnjvm::ceil)) {
+ } else if (name->equals(loader->ceil)) {
return llvm::CallInst::Create(module->func_llvm_ceil_f64, args[0], "tmp1",
currentBlock);
- } else if (name->equals(Jnjvm::floor)) {
+ } else if (name->equals(loader->floor)) {
return llvm::CallInst::Create(module->func_llvm_floor_f64, args[0],
"tmp1", currentBlock);
- } else if (name->equals(Jnjvm::rint)) {
+ } else if (name->equals(loader->rint)) {
return llvm::CallInst::Create(module->func_llvm_rint_f64, args[0],
"tmp1", currentBlock);
- } else if (name->equals(Jnjvm::cbrt)) {
+ } else if (name->equals(loader->cbrt)) {
return llvm::CallInst::Create(module->func_llvm_cbrt_f64, args[0], "tmp1",
currentBlock);
- } else if (name->equals(Jnjvm::cosh)) {
+ } else if (name->equals(loader->cosh)) {
return llvm::CallInst::Create(module->func_llvm_cosh_f64, args[0], "tmp1",
currentBlock);
- } else if (name->equals(Jnjvm::expm1)) {
+ } else if (name->equals(loader->expm1)) {
return llvm::CallInst::Create(module->func_llvm_expm1_f64, args[0],
"tmp1", currentBlock);
- } else if (name->equals(Jnjvm::hypot)) {
+ } else if (name->equals(loader->hypot)) {
return llvm::CallInst::Create(module->func_llvm_hypot_f64, args[0],
"tmp1", currentBlock);
- } else if (name->equals(Jnjvm::log10)) {
+ } else if (name->equals(loader->log10)) {
return llvm::CallInst::Create(module->func_llvm_log10_f64, args[0],
"tmp1", currentBlock);
- } else if (name->equals(Jnjvm::log1p)) {
+ } else if (name->equals(loader->log1p)) {
return llvm::CallInst::Create(module->func_llvm_log1p_f64, args[0],
"tmp1", currentBlock);
- } else if (name->equals(Jnjvm::sinh)) {
+ } else if (name->equals(loader->sinh)) {
return llvm::CallInst::Create(module->func_llvm_sinh_f64, args[0],
"tmp1", currentBlock);
- } else if (name->equals(Jnjvm::tanh)) {
+ } else if (name->equals(loader->tanh)) {
return llvm::CallInst::Create(module->func_llvm_tanh_f64, args[0],
"tmp1", currentBlock);
}
@@ -1504,14 +1562,12 @@
Instruction* JavaJIT::invokeInline(JavaMethod* meth,
std::vector<Value*>& args) {
- JavaJIT jit;
- jit.compilingClass = meth->classDef;
- jit.compilingMethod = meth;
+ JavaJIT jit(meth, llvmFunction);
jit.unifiedUnreachable = unifiedUnreachable;
jit.inlineMethods = inlineMethods;
jit.inlineMethods[meth] = true;
- jit.module = module;
- Instruction* ret = jit.inlineCompile(llvmFunction, currentBlock,
+ jit.inlining = true;
+ Instruction* ret = jit.inlineCompile(currentBlock,
currentExceptionBlock, args);
inlineMethods[meth] = false;
return ret;
@@ -1533,7 +1589,7 @@
makeArgs(it, index, args, signature->args.size() + 1);
JITVerifyNull(args[0]);
- if (cl->equals(Jnjvm::mathName)) {
+ if (cl->equals(compilingClass->classLoader->bootstrapLoader->mathName)) {
val = lowerMathOps(name, args);
}
@@ -1568,8 +1624,7 @@
(Function*)ctpInfo->infoOfStaticOrSpecialMethod(index, ACC_VIRTUAL,
signature, meth);
- if (meth && meth->canBeInlined && meth != compilingMethod &&
- inlineMethods[meth] == 0) {
+ if (meth && canBeInlined(meth)) {
val = invokeInline(meth, args);
} else {
val = invoke(func, args, "", currentBlock);
@@ -1603,10 +1658,15 @@
makeArgs(it, index, args, signature->args.size());
ctpInfo->markAsStaticCall(index);
- if (cl->equals(Jnjvm::mathName)) {
+ JnjvmBootstrapLoader* loader = compilingClass->classLoader->bootstrapLoader;
+ if (cl->equals(loader->mathName)) {
val = lowerMathOps(name, args);
}
+ if (cl->equals(loader->stackWalkerName)) {
+ callsStackWalker = true;
+ }
+
if (!val) {
Function* func = (Function*)
ctpInfo->infoOfStaticOrSpecialMethod(index, ACC_STATIC,
@@ -1620,8 +1680,7 @@
args.push_back(newCtpCache);
#endif
- if (meth && meth->canBeInlined && meth != compilingMethod &&
- inlineMethods[meth] == 0) {
+ if (meth && canBeInlined(meth)) {
val = invokeInline(meth, args);
} else {
val = invoke(func, args, "", currentBlock);
@@ -1655,8 +1714,10 @@
Args.clear();
#else
JavaConstantPool* ctp = compilingClass->ctpInfo;
- Value* CTP = module->getConstantPool(ctp, this);
- Value* Cl = module->getNativeClass(compilingClass, this);
+ Value* CTP = module->getConstantPool(ctp);
+ CTP = new LoadInst(CTP, "", currentBlock);
+ Value* Cl = module->getNativeClass(compilingClass);
+ Cl = new LoadInst(Cl, "", currentBlock);
#endif
Args.push_back(resolver);
@@ -1712,10 +1773,12 @@
currentBlock);
} else {
LLVMClassInfo* LCI = module->getClassInfo(cl);
- Size = LCI->getVirtualSize(this);
+ Size = LCI->getVirtualSize();
#ifndef ISOLATE_SHARING
- VT = module->getVirtualTable(cl, this);
- Cl = module->getNativeClass(cl, this);
+ 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);
@@ -1784,10 +1847,25 @@
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);
+ Cl = invoke(module->InitialisationCheckFunction, Cl, "",
+ currentBlock);
+ CallInst::Create(module->ForceInitialisationCheckFunction, Cl, "",
+ currentBlock);
+ object = module->getStaticInstance(field->classDef);
+ object = new LoadInst(object, "", currentBlock);
+ type = LCI->getStaticType();
+ return fieldGetter(this, type, object, LFI->getOffset());
+ }
+
if (field->classDef->isReady()) {
- object = module->getStaticInstance(field->classDef, this);
+ object = module->getStaticInstance(field->classDef);
+ object = new LoadInst(object, "", currentBlock);
type = LCI->getStaticType();
return fieldGetter(this, type, object, LFI->getOffset());
}
@@ -1801,29 +1879,29 @@
}
}
- const Type* Pty = module->arrayPtrType;
- Constant* zero = module->constantZero;
+ const Type* Pty = module->arrayPtrType;
+ Constant* zero = module->constantZero;
- Function* func = stat ? module->StaticFieldLookupFunction :
- module->VirtualFieldLookupFunction;
+ Function* func = stat ? module->StaticFieldLookupFunction :
+ module->VirtualFieldLookupFunction;
- const Type* returnType = 0;
- if (stat)
- returnType = module->ptrType;
- else
- returnType = Type::Int32Ty;
+ const Type* returnType = 0;
+ if (stat)
+ returnType = module->ptrType;
+ else
+ returnType = Type::Int32Ty;
- Value* ptr = getConstantPoolAt(index, func, returnType, 0, true);
- if (!stat) {
- Value* tmp = new BitCastInst(object, Pty, "", currentBlock);
- std::vector<Value*> args;
- args.push_back(zero);
- args.push_back(ptr);
- ptr = GetElementPtrInst::Create(tmp, args.begin(), args.end(), "",
- currentBlock);
- }
+ Value* ptr = getConstantPoolAt(index, func, returnType, 0, true);
+ if (!stat) {
+ Value* tmp = new BitCastInst(object, Pty, "", currentBlock);
+ std::vector<Value*> args;
+ args.push_back(zero);
+ args.push_back(ptr);
+ ptr = GetElementPtrInst::Create(tmp, args.begin(), args.end(), "",
+ currentBlock);
+ }
- return new BitCastInst(ptr, fieldTypePtr, "", currentBlock);
+ return new BitCastInst(ptr, fieldTypePtr, "", currentBlock);
}
void JavaJIT::convertValue(Value*& val, const Type* t1, BasicBlock* currentBlock,
@@ -2021,15 +2099,12 @@
#ifndef ISOLATE_SHARING
// ok now the cache
- mvm::BumpPtrAllocator& allocator = compilingClass->classLoader->allocator;
- Enveloppe* enveloppe =
- new(allocator) Enveloppe(compilingClass->ctpInfo, index);
- compilingMethod->caches.push_back(enveloppe);
+ Enveloppe& enveloppe = compilingMethod->enveloppes[nbEnveloppes++];
+ if (!inlining)
+ enveloppe.initialise(compilingClass->ctpInfo, index);
- Value* llvmEnv =
- ConstantExpr::getIntToPtr(ConstantInt::get(Type::Int64Ty,
- uint64_t (enveloppe)),
- module->EnveloppeType);
+ Value* llvmEnv = module->getEnveloppe(&enveloppe);
+ llvmEnv = new LoadInst(llvmEnv, "", currentBlock);
#else
Value* llvmEnv = getConstantPoolAt(index,
module->EnveloppeLookupFunction,
Modified: vmkit/branches/release_024/lib/JnJVM/VMCore/JavaJIT.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/JnJVM/VMCore/JavaJIT.h?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/JnJVM/VMCore/JavaJIT.h (original)
+++ vmkit/branches/release_024/lib/JnJVM/VMCore/JavaJIT.h Mon Nov 3 04:20:55 2008
@@ -64,6 +64,16 @@
public:
+ JavaJIT(JavaMethod* meth, llvm::Function* func) {
+ nbEnveloppes = 0;
+ compilingMethod = meth;
+ compilingClass = meth->classDef;
+ module = compilingClass->classLoader->getModule();
+ llvmFunction = func;
+ inlining = false;
+ callsStackWalker = false;
+ }
+
JnjvmModule* module;
static void invokeOnceVoid(Jnjvm* vm, JnjvmClassLoader* loader,
@@ -74,12 +84,12 @@
llvm::Function* javaCompile();
llvm::Function* nativeCompile(void* natPtr = 0);
- llvm::Instruction* inlineCompile(llvm::Function* parentFunction,
- llvm::BasicBlock*& curBB,
+ llvm::Instruction* inlineCompile(llvm::BasicBlock*& curBB,
llvm::BasicBlock* endExBlock,
std::vector<llvm::Value*>& args);
std::map<JavaMethod*, bool> inlineMethods;
+ bool inlining;
Class* compilingClass;
JavaMethod* compilingMethod;
@@ -266,6 +276,13 @@
static JavaObject* getCallingClassLoader();
static void printBacktrace();
static JavaMethod* IPToJavaMethod(void* ip);
+
+ /// nbEnveloppes - Number of enveloppes (ie invokeinterface) in this
+ /// method.
+ uint32 nbEnveloppes;
+
+ bool canBeInlined(JavaMethod* meth);
+ bool callsStackWalker;
};
enum Opcode {
Modified: vmkit/branches/release_024/lib/JnJVM/VMCore/JavaJITOpcodes.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/JnJVM/VMCore/JavaJITOpcodes.cpp?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/JnJVM/VMCore/JavaJITOpcodes.cpp (original)
+++ vmkit/branches/release_024/lib/JnJVM/VMCore/JavaJITOpcodes.cpp Mon Nov 3 04:20:55 2008
@@ -775,7 +775,7 @@
case IADD : {
Value* val2 = popAsInt();
Value* val1 = popAsInt();
- push(BinaryOperator::createAdd(val1, val2, "", currentBlock),
+ push(BinaryOperator::CreateAdd(val1, val2, "", currentBlock),
false);
break;
}
@@ -785,7 +785,7 @@
llvm::Value* val2 = pop();
pop();
llvm::Value* val1 = pop();
- push(BinaryOperator::createAdd(val1, val2, "", currentBlock),
+ push(BinaryOperator::CreateAdd(val1, val2, "", currentBlock),
false);
push(module->constantZero, false);
break;
@@ -794,7 +794,7 @@
case FADD : {
Value* val2 = pop();
Value* val1 = pop();
- push(BinaryOperator::createAdd(val1, val2, "", currentBlock),
+ push(BinaryOperator::CreateAdd(val1, val2, "", currentBlock),
false);
break;
}
@@ -804,7 +804,7 @@
llvm::Value* val2 = pop();
pop();
llvm::Value* val1 = pop();
- push(BinaryOperator::createAdd(val1, val2, "", currentBlock),
+ push(BinaryOperator::CreateAdd(val1, val2, "", currentBlock),
false);
push(module->constantZero, false);
break;
@@ -813,7 +813,7 @@
case ISUB : {
Value* val2 = popAsInt();
Value* val1 = popAsInt();
- push(BinaryOperator::createSub(val1, val2, "", currentBlock),
+ push(BinaryOperator::CreateSub(val1, val2, "", currentBlock),
false);
break;
}
@@ -822,7 +822,7 @@
llvm::Value* val2 = pop();
pop();
llvm::Value* val1 = pop();
- push(BinaryOperator::createSub(val1, val2, "", currentBlock),
+ push(BinaryOperator::CreateSub(val1, val2, "", currentBlock),
false);
push(module->constantZero, false);
break;
@@ -831,7 +831,7 @@
case FSUB : {
Value* val2 = pop();
Value* val1 = pop();
- push(BinaryOperator::createSub(val1, val2, "", currentBlock),
+ push(BinaryOperator::CreateSub(val1, val2, "", currentBlock),
false);
break;
}
@@ -841,7 +841,7 @@
llvm::Value* val2 = pop();
pop();
llvm::Value* val1 = pop();
- push(BinaryOperator::createSub(val1, val2, "", currentBlock),
+ push(BinaryOperator::CreateSub(val1, val2, "", currentBlock),
false);
push(module->constantZero, false);
break;
@@ -850,7 +850,7 @@
case IMUL : {
Value* val2 = popAsInt();
Value* val1 = popAsInt();
- push(BinaryOperator::createMul(val1, val2, "", currentBlock),
+ push(BinaryOperator::CreateMul(val1, val2, "", currentBlock),
false);
break;
}
@@ -860,7 +860,7 @@
llvm::Value* val2 = pop();
pop();
llvm::Value* val1 = pop();
- push(BinaryOperator::createMul(val1, val2, "", currentBlock),
+ push(BinaryOperator::CreateMul(val1, val2, "", currentBlock),
false);
push(module->constantZero, false);
break;
@@ -869,7 +869,7 @@
case FMUL : {
Value* val2 = pop();
Value* val1 = pop();
- push(BinaryOperator::createMul(val1, val2, "", currentBlock),
+ push(BinaryOperator::CreateMul(val1, val2, "", currentBlock),
false);
break;
}
@@ -879,7 +879,7 @@
llvm::Value* val2 = pop();
pop();
llvm::Value* val1 = pop();
- push(BinaryOperator::createMul(val1, val2, "", currentBlock),
+ push(BinaryOperator::CreateMul(val1, val2, "", currentBlock),
false);
push(module->constantZero, false);
break;
@@ -888,7 +888,7 @@
case IDIV : {
Value* val2 = popAsInt();
Value* val1 = popAsInt();
- push(BinaryOperator::createSDiv(val1, val2, "", currentBlock),
+ push(BinaryOperator::CreateSDiv(val1, val2, "", currentBlock),
false);
break;
}
@@ -898,7 +898,7 @@
llvm::Value* val2 = pop();
pop();
llvm::Value* val1 = pop();
- push(BinaryOperator::createSDiv(val1, val2, "", currentBlock),
+ push(BinaryOperator::CreateSDiv(val1, val2, "", currentBlock),
false);
push(module->constantZero, false);
break;
@@ -907,7 +907,7 @@
case FDIV : {
Value* val2 = pop();
Value* val1 = pop();
- push(BinaryOperator::createFDiv(val1, val2, "", currentBlock),
+ push(BinaryOperator::CreateFDiv(val1, val2, "", currentBlock),
false);
break;
}
@@ -917,7 +917,7 @@
llvm::Value* val2 = pop();
pop();
llvm::Value* val1 = pop();
- push(BinaryOperator::createFDiv(val1, val2, "", currentBlock),
+ push(BinaryOperator::CreateFDiv(val1, val2, "", currentBlock),
false);
push(module->constantZero, false);
break;
@@ -926,7 +926,7 @@
case IREM : {
Value* val2 = popAsInt();
Value* val1 = popAsInt();
- push(BinaryOperator::createSRem(val1, val2, "", currentBlock),
+ push(BinaryOperator::CreateSRem(val1, val2, "", currentBlock),
false);
break;
}
@@ -936,7 +936,7 @@
llvm::Value* val2 = pop();
pop();
llvm::Value* val1 = pop();
- push(BinaryOperator::createSRem(val1, val2, "", currentBlock),
+ push(BinaryOperator::CreateSRem(val1, val2, "", currentBlock),
false);
push(module->constantZero, false);
break;
@@ -945,7 +945,7 @@
case FREM : {
Value* val2 = pop();
Value* val1 = pop();
- push(BinaryOperator::createFRem(val1, val2, "", currentBlock),
+ push(BinaryOperator::CreateFRem(val1, val2, "", currentBlock),
false);
break;
}
@@ -955,14 +955,14 @@
llvm::Value* val2 = pop();
pop();
llvm::Value* val1 = pop();
- push(BinaryOperator::createFRem(val1, val2, "", currentBlock),
+ push(BinaryOperator::CreateFRem(val1, val2, "", currentBlock),
false);
push(module->constantZero, false);
break;
}
case INEG :
- push(BinaryOperator::createSub(
+ push(BinaryOperator::CreateSub(
module->constantZero,
popAsInt(), "", currentBlock),
false);
@@ -970,7 +970,7 @@
case LNEG : {
pop();
- push(BinaryOperator::createSub(
+ push(BinaryOperator::CreateSub(
module->constantLongZero,
pop(), "", currentBlock), false);
push(module->constantZero, false);
@@ -978,14 +978,14 @@
}
case FNEG :
- push(BinaryOperator::createSub(
+ push(BinaryOperator::CreateSub(
module->constantFloatMinusZero,
pop(), "", currentBlock), false);
break;
case DNEG : {
pop();
- push(BinaryOperator::createSub(
+ push(BinaryOperator::CreateSub(
module->constantDoubleMinusZero,
pop(), "", currentBlock), false);
push(module->constantZero, false);
@@ -995,7 +995,7 @@
case ISHL : {
Value* val2 = popAsInt();
Value* val1 = popAsInt();
- push(BinaryOperator::createShl(val1, val2, "", currentBlock),
+ push(BinaryOperator::CreateShl(val1, val2, "", currentBlock),
false);
break;
}
@@ -1004,7 +1004,7 @@
Value* val2 = new ZExtInst(pop(), Type::Int64Ty, "", currentBlock);
pop(); // remove the 0 on the stack
Value* val1 = pop();
- push(BinaryOperator::createShl(val1, val2, "", currentBlock),
+ push(BinaryOperator::CreateShl(val1, val2, "", currentBlock),
false);
push(module->constantZero, false);
break;
@@ -1013,7 +1013,7 @@
case ISHR : {
Value* val2 = popAsInt();
Value* val1 = popAsInt();
- push(BinaryOperator::createAShr(val1, val2, "", currentBlock),
+ push(BinaryOperator::CreateAShr(val1, val2, "", currentBlock),
false);
break;
}
@@ -1022,7 +1022,7 @@
Value* val2 = new ZExtInst(pop(), Type::Int64Ty, "", currentBlock);
pop(); // remove the 0 on the stack
Value* val1 = pop();
- push(BinaryOperator::createAShr(val1, val2, "", currentBlock),
+ push(BinaryOperator::CreateAShr(val1, val2, "", currentBlock),
false);
push(module->constantZero, false);
break;
@@ -1033,7 +1033,7 @@
Value* val1 = popAsInt();
Value* mask = ConstantInt::get(Type::Int32Ty, 0x1F);
val2 = BinaryOperator::CreateAnd(val2, mask, "", currentBlock);
- push(BinaryOperator::createLShr(val1, val2, "", currentBlock),
+ push(BinaryOperator::CreateLShr(val1, val2, "", currentBlock),
false);
break;
}
@@ -1044,7 +1044,7 @@
val2 = BinaryOperator::CreateAnd(val2, mask, "", currentBlock);
pop(); // remove the 0 on the stack
Value* val1 = pop();
- push(BinaryOperator::createLShr(val1, val2, "", currentBlock),
+ push(BinaryOperator::CreateLShr(val1, val2, "", currentBlock),
false);
push(module->constantZero, false);
break;
@@ -1053,7 +1053,7 @@
case IAND : {
Value* val2 = popAsInt();
Value* val1 = popAsInt();
- push(BinaryOperator::createAnd(val1, val2, "", currentBlock),
+ push(BinaryOperator::CreateAnd(val1, val2, "", currentBlock),
false);
break;
}
@@ -1063,7 +1063,7 @@
Value* val2 = pop();
pop(); // remove the 0 on the stack
Value* val1 = pop();
- push(BinaryOperator::createAnd(val1, val2, "", currentBlock),
+ push(BinaryOperator::CreateAnd(val1, val2, "", currentBlock),
false);
push(module->constantZero, false);
break;
@@ -1072,7 +1072,7 @@
case IOR : {
Value* val2 = popAsInt();
Value* val1 = popAsInt();
- push(BinaryOperator::createOr(val1, val2, "", currentBlock),
+ push(BinaryOperator::CreateOr(val1, val2, "", currentBlock),
false);
break;
}
@@ -1082,7 +1082,7 @@
Value* val2 = pop();
pop(); // remove the 0 on the stack
Value* val1 = pop();
- push(BinaryOperator::createOr(val1, val2, "", currentBlock),
+ push(BinaryOperator::CreateOr(val1, val2, "", currentBlock),
false);
push(module->constantZero, false);
break;
@@ -1091,7 +1091,7 @@
case IXOR : {
Value* val2 = popAsInt();
Value* val1 = popAsInt();
- push(BinaryOperator::createXor(val1, val2, "", currentBlock),
+ push(BinaryOperator::CreateXor(val1, val2, "", currentBlock),
false);
break;
}
@@ -1101,7 +1101,7 @@
Value* val2 = pop();
pop(); // remove the 0 on the stack
Value* val1 = pop();
- push(BinaryOperator::createXor(val1, val2, "", currentBlock),
+ push(BinaryOperator::CreateXor(val1, val2, "", currentBlock),
false);
push(module->constantZero, false);
break;
@@ -1110,7 +1110,7 @@
case IINC : {
uint16 idx = WREAD_U1(bytecodes, true, i);
sint16 val = WREAD_S1(bytecodes, false, i);
- llvm::Value* add = BinaryOperator::createAdd(
+ llvm::Value* add = BinaryOperator::CreateAdd(
new LoadInst(intLocals[idx], "", currentBlock),
ConstantInt::get(Type::Int32Ty, val), "",
currentBlock);
@@ -1840,7 +1840,9 @@
uint8 id = bytecodes[++i];
uint8 charId = arrayType(id);
#ifndef ISOLATE_SHARING
- dcl = JavaThread::get()->isolate->arrayClasses[id - 4];
+ JnjvmBootstrapLoader* loader =
+ compilingClass->classLoader->bootstrapLoader;
+ dcl = loader->getArrayClass(id);
#else
std::vector<Value*> args;
args.push_back(isolateLocal);
@@ -1870,8 +1872,10 @@
sizeElement = module->constantPtrSize;
}
#ifndef ISOLATE_SHARING
- valCl = module->getNativeClass(dcl, this);
- TheVT = module->getVirtualTable(dcl, this);
+ valCl = module->getNativeClass(dcl);
+ valCl = new LoadInst(valCl, "", currentBlock);
+ TheVT = module->getVirtualTable(dcl);
+ TheVT = new LoadInst(TheVT, "", currentBlock);
#endif
llvm::Value* arg1 = popAsInt();
@@ -1918,10 +1922,10 @@
}
currentBlock = BB2;
- Value* mult = BinaryOperator::createMul(arg1, sizeElement, "",
+ Value* mult = BinaryOperator::CreateMul(arg1, sizeElement, "",
currentBlock);
Value* size =
- BinaryOperator::createAdd(module->JavaObjectSizeConstant, mult,
+ BinaryOperator::CreateAdd(module->JavaObjectSizeConstant, mult,
"", currentBlock);
std::vector<Value*> args;
args.push_back(size);
@@ -2001,7 +2005,8 @@
Value* clVar = 0;
#ifndef ISOLATE_SHARING
if (dcl) {
- clVar = module->getNativeClass(dcl, this);
+ clVar = module->getNativeClass(dcl);
+ clVar = new LoadInst(clVar, "", currentBlock);
} else
#endif
clVar = getResolvedClass(index, false);
@@ -2042,7 +2047,8 @@
Value* clVar = 0;
if (dcl) {
- clVar = module->getNativeClass(dcl, this);
+ clVar = module->getNativeClass(dcl);
+ clVar = new LoadInst(clVar, "", currentBlock);
} else {
clVar = getResolvedClass(index, false);
}
@@ -2107,7 +2113,8 @@
UserClassArray* dcl = JCL->constructArray(className);
compilingClass->ctpInfo->loadClass(index);
- Value* valCl = module->getNativeClass(dcl ,this);
+ Value* valCl = module->getNativeClass(dcl);
+ valCl = new LoadInst(valCl, "", currentBlock);
#endif
Value** args = (Value**)alloca(sizeof(Value*) * (dim + 2));
args[0] = valCl;
@@ -2450,6 +2457,7 @@
break;
case INVOKEINTERFACE :
+ ++nbEnveloppes;
i += 4;
break;
Modified: vmkit/branches/release_024/lib/JnJVM/VMCore/JavaMetaJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/JnJVM/VMCore/JavaMetaJIT.cpp?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/JnJVM/VMCore/JavaMetaJIT.cpp (original)
+++ vmkit/branches/release_024/lib/JnJVM/VMCore/JavaMetaJIT.cpp Mon Nov 3 04:20:55 2008
@@ -34,10 +34,9 @@
cl->initialiseClass(vm);
bool stat = access == ACC_STATIC ? true : false;
- UserClass* methodCl = 0;
JavaMethod* method = cl->lookupMethod(loader->asciizConstructUTF8(func),
loader->asciizConstructUTF8(sign), stat,
- true, methodCl);
+ true, 0);
va_list ap;
va_start(ap, access);
if (stat) {
@@ -146,11 +145,9 @@
} \
\
verifyNull(obj);\
- UserClass* methodCl = 0; \
- JavaMethod* meth = obj->classOf->lookupMethod(name, type, false, true, methodCl);\
\
Signdef* sign = getSignature(); \
- void* func = meth->compiledPtr();\
+ void* func = (((void***)obj)[0])[offset];\
return ((FUNC_TYPE_VIRTUAL_BUF)sign->getVirtualCallBuf())(vm, cl->getConstantPool(), func, obj, buf);\
}\
\
Modified: vmkit/branches/release_024/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp (original)
+++ vmkit/branches/release_024/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp Mon Nov 3 04:20:55 2008
@@ -60,7 +60,7 @@
if (!rcache) {
UserClass* methodCl = 0;
JavaMethod* dmeth = ocl->lookupMethod(utf8, sign->keyName, false, true,
- methodCl);
+ &methodCl);
#ifndef ISOLATE_SHARING
assert(dmeth->classDef->isReady() &&
"Class not ready in a virtual lookup.");
@@ -99,13 +99,12 @@
}
UserCommonClass* cl = 0;
- UserCommonClass* fieldCl = 0;
const UTF8* utf8 = 0;
Typedef* sign = 0;
ctpInfo->resolveField(index, cl, utf8, sign);
- JavaField* field = cl->lookupField(utf8, sign->keyName, false, true, fieldCl);
+ JavaField* field = cl->lookupField(utf8, sign->keyName, false, true, 0);
ctpInfo->ctpRes[index] = (void*)field->ptrOffset;
@@ -126,7 +125,7 @@
ctpInfo->resolveField(index, cl, utf8, sign);
- JavaField* field = cl->lookupField(utf8, sign->keyName, true, true, fieldCl);
+ JavaField* field = cl->lookupField(utf8, sign->keyName, true, true, &fieldCl);
fieldCl->initialiseClass(JavaThread::get()->isolate);
void* ptr =
@@ -169,7 +168,7 @@
shared->resolveMethod(index, baseCl, utf8, sign);
UserClass* methodCl = 0;
- refCl->lookupMethod(utf8, sign->keyName, true, true, methodCl);
+ refCl->lookupMethod(utf8, sign->keyName, true, true, &methodCl);
ctpInfo->ctpRes[index] = methodCl->getConstantPool();
shared->ctpRes[clIndex] = refCl->classDef;
return (void*)methodCl->getConstantPool();
@@ -196,7 +195,7 @@
shared->resolveMethod(index, baseCl, utf8, sign);
UserClass* methodCl = 0;
- refCl->lookupMethod(utf8, sign->keyName, false, true, methodCl);
+ refCl->lookupMethod(utf8, sign->keyName, false, true, &methodCl);
shared->ctpRes[clIndex] = refCl->classDef;
*res = methodCl->getConstantPool();
return methodCl->getConstantPool();
@@ -213,9 +212,8 @@
Signdef* sign = 0;
caller->getConstantPool()->resolveMethod(index, cl, utf8, sign);
- UserClass* methodCl = 0;
JavaMethod* dmeth = cl->lookupMethodDontThrow(utf8, sign->keyName, false,
- true, methodCl);
+ true, 0);
if (!dmeth) {
va_list ap;
va_start(ap, index);
@@ -224,8 +222,7 @@
assert(obj->classOf->isReady() && "Class not ready in a virtual lookup.");
// Arg, the bytecode is buggy! Perform the lookup on the object class
// and do not update offset.
- dmeth = obj->classOf->lookupMethod(utf8, sign->keyName, false, true,
- methodCl);
+ dmeth = obj->classOf->lookupMethod(utf8, sign->keyName, false, true, 0);
} else {
caller->getConstantPool()->ctpRes[index] = (void*)dmeth->offset;
}
@@ -304,7 +301,7 @@
JavaThread::get()->isolate->indexOutOfBounds(obj, index);
}
-extern "C" UserCommonClass* initialisationCheck(UserCommonClass* cl) {
+extern "C" UserCommonClass* jnjvmRuntimeInitialiseClass(UserCommonClass* cl) {
cl->initialiseClass(JavaThread::get()->isolate);
return cl;
}
Modified: vmkit/branches/release_024/lib/JnJVM/VMCore/JavaThread.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/JnJVM/VMCore/JavaThread.cpp?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/JnJVM/VMCore/JavaThread.cpp (original)
+++ vmkit/branches/release_024/lib/JnJVM/VMCore/JavaThread.cpp Mon Nov 3 04:20:55 2008
@@ -19,6 +19,7 @@
#include "JavaThread.h"
#include "Jnjvm.h"
+
using namespace jnjvm;
const unsigned int JavaThread::StateRunning = 0;
@@ -78,3 +79,27 @@
#endif
}
}
+
+// We define these here because gcc compiles the 'throw' keyword
+// differently, whether these are defined in a file or not. Since many
+// cpp files import JavaThread.h, they couldn't use the keyword.
+
+extern "C" void* __cxa_allocate_exception(unsigned);
+extern "C" void __cxa_throw(void*, void*, void*);
+
+void JavaThread::throwException(JavaObject* obj) {
+ JavaThread* th = JavaThread::get();
+ assert(th->pendingException == 0 && "pending exception already there?");
+ th->pendingException = obj;
+ void* exc = __cxa_allocate_exception(0);
+ th->internalPendingException = exc;
+ __cxa_throw(exc, 0, 0);
+}
+
+void JavaThread::throwPendingException() {
+ JavaThread* th = JavaThread::get();
+ assert(th->pendingException);
+ void* exc = __cxa_allocate_exception(0);
+ th->internalPendingException = exc;
+ __cxa_throw(exc, 0, 0);
+}
Modified: vmkit/branches/release_024/lib/JnJVM/VMCore/JavaThread.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/JnJVM/VMCore/JavaThread.h?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/JnJVM/VMCore/JavaThread.h (original)
+++ vmkit/branches/release_024/lib/JnJVM/VMCore/JavaThread.h Mon Nov 3 04:20:55 2008
@@ -20,9 +20,6 @@
#include "JavaObject.h"
-extern "C" void* __cxa_allocate_exception(unsigned);
-extern "C" void __cxa_throw(void*, void*, void*);
-
namespace jnjvm {
class Class;
@@ -69,23 +66,14 @@
return (void*)
((char*)JavaThread::get()->internalPendingException - 8 * sizeof(void*));
}
-
- static void throwException(JavaObject* obj) {
- JavaThread* th = JavaThread::get();
- assert(th->pendingException == 0 && "pending exception already there?");
- th->pendingException = obj;
- void* exc = __cxa_allocate_exception(0);
- th->internalPendingException = exc;
- __cxa_throw(exc, 0, 0);
- }
-
- static void throwPendingException() {
- JavaThread* th = JavaThread::get();
- assert(th->pendingException);
- void* exc = __cxa_allocate_exception(0);
- th->internalPendingException = exc;
- __cxa_throw(exc, 0, 0);
- }
+
+ /// throwException - Throws the given exception in the current thread.
+ ///
+ static void throwException(JavaObject* obj);
+
+ /// throwPendingException - Throws a pending exception created by JNI.
+ ///
+ static void throwPendingException();
static bool compareException(UserClass* cl) {
JavaObject* pe = JavaThread::get()->pendingException;
Modified: vmkit/branches/release_024/lib/JnJVM/VMCore/JavaTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/JnJVM/VMCore/JavaTypes.cpp?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/JnJVM/VMCore/JavaTypes.cpp (original)
+++ vmkit/branches/release_024/lib/JnJVM/VMCore/JavaTypes.cpp Mon Nov 3 04:20:55 2008
@@ -196,7 +196,7 @@
intptr_t Signdef::staticCallBuf() {
if (!_staticCallBuf) {
- LLVMSignatureInfo* LSI = initialLoader->TheModule->getSignatureInfo(this);
+ LLVMSignatureInfo* LSI = initialLoader->getModule()->getSignatureInfo(this);
LSI->getStaticBuf();
}
return _staticCallBuf;
@@ -204,7 +204,7 @@
intptr_t Signdef::virtualCallBuf() {
if (!_virtualCallBuf) {
- LLVMSignatureInfo* LSI = initialLoader->TheModule->getSignatureInfo(this);
+ LLVMSignatureInfo* LSI = initialLoader->getModule()->getSignatureInfo(this);
LSI->getVirtualBuf();
}
return _virtualCallBuf;
@@ -212,7 +212,7 @@
intptr_t Signdef::staticCallAP() {
if (!_staticCallAP) {
- LLVMSignatureInfo* LSI = initialLoader->TheModule->getSignatureInfo(this);
+ LLVMSignatureInfo* LSI = initialLoader->getModule()->getSignatureInfo(this);
LSI->getStaticAP();
}
return _staticCallAP;
@@ -220,7 +220,7 @@
intptr_t Signdef::virtualCallAP() {
if (!_virtualCallAP) {
- LLVMSignatureInfo* LSI = initialLoader->TheModule->getSignatureInfo(this);
+ LLVMSignatureInfo* LSI = initialLoader->getModule()->getSignatureInfo(this);
LSI->getVirtualAP();
}
return _virtualCallAP;
Modified: vmkit/branches/release_024/lib/JnJVM/VMCore/JavaUpcalls.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/JnJVM/VMCore/JavaUpcalls.cpp?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/JnJVM/VMCore/JavaUpcalls.cpp (original)
+++ vmkit/branches/release_024/lib/JnJVM/VMCore/JavaUpcalls.cpp Mon Nov 3 04:20:55 2008
@@ -430,11 +430,11 @@
JavaMethod* internString =
UPCALL_METHOD(loader, "java/lang/VMString", "intern",
"(Ljava/lang/String;)Ljava/lang/String;", ACC_STATIC);
- loader->TheModule->setMethod(internString, "internString");
+ loader->getModule()->setMethod(internString, "internString");
JavaMethod* isArray =
UPCALL_METHOD(loader, "java/lang/Class", "isArray", "()Z", ACC_VIRTUAL);
- loader->TheModule->setMethod(isArray, "isArray");
+ loader->getModule()->setMethod(isArray, "isArray");
UPCALL_REFLECT_CLASS_EXCEPTION(loader, InvocationTargetException);
@@ -594,17 +594,17 @@
JavaMethod* getCallingClass =
UPCALL_METHOD(loader, "gnu/classpath/VMStackWalker", "getCallingClass",
"()Ljava/lang/Class;", ACC_STATIC);
- loader->TheModule->setMethod(getCallingClass, "getCallingClass");
+ loader->getModule()->setMethod(getCallingClass, "getCallingClass");
JavaMethod* getCallingClassLoader =
UPCALL_METHOD(loader, "gnu/classpath/VMStackWalker", "getCallingClassLoader",
"()Ljava/lang/ClassLoader;", ACC_STATIC);
- loader->TheModule->setMethod(getCallingClassLoader, "getCallingClassLoader");
+ loader->getModule()->setMethod(getCallingClassLoader, "getCallingClassLoader");
JavaMethod* postProperties =
UPCALL_METHOD(loader, "gnu/classpath/VMSystemProperties", "postInit",
"(Ljava/util/Properties;)V", ACC_STATIC);
- loader->TheModule->setMethod(postProperties, "propertiesPostInit");
+ loader->getModule()->setMethod(postProperties, "propertiesPostInit");
}
extern "C" JavaString* internString(JavaString* obj) {
Modified: vmkit/branches/release_024/lib/JnJVM/VMCore/JavaUpcalls.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/JnJVM/VMCore/JavaUpcalls.h?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/JnJVM/VMCore/JavaUpcalls.h (original)
+++ vmkit/branches/release_024/lib/JnJVM/VMCore/JavaUpcalls.h Mon Nov 3 04:20:55 2008
@@ -15,19 +15,21 @@
#include "JnjvmConfig.h"
#define UPCALL_CLASS(vm, name) \
- vm->loadName(vm->asciizConstructUTF8(name), false, false)
+ vm->loadName(vm->asciizConstructUTF8(name), true, false)
#define UPCALL_PRIMITIVE_CLASS(loader, name, nb) \
new(loader->allocator) \
UserClassPrimitive(loader, loader->asciizConstructUTF8(name), nb) \
#define UPCALL_FIELD(vm, cl, name, type, acc) \
- UPCALL_CLASS(vm, cl)->constructField(vm->asciizConstructUTF8(name), \
- vm->asciizConstructUTF8(type), acc)
+ UPCALL_CLASS(vm, cl)->lookupFieldDontThrow(vm->asciizConstructUTF8(name), \
+ vm->asciizConstructUTF8(type), \
+ isStatic(acc), false, 0)
#define UPCALL_METHOD(vm, cl, name, type, acc) \
- UPCALL_CLASS(vm, cl)->constructMethod(vm->asciizConstructUTF8(name), \
- vm->asciizConstructUTF8(type), acc)
+ UPCALL_CLASS(vm, cl)->lookupMethodDontThrow(vm->asciizConstructUTF8(name), \
+ vm->asciizConstructUTF8(type), \
+ isStatic(acc), false, 0)
#define UPCALL_ARRAY_CLASS(loader, name, depth) \
loader->constructArray( \
@@ -40,14 +42,14 @@
name = UPCALL_CLASS(loader, "java/lang/reflect/"#name)
#define UPCALL_METHOD_EXCEPTION(loader, name) \
- Init##name = name->constructMethod(loader->asciizConstructUTF8("<init>"), \
- loader->asciizConstructUTF8("(Ljava/lang/String;)V"), \
- ACC_VIRTUAL);
+ Init##name = name->lookupMethodDontThrow(loader->asciizConstructUTF8("<init>"), \
+ loader->asciizConstructUTF8("(Ljava/lang/String;)V"), \
+ false, false, 0);
#define UPCALL_METHOD_WITH_EXCEPTION(loader, name) \
- ErrorWithExcp##name = name->constructMethod(loader->asciizConstructUTF8("<init>"), \
+ ErrorWithExcp##name = name->lookupMethodDontThrow(loader->asciizConstructUTF8("<init>"), \
loader->asciizConstructUTF8("(Ljava/lang/Throwable;)V"), \
- ACC_VIRTUAL);
+ false, false, 0);
namespace jnjvm {
Modified: vmkit/branches/release_024/lib/JnJVM/VMCore/Jni.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/JnJVM/VMCore/Jni.cpp?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/JnJVM/VMCore/Jni.cpp (original)
+++ vmkit/branches/release_024/lib/JnJVM/VMCore/Jni.cpp Mon Nov 3 04:20:55 2008
@@ -158,10 +158,9 @@
UserCommonClass* cl = NativeUtil::resolvedImplClass(vm, clazz, true);
if (cl->isArray()) assert(0 && "implement me");
JavaObject* res = ((UserClass*)cl)->doNew(vm);
- UserClass* methodCl = 0;
- JavaMethod* init = cl->lookupMethod(Jnjvm::initName,
+ JavaMethod* init = cl->lookupMethod(vm->bootstrapLoader->initName,
cl->classLoader->asciizConstructUTF8("(Ljava/lang/String;)V"),
- false, true, methodCl);
+ false, true, 0);
init->invokeIntSpecial(vm, (UserClass*)cl, res, vm->asciizToStr(msg));
th->pendingException = res;
th->returnFromNative();
@@ -329,8 +328,7 @@
UserCommonClass* cl = NativeUtil::resolvedImplClass(vm, clazz, true);
const UTF8* name = vm->asciizToInternalUTF8(aname);
const UTF8* type = vm->asciizToInternalUTF8(atype);
- UserClass* methodCl = 0;
- JavaMethod* meth = cl->lookupMethod(name, type, false, true, methodCl);
+ JavaMethod* meth = cl->lookupMethod(name, type, false, true, 0);
return (jmethodID)meth;
@@ -872,10 +870,9 @@
// TODO: find a better place to store the UTF8
Jnjvm* vm = JavaThread::get()->isolate;
UserCommonClass* cl = NativeUtil::resolvedImplClass(vm, clazz, true);
- UserCommonClass* realCl = 0;
return (jfieldID)
cl->lookupField(cl->classLoader->asciizConstructUTF8(name),
- cl->classLoader->asciizConstructUTF8(sig), 0, 1, realCl);
+ cl->classLoader->asciizConstructUTF8(sig), 0, 1, 0);
END_EXCEPTION
return 0;
@@ -1118,8 +1115,7 @@
UserCommonClass* cl = NativeUtil::resolvedImplClass(vm, clazz, true);
const UTF8* name = vm->asciizToInternalUTF8(aname);
const UTF8* type = vm->asciizToInternalUTF8(atype);
- UserClass* methodCl = 0;
- JavaMethod* meth = cl->lookupMethod(name, type, true, true, methodCl);
+ JavaMethod* meth = cl->lookupMethod(name, type, true, true, 0);
return (jmethodID)meth;
@@ -1369,11 +1365,10 @@
// TODO: find a better place to store the UTF8
Jnjvm* vm = JavaThread::get()->isolate;
UserCommonClass* cl = NativeUtil::resolvedImplClass(vm, clazz, true);
- UserCommonClass* realCl = 0;
return (jfieldID)
cl->lookupField(cl->classLoader->asciizConstructUTF8(name),
cl->classLoader->asciizConstructUTF8(sig), true, true,
- realCl);
+ 0);
END_EXCEPTION
return 0;
Modified: vmkit/branches/release_024/lib/JnJVM/VMCore/Jnjvm.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/JnJVM/VMCore/Jnjvm.cpp?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/JnJVM/VMCore/Jnjvm.cpp (original)
+++ vmkit/branches/release_024/lib/JnJVM/VMCore/Jnjvm.cpp Mon Nov 3 04:20:55 2008
@@ -40,55 +40,10 @@
using namespace jnjvm;
-#define DEF_UTF8(var) \
- const UTF8* Jnjvm::var = 0
-
- DEF_UTF8(NoClassDefFoundError);
- DEF_UTF8(initName);
- DEF_UTF8(clinitName);
- DEF_UTF8(clinitType);
- DEF_UTF8(runName);
- DEF_UTF8(prelib);
- DEF_UTF8(postlib);
- DEF_UTF8(mathName);
- DEF_UTF8(abs);
- DEF_UTF8(sqrt);
- DEF_UTF8(sin);
- DEF_UTF8(cos);
- DEF_UTF8(tan);
- DEF_UTF8(asin);
- DEF_UTF8(acos);
- DEF_UTF8(atan);
- DEF_UTF8(atan2);
- DEF_UTF8(exp);
- DEF_UTF8(log);
- DEF_UTF8(pow);
- DEF_UTF8(ceil);
- DEF_UTF8(floor);
- DEF_UTF8(rint);
- DEF_UTF8(cbrt);
- DEF_UTF8(cosh);
- DEF_UTF8(expm1);
- DEF_UTF8(hypot);
- DEF_UTF8(log10);
- DEF_UTF8(log1p);
- DEF_UTF8(sinh);
- DEF_UTF8(tanh);
- DEF_UTF8(finalize);
-
-#undef DEF_UTF8
-
const char* Jnjvm::dirSeparator = "/";
const char* Jnjvm::envSeparator = ":";
const unsigned int Jnjvm::Magic = 0xcafebabe;
-#ifndef ISOLATE
-/// If we're not in a multi-vm environment, this can be made static.
-std::vector<void*> Jnjvm::nativeLibs;
-JnjvmBootstrapLoader* Jnjvm::bootstrapLoader;
-std::map<const char, UserClassPrimitive*> Jnjvm::primitiveMap;
-#endif
-
typedef void (*clinit_t)(Jnjvm* vm, UserConstantPool*);
void UserCommonClass::initialiseClass(Jnjvm* vm) {
@@ -112,10 +67,9 @@
cl->resolveStaticClass();
status = inClinit;
- UserClass* methodCl;
- JavaMethod* meth = lookupMethodDontThrow(Jnjvm::clinitName,
- Jnjvm::clinitType, true,
- false, methodCl);
+ JavaMethod* meth = lookupMethodDontThrow(vm->bootstrapLoader->clinitName,
+ vm->bootstrapLoader->clinitType,
+ true, false, 0);
PRINT_DEBUG(JNJVM_LOAD, 0, COLOR_NORMAL, "; ", 0);
PRINT_DEBUG(JNJVM_LOAD, 0, LIGHT_GREEN, "clinit ", 0);
@@ -125,10 +79,9 @@
(JavaObject*)vm->gcAllocator.allocateManagedObject(cl->getStaticSize(),
cl->getStaticVT());
val->initialise(cl);
- CommonClass::field_map* map = cl->getStaticFields();
- for (CommonClass::field_iterator i = map->begin(), e = map->end(); i!= e;
- ++i) {
- i->second->initField(val, vm);
+ JavaField* fields = cl->getStaticFields();
+ for (uint32 i = 0; i < cl->nbStaticFields; ++i) {
+ fields[i].initField(val, vm);
}
cl->setStaticInstance(val);
@@ -182,9 +135,13 @@
vsnprintf(tmp, 4096, fmt, ap);
va_end(ap);
- JavaObject* obj = cl->doNew(this);
- init->invokeIntSpecial(this, cl, obj, asciizToStr(tmp));
- JavaThread::throwException(obj);
+ if (cl && !bootstrapLoader->getModule()->isStaticCompiling()) {
+ JavaObject* obj = cl->doNew(this);
+ init->invokeIntSpecial(this, cl, obj, asciizToStr(tmp));
+ JavaThread::throwException(obj);
+ } else {
+ throw std::string(tmp);
+ }
}
void Jnjvm::arrayStoreException() {
@@ -300,10 +257,10 @@
obj);
}
-void Jnjvm::noClassDefFoundError(const char* fmt, ...) {
+void Jnjvm::noClassDefFoundError(const UTF8* name) {
error(upcalls->NoClassDefFoundError,
upcalls->InitNoClassDefFoundError,
- fmt);
+ "Unable to load %s", name->UTF8ToAsciiz());
}
void Jnjvm::classNotFoundException(JavaString* str) {
@@ -794,12 +751,13 @@
info.readArgs(argc, argv, this);
if (info.className) {
int pos = info.appArgumentsPos;
- //llvm::cl::ParseCommandLineOptions(pos, argv,
- // " JnJVM Java Virtual Machine\n");
+
argv = argv + pos - 1;
argc = argc - pos + 1;
-
- bootstrapThread = gc_new(JavaThread)(0, this, mvm::Thread::get()->baseSP);
+
+ mvm::Thread* oldThread = mvm::Thread::get();
+ JavaThread thread(0, this, oldThread->baseSP);
+ bootstrapThread = &thread;
loadBootstrap();
@@ -826,10 +784,11 @@
executeClass(info.className, args);
waitForExit();
+ mvm::Thread::set(oldThread);
}
}
-Jnjvm::Jnjvm(uint32 memLimit) {
+Jnjvm::Jnjvm(JnjvmBootstrapLoader* loader) {
classpath = getenv("CLASSPATH");
if (!classpath) classpath = ".";
@@ -839,36 +798,11 @@
javavmEnv = &JNI_JavaVMTable;
-#ifdef ISOLATE_SHARING
- initialiseStatics();
-#endif
-
+ bootstrapLoader = loader;
upcalls = bootstrapLoader->upcalls;
-#ifdef ISOLATE_SHARING
throwable = upcalls->newThrowable;
-#endif
- arrayClasses[JavaArray::T_BOOLEAN - 4] = upcalls->ArrayOfBool;
- arrayClasses[JavaArray::T_BYTE - 4] = upcalls->ArrayOfByte;
- arrayClasses[JavaArray::T_CHAR - 4] = upcalls->ArrayOfChar;
- arrayClasses[JavaArray::T_SHORT - 4] = upcalls->ArrayOfShort;
- arrayClasses[JavaArray::T_INT - 4] = upcalls->ArrayOfInt;
- arrayClasses[JavaArray::T_FLOAT - 4] = upcalls->ArrayOfFloat;
- arrayClasses[JavaArray::T_LONG - 4] = upcalls->ArrayOfLong;
- arrayClasses[JavaArray::T_DOUBLE - 4] = upcalls->ArrayOfDouble;
-
- primitiveMap[I_VOID] = upcalls->OfVoid;
- primitiveMap[I_BOOL] = upcalls->OfBool;
- primitiveMap[I_BYTE] = upcalls->OfByte;
- primitiveMap[I_CHAR] = upcalls->OfChar;
- primitiveMap[I_SHORT] = upcalls->OfShort;
- primitiveMap[I_INT] = upcalls->OfInt;
- primitiveMap[I_FLOAT] = upcalls->OfFloat;
- primitiveMap[I_LONG] = upcalls->OfLong;
- primitiveMap[I_DOUBLE] = upcalls->OfDouble;
-
- upcalls->initialiseClasspath(bootstrapLoader);
-
+
}
const UTF8* Jnjvm::asciizToInternalUTF8(const char* asciiz) {
@@ -894,3 +828,91 @@
}
return (const UTF8*)tmp;
}
+
+
+static void compileClass(Class* cl) {
+
+ for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) {
+ JavaMethod& meth = cl->virtualMethods[i];
+ if (!isAbstract(meth.access))
+ cl->classLoader->TheModuleProvider->parseFunction(&meth);
+ }
+
+ for (uint32 i = 0; i < cl->nbStaticMethods; ++i) {
+ JavaMethod& meth = cl->staticMethods[i];
+ if (!isAbstract(meth.access))
+ cl->classLoader->TheModuleProvider->parseFunction(&meth);
+ }
+}
+
+
+void Jnjvm::compile(const char* name) {
+ bootstrapLoader->analyseClasspathEnv(classpath);
+
+ mvm::Thread* oldThread = mvm::Thread::get();
+ JavaThread thread(0, this, oldThread->baseSP);
+ bootstrapThread = &thread;
+
+
+ uint32 size = strlen(name);
+ if (size > 4 &&
+ (!strcmp(&name[size - 4], ".jar") || !strcmp(&name[size - 4], ".zip"))) {
+
+
+ std::vector<Class*> classes;
+
+ ArrayUInt8* bytes = Reader::openFile(bootstrapLoader, name);
+ if (!bytes) unknownError("Can't find zip file.");
+ ZipArchive archive(bytes, bootstrapLoader->allocator);
+
+ char* realName = (char*)alloca(4096);
+ for (ZipArchive::table_iterator i = archive.filetable.begin(),
+ e = archive.filetable.end(); i != e; ++i) {
+ ZipFile* file = i->second;
+
+ size = strlen(file->filename);
+ if (size > 6 && !strcmp(&(file->filename[size - 6]), ".class")) {
+ UserClassArray* array = bootstrapLoader->upcalls->ArrayOfByte;
+ ArrayUInt8* res = (ArrayUInt8*)array->doNew(file->ucsize,
+ bootstrapLoader->allocator);
+ int ok = archive.readFile(res, file);
+ if (!ok) unknownError("Wrong zip file.");
+
+
+ memcpy(realName, file->filename, size);
+ realName[size - 6] = 0;
+ const UTF8* utf8 = bootstrapLoader->asciizConstructUTF8(realName);
+ Class* cl = bootstrapLoader->constructClass(utf8, res);
+ classes.push_back(cl);
+ }
+ }
+
+ // 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();
+ }
+
+ for (std::vector<Class*>::iterator i = classes.begin(), e = classes.end();
+ i != e; ++i) {
+ Class* cl = *i;
+ if (!cl->isInterface()) compileClass(cl);
+ }
+
+ } else {
+
+ const UTF8* utf8 = bootstrapLoader->asciizConstructUTF8(name);
+ UserClass* cl = bootstrapLoader->loadName(utf8, true, true);
+ compileClass(cl);
+ }
+
+ // Set the linkage to External, so that the printer does not complain.
+ llvm::Module* M = bootstrapLoader->getModule();
+ for (Module::iterator i = M->begin(), e = M->end(); i != e; ++i) {
+ i->setLinkage(llvm::GlobalValue::ExternalLinkage);
+ }
+
+ mvm::Thread::set(oldThread);
+}
Modified: vmkit/branches/release_024/lib/JnJVM/VMCore/Jnjvm.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/JnJVM/VMCore/Jnjvm.h?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/JnJVM/VMCore/Jnjvm.h (original)
+++ vmkit/branches/release_024/lib/JnJVM/VMCore/Jnjvm.h Mon Nov 3 04:20:55 2008
@@ -21,7 +21,6 @@
#include "mvm/Threads/Cond.h"
#include "mvm/Threads/Locks.h"
-#include "JavaTypes.h"
#include "JnjvmConfig.h"
#include "LockedMap.h"
@@ -89,14 +88,13 @@
///
mvm::BumpPtrAllocator allocator;
mvm::Allocator gcAllocator;
-#ifdef ISOLATE_SHARING
+
+ /// throwable - The java/lang/Throwable class. In an isolate
+ /// environment, generated code references this field.
UserClass* throwable;
-#endif
- std::map<const char, UserClassArray*> arrayClasses;
+
private:
- ISOLATE_STATIC std::map<const char, UserClassPrimitive*> primitiveMap;
-
/// bootstrapThread - The initial thread of this JVM.
///
JavaThread* bootstrapThread;
@@ -173,45 +171,11 @@
/// Magic - The magic number at the beginning of each .class file. 0xcafebabe.
///
static const unsigned int Magic;
-
- /// Lists of UTF8s used internaly in VMKit.
- static const UTF8* NoClassDefFoundError;
- static const UTF8* initName;
- static const UTF8* clinitName;
- static const UTF8* clinitType;
- static const UTF8* runName;
- static const UTF8* prelib;
- static const UTF8* postlib;
- static const UTF8* mathName;
- static const UTF8* abs;
- static const UTF8* sqrt;
- static const UTF8* sin;
- static const UTF8* cos;
- static const UTF8* tan;
- static const UTF8* asin;
- static const UTF8* acos;
- static const UTF8* atan;
- static const UTF8* atan2;
- static const UTF8* exp;
- static const UTF8* log;
- static const UTF8* pow;
- static const UTF8* ceil;
- static const UTF8* floor;
- static const UTF8* rint;
- static const UTF8* cbrt;
- static const UTF8* cosh;
- static const UTF8* expm1;
- static const UTF8* hypot;
- static const UTF8* log10;
- static const UTF8* log1p;
- static const UTF8* sinh;
- static const UTF8* tanh;
- static const UTF8* finalize;
/// bootstraLoader - Bootstrap loader for base classes of this virtual
/// machine.
///
- ISOLATE_STATIC JnjvmBootstrapLoader* bootstrapLoader;
+ JnjvmBootstrapLoader* bootstrapLoader;
/// upcalls - Upcalls to call Java methods and access Java fields.
///
@@ -234,10 +198,6 @@
///
std::vector< std::pair<char*, char*> > postProperties;
- /// nativeLibs - Native libraries (e.g. '.so') loaded by this JVM.
- ///
- ISOLATE_STATIC std::vector<void*> nativeLibs;
-
/// classpath - The CLASSPATH value, or the paths given in command line.
///
const char* classpath;
@@ -282,7 +242,7 @@
void noSuchMethodError(CommonClass* cl, const UTF8* name);
void classFormatError(const char* fmt, ...);
void noClassDefFoundError(JavaObject* obj);
- void noClassDefFoundError(const char* fmt, ...);
+ void noClassDefFoundError(const UTF8* name);
void classNotFoundException(JavaString* str);
/// asciizToStr - Constructs a java/lang/String object from the given asciiz.
@@ -326,25 +286,20 @@
void setClasspath(char* cp) {
classpath = cp;
}
-
- /// initialiseStatics - Initializes the isolate. The function initialize
- /// static variables in a single environment.
- ///
- ISOLATE_STATIC void initialiseStatics();
-
- ISOLATE_STATIC UserClassPrimitive* getPrimitiveClass(char id) {
- return primitiveMap[id];
- }
/// Jnjvm - Allocates a new JVM.
///
- Jnjvm(uint32 memLimit);
+ Jnjvm(JnjvmBootstrapLoader* loader);
/// runApplication - Runs the application with the given command line.
/// User-visible function, inherited by the VirtualMachine class.
///
virtual void runApplication(int argc, char** argv);
+ /// compile - Compile the .class, .zip or .jar file to LLVM IR.
+ ///
+ virtual void compile(const char* name);
+
};
} // end namespace jnjvm
Modified: vmkit/branches/release_024/lib/JnJVM/VMCore/JnjvmClassLoader.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/JnJVM/VMCore/JnjvmClassLoader.cpp?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/JnJVM/VMCore/JnjvmClassLoader.cpp (original)
+++ vmkit/branches/release_024/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Mon Nov 3 04:20:55 2008
@@ -7,10 +7,18 @@
//
//===----------------------------------------------------------------------===//
+#include <dlfcn.h>
#include <limits.h>
#include <unistd.h>
#include <sys/stat.h>
+
+#if defined(__MACH__)
+#define SELF_HANDLE RTLD_DEFAULT
+#else
+#define SELF_HANDLE 0
+#endif
+
#include "debug.h"
#include "mvm/Allocator.h"
@@ -29,21 +37,14 @@
using namespace jnjvm;
-#ifndef ISOLATE_SHARING
-JnjvmBootstrapLoader* JnjvmClassLoader::bootstrapLoader = 0;
-UserClass* JnjvmBootstrapLoader::SuperArray = 0;
-std::vector<UserClass*> JnjvmBootstrapLoader::InterfacesArray;
-#endif
-
-
extern const char* GNUClasspathGlibj;
extern const char* GNUClasspathLibs;
-JnjvmBootstrapLoader::JnjvmBootstrapLoader(uint32 memLimit) {
+JnjvmBootstrapLoader::JnjvmBootstrapLoader(bool staticCompilation) {
- JnjvmModule::initialise();
TheModule = new JnjvmModule("Bootstrap JnJVM");
- TheModuleProvider = new JnjvmModuleProvider(TheModule);
+ TheModuleProvider = new JnjvmModuleProvider(getModule());
+ getModule()->setIsStaticCompiling(staticCompilation);
hashUTF8 = new(allocator) UTF8Map(allocator, 0);
classes = new(allocator) ClassMap();
@@ -64,12 +65,166 @@
upcalls = new(allocator) Classpath();
bootstrapLoader = this;
+
+
+ // Create the name of char arrays.
+ const UTF8* utf8OfChar = asciizConstructUTF8("[C");
+
+ // Create the base class of char arrays.
+ upcalls->OfChar = UPCALL_PRIMITIVE_CLASS(this, "char", 2);
+
+ // Create the char array.
+ upcalls->ArrayOfChar = constructArray(utf8OfChar, upcalls->OfChar);
+
+ // Alright, now we can repair the damage: set the class to the UTF8s created
+ // and set the array class of UTF8s.
+ ((UTF8*)utf8OfChar)->classOf = upcalls->ArrayOfChar;
+ ((UTF8*)upcalls->OfChar->name)->classOf = upcalls->ArrayOfChar;
+ hashUTF8->array = upcalls->ArrayOfChar;
+
+ // Create the byte array, so that bytes for classes can be created.
+ upcalls->OfByte = UPCALL_PRIMITIVE_CLASS(this, "byte", 1);
+ upcalls->ArrayOfByte = constructArray(asciizConstructUTF8("[B"),
+ upcalls->OfByte);
+
+ InterfacesArray =
+ (Class**)allocator.Allocate(2 * sizeof(UserClass*));
+
+ // Now we can create the super and interfaces of arrays.
+ InterfacesArray[0] = loadName(asciizConstructUTF8("java/lang/Cloneable"),
+ false, false);
+
+ InterfacesArray[1] = loadName(asciizConstructUTF8("java/io/Serializable"),
+ false, false);
+
+ SuperArray = loadName(asciizConstructUTF8("java/lang/Object"), false,
+ false);
+
+ ClassArray::SuperArray = SuperArray->getInternal();
+ ClassArray::InterfacesArray =
+ (Class**)allocator.Allocate(2 * sizeof(UserClass*));
+ ClassArray::InterfacesArray[0] = (Class*)InterfacesArray[0]->getInternal();
+ ClassArray::InterfacesArray[1] = (Class*)(InterfacesArray[1]->getInternal());
+
+ // And repair the damage: set the interfaces and super of array classes already
+ // created.
+ upcalls->ArrayOfChar->setInterfaces(InterfacesArray);
+ upcalls->ArrayOfChar->setSuper(SuperArray);
+ upcalls->ArrayOfByte->setInterfaces(InterfacesArray);
+ upcalls->ArrayOfByte->setSuper(SuperArray);
+
+ // Yay, create the other primitive types.
+ upcalls->OfBool = UPCALL_PRIMITIVE_CLASS(this, "boolean", 1);
+ upcalls->OfShort = UPCALL_PRIMITIVE_CLASS(this, "short", 2);
+ upcalls->OfInt = UPCALL_PRIMITIVE_CLASS(this, "int", 4);
+ upcalls->OfLong = UPCALL_PRIMITIVE_CLASS(this, "long", 8);
+ upcalls->OfFloat = UPCALL_PRIMITIVE_CLASS(this, "float", 4);
+ upcalls->OfDouble = UPCALL_PRIMITIVE_CLASS(this, "double", 8);
+ upcalls->OfVoid = UPCALL_PRIMITIVE_CLASS(this, "void", 0);
+
+ // And finally create the primitive arrays.
+ upcalls->ArrayOfInt = constructArray(asciizConstructUTF8("[I"),
+ upcalls->OfInt);
+
+ upcalls->ArrayOfBool = constructArray(asciizConstructUTF8("[Z"),
+ upcalls->OfBool);
+
+ upcalls->ArrayOfLong = constructArray(asciizConstructUTF8("[J"),
+ upcalls->OfLong);
+
+ upcalls->ArrayOfFloat = constructArray(asciizConstructUTF8("[F"),
+ upcalls->OfFloat);
+
+ upcalls->ArrayOfDouble = constructArray(asciizConstructUTF8("[D"),
+ upcalls->OfDouble);
+
+ upcalls->ArrayOfShort = constructArray(asciizConstructUTF8("[S"),
+ upcalls->OfShort);
+
+ upcalls->ArrayOfString =
+ constructArray(asciizConstructUTF8("[Ljava/lang/String;"));
+
+ upcalls->ArrayOfObject =
+ constructArray(asciizConstructUTF8("[Ljava/lang/Object;"));
+
+
+ Attribut::codeAttribut = asciizConstructUTF8("Code");
+ Attribut::exceptionsAttribut = asciizConstructUTF8("Exceptions");
+ Attribut::constantAttribut = asciizConstructUTF8("ConstantValue");
+ Attribut::lineNumberTableAttribut = asciizConstructUTF8("LineNumberTable");
+ Attribut::innerClassesAttribut = asciizConstructUTF8("InnerClasses");
+ Attribut::sourceFileAttribut = asciizConstructUTF8("SourceFile");
+
+ initName = asciizConstructUTF8("<init>");
+ clinitName = asciizConstructUTF8("<clinit>");
+ clinitType = asciizConstructUTF8("()V");
+ runName = asciizConstructUTF8("run");
+ prelib = asciizConstructUTF8("lib");
+#if defined(__MACH__)
+ postlib = asciizConstructUTF8(".dylib");
+#else
+ postlib = asciizConstructUTF8(".so");
+#endif
+ mathName = asciizConstructUTF8("java/lang/Math");
+ stackWalkerName = asciizConstructUTF8("gnu/classpath/VMStackWalker");
+ NoClassDefFoundError = asciizConstructUTF8("java/lang/NoClassDefFoundError");
+
+#define DEF_UTF8(var) \
+ var = asciizConstructUTF8(#var)
+
+ DEF_UTF8(abs);
+ DEF_UTF8(sqrt);
+ DEF_UTF8(sin);
+ DEF_UTF8(cos);
+ DEF_UTF8(tan);
+ DEF_UTF8(asin);
+ DEF_UTF8(acos);
+ DEF_UTF8(atan);
+ DEF_UTF8(atan2);
+ DEF_UTF8(exp);
+ DEF_UTF8(log);
+ DEF_UTF8(pow);
+ DEF_UTF8(ceil);
+ DEF_UTF8(floor);
+ DEF_UTF8(rint);
+ DEF_UTF8(cbrt);
+ DEF_UTF8(cosh);
+ DEF_UTF8(expm1);
+ DEF_UTF8(hypot);
+ DEF_UTF8(log10);
+ DEF_UTF8(log1p);
+ DEF_UTF8(sinh);
+ DEF_UTF8(tanh);
+ DEF_UTF8(finalize);
+
+#undef DEF_UTF8
+
+ primitiveMap[I_VOID] = upcalls->OfVoid;
+ primitiveMap[I_BOOL] = upcalls->OfBool;
+ primitiveMap[I_BYTE] = upcalls->OfByte;
+ primitiveMap[I_CHAR] = upcalls->OfChar;
+ primitiveMap[I_SHORT] = upcalls->OfShort;
+ primitiveMap[I_INT] = upcalls->OfInt;
+ primitiveMap[I_FLOAT] = upcalls->OfFloat;
+ primitiveMap[I_LONG] = upcalls->OfLong;
+ primitiveMap[I_DOUBLE] = upcalls->OfDouble;
+
+ arrayTable[JavaArray::T_BOOLEAN - 4] = upcalls->ArrayOfBool;
+ arrayTable[JavaArray::T_BYTE - 4] = upcalls->ArrayOfByte;
+ arrayTable[JavaArray::T_CHAR - 4] = upcalls->ArrayOfChar;
+ arrayTable[JavaArray::T_SHORT - 4] = upcalls->ArrayOfShort;
+ arrayTable[JavaArray::T_INT - 4] = upcalls->ArrayOfInt;
+ arrayTable[JavaArray::T_FLOAT - 4] = upcalls->ArrayOfFloat;
+ arrayTable[JavaArray::T_LONG - 4] = upcalls->ArrayOfLong;
+ arrayTable[JavaArray::T_DOUBLE - 4] = upcalls->ArrayOfDouble;
+
+ upcalls->initialiseClasspath(this);
}
JnjvmClassLoader::JnjvmClassLoader(JnjvmClassLoader& JCL, JavaObject* loader,
Jnjvm* I) {
TheModule = new JnjvmModule("Applicative loader");
- TheModuleProvider = new JnjvmModuleProvider(TheModule);
+ TheModuleProvider = new JnjvmModuleProvider(getModule());
bootstrapLoader = JCL.bootstrapLoader;
hashUTF8 = new(allocator) UTF8Map(allocator,
@@ -81,12 +236,10 @@
javaLoader = loader;
isolate = I;
-#ifdef ISOLATE_SHARING
JavaMethod* meth = bootstrapLoader->upcalls->loadInClassLoader;
loader->classOf->lookupMethodDontThrow(meth->name, meth->type, false, true,
- loadClass);
+ &loadClass);
assert(loadClass && "Loader does not have a loadClass function");
-#endif
}
@@ -142,12 +295,7 @@
const UTF8* javaName = name->internalToJava(isolate, 0, name->size);
JavaString* str = isolate->UTF8ToStr(javaName);
Classpath* upcalls = bootstrapLoader->upcalls;
- UserClass* forCtp = 0;
-#ifdef ISOLATE_SHARING
- forCtp = loadClass;
-#else
- forCtp = upcalls->loadInClassLoader->classDef;
-#endif
+ UserClass* forCtp = loadClass;
JavaObject* obj = (JavaObject*)
upcalls->loadInClassLoader->invokeJavaObjectVirtual(isolate, forCtp,
javaLoader, str);
@@ -166,10 +314,10 @@
if (!cl && doThrow) {
Jnjvm* vm = JavaThread::get()->isolate;
- if (!(name->equals(Jnjvm::NoClassDefFoundError))) {
+ if (name->equals(bootstrapLoader->NoClassDefFoundError)) {
vm->unknownError("Unable to load NoClassDefFoundError");
}
- vm->noClassDefFoundError("unable to load %s", name->printString());
+ vm->noClassDefFoundError(name);
}
if (cl && doResolve) cl->resolveClass();
@@ -342,10 +490,10 @@
break;
default :
UserClassPrimitive* cl =
- isolate->getPrimitiveClass((char)name->elements[0]);
+ bootstrapLoader->getPrimitiveClass((char)name->elements[0]);
assert(cl && "No primitive");
- bool unsign = (cl == isolate->upcalls->OfChar ||
- cl == isolate->upcalls->OfBool);
+ bool unsign = (cl == bootstrapLoader->upcalls->OfChar ||
+ cl == bootstrapLoader->upcalls->OfBool);
res = new(allocator) PrimitiveTypedef(name, cl, unsign, cur);
}
return res;
@@ -515,3 +663,22 @@
return readerConstructUTF8(buf, n);
}
+
+void* JnjvmClassLoader::loadLib(const char* buf, bool& jnjvm) {
+ void* res = dlsym(SELF_HANDLE, buf);
+
+ if (!res) {
+ for (std::vector<void*>::iterator i = nativeLibs.begin(),
+ e = nativeLibs.end(); i!= e; ++i) {
+ res = dlsym((*i), buf);
+ if (res) break;
+ }
+ } else {
+ jnjvm = true;
+ }
+
+ if (!res && this != bootstrapLoader)
+ res = bootstrapLoader->loadLib(buf, jnjvm);
+
+ return res;
+}
Modified: vmkit/branches/release_024/lib/JnJVM/VMCore/JnjvmClassLoader.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/JnJVM/VMCore/JnjvmClassLoader.h?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/JnJVM/VMCore/JnjvmClassLoader.h (original)
+++ vmkit/branches/release_024/lib/JnJVM/VMCore/JnjvmClassLoader.h Mon Nov 3 04:20:55 2008
@@ -16,6 +16,7 @@
#include "types.h"
#include "mvm/Allocator.h"
+#include "mvm/CompilationUnit.h"
#include "mvm/Object.h"
#include "mvm/PrintBuffer.h"
@@ -49,7 +50,7 @@
/// its own tables (signatures, UTF8, types) which are mapped to a single
/// table for non-isolate environments.
///
-class JnjvmClassLoader : public mvm::Object {
+class JnjvmClassLoader : public mvm::CompilationUnit {
private:
@@ -111,7 +112,9 @@
/// TheModule - JIT module for compiling methods.
///
- JnjvmModule* TheModule;
+ JnjvmModule* getModule() {
+ return (JnjvmModule*)TheModule;
+ }
/// TheModuleProvider - JIT module provider for dynamic class loading and
/// lazy compilation.
@@ -192,7 +195,7 @@
/// bootstrapLoader - The bootstrap loader of the JVM. Loads the base
/// classes.
///
- ISOLATE_STATIC JnjvmBootstrapLoader* bootstrapLoader;
+ JnjvmBootstrapLoader* bootstrapLoader;
/// ~JnjvmClassLoader - Destroy the loader. Depending on the JVM
/// configuration, this may destroy the tables, JIT module and
@@ -212,9 +215,7 @@
classes = 0;
}
-#ifdef ISOLATE_SHARING
UserClass* loadClass;
-#endif
const UTF8* constructArrayName(uint32 steps, const UTF8* className);
@@ -222,6 +223,12 @@
/// Strings hashed by this classloader.
std::vector<JavaString*, gc_allocator<JavaString*> > strings;
+
+ /// nativeLibs - Native libraries (e.g. '.so') loaded by this class loader.
+ ///
+ std::vector<void*> nativeLibs;
+
+ void* loadLib(const char* buf, bool& jnjvm);
};
/// JnjvmBootstrapLoader - This class is for the bootstrap class loader, which
@@ -278,7 +285,7 @@
/// createBootstrapLoader - Creates the bootstrap loader, first thing
/// to do before any execution of a JVM.
///
- JnjvmBootstrapLoader(uint32 memLimit);
+ JnjvmBootstrapLoader(bool staticCompilation);
JnjvmBootstrapLoader() {}
virtual JavaString* UTF8ToStr(const UTF8* utf8);
@@ -288,9 +295,62 @@
/// Java code.
///
Classpath* upcalls;
+
+ /// InterfacesArray - The interfaces that array classes implement.
+ ///
+ UserClass** InterfacesArray;
+
+ /// SuperArray - The super of array classes.
+ UserClass* SuperArray;
- ISOLATE_STATIC std::vector<UserClass*> InterfacesArray;
- ISOLATE_STATIC UserClass* SuperArray;
+ /// Lists of UTF8s used internaly in VMKit.
+ const UTF8* NoClassDefFoundError;
+ const UTF8* initName;
+ const UTF8* clinitName;
+ const UTF8* clinitType;
+ const UTF8* runName;
+ const UTF8* prelib;
+ const UTF8* postlib;
+ const UTF8* mathName;
+ const UTF8* stackWalkerName;
+ const UTF8* abs;
+ const UTF8* sqrt;
+ const UTF8* sin;
+ const UTF8* cos;
+ const UTF8* tan;
+ const UTF8* asin;
+ const UTF8* acos;
+ const UTF8* atan;
+ const UTF8* atan2;
+ const UTF8* exp;
+ const UTF8* log;
+ const UTF8* pow;
+ const UTF8* ceil;
+ const UTF8* floor;
+ const UTF8* rint;
+ const UTF8* cbrt;
+ const UTF8* cosh;
+ const UTF8* expm1;
+ const UTF8* hypot;
+ const UTF8* log10;
+ const UTF8* log1p;
+ const UTF8* sinh;
+ const UTF8* tanh;
+ const UTF8* finalize;
+
+ /// primitiveMap - Map of primitive classes, hashed by id.
+ std::map<const char, UserClassPrimitive*> primitiveMap;
+
+ UserClassPrimitive* getPrimitiveClass(char id) {
+ return primitiveMap[id];
+ }
+
+ /// arrayTable - Table of array classes.
+ UserClassArray* arrayTable[8];
+
+ UserClassArray* getArrayClass(unsigned id) {
+ return arrayTable[id - 4];
+ }
};
} // end namespace jnjvm
Modified: vmkit/branches/release_024/lib/JnJVM/VMCore/JnjvmModule.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/JnJVM/VMCore/JnjvmModule.cpp?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/JnJVM/VMCore/JnjvmModule.cpp (original)
+++ vmkit/branches/release_024/lib/JnJVM/VMCore/JnjvmModule.cpp Mon Nov 3 04:20:55 2008
@@ -8,18 +8,17 @@
//===----------------------------------------------------------------------===//
#include "llvm/CallingConv.h"
+#include "llvm/Instructions.h"
#include "llvm/Support/MutexGuard.h"
#include "mvm/JIT.h"
-#include "JavaJIT.h"
#include "JavaThread.h"
#include "JavaTypes.h"
#include "Jnjvm.h"
#include "JnjvmModule.h"
#include "JnjvmModuleProvider.h"
-#include "LockedMap.h"
using namespace jnjvm;
@@ -58,6 +57,7 @@
llvm::ConstantInt* JnjvmModule::OffsetDisplayInClassConstant;
llvm::ConstantInt* JnjvmModule::OffsetStatusInClassConstant;
llvm::ConstantInt* JnjvmModule::OffsetCtpInClassConstant;
+llvm::ConstantInt* JnjvmModule::ClassReadyConstant;
const llvm::Type* JnjvmModule::JavaClassType;
const llvm::Type* JnjvmModule::VTType;
llvm::ConstantInt* JnjvmModule::JavaArrayElementsOffsetConstant;
@@ -65,7 +65,7 @@
llvm::ConstantInt* JnjvmModule::JavaObjectLockOffsetConstant;
llvm::ConstantInt* JnjvmModule::JavaObjectClassOffsetConstant;
-Value* JnjvmModule::getNativeClass(CommonClass* classDef, JavaJIT* jit) {
+Value* JnjvmModule::getNativeClass(CommonClass* classDef) {
llvm::GlobalVariable* varGV = 0;
native_class_iterator End = nativeClasses.end();
native_class_iterator I = nativeClasses.find(classDef);
@@ -75,7 +75,7 @@
uint64_t (classDef)),
JnjvmModule::JavaClassType);
- varGV = new GlobalVariable(JnjvmModule::JavaClassType, true,
+ varGV = new GlobalVariable(JnjvmModule::JavaClassType, !staticCompilation,
GlobalValue::ExternalLinkage,
cons, "", this);
@@ -83,10 +83,10 @@
} else {
varGV = I->second;
}
- return new LoadInst(varGV, "", jit->currentBlock);
+ return varGV;
}
-Value* JnjvmModule::getConstantPool(JavaConstantPool* ctp, JavaJIT* jit) {
+Value* JnjvmModule::getConstantPool(JavaConstantPool* ctp) {
llvm::GlobalVariable* varGV = 0;
constant_pool_iterator End = constantPools.end();
constant_pool_iterator I = constantPools.find(ctp);
@@ -95,17 +95,17 @@
Constant* cons =
ConstantExpr::getIntToPtr(ConstantInt::get(Type::Int64Ty, uint64(ptr)),
mvm::MvmModule::ptrPtrType);
- varGV = new GlobalVariable(mvm::MvmModule::ptrPtrType, true,
+ varGV = new GlobalVariable(mvm::MvmModule::ptrPtrType, !staticCompilation,
GlobalValue::ExternalLinkage,
cons, "", this);
constantPools.insert(std::make_pair(ctp, varGV));
} else {
varGV = I->second;
}
- return new LoadInst(varGV, "", jit->currentBlock);
+ return varGV;
}
-Value* JnjvmModule::getString(JavaString* str, JavaJIT* jit) {
+Value* JnjvmModule::getString(JavaString* str) {
llvm::GlobalVariable* varGV;
string_iterator SI = strings.find(str);
if (SI != strings.end()) {
@@ -115,25 +115,44 @@
Constant* cons =
ConstantExpr::getIntToPtr(ConstantInt::get(Type::Int64Ty, uint64(ptr)),
JnjvmModule::JavaObjectType);
- varGV = new GlobalVariable(JnjvmModule::JavaObjectType, true,
+ varGV = new GlobalVariable(JnjvmModule::JavaObjectType, !staticCompilation,
GlobalValue::ExternalLinkage,
cons, "", this);
strings.insert(std::make_pair(str, varGV));
}
- return new LoadInst(varGV, "", jit->currentBlock);
+ return varGV;
}
-Value* JnjvmModule::getJavaClass(CommonClass* cl, JavaJIT* jit) {
+Value* JnjvmModule::getEnveloppe(Enveloppe* enveloppe) {
+ llvm::GlobalVariable* varGV;
+ enveloppe_iterator SI = enveloppes.find(enveloppe);
+ if (SI != enveloppes.end()) {
+ varGV = SI->second;
+ } else {
+ void* ptr = enveloppe;
+ Constant* cons =
+ ConstantExpr::getIntToPtr(ConstantInt::get(Type::Int64Ty, uint64(ptr)),
+ JnjvmModule::EnveloppeType);
+ varGV = new GlobalVariable(JnjvmModule::EnveloppeType, !staticCompilation,
+ GlobalValue::ExternalLinkage,
+ cons, "", this);
+ enveloppes.insert(std::make_pair(enveloppe, varGV));
+ }
+ return varGV;
+}
+
+Value* JnjvmModule::getJavaClass(CommonClass* cl) {
llvm::GlobalVariable* varGV = 0;
java_class_iterator End = javaClasses.end();
java_class_iterator I = javaClasses.find(cl);
if (I == End) {
- JavaObject* obj = cl->getClassDelegatee(JavaThread::get()->isolate);
+ JavaObject* obj = isStaticCompiling() ? 0 :
+ cl->getClassDelegatee(JavaThread::get()->isolate);
Constant* cons =
ConstantExpr::getIntToPtr(ConstantInt::get(Type::Int64Ty, uint64(obj)),
JnjvmModule::JavaObjectType);
- varGV = new GlobalVariable(JnjvmModule::JavaObjectType, true,
+ varGV = new GlobalVariable(JnjvmModule::JavaObjectType, !staticCompilation,
GlobalValue::ExternalLinkage,
cons, "", this);
@@ -141,10 +160,10 @@
} else {
varGV = I->second;
}
- return new LoadInst(varGV, "", jit->currentBlock);
+ return varGV;
}
-Value* JnjvmModule::getStaticInstance(Class* classDef, JavaJIT* jit) {
+Value* JnjvmModule::getStaticInstance(Class* classDef) {
llvm::GlobalVariable* varGV = 0;
static_instance_iterator End = staticInstances.end();
static_instance_iterator I = staticInstances.find(classDef);
@@ -156,7 +175,7 @@
ConstantExpr::getIntToPtr(ConstantInt::get(Type::Int64Ty,
uint64_t (obj)), JnjvmModule::JavaObjectType);
- varGV = new GlobalVariable(JnjvmModule::JavaObjectType, true,
+ varGV = new GlobalVariable(JnjvmModule::JavaObjectType, !staticCompilation,
GlobalValue::ExternalLinkage,
cons, "", this);
@@ -165,10 +184,10 @@
varGV = I->second;
}
- return new LoadInst(varGV, "", jit->currentBlock);
+ return varGV;
}
-Value* JnjvmModule::getVirtualTable(CommonClass* classDef, JavaJIT* jit) {
+Value* JnjvmModule::getVirtualTable(CommonClass* classDef) {
llvm::GlobalVariable* varGV = 0;
virtual_table_iterator End = virtualTables.end();
virtual_table_iterator I = virtualTables.find(classDef);
@@ -181,7 +200,7 @@
ConstantExpr::getIntToPtr(ConstantInt::get(Type::Int64Ty,
uint64_t(classDef->virtualVT)),
JnjvmModule::VTType);
- varGV = new GlobalVariable(JnjvmModule::VTType, true,
+ varGV = new GlobalVariable(JnjvmModule::VTType, !staticCompilation,
GlobalValue::ExternalLinkage,
cons, "", this);
@@ -189,17 +208,41 @@
} else {
varGV = I->second;
}
- return new LoadInst(varGV, "", jit->currentBlock);
+ return varGV;
+}
+
+Value* JnjvmModule::getNativeFunction(JavaMethod* meth, void* ptr) {
+ llvm::GlobalVariable* varGV = 0;
+ native_function_iterator End = nativeFunctions.end();
+ native_function_iterator I = nativeFunctions.find(meth);
+ if (I == End) {
+
+
+ LLVMSignatureInfo* LSI = getSignatureInfo(meth->getSignature());
+ const llvm::Type* valPtrType = LSI->getNativePtrType();
+
+ Constant* cons =
+ ConstantExpr::getIntToPtr(ConstantInt::get(Type::Int64Ty, uint64_t(ptr)),
+ valPtrType);
+
+ varGV = new GlobalVariable(valPtrType, !staticCompilation,
+ GlobalValue::ExternalLinkage,
+ cons, "", this);
+
+ nativeFunctions.insert(std::make_pair(meth, varGV));
+ } else {
+ varGV = I->second;
+ }
+ return varGV;
}
#ifndef WITHOUT_VTABLE
VirtualTable* JnjvmModule::allocateVT(Class* cl,
- CommonClass::method_iterator meths) {
- if (meths == cl->virtualMethods.end()) {
+ uint32 index) {
+ if (index == cl->nbVirtualMethods) {
uint64 size = cl->virtualTableSize;
mvm::BumpPtrAllocator& allocator = cl->classLoader->allocator;
VirtualTable* VT = (VirtualTable*)allocator.Allocate(size * sizeof(void*));
- if (!VT) JavaThread::get()->isolate->outOfMemoryError(size * sizeof(void*));
if (cl->super) {
Class* super = (Class*)cl->super;
assert(cl->virtualTableSize >= cl->super->virtualTableSize &&
@@ -211,14 +254,14 @@
}
return VT;
} else {
- JavaMethod* meth = meths->second;
+ JavaMethod& meth = cl->virtualMethods[index];
VirtualTable* VT = 0;
- if (meth->name->equals(Jnjvm::finalize)) {
- VT = allocateVT(cl, ++meths);
+ if (meth.name->equals(cl->classLoader->bootstrapLoader->finalize)) {
+ VT = allocateVT(cl, ++index);
#ifndef ISOLATE_SHARING
- meth->offset = 0;
- Function* func = cl->classLoader->TheModuleProvider->parseFunction(meth);
- if (!cl->super) meth->canBeInlined = true;
+ meth.offset = 0;
+ Function* func = cl->classLoader->TheModuleProvider->parseFunction(&meth);
+ if (!cl->super) meth.canBeInlined = true;
Function::iterator BB = func->begin();
BasicBlock::iterator I = BB->begin();
if (isa<ReturnInst>(I)) {
@@ -226,30 +269,37 @@
} else {
ExecutionEngine* EE = mvm::MvmModule::executionEngine;
// LLVM does not allow recursive compilation. Create the code now.
- ((void**)VT)[0] = EE->getPointerToFunction(func);
+ if (staticCompilation) {
+ ((void**)VT)[0] = func;
+ } else {
+ ((void**)VT)[0] = EE->getPointerToFunction(func);
+ }
}
#endif
} else {
- Class* methodCl = 0;
JavaMethod* parent = cl->super?
- cl->super->lookupMethodDontThrow(meth->name, meth->type, false, true,
- methodCl) :
+ cl->super->lookupMethodDontThrow(meth.name, meth.type, false, true,
+ 0) :
0;
uint64_t offset = 0;
if (!parent) {
offset = cl->virtualTableSize++;
- meth->offset = offset;
+ meth.offset = offset;
} else {
offset = parent->offset;
- meth->offset = parent->offset;
+ meth.offset = parent->offset;
}
- VT = allocateVT(cl, ++meths);
- LLVMMethodInfo* LMI = getMethodInfo(meth);
+ VT = allocateVT(cl, ++index);
+ LLVMMethodInfo* LMI = getMethodInfo(&meth);
Function* func = LMI->getMethod();
ExecutionEngine* EE = mvm::MvmModule::executionEngine;
- ((void**)VT)[offset] = EE->getPointerToFunctionOrStub(func);
+ if (staticCompilation) {
+ ((void**)VT)[offset] = func;
+ } else {
+ ((void**)VT)[offset] = EE->getPointerToFunctionOrStub(func);
+ }
}
return VT;
@@ -258,46 +308,20 @@
#endif
-VirtualTable* JnjvmModule::makeVT(Class* cl, bool stat) {
+llvm::Function* JnjvmModule::makeTracer(Class* cl, bool stat) {
- VirtualTable* res = 0;
-#ifndef WITHOUT_VTABLE
+ LLVMClassInfo* LCI = (LLVMClassInfo*)getClassInfo(cl);
+ const Type* type = stat ? LCI->getStaticType() : LCI->getVirtualType();
+ JavaField* fields = 0;
+ uint32 nbFields = 0;
if (stat) {
-#endif
- mvm::BumpPtrAllocator& allocator = cl->classLoader->allocator;
- res = (VirtualTable*)allocator.Allocate(VT_SIZE);
- memcpy(res, JavaObject::VT, VT_SIZE);
-#ifndef WITHOUT_VTABLE
+ fields = cl->getStaticFields();
+ nbFields = cl->nbStaticFields;
} else {
- if (cl->super) {
- cl->virtualTableSize = cl->super->virtualTableSize;
- } else {
- cl->virtualTableSize = VT_NB_FUNCS;
- }
- res = allocateVT(cl, cl->virtualMethods.begin());
-
- if (!(cl->super)) {
- uint32 size = (cl->virtualTableSize - VT_NB_FUNCS) * sizeof(void*);
-#define COPY(CLASS) \
- memcpy((void*)((unsigned)CLASS::VT + VT_SIZE), \
- (void*)((unsigned)res + VT_SIZE), size);
-
- COPY(JavaArray)
- COPY(JavaObject)
- COPY(ArrayObject)
-
-#undef COPY
- }
+ fields = cl->getVirtualFields();
+ nbFields = cl->nbVirtualFields;
}
-#endif
-
-
-#ifdef WITH_TRACER
- LLVMClassInfo* LCI = (LLVMClassInfo*)getClassInfo(cl);
- const Type* type = stat ? LCI->getStaticType() : LCI->getVirtualType();
- CommonClass::field_map& fields = stat ? cl->staticFields : cl->virtualFields;
-
Function* func = Function::Create(JnjvmModule::MarkAndTraceType,
GlobalValue::ExternalLinkage,
"markAndTraceObject",
@@ -329,10 +353,10 @@
}
#endif
- for (CommonClass::field_iterator i = fields.begin(), e = fields.end();
- i!= e; ++i) {
- if (i->second->getSignature()->trace()) {
- LLVMFieldInfo* LFI = getFieldInfo(i->second);
+ for (uint32 i = 0; i < nbFields; ++i) {
+ JavaField& cur = fields[i];
+ if (cur.getSignature()->trace()) {
+ LLVMFieldInfo* LFI = getFieldInfo(&cur);
std::vector<Value*> args; //size = 2
args.push_back(zero);
args.push_back(LFI->getOffset());
@@ -354,17 +378,61 @@
}
ReturnInst::Create(block);
-
- void* codePtr = mvm::MvmModule::executionEngine->getPointerToGlobal(func);
- ((void**)res)[VT_TRACER_OFFSET] = codePtr;
- func->deleteBody();
-
if (!stat) {
LCI->virtualTracerFunction = func;
} else {
LCI->staticTracerFunction = func;
}
+
+ return func;
+}
+
+VirtualTable* JnjvmModule::makeVT(Class* cl, bool stat) {
+
+ VirtualTable* res = 0;
+#ifndef WITHOUT_VTABLE
+ if (stat) {
+#endif
+ mvm::BumpPtrAllocator& allocator = cl->classLoader->allocator;
+ res = (VirtualTable*)allocator.Allocate(VT_SIZE);
+ memcpy(res, JavaObject::VT, VT_SIZE);
+#ifndef WITHOUT_VTABLE
+ } else {
+ if (cl->super) {
+ cl->virtualTableSize = cl->super->virtualTableSize;
+ } else {
+ cl->virtualTableSize = VT_NB_FUNCS;
+ }
+ res = allocateVT(cl, 0);
+
+ if (!(cl->super)) {
+ uint32 size = (cl->virtualTableSize - VT_NB_FUNCS) * sizeof(void*);
+#define COPY(CLASS) \
+ memcpy((void*)((unsigned)CLASS::VT + VT_SIZE), \
+ (void*)((unsigned)res + VT_SIZE), size);
+
+ COPY(JavaArray)
+ COPY(JavaObject)
+ COPY(ArrayObject)
+
+#undef COPY
+ }
+ }
+#endif
+
+#ifdef WITH_TRACER
+ llvm::Function* func = makeTracer(cl, stat);
+
+ if (staticCompilation) {
+ ((void**)res)[VT_TRACER_OFFSET] = func;
+ } else {
+ void* codePtr = mvm::MvmModule::executionEngine->getPointerToFunction(func);
+ ((void**)res)[VT_TRACER_OFFSET] = codePtr;
+ func->deleteBody();
+ }
+
+
#endif
return res;
}
@@ -373,8 +441,6 @@
const Type* LLVMClassInfo::getVirtualType() {
if (!virtualType) {
std::vector<const llvm::Type*> fields;
- JavaField** array =
- (JavaField**)alloca(sizeof(JavaField*) * classDef->virtualFields.size());
if (classDef->super) {
LLVMClassInfo* CLI =
@@ -384,38 +450,35 @@
fields.push_back(JnjvmModule::JavaObjectType->getContainedType(0));
}
- for (CommonClass::field_iterator i = classDef->virtualFields.begin(),
- e = classDef->virtualFields.end(); i!= e; ++i) {
- JavaField* field = i->second;
- array[field->num] = field;
- }
-
-
- for (uint32 index = 0; index < classDef->virtualFields.size(); ++index) {
- Typedef* type = array[index]->getSignature();
+ for (uint32 i = 0; i < classDef->nbVirtualFields; ++i) {
+ JavaField& field = classDef->virtualFields[i];
+ field.num = i;
+ Typedef* type = field.getSignature();
LLVMAssessorInfo& LAI = JnjvmModule::getTypedefInfo(type);
fields.push_back(LAI.llvmType);
}
+
StructType* structType = StructType::get(fields, false);
virtualType = PointerType::getUnqual(structType);
ExecutionEngine* engine = mvm::MvmModule::executionEngine;
const TargetData* targetData = engine->getTargetData();
const StructLayout* sl = targetData->getStructLayout(structType);
- for (CommonClass::field_iterator i = classDef->virtualFields.begin(),
- e = classDef->virtualFields.end(); i!= e; ++i) {
- JavaField* field = i->second;
- field->ptrOffset = sl->getElementOffset(field->num + 1);
+ for (uint32 i = 0; i < classDef->nbVirtualFields; ++i) {
+ JavaField& field = classDef->virtualFields[i];
+ field.ptrOffset = sl->getElementOffset(i + 1);
}
- JnjvmModule* Mod = classDef->classLoader->TheModule;
- VirtualTable* VT = Mod->makeVT((Class*)classDef, false);
-
uint64 size = mvm::MvmModule::getTypeSize(structType);
classDef->virtualSize = (uint32)size;
- classDef->virtualVT = VT;
virtualSizeConstant = ConstantInt::get(Type::Int32Ty, size);
+
+ JnjvmModule* Mod = classDef->classLoader->getModule();
+ if (!Mod->isStaticCompiling()) {
+ classDef->virtualVT = Mod->makeVT((Class*)classDef, false);
+ }
+
}
@@ -427,19 +490,12 @@
if (!staticType) {
Class* cl = (Class*)classDef;
std::vector<const llvm::Type*> fields;
- JavaField** array = (JavaField**)
- alloca(sizeof(JavaField*) * (classDef->staticFields.size() + 1));
fields.push_back(JnjvmModule::JavaObjectType->getContainedType(0));
- for (CommonClass::field_iterator i = classDef->staticFields.begin(),
- e = classDef->staticFields.end(); i!= e; ++i) {
- JavaField* field = i->second;
- array[field->num] = field;
- }
-
- for (uint32 index = 0; index < classDef->staticFields.size(); ++index) {
- JavaField* field = array[index];
- Typedef* type = field->getSignature();
+ for (uint32 i = 0; i < classDef->nbStaticFields; ++i) {
+ JavaField& field = classDef->staticFields[i];
+ field.num = i;
+ Typedef* type = field.getSignature();
LLVMAssessorInfo& LAI = JnjvmModule::getTypedefInfo(type);
fields.push_back(LAI.llvmType);
}
@@ -450,25 +506,24 @@
const TargetData* targetData = engine->getTargetData();
const StructLayout* sl = targetData->getStructLayout(structType);
- for (CommonClass::field_iterator i = classDef->staticFields.begin(),
- e = classDef->staticFields.end(); i!= e; ++i) {
- JavaField* field = i->second;
- field->ptrOffset = sl->getElementOffset(field->num + 1);
+ for (uint32 i = 0; i < classDef->nbStaticFields; ++i) {
+ JavaField& field = classDef->staticFields[i];
+ field.ptrOffset = sl->getElementOffset(i + 1);
}
-
- JnjvmModule* Mod = cl->classLoader->TheModule;
- VirtualTable* VT = Mod->makeVT((Class*)classDef, true);
-
uint64 size = mvm::MvmModule::getTypeSize(structType);
cl->staticSize = size;
- cl->staticVT = VT;
+
+ JnjvmModule* Mod = cl->classLoader->getModule();
+ if (!Mod->isStaticCompiling()) {
+ cl->staticVT = Mod->makeVT((Class*)classDef, true);
+ }
}
return staticType;
}
-Value* LLVMClassInfo::getVirtualSize(JavaJIT* jit) {
+Value* LLVMClassInfo::getVirtualSize() {
if (!virtualSizeConstant) {
getVirtualType();
virtualSizeConstant =
@@ -854,9 +909,9 @@
Module* JnjvmModule::initialModule;
void JnjvmModule::initialise() {
- initialModule = new Module("Initial jnjvm module");
- jnjvm::llvm_runtime::makeLLVMModuleContents(initialModule);
- Module* module = initialModule;
+ jnjvm::llvm_runtime::makeLLVMModuleContents(this);
+ Module* module = this;
+ initialModule = this;
VTType = module->getTypeByName("VT");
@@ -924,48 +979,10 @@
OffsetDepthInClassConstant = mvm::MvmModule::constantFour;
OffsetStatusInClassConstant = mvm::MvmModule::constantFive;
OffsetCtpInClassConstant = mvm::MvmModule::constantSix;
-
- LLVMAssessorInfo::initialise();
-}
-
-void JnjvmModule::InitField(JavaField* field, JavaObject* obj, uint64 val) {
- Typedef* type = field->getSignature();
- if (!type->isPrimitive()) {
- ((sint32*)((uint64)obj + field->ptrOffset))[0] = (sint32)val;
- return;
- }
-
- PrimitiveTypedef* prim = (PrimitiveTypedef*)type;
- if (prim->isLong()) {
- ((sint64*)((uint64)obj + field->ptrOffset))[0] = val;
- } else if (prim->isInt()) {
- ((sint32*)((uint64)obj + field->ptrOffset))[0] = (sint32)val;
- } else if (prim->isChar()) {
- ((uint16*)((uint64)obj + field->ptrOffset))[0] = (uint16)val;
- } else if (prim->isShort()) {
- ((sint16*)((uint64)obj + field->ptrOffset))[0] = (sint16)val;
- } else if (prim->isByte()) {
- ((sint8*)((uint64)obj + field->ptrOffset))[0] = (sint8)val;
- } else if (prim->isBool()) {
- ((uint8*)((uint64)obj + field->ptrOffset))[0] = (uint8)val;
- } else {
- // 0 value for everything else
- ((sint32*)((uint64)obj + field->ptrOffset))[0] = (sint32)val;
- }
-}
+ ClassReadyConstant = ConstantInt::get(Type::Int32Ty, clinitParent);
-void
-JnjvmModule::InitField(JavaField* field, JavaObject* obj, JavaObject* val) {
- ((JavaObject**)((uint64)obj + field->ptrOffset))[0] = val;
-}
-
-void JnjvmModule::InitField(JavaField* field, JavaObject* obj, double val) {
- ((double*)((uint64)obj + field->ptrOffset))[0] = val;
-}
-
-void JnjvmModule::InitField(JavaField* field, JavaObject* obj, float val) {
- ((float*)((uint64)obj + field->ptrOffset))[0] = val;
+ LLVMAssessorInfo::initialise();
}
void JnjvmModule::setMethod(JavaMethod* meth, const char* name) {
@@ -978,11 +995,15 @@
return getMethodInfo(meth)->getMethod();
}
-JnjvmModule::JnjvmModule(const std::string &ModuleID) : MvmModule(ModuleID) {
+JnjvmModule::JnjvmModule(const std::string &ModuleID, bool sc) :
+ MvmModule(ModuleID) {
+
std::string str =
mvm::MvmModule::executionEngine->getTargetData()->getStringRepresentation();
setDataLayout(str);
-
+ staticCompilation = sc;
+ if (!VTType) initialise();
+
Module* module = initialModule;
InterfaceLookupFunction = module->getFunction("jnjvmVirtualLookup");
@@ -990,6 +1011,7 @@
InitialisationCheckFunction = module->getFunction("initialisationCheck");
ForceInitialisationCheckFunction =
module->getFunction("forceInitialisationCheck");
+ InitialiseClassFunction = module->getFunction("jnjvmRuntimeInitialiseClass");
GetConstantPoolAtFunction = module->getFunction("getConstantPoolAt");
ArrayLengthFunction = module->getFunction("arrayLength");
Modified: vmkit/branches/release_024/lib/JnJVM/VMCore/JnjvmModule.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/JnJVM/VMCore/JnjvmModule.h?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/JnJVM/VMCore/JnjvmModule.h (original)
+++ vmkit/branches/release_024/lib/JnJVM/VMCore/JnjvmModule.h Mon Nov 3 04:20:55 2008
@@ -33,7 +33,6 @@
class JavaField;
class JavaMethod;
class JavaObject;
-class JavaJIT;
class JnjvmModule;
class Signdef;
@@ -68,7 +67,7 @@
const llvm::Type * staticType;
public:
- llvm::Value* getVirtualSize(JavaJIT* jit);
+ llvm::Value* getVirtualSize();
llvm::Function* getStaticTracer();
llvm::Function* getVirtualTracer();
const llvm::Type* getVirtualType();
@@ -185,6 +184,8 @@
std::map<const Class*, llvm::GlobalVariable*> staticInstances;
std::map<const JavaConstantPool*, llvm::GlobalVariable*> constantPools;
std::map<const JavaString*, llvm::GlobalVariable*> strings;
+ std::map<const Enveloppe*, llvm::GlobalVariable*> enveloppes;
+ std::map<const JavaMethod*, llvm::GlobalVariable*> nativeFunctions;
typedef std::map<const CommonClass*, llvm::GlobalVariable*>::iterator
native_class_iterator;
@@ -204,14 +205,31 @@
typedef std::map<const JavaString*, llvm::GlobalVariable*>::iterator
string_iterator;
+ typedef std::map<const Enveloppe*, llvm::GlobalVariable*>::iterator
+ enveloppe_iterator;
+
+ typedef std::map<const JavaMethod*, llvm::GlobalVariable*>::iterator
+ native_function_iterator;
+
+
+ bool staticCompilation;
-
+
+ llvm::Function* makeTracer(Class* cl, bool stat);
VirtualTable* makeVT(Class* cl, bool stat);
- VirtualTable* allocateVT(Class* cl, CommonClass::method_iterator meths);
+ VirtualTable* allocateVT(Class* cl, uint32 index);
-
-public:
+public:
+
+ bool isStaticCompiling() {
+ return staticCompilation;
+ }
+
+ void setIsStaticCompiling(bool sc) {
+ staticCompilation = sc;
+ }
+
static llvm::ConstantInt* JavaArraySizeOffsetConstant;
static llvm::ConstantInt* JavaArrayElementsOffsetConstant;
static llvm::ConstantInt* JavaObjectLockOffsetConstant;
@@ -252,6 +270,7 @@
llvm::Function* PrintMethodStartFunction;
llvm::Function* PrintMethodEndFunction;
llvm::Function* JniProceedPendingExceptionFunction;
+ llvm::Function* InitialiseClassFunction;
llvm::Function* InitialisationCheckFunction;
llvm::Function* ForceInitialisationCheckFunction;
llvm::Function* ClassLookupFunction;
@@ -311,6 +330,8 @@
static llvm::ConstantInt* OffsetDisplayInClassConstant;
static llvm::ConstantInt* OffsetStatusInClassConstant;
static llvm::ConstantInt* OffsetCtpInClassConstant;
+
+ static llvm::ConstantInt* ClassReadyConstant;
static llvm::Constant* JavaClassNullConstant;
@@ -330,13 +351,6 @@
llvm::Function* OutOfMemoryErrorFunction;
llvm::Function* NegativeArraySizeExceptionFunction;
- static void InitField(JavaField* field);
- static void InitField(JavaField* field, JavaObject* obj, uint64 val = 0);
- static void InitField(JavaField* field, JavaObject* obj, JavaObject* val);
- static void InitField(JavaField* field, JavaObject* obj, double val);
- static void InitField(JavaField* field, JavaObject* obj, float val);
-
-
static void resolveVirtualClass(Class* cl);
static void resolveStaticClass(Class* cl);
static void setMethod(JavaMethod* meth, const char* name);
@@ -360,16 +374,18 @@
static LLVMAssessorInfo& getTypedefInfo(Typedef* type);
- explicit JnjvmModule(const std::string &ModuleID);
- static void initialise();
+ explicit JnjvmModule(const std::string &ModuleID, bool sc = false);
+ void initialise();
- llvm::Value* getNativeClass(CommonClass* cl, JavaJIT* jit);
- llvm::Value* getJavaClass(CommonClass* cl, JavaJIT* jit);
- llvm::Value* getStaticInstance(Class* cl, JavaJIT* jit);
- llvm::Value* getVirtualTable(CommonClass* cl, JavaJIT* jit);
-
- llvm::Value* getString(JavaString* str, JavaJIT* jit);
- llvm::Value* getConstantPool(JavaConstantPool* ctp, JavaJIT* jit);
+ llvm::Value* getNativeClass(CommonClass* cl);
+ llvm::Value* getJavaClass(CommonClass* cl);
+ llvm::Value* getStaticInstance(Class* cl);
+ llvm::Value* getVirtualTable(CommonClass* cl);
+
+ llvm::Value* getEnveloppe(Enveloppe* enveloppe);
+ llvm::Value* getString(JavaString* str);
+ llvm::Value* getConstantPool(JavaConstantPool* ctp);
+ llvm::Value* getNativeFunction(JavaMethod* meth, void* natPtr);
private:
static llvm::Module* initialModule;
Modified: vmkit/branches/release_024/lib/JnJVM/VMCore/JnjvmModuleProvider.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/JnJVM/VMCore/JnjvmModuleProvider.cpp?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/JnJVM/VMCore/JnjvmModuleProvider.cpp (original)
+++ vmkit/branches/release_024/lib/JnJVM/VMCore/JnjvmModuleProvider.cpp Mon Nov 3 04:20:55 2008
@@ -37,9 +37,8 @@
Signdef* sign = 0;
ctpInfo->resolveMethod(index, cl, utf8, sign);
- Class* methodCl = 0;
JavaMethod* meth = cl->lookupMethod(utf8, sign->keyName, isStatic, true,
- methodCl);
+ 0);
#ifndef ISOLATE_SHARING
// A multi environment would have already initialized the class. Besides,
@@ -130,11 +129,7 @@
if (func->hasNotBeenReadFromBitcode()) {
// We are jitting. Take the lock.
llvm::MutexGuard locked(mvm::MvmModule::executionEngine->lock);
- JavaJIT jit;
- jit.compilingClass = meth->classDef;
- jit.compilingMethod = meth;
- jit.module = (JnjvmModule*)TheModule;
- jit.llvmFunction = func;
+ JavaJIT jit(meth, func);
if (isNative(meth->access)) {
jit.nativeCompile();
} else {
@@ -156,7 +151,7 @@
}
const llvm::FunctionType* type = 0;
- JnjvmModule* M = cl->classLoader->TheModule;
+ JnjvmModule* M = cl->classLoader->getModule();
LLVMSignatureInfo* LSI = M->getSignatureInfo(sign);
if (stat) {
Modified: vmkit/branches/release_024/lib/JnJVM/VMCore/LowerConstantCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/JnJVM/VMCore/LowerConstantCalls.cpp?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/JnJVM/VMCore/LowerConstantCalls.cpp (original)
+++ vmkit/branches/release_024/lib/JnJVM/VMCore/LowerConstantCalls.cpp Mon Nov 3 04:20:55 2008
@@ -19,7 +19,6 @@
#include "JnjvmModule.h"
-#include <iostream>
using namespace llvm;
using namespace jnjvm;
@@ -228,9 +227,82 @@
BranchInst::Create(NBB, ifTrue);
break;
}
- }
-
- else if (V == module->GetConstantPoolAtFunction) {
+ } else if (V == module->InitialisationCheckFunction) {
+ Changed = true;
+
+ BasicBlock* NBB = 0;
+ if (CI->getParent()->getTerminator() != CI) {
+ NBB = II->getParent()->splitBasicBlock(II);
+ CI->getParent()->getTerminator()->eraseFromParent();
+ } else {
+ InvokeInst* Invoke = dyn_cast<InvokeInst>(CI);
+ assert(Invoke && "Last instruction is not an invoke");
+ NBB = Invoke->getNormalDest();
+ }
+
+ Value* Cl = Call.getArgument(0);
+ std::vector<Value*> indexes;
+ indexes.push_back(mvm::MvmModule::constantZero);
+ indexes.push_back(module->OffsetStatusInClassConstant);
+ Value* StatusPtr = GetElementPtrInst::Create(Cl, indexes.begin(),
+ indexes.end(), "", CI);
+ Value* Status = new LoadInst(StatusPtr, "", CI);
+
+
+ Value* test = new ICmpInst(ICmpInst::ICMP_UGT, Status,
+ jnjvm::JnjvmModule::ClassReadyConstant,
+ "", CI);
+
+ BasicBlock* trueCl = BasicBlock::Create("Initialized", &F);
+ BasicBlock* falseCl = BasicBlock::Create("Uninitialized", &F);
+ PHINode* node = llvm::PHINode::Create(JnjvmModule::JavaClassType, "", trueCl);
+ node->addIncoming(Cl, CI->getParent());
+ BranchInst::Create(trueCl, falseCl, test, CI);
+
+ std::vector<Value*> Args;
+ Args.push_back(Cl);
+
+ Value* res = 0;
+ if (InvokeInst* Invoke = dyn_cast<InvokeInst>(CI)) {
+ BasicBlock* UI = Invoke->getUnwindDest();
+ res = InvokeInst::Create(module->InitialiseClassFunction,
+ trueCl, UI, Args.begin(),
+ Args.end(), "", falseCl);
+
+ // For some reason, an LLVM pass may add PHI nodes to the
+ // exception destination.
+ BasicBlock::iterator Temp = UI->getInstList().begin();
+ while (PHINode* PHI = dyn_cast<PHINode>(Temp)) {
+ Value* Val = PHI->getIncomingValueForBlock(CI->getParent());
+ PHI->removeIncomingValue(CI->getParent(), false);
+ PHI->addIncoming(Val, falseCl);
+ Temp++;
+ }
+
+ // And here we set the phi nodes of the normal dest of the Invoke
+ // instruction. The phi nodes have now the trueCl as basic block.
+ Temp = NBB->getInstList().begin();
+ while (PHINode* PHI = dyn_cast<PHINode>(Temp)) {
+ Value* Val = PHI->getIncomingValueForBlock(CI->getParent());
+ PHI->removeIncomingValue(CI->getParent(), false);
+ PHI->addIncoming(Val, trueCl);
+ Temp++;
+ }
+ } else {
+ res = CallInst::Create(module->InitialiseClassFunction,
+ Args.begin(), Args.end(), "",
+ falseCl);
+ BranchInst::Create(trueCl, falseCl);
+ }
+
+ node->addIncoming(res, falseCl);
+
+
+ CI->replaceAllUsesWith(node);
+ CI->eraseFromParent();
+ BranchInst::Create(NBB, trueCl);
+ break;
+ } else if (V == module->GetConstantPoolAtFunction) {
Function* resolver = dyn_cast<Function>(Call.getArgument(0));
assert(resolver && "Wrong use of GetConstantPoolAt");
const Type* returnType = resolver->getReturnType();
@@ -289,6 +361,17 @@
PHI->addIncoming(Val, falseCl);
Temp++;
}
+
+ // And here we set the phi nodes of the normal dest of the Invoke
+ // instruction. The phi nodes have now the trueCl as basic block.
+ Temp = NBB->getInstList().begin();
+ while (PHINode* PHI = dyn_cast<PHINode>(Temp)) {
+ Value* Val = PHI->getIncomingValueForBlock(CI->getParent());
+ PHI->removeIncomingValue(CI->getParent(), false);
+ PHI->addIncoming(Val, trueCl);
+ Temp++;
+ }
+
} else {
res = CallInst::Create(resolver, Args.begin(), Args.end(), "",
falseCl);
Modified: vmkit/branches/release_024/lib/JnJVM/VMCore/NativeUtil.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/JnJVM/VMCore/NativeUtil.cpp?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/JnJVM/VMCore/NativeUtil.cpp (original)
+++ vmkit/branches/release_024/lib/JnJVM/VMCore/NativeUtil.cpp Mon Nov 3 04:20:55 2008
@@ -30,12 +30,6 @@
return JavaThread::get()->isolate;
}
-#if defined(__MACH__)
-#define SELF_HANDLE RTLD_DEFAULT
-#else
-#define SELF_HANDLE 0
-#endif
-
#define PRE "Java_"
#define PRE_LEN 5
@@ -177,25 +171,6 @@
}
-static void* loadName(char* buf, bool& jnjvm) {
- void* res = dlsym(SELF_HANDLE, buf);
- if (!res) {
-#ifndef SERVICE_VM
- Jnjvm* vm = JavaThread::get()->isolate;
-#else
- Jnjvm* vm = Jnjvm::bootstrapVM;
-#endif
- for (std::vector<void*>::iterator i = vm->nativeLibs.begin(),
- e = vm->nativeLibs.end(); i!= e; ++i) {
- res = dlsym((*i), buf);
- if (res) break;
- }
- } else {
- jnjvm = true;
- }
- return res;
-}
-
void* NativeUtil::nativeLookup(CommonClass* cl, JavaMethod* meth, bool& jnjvm) {
const UTF8* jniConsClName = cl->name;
const UTF8* jniConsName = meth->name;
@@ -206,20 +181,13 @@
char* buf = (char*)alloca(3 + PRE_LEN + mnlen + clen + (mtlen << 1));
jniConsFromMeth(cl, meth, buf);
- void* res = loadName(buf, jnjvm);
+ void* res = cl->classLoader->loadLib(buf, jnjvm);
if (!res) {
buf = jniConsFromMeth2(cl, meth, buf);
- res = loadName(buf, jnjvm);
+ res = cl->classLoader->loadLib(buf, jnjvm);
if (!res) {
buf = jniConsFromMeth3(cl, meth, buf);
- res = loadName(buf, jnjvm);
- if (!res) {
- printf("Native function %s not found. Probably "
- "not implemented by JnJVM?\n", meth->printString());
- JavaJIT::printBacktrace();
- JavaThread::get()->isolate->unknownError("can not find native method %s",
- meth->printString());
- }
+ res = cl->classLoader->loadLib(buf, jnjvm);
}
}
return res;
Modified: vmkit/branches/release_024/lib/JnJVM/VMCore/Reader.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/JnJVM/VMCore/Reader.cpp?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/JnJVM/VMCore/Reader.cpp (original)
+++ vmkit/branches/release_024/lib/JnJVM/VMCore/Reader.cpp Mon Nov 3 04:20:55 2008
@@ -25,7 +25,7 @@
const int Reader::SeekCur = SEEK_CUR;
const int Reader::SeekEnd = SEEK_END;
-ArrayUInt8* Reader::openFile(JnjvmBootstrapLoader* loader, char* path) {
+ArrayUInt8* Reader::openFile(JnjvmBootstrapLoader* loader, const char* path) {
FILE* fp = fopen(path, "r");
ArrayUInt8* res = 0;
if (fp != 0) {
@@ -41,7 +41,7 @@
}
ArrayUInt8* Reader::openZip(JnjvmBootstrapLoader* loader, ZipArchive* archive,
- char* filename) {
+ const char* filename) {
ArrayUInt8* ret = 0;
ZipFile* file = archive->getFile(filename);
if (file != 0) {
Modified: vmkit/branches/release_024/lib/JnJVM/VMCore/Reader.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/JnJVM/VMCore/Reader.h?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/JnJVM/VMCore/Reader.h (original)
+++ vmkit/branches/release_024/lib/JnJVM/VMCore/Reader.h Mon Nov 3 04:20:55 2008
@@ -76,8 +76,8 @@
static const int SeekCur;
static const int SeekEnd;
- static ArrayUInt8* openFile(JnjvmBootstrapLoader* loader, char* path);
- static ArrayUInt8* openZip(JnjvmBootstrapLoader* loader, ZipArchive* archive, char* filename);
+ static ArrayUInt8* openFile(JnjvmBootstrapLoader* loader, const char* path);
+ static ArrayUInt8* openZip(JnjvmBootstrapLoader* loader, ZipArchive* archive, const char* filename);
uint8 readU1() {
return bytes->elements[cursor++];
Modified: vmkit/branches/release_024/lib/JnJVM/VMCore/VirtualTables.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/JnJVM/VMCore/VirtualTables.cpp?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/JnJVM/VMCore/VirtualTables.cpp (original)
+++ vmkit/branches/release_024/lib/JnJVM/VMCore/VirtualTables.cpp Mon Nov 3 04:20:55 2008
@@ -32,8 +32,6 @@
INIT(JavaArray);
INIT(ArrayObject);
- INIT(Class);
- INIT(ClassArray);
INIT(JavaObject);
INIT(JavaThread);
INIT(Jnjvm);
@@ -70,10 +68,11 @@
(*i)->MARK_AND_TRACE; }}
void CommonClass::TRACER {
- if (super) super->classLoader->MARK_AND_TRACE;
- for (std::vector<Class*, gc_allocator<Class*> >::iterator i = interfaces.begin(),
- e = interfaces.end(); i!= e; ++i) {
- (*i)->classLoader->MARK_AND_TRACE;
+ if (status >= prepared) {
+ if (super) super->classLoader->MARK_AND_TRACE;
+ for (uint32 i = 0; i < nbInterfaces; ++i) {
+ interfaces[i]->classLoader->MARK_AND_TRACE;
+ }
}
classLoader->MARK_AND_TRACE;
#if !defined(ISOLATE)
@@ -118,7 +117,6 @@
void Jnjvm::TRACER {
appClassLoader->MARK_AND_TRACE;
TRACE_VECTOR(JavaObject*, gc_allocator, globalRefs);
- bootstrapThread->MARK_AND_TRACE;
bootstrapLoader->MARK_AND_TRACE;
#if defined(ISOLATE_SHARING)
JnjvmSharedLoader::sharedLoader->MARK_AND_TRACE;
@@ -142,10 +140,6 @@
void JnjvmBootstrapLoader::TRACER {
traceClassMap(classes);
- for (std::vector<ZipArchive*>::iterator i = bootArchives.begin(),
- e = bootArchives.end(); i != e; ++i) {
- (*i)->bytes->MARK_AND_TRACE;
- }
#define TRACE_DELEGATEE(prim) \
prim->delegatee->MARK_AND_TRACE
@@ -159,6 +153,7 @@
TRACE_DELEGATEE(upcalls->OfLong);
TRACE_DELEGATEE(upcalls->OfDouble);
#undef TRACE_DELEGATEE
+
TRACE_VECTOR(JavaString*, gc_allocator, strings);
}
Modified: vmkit/branches/release_024/lib/JnJVM/VMCore/Zip.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/JnJVM/VMCore/Zip.h?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/JnJVM/VMCore/Zip.h (original)
+++ vmkit/branches/release_024/lib/JnJVM/VMCore/Zip.h Mon Nov 3 04:20:55 2008
@@ -34,6 +34,7 @@
class ZipArchive : public mvm::PermanentObject {
friend class JnjvmBootstrapLoader;
+ friend class Jnjvm;
private:
mvm::BumpPtrAllocator& allocator;
Modified: vmkit/branches/release_024/lib/N3/VMCore/CLIJit.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/N3/VMCore/CLIJit.cpp?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/N3/VMCore/CLIJit.cpp (original)
+++ vmkit/branches/release_024/lib/N3/VMCore/CLIJit.cpp Mon Nov 3 04:20:55 2008
@@ -223,7 +223,7 @@
#endif
}
BinaryOperator* int32_tmp6 =
- BinaryOperator::create(Instruction::Add, int32_i_015_0, const_int32_9,
+ BinaryOperator::Create(Instruction::Add, int32_i_015_0, const_int32_9,
"tmp6", label_bb);
LoadInst* int32_tmp10 = new LoadInst(ptr_tmp918, "tmp10", false, label_bb);
ICmpInst* int1_tmp12 = new ICmpInst(ICmpInst::ICMP_SGT, int32_tmp10,
Modified: vmkit/branches/release_024/lib/N3/VMCore/N3.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/N3/VMCore/N3.h?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/N3/VMCore/N3.h (original)
+++ vmkit/branches/release_024/lib/N3/VMCore/N3.h Mon Nov 3 04:20:55 2008
@@ -79,7 +79,7 @@
static const UTF8* floatName;
static const UTF8* doubleName;
static const UTF8* testInfinity;
-
+
};
} // end namespace n3
Modified: vmkit/branches/release_024/lib/N3/VMCore/N3Initialise.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/N3/VMCore/N3Initialise.cpp?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/N3/VMCore/N3Initialise.cpp (original)
+++ vmkit/branches/release_024/lib/N3/VMCore/N3Initialise.cpp Mon Nov 3 04:20:55 2008
@@ -10,6 +10,7 @@
#include <vector>
+#include "mvm/CompilationUnit.h"
#include "mvm/JIT.h"
#include "mvm/Threads/Locks.h"
@@ -327,11 +328,12 @@
}
-void mvm::VirtualMachine::initialiseCLIVM() {
+mvm::CompilationUnit* mvm::VirtualMachine::initialiseCLIVM() {
if (!N3::bootstrapVM) {
initialiseVT();
initialiseStatics();
}
+ return 0;
}
void VirtualMachine::runApplication(int argc, char** argv) {
@@ -339,7 +341,11 @@
((N3*)this)->runMain(argc, argv);
}
-mvm::VirtualMachine* mvm::VirtualMachine::createCLIVM() {
+void VirtualMachine::compile(const char* argv) {
+ assert(0 && "This virtual machine does not perform static compilation yet!\n");
+}
+
+mvm::VirtualMachine* mvm::VirtualMachine::createCLIVM(mvm::CompilationUnit* C) {
N3* vm = N3::allocate("", N3::bootstrapVM);
return vm;
}
Modified: vmkit/branches/release_024/lib/N3/VMCore/Opcodes.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/N3/VMCore/Opcodes.cpp?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/N3/VMCore/Opcodes.cpp (original)
+++ vmkit/branches/release_024/lib/N3/VMCore/Opcodes.cpp Mon Nov 3 04:20:55 2008
@@ -251,7 +251,7 @@
Value* val1 = pop();
isPointer |= (val1->getType() == module->ptrType);
verifyType(val1, val2, currentBlock);
- Value* res = BinaryOperator::createAdd(val1, val2, "", currentBlock);
+ Value* res = BinaryOperator::CreateAdd(val1, val2, "", currentBlock);
if (isPointer) {
res = new IntToPtrInst(res, module->ptrType, "", currentBlock);
}
@@ -272,7 +272,7 @@
case AND: {
Value* val2 = pop();
Value* val1 = pop();
- push(BinaryOperator::createAnd(val1, val2, "", currentBlock));
+ push(BinaryOperator::CreateAnd(val1, val2, "", currentBlock));
break;
}
@@ -671,9 +671,9 @@
Value* one = pop();
if (one->getType()->isFloatingPoint()) {
convertValue(one, two->getType(), currentBlock);
- push(BinaryOperator::createFDiv(one, two, "", currentBlock));
+ push(BinaryOperator::CreateFDiv(one, two, "", currentBlock));
} else {
- push(BinaryOperator::createSDiv(one, two, "", currentBlock));
+ push(BinaryOperator::CreateSDiv(one, two, "", currentBlock));
}
break;
}
@@ -682,9 +682,9 @@
Value* two = pop();
Value* one = pop();
if (one->getType()->isFloatingPoint()) {
- push(BinaryOperator::createFDiv(one, two, "", currentBlock));
+ push(BinaryOperator::CreateFDiv(one, two, "", currentBlock));
} else {
- push(BinaryOperator::createUDiv(one, two, "", currentBlock));
+ push(BinaryOperator::CreateUDiv(one, two, "", currentBlock));
}
break;
}
@@ -1003,7 +1003,7 @@
Value* val2 = pop();
Value* val1 = pop();
convertValue(val1, val2->getType(), currentBlock);
- push(BinaryOperator::createMul(val1, val2, "", currentBlock));
+ push(BinaryOperator::CreateMul(val1, val2, "", currentBlock));
break;
}
@@ -1019,7 +1019,7 @@
case NEG : {
Value* val = pop();
- push(BinaryOperator::createSub(
+ push(BinaryOperator::CreateSub(
Constant::getNullValue(val->getType()),
val, "", currentBlock));
break;
@@ -1028,14 +1028,14 @@
case NOP : break;
case NOT : {
- push(BinaryOperator::createNot(pop(), "", currentBlock));
+ push(BinaryOperator::CreateNot(pop(), "", currentBlock));
break;
}
case OR : {
Value* two = pop();
Value* one = pop();
- push(BinaryOperator::createOr(one, two, "", currentBlock));
+ push(BinaryOperator::CreateOr(one, two, "", currentBlock));
break;
}
@@ -1048,9 +1048,9 @@
Value* two = pop();
Value* one = pop();
if (one->getType()->isFloatingPoint()) {
- push(BinaryOperator::createFRem(one, two, "", currentBlock));
+ push(BinaryOperator::CreateFRem(one, two, "", currentBlock));
} else {
- push(BinaryOperator::createSRem(one, two, "", currentBlock));
+ push(BinaryOperator::CreateSRem(one, two, "", currentBlock));
}
break;
}
@@ -1059,9 +1059,9 @@
Value* two = pop();
Value* one = pop();
if (one->getType()->isFloatingPoint()) {
- push(BinaryOperator::createFRem(one, two, "", currentBlock));
+ push(BinaryOperator::CreateFRem(one, two, "", currentBlock));
} else {
- push(BinaryOperator::createURem(one, two, "", currentBlock));
+ push(BinaryOperator::CreateURem(one, two, "", currentBlock));
}
break;
}
@@ -1087,7 +1087,7 @@
Value* val2 = pop();
Value* val1 = pop();
verifyType(val1, val2, currentBlock);
- push(BinaryOperator::createShl(val1, val2, "", currentBlock));
+ push(BinaryOperator::CreateShl(val1, val2, "", currentBlock));
break;
}
@@ -1095,7 +1095,7 @@
Value* val2 = pop();
Value* val1 = pop();
verifyType(val1, val2, currentBlock);
- push(BinaryOperator::createAShr(val1, val2, "", currentBlock));
+ push(BinaryOperator::CreateAShr(val1, val2, "", currentBlock));
break;
}
@@ -1103,7 +1103,7 @@
Value* val2 = pop();
Value* val1 = pop();
verifyType(val1, val2, currentBlock);
- push(BinaryOperator::createLShr(val1, val2, "", currentBlock));
+ push(BinaryOperator::CreateLShr(val1, val2, "", currentBlock));
break;
}
@@ -1235,7 +1235,7 @@
Value* val2 = pop();
Value* val1 = pop();
verifyType(val1, val2, currentBlock);
- push(BinaryOperator::createSub(val1, val2, "", currentBlock));
+ push(BinaryOperator::CreateSub(val1, val2, "", currentBlock));
break;
}
@@ -1269,7 +1269,7 @@
Value* two = pop();
Value* one = pop();
convertValue(two, one->getType(), currentBlock);
- push(BinaryOperator::createXor(one, two, "", currentBlock));
+ push(BinaryOperator::CreateXor(one, two, "", currentBlock));
break;
}
Modified: vmkit/branches/release_024/lib/N3/VMCore/VirtualMachine.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/lib/N3/VMCore/VirtualMachine.h?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/lib/N3/VMCore/VirtualMachine.h (original)
+++ vmkit/branches/release_024/lib/N3/VMCore/VirtualMachine.h Mon Nov 3 04:20:55 2008
@@ -127,6 +127,7 @@
VMThread* bootstrapThread;
virtual void runApplication(int argc, char** argv);
+ virtual void compile(const char* name);
};
Modified: vmkit/branches/release_024/tools/Makefile
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/tools/Makefile?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/tools/Makefile (original)
+++ vmkit/branches/release_024/tools/Makefile Mon Nov 3 04:20:55 2008
@@ -8,7 +8,7 @@
##===----------------------------------------------------------------------===##
LEVEL = ..
-PARALLEL_DIRS = vmkit
+PARALLEL_DIRS = vmkit vmjc
include $(LEVEL)/Makefile.config
Modified: vmkit/branches/release_024/tools/jnjvm/Main.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/tools/jnjvm/Main.cpp?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/tools/jnjvm/Main.cpp (original)
+++ vmkit/branches/release_024/tools/jnjvm/Main.cpp Mon Nov 3 04:20:55 2008
@@ -26,8 +26,8 @@
Thread::initialise();
Collector::initialise(0, &base);
- VirtualMachine::initialiseJVM();
- VirtualMachine* vm = VirtualMachine::createJVM();
+ CompilationUnit* CU = VirtualMachine::initialiseJVM();
+ VirtualMachine* vm = VirtualMachine::createJVM(CU);
vm->runApplication(argc, argv);
return 0;
Modified: vmkit/branches/release_024/tools/vmkit/CommandLine.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/tools/vmkit/CommandLine.cpp?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/tools/vmkit/CommandLine.cpp (original)
+++ vmkit/branches/release_024/tools/vmkit/CommandLine.cpp Mon Nov 3 04:20:55 2008
@@ -100,6 +100,7 @@
}
}
+#if 0
extern "C" int startApp(thread_arg_t* arg) {
int argc = arg->argc;
char** argv = arg->argv;
@@ -120,6 +121,7 @@
#endif
return 0;
}
+#endif
void CommandLine::executeInstr() {
if (!strcmp(argv[0], "load")) {
@@ -152,6 +154,7 @@
} else {
create_vm_t func = vmlets[argv[0]];
+ mvm::CompilationUnit* CU = compilers[argv[0]];
if (!func) {
fprintf(stderr, "\t Unknown vm %s\n", argv[0]);
} else {
@@ -163,7 +166,7 @@
int tid = 0;
Thread::start(&tid, (int (*)(void *))startApp, thread_arg);
#else
- VirtualMachine* VM = func();
+ VirtualMachine* VM = func(CU);
try {
VM->runApplication(argc, argv);
} catch(...) {
Modified: vmkit/branches/release_024/tools/vmkit/CommandLine.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/tools/vmkit/CommandLine.h?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/tools/vmkit/CommandLine.h (original)
+++ vmkit/branches/release_024/tools/vmkit/CommandLine.h Mon Nov 3 04:20:55 2008
@@ -29,7 +29,7 @@
#endif
typedef int (*boot_t)();
-typedef mvm::VirtualMachine* (*create_vm_t)();
+typedef mvm::VirtualMachine* (*create_vm_t)(mvm::CompilationUnit*);
namespace mvm {
@@ -54,6 +54,7 @@
char _yyChar;
std::map<const char*, create_vm_t, ltstr> vmlets;
+ std::map<const char*, mvm::CompilationUnit*, ltstr> compilers;
CommandLine();
Modified: vmkit/branches/release_024/tools/vmkit/Launcher.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/release_024/tools/vmkit/Launcher.cpp?rev=58604&r1=58603&r2=58604&view=diff
==============================================================================
--- vmkit/branches/release_024/tools/vmkit/Launcher.cpp (original)
+++ vmkit/branches/release_024/tools/vmkit/Launcher.cpp Mon Nov 3 04:20:55 2008
@@ -69,25 +69,29 @@
if (VMToRun == RunJava) {
#if WITH_JNJVM
- mvm::VirtualMachine::initialiseJVM();
- mvm::VirtualMachine* vm = mvm::VirtualMachine::createJVM();
+ mvm::CompilationUnit* CU = mvm::VirtualMachine::initialiseJVM();
+ mvm::VirtualMachine* vm = mvm::VirtualMachine::createJVM(CU);
vm->runApplication(argc, argv);
#endif
} else if (VMToRun == RunNet) {
#if WITH_N3
- mvm::VirtualMachine::initialiseCLIVM();
- mvm::VirtualMachine* vm = mvm::VirtualMachine::createCLIVM();
+ mvm::CompilationUnit* CU = mvm::VirtualMachine::initialiseCLIVM();
+ mvm::VirtualMachine* vm = mvm::VirtualMachine::createCLIVM(CU);
vm->runApplication(argc, argv);
#endif
} else {
mvm::CommandLine MyCl;
#if WITH_JNJVM
- mvm::VirtualMachine::initialiseJVM();
+ mvm::CompilationUnit* JVMCompiler =
+ mvm::VirtualMachine::initialiseJVM();
MyCl.vmlets["java"] = (mvm::VirtualMachine::createJVM);
+ MyCl.compilers["java"] = JVMCompiler;
#endif
#if WITH_N3
- mvm::VirtualMachine::initialiseCLIVM();
+ mvm::CompilationUnit* CLICompiler =
+ mvm::VirtualMachine::initialiseCLIVM();
MyCl.vmlets["net"] = (mvm::VirtualMachine::createCLIVM);
+ MyCl.compilers["net"] = CLICompiler;
#endif
MyCl.start();
}
More information about the vmkit-commits
mailing list