From nicolas.geoffray at lip6.fr Mon Nov 3 02:20:57 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Mon, 03 Nov 2008 10:20:57 -0000 Subject: [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/ Message-ID: <200811031020.mA3AKwt6024272@zion.cs.uiuc.edu> 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 * interfaces = cl->getInterfaces(); ArrayObject* ret = - (ArrayObject*)vm->upcalls->classArrayClass->doNew(interfaces->size(), vm); - sint32 index = 0; - for (std::vector::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* innerClasses = cl->getInnerClasses(); UserClassArray* array = vm->upcalls->constructorArrayClass; - ArrayObject* res = (ArrayObject*)array->doNew(innerClasses->size(), vm); - uint32 index = 0; - for (std::vector::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 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::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::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::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::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::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::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::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* interfaces = getInterfaces(); - for (std::vector::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* interfaces = getInterfaces(); - for (std::vector::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::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* 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& 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& 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& 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& 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 #include #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 interfaces; + Class** interfaces; - std::vector * 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 interfacesUTF8; - - std::vector* 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 >::iterator - field_iterator; - - typedef std::map > - 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 >::iterator - method_iterator; - - typedef std::map > - 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& res, bool publicOnly); void getDeclaredMethods(std::vector& res, bool publicOnly); void getDeclaredFields(std::vector& res, bool publicOnly); - void setInterfaces(std::vector 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 attributs; + Attribut* attributs; + uint16 nbAttributs; #if !defined(ISOLATE) && !defined(ISOLATE_SHARING) /// innerClasses - The inner classes of this class. /// - std::vector 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 & 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* getInnerClasses() { - return &innerClasses; - } -#endif - mvm::JITInfo* JInfo; template 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 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 attributs; + Attribut* attributs; + uint16 nbAttributs; /// caches - List of caches in this method. For all invokeinterface bytecode /// there is a corresponding cache. /// - std::vector 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 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 - -#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(""); - Jnjvm::clinitName = JCL->asciizConstructUTF8(""); - 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& 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(I) && "non terminator before buggy return"); - I->eraseFromParent(); - BranchInst::Create(endBlock, currentBlock); + + assert((isa(I) || isa(I)) && + "Malformed end Java block"); + + if (isa(I)) { + I->eraseFromParent(); + BranchInst::Create(endBlock, currentBlock); + } else if (InvokeInst* II = dyn_cast(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& 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& 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 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 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& args); std::map 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 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 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(""), \ - loader->asciizConstructUTF8("(Ljava/lang/String;)V"), \ - ACC_VIRTUAL); + Init##name = name->lookupMethodDontThrow(loader->asciizConstructUTF8(""), \ + loader->asciizConstructUTF8("(Ljava/lang/String;)V"), \ + false, false, 0); #define UPCALL_METHOD_WITH_EXCEPTION(loader, name) \ - ErrorWithExcp##name = name->constructMethod(loader->asciizConstructUTF8(""), \ + ErrorWithExcp##name = name->lookupMethodDontThrow(loader->asciizConstructUTF8(""), \ 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 Jnjvm::nativeLibs; -JnjvmBootstrapLoader* Jnjvm::bootstrapLoader; -std::map 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 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::iterator i = classes.begin(), e = classes.end(); + i != e; ++i) { + Class* cl = *i; + cl->resolveClass(); + } + + for (std::vector::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 arrayClasses; + private: - ISOLATE_STATIC std::map 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 > postProperties; - /// nativeLibs - Native libraries (e.g. '.so') loaded by this JVM. - /// - ISOLATE_STATIC std::vector 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 #include #include #include + +#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 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(""); + clinitName = asciizConstructUTF8(""); + 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::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 > strings; + + /// nativeLibs - Native libraries (e.g. '.so') loaded by this class loader. + /// + std::vector 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 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 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(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 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 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 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 staticInstances; std::map constantPools; std::map strings; + std::map enveloppes; + std::map nativeFunctions; typedef std::map::iterator native_class_iterator; @@ -204,14 +205,31 @@ typedef std::map::iterator string_iterator; + typedef std::map::iterator + enveloppe_iterator; + + typedef std::map::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 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(CI); + assert(Invoke && "Last instruction is not an invoke"); + NBB = Invoke->getNormalDest(); + } + + Value* Cl = Call.getArgument(0); + std::vector 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 Args; + Args.push_back(Cl); + + Value* res = 0; + if (InvokeInst* Invoke = dyn_cast(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(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(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(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(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::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 >::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::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 +#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 vmlets; + std::map 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(); } From nicolas.geoffray at lip6.fr Mon Nov 3 02:40:20 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Mon, 03 Nov 2008 10:40:20 -0000 Subject: [vmkit-commits] [vmkit] r58605 - in /vmkit/tags/release_024: include/mvm/ lib/JnJVM/Classpath/ lib/JnJVM/LLVMRuntime/ lib/JnJVM/VMCore/ lib/N3/VMCore/ tools/ tools/jnjvm/ tools/vmjc/ tools/vmkit/ Message-ID: <200811031040.mA3AeLsn024930@zion.cs.uiuc.edu> Author: geoffray Date: Mon Nov 3 04:40:19 2008 New Revision: 58605 URL: http://llvm.org/viewvc/llvm-project?rev=58605&view=rev Log: Sync with llvm 2.4 release. Added: vmkit/tags/release_024/include/mvm/CompilationUnit.h - copied unchanged from r58604, vmkit/branches/release_024/include/mvm/CompilationUnit.h vmkit/tags/release_024/tools/vmjc/ - copied from r58604, vmkit/branches/release_024/tools/vmjc/ vmkit/tags/release_024/tools/vmjc/Makefile - copied unchanged from r58604, vmkit/branches/release_024/tools/vmjc/Makefile vmkit/tags/release_024/tools/vmjc/vmjc.cpp - copied unchanged from r58604, vmkit/branches/release_024/tools/vmjc/vmjc.cpp Modified: vmkit/tags/release_024/include/mvm/Allocator.h vmkit/tags/release_024/include/mvm/VirtualMachine.h vmkit/tags/release_024/lib/JnJVM/Classpath/Classpath.cpp vmkit/tags/release_024/lib/JnJVM/Classpath/ClasspathReflect.h vmkit/tags/release_024/lib/JnJVM/Classpath/ClasspathVMClass.cpp vmkit/tags/release_024/lib/JnJVM/Classpath/ClasspathVMRuntime.cpp vmkit/tags/release_024/lib/JnJVM/LLVMRuntime/runtime-default.ll vmkit/tags/release_024/lib/JnJVM/VMCore/JavaCache.cpp vmkit/tags/release_024/lib/JnJVM/VMCore/JavaCache.h vmkit/tags/release_024/lib/JnJVM/VMCore/JavaClass.cpp vmkit/tags/release_024/lib/JnJVM/VMCore/JavaClass.h vmkit/tags/release_024/lib/JnJVM/VMCore/JavaConstantPool.cpp vmkit/tags/release_024/lib/JnJVM/VMCore/JavaInitialise.cpp vmkit/tags/release_024/lib/JnJVM/VMCore/JavaJIT.cpp vmkit/tags/release_024/lib/JnJVM/VMCore/JavaJIT.h vmkit/tags/release_024/lib/JnJVM/VMCore/JavaJITOpcodes.cpp vmkit/tags/release_024/lib/JnJVM/VMCore/JavaMetaJIT.cpp vmkit/tags/release_024/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp vmkit/tags/release_024/lib/JnJVM/VMCore/JavaThread.cpp vmkit/tags/release_024/lib/JnJVM/VMCore/JavaThread.h vmkit/tags/release_024/lib/JnJVM/VMCore/JavaTypes.cpp vmkit/tags/release_024/lib/JnJVM/VMCore/JavaUpcalls.cpp vmkit/tags/release_024/lib/JnJVM/VMCore/JavaUpcalls.h vmkit/tags/release_024/lib/JnJVM/VMCore/Jni.cpp vmkit/tags/release_024/lib/JnJVM/VMCore/Jnjvm.cpp vmkit/tags/release_024/lib/JnJVM/VMCore/Jnjvm.h vmkit/tags/release_024/lib/JnJVM/VMCore/JnjvmClassLoader.cpp vmkit/tags/release_024/lib/JnJVM/VMCore/JnjvmClassLoader.h vmkit/tags/release_024/lib/JnJVM/VMCore/JnjvmModule.cpp vmkit/tags/release_024/lib/JnJVM/VMCore/JnjvmModule.h vmkit/tags/release_024/lib/JnJVM/VMCore/JnjvmModuleProvider.cpp vmkit/tags/release_024/lib/JnJVM/VMCore/LowerConstantCalls.cpp vmkit/tags/release_024/lib/JnJVM/VMCore/NativeUtil.cpp vmkit/tags/release_024/lib/JnJVM/VMCore/Reader.cpp vmkit/tags/release_024/lib/JnJVM/VMCore/Reader.h vmkit/tags/release_024/lib/JnJVM/VMCore/VirtualTables.cpp vmkit/tags/release_024/lib/JnJVM/VMCore/Zip.h vmkit/tags/release_024/lib/N3/VMCore/CLIJit.cpp vmkit/tags/release_024/lib/N3/VMCore/N3.h vmkit/tags/release_024/lib/N3/VMCore/N3Initialise.cpp vmkit/tags/release_024/lib/N3/VMCore/Opcodes.cpp vmkit/tags/release_024/lib/N3/VMCore/VirtualMachine.h vmkit/tags/release_024/tools/Makefile vmkit/tags/release_024/tools/jnjvm/Main.cpp vmkit/tags/release_024/tools/vmkit/CommandLine.cpp vmkit/tags/release_024/tools/vmkit/CommandLine.h vmkit/tags/release_024/tools/vmkit/Launcher.cpp Modified: vmkit/tags/release_024/include/mvm/Allocator.h URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/include/mvm/Allocator.h?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/include/mvm/Allocator.h (original) +++ vmkit/tags/release_024/include/mvm/Allocator.h Mon Nov 3 04:40:19 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/tags/release_024/include/mvm/VirtualMachine.h URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/include/mvm/VirtualMachine.h?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/include/mvm/VirtualMachine.h (original) +++ vmkit/tags/release_024/include/mvm/VirtualMachine.h Mon Nov 3 04:40:19 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/tags/release_024/lib/JnJVM/Classpath/Classpath.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/JnJVM/Classpath/Classpath.cpp?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/JnJVM/Classpath/Classpath.cpp (original) +++ vmkit/tags/release_024/lib/JnJVM/Classpath/Classpath.cpp Mon Nov 3 04:40:19 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/tags/release_024/lib/JnJVM/Classpath/ClasspathReflect.h URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/JnJVM/Classpath/ClasspathReflect.h?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/JnJVM/Classpath/ClasspathReflect.h (original) +++ vmkit/tags/release_024/lib/JnJVM/Classpath/ClasspathReflect.h Mon Nov 3 04:40:19 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/tags/release_024/lib/JnJVM/Classpath/ClasspathVMClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/JnJVM/Classpath/ClasspathVMClass.cpp?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/JnJVM/Classpath/ClasspathVMClass.cpp (original) +++ vmkit/tags/release_024/lib/JnJVM/Classpath/ClasspathVMClass.cpp Mon Nov 3 04:40:19 2008 @@ -295,14 +295,11 @@ jclass Cl) { Jnjvm* vm = JavaThread::get()->isolate; UserCommonClass* cl = NativeUtil::resolvedImplClass(vm, Cl, false); - std::vector * interfaces = cl->getInterfaces(); ArrayObject* ret = - (ArrayObject*)vm->upcalls->classArrayClass->doNew(interfaces->size(), vm); - sint32 index = 0; - for (std::vector::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* innerClasses = cl->getInnerClasses(); UserClassArray* array = vm->upcalls->constructorArrayClass; - ArrayObject* res = (ArrayObject*)array->doNew(innerClasses->size(), vm); - uint32 index = 0; - for (std::vector::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/tags/release_024/lib/JnJVM/Classpath/ClasspathVMRuntime.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/JnJVM/Classpath/ClasspathVMRuntime.cpp?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/JnJVM/Classpath/ClasspathVMRuntime.cpp (original) +++ vmkit/tags/release_024/lib/JnJVM/Classpath/ClasspathVMRuntime.cpp Mon Nov 3 04:40:19 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/tags/release_024/lib/JnJVM/LLVMRuntime/runtime-default.ll URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/JnJVM/LLVMRuntime/runtime-default.ll?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/JnJVM/LLVMRuntime/runtime-default.ll (original) +++ vmkit/tags/release_024/lib/JnJVM/LLVMRuntime/runtime-default.ll Mon Nov 3 04:40:19 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/tags/release_024/lib/JnJVM/VMCore/JavaCache.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/JnJVM/VMCore/JavaCache.cpp?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/JnJVM/VMCore/JavaCache.cpp (original) +++ vmkit/tags/release_024/lib/JnJVM/VMCore/JavaCache.cpp Mon Nov 3 04:40:19 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/tags/release_024/lib/JnJVM/VMCore/JavaCache.h URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/JnJVM/VMCore/JavaCache.h?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/JnJVM/VMCore/JavaCache.h (original) +++ vmkit/tags/release_024/lib/JnJVM/VMCore/JavaCache.h Mon Nov 3 04:40:19 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/tags/release_024/lib/JnJVM/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/JnJVM/VMCore/JavaClass.cpp?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/JnJVM/VMCore/JavaClass.cpp (original) +++ vmkit/tags/release_024/lib/JnJVM/VMCore/JavaClass.cpp Mon Nov 3 04:40:19 2008 @@ -41,7 +41,7 @@ const UTF8* Attribut::sourceFileAttribut = 0; CommonClass* ClassArray::SuperArray; -std::vector 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::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::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::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::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::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::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::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* interfaces = getInterfaces(); - for (std::vector::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* interfaces = getInterfaces(); - for (std::vector::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::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* 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& 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& 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& 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& 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/tags/release_024/lib/JnJVM/VMCore/JavaClass.h URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/JnJVM/VMCore/JavaClass.h?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/JnJVM/VMCore/JavaClass.h (original) +++ vmkit/tags/release_024/lib/JnJVM/VMCore/JavaClass.h Mon Nov 3 04:40:19 2008 @@ -10,7 +10,6 @@ #ifndef JNJVM_JAVA_CLASS_H #define JNJVM_JAVA_CLASS_H -#include #include #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 interfaces; + Class** interfaces; - std::vector * 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 interfacesUTF8; - - std::vector* 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 >::iterator - field_iterator; - - typedef std::map > - 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 >::iterator - method_iterator; - - typedef std::map > - 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& res, bool publicOnly); void getDeclaredMethods(std::vector& res, bool publicOnly); void getDeclaredFields(std::vector& res, bool publicOnly); - void setInterfaces(std::vector 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 attributs; + Attribut* attributs; + uint16 nbAttributs; #if !defined(ISOLATE) && !defined(ISOLATE_SHARING) /// innerClasses - The inner classes of this class. /// - std::vector 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 & 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* getInnerClasses() { - return &innerClasses; - } -#endif - mvm::JITInfo* JInfo; template 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 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 attributs; + Attribut* attributs; + uint16 nbAttributs; /// caches - List of caches in this method. For all invokeinterface bytecode /// there is a corresponding cache. /// - std::vector 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 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/tags/release_024/lib/JnJVM/VMCore/JavaConstantPool.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/JnJVM/VMCore/JavaConstantPool.cpp?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/JnJVM/VMCore/JavaConstantPool.cpp (original) +++ vmkit/tags/release_024/lib/JnJVM/VMCore/JavaConstantPool.cpp Mon Nov 3 04:40:19 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/tags/release_024/lib/JnJVM/VMCore/JavaInitialise.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/JnJVM/VMCore/JavaInitialise.cpp?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/JnJVM/VMCore/JavaInitialise.cpp (original) +++ vmkit/tags/release_024/lib/JnJVM/VMCore/JavaInitialise.cpp Mon Nov 3 04:40:19 2008 @@ -7,28 +7,12 @@ // //===----------------------------------------------------------------------===// -#include - -#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(""); - Jnjvm::clinitName = JCL->asciizConstructUTF8(""); - 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/tags/release_024/lib/JnJVM/VMCore/JavaJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/JnJVM/VMCore/JavaJIT.cpp?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/JnJVM/VMCore/JavaJIT.cpp (original) +++ vmkit/tags/release_024/lib/JnJVM/VMCore/JavaJIT.cpp Mon Nov 3 04:40:19 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& 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(I) && "non terminator before buggy return"); - I->eraseFromParent(); - BranchInst::Create(endBlock, currentBlock); + + assert((isa(I) || isa(I)) && + "Malformed end Java block"); + + if (isa(I)) { + I->eraseFromParent(); + BranchInst::Create(endBlock, currentBlock); + } else if (InvokeInst* II = dyn_cast(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& 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& 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 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 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/tags/release_024/lib/JnJVM/VMCore/JavaJIT.h URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/JnJVM/VMCore/JavaJIT.h?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/JnJVM/VMCore/JavaJIT.h (original) +++ vmkit/tags/release_024/lib/JnJVM/VMCore/JavaJIT.h Mon Nov 3 04:40:19 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& args); std::map 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/tags/release_024/lib/JnJVM/VMCore/JavaJITOpcodes.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/JnJVM/VMCore/JavaJITOpcodes.cpp?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/JnJVM/VMCore/JavaJITOpcodes.cpp (original) +++ vmkit/tags/release_024/lib/JnJVM/VMCore/JavaJITOpcodes.cpp Mon Nov 3 04:40:19 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 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 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/tags/release_024/lib/JnJVM/VMCore/JavaMetaJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/JnJVM/VMCore/JavaMetaJIT.cpp?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/JnJVM/VMCore/JavaMetaJIT.cpp (original) +++ vmkit/tags/release_024/lib/JnJVM/VMCore/JavaMetaJIT.cpp Mon Nov 3 04:40:19 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/tags/release_024/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp (original) +++ vmkit/tags/release_024/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp Mon Nov 3 04:40:19 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/tags/release_024/lib/JnJVM/VMCore/JavaThread.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/JnJVM/VMCore/JavaThread.cpp?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/JnJVM/VMCore/JavaThread.cpp (original) +++ vmkit/tags/release_024/lib/JnJVM/VMCore/JavaThread.cpp Mon Nov 3 04:40:19 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/tags/release_024/lib/JnJVM/VMCore/JavaThread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/JnJVM/VMCore/JavaThread.h?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/JnJVM/VMCore/JavaThread.h (original) +++ vmkit/tags/release_024/lib/JnJVM/VMCore/JavaThread.h Mon Nov 3 04:40:19 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/tags/release_024/lib/JnJVM/VMCore/JavaTypes.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/JnJVM/VMCore/JavaTypes.cpp?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/JnJVM/VMCore/JavaTypes.cpp (original) +++ vmkit/tags/release_024/lib/JnJVM/VMCore/JavaTypes.cpp Mon Nov 3 04:40:19 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/tags/release_024/lib/JnJVM/VMCore/JavaUpcalls.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/JnJVM/VMCore/JavaUpcalls.cpp?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/JnJVM/VMCore/JavaUpcalls.cpp (original) +++ vmkit/tags/release_024/lib/JnJVM/VMCore/JavaUpcalls.cpp Mon Nov 3 04:40:19 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/tags/release_024/lib/JnJVM/VMCore/JavaUpcalls.h URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/JnJVM/VMCore/JavaUpcalls.h?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/JnJVM/VMCore/JavaUpcalls.h (original) +++ vmkit/tags/release_024/lib/JnJVM/VMCore/JavaUpcalls.h Mon Nov 3 04:40:19 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(""), \ - loader->asciizConstructUTF8("(Ljava/lang/String;)V"), \ - ACC_VIRTUAL); + Init##name = name->lookupMethodDontThrow(loader->asciizConstructUTF8(""), \ + loader->asciizConstructUTF8("(Ljava/lang/String;)V"), \ + false, false, 0); #define UPCALL_METHOD_WITH_EXCEPTION(loader, name) \ - ErrorWithExcp##name = name->constructMethod(loader->asciizConstructUTF8(""), \ + ErrorWithExcp##name = name->lookupMethodDontThrow(loader->asciizConstructUTF8(""), \ loader->asciizConstructUTF8("(Ljava/lang/Throwable;)V"), \ - ACC_VIRTUAL); + false, false, 0); namespace jnjvm { Modified: vmkit/tags/release_024/lib/JnJVM/VMCore/Jni.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/JnJVM/VMCore/Jni.cpp?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/JnJVM/VMCore/Jni.cpp (original) +++ vmkit/tags/release_024/lib/JnJVM/VMCore/Jni.cpp Mon Nov 3 04:40:19 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/tags/release_024/lib/JnJVM/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/JnJVM/VMCore/Jnjvm.cpp?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/JnJVM/VMCore/Jnjvm.cpp (original) +++ vmkit/tags/release_024/lib/JnJVM/VMCore/Jnjvm.cpp Mon Nov 3 04:40:19 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 Jnjvm::nativeLibs; -JnjvmBootstrapLoader* Jnjvm::bootstrapLoader; -std::map 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 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::iterator i = classes.begin(), e = classes.end(); + i != e; ++i) { + Class* cl = *i; + cl->resolveClass(); + } + + for (std::vector::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/tags/release_024/lib/JnJVM/VMCore/Jnjvm.h URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/JnJVM/VMCore/Jnjvm.h?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/JnJVM/VMCore/Jnjvm.h (original) +++ vmkit/tags/release_024/lib/JnJVM/VMCore/Jnjvm.h Mon Nov 3 04:40:19 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 arrayClasses; + private: - ISOLATE_STATIC std::map 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 > postProperties; - /// nativeLibs - Native libraries (e.g. '.so') loaded by this JVM. - /// - ISOLATE_STATIC std::vector 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/tags/release_024/lib/JnJVM/VMCore/JnjvmClassLoader.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/JnJVM/VMCore/JnjvmClassLoader.cpp?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/JnJVM/VMCore/JnjvmClassLoader.cpp (original) +++ vmkit/tags/release_024/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Mon Nov 3 04:40:19 2008 @@ -7,10 +7,18 @@ // //===----------------------------------------------------------------------===// +#include #include #include #include + +#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 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(""); + clinitName = asciizConstructUTF8(""); + 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::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/tags/release_024/lib/JnJVM/VMCore/JnjvmClassLoader.h URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/JnJVM/VMCore/JnjvmClassLoader.h?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/JnJVM/VMCore/JnjvmClassLoader.h (original) +++ vmkit/tags/release_024/lib/JnJVM/VMCore/JnjvmClassLoader.h Mon Nov 3 04:40:19 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 > strings; + + /// nativeLibs - Native libraries (e.g. '.so') loaded by this class loader. + /// + std::vector 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 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 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/tags/release_024/lib/JnJVM/VMCore/JnjvmModule.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/JnJVM/VMCore/JnjvmModule.cpp?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/JnJVM/VMCore/JnjvmModule.cpp (original) +++ vmkit/tags/release_024/lib/JnJVM/VMCore/JnjvmModule.cpp Mon Nov 3 04:40:19 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(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 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 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 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/tags/release_024/lib/JnJVM/VMCore/JnjvmModule.h URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/JnJVM/VMCore/JnjvmModule.h?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/JnJVM/VMCore/JnjvmModule.h (original) +++ vmkit/tags/release_024/lib/JnJVM/VMCore/JnjvmModule.h Mon Nov 3 04:40:19 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 staticInstances; std::map constantPools; std::map strings; + std::map enveloppes; + std::map nativeFunctions; typedef std::map::iterator native_class_iterator; @@ -204,14 +205,31 @@ typedef std::map::iterator string_iterator; + typedef std::map::iterator + enveloppe_iterator; + + typedef std::map::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/tags/release_024/lib/JnJVM/VMCore/JnjvmModuleProvider.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/JnJVM/VMCore/JnjvmModuleProvider.cpp?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/JnJVM/VMCore/JnjvmModuleProvider.cpp (original) +++ vmkit/tags/release_024/lib/JnJVM/VMCore/JnjvmModuleProvider.cpp Mon Nov 3 04:40:19 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/tags/release_024/lib/JnJVM/VMCore/LowerConstantCalls.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/JnJVM/VMCore/LowerConstantCalls.cpp?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/JnJVM/VMCore/LowerConstantCalls.cpp (original) +++ vmkit/tags/release_024/lib/JnJVM/VMCore/LowerConstantCalls.cpp Mon Nov 3 04:40:19 2008 @@ -19,7 +19,6 @@ #include "JnjvmModule.h" -#include 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(CI); + assert(Invoke && "Last instruction is not an invoke"); + NBB = Invoke->getNormalDest(); + } + + Value* Cl = Call.getArgument(0); + std::vector 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 Args; + Args.push_back(Cl); + + Value* res = 0; + if (InvokeInst* Invoke = dyn_cast(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(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(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(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(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/tags/release_024/lib/JnJVM/VMCore/NativeUtil.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/JnJVM/VMCore/NativeUtil.cpp?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/JnJVM/VMCore/NativeUtil.cpp (original) +++ vmkit/tags/release_024/lib/JnJVM/VMCore/NativeUtil.cpp Mon Nov 3 04:40:19 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::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/tags/release_024/lib/JnJVM/VMCore/Reader.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/JnJVM/VMCore/Reader.cpp?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/JnJVM/VMCore/Reader.cpp (original) +++ vmkit/tags/release_024/lib/JnJVM/VMCore/Reader.cpp Mon Nov 3 04:40:19 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/tags/release_024/lib/JnJVM/VMCore/Reader.h URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/JnJVM/VMCore/Reader.h?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/JnJVM/VMCore/Reader.h (original) +++ vmkit/tags/release_024/lib/JnJVM/VMCore/Reader.h Mon Nov 3 04:40:19 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/tags/release_024/lib/JnJVM/VMCore/VirtualTables.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/JnJVM/VMCore/VirtualTables.cpp?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/JnJVM/VMCore/VirtualTables.cpp (original) +++ vmkit/tags/release_024/lib/JnJVM/VMCore/VirtualTables.cpp Mon Nov 3 04:40:19 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 >::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::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/tags/release_024/lib/JnJVM/VMCore/Zip.h URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/JnJVM/VMCore/Zip.h?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/JnJVM/VMCore/Zip.h (original) +++ vmkit/tags/release_024/lib/JnJVM/VMCore/Zip.h Mon Nov 3 04:40:19 2008 @@ -34,6 +34,7 @@ class ZipArchive : public mvm::PermanentObject { friend class JnjvmBootstrapLoader; + friend class Jnjvm; private: mvm::BumpPtrAllocator& allocator; Modified: vmkit/tags/release_024/lib/N3/VMCore/CLIJit.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/N3/VMCore/CLIJit.cpp?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/N3/VMCore/CLIJit.cpp (original) +++ vmkit/tags/release_024/lib/N3/VMCore/CLIJit.cpp Mon Nov 3 04:40:19 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/tags/release_024/lib/N3/VMCore/N3.h URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/N3/VMCore/N3.h?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/N3/VMCore/N3.h (original) +++ vmkit/tags/release_024/lib/N3/VMCore/N3.h Mon Nov 3 04:40:19 2008 @@ -79,7 +79,7 @@ static const UTF8* floatName; static const UTF8* doubleName; static const UTF8* testInfinity; - + }; } // end namespace n3 Modified: vmkit/tags/release_024/lib/N3/VMCore/N3Initialise.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/N3/VMCore/N3Initialise.cpp?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/N3/VMCore/N3Initialise.cpp (original) +++ vmkit/tags/release_024/lib/N3/VMCore/N3Initialise.cpp Mon Nov 3 04:40:19 2008 @@ -10,6 +10,7 @@ #include +#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/tags/release_024/lib/N3/VMCore/Opcodes.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/N3/VMCore/Opcodes.cpp?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/N3/VMCore/Opcodes.cpp (original) +++ vmkit/tags/release_024/lib/N3/VMCore/Opcodes.cpp Mon Nov 3 04:40:19 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/tags/release_024/lib/N3/VMCore/VirtualMachine.h URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/N3/VMCore/VirtualMachine.h?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/lib/N3/VMCore/VirtualMachine.h (original) +++ vmkit/tags/release_024/lib/N3/VMCore/VirtualMachine.h Mon Nov 3 04:40:19 2008 @@ -127,6 +127,7 @@ VMThread* bootstrapThread; virtual void runApplication(int argc, char** argv); + virtual void compile(const char* name); }; Modified: vmkit/tags/release_024/tools/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/tools/Makefile?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/tools/Makefile (original) +++ vmkit/tags/release_024/tools/Makefile Mon Nov 3 04:40:19 2008 @@ -8,7 +8,7 @@ ##===----------------------------------------------------------------------===## LEVEL = .. -PARALLEL_DIRS = vmkit +PARALLEL_DIRS = vmkit vmjc include $(LEVEL)/Makefile.config Modified: vmkit/tags/release_024/tools/jnjvm/Main.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/tools/jnjvm/Main.cpp?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/tools/jnjvm/Main.cpp (original) +++ vmkit/tags/release_024/tools/jnjvm/Main.cpp Mon Nov 3 04:40:19 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/tags/release_024/tools/vmkit/CommandLine.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/tools/vmkit/CommandLine.cpp?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/tools/vmkit/CommandLine.cpp (original) +++ vmkit/tags/release_024/tools/vmkit/CommandLine.cpp Mon Nov 3 04:40:19 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/tags/release_024/tools/vmkit/CommandLine.h URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/tools/vmkit/CommandLine.h?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/tools/vmkit/CommandLine.h (original) +++ vmkit/tags/release_024/tools/vmkit/CommandLine.h Mon Nov 3 04:40:19 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 vmlets; + std::map compilers; CommandLine(); Modified: vmkit/tags/release_024/tools/vmkit/Launcher.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/tools/vmkit/Launcher.cpp?rev=58605&r1=58604&r2=58605&view=diff ============================================================================== --- vmkit/tags/release_024/tools/vmkit/Launcher.cpp (original) +++ vmkit/tags/release_024/tools/vmkit/Launcher.cpp Mon Nov 3 04:40:19 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(); } From nicolas.geoffray at lip6.fr Mon Nov 3 08:38:27 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Mon, 03 Nov 2008 16:38:27 -0000 Subject: [vmkit-commits] [vmkit] r58617 - /vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp Message-ID: <200811031638.mA3GcRwd011862@zion.cs.uiuc.edu> Author: geoffray Date: Mon Nov 3 10:38:27 2008 New Revision: 58617 URL: http://llvm.org/viewvc/llvm-project?rev=58617&view=rev Log: Don't trace object's class if it's not set. Modified: vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp Modified: vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp?rev=58617&r1=58616&r2=58617&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp Mon Nov 3 10:38:27 2008 @@ -52,7 +52,7 @@ #undef INIT void ArrayObject::TRACER { - classOf->classLoader->MARK_AND_TRACE; + if (classOf) classOf->classLoader->MARK_AND_TRACE; for (sint32 i = 0; i < size; i++) { if (elements[i]) elements[i]->MARK_AND_TRACE; } @@ -93,7 +93,7 @@ } void JavaObject::TRACER { - classOf->classLoader->MARK_AND_TRACE; + if (classOf) classOf->classLoader->MARK_AND_TRACE; LockObj* l = lockObj(); if (l) l->MARK_AND_TRACE; } @@ -103,7 +103,7 @@ #else extern "C" void JavaObjectTracer(JavaObject* obj) { #endif - obj->classOf->classLoader->MARK_AND_TRACE; + if (obj->classOf) obj->classOf->classLoader->MARK_AND_TRACE; LockObj* l = obj->lockObj(); if (l) l->MARK_AND_TRACE; } From nicolas.geoffray at lip6.fr Mon Nov 3 08:41:08 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Mon, 03 Nov 2008 16:41:08 -0000 Subject: [vmkit-commits] [vmkit] r58618 - /vmkit/branches/release_024/lib/JnJVM/VMCore/VirtualTables.cpp Message-ID: <200811031641.mA3Gf8vc012040@zion.cs.uiuc.edu> Author: geoffray Date: Mon Nov 3 10:41:08 2008 New Revision: 58618 URL: http://llvm.org/viewvc/llvm-project?rev=58618&view=rev Log: Import r58617 from mainline. Modified: vmkit/branches/release_024/lib/JnJVM/VMCore/VirtualTables.cpp 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=58618&r1=58617&r2=58618&view=diff ============================================================================== --- vmkit/branches/release_024/lib/JnJVM/VMCore/VirtualTables.cpp (original) +++ vmkit/branches/release_024/lib/JnJVM/VMCore/VirtualTables.cpp Mon Nov 3 10:41:08 2008 @@ -52,7 +52,7 @@ #undef INIT void ArrayObject::TRACER { - classOf->classLoader->MARK_AND_TRACE; + if (classOf) classOf->classLoader->MARK_AND_TRACE; for (sint32 i = 0; i < size; i++) { if (elements[i]) elements[i]->MARK_AND_TRACE; } @@ -93,7 +93,7 @@ } void JavaObject::TRACER { - classOf->classLoader->MARK_AND_TRACE; + if (classOf) classOf->classLoader->MARK_AND_TRACE; LockObj* l = lockObj(); if (l) l->MARK_AND_TRACE; } @@ -103,7 +103,7 @@ #else extern "C" void JavaObjectTracer(JavaObject* obj) { #endif - obj->classOf->classLoader->MARK_AND_TRACE; + if (obj->classOf) obj->classOf->classLoader->MARK_AND_TRACE; LockObj* l = obj->lockObj(); if (l) l->MARK_AND_TRACE; } From nicolas.geoffray at lip6.fr Mon Nov 3 08:44:05 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Mon, 03 Nov 2008 16:44:05 -0000 Subject: [vmkit-commits] [vmkit] r58619 - /vmkit/tags/release_024/lib/JnJVM/VMCore/VirtualTables.cpp Message-ID: <200811031644.mA3Gi53h012220@zion.cs.uiuc.edu> Author: geoffray Date: Mon Nov 3 10:44:05 2008 New Revision: 58619 URL: http://llvm.org/viewvc/llvm-project?rev=58619&view=rev Log: Import r58617 from mainline. Modified: vmkit/tags/release_024/lib/JnJVM/VMCore/VirtualTables.cpp Modified: vmkit/tags/release_024/lib/JnJVM/VMCore/VirtualTables.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/tags/release_024/lib/JnJVM/VMCore/VirtualTables.cpp?rev=58619&r1=58618&r2=58619&view=diff ============================================================================== --- vmkit/tags/release_024/lib/JnJVM/VMCore/VirtualTables.cpp (original) +++ vmkit/tags/release_024/lib/JnJVM/VMCore/VirtualTables.cpp Mon Nov 3 10:44:05 2008 @@ -52,7 +52,7 @@ #undef INIT void ArrayObject::TRACER { - classOf->classLoader->MARK_AND_TRACE; + if (classOf) classOf->classLoader->MARK_AND_TRACE; for (sint32 i = 0; i < size; i++) { if (elements[i]) elements[i]->MARK_AND_TRACE; } @@ -93,7 +93,7 @@ } void JavaObject::TRACER { - classOf->classLoader->MARK_AND_TRACE; + if (classOf) classOf->classLoader->MARK_AND_TRACE; LockObj* l = lockObj(); if (l) l->MARK_AND_TRACE; } @@ -103,7 +103,7 @@ #else extern "C" void JavaObjectTracer(JavaObject* obj) { #endif - obj->classOf->classLoader->MARK_AND_TRACE; + if (obj->classOf) obj->classOf->classLoader->MARK_AND_TRACE; LockObj* l = obj->lockObj(); if (l) l->MARK_AND_TRACE; } From nicolas.geoffray at lip6.fr Thu Nov 6 07:35:31 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 06 Nov 2008 15:35:31 -0000 Subject: [vmkit-commits] [vmkit] r58803 - /vmkit/trunk/www/releases.html Message-ID: <200811061535.mA6FZW3c030287@zion.cs.uiuc.edu> Author: geoffray Date: Thu Nov 6 09:35:24 2008 New Revision: 58803 URL: http://llvm.org/viewvc/llvm-project?rev=58803&view=rev Log: Add a new release page. Added: vmkit/trunk/www/releases.html Added: vmkit/trunk/www/releases.html URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/www/releases.html?rev=58803&view=auto ============================================================================== --- vmkit/trunk/www/releases.html (added) +++ vmkit/trunk/www/releases.html Thu Nov 6 09:35:24 2008 @@ -0,0 +1,60 @@ + + + + + + "vmkit" JVM and .Net runtimes for LLVM + + + + + + +
+ +

VMKit Releases

+ + +

The VMKit project was publicly released in the time of LLVM 2.3. Since + LLVM 2.4, VMKit follows each LLVM release. The first release of VMKit is + version 0.24.

+ + +

Downloads

+ + + + +
+ + From nicolas.geoffray at lip6.fr Sat Nov 8 03:48:09 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 08 Nov 2008 11:48:09 -0000 Subject: [vmkit-commits] [vmkit] r58903 - in /vmkit/trunk: ./ include/mvm/ include/mvm/Threads/ lib/JnJVM/Classpath/ lib/JnJVM/VMCore/ lib/Mvm/CommonThread/ lib/Mvm/GCMmap2/ lib/Mvm/Runtime/ lib/N3/VMCore/ tools/jnjvm/ tools/n3-mono/ tools/n3-pnetlib/ tools/vmjc/ tools/vmkit/ Message-ID: <200811081148.mA8BmCWx007992@zion.cs.uiuc.edu> Author: geoffray Date: Sat Nov 8 05:48:04 2008 New Revision: 58903 URL: http://llvm.org/viewvc/llvm-project?rev=58903&view=rev Log: Revamping threading in VMKit. Removed: vmkit/trunk/include/mvm/Threads/Key.h vmkit/trunk/lib/Mvm/GCMmap2/ctcircular.h Modified: vmkit/trunk/Makefile.common.in vmkit/trunk/include/mvm/JIT.h vmkit/trunk/include/mvm/Threads/Cond.h vmkit/trunk/include/mvm/Threads/Locks.h vmkit/trunk/include/mvm/Threads/Thread.h vmkit/trunk/include/mvm/VirtualMachine.h vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThread.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h vmkit/trunk/lib/JnJVM/VMCore/JavaObject.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaObject.h vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaThread.h vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp vmkit/trunk/lib/JnJVM/VMCore/JnjvmModuleProvider.cpp vmkit/trunk/lib/JnJVM/VMCore/LowerConstantCalls.cpp vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp vmkit/trunk/lib/Mvm/CommonThread/ctlock.cpp vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp vmkit/trunk/lib/Mvm/GCMmap2/MvmGC.h vmkit/trunk/lib/Mvm/GCMmap2/gc.cpp vmkit/trunk/lib/Mvm/GCMmap2/gccollector.h vmkit/trunk/lib/Mvm/GCMmap2/gcinit.cpp vmkit/trunk/lib/Mvm/GCMmap2/gcthread.cpp vmkit/trunk/lib/Mvm/GCMmap2/gcthread.h vmkit/trunk/lib/Mvm/Runtime/JIT.cpp vmkit/trunk/lib/Mvm/Runtime/LLVMRuntime.ll vmkit/trunk/lib/Mvm/Runtime/Object.cpp vmkit/trunk/lib/N3/VMCore/CLIJit.cpp vmkit/trunk/lib/N3/VMCore/LockedMap.h vmkit/trunk/lib/N3/VMCore/MSCorlib.cpp vmkit/trunk/lib/N3/VMCore/N3.cpp vmkit/trunk/lib/N3/VMCore/N3.h vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp vmkit/trunk/lib/N3/VMCore/VMCache.cpp vmkit/trunk/lib/N3/VMCore/VMClass.cpp vmkit/trunk/lib/N3/VMCore/VMObject.cpp vmkit/trunk/lib/N3/VMCore/VMObject.h vmkit/trunk/lib/N3/VMCore/VMThread.cpp vmkit/trunk/lib/N3/VMCore/VMThread.h vmkit/trunk/lib/N3/VMCore/VirtualMachine.cpp vmkit/trunk/lib/N3/VMCore/VirtualMachine.h vmkit/trunk/lib/N3/VMCore/VirtualTables.cpp vmkit/trunk/tools/jnjvm/Main.cpp vmkit/trunk/tools/n3-mono/Main.cpp vmkit/trunk/tools/n3-pnetlib/Main.cpp vmkit/trunk/tools/vmjc/vmjc.cpp vmkit/trunk/tools/vmkit/Launcher.cpp Modified: vmkit/trunk/Makefile.common.in URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/Makefile.common.in?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/Makefile.common.in (original) +++ vmkit/trunk/Makefile.common.in Sat Nov 8 05:48:04 2008 @@ -23,7 +23,7 @@ # Include LLVM's Master Makefile. include $(LLVM_OBJ_ROOT)/Makefile.common -CXX.Flags += @GC_FLAGS@ @VM_FLAGS@ -Wno-variadic-macros -fno-omit-frame-pointer -ansi +CXX.Flags += @GC_FLAGS@ @VM_FLAGS@ -Wno-variadic-macros -fno-omit-frame-pointer -ansi -DENABLE_THREADS # GNU Classpath flags CLASSPATH_FLAGS = @classpathinclude@ Modified: vmkit/trunk/include/mvm/JIT.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/JIT.h?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/include/mvm/JIT.h (original) +++ vmkit/trunk/include/mvm/JIT.h Sat Nov 8 05:48:04 2008 @@ -112,7 +112,7 @@ llvm::Function* llvm_atomic_lcs_i64; static llvm::ExecutionEngine* executionEngine; - static mvm::Lock* protectEngine; + static mvm::LockNormal protectEngine; static uint64 getTypeSize(const llvm::Type* type); static void AddStandardCompilePasses(llvm::FunctionPassManager*); @@ -179,10 +179,6 @@ static uint32 (*llvm_atomic_cmp_swap_i32) ( uint32* ptr, uint32 cmp, uint32 val ); static uint64 (*llvm_atomic_cmp_swap_i64) ( uint64* ptr, uint64 cmp, uint64 val ); - static llvm::GlobalVariable* executionEnvironment; - static mvm::Thread* (*getExecutionEnvironment)(); - static void (*setExecutionEnvironment)(mvm::Thread*); - }; // TODO: find what macro for gcc < 4.2 Modified: vmkit/trunk/include/mvm/Threads/Cond.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Threads/Cond.h?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/include/mvm/Threads/Cond.h (original) +++ vmkit/trunk/include/mvm/Threads/Cond.h Sat Nov 8 05:48:04 2008 @@ -10,27 +10,22 @@ #ifndef MVM_COND_H #define MVM_COND_H -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "mvm/Threads/Locks.h" - #include +#include namespace mvm { +class Lock; + class Cond { - unsigned int no_barrier; - unsigned int go; - unsigned int n_wait; + pthread_cond_t internalCond; public: - Cond() : no_barrier(0), go(0), n_wait(0) { } - static Cond *allocCond(void); + Cond(); + ~Cond(); void broadcast(void); void wait(Lock *l); - int timed_wait(Lock *l, timeval *tv); + int timedWait(Lock *l, timeval *tv); void signal(void); }; Removed: vmkit/trunk/include/mvm/Threads/Key.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Threads/Key.h?rev=58902&view=auto ============================================================================== --- vmkit/trunk/include/mvm/Threads/Key.h (original) +++ vmkit/trunk/include/mvm/Threads/Key.h (removed) @@ -1,54 +0,0 @@ -//===---------------- Key.h - Private thread keys -------------------------===// -// -// The Micro Virtual Machine -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef MVM_KEY_H -#define MVM_KEY_H - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include - -namespace mvm { - -class ThreadKey { -public: - pthread_key_t val; - - ThreadKey(void (*_destr)(void *)); - ThreadKey(); - void* get(); - void set(void*); - void initialise(); - -}; - -template -class Key { -public: - ThreadKey key; - - Key() { - initialise(); - } - - void initialise() { - key.initialise(); - } - - T* get() { return (T*)key.get(); } - void set(T *v) { key.set(v); } - -}; - - -} // end namespace mvm - -#endif // MVM_KEY_H Modified: vmkit/trunk/include/mvm/Threads/Locks.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Threads/Locks.h?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/include/mvm/Threads/Locks.h (original) +++ vmkit/trunk/include/mvm/Threads/Locks.h Sat Nov 8 05:48:04 2008 @@ -10,92 +10,61 @@ #ifndef MVM_LOCKS_H #define MVM_LOCKS_H -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif +#include namespace mvm { -class SpinLock { - unsigned int value; -public: - SpinLock() { value = 0; } - - void slock(); - void sunlock() { - value = 0; - } -}; +class Cond; +class LockNormal; +class LockRecursive; -class Lock : public SpinLock { +class Lock { + friend class Cond; protected: - void (*xlock)(Lock *); - void (*xunlock)(Lock *); - int (*xtrylock)(Lock *); - - int _owner; + int owner; + pthread_mutex_t internalLock; public: - inline Lock() { _owner = 0; } - inline int owner() { return _owner; } - inline void owner(int o) { _owner = o; } - - void lock() { - xlock(this); - } - - void unlock() { - xunlock(this); - } - - int trylock() { - int res = xtrylock(this); - return res; - } - - static Lock *allocNormal(); - static Lock *allocRecursive(); - static void destroy(Lock *); + Lock(bool rec); + + ~Lock(); + + virtual void lock() = 0; + virtual void unlock() = 0; - static bool selfOwner(Lock *); - static int getOwner(Lock *); + bool selfOwner(); + int getOwner(); }; class LockNormal : public Lock { - static void my_lock(Lock *); - static void my_unlock(Lock *); - static int my_trylock(Lock *); public: - LockNormal() { - xlock = my_lock; xunlock = my_unlock; xtrylock = my_trylock; - } + LockNormal() : Lock(false) {} + virtual void lock(); + virtual void unlock(); - void initialise() { - xlock = my_lock; xunlock = my_unlock; xtrylock = my_trylock; - } }; class LockRecursive : public Lock { +private: int n; - static void my_lock(Lock *); - static void my_unlock(Lock *); - static int my_trylock(Lock *); public: - LockRecursive() { - xlock = my_lock; xunlock = my_unlock; xtrylock = my_trylock; n = 0; + LockRecursive() : Lock(true) { + n = 0; } - void initialise() { - xlock = my_lock; xunlock = my_unlock; xtrylock = my_trylock; n = 0; - } + virtual void lock(); + virtual void unlock(); - static int recursion_count(Lock *); - static int my_unlock_all(Lock *); - static void my_lock_all(Lock *, int count); + int recursionCount() { + return n; + } + int unlockAll(); + void lockAll(int count); }; + } // end namespace mvm #endif // MVM_LOCKS_H Modified: vmkit/trunk/include/mvm/Threads/Thread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Threads/Thread.h?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/include/mvm/Threads/Thread.h (original) +++ vmkit/trunk/include/mvm/Threads/Thread.h Sat Nov 8 05:48:04 2008 @@ -15,7 +15,6 @@ #include "MvmGC.h" #include "mvm/JIT.h" #include "mvm/Object.h" -#include "mvm/Threads/Key.h" class Collector; @@ -24,10 +23,41 @@ class BumpPtrAllocator; + +class CircularBase { + CircularBase *_next; + CircularBase *_prev; +public: + inline CircularBase *next() { return _next; } + inline CircularBase *prev() { return _prev; } + + inline void next(CircularBase *n) { _next = n; } + inline void prev(CircularBase *p) { _prev = p; } + + inline CircularBase() { alone(); } + inline explicit CircularBase(CircularBase *p) { append(p); } + + inline void remove() { + _prev->_next = _next; + _next->_prev = _prev; + alone(); + } + + inline void append(CircularBase *p) { + _prev = p; + _next = p->_next; + _next->_prev = this; + _prev->_next = this; + } + + inline void alone() { _prev = _next = this; } +}; + + /// Thread - This class is the base of custom virtual machines' Thread classes. /// It provides static functions to manage threads. An instance of this class /// contains all thread-specific informations. -class Thread : public Object { +class Thread : public CircularBase { public: /// yield - Yield the processor to another thread. @@ -44,27 +74,22 @@ /// static int self(void); - /// initialise - Initialise the thread implementation. Used for pthread_key. - /// - static void initialise(void); - /// kill - Kill the thread with the given pid by sending it a signal. /// static int kill(int tid, int signo); + + /// kill - Kill the given thread by sending it a signal. + /// + int kill(int signo); /// exit - Exit the current thread. /// static void exit(int value); - /// start - Start the execution of a thread, creating it and setting its - /// Thread instance. + /// start - Start the execution of a thread. /// - static int start(int *tid, int (*fct)(void *), void *arg); + int start(void (*fct)(mvm::Thread*)); -private: - /// threadKey - the key for accessing the thread specific data. - /// - static mvm::Key* threadKey; public: @@ -83,29 +108,24 @@ /// threadID - The virtual machine specific thread id. /// uint32 threadID; - + /// get - Get the thread specific data of the current thread. /// static Thread* get() { -#if 1//defined(__PPC__) || defined(__ppc__) - return (Thread*)Thread::threadKey->get(); -#else - return (Thread*)mvm::jit::getExecutionEnvironment(); -#endif + return (Thread*)((uintptr_t)__builtin_frame_address(0) & IDMask); } - /// set - Set the thread specific data of the current thread. - /// - static void set(Thread* th) { -#if 1//defined(__PPC__) || defined(__ppc__) - Thread::threadKey->set(th); -#else - mvm::jit::setExecutionEnvironment(th); -#endif - } - private: + /// internalThreadID - The implementation specific thread id. + /// + void* internalThreadID; + + /// internalThreadStart - The implementation sepcific thread starter + /// function. + /// + static void internalThreadStart(mvm::Thread* th); + /// internalClearException - Clear any pending exception. virtual void internalClearException() {} @@ -116,6 +136,13 @@ Thread* th = Thread::get(); th->internalClearException(); } + + static const uint32_t IDMask = 0x7FF00000; + + void* operator new(size_t sz); + + void (*routine)(mvm::Thread*); + }; Modified: vmkit/trunk/include/mvm/VirtualMachine.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/VirtualMachine.h?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/include/mvm/VirtualMachine.h (original) +++ vmkit/trunk/include/mvm/VirtualMachine.h Sat Nov 8 05:48:04 2008 @@ -21,8 +21,7 @@ namespace mvm { /// VirtualMachine - This class is the root of virtual machine classes. It -/// defines what a VM should be. Currently, a VM only initializes itself -/// and runs applications. +/// defines what a VM should be. /// class VirtualMachine : public mvm::Object { public: @@ -33,7 +32,9 @@ /// compile - Compile a given file to LLVM. virtual void compile(const char* name) = 0; - + + /// waitForExit - Wait until the virtual machine stops its execution. + virtual void waitForExit() = 0; static CompilationUnit* initialiseJVM(bool staticCompilation = false); static VirtualMachine* createJVM(CompilationUnit* C = 0); Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThread.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThread.cpp?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThread.cpp (original) +++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThread.cpp Sat Nov 8 05:48:04 2008 @@ -40,30 +40,25 @@ return (jobject)(JavaThread::currentThread()); } -static void start(JavaObject* vmThread) { - // Get the classpath - Classpath* upcalls = vmThread->classOf->classLoader->bootstrapLoader->upcalls; - - // When starting the thread, the creator placed the vm object in the vmThread - Jnjvm* vm = (Jnjvm*)upcalls->vmdataVMThread->getObjectField(vmThread); - assert(vm && "Thread Creator did not put the vm"); - - // Classpath has set this field. - JavaObject* javaThread = upcalls->assocThread->getObjectField(vmThread); - assert(javaThread && "VMThread with no Java equivalent"); - - // Create the Java thread.Allocating it on stack will make it call the - // destructor when the function exists. - JavaThread th(javaThread, vm, &upcalls); - - // Ok, now we can set the real value of vmdata, which is the JavaThread - // object. - vm->upcalls->vmdataVMThread->setObjectField(vmThread, (JavaObject*)(void*)&th); +static void start(JavaThread* thread) { + Jnjvm* vm = thread->isolate; + + // Ok, now that the thread is created we can set the the value of vmdata, + // which is the JavaThread object. + JavaField* field = vm->upcalls->vmdataVMThread; + JavaObject* vmThread = thread->vmThread; + assert(vmThread && "Didn't fix the vmThread of a jnjvm thread"); + JavaObject* javaThread = thread->javaThread; + assert(javaThread && "Didn't fix the javaThread of a jnjvm thread"); + field->setObjectField(vmThread, (JavaObject*)(void*)thread); + UserClass* vmthClass = (UserClass*)vmThread->classOf; ThreadSystem& ts = vm->threadSystem; + // If the thread is not a daemon, it is added to the list of threads to + // wait until exit. bool isDaemon = vm->upcalls->daemon->getInt8Field(javaThread); if (!isDaemon) { @@ -72,8 +67,10 @@ ts.nonDaemonLock.unlock(); } - upcalls->runVMThread->invokeIntSpecial(vm, vmthClass, vmThread); - + // Run the VMThread::run function + vm->upcalls->runVMThread->invokeIntSpecial(vm, vmthClass, vmThread); + + // Remove the thread from the list. if (!isDaemon) { ts.nonDaemonLock.lock(); ts.nonDaemonThreads--; @@ -91,14 +88,13 @@ Jnjvm* vm = JavaThread::get()->isolate; JavaObject* vmThread = (JavaObject*)_vmThread; - // Set the vm in the vmData. We do this to give the vm to the created - // thread. The created thread will change the field to its JavaThread - // object. - vm->upcalls->vmdataVMThread->setObjectField(vmThread, (JavaObject*)vm); - - int tid = 0; - - mvm::Thread::start(&tid, (int (*)(void *))start, (void*)vmThread); + // Classpath has set this field. + JavaObject* javaThread = vm->upcalls->assocThread->getObjectField(vmThread); + assert(javaThread && "VMThread with no Java equivalent"); + + JavaThread* th = new JavaThread(javaThread, vmThread, vm); + if (!th) vm->outOfMemoryError(0); + th->start((void (*)(mvm::Thread*))start); } JNIEXPORT void JNICALL Java_java_lang_VMThread_interrupt( Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Sat Nov 8 05:48:04 2008 @@ -92,6 +92,7 @@ nbStaticMethods = 0; nbInterfaces = 0; access = 0; + ownerClass = 0; } Class::Class() : CommonClass() { @@ -276,6 +277,7 @@ virtualFields = 0; staticFields = 0; access = 0; + ownerClass = 0; #if !defined(ISOLATE) && !defined(ISOLATE_SHARING) this->delegatee = 0; #endif @@ -520,7 +522,8 @@ JavaObject* UserClass::doNew(Jnjvm* vm) { assert(this && "No class when allocating."); - assert((this->isReady() || classLoader->getModule()->isStaticCompiling()) + assert((this->isInitializing() || + classLoader->getModule()->isStaticCompiling()) && "Uninitialized class when allocating."); JavaObject* res = (JavaObject*)vm->gcAllocator.allocateManagedObject(getVirtualSize(), Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Sat Nov 8 05:48:04 2008 @@ -52,9 +52,9 @@ classRead = 1, /// The .class file has been read. prepared = 2, /// The parents of this class has been resolved. resolved = 3, /// The class has been resolved. - clinitParent = 4, /// The class is cliniting its parents. - inClinit = 5, /// The class is cliniting. - ready = 6, /// The class is ready to be used. + inClinit = 4, /// The class is cliniting. + ready = 5, /// The class is ready to be used. + erroneous = 6, /// The class is in an erroneous state. dontuseenums = 0xffffffff /// dummy value to force the enum to be int32 }JavaState; @@ -342,11 +342,9 @@ condVar.broadcast(); } - /// ownerClass - Is the current thread the owner of this thread? + /// ownerClass - Who is initializing this class. /// - bool ownerClass() { - return mvm::Lock::selfOwner(&lockVar); - } + uint32 ownerClass; /// lookupMethodDontThrow - Lookup a method in the method map of this class. /// Do not throw if the method is not found. @@ -440,7 +438,11 @@ /// isReady - Has this class been initialized? /// bool isReady() { - return status >= clinitParent; + return status == ready; + } + + bool isInitializing() { + return status >= inClinit; } /// isResolved - Has this class been resolved? Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaObject.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaObject.cpp?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaObject.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaObject.cpp Sat Nov 8 05:48:04 2008 @@ -91,7 +91,7 @@ void JavaObject::overflowThinlock() { LockObj* obj = LockObj::allocate(); - mvm::LockRecursive::my_lock_all(&obj->lock, 257); + obj->lock.lockAll(257); lock = ((uint32)obj >> 1) | 0x80000000; } @@ -151,7 +151,7 @@ LockObj* obj = LockObj::allocate(); uint32 val = (((uint32) obj) >> 1) | 0x80000000; uint32 count = lock & 0xFF; - mvm::LockRecursive::my_lock_all(&obj->lock, count + 1); + obj->lock.lockAll(count + 1); lock = val; return obj; } else { @@ -179,22 +179,22 @@ thread->interruptFlag = 0; thread->isolate->interruptedException(this); } else { - unsigned int recur = mvm::LockRecursive::recursion_count(&l->lock); + unsigned int recur = l->lock.recursionCount(); bool timeout = false; - mvm::LockRecursive::my_unlock_all(&l->lock); + l->lock.unlockAll(); JavaCond* cond = l->getCond(); cond->wait(thread); thread->state = JavaThread::StateWaiting; if (timed) { - timeout = varcondThread.timed_wait(&mutexThread, info); + timeout = varcondThread.timedWait(&mutexThread, info); } else { varcondThread.wait(&mutexThread); } bool interrupted = (thread->interruptFlag != 0); mutexThread.unlock(); - mvm::LockRecursive::my_lock_all(&l->lock, recur); + l->lock.lockAll(recur); if (interrupted || timeout) { cond->remove(thread); Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaObject.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaObject.h?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaObject.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaObject.h Sat Nov 8 05:48:04 2008 @@ -97,7 +97,7 @@ /// owner - Returns if the current thread owns this lock. /// bool owner() { - return mvm::Lock::selfOwner(&lock); + return lock.selfOwner(); } /// getCond - Returns the conditation variable of this lock, allocating it Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp Sat Nov 8 05:48:04 2008 @@ -40,7 +40,8 @@ uint32 index = enveloppe->index; ctpInfo->resolveMethod(index, cl, utf8, sign); - assert(obj->classOf->isReady() && "Class not ready in a virtual lookup."); + assert(obj->classOf->isInitializing() && + "Class not ready in a virtual lookup."); enveloppe->cacheLock.lock(); CacheNode* rcache = 0; @@ -62,7 +63,7 @@ JavaMethod* dmeth = ocl->lookupMethod(utf8, sign->keyName, false, true, &methodCl); #ifndef ISOLATE_SHARING - assert(dmeth->classDef->isReady() && + assert(dmeth->classDef->isInitializing() && "Class not ready in a virtual lookup."); #endif if (cache->methPtr) { @@ -128,10 +129,13 @@ JavaField* field = cl->lookupField(utf8, sign->keyName, true, true, &fieldCl); fieldCl->initialiseClass(JavaThread::get()->isolate); - void* ptr = - (void*)((uint64)(((UserClass*)fieldCl)->getStaticInstance()) + field->ptrOffset); - ctpInfo->ctpRes[index] = ptr; + JavaObject* obj = ((UserClass*)fieldCl)->getStaticInstance(); + + assert(obj && "No static instance in static field lookup"); + void* ptr = (void*)((uint64)obj + field->ptrOffset); + ctpInfo->ctpRes[index] = ptr; + return ptr; } @@ -219,7 +223,8 @@ va_start(ap, index); JavaObject* obj = va_arg(ap, JavaObject*); va_end(ap); - assert(obj->classOf->isReady() && "Class not ready in a virtual lookup."); + assert(obj->classOf->isInitializing() && + "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, 0); @@ -228,7 +233,8 @@ } #ifndef ISOLATE_SHARING - assert(dmeth->classDef->isReady() && "Class not ready in a virtual lookup."); + assert(dmeth->classDef->isInitializing() && + "Class not ready in a virtual lookup."); #endif return (void*)dmeth->offset; Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaThread.cpp Sat Nov 8 05:48:04 2008 @@ -9,7 +9,6 @@ #include "mvm/JIT.h" #include "mvm/PrintBuffer.h" -#include "mvm/Threads/Key.h" #include "mvm/Threads/Locks.h" #include "mvm/Threads/Thread.h" @@ -31,54 +30,24 @@ if (javaThread) javaThread->print(buf); } -JavaThread::JavaThread(JavaObject* thread, Jnjvm* vm, void* sp) { - if (!thread) bootstrap = true; - else bootstrap = false; +JavaThread::JavaThread(JavaObject* thread, JavaObject* vmth, Jnjvm* vm) { javaThread = thread; + vmThread = vmth; isolate = vm; interruptFlag = 0; state = StateRunning; pendingException = 0; vmAllocator = &isolate->allocator; - baseSP = sp; - mvm::Thread::set(this); - threadID = (mvm::Thread::self() << 8) & 0x7FFFFF00; - - if (!bootstrap) { -#ifdef MULTIPLE_GC - GC = isolate->GC; - GC->inject_my_thread(sp); -#else - Collector::inject_my_thread(sp); -#endif - #ifdef SERVICE_VM - ServiceDomain* domain = (ServiceDomain*)vm; - domain->startExecution(); - domain->lock->lock(); - domain->numThreads++; - domain->lock->unlock(); + ServiceDomain* domain = (ServiceDomain*)vm; + domain->startExecution(); + domain->lock->lock(); + domain->numThreads++; + domain->lock->unlock(); #endif - } - - } -JavaThread::~JavaThread() { - if (!bootstrap) { -#ifdef MULTIPLE_GC - GC->remove_my_thread(); -#else - Collector::remove_my_thread(); -#endif -#ifdef SERVICE_VM - ServiceDomain* vm = (ServiceDomain*)isolate; - vm->lock->lock(); - vm->numThreads--; - vm->lock->unlock(); -#endif - } -} +JavaThread::~JavaThread() {} // We define these here because gcc compiles the 'throw' keyword // differently, whether these are defined in a file or not. Since many Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaThread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaThread.h?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaThread.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaThread.h Sat Nov 8 05:48:04 2008 @@ -14,7 +14,6 @@ #include "mvm/Object.h" #include "mvm/Threads/Cond.h" -#include "mvm/Threads/Key.h" #include "mvm/Threads/Locks.h" #include "mvm/Threads/Thread.h" @@ -30,6 +29,7 @@ public: static VirtualTable *VT; JavaObject* javaThread; + JavaObject* vmThread; Jnjvm* isolate; mvm::LockNormal lock; mvm::Cond varcond; @@ -38,18 +38,17 @@ uint32 interruptFlag; uint32 state; std::vector sjlj_buffers; - bool bootstrap; static const unsigned int StateRunning; static const unsigned int StateWaiting; static const unsigned int StateInterrupted; - virtual void print(mvm::PrintBuffer *buf) const; + void print(mvm::PrintBuffer *buf) const; virtual void TRACER; - JavaThread() { bootstrap = true; } + JavaThread() {} ~JavaThread(); - JavaThread(JavaObject* thread, Jnjvm* isolate, void* sp); + JavaThread(JavaObject* thread, JavaObject* vmThread, Jnjvm* isolate); static JavaThread* get() { return (JavaThread*)mvm::Thread::get(); @@ -94,6 +93,13 @@ longjmp((__jmp_buf_tag*)sjlj_buffers.back(), 1); #endif } + + /// printString - Prints the class. + char *printString() const { + mvm::PrintBuffer *buf = mvm::PrintBuffer::alloc(); + print(buf); + return buf->contents()->cString(); + } private: virtual void internalClearException() { Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Sat Nov 8 05:48:04 2008 @@ -46,82 +46,199 @@ typedef void (*clinit_t)(Jnjvm* vm, UserConstantPool*); + +/// initialiseClass - Java class initialisation. Java specification §2.17.5. + void UserCommonClass::initialiseClass(Jnjvm* vm) { - // Primitives are initialized at boot time + + // Assumes that the Class object has already been verified and prepared and + // that the Class object contains state that can indicate one of four + // situations: + // + // * This Class object is verified and prepared but not initialized. + // * This Class object is being initialized by some particular thread T. + // * This Class object is fully initialized and ready for use. + // * This Class object is in an erroneous state, perhaps because the + // verification step failed or because initialization was attempted and + // failed. + + assert(status >= resolved || ownerClass || status == ready || + status == erroneous && "Class in wrong state"); + + // Primitives are initialized at boot time, arrays are initialized directly. if (isArray()) { status = ready; } else if (status != ready) { + + // 1. Synchronize on the Class object that represents the class or + // interface to be initialized. This involves waiting until the + // current thread can obtain the lock for that object + // (Java specification §8.13). acquire(); + uint32 self = mvm::Thread::get()->threadID; + + if (status == inClinit) { + // 2. If initialization by some other thread is in progress for the + // class or interface, then wait on this Class object (which + // temporarily releases the lock). When the current thread awakens + // from the wait, repeat this step. + if (ownerClass != self) { + while (ownerClass) { + waitClass(); + } + release(); + } else { + // 3. If initialization is in progress for the class or interface by + // the current thread, then this must be a recursive request for + // initialization. Release the lock on the Class object and complete + // normally. + release(); + return; + } + } + + // 4. If the class or interface has already been initialized, then no + // further action is required. Release the lock on the Class object + // and complete normally. if (status == ready) { release(); - } else if (status >= resolved && status != clinitParent && - status != inClinit) { - UserClass* cl = (UserClass*)this; - status = clinitParent; + return; + } + + // 5. If the Class object is in an erroneous state, then initialization is + // not possible. Release the lock on the Class object and throw a + // NoClassDefFoundError. + if (status == erroneous) { release(); - UserCommonClass* super = getSuper(); - if (super) { + vm->noClassDefFoundError(name); + } + + // 6. Otherwise, record the fact that initialization of the Class object is + // now in progress by the current thread and release the lock on the + // Class object. + ownerClass = self; + status = inClinit; + release(); + + + // 7. Next, if the Class object represents a class rather than an interface, + // and the direct superclass of this class has not yet been initialized, + // then recursively perform this entire procedure for the uninitialized + // superclass. If the initialization of the direct superclass completes + // abruptly because of a thrown exception, then lock this Class object, + // label it erroneous, notify all waiting threads, release the lock, + // and complete abruptly, throwing the same exception that resulted from + // the initializing the superclass. + UserCommonClass* super = getSuper(); + if (super) { + JavaObject *exc = 0; + try { super->initialiseClass(vm); + } catch(...) { + exc = JavaThread::getJavaException(); + assert(exc && "no exception?"); + JavaThread::clearException(); } - cl->resolveStaticClass(); + if (exc) { + acquire(); + status = erroneous; + ownerClass = 0; + broadcastClass(); + release(); + throw exc; + } + } + + // 8. Next, execute either the class variable initializers and static + // initializers of the class or the field initializers of the interface, + // in textual order, as though they were a single block, except that + // final static variables and fields of interfaces whose values are + // compile-time constants are initialized first. + + + UserClass* cl = (UserClass*)this; + cl->resolveStaticClass(); - status = inClinit; - 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); - PRINT_DEBUG(JNJVM_LOAD, 0, COLOR_NORMAL, "%s\n", printString()); + PRINT_DEBUG(JNJVM_LOAD, 0, COLOR_NORMAL, "; ", 0); + PRINT_DEBUG(JNJVM_LOAD, 0, LIGHT_GREEN, "clinit ", 0); + PRINT_DEBUG(JNJVM_LOAD, 0, COLOR_NORMAL, "%s\n", printString()); - JavaObject* val = - (JavaObject*)vm->gcAllocator.allocateManagedObject(cl->getStaticSize(), + JavaObject* val = + (JavaObject*)vm->gcAllocator.allocateManagedObject(cl->getStaticSize(), cl->getStaticVT()); - val->initialise(cl); - JavaField* fields = cl->getStaticFields(); - for (uint32 i = 0; i < cl->nbStaticFields; ++i) { - fields[i].initField(val, vm); - } + val->initialise(cl); + JavaField* fields = cl->getStaticFields(); + for (uint32 i = 0; i < cl->nbStaticFields; ++i) { + fields[i].initField(val, vm); + } - cl->setStaticInstance(val); - - if (meth) { - JavaObject* exc = 0; - try{ - clinit_t pred = (clinit_t)(intptr_t)meth->compiledPtr(); - pred(vm, cl->getConstantPool()); - } catch(...) { - exc = JavaThread::getJavaException(); - assert(exc && "no exception?"); - JavaThread::clearException(); - } - if (exc) { - if (exc->classOf->isAssignableFrom(vm->upcalls->newException)) { - vm->initializerError(exc); - } else { - JavaThread::throwException(exc); - } - } - } + cl->setStaticInstance(val); + + JavaMethod* meth = lookupMethodDontThrow(vm->bootstrapLoader->clinitName, + vm->bootstrapLoader->clinitType, + true, false, 0); + + JavaObject* exc = 0; + if (meth) { + try{ + clinit_t pred = (clinit_t)(intptr_t)meth->compiledPtr(); + pred(vm, cl->getConstantPool()); + } catch(...) { + exc = JavaThread::getJavaException(); + assert(exc && "no exception?"); + JavaThread::clearException(); + } + } + + // 9. If the execution of the initializers completes normally, then lock + // this Class object, label it fully initialized, notify all waiting + // threads, release the lock, and complete this procedure normally. + if (!exc) { + acquire(); status = ready; + ownerClass = 0; broadcastClass(); - } else if (status < resolved) { - release(); - vm->unknownError("try to clinit a not-read class..."); - } else { - if (!ownerClass()) { - while (status < ready) waitClass(); - release(); - initialiseClass(vm); - } release(); + return; } + + // 10. Otherwise, the initializers must have completed abruptly by + // throwing some exception E. If the class of E is not Error or one + // of its subclasses, then create a new instance of the class + // ExceptionInInitializerError, with E as the argument, and use this + // object in place of E in the following step. But if a new instance of + // ExceptionInInitializerError cannot be created because an + // OutOfMemoryError occurs, then instead use an OutOfMemoryError object + // in place of E in the following step. + if (exc->classOf->isAssignableFrom(vm->upcalls->newException)) { + Classpath* upcalls = classLoader->bootstrapLoader->upcalls; + UserClass* clExcp = upcalls->ExceptionInInitializerError; + Jnjvm* vm = JavaThread::get()->isolate; + JavaObject* obj = clExcp->doNew(vm); + if (!obj) { + fprintf(stderr, "implement me"); + abort(); + } + JavaMethod* init = upcalls->ErrorWithExcpExceptionInInitializerError; + init->invokeIntSpecial(vm, clExcp, obj, exc); + exc = obj; + } + + // 11. Lock the Class object, label it erroneous, notify all waiting + // threads, release the lock, and complete this procedure abruptly + // with reason E or its replacement as determined in the previous step. + acquire(); + status = erroneous; + ownerClass = 0; + broadcastClass(); + release(); + throw exc; } } - - + void Jnjvm::errorWithExcp(UserClass* cl, JavaMethod* init, const JavaObject* excp) { JavaObject* obj = cl->doNew(this); init->invokeIntSpecial(this, cl, obj, excp); @@ -338,25 +455,6 @@ extern "C" struct JNINativeInterface JNI_JNIEnvTable; extern "C" const struct JNIInvokeInterface JNI_JavaVMTable; -namespace jnjvm { - -class ClArgumentsInfo { -public: - uint32 appArgumentsPos; - char* className; - std::vector< std::pair > agents; - - void readArgs(int argc, char** argv, Jnjvm *vm); - void extractClassFromJar(Jnjvm* vm, int argc, char** argv, int i); - void javaAgent(char* cur); - - void printInformation(); - void nyi(); - void printVersion(); -}; - -} - void ClArgumentsInfo::javaAgent(char* cur) { assert(0 && "implement me"); } @@ -477,7 +575,7 @@ " load Java programming language agent, see java.lang.instrument\n"); } -void ClArgumentsInfo::readArgs(int argc, char** argv, Jnjvm* vm) { +void ClArgumentsInfo::readArgs(Jnjvm* vm) { className = 0; appArgumentsPos = 0; sint32 i = 1; @@ -734,57 +832,71 @@ } void Jnjvm::waitForExit() { + threadSystem.nonDaemonLock.lock(); - --(threadSystem.nonDaemonThreads); while (threadSystem.nonDaemonThreads) { threadSystem.nonDaemonVar.wait(&threadSystem.nonDaemonLock); } + + threadSystem.nonDaemonLock.unlock(); - threadSystem.nonDaemonLock.unlock(); return; } -void Jnjvm::runApplication(int argc, char** argv) { - ClArgumentsInfo info; - - info.readArgs(argc, argv, this); - if (info.className) { - int pos = info.appArgumentsPos; - - argv = argv + pos - 1; - argc = argc - pos + 1; - - mvm::Thread* oldThread = mvm::Thread::get(); - JavaThread thread(0, this, oldThread->baseSP); - bootstrapThread = &thread; +void Jnjvm::mainJavaStart(JavaThread* thread) { + Jnjvm* vm = thread->isolate; + vm->bootstrapThread = thread; - loadBootstrap(); + vm->loadBootstrap(); #ifdef SERVICE_VM - ServiceDomain::initialise((ServiceDomain*)this); + ServiceDomain::initialise((ServiceDomain*)vm); #endif - - if (info.agents.size()) { - assert(0 && "implement me"); - JavaObject* instrumenter = 0;//createInstrumenter(); - for (std::vector< std::pair >::iterator i = - info.agents.begin(), - e = info.agents.end(); i!= e; ++i) { - JavaString* args = asciizToStr(i->second); - executePremain(i->first, args, instrumenter); - } + + ClArgumentsInfo& info = vm->argumentsInfo; +#if 0 + if (info.agents.size()) { + assert(0 && "implement me"); + JavaObject* instrumenter = 0;//createInstrumenter(); + for (std::vector< std::pair >::iterator i = + info.agents.begin(), + e = info.agents.end(); i!= e; ++i) { + JavaString* args = vm->asciizToStr(i->second); + vm->executePremain(i->first, args, instrumenter); } + } +#endif - UserClassArray* array = bootstrapLoader->upcalls->ArrayOfString; - ArrayObject* args = (ArrayObject*)array->doNew(argc - 2, this); - for (int i = 2; i < argc; ++i) { - args->elements[i - 2] = (JavaObject*)asciizToStr(argv[i]); - } + UserClassArray* array = vm->bootstrapLoader->upcalls->ArrayOfString; + ArrayObject* args = (ArrayObject*)array->doNew(info.argc - 2, vm); + for (int i = 2; i < info.argc; ++i) { + args->elements[i - 2] = (JavaObject*)vm->asciizToStr(info.argv[i]); + } + + vm->executeClass(info.className, args); + + vm->threadSystem.nonDaemonLock.lock(); + --(vm->threadSystem.nonDaemonThreads); + if (vm->threadSystem.nonDaemonThreads == 0) + vm->threadSystem.nonDaemonVar.signal(); + vm->threadSystem.nonDaemonLock.unlock(); +} - executeClass(info.className, args); - waitForExit(); - mvm::Thread::set(oldThread); +void Jnjvm::runApplication(int argc, char** argv) { + argumentsInfo.argc = argc; + argumentsInfo.argv = argv; + argumentsInfo.readArgs(this); + if (argumentsInfo.className) { + int pos = argumentsInfo.appArgumentsPos; + + argumentsInfo.argv = argumentsInfo.argv + pos - 1; + argumentsInfo.argc = argumentsInfo.argc - pos + 1; + + bootstrapThread = new JavaThread(0, 0, this); + bootstrapThread->start((void (*)(mvm::Thread*))mainJavaStart); + } else { + threadSystem.nonDaemonThreads = 0; } } @@ -845,14 +957,14 @@ } } +static const char* name; -void Jnjvm::compile(const char* name) { - bootstrapLoader->analyseClasspathEnv(classpath); - - mvm::Thread* oldThread = mvm::Thread::get(); - JavaThread thread(0, this, oldThread->baseSP); - bootstrapThread = &thread; +void Jnjvm::mainCompilerStart(JavaThread* th) { + Jnjvm* vm = th->isolate; + JnjvmBootstrapLoader* bootstrapLoader = vm->bootstrapLoader; + + bootstrapLoader->analyseClasspathEnv(vm->classpath); uint32 size = strlen(name); if (size > 4 && @@ -862,7 +974,7 @@ std::vector classes; ArrayUInt8* bytes = Reader::openFile(bootstrapLoader, name); - if (!bytes) unknownError("Can't find zip file."); + if (!bytes) vm->unknownError("Can't find zip file."); ZipArchive archive(bytes, bootstrapLoader->allocator); char* realName = (char*)alloca(4096); @@ -876,7 +988,7 @@ ArrayUInt8* res = (ArrayUInt8*)array->doNew(file->ucsize, bootstrapLoader->allocator); int ok = archive.readFile(res, file); - if (!ok) unknownError("Wrong zip file."); + if (!ok) vm->unknownError("Wrong zip file."); memcpy(realName, file->filename, size); @@ -914,5 +1026,16 @@ i->setLinkage(llvm::GlobalValue::ExternalLinkage); } - mvm::Thread::set(oldThread); + vm->threadSystem.nonDaemonLock.lock(); + --(vm->threadSystem.nonDaemonThreads); + if (vm->threadSystem.nonDaemonThreads == 0) + vm->threadSystem.nonDaemonVar.signal(); + vm->threadSystem.nonDaemonLock.unlock(); + +} + +void Jnjvm::compile(const char* n) { + name = n; + bootstrapThread = new JavaThread(0, 0, this); + bootstrapThread->start((void (*)(mvm::Thread*))mainCompilerStart); } Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h Sat Nov 8 05:48:04 2008 @@ -80,6 +80,23 @@ }; +class ClArgumentsInfo { +public: + int argc; + char** argv; + uint32 appArgumentsPos; + char* className; + std::vector< std::pair > agents; + + void readArgs(Jnjvm *vm); + void extractClassFromJar(Jnjvm* vm, int argc, char** argv, int i); + void javaAgent(char* cur); + + void printInformation(); + void nyi(); + void printVersion(); +}; + /// Jnjvm - A JVM. Each execution of a program allocates a Jnjvm. /// class Jnjvm : public mvm::VirtualMachine { @@ -98,7 +115,7 @@ /// bootstrapThread - The initial thread of this JVM. /// JavaThread* bootstrapThread; - + /// error - Throws an exception in the execution of a JVM for the thread /// that calls this functions. This is used internally by Jnjvm to control /// which pair class/method are used. @@ -135,15 +152,15 @@ /// void executePremain(const char* className, JavaString* args, JavaObject* instrumenter); - - /// waitForExit - Waits that there are no more non-daemon threads in this JVM. + + /// mainJavaStart - Starts the execution of the application in a Java thread. /// - void waitForExit(); + static void mainJavaStart(JavaThread* thread); - /// runMain - Runs the application with the given command line. + /// mainCompileStart - Starts the static compilation of classes in a Java + /// thread. /// - void runMain(int argc, char** argv); - + static void mainCompilerStart(JavaThread* thread); public: @@ -185,7 +202,11 @@ /// control the end of the JVM's execution. /// ThreadSystem threadSystem; - + + /// argumentsInfo - The command line arguments given to the vm + /// + ClArgumentsInfo argumentsInfo; + /// jniEnv - The JNI environment of this JVM. /// void* jniEnv; @@ -257,9 +278,7 @@ /// UTF8, thus duplicating the UTF8. /// JavaString* internalUTF8ToStr(const UTF8* utf8); - - - + /// asciizToInternalUTF8 - Constructs an UTF8 out of the asciiz and changes /// '.' into '/'. /// @@ -299,7 +318,11 @@ /// compile - Compile the .class, .zip or .jar file to LLVM IR. /// virtual void compile(const char* name); - + + /// waitForExit - Waits that there are no more non-daemon threads in this JVM. + /// + virtual void waitForExit(); + }; } // end namespace jnjvm Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h Sat Nov 8 05:48:04 2008 @@ -51,6 +51,7 @@ /// table for non-isolate environments. /// class JnjvmClassLoader : public mvm::CompilationUnit { + friend class Jnjvm; private: Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp Sat Nov 8 05:48:04 2008 @@ -92,6 +92,7 @@ constant_pool_iterator I = constantPools.find(ctp); if (I == End) { void* ptr = ctp->ctpRes; + assert(ptr && "No constant pool found"); Constant* cons = ConstantExpr::getIntToPtr(ConstantInt::get(Type::Int64Ty, uint64(ptr)), mvm::MvmModule::ptrPtrType); @@ -112,6 +113,7 @@ varGV = SI->second; } else { void* ptr = str; + assert(ptr && "No string given"); Constant* cons = ConstantExpr::getIntToPtr(ConstantInt::get(Type::Int64Ty, uint64(ptr)), JnjvmModule::JavaObjectType); @@ -130,6 +132,7 @@ varGV = SI->second; } else { void* ptr = enveloppe; + assert(ptr && "No enveloppe given"); Constant* cons = ConstantExpr::getIntToPtr(ConstantInt::get(Type::Int64Ty, uint64(ptr)), JnjvmModule::EnveloppeType); @@ -149,6 +152,7 @@ JavaObject* obj = isStaticCompiling() ? 0 : cl->getClassDelegatee(JavaThread::get()->isolate); + assert(obj && "Delegatee not created"); Constant* cons = ConstantExpr::getIntToPtr(ConstantInt::get(Type::Int64Ty, uint64(obj)), JnjvmModule::JavaObjectType); @@ -171,6 +175,7 @@ LLVMClassInfo* LCI = getClassInfo(classDef); LCI->getStaticType(); JavaObject* obj = ((Class*)classDef)->getStaticInstance(); + assert(obj && "Getting static instance before it's created!"); Constant* cons = ConstantExpr::getIntToPtr(ConstantInt::get(Type::Int64Ty, uint64_t (obj)), JnjvmModule::JavaObjectType); @@ -196,6 +201,7 @@ LLVMClassInfo* LCI = getClassInfo((Class*)classDef); LCI->getVirtualType(); } + assert(classDef->virtualVT && "Virtual VT not created"); Constant* cons = ConstantExpr::getIntToPtr(ConstantInt::get(Type::Int64Ty, uint64_t(classDef->virtualVT)), @@ -220,6 +226,8 @@ LLVMSignatureInfo* LSI = getSignatureInfo(meth->getSignature()); const llvm::Type* valPtrType = LSI->getNativePtrType(); + + assert(ptr && "No native function given"); Constant* cons = ConstantExpr::getIntToPtr(ConstantInt::get(Type::Int64Ty, uint64_t(ptr)), @@ -980,7 +988,7 @@ OffsetStatusInClassConstant = mvm::MvmModule::constantFive; OffsetCtpInClassConstant = mvm::MvmModule::constantSix; - ClassReadyConstant = ConstantInt::get(Type::Int32Ty, clinitParent); + ClassReadyConstant = ConstantInt::get(Type::Int32Ty, ready); LLVMAssessorInfo::initialise(); } Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmModuleProvider.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmModuleProvider.cpp?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JnjvmModuleProvider.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmModuleProvider.cpp Sat Nov 8 05:48:04 2008 @@ -98,7 +98,7 @@ uint64_t offset = LMI->getOffset()->getZExtValue(); assert(meth->classDef->isResolved() && "Class not resolved"); #ifndef ISOLATE_SHARING - assert(meth->classDef->isReady() && "Class not ready"); + assert(meth->classDef->isInitializing() && "Class not ready"); #endif assert(meth->classDef->virtualVT && "Class has no VT"); assert(meth->classDef->virtualTableSize > offset && @@ -247,17 +247,17 @@ JnjvmModuleProvider::JnjvmModuleProvider(JnjvmModule *m) { TheModule = (Module*)m; - mvm::MvmModule::protectEngine->lock(); + mvm::MvmModule::protectEngine.lock(); mvm::MvmModule::executionEngine->addModuleProvider(this); - mvm::MvmModule::protectEngine->unlock(); + mvm::MvmModule::protectEngine.unlock(); perFunctionPasses = new llvm::FunctionPassManager(this); perFunctionPasses->add(new llvm::TargetData(m)); AddStandardCompilePasses(m, perFunctionPasses); } JnjvmModuleProvider::~JnjvmModuleProvider() { - mvm::MvmModule::protectEngine->lock(); + mvm::MvmModule::protectEngine.lock(); mvm::MvmModule::executionEngine->removeModuleProvider(this); - mvm::MvmModule::protectEngine->unlock(); + mvm::MvmModule::protectEngine.unlock(); delete TheModule; } Modified: vmkit/trunk/lib/JnJVM/VMCore/LowerConstantCalls.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/LowerConstantCalls.cpp?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/LowerConstantCalls.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/LowerConstantCalls.cpp Sat Nov 8 05:48:04 2008 @@ -249,7 +249,7 @@ Value* Status = new LoadInst(StatusPtr, "", CI); - Value* test = new ICmpInst(ICmpInst::ICMP_UGT, Status, + Value* test = new ICmpInst(ICmpInst::ICMP_EQ, Status, jnjvm::JnjvmModule::ClassReadyConstant, "", CI); Modified: vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp Sat Nov 8 05:48:04 2008 @@ -108,6 +108,12 @@ if (l) l->MARK_AND_TRACE; } +static void traceClassMap(ClassMap* classes) { + for (ClassMap::iterator i = classes->map.begin(), e = classes->map.end(); + i!= e; ++i) { + i->second->CALL_TRACER; + } +} void JavaThread::TRACER { javaThread->MARK_AND_TRACE; @@ -121,24 +127,7 @@ #if defined(ISOLATE_SHARING) JnjvmSharedLoader::sharedLoader->MARK_AND_TRACE; #endif -} - -static void traceClassMap(ClassMap* classes) { - for (ClassMap::iterator i = classes->map.begin(), e = classes->map.end(); - i!= e; ++i) { - i->second->CALL_TRACER; - } -} - -void JnjvmClassLoader::TRACER { - javaLoader->MARK_AND_TRACE; - traceClassMap(classes); - isolate->MARK_AND_TRACE; - TRACE_VECTOR(JavaString*, gc_allocator, strings); -} - -void JnjvmBootstrapLoader::TRACER { - traceClassMap(classes); + traceClassMap(bootstrapLoader->classes); #define TRACE_DELEGATEE(prim) \ prim->delegatee->MARK_AND_TRACE @@ -154,9 +143,25 @@ TRACE_DELEGATEE(upcalls->OfDouble); #undef TRACE_DELEGATEE + TRACE_VECTOR(JavaString*, gc_allocator, bootstrapLoader->strings); + + if (bootstrapThread) { + bootstrapThread->CALL_TRACER; + for (JavaThread* th = (JavaThread*)bootstrapThread->next(); + th != bootstrapThread; th = (JavaThread*)th->next()) + th->CALL_TRACER; + } +} + +void JnjvmClassLoader::TRACER { + javaLoader->MARK_AND_TRACE; + traceClassMap(classes); + isolate->MARK_AND_TRACE; TRACE_VECTOR(JavaString*, gc_allocator, strings); } +void JnjvmBootstrapLoader::TRACER {} + #if defined(ISOLATE_SHARING) void UserClass::TRACER { classLoader->MARK_AND_TRACE; Modified: vmkit/trunk/lib/Mvm/CommonThread/ctlock.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommonThread/ctlock.cpp?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/CommonThread/ctlock.cpp (original) +++ vmkit/trunk/lib/Mvm/CommonThread/ctlock.cpp Sat Nov 8 05:48:04 2008 @@ -16,224 +16,110 @@ using namespace mvm; -inline int atomic_test_and_pass(unsigned int *ptr) { +Lock::Lock(bool recursive) { + pthread_mutexattr_t attr; -#if defined(__ppc__) || defined(__powerpc__) - int result; -# if defined(__MACH__) - const int val=1; - - asm volatile("1:\n" -#if 0 - " lwz %0,0(%1)\n" /* result <- ptr[0] */ - " cmpwi %0,0\n" - " bne 1b\n" + // Initialize the mutex attributes + int errorcode = pthread_mutexattr_init(&attr); + assert(errorcode == 0); + + // Initialize the mutex as a recursive mutex, if requested, or normal + // otherwise. + int kind = ( recursive ? PTHREAD_MUTEX_RECURSIVE : PTHREAD_MUTEX_NORMAL ); + errorcode = pthread_mutexattr_settype(&attr, kind); + assert(errorcode == 0); + +#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && \ + !defined(__DragonFly__) + // Make it a process local mutex + errorcode = pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_PRIVATE); #endif - " lwarx %0,0,%1\n" /* result <- ptr[0] */ - " cmpwi %0,0\n" - " bne 1b\n" - " stwcx. %2,0,%1\n" /* ptr[0] <- 1 (si pas d'autre accès) */ - " bne- 1b\n" - " isync\n" /* empeche toute execution d'instruction après le lock!!! */ - :"=&r"(result): "r"(ptr), "r"(val): "cr0", "memory"); - /* le & empeche gcc d'utiliser le même register pour result et les entrées... */ -# else - const int val=1; - - asm volatile("1:\n" - " lwarx %0,0,%1\n" /* result <- ptr[0] */ - " cmpwi %0,0\n" - " bne 1b\n" - " stwcx. %2,0,%1\n" /* ptr[0] <- 1 (si pas d'autre accès) */ - " bne- 1b\n" - " isync\n" /* empeche toute execution d'instruction après le lock!!! */ - :"=&r"(result): "r"(ptr), "r"(val): "cr0", "memory"); - /* le & empeche gcc d'utiliser le même register pour result et les entrées... */ -# endif - - return result; -#elif defined(__i386__) - // asm ("bts $1, %1; sbbl %0, %0":"=r" (result):"m" (*ptr):"memory"); - unsigned int old; - int c=0; - do { - asm volatile("movl $1,%0;" - "xchgl %0, %1" : "=&r"(old) : "m"(*ptr)); - if(!old) - return 0; - if(!(++c & 0xf)) - Thread::yield(); - } while(1); -#else -#error "I do not know how to do an atomic test and pass on your machine" -#endif -} -Lock *Lock::allocRecursive() { - return new LockRecursive(); -} + // Initialize the mutex + errorcode = pthread_mutex_init(&internalLock, &attr); + assert(errorcode == 0); -Lock *Lock::allocNormal() { - return new LockNormal(); -} + // Destroy the attributes + errorcode = pthread_mutexattr_destroy(&attr); + assert(errorcode == 0); -void Lock::destroy(Lock *l) { + owner = 0; } -bool Lock::selfOwner(Lock *l) { - return l->owner() == Thread::self(); +Lock::~Lock() { + pthread_mutex_destroy((pthread_mutex_t*)&internalLock); } -int Lock::getOwner(Lock *l) { - return l->owner(); +bool Lock::selfOwner() { + return owner == Thread::self(); } -void SpinLock::slock() { - atomic_test_and_pass(&value); +int Lock::getOwner() { + return owner; } -void LockNormal::my_lock(Lock *l) { - unsigned int c = 0; - - l->slock(); - - while(l->owner()) { - l->sunlock(); - Thread::yield(&c); - l->slock(); - } - l->owner(Thread::self()); - l->sunlock(); +void LockNormal::lock() { + pthread_mutex_lock((pthread_mutex_t*)&internalLock); + owner = (int)pthread_self(); } -void LockNormal::my_unlock(Lock *l) { - l->owner(0); +void LockNormal::unlock() { + owner = 0; + pthread_mutex_unlock((pthread_mutex_t*)&internalLock); } -int LockNormal::my_trylock(Lock *) { - ctfatal("not implemented"); - return -1; +void LockRecursive::lock() { + pthread_mutex_lock((pthread_mutex_t*)&internalLock); + if (!owner) owner = (int)pthread_self(); + ++n; } -void LockRecursive::my_lock(Lock *l) { - unsigned int c = 0; - - int self = Thread::self(); - - l->slock(); - while(l->owner() && (l->owner() != self)) { - l->sunlock(); - Thread::yield(&c); - l->slock(); - } - l->owner(self); - ((LockRecursive *)l)->n++; - l->sunlock(); +void LockRecursive::unlock() { + --n; + owner = 0; + pthread_mutex_unlock((pthread_mutex_t*)&internalLock); } - void LockRecursive::my_unlock(Lock *l) { - if(!--((LockRecursive *)l)->n) - l->owner(0); - } - -int LockRecursive::my_trylock(Lock *) { - ctfatal("not implemented"); - return -1; +int LockRecursive::unlockAll() { + int res = n; + while (n) unlock(); + return res; } -int LockRecursive::recursion_count(Lock *l){ - return ((LockRecursive*)l)->n; +void LockRecursive::lockAll(int count) { + for (int i = 0; i < count; ++i) lock(); } -int LockRecursive::my_unlock_all(Lock *l){ - int count = ((LockRecursive*)l)->n; - ((LockRecursive*)l)->n = 0; - l->owner(0); - return count; +Cond::Cond() { + int errorcode = pthread_cond_init((pthread_cond_t*)&internalCond, NULL); + assert(errorcode == 0); } -void LockRecursive::my_lock_all(Lock *l, int count){ - LockRecursive::my_lock(l); - ((LockRecursive*)l)->n = count; -} - - - - -void Cond::wait(Lock *l) { - unsigned int n=0; - unsigned int my_barrier = no_barrier; - - n_wait++; /* un attente de plus */ - while(1) { - if(no_barrier == my_barrier) /* pas de broadcast */ - if(go) { /* un signal? */ - n_wait--; /* pus une attente en moins */ - go--; /* pour le pochain */ - return; - } else { /* à l'ouest rien de nouveau */ - l->unlock(); /* je rend gentillement le lock */ - Thread::yield(&n); /* j'attends qu'on me libère... */ - l->lock(); /* je reprends mon lock */ - } - else /* on a eu un broadcast */ - return; - } -} - -int Cond::timed_wait(Lock *l, struct timeval *ref) { - unsigned int n=0; - unsigned int my_barrier = no_barrier; - struct timeval max, cur; - - gettimeofday(&max, 0); - timeradd(&max, ref, &max); - - n_wait++; - while(1) { - if(no_barrier == my_barrier) /* pas de broadcast */ - if(go) { /* un signal? */ - n_wait--; /* puis une attente en moins */ - go--; /* pour le pochain */ - return 0; - } else { /* à l'ouest rien de nouveau */ - gettimeofday(&cur, 0); - if(timercmp(&cur, &max, >=)) {/* timesout écoulé */ - n_wait--; /* on n'attend plus */ - return 1; /* c'est nif */ - } - - l->unlock(); - timersub(&max, &cur, &cur); /* le reste */ - if(!cur.tv_sec && (cur.tv_usec <= 2)) - Thread::yield(); /* j'attends qu'on me libère... */ - else - Thread::yield(&n); /* j'attends qu'on me libère... */ - l->lock(); /* je reprends mon lock */ - } - else /* on a eu un broadcast */ - return 0; - } +Cond::~Cond() { + pthread_cond_destroy((pthread_cond_t*)&internalCond); } void Cond::broadcast() { - no_barrier++; - n_wait = 0; -} - -void Cond::signal() { - if(n_wait>go) go++; + pthread_cond_broadcast((pthread_cond_t*)&internalCond); } - -extern "C" void lock_C(Lock* l) { - return l->lock(); +void Cond::wait(Lock* l) { + pthread_cond_wait((pthread_cond_t*)&internalCond, + (pthread_mutex_t*)&(l->internalLock)); } -extern "C" void unlock_C(Lock* l) { - return l->unlock(); +void Cond::signal() { + pthread_cond_signal((pthread_cond_t*)&internalCond); } -Cond* Cond::allocCond() { - return new Cond(); +int Cond::timedWait(Lock* l, struct timeval *ref) { + + struct timespec timeout; + struct timeval now; + struct timezone tz; + gettimeofday(&now, &tz); + timeout.tv_sec = now.tv_sec + ref->tv_sec; + timeout.tv_nsec = now.tv_usec + ref->tv_usec; + return pthread_cond_timedwait((pthread_cond_t*)&internalCond, + (pthread_mutex_t*)&(l->internalLock), &timeout); } Modified: vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp (original) +++ vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp Sat Nov 8 05:48:04 2008 @@ -7,12 +7,12 @@ // //===----------------------------------------------------------------------===// -#include "mvm/Threads/Key.h" #include "mvm/Threads/Thread.h" #include #include #include +#include using namespace mvm; @@ -20,11 +20,7 @@ sched_yield(); } -int Thread::self() { - return (int)pthread_self(); -} - -void Thread::yield(unsigned int *c) { + void Thread::yield(unsigned int *c) { if(++(*c) & 3) sched_yield(); else { @@ -35,44 +31,152 @@ } } +int Thread::self() { + return (int)pthread_self(); +} + int Thread::kill(int tid, int signo) { return pthread_kill((pthread_t)tid, signo); } +int Thread::kill(int signo) { + return pthread_kill((pthread_t)internalThreadID, signo); +} + void Thread::exit(int value) { pthread_exit((void*)value); } -void* ThreadKey::get() { - pthread_key_t k = (pthread_key_t)val; - return (void *)pthread_getspecific(k); -} +// These could be set at runtime. +#define STACK_SIZE 0x100000 +#define NR_THREADS 255 -void ThreadKey::set(void *v) { - pthread_key_t k = (pthread_key_t)val; - pthread_setspecific(k, v); -} -ThreadKey::ThreadKey(void (*_destr)(void *)) { - pthread_key_create((pthread_key_t*)&val, _destr); -} +/// StackThreadManager - This class allocates all stacks for threads. Because +/// we want fast access to thread local data, and can not rely on platform +/// dependent thread local storage (eg pthread keys are inefficient, tls is +/// specific to Linux), we put thread local data at the bottom of the +/// stack. A simple mask computes the thread local data , based on the current +/// stack pointer. +// +/// The stacks are allocated at boot time. They must all be in the memory range +/// 0x?0000000 and Ox(?+1)0000000, so that the thread local data can be computed +/// and threads have a unique ID. +/// +class StackThreadManager { +public: + uintptr_t baseAddr; + uint32 allocPtr; + uint32 used[NR_THREADS]; + LockNormal lock; + + StackThreadManager() { + baseAddr = 0; + uintptr_t ptr = 0x00000000; + + // Do an mmap at a fixed address. If the mmap fails for a given address + // use the next one. + while (!baseAddr && ptr != 0xF0000000) { + ptr = ptr + 0x10000000; +#if defined (__MACH__) + uint32 flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED; +#else + uint32 flags = MAP_PRIVATE | MAP_ANON | MAP_FIXED; +#endif + baseAddr = (uintptr_t)mmap((void*)ptr, STACK_SIZE * NR_THREADS, + PROT_READ | PROT_WRITE, flags, 0, 0); + if (baseAddr == (uintptr_t)MAP_FAILED) baseAddr = 0; + } + if (!baseAddr) { + fprintf(stderr, "Can not allocate thread memory\n"); + abort(); + } + + // Protect the page after the first page. The first page contains thread + // specific data. The second page has no access rights to catch stack + // overflows. + uint32 pagesize = getpagesize(); + for (uint32 i = 0; i < NR_THREADS; ++i) { + uintptr_t addr = baseAddr + (i * STACK_SIZE) + pagesize; + mprotect((void*)addr, pagesize, PROT_NONE); + } -ThreadKey::ThreadKey() { - pthread_key_create((pthread_key_t*)&val, NULL); -} + memset((void*)used, 0, NR_THREADS); + allocPtr = 0; + } -void ThreadKey::initialise() { - pthread_key_create((pthread_key_t*)&val, NULL); -} + uintptr_t allocate() { + uint32 start = allocPtr; + bool found = false; + uint32 myAllocPtr = allocPtr; + do { + found = __sync_bool_compare_and_swap(&used[myAllocPtr], 0, 1); + myAllocPtr++; + if (myAllocPtr == NR_THREADS) myAllocPtr = 0; + } while (myAllocPtr != start && !found); + + if (found) { + allocPtr = myAllocPtr; + return baseAddr + (myAllocPtr - 1) * STACK_SIZE; + } + + return 0; + } + +}; + + +/// Static allocate a stack manager. In the future, this should be virtual +/// machine specific. +StackThreadManager TheStackManager; + +/// internalThreadStart - The initial function called by a thread. Sets some +/// thread specific data, registers the thread to the GC and calls the +/// given routine of th. +/// +void Thread::internalThreadStart(mvm::Thread* th) { + th->internalThreadID = (void*)pthread_self(); + th->threadID = (int)th & mvm::Thread::IDMask; + th->baseSP = &th; + +#ifdef MULTIPLE_GC + GC->inject_my_thread(th); +#else + Collector::inject_my_thread(th); +#endif + + + th->routine(th); + +#ifdef MULTIPLE_GC + GC->remove_my_thread(th); +#else + Collector::remove_my_thread(th); +#endif -void Thread::initialise() { - Thread::threadKey = new mvm::Key(); - Thread* th = new Thread(); - mvm::Thread::set(th); } -int Thread::start(int *tid, int (*fct)(void *), void *arg) { - int res = pthread_create((pthread_t *)tid, 0, (void * (*)(void *))fct, arg); +/// start - Called by the creator of the thread to run the new thread. +/// The thread is in a detached state, because each virtual machine has +/// its own way of waiting for created threads. +int Thread::start(void (*fct)(mvm::Thread*)) { + pthread_attr_t attributs; + pthread_attr_init(&attributs); + pthread_attr_setstack(&attributs, this, STACK_SIZE); + pthread_t tid; + routine = fct; + int res = pthread_create(&tid, &attributs, + (void* (*)(void *))internalThreadStart, this); pthread_detach(*(pthread_t *)tid); + pthread_attr_destroy(&attributs); return res; } + + +/// operator new - Get a stack from the stack manager. The Thread object +/// will be placed in the first page at the bottom of the stack. Hence +/// Thread objects can not exceed a page. +void* Thread::operator new(size_t sz) { + assert(sz < (size_t)getpagesize() && "Thread local data too big"); + return (void*)TheStackManager.allocate(); +} Modified: vmkit/trunk/lib/Mvm/GCMmap2/MvmGC.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/GCMmap2/MvmGC.h?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/GCMmap2/MvmGC.h (original) +++ vmkit/trunk/lib/Mvm/GCMmap2/MvmGC.h Sat Nov 8 05:48:04 2008 @@ -32,6 +32,10 @@ #define MARK_AND_TRACE markAndTrace() #endif +namespace mvm { + class Thread; +} + class Collector; class gc : public gcRoot { @@ -74,7 +78,7 @@ #endif typedef void (*markerFn)(void*); - static void initialise(markerFn mark, void *base_sp); + static void initialise(markerFn mark); STATIC void destroy(); STATIC void die_if_sigsegv_occured_during_collection(void *addr); @@ -84,8 +88,8 @@ STATIC void gcStats(size_t &no, size_t &nbb); STATIC void maybeCollect(); STATIC void collect(void); - STATIC void inject_my_thread(void *sp); - STATIC void remove_my_thread(); + STATIC void inject_my_thread(mvm::Thread* th); + STATIC void remove_my_thread(mvm::Thread* th); #ifdef MULTIPLE_GC static Collector* allocate(); #endif Removed: vmkit/trunk/lib/Mvm/GCMmap2/ctcircular.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/GCMmap2/ctcircular.h?rev=58902&view=auto ============================================================================== --- vmkit/trunk/lib/Mvm/GCMmap2/ctcircular.h (original) +++ vmkit/trunk/lib/Mvm/GCMmap2/ctcircular.h (removed) @@ -1,57 +0,0 @@ -//===------------- ctcircular.h - Mvm Garbage Collector -------------------===// -// -// Mvm -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef _CT_CIRCULAR_H_ -#define _CT_CIRCULAR_H_ - -#include "ctosdep.h" - - -class CircularBase { - CircularBase *_next; - CircularBase *_prev; -public: - inline CircularBase *next() { return _next; } - inline CircularBase *prev() { return _prev; } - - inline void next(CircularBase *n) { _next = n; } - inline void prev(CircularBase *p) { _prev = p; } - - inline CircularBase() { alone(); } - inline explicit CircularBase(CircularBase *p) { append(p); } - - inline void remove() { - _prev->_next = _next; - _next->_prev = _prev; - alone(); - } - - inline void append(CircularBase *p) { - _prev = p; - _next = p->_next; - _next->_prev = this; - _prev->_next = this; - } - - inline void alone() { _prev = _next = this; } -}; - -class Circular : public CircularBase, public TObj { -public: - inline Circular() : CircularBase() {} - inline Circular(Circular *p) : CircularBase(p) {} - inline ~Circular() { - if(prev() != this) { - next()->prev(prev()); - delete next(); - } - } -}; - -#endif Modified: vmkit/trunk/lib/Mvm/GCMmap2/gc.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/GCMmap2/gc.cpp?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/GCMmap2/gc.cpp (original) +++ vmkit/trunk/lib/Mvm/GCMmap2/gc.cpp Sat Nov 8 05:48:04 2008 @@ -111,29 +111,18 @@ COLLECTOR gcStats(&no, &nbb); } -void Collector::initialise(markerFn marker, void *base_sp) { -#ifdef MULTIPLE_GC - GCCollector* GC = new GCCollector(); - GCCollector::bootstrapGC = GC; - mvm::Thread::get()->GC = GC; - GC->initialise(marker); - GC->inject_my_thread(base_sp); -#else +void Collector::initialise(markerFn marker) { GCCollector::initialise(marker); - GCCollector::inject_my_thread(base_sp); -#endif - mvm::Thread::get()->baseSP = base_sp; } void Collector::destroy() { COLLECTOR destroy(); } -void Collector::inject_my_thread(void *base_sp) { +void Collector::inject_my_thread(mvm::Thread* th) { #ifdef HAVE_PTHREAD - COLLECTOR inject_my_thread(base_sp); + COLLECTOR inject_my_thread(th); #endif - mvm::Thread::get()->baseSP = base_sp; } void Collector::maybeCollect() { @@ -182,9 +171,9 @@ //onMemoryError = &COLLECTOR defaultMemoryError; } -void Collector::remove_my_thread() { +void Collector::remove_my_thread(mvm::Thread* th) { #ifdef HAVE_PTHREAD - COLLECTOR remove_thread(COLLECTOR threads->myloc()); + COLLECTOR remove_thread(th); #endif } @@ -200,9 +189,10 @@ #else #define COLLECTOR GCCollector:: #endif + mvm::Thread* th = mvm::Thread::get(); unsigned int cm = COLLECTOR current_mark; - if(Thread::self() != collector_tid) { + if(th != current_collector) { collectorGo(); while((COLLECTOR current_mark == cm) && (COLLECTOR status == COLLECTOR stat_collect)) @@ -224,18 +214,18 @@ #else #define COLLECTOR GCCollector:: #endif - GCThreadCollector *loc = COLLECTOR threads->myloc(); - + mvm::Thread* th = mvm::Thread::get(); + jmp_buf buf; setjmp(buf); COLLECTOR threads->stackLock(); - if(!loc) /* a key is being destroyed */ + if(!th) /* The thread is being destroyed */ COLLECTOR threads->another_mark(); else { register unsigned int **cur = (unsigned int**)(void*)&buf; - register unsigned int **max = loc->base_sp(); + register unsigned int **max = (unsigned int**)th->baseSP; GCChunkNode *node; Modified: vmkit/trunk/lib/Mvm/GCMmap2/gccollector.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/GCMmap2/gccollector.h?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/GCMmap2/gccollector.h (original) +++ vmkit/trunk/lib/Mvm/GCMmap2/gccollector.h Sat Nov 8 05:48:04 2008 @@ -113,9 +113,9 @@ static int siggc(); #ifdef HAVE_PTHREAD - STATIC void inject_my_thread(void *base_sp); - STATIC inline void remove_thread(GCThreadCollector *loc) { - threads->remove(loc); + STATIC void inject_my_thread(mvm::Thread* th); + STATIC inline void remove_thread(mvm::Thread* th) { + threads->remove(th); } STATIC inline int isStable(gc_lock_recovery_fct_t fct, int a0, int a1, int a2, int a3, int a4, int a5, int a6, int a7) { Modified: vmkit/trunk/lib/Mvm/GCMmap2/gcinit.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/GCMmap2/gcinit.cpp?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/GCMmap2/gcinit.cpp (original) +++ vmkit/trunk/lib/Mvm/GCMmap2/gcinit.cpp Sat Nov 8 05:48:04 2008 @@ -80,42 +80,9 @@ allocator = 0; } - -static void *get_curr_fp(void) -{ - register void *fp; - asm( -# if defined(__ppc__) || defined(__PPC__) -# if defined(__MACH__) - "mr %0, r1" -# else - "mr %0, 1" -# endif -# elif defined(__i386__) - "movl %%ebp, %0" -# elif defined(__amd64__) - "movq %%rbp, %0" -# else -# error: -# error: I do not know how to read the frame pointer on this machine -# error: -# endif - :"=r"(fp):); - return fp; -} - -static void *get_base_sp(void) -{ - void *fp= 0; - for (fp= get_curr_fp(); (*(void **)fp); fp= *(void **)fp) {} - return fp; -} - #ifdef HAVE_PTHREAD -void GCCollector::inject_my_thread(void *base_sp) { - if(!base_sp) - base_sp = get_base_sp(); - threads->inject(base_sp, current_mark); +void GCCollector::inject_my_thread(mvm::Thread* th) { + threads->inject(th); } #endif Modified: vmkit/trunk/lib/Mvm/GCMmap2/gcthread.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/GCMmap2/gcthread.cpp?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/GCMmap2/gcthread.cpp (original) +++ vmkit/trunk/lib/Mvm/GCMmap2/gcthread.cpp Sat Nov 8 05:48:04 2008 @@ -19,27 +19,27 @@ } void GCThread::synchronize() { - GCThreadCollector *cur; int signo = GCCollector::siggc(); - int reached = 0; - collector_tid = Thread::self(); - + mvm::Thread* self = mvm::Thread::get(); + assert(self && "No thread local data for this thread"); + current_collector = self; _nb_collected = 0; - for(cur=(GCThreadCollector *)base.next(); cur!=&base; cur=(GCThreadCollector *)cur->next()) { - int t = cur->tid(); - if(t != Thread::self()) - Thread::kill(cur->tid(), signo); - else - reached = 1; + + for(mvm::Thread* cur = (mvm::Thread*)self->next(); cur != self; + cur = (mvm::Thread*)cur->next()) { + cur->kill(signo); } - if(reached) /* moi aussi je dois collecter... */ - GCCollector::siggc_handler(signo); - waitStacks(); + + GCCollector::siggc_handler(signo); + + waitStacks(); } -int GCLockRecovery::verify_recall(gc_lock_recovery_fct_t fct, int a0, int a1, int a2, int a3, int a4, int a5, int a6, int a7) { - if(owner() == Thread::self()) { - _fct = fct; _args[0] = a0; _args[1] = a1; _args[2] = a2; _args[3] = a3; +int GCLockRecovery::verify_recall(gc_lock_recovery_fct_t fct, int a0, int a1, + int a2, int a3, int a4, int a5, int a6, + int a7) { + if(selfOwner()) { + _fct = fct; _args[0] = a0; _args[1] = a1; _args[2] = a2; _args[3] = a3; _args[4] = a4; _args[5] = a5; _args[6] = a6; _args[7] = a7; return 0; } else Modified: vmkit/trunk/lib/Mvm/GCMmap2/gcthread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/GCMmap2/gcthread.h?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/GCMmap2/gcthread.h (original) +++ vmkit/trunk/lib/Mvm/GCMmap2/gcthread.h Sat Nov 8 05:48:04 2008 @@ -10,43 +10,12 @@ #ifndef _GC_THREAD_H_ #define _GC_THREAD_H_ -#include "ctcircular.h" #include "mvm/Threads/Cond.h" -#include "mvm/Threads/Key.h" #include "mvm/Threads/Locks.h" -#include "mvm/Threads/Thread.h" // only for self - -// class GCAllocator; +#include "mvm/Threads/Thread.h" namespace mvm { -class GCThreadCollector : public CircularBase { - void *_base_sp; - int _tid; - -public: -#ifdef SERVICE_GC - void* meta; -#endif - inline GCThreadCollector() {} - inline GCThreadCollector(GCThreadCollector *pred, int t, void *p, int m) : CircularBase(pred) { - _base_sp = p; - _tid = t; -#ifdef SERVICE_GC - meta = 0; -#endif - } - - /* This function is only called in two cases: - * 1) When a thread quits, in which case everything is already done. - * 2) When the collector quits, in which case all memory is freed. - */ - inline ~GCThreadCollector() {} - - inline int tid() { return _tid; } - inline unsigned int **base_sp() { return (unsigned int **)_base_sp; } -}; - class GCLockRecovery : public LockNormal { gc_lock_recovery_fct_t _fct; int _args[8]; @@ -54,10 +23,11 @@ public: inline GCLockRecovery() { _fct = 0; } - int verify_recall(gc_lock_recovery_fct_t fct, int a0, int a1, int a2, int a3, int a4, int a5, int a6, int a7); + int verify_recall(gc_lock_recovery_fct_t fct, int a0, int a1, int a2, int a3, + int a4, int a5, int a6, int a7); inline void unlock_dont_recovery() { - if(owner() == Thread::self()) { + if(selfOwner()) { LockNormal::unlock(); } } @@ -66,8 +36,8 @@ if(_fct) { gc_lock_recovery_fct_t tmp = _fct; int l[8]; - l[0] = _args[0]; l[1] = _args[1]; l[2] = _args[2]; l[3] = _args[3]; - l[4] = _args[4]; l[5] = _args[5]; l[6] = _args[6]; l[7] = _args[7]; + l[0] = _args[0]; l[1] = _args[1]; l[2] = _args[2]; l[3] = _args[3]; + l[4] = _args[4]; l[5] = _args[5]; l[6] = _args[6]; l[7] = _args[7]; _fct = 0; LockNormal::unlock(); tmp(l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7]); @@ -77,28 +47,44 @@ }; class GCThread { - GCLockRecovery _globalLock; /* global lock for gcmalloc */ - LockNormal _stackLock; /* stack lock for synchronization */ - Cond _stackCond; /* condition for unlocking other tasks (write protect) */ - Cond _collectionCond;/* condition for unblocking the collecter */ - unsigned int _nb_threads; /* number of active threads */ - unsigned int _nb_collected; /* number of threads collected */ - int collector_tid; /* don't synchonize this one */ + /// _globalLoc - Global lock for gcmalloc. + GCLockRecovery _globalLock; + + /// _stackLock - Stack lock for synchronization. + LockNormal _stackLock; + + /// _stackCond - Condition for unlocking other tasks (write protect). + Cond _stackCond; + + /// _collectionCond - Condition for unblocking the collector. + Cond _collectionCond; + + /// _nb_threads - Number of active threads. + unsigned int _nb_threads; + + /// _nb_collected - Number of threads collected. + unsigned int _nb_collected; + + /// current_collector - The initiating thread for collection. Don't + /// synchonize this one. + mvm::Thread* current_collector; public: - GCThreadCollector base; - Key _loc; + mvm::Thread* base; + GCThread() { _nb_threads = 0; _nb_collected = 0; - collector_tid = 0; + current_collector = 0; + base = 0; } inline void lock() { _globalLock.lock(); } inline void unlock() { _globalLock.unlock(); } inline void unlock_dont_recovery() { _globalLock.unlock_dont_recovery(); } - inline int isStable(gc_lock_recovery_fct_t fct, int a0, int a1, int a2, int a3, int a4, int a5, int a6, int a7) { + inline int isStable(gc_lock_recovery_fct_t fct, int a0, int a1, int a2, + int a3, int a4, int a5, int a6, int a7) { return _globalLock.verify_recall(fct, a0, a1, a2, a3, a4, a5, a6, a7); } @@ -110,34 +96,34 @@ inline void collectionFinished() { _collectionCond.broadcast(); } inline void collectorGo() { _stackCond.broadcast(); } - inline void cancel() { - _nb_collected = _nb_threads; /* all stacks have been collected */ - collectorGo(); /* unblock all threads in stack collection */ - collectionFinished(); /* unblock mutators */ + inline void cancel() { + // all stacks have been collected + _nb_collected = _nb_threads; + // unblock all threads in stack collection + collectorGo(); + // unblock mutators + collectionFinished(); } - inline GCThreadCollector *myloc() { return _loc.get(); } - inline void another_mark() { _nb_collected++; } void synchronize(); - inline void remove(GCThreadCollector *loc) { + inline void remove(mvm::Thread* th) { lock(); - loc->remove(); + th->remove(); _nb_threads--; - delete loc; + if (!_nb_threads) base = 0; unlock(); } - inline void inject(void *sp, int m) { - GCThreadCollector *me = _loc.get(); - if(me) - gcfatal("thread %d is already in pool for allocator %p", Thread::self(), this); - lock(); /* the new should be protected */ - me = new GCThreadCollector(&base, Thread::self(), sp, m); + inline void inject(mvm::Thread* th) { + lock(); + if (base) + th->append(base); + else + base = th; _nb_threads++; - _loc.set(me); unlock(); } }; Modified: vmkit/trunk/lib/Mvm/Runtime/JIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/JIT.cpp?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Runtime/JIT.cpp (original) +++ vmkit/trunk/lib/Mvm/Runtime/JIT.cpp Sat Nov 8 05:48:04 2008 @@ -78,14 +78,6 @@ (uintptr_t)executionEngine->getPointerToFunction( module.getFunction("runtime.llvm.atomic.cmp.swap.i64")); - executionEnvironment = module.getGlobalVariable("executionEnvironment"); - getExecutionEnvironment = (mvm::Thread* (*)()) - (uintptr_t)executionEngine->getPointerToFunction( - module.getFunction("getExecutionEnvironment")); - setExecutionEnvironment = (void (*)(mvm::Thread*)) - (uintptr_t)executionEngine->getPointerToFunction( - module.getFunction("setExecutionEnvironment")); - // Type declaration ptrType = PointerType::getUnqual(Type::Int8Ty); ptr32Type = PointerType::getUnqual(Type::Int32Ty); @@ -134,8 +126,6 @@ constantPtrNull = Constant::getNullValue(ptrType); constantPtrSize = ConstantInt::get(Type::Int32Ty, sizeof(void*)); arrayPtrType = PointerType::getUnqual(ArrayType::get(Type::Int8Ty, 0)); - - protectEngine = mvm::Lock::allocNormal(); } @@ -203,7 +193,7 @@ } llvm::ExecutionEngine* MvmModule::executionEngine; -mvm::Lock* MvmModule::protectEngine; +mvm::LockNormal MvmModule::protectEngine; llvm::ConstantInt* MvmModule::constantInt8Zero; llvm::ConstantInt* MvmModule::constantZero; @@ -264,10 +254,6 @@ uint64 val); -llvm::GlobalVariable* MvmModule::executionEnvironment; -mvm::Thread* (*MvmModule::getExecutionEnvironment)(); -void (*MvmModule::setExecutionEnvironment)(mvm::Thread*); - uint64 MvmModule::getTypeSize(const llvm::Type* type) { return executionEngine->getTargetData()->getABITypeSize(type); } Modified: vmkit/trunk/lib/Mvm/Runtime/LLVMRuntime.ll URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/LLVMRuntime.ll?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Runtime/LLVMRuntime.ll (original) +++ vmkit/trunk/lib/Mvm/Runtime/LLVMRuntime.ll Sat Nov 8 05:48:04 2008 @@ -100,21 +100,3 @@ %A = call i64 @llvm.atomic.cmp.swap.i64.p0i64( i64* %ptr, i64 %cmp, i64 %swap) ret i64 %A } - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;;;;;;;;;;;;;;;;;;;; TLS for the execution environment ;;;;;;;;;;;;;;;;;;;;;;;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -%Thread = type {%VT*, i32} - - at executionEnvironment = thread_local global %Thread* null - -define %Thread* @getExecutionEnvironment() nounwind readnone { - %E = load %Thread** @executionEnvironment - ret %Thread* %E -} - -define void @setExecutionEnvironment(%Thread* %E) nounwind { - store %Thread* %E, %Thread** @executionEnvironment - ret void -} Modified: vmkit/trunk/lib/Mvm/Runtime/Object.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/Object.cpp?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Runtime/Object.cpp (original) +++ vmkit/trunk/lib/Mvm/Runtime/Object.cpp Sat Nov 8 05:48:04 2008 @@ -14,7 +14,6 @@ #include "mvm/Method.h" #include "mvm/Object.h" #include "mvm/PrintBuffer.h" -#include "mvm/Threads/Key.h" #include "mvm/Threads/Thread.h" using namespace mvm; @@ -23,8 +22,6 @@ VirtualTable *NativeString::VT = 0; VirtualTable *PrintBuffer::VT = 0; -mvm::Key* mvm::Thread::threadKey = 0; - void Object::initialise() { # define INIT(X) { \ Modified: vmkit/trunk/lib/N3/VMCore/CLIJit.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/CLIJit.cpp?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/CLIJit.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/CLIJit.cpp Sat Nov 8 05:48:04 2008 @@ -1503,9 +1503,9 @@ } void CLIJit::initialiseAppDomain(N3* vm) { - mvm::MvmModule::protectEngine->lock(); + mvm::MvmModule::protectEngine.lock(); mvm::MvmModule::executionEngine->addModuleProvider(vm->TheModuleProvider); - mvm::MvmModule::protectEngine->unlock(); + mvm::MvmModule::protectEngine.unlock(); } namespace n3 { @@ -1517,9 +1517,9 @@ void CLIJit::initialiseBootstrapVM(N3* vm) { mvm::MvmModule* module = vm->module; - module->protectEngine->lock(); + module->protectEngine.lock(); module->executionEngine->addModuleProvider(vm->TheModuleProvider); - module->protectEngine->unlock(); + module->protectEngine.unlock(); n3::llvm_runtime::makeLLVMModuleContents(module); Modified: vmkit/trunk/lib/N3/VMCore/LockedMap.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/LockedMap.h?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/LockedMap.h (original) +++ vmkit/trunk/lib/N3/VMCore/LockedMap.h Sat Nov 8 05:48:04 2008 @@ -123,7 +123,7 @@ static VirtualTable* VT; static ClassNameMap* allocate() { ClassNameMap* map = gc_new(ClassNameMap)(); - map->lock = mvm::Lock::allocNormal(); + map->lock = new mvm::LockNormal(); return map; } }; @@ -134,7 +134,7 @@ static VirtualTable* VT; static ClassTokenMap* allocate() { ClassTokenMap* map = gc_new(ClassTokenMap)(); - map->lock = mvm::Lock::allocNormal(); + map->lock = new mvm::LockNormal(); return map; } @@ -146,7 +146,7 @@ static VirtualTable* VT; static FieldTokenMap* allocate() { FieldTokenMap* map = gc_new(FieldTokenMap)(); - map->lock = mvm::Lock::allocNormal(); + map->lock = new mvm::LockNormal(); return map; } }; @@ -157,7 +157,7 @@ static VirtualTable* VT; static MethodTokenMap* allocate() { MethodTokenMap* map = gc_new(MethodTokenMap)(); - map->lock = mvm::Lock::allocNormal(); + map->lock = new mvm::LockNormal(); return map; } }; @@ -168,7 +168,7 @@ static VirtualTable* VT; static AssemblyMap* allocate() { AssemblyMap* map = gc_new(AssemblyMap)(); - map->lock = mvm::Lock::allocNormal(); + map->lock = new mvm::LockNormal(); return map; } }; @@ -180,7 +180,7 @@ static VirtualTable* VT; static StringMap* allocate() { StringMap* map = gc_new(StringMap)(); - map->lock = mvm::Lock::allocRecursive(); + map->lock = new mvm::LockRecursive(); return map; } }; @@ -191,7 +191,7 @@ static VirtualTable* VT; static FunctionMap* allocate() { FunctionMap* map = gc_new(FunctionMap)(); - map->lock = mvm::Lock::allocNormal(); + map->lock = new mvm::LockNormal(); return map; } }; @@ -222,7 +222,7 @@ static UTF8Map* allocate() { UTF8Map* map = gc_new(UTF8Map)(); - map->lock = mvm::Lock::allocNormal(); + map->lock = new mvm::LockNormal(); return map; } Modified: vmkit/trunk/lib/N3/VMCore/MSCorlib.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/MSCorlib.cpp?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/MSCorlib.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/MSCorlib.cpp Sat Nov 8 05:48:04 2008 @@ -195,7 +195,7 @@ extern "C" void System_GC_Collect() { #ifdef MULTIPLE_GC - mvm::Thread::get()->GC->collect(); + VMThread::get()->GC->collect(); #else Collector::collect(); #endif Modified: vmkit/trunk/lib/N3/VMCore/N3.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/N3.cpp?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/N3.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/N3.cpp Sat Nov 8 05:48:04 2008 @@ -60,28 +60,16 @@ N3* N3::allocateBootstrap() { N3 *vm= gc_new(N3)(); -#ifdef MULTIPLE_GC - Collector* GC = Collector::allocate(); -#endif - std::string str = mvm::MvmModule::executionEngine->getTargetData()->getStringRepresentation(); vm->module = new mvm::MvmModule("Bootstrap N3"); vm->module->setDataLayout(str); - vm->protectModule = mvm::Lock::allocNormal(); + vm->protectModule = new mvm::LockNormal(); vm->functions = FunctionMap::allocate(); vm->TheModuleProvider = new N3ModuleProvider(vm->module, vm->functions); CLIJit::initialiseBootstrapVM(vm); - vm->bootstrapThread = VMThread::allocate(0, vm); - vm->bootstrapThread->baseSP = mvm::Thread::get()->baseSP; -#ifdef MULTIPLE_GC - vm->bootstrapThread->GC = GC; - mvm::MvmModule::memoryManager->addGCForModule(vm->module, GC); -#endif - VMThread::set(vm->bootstrapThread); - vm->name = "bootstrapN3"; vm->hashUTF8 = UTF8Map::allocate(); vm->hashStr = StringMap::allocate(); @@ -95,26 +83,15 @@ N3* N3::allocate(const char* name, N3* parent) { N3 *vm= gc_new(N3)(); -#ifdef MULTIPLE_GC - Collector* GC = Collector::allocate(); -#endif - std::string str = mvm::MvmModule::executionEngine->getTargetData()->getStringRepresentation(); vm->module = new mvm::MvmModule("App Domain"); vm->module->setDataLayout(str); - vm->protectModule = mvm::Lock::allocNormal(); + vm->protectModule = new mvm::LockNormal(); vm->functions = FunctionMap::allocate(); vm->TheModuleProvider = new N3ModuleProvider(vm->module, vm->functions); CLIJit::initialiseAppDomain(vm); - vm->bootstrapThread = VMThread::allocate(0, vm); - vm->bootstrapThread->baseSP = mvm::Thread::get()->baseSP; -#ifdef MULTIPLE_GC - vm->bootstrapThread->GC = GC; - mvm::MvmModule::memoryManager->addGCForModule(vm->module, GC); -#endif - VMThread::set(vm->bootstrapThread); vm->threadSystem = ThreadSystem::allocateThreadSystem(); vm->name = name; @@ -153,22 +130,6 @@ return res; } -namespace n3 { - -class ClArgumentsInfo { -public: - uint32 appArgumentsPos; - char* assembly; - - void readArgs(int argc, char** argv, N3 *vm); - - void printInformation(); - void nyi(); - void printVersion(); -}; - -} - void ClArgumentsInfo::nyi() { fprintf(stdout, "Not yet implemented\n"); } @@ -203,7 +164,6 @@ void N3::waitForExit() { threadSystem->nonDaemonLock->lock(); - --(threadSystem->nonDaemonThreads); while (threadSystem->nonDaemonThreads) { threadSystem->nonDaemonVar->wait(threadSystem->nonDaemonLock); @@ -249,25 +209,43 @@ } void N3::runMain(int argc, char** argv) { - ClArgumentsInfo info; + ClArgumentsInfo& info = argumentsInfo; info.readArgs(argc, argv, this); if (info.assembly) { - argv = argv + info.appArgumentsPos - 1; - argc = argc - info.appArgumentsPos + 1; + info.argv = argv + info.appArgumentsPos - 1; + info.argc = argc - info.appArgumentsPos + 1; - MSCorlib::loadBootstrap(this); - ArrayObject* args = ArrayObject::acons(argc - 2, MSCorlib::arrayString); - for (int i = 2; i < argc; ++i) { - args->setAt(i - 2, (VMObject*)asciizToStr(argv[i])); - } - try{ - executeAssembly(info.assembly, args); - }catch(...) { - VMObject* exc = VMThread::get()->pendingException; - printf("N3 caught %s\n", exc->printString()); - } - waitForExit(); + bootstrapThread = VMThread::TheThread; + bootstrapThread->vm = this; + bootstrapThread->start((void (*)(mvm::Thread*))mainCLIStart); + + } else { + --(threadSystem->nonDaemonThreads); } } + +void N3::mainCLIStart(VMThread* th) { + N3* vm = (N3*)th->vm; + MSCorlib::loadBootstrap(vm); + + ClArgumentsInfo& info = vm->argumentsInfo; + ArrayObject* args = ArrayObject::acons(info.argc - 2, MSCorlib::arrayString); + for (int i = 2; i < info.argc; ++i) { + args->setAt(i - 2, (VMObject*)vm->asciizToStr(info.argv[i])); + } + + try{ + vm->executeAssembly(info.assembly, args); + }catch(...) { + VMObject* exc = th->pendingException; + printf("N3 caught %s\n", exc->printString()); + } + + vm->threadSystem->nonDaemonLock->lock(); + --(vm->threadSystem->nonDaemonThreads); + if (vm->threadSystem->nonDaemonThreads == 0) + vm->threadSystem->nonDaemonVar->signal(); + vm->threadSystem->nonDaemonLock->unlock(); +} Modified: vmkit/trunk/lib/N3/VMCore/N3.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/N3.h?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/N3.h (original) +++ vmkit/trunk/lib/N3/VMCore/N3.h Sat Nov 8 05:48:04 2008 @@ -22,6 +22,7 @@ class Assembly; class AssemblyMap; class FunctionMap; +class N3; class N3ModuleProvider; class StringMap; class UTF8; @@ -32,6 +33,21 @@ class VMField; class VMMethod; +class ClArgumentsInfo { +public: + int argc; + char** argv; + uint32 appArgumentsPos; + char* assembly; + + void readArgs(int argc, char** argv, N3 *vm); + + void printInformation(); + void nyi(); + void printVersion(); +}; + + class N3 : public VirtualMachine { public: static VirtualTable* VT; @@ -43,6 +59,7 @@ Assembly* constructAssembly(const UTF8* name); Assembly* lookupAssembly(const UTF8* name); + ClArgumentsInfo argumentsInfo; const char* name; StringMap * hashStr; AssemblyMap* loadedAssemblies; @@ -58,7 +75,8 @@ Assembly* loadAssembly(const UTF8* name, const char* extension); void executeAssembly(const char* name, ArrayObject* args); void runMain(int argc, char** argv); - void waitForExit(); + virtual void waitForExit(); + static void mainCLIStart(VMThread* th); static N3* bootstrapVM; Modified: vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/N3Initialise.cpp Sat Nov 8 05:48:04 2008 @@ -220,14 +220,15 @@ } +VMThread* VMThread::TheThread = 0; static void initialiseStatics() { CLIJit::initialise(); - VMObject::globalLock = mvm::Lock::allocNormal(); + VMObject::globalLock = new mvm::LockNormal(); N3* vm = N3::bootstrapVM = N3::allocateBootstrap(); - + VMThread::TheThread = VMThread::allocate(0, vm); vm->assemblyPath.push_back(""); @@ -337,7 +338,6 @@ } void VirtualMachine::runApplication(int argc, char** argv) { - mvm::Thread::set(this->bootstrapThread); ((N3*)this)->runMain(argc, argv); } Modified: vmkit/trunk/lib/N3/VMCore/VMCache.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/VMCache.cpp?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/VMCache.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/VMCache.cpp Sat Nov 8 05:48:04 2008 @@ -61,7 +61,7 @@ Enveloppe* enveloppe = gc_new(Enveloppe)(); enveloppe->firstCache = CacheNode::allocate(); enveloppe->firstCache->enveloppe = enveloppe; - enveloppe->cacheLock = mvm::Lock::allocNormal(); + enveloppe->cacheLock = new mvm::LockNormal(); enveloppe->originalMethod = meth; return enveloppe; } Modified: vmkit/trunk/lib/N3/VMCore/VMClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/VMClass.cpp?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/VMClass.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/VMClass.cpp Sat Nov 8 05:48:04 2008 @@ -56,7 +56,7 @@ } bool VMCommonClass::ownerClass() { - return mvm::Lock::selfOwner(lockVar); + return lockVar->selfOwner(); } @@ -160,8 +160,8 @@ void VMCommonClass::initialise(VirtualMachine* vm, bool isArray) { - this->lockVar = mvm::Lock::allocRecursive(); - this->condVar = mvm::Cond::allocCond(); + this->lockVar = new mvm::LockRecursive(); + this->condVar = new mvm::Cond(); this->delegatee = 0; this->status = hashed; this->vm = vm; Modified: vmkit/trunk/lib/N3/VMCore/VMObject.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/VMObject.cpp?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/VMObject.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/VMObject.cpp Sat Nov 8 05:48:04 2008 @@ -77,7 +77,7 @@ LockObj* LockObj::allocate() { LockObj* res = gc_new(LockObj)(); - res->lock = mvm::Lock::allocRecursive(); + res->lock = new mvm::LockRecursive(); res->varcond = VMCond::allocate(); return res; } @@ -91,7 +91,7 @@ } bool LockObj::owner() { - return mvm::Lock::selfOwner(lock); + return lock->selfOwner(); } void VMObject::print(mvm::PrintBuffer* buf) const { @@ -142,21 +142,21 @@ thread->interruptFlag = 0; thread->vm->interruptedException(this); } else { - unsigned int recur = mvm::LockRecursive::recursion_count(l->lock); + unsigned int recur = l->lock->recursionCount(); bool timeout = false; - mvm::LockRecursive::my_unlock_all(l->lock); + l->lock->unlockAll(); l->varcond->wait(thread); thread->state = VMThread::StateWaiting; if (timed) { - timeout = varcondThread->timed_wait(mutexThread, info); + timeout = varcondThread->timedWait(mutexThread, info); } else { varcondThread->wait(mutexThread); } bool interrupted = (thread->interruptFlag != 0); mutexThread->unlock(); - mvm::LockRecursive::my_lock_all(l->lock, recur); + l->lock->lockAll(recur); if (interrupted || timeout) { l->varcond->remove(thread); Modified: vmkit/trunk/lib/N3/VMCore/VMObject.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/VMObject.h?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/VMObject.h (original) +++ vmkit/trunk/lib/N3/VMCore/VMObject.h Sat Nov 8 05:48:04 2008 @@ -48,7 +48,7 @@ class LockObj : public mvm::Object { public: static VirtualTable* VT; - mvm::Lock *lock; + mvm::LockRecursive *lock; VMCond* varcond; virtual void print(mvm::PrintBuffer* buf) const; Modified: vmkit/trunk/lib/N3/VMCore/VMThread.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/VMThread.cpp?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/VMThread.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/VMThread.cpp Sat Nov 8 05:48:04 2008 @@ -11,7 +11,6 @@ #include "mvm/JIT.h" #include "mvm/PrintBuffer.h" -#include "mvm/Threads/Key.h" #include "mvm/Threads/Locks.h" #include "mvm/Threads/Thread.h" @@ -42,18 +41,14 @@ perFunctionPasses = 0; } -VMThread* VMThread::get() { - return (VMThread*)mvm::Thread::get(); -} - extern void AddStandardCompilePasses(llvm::FunctionPassManager*); VMThread* VMThread::allocate(VMObject* thread, VirtualMachine* vm) { - VMThread* key = gc_new(VMThread)(); + VMThread* key = new VMThread(); key->vmThread = thread; key->vm = vm; - key->lock = mvm::Lock::allocNormal(); - key->varcond = mvm::Cond::allocCond(); + key->lock = new mvm::LockNormal(); + key->varcond = new mvm::Cond(); key->interruptFlag = 0; key->state = StateRunning; key->self = mvm::Thread::self(); Modified: vmkit/trunk/lib/N3/VMCore/VMThread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/VMThread.h?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/VMThread.h (original) +++ vmkit/trunk/lib/N3/VMCore/VMThread.h Sat Nov 8 05:48:04 2008 @@ -16,7 +16,6 @@ #include "mvm/Object.h" #include "mvm/Threads/Cond.h" -#include "mvm/Threads/Key.h" #include "mvm/Threads/Locks.h" #include "mvm/Threads/Thread.h" @@ -50,7 +49,12 @@ ~VMThread(); VMThread(); - static VMThread* get(); + // Temporary solution until N3 can cleanly bootstrap itself and + // implement threads. + static VMThread* TheThread; + static VMThread* get() { + return TheThread; + } static VMThread* allocate(VMObject* thread, VirtualMachine* vm); static VMObject* currentThread(); Modified: vmkit/trunk/lib/N3/VMCore/VirtualMachine.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/VirtualMachine.cpp?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/VirtualMachine.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/VirtualMachine.cpp Sat Nov 8 05:48:04 2008 @@ -78,8 +78,8 @@ ThreadSystem* ThreadSystem::allocateThreadSystem() { ThreadSystem* res = gc_new(ThreadSystem)(); res->nonDaemonThreads = 1; - res->nonDaemonLock = mvm::Lock::allocNormal(); - res->nonDaemonVar = mvm::Cond::allocCond(); + res->nonDaemonLock = new mvm::LockNormal(); + res->nonDaemonVar = new mvm::Cond(); return res; } Modified: vmkit/trunk/lib/N3/VMCore/VirtualMachine.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/VirtualMachine.h?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/VirtualMachine.h (original) +++ vmkit/trunk/lib/N3/VMCore/VirtualMachine.h Sat Nov 8 05:48:04 2008 @@ -128,6 +128,9 @@ virtual void runApplication(int argc, char** argv); virtual void compile(const char* name); + virtual void waitForExit() { + // Currently unimplemented. + } }; Modified: vmkit/trunk/lib/N3/VMCore/VirtualTables.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/VirtualTables.cpp?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/VirtualTables.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/VirtualTables.cpp Sat Nov 8 05:48:04 2008 @@ -209,7 +209,10 @@ } void VMCond::TRACER { - TRACE_VECTOR(VMThread*, threads, std::allocator); + for (std::vector >::iterator i = threads.begin(), e = threads.end(); + i!= e; ++i) { + (*i)->CALL_TRACER; + } } void LockObj::TRACER { @@ -234,8 +237,12 @@ threadSystem->MARK_AND_TRACE; hashUTF8->MARK_AND_TRACE; functions->MARK_AND_TRACE; - //protectModule->MARK_AND_TRACE; - bootstrapThread->MARK_AND_TRACE; + if (bootstrapThread) { + bootstrapThread->CALL_TRACER; + for (VMThread* th = (VMThread*)bootstrapThread->next(); + th != bootstrapThread; th = (VMThread*)th->next()) + th->CALL_TRACER; + } } void Param::TRACER { Modified: vmkit/trunk/tools/jnjvm/Main.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/jnjvm/Main.cpp?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/tools/jnjvm/Main.cpp (original) +++ vmkit/trunk/tools/jnjvm/Main.cpp Sat Nov 8 05:48:04 2008 @@ -19,16 +19,15 @@ int main(int argc, char **argv, char **envp) { llvm::llvm_shutdown_obj X; - int base; MvmModule::initialise(); Object::initialise(); - Thread::initialise(); - Collector::initialise(0, &base); + Collector::initialise(0); CompilationUnit* CU = VirtualMachine::initialiseJVM(); VirtualMachine* vm = VirtualMachine::createJVM(CU); vm->runApplication(argc, argv); + vm->waitForExit(); return 0; } Modified: vmkit/trunk/tools/n3-mono/Main.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/n3-mono/Main.cpp?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/tools/n3-mono/Main.cpp (original) +++ vmkit/trunk/tools/n3-mono/Main.cpp Sat Nov 8 05:48:04 2008 @@ -19,16 +19,15 @@ int main(int argc, char **argv, char **envp) { llvm::llvm_shutdown_obj X; - int base; MvmModule::initialise(); Object::initialise(); - Thread::initialise(); - Collector::initialise(0, &base); + Collector::initialise(0); VirtualMachine::initialiseCLIVM(); VirtualMachine* vm = VirtualMachine::createCLIVM(); vm->runApplication(argc, argv); + vm->waitForExit(); return 0; } Modified: vmkit/trunk/tools/n3-pnetlib/Main.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/n3-pnetlib/Main.cpp?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/tools/n3-pnetlib/Main.cpp (original) +++ vmkit/trunk/tools/n3-pnetlib/Main.cpp Sat Nov 8 05:48:04 2008 @@ -19,16 +19,15 @@ int main(int argc, char **argv, char **envp) { llvm::llvm_shutdown_obj X; - int base; MvmModule::initialise(); Object::initialise(); - Thread::initialise(); - Collector::initialise(0, &base); + Collector::initialise(0); VirtualMachine::initialiseCLIVM(); VirtualMachine* vm = VirtualMachine::createCLIVM(); vm->runApplication(argc, argv); + vm->waitForExit(); return 0; } Modified: vmkit/trunk/tools/vmjc/vmjc.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/vmjc/vmjc.cpp?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/tools/vmjc/vmjc.cpp (original) +++ vmkit/trunk/tools/vmjc/vmjc.cpp Sat Nov 8 05:48:04 2008 @@ -54,7 +54,6 @@ int main(int argc, char **argv) { llvm_shutdown_obj X; // Call llvm_shutdown() on exit. - int base; try { cl::ParseCommandLineOptions(argc, argv, "vmkit .class -> .ll compiler\n"); sys::PrintStackTraceOnErrorSignal(); @@ -70,14 +69,13 @@ mvm::MvmModule::initialise(); mvm::Object::initialise(); - mvm::Thread::initialise(); - Collector::initialise(0, &base); + Collector::initialise(0); Collector::enable(0); mvm::CompilationUnit* CU = mvm::VirtualMachine::initialiseJVM(true); mvm::VirtualMachine* vm = mvm::VirtualMachine::createJVM(CU); vm->compile(InputFilename.c_str()); - + vm->waitForExit(); if (DontPrint) { // Just use stdout. We won't actually print anything on it. Modified: vmkit/trunk/tools/vmkit/Launcher.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/vmkit/Launcher.cpp?rev=58903&r1=58902&r2=58903&view=diff ============================================================================== --- vmkit/trunk/tools/vmkit/Launcher.cpp (original) +++ vmkit/trunk/tools/vmkit/Launcher.cpp Sat Nov 8 05:48:04 2008 @@ -47,7 +47,6 @@ int main(int argc, char** argv) { llvm::llvm_shutdown_obj X; - int base; int pos = found(argv, argc, "-java"); if (pos) { @@ -63,8 +62,7 @@ mvm::MvmModule::initialise(Fast); mvm::Object::initialise(); - mvm::Thread::initialise(); - Collector::initialise(0, &base); + Collector::initialise(0); Collector::enable(0); if (VMToRun == RunJava) { From nicolas.geoffray at lip6.fr Sat Nov 8 08:17:05 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 08 Nov 2008 16:17:05 -0000 Subject: [vmkit-commits] [vmkit] r58910 - in /vmkit/trunk: include/mvm/JIT.h lib/JnJVM/LLVMRuntime/runtime-default.ll lib/JnJVM/VMCore/JavaJIT.cpp lib/JnJVM/VMCore/JnjvmModule.cpp lib/JnJVM/VMCore/JnjvmModule.h lib/Mvm/Runtime/JIT.cpp lib/Mvm/Runtime/LLVMRuntime.ll Message-ID: <200811081617.mA8GH7j9016781@zion.cs.uiuc.edu> Author: geoffray Date: Sat Nov 8 10:16:57 2008 New Revision: 58910 URL: http://llvm.org/viewvc/llvm-project?rev=58910&view=rev Log: GetThreadID is now inlined with frameaddress. Modified: vmkit/trunk/include/mvm/JIT.h vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.h vmkit/trunk/lib/Mvm/Runtime/JIT.cpp vmkit/trunk/lib/Mvm/Runtime/LLVMRuntime.ll Modified: vmkit/trunk/include/mvm/JIT.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/JIT.h?rev=58910&r1=58909&r2=58910&view=diff ============================================================================== --- vmkit/trunk/include/mvm/JIT.h (original) +++ vmkit/trunk/include/mvm/JIT.h Sat Nov 8 10:16:57 2008 @@ -106,6 +106,7 @@ llvm::Function* llvm_memcpy_i32; llvm::Function* llvm_memset_i32; + llvm::Function* llvm_frameaddress; llvm::Function* llvm_atomic_lcs_i8; llvm::Function* llvm_atomic_lcs_i16; llvm::Function* llvm_atomic_lcs_i32; @@ -158,6 +159,7 @@ static llvm::ConstantFP* constantDoubleMinusZero; static llvm::Constant* constantPtrNull; static llvm::ConstantInt* constantPtrSize; + static llvm::ConstantInt* constantThreadIDMask; static const llvm::PointerType* ptrType; static const llvm::PointerType* ptr32Type; static const llvm::PointerType* ptrPtrType; Modified: vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll?rev=58910&r1=58909&r2=58910&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll (original) +++ vmkit/trunk/lib/JnJVM/LLVMRuntime/runtime-default.ll Sat Nov 8 10:16:57 2008 @@ -155,10 +155,6 @@ ;;; class. declare %JavaObject* @getClassDelegatee(%JavaClass*) readnone -;;; getThreadID - Returns the thread ID of the current thread. Used for thin -;;; locks. -declare i32 @getThreadID() readnone - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Exception methods ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -169,14 +165,14 @@ declare void @negativeArraySizeException(i32) declare void @outOfMemoryError(i32) -declare void @JavaThreadThrowException(%JavaObject*) -declare void @JavaThreadClearException() -declare i8* @JavaThreadGetException() +declare void @JavaThreadThrowException(%JavaObject*) +declare void @JavaThreadClearException() +declare i8* @JavaThreadGetException() declare %JavaObject* @JavaThreadGetJavaException() -declare i1 @JavaThreadCompareException(%JavaClass*) +declare i1 @JavaThreadCompareException(%JavaClass*) declare void @jniProceedPendingException() -declare i8* @getSJLJBuffer() +declare i8* @getSJLJBuffer() ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Debugging methods ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp?rev=58910&r1=58909&r2=58910&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp Sat Nov 8 10:16:57 2008 @@ -326,8 +326,11 @@ gep.push_back(module->JavaObjectLockOffsetConstant); Value* lockPtr = GetElementPtrInst::Create(obj, gep.begin(), gep.end(), "", currentBlock); - Value* threadId = CallInst::Create(module->GetThreadIDFunction, "", - currentBlock); + Value* threadId = CallInst::Create(module->llvm_frameaddress, + module->constantZero, "", currentBlock); + threadId = new PtrToIntInst(threadId, Type::Int32Ty, "", currentBlock); + threadId = BinaryOperator::CreateAnd(threadId, module->constantThreadIDMask, + "", currentBlock); std::vector atomicArgs; atomicArgs.push_back(lockPtr); atomicArgs.push_back(module->constantZero); @@ -411,8 +414,11 @@ Value* lockPtr = GetElementPtrInst::Create(obj, gep.begin(), gep.end(), "", currentBlock); Value* lock = new LoadInst(lockPtr, "", currentBlock); - Value* threadId = CallInst::Create(module->GetThreadIDFunction, "", - currentBlock); + Value* threadId = CallInst::Create(module->llvm_frameaddress, + module->constantZero, "", currentBlock); + threadId = new PtrToIntInst(threadId, Type::Int32Ty, "", currentBlock); + threadId = BinaryOperator::CreateAnd(threadId, module->constantThreadIDMask, + "", currentBlock); Value* cmp = new ICmpInst(ICmpInst::ICMP_EQ, lock, threadId, "", currentBlock); Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp?rev=58910&r1=58909&r2=58910&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp Sat Nov 8 10:16:57 2008 @@ -1109,7 +1109,6 @@ GetCollectorFunction = module->getFunction("getCollector"); #endif - GetThreadIDFunction = module->getFunction("getThreadID"); GetLockFunction = module->getFunction("getLock"); } Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.h?rev=58910&r1=58909&r2=58910&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.h Sat Nov 8 10:16:57 2008 @@ -321,7 +321,6 @@ llvm::Function* GetObjectSizeFromClassFunction; llvm::Function* GetLockFunction; - llvm::Function* GetThreadIDFunction; llvm::Function* OverflowThinLockFunction; static llvm::ConstantInt* OffsetObjectSizeInClassConstant; Modified: vmkit/trunk/lib/Mvm/Runtime/JIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/JIT.cpp?rev=58910&r1=58909&r2=58910&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Runtime/JIT.cpp (original) +++ vmkit/trunk/lib/Mvm/Runtime/JIT.cpp Sat Nov 8 10:16:57 2008 @@ -122,6 +122,7 @@ constantDoubleMinusInfinity = ConstantFP::get(Type::DoubleTy, MinDouble); constantDoubleMinusZero = ConstantFP::get(Type::DoubleTy, -0.0); constantFloatMinusZero = ConstantFP::get(Type::FloatTy, -0.0f); + constantThreadIDMask = ConstantInt::get(Type::Int32Ty, mvm::Thread::IDMask); constantPtrNull = Constant::getNullValue(ptrType); constantPtrSize = ConstantInt::get(Type::Int32Ty, sizeof(void*)); @@ -185,7 +186,8 @@ llvm_memcpy_i32 = module->getFunction("llvm.memcpy.i32"); llvm_memset_i32 = module->getFunction("llvm.memset.i32"); - + llvm_frameaddress = module->getFunction("llvm.frameaddress"); + llvm_atomic_lcs_i8 = module->getFunction("llvm.atomic.cmp.swap.i8.p0i8"); llvm_atomic_lcs_i16 = module->getFunction("llvm.atomic.cmp.swap.i16.p0i16"); llvm_atomic_lcs_i32 = module->getFunction("llvm.atomic.cmp.swap.i32.p0i32"); @@ -234,6 +236,7 @@ llvm::ConstantFP* MvmModule::constantDoubleMinusZero; llvm::Constant* MvmModule::constantPtrNull; llvm::ConstantInt* MvmModule::constantPtrSize; +llvm::ConstantInt* MvmModule::constantThreadIDMask; const llvm::PointerType* MvmModule::ptrType; const llvm::PointerType* MvmModule::ptr32Type; const llvm::PointerType* MvmModule::ptrPtrType; Modified: vmkit/trunk/lib/Mvm/Runtime/LLVMRuntime.ll URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/LLVMRuntime.ll?rev=58910&r1=58909&r2=58910&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Runtime/LLVMRuntime.ll (original) +++ vmkit/trunk/lib/Mvm/Runtime/LLVMRuntime.ll Sat Nov 8 10:16:57 2008 @@ -20,13 +20,13 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; declare void @_Unwind_Resume_or_Rethrow(i8*) -declare i8* @llvm.eh.exception() nounwind -declare i32 @llvm.eh.selector.i32(i8*, i8*, ...) nounwind -declare i64 @llvm.eh.selector.i64(i8*, i8*, ...) nounwind +declare i8* @llvm.eh.exception() nounwind +declare i32 @llvm.eh.selector.i32(i8*, i8*, ...) nounwind +declare i64 @llvm.eh.selector.i64(i8*, i8*, ...) nounwind declare void @__gxx_personality_v0() -declare i8* @__cxa_begin_catch(i8*) +declare i8* @__cxa_begin_catch(i8*) declare void @__cxa_end_catch() -declare i32 @setjmp(i8*) +declare i32 @setjmp(i8*) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Math ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -55,7 +55,7 @@ declare double @hypot(double, double) declare double @pow(double, double) declare double @atan2(double, double) -declare float @fabsf(float) +declare float @fabsf(float) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Memory ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -63,12 +63,13 @@ declare void @llvm.memcpy.i32(i8 *, i8 *, i32, i32) nounwind declare void @llvm.memset.i32(i8 *, i8, i32, i32) nounwind +declare i8* @llvm.frameaddress(i32) nounwind readnone ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Atomic ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -declare i8 @llvm.atomic.cmp.swap.i8.p0i8(i8*, i8, i8) nounwind +declare i8 @llvm.atomic.cmp.swap.i8.p0i8(i8*, i8, i8) nounwind declare i16 @llvm.atomic.cmp.swap.i16.p0i16(i16*, i16, i16) nounwind declare i32 @llvm.atomic.cmp.swap.i32.p0i32(i32*, i32, i32) nounwind declare i64 @llvm.atomic.cmp.swap.i64.p0i64(i64*, i64, i64) nounwind From nicolas.geoffray at lip6.fr Sat Nov 8 08:19:30 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 08 Nov 2008 16:19:30 -0000 Subject: [vmkit-commits] [vmkit] r58912 - /vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp Message-ID: <200811081619.mA8GJUpd016853@zion.cs.uiuc.edu> Author: geoffray Date: Sat Nov 8 10:19:29 2008 New Revision: 58912 URL: http://llvm.org/viewvc/llvm-project?rev=58912&view=rev Log: Remove getThreadID. Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp?rev=58912&r1=58911&r2=58912&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp Sat Nov 8 10:19:29 2008 @@ -425,10 +425,6 @@ return JavaThread::clearException(); } -extern "C" uint32 getThreadID() { - return JavaThread::get()->threadID; -} - extern "C" void overflowThinLock(JavaObject* obj) { obj->overflowThinlock(); } From nicolas.geoffray at lip6.fr Sat Nov 8 08:52:30 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 08 Nov 2008 16:52:30 -0000 Subject: [vmkit-commits] [vmkit] r58915 - in /vmkit/trunk/lib/JnJVM/VMCore: JavaClass.h JnjvmModule.cpp NativeUtil.cpp Message-ID: <200811081652.mA8GqVTx018085@zion.cs.uiuc.edu> Author: geoffray Date: Sat Nov 8 10:52:25 2008 New Revision: 58915 URL: http://llvm.org/viewvc/llvm-project?rev=58915&view=rev Log: Make JNI name creation of methods instance functions of JavaMethod. Use this name for static compilation. Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp vmkit/trunk/lib/JnJVM/VMCore/NativeUtil.cpp Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h?rev=58915&r1=58914&r2=58915&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Sat Nov 8 10:52:25 2008 @@ -801,6 +801,13 @@ /// printString - Output a string representation of the method. /// const char* printString() const; + + /// jniConsFromMeth - Construct the JNI name of this method. + /// + void jniConsFromMeth(char* buf) const; + void jniConsFromMeth2(char* buf) const; + void jniConsFromMeth3(char* buf) const; + //===----------------------------------------------------------------------===// // @@ -996,6 +1003,9 @@ return static_cast(JInfo); } + #define JNI_NAME_PRE "Java_" + #define JNI_NAME_PRE_LEN 5 + }; Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp?rev=58915&r1=58914&r2=58915&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp Sat Nov 8 10:52:25 2008 @@ -557,10 +557,28 @@ Function* LLVMMethodInfo::getMethod() { if (!methodFunction) { JnjvmClassLoader* JCL = methodDef->classDef->classLoader; - methodFunction = Function::Create(getFunctionType(), - GlobalValue::GhostLinkage, - methodDef->printString(), - JCL->TheModule); + JnjvmModule* Mod = JCL->getModule(); + if (Mod->isStaticCompiling()) { + const UTF8* jniConsClName = methodDef->classDef->name; + const UTF8* jniConsName = methodDef->name; + const UTF8* jniConsType = methodDef->type; + sint32 clen = jniConsClName->size; + sint32 mnlen = jniConsName->size; + sint32 mtlen = jniConsType->size; + + char* buf = + (char*)alloca(3 + JNI_NAME_PRE_LEN + mnlen + clen + (mtlen << 1)); + methodDef->jniConsFromMeth3(buf); + methodFunction = Function::Create(getFunctionType(), + GlobalValue::GhostLinkage, buf, Mod); + + } else { + + methodFunction = Function::Create(getFunctionType(), + GlobalValue::GhostLinkage, + "", Mod); + + } JCL->TheModuleProvider->addFunction(methodFunction, methodDef); } return methodFunction; Modified: vmkit/trunk/lib/JnJVM/VMCore/NativeUtil.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/NativeUtil.cpp?rev=58915&r1=58914&r2=58915&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/NativeUtil.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/NativeUtil.cpp Sat Nov 8 10:52:25 2008 @@ -7,9 +7,6 @@ // //===----------------------------------------------------------------------===// -#include -#include -#include #include "ClasspathReflect.h" #include "JavaArray.h" @@ -24,25 +21,25 @@ #include "NativeUtil.h" #include "Reader.h" +#include +#include + using namespace jnjvm; Jnjvm* NativeUtil::myVM(JNIEnv* env) { return JavaThread::get()->isolate; } -#define PRE "Java_" -#define PRE_LEN 5 - -static char* jniConsFromMeth(CommonClass* cl, JavaMethod* meth, char* buf) { - const UTF8* jniConsClName = cl->name; - const UTF8* jniConsName = meth->name; +void JavaMethod::jniConsFromMeth(char* buf) const { + const UTF8* jniConsClName = classDef->name; + const UTF8* jniConsName = name; sint32 clen = jniConsClName->size; sint32 mnlen = jniConsName->size; uint32 cur = 0; - char* ptr = &(buf[PRE_LEN]); + char* ptr = &(buf[JNI_NAME_PRE_LEN]); - memcpy(buf, PRE, PRE_LEN); + memcpy(buf, JNI_NAME_PRE, JNI_NAME_PRE_LEN); for (sint32 i =0; i < clen; ++i) { cur = jniConsClName->elements[i]; @@ -63,20 +60,19 @@ ptr[0] = 0; - return buf; } -static char* jniConsFromMeth2(CommonClass* cl, JavaMethod* meth, char* buf) { - const UTF8* jniConsClName = cl->name; - const UTF8* jniConsName = meth->name; +void JavaMethod::jniConsFromMeth2(char* buf) const { + const UTF8* jniConsClName = classDef->name; + const UTF8* jniConsName = name; sint32 clen = jniConsClName->size; sint32 mnlen = jniConsName->size; uint32 cur = 0; - char* ptr = &(buf[PRE_LEN]); + char* ptr = &(buf[JNI_NAME_PRE_LEN]); - memcpy(buf, PRE, PRE_LEN); + memcpy(buf, JNI_NAME_PRE, JNI_NAME_PRE_LEN); for (sint32 i =0; i < clen; ++i) { cur = jniConsClName->elements[i]; @@ -102,21 +98,20 @@ ptr[0] = 0; - return buf; } -static char* jniConsFromMeth3(CommonClass* cl, JavaMethod* meth, char* buf) { - const UTF8* jniConsClName = cl->name; - const UTF8* jniConsName = meth->name; - const UTF8* jniConsType = meth->type; +void JavaMethod::jniConsFromMeth3(char* buf) const { + const UTF8* jniConsClName = classDef->name; + const UTF8* jniConsName = name; + const UTF8* jniConsType = type; sint32 clen = jniConsClName->size; sint32 mnlen = jniConsName->size; uint32 cur = 0; - char* ptr = &(buf[PRE_LEN]); + char* ptr = &(buf[JNI_NAME_PRE_LEN]); - memcpy(buf, PRE, PRE_LEN); + memcpy(buf, JNI_NAME_PRE, JNI_NAME_PRE_LEN); for (sint32 i =0; i < clen; ++i) { cur = jniConsClName->elements[i]; @@ -167,7 +162,6 @@ ptr[0] = 0; - return buf; } @@ -179,23 +173,22 @@ sint32 mnlen = jniConsName->size; sint32 mtlen = jniConsType->size; - char* buf = (char*)alloca(3 + PRE_LEN + mnlen + clen + (mtlen << 1)); - jniConsFromMeth(cl, meth, buf); + char* buf = (char*)alloca(3 + JNI_NAME_PRE_LEN + mnlen + clen + (mtlen << 1)); + meth->jniConsFromMeth(buf); void* res = cl->classLoader->loadLib(buf, jnjvm); if (!res) { - buf = jniConsFromMeth2(cl, meth, buf); + meth->jniConsFromMeth2(buf); res = cl->classLoader->loadLib(buf, jnjvm); if (!res) { - buf = jniConsFromMeth3(cl, meth, buf); + meth->jniConsFromMeth3(buf); res = cl->classLoader->loadLib(buf, jnjvm); } } return res; } -#undef PRE_LEN - -UserCommonClass* NativeUtil::resolvedImplClass(Jnjvm* vm, jclass clazz, bool doClinit) { +UserCommonClass* NativeUtil::resolvedImplClass(Jnjvm* vm, jclass clazz, + bool doClinit) { UserCommonClass* cl = ((JavaObjectClass*)clazz)->getClass(); cl->resolveClass(); if (doClinit) cl->initialiseClass(vm); From nicolas.geoffray at lip6.fr Sat Nov 8 09:26:44 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 08 Nov 2008 17:26:44 -0000 Subject: [vmkit-commits] [vmkit] r58918 - in /vmkit/trunk/lib/JnJVM/VMCore: JavaClass.h JavaMetaJIT.cpp Jnjvm.cpp JnjvmModule.cpp Message-ID: <200811081726.mA8HQiYx019122@zion.cs.uiuc.edu> Author: geoffray Date: Sat Nov 8 11:26:44 2008 New Revision: 58918 URL: http://llvm.org/viewvc/llvm-project?rev=58918&view=rev Log: Java functions do not take a Jnjvm object as parameter anymore. Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h?rev=58918&r1=58917&r2=58918&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Sat Nov 8 11:26:44 2008 @@ -885,6 +885,9 @@ return static_cast(JInfo); } + #define JNI_NAME_PRE "Java_" + #define JNI_NAME_PRE_LEN 5 + }; /// JavaField - This class represents a Java field. @@ -1003,8 +1006,6 @@ return static_cast(JInfo); } - #define JNI_NAME_PRE "Java_" - #define JNI_NAME_PRE_LEN 5 }; Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp?rev=58918&r1=58917&r2=58918&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp Sat Nov 8 11:26:44 2008 @@ -106,7 +106,7 @@ void* _buf = (void*)buf; \ readArgs(buf, sign, ap); \ void* func = (((void***)obj)[0])[offset];\ - return ((FUNC_TYPE_VIRTUAL_BUF)sign->getVirtualCallBuf())(vm, cl->getConstantPool(), func, obj, _buf);\ + return ((FUNC_TYPE_VIRTUAL_BUF)sign->getVirtualCallBuf())(cl->getConstantPool(), func, obj, _buf);\ }\ \ TYPE JavaMethod::invoke##TYPE_NAME##SpecialAP(Jnjvm* vm, UserClass* cl, JavaObject* obj, va_list ap) {\ @@ -121,7 +121,7 @@ void* _buf = (void*)buf; \ readArgs(buf, sign, ap); \ void* func = this->compiledPtr();\ - return ((FUNC_TYPE_VIRTUAL_BUF)sign->getVirtualCallBuf())(vm, cl->getConstantPool(), func, obj, _buf);\ + return ((FUNC_TYPE_VIRTUAL_BUF)sign->getVirtualCallBuf())(cl->getConstantPool(), func, obj, _buf);\ }\ \ TYPE JavaMethod::invoke##TYPE_NAME##StaticAP(Jnjvm* vm, UserClass* cl, va_list ap) {\ @@ -135,7 +135,7 @@ void* _buf = (void*)buf; \ readArgs(buf, sign, ap); \ void* func = this->compiledPtr();\ - return ((FUNC_TYPE_STATIC_BUF)sign->getStaticCallBuf())(vm, cl->getConstantPool(), func, _buf);\ + return ((FUNC_TYPE_STATIC_BUF)sign->getStaticCallBuf())(cl->getConstantPool(), func, _buf);\ }\ \ TYPE JavaMethod::invoke##TYPE_NAME##VirtualBuf(Jnjvm* vm, UserClass* cl, JavaObject* obj, void* buf) {\ @@ -148,7 +148,7 @@ \ Signdef* sign = getSignature(); \ void* func = (((void***)obj)[0])[offset];\ - return ((FUNC_TYPE_VIRTUAL_BUF)sign->getVirtualCallBuf())(vm, cl->getConstantPool(), func, obj, buf);\ + return ((FUNC_TYPE_VIRTUAL_BUF)sign->getVirtualCallBuf())(cl->getConstantPool(), func, obj, buf);\ }\ \ TYPE JavaMethod::invoke##TYPE_NAME##SpecialBuf(Jnjvm* vm, UserClass* cl, JavaObject* obj, void* buf) {\ @@ -160,7 +160,7 @@ verifyNull(obj);\ void* func = this->compiledPtr();\ Signdef* sign = getSignature(); \ - return ((FUNC_TYPE_VIRTUAL_BUF)sign->getVirtualCallBuf())(vm, cl->getConstantPool(), func, obj, buf);\ + return ((FUNC_TYPE_VIRTUAL_BUF)sign->getVirtualCallBuf())(cl->getConstantPool(), func, obj, buf);\ }\ \ TYPE JavaMethod::invoke##TYPE_NAME##StaticBuf(Jnjvm* vm, UserClass* cl, void* buf) {\ @@ -171,7 +171,7 @@ \ void* func = this->compiledPtr();\ Signdef* sign = getSignature(); \ - return ((FUNC_TYPE_STATIC_BUF)sign->getStaticCallBuf())(vm, cl->getConstantPool(), func, buf);\ + return ((FUNC_TYPE_STATIC_BUF)sign->getStaticCallBuf())(cl->getConstantPool(), func, buf);\ }\ \ TYPE JavaMethod::invoke##TYPE_NAME##Virtual(Jnjvm* vm, UserClass* cl, JavaObject* obj, ...) { \ @@ -211,7 +211,7 @@ verifyNull(obj); \ void* func = (((void***)obj)[0])[offset];\ Signdef* sign = getSignature(); \ - return ((FUNC_TYPE_VIRTUAL_AP)sign->getVirtualCallAP())(vm, cl->getConstantPool(), func, obj, ap);\ + return ((FUNC_TYPE_VIRTUAL_AP)sign->getVirtualCallAP())(cl->getConstantPool(), func, obj, ap);\ }\ \ TYPE JavaMethod::invoke##TYPE_NAME##SpecialAP(Jnjvm* vm, UserClass* cl, JavaObject* obj, va_list ap) {\ @@ -223,7 +223,7 @@ verifyNull(obj);\ void* func = this->compiledPtr();\ Signdef* sign = getSignature(); \ - return ((FUNC_TYPE_VIRTUAL_AP)sign->getVirtualCallAP())(vm, cl->getConstantPool(), func, obj, ap);\ + return ((FUNC_TYPE_VIRTUAL_AP)sign->getVirtualCallAP())(cl->getConstantPool(), func, obj, ap);\ }\ \ TYPE JavaMethod::invoke##TYPE_NAME##StaticAP(Jnjvm* vm, UserClass* cl, va_list ap) {\ @@ -234,7 +234,7 @@ \ void* func = this->compiledPtr();\ Signdef* sign = getSignature(); \ - return ((FUNC_TYPE_STATIC_AP)sign->getStaticCallAP())(vm, cl->getConstantPool(), func, ap);\ + return ((FUNC_TYPE_STATIC_AP)sign->getStaticCallAP())(cl->getConstantPool(), func, ap);\ }\ \ TYPE JavaMethod::invoke##TYPE_NAME##VirtualBuf(Jnjvm* vm, UserClass* cl, JavaObject* obj, void* buf) {\ @@ -246,7 +246,7 @@ verifyNull(obj);\ void* func = (((void***)obj)[0])[offset];\ Signdef* sign = getSignature(); \ - return ((FUNC_TYPE_VIRTUAL_BUF)sign->getVirtualCallBuf())(vm, cl->getConstantPool(), func, obj, buf);\ + return ((FUNC_TYPE_VIRTUAL_BUF)sign->getVirtualCallBuf())(cl->getConstantPool(), func, obj, buf);\ }\ \ TYPE JavaMethod::invoke##TYPE_NAME##SpecialBuf(Jnjvm* vm, UserClass* cl, JavaObject* obj, void* buf) {\ @@ -258,7 +258,7 @@ verifyNull(obj);\ void* func = this->compiledPtr();\ Signdef* sign = getSignature(); \ - return ((FUNC_TYPE_VIRTUAL_BUF)sign->getVirtualCallBuf())(vm, cl->getConstantPool(), func, obj, buf);\ + return ((FUNC_TYPE_VIRTUAL_BUF)sign->getVirtualCallBuf())(cl->getConstantPool(), func, obj, buf);\ }\ \ TYPE JavaMethod::invoke##TYPE_NAME##StaticBuf(Jnjvm* vm, UserClass* cl, void* buf) {\ @@ -269,7 +269,7 @@ \ void* func = this->compiledPtr();\ Signdef* sign = getSignature(); \ - return ((FUNC_TYPE_STATIC_BUF)sign->getStaticCallBuf())(vm, cl->getConstantPool(), func, buf);\ + return ((FUNC_TYPE_STATIC_BUF)sign->getStaticCallBuf())(cl->getConstantPool(), func, buf);\ }\ \ TYPE JavaMethod::invoke##TYPE_NAME##Virtual(Jnjvm* vm, UserClass* cl, JavaObject* obj, ...) { \ @@ -298,29 +298,29 @@ #endif -typedef uint32 (*uint32_virtual_ap)(Jnjvm*, UserConstantPool*, void*, JavaObject*, va_list); -typedef sint64 (*sint64_virtual_ap)(Jnjvm*, UserConstantPool*, void*, JavaObject*, va_list); -typedef float (*float_virtual_ap)(Jnjvm*, UserConstantPool*, void*, JavaObject*, va_list); -typedef double (*double_virtual_ap)(Jnjvm*, UserConstantPool*, void*, JavaObject*, va_list); -typedef JavaObject* (*object_virtual_ap)(Jnjvm*, UserConstantPool*, void*, JavaObject*, va_list); - -typedef uint32 (*uint32_static_ap)(Jnjvm*, UserConstantPool*, void*, va_list); -typedef sint64 (*sint64_static_ap)(Jnjvm*, UserConstantPool*, void*, va_list); -typedef float (*float_static_ap)(Jnjvm*, UserConstantPool*, void*, va_list); -typedef double (*double_static_ap)(Jnjvm*, UserConstantPool*, void*, va_list); -typedef JavaObject* (*object_static_ap)(Jnjvm*, UserConstantPool*, void*, va_list); - -typedef uint32 (*uint32_virtual_buf)(Jnjvm*, UserConstantPool*, void*, JavaObject*, void*); -typedef sint64 (*sint64_virtual_buf)(Jnjvm*, UserConstantPool*, void*, JavaObject*, void*); -typedef float (*float_virtual_buf)(Jnjvm*, UserConstantPool*, void*, JavaObject*, void*); -typedef double (*double_virtual_buf)(Jnjvm*, UserConstantPool*, void*, JavaObject*, void*); -typedef JavaObject* (*object_virtual_buf)(Jnjvm*, UserConstantPool*, void*, JavaObject*, void*); - -typedef uint32 (*uint32_static_buf)(Jnjvm*, UserConstantPool*, void*, void*); -typedef sint64 (*sint64_static_buf)(Jnjvm*, UserConstantPool*, void*, void*); -typedef float (*float_static_buf)(Jnjvm*, UserConstantPool*, void*, void*); -typedef double (*double_static_buf)(Jnjvm*, UserConstantPool*, void*, void*); -typedef JavaObject* (*object_static_buf)(Jnjvm*, UserConstantPool*, void*, void*); +typedef uint32 (*uint32_virtual_ap)(UserConstantPool*, void*, JavaObject*, va_list); +typedef sint64 (*sint64_virtual_ap)(UserConstantPool*, void*, JavaObject*, va_list); +typedef float (*float_virtual_ap)(UserConstantPool*, void*, JavaObject*, va_list); +typedef double (*double_virtual_ap)(UserConstantPool*, void*, JavaObject*, va_list); +typedef JavaObject* (*object_virtual_ap)(UserConstantPool*, void*, JavaObject*, va_list); + +typedef uint32 (*uint32_static_ap)(UserConstantPool*, void*, va_list); +typedef sint64 (*sint64_static_ap)(UserConstantPool*, void*, va_list); +typedef float (*float_static_ap)(UserConstantPool*, void*, va_list); +typedef double (*double_static_ap)(UserConstantPool*, void*, va_list); +typedef JavaObject* (*object_static_ap)(UserConstantPool*, void*, va_list); + +typedef uint32 (*uint32_virtual_buf)(UserConstantPool*, void*, JavaObject*, void*); +typedef sint64 (*sint64_virtual_buf)(UserConstantPool*, void*, JavaObject*, void*); +typedef float (*float_virtual_buf)(UserConstantPool*, void*, JavaObject*, void*); +typedef double (*double_virtual_buf)(UserConstantPool*, void*, JavaObject*, void*); +typedef JavaObject* (*object_virtual_buf)(UserConstantPool*, void*, JavaObject*, void*); + +typedef uint32 (*uint32_static_buf)(UserConstantPool*, void*, void*); +typedef sint64 (*sint64_static_buf)(UserConstantPool*, void*, void*); +typedef float (*float_static_buf)(UserConstantPool*, void*, void*); +typedef double (*double_static_buf)(UserConstantPool*, void*, void*); +typedef JavaObject* (*object_static_buf)(UserConstantPool*, void*, void*); INVOKE(uint32, Int, uint32_virtual_ap, uint32_static_ap, uint32_virtual_buf, uint32_static_buf) INVOKE(sint64, Long, sint64_virtual_ap, sint64_static_ap, sint64_virtual_buf, sint64_static_buf) Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp?rev=58918&r1=58917&r2=58918&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Sat Nov 8 11:26:44 2008 @@ -44,7 +44,7 @@ const char* Jnjvm::envSeparator = ":"; const unsigned int Jnjvm::Magic = 0xcafebabe; -typedef void (*clinit_t)(Jnjvm* vm, UserConstantPool*); +typedef void (*clinit_t)(UserConstantPool*); /// initialiseClass - Java class initialisation. Java specification §2.17.5. @@ -185,7 +185,7 @@ if (meth) { try{ clinit_t pred = (clinit_t)(intptr_t)meth->compiledPtr(); - pred(vm, cl->getConstantPool()); + pred(cl->getConstantPool()); } catch(...) { exc = JavaThread::getJavaException(); assert(exc && "no exception?"); @@ -239,7 +239,8 @@ } } -void Jnjvm::errorWithExcp(UserClass* cl, JavaMethod* init, const JavaObject* excp) { +void Jnjvm::errorWithExcp(UserClass* cl, JavaMethod* init, + const JavaObject* excp) { JavaObject* obj = cl->doNew(this); init->invokeIntSpecial(this, cl, obj, excp); JavaThread::throwException(obj); @@ -505,7 +506,8 @@ ArrayUInt8* res = (ArrayUInt8*)array->doNew(file->ucsize, vm); int ok = archive.readFile(res, file); if (ok) { - char* mainClass = findInformation(vm, res, MAIN_CLASS, LENGTH_MAIN_CLASS); + char* mainClass = findInformation(vm, res, MAIN_CLASS, + LENGTH_MAIN_CLASS); if (mainClass) { className = mainClass; } else { @@ -572,7 +574,7 @@ "-agentpath:[=]\n" " load native agent library by full pathname\n" "-javaagent:[=]\n" - " load Java programming language agent, see java.lang.instrument\n"); + " load Java programming language agent, see java.lang.instrument\n"); } void ClArgumentsInfo::readArgs(Jnjvm* vm) { @@ -855,7 +857,7 @@ #endif ClArgumentsInfo& info = vm->argumentsInfo; -#if 0 + if (info.agents.size()) { assert(0 && "implement me"); JavaObject* instrumenter = 0;//createInstrumenter(); @@ -866,7 +868,6 @@ vm->executePremain(i->first, args, instrumenter); } } -#endif UserClassArray* array = vm->bootstrapLoader->upcalls->ArrayOfString; ArrayObject* args = (ArrayObject*)array->doNew(info.argc - 2, vm); Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp?rev=58918&r1=58917&r2=58918&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp Sat Nov 8 11:26:44 2008 @@ -635,7 +635,6 @@ } #if defined(ISOLATE_SHARING) - llvmArgs.push_back(JnjvmModule::JnjvmType); // vm llvmArgs.push_back(JnjvmModule::ConstantPoolType); // cached constant pool #endif @@ -659,7 +658,6 @@ } #if defined(ISOLATE_SHARING) - llvmArgs.push_back(JnjvmModule::JnjvmType); // vm llvmArgs.push_back(JnjvmModule::ConstantPoolType); // cached constant pool #endif @@ -686,7 +684,6 @@ } #if defined(ISOLATE_SHARING) - llvmArgs.push_back(JnjvmModule::JnjvmType); // vm llvmArgs.push_back(JnjvmModule::ConstantPoolType); // cached constant pool #endif @@ -712,10 +709,6 @@ Function::arg_iterator i = res->arg_begin(); Value *obj, *ptr, *func; #if defined(ISOLATE_SHARING) - Value* vm = i; -#endif - ++i; -#if defined(ISOLATE_SHARING) Value* ctp = i; #endif ++i; @@ -745,7 +738,6 @@ } #if defined(ISOLATE_SHARING) - Args.push_back(vm); Args.push_back(ctp); #endif @@ -773,10 +765,6 @@ Function::arg_iterator i = res->arg_begin(); Value *obj, *ap, *func; #if defined(ISOLATE_SHARING) - Value* vm = i; -#endif - ++i; -#if defined(ISOLATE_SHARING) Value* ctp = i; #endif ++i; @@ -796,7 +784,6 @@ } #if defined(ISOLATE_SHARING) - Args.push_back(vm); Args.push_back(ctp); #endif @@ -837,7 +824,6 @@ // Lock here because we are called by arbitrary code llvm::MutexGuard locked(mvm::MvmModule::executionEngine->lock); std::vector Args2; - Args2.push_back(JnjvmModule::JnjvmType); // vm Args2.push_back(JnjvmModule::ConstantPoolType); // ctp Args2.push_back(getVirtualPtrType()); Args2.push_back(JnjvmModule::JavaObjectType); @@ -853,7 +839,6 @@ // Lock here because we are called by arbitrary code llvm::MutexGuard locked(mvm::MvmModule::executionEngine->lock); std::vector Args; - Args.push_back(JnjvmModule::JnjvmType); // vm Args.push_back(JnjvmModule::ConstantPoolType); // ctp Args.push_back(getStaticPtrType()); Args.push_back(PointerType::getUnqual(Type::Int32Ty)); From nicolas.geoffray at lip6.fr Sat Nov 8 09:44:50 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 08 Nov 2008 17:44:50 -0000 Subject: [vmkit-commits] [vmkit] r58919 - in /vmkit/trunk: include/mvm/Threads/Locks.h include/mvm/Threads/Thread.h lib/JnJVM/Classpath/ClasspathVMThrowable.cpp lib/JnJVM/VMCore/JavaRuntimeJIT.cpp lib/Mvm/CommonThread/ctlock.cpp lib/Mvm/CommonThread/ctthread.cpp lib/N3/VMCore/VMThread.cpp lib/N3/VMCore/VMThread.h Message-ID: <200811081744.mA8HioFg019708@zion.cs.uiuc.edu> Author: geoffray Date: Sat Nov 8 11:44:49 2008 New Revision: 58919 URL: http://llvm.org/viewvc/llvm-project?rev=58919&view=rev Log: Remove all uses of pthread_self and use mvm::Thread::get instead. Modified: vmkit/trunk/include/mvm/Threads/Locks.h vmkit/trunk/include/mvm/Threads/Thread.h vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp vmkit/trunk/lib/Mvm/CommonThread/ctlock.cpp vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp vmkit/trunk/lib/N3/VMCore/VMThread.cpp vmkit/trunk/lib/N3/VMCore/VMThread.h Modified: vmkit/trunk/include/mvm/Threads/Locks.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Threads/Locks.h?rev=58919&r1=58918&r2=58919&view=diff ============================================================================== --- vmkit/trunk/include/mvm/Threads/Locks.h (original) +++ vmkit/trunk/include/mvm/Threads/Locks.h Sat Nov 8 11:44:49 2008 @@ -17,11 +17,12 @@ class Cond; class LockNormal; class LockRecursive; +class Thread; class Lock { friend class Cond; protected: - int owner; + mvm::Thread* owner; pthread_mutex_t internalLock; public: @@ -33,7 +34,7 @@ virtual void unlock() = 0; bool selfOwner(); - int getOwner(); + mvm::Thread* getOwner(); }; Modified: vmkit/trunk/include/mvm/Threads/Thread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Threads/Thread.h?rev=58919&r1=58918&r2=58919&view=diff ============================================================================== --- vmkit/trunk/include/mvm/Threads/Thread.h (original) +++ vmkit/trunk/include/mvm/Threads/Thread.h Sat Nov 8 11:44:49 2008 @@ -69,11 +69,6 @@ /// static void yield(unsigned int* n); - /// self - The thread id of the current thread, which is specific to the - /// underlying implementation. - /// - static int self(void); - /// kill - Kill the thread with the given pid by sending it a signal. /// static int kill(int tid, int signo); Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.cpp?rev=58919&r1=58918&r2=58919&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.cpp (original) +++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThrowable.cpp Sat Nov 8 11:44:49 2008 @@ -71,7 +71,8 @@ JavaObject* res = newS->doNew(vm); vm->upcalls->initStackTraceElement->invokeIntSpecial(vm, newS, res, sourceName, - (uint32)ip, className, + 0, // source line + className, methodName, native); return res; } Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp?rev=58919&r1=58918&r2=58919&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp Sat Nov 8 11:44:49 2008 @@ -253,17 +253,17 @@ extern "C" void printMethodStart(JavaMethod* meth) { - printf("[%d] executing %s\n", mvm::Thread::self(), meth->printString()); + printf("[%d] executing %s\n", mvm::Thread::get(), meth->printString()); fflush(stdout); } extern "C" void printMethodEnd(JavaMethod* meth) { - printf("[%d] return from %s\n", mvm::Thread::self(), meth->printString()); + printf("[%d] return from %s\n", mvm::Thread::get(), meth->printString()); fflush(stdout); } extern "C" void printExecution(char* opcode, uint32 index, JavaMethod* meth) { - printf("[%d] executing %s %s at %d\n", mvm::Thread::self(), meth->printString(), + printf("[%d] executing %s %s at %d\n", mvm::Thread::get(), meth->printString(), opcode, index); fflush(stdout); } Modified: vmkit/trunk/lib/Mvm/CommonThread/ctlock.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommonThread/ctlock.cpp?rev=58919&r1=58918&r2=58919&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/CommonThread/ctlock.cpp (original) +++ vmkit/trunk/lib/Mvm/CommonThread/ctlock.cpp Sat Nov 8 11:44:49 2008 @@ -51,16 +51,16 @@ } bool Lock::selfOwner() { - return owner == Thread::self(); + return owner == mvm::Thread::get(); } -int Lock::getOwner() { +mvm::Thread* Lock::getOwner() { return owner; } void LockNormal::lock() { pthread_mutex_lock((pthread_mutex_t*)&internalLock); - owner = (int)pthread_self(); + owner = mvm::Thread::get(); } void LockNormal::unlock() { @@ -70,7 +70,7 @@ void LockRecursive::lock() { pthread_mutex_lock((pthread_mutex_t*)&internalLock); - if (!owner) owner = (int)pthread_self(); + if (!owner) owner = mvm::Thread::get(); ++n; } Modified: vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp?rev=58919&r1=58918&r2=58919&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp (original) +++ vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp Sat Nov 8 11:44:49 2008 @@ -31,10 +31,6 @@ } } -int Thread::self() { - return (int)pthread_self(); -} - int Thread::kill(int tid, int signo) { return pthread_kill((pthread_t)tid, signo); } @@ -135,7 +131,6 @@ /// given routine of th. /// void Thread::internalThreadStart(mvm::Thread* th) { - th->internalThreadID = (void*)pthread_self(); th->threadID = (int)th & mvm::Thread::IDMask; th->baseSP = &th; @@ -163,11 +158,10 @@ pthread_attr_t attributs; pthread_attr_init(&attributs); pthread_attr_setstack(&attributs, this, STACK_SIZE); - pthread_t tid; routine = fct; - int res = pthread_create(&tid, &attributs, + int res = pthread_create((pthread_t*)(void*)(&internalThreadID), &attributs, (void* (*)(void *))internalThreadStart, this); - pthread_detach(*(pthread_t *)tid); + pthread_detach((pthread_t)internalThreadID); pthread_attr_destroy(&attributs); return res; } Modified: vmkit/trunk/lib/N3/VMCore/VMThread.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/VMThread.cpp?rev=58919&r1=58918&r2=58919&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/VMThread.cpp (original) +++ vmkit/trunk/lib/N3/VMCore/VMThread.cpp Sat Nov 8 11:44:49 2008 @@ -51,7 +51,6 @@ key->varcond = new mvm::Cond(); key->interruptFlag = 0; key->state = StateRunning; - key->self = mvm::Thread::self(); key->pendingException = 0; key->perFunctionPasses = new llvm::FunctionPassManager(vm->TheModuleProvider); key->perFunctionPasses->add(new llvm::TargetData(vm->module)); Modified: vmkit/trunk/lib/N3/VMCore/VMThread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/VMThread.h?rev=58919&r1=58918&r2=58919&view=diff ============================================================================== --- vmkit/trunk/lib/N3/VMCore/VMThread.h (original) +++ vmkit/trunk/lib/N3/VMCore/VMThread.h Sat Nov 8 11:44:49 2008 @@ -36,7 +36,6 @@ mvm::Cond* varcond; VMObject* pendingException; void* internalPendingException; - unsigned int self; unsigned int interruptFlag; unsigned int state; From nicolas.geoffray at lip6.fr Sun Nov 9 09:03:46 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 09 Nov 2008 17:03:46 -0000 Subject: [vmkit-commits] [vmkit] r58936 - /vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp Message-ID: <200811091703.mA9H3kIG004370@zion.cs.uiuc.edu> Author: geoffray Date: Sun Nov 9 11:03:44 2008 New Revision: 58936 URL: http://llvm.org/viewvc/llvm-project?rev=58936&view=rev Log: Typo. Modified: vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp Modified: vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp?rev=58936&r1=58935&r2=58936&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp (original) +++ vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp Sun Nov 9 11:03:44 2008 @@ -75,9 +75,9 @@ while (!baseAddr && ptr != 0xF0000000) { ptr = ptr + 0x10000000; #if defined (__MACH__) - uint32 flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED; -#else uint32 flags = MAP_PRIVATE | MAP_ANON | MAP_FIXED; +#else + uint32 flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED; #endif baseAddr = (uintptr_t)mmap((void*)ptr, STACK_SIZE * NR_THREADS, PROT_READ | PROT_WRITE, flags, 0, 0); From nicolas.geoffray at lip6.fr Sun Nov 9 09:04:45 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 09 Nov 2008 17:04:45 -0000 Subject: [vmkit-commits] [vmkit] r58937 - /vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp Message-ID: <200811091704.mA9H4j5a004425@zion.cs.uiuc.edu> Author: geoffray Date: Sun Nov 9 11:04:45 2008 New Revision: 58937 URL: http://llvm.org/viewvc/llvm-project?rev=58937&view=rev Log: Fix asserts in the case for static compilation. Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp?rev=58937&r1=58936&r2=58937&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp Sun Nov 9 11:04:45 2008 @@ -152,7 +152,7 @@ JavaObject* obj = isStaticCompiling() ? 0 : cl->getClassDelegatee(JavaThread::get()->isolate); - assert(obj && "Delegatee not created"); + assert((obj || isStaticCompiling()) && "Delegatee not created"); Constant* cons = ConstantExpr::getIntToPtr(ConstantInt::get(Type::Int64Ty, uint64(obj)), JnjvmModule::JavaObjectType); @@ -175,7 +175,8 @@ LLVMClassInfo* LCI = getClassInfo(classDef); LCI->getStaticType(); JavaObject* obj = ((Class*)classDef)->getStaticInstance(); - assert(obj && "Getting static instance before it's created!"); + assert((obj || isStaticCompiling()) && + "Getting static instance before it's created!"); Constant* cons = ConstantExpr::getIntToPtr(ConstantInt::get(Type::Int64Ty, uint64_t (obj)), JnjvmModule::JavaObjectType); @@ -201,7 +202,8 @@ LLVMClassInfo* LCI = getClassInfo((Class*)classDef); LCI->getVirtualType(); } - assert(classDef->virtualVT && "Virtual VT not created"); + assert((classDef->virtualVT || isStaticCompiling()) && + "Virtual VT not created"); Constant* cons = ConstantExpr::getIntToPtr(ConstantInt::get(Type::Int64Ty, uint64_t(classDef->virtualVT)), @@ -227,7 +229,7 @@ LLVMSignatureInfo* LSI = getSignatureInfo(meth->getSignature()); const llvm::Type* valPtrType = LSI->getNativePtrType(); - assert(ptr && "No native function given"); + assert((ptr || isStaticCompiling()) && "No native function given"); Constant* cons = ConstantExpr::getIntToPtr(ConstantInt::get(Type::Int64Ty, uint64_t(ptr)), From nicolas.geoffray at lip6.fr Sun Nov 9 13:03:00 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 09 Nov 2008 21:03:00 -0000 Subject: [vmkit-commits] [vmkit] r58942 - /vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Message-ID: <200811092103.mA9L302A012604@zion.cs.uiuc.edu> Author: geoffray Date: Sun Nov 9 15:02:59 2008 New Revision: 58942 URL: http://llvm.org/viewvc/llvm-project?rev=58942&view=rev Log: Proper class initialization and catch exceptions when static compiling. Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp?rev=58942&r1=58941&r2=58942&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Sun Nov 9 15:02:59 2008 @@ -51,6 +51,12 @@ void UserCommonClass::initialiseClass(Jnjvm* vm) { + // Primitives are initialized at boot time, arrays are initialized directly. + if (isArray()) { + status = ready; + return; + } + // Assumes that the Class object has already been verified and prepared and // that the Class object contains state that can indicate one of four // situations: @@ -65,10 +71,7 @@ assert(status >= resolved || ownerClass || status == ready || status == erroneous && "Class in wrong state"); - // Primitives are initialized at boot time, arrays are initialized directly. - if (isArray()) { - status = ready; - } else if (status != ready) { + if (status != ready) { // 1. Synchronize on the Class object that represents the class or // interface to be initialized. This involves waiting until the @@ -86,7 +89,6 @@ while (ownerClass) { waitClass(); } - release(); } else { // 3. If initialization is in progress for the class or interface by // the current thread, then this must be a recursive request for @@ -963,70 +965,75 @@ void Jnjvm::mainCompilerStart(JavaThread* th) { Jnjvm* vm = th->isolate; - JnjvmBootstrapLoader* bootstrapLoader = vm->bootstrapLoader; + try { + JnjvmBootstrapLoader* bootstrapLoader = vm->bootstrapLoader; - bootstrapLoader->analyseClasspathEnv(vm->classpath); + bootstrapLoader->analyseClasspathEnv(vm->classpath); - uint32 size = strlen(name); - if (size > 4 && - (!strcmp(&name[size - 4], ".jar") || !strcmp(&name[size - 4], ".zip"))) { + uint32 size = strlen(name); + if (size > 4 && + (!strcmp(&name[size - 4], ".jar") || !strcmp(&name[size - 4], ".zip"))) { - std::vector classes; + std::vector classes; - ArrayUInt8* bytes = Reader::openFile(bootstrapLoader, name); - if (!bytes) vm->unknownError("Can't find zip file."); - ZipArchive archive(bytes, bootstrapLoader->allocator); + ArrayUInt8* bytes = Reader::openFile(bootstrapLoader, name); + if (!bytes) vm->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; + 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) vm->unknownError("Wrong zip file."); + 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) vm->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); + 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::iterator i = classes.begin(), e = classes.end(); - i != e; ++i) { - Class* cl = *i; - cl->resolveClass(); - } + // First resolve everyone so that there can not be unknown references in + // constant pools. + for (std::vector::iterator i = classes.begin(), + e = classes.end(); i != e; ++i) { + Class* cl = *i; + cl->resolveClass(); + } - for (std::vector::iterator i = classes.begin(), e = classes.end(); - i != e; ++i) { - Class* cl = *i; - if (!cl->isInterface()) compileClass(cl); - } + for (std::vector::iterator i = classes.begin(), e = classes.end(); + i != e; ++i) { + Class* cl = *i; + if (!cl->isInterface()) compileClass(cl); + } - } else { + } else { - const UTF8* utf8 = bootstrapLoader->asciizConstructUTF8(name); - UserClass* cl = bootstrapLoader->loadName(utf8, true, true); - compileClass(cl); - } + 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); + // 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); + } + + } catch(std::string str) { + fprintf(stderr, "Error : %s\n", str.c_str()); } - + vm->threadSystem.nonDaemonLock.lock(); --(vm->threadSystem.nonDaemonThreads); if (vm->threadSystem.nonDaemonThreads == 0) From nicolas.geoffray at lip6.fr Mon Nov 10 12:36:52 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Mon, 10 Nov 2008 20:36:52 -0000 Subject: [vmkit-commits] [vmkit] r58998 - /vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp Message-ID: <200811102036.mAAKaqL4001429@zion.cs.uiuc.edu> Author: geoffray Date: Mon Nov 10 14:36:51 2008 New Revision: 58998 URL: http://llvm.org/viewvc/llvm-project?rev=58998&view=rev Log: Remove warnings. Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp?rev=58998&r1=58997&r2=58998&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp Mon Nov 10 14:36:51 2008 @@ -253,18 +253,20 @@ extern "C" void printMethodStart(JavaMethod* meth) { - printf("[%d] executing %s\n", mvm::Thread::get(), meth->printString()); + printf("[%x] executing %s\n", (unsigned)mvm::Thread::get(), + meth->printString()); fflush(stdout); } extern "C" void printMethodEnd(JavaMethod* meth) { - printf("[%d] return from %s\n", mvm::Thread::get(), meth->printString()); + printf("[%x] return from %s\n", (unsigned)mvm::Thread::get(), + meth->printString()); fflush(stdout); } extern "C" void printExecution(char* opcode, uint32 index, JavaMethod* meth) { - printf("[%d] executing %s %s at %d\n", mvm::Thread::get(), meth->printString(), - opcode, index); + printf("[%x] executing %s %s at %d\n", (unsigned)mvm::Thread::get(), + meth->printString(), opcode, index); fflush(stdout); } From nicolas.geoffray at lip6.fr Mon Nov 10 12:38:05 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Mon, 10 Nov 2008 20:38:05 -0000 Subject: [vmkit-commits] [vmkit] r58999 - in /vmkit/trunk: include/mvm/JIT.h lib/JnJVM/Classpath/ClasspathVMObject.cpp lib/JnJVM/VMCore/JavaJIT.cpp lib/JnJVM/VMCore/JavaJITOpcodes.cpp lib/JnJVM/VMCore/JavaObject.cpp lib/JnJVM/VMCore/JavaObject.h lib/Mvm/Runtime/JIT.cpp Message-ID: <200811102038.mAAKc6rB001498@zion.cs.uiuc.edu> Author: geoffray Date: Mon Nov 10 14:38:05 2008 New Revision: 58999 URL: http://llvm.org/viewvc/llvm-project?rev=58999&view=rev Log: Implement biased-locking. Modified: vmkit/trunk/include/mvm/JIT.h vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMObject.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaObject.cpp vmkit/trunk/lib/JnJVM/VMCore/JavaObject.h vmkit/trunk/lib/Mvm/Runtime/JIT.cpp Modified: vmkit/trunk/include/mvm/JIT.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/JIT.h?rev=58999&r1=58998&r2=58999&view=diff ============================================================================== --- vmkit/trunk/include/mvm/JIT.h (original) +++ vmkit/trunk/include/mvm/JIT.h Mon Nov 10 14:38:05 2008 @@ -160,6 +160,8 @@ static llvm::Constant* constantPtrNull; static llvm::ConstantInt* constantPtrSize; static llvm::ConstantInt* constantThreadIDMask; + static llvm::ConstantInt* constantLockedMask; + static llvm::ConstantInt* constantThreadFreeMask; static const llvm::PointerType* ptrType; static const llvm::PointerType* ptr32Type; static const llvm::PointerType* ptrPtrType; Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMObject.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMObject.cpp?rev=58999&r1=58998&r2=58999&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMObject.cpp (original) +++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMObject.cpp Mon Nov 10 14:38:05 2008 @@ -43,7 +43,7 @@ JavaObject* res = (JavaObject*) vm->gcAllocator.allocateManagedObject(size, src->getVirtualTable()); memcpy(res, src, size); - res->lock = 0; + res->lock = JavaThread::get()->threadID;; return (jobject)res; } Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp?rev=58999&r1=58998&r2=58999&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp Mon Nov 10 14:38:05 2008 @@ -321,90 +321,45 @@ } void JavaJIT::monitorEnter(Value* obj) { + std::vector gep; gep.push_back(module->constantZero); gep.push_back(module->JavaObjectLockOffsetConstant); Value* lockPtr = GetElementPtrInst::Create(obj, gep.begin(), gep.end(), "", currentBlock); + Value* lock = new LoadInst(lockPtr, "", currentBlock); + Value* lockMask = BinaryOperator::CreateAnd(lock, + module->constantThreadFreeMask, + "", currentBlock); Value* threadId = CallInst::Create(module->llvm_frameaddress, module->constantZero, "", currentBlock); threadId = new PtrToIntInst(threadId, Type::Int32Ty, "", currentBlock); threadId = BinaryOperator::CreateAnd(threadId, module->constantThreadIDMask, "", currentBlock); - std::vector atomicArgs; - atomicArgs.push_back(lockPtr); - atomicArgs.push_back(module->constantZero); - atomicArgs.push_back(threadId); - - // Do the atomic compare and swap. - Value* atomic = CallInst::Create(module->llvm_atomic_lcs_i32, - atomicArgs.begin(), atomicArgs.end(), "", - currentBlock); - Value* cmp = new ICmpInst(ICmpInst::ICMP_EQ, atomic, module->constantZero, - "", currentBlock); + Value* cmp = new ICmpInst(ICmpInst::ICMP_EQ, lockMask, threadId, "", + currentBlock); - BasicBlock* OK = createBasicBlock("synchronize passed"); - BasicBlock* NotOK = createBasicBlock("synchronize did not pass"); + BasicBlock* ThinLockBB = createBasicBlock("thread local"); BasicBlock* FatLockBB = createBasicBlock("fat lock"); - BasicBlock* ThinLockBB = createBasicBlock("thin lock"); - - BranchInst::Create(OK, NotOK, cmp, currentBlock); - - currentBlock = NotOK; - - // 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, "", - currentBlock); - cmp = new ICmpInst(ICmpInst::ICMP_EQ, isThin, module->constantZero, "", - currentBlock); + BasicBlock* EndLockBB = createBasicBlock("End lock"); BranchInst::Create(ThinLockBB, FatLockBB, cmp, currentBlock); - // It's a thin lock. Look if we're the owner of this lock. currentBlock = ThinLockBB; - Value* idMask = ConstantInt::get(Type::Int32Ty, 0x7FFFFF00); - Value* cptMask = ConstantInt::get(Type::Int32Ty, 0xFF); - Value* IdInLock = BinaryOperator::CreateAnd(atomic, idMask, "", currentBlock); - Value* owner = new ICmpInst(ICmpInst::ICMP_EQ, threadId, IdInLock, "", - currentBlock); + Value* increment = BinaryOperator::CreateAdd(lock, module->constantOne, "", + currentBlock); + new StoreInst(increment, lockPtr, false, currentBlock); + BranchInst::Create(EndLockBB, currentBlock); - BasicBlock* OwnerBB = createBasicBlock("owner thread"); - - BranchInst::Create(OwnerBB, FatLockBB, owner, currentBlock); - currentBlock = OwnerBB; - - // OK, we are the owner, now check if the counter will overflow. - Value* count = BinaryOperator::CreateAnd(atomic, cptMask, "", currentBlock); - cmp = new ICmpInst(ICmpInst::ICMP_ULT, count, cptMask, "", currentBlock); - - BasicBlock* IncCounterBB = createBasicBlock("Increment counter"); - BasicBlock* OverflowCounterBB = createBasicBlock("Overflow counter"); - - BranchInst::Create(IncCounterBB, OverflowCounterBB, cmp, currentBlock); - currentBlock = IncCounterBB; - - // The counter will not overflow, increment it. - Value* Add = BinaryOperator::CreateAdd(module->constantOne, atomic, "", - currentBlock); - new StoreInst(Add, lockPtr, false, currentBlock); - BranchInst::Create(OK, currentBlock); - - currentBlock = OverflowCounterBB; - - // The counter will overflow, call this function to create a new lock, - // lock it 0x101 times, and pass. - CallInst::Create(module->OverflowThinLockFunction, obj, "", - currentBlock); - BranchInst::Create(OK, currentBlock); - currentBlock = FatLockBB; - // Either it's a fat lock or there is contention. + // Either it's a fat lock or there is contention or it's not thread local or + // it's locked at least once. CallInst::Create(module->AquireObjectFunction, obj, "", currentBlock); - BranchInst::Create(OK, currentBlock); - currentBlock = OK; + + BranchInst::Create(EndLockBB, currentBlock); + currentBlock = EndLockBB; } void JavaJIT::monitorExit(Value* obj) { @@ -414,51 +369,33 @@ Value* lockPtr = GetElementPtrInst::Create(obj, gep.begin(), gep.end(), "", currentBlock); Value* lock = new LoadInst(lockPtr, "", currentBlock); + Value* lockMask = BinaryOperator::CreateAnd(lock, module->constantLockedMask, + "", currentBlock); Value* threadId = CallInst::Create(module->llvm_frameaddress, module->constantZero, "", currentBlock); threadId = new PtrToIntInst(threadId, Type::Int32Ty, "", currentBlock); threadId = BinaryOperator::CreateAnd(threadId, module->constantThreadIDMask, "", currentBlock); - Value* cmp = new ICmpInst(ICmpInst::ICMP_EQ, lock, threadId, "", + Value* cmp = new ICmpInst(ICmpInst::ICMP_EQ, lockMask, threadId, "", currentBlock); BasicBlock* EndUnlock = createBasicBlock("end unlock"); - BasicBlock* LockedOnceBB = createBasicBlock("desynchronize thin lock"); - BasicBlock* NotLockedOnceBB = - createBasicBlock("simple desynchronize did not pass"); + BasicBlock* ThinLockBB = createBasicBlock("desynchronize thin lock"); BasicBlock* FatLockBB = createBasicBlock("fat lock"); - BasicBlock* ThinLockBB = createBasicBlock("thin lock"); - - BranchInst::Create(LockedOnceBB, NotLockedOnceBB, cmp, currentBlock); - - // Locked once, set zero - currentBlock = LockedOnceBB; - new StoreInst(module->constantZero, lockPtr, false, currentBlock); - BranchInst::Create(EndUnlock, currentBlock); - - currentBlock = NotLockedOnceBB; - // Look if the lock is thin. - Value* thinMask = ConstantInt::get(Type::Int32Ty, 0x80000000); - Value* isThin = BinaryOperator::CreateAnd(lock, thinMask, "", - currentBlock); - cmp = new ICmpInst(ICmpInst::ICMP_EQ, isThin, module->constantZero, "", - currentBlock); BranchInst::Create(ThinLockBB, FatLockBB, cmp, currentBlock); + // Locked by the thread, decrement. currentBlock = ThinLockBB; - - // Decrement the counter. - Value* Sub = BinaryOperator::CreateSub(lock, module->constantOne, "", - currentBlock); - new StoreInst(Sub, lockPtr, false, currentBlock); + Value* decrement = BinaryOperator::CreateSub(lock, module->constantOne, "", + currentBlock); + new StoreInst(decrement, lockPtr, false, currentBlock); BranchInst::Create(EndUnlock, currentBlock); + // Either it's a fat lock or there is contention or it's not thread local. currentBlock = FatLockBB; - - // Either it's a fat lock or there is contention. CallInst::Create(module->ReleaseObjectFunction, obj, "", currentBlock); BranchInst::Create(EndUnlock, currentBlock); currentBlock = EndUnlock; @@ -1817,7 +1754,18 @@ Value* GEP = GetElementPtrInst::Create(val, gep.begin(), gep.end(), "", currentBlock); new StoreInst(Cl, GEP, currentBlock); - + + gep.clear(); + gep.push_back(module->constantZero); + gep.push_back(module->JavaObjectLockOffsetConstant); + Value* lockPtr = GetElementPtrInst::Create(val, gep.begin(), gep.end(), "", + currentBlock); + Value* threadId = CallInst::Create(module->llvm_frameaddress, + module->constantZero, "", currentBlock); + threadId = new PtrToIntInst(threadId, Type::Int32Ty, "", currentBlock); + threadId = BinaryOperator::CreateAnd(threadId, module->constantThreadIDMask, + "", currentBlock); + new StoreInst(threadId, lockPtr, currentBlock); push(val, false); } Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp?rev=58999&r1=58998&r2=58999&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp Mon Nov 10 14:38:05 2008 @@ -1955,6 +1955,18 @@ currentBlock); new StoreInst(valCl, GEP, currentBlock); + gep.clear(); + gep.push_back(module->constantZero); + gep.push_back(module->JavaObjectLockOffsetConstant); + Value* lockPtr = GetElementPtrInst::Create(res, gep.begin(), gep.end(), "", + currentBlock); + Value* threadId = CallInst::Create(module->llvm_frameaddress, + module->constantZero, "", currentBlock); + threadId = new PtrToIntInst(threadId, Type::Int32Ty, "", currentBlock); + threadId = BinaryOperator::CreateAnd(threadId, module->constantThreadIDMask, + "", currentBlock); + new StoreInst(threadId, lockPtr, currentBlock); + push(res, false); break; Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaObject.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaObject.cpp?rev=58999&r1=58998&r2=58999&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaObject.cpp (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaObject.cpp Mon Nov 10 14:38:05 2008 @@ -79,8 +79,7 @@ } bool JavaObject::owner() { - uint32 id = mvm::Thread::get()->threadID; - if (id == lock) return true; + uint32 id = (uint32)mvm::Thread::get(); if ((lock & 0x7FFFFF00) == id) return true; if (lock & 0x80000000) { LockObj* obj = (LockObj*)(lock << 1); @@ -91,57 +90,61 @@ void JavaObject::overflowThinlock() { LockObj* obj = LockObj::allocate(); - obj->lock.lockAll(257); + obj->lock.lockAll(256); lock = ((uint32)obj >> 1) | 0x80000000; } void JavaObject::release() { - uint32 id = mvm::Thread::get()->threadID; - if (lock == id) { - lock = 0; - } else if (lock & 0x80000000) { + uint32 id = (uint32)mvm::Thread::get(); + if ((lock & 0x7FFFFF00) == id) { + --lock; + } else { LockObj* obj = (LockObj*)(lock << 1); obj->release(); - } else { - lock--; - } + } } void JavaObject::acquire() { - uint32 id = mvm::Thread::get()->threadID; - uint32 val = __sync_val_compare_and_swap((uint32*)&lock, 0, id); - if (val != 0) { - //fat! - if (!(val & 0x80000000)) { - if ((val & 0x7FFFFF00) == id) { - if ((val & 0xFF) != 0xFF) { - lock++; - } else { - overflowThinlock(); - } + uint32 id = (uint32)mvm::Thread::get(); + if ((lock & 0x7FFFFFFF) == id) { + lock |= 1; + } else if ((lock & 0x7FFFFF00) == id) { + if ((lock & 0xFF) == 0xFF) { + overflowThinlock(); + } else { + ++lock; + } + } else { + uint32 currentLock = lock & 0x7FFFFF00; + uint32 val = __sync_val_compare_and_swap((uint32*)&lock, currentLock, (id + 1)); + if (val != currentLock) { + //fat! + if (val & 0x80000000) { +end: + LockObj* obj = (LockObj*)(lock << 1); + obj->acquire(); } else { LockObj* obj = LockObj::allocate(); uint32 val = ((uint32)obj >> 1) | 0x80000000; -loop: uint32 count = 0; - while (lock) { +loop: + while ((lock & 0xFF) != 0) { if (lock & 0x80000000) { #ifdef USE_GC_BOEHM delete obj; #endif goto end; } - else mvm::Thread::yield(&count); + else { + mvm::Thread::yield(&count); + } } - uint32 test = __sync_val_compare_and_swap((uint32*)&lock, 0, val); - if (test) goto loop; + currentLock = lock & 0x7FFFFF00; + uint32 test = __sync_val_compare_and_swap(&lock, currentLock, val); + if (test != currentLock) goto loop; obj->acquire(); } - } else { -end: - LockObj* obj = (LockObj*)(lock << 1); - obj->acquire(); } } } @@ -151,7 +154,7 @@ LockObj* obj = LockObj::allocate(); uint32 val = (((uint32) obj) >> 1) | 0x80000000; uint32 count = lock & 0xFF; - obj->lock.lockAll(count + 1); + obj->lock.lockAll(count); lock = val; return obj; } else { Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaObject.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaObject.h?rev=58999&r1=58998&r2=58999&view=diff ============================================================================== --- vmkit/trunk/lib/JnJVM/VMCore/JavaObject.h (original) +++ vmkit/trunk/lib/JnJVM/VMCore/JavaObject.h Mon Nov 10 14:38:05 2008 @@ -14,6 +14,7 @@ #include "mvm/Object.h" #include "mvm/Threads/Locks.h" +#include "mvm/Threads/Thread.h" #include "types.h" @@ -160,7 +161,7 @@ /// void initialise(UserCommonClass* cl) { this->classOf = cl; - this->lock = 0; + this->lock = (uint32)mvm::Thread::get(); } /// instanceOf - Is this object's class of type the given class? Modified: vmkit/trunk/lib/Mvm/Runtime/JIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/JIT.cpp?rev=58999&r1=58998&r2=58999&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Runtime/JIT.cpp (original) +++ vmkit/trunk/lib/Mvm/Runtime/JIT.cpp Mon Nov 10 14:38:05 2008 @@ -123,6 +123,8 @@ constantDoubleMinusZero = ConstantFP::get(Type::DoubleTy, -0.0); constantFloatMinusZero = ConstantFP::get(Type::FloatTy, -0.0f); constantThreadIDMask = ConstantInt::get(Type::Int32Ty, mvm::Thread::IDMask); + constantLockedMask = ConstantInt::get(Type::Int32Ty, 0x7FFFFF00); + constantThreadFreeMask = ConstantInt::get(Type::Int32Ty, 0x7FFFFFFF); constantPtrNull = Constant::getNullValue(ptrType); constantPtrSize = ConstantInt::get(Type::Int32Ty, sizeof(void*)); @@ -237,6 +239,8 @@ llvm::Constant* MvmModule::constantPtrNull; llvm::ConstantInt* MvmModule::constantPtrSize; llvm::ConstantInt* MvmModule::constantThreadIDMask; +llvm::ConstantInt* MvmModule::constantLockedMask; +llvm::ConstantInt* MvmModule::constantThreadFreeMask; const llvm::PointerType* MvmModule::ptrType; const llvm::PointerType* MvmModule::ptr32Type; const llvm::PointerType* MvmModule::ptrPtrType; From nicolas.geoffray at lip6.fr Tue Nov 11 01:43:13 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Tue, 11 Nov 2008 09:43:13 -0000 Subject: [vmkit-commits] [vmkit] r59038 - in /vmkit/trunk/www: releases.html releases/ releases/index.html Message-ID: <200811110943.mAB9hDcf010988@zion.cs.uiuc.edu> Author: geoffray Date: Tue Nov 11 03:43:13 2008 New Revision: 59038 URL: http://llvm.org/viewvc/llvm-project?rev=59038&view=rev Log: Fix link for the 2.4 release notes. Added: vmkit/trunk/www/releases/ vmkit/trunk/www/releases/index.html - copied unchanged from r58803, vmkit/trunk/www/releases.html Removed: vmkit/trunk/www/releases.html Removed: vmkit/trunk/www/releases.html URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/www/releases.html?rev=59037&view=auto ============================================================================== --- vmkit/trunk/www/releases.html (original) +++ vmkit/trunk/www/releases.html (removed) @@ -1,60 +0,0 @@ - - - - - - "vmkit" JVM and .Net runtimes for LLVM - - - - - - -
- -

VMKit Releases

- - -

The VMKit project was publicly released in the time of LLVM 2.3. Since - LLVM 2.4, VMKit follows each LLVM release. The first release of VMKit is - version 0.24.

- - -

Downloads

- - - - -
- - From nicolas.geoffray at lip6.fr Tue Nov 11 01:59:10 2008 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Tue, 11 Nov 2008 09:59:10 -0000 Subject: [vmkit-commits] [vmkit] r59040 - /vmkit/trunk/www/releases/index.html Message-ID: <200811110959.mAB9xAuD011492@zion.cs.uiuc.edu> Author: geoffray Date: Tue Nov 11 03:59:10 2008 New Revision: 59040 URL: http://llvm.org/viewvc/llvm-project?rev=59040&view=rev Log: Fix links. Modified: vmkit/trunk/www/releases/index.html Modified: vmkit/trunk/www/releases/index.html URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/www/releases/index.html?rev=59040&r1=59039&r2=59040&view=diff ============================================================================== --- vmkit/trunk/www/releases/index.html (original) +++ vmkit/trunk/www/releases/index.html Tue Nov 11 03:59:10 2008 @@ -5,8 +5,8 @@ "vmkit" JVM and .Net runtimes for LLVM - - + +