From nicolas.geoffray at lip6.fr Fri Jul 1 09:46:40 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Fri, 01 Jul 2011 16:46:40 -0000 Subject: [vmkit-commits] [vmkit] r134239 - in /vmkit/trunk: include/j3/J3Intrinsics.h include/j3/JavaAOTCompiler.h include/j3/JavaLLVMCompiler.h include/mvm/Config/config.h.in include/mvm/Threads/CollectionRV.h include/mvm/Threads/Thread.h lib/Mvm/CommonThread/CollectionRV.cpp lib/Mvm/CommonThread/ObjectLocks.cpp lib/Mvm/CommonThread/cterror.cpp lib/Mvm/CommonThread/cterror.h lib/Mvm/CommonThread/ctlock.cpp lib/Mvm/CommonThread/ctthread.cpp Message-ID: <20110701164640.E26002A6C12C@llvm.org> Author: geoffray Date: Fri Jul 1 11:46:40 2011 New Revision: 134239 URL: http://llvm.org/viewvc/llvm-project?rev=134239&view=rev Log: Remove obsolete code. Removed: vmkit/trunk/lib/Mvm/CommonThread/cterror.cpp vmkit/trunk/lib/Mvm/CommonThread/cterror.h Modified: vmkit/trunk/include/j3/J3Intrinsics.h vmkit/trunk/include/j3/JavaAOTCompiler.h vmkit/trunk/include/j3/JavaLLVMCompiler.h vmkit/trunk/include/mvm/Config/config.h.in vmkit/trunk/include/mvm/Threads/CollectionRV.h vmkit/trunk/include/mvm/Threads/Thread.h vmkit/trunk/lib/Mvm/CommonThread/CollectionRV.cpp vmkit/trunk/lib/Mvm/CommonThread/ObjectLocks.cpp vmkit/trunk/lib/Mvm/CommonThread/ctlock.cpp vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp Modified: vmkit/trunk/include/j3/J3Intrinsics.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/J3Intrinsics.h?rev=134239&r1=134238&r2=134239&view=diff ============================================================================== --- vmkit/trunk/include/j3/J3Intrinsics.h (original) +++ vmkit/trunk/include/j3/J3Intrinsics.h Fri Jul 1 11:46:40 2011 @@ -44,10 +44,6 @@ const llvm::Type* JavaThreadType; const llvm::Type* MutatorThreadType; -#ifdef ISOLATE_SHARING - const llvm::Type* JnjvmType; -#endif - llvm::Function* StartJNIFunction; llvm::Function* EndJNIFunction; llvm::Function* InterfaceLookupFunction; @@ -68,9 +64,7 @@ llvm::Function* ResolveStaticStubFunction; llvm::Function* ResolveInterfaceFunction; -#ifndef WITHOUT_VTABLE llvm::Function* VirtualLookupFunction; -#endif llvm::Function* IsAssignableFromFunction; llvm::Function* IsSecondaryClassFunction; llvm::Function* GetDepthFunction; @@ -83,19 +77,6 @@ llvm::Function* MultiCallNewFunction; llvm::Function* GetArrayClassFunction; -#ifdef ISOLATE_SHARING - llvm::Function* GetCtpClassFunction; - llvm::Function* GetJnjvmExceptionClassFunction; - llvm::Function* GetJnjvmArrayClassFunction; - llvm::Function* StaticCtpLookupFunction; - llvm::Function* SpecialCtpLookupFunction; -#endif - -#ifdef SERVICE - llvm::Function* ServiceCallStartFunction; - llvm::Function* ServiceCallStopFunction; -#endif - llvm::Function* GetClassDelegateeFunction; llvm::Function* RuntimeDelegateeFunction; llvm::Function* ArrayLengthFunction; Modified: vmkit/trunk/include/j3/JavaAOTCompiler.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/JavaAOTCompiler.h?rev=134239&r1=134238&r2=134239&view=diff ============================================================================== --- vmkit/trunk/include/j3/JavaAOTCompiler.h (original) +++ vmkit/trunk/include/j3/JavaAOTCompiler.h Fri Jul 1 11:46:40 2011 @@ -70,10 +70,6 @@ virtual void setMethod(llvm::Function* func, void* ptr, const char* name); -#ifdef SERVICE - virtual llvm::Value* getIsolate(Jnjvm* vm, llvm::Value* Where); -#endif - virtual ~JavaAOTCompiler() {} virtual void* loadMethod(void* handle, const char* symbol); @@ -156,13 +152,6 @@ typedef std::map::iterator utf8_iterator; -#ifdef SERVICE - virtual llvm::Value* getIsolate(Jnjvm* vm, llvm::Value* Where); - std::map isolates; - typedef std::map::iterator - isolate_iterator; -#endif - bool isCompiling(const CommonClass* cl) const; public: Modified: vmkit/trunk/include/j3/JavaLLVMCompiler.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/JavaLLVMCompiler.h?rev=134239&r1=134238&r2=134239&view=diff ============================================================================== --- vmkit/trunk/include/j3/JavaLLVMCompiler.h (original) +++ vmkit/trunk/include/j3/JavaLLVMCompiler.h Fri Jul 1 11:46:40 2011 @@ -197,10 +197,6 @@ virtual void setMethod(llvm::Function* func, void* ptr, const char* name) = 0; -#ifdef SERVICE - virtual llvm::Value* getIsolate(Jnjvm* vm, llvm::Value* Where) = 0; -#endif - virtual void* materializeFunction(JavaMethod* meth) = 0; llvm::Function* parseFunction(JavaMethod* meth); Modified: vmkit/trunk/include/mvm/Config/config.h.in URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Config/config.h.in?rev=134239&r1=134238&r2=134239&view=diff ============================================================================== --- vmkit/trunk/include/mvm/Config/config.h.in (original) +++ vmkit/trunk/include/mvm/Config/config.h.in Fri Jul 1 11:46:40 2011 @@ -78,18 +78,6 @@ /* Define to 1 if your declares `struct tm'. */ #undef TM_IN_SYS_TIME -/* Using the boehm gc */ -#undef USE_GC_BOEHM - -/* Using the gcmmap2 */ -#undef USE_GC_MMAP2 - -/* Compiling N3 */ -#undef WITH_N3 - -/* Compiling JNJVM */ -#undef WITH_J3 - /* Define to `int' if does not define. */ #undef pid_t Modified: vmkit/trunk/include/mvm/Threads/CollectionRV.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Threads/CollectionRV.h?rev=134239&r1=134238&r2=134239&view=diff ============================================================================== --- vmkit/trunk/include/mvm/Threads/CollectionRV.h (original) +++ vmkit/trunk/include/mvm/Threads/CollectionRV.h Fri Jul 1 11:46:40 2011 @@ -80,18 +80,6 @@ }; -class UncooperativeCollectionRV : public CollectionRV { -public: - void finishRV(); - void synchronize(); - - void join(); - void joinAfterUncooperative(void* SP); - void joinBeforeUncooperative(); - void addThread(Thread* th); -}; - - } #endif Modified: vmkit/trunk/include/mvm/Threads/Thread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Threads/Thread.h?rev=134239&r1=134238&r2=134239&view=diff ============================================================================== --- vmkit/trunk/include/mvm/Threads/Thread.h (original) +++ vmkit/trunk/include/mvm/Threads/Thread.h Fri Jul 1 11:46:40 2011 @@ -289,12 +289,6 @@ /// void (*routine)(mvm::Thread*); -#ifdef SERVICE - /// stoppingService - The service that is currently stopping. - /// - VirtualMachine* stoppingService; -#endif - /// printBacktrace - Print the backtrace. /// void printBacktrace(); Modified: vmkit/trunk/lib/Mvm/CommonThread/CollectionRV.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommonThread/CollectionRV.cpp?rev=134239&r1=134238&r2=134239&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/CommonThread/CollectionRV.cpp (original) +++ vmkit/trunk/lib/Mvm/CommonThread/CollectionRV.cpp Fri Jul 1 11:46:40 2011 @@ -82,50 +82,6 @@ unlockRV(); } - -#if defined(__MACH__) -# define SIGGC SIGXCPU -#else -# define SIGGC SIGPWR -#endif - -void UncooperativeCollectionRV::synchronize() { - assert(nbJoined == 0); - mvm::Thread* self = mvm::Thread::get(); - // Lock thread lock, so that we can traverse the thread list safely. This will - // be released on finishRV. - self->MyVM->threadLock.lock(); - - for (mvm::Thread* cur = (mvm::Thread*)self->next(); cur != self; - cur = (mvm::Thread*)cur->next()) { - int res = cur->kill(SIGGC); - assert(!res && "Error on kill"); - } - - // And wait for other threads to finish. - waitRV(); - - // Unlock, so that threads in uncooperative code that go back to cooperative - // code can set back their lastSP. - unlockRV(); -} - - -void UncooperativeCollectionRV::join() { - mvm::Thread* th = mvm::Thread::get(); - th->inRV = true; - - lockRV(); - void* old = th->getLastSP(); - th->setLastSP(FRAME_PTR()); - another_mark(); - waitEndOfRV(); - th->setLastSP(old); - unlockRV(); - - th->inRV = false; -} - void CooperativeCollectionRV::join() { mvm::Thread* th = mvm::Thread::get(); assert(th->doYield && "No yield"); @@ -213,47 +169,6 @@ mvm::Thread::get()->inRV = false; } -void UncooperativeCollectionRV::finishRV() { - lockRV(); - mvm::Thread* initiator = mvm::Thread::get(); - assert(nbJoined == initiator->MyVM->numberOfThreads && "Inconsistent state"); - nbJoined = 0; - initiator->MyVM->threadLock.unlock(); - condEndRV.broadcast(); - unlockRV(); - initiator->inRV = false; -} - -void UncooperativeCollectionRV::joinAfterUncooperative(void* SP) { - UNREACHABLE(); -} - -void UncooperativeCollectionRV::joinBeforeUncooperative() { - UNREACHABLE(); -} - void CooperativeCollectionRV::addThread(Thread* th) { // Nothing to do. } - -static void siggcHandler(int) { - mvm::Thread* th = mvm::Thread::get(); - th->MyVM->rendezvous.join(); -} - -void UncooperativeCollectionRV::addThread(Thread* th) { - // Set the SIGGC handler for uncooperative rendezvous. - struct sigaction sa; - sigset_t mask; - sigaction(SIGGC, 0, &sa); - sigfillset(&mask); - sa.sa_mask = mask; - sa.sa_handler = siggcHandler; - sa.sa_flags |= SA_RESTART; - sigaction(SIGGC, &sa, NULL); - - if (nbJoined != 0) { - // In uncooperative mode, we may have missed a signal. - join(); - } -} Modified: vmkit/trunk/lib/Mvm/CommonThread/ObjectLocks.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommonThread/ObjectLocks.cpp?rev=134239&r1=134238&r2=134239&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/CommonThread/ObjectLocks.cpp (original) +++ vmkit/trunk/lib/Mvm/CommonThread/ObjectLocks.cpp Fri Jul 1 11:46:40 2011 @@ -15,7 +15,6 @@ #include "mvm/Threads/Thread.h" #include "mvm/VirtualMachine.h" #include "MvmGC.h" -#include "cterror.h" #include #include #include Removed: vmkit/trunk/lib/Mvm/CommonThread/cterror.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommonThread/cterror.cpp?rev=134238&view=auto ============================================================================== --- vmkit/trunk/lib/Mvm/CommonThread/cterror.cpp (original) +++ vmkit/trunk/lib/Mvm/CommonThread/cterror.cpp (removed) @@ -1,35 +0,0 @@ -//===-------------- cterror.cc - Mvm common threads -----------------------===// -// -// Mvm -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "cterror.h" -#include -#include -#include -#include -#include - -void (*pgcdomsgf)(const char *, unsigned int l, const char *, const char *, ...) = _gcdomsgf; -void (**gcdomsgf)(const char *, unsigned int l, const char *, const char *, ...) = &pgcdomsgf; - -const char *ctperror() { - return strerror(errno); -} - -void _gcdomsgf(const char *file, unsigned int l, const char *func, const char *msg, ...) -{ - va_list va; - va_start(va, msg); - fprintf(stderr, "GC[error] in %s line %d (function %s)\n", file, l, func); - vfprintf(stderr, msg, va); - fprintf(stderr, "\n"); - va_end(va); - exit(0); -} - - Removed: vmkit/trunk/lib/Mvm/CommonThread/cterror.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommonThread/cterror.h?rev=134238&view=auto ============================================================================== --- vmkit/trunk/lib/Mvm/CommonThread/cterror.h (original) +++ vmkit/trunk/lib/Mvm/CommonThread/cterror.h (removed) @@ -1,22 +0,0 @@ -//===---------------- cterror.h - Mvm common threads ----------------------===// -// -// Mvm -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef _CT_ERROR_H_ -#define _CT_ERROR_H_ - -extern const char *ctperror(); -extern void _gcdomsgf(const char *file, unsigned int l, const char *func, const char *msg, ...); -extern void (*pgcdomsgf)(const char *, unsigned int l, const char *, const char *, ...); -extern void (**gcdomsgf)(const char *, unsigned int l, const char *, const char *, ...); - -#define ctfatal(msg) (*gcdomsgf)(__FILE__, __LINE__, __PRETTY_FUNCTION__, msg) - -#endif - - Modified: vmkit/trunk/lib/Mvm/CommonThread/ctlock.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommonThread/ctlock.cpp?rev=134239&r1=134238&r2=134239&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/CommonThread/ctlock.cpp (original) +++ vmkit/trunk/lib/Mvm/CommonThread/ctlock.cpp Fri Jul 1 11:46:40 2011 @@ -14,7 +14,6 @@ #include "mvm/Threads/Thread.h" #include "mvm/VirtualMachine.h" #include "MvmGC.h" -#include "cterror.h" #include #include #include Modified: vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp?rev=134239&r1=134238&r2=134239&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp (original) +++ vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp Fri Jul 1 11:46:40 2011 @@ -93,12 +93,6 @@ lastKnownFrame = lastKnownFrame->previousFrame; } -#if defined(__MACH__) -#define SELF_HANDLE RTLD_DEFAULT -#else -#define SELF_HANDLE 0 -#endif - void Thread::internalThrowException() { #if defined(__MACH__) _longjmp(lastExceptionBuffer->buffer, 1); @@ -374,9 +368,6 @@ assert(th->MyVM && "VM not set in a thread"); -#ifdef ISOLATE - th->IsolateID = th->MyVM->IsolateID; -#endif th->MyVM->rendezvous.addThread(th); th->routine(th); th->MyVM->removeThread(th); From nicolas.geoffray at lip6.fr Fri Jul 1 10:01:34 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Fri, 01 Jul 2011 17:01:34 -0000 Subject: [vmkit-commits] [vmkit] r134241 - in /vmkit/trunk/lib: J3/VMCore/LockedMap.h Mvm/Compiler/InlineMalloc.cpp Mvm/MMTk/MutatorThread.cpp Mvm/MMTk/MvmGC.h Mvm/Runtime/LLVMAssembly.ll Mvm/Runtime/LLVMAssembly64.ll Mvm/Runtime/Object.cpp Mvm/Runtime/UTF8.cpp Message-ID: <20110701170134.D88192A6C12C@llvm.org> Author: geoffray Date: Fri Jul 1 12:01:34 2011 New Revision: 134241 URL: http://llvm.org/viewvc/llvm-project?rev=134241&view=rev Log: More cleanup. Removed: vmkit/trunk/lib/Mvm/MMTk/MutatorThread.cpp vmkit/trunk/lib/Mvm/Runtime/LLVMAssembly.ll vmkit/trunk/lib/Mvm/Runtime/LLVMAssembly64.ll Modified: vmkit/trunk/lib/J3/VMCore/LockedMap.h vmkit/trunk/lib/Mvm/Compiler/InlineMalloc.cpp vmkit/trunk/lib/Mvm/MMTk/MvmGC.h vmkit/trunk/lib/Mvm/Runtime/Object.cpp vmkit/trunk/lib/Mvm/Runtime/UTF8.cpp Modified: vmkit/trunk/lib/J3/VMCore/LockedMap.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/LockedMap.h?rev=134241&r1=134240&r2=134241&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/LockedMap.h (original) +++ vmkit/trunk/lib/J3/VMCore/LockedMap.h Fri Jul 1 12:01:34 2011 @@ -71,7 +71,7 @@ TLock lock; std::map > > map; + std::allocator > > map; inline Container lookupOrCreate(Key& V, Meta meta, funcCreate func) { Container res = 0; Modified: vmkit/trunk/lib/Mvm/Compiler/InlineMalloc.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Compiler/InlineMalloc.cpp?rev=134241&r1=134240&r2=134241&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Compiler/InlineMalloc.cpp (original) +++ vmkit/trunk/lib/Mvm/Compiler/InlineMalloc.cpp Fri Jul 1 12:01:34 2011 @@ -34,11 +34,6 @@ }; char InlineMalloc::ID = 0; -#if 0 - static RegisterPass X("InlineMalloc", - "Inline calls to gcmalloc"); -#endif - bool InlineMalloc::runOnFunction(Function& F) { Function* Malloc = F.getParent()->getFunction("gcmalloc"); Removed: vmkit/trunk/lib/Mvm/MMTk/MutatorThread.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/MMTk/MutatorThread.cpp?rev=134240&view=auto ============================================================================== --- vmkit/trunk/lib/Mvm/MMTk/MutatorThread.cpp (original) +++ vmkit/trunk/lib/Mvm/MMTk/MutatorThread.cpp (removed) @@ -1,14 +0,0 @@ -//===--------- MutatorThread.cpp - Thread for GC --------------------------===// -// -// The VMKit project -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - - -#include "MutatorThread.h" -#include "MvmGC.h" - -using namespace mvm; Modified: vmkit/trunk/lib/Mvm/MMTk/MvmGC.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/MMTk/MvmGC.h?rev=134241&r1=134240&r2=134241&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/MMTk/MvmGC.h (original) +++ vmkit/trunk/lib/Mvm/MMTk/MvmGC.h Fri Jul 1 12:01:34 2011 @@ -14,8 +14,6 @@ #include "mvm/GC/GC.h" #include -#define gc_allocator std::allocator - class VirtualTable { public: uintptr_t destructor; Removed: vmkit/trunk/lib/Mvm/Runtime/LLVMAssembly.ll URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/LLVMAssembly.ll?rev=134240&view=auto ============================================================================== --- vmkit/trunk/lib/Mvm/Runtime/LLVMAssembly.ll (original) +++ vmkit/trunk/lib/Mvm/Runtime/LLVMAssembly.ll (removed) @@ -1,31 +0,0 @@ -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Atomic ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -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 - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;;;;;;;;;;;;;;;;;;;;;;;;Helper functions for gcc < 4.2 ;;;;;;;;;;;;;;;;;;;;;;;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -define i8 @llvm_atomic_cmp_swap_i8(i8* %ptr, i8 %cmp, i8 %swap) -nounwind { - %A = call i8 @llvm.atomic.cmp.swap.i8.p0i8( i8* %ptr, i8 %cmp, i8 %swap) - ret i8 %A -} - -define i16 @llvm_atomic_cmp_swap_i16(i16* %ptr, i16 %cmp, i16 %swap) -nounwind { - %A = call i16 @llvm.atomic.cmp.swap.i16.p0i16( i16* %ptr, i16 %cmp, i16 %swap) - ret i16 %A -} - -define i32 @llvm_atomic_cmp_swap_i32(i32* %ptr, i32 %cmp, i32 %swap) -nounwind { - %A = call i32 @llvm.atomic.cmp.swap.i32.p0i32(i32* %ptr, i32 %cmp, i32 %swap) - ret i32 %A -} - - Removed: vmkit/trunk/lib/Mvm/Runtime/LLVMAssembly64.ll URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/LLVMAssembly64.ll?rev=134240&view=auto ============================================================================== --- vmkit/trunk/lib/Mvm/Runtime/LLVMAssembly64.ll (original) +++ vmkit/trunk/lib/Mvm/Runtime/LLVMAssembly64.ll (removed) @@ -1,7 +0,0 @@ -declare i64 @llvm.atomic.cmp.swap.i64.p0i64(i64*, i64, i64) nounwind - -define i64 @llvm_atomic_cmp_swap_i64(i64* %ptr, i64 %cmp, i64 %swap) -nounwind { - %A = call i64 @llvm.atomic.cmp.swap.i64.p0i64( i64* %ptr, i64 %cmp, i64 %swap) - ret i64 %A -} Modified: vmkit/trunk/lib/Mvm/Runtime/Object.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/Object.cpp?rev=134241&r1=134240&r2=134241&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Runtime/Object.cpp (original) +++ vmkit/trunk/lib/Mvm/Runtime/Object.cpp Fri Jul 1 12:01:34 2011 @@ -1,6 +1,6 @@ -//===--------- Object.cc - Common objects for vmlets ----------------------===// +//===--------- Object.cpp - Common objects GC objects ---------------------===// // -// The Micro Virtual Machine +// The VMKit project // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. Modified: vmkit/trunk/lib/Mvm/Runtime/UTF8.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/UTF8.cpp?rev=134241&r1=134240&r2=134241&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Runtime/UTF8.cpp (original) +++ vmkit/trunk/lib/Mvm/Runtime/UTF8.cpp Fri Jul 1 12:01:34 2011 @@ -1,3 +1,12 @@ +//===------------- UTF8.cpp - Common UTF8 functions -----------------------===// +// +// The VMKit project +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + #include "mvm/Allocator.h" #include "mvm/UTF8.h" #include "mvm/PrintBuffer.h" From nicolas.geoffray at lip6.fr Sat Jul 2 03:47:10 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 02 Jul 2011 10:47:10 -0000 Subject: [vmkit-commits] [vmkit] r134313 - in /vmkit/trunk: lib/J3/Compiler/ lib/J3/LLVMRuntime/ lib/J3/VMCore/ tools/vmjc/ Message-ID: <20110702104710.9A0CF2A6C12C@llvm.org> Author: geoffray Date: Sat Jul 2 05:47:10 2011 New Revision: 134313 URL: http://llvm.org/viewvc/llvm-project?rev=134313&view=rev Log: More cleanup. Removed: vmkit/trunk/lib/J3/LLVMRuntime/runtime-default-thread.ll vmkit/trunk/lib/J3/LLVMRuntime/runtime-isolate.ll vmkit/trunk/lib/J3/LLVMRuntime/runtime-service.ll Modified: vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp vmkit/trunk/lib/J3/Compiler/JavaJIT.h vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp vmkit/trunk/lib/J3/Compiler/LowerConstantCalls.cpp vmkit/trunk/lib/J3/VMCore/JavaClass.cpp vmkit/trunk/lib/J3/VMCore/JavaClass.h vmkit/trunk/lib/J3/VMCore/JavaConstantPool.cpp vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp vmkit/trunk/lib/J3/VMCore/JavaThread.cpp vmkit/trunk/lib/J3/VMCore/JavaThread.h vmkit/trunk/lib/J3/VMCore/JavaTypes.h vmkit/trunk/lib/J3/VMCore/Jni.cpp vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp vmkit/trunk/lib/J3/VMCore/JnjvmConfig.h vmkit/trunk/lib/J3/VMCore/LinkJavaRuntime.h vmkit/trunk/lib/J3/VMCore/ReferenceQueue.h vmkit/trunk/lib/J3/VMCore/VirtualTables.cpp vmkit/trunk/tools/vmjc/vmjc.cpp Modified: vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp?rev=134313&r1=134312&r2=134313&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp Sat Jul 2 05:47:10 2011 @@ -38,10 +38,6 @@ VTType = PointerType::getUnqual(module->getTypeByName("VT")); LLVMContext& Context = module->getContext(); -#ifdef ISOLATE_SHARING - JnjvmType = - PointerType::getUnqual(module->getTypeByName("Jnjvm")); -#endif ConstantPoolType = ptrPtrType; JavaObjectType = @@ -222,23 +218,7 @@ GetFinalFloatFieldFunction = module->getFunction("getFinalFloatField"); GetFinalDoubleFieldFunction = module->getFunction("getFinalDoubleField"); -#ifdef ISOLATE_SHARING - GetCtpClassFunction = module->getFunction("getCtpClass"); - GetJnjvmExceptionClassFunction = - module->getFunction("getJnjvmExceptionClass"); - GetJnjvmArrayClassFunction = module->getFunction("getJnjvmArrayClass"); - StaticCtpLookupFunction = module->getFunction("j3StaticCtpLookup"); - SpecialCtpLookupFunction = module->getFunction("j3SpecialCtpLookup"); -#endif - -#ifdef SERVICE - ServiceCallStartFunction = module->getFunction("j3ServiceCallStart"); - ServiceCallStopFunction = module->getFunction("j3ServiceCallStop"); -#endif - -#ifndef WITHOUT_VTABLE VirtualLookupFunction = module->getFunction("j3VirtualTableLookup"); -#endif GetLockFunction = module->getFunction("getLock"); ThrowExceptionFromJITFunction = Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=134313&r1=134312&r2=134313&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Sat Jul 2 05:47:10 2011 @@ -228,10 +228,6 @@ } Constant* JavaAOTCompiler::getJavaClassPtr(CommonClass* cl) { -#ifdef ISOLATE - abort(); - return 0; -#else // Make sure it's emitted. getJavaClass(cl); @@ -248,7 +244,6 @@ Constant* Ptr = ConstantExpr::getGetElementPtr(TCMArray, GEP2, 2); return Ptr; -#endif } JavaObject* JavaAOTCompiler::getFinalObject(llvm::Value* obj) { @@ -476,10 +471,6 @@ } Constant* JavaAOTCompiler::getStaticInstance(Class* classDef) { -#ifdef ISOLATE - assert(0 && "Should not be here"); - abort(); -#endif static_instance_iterator End = staticInstances.end(); static_instance_iterator I = staticInstances.find(classDef); if (I == End) { @@ -1687,37 +1678,6 @@ } -#ifdef SERVICE -Value* JavaAOTCompiler::getIsolate(Jnjvm* isolate, Value* Where) { - llvm::Constant* varGV = 0; - isolate_iterator End = isolates.end(); - isolate_iterator I = isolates.find(isolate); - if (I == End) { - - - Constant* cons = - ConstantExpr::getIntToPtr(ConstantInt::get(Type::getInt64Ty(getLLVMContext()), - uint64_t(isolate)), - ptrType); - - Module& Mod = *getLLVMModule(); - varGV = new GlobalVariable(Mod, ptrType, !staticCompilation, - GlobalValue::ExternalLinkage, - cons, ""); - - isolates.insert(std::make_pair(isolate, varGV)); - } else { - varGV = I->second; - } - if (BasicBlock* BB = dyn_cast(Where)) { - return new LoadInst(varGV, "", BB); - } else { - assert(dyn_cast(Where) && "Wrong use of module"); - return new LoadInst(varGV, "", dyn_cast(Where)); - } -} -#endif - void JavaAOTCompiler::CreateStaticInitializer() { std::vector llvmArgs; @@ -1766,28 +1726,6 @@ } } -#if 0 - // Disable initialization of UTF8s, it makes the Init method too big. - // If we have defined some UTF8s. - if (utf8s.begin() != utf8s.end()) { - llvmArgs.clear(); - llvmArgs.push_back(JavaIntrinsics.ptrType); // class loader - llvmArgs.push_back(utf8s.begin()->second->getType()); // val - FTy = FunctionType::get(Type::getVoidTy(getLLVMContext()), llvmArgs, false); - - Function* AddUTF8 = Function::Create(FTy, GlobalValue::ExternalLinkage, - "vmjcAddUTF8", getLLVMModule()); - - - - for (utf8_iterator i = utf8s.begin(), e = utf8s.end(); i != e; ++i) { - Args[0] = loader; - Args[1] = i->second; - CallInst::Create(AddUTF8, Args, Args + 2, "", currentBlock); - } - } -#endif - for (native_class_iterator i = nativeClasses.begin(), e = nativeClasses.end(); i != e; ++i) { if (isCompiling(i->first)) { Modified: vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp?rev=134313&r1=134312&r2=134313&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp Sat Jul 2 05:47:10 2011 @@ -45,10 +45,6 @@ using namespace llvm; static bool needsInitialisationCheck(Class* cl, Class* compilingClass) { -#ifdef SERVICE - return true; -#else - if (cl->isReadyForCompilation() || (!cl->isInterface() && compilingClass->isAssignableFrom(cl))) { return false; @@ -62,7 +58,6 @@ } return true; -#endif } bool JavaJIT::canBeInlined(JavaMethod* meth) { @@ -135,17 +130,10 @@ Value* indexes2[2]; indexes2[0] = intrinsics->constantZero; -#ifdef ISOLATE_SHARING - Value* indexesCtp; //[3]; -#endif if (meth) { LLVMMethodInfo* LMI = TheCompiler->getMethodInfo(meth); Constant* Offset = LMI->getOffset(); indexes2[1] = Offset; -#ifdef ISOLATE_SHARING - indexesCtp = ConstantInt::get(Type::getInt32Ty(*llvmContext), - Offset->getZExtValue() * -1); -#endif } else { GlobalVariable* GV = new GlobalVariable(*llvmFunction->getParent(), @@ -178,11 +166,6 @@ currentBlock = endResolveVirtual; indexes2[1] = node; -#ifdef ISOLATE_SHARING - Value* mul = BinaryOperator::CreateMul(val, intrinsics->constantMinusOne, - "", currentBlock); - indexesCtp = mul; -#endif } makeArgs(it, index, args, signature->nbArguments + 1); @@ -196,13 +179,6 @@ Value* Func = new LoadInst(FuncPtr, "", currentBlock); Func = new BitCastInst(Func, LSI->getVirtualPtrType(), "", currentBlock); -#ifdef ISOLATE_SHARING - Value* CTP = GetElementPtrInst::Create(VT, indexesCtp, "", currentBlock); - - CTP = new LoadInst(CTP, "", currentBlock); - CTP = new BitCastInst(CTP, intrinsics->ConstantPoolType, "", currentBlock); - args.push_back(CTP); -#endif val = invoke(Func, args, "", currentBlock); if (endBlock) { @@ -396,13 +372,7 @@ uint32 index = 0; if (stat) { -#ifdef ISOLATE_SHARING - Value* val = getClassCtp(); - Value* cl = CallInst::Create(intrinsics->GetClassDelegateePtrFunction, - val, "", currentBlock); -#else Value* cl = TheCompiler->getJavaClassPtr(compilingClass); -#endif nativeArgs.push_back(cl); index = 2; } else { @@ -658,27 +628,6 @@ currentBlock = OK; } -#ifdef ISOLATE_SHARING -Value* JavaJIT::getStaticInstanceCtp() { - Value* cl = getClassCtp(); - Value* indexes[2] = { intrinsics->constantZero, module->constantSeven }; - Value* arg1 = GetElementPtrInst::Create(cl, indexes, indexes + 2, - "", currentBlock); - arg1 = new LoadInst(arg1, "", false, currentBlock); - return arg1; - -} - -Value* JavaJIT::getClassCtp() { - Value* indexes = intrinsics->constantOne; - Value* arg1 = GetElementPtrInst::Create(ctpCache, indexes.begin(), - indexes.end(), "", currentBlock); - arg1 = new LoadInst(arg1, "", false, currentBlock); - arg1 = new BitCastInst(arg1, intrinsics->JavaClassType, "", currentBlock); - return arg1; -} -#endif - void JavaJIT::beginSynchronize() { Value* obj = 0; if (isVirtual(compilingMethod->access)) { @@ -847,15 +796,11 @@ floatStack.push_back(new AllocaInst(Type::getFloatTy(*llvmContext), "", firstBB)); } } - - + uint32 index = 0; uint32 count = 0; -#if defined(ISOLATE_SHARING) - uint32 max = args.size() - 2; -#else uint32 max = args.size(); -#endif + Signdef* sign = compilingMethod->getSignature(); Typedef* const* arguments = sign->getArgumentsType(); uint32 type = 0; @@ -870,7 +815,6 @@ thisObject = objectLocals[0]; } - for (;count < max; ++i, ++index, ++count, ++type) { const Typedef* cur = arguments[type]; @@ -1017,11 +961,8 @@ uint32 index = 0; uint32 count = 0; -#if defined(ISOLATE_SHARING) - uint32 max = func->arg_size() - 2; -#else uint32 max = func->arg_size(); -#endif + Function::arg_iterator i = func->arg_begin(); Signdef* sign = compilingMethod->getSignature(); Typedef* const* arguments = sign->getArgumentsType(); @@ -1073,62 +1014,6 @@ } #endif -#if defined(ISOLATE_SHARING) - ctpCache = i; - Value* addrCtpCache = new AllocaInst(intrinsics->ConstantPoolType, "", - currentBlock); - /// make it volatile to be sure it's on the stack - new StoreInst(ctpCache, addrCtpCache, true, currentBlock); -#endif - - -#if defined(SERVICE) - JnjvmClassLoader* loader = compilingClass->classLoader; - Value* Cmp = 0; - Value* mutatorThreadId = 0; - Value* OldIsolateID = 0; - Value* IsolateIDPtr = 0; - Value* OldIsolate = 0; - Value* NewIsolate = 0; - Value* IsolatePtr = 0; - if (loader != loader->bootstrapLoader && isPublic(compilingMethod->access)) { - mutatorThreadId = getMutatorThreadPtr(); - - IsolateIDPtr = getIsolateIDPtr(mutatorThreadPtr); - const Type* realType = PointerType::getUnqual(intrinsics->pointerSizeType); - IsolateIDPtr = new BitCastInst(IsolateIDPtr, realType, "", - currentBlock); - OldIsolateID = new LoadInst(IsolateIDPtr, "", currentBlock); - - Value* MyID = ConstantInt::get(intrinsics->pointerSizeType, - loader->getIsolate()->IsolateID); - Cmp = new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, OldIsolateID, MyID, - ""); - - BasicBlock* EndBB = createBasicBlock("After service check"); - BasicBlock* ServiceBB = createBasicBlock("Begin service call"); - - BranchInst::Create(EndBB, ServiceBB, Cmp, currentBlock); - - currentBlock = ServiceBB; - - new StoreInst(MyID, IsolateIDPtr, currentBlock); - IsolatePtr = getVMPtr(mutatorThreadId); - - OldIsolate = new LoadInst(IsolatePtr, "", currentBlock); - NewIsolate = intrinsics->getIsolate(loader->getIsolate(), currentBlock); - new StoreInst(NewIsolate, IsolatePtr, currentBlock); - -#if DEBUG - Value* GEP[2] = { OldIsolate, NewIsolate }; - CallInst::Create(intrinsics->ServiceCallStartFunction, GEP, GEP + 2, - "", currentBlock); -#endif - BranchInst::Create(EndBB, currentBlock); - currentBlock = EndBB; - } -#endif - readExceptionTable(reader, codeLen); reader.cursor = start; @@ -1223,28 +1108,6 @@ } #endif -#if defined(SERVICE) - if (Cmp) { - BasicBlock* EndBB = createBasicBlock("After service check"); - BasicBlock* ServiceBB = createBasicBlock("End Service call"); - - BranchInst::Create(EndBB, ServiceBB, Cmp, currentBlock); - - currentBlock = ServiceBB; - - new StoreInst(OldIsolateID, IsolateIDPtr, currentBlock); - new StoreInst(OldIsolate, IsolatePtr, currentBlock); - -#if DEBUG - Value* GEP[2] = { OldIsolate, NewIsolate }; - CallInst::Create(intrinsics->ServiceCallStopFunction, GEP, GEP + 2, - "", currentBlock); -#endif - BranchInst::Create(EndBB, currentBlock); - currentBlock = EndBB; - } -#endif - PI = pred_begin(currentBlock); PE = pred_end(currentBlock); if (PI == PE) { @@ -1285,10 +1148,9 @@ UTF8Buffer(compilingClass->name).cString(), UTF8Buffer(compilingMethod->name).cString()); -#ifndef DWARF_EXCEPTIONS - if (codeLen < 5 && !callsStackWalker && !TheCompiler->isStaticCompiling()) + if (codeLen < 5 && !callsStackWalker && !TheCompiler->isStaticCompiling()) { compilingMethod->canBeInlined = false; -#endif + } Attribut* annotationsAtt = compilingMethod->lookupAttribut(Attribut::annotationsAttribut); @@ -1333,10 +1195,6 @@ uint8 type = ctpInfo->typeAt(index); if (type == JavaConstantPool::ConstantString) { -#if defined(ISOLATE) - abort(); -#else - if (TheCompiler->isStaticCompiling()) { const UTF8* utf8 = ctpInfo->UTF8At(ctpInfo->ctpDef[index]); JavaString* str = *(compilingClass->classLoader->UTF8ToStr(utf8)); @@ -1357,7 +1215,6 @@ push(val, false, upcalls->newString); } } -#endif } else if (type == JavaConstantPool::ConstantLong) { push(ConstantInt::get(Type::getInt64Ty(*llvmContext), ctpInfo->LongAt(index)), false); @@ -1441,20 +1298,11 @@ void JavaJIT::makeArgs(FunctionType::param_iterator it, uint32 index, std::vector& Args, uint32 nb) { -#if defined(ISOLATE_SHARING) - nb += 1; -#endif Args.reserve(nb + 2); mvm::ThreadAllocator threadAllocator; Value** args = (Value**)threadAllocator.Allocate(nb*sizeof(Value*)); -#if defined(ISOLATE_SHARING) - args[nb - 1] = isolateLocal; - sint32 start = nb - 2; - it--; - it--; -#else sint32 start = nb - 1; -#endif + for (sint32 i = start; i >= 0; --i) { it--; if (it->get() == Type::getInt64Ty(*llvmContext) || it->get() == Type::getDoubleTy(*llvmContext)) { @@ -1738,18 +1586,9 @@ func = TheCompiler->getMethod(meth); } -#if defined(ISOLATE_SHARING) - Value* newCtpCache = getConstantPoolAt(index, - intrinsics->StaticCtpLookupFunction, - intrinsics->ConstantPoolType, 0, - false); -#endif std::vector args; // size = [signature->nbIn + 2]; FunctionType::param_iterator it = staticType->param_end(); makeArgs(it, index, args, signature->nbArguments); -#if defined(ISOLATE_SHARING) - args.push_back(newCtpCache); -#endif if (className->equals(loader->mathName)) { val = lowerMathOps(name, args); @@ -1784,16 +1623,9 @@ // This makes unswitch loop very unhappy time-wise, but makes GVN happy // number-wise. IMO, it's better to have this than Unswitch. -#ifdef ISOLATE_SHARING - Value* CTP = ctpCache; - Value* Cl = GetElementPtrInst::Create(CTP, intrinsics->ConstantOne, "", - currentBlock); - Cl = new LoadInst(Cl, "", currentBlock); -#else JavaConstantPool* ctp = compilingClass->ctpInfo; Value* CTP = TheCompiler->getConstantPool(ctp); Value* Cl = TheCompiler->getNativeClass(compilingClass); -#endif std::vector Args; Args.push_back(resolver); @@ -1937,18 +1769,11 @@ if (needsCheck) { Cl = invoke(intrinsics->InitialisationCheckFunction, Cl, "", currentBlock); - } -#if !defined(ISOLATE) && !defined(ISOLATE_SHARING) - if (needsCheck) { CallInst::Create(intrinsics->ForceInitialisationCheckFunction, Cl, "", currentBlock); } object = TheCompiler->getStaticInstance(field->classDef); -#else - object = CallInst::Create(intrinsics->GetStaticInstanceFunction, Cl, "", - currentBlock); -#endif } else { object = new LoadInst( object, "", TheCompiler->useCooperativeGC(), currentBlock); @@ -2052,7 +1877,6 @@ Value* ptr = ldResolved(index, true, NULL, LAI.llvmTypePtr); bool final = false; -#if !defined(ISOLATE) && !defined(ISOLATE_SHARING) JnjvmBootstrapLoader* JBL = compilingClass->classLoader->bootstrapLoader; if (!compilingMethod->name->equals(JBL->clinitName)) { JavaField* field = compilingClass->ctpInfo->lookupField(index, true); @@ -2105,7 +1929,6 @@ } } } -#endif if (!final) { JnjvmClassLoader* JCL = compilingClass->classLoader; @@ -2911,7 +2734,6 @@ ex->catche = reader.readU2(); -#ifndef ISOLATE_SHARING if (ex->catche) { UserClass* cl = (UserClass*)(compilingClass->ctpInfo->isClassLoaded(ex->catche)); @@ -2922,7 +2744,6 @@ } else { ex->catchClass = Classpath::newThrowable; } -#endif ex->tester = createBasicBlock("testException"); @@ -2987,34 +2808,6 @@ Value* VTVar = TheCompiler->getVirtualTable(cur->catchClass->virtualVT); - -#ifdef SERVICE - // Verifies that the current isolate is not stopped. If it is, we don't - // catch the exception but resume unwinding. - JnjvmClassLoader* loader = compilingClass->classLoader;; - if (loader != loader->bootstrapLoader) { - Value* Isolate = getVMPtr(getMutatorThread()); - - Isolate = new LoadInst(Isolate, "", currentBlock); - Isolate = new BitCastInst(Isolate, intrinsics->ptrPtrType, "", currentBlock); - Value* Status = GetElementPtrInst::Create(Isolate, intrinsics->constantOne, "", - currentBlock); - Status = new LoadInst(Status, "", currentBlock); - Status = new PtrToIntInst(Status, Type::Int32Ty, "", currentBlock); - - Value* stopping = new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, Status, - intrinsics->constantOne, ""); - - BasicBlock* raiseBlock = createBasicBlock("raiseBlock"); - BasicBlock* continueBlock = createBasicBlock("continueBlock"); - BranchInst::Create(raiseBlock, continueBlock, stopping, currentBlock); - currentBlock = raiseBlock; - BranchInst::Create(endExceptionBlock, currentBlock); - - currentBlock = continueBlock; - } -#endif - // Get the Java exception. Value* obj = currentBlock->begin(); @@ -3068,39 +2861,6 @@ // Clear exceptions. new StoreInst(intrinsics->JavaObjectNullConstant, javaExceptionPtr, currentBlock); - -#if defined(SERVICE) - - // Change the isolate we are currently running, now that we have catched - // the exception: the exception may have been thrown by another isolate. - Value* mutatorThreadId = 0; - Value* OldIsolateID = 0; - Value* IsolateIDPtr = 0; - Value* OldIsolate = 0; - Value* NewIsolate = 0; - Value* IsolatePtr = 0; - currentBlock = cur->javaHandler; - if (loader != loader->bootstrapLoader) { - mutatorThreadId = getGetMutatorThreadPtr(); - IsolateIDPtr = getIsolateIDPtr(mutatorThreadId); - const Type* realType = PointerType::getUnqual(intrinsics->pointerSizeType); - IsolateIDPtr = new BitCastInst(IsolateIDPtr, realType, "", - currentBlock); - OldIsolateID = new LoadInst(IsolateIDPtr, "", currentBlock); - - Value* MyID = ConstantInt::get(intrinsics->pointerSizeType, - loader->getIsolate()->IsolateID); - - new StoreInst(MyID, IsolateIDPtr, currentBlock); - IsolatePtr = getVMPtr(mutatorThreadPtr); - - OldIsolate = new LoadInst(IsolatePtr, "", currentBlock); - NewIsolate = intrinsics->getIsolate(loader->getIsolate(), currentBlock); - new StoreInst(NewIsolate, IsolatePtr, currentBlock); - - } -#endif - } // Restore currentBlock. Modified: vmkit/trunk/lib/J3/Compiler/JavaJIT.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJIT.h?rev=134313&r1=134312&r2=134313&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJIT.h (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJIT.h Sat Jul 2 05:47:10 2011 @@ -508,25 +508,6 @@ //===--------------------- Yield point support ---------------------------===// void checkYieldPoint(); - - -#if defined(ISOLATE_SHARING) -//===----------------- Sharing bytecode support ---------------------------===// - - /// isolateLocal - The Jnjvm object that the method is currently executing. - llvm::Value* isolateLocal; - - /// ctpCache - The constant pool cache. - llvm::Value* ctpCache; - - /// getStaticInstanceCtp - Get the static instance of the class of the method - /// being compiled. - llvm::Value* getStaticInstanceCtp(); - - /// getClassCtp - Get the class of the method being compiled. - llvm::Value* getClassCtp(); -#endif - }; enum Opcode { Modified: vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp?rev=134313&r1=134312&r2=134313&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp Sat Jul 2 05:47:10 2011 @@ -154,10 +154,6 @@ } Constant* JavaJITCompiler::getStaticInstance(Class* classDef) { -#ifdef ISOLATE - assert(0 && "Should not be here"); - abort(); -#endif void* obj = classDef->getStaticInstance(); if (!obj) { classDef->acquire(); @@ -214,14 +210,6 @@ // ~JavaLLVMCompiler will delete the module. } -#ifdef SERVICE -Value* JavaJITCompiler::getIsolate(Jnjvm* isolate, Value* Where) { - ConstantInt* CI = ConstantInt::get(Type::getInt64Ty(getLLVMContext()), - uint64_t(isolate)); - return ConstantExpr::getIntToPtr(CI, JavaIntrinsics.ptrType); -} -#endif - void JavaJITCompiler::makeVT(Class* cl) { JavaVirtualTable* VT = cl->virtualVT; assert(VT && "No VT was allocated!"); Modified: vmkit/trunk/lib/J3/Compiler/LowerConstantCalls.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/LowerConstantCalls.cpp?rev=134313&r1=134312&r2=134313&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/LowerConstantCalls.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/LowerConstantCalls.cpp Sat Jul 2 05:47:10 2011 @@ -36,65 +36,6 @@ }; char LowerConstantCalls::ID = 0; -#if 0 - static RegisterPass X("LowerConstantCalls", - "Lower Constant calls"); -#endif - - -#ifdef ISOLATE -static Value* getTCM(J3Intrinsics* intrinsics, Value* Arg, Instruction* CI) { - Value* GEP[2] = { intrinsics->constantZero, - intrinsics->OffsetTaskClassMirrorInClassConstant }; - Value* TCMArray = GetElementPtrInst::Create(Arg, GEP, GEP + 2, "", CI); - - Value* threadId = CallInst::Create(intrinsics->llvm_frameaddress, - intrinsics->constantZero, "", CI); - threadId = new PtrToIntInst(threadId, intrinsics->pointerSizeType, "", CI); - threadId = BinaryOperator::CreateAnd(threadId, intrinsics->constantThreadIDMask, - "", CI); - - threadId = new IntToPtrInst(threadId, intrinsics->ptr32Type, "", CI); - - Value* GEP1[2] = { intrinsics->OffsetThreadInMutatorThreadConstant, intrinsics->OffsetIsolateInThreadConstant } - Value* IsolateID = GetElementPtrInst::Create(threadId, GEP1, GEP1 + 2, "", CI); - - IsolateID = new LoadInst(IsolateID, "", CI); - - Value* GEP2[2] = { intrinsics->constantZero, IsolateID }; - - Value* TCM = GetElementPtrInst::Create(TCMArray, GEP2, GEP2 + 2, "", - CI); - return TCM; -} - -static Value* getDelegatee(J3Intrinsics* intrinsics, Value* Arg, Instruction* CI) { - Value* GEP[2] = { intrinsics->constantZero, - intrinsics->constantTwo }; - Value* TCMArray = GetElementPtrInst::Create(Arg, GEP, GEP + 2, "", CI); - - Value* threadId = CallInst::Create(intrinsics->llvm_frameaddress, - intrinsics->constantZero, "", CI); - threadId = new PtrToIntInst(threadId, intrinsics->pointerSizeType, "", CI); - threadId = BinaryOperator::CreateAnd(threadId, intrinsics->constantThreadIDMask, - "", CI); - - threadId = new IntToPtrInst(threadId, intrinsics->ptr32Type, "", CI); - - Value* GEP1[2] = { intrinsics->OffsetThreadInMutatorThreadConstant, intrinsics->OffsetIsolateInThreadConstant } - Value* IsolateID = GetElementPtrInst::Create(threadId, GEP1, GEP1 + 2, "", CI); - - IsolateID = new LoadInst(IsolateID, "", CI); - - Value* GEP2[2] = { intrinsics->constantZero, IsolateID }; - - Value* TCM = GetElementPtrInst::Create(TCMArray, GEP2, GEP2 + 2, "", - CI); - return new LoadInst(TCM, "", CI); -} - -#else - static Value* getTCM(J3Intrinsics* intrinsics, Value* Arg, Instruction* CI) { Value* GEP[2] = { intrinsics->constantZero, intrinsics->OffsetTaskClassMirrorInClassConstant }; @@ -120,7 +61,6 @@ return new LoadInst(TCM, "", CI); } -#endif bool LowerConstantCalls::runOnFunction(Function& F) { LLVMContext* Context = &F.getContext(); @@ -489,14 +429,7 @@ NBB = Invoke->getNormalDest(); } -#ifdef ISOLATE_SHARING - ConstantInt* Cons = dyn_cast(Index); - assert(CI && "Wrong use of GetConstantPoolAt"); - uint64 val = Cons->getZExtValue(); - Value* indexes = ConstantInt::get(Type::getInt32Ty(*Context), val + 1); -#else Value* indexes = Index; -#endif Value* arg1 = GetElementPtrInst::Create(CTP, indexes, "", CI); arg1 = new LoadInst(arg1, "", false, CI); Value* test = new ICmpInst(CI, ICmpInst::ICMP_EQ, arg1, @@ -767,40 +700,6 @@ // And reanalyse the current block. break; } -#ifdef ISOLATE_SHARING - else if (V == intrinsics->GetCtpClassFunction) { - Changed = true; - Value* val = Call.getArgument(0); - Value* indexes[2] = { intrinsics->constantZero, - intrinsics->OffsetCtpInClassConstant }; - Value* VTPtr = GetElementPtrInst::Create(val, indexes, - indexes + 2, "", CI); - Value* VT = new LoadInst(VTPtr, "", CI); - CI->replaceAllUsesWith(VT); - CI->eraseFromParent(); - } else if (V == intrinsics->GetJnjvmArrayClassFunction) { - Changed = true; - Value* val = Call.getArgument(0); - Value* index = Call.getArgument(1); - Value* indexes[3] = { intrinsics->constantZero, intrinsics->constantTwo, - index }; - Value* VTPtr = GetElementPtrInst::Create(val, indexes, indexes + 3, - "", CI); - Value* VT = new LoadInst(VTPtr, "", CI); - CI->replaceAllUsesWith(VT); - CI->eraseFromParent(); - } else if (V == intrinsics->GetJnjvmExceptionClassFunction) { - Changed = true; - Value* val = Call.getArgument(0); - Value* indexes[2] = { intrinsics->constantZero, intrinsics->constantOne }; - Value* VTPtr = GetElementPtrInst::Create(val, indexes, indexes + 2, - "", CI); - Value* VT = new LoadInst(VTPtr, "", CI); - CI->replaceAllUsesWith(VT); - CI->eraseFromParent(); - } -#endif - } } } Removed: vmkit/trunk/lib/J3/LLVMRuntime/runtime-default-thread.ll URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/LLVMRuntime/runtime-default-thread.ll?rev=134312&view=auto ============================================================================== --- vmkit/trunk/lib/J3/LLVMRuntime/runtime-default-thread.ll (original) +++ vmkit/trunk/lib/J3/LLVMRuntime/runtime-default-thread.ll (removed) @@ -1,2 +0,0 @@ -;;; Field 0: the thread -%MutatorThread = type { %Thread } Removed: vmkit/trunk/lib/J3/LLVMRuntime/runtime-isolate.ll URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/LLVMRuntime/runtime-isolate.ll?rev=134312&view=auto ============================================================================== --- vmkit/trunk/lib/J3/LLVMRuntime/runtime-isolate.ll (original) +++ vmkit/trunk/lib/J3/LLVMRuntime/runtime-isolate.ll (removed) @@ -1,46 +0,0 @@ -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;;;;;;;;;;;;;;;;;;;;;;;; Isolate specific types ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -%Jnjvm = type { %VT*, %JavaClass*, [9 x %JavaClass*] } - -%JavaCommonClass = type { [32 x %JavaObject*], - i16, %JavaClass**, i16, %UTF8*, %JavaClass*, i8*, - %VT* } - - -%JavaClass = type { %JavaCommonClass, i32, i32, [32 x %TaskClassMirror], - %JavaField*, i16, %JavaField*, i16, %JavaMethod*, i16, - %JavaMethod*, i16, i8*, %ArrayUInt8*, i8*, %Attribut*, - i16, %JavaClass**, i16, %JavaClass*, i16, i8, i8, i32, i32 } - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;;;;;;;;;;;;;;;;;;;;;;; Isolate specific methods ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -;;; j3EnveloppeLookup - Find the enveloppe for the current user class. -declare i8* @j3EnveloppeLookup(%JavaClass*, i32, ...) readnone - -;;; j3StaticCtpLookup - Find the user constant pool at the given offset in -;;; the constant pool. -declare i8* @j3StaticCtpLookup(%JavaClass*, i32, ...) readnone - -;;; j3SpecialCtpLookup - Find the user constant pool at the given offset in -;;; the constant pool. -declare i8** @j3SpecialCtpLookup(i8**, i32, i8**) readnone - -;;; getCtpCacheNode - Get the constant pool cache of a cache node. This is a -;;; constant call because the cache node never changes. -declare i8** @getCtpCacheNode(%CacheNode*) readnone - -;;; getCtpCacheNode - Get the constant pool cache of a class. This is a -;;; constant call because the constant pool never changes. -declare i8** @getCtpClass(%JavaClass*) readnone - -;;; getJnjvmExceptionClass - Get the exception user class for the given -;;; isolate. -declare %JavaClass* @getJnjvmExceptionClass(%Jnjvm*) readnone - -;;; getJnjvmArrayClass - Get the array user class of the index, for the given -;;; isolate. -declare %JavaClass* @getJnjvmArrayClass(%Jnjvm*, i32) readnone Removed: vmkit/trunk/lib/J3/LLVMRuntime/runtime-service.ll URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/LLVMRuntime/runtime-service.ll?rev=134312&view=auto ============================================================================== --- vmkit/trunk/lib/J3/LLVMRuntime/runtime-service.ll (original) +++ vmkit/trunk/lib/J3/LLVMRuntime/runtime-service.ll (removed) @@ -1,9 +0,0 @@ -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;;;;;;;;;;;;;;;;;;;;;;; Service specific methods ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -;;; j3ServiceCallStart - Mark the switching between services. -declare void @j3ServiceCallStart(i8*, i8*) - -;;; j3ServiceCallStop - Mark the switching between services. -declare void @j3ServiceCallStop(i8*, i8*) Modified: vmkit/trunk/lib/J3/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaClass.cpp?rev=134313&r1=134312&r2=134313&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JavaClass.cpp Sat Jul 2 05:47:10 2011 @@ -135,14 +135,12 @@ } } -JavaMethod::~JavaMethod() { - +JavaMethod::~JavaMethod() { for (uint32 i = 0; i < nbAttributs; ++i) { Attribut* cur = &(attributs[i]); cur->~Attribut(); classDef->classLoader->allocator.Deallocate(cur); } - } UserClassPrimitive* CommonClass::toPrimitive(Jnjvm* vm) const { @@ -271,18 +269,9 @@ } void* JavaMethod::compiledPtr() { - if (code != 0) return code; - else { -#ifdef SERVICE - Jnjvm *vm = classDef->classLoader->getIsolate(); - if (vm && vm->status == 0) { - JavaThread* th = JavaThread::get(); - th->throwException(th->ServiceException); - } -#endif + if (code == 0) { code = classDef->classLoader->getCompiler()->materializeFunction(this); } - return code; } @@ -922,12 +911,6 @@ interfaces[i]->resolveClass(); } -#ifndef ISOLATE_SHARING -#ifdef ISOLATE -void Class::resolveClass() { - UNIMPLEMENTED(); -} -#else void Class::resolveClass() { if (isResolved() || isErroneous()) return; resolveParents(); @@ -937,13 +920,6 @@ &(getCurrentTaskClassMirror().status), loaded, resolved); assert(isResolved() || isErroneous()); } -#endif -#else -void Class::resolveClass() { - assert(status >= resolved && - "Asking to resolve a not resolved-class in a isolate environment"); -} -#endif void UserClass::resolveInnerOuterClasses() { if (!innerOuterResolved) { @@ -1043,32 +1019,6 @@ } -#ifdef ISOLATE -TaskClassMirror& Class::getCurrentTaskClassMirror() { - return IsolateInfo[JavaThread::get()->getJVM()->IsolateID]; -} - -JavaObject* CommonClass::getDelegatee() { - return delegatee[JavaThread::get()->getJVM()->IsolateID]; -} - -JavaObject** CommonClass::getDelegateePtr() { - return &(delegatee[JavaThread::get()->getJVM()->IsolateID]); -} - -JavaObject* CommonClass::setDelegatee(JavaObject* val) { - llvm_gcroot(val, 0); - JavaObject** obj = &(delegatee[JavaThread::get()->getJVM()->IsolateID]); - classLoader->lock.lock(); - if (*obj == NULL) { - mvm::Collector::objectReferenceNonHeapWriteBarrier((gc**)obj, (gc*)val); - } - classLoader->lock.unlock(); - return getDelegatee(); -} - -#else - JavaObject* CommonClass::setDelegatee(JavaObject* val) { llvm_gcroot(val, 0); JavaObject** obj = &(delegatee[0]); @@ -1080,9 +1030,6 @@ return getDelegatee(); } -#endif - - UserCommonClass* UserCommonClass::resolvedImplClass(Jnjvm* vm, JavaObject* clazz, @@ -1099,6 +1046,7 @@ return cl; } + void JavaMethod::jniConsFromMeth(char* buf, const UTF8* jniConsClName, const UTF8* jniConsName, const UTF8* jniConsType, @@ -1272,8 +1220,8 @@ } -bool UserClass::isNativeOverloaded(JavaMethod* meth) { - + +bool UserClass::isNativeOverloaded(JavaMethod* meth) { for (uint32 i = 0; i < nbVirtualMethods; ++i) { JavaMethod& cur = virtualMethods[i]; if (&cur != meth && isNative(cur.access) && cur.name->equals(meth->name)) @@ -1290,8 +1238,7 @@ } -ArrayUInt16* JavaMethod::toString() const { - +ArrayUInt16* JavaMethod::toString() const { Jnjvm* vm = JavaThread::get()->getJVM(); uint32 size = classDef->name->size + name->size + type->size + 1; ArrayUInt16* res = (ArrayUInt16*)vm->upcalls->ArrayOfChar->doNew(size, vm); @@ -1324,6 +1271,7 @@ return res; } + bool UserClass::needsInitialisationCheck() { if (isReady()) return false; @@ -1344,6 +1292,7 @@ return false; } + void ClassArray::initialiseVT(Class* javaLangObject) { ClassArray::SuperArray = javaLangObject; Modified: vmkit/trunk/lib/J3/VMCore/JavaClass.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaClass.h?rev=134313&r1=134312&r2=134313&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaClass.h (original) +++ vmkit/trunk/lib/J3/VMCore/JavaClass.h Sat Jul 2 05:47:10 2011 @@ -158,9 +158,6 @@ /// super or interfaces. /// class CommonClass : public mvm::PermanentObject { -#ifdef ISOLATE_SHARING -friend class UserCommonClass; -#endif public: @@ -342,7 +339,6 @@ /// JavaObject* setDelegatee(JavaObject* val); -#if !defined(ISOLATE) && !defined(ISOLATE_SHARING) /// getDelegatee - Get the java/lang/Class object representing this class. /// JavaObject* getDelegatee() const { @@ -356,13 +352,6 @@ return delegatee; } -#else -#if defined(ISOLATE) - JavaObject* getDelegatee(); - JavaObject** getDelegateePtr(); -#endif -#endif - /// resolvedImplClass - Return the internal representation of the /// java.lang.Class object. The class must be resolved. // @@ -593,11 +582,9 @@ return staticSize; } -#ifndef ISOLATE_SHARING /// doNew - Allocates a Java object whose class is this class. /// JavaObject* doNew(Jnjvm* vm); -#endif /// tracer - Tracer function of instances of Class. /// @@ -686,8 +673,6 @@ /// void broadcastClass(); -#ifndef ISOLATE - /// getCurrentTaskClassMirror - Get the class task mirror of the executing /// isolate. /// @@ -719,35 +704,6 @@ getCurrentTaskClassMirror().status = resolving; } - -#else - - TaskClassMirror& getCurrentTaskClassMirror(); - - bool isReadyForCompilation() { - return false; - } - - void setResolved() { - for (uint32 i = 0; i < NR_ISOLATES; ++i) { - IsolateInfo[i].status = resolved; - } - } - - void setIsResolving() { - for (uint32 i = 0; i < NR_ISOLATES; ++i) { - IsolateInfo[i].status = resolving; - } - } - - void setErroneous() { - for (uint32 i = 0; i < NR_ISOLATES; ++i) { - IsolateInfo[i].status = erroneous; - } - } - -#endif - /// getStaticInstance - Get the memory that holds static variables. /// void* getStaticInstance() { @@ -1349,9 +1305,4 @@ } // end namespace j3 - -#ifdef ISOLATE_SHARING -#include "IsolateCommonClass.h" -#endif - #endif Modified: vmkit/trunk/lib/J3/VMCore/JavaConstantPool.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaConstantPool.cpp?rev=134313&r1=134312&r2=134313&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaConstantPool.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JavaConstantPool.cpp Sat Jul 2 05:47:10 2011 @@ -9,7 +9,6 @@ #define JNJVM_LOAD 0 -#include #include #include @@ -282,7 +281,6 @@ CommonClass* JavaConstantPool::loadClass(uint32 index, bool resolve) { CommonClass* temp = isClassLoaded(index); -#ifndef ISOLATE_SHARING if (!temp) { JnjvmClassLoader* loader = classDef->classLoader; const UTF8* name = UTF8At(ctpDef[index]); @@ -293,20 +291,17 @@ } ctpRes[index] = temp; } -#endif return temp; } CommonClass* JavaConstantPool::getMethodClassIfLoaded(uint32 index) { CommonClass* temp = isClassLoaded(index); -#ifndef ISOLATE_SHARING if (!temp) { JnjvmClassLoader* loader = classDef->classLoader; assert(loader && "Class has no loader?"); const UTF8* name = UTF8At(ctpDef[index]); temp = loader->lookupClassOrArray(name); } -#endif if (!temp && classDef->classLoader->getCompiler()->isStaticCompiling()) { temp = loadClass(index); @@ -504,13 +499,10 @@ if (field) { if (!stat) { ctpRes[index] = (void*)field->ptrOffset; - } -#ifndef ISOLATE_SHARING - else if (lookup->isReady()) { + } else if (lookup->isReady()) { void* S = field->classDef->getStaticInstance(); ctpRes[index] = (void*)((uint64)S + field->ptrOffset); } -#endif } return field; } Modified: vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp?rev=134313&r1=134312&r2=134313&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp Sat Jul 2 05:47:10 2011 @@ -138,7 +138,6 @@ return res; } -#ifndef WITHOUT_VTABLE // Throws if the method is not found. extern "C" uint32 j3VirtualTableLookup(UserClass* caller, uint32 index, uint32* offset, JavaObject* obj) { @@ -169,10 +168,8 @@ *offset = dmeth->offset; } -#if !defined(ISOLATE_SHARING) && !defined(SERVICE) assert(dmeth->classDef->isInitializing() && "Class not ready in a virtual lookup."); -#endif res = dmeth->offset; @@ -180,7 +177,6 @@ return res; } -#endif // Throws if the class is not found. extern "C" void* j3ClassLookup(UserClass* caller, uint32 index) { @@ -546,9 +542,7 @@ UserConstantPool* ctpInfo = cl->getConstantPool(); const UTF8* utf8 = ctpInfo->UTF8At(ctpInfo->ctpDef[index]); str = cl->classLoader->UTF8ToStr(utf8); -#if defined(ISOLATE_SHARING) || !defined(ISOLATE) ctpInfo->ctpRes[index] = str; -#endif END_NATIVE_EXCEPTION @@ -591,9 +585,7 @@ // Update the virtual table. assert(lookup->isResolved() && "Class not resolved"); -#if !defined(ISOLATE_SHARING) && !defined(SERVICE) assert(lookup->isInitializing() && "Class not ready"); -#endif assert(lookup->virtualVT && "Class has no VT"); assert(lookup->virtualTableSize > Virt->offset && "The method's offset is greater than the virtual table size"); @@ -741,62 +733,3 @@ UTF8Buffer(meth->name).cString(), OpcodeNames[opcode], index); } - -#ifdef SERVICE - -extern "C" void j3ServiceCallStart(Jnjvm* OldService, - Jnjvm* NewService) { - fprintf(stderr, "I have switched from %d to %d\n", OldService->IsolateID, - NewService->IsolateID); - - fprintf(stderr, "Now the thread id is %d\n", mvm::Thread::get()->IsolateID); -} - -extern "C" void j3ServiceCallStop(Jnjvm* OldService, - Jnjvm* NewService) { - fprintf(stderr, "End service call\n"); -} - -#endif - - -#ifdef ISOLATE_SHARING -extern "C" void* j3StaticCtpLookup(UserClass* cl, uint32 index) { - UserConstantPool* ctpInfo = cl->getConstantPool(); - JavaConstantPool* shared = ctpInfo->getSharedPool(); - uint32 clIndex = shared->getClassIndexFromMethod(index); - UserClass* refCl = (UserClass*)ctpInfo->loadClass(clIndex); - refCl->initialiseClass(JavaThread::get()->getJVM()); - - CommonClass* baseCl = 0; - const UTF8* utf8 = 0; - Signdef* sign = 0; - - shared->resolveMethod(index, baseCl, utf8, sign); - UserClass* methodCl = 0; - refCl->lookupMethod(utf8, sign->keyName, true, true, &methodCl); - ctpInfo->ctpRes[index] = methodCl->getConstantPool(); - shared->ctpRes[clIndex] = refCl->classDef; - return (void*)methodCl->getConstantPool(); -} - -extern "C" UserConstantPool* j3SpecialCtpLookup(UserConstantPool* ctpInfo, - uint32 index, - UserConstantPool** res) { - JavaConstantPool* shared = ctpInfo->getSharedPool(); - uint32 clIndex = shared->getClassIndexFromMethod(index); - UserClass* refCl = (UserClass*)ctpInfo->loadClass(clIndex); - - CommonClass* baseCl = 0; - const UTF8* utf8 = 0; - Signdef* sign = 0; - - shared->resolveMethod(index, baseCl, utf8, sign); - UserClass* methodCl = 0; - refCl->lookupMethod(utf8, sign->keyName, false, true, &methodCl); - shared->ctpRes[clIndex] = refCl->classDef; - *res = methodCl->getConstantPool(); - return methodCl->getConstantPool(); -} - -#endif Modified: vmkit/trunk/lib/J3/VMCore/JavaThread.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaThread.cpp?rev=134313&r1=134312&r2=134313&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaThread.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JavaThread.cpp Sat Jul 2 05:47:10 2011 @@ -27,14 +27,6 @@ currentAddedReferences = NULL; javaThread = NULL; vmThread = NULL; - -#ifdef SERVICE - eipIndex = 0; - replacedEIPs = new void*[100]; - if (isolate->upcalls->newThrowable) { - ServiceException = isolate->upcalls->newThrowable->doNew(isolate); - } -#endif } void JavaThread::initialise(JavaObject* thread, JavaObject* vmth) { @@ -46,9 +38,6 @@ JavaThread::~JavaThread() { delete localJNIRefs; -#ifdef SERVICE - delete replacedEIPs; -#endif } void JavaThread::throwException(JavaObject* obj) { Modified: vmkit/trunk/lib/J3/VMCore/JavaThread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaThread.h?rev=134313&r1=134312&r2=134313&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaThread.h (original) +++ vmkit/trunk/lib/J3/VMCore/JavaThread.h Sat Jul 2 05:47:10 2011 @@ -112,9 +112,6 @@ /// JavaThread - Empty constructor, used to get the VT. /// JavaThread() { -#ifdef SERVICE - replacedEIPs = 0; -#endif } /// ~JavaThread - Delete any potential malloc'ed objects used by this thread. @@ -221,25 +218,6 @@ virtual void internalClearException() { pendingException = NULL; } - -public: - -#ifdef SERVICE - /// ServiceException - The exception that will be thrown if a bundle is - /// stopped. - JavaObject* ServiceException; - - /// replacedEIPs - List of instruction pointers which must be replaced - /// to a function that throws an exception. We maintain this list and update - /// the stack correctly so that Dwarf unwinding does not complain. - /// - void** replacedEIPs; - - /// eipIndex - The current index in the replacedIPs list. - /// - uint32_t eipIndex; -#endif - }; } // end namespace j3 Modified: vmkit/trunk/lib/J3/VMCore/JavaTypes.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaTypes.h?rev=134313&r1=134312&r2=134313&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaTypes.h (original) +++ vmkit/trunk/lib/J3/VMCore/JavaTypes.h Sat Jul 2 05:47:10 2011 @@ -423,16 +423,13 @@ } private: - + /// arguments - The list of arguments of the signature. First is the return /// type. /// Typedef* arguments[1]; - - }; - } // end namespace j3 #endif Modified: vmkit/trunk/lib/J3/VMCore/Jni.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Jni.cpp?rev=134313&r1=134312&r2=134313&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/Jni.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/Jni.cpp Sat Jul 2 05:47:10 2011 @@ -29,21 +29,13 @@ UserClass* getClassFromStaticMethod(Jnjvm* vm, JavaMethod* meth, JavaObject* clazz) { llvm_gcroot(clazz, 0); -#ifdef ISOLATE_SHARING - return (UserClass*)UserCommonClass::resolvedImplClass(vm, clazz, false); -#else return meth->classDef; -#endif } static UserClass* getClassFromVirtualMethod(Jnjvm* vm, JavaMethod* meth, UserCommonClass* cl) { -#ifdef ISOLATE_SHARING - return cl->lookupClassFromMethod(this); -#else return meth->classDef; -#endif } extern "C" const struct JNIInvokeInterface_ JNI_JavaVMTable; Modified: vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp?rev=134313&r1=134312&r2=134313&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp Sat Jul 2 05:47:10 2011 @@ -216,11 +216,7 @@ clinitType = asciizConstructUTF8("()V"); runName = asciizConstructUTF8("run"); prelib = asciizConstructUTF8("lib"); -#if defined(__MACH__) - postlib = asciizConstructUTF8(".dylib"); -#else - postlib = asciizConstructUTF8(".so"); -#endif + postlib = asciizConstructUTF8(DYLD_EXTENSION); mathName = asciizConstructUTF8("java/lang/Math"); stackWalkerName = asciizConstructUTF8("gnu/classpath/VMStackWalker"); NoClassDefFoundError = asciizConstructUTF8("java/lang/NoClassDefFoundError"); @@ -283,28 +279,6 @@ JavaObject::getClass(loader)->asClass()->lookupMethodDontThrow( meth->name, meth->type, false, true, &loadClass); assert(loadClass && "Loader does not have a loadClass function"); - -#if defined(SERVICE) - /// If the appClassLoader is already set in the isolate, then we need - /// a new one each time a class loader is allocated. - if (isolate->appClassLoader) { - isolate = new Jnjvm(allocator, bootstrapLoader); - isolate->memoryLimit = 4000000; - isolate->threadLimit = 10; - isolate->parent = I->parent; - isolate->CU = this; - mvm::Thread* th = mvm::Thread::get(); - mvm::VirtualMachine* OldVM = th->MyVM; - th->MyVM = isolate; - th->IsolateID = isolate->IsolateID; - - isolate->loadBootstrap(); - - th->MyVM = OldVM; - th->IsolateID = OldVM->IsolateID; - } -#endif - } void JnjvmClassLoader::setCompiler(JavaCompiler* Comp) { Modified: vmkit/trunk/lib/J3/VMCore/JnjvmConfig.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JnjvmConfig.h?rev=134313&r1=134312&r2=134313&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JnjvmConfig.h (original) +++ vmkit/trunk/lib/J3/VMCore/JnjvmConfig.h Sat Jul 2 05:47:10 2011 @@ -11,10 +11,6 @@ #ifndef JNJVM_CONFIG_H #define JNJVM_CONFIG_H -#ifdef ISOLATE_SHARING -#define ISOLATE_STATIC -#else - namespace j3 { class ClassArray; @@ -31,13 +27,7 @@ } #define ISOLATE_STATIC static -#endif - -#ifdef ISOLATE -#define NR_ISOLATES 32 -#else #define NR_ISOLATES 1 -#endif #endif // JNJVM_CONFIG_H Modified: vmkit/trunk/lib/J3/VMCore/LinkJavaRuntime.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/LinkJavaRuntime.h?rev=134313&r1=134312&r2=134313&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/LinkJavaRuntime.h (original) +++ vmkit/trunk/lib/J3/VMCore/LinkJavaRuntime.h Sat Jul 2 05:47:10 2011 @@ -61,29 +61,10 @@ extern "C" void j3PrintExecution(uint32 opcode, uint32 index, JavaMethod* meth); - -#ifdef SERVICE -extern "C" void j3ServiceCallStart(Jnjvm* OldService, - Jnjvm* NewService); -extern "C" void j3ServiceCallStop(Jnjvm* OldService, - Jnjvm* NewService); -#endif - - - - -#ifdef ISOLATE_SHARING -extern "C" void* j3StaticCtpLookup(UserClass* cl, uint32 index); -extern "C" UserConstantPool* j3SpecialCtpLookup(UserConstantPool* ctpInfo, - uint32 index, - UserConstantPool** res); -#endif - - namespace force_linker { struct ForceRuntimeLinking { ForceRuntimeLinking() { - // We must reference the passes in such a way that compilers will not + // We must reference the methods in such a way that compilers will not // delete it all as dead code, even with whole program optimization, // yet is effectively a NO-OP. As the compiler isn't smart enough // to know that getenv() never returns -1, this will do the job. @@ -117,16 +98,6 @@ (void) j3PrintMethodEnd(0); (void) j3PrintExecution(0, 0, 0); (void) j3StringLookup(0, 0); -#ifdef SERVICE - (void) j3ServiceCallStart(0, 0); - (void) j3ServiceCallStop(0, 0); -#endif - -#ifdef ISOLATE_SHARING - (void) j3StaticCtpLookup(0, 0); - (void) j3SpecialCtpLookup(0, 0, 0); -#endif - } } ForcePassLinking; // Force link by creating a global definition. } Modified: vmkit/trunk/lib/J3/VMCore/ReferenceQueue.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/ReferenceQueue.h?rev=134313&r1=134312&r2=134313&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/ReferenceQueue.h (original) +++ vmkit/trunk/lib/J3/VMCore/ReferenceQueue.h Sat Jul 2 05:47:10 2011 @@ -205,7 +205,6 @@ delete[] FinalizationQueue; delete[] ToBeFinalized; } - }; } // namespace j3 Modified: vmkit/trunk/lib/J3/VMCore/VirtualTables.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/VirtualTables.cpp?rev=134313&r1=134312&r2=134313&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/VirtualTables.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/VirtualTables.cpp Sat Jul 2 05:47:10 2011 @@ -7,9 +7,7 @@ // //===----------------------------------------------------------------------===// // -// This file contains GC specific tracing functions. It is used by the -// GCMmap2 garbage collector and may be of use for other GCs. Boehm GC does -// not use these functions. +// This file contains GC specific tracing functions. // // The file is divided into four parts: // (1) Declaration of internal GC classes. Modified: vmkit/trunk/tools/vmjc/vmjc.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/vmjc/vmjc.cpp?rev=134313&r1=134312&r2=134313&view=diff ============================================================================== --- vmkit/trunk/tools/vmjc/vmjc.cpp (original) +++ vmkit/trunk/tools/vmjc/vmjc.cpp Sat Jul 2 05:47:10 2011 @@ -139,60 +139,7 @@ return 0; } - // Disable cross-compiling for now. - if (false) { - Module* TheModule = new Module("bootstrap module", - *(new llvm::LLVMContext())); - if (!TargetTriple.empty()) - TheModule->setTargetTriple(TargetTriple); - else - TheModule->setTargetTriple(mvm::MvmModule::getHostTriple()); - -#if 0 - // explicitly specified an architecture to compile for. - const Target *TheTarget = 0; - if (!MArch.empty()) { - for (TargetRegistry::iterator it = TargetRegistry::begin(), - ie = TargetRegistry::end(); it != ie; ++it) { - if (MArch == it->getName()) { - TheTarget = &*it; - break; - } - } - - if (!TheTarget) { - errs() << argv[0] << ": error: invalid target '" << MArch << "'.\n"; - return 1; - } - } else { - std::string Err; - TheTarget = - TargetRegistry::getClosestStaticTargetForModule(*TheModule, Err); - if (TheTarget == 0) { - errs() << argv[0] << ": error auto-selecting target for module '" - << Err << "'. Please use the -march option to explicitly " - << "pick a target.\n"; - return 1; - } - } - - std::string FeaturesStr; - std::auto_ptr - target(TheTarget->createTargetMachine(*TheModule, FeaturesStr)); - assert(target.get() && "Could not allocate target machine!"); - TargetMachine &Target = *target.get(); - - // Install information about target datalayout stuff into the module for - // optimizer use. - TheModule->setDataLayout(Target.getTargetData()-> - getStringRepresentation()); - - - mvm::MvmModule::initialise(CodeGenOpt::Default, TheModule, &Target); -#endif - } else { - mvm::MvmModule::initialise(); - } + mvm::MvmModule::initialise(); for (std::vector::iterator i = LoadBytecodeFiles.begin(), e = LoadBytecodeFiles.end(); i != e; ++i) { From nicolas.geoffray at lip6.fr Sat Jul 2 03:47:55 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 02 Jul 2011 10:47:55 -0000 Subject: [vmkit-commits] [vmkit] r134314 - /vmkit/trunk/Makefile.common.in Message-ID: <20110702104755.BC6722A6C12C@llvm.org> Author: geoffray Date: Sat Jul 2 05:47:55 2011 New Revision: 134314 URL: http://llvm.org/viewvc/llvm-project?rev=134314&view=rev Log: Remove reference to PNET. Modified: vmkit/trunk/Makefile.common.in Modified: vmkit/trunk/Makefile.common.in URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/Makefile.common.in?rev=134314&r1=134313&r2=134314&view=diff ============================================================================== --- vmkit/trunk/Makefile.common.in (original) +++ vmkit/trunk/Makefile.common.in Sat Jul 2 05:47:55 2011 @@ -38,9 +38,6 @@ CLASSPATH_FLAGS = GLIBJ = @classpathglibj@ -# Pnet location -PNETLIB = @pnetlocalprefix@ - LIBS += -lz include $(PROJ_SRC_ROOT)/Makefile.rules From nicolas.geoffray at lip6.fr Sat Jul 2 03:49:02 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 02 Jul 2011 10:49:02 -0000 Subject: [vmkit-commits] [vmkit] r134315 - /vmkit/trunk/LICENSE.TXT Message-ID: <20110702104902.4C56B2A6C12C@llvm.org> Author: geoffray Date: Sat Jul 2 05:49:02 2011 New Revision: 134315 URL: http://llvm.org/viewvc/llvm-project?rev=134315&view=rev Log: Add copyright for jni.h Modified: vmkit/trunk/LICENSE.TXT Modified: vmkit/trunk/LICENSE.TXT URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/LICENSE.TXT?rev=134315&r1=134314&r2=134315&view=diff ============================================================================== --- vmkit/trunk/LICENSE.TXT (original) +++ vmkit/trunk/LICENSE.TXT Sat Jul 2 05:49:02 2011 @@ -64,3 +64,4 @@ Mono libraries vmkit/lib/N3/Mono PNetlib libraries vmkit/lib/N3/PNet MMTk vmkit/mmtk/ +JNI vmkit/include/j3/ From nicolas.geoffray at lip6.fr Sat Jul 2 03:50:16 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 02 Jul 2011 10:50:16 -0000 Subject: [vmkit-commits] [vmkit] r134316 - /vmkit/trunk/LICENSE.TXT Message-ID: <20110702105016.230DF2A6C12C@llvm.org> Author: geoffray Date: Sat Jul 2 05:50:15 2011 New Revision: 134316 URL: http://llvm.org/viewvc/llvm-project?rev=134316&view=rev Log: Remove reference to deleted files. Modified: vmkit/trunk/LICENSE.TXT Modified: vmkit/trunk/LICENSE.TXT URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/LICENSE.TXT?rev=134316&r1=134315&r2=134316&view=diff ============================================================================== --- vmkit/trunk/LICENSE.TXT (original) +++ vmkit/trunk/LICENSE.TXT Sat Jul 2 05:50:15 2011 @@ -61,7 +61,5 @@ Program Directory ------- --------- -Mono libraries vmkit/lib/N3/Mono -PNetlib libraries vmkit/lib/N3/PNet MMTk vmkit/mmtk/ JNI vmkit/include/j3/ From nicolas.geoffray at lip6.fr Sat Jul 2 04:12:25 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 02 Jul 2011 11:12:25 -0000 Subject: [vmkit-commits] [vmkit] r134317 - in /vmkit/trunk/lib/J3: Classpath/ClasspathVMRuntime.inc Compiler/JavaJIT.cpp Compiler/LLVMInfo.cpp Compiler/LowerConstantCalls.cpp Message-ID: <20110702111225.65E762A6C12C@llvm.org> Author: geoffray Date: Sat Jul 2 06:12:25 2011 New Revision: 134317 URL: http://llvm.org/viewvc/llvm-project?rev=134317&view=rev Log: Remove reference to old variables. Modified: vmkit/trunk/lib/J3/Classpath/ClasspathVMRuntime.inc vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp vmkit/trunk/lib/J3/Compiler/LowerConstantCalls.cpp Modified: vmkit/trunk/lib/J3/Classpath/ClasspathVMRuntime.inc URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Classpath/ClasspathVMRuntime.inc?rev=134317&r1=134316&r2=134317&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Classpath/ClasspathVMRuntime.inc (original) +++ vmkit/trunk/lib/J3/Classpath/ClasspathVMRuntime.inc Sat Jul 2 06:12:25 2011 @@ -181,12 +181,7 @@ jclass clazz, #endif jint par1) { -#if defined(ISOLATE) || defined(ISOLATE_SHARING) - // TODO: do a longjmp exit(par1); -#else - exit(par1); -#endif } JNIEXPORT jlong Java_java_lang_VMRuntime_freeMemory( Modified: vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp?rev=134317&r1=134316&r2=134317&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp Sat Jul 2 06:12:25 2011 @@ -1470,32 +1470,6 @@ const llvm::FunctionType* virtualType = LSI->getVirtualType(); llvm::Instruction* val = 0; -#if defined(ISOLATE_SHARING) - const Type* Ty = intrinsics->ConstantPoolType; - Constant* Nil = Constant::getNullValue(Ty); - GlobalVariable* GV = new GlobalVariable(*llvmFunction->getParent(),Ty, false, - GlobalValue::ExternalLinkage, Nil, - ""); - Value* res = new LoadInst(GV, "", false, currentBlock); - Value* test = new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, res, Nil, ""); - - BasicBlock* trueCl = createBasicBlock("UserCtp OK"); - BasicBlock* falseCl = createBasicBlock("UserCtp Not OK"); - PHINode* node = llvm::PHINode::Create(Ty, 2, "", trueCl); - node->addIncoming(res, currentBlock); - BranchInst::Create(falseCl, trueCl, test, currentBlock); - std::vector Args; - Args.push_back(ctpCache); - Args.push_back(ConstantInt::get(Type::getInt32Ty(*llvmContext), index)); - Args.push_back(GV); - res = CallInst::Create(intrinsics->SpecialCtpLookupFunction, Args.begin(), - Args.end(), "", falseCl); - node->addIncoming(res, falseCl); - BranchInst::Create(trueCl, falseCl); - currentBlock = trueCl; - args.push_back(node); -#endif - if (!meth) { meth = ctpInfo->infoOfStaticOrSpecialMethod(index, ACC_VIRTUAL, signature); } Modified: vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp?rev=134317&r1=134316&r2=134317&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp Sat Jul 2 06:12:25 2011 @@ -235,10 +235,6 @@ llvmArgs.push_back(LAI.llvmType); } -#if defined(ISOLATE_SHARING) - llvmArgs.push_back(Mod->getIntrinsics()->ConstantPoolType); -#endif - LLVMAssessorInfo& LAI = Compiler->getTypedefInfo(signature->getReturnType()); virtualType = FunctionType::get(LAI.llvmType, llvmArgs, false); @@ -261,11 +257,6 @@ llvmArgs.push_back(LAI.llvmType); } -#if defined(ISOLATE_SHARING) - // cached constant pool - llvmArgs.push_back(Compiler->getIntrinsics()->ConstantPoolType); -#endif - LLVMAssessorInfo& LAI = Compiler->getTypedefInfo(signature->getReturnType()); staticType = FunctionType::get(LAI.llvmType, llvmArgs, false); @@ -299,11 +290,6 @@ } } -#if defined(ISOLATE_SHARING) - // cached constant pool - llvmArgs.push_back(Compiler->getIntrinsics()->ConstantPoolType); -#endif - LLVMAssessorInfo& LAI = Compiler->getTypedefInfo(signature->getReturnType()); const llvm::Type* RetType = @@ -343,9 +329,6 @@ BasicBlock* currentBlock = BasicBlock::Create(context, "enter", res); Function::arg_iterator i = res->arg_begin(); Value *obj, *ptr, *func; -#if defined(ISOLATE_SHARING) - Value* ctp = i; -#endif ++i; func = i; ++i; @@ -396,10 +379,6 @@ currentBlock); } -#if defined(ISOLATE_SHARING) - Args.push_back(ctp); -#endif - Value* val = CallInst::Create(func, Args.begin(), Args.end(), "", currentBlock); if (!signature->getReturnType()->isVoid()) { @@ -435,9 +414,6 @@ BasicBlock* currentBlock = BasicBlock::Create(context, "enter", res); Function::arg_iterator i = res->arg_begin(); Value *obj, *ap, *func; -#if defined(ISOLATE_SHARING) - Value* ctp = i; -#endif ++i; func = i; ++i; @@ -476,10 +452,6 @@ Args.push_back(arg); } -#if defined(ISOLATE_SHARING) - Args.push_back(ctp); -#endif - Value* val = CallInst::Create(func, Args.begin(), Args.end(), "", currentBlock); if (!signature->getReturnType()->isVoid()) { Modified: vmkit/trunk/lib/J3/Compiler/LowerConstantCalls.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/LowerConstantCalls.cpp?rev=134317&r1=134316&r2=134317&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/LowerConstantCalls.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/LowerConstantCalls.cpp Sat Jul 2 06:12:25 2011 @@ -302,18 +302,6 @@ Value* Class = new LoadInst(ClassPtr, "", CI); CI->replaceAllUsesWith(Class); CI->eraseFromParent(); -#if defined(ISOLATE) - } else if (V == intrinsics->GetStaticInstanceFunction) { - Changed = true; - - Value* TCM = getTCM(intrinsics, Call.getArgument(0), CI); - Constant* C = intrinsics->OffsetStaticInstanceInTaskClassMirrorConstant; - Value* GEP[2] = { intrinsics->constantZero, C }; - Value* Replace = GetElementPtrInst::Create(TCM, GEP, GEP + 2, "", CI); - Replace = new LoadInst(Replace, "", CI); - CI->replaceAllUsesWith(Replace); - CI->eraseFromParent(); -#endif } else if (V == intrinsics->GetClassDelegateeFunction) { Changed = true; BasicBlock* NBB = II->getParent()->splitBasicBlock(II); From nicolas.geoffray at lip6.fr Mon Jul 11 14:28:04 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Mon, 11 Jul 2011 21:28:04 -0000 Subject: [vmkit-commits] [vmkit] r134923 - in /vmkit/trunk: ./ include/j3/ lib/J3/Classpath/ lib/J3/Compiler/ lib/J3/LLVMRuntime/ lib/J3/VMCore/ lib/Mvm/Compiler/ tools/ tools/precompiler/ tools/precompiler/trainer/ Message-ID: <20110711212804.746982A6C12C@llvm.org> Author: geoffray Date: Mon Jul 11 16:28:04 2011 New Revision: 134923 URL: http://llvm.org/viewvc/llvm-project?rev=134923&view=rev Log: Add a precompiler tool that precompiles bootstrap classes used when running a program. Added: vmkit/trunk/tools/precompiler/ vmkit/trunk/tools/precompiler/Makefile (with props) vmkit/trunk/tools/precompiler/Precompiler.cpp vmkit/trunk/tools/precompiler/trainer/ vmkit/trunk/tools/precompiler/trainer/HelloWorld.java vmkit/trunk/tools/precompiler/trainer/Makefile (with props) Modified: vmkit/trunk/Makefile.common.in vmkit/trunk/include/j3/J3Intrinsics.h vmkit/trunk/include/j3/JavaAOTCompiler.h vmkit/trunk/include/j3/JavaJITCompiler.h vmkit/trunk/include/j3/JavaLLVMCompiler.h vmkit/trunk/lib/J3/Classpath/JavaUpcalls.cpp vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp vmkit/trunk/lib/J3/LLVMRuntime/runtime-single.ll vmkit/trunk/lib/J3/VMCore/JavaClass.cpp vmkit/trunk/lib/J3/VMCore/JavaClass.h vmkit/trunk/lib/J3/VMCore/JavaConstantPool.cpp vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp vmkit/trunk/lib/J3/VMCore/Reader.h vmkit/trunk/lib/Mvm/Compiler/JIT.cpp vmkit/trunk/tools/Makefile Modified: vmkit/trunk/Makefile.common.in URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/Makefile.common.in?rev=134923&r1=134922&r2=134923&view=diff ============================================================================== --- vmkit/trunk/Makefile.common.in (original) +++ vmkit/trunk/Makefile.common.in Mon Jul 11 16:28:04 2011 @@ -20,9 +20,7 @@ # Define BYTECODE_LIBRARY before including LLVM's Makefile.common to get # dependencies right. -ifeq ($(MODULE_WITH_GC), 1) - BYTECODE_LIBRARY = 1 -endif +BYTECODE_LIBRARY = 1 ifeq ($(BUILD_FRAMETABLE), 1) BUILT_SOURCES = FrametablesSymbols.inc FrametablesExterns.inc Modified: vmkit/trunk/include/j3/J3Intrinsics.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/J3Intrinsics.h?rev=134923&r1=134922&r2=134923&view=diff ============================================================================== --- vmkit/trunk/include/j3/J3Intrinsics.h (original) +++ vmkit/trunk/include/j3/J3Intrinsics.h Mon Jul 11 16:28:04 2011 @@ -35,7 +35,9 @@ const llvm::Type* JavaClassType; const llvm::Type* JavaClassArrayType; const llvm::Type* JavaClassPrimitiveType; - const llvm::Type* ConstantPoolType; + const llvm::Type* ClassBytesType; + const llvm::Type* JavaConstantPoolType; + const llvm::Type* ResolvedConstantPoolType; const llvm::Type* CodeLineInfoType; const llvm::Type* UTF8Type; const llvm::Type* JavaMethodType; Modified: vmkit/trunk/include/j3/JavaAOTCompiler.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/JavaAOTCompiler.h?rev=134923&r1=134922&r2=134923&view=diff ============================================================================== --- vmkit/trunk/include/j3/JavaAOTCompiler.h (original) +++ vmkit/trunk/include/j3/JavaAOTCompiler.h Mon Jul 11 16:28:04 2011 @@ -16,6 +16,8 @@ class ArrayObject; class Attribut; +class ClassBytes; +class JnjvmBootstrapLoader; using mvm::UTF8; @@ -48,6 +50,7 @@ virtual llvm::Value* addCallback(Class* cl, uint16 index, Signdef* sign, bool stat, llvm::BasicBlock* insert); + virtual llvm::Function* getMethod(JavaMethod* meth); virtual void makeVT(Class* cl); virtual void makeIMT(Class* cl); @@ -64,7 +67,7 @@ virtual llvm::Constant* getString(JavaString* str); virtual llvm::Constant* getStringPtr(JavaString** str); - virtual llvm::Constant* getConstantPool(JavaConstantPool* ctp); + virtual llvm::Constant* getResolvedConstantPool(JavaConstantPool* ctp); virtual llvm::Constant* getNativeFunction(JavaMethod* meth, void* natPtr); virtual void setMethod(llvm::Function* func, void* ptr, const char* name); @@ -93,6 +96,9 @@ llvm::Constant* CreateConstantFromJavaClass(CommonClass* cl); llvm::Constant* CreateConstantForBaseObject(CommonClass* cl); llvm::Constant* CreateConstantFromJavaObject(JavaObject* obj); + llvm::Constant* CreateConstantFromClassBytes(ClassBytes* bytes); + llvm::Constant* CreateConstantFromJavaConstantPool(JavaConstantPool* ctp); + void AddInitializerToClass(llvm::GlobalVariable* varGV, CommonClass* classDef); llvm::Constant* getUTF8(const UTF8* val); template @@ -103,29 +109,30 @@ llvm::Constant* CreateConstantFromObjectArray(const ArrayObject* val); - std::map nativeClasses; + std::map nativeClasses; std::map arrayClasses; std::map javaClasses; std::map virtualTables; std::map staticInstances; - std::map constantPools; + std::map resolvedConstantPools; std::map strings; std::map nativeFunctions; std::map utf8s; std::map virtualMethods; std::map finalObjects; std::map reverseFinalObjects; + std::vector toCompile; typedef std::map::iterator final_object_iterator; typedef std::map::iterator reverse_final_object_iterator; - + typedef std::map::iterator method_iterator; - typedef std::map::iterator + typedef std::map::iterator native_class_iterator; typedef std::map::iterator @@ -141,8 +148,8 @@ static_instance_iterator; typedef std::map::iterator - constant_pool_iterator; - + resolved_constant_pool_iterator; + typedef std::map::iterator string_iterator; @@ -166,6 +173,7 @@ bool generateStubs; bool assumeCompiled; bool compileRT; + bool precompile; std::vector* clinits; @@ -178,10 +186,12 @@ void compileFile(Jnjvm* vm, const char* name); void compileClass(Class* cl); + void compileClassLoader(JnjvmBootstrapLoader* loader); void generateMain(const char* name, bool jit); private: void compileAllStubs(Signdef* sign); + llvm::Function* getMethodOrStub(JavaMethod* meth); }; } // end namespace j3 Modified: vmkit/trunk/include/j3/JavaJITCompiler.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/JavaJITCompiler.h?rev=134923&r1=134922&r2=134923&view=diff ============================================================================== --- vmkit/trunk/include/j3/JavaJITCompiler.h (original) +++ vmkit/trunk/include/j3/JavaJITCompiler.h Mon Jul 11 16:28:04 2011 @@ -70,7 +70,7 @@ virtual llvm::Constant* getString(JavaString* str); virtual llvm::Constant* getStringPtr(JavaString** str); - virtual llvm::Constant* getConstantPool(JavaConstantPool* ctp); + virtual llvm::Constant* getResolvedConstantPool(JavaConstantPool* ctp); virtual llvm::Constant* getNativeFunction(JavaMethod* meth, void* natPtr); virtual void setMethod(llvm::Function* func, void* ptr, const char* name); Modified: vmkit/trunk/include/j3/JavaLLVMCompiler.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/JavaLLVMCompiler.h?rev=134923&r1=134922&r2=134923&view=diff ============================================================================== --- vmkit/trunk/include/j3/JavaLLVMCompiler.h (original) +++ vmkit/trunk/include/j3/JavaLLVMCompiler.h Mon Jul 11 16:28:04 2011 @@ -123,7 +123,7 @@ void resolveVirtualClass(Class* cl); void resolveStaticClass(Class* cl); - llvm::Function* getMethod(JavaMethod* meth); + virtual llvm::Function* getMethod(JavaMethod* meth); void initialiseAssessorInfo(); std::map AssessorInfo; @@ -192,7 +192,7 @@ virtual llvm::Constant* getString(JavaString* str) = 0; virtual llvm::Constant* getStringPtr(JavaString** str) = 0; - virtual llvm::Constant* getConstantPool(JavaConstantPool* ctp) = 0; + virtual llvm::Constant* getResolvedConstantPool(JavaConstantPool* ctp) = 0; virtual llvm::Constant* getNativeFunction(JavaMethod* meth, void* natPtr) = 0; virtual void setMethod(llvm::Function* func, void* ptr, const char* name) = 0; Modified: vmkit/trunk/lib/J3/Classpath/JavaUpcalls.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Classpath/JavaUpcalls.cpp?rev=134923&r1=134922&r2=134923&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Classpath/JavaUpcalls.cpp (original) +++ vmkit/trunk/lib/J3/Classpath/JavaUpcalls.cpp Mon Jul 11 16:28:04 2011 @@ -31,7 +31,6 @@ using namespace j3; -#ifndef ISOLATE_SHARING Class* Classpath::newThread; Class* Classpath::newVMThread; JavaField* Classpath::assocThread; @@ -226,8 +225,6 @@ JavaMethod* Classpath::EnqueueReference; Class* Classpath::newReference; -#endif - void Classpath::CreateJavaThread(Jnjvm* vm, JavaThread* myth, const char* thName, JavaObject* Group) { JavaObjectVMThread* vmth = NULL; Modified: vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp?rev=134923&r1=134922&r2=134923&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp Mon Jul 11 16:28:04 2011 @@ -38,8 +38,8 @@ VTType = PointerType::getUnqual(module->getTypeByName("VT")); LLVMContext& Context = module->getContext(); - ConstantPoolType = ptrPtrType; - + ResolvedConstantPoolType = ptrPtrType; + JavaObjectType = PointerType::getUnqual(module->getTypeByName("JavaObject")); @@ -54,6 +54,10 @@ PointerType::getUnqual(module->getTypeByName("JavaClassArray")); JavaClassType = PointerType::getUnqual(module->getTypeByName("JavaClass")); + ClassBytesType = + PointerType::getUnqual(module->getTypeByName("ClassBytes")); + JavaConstantPoolType = + PointerType::getUnqual(module->getTypeByName("JavaConstantPool")); JavaArrayUInt8Type = PointerType::getUnqual(module->getTypeByName("ArrayUInt8")); Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=134923&r1=134922&r2=134923&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Mon Jul 11 16:28:04 2011 @@ -39,7 +39,7 @@ bool JavaAOTCompiler::isCompiling(const CommonClass* cl) const { if (cl->isClass()) { // A class is being static compiled if owner class is not null. - return cl->asClass()->getOwnerClass() != 0; + return precompile || (cl->asClass()->getOwnerClass() != 0); } else if (cl->isArray()) { // Only compile an aray if we are compiling rt.jar. return compileRT; @@ -50,6 +50,20 @@ } } +void JavaAOTCompiler::AddInitializerToClass(GlobalVariable* varGV, CommonClass* classDef) { + if (classDef->isClass() && isCompiling(classDef)) { + Constant* C = CreateConstantFromClass(classDef->asClass()); + varGV->setInitializer(C); + } else if (classDef->isArray()) { + Constant* C = CreateConstantFromClassArray(classDef->asArrayClass()); + varGV->setInitializer(C); + } else if (classDef->isPrimitive()) { + Constant* C = + CreateConstantFromClassPrimitive(classDef->asPrimitiveClass()); + varGV->setInitializer(C); + } +} + Constant* JavaAOTCompiler::getNativeClass(CommonClass* classDef) { if (classDef->isClass() || isCompiling(classDef) || assumeCompiled) { @@ -74,20 +88,11 @@ nativeClasses.insert(std::make_pair(classDef, varGV)); - if (classDef->isClass() && isCompiling(classDef)) { - Constant* C = CreateConstantFromClass(classDef->asClass()); - varGV->setInitializer(C); - } else if (classDef->isArray()) { - Constant* C = CreateConstantFromClassArray(classDef->asArrayClass()); - varGV->setInitializer(C); - } else if (classDef->isPrimitive()) { - Constant* C = - CreateConstantFromClassPrimitive(classDef->asPrimitiveClass()); - varGV->setInitializer(C); + if (!precompile) { + AddInitializerToClass(varGV, classDef); } return varGV; - } else { return I->second; } @@ -114,19 +119,79 @@ return 0; } -Constant* JavaAOTCompiler::getConstantPool(JavaConstantPool* ctp) { - llvm::Constant* varGV = 0; - constant_pool_iterator End = constantPools.end(); - constant_pool_iterator I = constantPools.find(ctp); +Constant* JavaAOTCompiler::CreateConstantFromJavaConstantPool(JavaConstantPool* ctp) { + const StructType* STy = + dyn_cast(JavaIntrinsics.JavaConstantPoolType->getContainedType(0)); + Module& Mod = *getLLVMModule(); + + std::vector Elemts; + + // Class + Elemts.push_back(getNativeClass(ctp->classDef)); + + // ctpSize + Elemts.push_back(ConstantInt::get(Type::getInt32Ty(getLLVMContext()), ctp->ctpSize)); + + // ctpType + const ArrayType* ATy = ArrayType::get(Type::getInt8Ty(getLLVMContext()), ctp->ctpSize); + std::vector Vals; + for (uint32 i = 0; i < ctp->ctpSize; ++i) { + Vals.push_back(ConstantInt::get(Type::getInt8Ty(getLLVMContext()), ctp->ctpType[i])); + } + + Constant* Array = ConstantArray::get(ATy, Vals); + GlobalVariable* varGV = new GlobalVariable(Mod, Array->getType(), false, + GlobalValue::InternalLinkage, + Array, ""); + + Array = ConstantExpr::getBitCast( + varGV, PointerType::getUnqual(Type::getInt8Ty(getLLVMContext()))); + Elemts.push_back(Array); + + // ctpDef + ATy = ArrayType::get(Type::getInt32Ty(getLLVMContext()), ctp->ctpSize); + Vals.clear(); + for (uint32 i = 0; i < ctp->ctpSize; ++i) { + Vals.push_back(ConstantInt::get(Type::getInt32Ty(getLLVMContext()), ctp->ctpDef[i])); + } + + Array = ConstantArray::get(ATy, Vals); + varGV = new GlobalVariable(Mod, Array->getType(), false, + GlobalValue::InternalLinkage, + Array, ""); + + Array = ConstantExpr::getBitCast( + varGV, PointerType::getUnqual(Type::getInt32Ty(getLLVMContext()))); + + Elemts.push_back(Array); + + // ctpRes + Elemts.push_back(getResolvedConstantPool(ctp)); + + return ConstantStruct::get(STy, Elemts); +} + +Constant* JavaAOTCompiler::getResolvedConstantPool(JavaConstantPool* ctp) { + resolved_constant_pool_iterator End = resolvedConstantPools.end(); + resolved_constant_pool_iterator I = resolvedConstantPools.find(ctp); if (I == End) { - const Type* Ty = JavaIntrinsics.ConstantPoolType->getContainedType(0); Module& Mod = *getLLVMModule(); + + const ArrayType* ATy = ArrayType::get(JavaIntrinsics.ptrType, ctp->ctpSize); + std::vector Vals; + for (uint32 i = 0; i < ctp->ctpSize; ++i) { + Vals.push_back(Constant::getNullValue(JavaIntrinsics.ptrType)); + } + + Constant* Array = ConstantArray::get(ATy, Vals); + GlobalVariable* varGV = new GlobalVariable(Mod, Array->getType(), false, + GlobalValue::InternalLinkage, + Array, ""); + + Array = ConstantExpr::getBitCast(varGV, JavaIntrinsics.ResolvedConstantPoolType); - varGV = new GlobalVariable(Mod, Ty, false, - GlobalValue::InternalLinkage, - Constant::getNullValue(Ty), ""); - constantPools.insert(std::make_pair(ctp, varGV)); - return varGV; + resolvedConstantPools.insert(std::make_pair(ctp, Array)); + return Array; } else { return I->second; } @@ -197,33 +262,38 @@ } Constant* JavaAOTCompiler::getJavaClass(CommonClass* cl) { - java_class_iterator End = javaClasses.end(); - java_class_iterator I = javaClasses.find(cl); - if (I == End) { - final_object_iterator End = finalObjects.end(); - final_object_iterator I = finalObjects.find(cl->delegatee[0]); + Class* javaClass = cl->classLoader->bootstrapLoader->upcalls->newClass; + LLVMClassInfo* LCI = getClassInfo(javaClass); + const llvm::Type* Ty = LCI->getVirtualType(); + + if (useCooperativeGC()) { + return Constant::getNullValue(JavaIntrinsics.JavaObjectType); + } else { + java_class_iterator End = javaClasses.end(); + java_class_iterator I = javaClasses.find(cl); if (I == End) { + final_object_iterator End = finalObjects.end(); + final_object_iterator I = finalObjects.find(cl->delegatee[0]); + if (I == End) { + + Module& Mod = *getLLVMModule(); + + GlobalVariable* varGV = + new GlobalVariable(Mod, Ty->getContainedType(0), false, + GlobalValue::InternalLinkage, 0, ""); + + Constant* res = ConstantExpr::getCast(Instruction::BitCast, varGV, + JavaIntrinsics.JavaObjectType); - Class* javaClass = cl->classLoader->bootstrapLoader->upcalls->newClass; - LLVMClassInfo* LCI = getClassInfo(javaClass); - const llvm::Type* Ty = LCI->getVirtualType(); - Module& Mod = *getLLVMModule(); - - GlobalVariable* varGV = - new GlobalVariable(Mod, Ty->getContainedType(0), false, - GlobalValue::InternalLinkage, 0, ""); - - Constant* res = ConstantExpr::getCast(Instruction::BitCast, varGV, - JavaIntrinsics.JavaObjectType); - - javaClasses.insert(std::make_pair(cl, res)); - varGV->setInitializer(CreateConstantFromJavaClass(cl)); - return res; + javaClasses.insert(std::make_pair(cl, res)); + varGV->setInitializer(CreateConstantFromJavaClass(cl)); + return res; + } else { + return I->second; + } } else { return I->second; } - } else { - return I->second; } } @@ -389,8 +459,8 @@ Attribut* attribut = field.lookupAttribut(Attribut::constantAttribut); - if (!attribut) { - if (cl->getStaticInstance() != NULL) { + if (attribut == NULL) { + if ((cl->getStaticInstance() != NULL) && !useCooperativeGC()) { if (type->isPrimitive()) { const PrimitiveTypedef* prim = (const PrimitiveTypedef*)type; if (prim->isBool() || prim->isByte()) { @@ -454,12 +524,16 @@ } else { Elts.push_back(ConstantInt::get(Ty, (uint64)ctpInfo->IntegerAt(idx))); } - } else if (type->isReference()){ - const UTF8* utf8 = ctpInfo->UTF8At(ctpInfo->ctpDef[idx]); - JavaString* obj = ctpInfo->resolveString(utf8, idx); - Constant* C = getString(obj); - C = ConstantExpr::getBitCast(C, JavaIntrinsics.JavaObjectType); - Elts.push_back(C); + } else if (type->isReference()) { + if (useCooperativeGC()) { + Elts.push_back(JavaIntrinsics.JavaObjectNullConstant); + } else { + const UTF8* utf8 = ctpInfo->UTF8At(ctpInfo->ctpDef[idx]); + JavaString* obj = ctpInfo->resolveString(utf8, idx); + Constant* C = getString(obj); + C = ConstantExpr::getBitCast(C, JavaIntrinsics.JavaObjectType); + Elts.push_back(C); + } } else { fprintf(stderr, "Implement me"); abort(); @@ -565,6 +639,7 @@ } Constant* JavaAOTCompiler::CreateConstantForBaseObject(CommonClass* cl) { + assert(!useCooperativeGC()); const StructType* STy = dyn_cast(JavaIntrinsics.JavaObjectType->getContainedType(0)); @@ -581,6 +656,7 @@ } Constant* JavaAOTCompiler::CreateConstantFromJavaClass(CommonClass* cl) { + assert(!useCooperativeGC()); Class* javaClass = cl->classLoader->bootstrapLoader->upcalls->newClass; LLVMClassInfo* LCI = getClassInfo(javaClass); const StructType* STy = @@ -610,6 +686,7 @@ } Constant* JavaAOTCompiler::CreateConstantFromJavaObject(JavaObject* obj) { + assert(!useCooperativeGC()); CommonClass* cl = JavaObject::getClass(obj); if (cl->isArray()) { @@ -716,6 +793,7 @@ } Constant* JavaAOTCompiler::CreateConstantFromJavaString(JavaString* str) { + assert(!useCooperativeGC()); Class* cl = JavaObject::getClass(str)->asClass(); LLVMClassInfo* LCI = getClassInfo(cl); const StructType* STy = @@ -944,11 +1022,11 @@ MethodElts.push_back(ConstantInt::get(Type::getInt8Ty(getLLVMContext()), method.canBeInlined)); // code - if (isAbstract(method.access)) { + if (isAbstract(method.access) + || (precompile && getMethodInfo(&method)->getMethod()->hasExternalWeakLinkage())) { MethodElts.push_back(Constant::getNullValue(JavaIntrinsics.ptrType)); } else { - LLVMMethodInfo* LMI = getMethodInfo(&method); - Function* func = LMI->getMethod(); + Function* func = getMethod(&method); MethodElts.push_back(ConstantExpr::getCast(Instruction::BitCast, func, JavaIntrinsics.ptrType)); } @@ -1151,10 +1229,20 @@ ClassElts.push_back(Constant::getNullValue(JavaIntrinsics.ptrType)); // bytes - ClassElts.push_back(Constant::getNullValue(JavaIntrinsics.JavaArrayUInt8Type)); + Constant* bytes = CreateConstantFromClassBytes(cl->bytes); + GlobalVariable* varGV = new GlobalVariable(*getLLVMModule(), bytes->getType(), false, + GlobalValue::InternalLinkage, + bytes, ""); + + bytes = ConstantExpr::getBitCast(varGV, JavaIntrinsics.ClassBytesType); + ClassElts.push_back(bytes); // ctpInfo - ClassElts.push_back(Constant::getNullValue(JavaIntrinsics.ptrType)); + Constant* ctpInfo = CreateConstantFromJavaConstantPool(cl->ctpInfo); + varGV = new GlobalVariable(*getLLVMModule(), ctpInfo->getType(), false, + GlobalValue::InternalLinkage, + ctpInfo, ""); + ClassElts.push_back(varGV); // attributs if (cl->nbAttributs) { @@ -1229,8 +1317,30 @@ return ConstantStruct::get(STy, ClassElts); } +Constant* JavaAOTCompiler::CreateConstantFromClassBytes(ClassBytes* bytes) { + std::vector Elemts; + const ArrayType* ATy = ArrayType::get(Type::getInt8Ty(getLLVMContext()), bytes->size); + Elemts.push_back(Type::getInt32Ty(getLLVMContext())); + Elemts.push_back(ATy); + + const StructType* STy = StructType::get(getLLVMContext(), Elemts); + + std::vector Cts; + Cts.push_back(ConstantInt::get(Type::getInt32Ty(getLLVMContext()), bytes->size)); + + std::vector Vals; + for (uint32 i = 0; i < bytes->size; ++i) { + Vals.push_back(ConstantInt::get(Type::getInt8Ty(getLLVMContext()), bytes->elements[i])); + } + + Cts.push_back(ConstantArray::get(ATy, Vals)); + + return ConstantStruct::get(STy, Cts); +} + template Constant* JavaAOTCompiler::CreateConstantFromIntArray(const T* val, const Type* Ty) { + assert(!useCooperativeGC()); std::vector Elemts; const ArrayType* ATy = ArrayType::get(Ty, T::getSize(val)); Elemts.push_back(JavaIntrinsics.JavaObjectType->getContainedType(0)); @@ -1257,6 +1367,7 @@ template Constant* JavaAOTCompiler::CreateConstantFromFPArray(const T* val, const Type* Ty) { + assert(!useCooperativeGC()); std::vector Elemts; const ArrayType* ATy = ArrayType::get(Ty, T::getSize(val)); Elemts.push_back(JavaIntrinsics.JavaObjectType->getContainedType(0)); @@ -1282,6 +1393,7 @@ } Constant* JavaAOTCompiler::CreateConstantFromObjectArray(const ArrayObject* val) { + assert(!useCooperativeGC()); std::vector Elemts; const llvm::Type* Ty = JavaIntrinsics.JavaObjectType; const ArrayType* ATy = ArrayType::get(Ty, ArrayObject::getSize(val)); @@ -1357,6 +1469,25 @@ } } +Function* JavaAOTCompiler::getMethodOrStub(JavaMethod* meth) { + assert(!isStatic(meth->access)); + // TODO: check if llvm Function is populated instead of checking code is NULL + if (precompile && (meth->code == NULL)) { + LLVMSignatureInfo* LSI = getSignatureInfo(meth->getSignature()); + return LSI->getVirtualStub(); + } else { + return getMethod(meth); + } +} + +Function* JavaAOTCompiler::getMethod(JavaMethod* meth) { + Function* func = getMethodInfo(meth)->getMethod(); + if (func->hasExternalWeakLinkage()) { + toCompile.push_back(meth); + } + return func; +} + Constant* JavaAOTCompiler::CreateConstantFromVT(JavaVirtualTable* VT) { CommonClass* classDef = VT->cl; uint32 size = classDef->isClass() ? classDef->asClass()->virtualTableSize : @@ -1376,8 +1507,7 @@ Function* Finalizer = 0; JavaMethod* meth = (JavaMethod*)(RealVT->destructor); if (meth) { - LLVMMethodInfo* LMI = getMethodInfo(meth); - Finalizer = LMI->getMethod(); + Finalizer = getMethodOrStub(meth); } Elemts.push_back(Finalizer ? @@ -1499,8 +1629,7 @@ Imeth->type, false, true, 0); assert(meth && "No method found"); - LLVMMethodInfo* LMI = getMethodInfo(meth); - Function* func = LMI->getMethod(); + Function* func = getMethodOrStub(meth); IElemts.push_back(ConstantExpr::getBitCast(func, PTy)); } else if (size > 1) { std::vector methods; @@ -1521,8 +1650,7 @@ if (SameMethod) { assert(methods[0] && "No method found"); - LLVMMethodInfo* LMI = getMethodInfo(methods[0]); - Function* func = LMI->getMethod(); + Function* func = getMethodOrStub(methods[0]); IElemts.push_back(ConstantExpr::getBitCast(func, PTy)); } else { @@ -1541,8 +1669,7 @@ JavaMethod* Cmeth = *it; assert(Cmeth && "No method found"); - LLVMMethodInfo* LMI = getMethodInfo(Cmeth); - Function* func = LMI->getMethod(); + Function* func = getMethodOrStub(Cmeth); InternalElemts.push_back( ConstantExpr::getBitCast(getMethodInClass(Imeth), PTy)); InternalElemts.push_back(ConstantExpr::getBitCast(func, PTy)); @@ -1577,8 +1704,7 @@ // methods for (uint32 i = JavaVirtualTable::getFirstJavaMethodIndex(); i < size; ++i) { JavaMethod* meth = ((JavaMethod**)RealVT)[i]; - LLVMMethodInfo* LMI = getMethodInfo(meth); - Function* F = LMI->getMethod(); + Function* F = getMethodOrStub(meth); if (isAbstract(meth->access)) { Elemts.push_back(Constant::getNullValue(PTy)); } else { @@ -1591,20 +1717,13 @@ return Array; } -namespace mvm { - llvm::FunctionPass* createEscapeAnalysisPass(llvm::Function*); -} - -namespace j3 { - llvm::FunctionPass* createLowerConstantCallsPass(); -} - JavaAOTCompiler::JavaAOTCompiler(const std::string& ModuleID) : JavaLLVMCompiler(ModuleID) { generateStubs = true; assumeCompiled = false; compileRT = false; + precompile = false; std::vector llvmArgs; llvmArgs.push_back(JavaIntrinsics.ptrType); // class loader. @@ -1662,7 +1781,7 @@ fprintf(stderr, "Number of static instances : %llu\n", (unsigned long long int) staticInstances.size()); fprintf(stderr, "Number of constant pools : %llu\n", - (unsigned long long int) constantPools.size()); + (unsigned long long int) resolvedConstantPools.size()); fprintf(stderr, "Number of strings : %llu\n", (unsigned long long int) strings.size()); fprintf(stderr, "Number of native functions : %llu\n", @@ -1752,8 +1871,7 @@ for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) { JavaMethod& meth = cl->virtualMethods[i]; if (!isAbstract(meth.access)) { - LLVMMethodInfo* LMI = getMethodInfo(&meth); - Function* func = LMI->getMethod(); + Function* func = getMethod(&meth); func->addFnAttr(Attribute::NoInline); } } @@ -1761,8 +1879,7 @@ for (uint32 i = 0; i < cl->nbStaticMethods; ++i) { JavaMethod& meth = cl->staticMethods[i]; if (!isAbstract(meth.access)) { - LLVMMethodInfo* LMI = getMethodInfo(&meth); - Function* func = LMI->getMethod(); + Function* func = getMethod(&meth); func->addFnAttr(Attribute::NoInline); } } @@ -1786,7 +1903,6 @@ } if (!cl->super) VT->destructor = 0; - } void JavaAOTCompiler::makeIMT(Class* cl) { @@ -1807,7 +1923,6 @@ const UTF8* methCl = 0; ctpInfo->nameOfStaticOrSpecialMethod(index, methCl, name, signature); - fprintf(stderr, "Warning: emitting a callback from %s (%s.%s)\n", UTF8Buffer(cl->name).cString(), UTF8Buffer(methCl).cString(), UTF8Buffer(name).cString()); @@ -1923,52 +2038,36 @@ M->addJavaPasses(); - // First resolve everyone so that there can not be unknown references in - // constant pools. - for (std::vector::iterator i = classes.begin(), - e = classes.end(); i != e; ++i) { - Class* cl = *i; - cl->resolveClass(); - cl->setOwnerClass(JavaThread::get()); - - for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) { - LLVMMethodInfo* LMI = M->getMethodInfo(&cl->virtualMethods[i]); - LMI->getMethod(); - } - - for (uint32 i = 0; i < cl->nbStaticMethods; ++i) { - LLVMMethodInfo* LMI = M->getMethodInfo(&cl->staticMethods[i]); - LMI->getMethod(); - } + // First resolve everyone so that there can not be unknown references in + // constant pools. + for (std::vector::iterator i = classes.begin(), + e = classes.end(); i != e; ++i) { + Class* cl = *i; + cl->resolveClass(); + cl->setOwnerClass(JavaThread::get()); + + for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) { + M->getMethod(&cl->virtualMethods[i]); + } + for (uint32 i = 0; i < cl->nbStaticMethods; ++i) { + M->getMethod(&cl->staticMethods[i]); } - if (!M->clinits->empty()) { - vm->loadBootstrap(); + } - for (std::vector::iterator i = M->clinits->begin(), - e = M->clinits->end(); i != e; ++i) { - - if (i->at(i->length() - 1) == '*') { - for (std::vector::iterator ii = classes.begin(), - ee = classes.end(); ii != ee; ++ii) { - Class* cl = *ii; - if (!strncmp(UTF8Buffer(cl->name).cString(), i->c_str(), - i->length() - 1)) { - TRY { - cl->asClass()->initialiseClass(vm); - } CATCH { - fprintf(stderr, "Error when initializing %s\n", - UTF8Buffer(cl->name).cString()); - abort(); - } END_CATCH; - } - } - } else { + if (!M->clinits->empty()) { + vm->loadBootstrap(); - const UTF8* name = bootstrapLoader->asciizConstructUTF8(i->c_str()); - CommonClass* cl = bootstrapLoader->lookupClass(name); - if (cl && cl->isClass()) { + for (std::vector::iterator i = M->clinits->begin(), + e = M->clinits->end(); i != e; ++i) { + + if (i->at(i->length() - 1) == '*') { + for (std::vector::iterator ii = classes.begin(), + ee = classes.end(); ii != ee; ++ii) { + Class* cl = *ii; + if (!strncmp(UTF8Buffer(cl->name).cString(), i->c_str(), + i->length() - 1)) { TRY { cl->asClass()->initialiseClass(vm); } CATCH { @@ -1976,88 +2075,102 @@ UTF8Buffer(cl->name).cString()); abort(); } END_CATCH; - } else { - fprintf(stderr, "Class %s does not exist or is an array class.\n", - i->c_str()); } } - } - bootstrapLoader->setCompiler(M); - } - - for (std::vector::iterator i = classes.begin(), e = classes.end(); - i != e; ++i) { - Class* cl = *i; - cl->setOwnerClass(JavaThread::get()); - } - - for (std::vector::iterator i = classes.begin(), e = classes.end(); - i != e; ++i) { - Class* cl = *i; - M->compileClass(cl); - } + } else { - } else { - M->addJavaPasses(); - char* realName = (char*)allocator.Allocate(size + 1); - if (size > 6 && !strcmp(&name[size - 6], ".class")) { - memcpy(realName, name, size - 6); - realName[size - 6] = 0; - } else { - memcpy(realName, name, size + 1); - } - - const UTF8* utf8 = bootstrapLoader->asciizConstructUTF8(realName); - UserClass* cl = bootstrapLoader->loadName(utf8, true, true, NULL); - - if (!M->clinits->empty()) { - vm->loadBootstrap(); - cl->initialiseClass(vm); - bootstrapLoader->setCompiler(M); + const UTF8* name = bootstrapLoader->asciizConstructUTF8(i->c_str()); + CommonClass* cl = bootstrapLoader->lookupClass(name); + if (cl && cl->isClass()) { + TRY { + cl->asClass()->initialiseClass(vm); + } CATCH { + fprintf(stderr, "Error when initializing %s\n", + UTF8Buffer(cl->name).cString()); + abort(); + } END_CATCH; + } else { + fprintf(stderr, "Class %s does not exist or is an array class.\n", + i->c_str()); + } + } } - + bootstrapLoader->setCompiler(M); + } + + for (std::vector::iterator i = classes.begin(), e = classes.end(); + i != e; ++i) { + Class* cl = *i; cl->setOwnerClass(JavaThread::get()); - cl->resolveInnerOuterClasses(); - for (uint32 i = 0; i < cl->nbInnerClasses; ++i) { - cl->innerClasses[i]->setOwnerClass(JavaThread::get()); - M->compileClass(cl->innerClasses[i]); - } + } + + for (std::vector::iterator i = classes.begin(), e = classes.end(); + i != e; ++i) { + Class* cl = *i; M->compileClass(cl); } - - if (M->compileRT) { - // Make sure that if we compile RT, the native classes are emitted. - M->getNativeClass(bootstrapLoader->upcalls->OfVoid); - M->getNativeClass(bootstrapLoader->upcalls->OfBool); - M->getNativeClass(bootstrapLoader->upcalls->OfByte); - M->getNativeClass(bootstrapLoader->upcalls->OfChar); - M->getNativeClass(bootstrapLoader->upcalls->OfShort); - M->getNativeClass(bootstrapLoader->upcalls->OfInt); - M->getNativeClass(bootstrapLoader->upcalls->OfFloat); - M->getNativeClass(bootstrapLoader->upcalls->OfLong); - M->getNativeClass(bootstrapLoader->upcalls->OfDouble); - // Also do not allow inling of some functions. + } else { + M->addJavaPasses(); + char* realName = (char*)allocator.Allocate(size + 1); + if (size > 6 && !strcmp(&name[size - 6], ".class")) { + memcpy(realName, name, size - 6); + realName[size - 6] = 0; + } else { + memcpy(realName, name, size + 1); + } + + const UTF8* utf8 = bootstrapLoader->asciizConstructUTF8(realName); + UserClass* cl = bootstrapLoader->loadName(utf8, true, true, NULL); + + if (!M->clinits->empty()) { + vm->loadBootstrap(); + cl->initialiseClass(vm); + bootstrapLoader->setCompiler(M); + } + + cl->setOwnerClass(JavaThread::get()); + cl->resolveInnerOuterClasses(); + for (uint32 i = 0; i < cl->nbInnerClasses; ++i) { + cl->innerClasses[i]->setOwnerClass(JavaThread::get()); + M->compileClass(cl->innerClasses[i]); + } + M->compileClass(cl); + } + + if (M->compileRT) { + // Make sure that if we compile RT, the native classes are emitted. + M->getNativeClass(bootstrapLoader->upcalls->OfVoid); + M->getNativeClass(bootstrapLoader->upcalls->OfBool); + M->getNativeClass(bootstrapLoader->upcalls->OfByte); + M->getNativeClass(bootstrapLoader->upcalls->OfChar); + M->getNativeClass(bootstrapLoader->upcalls->OfShort); + M->getNativeClass(bootstrapLoader->upcalls->OfInt); + M->getNativeClass(bootstrapLoader->upcalls->OfFloat); + M->getNativeClass(bootstrapLoader->upcalls->OfLong); + M->getNativeClass(bootstrapLoader->upcalls->OfDouble); + + // Also do not allow inling of some functions. #define SET_INLINE(NAME) { \ - const UTF8* name = bootstrapLoader->asciizConstructUTF8(NAME); \ - Class* cl = (Class*)bootstrapLoader->lookupClass(name); \ - if (cl) M->setNoInline(cl); } - - SET_INLINE("java/util/concurrent/atomic/AtomicReferenceFieldUpdater") - SET_INLINE("java/util/concurrent/atomic/AtomicReferenceFieldUpdater" - "$AtomicReferenceFieldUpdaterImpl") - SET_INLINE("java/util/concurrent/atomic/AtomicIntegerFieldUpdater") - SET_INLINE("java/util/concurrent/atomic/AtomicIntegerFieldUpdater" - "$AtomicIntegerFieldUpdaterImpl") - SET_INLINE("java/util/concurrent/atomic/AtomicLongFieldUpdater") - SET_INLINE("java/util/concurrent/atomic/AtomicLongFieldUpdater" - "$CASUpdater") - SET_INLINE("java/util/concurrent/atomic/AtomicLongFieldUpdater" - "$LockedUpdater") + const UTF8* name = bootstrapLoader->asciizConstructUTF8(NAME); \ + Class* cl = (Class*)bootstrapLoader->lookupClass(name); \ + if (cl) M->setNoInline(cl); } + + SET_INLINE("java/util/concurrent/atomic/AtomicReferenceFieldUpdater") + SET_INLINE("java/util/concurrent/atomic/AtomicReferenceFieldUpdater" + "$AtomicReferenceFieldUpdaterImpl") + SET_INLINE("java/util/concurrent/atomic/AtomicIntegerFieldUpdater") + SET_INLINE("java/util/concurrent/atomic/AtomicIntegerFieldUpdater" + "$AtomicIntegerFieldUpdaterImpl") + SET_INLINE("java/util/concurrent/atomic/AtomicLongFieldUpdater") + SET_INLINE("java/util/concurrent/atomic/AtomicLongFieldUpdater" + "$CASUpdater") + SET_INLINE("java/util/concurrent/atomic/AtomicLongFieldUpdater" + "$LockedUpdater") #undef SET_INLINE - } + } - M->CreateStaticInitializer(); + M->CreateStaticInitializer(); end: @@ -2072,6 +2185,42 @@ vm->waitForExit(); } +void JavaAOTCompiler::compileClassLoader(JnjvmBootstrapLoader* loader) { + loader->setCompiler(this); + compileRT = true; + precompile = true; + addJavaPasses(); + + for (ClassMap::iterator i = loader->getClasses()->map.begin(), + e = loader->getClasses()->map.end(); i!= e; ++i) { + getNativeClass(i->second); + if (i->second->isClass()) { + Class* cl = i->second->asClass(); + for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) { + JavaMethod& meth = cl->virtualMethods[i]; + if (meth.code != NULL) parseFunction(&meth); + } + + for (uint32 i = 0; i < cl->nbStaticMethods; ++i) { + JavaMethod& meth = cl->staticMethods[i]; + if (meth.code != NULL) parseFunction(&meth); + } + } + } + + while (!toCompile.empty()) { + JavaMethod* meth = toCompile.back(); + toCompile.pop_back(); + getNativeClass(meth->classDef); + parseFunction(meth); + } + + for (native_class_iterator i = nativeClasses.begin(), + e = nativeClasses.end(); i != e; ++i) { + AddInitializerToClass(i->second, i->first); + } +} + /// compileAllStubs - Compile all the native -> Java stubs. /// TODO: Once LLVM supports va_arg, enable AP. /// Modified: vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp?rev=134923&r1=134922&r2=134923&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp Mon Jul 11 16:28:04 2011 @@ -236,7 +236,7 @@ return GetElementPtrInst::Create(mutatorThreadPtr, GEP, GEP + 3, "", currentBlock); } -llvm::Value* JavaJIT::getDoYieldPtr(llvm::Value* mutatorThreadPtr) { +llvm::Value* JavaJIT::getDoYieldPtr(llvm::Value* mutatorThreadPtr) { Value* GEP[3] = { intrinsics->constantZero, intrinsics->OffsetThreadInMutatorThreadConstant, intrinsics->OffsetDoYieldInThreadConstant }; @@ -1195,14 +1195,14 @@ uint8 type = ctpInfo->typeAt(index); if (type == JavaConstantPool::ConstantString) { - if (TheCompiler->isStaticCompiling()) { + if (TheCompiler->isStaticCompiling() && !TheCompiler->useCooperativeGC()) { const UTF8* utf8 = ctpInfo->UTF8At(ctpInfo->ctpDef[index]); JavaString* str = *(compilingClass->classLoader->UTF8ToStr(utf8)); Value* val = TheCompiler->getString(str); push(val, false, upcalls->newString); } else { JavaString** str = (JavaString**)ctpInfo->ctpRes[index]; - if (str) { + if ((str != NULL) && !TheCompiler->isStaticCompiling()) { Value* val = TheCompiler->getStringPtr(str); val = new LoadInst(val, "", currentBlock); push(val, false, upcalls->newString); @@ -1468,11 +1468,7 @@ ctpInfo->nameOfStaticOrSpecialMethod(index, cl, name, signature); LLVMSignatureInfo* LSI = TheCompiler->getSignatureInfo(signature); const llvm::FunctionType* virtualType = LSI->getVirtualType(); - llvm::Instruction* val = 0; - - if (!meth) { - meth = ctpInfo->infoOfStaticOrSpecialMethod(index, ACC_VIRTUAL, signature); - } + meth = ctpInfo->infoOfStaticOrSpecialMethod(index, ACC_VIRTUAL, signature); Value* func = 0; bool needsInit = false; @@ -1502,6 +1498,7 @@ return; } + llvm::Instruction* val = 0; if (meth && canBeInlined(meth)) { val = invokeInline(meth, args); } else { @@ -1598,7 +1595,7 @@ // This makes unswitch loop very unhappy time-wise, but makes GVN happy // number-wise. IMO, it's better to have this than Unswitch. JavaConstantPool* ctp = compilingClass->ctpInfo; - Value* CTP = TheCompiler->getConstantPool(ctp); + Value* CTP = TheCompiler->getResolvedConstantPool(ctp); Value* Cl = TheCompiler->getNativeClass(compilingClass); std::vector Args; @@ -2139,8 +2136,8 @@ Args.push_back(targetObject); Args.push_back(Meth); Args.push_back(Index); - Value* node = - invoke(intrinsics->ResolveInterfaceFunction, Args, "", currentBlock); + Value* node = invoke(intrinsics->ResolveInterfaceFunction, + Args, "invokeinterface", currentBlock); node = new BitCastInst(node, virtualPtrType, "", currentBlock); #endif Modified: vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp?rev=134923&r1=134922&r2=134923&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp Mon Jul 11 16:28:04 2011 @@ -100,12 +100,12 @@ return ConstantExpr::getIntToPtr(CI, Ty); } -Constant* JavaJITCompiler::getConstantPool(JavaConstantPool* ctp) { +Constant* JavaJITCompiler::getResolvedConstantPool(JavaConstantPool* ctp) { void* ptr = ctp->ctpRes; assert(ptr && "No constant pool found"); ConstantInt* CI = ConstantInt::get(Type::getInt64Ty(getLLVMContext()), uint64_t(ptr)); - return ConstantExpr::getIntToPtr(CI, JavaIntrinsics.ConstantPoolType); + return ConstantExpr::getIntToPtr(CI, JavaIntrinsics.ResolvedConstantPoolType); } Constant* JavaJITCompiler::getMethodInClass(JavaMethod* meth) { @@ -449,7 +449,7 @@ } } // Load the constant pool. - Value* CTP = getConstantPool(ctpInfo); + Value* CTP = getResolvedConstantPool(ctpInfo); Value* Index = ConstantInt::get(Type::getInt32Ty(insert->getContext()), index); Value* func = GetElementPtrInst::Create(CTP, Index, "", insert); Modified: vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp?rev=134923&r1=134922&r2=134923&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp Mon Jul 11 16:28:04 2011 @@ -591,7 +591,7 @@ // Lock here because we are called by arbitrary code mvm::MvmModule::protectIR(); std::vector Args; - Args.push_back(Compiler->getIntrinsics()->ConstantPoolType); // ctp + Args.push_back(Compiler->getIntrinsics()->ResolvedConstantPoolType); // ctp Args.push_back(getVirtualPtrType()); Args.push_back(Compiler->getIntrinsics()->JavaObjectType); Args.push_back(Compiler->AssessorInfo[I_LONG].llvmTypePtr); @@ -608,7 +608,7 @@ // Lock here because we are called by arbitrary code mvm::MvmModule::protectIR(); std::vector Args; - Args.push_back(Compiler->getIntrinsics()->ConstantPoolType); // ctp + Args.push_back(Compiler->getIntrinsics()->ResolvedConstantPoolType); // ctp Args.push_back(getStaticPtrType()); Args.push_back(Compiler->AssessorInfo[I_LONG].llvmTypePtr); LLVMAssessorInfo& LAI = Modified: vmkit/trunk/lib/J3/LLVMRuntime/runtime-single.ll URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/LLVMRuntime/runtime-single.ll?rev=134923&r1=134922&r2=134923&view=diff ============================================================================== --- vmkit/trunk/lib/J3/LLVMRuntime/runtime-single.ll (original) +++ vmkit/trunk/lib/J3/LLVMRuntime/runtime-single.ll Mon Jul 11 16:28:04 2011 @@ -5,8 +5,9 @@ %JavaCommonClass = type { [1 x %JavaObject*], i16, %JavaClass**, i16, %UTF8*, %JavaClass*, i8*, %VT* } +%ClassBytes = type { i32, i8* } %JavaClass = type { %JavaCommonClass, i32, i32, [1 x %TaskClassMirror], %JavaField*, i16, %JavaField*, i16, %JavaMethod*, i16, - %JavaMethod*, i16, i8*, %ArrayUInt8*, i8*, %Attribut*, + %JavaMethod*, i16, i8*, %ClassBytes*, %JavaConstantPool*, %Attribut*, i16, %JavaClass**, i16, %JavaClass*, i16, i8, i8, i32, i32 } Modified: vmkit/trunk/lib/J3/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaClass.cpp?rev=134923&r1=134922&r2=134923&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JavaClass.cpp Mon Jul 11 16:28:04 2011 @@ -605,7 +605,7 @@ } else { InitStaticField((uint64)ctpInfo->IntegerAt(idx)); } - } else if (type->isReference()){ + } else if (type->isReference()) { const UTF8* utf8 = ctpInfo->UTF8At(ctpInfo->ctpDef[idx]); InitStaticField((JavaObject*)ctpInfo->resolveString(utf8, idx)); } else { Modified: vmkit/trunk/lib/J3/VMCore/JavaClass.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaClass.h?rev=134923&r1=134922&r2=134923&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaClass.h (original) +++ vmkit/trunk/lib/J3/VMCore/JavaClass.h Mon Jul 11 16:28:04 2011 @@ -848,7 +848,7 @@ Virtual }; - /// constructMethod - Create a new method. + /// initialise - Create a new method. /// void initialise(Class* cl, const UTF8* name, const UTF8* type, uint16 access); Modified: vmkit/trunk/lib/J3/VMCore/JavaConstantPool.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaConstantPool.cpp?rev=134923&r1=134922&r2=134923&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaConstantPool.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JavaConstantPool.cpp Mon Jul 11 16:28:04 2011 @@ -290,6 +290,8 @@ temp = loader->loadName(name, resolve, false, NULL); } ctpRes[index] = temp; + } else if (resolve && temp->isClass()) { + temp->asClass()->resolveClass(); } return temp; } @@ -303,9 +305,14 @@ temp = loader->lookupClassOrArray(name); } - if (!temp && classDef->classLoader->getCompiler()->isStaticCompiling()) { - temp = loadClass(index); + if (classDef->classLoader->getCompiler()->isStaticCompiling()) { + if (temp == NULL) { + temp = loadClass(index, true); + } else if (temp->isClass()) { + temp->asClass()->resolveClass(); + } } + return temp; } Modified: vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp?rev=134923&r1=134922&r2=134923&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp Mon Jul 11 16:28:04 2011 @@ -1198,6 +1198,10 @@ JavaField& field = realCl->staticFields[i]; JCL->hashUTF8->insert(field.name); JCL->hashUTF8->insert(field.type); + if (field.getSignature()->isReference() + && (field.lookupAttribut(Attribut::constantAttribut) != NULL)) { + field.InitStaticField(JCL->getIsolate()); + } } for (uint32 i = 0; i< realCl->nbVirtualFields; ++i) { @@ -1207,9 +1211,9 @@ } } - if (!cl->isPrimitive()) + if (!cl->isPrimitive()) { JCL->getClasses()->map.insert(std::make_pair(cl->name, cl)); - + } } extern "C" void vmjcGetClassArray(JnjvmClassLoader* JCL, ClassArray** ptr, Modified: vmkit/trunk/lib/J3/VMCore/Reader.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Reader.h?rev=134923&r1=134922&r2=134923&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/Reader.h (original) +++ vmkit/trunk/lib/J3/VMCore/Reader.h Mon Jul 11 16:28:04 2011 @@ -41,8 +41,6 @@ class Reader { public: - // bytes - Pointer to a reference array. The array is not manipulated directly - // in order to support copying GC. ClassBytes* bytes; uint32 min; uint32 cursor; Modified: vmkit/trunk/lib/Mvm/Compiler/JIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Compiler/JIT.cpp?rev=134923&r1=134922&r2=134923&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Compiler/JIT.cpp (original) +++ vmkit/trunk/lib/Mvm/Compiler/JIT.cpp Mon Jul 11 16:28:04 2011 @@ -316,10 +316,6 @@ void MvmModule::runPasses(llvm::Function* func, llvm::FunctionPassManager* pm) { - // Take the lock because the pass manager will call materializeFunction. - // Our implementation of materializeFunction requires that the lock is held - // by the caller. This is due to LLVM's JIT subsystem where the call to - // materializeFunction is guarded. pm->run(*func); } Modified: vmkit/trunk/tools/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/Makefile?rev=134923&r1=134922&r2=134923&view=diff ============================================================================== --- vmkit/trunk/tools/Makefile (original) +++ vmkit/trunk/tools/Makefile Mon Jul 11 16:28:04 2011 @@ -10,7 +10,7 @@ include $(LEVEL)/Makefile.config -PARALLEL_DIRS = j3 vmjc llcj +PARALLEL_DIRS = j3 vmjc llcj precompiler include $(LEVEL)/Makefile.common Added: vmkit/trunk/tools/precompiler/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/precompiler/Makefile?rev=134923&view=auto ============================================================================== --- vmkit/trunk/tools/precompiler/Makefile (added) +++ vmkit/trunk/tools/precompiler/Makefile Mon Jul 11 16:28:04 2011 @@ -0,0 +1,18 @@ +##===- tools/precompiler/Makefile --------------------------*- Makefile -*-===## +# +# The VMKit project +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## +LEVEL = ../.. + +include $(LEVEL)/Makefile.config + +TOOLNAME = precompiler +USEDLIBS = Classpath.a J3.a J3Compiler.a Mvm.a MvmCompiler.a CommonThread.a FinalMMTk.a InlineMMTk.a +BUILD_FRAMETABLE = 1 +LINK_COMPONENTS = jit nativecodegen scalaropts instrumentation ipa ipo asmparser linker bitwriter + +include $(LEVEL)/Makefile.common Propchange: vmkit/trunk/tools/precompiler/Makefile ------------------------------------------------------------------------------ svn:executable = * Added: vmkit/trunk/tools/precompiler/Precompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/precompiler/Precompiler.cpp?rev=134923&view=auto ============================================================================== --- vmkit/trunk/tools/precompiler/Precompiler.cpp (added) +++ vmkit/trunk/tools/precompiler/Precompiler.cpp Mon Jul 11 16:28:04 2011 @@ -0,0 +1,88 @@ +//===------------------------ Precompiler.cpp -----------------------------===// +// Run a program and emit code for classes loaded by the bootstrap loader -===// +// +// The VMKit project +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/ManagedStatic.h" +#include "llvm/Support/raw_ostream.h" +#include "llvm/Support/Path.h" +#include "llvm/Bitcode/ReaderWriter.h" +#include "llvm/Support/Signals.h" + +#include "MvmGC.h" +#include "mvm/JIT.h" +#include "mvm/MethodInfo.h" +#include "mvm/Object.h" +#include "mvm/VirtualMachine.h" +#include "mvm/Threads/Thread.h" + +#include "j3/JavaAOTCompiler.h" +#include "j3/JavaJITCompiler.h" +#include "../../lib/J3/VMCore/JnjvmClassLoader.h" +#include "../../lib/J3/VMCore/Jnjvm.h" + +#include + +extern llvm::cl::opt StandardCompileOpts; + +using namespace j3; +using namespace mvm; + +#include "FrametablesExterns.inc" + +CamlFrames* frametables[] = { + #include "FrametablesSymbols.inc" +}; + +int main(int argc, char **argv, char **envp) { + llvm::llvm_shutdown_obj X; + + // Initialize base components. + MvmModule::initialise(); + Collector::initialise(); + + // Tell the compiler to run all optimizations. + StandardCompileOpts = true; + + // Create the allocator that will allocate the bootstrap loader and the JVM. + mvm::BumpPtrAllocator Allocator; + JavaJITCompiler* JIT = JavaJITCompiler::CreateCompiler("JIT"); + JnjvmBootstrapLoader* loader = new(Allocator, "Bootstrap loader") + JnjvmBootstrapLoader(Allocator, JIT, true); + Jnjvm* vm = new(Allocator, "VM") Jnjvm(Allocator, (CamlFrames**)frametables, loader); + + // Run the application. + vm->runApplication(argc, argv); + vm->waitForExit(); + + // Now AOT Compile all compiled methods. + JavaAOTCompiler* AOT = new JavaAOTCompiler("AOT"); + AOT->compileClassLoader(loader); + + AOT->printStats(); + + // Emit the bytecode in file. + std::string OutputFilename = "generated.bc"; + std::string ErrorInfo; + std::auto_ptr Out + (new llvm::raw_fd_ostream(OutputFilename.c_str(), ErrorInfo, + llvm::raw_fd_ostream::F_Binary)); + if (!ErrorInfo.empty()) { + llvm::errs() << ErrorInfo << '\n'; + return 1; + } + + // Make sure that the Out file gets unlinked from the disk if we get a + // SIGINT. + llvm::sys::RemoveFileOnSignal(llvm::sys::Path(OutputFilename)); + + llvm::WriteBitcodeToFile(AOT->getLLVMModule(), *Out); + + return 0; +} Added: vmkit/trunk/tools/precompiler/trainer/HelloWorld.java URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/precompiler/trainer/HelloWorld.java?rev=134923&view=auto ============================================================================== --- vmkit/trunk/tools/precompiler/trainer/HelloWorld.java (added) +++ vmkit/trunk/tools/precompiler/trainer/HelloWorld.java Mon Jul 11 16:28:04 2011 @@ -0,0 +1,8 @@ +class HelloWorld { + + public static final String str = "Hello World"; + + public static void main(String[] args) { + System.out.println(str); + } +} Added: vmkit/trunk/tools/precompiler/trainer/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/precompiler/trainer/Makefile?rev=134923&view=auto ============================================================================== --- vmkit/trunk/tools/precompiler/trainer/Makefile (added) +++ vmkit/trunk/tools/precompiler/trainer/Makefile Mon Jul 11 16:28:04 2011 @@ -0,0 +1,24 @@ +##===- tools/precompiler/trainer/Makefile ------------------*- Makefile -*-===## +# +# The VMKit project +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## +LEVEL = ../../.. + +include $(LEVEL)/Makefile.config + +MODULE_WITH_GC = Precompiled + +BUILT_SOURCES = generated.bc + +include $(LEVEL)/Makefile.common + +PRECOMPILER := $(ToolDir)/precompiler$(EXEEXT) + +generated.bc: $(PRECOMPILER) HelloWorld.java + $(Echo) "Building precompiled bootstrap code" + $(Verb) javac HelloWorld.java + $(Verb) $(PRECOMPILER) -cp $$PWD HelloWorld Propchange: vmkit/trunk/tools/precompiler/trainer/Makefile ------------------------------------------------------------------------------ svn:executable = * From nicolas.geoffray at lip6.fr Tue Jul 12 13:48:30 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Tue, 12 Jul 2011 20:48:30 -0000 Subject: [vmkit-commits] [vmkit] r134999 - /vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp Message-ID: <20110712204830.6F6882A6C12C@llvm.org> Author: geoffray Date: Tue Jul 12 15:48:30 2011 New Revision: 134999 URL: http://llvm.org/viewvc/llvm-project?rev=134999&view=rev Log: Only mmap 0x20000000 for threads, the other addresses will be used by MMTk. 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=134999&r1=134998&r2=134999&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp (original) +++ vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp Tue Jul 12 15:48:30 2011 @@ -290,20 +290,15 @@ baseAddr = 0; uintptr_t ptr = START_ADDR; - // Do an mmap at a fixed address. If the mmap fails for a given address - // use the next one. - while (!baseAddr && ptr != END_ADDR) { - ptr = ptr + 0x10000000; #if defined (__MACH__) - uint32 flags = MAP_PRIVATE | MAP_ANON | MAP_FIXED; + uint32 flags = MAP_PRIVATE | MAP_ANON | MAP_FIXED; #else - uint32 flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED; + uint32 flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED; #endif - baseAddr = (uintptr_t)mmap((void*)ptr, STACK_SIZE * NR_THREADS, - PROT_READ | PROT_WRITE, flags, -1, 0); - if (baseAddr == (uintptr_t)MAP_FAILED) baseAddr = 0; - } - if (!baseAddr) { + baseAddr = (uintptr_t)mmap((void*)ptr, STACK_SIZE * NR_THREADS, + PROT_READ | PROT_WRITE, flags, -1, 0); + + if (baseAddr == (uintptr_t) MAP_FAILED) { fprintf(stderr, "Can not allocate thread memory\n"); abort(); } From nicolas.geoffray at lip6.fr Thu Jul 14 14:06:14 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 14 Jul 2011 21:06:14 -0000 Subject: [vmkit-commits] [vmkit] r135187 - in /vmkit/trunk: include/j3/J3Intrinsics.h include/j3/JavaAOTCompiler.h include/j3/LLVMInfo.h include/mvm/JIT.h lib/J3/Compiler/J3Intrinsics.cpp lib/J3/Compiler/JavaAOTCompiler.cpp lib/J3/Compiler/JavaJIT.cpp lib/J3/Compiler/LLVMInfo.cpp lib/J3/LLVMRuntime/runtime-default.ll mmtk/inline/Makefile mmtk/magic/LowerMagic.cpp Message-ID: <20110714210614.46EF32A6C12C@llvm.org> Author: geoffray Date: Thu Jul 14 16:06:13 2011 New Revision: 135187 URL: http://llvm.org/viewvc/llvm-project?rev=135187&view=rev Log: API changes from LLVM after type-system-rewrite commit. Modified: vmkit/trunk/include/j3/J3Intrinsics.h vmkit/trunk/include/j3/JavaAOTCompiler.h vmkit/trunk/include/j3/LLVMInfo.h vmkit/trunk/include/mvm/JIT.h vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp vmkit/trunk/lib/J3/LLVMRuntime/runtime-default.ll vmkit/trunk/mmtk/inline/Makefile vmkit/trunk/mmtk/magic/LowerMagic.cpp Modified: vmkit/trunk/include/j3/J3Intrinsics.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/J3Intrinsics.h?rev=135187&r1=135186&r2=135187&view=diff ============================================================================== --- vmkit/trunk/include/j3/J3Intrinsics.h (original) +++ vmkit/trunk/include/j3/J3Intrinsics.h Thu Jul 14 16:06:13 2011 @@ -17,34 +17,34 @@ class J3Intrinsics : public mvm::BaseIntrinsics { public: - const llvm::Type* JavaArrayUInt8Type; - const llvm::Type* JavaArraySInt8Type; - const llvm::Type* JavaArrayUInt16Type; - const llvm::Type* JavaArraySInt16Type; - const llvm::Type* JavaArrayUInt32Type; - const llvm::Type* JavaArraySInt32Type; - const llvm::Type* JavaArrayLongType; - const llvm::Type* JavaArrayFloatType; - const llvm::Type* JavaArrayDoubleType; - const llvm::Type* JavaArrayObjectType; - - const llvm::Type* VTType; - const llvm::Type* JavaObjectType; - const llvm::Type* JavaArrayType; - const llvm::Type* JavaCommonClassType; - const llvm::Type* JavaClassType; - const llvm::Type* JavaClassArrayType; - const llvm::Type* JavaClassPrimitiveType; - const llvm::Type* ClassBytesType; - const llvm::Type* JavaConstantPoolType; - const llvm::Type* ResolvedConstantPoolType; - const llvm::Type* CodeLineInfoType; - const llvm::Type* UTF8Type; - const llvm::Type* JavaMethodType; - const llvm::Type* JavaFieldType; - const llvm::Type* AttributType; - const llvm::Type* JavaThreadType; - const llvm::Type* MutatorThreadType; + llvm::Type* JavaArrayUInt8Type; + llvm::Type* JavaArraySInt8Type; + llvm::Type* JavaArrayUInt16Type; + llvm::Type* JavaArraySInt16Type; + llvm::Type* JavaArrayUInt32Type; + llvm::Type* JavaArraySInt32Type; + llvm::Type* JavaArrayLongType; + llvm::Type* JavaArrayFloatType; + llvm::Type* JavaArrayDoubleType; + llvm::Type* JavaArrayObjectType; + + llvm::Type* VTType; + llvm::Type* JavaObjectType; + llvm::Type* JavaArrayType; + llvm::Type* JavaCommonClassType; + llvm::Type* JavaClassType; + llvm::Type* JavaClassArrayType; + llvm::Type* JavaClassPrimitiveType; + llvm::Type* ClassBytesType; + llvm::Type* JavaConstantPoolType; + llvm::Type* ResolvedConstantPoolType; + llvm::Type* CodeLineInfoType; + llvm::Type* UTF8Type; + llvm::Type* JavaMethodType; + llvm::Type* JavaFieldType; + llvm::Type* AttributType; + llvm::Type* JavaThreadType; + llvm::Type* MutatorThreadType; llvm::Function* StartJNIFunction; llvm::Function* EndJNIFunction; Modified: vmkit/trunk/include/j3/JavaAOTCompiler.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/JavaAOTCompiler.h?rev=135187&r1=135186&r2=135187&view=diff ============================================================================== --- vmkit/trunk/include/j3/JavaAOTCompiler.h (original) +++ vmkit/trunk/include/j3/JavaAOTCompiler.h Thu Jul 14 16:06:13 2011 @@ -102,10 +102,10 @@ llvm::Constant* getUTF8(const UTF8* val); template - llvm::Constant* CreateConstantFromIntArray(const T* val, const llvm::Type* Ty); + llvm::Constant* CreateConstantFromIntArray(const T* val, llvm::Type* Ty); template - llvm::Constant* CreateConstantFromFPArray(const T* val, const llvm::Type* Ty); + llvm::Constant* CreateConstantFromFPArray(const T* val, llvm::Type* Ty); llvm::Constant* CreateConstantFromObjectArray(const ArrayObject* val); Modified: vmkit/trunk/include/j3/LLVMInfo.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/LLVMInfo.h?rev=135187&r1=135186&r2=135187&view=diff ============================================================================== --- vmkit/trunk/include/j3/LLVMInfo.h (original) +++ vmkit/trunk/include/j3/LLVMInfo.h Thu Jul 14 16:06:13 2011 @@ -31,8 +31,8 @@ class LLVMAssessorInfo { public: - const llvm::Type* llvmType; - const llvm::Type* llvmTypePtr; + llvm::Type* llvmType; + llvm::Type* llvmTypePtr; uint8_t logSizeInBytesConstant; }; @@ -50,16 +50,16 @@ llvm::Constant* virtualSizeConstant; /// virtualType - The LLVM type of instance of this class. - const llvm::Type * virtualType; + llvm::Type * virtualType; /// staticType - The LLVM type of the static instance of this class. - const llvm::Type * staticType; + llvm::Type * staticType; public: llvm::Value* getVirtualSize(); - const llvm::Type* getVirtualType(); - const llvm::Type* getStaticType(); + llvm::Type* getVirtualType(); + llvm::Type* getStaticType(); LLVMClassInfo(Class* cl, JavaLLVMCompiler* comp) : Compiler(comp), @@ -84,13 +84,13 @@ llvm::Function* methodFunction; llvm::Constant* offsetConstant; - const llvm::FunctionType* functionType; + llvm::FunctionType* functionType; llvm::MDNode* DbgSubprogram; public: llvm::Function* getMethod(); llvm::Constant* getOffset(); - const llvm::FunctionType* getFunctionType(); + llvm::FunctionType* getFunctionType(); LLVMMethodInfo(JavaMethod* M, JavaLLVMCompiler* comp) : Compiler(comp), methodDef(M), methodFunction(0), offsetConstant(0), functionType(0), @@ -135,16 +135,16 @@ /// Compiler - The compiler for this signature info. JavaLLVMCompiler* Compiler; - const llvm::FunctionType* staticType; - const llvm::FunctionType* virtualType; - const llvm::FunctionType* nativeType; - - const llvm::FunctionType* virtualBufType; - const llvm::FunctionType* staticBufType; - - const llvm::PointerType* staticPtrType; - const llvm::PointerType* virtualPtrType; - const llvm::PointerType* nativePtrType; + llvm::FunctionType* staticType; + llvm::FunctionType* virtualType; + llvm::FunctionType* nativeType; + + llvm::FunctionType* virtualBufType; + llvm::FunctionType* staticBufType; + + llvm::PointerType* staticPtrType; + llvm::PointerType* virtualPtrType; + llvm::PointerType* nativePtrType; llvm::Function* virtualBufFunction; llvm::Function* virtualAPFunction; @@ -163,16 +163,16 @@ public: - const llvm::FunctionType* getVirtualType(); - const llvm::FunctionType* getStaticType(); - const llvm::FunctionType* getNativeType(); - - const llvm::FunctionType* getVirtualBufType(); - const llvm::FunctionType* getStaticBufType(); - - const llvm::PointerType* getStaticPtrType(); - const llvm::PointerType* getNativePtrType(); - const llvm::PointerType* getVirtualPtrType(); + llvm::FunctionType* getVirtualType(); + llvm::FunctionType* getStaticType(); + llvm::FunctionType* getNativeType(); + + llvm::FunctionType* getVirtualBufType(); + llvm::FunctionType* getStaticBufType(); + + llvm::PointerType* getStaticPtrType(); + llvm::PointerType* getNativePtrType(); + llvm::PointerType* getVirtualPtrType(); llvm::Function* getVirtualBuf(); llvm::Function* getVirtualAP(); Modified: vmkit/trunk/include/mvm/JIT.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/JIT.h?rev=135187&r1=135186&r2=135187&view=diff ============================================================================== --- vmkit/trunk/include/mvm/JIT.h (original) +++ vmkit/trunk/include/mvm/JIT.h Thu Jul 14 16:06:13 2011 @@ -171,11 +171,11 @@ llvm::Constant* constantPtrOne; llvm::Constant* constantPtrZero; - const llvm::PointerType* ptrType; - const llvm::PointerType* ptr32Type; - const llvm::PointerType* ptrPtrType; - const llvm::Type* arrayPtrType; - const llvm::Type* pointerSizeType; + llvm::PointerType* ptrType; + llvm::PointerType* ptr32Type; + llvm::PointerType* ptrPtrType; + llvm::Type* arrayPtrType; + llvm::Type* pointerSizeType; }; Modified: vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp?rev=135187&r1=135186&r2=135187&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp Thu Jul 14 16:06:13 2011 @@ -35,8 +35,9 @@ BaseIntrinsics(module) { j3::llvm_runtime::makeLLVMModuleContents(module); - VTType = PointerType::getUnqual(module->getTypeByName("VT")); LLVMContext& Context = module->getContext(); + VTType = PointerType::getUnqual(ArrayType::get( + PointerType::getUnqual(FunctionType::get(Type::getInt32Ty(Context), true)), 0)); ResolvedConstantPoolType = ptrPtrType; Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=135187&r1=135186&r2=135187&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Thu Jul 14 16:06:13 2011 @@ -71,7 +71,7 @@ native_class_iterator End = nativeClasses.end(); native_class_iterator I = nativeClasses.find(classDef); if (I == End) { - const llvm::Type* Ty = 0; + llvm::Type* Ty = NULL; if (classDef->isArray()) { Ty = JavaIntrinsics.JavaClassArrayType->getContainedType(0); @@ -100,7 +100,7 @@ array_class_iterator End = arrayClasses.end(); array_class_iterator I = arrayClasses.find(classDef->asArrayClass()); if (I == End) { - const llvm::Type* Ty = JavaIntrinsics.JavaClassArrayType; + llvm::Type* Ty = JavaIntrinsics.JavaClassArrayType; Module& Mod = *getLLVMModule(); GlobalVariable* varGV = @@ -120,7 +120,7 @@ } Constant* JavaAOTCompiler::CreateConstantFromJavaConstantPool(JavaConstantPool* ctp) { - const StructType* STy = + StructType* STy = dyn_cast(JavaIntrinsics.JavaConstantPoolType->getContainedType(0)); Module& Mod = *getLLVMModule(); @@ -133,7 +133,7 @@ Elemts.push_back(ConstantInt::get(Type::getInt32Ty(getLLVMContext()), ctp->ctpSize)); // ctpType - const ArrayType* ATy = ArrayType::get(Type::getInt8Ty(getLLVMContext()), ctp->ctpSize); + ArrayType* ATy = ArrayType::get(Type::getInt8Ty(getLLVMContext()), ctp->ctpSize); std::vector Vals; for (uint32 i = 0; i < ctp->ctpSize; ++i) { Vals.push_back(ConstantInt::get(Type::getInt8Ty(getLLVMContext()), ctp->ctpType[i])); @@ -177,7 +177,7 @@ if (I == End) { Module& Mod = *getLLVMModule(); - const ArrayType* ATy = ArrayType::get(JavaIntrinsics.ptrType, ctp->ctpSize); + ArrayType* ATy = ArrayType::get(JavaIntrinsics.ptrType, ctp->ctpSize); std::vector Vals; for (uint32 i = 0; i < ctp->ctpSize; ++i) { Vals.push_back(Constant::getNullValue(JavaIntrinsics.ptrType)); @@ -218,7 +218,7 @@ std::string name(UTF8Buffer(cl->name).toCompileName()->cString()); name += "_VirtualMethods"; Module& Mod = *getLLVMModule(); - const Type* ATy = + Type* ATy = ArrayType::get(JavaIntrinsics.JavaMethodType->getContainedType(0), cl->nbVirtualMethods + cl->nbStaticMethods); @@ -239,7 +239,7 @@ } else { assert(str && "No string given"); LLVMClassInfo* LCI = getClassInfo(JavaObject::getClass(str)->asClass()); - const llvm::Type* Ty = LCI->getVirtualType(); + llvm::Type* Ty = LCI->getVirtualType(); Module& Mod = *getLLVMModule(); const char* name = JavaString::strToAsciiz(str); @@ -264,7 +264,7 @@ Constant* JavaAOTCompiler::getJavaClass(CommonClass* cl) { Class* javaClass = cl->classLoader->bootstrapLoader->upcalls->newClass; LLVMClassInfo* LCI = getClassInfo(javaClass); - const llvm::Type* Ty = LCI->getVirtualType(); + llvm::Type* Ty = LCI->getVirtualType(); if (useCooperativeGC()) { return Constant::getNullValue(JavaIntrinsics.JavaObjectType); @@ -342,8 +342,8 @@ intptr_t* realObj = (intptr_t*)obj; intptr_t size = realObj[0]; - const ArrayType* ATy = ArrayType::get(JavaIntrinsics.JavaObjectType, - size + 1); + ArrayType* ATy = ArrayType::get(JavaIntrinsics.JavaObjectType, + size + 1); std::vector Vals; for (sint32 i = 0; i < size + 1; ++i) { @@ -379,7 +379,7 @@ if (I == End) { if (mvm::Collector::begOf(obj)) { - const Type* Ty = 0; + Type* Ty = 0; CommonClass* cl = JavaObject::getClass(obj); if (cl->isArray()) { @@ -409,8 +409,8 @@ Ty = JavaIntrinsics.JavaObjectType; } - std::vector Elemts; - const ArrayType* ATy = ArrayType::get(Ty, JavaArray::getSize(obj)); + std::vector Elemts; + ArrayType* ATy = ArrayType::get(Ty, JavaArray::getSize(obj)); Elemts.push_back(JavaIntrinsics.JavaObjectType->getContainedType(0)); Elemts.push_back(JavaIntrinsics.pointerSizeType); Elemts.push_back(ATy); @@ -446,8 +446,8 @@ Constant* JavaAOTCompiler::CreateConstantFromStaticInstance(Class* cl) { LLVMClassInfo* LCI = getClassInfo(cl); - const Type* Ty = LCI->getStaticType(); - const StructType* STy = dyn_cast(Ty->getContainedType(0)); + Type* Ty = LCI->getStaticType(); + StructType* STy = dyn_cast(Ty->getContainedType(0)); std::vector Elts; @@ -455,7 +455,7 @@ JavaField& field = cl->staticFields[i]; const Typedef* type = field.getSignature(); LLVMAssessorInfo& LAI = getTypedefInfo(type); - const Type* Ty = LAI.llvmType; + Type* Ty = LAI.llvmType; Attribut* attribut = field.lookupAttribut(Attribut::constantAttribut); @@ -550,7 +550,7 @@ if (I == End) { LLVMClassInfo* LCI = getClassInfo(classDef); - const Type* Ty = LCI->getStaticType(); + Type* Ty = LCI->getStaticType(); Ty = Ty->getContainedType(0); std::string name(UTF8Buffer(classDef->name).toCompileName()->cString()); name += "_static"; @@ -589,9 +589,9 @@ virtual_table_iterator I = virtualTables.find(VT); if (I == End) { - const ArrayType* ATy = + ArrayType* ATy = dyn_cast(JavaIntrinsics.VTType->getContainedType(0)); - const PointerType* PTy = dyn_cast(ATy->getContainedType(0)); + PointerType* PTy = dyn_cast(ATy->getContainedType(0)); ATy = ArrayType::get(PTy, size); std::string name(UTF8Buffer(classDef->name).toCompileName()->cString()); name += "_VT"; @@ -624,7 +624,7 @@ if (I == End) { LLVMSignatureInfo* LSI = getSignatureInfo(meth->getSignature()); - const llvm::Type* valPtrType = LSI->getNativePtrType(); + llvm::Type* valPtrType = LSI->getNativePtrType(); Module& Mod = *getLLVMModule(); varGV = new GlobalVariable(Mod, valPtrType, false, @@ -640,7 +640,7 @@ Constant* JavaAOTCompiler::CreateConstantForBaseObject(CommonClass* cl) { assert(!useCooperativeGC()); - const StructType* STy = + StructType* STy = dyn_cast(JavaIntrinsics.JavaObjectType->getContainedType(0)); std::vector Elmts; @@ -659,7 +659,7 @@ assert(!useCooperativeGC()); Class* javaClass = cl->classLoader->bootstrapLoader->upcalls->newClass; LLVMClassInfo* LCI = getClassInfo(javaClass); - const StructType* STy = + StructType* STy = dyn_cast(LCI->getVirtualType()->getContainedType(0)); std::vector Elmts; @@ -737,7 +737,7 @@ TempElts.push_back(CurConstant); Class* curCl = cl->virtualVT->display[j]->cl->asClass(); LLVMClassInfo* LCI = getClassInfo(curCl); - const StructType* STy = + StructType* STy = dyn_cast(LCI->getVirtualType()->getContainedType(0)); for (uint32 i = 0; i < curCl->nbVirtualFields; ++i) { @@ -780,7 +780,7 @@ Constant* C = getFinalObject(val, FieldCl); TempElts.push_back(C); } else { - const llvm::Type* Ty = JavaIntrinsics.JavaObjectType; + llvm::Type* Ty = JavaIntrinsics.JavaObjectType; TempElts.push_back(Constant::getNullValue(Ty)); } } @@ -796,7 +796,7 @@ assert(!useCooperativeGC()); Class* cl = JavaObject::getClass(str)->asClass(); LLVMClassInfo* LCI = getClassInfo(cl); - const StructType* STy = + StructType* STy = dyn_cast(LCI->getVirtualType()->getContainedType(0)); std::vector Elmts; @@ -828,7 +828,7 @@ Constant* JavaAOTCompiler::CreateConstantFromAttribut(Attribut& attribut) { - const StructType* STy = + StructType* STy = dyn_cast(JavaIntrinsics.AttributType->getContainedType(0)); @@ -847,21 +847,21 @@ } Constant* JavaAOTCompiler::CreateConstantFromCommonClass(CommonClass* cl) { - const StructType* STy = + StructType* STy = dyn_cast(JavaIntrinsics.JavaCommonClassType->getContainedType(0)); Module& Mod = *getLLVMModule(); - const llvm::Type* TempTy = 0; + llvm::Type* TempTy = NULL; std::vector CommonClassElts; std::vector TempElmts; // delegatee - const ArrayType* ATy = dyn_cast(STy->getContainedType(0)); + ArrayType* ATy = dyn_cast(STy->getContainedType(0)); assert(ATy && "Malformed type"); Constant* TCM[1] = { getJavaClass(cl) }; - CommonClassElts.push_back(ConstantArray::get(ATy, TCM, 1)); + CommonClassElts.push_back(ConstantArray::get(ATy, TCM)); // access CommonClassElts.push_back(ConstantInt::get(Type::getInt16Ty(getLLVMContext()), cl->access)); @@ -882,7 +882,7 @@ CommonClassElts.push_back(interfaces); } else { - const Type* Ty = PointerType::getUnqual(JavaIntrinsics.JavaClassType); + Type* Ty = PointerType::getUnqual(JavaIntrinsics.JavaClassType); CommonClassElts.push_back(Constant::getNullValue(Ty)); } @@ -917,7 +917,7 @@ } Constant* JavaAOTCompiler::CreateConstantFromJavaField(JavaField& field) { - const StructType* STy = + StructType* STy = dyn_cast(JavaIntrinsics.JavaFieldType->getContainedType(0)); std::vector FieldElts; @@ -937,8 +937,8 @@ // attributs if (field.nbAttributs) { - const llvm::Type* AttrTy = JavaIntrinsics.AttributType->getContainedType(0); - const ArrayType* ATy = ArrayType::get(AttrTy, field.nbAttributs); + llvm::Type* AttrTy = JavaIntrinsics.AttributType->getContainedType(0); + ArrayType* ATy = ArrayType::get(AttrTy, field.nbAttributs); for (uint32 i = 0; i < field.nbAttributs; ++i) { TempElts.push_back(CreateConstantFromAttribut(field.attributs[i])); } @@ -972,7 +972,7 @@ } Constant* JavaAOTCompiler::CreateConstantFromJavaMethod(JavaMethod& method) { - const StructType* STy = + StructType* STy = dyn_cast(JavaIntrinsics.JavaMethodType->getContainedType(0)); Module& Mod = *getLLVMModule(); @@ -987,8 +987,8 @@ // attributs if (method.nbAttributs) { - const llvm::Type* AttrTy = JavaIntrinsics.AttributType->getContainedType(0); - const ArrayType* ATy = ArrayType::get(AttrTy, method.nbAttributs); + llvm::Type* AttrTy = JavaIntrinsics.AttributType->getContainedType(0); + ArrayType* ATy = ArrayType::get(AttrTy, method.nbAttributs); for (uint32 i = 0; i < method.nbAttributs; ++i) { TempElts.push_back(CreateConstantFromAttribut(method.attributs[i])); } @@ -1044,9 +1044,9 @@ } Constant* JavaAOTCompiler::CreateConstantFromClassPrimitive(ClassPrimitive* cl) { - const llvm::Type* JCPTy = + llvm::Type* JCPTy = JavaIntrinsics.JavaClassPrimitiveType->getContainedType(0); - const StructType* STy = dyn_cast(JCPTy); + StructType* STy = dyn_cast(JCPTy); std::vector ClassElts; @@ -1060,7 +1060,7 @@ } Constant* JavaAOTCompiler::CreateConstantFromClassArray(ClassArray* cl) { - const StructType* STy = + StructType* STy = dyn_cast(JavaIntrinsics.JavaClassArrayType->getContainedType(0)); std::vector ClassElts; @@ -1081,7 +1081,7 @@ } Constant* JavaAOTCompiler::CreateConstantFromClass(Class* cl) { - const StructType* STy = + StructType* STy = dyn_cast(JavaIntrinsics.JavaClassType->getContainedType(0)); Module& Mod = *getLLVMModule(); @@ -1100,10 +1100,10 @@ cl->alignment)); // IsolateInfo - const ArrayType* ATy = dyn_cast(STy->getContainedType(3)); + ArrayType* ATy = dyn_cast(STy->getContainedType(3)); assert(ATy && "Malformed type"); - const StructType* TCMTy = dyn_cast(ATy->getContainedType(0)); + StructType* TCMTy = dyn_cast(ATy->getContainedType(0)); assert(TCMTy && "Malformed type"); uint32 status = cl->needsInitialisationCheck() ? vmjc : ready; @@ -1114,7 +1114,7 @@ TempElts.push_back(getStaticInstance(cl)); Constant* CStr[1] = { ConstantStruct::get(TCMTy, TempElts) }; TempElts.clear(); - ClassElts.push_back(ConstantArray::get(ATy, CStr, 1)); + ClassElts.push_back(ConstantArray::get(ATy, CStr)); if (cl->nbVirtualFields + cl->nbStaticFields) { ATy = ArrayType::get(JavaIntrinsics.JavaFieldType->getContainedType(0), @@ -1274,7 +1274,7 @@ TempElts.push_back(getNativeClass(cl->innerClasses[i])); } - const llvm::Type* TempTy = JavaIntrinsics.JavaClassType; + llvm::Type* TempTy = JavaIntrinsics.JavaClassType; ATy = ArrayType::get(TempTy, cl->nbInnerClasses); Constant* innerClasses = ConstantArray::get(ATy, TempElts); innerClasses = new GlobalVariable(*getLLVMModule(), ATy, true, @@ -1285,7 +1285,7 @@ ClassElts.push_back(innerClasses); } else { - const Type* Ty = PointerType::getUnqual(JavaIntrinsics.JavaClassType); + Type* Ty = PointerType::getUnqual(JavaIntrinsics.JavaClassType); ClassElts.push_back(Constant::getNullValue(Ty)); } @@ -1318,12 +1318,12 @@ } Constant* JavaAOTCompiler::CreateConstantFromClassBytes(ClassBytes* bytes) { - std::vector Elemts; - const ArrayType* ATy = ArrayType::get(Type::getInt8Ty(getLLVMContext()), bytes->size); + std::vector Elemts; + ArrayType* ATy = ArrayType::get(Type::getInt8Ty(getLLVMContext()), bytes->size); Elemts.push_back(Type::getInt32Ty(getLLVMContext())); Elemts.push_back(ATy); - const StructType* STy = StructType::get(getLLVMContext(), Elemts); + StructType* STy = StructType::get(getLLVMContext(), Elemts); std::vector Cts; Cts.push_back(ConstantInt::get(Type::getInt32Ty(getLLVMContext()), bytes->size)); @@ -1339,17 +1339,17 @@ } template -Constant* JavaAOTCompiler::CreateConstantFromIntArray(const T* val, const Type* Ty) { +Constant* JavaAOTCompiler::CreateConstantFromIntArray(const T* val, Type* Ty) { assert(!useCooperativeGC()); - std::vector Elemts; - const ArrayType* ATy = ArrayType::get(Ty, T::getSize(val)); + std::vector Elemts; + ArrayType* ATy = ArrayType::get(Ty, T::getSize(val)); Elemts.push_back(JavaIntrinsics.JavaObjectType->getContainedType(0)); Elemts.push_back(JavaIntrinsics.pointerSizeType); Elemts.push_back(ATy); - const StructType* STy = StructType::get(getLLVMModule()->getContext(), Elemts); + StructType* STy = StructType::get(getLLVMModule()->getContext(), Elemts); std::vector Cts; Cts.push_back(CreateConstantForBaseObject(JavaObject::getClass(val))); @@ -1366,17 +1366,17 @@ } template -Constant* JavaAOTCompiler::CreateConstantFromFPArray(const T* val, const Type* Ty) { +Constant* JavaAOTCompiler::CreateConstantFromFPArray(const T* val, Type* Ty) { assert(!useCooperativeGC()); - std::vector Elemts; - const ArrayType* ATy = ArrayType::get(Ty, T::getSize(val)); + std::vector Elemts; + ArrayType* ATy = ArrayType::get(Ty, T::getSize(val)); Elemts.push_back(JavaIntrinsics.JavaObjectType->getContainedType(0)); Elemts.push_back(JavaIntrinsics.pointerSizeType); Elemts.push_back(ATy); - const StructType* STy = StructType::get(getLLVMModule()->getContext(), Elemts); + StructType* STy = StructType::get(getLLVMModule()->getContext(), Elemts); std::vector Cts; Cts.push_back(CreateConstantForBaseObject(JavaObject::getClass(val))); @@ -1394,16 +1394,16 @@ Constant* JavaAOTCompiler::CreateConstantFromObjectArray(const ArrayObject* val) { assert(!useCooperativeGC()); - std::vector Elemts; - const llvm::Type* Ty = JavaIntrinsics.JavaObjectType; - const ArrayType* ATy = ArrayType::get(Ty, ArrayObject::getSize(val)); + std::vector Elemts; + llvm::Type* Ty = JavaIntrinsics.JavaObjectType; + ArrayType* ATy = ArrayType::get(Ty, ArrayObject::getSize(val)); Elemts.push_back(JavaIntrinsics.JavaObjectType->getContainedType(0)); Elemts.push_back(JavaIntrinsics.pointerSizeType); Elemts.push_back(ATy); - const StructType* STy = StructType::get(getLLVMModule()->getContext(), Elemts); + StructType* STy = StructType::get(getLLVMModule()->getContext(), Elemts); std::vector Cts; Cts.push_back(CreateConstantForBaseObject(JavaObject::getClass(val))); @@ -1426,13 +1426,13 @@ } Constant* JavaAOTCompiler::CreateConstantFromUTF8(const UTF8* val) { - std::vector Elemts; - const ArrayType* ATy = ArrayType::get(Type::getInt16Ty(getLLVMContext()), val->size); + std::vector Elemts; + ArrayType* ATy = ArrayType::get(Type::getInt16Ty(getLLVMContext()), val->size); Elemts.push_back(JavaIntrinsics.pointerSizeType); Elemts.push_back(ATy); - const StructType* STy = StructType::get(getLLVMModule()->getContext(), + StructType* STy = StructType::get(getLLVMModule()->getContext(), Elemts); std::vector Cts; @@ -1495,9 +1495,9 @@ JavaVirtualTable* RealVT = classDef->isClass() ? VT : ClassArray::SuperArray->virtualVT; - const ArrayType* ATy = + ArrayType* ATy = dyn_cast(JavaIntrinsics.VTType->getContainedType(0)); - const PointerType* PTy = dyn_cast(ATy->getContainedType(0)); + PointerType* PTy = dyn_cast(ATy->getContainedType(0)); ATy = ArrayType::get(PTy, size); ConstantPointerNull* N = ConstantPointerNull::get(PTy); @@ -1572,8 +1572,8 @@ ConstantInt::get(Type::getInt64Ty(getLLVMContext()), VT->nbSecondaryTypes), PTy)); // secondaryTypes - const ArrayType* DTy = ArrayType::get(JavaIntrinsics.VTType, - VT->nbSecondaryTypes); + ArrayType* DTy = ArrayType::get(JavaIntrinsics.VTType, + VT->nbSecondaryTypes); std::vector TempElmts; for (uint32 i = 0; i < VT->nbSecondaryTypes; ++i) { @@ -1612,9 +1612,9 @@ classDef->asClass()->fillIMT(contents); - const ArrayType* ATy = + ArrayType* ATy = dyn_cast(JavaIntrinsics.VTType->getContainedType(0)); - const PointerType* PTy = dyn_cast(ATy->getContainedType(0)); + PointerType* PTy = dyn_cast(ATy->getContainedType(0)); ATy = ArrayType::get(PTy, InterfaceMethodTable::NumIndexes); ConstantPointerNull* N = ConstantPointerNull::get(PTy); @@ -1656,7 +1656,7 @@ uint32_t length = 2 * size; - const ArrayType* ATy = + ArrayType* ATy = dyn_cast(JavaIntrinsics.VTType->getContainedType(0)); ATy = ArrayType::get(PTy, length); std::vector InternalElemts; @@ -1725,10 +1725,10 @@ compileRT = false; precompile = false; - std::vector llvmArgs; + std::vector llvmArgs; llvmArgs.push_back(JavaIntrinsics.ptrType); // class loader. - const FunctionType* FTy = FunctionType::get(Type::getVoidTy(getLLVMContext()), - llvmArgs, false); + FunctionType* FTy = FunctionType::get(Type::getVoidTy(getLLVMContext()), + llvmArgs, false); StaticInitializer = Function::Create(FTy, GlobalValue::InternalLinkage, "Init", getLLVMModule()); @@ -1799,10 +1799,10 @@ void JavaAOTCompiler::CreateStaticInitializer() { - std::vector llvmArgs; + std::vector llvmArgs; llvmArgs.push_back(JavaIntrinsics.ptrType); // class loader llvmArgs.push_back(JavaIntrinsics.JavaCommonClassType); // cl - const FunctionType* FTy = + FunctionType* FTy = FunctionType::get(Type::getVoidTy(getLLVMContext()), llvmArgs, false); Function* AddClass = Function::Create(FTy, GlobalValue::ExternalLinkage, @@ -1929,8 +1929,8 @@ LLVMSignatureInfo* LSI = getSignatureInfo(sign); - const FunctionType* type = stat ? LSI->getStaticType() : - LSI->getVirtualType(); + FunctionType* type = stat ? LSI->getStaticType() : + LSI->getVirtualType(); Value* func = ConstantExpr::getBitCast(Callback, PointerType::getUnqual(type)); @@ -2234,7 +2234,7 @@ void JavaAOTCompiler::generateMain(const char* name, bool jit) { // Type Definitions - std::vector FuncArgs; + std::vector FuncArgs; FuncArgs.push_back(Type::getInt32Ty(getLLVMContext())); FuncArgs.push_back(PointerType::getUnqual(JavaIntrinsics.ptrType)); Modified: vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp?rev=135187&r1=135186&r2=135187&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp Thu Jul 14 16:06:13 2011 @@ -1305,12 +1305,13 @@ for (sint32 i = start; i >= 0; --i) { it--; - if (it->get() == Type::getInt64Ty(*llvmContext) || it->get() == Type::getDoubleTy(*llvmContext)) { + if (*it == Type::getInt64Ty(*llvmContext) + || *it == Type::getDoubleTy(*llvmContext)) { pop(); } Value* tmp = pop(); - const Type* type = it->get(); + Type* type = *it; if (tmp->getType() != type) { // int8 or int16 convertValue(tmp, type, currentBlock, false); } Modified: vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp?rev=135187&r1=135186&r2=135187&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp Thu Jul 14 16:06:13 2011 @@ -35,17 +35,17 @@ using namespace j3; using namespace llvm; -const Type* LLVMClassInfo::getVirtualType() { +Type* LLVMClassInfo::getVirtualType() { if (!virtualType) { - std::vector fields; + std::vector fields; const TargetData* targetData = mvm::MvmModule::TheTargetData; const StructLayout* sl = 0; - const StructType* structType = 0; + StructType* structType = 0; LLVMContext& context = Compiler->getLLVMModule()->getContext(); if (classDef->super) { LLVMClassInfo* CLI = Compiler->getClassInfo(classDef->super); - const llvm::Type* Ty = CLI->getVirtualType()->getContainedType(0); + llvm::Type* Ty = CLI->getVirtualType()->getContainedType(0); fields.push_back(Ty); for (uint32 i = 0; i < classDef->nbVirtualFields; ++i) { @@ -63,7 +63,7 @@ } else { virtualType = Compiler->getIntrinsics()->JavaObjectType; assert(virtualType && "intrinsics not initalized"); - structType = dyn_cast(virtualType->getContainedType(0)); + structType = dyn_cast(virtualType->getContainedType(0)); sl = targetData->getStructLayout(structType); } @@ -90,11 +90,11 @@ return virtualType; } -const Type* LLVMClassInfo::getStaticType() { +Type* LLVMClassInfo::getStaticType() { if (!staticType) { Class* cl = (Class*)classDef; - std::vector fields; + std::vector fields; LLVMContext& context = Compiler->getLLVMModule()->getContext(); @@ -179,7 +179,7 @@ return methodFunction; } -const FunctionType* LLVMMethodInfo::getFunctionType() { +FunctionType* LLVMMethodInfo::getFunctionType() { if (!functionType) { Signdef* sign = methodDef->getSignature(); LLVMSignatureInfo* LSI = Compiler->getSignatureInfo(sign); @@ -219,11 +219,11 @@ return offsetConstant; } -const llvm::FunctionType* LLVMSignatureInfo::getVirtualType() { +llvm::FunctionType* LLVMSignatureInfo::getVirtualType() { if (!virtualType) { // Lock here because we are called by arbitrary code mvm::MvmModule::protectIR(); - std::vector llvmArgs; + std::vector llvmArgs; uint32 size = signature->nbArguments; Typedef* const* arguments = signature->getArgumentsType(); @@ -243,11 +243,11 @@ return virtualType; } -const llvm::FunctionType* LLVMSignatureInfo::getStaticType() { +llvm::FunctionType* LLVMSignatureInfo::getStaticType() { if (!staticType) { // Lock here because we are called by arbitrary code mvm::MvmModule::protectIR(); - std::vector llvmArgs; + std::vector llvmArgs; uint32 size = signature->nbArguments; Typedef* const* arguments = signature->getArgumentsType(); @@ -265,15 +265,15 @@ return staticType; } -const llvm::FunctionType* LLVMSignatureInfo::getNativeType() { +llvm::FunctionType* LLVMSignatureInfo::getNativeType() { if (!nativeType) { // Lock here because we are called by arbitrary code mvm::MvmModule::protectIR(); - std::vector llvmArgs; + std::vector llvmArgs; uint32 size = signature->nbArguments; Typedef* const* arguments = signature->getArgumentsType(); - const llvm::Type* Ty = + llvm::Type* Ty = PointerType::getUnqual(Compiler->getIntrinsics()->JavaObjectType); llvmArgs.push_back(Compiler->getIntrinsics()->ptrType); // JNIEnv @@ -282,7 +282,7 @@ for (uint32 i = 0; i < size; ++i) { Typedef* type = arguments[i]; LLVMAssessorInfo& LAI = Compiler->getTypedefInfo(type); - const llvm::Type* Ty = LAI.llvmType; + llvm::Type* Ty = LAI.llvmType; if (Ty == Compiler->getIntrinsics()->JavaObjectType) { llvmArgs.push_back(LAI.llvmTypePtr); } else { @@ -292,7 +292,7 @@ LLVMAssessorInfo& LAI = Compiler->getTypedefInfo(signature->getReturnType()); - const llvm::Type* RetType = + llvm::Type* RetType = LAI.llvmType == Compiler->getIntrinsics()->JavaObjectType ? LAI.llvmTypePtr : LAI.llvmType; nativeType = FunctionType::get(RetType, llvmArgs, false); @@ -564,21 +564,21 @@ return stub; } -const PointerType* LLVMSignatureInfo::getStaticPtrType() { +PointerType* LLVMSignatureInfo::getStaticPtrType() { if (!staticPtrType) { staticPtrType = PointerType::getUnqual(getStaticType()); } return staticPtrType; } -const PointerType* LLVMSignatureInfo::getVirtualPtrType() { +PointerType* LLVMSignatureInfo::getVirtualPtrType() { if (!virtualPtrType) { virtualPtrType = PointerType::getUnqual(getVirtualType()); } return virtualPtrType; } -const PointerType* LLVMSignatureInfo::getNativePtrType() { +PointerType* LLVMSignatureInfo::getNativePtrType() { if (!nativePtrType) { nativePtrType = PointerType::getUnqual(getNativeType()); } @@ -586,11 +586,11 @@ } -const FunctionType* LLVMSignatureInfo::getVirtualBufType() { +FunctionType* LLVMSignatureInfo::getVirtualBufType() { if (!virtualBufType) { // Lock here because we are called by arbitrary code mvm::MvmModule::protectIR(); - std::vector Args; + std::vector Args; Args.push_back(Compiler->getIntrinsics()->ResolvedConstantPoolType); // ctp Args.push_back(getVirtualPtrType()); Args.push_back(Compiler->getIntrinsics()->JavaObjectType); @@ -603,11 +603,11 @@ return virtualBufType; } -const FunctionType* LLVMSignatureInfo::getStaticBufType() { +FunctionType* LLVMSignatureInfo::getStaticBufType() { if (!staticBufType) { // Lock here because we are called by arbitrary code mvm::MvmModule::protectIR(); - std::vector Args; + std::vector Args; Args.push_back(Compiler->getIntrinsics()->ResolvedConstantPoolType); // ctp Args.push_back(getStaticPtrType()); Args.push_back(Compiler->AssessorInfo[I_LONG].llvmTypePtr); Modified: vmkit/trunk/lib/J3/LLVMRuntime/runtime-default.ll URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/LLVMRuntime/runtime-default.ll?rev=135187&r1=135186&r2=135187&view=diff ============================================================================== --- vmkit/trunk/lib/J3/LLVMRuntime/runtime-default.ll (original) +++ vmkit/trunk/lib/J3/LLVMRuntime/runtime-default.ll Thu Jul 14 16:06:13 2011 @@ -64,7 +64,37 @@ %JavaClassArray = type { %JavaCommonClass, %JavaCommonClass* } ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;;;; Constant calls for Jnjvm runtime internal objects field accesses ;;;;;;;;; +;;;;;;;;;;;;;;;;;;;; Make sure all named types are emitted ;;;;;;;;;;;;;;;;;;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +declare void @listAllTypes(%JavaObject, + %JavaArray, + %JavaCommonClass, + %JavaClassPrimitive, + %JavaClassArray, + %JavaClass, + %ClassBytes, + %JavaConstantPool, + %ArrayUInt8, + %ArraySInt8, + %ArrayUInt16, + %ArraySInt16, + %ArrayUInt32, + %ArraySInt32, + %ArrayLong, + %ArrayDouble, + %ArrayFloat, + %ArrayObject, + %JavaField, + %JavaMethod, + %UTF8, + %Attribut, + %JavaThread, + %MutatorThread, + %CodeLineInfo); + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;;;;;; Constant calls for J3 runtime internal objects field accesses ;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; j3RuntimeInitialiseClass - Initialises the class. Modified: vmkit/trunk/mmtk/inline/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/inline/Makefile?rev=135187&r1=135186&r2=135187&view=diff ============================================================================== --- vmkit/trunk/mmtk/inline/Makefile (original) +++ vmkit/trunk/mmtk/inline/Makefile Thu Jul 14 16:06:13 2011 @@ -17,3 +17,6 @@ # Use CompileCommonOpts instead of CXX.Flags to make sure the flag is added # after the -Wall added by LLVM. CompileCommonOpts += -Wno-unused-variable + +clean-local:: + $(Verb) $(RM) -f *.inc Modified: vmkit/trunk/mmtk/magic/LowerMagic.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/magic/LowerMagic.cpp?rev=135187&r1=135186&r2=135187&view=diff ============================================================================== --- vmkit/trunk/mmtk/magic/LowerMagic.cpp (original) +++ vmkit/trunk/mmtk/magic/LowerMagic.cpp Thu Jul 14 16:06:13 2011 @@ -382,22 +382,22 @@ Module* globalModule = F.getParent(); LLVMContext& Context = globalModule->getContext(); bool Changed = false; - const llvm::Type* pointerSizeType = + llvm::Type* pointerSizeType = globalModule->getPointerSize() == llvm::Module::Pointer32 ? Type::getInt32Ty(Context) : Type::getInt64Ty(Context); Constant* constantPtrLogSize = ConstantInt::get(Type::getInt32Ty(Context), sizeof(void*) == 8 ? 3 : 2); - const llvm::Type* ptrType = PointerType::getUnqual(Type::getInt8Ty(Context)); - const llvm::Type* ptrSizeType = PointerType::getUnqual(pointerSizeType); + llvm::Type* ptrType = PointerType::getUnqual(Type::getInt8Ty(Context)); + llvm::Type* ptrSizeType = PointerType::getUnqual(pointerSizeType); initialiseFunctions(globalModule); Function* MMalloc = globalModule->getFunction("AllocateMagicArray"); if (!MMalloc) { - std::vectorFuncTyArgs; + std::vectorFuncTyArgs; FuncTyArgs.push_back(Type::getInt32Ty(Context)); FuncTyArgs.push_back(ptrType); FunctionType* FuncTy = FunctionType::get(ptrType, FuncTyArgs, false); From nicolas.geoffray at lip6.fr Thu Jul 14 14:53:07 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 14 Jul 2011 21:53:07 -0000 Subject: [vmkit-commits] [vmkit] r135201 - in /vmkit/trunk/www: UsersManual.html get_started.html menu.html.incl use_aot.html use_mmtk.html Message-ID: <20110714215307.E841C2A6C12C@llvm.org> Author: geoffray Date: Thu Jul 14 16:53:07 2011 New Revision: 135201 URL: http://llvm.org/viewvc/llvm-project?rev=135201&view=rev Log: Remove obsolete instructions and be explicit that vmkit now needs clang or llvm-gcc. Removed: vmkit/trunk/www/UsersManual.html vmkit/trunk/www/use_aot.html vmkit/trunk/www/use_mmtk.html Modified: vmkit/trunk/www/get_started.html vmkit/trunk/www/menu.html.incl Removed: vmkit/trunk/www/UsersManual.html URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/www/UsersManual.html?rev=135200&view=auto ============================================================================== --- vmkit/trunk/www/UsersManual.html (original) +++ vmkit/trunk/www/UsersManual.html (removed) @@ -1,22 +0,0 @@ - - - - - VMKit - Getting Started - - - - - - - -
- -

VMKit User's Manual

- -
    -
  • Java Ahead of Time (AOT) Compilation
  • -
  • VMKit and MMTk
  • - - Modified: vmkit/trunk/www/get_started.html URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/www/get_started.html?rev=135201&r1=135200&r2=135201&view=diff ============================================================================== --- vmkit/trunk/www/get_started.html (original) +++ vmkit/trunk/www/get_started.html Thu Jul 14 16:53:07 2011 @@ -40,7 +40,8 @@
    1. Checkout - and build LLVM from SVN head:
    2. + and build LLVM from SVN head. Make sure you have llvm-gcc or clang available + when you configure LLVM. Alternatively, you can also checkout clang in llvm/tools.
      • svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
      • @@ -98,6 +99,18 @@
        Tell vmkit where GNU Classpath glibj.zip is located.

        --with-gnu-classpath-libs=<directory>
        Tell vmkit where GNU Classpath libs are located.
        +

        --with-mmtk-plan=
        +
        +
          +
        • org.mmtk.plan.marksweep.MS (default)
        • +
        • org.mmtk.plan.copyms.CopyMS
        • +
        • org.mmtk.plan.semispace.SS
        • +
        • org.mmtk.plan.immix.Immix
        • +
        • org.mmtk.plan.generational.marksweep.GenMS
        • +
        • org.mmtk.plan.generational.copying.GenCopy
        • +
        • org.mmtk.plan.generational.immix.GenImmix
        • +
        +
      Modified: vmkit/trunk/www/menu.html.incl URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/www/menu.html.incl?rev=135201&r1=135200&r2=135201&view=diff ============================================================================== --- vmkit/trunk/www/menu.html.incl (original) +++ vmkit/trunk/www/menu.html.incl Thu Jul 14 16:53:07 2011 @@ -8,7 +8,6 @@ About Get Started Get Involved - Users Manual Open Projects Publications Releases Removed: vmkit/trunk/www/use_aot.html URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/www/use_aot.html?rev=135200&view=auto ============================================================================== --- vmkit/trunk/www/use_aot.html (original) +++ vmkit/trunk/www/use_aot.html (removed) @@ -1,60 +0,0 @@ - - - - - VMKit - Getting Started - - - - - - - -
      - -

      Getting Started: Java Ahead of Time compilation with VMKit

      - - -

      This page gives you the instructions on how to use the Java ahead of time -compiler of VMKit.

      - - -
        -
      1. Checkout - and build VMKit from SVN head.
      2. - -
      3. Compile into a dynamic library the core Java libs (e.g. GNU Classpath): -
      4. - -
          -
        • cd tools/vmjc/libvmjc
        • -
        • make ENABLE_OPTIMIZED=1 (go get coffee)
        • -
        - -
      5. Update PATH to include LLVM and VMKit binaries (replace *_OBJ with your - directory):
      6. -
          -
        • export PATH=$(LLVM_OBJ)/Release/bin:$(VMKIT_OBJ)/Release/bin -
        • -
        - -
      7. Update LD_LIBRARY_PATH to include the dynamic library previously - compiled (replace VMKIT_OBJ with your directory):
      8. -
          -
        • export LD_LIBRARY_PATH=$(VMKIT_OBJ)/Release/lib -
        • -
        - -
      9. Use the llcj tool on a class or a jar file:
      10. -
          -
        • llcj -S Foo.class (emit bytecode)
        • -
        • llcj --main=Foo Foo.class (generate an executable)
        • -
        • llcj -c Foo.class (generate an object file)
        • -
        - -
      - -
      - - Removed: vmkit/trunk/www/use_mmtk.html URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/www/use_mmtk.html?rev=135200&view=auto ============================================================================== --- vmkit/trunk/www/use_mmtk.html (original) +++ vmkit/trunk/www/use_mmtk.html (removed) @@ -1,56 +0,0 @@ - - - - - VMKit - Getting Started - - - - - - - -
      - -

      Getting Started: VMKit and MMTk

      - - -

      This page gives you the instructions on how to build VMKit with a MMTk garbage collector.

      - - -
        -
      1. Checkout - and build LLVM-GCC from SVN head.
      2. -
      3. Update PATH to include the llvm-gcc binary.
      4. -
      5. Re-configure LLVM.
      6. -
      7. Configure VMKit with three additional options:
      8. -
          -
        • --with-gc=mmtk
        • -
        • --with-llvmgcc
        • -
        • --with-mmtk-plan=
        • -
            -
          • org.mmtk.plan.marksweep.MS (default)
          • -
          • org.mmtk.plan.copyms.CopyMS
          • -
          • org.mmtk.plan.semispace.SS
          • -
          • org.mmtk.plan.immix.Immix
          • -
          • org.mmtk.plan.generational.marksweep.GenMS
          • -
          • org.mmtk.plan.generational.copying.GenCopy
          • -
          • org.mmtk.plan.generational.immix.GenImmix
          • -
          -
        -
-
  • Build VMKit:
  • -
      -
    • make ENABLE_OPTIMIZED=1
    • -
    -
  • Run VMKit:
  • -
      -
    • Release/bin/j3 Foo
    • -
    - - - -
    - - From nicolas.geoffray at lip6.fr Thu Jul 21 13:58:12 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 21 Jul 2011 20:58:12 -0000 Subject: [vmkit-commits] [vmkit] r135703 - in /vmkit/trunk: include/mvm/JIT.h lib/J3/Compiler/JavaAOTCompiler.cpp lib/J3/Compiler/JavaJIT.cpp lib/J3/Compiler/JavaJIT.h lib/J3/Compiler/JavaJITCompiler.cpp lib/J3/Compiler/JavaJITOpcodes.cpp lib/J3/Compiler/LLVMInfo.cpp lib/J3/Compiler/LLVMMaterializer.cpp lib/J3/Compiler/LowerConstantCalls.cpp lib/Mvm/Compiler/JIT.cpp mmtk/magic/LowerMagic.cpp Message-ID: <20110721205812.575EC2A6C12D@llvm.org> Author: geoffray Date: Thu Jul 21 15:58:12 2011 New Revision: 135703 URL: http://llvm.org/viewvc/llvm-project?rev=135703&view=rev Log: Update to new LLVM API. Modified: vmkit/trunk/include/mvm/JIT.h vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp vmkit/trunk/lib/J3/Compiler/JavaJIT.h vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp vmkit/trunk/lib/J3/Compiler/LLVMMaterializer.cpp vmkit/trunk/lib/J3/Compiler/LowerConstantCalls.cpp vmkit/trunk/lib/Mvm/Compiler/JIT.cpp vmkit/trunk/mmtk/magic/LowerMagic.cpp Modified: vmkit/trunk/include/mvm/JIT.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/JIT.h?rev=135703&r1=135702&r2=135703&view=diff ============================================================================== --- vmkit/trunk/include/mvm/JIT.h (original) +++ vmkit/trunk/include/mvm/JIT.h Thu Jul 21 15:58:12 2011 @@ -189,7 +189,7 @@ static llvm::ExecutionEngine* executionEngine; //static unsigned MetadataTypeKind; - static uint64 getTypeSize(const llvm::Type* type); + static uint64 getTypeSize(llvm::Type* type); static void runPasses(llvm::Function* func, llvm::FunctionPassManager*); static void initialise(llvm::CodeGenOpt::Level = llvm::CodeGenOpt::Default, llvm::Module* TheModule = 0, Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=135703&r1=135702&r2=135703&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Thu Jul 21 15:58:12 2011 @@ -1841,7 +1841,7 @@ for (string_iterator i = strings.begin(), e = strings.end(); i != e; ++i) { Args[0] = loader; Args[1] = i->second; - CallInst::Create(AddString, Args, Args + 2, "", currentBlock); + CallInst::Create(AddString, ArrayRef(Args, 2), "", currentBlock); } } @@ -1851,7 +1851,7 @@ Args[0] = loader; Args[1] = ConstantExpr::getBitCast(i->second, JavaIntrinsics.JavaCommonClassType); - CallInst::Create(AddClass, Args, Args + 2, "", currentBlock); + CallInst::Create(AddClass, ArrayRef(Args, 2), "", currentBlock); } } @@ -1860,7 +1860,7 @@ Args[0] = loader; Args[1] = i->second; Args[2] = getUTF8(i->first->name); - CallInst::Create(GetClassArray, Args, Args + 3, "", currentBlock); + CallInst::Create(GetClassArray, ArrayRef(Args, 3), "", currentBlock); } @@ -2272,7 +2272,7 @@ jit ? "StartJnjvmWithJIT" : "StartJnjvmWithoutJIT", TheModule); - Value* res = CallInst::Create(CalledFunc, Args, Args + 3, "", currentBlock); + Value* res = CallInst::Create(CalledFunc, ArrayRef(Args, 3), "", currentBlock); ReturnInst::Create(getLLVMContext(), res, currentBlock); } Modified: vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp?rev=135703&r1=135702&r2=135703&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp Thu Jul 21 15:58:12 2011 @@ -114,9 +114,9 @@ Typedef* retTypedef = signature->getReturnType(); std::vector args; // size = [signature->nbIn + 3]; LLVMSignatureInfo* LSI = TheCompiler->getSignatureInfo(signature); - const llvm::FunctionType* virtualType = LSI->getVirtualType(); + llvm::FunctionType* virtualType = LSI->getVirtualType(); FunctionType::param_iterator it = virtualType->param_end(); - const llvm::Type* retType = virtualType->getReturnType(); + llvm::Type* retType = virtualType->getReturnType(); bool needsInit = false; if (canBeDirect && meth && !TheCompiler->needsCallback(meth, &needsInit)) { @@ -173,8 +173,7 @@ Value* VT = CallInst::Create(intrinsics->GetVTFunction, args[0], "", currentBlock); - Value* FuncPtr = GetElementPtrInst::Create(VT, indexes2, indexes2 + 2, "", - currentBlock); + Value* FuncPtr = GetElementPtrInst::Create(VT, indexes2, indexes2 + 2, "", currentBlock); Value* Func = new LoadInst(FuncPtr, "", currentBlock); @@ -277,8 +276,8 @@ bool stat = isStatic(compilingMethod->access); - const FunctionType *funcType = llvmFunction->getFunctionType(); - const llvm::Type* returnType = funcType->getReturnType(); + FunctionType *funcType = llvmFunction->getFunctionType(); + Type* returnType = funcType->getReturnType(); bool j3 = false; @@ -329,8 +328,7 @@ i++) { args.push_back(i); } - Value* res = CallInst::Create( - callee, args.begin(), args.end(), "", currentBlock); + Value* res = CallInst::Create(callee, args, "", currentBlock); if (returnType != Type::getVoidTy(*llvmContext)) { ReturnInst::Create(*llvmContext, res, currentBlock); } else { @@ -384,7 +382,7 @@ if (i->getType() == intrinsics->JavaObjectType) { BasicBlock* BB = createBasicBlock(""); BasicBlock* NotZero = createBasicBlock(""); - const Type* Ty = PointerType::getUnqual(intrinsics->JavaObjectType); + Type* Ty = PointerType::getUnqual(intrinsics->JavaObjectType); PHINode* node = PHINode::Create(Ty, 2, "", BB); Value* test = new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, i, @@ -408,7 +406,7 @@ intrinsics->constantPtrNull }; - CallInst::Create(intrinsics->llvm_gc_gcroot, GCArgs, GCArgs + 2, "", + CallInst::Create(intrinsics->llvm_gc_gcroot, GCArgs, "", func->begin()->getTerminator()); } @@ -437,7 +435,7 @@ intrinsics->constantPtrNull }; - CallInst::Create(intrinsics->llvm_gc_gcroot, GCArgs, GCArgs + 2, "", + CallInst::Create(intrinsics->llvm_gc_gcroot, GCArgs, "", currentBlock); } else { new StoreInst(intrinsics->JavaObjectNullConstant, ResultObject, "", @@ -455,7 +453,7 @@ BasicBlock* unloadedBlock = createBasicBlock(""); BasicBlock* endBlock = createBasicBlock(""); Value* test = new LoadInst(nativeFunc, "", currentBlock); - const llvm::Type* Ty = test->getType(); + Type* Ty = test->getType(); PHINode* node = PHINode::Create(Ty, 2, "", endBlock); node->addIncoming(test, currentBlock); Value* cmp = new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, test, @@ -480,14 +478,13 @@ Value* Args4[3] = { temp, oldCLIN, Frame }; - CallInst::Create(intrinsics->StartJNIFunction, Args4, Args4 + 3, "", - currentBlock); + CallInst::Create(intrinsics->StartJNIFunction, Args4, "", currentBlock); - Value* result = llvm::CallInst::Create(nativeFunc, nativeArgs.begin(), - nativeArgs.end(), "", currentBlock); + Value* result = llvm::CallInst::Create(nativeFunc, nativeArgs, "", + currentBlock); if (returnType == intrinsics->JavaObjectType) { - const Type* Ty = PointerType::getUnqual(intrinsics->JavaObjectType); + Type* Ty = PointerType::getUnqual(intrinsics->JavaObjectType); Constant* C = Constant::getNullValue(Ty); Value* cmp = new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, result, C, ""); BasicBlock* loadBlock = createBasicBlock(""); @@ -512,7 +509,7 @@ Value* Args2[1] = { oldCLIN }; - CallInst::Create(intrinsics->EndJNIFunction, Args2, Args2 + 1, "", currentBlock); + CallInst::Create(intrinsics->EndJNIFunction, Args2, "", currentBlock); // Synchronize after leaving native. if (isSynchro(compilingMethod->access)) @@ -560,8 +557,7 @@ // Do the atomic compare and swap. Value* atomic = CallInst::Create(intrinsics->llvm_atomic_lcs_ptr, - atomicArgs.begin(), atomicArgs.end(), "", - currentBlock); + atomicArgs, "", currentBlock); Value* cmp = new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, atomic, lock, ""); @@ -609,8 +605,7 @@ // Do the atomic compare and swap. Value* atomic = CallInst::Create(intrinsics->llvm_atomic_lcs_ptr, - atomicArgs.begin(), atomicArgs.end(), "", - currentBlock); + atomicArgs, "", currentBlock); Value* cmp = new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, atomic, oldValMask, ""); @@ -685,8 +680,7 @@ Instruction* I = new BitCastInst(temp, intrinsics->ptrPtrType, ""); I->insertAfter(temp); Value* GCArgs[2] = { I, intrinsics->constantPtrNull }; - Instruction* C = CallInst::Create(intrinsics->llvm_gc_gcroot, GCArgs, - GCArgs + 2, ""); + Instruction* C = CallInst::Create(intrinsics->llvm_gc_gcroot, GCArgs, ""); C->insertAfter(I); } } @@ -724,7 +718,7 @@ assert(LMI); Function* func = LMI->getMethod(); - const Type* returnType = func->getReturnType(); + Type* returnType = func->getReturnType(); endBlock = createBasicBlock("end"); currentBlock = curBB; @@ -818,7 +812,7 @@ for (;count < max; ++i, ++index, ++count, ++type) { const Typedef* cur = arguments[type]; - const Type* curType = (*i)->getType(); + Type* curType = (*i)->getType(); if (curType == Type::getInt64Ty(*llvmContext)){ new StoreInst(*i, longLocals[index], false, currentBlock); @@ -905,8 +899,8 @@ reader.seek(codeLen, Reader::SeekCur); - const FunctionType *funcType = llvmFunction->getFunctionType(); - const Type* returnType = funcType->getReturnType(); + FunctionType *funcType = llvmFunction->getFunctionType(); + Type* returnType = funcType->getReturnType(); Function* func = llvmFunction; @@ -929,8 +923,7 @@ new BitCastInst(returnValue, intrinsics->ptrPtrType, "", currentBlock); Value* GCArgs[2] = { cast, intrinsics->constantPtrNull }; - CallInst::Create(intrinsics->llvm_gc_gcroot, GCArgs, GCArgs + 2, "", - currentBlock); + CallInst::Create(intrinsics->llvm_gc_gcroot, GCArgs, "", currentBlock); } for (int i = 0; i < maxLocals; i++) { @@ -980,7 +973,7 @@ for (;count < max; ++i, ++index, ++count, ++type) { const Typedef* cur = arguments[type]; - const llvm::Type* curType = i->getType(); + Type* curType = i->getType(); if (curType == Type::getInt64Ty(*llvmContext)){ new StoreInst(i, longLocals[index], false, currentBlock); @@ -1174,7 +1167,7 @@ return llvmFunction; } -void JavaJIT::compareFP(Value* val1, Value* val2, const Type* ty, bool l) { +void JavaJIT::compareFP(Value* val1, Value* val2, Type* ty, bool l) { Value* one = intrinsics->constantOne; Value* zero = intrinsics->constantZero; Value* minus = intrinsics->constantMinusOne; @@ -1208,7 +1201,7 @@ push(val, false, upcalls->newString); } else { // Lookup the constant pool cache - const llvm::Type* Ty = PointerType::getUnqual(intrinsics->JavaObjectType); + Type* Ty = PointerType::getUnqual(intrinsics->JavaObjectType); Value* val = getConstantPoolAt(index, intrinsics->StringLookupFunction, Ty, 0, false); val = new LoadInst(val, "", currentBlock); @@ -1261,7 +1254,7 @@ } Value* JavaJIT::verifyAndComputePtr(Value* obj, Value* index, - const Type* arrayType, bool verif) { + Type* arrayType, bool verif) { JITVerifyNull(obj); if (index->getType() != Type::getInt32Ty(*llvmContext)) { @@ -1395,8 +1388,7 @@ "tmp1", currentBlock); } else if (name->equals(loader->atan2)) { return llvm::CallInst::Create(intrinsics->func_llvm_atan2_f64, - args.begin(), args.end(), "tmp1", - currentBlock); + args, "tmp1", currentBlock); } else if (name->equals(loader->exp)) { return llvm::CallInst::Create(intrinsics->func_llvm_exp_f64, args[0], "tmp1", currentBlock); @@ -1404,8 +1396,8 @@ return llvm::CallInst::Create(intrinsics->func_llvm_log_f64, args[0], "tmp1", currentBlock); } else if (name->equals(loader->pow)) { - return llvm::CallInst::Create(intrinsics->func_llvm_pow_f64, args.begin(), - args.end(), "tmp1", currentBlock); + return llvm::CallInst::Create(intrinsics->func_llvm_pow_f64, args, + "tmp1", currentBlock); } else if (name->equals(loader->ceil)) { return llvm::CallInst::Create(intrinsics->func_llvm_ceil_f64, args[0], "tmp1", currentBlock); @@ -1468,7 +1460,7 @@ ctpInfo->nameOfStaticOrSpecialMethod(index, cl, name, signature); LLVMSignatureInfo* LSI = TheCompiler->getSignatureInfo(signature); - const llvm::FunctionType* virtualType = LSI->getVirtualType(); + FunctionType* virtualType = LSI->getVirtualType(); meth = ctpInfo->infoOfStaticOrSpecialMethod(index, ACC_VIRTUAL, signature); Value* func = 0; @@ -1506,7 +1498,7 @@ val = invoke(func, args, "", currentBlock); } - const llvm::Type* retType = virtualType->getReturnType(); + Type* retType = virtualType->getReturnType(); if (retType != Type::getVoidTy(*llvmContext)) { if (retType == intrinsics->JavaObjectType) { JnjvmClassLoader* JCL = compilingClass->classLoader; @@ -1528,7 +1520,7 @@ const UTF8* className = 0; ctpInfo->nameOfStaticOrSpecialMethod(index, className, name, signature); LLVMSignatureInfo* LSI = TheCompiler->getSignatureInfo(signature); - const llvm::FunctionType* staticType = LSI->getStaticType(); + FunctionType* staticType = LSI->getStaticType(); ctpInfo->markAsStaticCall(index); JnjvmBootstrapLoader* loader = compilingClass->classLoader->bootstrapLoader; llvm::Instruction* val = 0; @@ -1574,7 +1566,7 @@ } } - const llvm::Type* retType = staticType->getReturnType(); + Type* retType = staticType->getReturnType(); if (retType != Type::getVoidTy(*llvmContext)) { if (retType == intrinsics->JavaObjectType) { JnjvmClassLoader* JCL = compilingClass->classLoader; @@ -1590,7 +1582,7 @@ } Value* JavaJIT::getConstantPoolAt(uint32 index, Function* resolver, - const Type* returnType, + Type* returnType, Value* additionalArg, bool doThrow) { // This makes unswitch loop very unhappy time-wise, but makes GVN happy @@ -1611,11 +1603,11 @@ res = invoke(intrinsics->GetConstantPoolAtFunction, Args, "", currentBlock); } else { - res = CallInst::Create(intrinsics->GetConstantPoolAtFunction, Args.begin(), - Args.end(), "", currentBlock); + res = CallInst::Create(intrinsics->GetConstantPoolAtFunction, Args, + "", currentBlock); } - const Type* realType = + Type* realType = intrinsics->GetConstantPoolAtFunction->getReturnType(); if (returnType == Type::getInt32Ty(*llvmContext)) { return new PtrToIntInst(res, Type::getInt32Ty(*llvmContext), "", currentBlock); @@ -1725,14 +1717,14 @@ } Value* JavaJIT::ldResolved(uint16 index, bool stat, Value* object, - const Type* fieldTypePtr) { + Type* fieldTypePtr) { JavaConstantPool* info = compilingClass->ctpInfo; JavaField* field = info->lookupField(index, stat); if (field && field->classDef->isResolved()) { LLVMClassInfo* LCI = TheCompiler->getClassInfo(field->classDef); LLVMFieldInfo* LFI = TheCompiler->getFieldInfo(field); - const Type* type = 0; + Type* type = NULL; if (stat) { type = LCI->getStaticType(); Value* Cl = TheCompiler->getNativeClass(field->classDef); @@ -1762,13 +1754,13 @@ return ptr; } - const Type* Pty = intrinsics->arrayPtrType; + Type* Pty = intrinsics->arrayPtrType; Constant* zero = intrinsics->constantZero; Function* func = stat ? intrinsics->StaticFieldLookupFunction : intrinsics->VirtualFieldLookupFunction; - const Type* returnType = 0; + Type* returnType = NULL; if (stat) { returnType = intrinsics->ptrType; } else { @@ -1787,9 +1779,9 @@ return new BitCastInst(ptr, fieldTypePtr, "", currentBlock); } -void JavaJIT::convertValue(Value*& val, const Type* t1, BasicBlock* currentBlock, +void JavaJIT::convertValue(Value*& val, Type* t1, BasicBlock* currentBlock, bool usign) { - const Type* t2 = val->getType(); + Type* t2 = val->getType(); if (t1 != t2) { if (t1->isIntegerTy() && t2->isIntegerTy()) { if (t2->getPrimitiveSizeInBits() < t1->getPrimitiveSizeInBits()) { @@ -1817,7 +1809,7 @@ void JavaJIT::setStaticField(uint16 index) { Typedef* sign = compilingClass->ctpInfo->infoOfField(index); LLVMAssessorInfo& LAI = TheCompiler->getTypedefInfo(sign); - const Type* type = LAI.llvmType; + Type* type = LAI.llvmType; Value* ptr = ldResolved(index, true, NULL, LAI.llvmTypePtr); @@ -1835,7 +1827,7 @@ ptr = new BitCastInst(ptr, intrinsics->ptrPtrType, "", currentBlock); val = new BitCastInst(val, intrinsics->ptrType, "", currentBlock); Value* args[2] = { ptr, val }; - CallInst::Create(intrinsics->NonHeapWriteBarrierFunction, args, args + 2, "", currentBlock); + CallInst::Create(intrinsics->NonHeapWriteBarrierFunction, args, "", currentBlock); } else { new StoreInst(val, ptr, false, currentBlock); } @@ -1844,7 +1836,7 @@ void JavaJIT::getStaticField(uint16 index) { Typedef* sign = compilingClass->ctpInfo->infoOfField(index); LLVMAssessorInfo& LAI = TheCompiler->getTypedefInfo(sign); - const Type* type = LAI.llvmType; + Type* type = LAI.llvmType; Value* ptr = ldResolved(index, true, NULL, LAI.llvmTypePtr); @@ -1916,7 +1908,7 @@ void JavaJIT::setVirtualField(uint16 index) { Typedef* sign = compilingClass->ctpInfo->infoOfField(index); LLVMAssessorInfo& LAI = TheCompiler->getTypedefInfo(sign); - const Type* type = LAI.llvmType; + Type* type = LAI.llvmType; int stackIndex = currentStackIndex - 2; if (type == Type::getInt64Ty(*llvmContext) || type == Type::getDoubleTy(*llvmContext)) { @@ -1942,7 +1934,7 @@ object = new LoadInst(object, "", currentBlock); object = new BitCastInst(object, intrinsics->ptrType, "", currentBlock); Value* args[3] = { object, ptr, val }; - CallInst::Create(intrinsics->FieldWriteBarrierFunction, args, args + 3, "", currentBlock); + CallInst::Create(intrinsics->FieldWriteBarrierFunction, args, "", currentBlock); } else { new StoreInst(val, ptr, false, currentBlock); } @@ -1954,7 +1946,7 @@ CommonClass* cl = sign->findAssocClass(JCL); LLVMAssessorInfo& LAI = TheCompiler->getTypedefInfo(sign); - const Type* type = LAI.llvmType; + Type* type = LAI.llvmType; Value* obj = objectStack[currentStackIndex - 1]; pop(); // Pop the object @@ -2012,10 +2004,10 @@ Signdef* signature = ctpInfo->infoOfInterfaceOrVirtualMethod(index, name); LLVMSignatureInfo* LSI = TheCompiler->getSignatureInfo(signature); - const llvm::FunctionType* virtualType = LSI->getVirtualType(); - const llvm::PointerType* virtualPtrType = LSI->getVirtualPtrType(); + FunctionType* virtualType = LSI->getVirtualType(); + PointerType* virtualPtrType = LSI->getVirtualPtrType(); - const llvm::Type* retType = virtualType->getReturnType(); + Type* retType = virtualType->getReturnType(); CommonClass* cl = 0; JavaMethod* meth = 0; @@ -2079,7 +2071,7 @@ Constant* MinusTwo = ConstantInt::get(intrinsics->pointerSizeType, -2); BinaryOperator* int32_25 = BinaryOperator::Create(Instruction::And, int32_19, MinusTwo, "", currentBlock); - const PointerType* Ty = PointerType::getUnqual(intrinsics->JavaMethodType); + PointerType* Ty = PointerType::getUnqual(intrinsics->JavaMethodType); CastInst* ptr_26 = new IntToPtrInst(int32_25, Ty, "", currentBlock); LoadInst* int32_27 = new LoadInst(ptr_26, "", false, currentBlock); ICmpInst* int1_28 = new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, int32_27, @@ -2402,8 +2394,7 @@ const char* Name, BasicBlock *InsertAtEnd) { - Instruction* res = CallInst::Create(F, args.begin(), args.end(), Name, - InsertAtEnd); + Instruction* res = CallInst::Create(F, args, Name, InsertAtEnd); DebugLoc DL = CreateLocation(); res->setDebugLoc(DL); @@ -2503,7 +2494,7 @@ Value* args[2] = { arg1, arg2 }; - Instruction* res = CallInst::Create(F, args, args + 2, Name, InsertAtEnd); + Instruction* res = CallInst::Create(F, args, Name, InsertAtEnd); DebugLoc DL = CreateLocation(); res->setDebugLoc(DL); @@ -2629,7 +2620,7 @@ void JavaJIT::throwException(llvm::Function* F, Value** args, uint32 nbArgs) { - Instruction* obj = CallInst::Create(F, args, args + nbArgs, "", currentBlock); + Instruction* obj = CallInst::Create(F, ArrayRef(args, nbArgs), "", currentBlock); DebugLoc DL = CreateLocation(); obj->setDebugLoc(DL); @@ -2794,8 +2785,7 @@ Value* classArgs[2] = { objVT, VTVar }; cmp = CallInst::Create(intrinsics->IsSecondaryClassFunction, - classArgs, classArgs + 2, "", - currentBlock); + classArgs, "", currentBlock); } else { @@ -2804,8 +2794,7 @@ Value* displayArgs[2] = { inDisplay, depthCl }; Value* VTInDisplay = CallInst::Create(intrinsics->GetVTInDisplayFunction, - displayArgs, displayArgs + 2, "", - currentBlock); + displayArgs, "", currentBlock); cmp = new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, VTInDisplay, VTVar, ""); Modified: vmkit/trunk/lib/J3/Compiler/JavaJIT.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJIT.h?rev=135703&r1=135702&r2=135703&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJIT.h (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJIT.h Thu Jul 21 15:58:12 2011 @@ -134,7 +134,7 @@ } /// convertValue - Convert a value to a new type. - void convertValue(llvm::Value*& val, const llvm::Type* t1, + void convertValue(llvm::Value*& val, llvm::Type* t1, llvm::BasicBlock* currentBlock, bool usign); /// getMutatorThreadPtr - Emit code to get a pointer to the current MutatorThread. @@ -222,11 +222,11 @@ /// verifyAndComputePtr - Computes the address in the array. If out of bounds /// throw an exception. llvm::Value* verifyAndComputePtr(llvm::Value* obj, llvm::Value* index, - const llvm::Type* arrayType, + llvm::Type* arrayType, bool verif = true); /// compareFP - Do float comparisons. - void compareFP(llvm::Value*, llvm::Value*, const llvm::Type*, bool l); + void compareFP(llvm::Value*, llvm::Value*, llvm::Type*, bool l); //===------------------------- Stack manipulation -------------------------===// @@ -242,7 +242,7 @@ /// push - Push a new value in the stack. void push(llvm::Value* val, bool unsign, CommonClass* cl = 0) { - const llvm::Type* type = val->getType(); + llvm::Type* type = val->getType(); if (unsign) { val = new llvm::ZExtInst(val, llvm::Type::getInt32Ty(*llvmContext), "", currentBlock); new llvm::StoreInst(val, intStack[currentStackIndex++], false, @@ -435,7 +435,7 @@ /// ldResolved - Emit code to get a pointer to a field. llvm::Value* ldResolved(uint16 index, bool stat, llvm::Value* object, - const llvm::Type* fieldTypePtr); + llvm::Type* fieldTypePtr); //===--------------------- Constant pool accesses ------------------------===// @@ -454,7 +454,7 @@ /// pool. The generated code invokes the resolver if the constant pool /// contains no value at the index. llvm::Value* getConstantPoolAt(uint32 index, llvm::Function* resolver, - const llvm::Type* returnType, + llvm::Type* returnType, llvm::Value* addArg, bool doThrow = true); //===----------------------- Java method calls ---------------------------===// Modified: vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp?rev=135703&r1=135702&r2=135703&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp Thu Jul 21 15:58:12 2011 @@ -92,7 +92,7 @@ Constant* JavaJITCompiler::getNativeClass(CommonClass* classDef) { - const llvm::Type* Ty = classDef->isClass() ? JavaIntrinsics.JavaClassType : + Type* Ty = classDef->isClass() ? JavaIntrinsics.JavaClassType : JavaIntrinsics.JavaCommonClassType; ConstantInt* CI = ConstantInt::get(Type::getInt64Ty(getLLVMContext()), @@ -122,7 +122,7 @@ Constant* JavaJITCompiler::getStringPtr(JavaString** str) { assert(str && "No string given"); - const llvm::Type* Ty = PointerType::getUnqual(JavaIntrinsics.JavaObjectType); + Type* Ty = PointerType::getUnqual(JavaIntrinsics.JavaObjectType); ConstantInt* CI = ConstantInt::get(Type::getInt64Ty(getLLVMContext()), uint64(str)); return ConstantExpr::getIntToPtr(CI, Ty); @@ -139,7 +139,7 @@ assert(obj && "Delegatee not created"); Constant* CI = ConstantInt::get(Type::getInt64Ty(getLLVMContext()), uint64(obj)); - const Type* Ty = PointerType::getUnqual(JavaIntrinsics.JavaObjectType); + Type* Ty = PointerType::getUnqual(JavaIntrinsics.JavaObjectType); return ConstantExpr::getIntToPtr(CI, Ty); } @@ -182,7 +182,7 @@ Constant* JavaJITCompiler::getNativeFunction(JavaMethod* meth, void* ptr) { LLVMSignatureInfo* LSI = getSignatureInfo(meth->getSignature()); - const llvm::Type* valPtrType = LSI->getNativePtrType(); + Type* valPtrType = LSI->getNativePtrType(); assert(ptr && "No native function given"); Modified: vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp?rev=135703&r1=135702&r2=135703&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp Thu Jul 21 15:58:12 2011 @@ -164,7 +164,7 @@ }; - CallInst::Create(intrinsics->PrintExecutionFunction, args, args + 3, "", + CallInst::Create(intrinsics->PrintExecutionFunction, args, "", currentBlock); } #endif @@ -707,7 +707,7 @@ Value* VTArgs[2] = { valVT, objVT }; Value* res = CallInst::Create(intrinsics->IsAssignableFromFunction, - VTArgs, VTArgs + 2, "", currentBlock); + VTArgs, "", currentBlock); BranchInst::Create(endBlock, exceptionBlock, res, currentBlock); @@ -726,7 +726,7 @@ val = new BitCastInst(val, intrinsics->ptrType, "", currentBlock); obj = new BitCastInst(obj, intrinsics->ptrType, "", currentBlock); Value* args[3] = { obj, ptr, val }; - CallInst::Create(intrinsics->ArrayWriteBarrierFunction, args, args + 3, "", currentBlock); + CallInst::Create(intrinsics->ArrayWriteBarrierFunction, args, "", currentBlock); } else { new StoreInst(val, ptr, false, currentBlock); } @@ -748,7 +748,7 @@ case CASTORE : { Value* val = pop(); - const Type* type = val->getType(); + Type* type = val->getType(); if (type == Type::getInt32Ty(*llvmContext)) { val = new TruncInst(val, Type::getInt16Ty(*llvmContext), "", currentBlock); } else if (type == Type::getInt8Ty(*llvmContext)) { @@ -764,7 +764,7 @@ case SASTORE : { Value* val = pop(); - const Type* type = val->getType(); + Type* type = val->getType(); if (type == Type::getInt32Ty(*llvmContext)) { val = new TruncInst(val, Type::getInt16Ty(*llvmContext), "", currentBlock); } else if (type == Type::getInt8Ty(*llvmContext)) { @@ -1635,7 +1635,7 @@ BasicBlock* ifTrue = ifTrueInfo.newBlock; Value* op = pop(); - const Type* type = op->getType(); + Type* type = op->getType(); Constant* val = Constant::getNullValue(type); llvm::Value* test = new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, op, val, ""); @@ -1652,7 +1652,7 @@ BasicBlock* ifTrue = ifTrueInfo.newBlock; Value* op = pop(); - const Type* type = op->getType(); + Type* type = op->getType(); Constant* val = Constant::getNullValue(type); llvm::Value* test = new ICmpInst(*currentBlock, ICmpInst::ICMP_NE, op, val, ""); @@ -1668,7 +1668,7 @@ i += 2; BasicBlock* ifTrue = ifTrueInfo.newBlock; Value* op = pop(); - const Type* type = op->getType(); + Type* type = op->getType(); Constant* val = Constant::getNullValue(type); llvm::Value* test = new ICmpInst(*currentBlock, ICmpInst::ICMP_SLT, op, val, ""); @@ -1684,7 +1684,7 @@ i += 2; BasicBlock* ifTrue = ifTrueInfo.newBlock; Value* op = pop(); - const Type* type = op->getType(); + Type* type = op->getType(); Constant* val = Constant::getNullValue(type); llvm::Value* test = new ICmpInst(*currentBlock, ICmpInst::ICMP_SGE, op, val, ""); @@ -1700,7 +1700,7 @@ i += 2; BasicBlock* ifTrue = ifTrueInfo.newBlock; Value* op = pop(); - const Type* type = op->getType(); + Type* type = op->getType(); Constant* val = Constant::getNullValue(type); llvm::Value* test = new ICmpInst(*currentBlock, ICmpInst::ICMP_SGT, op, val, ""); @@ -1716,7 +1716,7 @@ i += 2; BasicBlock* ifTrue = ifTrueInfo.newBlock; Value* op = pop(); - const Type* type = op->getType(); + Type* type = op->getType(); Constant* val = Constant::getNullValue(type); llvm::Value* test = new ICmpInst(*currentBlock, ICmpInst::ICMP_SLE, op, val, ""); @@ -1902,7 +1902,7 @@ Value* index = pop(); - const llvm::Type* type = index->getType(); + Type* type = index->getType(); for (sint32 cur = low; cur < high; ++cur) { Value* cmp = new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, ConstantInt::get(type, cur), index, ""); @@ -2071,7 +2071,7 @@ Value* args[2] = { isolateLocal, ConstantInt::get(Type::getInt32Ty(*llvmContext), id - 4) }; valCl = CallInst::Create(intrinsics->GetJnjvmArrayClassFunction, - args, args + 2, "", currentBlock); + args, "", currentBlock); #endif LLVMAssessorInfo& LAI = TheCompiler->AssessorInfo[charId]; @@ -2111,13 +2111,13 @@ } } else { - const llvm::Type* Ty = + Type* Ty = PointerType::getUnqual(intrinsics->VTType); Value* args[3]= { TheCompiler->getNativeClass(compilingClass), ConstantInt::get(Type::getInt32Ty(*llvmContext), index), Constant::getNullValue(Ty) }; TheVT = CallInst::Create(intrinsics->GetArrayClassFunction, args, - args + 3, "", currentBlock); + "", currentBlock); } sizeElement = intrinsics->constantPtrLogSize; @@ -2248,8 +2248,7 @@ if (cl) { if (cl->isSecondaryClass()) { res = CallInst::Create(intrinsics->IsSecondaryClassFunction, - classArgs, classArgs + 2, "", - currentBlock); + classArgs, "", currentBlock); } else { Value* inDisplay = CallInst::Create(intrinsics->GetDisplayFunction, objVT, "", currentBlock); @@ -2259,16 +2258,14 @@ Value* displayArgs[2] = { inDisplay, CI }; Value* VTInDisplay = CallInst::Create(intrinsics->GetVTInDisplayFunction, - displayArgs, displayArgs + 2, "", - currentBlock); + displayArgs, "", currentBlock); res = new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, VTInDisplay, TheVT, ""); } } else { res = CallInst::Create(intrinsics->IsAssignableFromFunction, - classArgs, classArgs + 2, "", - currentBlock); + classArgs, "", currentBlock); } node->addIncoming(res, currentBlock); Modified: vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp?rev=135703&r1=135702&r2=135703&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp Thu Jul 21 15:58:12 2011 @@ -379,8 +379,7 @@ currentBlock); } - Value* val = CallInst::Create(func, Args.begin(), Args.end(), "", - currentBlock); + Value* val = CallInst::Create(func, Args, "", currentBlock); if (!signature->getReturnType()->isVoid()) { ReturnInst::Create(context, val, currentBlock); } else { @@ -452,8 +451,7 @@ Args.push_back(arg); } - Value* val = CallInst::Create(func, Args.begin(), Args.end(), "", - currentBlock); + Value* val = CallInst::Create(func, Args, "", currentBlock); if (!signature->getReturnType()->isVoid()) { ReturnInst::Create(context, val, currentBlock); } else { @@ -507,8 +505,7 @@ Intrinsics.constantPtrNull }; - CallInst::Create(Intrinsics.llvm_gc_gcroot, GCArgs, GCArgs + 2, "", - currentBlock); + CallInst::Create(Intrinsics.llvm_gc_gcroot, GCArgs, "", currentBlock); } TempArgs.push_back(temp); @@ -525,7 +522,7 @@ Value* val = CallInst::Create(virt ? Intrinsics.ResolveVirtualStubFunction : special ? Intrinsics.ResolveSpecialStubFunction: Intrinsics.ResolveStaticStubFunction, - Args.begin(), Args.end(), "", currentBlock); + Args, "", currentBlock); Constant* nullValue = Constant::getNullValue(val->getType()); Value* cmp = new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, @@ -547,8 +544,7 @@ } FunctionArgs.push_back(temp); } - Value* res = CallInst::Create(Func, FunctionArgs.begin(), FunctionArgs.end(), - "", currentBlock); + Value* res = CallInst::Create(Func, FunctionArgs, "", currentBlock); if (node) node->addIncoming(res, currentBlock); BranchInst::Create(endBlock, currentBlock); Modified: vmkit/trunk/lib/J3/Compiler/LLVMMaterializer.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/LLVMMaterializer.cpp?rev=135703&r1=135702&r2=135703&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/LLVMMaterializer.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/LLVMMaterializer.cpp Thu Jul 21 15:58:12 2011 @@ -91,7 +91,7 @@ F = TheModule->getFunction(key); if (F) return F; - const FunctionType* type = stat ? LSI->getStaticType() : + FunctionType* type = stat ? LSI->getStaticType() : LSI->getVirtualType(); F = Function::Create(type, GlobalValue::ExternalWeakLinkage, key, TheModule); Modified: vmkit/trunk/lib/J3/Compiler/LowerConstantCalls.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/LowerConstantCalls.cpp?rev=135703&r1=135702&r2=135703&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/LowerConstantCalls.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/LowerConstantCalls.cpp Thu Jul 21 15:58:12 2011 @@ -290,7 +290,7 @@ intrinsics->OffsetDisplayInVTConstant }; Value* DisplayPtr = GetElementPtrInst::Create(val, indexes, indexes + 2, "", CI); - const llvm::Type* Ty = PointerType::getUnqual(intrinsics->VTType); + Type* Ty = PointerType::getUnqual(intrinsics->VTType); DisplayPtr = new BitCastInst(DisplayPtr, Ty, "", CI); CI->replaceAllUsesWith(DisplayPtr); CI->eraseFromParent(); @@ -363,8 +363,7 @@ BasicBlock* UI = Invoke->getUnwindDest(); res = InvokeInst::Create(intrinsics->InitialiseClassFunction, - trueCl, UI, Args, Args + 1, - "", falseCl); + trueCl, UI, Args, "", falseCl); // For some reason, an LLVM pass may add PHI nodes to the // exception destination. @@ -403,7 +402,7 @@ } else if (V == intrinsics->GetConstantPoolAtFunction) { Function* resolver = dyn_cast(Call.getArgument(0)); assert(resolver && "Wrong use of GetConstantPoolAt"); - const Type* returnType = resolver->getReturnType(); + Type* returnType = resolver->getReturnType(); Value* CTP = Call.getArgument(1); Value* Index = Call.getArgument(3); Changed = true; @@ -438,8 +437,7 @@ Instruction* res = 0; if (InvokeInst* Invoke = dyn_cast(CI)) { BasicBlock* UI = Invoke->getUnwindDest(); - res = InvokeInst::Create(resolver, trueCl, UI, Args.begin(), - Args.end(), "", falseCl); + res = InvokeInst::Create(resolver, trueCl, UI, Args, "", falseCl); // For some reason, an LLVM pass may add PHI nodes to the // exception destination. @@ -462,8 +460,7 @@ } } else { - res = CallInst::Create(resolver, Args.begin(), Args.end(), "", - falseCl); + res = CallInst::Create(resolver, Args, "", falseCl); BranchInst::Create(trueCl, falseCl); } @@ -475,7 +472,7 @@ BranchInst::Create(NBB, trueCl); break; } else if (V == intrinsics->GetArrayClassFunction) { - const llvm::Type* Ty = PointerType::getUnqual(intrinsics->VTType); + Type* Ty = PointerType::getUnqual(intrinsics->VTType); Constant* nullValue = Constant::getNullValue(Ty); // Check if we have already proceed this call. if (Call.getArgument(2) == nullValue) { @@ -502,7 +499,7 @@ Value* args[3] = { Call.getArgument(0), Call.getArgument(1), GV }; Instruction* res = CallInst::Create(intrinsics->GetArrayClassFunction, args, - args + 3, "", NotOKBlock); + "", NotOKBlock); res->setDebugLoc(CI->getDebugLoc()); BranchInst::Create(OKBlock, NotOKBlock); node->addIncoming(res, NotOKBlock); @@ -561,7 +558,7 @@ Value* Args[2] = { VT1, VT2 }; res = CallInst::Create(intrinsics->IsSecondaryClassFunction, Args, - Args + 2, "", FailedBlock); + "", FailedBlock); res->setDebugLoc(CI->getDebugLoc()); node->addIncoming(res, FailedBlock); @@ -592,7 +589,7 @@ BasicBlock* BB6 = BasicBlock::Create(*Context, "BB6", &F); BasicBlock* BB7 = BasicBlock::Create(*Context, "BB7", &F); BasicBlock* BB9 = BasicBlock::Create(*Context, "BB9", &F); - const Type* Ty = PointerType::getUnqual(intrinsics->VTType); + Type* Ty = PointerType::getUnqual(intrinsics->VTType); PHINode* resFwd = PHINode::Create(Type::getInt32Ty(*Context), 2, "", BB7); Modified: vmkit/trunk/lib/Mvm/Compiler/JIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Compiler/JIT.cpp?rev=135703&r1=135702&r2=135703&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Compiler/JIT.cpp (original) +++ vmkit/trunk/lib/Mvm/Compiler/JIT.cpp Thu Jul 21 15:58:12 2011 @@ -310,7 +310,7 @@ mvm::BumpPtrAllocator* MvmModule::Allocator; //unsigned MvmModule::MetadataTypeKind; -uint64 MvmModule::getTypeSize(const llvm::Type* type) { +uint64 MvmModule::getTypeSize(llvm::Type* type) { return TheTargetData->getTypeAllocSize(type); } Modified: vmkit/trunk/mmtk/magic/LowerMagic.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/magic/LowerMagic.cpp?rev=135703&r1=135702&r2=135703&view=diff ============================================================================== --- vmkit/trunk/mmtk/magic/LowerMagic.cpp (original) +++ vmkit/trunk/mmtk/magic/LowerMagic.cpp Thu Jul 21 15:58:12 2011 @@ -459,7 +459,7 @@ !strcmp(FCur->getName().data(), AddressStoreWordMethod)) { Value* Addr = Call.getArgument(0); Value* Obj = Call.getArgument(1); - const llvm::Type* Ty = PointerType::getUnqual(Obj->getType()); + Type* Ty = PointerType::getUnqual(Obj->getType()); Addr = new BitCastInst(Addr, Ty, "", CI); new StoreInst(Obj, Addr, CI); CI->eraseFromParent(); @@ -471,7 +471,7 @@ !strcmp(FCur->getName().data(), AddressLoadIntMethod) || !strcmp(FCur->getName().data(), AddressPrepareWordMethod)) { Value* Addr = Call.getArgument(0); - const Type* Ty = PointerType::getUnqual(FCur->getReturnType()); + Type* Ty = PointerType::getUnqual(FCur->getReturnType()); Addr = new BitCastInst(Addr, Ty, "", CI); Value* LD = new LoadInst(Addr, "", CI); CI->replaceAllUsesWith(LD); @@ -584,13 +584,13 @@ Ptr = new PtrToIntInst(Ptr, pointerSizeType, "", CI); Offset = new PtrToIntInst(Offset, pointerSizeType, "", CI); Ptr = BinaryOperator::CreateAdd(Ptr, Offset, "", CI); - const Type* Ty = PointerType::getUnqual(pointerSizeType); + Type* Ty = PointerType::getUnqual(pointerSizeType); Ptr = new IntToPtrInst(Ptr, Ty, "", CI); Old = new PtrToIntInst(Old, pointerSizeType, "", CI); Val = new PtrToIntInst(Val, pointerSizeType, "", CI); Value* Args[3] = { Ptr, Old, Val }; - Value* res = CallInst::Create(CASPtr, Args, Args + 3, "", CI); + Value* res = CallInst::Create(CASPtr, Args, "", CI); res = new ICmpInst(CI, ICmpInst::ICMP_EQ, res, Old, ""); res = new ZExtInst(res, FCur->getReturnType(), "", CI); @@ -601,13 +601,13 @@ Value* Old = Call.getArgument(1); Value* Val = Call.getArgument(2); - const Type* Ty = PointerType::getUnqual(pointerSizeType); + Type* Ty = PointerType::getUnqual(pointerSizeType); Ptr = new BitCastInst(Ptr, Ty, "", CI); Old = new PtrToIntInst(Old, pointerSizeType, "", CI); Val = new PtrToIntInst(Val, pointerSizeType, "", CI); Value* Args[3] = { Ptr, Old, Val }; - Value* res = CallInst::Create(CASPtr, Args, Args + 3, "", CI); + Value* res = CallInst::Create(CASPtr, Args, "", CI); res = new ICmpInst(CI, ICmpInst::ICMP_EQ, res, Old, ""); res = new ZExtInst(res, FCur->getReturnType(), "", CI); @@ -626,7 +626,7 @@ Ptr = new PtrToIntInst(Ptr, pointerSizeType, "", CI); Offset = new PtrToIntInst(Offset, pointerSizeType, "", CI); Ptr = BinaryOperator::CreateAdd(Ptr, Offset, "", CI); - const Type* Ty = PointerType::getUnqual(FCur->getReturnType()); + Type* Ty = PointerType::getUnqual(FCur->getReturnType()); Ptr = new IntToPtrInst(Ptr, Ty, "", CI); Value* res = new LoadInst(Ptr, "", CI); @@ -643,7 +643,7 @@ Ptr = new PtrToIntInst(Ptr, pointerSizeType, "", CI); Offset = new PtrToIntInst(Offset, pointerSizeType, "", CI); Ptr = BinaryOperator::CreateAdd(Ptr, Offset, "", CI); - const Type* Ty = PointerType::getUnqual(Val->getType()); + Type* Ty = PointerType::getUnqual(Val->getType()); Ptr = new IntToPtrInst(Ptr, Ty, "", CI); new StoreInst(Val, Ptr, CI); @@ -1197,7 +1197,7 @@ Length = BinaryOperator::CreateShl(Length, constantPtrLogSize, "", CI); Val = new IntToPtrInst(Val, ptrType, "", CI); Value* args[2] = { Length, Val }; - Value* res = CallInst::Create(MMalloc, args, args + 2, "", CI); + Value* res = CallInst::Create(MMalloc, args, "", CI); res = new BitCastInst(res, FCur->getReturnType(), "", CI); CI->replaceAllUsesWith(res); CI->eraseFromParent(); From nicolas.geoffray at lip6.fr Fri Jul 22 14:32:31 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Fri, 22 Jul 2011 21:32:31 -0000 Subject: [vmkit-commits] [vmkit] r135808 - in /vmkit/trunk: lib/J3/Compiler/JavaAOTCompiler.cpp lib/J3/Compiler/LLVMInfo.cpp lib/J3/VMCore/JavaClass.cpp lib/J3/VMCore/JnjvmClassLoader.cpp lib/Mvm/Compiler/JIT.cpp mmtk/inline/InlineMethods.cpp mmtk/magic/LowerJavaRT.cpp mmtk/mmtk-alloc/Selected.cpp mmtk/mmtk-j3/Memory.cpp tools/precompiler/Precompiler.cpp tools/vmjc/vmjc.cpp Message-ID: <20110722213231.BDD6B2A6C12D@llvm.org> Author: geoffray Date: Fri Jul 22 16:32:31 2011 New Revision: 135808 URL: http://llvm.org/viewvc/llvm-project?rev=135808&view=rev Log: Few changes to make AOT precompiler work. Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp vmkit/trunk/lib/J3/VMCore/JavaClass.cpp vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp vmkit/trunk/lib/Mvm/Compiler/JIT.cpp vmkit/trunk/mmtk/inline/InlineMethods.cpp vmkit/trunk/mmtk/magic/LowerJavaRT.cpp vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp vmkit/trunk/mmtk/mmtk-j3/Memory.cpp vmkit/trunk/tools/precompiler/Precompiler.cpp vmkit/trunk/tools/vmjc/vmjc.cpp Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=135808&r1=135807&r2=135808&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Fri Jul 22 16:32:31 2011 @@ -57,7 +57,7 @@ } else if (classDef->isArray()) { Constant* C = CreateConstantFromClassArray(classDef->asArrayClass()); varGV->setInitializer(C); - } else if (classDef->isPrimitive()) { + } else if (classDef->isPrimitive() && compileRT) { Constant* C = CreateConstantFromClassPrimitive(classDef->asPrimitiveClass()); varGV->setInitializer(C); @@ -2186,7 +2186,6 @@ } void JavaAOTCompiler::compileClassLoader(JnjvmBootstrapLoader* loader) { - loader->setCompiler(this); compileRT = true; precompile = true; addJavaPasses(); @@ -2215,10 +2214,19 @@ parseFunction(meth); } - for (native_class_iterator i = nativeClasses.begin(), - e = nativeClasses.end(); i != e; ++i) { - AddInitializerToClass(i->second, i->first); - } + bool changed = false; + do { + changed = false; + for (native_class_iterator i = nativeClasses.begin(), + e = nativeClasses.end(); i != e; ++i) { + if (!i->second->hasInitializer()) { + changed = true; + AddInitializerToClass(i->second, i->first); + } + } + } while (changed); + + CreateStaticInitializer(); } /// compileAllStubs - Compile all the native -> Java stubs. Modified: vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp?rev=135808&r1=135807&r2=135808&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp Fri Jul 22 16:32:31 2011 @@ -406,7 +406,7 @@ Function* res = Function::Create(virt ? getVirtualBufType() : getStaticBufType(), - GlobalValue::InternalLinkage, name, + GlobalValue::ExternalLinkage, name, Compiler->getLLVMModule()); LLVMContext& context = Compiler->getLLVMModule()->getContext(); @@ -480,7 +480,7 @@ Function* stub = Function::Create((virt || special) ? getVirtualType() : getStaticType(), - GlobalValue::InternalLinkage, name, + GlobalValue::ExternalLinkage, name, Compiler->getLLVMModule()); LLVMContext& context = Compiler->getLLVMModule()->getContext(); Modified: vmkit/trunk/lib/J3/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaClass.cpp?rev=135808&r1=135807&r2=135808&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JavaClass.cpp Fri Jul 22 16:32:31 2011 @@ -53,7 +53,7 @@ this->name = name; } -Attribut* Class::lookupAttribut(const UTF8* key ) { +Attribut* Class::lookupAttribut(const UTF8* key) { for (uint32 i = 0; i < nbAttributs; ++i) { Attribut* cur = &(attributs[i]); if (cur->name->equals(key)) return cur; @@ -62,7 +62,7 @@ return 0; } -Attribut* JavaField::lookupAttribut(const UTF8* key ) { +Attribut* JavaField::lookupAttribut(const UTF8* key) { for (uint32 i = 0; i < nbAttributs; ++i) { Attribut* cur = &(attributs[i]); if (cur->name->equals(key)) return cur; @@ -71,7 +71,7 @@ return 0; } -Attribut* JavaMethod::lookupAttribut(const UTF8* key ) { +Attribut* JavaMethod::lookupAttribut(const UTF8* key) { for (uint32 i = 0; i < nbAttributs; ++i) { Attribut* cur = &(attributs[i]); if (cur->name->equals(key)) return cur; Modified: vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp?rev=135808&r1=135807&r2=135808&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp Fri Jul 22 16:32:31 2011 @@ -1198,10 +1198,6 @@ JavaField& field = realCl->staticFields[i]; JCL->hashUTF8->insert(field.name); JCL->hashUTF8->insert(field.type); - if (field.getSignature()->isReference() - && (field.lookupAttribut(Attribut::constantAttribut) != NULL)) { - field.InitStaticField(JCL->getIsolate()); - } } for (uint32 i = 0; i< realCl->nbVirtualFields; ++i) { Modified: vmkit/trunk/lib/Mvm/Compiler/JIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Compiler/JIT.cpp?rev=135808&r1=135807&r2=135808&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Compiler/JIT.cpp (original) +++ vmkit/trunk/lib/Mvm/Compiler/JIT.cpp Fri Jul 22 16:32:31 2011 @@ -48,12 +48,6 @@ #include #include -#if defined(__MACH__) -#define SELF_HANDLE RTLD_DEFAULT -#else -#define SELF_HANDLE 0 -#endif - using namespace mvm; using namespace llvm; @@ -156,18 +150,15 @@ } +extern "C" void MMTk_InlineMethods(llvm::Module* module); + BaseIntrinsics::BaseIntrinsics(llvm::Module* module) { module->setDataLayout(MvmModule::globalModule->getDataLayout()); module->setTargetTriple(MvmModule::globalModule->getTargetTriple()); LLVMContext& Context = module->getContext(); - typedef void (*init_inline_t)(llvm::Module* module); - static const char* MMTkSymbol = "MMTk_InlineMethods"; - init_inline_t init_inline = - (init_inline_t)(uintptr_t)dlsym(SELF_HANDLE, MMTkSymbol); - if (init_inline != NULL) init_inline(module); - + MMTk_InlineMethods(module); mvm::llvm_runtime::makeLLVMModuleContents(module); // Type declaration Modified: vmkit/trunk/mmtk/inline/InlineMethods.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/inline/InlineMethods.cpp?rev=135808&r1=135807&r2=135808&view=diff ============================================================================== --- vmkit/trunk/mmtk/inline/InlineMethods.cpp (original) +++ vmkit/trunk/mmtk/inline/InlineMethods.cpp Fri Jul 22 16:32:31 2011 @@ -35,11 +35,11 @@ #include "MMTkNonHeapWriteInline.inc" } -extern "C" void MMTk_InlineMethods(llvm::Module* module) { - mmtk_malloc::makeLLVMFunction(module); - //mmtk_field_write::makeLLVMFunction(module); - //mmtk_array_write::makeLLVMFunction(module); - //mmtk_non_heap_write::makeLLVMFunction(module); } +extern "C" void MMTk_InlineMethods(llvm::Module* module) { + //mmtk::mmtk_malloc::makeLLVMFunction(module); + //mmtk::mmtk_field_write::makeLLVMFunction(module); + //mmtk::mmtk_array_write::makeLLVMFunction(module); + //mmtk::mmtk_non_heap_write::makeLLVMFunction(module); } Modified: vmkit/trunk/mmtk/magic/LowerJavaRT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/magic/LowerJavaRT.cpp?rev=135808&r1=135807&r2=135808&view=diff ============================================================================== --- vmkit/trunk/mmtk/magic/LowerJavaRT.cpp (original) +++ vmkit/trunk/mmtk/magic/LowerJavaRT.cpp Fri Jul 22 16:32:31 2011 @@ -69,6 +69,7 @@ if (!strncmp(GV.getName().data(), "JnJVM_java", 10) || !strncmp(GV.getName().data(), "java", 4) || !strncmp(GV.getName().data(), "JnJVM_gnu", 9) || + !strncmp(GV.getName().data(), "_3", 2) || !strncmp(GV.getName().data(), "gnu", 3)) { GV.replaceAllUsesWith(Constant::getNullValue(GV.getType())); GV.eraseFromParent(); @@ -92,9 +93,4 @@ return Changed; } - -ModulePass* createLowerJavaRT() { - return new LowerJavaRT(); -} - } Modified: vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp?rev=135808&r1=135807&r2=135808&view=diff ============================================================================== --- vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp (original) +++ vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp Fri Jul 22 16:32:31 2011 @@ -164,7 +164,7 @@ #else uint32 flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED; #endif - void* baseAddr = mmap((void*)0x30000000, 0x30000000, PROT_READ | PROT_WRITE, + void* baseAddr = mmap((void*)0x60000000, 0x40000000, PROT_READ | PROT_WRITE, flags, -1, 0); if (baseAddr == MAP_FAILED) { perror("mmap"); Modified: vmkit/trunk/mmtk/mmtk-j3/Memory.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/mmtk-j3/Memory.cpp?rev=135808&r1=135807&r2=135808&view=diff ============================================================================== --- vmkit/trunk/mmtk/mmtk-j3/Memory.cpp (original) +++ vmkit/trunk/mmtk/mmtk-j3/Memory.cpp Fri Jul 22 16:32:31 2011 @@ -16,19 +16,19 @@ namespace mmtk { extern "C" uintptr_t Java_org_j3_mmtk_Memory_getHeapStartConstant__ (MMTkObject* M) { - return (uintptr_t)0x30000000; + return (uintptr_t)0x60000000; } extern "C" uintptr_t Java_org_j3_mmtk_Memory_getHeapEndConstant__ (MMTkObject* M) { - return (uintptr_t)0x60000000; + return (uintptr_t)0xa0000000; } extern "C" uintptr_t Java_org_j3_mmtk_Memory_getAvailableStartConstant__ (MMTkObject* M) { - return (uintptr_t)0x30000000; + return (uintptr_t)0x60000000; } extern "C" uintptr_t Java_org_j3_mmtk_Memory_getAvailableEndConstant__ (MMTkObject* M) { - return (uintptr_t)0x60000000; + return (uintptr_t)0xa0000000; } extern "C" sint32 Modified: vmkit/trunk/tools/precompiler/Precompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/precompiler/Precompiler.cpp?rev=135808&r1=135807&r2=135808&view=diff ============================================================================== --- vmkit/trunk/tools/precompiler/Precompiler.cpp (original) +++ vmkit/trunk/tools/precompiler/Precompiler.cpp Fri Jul 22 16:32:31 2011 @@ -24,6 +24,7 @@ #include "j3/JavaAOTCompiler.h" #include "j3/JavaJITCompiler.h" +#include "../../lib/J3/VMCore/JavaThread.h" #include "../../lib/J3/VMCore/JnjvmClassLoader.h" #include "../../lib/J3/VMCore/Jnjvm.h" @@ -40,6 +41,16 @@ #include "FrametablesSymbols.inc" }; + +static void mainCompilerLoaderStart(JavaThread* th) { + Jnjvm* vm = th->getJVM(); + JnjvmBootstrapLoader* bootstrapLoader = vm->bootstrapLoader; + JavaAOTCompiler* M = (JavaAOTCompiler*)bootstrapLoader->getCompiler(); + M->compileClassLoader(bootstrapLoader); + vm->exit(); +} + + int main(int argc, char **argv, char **envp) { llvm::llvm_shutdown_obj X; @@ -63,7 +74,13 @@ // Now AOT Compile all compiled methods. JavaAOTCompiler* AOT = new JavaAOTCompiler("AOT"); - AOT->compileClassLoader(loader); + loader->setCompiler(AOT); + + vm->doExit = false; + JavaThread* th = new JavaThread(vm); + vm->setMainThread(th); + th->start((void (*)(mvm::Thread*))mainCompilerLoaderStart); + vm->waitForExit(); AOT->printStats(); Modified: vmkit/trunk/tools/vmjc/vmjc.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/vmjc/vmjc.cpp?rev=135808&r1=135807&r2=135808&view=diff ============================================================================== --- vmkit/trunk/tools/vmjc/vmjc.cpp (original) +++ vmkit/trunk/tools/vmjc/vmjc.cpp Fri Jul 22 16:32:31 2011 @@ -224,3 +224,6 @@ return 0; } +// Because MMTk has not been created yet, provide this method in order to link. +extern "C" void MMTk_InlineMethods(llvm::Module* module) { +} From nicolas.geoffray at lip6.fr Sat Jul 23 03:30:42 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 23 Jul 2011 10:30:42 -0000 Subject: [vmkit-commits] [vmkit] r135850 - in /vmkit/trunk/lib/J3/VMCore: Jnjvm.cpp JnjvmClassLoader.cpp JnjvmClassLoader.h Precompiled.cpp Message-ID: <20110723103042.CAF582A6C12D@llvm.org> Author: geoffray Date: Sat Jul 23 05:30:42 2011 New Revision: 135850 URL: http://llvm.org/viewvc/llvm-project?rev=135850&view=rev Log: Move code related to AOT compilation in Precompiled.cpp and clean up class loader class. Added: vmkit/trunk/lib/J3/VMCore/Precompiled.cpp Modified: vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h Modified: vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp?rev=135850&r1=135849&r2=135850&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp Sat Jul 23 05:30:42 2011 @@ -1344,8 +1344,6 @@ } end = end->prev; } - - bootstrapLoader->insertAllMethodsInVM(this); } Jnjvm::~Jnjvm() { Modified: vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp?rev=135850&r1=135849&r2=135850&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp Sat Jul 23 05:30:42 2011 @@ -23,7 +23,6 @@ #include - #if defined(__MACH__) #define SELF_HANDLE RTLD_DEFAULT #define DYLD_EXTENSION ".dylib" @@ -87,57 +86,16 @@ bootstrapLoader = this; // Try to find if we have a pre-compiled rt.jar + bool bootLoaded = false; if (dlLoad) { - SuperArray = (Class*)dlsym(SELF_HANDLE, "java_lang_Object"); - if (!SuperArray) { - nativeHandle = dlopen("libvmjc"DYLD_EXTENSION, RTLD_LAZY | RTLD_GLOBAL); - if (nativeHandle) { - // Found it! - SuperArray = (Class*)dlsym(nativeHandle, "java_lang_Object"); - } - } - - if (SuperArray) { - assert(TheCompiler && - "Loading libvmjc"DYLD_EXTENSION" requires a compiler"); - ClassArray::SuperArray = (Class*)SuperArray->getInternal(); - - // Get the native classes. - upcalls->OfVoid = (ClassPrimitive*)dlsym(nativeHandle, "void"); - upcalls->OfBool = (ClassPrimitive*)dlsym(nativeHandle, "boolean"); - upcalls->OfByte = (ClassPrimitive*)dlsym(nativeHandle, "byte"); - upcalls->OfChar = (ClassPrimitive*)dlsym(nativeHandle, "char"); - upcalls->OfShort = (ClassPrimitive*)dlsym(nativeHandle, "short"); - upcalls->OfInt = (ClassPrimitive*)dlsym(nativeHandle, "int"); - upcalls->OfFloat = (ClassPrimitive*)dlsym(nativeHandle, "float"); - upcalls->OfLong = (ClassPrimitive*)dlsym(nativeHandle, "long"); - upcalls->OfDouble = (ClassPrimitive*)dlsym(nativeHandle, "double"); - - - // We have the java/lang/Object class, execute the static initializer. - static_init_t init = (static_init_t)(uintptr_t)SuperArray->classLoader; - assert(init && "Loaded the wrong boot library"); - init(this); - - // Get the base object arrays after the init, because init puts arrays - // in the class loader map. - upcalls->ArrayOfString = - constructArray(asciizConstructUTF8("[Ljava/lang/String;")); - - upcalls->ArrayOfObject = - constructArray(asciizConstructUTF8("[Ljava/lang/Object;")); - - InterfacesArray = upcalls->ArrayOfObject->interfaces; - ClassArray::InterfacesArray = InterfacesArray; - - } + bootLoaded = Precompiled::Init(this); } - - if (!upcalls->OfChar) { - // Allocate interfaces. - InterfacesArray = (Class**)allocator.Allocate(2 * sizeof(UserClass*), - "Interface array"); - ClassArray::InterfacesArray = InterfacesArray; + + if (!bootLoaded) { + // Allocate the interfaces array for array classes, so that VT construction + // can use it right away. + ClassArray::InterfacesArray = + (Class**)allocator.Allocate(2 * sizeof(UserClass*), "Interface array"); // Create the primitive classes. upcalls->OfChar = UPCALL_PRIMITIVE_CLASS(this, "char", 1); @@ -249,9 +207,7 @@ DEF_UTF8(tanh); DEF_UTF8(finalize); -#undef DEF_UTF8 - - +#undef DEF_UTF8 } JnjvmClassLoader::JnjvmClassLoader(mvm::BumpPtrAllocator& Alloc, @@ -1065,185 +1021,20 @@ return res; } -class JavaStaticMethodInfo : public mvm::CamlMethodInfo { -public: - virtual void print(void* ip, void* addr); - virtual bool isHighLevelMethod() { - return true; - } - - JavaStaticMethodInfo(mvm::CamlMethodInfo* super, void* ip, JavaMethod* M) : - mvm::CamlMethodInfo(super->CF) { - MetaInfo = M; - Owner = M->classDef->classLoader->getCompiler(); - } -}; - -void JavaStaticMethodInfo::print(void* ip, void* addr) { - void* new_ip = NULL; - if (ip) new_ip = mvm::MethodInfo::isStub(ip, addr); - JavaMethod* meth = (JavaMethod*)MetaInfo; - fprintf(stderr, "; %p in %s.%s", new_ip, - UTF8Buffer(meth->classDef->name).cString(), - UTF8Buffer(meth->name).cString()); - if (ip != new_ip) fprintf(stderr, " (from stub)"); - fprintf(stderr, "\n"); -} - -void JnjvmClassLoader::insertAllMethodsInVM(Jnjvm* vm) { - for (ClassMap::iterator i = classes->map.begin(), e = classes->map.end(); - i != e; ++i) { - CommonClass* cl = i->second; - if (cl->isClass()) { - Class* C = cl->asClass(); - - for (uint32 i = 0; i < C->nbVirtualMethods; ++i) { - JavaMethod& meth = C->virtualMethods[i]; - if (!isAbstract(meth.access) && meth.code) { - JavaStaticMethodInfo* MI = new (allocator, "JavaStaticMethodInfo") - JavaStaticMethodInfo(0, meth.code, &meth); - vm->FunctionsCache.addMethodInfo(MI, meth.code); - } - } - - for (uint32 i = 0; i < C->nbStaticMethods; ++i) { - JavaMethod& meth = C->staticMethods[i]; - if (!isAbstract(meth.access) && meth.code) { - JavaStaticMethodInfo* MI = new (allocator, "JavaStaticMethodInfo") - JavaStaticMethodInfo(0, meth.code, &meth); - vm->FunctionsCache.addMethodInfo(MI, meth.code); - } - } - } - } -} - -void JnjvmClassLoader::loadLibFromJar(Jnjvm* vm, const char* name, - const char* file) { - - mvm::ThreadAllocator threadAllocator; - char* soName = (char*)threadAllocator.Allocate( - strlen(name) + strlen(DYLD_EXTENSION)); - const char* ptr = strrchr(name, '/'); - sprintf(soName, "%s%s", ptr ? ptr + 1 : name, DYLD_EXTENSION); - void* handle = dlopen(soName, RTLD_LAZY | RTLD_LOCAL); - if (handle) { - Class* cl = (Class*)dlsym(handle, file); - if (cl) { - static_init_t init = (static_init_t)(uintptr_t)cl->classLoader; - assert(init && "Loaded the wrong library"); - init(this); - insertAllMethodsInVM(vm); - } - } -} -void JnjvmClassLoader::loadLibFromFile(Jnjvm* vm, const char* name) { - mvm::ThreadAllocator threadAllocator; - assert(classes->map.size() == 0); - char* soName = (char*)threadAllocator.Allocate( - strlen(name) + strlen(DYLD_EXTENSION)); - sprintf(soName, "%s%s", name, DYLD_EXTENSION); - void* handle = dlopen(soName, RTLD_LAZY | RTLD_LOCAL); - if (handle) { - Class* cl = (Class*)dlsym(handle, name); - if (cl) { - static_init_t init = (static_init_t)(uintptr_t)cl->classLoader; - init(this); - insertAllMethodsInVM(vm); - } - } -} - -Class* JnjvmClassLoader::loadClassFromSelf(Jnjvm* vm, const char* name) { - assert(classes->map.size() == 0); - Class* cl = (Class*)dlsym(SELF_HANDLE, name); - if (cl) { - static_init_t init = (static_init_t)(uintptr_t)cl->classLoader; - init(this); - insertAllMethodsInVM(vm); - } - return cl; -} - - -// Extern "C" functions called by the vmjc static intializer. -extern "C" void vmjcAddPreCompiledClass(JnjvmClassLoader* JCL, - CommonClass* cl) { - cl->classLoader = JCL; - - JCL->hashUTF8->insert(cl->name); - - if (cl->isClass()) { - Class* realCl = cl->asClass(); - // To avoid data alignment in the llvm assembly emitter, we set the - // staticMethods and staticFields fields here. - realCl->staticMethods = realCl->virtualMethods + realCl->nbVirtualMethods; - realCl->staticFields = realCl->virtualFields + realCl->nbVirtualFields; - cl->virtualVT->setNativeTracer(cl->virtualVT->tracer, ""); - - for (uint32 i = 0; i< realCl->nbStaticMethods; ++i) { - JavaMethod& meth = realCl->staticMethods[i]; - JCL->hashUTF8->insert(meth.name); - JCL->hashUTF8->insert(meth.type); - } - - for (uint32 i = 0; i< realCl->nbVirtualMethods; ++i) { - JavaMethod& meth = realCl->virtualMethods[i]; - JCL->hashUTF8->insert(meth.name); - JCL->hashUTF8->insert(meth.type); - } - - for (uint32 i = 0; i< realCl->nbStaticFields; ++i) { - JavaField& field = realCl->staticFields[i]; - JCL->hashUTF8->insert(field.name); - JCL->hashUTF8->insert(field.type); - } - - for (uint32 i = 0; i< realCl->nbVirtualFields; ++i) { - JavaField& field = realCl->virtualFields[i]; - JCL->hashUTF8->insert(field.name); - JCL->hashUTF8->insert(field.type); - } - } - - if (!cl->isPrimitive()) { - JCL->getClasses()->map.insert(std::make_pair(cl->name, cl)); +JavaString** StringList::addString(JnjvmClassLoader* JCL, JavaString* obj) { + llvm_gcroot(obj, 0); + if (length == MAXIMUM_STRINGS) { + StringList* next = new(JCL->allocator, "StringList") StringList(); + next->prev = this; + JCL->strings = next; + return next->addString(JCL, obj); + } else { + JCL->lock.lock(); + mvm::Collector::objectReferenceNonHeapWriteBarrier( + (gc**)&(strings[length]), (gc*)obj); + JavaString** res = &strings[length++]; + JCL->lock.unlock(); + return res; } } - -extern "C" void vmjcGetClassArray(JnjvmClassLoader* JCL, ClassArray** ptr, - const UTF8* name) { - JCL->hashUTF8->insert(name); - *ptr = JCL->constructArray(name); -} - -extern "C" void vmjcAddUTF8(JnjvmClassLoader* JCL, const UTF8* val) { - JCL->hashUTF8->insert(val); -} - -extern "C" void vmjcAddString(JnjvmClassLoader* JCL, JavaString* val) { - JCL->strings->addString(JCL, val); -} - -extern "C" intptr_t vmjcNativeLoader(JavaMethod* meth) { - bool j3 = false; - const UTF8* jniConsClName = meth->classDef->name; - const UTF8* jniConsName = meth->name; - const UTF8* jniConsType = meth->type; - sint32 clen = jniConsClName->size; - sint32 mnlen = jniConsName->size; - sint32 mtlen = jniConsType->size; - - mvm::ThreadAllocator threadAllocator; - char* buf = (char*)threadAllocator.Allocate( - 3 + JNI_NAME_PRE_LEN + 1 + ((mnlen + clen + mtlen) << 3)); - intptr_t res = meth->classDef->classLoader->nativeLookup(meth, j3, buf); - assert(res && "Could not find required native method"); - return res; -} - -extern "C" void staticCallback() { - fprintf(stderr, "Implement me"); - abort(); -} Modified: vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h?rev=135850&r1=135849&r2=135850&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h (original) +++ vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h Sat Jul 23 05:30:42 2011 @@ -47,7 +47,6 @@ class VMClassLoader; class ZipArchive; - /// JnjvmClassLoader - Runtime representation of a class loader. It contains /// its own tables (signatures, UTF8, types) which are mapped to a single /// table for non-isolate environments. @@ -359,23 +358,11 @@ virtual JavaString** UTF8ToStr(const UTF8* utf8); - /// nativeHandle - Non-null handle if boot classes were static compiled in - /// a dynamic library - /// - void* nativeHandle; - /// upcalls - Upcall classes, fields and methods so that C++ code can call /// Java code. /// Classpath* upcalls; - /// InterfacesArray - The interfaces that array classes implement. - /// - UserClass** InterfacesArray; - - /// SuperArray - The super of array classes. - UserClass* SuperArray; - /// Lists of UTF8s used internaly in VMKit. const UTF8* NoClassDefFoundError; const UTF8* initName; @@ -431,6 +418,14 @@ friend class ClArgumentsInfo; }; + +/// Precompiled - A helper class to initialize a class loader in case +/// it has been precompiled. +class Precompiled { + public: + static bool Init(JnjvmBootstrapLoader* loader); +}; + /// VMClassLoader - The vmdata object that will be placed in and will only /// be referenced by the java.lang.Classloader Java object. Having a /// separate class between VMClassLoader and JnjvmClassLoader allows to @@ -503,26 +498,11 @@ public: StringList() { - prev = 0; + prev = NULL; length = 0; } - JavaString** addString(JnjvmClassLoader* JCL, JavaString* obj) { - llvm_gcroot(obj, 0); - if (length == MAXIMUM_STRINGS) { - StringList* next = new(JCL->allocator, "StringList") StringList(); - next->prev = this; - JCL->strings = next; - return next->addString(JCL, obj); - } else { - JCL->lock.lock(); - mvm::Collector::objectReferenceNonHeapWriteBarrier( - (gc**)&(strings[length]), (gc*)obj); - JavaString** res = &strings[length++]; - JCL->lock.unlock(); - return res; - } - } + JavaString** addString(JnjvmClassLoader* JCL, JavaString* obj); }; } // end namespace j3 Added: vmkit/trunk/lib/J3/VMCore/Precompiled.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Precompiled.cpp?rev=135850&view=auto ============================================================================== --- vmkit/trunk/lib/J3/VMCore/Precompiled.cpp (added) +++ vmkit/trunk/lib/J3/VMCore/Precompiled.cpp Sat Jul 23 05:30:42 2011 @@ -0,0 +1,261 @@ +//===-------- Precompiled.cpp - Support for precompiled code --------------===// +// +// The VMKit project +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// for dlopen and dlsym +#include + +#if defined(__MACH__) +#define SELF_HANDLE RTLD_DEFAULT +#define DYLD_EXTENSION ".dylib" +#else +#define SELF_HANDLE 0 +#define DYLD_EXTENSION ".so" +#endif + +#include "mvm/MethodInfo.h" + +#include "JavaClass.h" +#include "JavaUpcalls.h" +#include "JnjvmClassLoader.h" +#include "Jnjvm.h" +#include "LockedMap.h" + +namespace j3 { + +typedef void (*static_init_t)(JnjvmClassLoader*); + +bool Precompiled::Init(JnjvmBootstrapLoader* loader) { + Class* javaLangObject = (Class*)dlsym(SELF_HANDLE, "java_lang_Object"); + void* nativeHandle = SELF_HANDLE; + if (javaLangObject == NULL) { + void* handle = dlopen("libvmjc"DYLD_EXTENSION, RTLD_LAZY | RTLD_GLOBAL); + if (handle != NULL) { + nativeHandle = handle; + javaLangObject = (Class*)dlsym(nativeHandle, "java_lang_Object"); + } + } + + if (javaLangObject == NULL) { + return false; + } + + // Get the native classes. + Classpath* upcalls = loader->upcalls; + upcalls->OfVoid = (ClassPrimitive*)dlsym(nativeHandle, "void"); + upcalls->OfBool = (ClassPrimitive*)dlsym(nativeHandle, "boolean"); + upcalls->OfByte = (ClassPrimitive*)dlsym(nativeHandle, "byte"); + upcalls->OfChar = (ClassPrimitive*)dlsym(nativeHandle, "char"); + upcalls->OfShort = (ClassPrimitive*)dlsym(nativeHandle, "short"); + upcalls->OfInt = (ClassPrimitive*)dlsym(nativeHandle, "int"); + upcalls->OfFloat = (ClassPrimitive*)dlsym(nativeHandle, "float"); + upcalls->OfLong = (ClassPrimitive*)dlsym(nativeHandle, "long"); + upcalls->OfDouble = (ClassPrimitive*)dlsym(nativeHandle, "double"); + + // We have the java/lang/Object class, execute the static initializer. + static_init_t init = (static_init_t)(uintptr_t)javaLangObject->classLoader; + assert(init && "Loaded the wrong boot library"); + init(loader); + + // Get the base object arrays after the init, because init puts arrays + // in the class loader map. + upcalls->ArrayOfString = + loader->constructArray(loader->asciizConstructUTF8("[Ljava/lang/String;")); + + upcalls->ArrayOfObject = + loader->constructArray(loader->asciizConstructUTF8("[Ljava/lang/Object;")); + + ClassArray::InterfacesArray = upcalls->ArrayOfObject->interfaces; + + return true; +} + +class JavaStaticMethodInfo : public mvm::CamlMethodInfo { +public: + virtual void print(void* ip, void* addr); + virtual bool isHighLevelMethod() { + return true; + } + + JavaStaticMethodInfo(mvm::CamlMethodInfo* super, void* ip, JavaMethod* M) : + mvm::CamlMethodInfo(super->CF) { + MetaInfo = M; + Owner = M->classDef->classLoader->getCompiler(); + } +}; + +void JavaStaticMethodInfo::print(void* ip, void* addr) { + void* new_ip = NULL; + if (ip) new_ip = mvm::MethodInfo::isStub(ip, addr); + JavaMethod* meth = (JavaMethod*)MetaInfo; + fprintf(stderr, "; %p in %s.%s", new_ip, + UTF8Buffer(meth->classDef->name).cString(), + UTF8Buffer(meth->name).cString()); + if (ip != new_ip) fprintf(stderr, " (from stub)"); + fprintf(stderr, "\n"); +} + +void JnjvmClassLoader::insertAllMethodsInVM(Jnjvm* vm) { + for (ClassMap::iterator i = classes->map.begin(), e = classes->map.end(); + i != e; ++i) { + CommonClass* cl = i->second; + if (cl->isClass()) { + Class* C = cl->asClass(); + + for (uint32 i = 0; i < C->nbVirtualMethods; ++i) { + JavaMethod& meth = C->virtualMethods[i]; + if (!isAbstract(meth.access) && meth.code) { + JavaStaticMethodInfo* MI = new (allocator, "JavaStaticMethodInfo") + JavaStaticMethodInfo(0, meth.code, &meth); + vm->FunctionsCache.addMethodInfo(MI, meth.code); + } + } + + for (uint32 i = 0; i < C->nbStaticMethods; ++i) { + JavaMethod& meth = C->staticMethods[i]; + if (!isAbstract(meth.access) && meth.code) { + JavaStaticMethodInfo* MI = new (allocator, "JavaStaticMethodInfo") + JavaStaticMethodInfo(0, meth.code, &meth); + vm->FunctionsCache.addMethodInfo(MI, meth.code); + } + } + } + } +} + +void JnjvmClassLoader::loadLibFromJar(Jnjvm* vm, const char* name, + const char* file) { + + mvm::ThreadAllocator threadAllocator; + char* soName = (char*)threadAllocator.Allocate( + strlen(name) + strlen(DYLD_EXTENSION)); + const char* ptr = strrchr(name, '/'); + sprintf(soName, "%s%s", ptr ? ptr + 1 : name, DYLD_EXTENSION); + void* handle = dlopen(soName, RTLD_LAZY | RTLD_LOCAL); + if (handle) { + Class* cl = (Class*)dlsym(handle, file); + if (cl) { + static_init_t init = (static_init_t)(uintptr_t)cl->classLoader; + assert(init && "Loaded the wrong library"); + init(this); + insertAllMethodsInVM(vm); + } + } +} + +void JnjvmClassLoader::loadLibFromFile(Jnjvm* vm, const char* name) { + mvm::ThreadAllocator threadAllocator; + assert(classes->map.size() == 0); + char* soName = (char*)threadAllocator.Allocate( + strlen(name) + strlen(DYLD_EXTENSION)); + sprintf(soName, "%s%s", name, DYLD_EXTENSION); + void* handle = dlopen(soName, RTLD_LAZY | RTLD_LOCAL); + if (handle) { + Class* cl = (Class*)dlsym(handle, name); + if (cl) { + static_init_t init = (static_init_t)(uintptr_t)cl->classLoader; + init(this); + insertAllMethodsInVM(vm); + } + } +} + +Class* JnjvmClassLoader::loadClassFromSelf(Jnjvm* vm, const char* name) { + assert(classes->map.size() == 0); + Class* cl = (Class*)dlsym(SELF_HANDLE, name); + if (cl) { + static_init_t init = (static_init_t)(uintptr_t)cl->classLoader; + init(this); + insertAllMethodsInVM(vm); + } + return cl; +} + + +// Extern "C" functions called by the vmjc static intializer. +extern "C" void vmjcAddPreCompiledClass(JnjvmClassLoader* JCL, + CommonClass* cl) { + cl->classLoader = JCL; + + JCL->hashUTF8->insert(cl->name); + + if (cl->isClass()) { + Class* realCl = cl->asClass(); + // To avoid data alignment in the llvm assembly emitter, we set the + // staticMethods and staticFields fields here. + realCl->staticMethods = realCl->virtualMethods + realCl->nbVirtualMethods; + realCl->staticFields = realCl->virtualFields + realCl->nbVirtualFields; + cl->virtualVT->setNativeTracer(cl->virtualVT->tracer, ""); + + for (uint32 i = 0; i< realCl->nbStaticMethods; ++i) { + JavaMethod& meth = realCl->staticMethods[i]; + JCL->hashUTF8->insert(meth.name); + JCL->hashUTF8->insert(meth.type); + } + + for (uint32 i = 0; i< realCl->nbVirtualMethods; ++i) { + JavaMethod& meth = realCl->virtualMethods[i]; + JCL->hashUTF8->insert(meth.name); + JCL->hashUTF8->insert(meth.type); + } + + for (uint32 i = 0; i< realCl->nbStaticFields; ++i) { + JavaField& field = realCl->staticFields[i]; + JCL->hashUTF8->insert(field.name); + JCL->hashUTF8->insert(field.type); + } + + for (uint32 i = 0; i< realCl->nbVirtualFields; ++i) { + JavaField& field = realCl->virtualFields[i]; + JCL->hashUTF8->insert(field.name); + JCL->hashUTF8->insert(field.type); + } + } + + if (!cl->isPrimitive()) { + JCL->getClasses()->map.insert(std::make_pair(cl->name, cl)); + } +} + +extern "C" void vmjcGetClassArray(JnjvmClassLoader* JCL, ClassArray** ptr, + const UTF8* name) { + JCL->hashUTF8->insert(name); + *ptr = JCL->constructArray(name); +} + +extern "C" void vmjcAddUTF8(JnjvmClassLoader* JCL, const UTF8* val) { + JCL->hashUTF8->insert(val); +} + +extern "C" void vmjcAddString(JnjvmClassLoader* JCL, JavaString* val) { + JCL->strings->addString(JCL, val); +} + +extern "C" intptr_t vmjcNativeLoader(JavaMethod* meth) { + bool j3 = false; + const UTF8* jniConsClName = meth->classDef->name; + const UTF8* jniConsName = meth->name; + const UTF8* jniConsType = meth->type; + sint32 clen = jniConsClName->size; + sint32 mnlen = jniConsName->size; + sint32 mtlen = jniConsType->size; + + mvm::ThreadAllocator threadAllocator; + char* buf = (char*)threadAllocator.Allocate( + 3 + JNI_NAME_PRE_LEN + 1 + ((mnlen + clen + mtlen) << 3)); + intptr_t res = meth->classDef->classLoader->nativeLookup(meth, j3, buf); + assert(res && "Could not find required native method"); + return res; +} + +extern "C" void staticCallback() { + fprintf(stderr, "Implement me"); + abort(); +} + +} From nicolas.geoffray at lip6.fr Sat Jul 23 14:54:55 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 23 Jul 2011 21:54:55 -0000 Subject: [vmkit-commits] [vmkit] r135863 - in /vmkit/trunk: ./ lib/J3/Classpath/ lib/J3/Compiler/ lib/J3/Compiler/AOT/ lib/J3/VMCore/ lib/Mvm/StaticGCPass/ mmtk/mmtk-alloc/ mmtk/mmtk-j3/ tools/ tools/j3/ tools/precompiler/ tools/precompiler/trainer/ Message-ID: <20110723215455.E24EA2A6C12D@llvm.org> Author: geoffray Date: Sat Jul 23 16:54:55 2011 New Revision: 135863 URL: http://llvm.org/viewvc/llvm-project?rev=135863&view=rev Log: Include precompiled Java code in final j3 executable. Added: vmkit/trunk/lib/J3/Compiler/AOT/ vmkit/trunk/lib/J3/Compiler/AOT/Makefile vmkit/trunk/lib/J3/Compiler/AOT/StaticJ3GC.cpp Modified: vmkit/trunk/Makefile vmkit/trunk/lib/J3/Classpath/JavaUpcalls.h vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp vmkit/trunk/lib/J3/Compiler/Makefile vmkit/trunk/lib/J3/VMCore/JavaClass.h vmkit/trunk/lib/J3/VMCore/JavaConstantPool.cpp vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h vmkit/trunk/lib/J3/VMCore/Precompiled.cpp vmkit/trunk/lib/Mvm/StaticGCPass/StaticGCPass.cpp vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp vmkit/trunk/mmtk/mmtk-j3/Memory.cpp vmkit/trunk/tools/Makefile vmkit/trunk/tools/j3/Makefile vmkit/trunk/tools/precompiler/Makefile vmkit/trunk/tools/precompiler/trainer/Makefile Modified: vmkit/trunk/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/Makefile?rev=135863&r1=135862&r2=135863&view=diff ============================================================================== --- vmkit/trunk/Makefile (original) +++ vmkit/trunk/Makefile Sat Jul 23 16:54:55 2011 @@ -13,7 +13,7 @@ # Top-Level vmkit Build Stages: # -DIRS := lib/Mvm/StaticGCPass lib tools/vmjc mmtk tools +DIRS := lib/Mvm/StaticGCPass lib tools/vmjc mmtk tools/precompiler tools EXTRA_DIST=include Modified: vmkit/trunk/lib/J3/Classpath/JavaUpcalls.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Classpath/JavaUpcalls.h?rev=135863&r1=135862&r2=135863&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Classpath/JavaUpcalls.h (original) +++ vmkit/trunk/lib/J3/Classpath/JavaUpcalls.h Sat Jul 23 16:54:55 2011 @@ -56,8 +56,11 @@ class Jnjvm; class JavaField; class JavaMethod; +class JavaObject; +class JavaThread; class Class; class ClassArray; +class JnjvmClassLoader; class Classpath : public mvm::PermanentObject { public: Added: vmkit/trunk/lib/J3/Compiler/AOT/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/AOT/Makefile?rev=135863&view=auto ============================================================================== --- vmkit/trunk/lib/J3/Compiler/AOT/Makefile (added) +++ vmkit/trunk/lib/J3/Compiler/AOT/Makefile Sat Jul 23 16:54:55 2011 @@ -0,0 +1,15 @@ +##===- lib/J3/Compiler/AOT/Makefile ------------------------*- Makefile -*-===## +# +# The VMKit project +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## + +LEVEL = ../../../.. +LIBRARYNAME = StaticJ3GC +LOADABLE_MODULE = 1 + +include $(LEVEL)/Makefile.common + Added: vmkit/trunk/lib/J3/Compiler/AOT/StaticJ3GC.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/AOT/StaticJ3GC.cpp?rev=135863&view=auto ============================================================================== --- vmkit/trunk/lib/J3/Compiler/AOT/StaticJ3GC.cpp (added) +++ vmkit/trunk/lib/J3/Compiler/AOT/StaticJ3GC.cpp Sat Jul 23 16:54:55 2011 @@ -0,0 +1,155 @@ +//===----- StaticJ3GC.cpp - Support for Ahead of Time Compiler GC -------===// +// +// The VMKit project +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/CodeGen/GCs.h" +#include "llvm/CodeGen/GCStrategy.h" +#include "llvm/CodeGen/AsmPrinter.h" +#include "llvm/CodeGen/GCMetadataPrinter.h" +#include "llvm/Module.h" +#include "llvm/MC/MCAsmInfo.h" +#include "llvm/MC/MCContext.h" +#include "llvm/MC/MCSymbol.h" +#include "llvm/MC/MCStreamer.h" +#include "llvm/Target/Mangler.h" +#include "llvm/Target/TargetData.h" +#include "llvm/Target/TargetLoweringObjectFile.h" +#include "llvm/Target/TargetMachine.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/Support/Compiler.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/FormattedStream.h" +#include + +using namespace llvm; + +namespace { + class StaticJ3GC : public GCStrategy { + public: + StaticJ3GC(); + }; +} + +static GCRegistry::Add +X("java_aot", "Java GC for AOT-generated functions"); + +StaticJ3GC::StaticJ3GC() { + NeededSafePoints = 1 << GC::PostCall; + UsesMetadata = true; +} + +namespace { + + class StaticJ3GCMetadataPrinter : public GCMetadataPrinter { + public: + void beginAssembly(AsmPrinter &AP); + void finishAssembly(AsmPrinter &AP); + }; + +} + +static GCMetadataPrinterRegistry::Add +Y("java_aot", "Java GC for AOT-generated functions"); + +void StaticJ3GCMetadataPrinter::beginAssembly(AsmPrinter &AP) { +} + +/// emitAssembly - Print the frametable. The ocaml frametable format is thus: +/// +/// extern "C" struct align(sizeof(intptr_t)) { +/// void *FunctionAddress; +/// uint16_t NumDescriptors; +/// struct align(sizeof(intptr_t)) { +/// void *ReturnAddress; +/// uint16_t BytecodeIndex; +/// uint16_t FrameSize; +/// uint16_t NumLiveOffsets; +/// uint16_t LiveOffsets[NumLiveOffsets]; +/// } Descriptors[NumDescriptors]; +/// } ${method}__frame; +/// +/// Note that this precludes programs from stack frames larger than 64K +/// (FrameSize and LiveOffsets would overflow). FrameTablePrinter will abort if +/// either condition is detected in a function which uses the GC. +/// +void StaticJ3GCMetadataPrinter::finishAssembly(AsmPrinter &AP) { + unsigned IntPtrSize = AP.TM.getTargetData()->getPointerSize(); + + AP.OutStreamer.SwitchSection(AP.getObjFileLowering().getDataSection()); + + + for (iterator I = begin(), IE = end(); I != IE; ++I) { + GCFunctionInfo &FI = **I; + + // Emit the frame symbol + MCSymbol *Sym = AP.OutContext.GetOrCreateSymbol(FI.getFunction().getName() + "_frame"); + AP.OutStreamer.EmitSymbolAttribute(Sym, MCSA_Global); + AP.OutStreamer.EmitLabel(Sym); + + // Emit the method symbol + MCSymbol *FunctionSym = AP.Mang->getSymbol(&FI.getFunction()); + AP.OutStreamer.EmitSymbolValue(FunctionSym, IntPtrSize, 0); + + int NumDescriptors = 0; + for (GCFunctionInfo::iterator J = FI.begin(), JE = FI.end(); J != JE; ++J) { + NumDescriptors++; + } + if (NumDescriptors >= 1<<16) { + // Very rude! + report_fatal_error(" Too much descriptor for J3 AOT GC"); + } + AP.EmitInt16(NumDescriptors); + AP.EmitAlignment(IntPtrSize == 4 ? 2 : 3); + + uint64_t FrameSize = FI.getFrameSize(); + if (FrameSize >= 1<<16) { + // Very rude! + report_fatal_error("Function '" + FI.getFunction().getName() + + "' is too large for the J3 AOT GC! " + "Frame size " + Twine(FrameSize) + ">= 65536.\n" + "(" + Twine(uintptr_t(&FI)) + ")"); + } + + AP.OutStreamer.AddComment("live roots for " + + Twine(FI.getFunction().getName())); + AP.OutStreamer.AddBlankLine(); + + for (GCFunctionInfo::iterator J = FI.begin(), JE = FI.end(); J != JE; ++J) { + size_t LiveCount = FI.live_size(J); + if (LiveCount >= 1<<16) { + // Very rude! + report_fatal_error("Function '" + FI.getFunction().getName() + + "' is too large for the ocaml GC! " + "Live root count "+Twine(LiveCount)+" >= 65536."); + } + + DebugLoc DL = J->Loc; + uint32_t bytecodeIndex = DL.getLine(); + uint32_t second = DL.getCol(); + assert(second == 0 && "Wrong column number"); + + AP.OutStreamer.EmitSymbolValue(J->Label, IntPtrSize, 0); + AP.EmitInt16(bytecodeIndex); + AP.EmitInt16(FrameSize); + AP.EmitInt16(LiveCount); + + for (GCFunctionInfo::live_iterator K = FI.live_begin(J), + KE = FI.live_end(J); K != KE; ++K) { + if (K->StackOffset >= 1<<16) { + // Very rude! + report_fatal_error( + "GC root stack offset is outside of fixed stack frame and out " + "of range for ocaml GC!"); + } + AP.EmitInt16(K->StackOffset); + } + + AP.EmitAlignment(IntPtrSize == 4 ? 2 : 3); + } + } +} Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=135863&r1=135862&r2=135863&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Sat Jul 23 16:54:55 2011 @@ -1022,8 +1022,7 @@ MethodElts.push_back(ConstantInt::get(Type::getInt8Ty(getLLVMContext()), method.canBeInlined)); // code - if (isAbstract(method.access) - || (precompile && getMethodInfo(&method)->getMethod()->hasExternalWeakLinkage())) { + if (method.code == NULL) { MethodElts.push_back(Constant::getNullValue(JavaIntrinsics.ptrType)); } else { Function* func = getMethod(&method); @@ -1032,7 +1031,15 @@ } // codeInfo - MethodElts.push_back(Constant::getNullValue(JavaIntrinsics.CodeLineInfoType)); + if (useCooperativeGC() && method.code != NULL) { + Twine name = getMethodInfo(&method)->getMethod()->getName() + "_frame"; + GlobalVariable* frame = new GlobalVariable( + Mod, JavaIntrinsics.CodeLineInfoType->getContainedType(0), false, + GlobalValue::ExternalLinkage, NULL, name); + MethodElts.push_back(frame); + } else { + MethodElts.push_back(Constant::getNullValue(JavaIntrinsics.CodeLineInfoType)); + } // codeInfoLength MethodElts.push_back(ConstantInt::get(Type::getInt16Ty(getLLVMContext()), 0)); @@ -1106,11 +1113,10 @@ StructType* TCMTy = dyn_cast(ATy->getContainedType(0)); assert(TCMTy && "Malformed type"); - uint32 status = cl->needsInitialisationCheck() ? vmjc : ready; TempElts.push_back(ConstantInt::get(Type::getInt8Ty(getLLVMContext()), - status)); + cl->getInitializationState())); TempElts.push_back(ConstantInt::get(Type::getInt1Ty(getLLVMContext()), - status == ready ? 1 : 0)); + cl->isReady() ? 1 : 0)); TempElts.push_back(getStaticInstance(cl)); Constant* CStr[1] = { ConstantStruct::get(TCMTy, TempElts) }; TempElts.clear(); @@ -2190,6 +2196,25 @@ precompile = true; addJavaPasses(); + // Make sure that the native classes are emitted. + getNativeClass(loader->upcalls->OfVoid); + getNativeClass(loader->upcalls->OfBool); + getNativeClass(loader->upcalls->OfByte); + getNativeClass(loader->upcalls->OfChar); + getNativeClass(loader->upcalls->OfShort); + getNativeClass(loader->upcalls->OfInt); + getNativeClass(loader->upcalls->OfFloat); + getNativeClass(loader->upcalls->OfLong); + getNativeClass(loader->upcalls->OfDouble); + + // First set classes that have been more than resolved to resolved. + for (ClassMap::iterator i = loader->getClasses()->map.begin(), + e = loader->getClasses()->map.end(); i!= e; ++i) { + if (i->second->isClass() && i->second->asClass()->isResolved()) { + i->second->asClass()->setResolved(); + } + } + for (ClassMap::iterator i = loader->getClasses()->map.begin(), e = loader->getClasses()->map.end(); i!= e; ++i) { getNativeClass(i->second); @@ -2197,12 +2222,20 @@ Class* cl = i->second->asClass(); for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) { JavaMethod& meth = cl->virtualMethods[i]; - if (meth.code != NULL) parseFunction(&meth); + if (meth.code != NULL) { + Function* Func = parseFunction(&meth); + Func->clearGC(); + Func->setGC("java_aot"); + } } for (uint32 i = 0; i < cl->nbStaticMethods; ++i) { JavaMethod& meth = cl->staticMethods[i]; - if (meth.code != NULL) parseFunction(&meth); + if (meth.code != NULL) { + Function* Func = parseFunction(&meth); + Func->clearGC(); + Func->setGC("java_aot"); + } } } } @@ -2211,7 +2244,11 @@ JavaMethod* meth = toCompile.back(); toCompile.pop_back(); getNativeClass(meth->classDef); - parseFunction(meth); + Function* Func = parseFunction(meth); + Func->clearGC(); + Func->setGC("java_aot"); + // Also update code to notify that this function has been emitted. + meth->code = Func; } bool changed = false; Modified: vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp?rev=135863&r1=135862&r2=135863&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp Sat Jul 23 16:54:55 2011 @@ -172,7 +172,7 @@ methodFunction->setGC("vmkit"); Compiler->functions.insert(std::make_pair(methodFunction, methodDef)); - if (Compiler != JCL->getCompiler() && methodDef->code) { + if (!Compiler->isStaticCompiling() && methodDef->code) { Compiler->setMethod(methodFunction, methodDef->code, methodFunction->getName().data()); } } Modified: vmkit/trunk/lib/J3/Compiler/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/Makefile?rev=135863&r1=135862&r2=135863&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/Makefile (original) +++ vmkit/trunk/lib/J3/Compiler/Makefile Sat Jul 23 16:54:55 2011 @@ -10,6 +10,7 @@ include $(LEVEL)/Makefile.config +DIRS = AOT MODULE_WITH_GC = J3Compiler include $(LEVEL)/Makefile.common Modified: vmkit/trunk/lib/J3/VMCore/JavaClass.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaClass.h?rev=135863&r1=135862&r2=135863&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaClass.h (original) +++ vmkit/trunk/lib/J3/VMCore/JavaClass.h Sat Jul 23 16:54:55 2011 @@ -713,6 +713,7 @@ /// setStaticInstance - Set the memory that holds static variables. /// void setStaticInstance(void* val) { + assert(getCurrentTaskClassMirror().staticInstance == NULL); getCurrentTaskClassMirror().staticInstance = val; } Modified: vmkit/trunk/lib/J3/VMCore/JavaConstantPool.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaConstantPool.cpp?rev=135863&r1=135862&r2=135863&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaConstantPool.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JavaConstantPool.cpp Sat Jul 23 16:54:55 2011 @@ -270,7 +270,14 @@ UTF8Buffer(classDef->name).cString()); abort(); } - return (CommonClass*)ctpRes[entry]; + + CommonClass* res = (CommonClass*)ctpRes[entry]; + if (res == NULL) { + JnjvmClassLoader* loader = classDef->classLoader; + const UTF8* name = UTF8At(ctpDef[entry]); + res = loader->lookupClassOrArray(name); + } + return res; } const UTF8* JavaConstantPool::resolveClassName(uint32 index) { @@ -298,12 +305,6 @@ CommonClass* JavaConstantPool::getMethodClassIfLoaded(uint32 index) { CommonClass* temp = isClassLoaded(index); - if (!temp) { - JnjvmClassLoader* loader = classDef->classLoader; - assert(loader && "Class has no loader?"); - const UTF8* name = UTF8At(ctpDef[index]); - temp = loader->lookupClassOrArray(name); - } if (classDef->classLoader->getCompiler()->isStaticCompiling()) { if (temp == NULL) { Modified: vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp?rev=135863&r1=135862&r2=135863&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp Sat Jul 23 16:54:55 2011 @@ -115,7 +115,6 @@ // now in progress by the current thread and release the lock on the // Class object. setOwnerClass(self); - bool vmjced = (getInitializationState() == vmjc); setInitializationState(inClinit); UserClass* cl = (UserClass*)this; @@ -162,17 +161,11 @@ PRINT_DEBUG(JNJVM_LOAD, 0, LIGHT_GREEN, "clinit ", 0); PRINT_DEBUG(JNJVM_LOAD, 0, COLOR_NORMAL, "%s\n", mvm::PrintString(this).cString()); - - - if (!vmjced) { - JavaField* fields = cl->getStaticFields(); - for (uint32 i = 0; i < cl->nbStaticFields; ++i) { - fields[i].InitStaticField(vm); - } + JavaField* fields = cl->getStaticFields(); + for (uint32 i = 0; i < cl->nbStaticFields; ++i) { + fields[i].InitStaticField(vm); } - - JavaMethod* meth = lookupMethodDontThrow(vm->bootstrapLoader->clinitName, vm->bootstrapLoader->clinitType, true, false, 0); @@ -1325,25 +1318,17 @@ VirtualMachine(Alloc, frames), lockSystem(Alloc) { classpath = getenv("CLASSPATH"); - if (!classpath) classpath = "."; + if (classpath == NULL) classpath = "."; - appClassLoader = 0; + appClassLoader = NULL; jniEnv = &JNI_JNIEnvTable; javavmEnv = &JNI_JavaVMTable; bootstrapLoader = loader; upcalls = bootstrapLoader->upcalls; - throwable = upcalls->newThrowable; - StringList* end = loader->strings; - while (end) { - for (uint32 i = 0; i < end->length; ++i) { - JavaString* obj = end->strings[i]; - hashStr.insert(obj); - } - end = end->prev; - } + Precompiled::ReadFrames(this, this->bootstrapLoader); } Jnjvm::~Jnjvm() { Modified: vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h?rev=135863&r1=135862&r2=135863&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h (original) +++ vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h Sat Jul 23 16:54:55 2011 @@ -424,6 +424,7 @@ class Precompiled { public: static bool Init(JnjvmBootstrapLoader* loader); + static void ReadFrames(Jnjvm* vm, JnjvmClassLoader* loader); }; /// VMClassLoader - The vmdata object that will be placed in and will only Modified: vmkit/trunk/lib/J3/VMCore/Precompiled.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Precompiled.cpp?rev=135863&r1=135862&r2=135863&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/Precompiled.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/Precompiled.cpp Sat Jul 23 16:54:55 2011 @@ -44,6 +44,8 @@ if (javaLangObject == NULL) { return false; } + + ClassArray::SuperArray = javaLangObject; // Get the native classes. Classpath* upcalls = loader->upcalls; @@ -75,59 +77,12 @@ return true; } -class JavaStaticMethodInfo : public mvm::CamlMethodInfo { -public: - virtual void print(void* ip, void* addr); - virtual bool isHighLevelMethod() { - return true; - } - - JavaStaticMethodInfo(mvm::CamlMethodInfo* super, void* ip, JavaMethod* M) : - mvm::CamlMethodInfo(super->CF) { - MetaInfo = M; - Owner = M->classDef->classLoader->getCompiler(); - } -}; - -void JavaStaticMethodInfo::print(void* ip, void* addr) { - void* new_ip = NULL; - if (ip) new_ip = mvm::MethodInfo::isStub(ip, addr); - JavaMethod* meth = (JavaMethod*)MetaInfo; - fprintf(stderr, "; %p in %s.%s", new_ip, - UTF8Buffer(meth->classDef->name).cString(), - UTF8Buffer(meth->name).cString()); - if (ip != new_ip) fprintf(stderr, " (from stub)"); - fprintf(stderr, "\n"); -} void JnjvmClassLoader::insertAllMethodsInVM(Jnjvm* vm) { - for (ClassMap::iterator i = classes->map.begin(), e = classes->map.end(); - i != e; ++i) { - CommonClass* cl = i->second; - if (cl->isClass()) { - Class* C = cl->asClass(); - - for (uint32 i = 0; i < C->nbVirtualMethods; ++i) { - JavaMethod& meth = C->virtualMethods[i]; - if (!isAbstract(meth.access) && meth.code) { - JavaStaticMethodInfo* MI = new (allocator, "JavaStaticMethodInfo") - JavaStaticMethodInfo(0, meth.code, &meth); - vm->FunctionsCache.addMethodInfo(MI, meth.code); - } - } - - for (uint32 i = 0; i < C->nbStaticMethods; ++i) { - JavaMethod& meth = C->staticMethods[i]; - if (!isAbstract(meth.access) && meth.code) { - JavaStaticMethodInfo* MI = new (allocator, "JavaStaticMethodInfo") - JavaStaticMethodInfo(0, meth.code, &meth); - vm->FunctionsCache.addMethodInfo(MI, meth.code); - } - } - } - } + UNIMPLEMENTED(); } + void JnjvmClassLoader::loadLibFromJar(Jnjvm* vm, const char* name, const char* file) { @@ -148,6 +103,7 @@ } } + void JnjvmClassLoader::loadLibFromFile(Jnjvm* vm, const char* name) { mvm::ThreadAllocator threadAllocator; assert(classes->map.size() == 0); @@ -165,6 +121,7 @@ } } + Class* JnjvmClassLoader::loadClassFromSelf(Jnjvm* vm, const char* name) { assert(classes->map.size() == 0); Class* cl = (Class*)dlsym(SELF_HANDLE, name); @@ -222,6 +179,7 @@ } } + extern "C" void vmjcGetClassArray(JnjvmClassLoader* JCL, ClassArray** ptr, const UTF8* name) { JCL->hashUTF8->insert(name); @@ -258,4 +216,159 @@ abort(); } + +class StaticJ3Frame { +public: + void* ReturnAddress; + uint16_t BytecodeIndex; + uint16_t FrameSize; + uint16_t NumLiveOffsets; + int16_t LiveOffsets[1]; +}; + +class StaticJ3Frames { +public: + void* FunctionAddress; + uint16_t NumDescriptors; + StaticJ3Frame* frames() const; +}; + +class StaticJ3FrameDecoder { +public: + StaticJ3Frames* frames ; + uint32 currentDescriptor; + StaticJ3Frame* currentFrame; + + StaticJ3FrameDecoder(StaticJ3Frames* frames) { + this->frames = frames; + currentDescriptor = 0; + currentFrame = frames->frames(); + } + + bool hasNext() { + return currentDescriptor < frames->NumDescriptors; + } + + void advance() { + ++currentDescriptor; + if (!hasNext()) return; + intptr_t ptr = + ptr = reinterpret_cast(currentFrame) + + currentFrame->NumLiveOffsets * sizeof(uint16_t) + + sizeof(void*) // ReturnAddress + + sizeof(uint16_t) // BytecodeIndex + + sizeof(uint16_t) // FrameSize + + sizeof(uint16_t); // NumLiveOffsets + if (ptr & 2) { + ptr += sizeof(uint16_t); + } + currentFrame = reinterpret_cast(ptr); + } + + StaticJ3Frame* next() { + assert(hasNext()); + StaticJ3Frame* result = currentFrame; + advance(); + return result; + } +}; + +StaticJ3Frame* StaticJ3Frames::frames() const { + intptr_t ptr = reinterpret_cast(this) + sizeof(void*) + sizeof(uint16_t); + // If the frames structure was not 4-aligned, manually do it here. + if (ptr & 2) { + ptr += sizeof(uint16_t); + } + return reinterpret_cast(ptr); +} + +class JavaStaticMethodInfo : public mvm::MethodInfo { +private: + StaticJ3Frame* frame; +public: + virtual void print(void* ip, void* addr); + virtual bool isHighLevelMethod() { + return true; + } + + virtual void scan(uintptr_t closure, void* ip, void* addr) { + assert(frame != NULL); + //uintptr_t spaddr = (uintptr_t)addr + CF->FrameSize + sizeof(void*); + uintptr_t spaddr = ((uintptr_t*)addr)[0]; + for (uint16 i = 0; i < frame->NumLiveOffsets; ++i) { + mvm::Collector::scanObject((void**)(spaddr + frame->LiveOffsets[i]), closure); + } + } + + JavaStaticMethodInfo(StaticJ3Frame* F, JavaMethod* M) { + frame = F; + MetaInfo = M; + Owner = M->classDef->classLoader->getCompiler(); + } +}; + + +void JavaStaticMethodInfo::print(void* ip, void* addr) { + JavaMethod* meth = (JavaMethod*)MetaInfo; + CodeLineInfo* info = meth->lookupCodeLineInfo((uintptr_t)ip); + if (info != NULL) { + fprintf(stderr, "; %p (%p) in %s.%s (AOT line %d, bytecode %d, code start %p)", ip, addr, + UTF8Buffer(meth->classDef->name).cString(), + UTF8Buffer(meth->name).cString(), + meth->lookupLineNumber((uintptr_t)ip), + info->bytecodeIndex, meth->code); + } else { + fprintf(stderr, "; %p (%p) in %s.%s (native method, code start %p)", ip, addr, + UTF8Buffer(meth->classDef->name).cString(), + UTF8Buffer(meth->name).cString(), meth->code); + } + fprintf(stderr, "\n"); +} + + +static void ReadFrame(Jnjvm* vm, JnjvmClassLoader* loader, JavaMethod* meth) { + StaticJ3Frames* frames = reinterpret_cast(meth->codeInfo); + StaticJ3FrameDecoder decoder(frames); + mvm::BumpPtrAllocator& allocator = loader->allocator; + meth->codeInfoLength = frames->NumDescriptors; + if (frames->NumDescriptors > 0) { + meth->codeInfo = new(allocator, "CodeLineInfo") CodeLineInfo[frames->NumDescriptors]; + } else { + meth->codeInfo = NULL; + } + + int codeInfoIndex = 0; + while (decoder.hasNext()) { + StaticJ3Frame* frame = decoder.next(); + mvm::MethodInfo* MI = new(allocator, "JavaStaticMethodInfo") JavaStaticMethodInfo(frame, meth); + vm->FunctionsCache.addMethodInfo(MI, frame->ReturnAddress); + meth->codeInfo[codeInfoIndex].address = reinterpret_cast(frame->ReturnAddress); + meth->codeInfo[codeInfoIndex++].bytecodeIndex = frame->BytecodeIndex; + } +} + + +void Precompiled::ReadFrames(Jnjvm* vm, JnjvmClassLoader* loader) { + for (ClassMap::iterator i = loader->getClasses()->map.begin(), + e = loader->getClasses()->map.end(); i != e; ++i) { + CommonClass* cl = i->second; + if (cl->isClass()) { + Class* C = cl->asClass(); + for (uint32 i = 0; i < C->nbVirtualMethods; ++i) { + JavaMethod& meth = C->virtualMethods[i]; + if (meth.code != NULL) { + ReadFrame(vm, loader, &meth); + } + } + + for (uint32 i = 0; i < C->nbStaticMethods; ++i) { + JavaMethod& meth = C->staticMethods[i]; + if (meth.code != NULL) { + ReadFrame(vm, loader, &meth); + } + } + } + } +} + } Modified: vmkit/trunk/lib/Mvm/StaticGCPass/StaticGCPass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/StaticGCPass/StaticGCPass.cpp?rev=135863&r1=135862&r2=135863&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/StaticGCPass/StaticGCPass.cpp (original) +++ vmkit/trunk/lib/Mvm/StaticGCPass/StaticGCPass.cpp Sat Jul 23 16:54:55 2011 @@ -39,6 +39,10 @@ RegisterPass X("StaticGCPass", "Add GC information in files compiled with llvm-gcc"); +static bool HasVmkitGC(Function* F) { + return !strcmp(F->getGC(), "vmkit"); +} + bool StaticGCPass::runOnModule(Module& M) { Function* F = M.getFunction("__llvm_gcroot"); @@ -54,8 +58,13 @@ E = gcrootFun->use_end(); I != E; ++I) { if (Instruction* II = dyn_cast(*I)) { Function* F = II->getParent()->getParent(); - if (F->hasGC()) F->clearGC(); - F->setGC("ocaml"); + if (!F->hasGC()) { + F->setGC("ocaml"); + } else if (HasVmkitGC(F)) { + F->clearGC(); + F->setGC("ocaml"); + } + assert(F->hasGC()); } } @@ -66,7 +75,7 @@ "Functions using gc_root should not have static linkage.\n", I->getName().data()); } - if (I->hasGC() && !strcmp(I->getGC(), "vmkit")) I->setGC("ocaml"); + if (I->hasGC() && HasVmkitGC(I)) I->setGC("ocaml"); } if (error) abort(); Modified: vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp?rev=135863&r1=135862&r2=135863&view=diff ============================================================================== --- vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp (original) +++ vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp Sat Jul 23 16:54:55 2011 @@ -164,7 +164,7 @@ #else uint32 flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED; #endif - void* baseAddr = mmap((void*)0x60000000, 0x40000000, PROT_READ | PROT_WRITE, + void* baseAddr = mmap((void*)0x60000000, 0x30000000, PROT_READ | PROT_WRITE, flags, -1, 0); if (baseAddr == MAP_FAILED) { perror("mmap"); Modified: vmkit/trunk/mmtk/mmtk-j3/Memory.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/mmtk-j3/Memory.cpp?rev=135863&r1=135862&r2=135863&view=diff ============================================================================== --- vmkit/trunk/mmtk/mmtk-j3/Memory.cpp (original) +++ vmkit/trunk/mmtk/mmtk-j3/Memory.cpp Sat Jul 23 16:54:55 2011 @@ -20,7 +20,7 @@ } extern "C" uintptr_t Java_org_j3_mmtk_Memory_getHeapEndConstant__ (MMTkObject* M) { - return (uintptr_t)0xa0000000; + return (uintptr_t)0x90000000; } extern "C" uintptr_t Java_org_j3_mmtk_Memory_getAvailableStartConstant__ (MMTkObject* M) { @@ -28,7 +28,7 @@ } extern "C" uintptr_t Java_org_j3_mmtk_Memory_getAvailableEndConstant__ (MMTkObject* M) { - return (uintptr_t)0xa0000000; + return (uintptr_t)0x90000000; } extern "C" sint32 Modified: vmkit/trunk/tools/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/Makefile?rev=135863&r1=135862&r2=135863&view=diff ============================================================================== --- vmkit/trunk/tools/Makefile (original) +++ vmkit/trunk/tools/Makefile Sat Jul 23 16:54:55 2011 @@ -10,7 +10,7 @@ include $(LEVEL)/Makefile.config -PARALLEL_DIRS = j3 vmjc llcj precompiler +PARALLEL_DIRS = j3 vmjc llcj include $(LEVEL)/Makefile.common Modified: vmkit/trunk/tools/j3/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/j3/Makefile?rev=135863&r1=135862&r2=135863&view=diff ============================================================================== --- vmkit/trunk/tools/j3/Makefile (original) +++ vmkit/trunk/tools/j3/Makefile Sat Jul 23 16:54:55 2011 @@ -11,8 +11,8 @@ include $(LEVEL)/Makefile.config TOOLNAME = j3 -USEDLIBS = Classpath.a J3.a J3Compiler.a Mvm.a MvmCompiler.a CommonThread.a FinalMMTk.a InlineMMTk.a +USEDLIBS = Classpath.a J3.a J3Compiler.a Mvm.a MvmCompiler.a CommonThread.a FinalMMTk.a InlineMMTk.a Precompiled.a BUILD_FRAMETABLE = 1 -LINK_COMPONENTS = jit nativecodegen scalaropts instrumentation ipa ipo asmparser linker +LINK_COMPONENTS = jit nativecodegen scalaropts instrumentation ipa ipo include $(LEVEL)/Makefile.common Modified: vmkit/trunk/tools/precompiler/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/precompiler/Makefile?rev=135863&r1=135862&r2=135863&view=diff ============================================================================== --- vmkit/trunk/tools/precompiler/Makefile (original) +++ vmkit/trunk/tools/precompiler/Makefile Sat Jul 23 16:54:55 2011 @@ -10,6 +10,7 @@ include $(LEVEL)/Makefile.config +DIRS = trainer TOOLNAME = precompiler USEDLIBS = Classpath.a J3.a J3Compiler.a Mvm.a MvmCompiler.a CommonThread.a FinalMMTk.a InlineMMTk.a BUILD_FRAMETABLE = 1 Modified: vmkit/trunk/tools/precompiler/trainer/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/precompiler/trainer/Makefile?rev=135863&r1=135862&r2=135863&view=diff ============================================================================== --- vmkit/trunk/tools/precompiler/trainer/Makefile (original) +++ vmkit/trunk/tools/precompiler/trainer/Makefile Sat Jul 23 16:54:55 2011 @@ -18,7 +18,16 @@ PRECOMPILER := $(ToolDir)/precompiler$(EXEEXT) -generated.bc: $(PRECOMPILER) HelloWorld.java +generated.bc: $(PRECOMPILER) HelloWorld.java $(LibDir)/StaticJ3GC$(SHLIBEXT) $(LibDir)/StaticGCPass$(SHLIBEXT) $(Echo) "Building precompiled bootstrap code" $(Verb) javac HelloWorld.java $(Verb) $(PRECOMPILER) -cp $$PWD HelloWorld + $(Verb) $(MKDIR) $(ObjDir) + $(Verb) $(LOPT) generated.bc -load=$(LibDir)/StaticGCPass$(SHLIBEXT) -StaticGCPass -o $(LibDir)/Precompiled.bc + $(Verb) $(LLC) -O0 -fast-isel=false -load=$(LibDir)/StaticJ3GC$(SHLIBEXT) -disable-fp-elim $(LibDir)/Precompiled.bc -o $(ObjDir)/Precompiled.s + $(Verb) $(Compile.C) $(ObjDir)/Precompiled.s -o $(ObjDir)/Precompiled.o + $(Verb) $(Archive) $(LibDir)/libPrecompiled.a $(ObjDir)/Precompiled.o + $(Verb) $(Ranlib) $(LibDir)/libPrecompiled.a + +clean-local:: + $(Verb) $(RM) -f HelloWorld.class generated.bc From nicolas.geoffray at lip6.fr Sun Jul 24 05:55:59 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 24 Jul 2011 12:55:59 -0000 Subject: [vmkit-commits] [vmkit] r135868 - in /vmkit/trunk: include/mvm/MethodInfo.h lib/Mvm/Runtime/MethodInfo.cpp Message-ID: <20110724125559.80E3A2A6C12D@llvm.org> Author: geoffray Date: Sun Jul 24 07:55:59 2011 New Revision: 135868 URL: http://llvm.org/viewvc/llvm-project?rev=135868&view=rev Log: Do not call dladdr when initialzing the frames, but when printing them. Modified: vmkit/trunk/include/mvm/MethodInfo.h vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp Modified: vmkit/trunk/include/mvm/MethodInfo.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/MethodInfo.h?rev=135868&r1=135867&r2=135868&view=diff ============================================================================== --- vmkit/trunk/include/mvm/MethodInfo.h (original) +++ vmkit/trunk/include/mvm/MethodInfo.h Sun Jul 24 07:55:59 2011 @@ -17,7 +17,7 @@ class MethodInfo : public PermanentObject { public: - virtual void print(void* ip, void* addr) = 0; + virtual void print(void* ip, void* addr); virtual void scan(uintptr_t closure, void* ip, void* addr) = 0; virtual bool isHighLevelMethod() { return false; @@ -57,21 +57,8 @@ } }; -class StaticCamlMethodInfo : public CamlMethodInfo { - const char* name; -public: - virtual void print(void* ip, void* addr); - StaticCamlMethodInfo(CamlFrame* CF, const char* n) : - CamlMethodInfo(CF) { - Owner = NULL; - MetaInfo = NULL; - name = n; - } -}; - class DefaultMethodInfo : public MethodInfo { public: - virtual void print(void* ip, void* addr); virtual void scan(uintptr_t closure, void* ip, void* addr); static DefaultMethodInfo DM; Modified: vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp?rev=135868&r1=135867&r2=135868&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp (original) +++ vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp Sun Jul 24 07:55:59 2011 @@ -26,11 +26,7 @@ } } -void StaticCamlMethodInfo::print(void* ip, void* addr) { - fprintf(stderr, "; %p (%p) in %s static method\n", ip, addr, name); -} - -void DefaultMethodInfo::print(void* ip, void* addr) { +void MethodInfo::print(void* ip, void* addr) { Dl_info info; int res = dladdr(ip, &info); if (res != 0 && info.dli_sname != NULL) { @@ -95,13 +91,10 @@ CamlFrames* frames = NULL; while ((frames = allFrames[i++]) != NULL) { CamlFrameDecoder decoder(frames); - Dl_info info; while (decoder.hasNext()) { CamlFrame* frame = decoder.next(); - int res = dladdr(frame->ReturnAddress, &info); - assert(res != 0 && "No frame"); - StaticCamlMethodInfo* MI = new(*StaticAllocator, "StaticCamlMethodInfo") - StaticCamlMethodInfo(frame, info.dli_sname); + CamlMethodInfo* MI = + new(*StaticAllocator, "CamlMethodInfo") CamlMethodInfo(frame); addMethodInfo(MI, frame->ReturnAddress); } } From nicolas.geoffray at lip6.fr Sun Jul 24 05:57:25 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 24 Jul 2011 12:57:25 -0000 Subject: [vmkit-commits] [vmkit] r135869 - in /vmkit/trunk/lib/J3: Classpath/ClasspathReflect.cpp Classpath/ClasspathReflect.h VMCore/JavaArray.cpp VMCore/JavaArray.h VMCore/JavaClass.cpp VMCore/JavaClass.h Message-ID: <20110724125725.70D742A6C12D@llvm.org> Author: geoffray Date: Sun Jul 24 07:57:25 2011 New Revision: 135869 URL: http://llvm.org/viewvc/llvm-project?rev=135869&view=rev Log: Move code around (.h ->.cpp) to remove ld errors when compiling with -g and -pg. Added: vmkit/trunk/lib/J3/Classpath/ClasspathReflect.cpp Modified: vmkit/trunk/lib/J3/Classpath/ClasspathReflect.h vmkit/trunk/lib/J3/VMCore/JavaArray.cpp vmkit/trunk/lib/J3/VMCore/JavaArray.h vmkit/trunk/lib/J3/VMCore/JavaClass.cpp vmkit/trunk/lib/J3/VMCore/JavaClass.h Added: vmkit/trunk/lib/J3/Classpath/ClasspathReflect.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Classpath/ClasspathReflect.cpp?rev=135869&view=auto ============================================================================== --- vmkit/trunk/lib/J3/Classpath/ClasspathReflect.cpp (added) +++ vmkit/trunk/lib/J3/Classpath/ClasspathReflect.cpp Sun Jul 24 07:57:25 2011 @@ -0,0 +1,30 @@ +//===- ClasspathReflect.cpp - Internal representation of core system classes -// +// +// The VMKit project +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "ClasspathReflect.h" +#include "JavaClass.h" +#include "JavaObject.h" +#include "JavaThread.h" + +namespace j3 { + +JavaMethod* JavaObjectConstructor::getInternalMethod(JavaObjectConstructor* self) { + llvm_gcroot(self, 0); + UserCommonClass* cls = JavaObjectClass::getClass(self->declaringClass); + return &(cls->asClass()->virtualMethods[self->slot]); +} + + +JavaMethod* JavaObjectMethod::getInternalMethod(JavaObjectMethod* self) { + llvm_gcroot(self, 0); + UserCommonClass* cls = JavaObjectClass::getClass(self->declaringClass); + return &(cls->asClass()->virtualMethods[self->slot]); +} + +} Modified: vmkit/trunk/lib/J3/Classpath/ClasspathReflect.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Classpath/ClasspathReflect.h?rev=135869&r1=135868&r2=135869&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Classpath/ClasspathReflect.h (original) +++ vmkit/trunk/lib/J3/Classpath/ClasspathReflect.h Sun Jul 24 07:57:25 2011 @@ -104,11 +104,7 @@ mvm::Collector::markAndTrace(obj, &obj->declaringClass, closure); } - static JavaMethod* getInternalMethod(JavaObjectMethod* self) { - llvm_gcroot(self, 0); - UserCommonClass* cls = JavaObjectClass::getClass(self->declaringClass); - return &(cls->asClass()->virtualMethods[self->slot]); - } + static JavaMethod* getInternalMethod(JavaObjectMethod* self); static UserClass* getClass(JavaObjectMethod* self) { llvm_gcroot(self, 0); @@ -129,11 +125,7 @@ mvm::Collector::markAndTrace(obj, &obj->declaringClass, closure); } - static JavaMethod* getInternalMethod(JavaObjectConstructor* self) { - llvm_gcroot(self, 0); - UserCommonClass* cls = JavaObjectClass::getClass(self->declaringClass); - return &(cls->asClass()->virtualMethods[self->slot]); - } + static JavaMethod* getInternalMethod(JavaObjectConstructor* self); static UserClass* getClass(JavaObjectConstructor* self) { llvm_gcroot(self, 0); Modified: vmkit/trunk/lib/J3/VMCore/JavaArray.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaArray.cpp?rev=135869&r1=135868&r2=135869&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaArray.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JavaArray.cpp Sun Jul 24 07:57:25 2011 @@ -34,3 +34,11 @@ const unsigned int JavaArray::T_SHORT = 9; const unsigned int JavaArray::T_INT = 10; const unsigned int JavaArray::T_LONG = 11; + +void ArrayObject::setElement(ArrayObject* self, JavaObject* value, uint32_t i) { + llvm_gcroot(self, 0); + llvm_gcroot(value, 0); + if (value != NULL) assert(value->getVirtualTable()); + mvm::Collector::objectReferenceArrayWriteBarrier( + (gc*)self, (gc**)&(self->elements[i]), (gc*)value); +} Modified: vmkit/trunk/lib/J3/VMCore/JavaArray.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaArray.h?rev=135869&r1=135868&r2=135869&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaArray.h (original) +++ vmkit/trunk/lib/J3/VMCore/JavaArray.h Sun Jul 24 07:57:25 2011 @@ -95,13 +95,7 @@ return self->elements[i]; } - static void setElement(ArrayObject* self, JavaObject* value, uint32_t i) { - llvm_gcroot(self, 0); - llvm_gcroot(value, 0); - if (value != NULL) assert(value->getVirtualTable()); - mvm::Collector::objectReferenceArrayWriteBarrier( - (gc*)self, (gc**)&(self->elements[i]), (gc*)value); - } + static void setElement(ArrayObject* self, JavaObject* value, uint32_t i); static JavaObject** getElements(ArrayObject* self) { llvm_gcroot(self, 0); Modified: vmkit/trunk/lib/J3/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaClass.cpp?rev=135869&r1=135868&r2=135869&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JavaClass.cpp Sun Jul 24 07:57:25 2011 @@ -1790,3 +1790,11 @@ JavaObject** ptr = (JavaObject**)((uint64)obj + ptrOffset); mvm::Collector::objectReferenceWriteBarrier((gc*)obj, (gc**)ptr, (gc*)val); } + +void JavaField::setStaticObjectField(JavaObject* val) { + llvm_gcroot(val, 0); + if (val != NULL) assert(val->getVirtualTable()); + assert(classDef->isResolved()); + JavaObject** ptr = (JavaObject**)((uint64)classDef->getStaticInstance() + ptrOffset); + mvm::Collector::objectReferenceNonHeapWriteBarrier((gc**)ptr, (gc*)val); +} Modified: vmkit/trunk/lib/J3/VMCore/JavaClass.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaClass.h?rev=135869&r1=135868&r2=135869&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaClass.h (original) +++ vmkit/trunk/lib/J3/VMCore/JavaClass.h Sun Jul 24 07:57:25 2011 @@ -1246,13 +1246,7 @@ return ((JavaObject**)ptr)[0]; } - void setStaticObjectField(JavaObject* val) { - llvm_gcroot(val, 0); - if (val != NULL) assert(val->getVirtualTable()); - assert(classDef->isResolved()); - JavaObject** ptr = (JavaObject**)((uint64)classDef->getStaticInstance() + ptrOffset); - mvm::Collector::objectReferenceNonHeapWriteBarrier((gc**)ptr, (gc*)val); - } + void setStaticObjectField(JavaObject* val); JavaObject* getInstanceObjectField(JavaObject* obj) { llvm_gcroot(obj, 0); From nicolas.geoffray at lip6.fr Sun Jul 24 08:07:20 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 24 Jul 2011 15:07:20 -0000 Subject: [vmkit-commits] [vmkit] r135872 - /vmkit/trunk/lib/J3/VMCore/Precompiled.cpp Message-ID: <20110724150720.DDFF52A6C12C@llvm.org> Author: geoffray Date: Sun Jul 24 10:07:20 2011 New Revision: 135872 URL: http://llvm.org/viewvc/llvm-project?rev=135872&view=rev Log: Fix typo. Modified: vmkit/trunk/lib/J3/VMCore/Precompiled.cpp Modified: vmkit/trunk/lib/J3/VMCore/Precompiled.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Precompiled.cpp?rev=135872&r1=135871&r2=135872&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/Precompiled.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/Precompiled.cpp Sun Jul 24 10:07:20 2011 @@ -252,8 +252,7 @@ void advance() { ++currentDescriptor; if (!hasNext()) return; - intptr_t ptr = - ptr = reinterpret_cast(currentFrame) + uintptr_t ptr = reinterpret_cast(currentFrame) + currentFrame->NumLiveOffsets * sizeof(uint16_t) + sizeof(void*) // ReturnAddress + sizeof(uint16_t) // BytecodeIndex From nicolas.geoffray at lip6.fr Sun Jul 24 08:10:17 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 24 Jul 2011 15:10:17 -0000 Subject: [vmkit-commits] [vmkit] r135874 - in /vmkit/trunk: include/mvm/VirtualMachine.h lib/J3/VMCore/Precompiled.cpp lib/Mvm/Runtime/MethodInfo.cpp Message-ID: <20110724151017.14FB52A6C12C@llvm.org> Author: geoffray Date: Sun Jul 24 10:10:16 2011 New Revision: 135874 URL: http://llvm.org/viewvc/llvm-project?rev=135874&view=rev Log: Use a llvm::DenseMap for the function pointers map. Modified: vmkit/trunk/include/mvm/VirtualMachine.h vmkit/trunk/lib/J3/VMCore/Precompiled.cpp vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp Modified: vmkit/trunk/include/mvm/VirtualMachine.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/VirtualMachine.h?rev=135874&r1=135873&r2=135874&view=diff ============================================================================== --- vmkit/trunk/include/mvm/VirtualMachine.h (original) +++ vmkit/trunk/include/mvm/VirtualMachine.h Sun Jul 24 10:10:16 2011 @@ -10,6 +10,8 @@ #ifndef MVM_VIRTUALMACHINE_H #define MVM_VIRTUALMACHINE_H +#include "llvm/ADT/DenseMap.h" + #include "mvm/Allocator.h" #include "mvm/Threads/CollectionRV.h" #include "mvm/Threads/Locks.h" @@ -29,7 +31,7 @@ /// used when walking the stack so that VMKit knows which applicative method /// is executing on the stack. /// - std::map Functions; + llvm::DenseMap Functions; /// FunctionMapLock - Spin lock to protect the Functions map. /// @@ -42,6 +44,9 @@ /// addMethodInfo - A new instruction pointer in the function map. /// void addMethodInfo(MethodInfo* meth, void* ip); + void addMethodInfoNoLock(MethodInfo* meth, void* ip) { + Functions[ip] = meth; + } /// removeMethodInfos - Remove all MethodInfo owned by the given owner. void removeMethodInfos(void* owner); Modified: vmkit/trunk/lib/J3/VMCore/Precompiled.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Precompiled.cpp?rev=135874&r1=135873&r2=135874&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/Precompiled.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/Precompiled.cpp Sun Jul 24 10:10:16 2011 @@ -340,7 +340,8 @@ while (decoder.hasNext()) { StaticJ3Frame* frame = decoder.next(); mvm::MethodInfo* MI = new(allocator, "JavaStaticMethodInfo") JavaStaticMethodInfo(frame, meth); - vm->FunctionsCache.addMethodInfo(MI, frame->ReturnAddress); + assert(loader->bootstrapLoader == loader && "Can only add frame without lock for the bootstrap loader"); + vm->FunctionsCache.addMethodInfoNoLock(MI, frame->ReturnAddress); meth->codeInfo[codeInfoIndex].address = reinterpret_cast(frame->ReturnAddress); meth->codeInfo[codeInfoIndex++].bytecodeIndex = frame->BytecodeIndex; } Modified: vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp?rev=135874&r1=135873&r2=135874&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp (original) +++ vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp Sun Jul 24 10:10:16 2011 @@ -7,6 +7,9 @@ // //===----------------------------------------------------------------------===// +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/DenseSet.h" + #include "mvm/Allocator.h" #include "mvm/MethodInfo.h" #include "mvm/VirtualMachine.h" @@ -95,14 +98,14 @@ CamlFrame* frame = decoder.next(); CamlMethodInfo* MI = new(*StaticAllocator, "CamlMethodInfo") CamlMethodInfo(frame); - addMethodInfo(MI, frame->ReturnAddress); + addMethodInfoNoLock(MI, frame->ReturnAddress); } } } MethodInfo* FunctionMap::IPToMethodInfo(void* ip) { FunctionMapLock.acquire(); - std::map::iterator I = Functions.find(ip); + llvm::DenseMap::iterator I = Functions.find(ip); MethodInfo* res = NULL; if (I != Functions.end()) { res = I->second; @@ -113,24 +116,29 @@ return res; } + void FunctionMap::addMethodInfo(MethodInfo* meth, void* ip) { FunctionMapLock.acquire(); - Functions.insert(std::make_pair(ip, meth)); + addMethodInfoNoLock(meth, ip); FunctionMapLock.release(); } void FunctionMap::removeMethodInfos(void* owner) { FunctionMapLock.acquire(); - std::map::iterator temp; - for (std::map::iterator i = Functions.begin(), + llvm::DenseSet toRemove; + for (llvm::DenseMap::iterator i = Functions.begin(), e = Functions.end(); i != e;) { mvm::MethodInfo* MI = i->second; - temp = i; - i++; if (MI->Owner == owner) { - Functions.erase(temp); + toRemove.insert(i->first); } } + + for (llvm::DenseSet::iterator i = toRemove.begin(), + e = toRemove.end(); i != e;) { + Functions.erase(*i); + } + FunctionMapLock.release(); } From nicolas.geoffray at lip6.fr Sun Jul 24 09:24:19 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 24 Jul 2011 16:24:19 -0000 Subject: [vmkit-commits] [vmkit] r135877 - in /vmkit/trunk: Makefile Makefile.rules lib/Mvm/StaticGCPass/StaticGCPass.cpp lib/Mvm/StaticGCPrinter/ lib/Mvm/StaticGCPrinter/Makefile lib/Mvm/StaticGCPrinter/VmkitGCPrinter.cpp tools/precompiler/trainer/Makefile Message-ID: <20110724162419.3C2AF2A6C12C@llvm.org> Author: geoffray Date: Sun Jul 24 11:24:19 2011 New Revision: 135877 URL: http://llvm.org/viewvc/llvm-project?rev=135877&view=rev Log: Add a vmkit static GC, similar to ocaml, but that makes sure the frame names are mangled. Added: vmkit/trunk/lib/Mvm/StaticGCPrinter/ vmkit/trunk/lib/Mvm/StaticGCPrinter/Makefile vmkit/trunk/lib/Mvm/StaticGCPrinter/VmkitGCPrinter.cpp Modified: vmkit/trunk/Makefile vmkit/trunk/Makefile.rules vmkit/trunk/lib/Mvm/StaticGCPass/StaticGCPass.cpp vmkit/trunk/tools/precompiler/trainer/Makefile Modified: vmkit/trunk/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/Makefile?rev=135877&r1=135876&r2=135877&view=diff ============================================================================== --- vmkit/trunk/Makefile (original) +++ vmkit/trunk/Makefile Sun Jul 24 11:24:19 2011 @@ -13,7 +13,7 @@ # Top-Level vmkit Build Stages: # -DIRS := lib/Mvm/StaticGCPass lib tools/vmjc mmtk tools/precompiler tools +DIRS := lib/Mvm/StaticGCPass lib/Mvm/StaticGCPrinter lib tools/vmjc mmtk tools/precompiler tools EXTRA_DIST=include Modified: vmkit/trunk/Makefile.rules URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/Makefile.rules?rev=135877&r1=135876&r2=135877&view=diff ============================================================================== --- vmkit/trunk/Makefile.rules (original) +++ vmkit/trunk/Makefile.rules Sun Jul 24 11:24:19 2011 @@ -78,7 +78,7 @@ $(Verb) $(LLVMLD) -r -o $(LibDir)/FinalMMTk.bc $(LibDir)/MMTKAlloc.bc $(JARNAME)-optimized.bc $(LibDir)/MMTKRuntime.bc $(Verb) $(LOPT) $(LibDir)/FinalMMTk.bc -load=$(LibDir)/StaticGCPass$(SHLIBEXT) -std-compile-opts -StaticGCPass -o $(LibDir)/FinalMMTk.bc $(Verb) $(MKDIR) $(ObjDir) - $(Verb) $(LLC) -disable-fp-elim $(LibDir)/FinalMMTk.bc -o $(ObjDir)/FinalMMTk.s + $(Verb) $(LLC) -disable-fp-elim -load=$(LibDir)/StaticGCPrinter$(SHLIBEXT) $(LibDir)/FinalMMTk.bc -o $(ObjDir)/FinalMMTk.s $(Verb) $(Compile.C) $(ObjDir)/FinalMMTk.s -o $(ObjDir)/FinalMMTk.o $(Verb) $(Archive) $(LibDir)/libFinalMMTk.a $(ObjDir)/FinalMMTk.o $(Verb) $(Ranlib) $(LibDir)/libFinalMMTk.a @@ -110,7 +110,7 @@ $(ObjectsSWithGC): $(ObjDir)/%_gc.s: $(ObjDir)/%_gc.bc $(LLC) $(Echo) "Compiling $*.bc to $*.s for $(BuildMode) build" - $(Verb) $(LLC) -disable-fp-elim $< -o $@ + $(Verb) $(LLC) -disable-fp-elim -load=$(LibDir)/StaticGCPrinter$(SHLIBEXT) $< -o $@ $(ObjectsWithGC): $(ObjDir)/%_gc.o: $(ObjDir)/%_gc.s $(ObjDir)/.dir $(Echo) "Compiling $*.s for $(BuildMode) build" $(PIC_FLAG) Modified: vmkit/trunk/lib/Mvm/StaticGCPass/StaticGCPass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/StaticGCPass/StaticGCPass.cpp?rev=135877&r1=135876&r2=135877&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/StaticGCPass/StaticGCPass.cpp (original) +++ vmkit/trunk/lib/Mvm/StaticGCPass/StaticGCPass.cpp Sun Jul 24 11:24:19 2011 @@ -39,10 +39,6 @@ RegisterPass X("StaticGCPass", "Add GC information in files compiled with llvm-gcc"); -static bool HasVmkitGC(Function* F) { - return !strcmp(F->getGC(), "vmkit"); -} - bool StaticGCPass::runOnModule(Module& M) { Function* F = M.getFunction("__llvm_gcroot"); @@ -59,12 +55,8 @@ if (Instruction* II = dyn_cast(*I)) { Function* F = II->getParent()->getParent(); if (!F->hasGC()) { - F->setGC("ocaml"); - } else if (HasVmkitGC(F)) { - F->clearGC(); - F->setGC("ocaml"); + F->setGC("vmkit"); } - assert(F->hasGC()); } } @@ -75,7 +67,6 @@ "Functions using gc_root should not have static linkage.\n", I->getName().data()); } - if (I->hasGC() && HasVmkitGC(I)) I->setGC("ocaml"); } if (error) abort(); Added: vmkit/trunk/lib/Mvm/StaticGCPrinter/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/StaticGCPrinter/Makefile?rev=135877&view=auto ============================================================================== --- vmkit/trunk/lib/Mvm/StaticGCPrinter/Makefile (added) +++ vmkit/trunk/lib/Mvm/StaticGCPrinter/Makefile Sun Jul 24 11:24:19 2011 @@ -0,0 +1,15 @@ +##===- lib/Mvm/StaticGCPrinter/Makefile --------------------*- Makefile -*-===## +# +# The VMKit project +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## + +LEVEL = ../../.. +LIBRARYNAME = StaticGCPrinter +LOADABLE_MODULE = 1 + +include $(LEVEL)/Makefile.common + Added: vmkit/trunk/lib/Mvm/StaticGCPrinter/VmkitGCPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/StaticGCPrinter/VmkitGCPrinter.cpp?rev=135877&view=auto ============================================================================== --- vmkit/trunk/lib/Mvm/StaticGCPrinter/VmkitGCPrinter.cpp (added) +++ vmkit/trunk/lib/Mvm/StaticGCPrinter/VmkitGCPrinter.cpp Sun Jul 24 11:24:19 2011 @@ -0,0 +1,197 @@ +//===-- VmkitGCPrinter.cpp - Vmkit frametable emitter ---------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements printing the assembly code for a Vmkit frametable. +// +//===----------------------------------------------------------------------===// + +#include "llvm/CodeGen/GCs.h" +#include "llvm/CodeGen/AsmPrinter.h" +#include "llvm/CodeGen/GCMetadataPrinter.h" +#include "llvm/CodeGen/GCStrategy.h" +#include "llvm/Module.h" +#include "llvm/MC/MCAsmInfo.h" +#include "llvm/MC/MCContext.h" +#include "llvm/MC/MCSymbol.h" +#include "llvm/MC/MCStreamer.h" +#include "llvm/Target/Mangler.h" +#include "llvm/Target/TargetData.h" +#include "llvm/Target/TargetLoweringObjectFile.h" +#include "llvm/Target/TargetMachine.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/FormattedStream.h" +#include +using namespace llvm; + +namespace { + class VmkitGC : public GCStrategy { + public: + VmkitGC(); + }; + + class VmkitGCMetadataPrinter : public GCMetadataPrinter { + public: + void beginAssembly(AsmPrinter &AP); + void finishAssembly(AsmPrinter &AP); + }; + +} + + +static GCRegistry::Add +X("vmkit", "VMKit GC for AOT-generated functions"); + + +static GCMetadataPrinterRegistry::Add +Y("vmkit", "VMKit GC for AOT-generated functions"); + + +VmkitGC::VmkitGC() { + NeededSafePoints = 1 << GC::PostCall; + UsesMetadata = true; +} + + +static bool isAcceptableChar(char C) { + if ((C < 'a' || C > 'z') && + (C < 'A' || C > 'Z') && + (C < '0' || C > '9') && + C != '_' && C != '$' && C != '@') { + return false; + } + return true; +} + +static char HexDigit(int V) { + return V < 10 ? V+'0' : V+'A'-10; +} + +static void MangleLetter(SmallVectorImpl &OutName, unsigned char C) { + OutName.push_back('_'); + OutName.push_back(HexDigit(C >> 4)); + OutName.push_back(HexDigit(C & 15)); + OutName.push_back('_'); +} + + +static void EmitVmkitGlobal(const Module &M, AsmPrinter &AP, const char *Id) { + const std::string &MId = M.getModuleIdentifier(); + + std::string SymName; + SymName += "vmkit"; + size_t Letter = SymName.size(); + SymName.append(MId.begin(), std::find(MId.begin(), MId.end(), '.')); + SymName += "__"; + SymName += Id; + + // Capitalize the first letter of the module name. + SymName[Letter] = toupper(SymName[Letter]); + + SmallString<128> TmpStr; + AP.Mang->getNameWithPrefix(TmpStr, SymName); + + SmallString<128> FinalStr; + for (unsigned i = 0, e = TmpStr.size(); i != e; ++i) { + if (!isAcceptableChar(TmpStr[i])) { + MangleLetter(FinalStr, TmpStr[i]); + } else { + FinalStr.push_back(TmpStr[i]); + } + } + + MCSymbol *Sym = AP.OutContext.GetOrCreateSymbol(FinalStr); + + AP.OutStreamer.EmitSymbolAttribute(Sym, MCSA_Global); + AP.OutStreamer.EmitLabel(Sym); +} + +void VmkitGCMetadataPrinter::beginAssembly(AsmPrinter &AP) { +} + +/// emitAssembly - Print the frametable. The ocaml frametable format is thus: +/// +/// extern "C" struct align(sizeof(intptr_t)) { +/// uint16_t NumDescriptors; +/// struct align(sizeof(intptr_t)) { +/// void *ReturnAddress; +/// uint16_t FrameSize; +/// uint16_t NumLiveOffsets; +/// uint16_t LiveOffsets[NumLiveOffsets]; +/// } Descriptors[NumDescriptors]; +/// } vmkit${module}__frametable; +/// +/// Note that this precludes programs from stack frames larger than 64K +/// (FrameSize and LiveOffsets would overflow). FrameTablePrinter will abort if +/// either condition is detected in a function which uses the GC. +/// +void VmkitGCMetadataPrinter::finishAssembly(AsmPrinter &AP) { + unsigned IntPtrSize = AP.TM.getTargetData()->getPointerSize(); + AP.OutStreamer.SwitchSection(AP.getObjFileLowering().getDataSection()); + EmitVmkitGlobal(getModule(), AP, "frametable"); + + int NumDescriptors = 0; + for (iterator I = begin(), IE = end(); I != IE; ++I) { + GCFunctionInfo &FI = **I; + for (GCFunctionInfo::iterator J = FI.begin(), JE = FI.end(); J != JE; ++J) { + NumDescriptors++; + } + } + + if (NumDescriptors >= 1<<16) { + // Very rude! + report_fatal_error(" Too much descriptor for vmkit GC"); + } + AP.EmitInt16(NumDescriptors); + AP.EmitAlignment(IntPtrSize == 4 ? 2 : 3); + + for (iterator I = begin(), IE = end(); I != IE; ++I) { + GCFunctionInfo &FI = **I; + + uint64_t FrameSize = FI.getFrameSize(); + if (FrameSize >= 1<<16) { + // Very rude! + report_fatal_error("Function '" + FI.getFunction().getName() + + "' is too large for the vmkit GC! " + "Frame size " + Twine(FrameSize) + ">= 65536.\n" + "(" + Twine(uintptr_t(&FI)) + ")"); + } + + AP.OutStreamer.AddComment("live roots for " + + Twine(FI.getFunction().getName())); + AP.OutStreamer.AddBlankLine(); + + for (GCFunctionInfo::iterator J = FI.begin(), JE = FI.end(); J != JE; ++J) { + size_t LiveCount = FI.live_size(J); + if (LiveCount >= 1<<16) { + // Very rude! + report_fatal_error("Function '" + FI.getFunction().getName() + + "' is too large for the vmkit GC! " + "Live root count "+Twine(LiveCount)+" >= 65536."); + } + + AP.OutStreamer.EmitSymbolValue(J->Label, IntPtrSize, 0); + AP.EmitInt16(FrameSize); + AP.EmitInt16(LiveCount); + + for (GCFunctionInfo::live_iterator K = FI.live_begin(J), + KE = FI.live_end(J); K != KE; ++K) { + if (K->StackOffset >= 1<<16) { + // Very rude! + report_fatal_error( + "GC root stack offset is outside of fixed stack frame and out " + "of range for vmkit GC!"); + } + AP.EmitInt16(K->StackOffset); + } + + AP.EmitAlignment(IntPtrSize == 4 ? 2 : 3); + } + } +} Modified: vmkit/trunk/tools/precompiler/trainer/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/precompiler/trainer/Makefile?rev=135877&r1=135876&r2=135877&view=diff ============================================================================== --- vmkit/trunk/tools/precompiler/trainer/Makefile (original) +++ vmkit/trunk/tools/precompiler/trainer/Makefile Sun Jul 24 11:24:19 2011 @@ -18,13 +18,13 @@ PRECOMPILER := $(ToolDir)/precompiler$(EXEEXT) -generated.bc: $(PRECOMPILER) HelloWorld.java $(LibDir)/StaticJ3GC$(SHLIBEXT) $(LibDir)/StaticGCPass$(SHLIBEXT) +generated.bc: $(PRECOMPILER) HelloWorld.java $(LibDir)/StaticJ3GC$(SHLIBEXT) $(LibDir)/StaticGCPass$(SHLIBEXT) $(LibDir)/StaticGCPrinter$(SHLIBEXT) $(Echo) "Building precompiled bootstrap code" $(Verb) javac HelloWorld.java $(Verb) $(PRECOMPILER) -cp $$PWD HelloWorld $(Verb) $(MKDIR) $(ObjDir) $(Verb) $(LOPT) generated.bc -load=$(LibDir)/StaticGCPass$(SHLIBEXT) -StaticGCPass -o $(LibDir)/Precompiled.bc - $(Verb) $(LLC) -O0 -fast-isel=false -load=$(LibDir)/StaticJ3GC$(SHLIBEXT) -disable-fp-elim $(LibDir)/Precompiled.bc -o $(ObjDir)/Precompiled.s + $(Verb) $(LLC) -O0 -fast-isel=false -load=$(LibDir)/StaticJ3GC$(SHLIBEXT) -load=$(LibDir)/StaticGCPrinter$(SHLIBEXT) -disable-fp-elim $(LibDir)/Precompiled.bc -o $(ObjDir)/Precompiled.s $(Verb) $(Compile.C) $(ObjDir)/Precompiled.s -o $(ObjDir)/Precompiled.o $(Verb) $(Archive) $(LibDir)/libPrecompiled.a $(ObjDir)/Precompiled.o $(Verb) $(Ranlib) $(LibDir)/libPrecompiled.a From nicolas.geoffray at lip6.fr Sun Jul 24 11:03:28 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 24 Jul 2011 18:03:28 -0000 Subject: [vmkit-commits] [vmkit] r135878 - in /vmkit/trunk/mmtk: mmtk-alloc/Selected.cpp mmtk-j3/Memory.cpp Message-ID: <20110724180328.D9A7B2A6C12C@llvm.org> Author: geoffray Date: Sun Jul 24 13:03:28 2011 New Revision: 135878 URL: http://llvm.org/viewvc/llvm-project?rev=135878&view=rev Log: Move code that depends on the memory begin/end of MMTk in one place. Modified: vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp vmkit/trunk/mmtk/mmtk-j3/Memory.cpp Modified: vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp?rev=135878&r1=135877&r2=135878&view=diff ============================================================================== --- vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp (original) +++ vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp Sun Jul 24 13:03:28 2011 @@ -157,20 +157,6 @@ } void Collector::initialise() { - // Allocate the memory for MMTk right now, to avoid conflicts with - // other allocators. -#if defined (__MACH__) - uint32 flags = MAP_PRIVATE | MAP_ANON | MAP_FIXED; -#else - uint32 flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED; -#endif - void* baseAddr = mmap((void*)0x60000000, 0x30000000, PROT_READ | PROT_WRITE, - flags, -1, 0); - if (baseAddr == MAP_FAILED) { - perror("mmap"); - abort(); - } - JnJVM_org_j3_bindings_Bindings_boot__Lorg_vmmagic_unboxed_Extent_2Lorg_vmmagic_unboxed_Extent_2(128 * 1024 * 1024, 1024 * 1024 * 1024); } Modified: vmkit/trunk/mmtk/mmtk-j3/Memory.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/mmtk-j3/Memory.cpp?rev=135878&r1=135877&r2=135878&view=diff ============================================================================== --- vmkit/trunk/mmtk/mmtk-j3/Memory.cpp (original) +++ vmkit/trunk/mmtk/mmtk-j3/Memory.cpp Sun Jul 24 13:03:28 2011 @@ -15,20 +15,43 @@ namespace mmtk { +static const uintptr_t MemoryStart = 0x50000000; +static const uintptr_t MemorySize = 0x40000000; + +class InitCollector { +public: + InitCollector() { +#if defined (__MACH__) + uint32 flags = MAP_PRIVATE | MAP_ANON | MAP_FIXED; +#else + uint32 flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED; +#endif + void* baseAddr = mmap((void*)MemoryStart, MemorySize, PROT_READ | PROT_WRITE, + flags, -1, 0); + if (baseAddr == MAP_FAILED) { + perror("mmap"); + abort(); + } + } +}; + +// Allocate the memory for MMTk right now, to avoid conflicts with other allocators. +InitCollector initCollector; + extern "C" uintptr_t Java_org_j3_mmtk_Memory_getHeapStartConstant__ (MMTkObject* M) { - return (uintptr_t)0x60000000; + return MemoryStart; } extern "C" uintptr_t Java_org_j3_mmtk_Memory_getHeapEndConstant__ (MMTkObject* M) { - return (uintptr_t)0x90000000; + return MemoryStart + MemorySize; } extern "C" uintptr_t Java_org_j3_mmtk_Memory_getAvailableStartConstant__ (MMTkObject* M) { - return (uintptr_t)0x60000000; + return Java_org_j3_mmtk_Memory_getHeapStartConstant__ (M); } extern "C" uintptr_t Java_org_j3_mmtk_Memory_getAvailableEndConstant__ (MMTkObject* M) { - return (uintptr_t)0x90000000; + return Java_org_j3_mmtk_Memory_getHeapEndConstant__ (M); } extern "C" sint32 From nicolas.geoffray at lip6.fr Sun Jul 24 11:18:14 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 24 Jul 2011 18:18:14 -0000 Subject: [vmkit-commits] [vmkit] r135879 - in /vmkit/trunk: Makefile.rules lib/J3/Compiler/AOT/StaticJ3GC.cpp mmtk/mmtk-j3/Memory.cpp tools/precompiler/trainer/Makefile Message-ID: <20110724181814.661B12A6C12C@llvm.org> Author: geoffray Date: Sun Jul 24 13:18:14 2011 New Revision: 135879 URL: http://llvm.org/viewvc/llvm-project?rev=135879&view=rev Log: A few fixes to make J3 compile on OSX again. Modified: vmkit/trunk/Makefile.rules vmkit/trunk/lib/J3/Compiler/AOT/StaticJ3GC.cpp vmkit/trunk/mmtk/mmtk-j3/Memory.cpp vmkit/trunk/tools/precompiler/trainer/Makefile Modified: vmkit/trunk/Makefile.rules URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/Makefile.rules?rev=135879&r1=135878&r2=135879&view=diff ============================================================================== --- vmkit/trunk/Makefile.rules (original) +++ vmkit/trunk/Makefile.rules Sun Jul 24 13:18:14 2011 @@ -79,7 +79,7 @@ $(Verb) $(LOPT) $(LibDir)/FinalMMTk.bc -load=$(LibDir)/StaticGCPass$(SHLIBEXT) -std-compile-opts -StaticGCPass -o $(LibDir)/FinalMMTk.bc $(Verb) $(MKDIR) $(ObjDir) $(Verb) $(LLC) -disable-fp-elim -load=$(LibDir)/StaticGCPrinter$(SHLIBEXT) $(LibDir)/FinalMMTk.bc -o $(ObjDir)/FinalMMTk.s - $(Verb) $(Compile.C) $(ObjDir)/FinalMMTk.s -o $(ObjDir)/FinalMMTk.o + $(Verb) $(Compile.Wrapper) $(LLVMCC) $(CPP.Flags) $(C.Flags) $(CFLAGS) $(CPPFLAGS) $(TargetCommonOpts) $(CompileCommonOpts) -c $(ObjDir)/FinalMMTk.s -o $(ObjDir)/FinalMMTk.o $(Verb) $(Archive) $(LibDir)/libFinalMMTk.a $(ObjDir)/FinalMMTk.o $(Verb) $(Ranlib) $(LibDir)/libFinalMMTk.a $(Verb) $(LLC) -march=cpp -cppgen=function -cppfor=gcmalloc $(LibDir)/FinalMMTk.bc -o $(PROJ_SRC_ROOT)/mmtk/inline/MMTkMallocInline.inc @@ -136,10 +136,10 @@ ifdef BUILD_FRAMETABLE FrametablesExterns.inc: $(ProjLibsPaths) - $(Verb) nm $(ProjLibsPaths) | grep __frametable | sed 's/\([a-f0-9]*\)\s\([a-zA-Z]*\)\s\([a-zA-Z0-9_]*\)/extern "C" CamlFrames \3;/' > $@ + $(Verb) nm $(ProjLibsPaths) | grep __frametable | sed 's/\([a-f0-9]*\) \([a-zA-Z]*\) [_?]\([a-zA-Z0-9_]*\)/extern "C" CamlFrames \3;/' > $@ FrametablesSymbols.inc: $(ProjLibsPaths) - $(Verb) nm $(ProjLibsPaths) | grep __frametable | sed 's/\([a-f0-9]*\)\s\([a-zA-Z]*\)\s\([a-zA-Z0-9_]*\)/\&\3,/' > $@ + $(Verb) nm $(ProjLibsPaths) | grep __frametable | sed 's/\([a-f0-9]*\) \([a-zA-Z]*\) [_?]\([a-zA-Z0-9_]*\)/\&\3,/' > $@ all-local:: FrametablesExterns.inc FrametablesSymbols.inc Modified: vmkit/trunk/lib/J3/Compiler/AOT/StaticJ3GC.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/AOT/StaticJ3GC.cpp?rev=135879&r1=135878&r2=135879&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/AOT/StaticJ3GC.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/AOT/StaticJ3GC.cpp Sun Jul 24 13:18:14 2011 @@ -87,7 +87,9 @@ GCFunctionInfo &FI = **I; // Emit the frame symbol - MCSymbol *Sym = AP.OutContext.GetOrCreateSymbol(FI.getFunction().getName() + "_frame"); + SmallString<128> TmpStr; + AP.Mang->getNameWithPrefix(TmpStr, FI.getFunction().getName() + "_frame"); + MCSymbol *Sym = AP.OutContext.GetOrCreateSymbol(TmpStr); AP.OutStreamer.EmitSymbolAttribute(Sym, MCSA_Global); AP.OutStreamer.EmitLabel(Sym); Modified: vmkit/trunk/mmtk/mmtk-j3/Memory.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/mmtk-j3/Memory.cpp?rev=135879&r1=135878&r2=135879&view=diff ============================================================================== --- vmkit/trunk/mmtk/mmtk-j3/Memory.cpp (original) +++ vmkit/trunk/mmtk/mmtk-j3/Memory.cpp Sun Jul 24 13:18:14 2011 @@ -15,7 +15,12 @@ namespace mmtk { +#if defined (__MACH__) +static const uintptr_t MemoryStart = 0x30000000; +#else static const uintptr_t MemoryStart = 0x50000000; +#endif + static const uintptr_t MemorySize = 0x40000000; class InitCollector { Modified: vmkit/trunk/tools/precompiler/trainer/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/precompiler/trainer/Makefile?rev=135879&r1=135878&r2=135879&view=diff ============================================================================== --- vmkit/trunk/tools/precompiler/trainer/Makefile (original) +++ vmkit/trunk/tools/precompiler/trainer/Makefile Sun Jul 24 13:18:14 2011 @@ -25,7 +25,8 @@ $(Verb) $(MKDIR) $(ObjDir) $(Verb) $(LOPT) generated.bc -load=$(LibDir)/StaticGCPass$(SHLIBEXT) -StaticGCPass -o $(LibDir)/Precompiled.bc $(Verb) $(LLC) -O0 -fast-isel=false -load=$(LibDir)/StaticJ3GC$(SHLIBEXT) -load=$(LibDir)/StaticGCPrinter$(SHLIBEXT) -disable-fp-elim $(LibDir)/Precompiled.bc -o $(ObjDir)/Precompiled.s - $(Verb) $(Compile.C) $(ObjDir)/Precompiled.s -o $(ObjDir)/Precompiled.o + $(Verb) $(Compile.Wrapper) $(LLVMCC) $(CPP.Flags) $(C.Flags) $(CFLAGS) $(CPPFLAGS) $(TargetCommonOpts) $(CompileCommonOpts) -c $(ObjDir)/Precompiled.s -o $(ObjDir)/Precompiled.o + $(Verb) $(Archive) $(LibDir)/libPrecompiled.a $(ObjDir)/Precompiled.o $(Verb) $(Ranlib) $(LibDir)/libPrecompiled.a From nicolas.geoffray at lip6.fr Sun Jul 24 11:38:13 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 24 Jul 2011 18:38:13 -0000 Subject: [vmkit-commits] [vmkit] r135880 - /vmkit/trunk/Makefile.rules Message-ID: <20110724183813.634BF2A6C12C@llvm.org> Author: geoffray Date: Sun Jul 24 13:38:13 2011 New Revision: 135880 URL: http://llvm.org/viewvc/llvm-project?rev=135880&view=rev Log: Fix regexp for portability. Modified: vmkit/trunk/Makefile.rules Modified: vmkit/trunk/Makefile.rules URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/Makefile.rules?rev=135880&r1=135879&r2=135880&view=diff ============================================================================== --- vmkit/trunk/Makefile.rules (original) +++ vmkit/trunk/Makefile.rules Sun Jul 24 13:38:13 2011 @@ -136,10 +136,10 @@ ifdef BUILD_FRAMETABLE FrametablesExterns.inc: $(ProjLibsPaths) - $(Verb) nm $(ProjLibsPaths) | grep __frametable | sed 's/\([a-f0-9]*\) \([a-zA-Z]*\) [_?]\([a-zA-Z0-9_]*\)/extern "C" CamlFrames \3;/' > $@ + $(Verb) nm $(ProjLibsPaths) | grep __frametable | sed 's/\([a-f0-9]*\) \([a-zA-Z]*\) _*\([a-zA-Z0-9_]*\)/extern "C" CamlFrames \3;/' > $@ FrametablesSymbols.inc: $(ProjLibsPaths) - $(Verb) nm $(ProjLibsPaths) | grep __frametable | sed 's/\([a-f0-9]*\) \([a-zA-Z]*\) [_?]\([a-zA-Z0-9_]*\)/\&\3,/' > $@ + $(Verb) nm $(ProjLibsPaths) | grep __frametable | sed 's/\([a-f0-9]*\) \([a-zA-Z]*\) _*\([a-zA-Z0-9_]*\)/\&\3,/' > $@ all-local:: FrametablesExterns.inc FrametablesSymbols.inc From nicolas.geoffray at lip6.fr Sun Jul 24 12:21:32 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 24 Jul 2011 19:21:32 -0000 Subject: [vmkit-commits] [vmkit] r135883 - in /vmkit/trunk: Makefile.rules lib/J3/Compiler/JavaAOTCompiler.cpp tools/precompiler/trainer/Makefile Message-ID: <20110724192132.2D4F82A6C12C@llvm.org> Author: geoffray Date: Sun Jul 24 14:21:31 2011 New Revision: 135883 URL: http://llvm.org/viewvc/llvm-project?rev=135883&view=rev Log: Update Makefile to not output warnings and messages. Modified: vmkit/trunk/Makefile.rules vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp vmkit/trunk/tools/precompiler/trainer/Makefile Modified: vmkit/trunk/Makefile.rules URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/Makefile.rules?rev=135883&r1=135882&r2=135883&view=diff ============================================================================== --- vmkit/trunk/Makefile.rules (original) +++ vmkit/trunk/Makefile.rules Sun Jul 24 14:21:31 2011 @@ -79,7 +79,7 @@ $(Verb) $(LOPT) $(LibDir)/FinalMMTk.bc -load=$(LibDir)/StaticGCPass$(SHLIBEXT) -std-compile-opts -StaticGCPass -o $(LibDir)/FinalMMTk.bc $(Verb) $(MKDIR) $(ObjDir) $(Verb) $(LLC) -disable-fp-elim -load=$(LibDir)/StaticGCPrinter$(SHLIBEXT) $(LibDir)/FinalMMTk.bc -o $(ObjDir)/FinalMMTk.s - $(Verb) $(Compile.Wrapper) $(LLVMCC) $(CPP.Flags) $(C.Flags) $(CFLAGS) $(CPPFLAGS) $(TargetCommonOpts) $(CompileCommonOpts) -c $(ObjDir)/FinalMMTk.s -o $(ObjDir)/FinalMMTk.o + $(Verb) $(LLVMCC) -c $(ObjDir)/FinalMMTk.s -o $(ObjDir)/FinalMMTk.o $(Verb) $(Archive) $(LibDir)/libFinalMMTk.a $(ObjDir)/FinalMMTk.o $(Verb) $(Ranlib) $(LibDir)/libFinalMMTk.a $(Verb) $(LLC) -march=cpp -cppgen=function -cppfor=gcmalloc $(LibDir)/FinalMMTk.bc -o $(PROJ_SRC_ROOT)/mmtk/inline/MMTkMallocInline.inc Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=135883&r1=135882&r2=135883&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Sun Jul 24 14:21:31 2011 @@ -1775,31 +1775,31 @@ } void JavaAOTCompiler::printStats() { - fprintf(stderr, "----------------- Info from the module -----------------\n"); - fprintf(stderr, "Number of native classes : %llu\n", + fprintf(stdout, "----------------- Info from the module -----------------\n"); + fprintf(stdout, "Number of native classes : %llu\n", (unsigned long long int) nativeClasses.size()); - fprintf(stderr, "Number of Java classes : %llu\n", + fprintf(stdout, "Number of Java classes : %llu\n", (unsigned long long int) javaClasses.size()); - fprintf(stderr, "Number of external array classes : %llu\n", + fprintf(stdout, "Number of external array classes : %llu\n", (unsigned long long int) arrayClasses.size()); - fprintf(stderr, "Number of virtual tables : %llu\n", + fprintf(stdout, "Number of virtual tables : %llu\n", (unsigned long long int) virtualTables.size()); - fprintf(stderr, "Number of static instances : %llu\n", + fprintf(stdout, "Number of static instances : %llu\n", (unsigned long long int) staticInstances.size()); - fprintf(stderr, "Number of constant pools : %llu\n", + fprintf(stdout, "Number of constant pools : %llu\n", (unsigned long long int) resolvedConstantPools.size()); - fprintf(stderr, "Number of strings : %llu\n", + fprintf(stdout, "Number of strings : %llu\n", (unsigned long long int) strings.size()); - fprintf(stderr, "Number of native functions : %llu\n", + fprintf(stdout, "Number of native functions : %llu\n", (unsigned long long int) nativeFunctions.size()); - fprintf(stderr, "----------------- Total size in .data ------------------\n"); + fprintf(stdout, "----------------- Total size in .data ------------------\n"); uint64 size = 0; Module* Mod = getLLVMModule(); for (Module::const_global_iterator i = Mod->global_begin(), e = Mod->global_end(); i != e; ++i) { size += mvm::MvmModule::getTypeSize(i->getType()); } - fprintf(stderr, "%lluB\n", (unsigned long long int)size); + fprintf(stdout, "%lluB\n", (unsigned long long int)size); } Modified: vmkit/trunk/tools/precompiler/trainer/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/precompiler/trainer/Makefile?rev=135883&r1=135882&r2=135883&view=diff ============================================================================== --- vmkit/trunk/tools/precompiler/trainer/Makefile (original) +++ vmkit/trunk/tools/precompiler/trainer/Makefile Sun Jul 24 14:21:31 2011 @@ -18,15 +18,18 @@ PRECOMPILER := $(ToolDir)/precompiler$(EXEEXT) +ifndef VERBOSE + J3.Flags := > /dev/null +endif + generated.bc: $(PRECOMPILER) HelloWorld.java $(LibDir)/StaticJ3GC$(SHLIBEXT) $(LibDir)/StaticGCPass$(SHLIBEXT) $(LibDir)/StaticGCPrinter$(SHLIBEXT) $(Echo) "Building precompiled bootstrap code" $(Verb) javac HelloWorld.java - $(Verb) $(PRECOMPILER) -cp $$PWD HelloWorld + $(Verb) $(PRECOMPILER) -cp $$PWD HelloWorld $(J3.Flags) $(Verb) $(MKDIR) $(ObjDir) $(Verb) $(LOPT) generated.bc -load=$(LibDir)/StaticGCPass$(SHLIBEXT) -StaticGCPass -o $(LibDir)/Precompiled.bc $(Verb) $(LLC) -O0 -fast-isel=false -load=$(LibDir)/StaticJ3GC$(SHLIBEXT) -load=$(LibDir)/StaticGCPrinter$(SHLIBEXT) -disable-fp-elim $(LibDir)/Precompiled.bc -o $(ObjDir)/Precompiled.s - $(Verb) $(Compile.Wrapper) $(LLVMCC) $(CPP.Flags) $(C.Flags) $(CFLAGS) $(CPPFLAGS) $(TargetCommonOpts) $(CompileCommonOpts) -c $(ObjDir)/Precompiled.s -o $(ObjDir)/Precompiled.o - + $(Verb) $(Compile.Wrapper) $(LLVMCC) -c $(ObjDir)/Precompiled.s -o $(ObjDir)/Precompiled.o $(Verb) $(Archive) $(LibDir)/libPrecompiled.a $(ObjDir)/Precompiled.o $(Verb) $(Ranlib) $(LibDir)/libPrecompiled.a From nicolas.geoffray at lip6.fr Sun Jul 24 13:19:47 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 24 Jul 2011 20:19:47 -0000 Subject: [vmkit-commits] [vmkit] r135884 - /vmkit/trunk/tools/precompiler/trainer/Makefile Message-ID: <20110724201947.1ED4E2A6C12C@llvm.org> Author: geoffray Date: Sun Jul 24 15:19:46 2011 New Revision: 135884 URL: http://llvm.org/viewvc/llvm-project?rev=135884&view=rev Log: Fix Makefile so that compilation with multiple threads work. Modified: vmkit/trunk/tools/precompiler/trainer/Makefile Modified: vmkit/trunk/tools/precompiler/trainer/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/precompiler/trainer/Makefile?rev=135884&r1=135883&r2=135884&view=diff ============================================================================== --- vmkit/trunk/tools/precompiler/trainer/Makefile (original) +++ vmkit/trunk/tools/precompiler/trainer/Makefile Sun Jul 24 15:19:46 2011 @@ -12,7 +12,7 @@ MODULE_WITH_GC = Precompiled -BUILT_SOURCES = generated.bc +BUILT_SOURCES = Precompiled.bc include $(LEVEL)/Makefile.common @@ -22,16 +22,17 @@ J3.Flags := > /dev/null endif -generated.bc: $(PRECOMPILER) HelloWorld.java $(LibDir)/StaticJ3GC$(SHLIBEXT) $(LibDir)/StaticGCPass$(SHLIBEXT) $(LibDir)/StaticGCPrinter$(SHLIBEXT) +Precompiled.bc: $(PRECOMPILER) HelloWorld.java $(LibDir)/StaticJ3GC$(SHLIBEXT) $(LibDir)/StaticGCPass$(SHLIBEXT) $(LibDir)/StaticGCPrinter$(SHLIBEXT) $(Echo) "Building precompiled bootstrap code" $(Verb) javac HelloWorld.java $(Verb) $(PRECOMPILER) -cp $$PWD HelloWorld $(J3.Flags) $(Verb) $(MKDIR) $(ObjDir) $(Verb) $(LOPT) generated.bc -load=$(LibDir)/StaticGCPass$(SHLIBEXT) -StaticGCPass -o $(LibDir)/Precompiled.bc $(Verb) $(LLC) -O0 -fast-isel=false -load=$(LibDir)/StaticJ3GC$(SHLIBEXT) -load=$(LibDir)/StaticGCPrinter$(SHLIBEXT) -disable-fp-elim $(LibDir)/Precompiled.bc -o $(ObjDir)/Precompiled.s - $(Verb) $(Compile.Wrapper) $(LLVMCC) -c $(ObjDir)/Precompiled.s -o $(ObjDir)/Precompiled.o + $(Verb) $(LLVMCC) -c $(ObjDir)/Precompiled.s -o $(ObjDir)/Precompiled.o $(Verb) $(Archive) $(LibDir)/libPrecompiled.a $(ObjDir)/Precompiled.o $(Verb) $(Ranlib) $(LibDir)/libPrecompiled.a + $(Verb) $(MV) generated.bc Precompiled.bc clean-local:: - $(Verb) $(RM) -f HelloWorld.class generated.bc + $(Verb) $(RM) -f HelloWorld.class Precompiled.bc From nicolas.geoffray at lip6.fr Sun Jul 24 13:40:13 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 24 Jul 2011 20:40:13 -0000 Subject: [vmkit-commits] [vmkit] r135887 - /vmkit/trunk/tools/precompiler/trainer/Makefile Message-ID: <20110724204014.047982A6C12C@llvm.org> Author: geoffray Date: Sun Jul 24 15:40:13 2011 New Revision: 135887 URL: http://llvm.org/viewvc/llvm-project?rev=135887&view=rev Log: Remove useless line. Modified: vmkit/trunk/tools/precompiler/trainer/Makefile Modified: vmkit/trunk/tools/precompiler/trainer/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/precompiler/trainer/Makefile?rev=135887&r1=135886&r2=135887&view=diff ============================================================================== --- vmkit/trunk/tools/precompiler/trainer/Makefile (original) +++ vmkit/trunk/tools/precompiler/trainer/Makefile Sun Jul 24 15:40:13 2011 @@ -10,8 +10,6 @@ include $(LEVEL)/Makefile.config -MODULE_WITH_GC = Precompiled - BUILT_SOURCES = Precompiled.bc include $(LEVEL)/Makefile.common From nicolas.geoffray at lip6.fr Mon Jul 25 11:53:31 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Mon, 25 Jul 2011 18:53:31 -0000 Subject: [vmkit-commits] [vmkit] r135931 - in /vmkit/trunk: include/j3/JavaAOTCompiler.h lib/J3/Compiler/JavaAOTCompiler.cpp lib/J3/VMCore/Jnjvm.cpp lib/J3/VMCore/JnjvmClassLoader.cpp lib/J3/VMCore/JnjvmClassLoader.h lib/J3/VMCore/UTF8.h Message-ID: <20110725185331.72F052A6C12C@llvm.org> Author: geoffray Date: Mon Jul 25 13:53:31 2011 New Revision: 135931 URL: http://llvm.org/viewvc/llvm-project?rev=135931&view=rev Log: Include all bytes of the bootstrap classpath after precompiling. Modified: vmkit/trunk/include/j3/JavaAOTCompiler.h vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h vmkit/trunk/lib/J3/VMCore/UTF8.h Modified: vmkit/trunk/include/j3/JavaAOTCompiler.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/JavaAOTCompiler.h?rev=135931&r1=135930&r2=135931&view=diff ============================================================================== --- vmkit/trunk/include/j3/JavaAOTCompiler.h (original) +++ vmkit/trunk/include/j3/JavaAOTCompiler.h Mon Jul 25 13:53:31 2011 @@ -59,6 +59,7 @@ virtual llvm::Constant* getFinalObject(JavaObject* obj, CommonClass* cl); virtual JavaObject* getFinalObject(llvm::Value* C); virtual llvm::Constant* getNativeClass(CommonClass* cl); + virtual llvm::Constant* getClassBytes(const UTF8* name, ClassBytes* bytes); virtual llvm::Constant* getJavaClass(CommonClass* cl); virtual llvm::Constant* getJavaClassPtr(CommonClass* cl); virtual llvm::Constant* getStaticInstance(Class* cl); @@ -110,6 +111,7 @@ llvm::Constant* CreateConstantFromObjectArray(const ArrayObject* val); std::map nativeClasses; + std::map classBytes; std::map arrayClasses; std::map javaClasses; std::map virtualTables; @@ -135,6 +137,9 @@ typedef std::map::iterator native_class_iterator; + typedef std::map::iterator + class_bytes_iterator; + typedef std::map::iterator array_class_iterator; Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=135931&r1=135930&r2=135931&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Mon Jul 25 13:53:31 2011 @@ -256,6 +256,22 @@ } } +Constant* JavaAOTCompiler::getClassBytes(const UTF8* className, ClassBytes* bytes) { + class_bytes_iterator CI = classBytes.find(bytes); + if (CI != classBytes.end()) { + return CI->second; + } + + std::string name(UTF8Buffer(className).toCompileName()->cString()); + name += "_bytes"; + Constant* C = CreateConstantFromClassBytes(bytes); + GlobalVariable* varGV = new GlobalVariable(*getLLVMModule(), C->getType(), false, + GlobalValue::ExternalLinkage, + C, name); + classBytes[bytes] = varGV; + return varGV; +} + Constant* JavaAOTCompiler::getStringPtr(JavaString** str) { fprintf(stderr, "Implement me"); abort(); @@ -1234,20 +1250,16 @@ // ownerClass ClassElts.push_back(Constant::getNullValue(JavaIntrinsics.ptrType)); - // bytes - Constant* bytes = CreateConstantFromClassBytes(cl->bytes); - GlobalVariable* varGV = new GlobalVariable(*getLLVMModule(), bytes->getType(), false, - GlobalValue::InternalLinkage, - bytes, ""); - - bytes = ConstantExpr::getBitCast(varGV, JavaIntrinsics.ClassBytesType); + // bytes + Constant* bytes = ConstantExpr::getBitCast(getClassBytes(cl->name, cl->bytes), + JavaIntrinsics.ClassBytesType); ClassElts.push_back(bytes); // ctpInfo Constant* ctpInfo = CreateConstantFromJavaConstantPool(cl->ctpInfo); - varGV = new GlobalVariable(*getLLVMModule(), ctpInfo->getType(), false, - GlobalValue::InternalLinkage, - ctpInfo, ""); + Constant* varGV = new GlobalVariable(*getLLVMModule(), ctpInfo->getType(), false, + GlobalValue::InternalLinkage, + ctpInfo, ""); ClassElts.push_back(varGV); // attributs @@ -2263,6 +2275,18 @@ } } while (changed); + for (std::vector::iterator i = loader->bootArchives.begin(), + e = loader->bootArchives.end(); i != e; ++i) { + ZipArchive* archive = *i; + for (ZipArchive::table_iterator zi = archive->filetable.begin(), + ze = archive->filetable.end(); zi != ze; zi++) { + const char* name = zi->first; + ClassBytes* bytes = Reader::openZip(loader, archive, name); + getClassBytes(loader->asciizConstructUTF8(name), bytes); + } + } + + CreateStaticInitializer(); } Modified: vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp?rev=135931&r1=135930&r2=135931&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp Mon Jul 25 13:53:31 2011 @@ -1246,7 +1246,6 @@ llvm_gcroot(exc, 0); Jnjvm* vm = thread->getJVM(); - vm->bootstrapLoader->analyseClasspathEnv(vm->bootstrapLoader->bootClasspathEnv); vm->argumentsInfo.readArgs(vm); if (vm->argumentsInfo.className == NULL) { vm->threadSystem.leave(); Modified: vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp?rev=135931&r1=135930&r2=135931&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp Mon Jul 25 13:53:31 2011 @@ -71,17 +71,9 @@ javaSignatures = new(allocator, "SignMap") SignMap(); strings = new(allocator, "StringList") StringList(); - bootClasspathEnv = getenv("JNJVM_BOOTCLASSPATH"); - if (!bootClasspathEnv) { - bootClasspathEnv = GNUClasspathGlibj; - } - - libClasspathEnv = getenv("JNJVM_LIBCLASSPATH"); - if (!libClasspathEnv) { - libClasspathEnv = GNUClasspathLibs; - } - - + bootClasspathEnv = GNUClasspathGlibj; + libClasspathEnv = GNUClasspathLibs; + upcalls = new(allocator, "Classpath") Classpath(); bootstrapLoader = this; @@ -92,6 +84,10 @@ } if (!bootLoaded) { + // Analyze the boot classpath, we know bootstrap classes are not in the + // executable. + analyseClasspathEnv(bootClasspathEnv); + // Allocate the interfaces array for array classes, so that VT construction // can use it right away. ClassArray::InterfacesArray = @@ -243,7 +239,10 @@ } ClassBytes* JnjvmBootstrapLoader::openName(const UTF8* utf8) { - ClassBytes* res = 0; + ClassBytes* res = reinterpret_cast(dlsym(SELF_HANDLE, + UTF8Buffer(utf8).toCompileName(".class_bytes")->cString())); + if (res != NULL) return res; + mvm::ThreadAllocator threadAllocator; char* asciiz = (char*)threadAllocator.Allocate(utf8->size + 1); @@ -261,7 +260,7 @@ sprintf(buf, "%s%s.class", str, asciiz); res = Reader::openFile(this, buf); - if (res) return res; + if (res != NULL) return res; } for (std::vector::iterator i = bootArchives.begin(), @@ -271,10 +270,10 @@ char* buf = (char*)threadAllocator.Allocate(alen + 7); sprintf(buf, "%s.class", asciiz); res = Reader::openZip(this, archive, buf); - if (res) return res; + if (res != NULL) return res; } - return 0; + return NULL; } Modified: vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h?rev=135931&r1=135930&r2=135931&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h (original) +++ vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h Mon Jul 25 13:53:31 2011 @@ -416,6 +416,7 @@ virtual ~JnjvmBootstrapLoader(); friend class ClArgumentsInfo; + friend class JavaAOTCompiler; }; Modified: vmkit/trunk/lib/J3/VMCore/UTF8.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/UTF8.h?rev=135931&r1=135930&r2=135931&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/UTF8.h (original) +++ vmkit/trunk/lib/J3/VMCore/UTF8.h Mon Jul 25 13:53:31 2011 @@ -29,10 +29,11 @@ /// toCompileName - Change the utf8 following JNI conventions. /// - UTF8Buffer* toCompileName() { + UTF8Buffer* toCompileName(const char* suffix = "") { const char *buffer = cString(); uint32 len = strlen(buffer); - char* newBuffer = new char[(len << 1) + 1]; + uint32 suffixLen = strlen(suffix); + char* newBuffer = new char[(len << 1) + suffixLen + 1]; uint32 j = 0; for (uint32 i = 0; i < len; ++i) { if (buffer[i] == '/') { @@ -53,6 +54,9 @@ newBuffer[j++] = buffer[i]; } } + for (uint32 i = 0; i < suffixLen; i++) { + newBuffer[j++] = suffix[i]; + } newBuffer[j] = 0; replaceWith(newBuffer); return this; From nicolas.geoffray at lip6.fr Mon Jul 25 12:49:42 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Mon, 25 Jul 2011 19:49:42 -0000 Subject: [vmkit-commits] [vmkit] r135941 - in /vmkit/trunk: include/mvm/VirtualMachine.h lib/Mvm/Runtime/MethodInfo.cpp Message-ID: <20110725194942.4F7202A6C12C@llvm.org> Author: geoffray Date: Mon Jul 25 14:49:42 2011 New Revision: 135941 URL: http://llvm.org/viewvc/llvm-project?rev=135941&view=rev Log: Use the VM allocator to allocate caml frames. Also make sure the function cache is big enough so that we don't resize at startup. Modified: vmkit/trunk/include/mvm/VirtualMachine.h vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp Modified: vmkit/trunk/include/mvm/VirtualMachine.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/VirtualMachine.h?rev=135941&r1=135940&r2=135941&view=diff ============================================================================== --- vmkit/trunk/include/mvm/VirtualMachine.h (original) +++ vmkit/trunk/include/mvm/VirtualMachine.h Mon Jul 25 14:49:42 2011 @@ -51,7 +51,7 @@ /// removeMethodInfos - Remove all MethodInfo owned by the given owner. void removeMethodInfos(void* owner); - FunctionMap(CamlFrames** frames); + FunctionMap(BumpPtrAllocator& allocator, CamlFrames** frames); }; /// VirtualMachine - This class is the root of virtual machine classes. It @@ -60,7 +60,7 @@ class VirtualMachine : public mvm::PermanentObject { protected: VirtualMachine(mvm::BumpPtrAllocator &Alloc, mvm::CamlFrames** frames) : - allocator(Alloc), FunctionsCache(frames) { + allocator(Alloc), FunctionsCache(Alloc, frames) { mainThread = NULL; numberOfThreads = 0; doExit = false; Modified: vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp?rev=135941&r1=135940&r2=135941&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp (original) +++ vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp Mon Jul 25 14:49:42 2011 @@ -87,9 +87,9 @@ static BumpPtrAllocator* StaticAllocator = NULL; -FunctionMap::FunctionMap(CamlFrames** allFrames) { +FunctionMap::FunctionMap(BumpPtrAllocator& allocator, CamlFrames** allFrames) { if (allFrames == NULL) return; - StaticAllocator = new BumpPtrAllocator(); + Functions.resize(40000); // Make sure the cache is big enough. int i = 0; CamlFrames* frames = NULL; while ((frames = allFrames[i++]) != NULL) { @@ -97,7 +97,7 @@ while (decoder.hasNext()) { CamlFrame* frame = decoder.next(); CamlMethodInfo* MI = - new(*StaticAllocator, "CamlMethodInfo") CamlMethodInfo(frame); + new(allocator, "CamlMethodInfo") CamlMethodInfo(frame); addMethodInfoNoLock(MI, frame->ReturnAddress); } } From nicolas.geoffray at lip6.fr Mon Jul 25 14:43:41 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Mon, 25 Jul 2011 21:43:41 -0000 Subject: [vmkit-commits] [vmkit] r135981 - in /vmkit/trunk: include/mvm/UTF8.h lib/Mvm/Runtime/UTF8.cpp Message-ID: <20110725214341.296902A6C12C@llvm.org> Author: geoffray Date: Mon Jul 25 16:43:40 2011 New Revision: 135981 URL: http://llvm.org/viewvc/llvm-project?rev=135981&view=rev Log: Remove unused methods. Modified: vmkit/trunk/include/mvm/UTF8.h vmkit/trunk/lib/Mvm/Runtime/UTF8.cpp Modified: vmkit/trunk/include/mvm/UTF8.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/UTF8.h?rev=135981&r1=135980&r2=135981&view=diff ============================================================================== --- vmkit/trunk/include/mvm/UTF8.h (original) +++ vmkit/trunk/include/mvm/UTF8.h Mon Jul 25 16:43:40 2011 @@ -89,13 +89,6 @@ } } - void copy(UTF8Map* newMap) { - for (iterator i = map.begin(), e = map.end(); i!= e; ++i) { - newMap->map.insert(*i); - } - } - - void replace(const UTF8* oldUTF8, const UTF8* newUTF8); void insert(const UTF8* val); }; Modified: vmkit/trunk/lib/Mvm/Runtime/UTF8.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/UTF8.cpp?rev=135981&r1=135980&r2=135981&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Runtime/UTF8.cpp (original) +++ vmkit/trunk/lib/Mvm/Runtime/UTF8.cpp Mon Jul 25 16:43:40 2011 @@ -67,22 +67,6 @@ else return !(memcmp(val->elements, buf, len * sizeof(uint16))); } -void UTF8Map::replace(const UTF8* oldUTF8, const UTF8* newUTF8) { - lock.lock(); - uint32 key = oldUTF8->hash(); - std::pair p = map.equal_range(key); - - for (UTF8Map::iterator i = p.first; i != p.second; i++) { - if (i->second == oldUTF8) { - map.erase(i); - break; - } - } - map.insert(std::make_pair(key, newUTF8)); - lock.unlock(); - -} - const UTF8* UTF8Map::lookupOrCreateAsciiz(const char* asciiz) { sint32 size = strlen(asciiz); uint32 key = asciizHasher(asciiz, size); From nicolas.geoffray at lip6.fr Mon Jul 25 16:05:46 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Mon, 25 Jul 2011 23:05:46 -0000 Subject: [vmkit-commits] [vmkit] r136005 - in /vmkit/trunk/lib/J3: Compiler/JavaAOTCompiler.cpp Compiler/LLVMInfo.cpp VMCore/JavaTypes.h VMCore/JnjvmClassLoader.h Message-ID: <20110725230546.7A6612A6C12C@llvm.org> Author: geoffray Date: Mon Jul 25 18:05:46 2011 New Revision: 136005 URL: http://llvm.org/viewvc/llvm-project?rev=136005&view=rev Log: 1) Emit stubs used during execution of the trainer. 2) Make sure we don't try to recreate IMT and VT of precompiled classes. Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp vmkit/trunk/lib/J3/VMCore/JavaTypes.h vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=136005&r1=136004&r2=136005&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Mon Jul 25 18:05:46 2011 @@ -2275,6 +2275,7 @@ } } while (changed); + // Add the bootstrap classes to the image. for (std::vector::iterator i = loader->bootArchives.begin(), e = loader->bootArchives.end(); i != e; ++i) { ZipArchive* archive = *i; @@ -2286,6 +2287,38 @@ } } + // Finally add used stubs to the image. + for (SignMap::iterator i = loader->javaSignatures->map.begin(), + e = loader->javaSignatures->map.end(); i != e; i++) { + Signdef* signature = i->second; + LLVMSignatureInfo* LSI = getSignatureInfo(signature); + if (signature->_staticCallBuf != 0) { + LSI->getStaticBuf(); + } + if (signature->_virtualCallBuf != 0) { + LSI->getVirtualBuf(); + } + if (signature->_staticCallAP != 0) { + LSI->getStaticAP(); + } + if (signature->_virtualCallAP != 0) { + LSI->getVirtualAP(); + } + if (signature->_virtualCallStub != 0) { + LSI->getVirtualStub(); + } + if (signature->_specialCallStub != 0) { + LSI->getSpecialStub(); + } + if (signature->_staticCallStub != 0) { + LSI->getStaticStub(); + } + } + + // Finally emit the stub for the main signature. + Signdef* mainSignature = + loader->constructSign(loader->asciizConstructUTF8("([Ljava/lang/String;)V")); + getSignatureInfo(mainSignature)->getStaticBuf(); CreateStaticInitializer(); } Modified: vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp?rev=136005&r1=136004&r2=136005&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp Mon Jul 25 18:05:46 2011 @@ -72,7 +72,9 @@ virtualSizeConstant = ConstantInt::get(Type::getInt32Ty(context), size); // TODO: put that elsewhere. - if (Compiler == classDef->classLoader->getCompiler()) { + // The class is resolved if it was precompiled. + if ((!classDef->isResolved() || Compiler->isStaticCompiling()) + && Compiler == classDef->classLoader->getCompiler()) { for (uint32 i = 0; i < classDef->nbVirtualFields; ++i) { JavaField& field = classDef->virtualFields[i]; field.ptrOffset = sl->getElementOffset(i + 1); @@ -396,18 +398,23 @@ std::vector Args; J3Intrinsics& Intrinsics = *Compiler->getIntrinsics(); - std::string name; + Function* res = NULL; if (Compiler->isStaticCompiling()) { - name += UTF8Buffer(signature->keyName).cString(); - name += virt ? "virtual_ap" : "static_ap"; + mvm::ThreadAllocator allocator; + const char* type = virt ? "virtual_ap" : "static_ap"; + char* buf = (char*)allocator.Allocate( + (signature->keyName->size << 1) + 1 + 11); + signature->nativeName(buf, type); + res = Function::Create(virt ? getVirtualBufType() : getStaticBufType(), + GlobalValue::ExternalLinkage, buf, + Compiler->getLLVMModule()); + + } else { - name = ""; + res = Function::Create(virt ? getVirtualBufType() : getStaticBufType(), + GlobalValue::ExternalLinkage, "", + Compiler->getLLVMModule()); } - - Function* res = Function::Create(virt ? getVirtualBufType() : - getStaticBufType(), - GlobalValue::ExternalLinkage, name, - Compiler->getLLVMModule()); LLVMContext& context = Compiler->getLLVMModule()->getContext(); BasicBlock* currentBlock = BasicBlock::Create(context, "enter", res); @@ -470,18 +477,23 @@ std::vector TempArgs; J3Intrinsics& Intrinsics = *Compiler->getIntrinsics(); - std::string name; + Function* stub = NULL; if (Compiler->isStaticCompiling()) { - name += UTF8Buffer(signature->keyName).cString(); - name += virt ? "virtual_stub" : special ? "special_stub" : "static_stub"; + mvm::ThreadAllocator allocator; + const char* type = virt ? "virtual_stub" : special ? "special_stub" : "static_stub"; + char* buf = (char*)allocator.Allocate( + (signature->keyName->size << 1) + 1 + 11); + signature->nativeName(buf, type); + stub = Function::Create((virt || special)? getVirtualType() : getStaticType(), + GlobalValue::ExternalLinkage, buf, + Compiler->getLLVMModule()); + + } else { - name = ""; + stub = Function::Create((virt || special)? getVirtualType() : getStaticType(), + GlobalValue::ExternalLinkage, "", + Compiler->getLLVMModule()); } - - Function* stub = Function::Create((virt || special) ? getVirtualType() : - getStaticType(), - GlobalValue::ExternalLinkage, name, - Compiler->getLLVMModule()); LLVMContext& context = Compiler->getLLVMModule()->getContext(); BasicBlock* currentBlock = BasicBlock::Create(context, "enter", stub); Modified: vmkit/trunk/lib/J3/VMCore/JavaTypes.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaTypes.h?rev=136005&r1=136004&r2=136005&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaTypes.h (original) +++ vmkit/trunk/lib/J3/VMCore/JavaTypes.h Mon Jul 25 18:05:46 2011 @@ -428,6 +428,8 @@ /// type. /// Typedef* arguments[1]; + + friend class JavaAOTCompiler; }; } // end namespace j3 Modified: vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h?rev=136005&r1=136004&r2=136005&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h (original) +++ vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h Mon Jul 25 18:05:46 2011 @@ -305,6 +305,7 @@ friend class Class; friend class CommonClass; friend class StringList; + friend class JavaAOTCompiler; }; /// JnjvmBootstrapLoader - This class is for the bootstrap class loader, which From nicolas.geoffray at lip6.fr Tue Jul 26 13:51:47 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Tue, 26 Jul 2011 20:51:47 -0000 Subject: [vmkit-commits] [vmkit] r136136 - in /vmkit/trunk/lib/J3/Compiler: JavaJIT.cpp JavaJITOpcodes.cpp LowerConstantCalls.cpp Message-ID: <20110726205147.289122A6C12C@llvm.org> Author: geoffray Date: Tue Jul 26 15:51:46 2011 New Revision: 136136 URL: http://llvm.org/viewvc/llvm-project?rev=136136&view=rev Log: Update to new LLVM API. Modified: vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp vmkit/trunk/lib/J3/Compiler/LowerConstantCalls.cpp Modified: vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp?rev=136136&r1=136135&r2=136136&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp Tue Jul 26 15:51:46 2011 @@ -173,7 +173,7 @@ Value* VT = CallInst::Create(intrinsics->GetVTFunction, args[0], "", currentBlock); - Value* FuncPtr = GetElementPtrInst::Create(VT, indexes2, indexes2 + 2, "", currentBlock); + Value* FuncPtr = GetElementPtrInst::Create(VT, indexes2, "", currentBlock); Value* Func = new LoadInst(FuncPtr, "", currentBlock); @@ -224,7 +224,7 @@ intrinsics->OffsetThreadInMutatorThreadConstant, intrinsics->OffsetIsolateIDInThreadConstant }; - return GetElementPtrInst::Create(mutatorThreadPtr, GEP, GEP + 3, "", currentBlock); + return GetElementPtrInst::Create(mutatorThreadPtr, GEP, "", currentBlock); } llvm::Value* JavaJIT::getVMPtr(llvm::Value* mutatorThreadPtr) { @@ -232,7 +232,7 @@ intrinsics->OffsetThreadInMutatorThreadConstant, intrinsics->OffsetVMInThreadConstant }; - return GetElementPtrInst::Create(mutatorThreadPtr, GEP, GEP + 3, "", currentBlock); + return GetElementPtrInst::Create(mutatorThreadPtr, GEP, "", currentBlock); } llvm::Value* JavaJIT::getDoYieldPtr(llvm::Value* mutatorThreadPtr) { @@ -240,7 +240,7 @@ intrinsics->OffsetThreadInMutatorThreadConstant, intrinsics->OffsetDoYieldInThreadConstant }; - return GetElementPtrInst::Create(mutatorThreadPtr, GEP, GEP + 3, "", currentBlock); + return GetElementPtrInst::Create(mutatorThreadPtr, GEP, "", currentBlock); } llvm::Value* JavaJIT::getCXXExceptionPtr(llvm::Value* mutatorThreadPtr) { @@ -248,21 +248,21 @@ intrinsics->OffsetThreadInMutatorThreadConstant, intrinsics->OffsetCXXExceptionInThreadConstant }; - return GetElementPtrInst::Create(mutatorThreadPtr, GEP, GEP + 3, "", currentBlock); + return GetElementPtrInst::Create(mutatorThreadPtr, GEP, "", currentBlock); } llvm::Value* JavaJIT::getJNIEnvPtr(llvm::Value* javaThreadPtr) { Value* GEP[2] = { intrinsics->constantZero, intrinsics->OffsetJNIInJavaThreadConstant }; - return GetElementPtrInst::Create(javaThreadPtr, GEP, GEP + 2, "", currentBlock); + return GetElementPtrInst::Create(javaThreadPtr, GEP, "", currentBlock); } llvm::Value* JavaJIT::getJavaExceptionPtr(llvm::Value* javaThreadPtr) { Value* GEP[2] = { intrinsics->constantZero, intrinsics->OffsetJavaExceptionInJavaThreadConstant }; - return GetElementPtrInst::Create(javaThreadPtr, GEP, GEP + 2, "", currentBlock); + return GetElementPtrInst::Create(javaThreadPtr, GEP, "", currentBlock); } @@ -531,8 +531,7 @@ std::vector gep; gep.push_back(intrinsics->constantZero); gep.push_back(intrinsics->JavaObjectLockOffsetConstant); - Value* lockPtr = GetElementPtrInst::Create(obj, gep.begin(), gep.end(), "", - currentBlock); + Value* lockPtr = GetElementPtrInst::Create(obj, gep, "", currentBlock); Value* lock = new LoadInst(lockPtr, "", currentBlock); lock = new PtrToIntInst(lock, intrinsics->pointerSizeType, "", currentBlock); @@ -579,8 +578,7 @@ std::vector gep; gep.push_back(intrinsics->constantZero); gep.push_back(intrinsics->JavaObjectLockOffsetConstant); - Value* lockPtr = GetElementPtrInst::Create(obj, gep.begin(), gep.end(), "", - currentBlock); + Value* lockPtr = GetElementPtrInst::Create(obj, gep, "", currentBlock); lockPtr = new BitCastInst(lockPtr, PointerType::getUnqual(intrinsics->pointerSizeType), "", currentBlock); @@ -1282,8 +1280,7 @@ Value* val = new BitCastInst(obj, arrayType, "", currentBlock); Value* indexes[3] = { zero, intrinsics->JavaArrayElementsOffsetConstant, index }; - Value* ptr = GetElementPtrInst::Create(val, indexes, indexes + 3, "", - currentBlock); + Value* ptr = GetElementPtrInst::Create(val, indexes, "", currentBlock); return ptr; @@ -1748,8 +1745,7 @@ Value* objectConvert = new BitCastInst(object, type, "", currentBlock); Value* args[2] = { intrinsics->constantZero, LFI->getOffset() }; - Value* ptr = llvm::GetElementPtrInst::Create(objectConvert, - args, args + 2, "", + Value* ptr = llvm::GetElementPtrInst::Create(objectConvert, args, "", currentBlock); return ptr; } @@ -1773,7 +1769,7 @@ object, "", TheCompiler->useCooperativeGC(), currentBlock); Value* tmp = new BitCastInst(object, Pty, "", currentBlock); Value* args[2] = { zero, ptr }; - ptr = GetElementPtrInst::Create(tmp, args, args + 2, "", currentBlock); + ptr = GetElementPtrInst::Create(tmp, args, "", currentBlock); } return new BitCastInst(ptr, fieldTypePtr, "", currentBlock); @@ -2046,7 +2042,7 @@ Value* indices[2] = { intrinsics->constantZero, Index }; - Instruction* ptr_18 = GetElementPtrInst::Create(IMT, indices, indices + 2, "", + Instruction* ptr_18 = GetElementPtrInst::Create(IMT, indices, "", currentBlock); Instruction* int32_19 = new LoadInst(ptr_18, "", false, currentBlock); int32_19 = new PtrToIntInst(int32_19, intrinsics->pointerSizeType, "", @@ -2198,8 +2194,7 @@ ptr_21_indices.push_back(intrinsics->constantZero); ptr_21_indices.push_back(intrinsics->OffsetAccessInCommonClassConstant); Instruction* ptr_21 = - GetElementPtrInst::Create(ptr_20, ptr_21_indices.begin(), - ptr_21_indices.end(), "", label_bb); + GetElementPtrInst::Create(ptr_20, ptr_21_indices, "", label_bb); LoadInst* int32_22 = new LoadInst(ptr_21, "", false, label_bb); Value* cmp = BinaryOperator::CreateAnd(int32_22, intrinsics->IsArrayConstant, "", label_bb); @@ -2255,16 +2250,14 @@ intrinsics->OffsetBaseClassInArrayClassConstant }; Instruction* temp = new BitCastInst(ptr_20, intrinsics->JavaClassArrayType, "", log_label_entry); - Instruction* ptr_10 = GetElementPtrInst::Create(temp, ptr_10_indices, - ptr_10_indices + 2, "", + Instruction* ptr_10 = GetElementPtrInst::Create(temp, ptr_10_indices, "", log_label_entry); LoadInst* ptr_11 = new LoadInst(ptr_10, "", false, log_label_entry); Value* ptr_12_indices[2] = { intrinsics->constantZero, intrinsics->OffsetAccessInCommonClassConstant }; - Instruction* ptr_12 = GetElementPtrInst::Create(ptr_11, ptr_12_indices, - ptr_12_indices + 2, "", + Instruction* ptr_12 = GetElementPtrInst::Create(ptr_11, ptr_12_indices, "", log_label_entry); LoadInst* int16_13 = new LoadInst(ptr_12, "", false, log_label_entry); @@ -2282,8 +2275,7 @@ temp = new BitCastInst(ptr_11, intrinsics->JavaClassPrimitiveType, "", log_label_bb); GetElementPtrInst* ptr_18 = GetElementPtrInst::Create(temp, ptr_11_indices, - ptr_11_indices + 2, "", - log_label_bb); + "", log_label_bb); LoadInst* int32_20 = new LoadInst(ptr_18, "", false, log_label_bb); int32_start = BinaryOperator::CreateShl(int32_start, int32_20, "", @@ -2302,11 +2294,11 @@ Value* indexes[3] = { intrinsics->constantZero, intrinsics->JavaArrayElementsOffsetConstant, int32_start }; - Instruction* ptr_42 = GetElementPtrInst::Create(ptr_src, indexes, indexes + 3, + Instruction* ptr_42 = GetElementPtrInst::Create(ptr_src, indexes, "", log_label_bb); indexes[2] = int32_start2; - Instruction* ptr_44 = GetElementPtrInst::Create(ptr_dst, indexes, indexes + 3, + Instruction* ptr_44 = GetElementPtrInst::Create(ptr_dst, indexes, "", log_label_bb); BranchInst::Create(label_memmove, log_label_bb); Modified: vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp?rev=136136&r1=136135&r2=136136&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp Tue Jul 26 15:51:46 2011 @@ -2162,8 +2162,7 @@ // Set the size Value* gep4[2] = { intrinsics->constantZero, intrinsics->JavaArraySizeOffsetConstant }; - Value* GEP = GetElementPtrInst::Create(cast, gep4, gep4 + 2, - "", currentBlock); + Value* GEP = GetElementPtrInst::Create(cast, gep4, "", currentBlock); arg1 = new IntToPtrInst(arg1, intrinsics->ptrType, "", currentBlock); new StoreInst(arg1, GEP, currentBlock); Modified: vmkit/trunk/lib/J3/Compiler/LowerConstantCalls.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/LowerConstantCalls.cpp?rev=136136&r1=136135&r2=136136&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/LowerConstantCalls.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/LowerConstantCalls.cpp Tue Jul 26 15:51:46 2011 @@ -39,12 +39,11 @@ static Value* getTCM(J3Intrinsics* intrinsics, Value* Arg, Instruction* CI) { Value* GEP[2] = { intrinsics->constantZero, intrinsics->OffsetTaskClassMirrorInClassConstant }; - Value* TCMArray = GetElementPtrInst::Create(Arg, GEP, GEP + 2, "", CI); + Value* TCMArray = GetElementPtrInst::Create(Arg, GEP, "", CI); Value* GEP2[2] = { intrinsics->constantZero, intrinsics->constantZero }; - Value* TCM = GetElementPtrInst::Create(TCMArray, GEP2, GEP2 + 2, "", - CI); + Value* TCM = GetElementPtrInst::Create(TCMArray, GEP2, "", CI); return TCM; } @@ -52,12 +51,11 @@ static Value* getDelegatee(J3Intrinsics* intrinsics, Value* Arg, Instruction* CI) { Value* GEP[2] = { intrinsics->constantZero, intrinsics->constantZero }; - Value* TCMArray = GetElementPtrInst::Create(Arg, GEP, GEP + 2, "", CI); + Value* TCMArray = GetElementPtrInst::Create(Arg, GEP, "", CI); Value* GEP2[2] = { intrinsics->constantZero, intrinsics->constantZero }; - Value* TCM = GetElementPtrInst::Create(TCMArray, GEP2, GEP2 + 2, "", - CI); + Value* TCM = GetElementPtrInst::Create(TCMArray, GEP2, "", CI); return new LoadInst(TCM, "", CI); } @@ -170,8 +168,7 @@ "", CI); Value* args[2] = { intrinsics->constantZero, intrinsics->JavaArraySizeOffsetConstant }; - Value* ptr = GetElementPtrInst::Create(array, args, args + 2, - "", CI); + Value* ptr = GetElementPtrInst::Create(array, args, "", CI); Value* load = new LoadInst(ptr, "", CI); load = new PtrToIntInst(load, Type::getInt32Ty(*Context), "", CI); CI->replaceAllUsesWith(load); @@ -180,8 +177,7 @@ Changed = true; Value* val = Call.getArgument(0); // get the object Value* indexes[2] = { intrinsics->constantZero, intrinsics->constantZero }; - Value* VTPtr = GetElementPtrInst::Create(val, indexes, indexes + 2, - "", CI); + Value* VTPtr = GetElementPtrInst::Create(val, indexes, "", CI); Value* VT = new LoadInst(VTPtr, "", CI); CI->replaceAllUsesWith(VT); CI->eraseFromParent(); @@ -190,8 +186,7 @@ Value* val = Call.getArgument(0); // get the VT Value* indexes[2] = { intrinsics->constantZero, intrinsics->OffsetIMTInVTConstant }; - Value* IMTPtr = GetElementPtrInst::Create(val, indexes, indexes + 2, - "", CI); + Value* IMTPtr = GetElementPtrInst::Create(val, indexes, "", CI); Value* IMT = new LoadInst(IMTPtr, "", CI); IMT = new BitCastInst(IMT, CI->getType(), "", CI); CI->replaceAllUsesWith(IMT); @@ -201,14 +196,12 @@ Value* val = Call.getArgument(0); // get the object Value* args2[2] = { intrinsics->constantZero, intrinsics->JavaObjectVTOffsetConstant }; - Value* VTPtr = GetElementPtrInst::Create(val, args2, args2 + 2, - "", CI); + Value* VTPtr = GetElementPtrInst::Create(val, args2, "", CI); Value* VT = new LoadInst(VTPtr, "", CI); Value* args3[2] = { intrinsics->constantZero, intrinsics->OffsetClassInVTConstant }; - Value* clPtr = GetElementPtrInst::Create(VT, args3, args3 + 2, - "", CI); + Value* clPtr = GetElementPtrInst::Create(VT, args3, "", CI); Value* cl = new LoadInst(clPtr, "", CI); cl = new BitCastInst(cl, intrinsics->JavaCommonClassType, "", CI); @@ -221,8 +214,7 @@ Value* indexes[3] = { intrinsics->constantZero, intrinsics->constantZero, intrinsics->OffsetVTInClassConstant }; - Value* VTPtr = GetElementPtrInst::Create(val, indexes, indexes + 3, - "", CI); + Value* VTPtr = GetElementPtrInst::Create(val, indexes, "", CI); Value* VT = new LoadInst(VTPtr, "", CI); CI->replaceAllUsesWith(VT); CI->eraseFromParent(); @@ -232,8 +224,7 @@ Value* val = Call.getArgument(0); Value* indexes[2] = { intrinsics->constantZero, intrinsics->OffsetVTInClassConstant }; - Value* VTPtr = GetElementPtrInst::Create(val, indexes, indexes + 2, - "", CI); + Value* VTPtr = GetElementPtrInst::Create(val, indexes, "", CI); Value* VT = new LoadInst(VTPtr, "", CI); CI->replaceAllUsesWith(VT); CI->eraseFromParent(); @@ -244,8 +235,7 @@ Value* indexes[3] = { intrinsics->constantZero, intrinsics->constantZero, intrinsics->OffsetVTInClassConstant }; - Value* VTPtr = GetElementPtrInst::Create(val, indexes, indexes + 3, - "", CI); + Value* VTPtr = GetElementPtrInst::Create(val, indexes, "", CI); Value* VT = new LoadInst(VTPtr, "", CI); CI->replaceAllUsesWith(VT); CI->eraseFromParent(); @@ -255,8 +245,7 @@ Value* val = Call.getArgument(0); Value* indexes[2] = { intrinsics->constantZero, intrinsics->OffsetBaseClassVTInVTConstant }; - Value* VTPtr = GetElementPtrInst::Create(val, indexes, indexes + 2, - "", CI); + Value* VTPtr = GetElementPtrInst::Create(val, indexes, "", CI); Value* VT = new LoadInst(VTPtr, "", CI); VT = new BitCastInst(VT, intrinsics->VTType, "", CI); CI->replaceAllUsesWith(VT); @@ -267,8 +256,7 @@ Value* val = Call.getArgument(0); Value* indexes[2] = { intrinsics->constantZero, intrinsics->OffsetObjectSizeInClassConstant }; - Value* SizePtr = GetElementPtrInst::Create(val, indexes, indexes + 2, - "", CI); + Value* SizePtr = GetElementPtrInst::Create(val, indexes, "", CI); Value* Size = new LoadInst(SizePtr, "", CI); CI->replaceAllUsesWith(Size); CI->eraseFromParent(); @@ -277,8 +265,7 @@ Value* val = Call.getArgument(0); Value* indexes[2] = { intrinsics->constantZero, intrinsics->OffsetDepthInVTConstant }; - Value* DepthPtr = GetElementPtrInst::Create(val, indexes, - indexes + 2, "", CI); + Value* DepthPtr = GetElementPtrInst::Create(val, indexes, "", CI); Value* Depth = new LoadInst(DepthPtr, "", CI); Depth = new PtrToIntInst(Depth, Type::getInt32Ty(*Context), "", CI); CI->replaceAllUsesWith(Depth); @@ -288,8 +275,7 @@ Value* val = Call.getArgument(0); Value* indexes[2] = { intrinsics->constantZero, intrinsics->OffsetDisplayInVTConstant }; - Value* DisplayPtr = GetElementPtrInst::Create(val, indexes, - indexes + 2, "", CI); + Value* DisplayPtr = GetElementPtrInst::Create(val, indexes, "", CI); Type* Ty = PointerType::getUnqual(intrinsics->VTType); DisplayPtr = new BitCastInst(DisplayPtr, Ty, "", CI); CI->replaceAllUsesWith(DisplayPtr); @@ -345,8 +331,7 @@ Value* GEP[2] = { intrinsics->constantZero, intrinsics->OffsetInitializedInTaskClassMirrorConstant }; - Value* StatusPtr = GetElementPtrInst::Create(TCM, GEP, GEP + 2, "", - CI); + Value* StatusPtr = GetElementPtrInst::Create(TCM, GEP, "", CI); Value* test = new LoadInst(StatusPtr, "", CI); @@ -540,13 +525,11 @@ ConstantInt* CC = ConstantInt::get(Type::getInt32Ty(*Context), JavaVirtualTable::getOffsetIndex()); Value* indices[2] = { intrinsics->constantZero, CC }; - Value* Offset = GetElementPtrInst::Create(VT2, indices, indices + 2, - "", CI); + Value* Offset = GetElementPtrInst::Create(VT2, indices, "", CI); Offset = new LoadInst(Offset, "", false, CI); Offset = new PtrToIntInst(Offset, Type::getInt32Ty(*Context), "", CI); indices[1] = Offset; - Value* CurVT = GetElementPtrInst::Create(VT1, indices, indices + 2, - "", CI); + Value* CurVT = GetElementPtrInst::Create(VT1, indices, "", CI); CurVT = new LoadInst(CurVT, "", false, CI); CurVT = new BitCastInst(CurVT, intrinsics->VTType, "", CI); @@ -599,8 +582,7 @@ ConstantInt* cacheIndex = ConstantInt::get(Type::getInt32Ty(*Context), JavaVirtualTable::getCacheIndex()); Value* indices[2] = { intrinsics->constantZero, cacheIndex }; - Instruction* CachePtr = - GetElementPtrInst::Create(VT1, indices, indices + 2, "", CI); + Instruction* CachePtr = GetElementPtrInst::Create(VT1, indices, "", CI); CachePtr = new BitCastInst(CachePtr, Ty, "", CI); Value* Cache = new LoadInst(CachePtr, "", false, CI); ICmpInst* cmp1 = new ICmpInst(CI, ICmpInst::ICMP_EQ, Cache, VT2, ""); @@ -618,9 +600,7 @@ ConstantInt* sizeIndex = ConstantInt::get(Type::getInt32Ty(*Context), JavaVirtualTable::getNumSecondaryTypesIndex()); indices[1] = sizeIndex; - Instruction* Size = GetElementPtrInst::Create(VT1, indices, - indices + 2, "", - Preheader); + Instruction* Size = GetElementPtrInst::Create(VT1, indices, "", Preheader); Size = new LoadInst(Size, "", false, Preheader); Size = new PtrToIntInst(Size, Type::getInt32Ty(*Context), "", Preheader); @@ -628,7 +608,7 @@ JavaVirtualTable::getSecondaryTypesIndex()); indices[1] = secondaryTypesIndex; Instruction* secondaryTypes = - GetElementPtrInst::Create(VT1, indices, indices + 2, "", Preheader); + GetElementPtrInst::Create(VT1, indices, "", Preheader); secondaryTypes = new LoadInst(secondaryTypes, "", false, Preheader); secondaryTypes = new BitCastInst(secondaryTypes, Ty, "", Preheader); BranchInst::Create(BB7, Preheader); From nicolas.geoffray at lip6.fr Wed Jul 27 15:00:55 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Wed, 27 Jul 2011 22:00:55 -0000 Subject: [vmkit-commits] [vmkit] r136276 - /vmkit/trunk/lib/J3/VMCore/Precompiled.cpp Message-ID: <20110727220055.619EC2A6C12C@llvm.org> Author: geoffray Date: Wed Jul 27 17:00:55 2011 New Revision: 136276 URL: http://llvm.org/viewvc/llvm-project?rev=136276&view=rev Log: No need to call setNativeTracer. Modified: vmkit/trunk/lib/J3/VMCore/Precompiled.cpp Modified: vmkit/trunk/lib/J3/VMCore/Precompiled.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Precompiled.cpp?rev=136276&r1=136275&r2=136276&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/Precompiled.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/Precompiled.cpp Wed Jul 27 17:00:55 2011 @@ -147,7 +147,6 @@ // staticMethods and staticFields fields here. realCl->staticMethods = realCl->virtualMethods + realCl->nbVirtualMethods; realCl->staticFields = realCl->virtualFields + realCl->nbVirtualFields; - cl->virtualVT->setNativeTracer(cl->virtualVT->tracer, ""); for (uint32 i = 0; i< realCl->nbStaticMethods; ++i) { JavaMethod& meth = realCl->staticMethods[i]; From nicolas.geoffray at lip6.fr Fri Jul 29 09:44:36 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Fri, 29 Jul 2011 16:44:36 -0000 Subject: [vmkit-commits] [vmkit] r136466 - in /vmkit/trunk: include/mvm/UTF8.h lib/J3/VMCore/JnjvmClassLoader.cpp lib/J3/VMCore/LockedMap.cpp lib/J3/VMCore/LockedMap.h Message-ID: <20110729164437.08F3E2A6C12C@llvm.org> Author: geoffray Date: Fri Jul 29 11:44:36 2011 New Revision: 136466 URL: http://llvm.org/viewvc/llvm-project?rev=136466&view=rev Log: Clean up LockedMap, and use DenseMap as much as possible. Modified: vmkit/trunk/include/mvm/UTF8.h vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp vmkit/trunk/lib/J3/VMCore/LockedMap.cpp vmkit/trunk/lib/J3/VMCore/LockedMap.h Modified: vmkit/trunk/include/mvm/UTF8.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/UTF8.h?rev=136466&r1=136465&r2=136466&view=diff ============================================================================== --- vmkit/trunk/include/mvm/UTF8.h (original) +++ vmkit/trunk/include/mvm/UTF8.h Fri Jul 29 11:44:36 2011 @@ -19,10 +19,6 @@ return allocator.Allocate(sizeof(UTF8) + (n - 1) * sizeof(uint16), "UTF8"); } - UTF8(sint32 n) { - size = n; - } - public: /// size - The (constant) size of the array. ssize_t size; @@ -63,7 +59,10 @@ uint32_t hash() const { return readerHasher(elements, size); } - + + UTF8(sint32 n) { + size = n; + } }; Modified: vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp?rev=136466&r1=136465&r2=136466&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp Fri Jul 29 11:44:36 2011 @@ -551,7 +551,10 @@ } UserCommonClass* JnjvmClassLoader::lookupClass(const UTF8* utf8) { - return classes->lookup(utf8); + classes->lock.lock(); + UserCommonClass* cl = classes->map.lookup(utf8); + classes->lock.unlock(); + return cl; } UserCommonClass* JnjvmClassLoader::loadBaseClass(const UTF8* name, @@ -604,12 +607,9 @@ UserClass* res = NULL; lock.lock(); classes->lock.lock(); - ClassMap::iterator End = classes->map.end(); - ClassMap::iterator I = classes->map.find(name); + res = (UserClass*) classes->map.lookup(name); classes->lock.unlock(); - if (I != End) { - res = ((UserClass*)(I->second)); - } else { + if (res == NULL) { TRY { const UTF8* internalName = readerConstructUTF8(name->elements, name->size); res = new(allocator, "Class") UserClass(this, internalName, bytes); @@ -620,18 +620,18 @@ classes->lock.lock(); assert(res->getDelegatee() == NULL); assert(res->getStaticInstance() == NULL); - bool success = classes->map.insert(std::make_pair(internalName, res)).second; + assert(classes->map.lookup(internalName) == NULL); + classes->map[internalName] = res; classes->lock.unlock(); - assert(success && "Could not add class in map"); } CATCH { excp = JavaThread::get()->pendingException; JavaThread::get()->clearException(); } END_CATCH; } + lock.unlock(); if (excp != NULL) { JavaThread::get()->throwException(excp); } - lock.unlock(); if (res->super == NULL) { // java.lang.Object just got created, initialise VTs of arrays. @@ -645,17 +645,14 @@ assert(baseClass && "constructing an array class without a base class"); assert(baseClass->classLoader == this && "constructing an array with wrong loader"); - classes->lock.lock(); - ClassMap::iterator End = classes->map.end(); - ClassMap::iterator I = classes->map.find(name); UserClassArray* res = 0; - if (I == End) { + classes->lock.lock(); + res = (UserClassArray*) classes->map.lookup(name); + if (res == NULL) { const UTF8* internalName = readerConstructUTF8(name->elements, name->size); res = new(allocator, "Array class") UserClassArray(this, internalName, baseClass); classes->map.insert(std::make_pair(internalName, res)); - } else { - res = ((UserClassArray*)(I->second)); } classes->lock.unlock(); return res; @@ -686,10 +683,10 @@ Typedef* JnjvmClassLoader::constructType(const UTF8* name) { javaTypes->lock.lock(); - Typedef* res = javaTypes->lookup(name); + Typedef* res = javaTypes->map.lookup(name); if (res == 0) { res = internalConstructType(name); - javaTypes->hash(name, res); + javaTypes->map[name] = res; } javaTypes->lock.unlock(); return res; @@ -762,7 +759,7 @@ Signdef* JnjvmClassLoader::constructSign(const UTF8* name) { javaSignatures->lock.lock(); - Signdef* res = javaSignatures->lookup(name); + Signdef* res = javaSignatures->map.lookup(name); if (res == 0) { std::vector buf; uint32 len = (uint32)name->size; @@ -792,7 +789,7 @@ res = new(allocator, buf.size()) Signdef(name, this, buf, ret); - javaSignatures->hash(name, res); + javaSignatures->map[name] = res; } javaSignatures->lock.unlock(); return res; Modified: vmkit/trunk/lib/J3/VMCore/LockedMap.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/LockedMap.cpp?rev=136466&r1=136465&r2=136466&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/LockedMap.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/LockedMap.cpp Fri Jul 29 11:44:36 2011 @@ -15,10 +15,6 @@ using namespace j3; -bool ltutf8::operator()(const UTF8* s1, const UTF8* s2) const { - return s1->lessThan(s2); -} - bool ltarray16::operator()(const ArrayUInt16* s1, const ArrayUInt16* s2) const { llvm_gcroot(s1, 0); llvm_gcroot(s2, 0); Modified: vmkit/trunk/lib/J3/VMCore/LockedMap.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/LockedMap.h?rev=136466&r1=136465&r2=136466&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/LockedMap.h (original) +++ vmkit/trunk/lib/J3/VMCore/LockedMap.h Fri Jul 29 11:44:36 2011 @@ -16,6 +16,8 @@ #ifndef JNJVM_LOCKED_MAP_H #define JNJVM_LOCKED_MAP_H +#include "llvm/ADT/DenseMap.h" + #include #include @@ -26,10 +28,28 @@ #include "mvm/Threads/Locks.h" #include "UTF8.h" -#include "JavaArray.h" // for comparing UTF8s +namespace llvm { +// Provide DenseMapInfo for UTF8. +template<> +struct DenseMapInfo { + static inline const j3::UTF8* getEmptyKey() { + static j3::UTF8 emptyKey(0); + return &emptyKey; + } + static inline const j3::UTF8* getTombstoneKey() { + static j3::UTF8 tombstoneKey(0); + return &tombstoneKey; + } + static unsigned getHashValue(const j3::UTF8* PtrVal) { + return PtrVal->hash(); + } + static bool isEqual(const j3::UTF8* LHS, const j3::UTF8* RHS) { return LHS->equals(RHS); } +}; +} namespace j3 { +class ArrayUInt16; class JavaString; class JnjvmClassLoader; class Signdef; @@ -37,155 +57,95 @@ class UserCommonClass; class UserClassArray; -struct ltutf8 { - bool operator()(const UTF8* s1, const UTF8* s2) const; -}; - struct ltarray16 { bool operator()(const ArrayUInt16* s1, const ArrayUInt16* s2) const; }; -class MapNoGC { +class StringMap : public mvm::PermanentObject { public: - static void gcroot(void* val, void* unused) - __attribute__ ((always_inline)) {} - -}; - -class MapWithGC { -public: - static void gcroot(void* val, void* unused) - __attribute__ ((always_inline)) { - llvm_gcroot(val, unused); - } - -}; - + typedef std::map::iterator iterator; + typedef JavaString* (*funcCreate)(const ArrayUInt16*& V, Jnjvm* vm); -template -class LockedMap : public mvm::PermanentObject { -public: - typedef typename std::map::iterator iterator; - typedef Container (*funcCreate)(Key& V, Meta meta); - - TLock lock; - std::map > > map; + mvm::LockNormal lock; + std::map > > map; - inline Container lookupOrCreate(Key& V, Meta meta, funcCreate func) { - Container res = 0; - IsGC::gcroot(res, 0); - IsGC::gcroot((void*)V, 0); + inline JavaString* lookupOrCreate(const ArrayUInt16* array, Jnjvm* vm, funcCreate func) { + JavaString* res = 0; + llvm_gcroot(res, 0); + llvm_gcroot(array, 0); lock.lock(); iterator End = map.end(); - iterator I = map.find(V); + iterator I = map.find(array); if (I == End) { - res = func(V, meta); - map.insert(std::make_pair(V, res)); + res = func(array, vm); + map.insert(std::make_pair(array, res)); lock.unlock(); return res; } else { lock.unlock(); - return ((Container)(I->second)); + return ((JavaString*)(I->second)); } } - inline void remove(Key V) { - IsGC::gcroot(V, 0); - lock.lock(); - map.erase(V); - lock.unlock(); - } - - inline void remove(Key V, Container C) { - IsGC::gcroot(C, 0); - IsGC::gcroot(V, 0); + inline void remove(const ArrayUInt16* array) { + llvm_gcroot(array, 0); lock.lock(); - removeUnlocked(V, C); + map.erase(array); lock.unlock(); } - inline void removeUnlocked(Key V, Container C) { - IsGC::gcroot(C, 0); - IsGC::gcroot((void*)V, 0); - iterator End = map.end(); - iterator I = map.find(V); - - if (I != End && I->second == C) - map.erase(I); - } - - inline Container lookup(Key V) { - IsGC::gcroot((void*)V, 0); + inline JavaString* lookup(const ArrayUInt16* array) { + llvm_gcroot(array, 0); lock.lock(); iterator End = map.end(); - iterator I = map.find(V); + iterator I = map.find(array); lock.unlock(); - return I != End ? ((Container)(I->second)) : 0; + return I != End ? ((JavaString*)(I->second)) : 0; } - inline void hash(Key k, Container c) { - IsGC::gcroot(c, 0); - IsGC::gcroot(k, 0); + inline void hash(const ArrayUInt16* array, JavaString* str) { + llvm_gcroot(array, 0); + llvm_gcroot(str, 0); lock.lock(); - map.insert(std::make_pair(k, c)); + map.insert(std::make_pair(array, str)); lock.unlock(); } - ~LockedMap() {} -}; + inline void removeUnlocked(const ArrayUInt16* array, JavaString* str) { + llvm_gcroot(str, 0); + llvm_gcroot(array, 0); + iterator End = map.end(); + iterator I = map.find(array); + + if (I != End && I->second == str) map.erase(I); + } -class ClassMap : - public LockedMap { + ~StringMap() {} + void insert(JavaString* str); }; -class StringMap : - public LockedMap { +class ClassMap : public mvm::PermanentObject { public: - void insert(JavaString* str); - + mvm::LockRecursive lock; + llvm::DenseMap map; + typedef llvm::DenseMap::iterator iterator; }; class TypeMap : public mvm::PermanentObject { public: mvm::LockNormal lock; - - std::map map; - typedef std::map::iterator iterator; - - inline Typedef* lookup(const UTF8* V) { - iterator End = map.end(); - iterator I = map.find(V); - return I != End ? I->second : 0; - } - - inline void hash(const UTF8* k, Typedef* c) { - map.insert(std::make_pair(k, c)); - } + llvm::DenseMap map; + typedef llvm::DenseMap::iterator iterator; }; class SignMap : public mvm::PermanentObject { public: mvm::LockNormal lock; - - std::map map; - typedef std::map::iterator iterator; - - inline Signdef* lookup(const UTF8* V) { - iterator End = map.end(); - iterator I = map.find(V); - return I != End ? I->second : 0; - } - - inline void hash(const UTF8* k, Signdef* c) { - map.insert(std::make_pair(k, c)); - } - + llvm::DenseMap map; + typedef llvm::DenseMap::iterator iterator; }; } // end namespace j3 From nicolas.geoffray at lip6.fr Sun Jul 31 03:54:50 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 31 Jul 2011 10:54:50 -0000 Subject: [vmkit-commits] [vmkit] r136592 - in /vmkit/trunk: include/j3/J3Intrinsics.h include/j3/JavaAOTCompiler.h lib/J3/Compiler/J3Intrinsics.cpp lib/J3/Compiler/JavaAOTCompiler.cpp lib/J3/LLVMRuntime/runtime-default.ll lib/J3/VMCore/JnjvmClassLoader.cpp lib/J3/VMCore/JnjvmClassLoader.h lib/J3/VMCore/LockedMap.cpp lib/J3/VMCore/LockedMap.h lib/J3/VMCore/Precompiled.cpp mmtk/mmtk-j3/Memory.cpp Message-ID: <20110731105450.595C02A6C12C@llvm.org> Author: geoffray Date: Sun Jul 31 05:54:50 2011 New Revision: 136592 URL: http://llvm.org/viewvc/llvm-project?rev=136592&view=rev Log: Precompile the class map. Modified: vmkit/trunk/include/j3/J3Intrinsics.h vmkit/trunk/include/j3/JavaAOTCompiler.h vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp vmkit/trunk/lib/J3/LLVMRuntime/runtime-default.ll vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h vmkit/trunk/lib/J3/VMCore/LockedMap.cpp vmkit/trunk/lib/J3/VMCore/LockedMap.h vmkit/trunk/lib/J3/VMCore/Precompiled.cpp vmkit/trunk/mmtk/mmtk-j3/Memory.cpp Modified: vmkit/trunk/include/j3/J3Intrinsics.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/J3Intrinsics.h?rev=136592&r1=136591&r2=136592&view=diff ============================================================================== --- vmkit/trunk/include/j3/J3Intrinsics.h (original) +++ vmkit/trunk/include/j3/J3Intrinsics.h Sun Jul 31 05:54:50 2011 @@ -45,6 +45,7 @@ llvm::Type* AttributType; llvm::Type* JavaThreadType; llvm::Type* MutatorThreadType; + llvm::Type* J3DenseMapType; llvm::Function* StartJNIFunction; llvm::Function* EndJNIFunction; Modified: vmkit/trunk/include/j3/JavaAOTCompiler.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/JavaAOTCompiler.h?rev=136592&r1=136591&r2=136592&view=diff ============================================================================== --- vmkit/trunk/include/j3/JavaAOTCompiler.h (original) +++ vmkit/trunk/include/j3/JavaAOTCompiler.h Sun Jul 31 05:54:50 2011 @@ -11,6 +11,7 @@ #define J3_AOT_COMPILER_H #include "j3/JavaLLVMCompiler.h" +#include "j3/J3DenseMap.h" namespace j3 { @@ -58,7 +59,7 @@ llvm::Constant* HandleMagic(JavaObject* obj, CommonClass* cl); virtual llvm::Constant* getFinalObject(JavaObject* obj, CommonClass* cl); virtual JavaObject* getFinalObject(llvm::Value* C); - virtual llvm::Constant* getNativeClass(CommonClass* cl); + virtual llvm::GlobalVariable* getNativeClass(CommonClass* cl); virtual llvm::Constant* getClassBytes(const UTF8* name, ClassBytes* bytes); virtual llvm::Constant* getJavaClass(CommonClass* cl); virtual llvm::Constant* getJavaClassPtr(CommonClass* cl); @@ -99,6 +100,7 @@ llvm::Constant* CreateConstantFromJavaObject(JavaObject* obj); llvm::Constant* CreateConstantFromClassBytes(ClassBytes* bytes); llvm::Constant* CreateConstantFromJavaConstantPool(JavaConstantPool* ctp); + llvm::Constant* CreateConstantFromClassMap(const J3DenseMap& map); void AddInitializerToClass(llvm::GlobalVariable* varGV, CommonClass* classDef); llvm::Constant* getUTF8(const UTF8* val); Modified: vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp?rev=136592&r1=136591&r2=136592&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp Sun Jul 31 05:54:50 2011 @@ -97,6 +97,10 @@ CodeLineInfoType = PointerType::getUnqual(module->getTypeByName("CodeLineInfo")); + J3DenseMapType = + PointerType::getUnqual(module->getTypeByName("J3DenseMap")); + + JavaObjectNullConstant = Constant::getNullValue(J3Intrinsics::JavaObjectType); MaxArraySizeConstant = ConstantInt::get(Type::getInt32Ty(Context), Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=136592&r1=136591&r2=136592&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Sun Jul 31 05:54:50 2011 @@ -64,7 +64,7 @@ } } -Constant* JavaAOTCompiler::getNativeClass(CommonClass* classDef) { +GlobalVariable* JavaAOTCompiler::getNativeClass(CommonClass* classDef) { if (classDef->isClass() || isCompiling(classDef) || assumeCompiled) { @@ -88,7 +88,7 @@ nativeClasses.insert(std::make_pair(classDef, varGV)); - if (!precompile) { + if (!precompile || classDef->isPrimitive()) { AddInitializerToClass(varGV, classDef); } @@ -916,11 +916,7 @@ CommonClassElts.push_back(Constant::getNullValue(TempTy)); } - // classLoader: store the static initializer, it will be overriden once - // the class is loaded. - Constant* loader = ConstantExpr::getBitCast(StaticInitializer, - JavaIntrinsics.ptrType); - CommonClassElts.push_back(loader); + CommonClassElts.push_back(Constant::getNullValue(JavaIntrinsics.ptrType)); // virtualTable if (cl->virtualVT) { @@ -1103,6 +1099,59 @@ return ConstantStruct::get(STy, ClassElts); } +Constant* JavaAOTCompiler::CreateConstantFromClassMap(const J3DenseMap& map) { + StructType* STy = + dyn_cast(JavaIntrinsics.J3DenseMapType->getContainedType(0)); + Module& Mod = *getLLVMModule(); + + std::vector elements; + elements.push_back(ConstantInt::get(Type::getInt32Ty(getLLVMContext()), map.NumBuckets)); + + Constant* buckets; + if (map.NumBuckets > 0) { + std::vector TempElts; + ArrayType* ATy = ArrayType::get(JavaIntrinsics.ptrType, map.NumBuckets * 2); + + for (uint32 i = 0; i < map.NumBuckets; ++i) { + J3Pair pair = map.Buckets[i]; + if (pair.first == &TombstoneKey) { + static GlobalVariable* gv = + new GlobalVariable(Mod, JavaIntrinsics.UTF8Type->getContainedType(0), + false, GlobalValue::ExternalLinkage, NULL, + "TombstoneKey"); + TempElts.push_back(ConstantExpr::getCast(Instruction::BitCast, gv, JavaIntrinsics.ptrType)); + TempElts.push_back(Constant::getNullValue(JavaIntrinsics.ptrType)); + } else if (pair.first == &EmptyKey) { + static GlobalVariable* gv = + new GlobalVariable(Mod, JavaIntrinsics.UTF8Type->getContainedType(0), + false, GlobalValue::ExternalLinkage, NULL, + "EmptyKey"); + TempElts.push_back(ConstantExpr::getCast(Instruction::BitCast, gv, JavaIntrinsics.ptrType)); + TempElts.push_back(Constant::getNullValue(JavaIntrinsics.ptrType)); + } else { + TempElts.push_back(ConstantExpr::getCast(Instruction::BitCast, getUTF8(pair.first), JavaIntrinsics.ptrType)); + TempElts.push_back(ConstantExpr::getCast(Instruction::BitCast, getNativeClass(pair.second), JavaIntrinsics.ptrType)); + } + } + + buckets = ConstantArray::get(ATy, TempElts); + + GlobalVariable* gv = new GlobalVariable(Mod, ATy, false, GlobalValue::InternalLinkage, buckets, ""); + buckets = ConstantExpr::getCast(Instruction::BitCast, gv, JavaIntrinsics.ptrType); + } else { + buckets = Constant::getNullValue(JavaIntrinsics.ptrType); + } + + elements.push_back(buckets); + elements.push_back(ConstantInt::get(Type::getInt32Ty(getLLVMContext()), map.NumEntries)); + elements.push_back(ConstantInt::get(Type::getInt32Ty(getLLVMContext()), map.NumTombstones)); + elements.push_back(ConstantInt::get(Type::getInt1Ty(getLLVMContext()), 1)); + + return new GlobalVariable(Mod, STy, false, + GlobalValue::ExternalLinkage, + ConstantStruct::get(STy, elements), "ClassMap"); +} + Constant* JavaAOTCompiler::CreateConstantFromClass(Class* cl) { StructType* STy = dyn_cast(JavaIntrinsics.JavaClassType->getContainedType(0)); @@ -1145,25 +1194,20 @@ // virtualFields if (cl->nbVirtualFields) { - for (uint32 i = 0; i < cl->nbVirtualFields; ++i) { TempElts.push_back(CreateConstantFromJavaField(cl->virtualFields[i])); } - } // staticFields if (cl->nbStaticFields) { - for (uint32 i = 0; i < cl->nbStaticFields; ++i) { TempElts.push_back(CreateConstantFromJavaField(cl->staticFields[i])); } - } Constant* fields = 0; if (cl->nbStaticFields + cl->nbVirtualFields) { - fields = ConstantArray::get(ATy, TempElts); TempElts.clear(); fields = new GlobalVariable(Mod, ATy, false, @@ -1744,15 +1788,8 @@ precompile = false; std::vector llvmArgs; - llvmArgs.push_back(JavaIntrinsics.ptrType); // class loader. - FunctionType* FTy = FunctionType::get(Type::getVoidTy(getLLVMContext()), - llvmArgs, false); - - StaticInitializer = Function::Create(FTy, GlobalValue::InternalLinkage, - "Init", getLLVMModule()); - - llvmArgs.clear(); - FTy = FunctionType::get(Type::getVoidTy(getLLVMContext()), llvmArgs, false); + FunctionType* FTy = FunctionType::get( + Type::getVoidTy(getLLVMContext()), llvmArgs, false); Callback = Function::Create(FTy, GlobalValue::ExternalLinkage, "staticCallback", getLLVMModule()); @@ -1826,6 +1863,13 @@ Function* AddClass = Function::Create(FTy, GlobalValue::ExternalLinkage, "vmjcAddPreCompiledClass", getLLVMModule()); + + llvmArgs.clear(); + llvmArgs.push_back(JavaIntrinsics.ptrType); // class loader. + FTy = FunctionType::get(Type::getVoidTy(getLLVMContext()), llvmArgs, false); + + StaticInitializer = Function::Create(FTy, GlobalValue::InternalLinkage, + "Init", getLLVMModule()); llvmArgs.clear(); // class loader @@ -2219,11 +2263,15 @@ getNativeClass(loader->upcalls->OfLong); getNativeClass(loader->upcalls->OfDouble); - // First set classes that have been more than resolved to resolved. + // First set all classes to resolved. for (ClassMap::iterator i = loader->getClasses()->map.begin(), e = loader->getClasses()->map.end(); i!= e; ++i) { - if (i->second->isClass() && i->second->asClass()->isResolved()) { - i->second->asClass()->setResolved(); + if (i->second->isClass()) { + if (i->second->asClass()->isResolved()) { + i->second->asClass()->setResolved(); + } else { + i->second->asClass()->resolveClass(); + } } } @@ -2263,17 +2311,12 @@ meth->code = Func; } - bool changed = false; - do { - changed = false; - for (native_class_iterator i = nativeClasses.begin(), - e = nativeClasses.end(); i != e; ++i) { - if (!i->second->hasInitializer()) { - changed = true; - AddInitializerToClass(i->second, i->first); - } - } - } while (changed); + // Add all class initializers. + for (ClassMap::iterator i = loader->getClasses()->map.begin(), + e = loader->getClasses()->map.end(); i!= e; ++i) { + GlobalVariable* gv = getNativeClass(i->second); + AddInitializerToClass(gv, i->second); + } // Add the bootstrap classes to the image. for (std::vector::iterator i = loader->bootArchives.begin(), @@ -2320,7 +2363,8 @@ loader->constructSign(loader->asciizConstructUTF8("([Ljava/lang/String;)V")); getSignatureInfo(mainSignature)->getStaticBuf(); - CreateStaticInitializer(); + // Emit the class map. + CreateConstantFromClassMap(loader->classes->map); } /// compileAllStubs - Compile all the native -> Java stubs. Modified: vmkit/trunk/lib/J3/LLVMRuntime/runtime-default.ll URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/LLVMRuntime/runtime-default.ll?rev=136592&r1=136591&r2=136592&view=diff ============================================================================== --- vmkit/trunk/lib/J3/LLVMRuntime/runtime-default.ll (original) +++ vmkit/trunk/lib/J3/LLVMRuntime/runtime-default.ll Sun Jul 31 05:54:50 2011 @@ -63,6 +63,8 @@ %JavaClassPrimitive = type { %JavaCommonClass, i32 } %JavaClassArray = type { %JavaCommonClass, %JavaCommonClass* } +%J3DenseMap = type { i32, i8*, i32, i32, i1 } + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;; Make sure all named types are emitted ;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -91,7 +93,8 @@ %Attribut, %JavaThread, %MutatorThread, - %CodeLineInfo); + %CodeLineInfo, + %J3DenseMap); ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;; Constant calls for J3 runtime internal objects field accesses ;;;;;;;;; Modified: vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp?rev=136592&r1=136591&r2=136592&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp Sun Jul 31 05:54:50 2011 @@ -66,7 +66,6 @@ TheCompiler = Comp; hashUTF8 = new(allocator, "UTF8Map") UTF8Map(allocator); - classes = new(allocator, "ClassMap") ClassMap(); javaTypes = new(allocator, "TypeMap") TypeMap(); javaSignatures = new(allocator, "SignMap") SignMap(); strings = new(allocator, "StringList") StringList(); @@ -84,6 +83,7 @@ } if (!bootLoaded) { + classes = new(allocator, "ClassMap") ClassMap(); // Analyze the boot classpath, we know bootstrap classes are not in the // executable. analyseClasspathEnv(bootClasspathEnv); Modified: vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h?rev=136592&r1=136591&r2=136592&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h (original) +++ vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h Sun Jul 31 05:54:50 2011 @@ -418,6 +418,7 @@ friend class ClArgumentsInfo; friend class JavaAOTCompiler; + friend class Precompiled; }; Modified: vmkit/trunk/lib/J3/VMCore/LockedMap.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/LockedMap.cpp?rev=136592&r1=136591&r2=136592&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/LockedMap.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/LockedMap.cpp Sun Jul 31 05:54:50 2011 @@ -13,7 +13,10 @@ #include "JavaString.h" #include "LockedMap.h" -using namespace j3; +namespace j3 { + +extern "C" const UTF8 TombstoneKey(0); +extern "C" const UTF8 EmptyKey(0); bool ltarray16::operator()(const ArrayUInt16* s1, const ArrayUInt16* s2) const { llvm_gcroot(s1, 0); @@ -36,3 +39,5 @@ assert(&(map.find(array)->second) == &(it->second)); assert(&(map.find(array)->first) == &(it->first)); } + +} Modified: vmkit/trunk/lib/J3/VMCore/LockedMap.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/LockedMap.h?rev=136592&r1=136591&r2=136592&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/LockedMap.h (original) +++ vmkit/trunk/lib/J3/VMCore/LockedMap.h Sun Jul 31 05:54:50 2011 @@ -16,7 +16,7 @@ #ifndef JNJVM_LOCKED_MAP_H #define JNJVM_LOCKED_MAP_H -#include "llvm/ADT/DenseMap.h" +#include "j3/J3DenseMap.h" #include @@ -28,26 +28,26 @@ #include "mvm/Threads/Locks.h" #include "UTF8.h" -namespace llvm { -// Provide DenseMapInfo for UTF8. +extern "C" const j3::UTF8 TombstoneKey; +extern "C" const j3::UTF8 EmptyKey; + +namespace j3 { + +// Provide J3DenseMapInfo for UTF8. template<> -struct DenseMapInfo { +struct J3DenseMapInfo { static inline const j3::UTF8* getEmptyKey() { - static j3::UTF8 emptyKey(0); - return &emptyKey; + return &EmptyKey; } static inline const j3::UTF8* getTombstoneKey() { - static j3::UTF8 tombstoneKey(0); - return &tombstoneKey; + return &TombstoneKey; } static unsigned getHashValue(const j3::UTF8* PtrVal) { return PtrVal->hash(); } static bool isEqual(const j3::UTF8* LHS, const j3::UTF8* RHS) { return LHS->equals(RHS); } }; -} -namespace j3 { class ArrayUInt16; class JavaString; @@ -129,23 +129,26 @@ class ClassMap : public mvm::PermanentObject { public: + ClassMap() {} + ClassMap(J3DenseMap* precompiled) : map(*precompiled) {} + mvm::LockRecursive lock; - llvm::DenseMap map; - typedef llvm::DenseMap::iterator iterator; + J3DenseMap map; + typedef J3DenseMap::iterator iterator; }; class TypeMap : public mvm::PermanentObject { public: mvm::LockNormal lock; - llvm::DenseMap map; - typedef llvm::DenseMap::iterator iterator; + J3DenseMap map; + typedef J3DenseMap::iterator iterator; }; class SignMap : public mvm::PermanentObject { public: mvm::LockNormal lock; - llvm::DenseMap map; - typedef llvm::DenseMap::iterator iterator; + J3DenseMap map; + typedef J3DenseMap::iterator iterator; }; } // end namespace j3 Modified: vmkit/trunk/lib/J3/VMCore/Precompiled.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Precompiled.cpp?rev=136592&r1=136591&r2=136592&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/Precompiled.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/Precompiled.cpp Sun Jul 31 05:54:50 2011 @@ -30,54 +30,6 @@ typedef void (*static_init_t)(JnjvmClassLoader*); -bool Precompiled::Init(JnjvmBootstrapLoader* loader) { - Class* javaLangObject = (Class*)dlsym(SELF_HANDLE, "java_lang_Object"); - void* nativeHandle = SELF_HANDLE; - if (javaLangObject == NULL) { - void* handle = dlopen("libvmjc"DYLD_EXTENSION, RTLD_LAZY | RTLD_GLOBAL); - if (handle != NULL) { - nativeHandle = handle; - javaLangObject = (Class*)dlsym(nativeHandle, "java_lang_Object"); - } - } - - if (javaLangObject == NULL) { - return false; - } - - ClassArray::SuperArray = javaLangObject; - - // Get the native classes. - Classpath* upcalls = loader->upcalls; - upcalls->OfVoid = (ClassPrimitive*)dlsym(nativeHandle, "void"); - upcalls->OfBool = (ClassPrimitive*)dlsym(nativeHandle, "boolean"); - upcalls->OfByte = (ClassPrimitive*)dlsym(nativeHandle, "byte"); - upcalls->OfChar = (ClassPrimitive*)dlsym(nativeHandle, "char"); - upcalls->OfShort = (ClassPrimitive*)dlsym(nativeHandle, "short"); - upcalls->OfInt = (ClassPrimitive*)dlsym(nativeHandle, "int"); - upcalls->OfFloat = (ClassPrimitive*)dlsym(nativeHandle, "float"); - upcalls->OfLong = (ClassPrimitive*)dlsym(nativeHandle, "long"); - upcalls->OfDouble = (ClassPrimitive*)dlsym(nativeHandle, "double"); - - // We have the java/lang/Object class, execute the static initializer. - static_init_t init = (static_init_t)(uintptr_t)javaLangObject->classLoader; - assert(init && "Loaded the wrong boot library"); - init(loader); - - // Get the base object arrays after the init, because init puts arrays - // in the class loader map. - upcalls->ArrayOfString = - loader->constructArray(loader->asciizConstructUTF8("[Ljava/lang/String;")); - - upcalls->ArrayOfObject = - loader->constructArray(loader->asciizConstructUTF8("[Ljava/lang/Object;")); - - ClassArray::InterfacesArray = upcalls->ArrayOfObject->interfaces; - - return true; -} - - void JnjvmClassLoader::insertAllMethodsInVM(Jnjvm* vm) { UNIMPLEMENTED(); } @@ -172,10 +124,6 @@ JCL->hashUTF8->insert(field.type); } } - - if (!cl->isPrimitive()) { - JCL->getClasses()->map.insert(std::make_pair(cl->name, cl)); - } } @@ -370,4 +318,63 @@ } } +bool Precompiled::Init(JnjvmBootstrapLoader* loader) { + Class* javaLangObject = (Class*)dlsym(SELF_HANDLE, "java_lang_Object"); + void* nativeHandle = SELF_HANDLE; + if (javaLangObject == NULL) { + void* handle = dlopen("libvmjc"DYLD_EXTENSION, RTLD_LAZY | RTLD_GLOBAL); + if (handle != NULL) { + nativeHandle = handle; + javaLangObject = (Class*)dlsym(nativeHandle, "java_lang_Object"); + } + } + + if (javaLangObject == NULL) { + return false; + } + + ClassArray::SuperArray = javaLangObject; + + // Get the native classes. + Classpath* upcalls = loader->upcalls; + upcalls->OfVoid = (ClassPrimitive*)dlsym(nativeHandle, "void"); + upcalls->OfBool = (ClassPrimitive*)dlsym(nativeHandle, "boolean"); + upcalls->OfByte = (ClassPrimitive*)dlsym(nativeHandle, "byte"); + upcalls->OfChar = (ClassPrimitive*)dlsym(nativeHandle, "char"); + upcalls->OfShort = (ClassPrimitive*)dlsym(nativeHandle, "short"); + upcalls->OfInt = (ClassPrimitive*)dlsym(nativeHandle, "int"); + upcalls->OfFloat = (ClassPrimitive*)dlsym(nativeHandle, "float"); + upcalls->OfLong = (ClassPrimitive*)dlsym(nativeHandle, "long"); + upcalls->OfDouble = (ClassPrimitive*)dlsym(nativeHandle, "double"); + upcalls->OfVoid->classLoader = loader; + upcalls->OfBool->classLoader = loader; + upcalls->OfByte->classLoader = loader; + upcalls->OfChar->classLoader = loader; + upcalls->OfShort->classLoader = loader; + upcalls->OfInt->classLoader = loader; + upcalls->OfFloat->classLoader = loader; + upcalls->OfLong->classLoader = loader; + upcalls->OfDouble->classLoader = loader; + + J3DenseMap* precompiledClassMap = + reinterpret_cast*>(dlsym(nativeHandle, "ClassMap")); + loader->classes = new (loader->allocator, "ClassMap") ClassMap(precompiledClassMap); + for (ClassMap::iterator i = loader->getClasses()->map.begin(), + e = loader->getClasses()->map.end(); i != e; i++) { + vmjcAddPreCompiledClass(loader, i->second); + } + + // Get the base object arrays after the init, because init puts arrays + // in the class loader map. + upcalls->ArrayOfString = + loader->constructArray(loader->asciizConstructUTF8("[Ljava/lang/String;")); + + upcalls->ArrayOfObject = + loader->constructArray(loader->asciizConstructUTF8("[Ljava/lang/Object;")); + + ClassArray::InterfacesArray = upcalls->ArrayOfObject->interfaces; + + return true; +} + } Modified: vmkit/trunk/mmtk/mmtk-j3/Memory.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/mmtk-j3/Memory.cpp?rev=136592&r1=136591&r2=136592&view=diff ============================================================================== --- vmkit/trunk/mmtk/mmtk-j3/Memory.cpp (original) +++ vmkit/trunk/mmtk/mmtk-j3/Memory.cpp Sun Jul 31 05:54:50 2011 @@ -21,7 +21,7 @@ static const uintptr_t MemoryStart = 0x50000000; #endif -static const uintptr_t MemorySize = 0x40000000; +static const uintptr_t MemorySize = 0x30000000; class InitCollector { public: From nicolas.geoffray at lip6.fr Sun Jul 31 08:48:38 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 31 Jul 2011 15:48:38 -0000 Subject: [vmkit-commits] [vmkit] r136593 - in /vmkit/trunk/lib/J3: Compiler/JavaAOTCompiler.cpp VMCore/Precompiled.cpp Message-ID: <20110731154838.AD3822A6C12C@llvm.org> Author: geoffray Date: Sun Jul 31 10:48:38 2011 New Revision: 136593 URL: http://llvm.org/viewvc/llvm-project?rev=136593&view=rev Log: Emit staticMethods and staticFields directly. There is no alignment when not using global variables. Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp vmkit/trunk/lib/J3/VMCore/Precompiled.cpp Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=136593&r1=136592&r2=136593&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Sun Jul 31 10:48:38 2011 @@ -1228,9 +1228,7 @@ ClassElts.push_back(nbVirtualFields); // staticFields - // Output null, getLLVMModule() will be set in the initializer. Otherwise, the - // assembly emitter of LLVM will try to align the data. - ClassElts.push_back(Constant::getNullValue(JavaIntrinsics.JavaFieldType)); + ClassElts.push_back(ConstantExpr::getGetElementPtr(fields, nbVirtualFields)); // nbStaticFields ClassElts.push_back(ConstantInt::get(Type::getInt16Ty(getLLVMContext()), cl->nbStaticFields)); @@ -1285,8 +1283,7 @@ ClassElts.push_back(nbVirtualMethods); // staticMethods - // Output null, getLLVMModule() will be set in the initializer. - ClassElts.push_back(Constant::getNullValue(JavaIntrinsics.JavaMethodType)); + ClassElts.push_back(ConstantExpr::getGetElementPtr(methods, nbVirtualMethods)); // nbStaticMethods ClassElts.push_back(ConstantInt::get(Type::getInt16Ty(getLLVMContext()), cl->nbStaticMethods)); Modified: vmkit/trunk/lib/J3/VMCore/Precompiled.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Precompiled.cpp?rev=136593&r1=136592&r2=136593&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/Precompiled.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/Precompiled.cpp Sun Jul 31 10:48:38 2011 @@ -95,10 +95,6 @@ if (cl->isClass()) { Class* realCl = cl->asClass(); - // To avoid data alignment in the llvm assembly emitter, we set the - // staticMethods and staticFields fields here. - realCl->staticMethods = realCl->virtualMethods + realCl->nbVirtualMethods; - realCl->staticFields = realCl->virtualFields + realCl->nbVirtualFields; for (uint32 i = 0; i< realCl->nbStaticMethods; ++i) { JavaMethod& meth = realCl->staticMethods[i]; From nicolas.geoffray at lip6.fr Sun Jul 31 09:56:00 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 31 Jul 2011 16:56:00 -0000 Subject: [vmkit-commits] [vmkit] r136594 - in /vmkit/trunk: include/j3/JavaAOTCompiler.h include/mvm/MvmDenseMap.h include/mvm/UTF8.h lib/J3/Compiler/JavaAOTCompiler.cpp lib/J3/VMCore/LockedMap.cpp lib/J3/VMCore/LockedMap.h lib/J3/VMCore/Precompiled.cpp lib/Mvm/Runtime/UTF8.cpp Message-ID: <20110731165600.680242A6C12C@llvm.org> Author: geoffray Date: Sun Jul 31 11:56:00 2011 New Revision: 136594 URL: http://llvm.org/viewvc/llvm-project?rev=136594&view=rev Log: Move j3::J3DenseMap to mvm::MvmDenseMap. Added: vmkit/trunk/include/mvm/MvmDenseMap.h Modified: vmkit/trunk/include/j3/JavaAOTCompiler.h vmkit/trunk/include/mvm/UTF8.h vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp vmkit/trunk/lib/J3/VMCore/LockedMap.cpp vmkit/trunk/lib/J3/VMCore/LockedMap.h vmkit/trunk/lib/J3/VMCore/Precompiled.cpp vmkit/trunk/lib/Mvm/Runtime/UTF8.cpp Modified: vmkit/trunk/include/j3/JavaAOTCompiler.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/JavaAOTCompiler.h?rev=136594&r1=136593&r2=136594&view=diff ============================================================================== --- vmkit/trunk/include/j3/JavaAOTCompiler.h (original) +++ vmkit/trunk/include/j3/JavaAOTCompiler.h Sun Jul 31 11:56:00 2011 @@ -10,8 +10,8 @@ #ifndef J3_AOT_COMPILER_H #define J3_AOT_COMPILER_H +#include "mvm/MvmDenseMap.h" #include "j3/JavaLLVMCompiler.h" -#include "j3/J3DenseMap.h" namespace j3 { @@ -100,7 +100,7 @@ llvm::Constant* CreateConstantFromJavaObject(JavaObject* obj); llvm::Constant* CreateConstantFromClassBytes(ClassBytes* bytes); llvm::Constant* CreateConstantFromJavaConstantPool(JavaConstantPool* ctp); - llvm::Constant* CreateConstantFromClassMap(const J3DenseMap& map); + llvm::Constant* CreateConstantFromClassMap(const mvm::MvmDenseMap& map); void AddInitializerToClass(llvm::GlobalVariable* varGV, CommonClass* classDef); llvm::Constant* getUTF8(const UTF8* val); Added: vmkit/trunk/include/mvm/MvmDenseMap.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/MvmDenseMap.h?rev=136594&view=auto ============================================================================== --- vmkit/trunk/include/mvm/MvmDenseMap.h (added) +++ vmkit/trunk/include/mvm/MvmDenseMap.h Sun Jul 31 11:56:00 2011 @@ -0,0 +1,512 @@ +//===- MvmDenseMap.h - Dense probed hash table ------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines the MvmDenseMap copied from llvm/ADT/DenseMap.h, but +// without storing pairs. +// +//===----------------------------------------------------------------------===// + +#ifndef MVM_DENSEMAP_H +#define MVM_DENSEMAP_H + +#include "llvm/Support/MathExtras.h" +#include "llvm/Support/PointerLikeTypeTraits.h" +#include "llvm/Support/type_traits.h" +#include +#include +#include +#include +#include +#include +#include + +namespace mvm { + +template +struct MvmDenseMapInfo { + //static inline T getEmptyKey(); + //static inline T getTombstoneKey(); + //static unsigned getHashValue(const T &Val); + //static bool isEqual(const T &LHS, const T &RHS); +}; + +template, + bool IsConst = false> +class MvmDenseMapIterator; + +template +struct MvmPair { + KeyT first; + ValueT second; +}; + +template > +class MvmDenseMap { +public: + typedef MvmPair BucketT; + uint32_t NumBuckets; + BucketT *Buckets; + + uint32_t NumEntries; + uint32_t NumTombstones; + bool IsPrecompiled; + + typedef KeyT key_type; + typedef ValueT mapped_type; + typedef BucketT value_type; + + explicit MvmDenseMap(unsigned NumInitBuckets = 0) { + IsPrecompiled = false; + init(NumInitBuckets); + } + + ~MvmDenseMap() { + const KeyT EmptyKey = getEmptyKey(), TombstoneKey = getTombstoneKey(); + for (BucketT *P = Buckets, *E = Buckets+NumBuckets; P != E; ++P) { + if (!KeyInfoT::isEqual(P->first, EmptyKey) && + !KeyInfoT::isEqual(P->first, TombstoneKey)) + P->second.~ValueT(); + P->first.~KeyT(); + } +#ifndef NDEBUG + if (NumBuckets) + memset((void*)Buckets, 0x5a, sizeof(BucketT)*NumBuckets); +#endif + if (!IsPrecompiled) { + operator delete(Buckets); + } + } + + typedef MvmDenseMapIterator iterator; + typedef MvmDenseMapIterator const_iterator; + inline iterator begin() { + // When the map is empty, avoid the overhead of AdvancePastEmptyBuckets(). + return empty() ? end() : iterator(Buckets, Buckets+NumBuckets); + } + inline iterator end() { + return iterator(Buckets+NumBuckets, Buckets+NumBuckets); + } + inline const_iterator begin() const { + return empty() ? end() : const_iterator(Buckets, Buckets+NumBuckets); + } + inline const_iterator end() const { + return const_iterator(Buckets+NumBuckets, Buckets+NumBuckets); + } + + bool empty() const { return NumEntries == 0; } + unsigned size() const { return NumEntries; } + + /// Grow the densemap so that it has at least Size buckets. Does not shrink + void resize(size_t Size) { + if (Size > NumBuckets) + grow(Size); + } + + void clear() { + if (NumEntries == 0 && NumTombstones == 0) return; + + // If the capacity of the array is huge, and the # elements used is small, + // shrink the array. + if (NumEntries * 4 < NumBuckets && NumBuckets > 64) { + shrink_and_clear(); + return; + } + + const KeyT EmptyKey = getEmptyKey(), TombstoneKey = getTombstoneKey(); + for (BucketT *P = Buckets, *E = Buckets+NumBuckets; P != E; ++P) { + if (!KeyInfoT::isEqual(P->first, EmptyKey)) { + if (!KeyInfoT::isEqual(P->first, TombstoneKey)) { + P->second.~ValueT(); + --NumEntries; + } + P->first = EmptyKey; + } + } + assert(NumEntries == 0 && "Node count imbalance!"); + NumTombstones = 0; + } + + /// count - Return true if the specified key is in the map. + bool count(const KeyT &Val) const { + BucketT *TheBucket; + return LookupBucketFor(Val, TheBucket); + } + + iterator find(const KeyT &Val) { + BucketT *TheBucket; + if (LookupBucketFor(Val, TheBucket)) + return iterator(TheBucket, Buckets+NumBuckets); + return end(); + } + const_iterator find(const KeyT &Val) const { + BucketT *TheBucket; + if (LookupBucketFor(Val, TheBucket)) + return const_iterator(TheBucket, Buckets+NumBuckets); + return end(); + } + + /// lookup - Return the entry for the specified key, or a default + /// constructed value if no such entry exists. + ValueT lookup(const KeyT &Val) const { + BucketT *TheBucket; + if (LookupBucketFor(Val, TheBucket)) + return TheBucket->second; + return ValueT(); + } + + // Inserts key,value pair into the map if the key isn't already in the map. + // If the key is already in the map, it returns false and doesn't update the + // value. + std::pair insert(const std::pair &KV) { + BucketT *TheBucket; + if (LookupBucketFor(KV.first, TheBucket)) + return std::make_pair(iterator(TheBucket, Buckets+NumBuckets), + false); // Already in map. + + // Otherwise, insert the new element. + TheBucket = InsertIntoBucket(KV.first, KV.second, TheBucket); + return std::make_pair(iterator(TheBucket, Buckets+NumBuckets), + true); + } + + /// insert - Range insertion of pairs. + template + void insert(InputIt I, InputIt E) { + for (; I != E; ++I) + insert(*I); + } + + + bool erase(const KeyT &Val) { + BucketT *TheBucket; + if (!LookupBucketFor(Val, TheBucket)) + return false; // not in map. + + TheBucket->second.~ValueT(); + TheBucket->first = getTombstoneKey(); + --NumEntries; + ++NumTombstones; + return true; + } + void erase(iterator I) { + BucketT *TheBucket = &*I; + TheBucket->second.~ValueT(); + TheBucket->first = getTombstoneKey(); + --NumEntries; + ++NumTombstones; + } + + void swap(MvmDenseMap& RHS) { + std::swap(NumBuckets, RHS.NumBuckets); + std::swap(Buckets, RHS.Buckets); + std::swap(NumEntries, RHS.NumEntries); + std::swap(NumTombstones, RHS.NumTombstones); + } + + value_type& FindAndConstruct(const KeyT &Key) { + BucketT *TheBucket; + if (LookupBucketFor(Key, TheBucket)) + return *TheBucket; + + return *InsertIntoBucket(Key, ValueT(), TheBucket); + } + + ValueT &operator[](const KeyT &Key) { + return FindAndConstruct(Key).second; + } + + /// isPointerIntoBucketsArray - Return true if the specified pointer points + /// somewhere into the MvmDenseMap's array of buckets (i.e. either to a key or + /// value in the MvmDenseMap). + bool isPointerIntoBucketsArray(const void *Ptr) const { + return Ptr >= Buckets && Ptr < Buckets+NumBuckets; + } + + /// getPointerIntoBucketsArray() - Return an opaque pointer into the buckets + /// array. In conjunction with the previous method, this can be used to + /// determine whether an insertion caused the MvmDenseMap to reallocate. + const void *getPointerIntoBucketsArray() const { return Buckets; } + +private: + BucketT *InsertIntoBucket(const KeyT &Key, const ValueT &Value, + BucketT *TheBucket) { + // If the load of the hash table is more than 3/4, or if fewer than 1/8 of + // the buckets are empty (meaning that many are filled with tombstones), + // grow the table. + // + // The later case is tricky. For example, if we had one empty bucket with + // tons of tombstones, failing lookups (e.g. for insertion) would have to + // probe almost the entire table until it found the empty bucket. If the + // table completely filled with tombstones, no lookup would ever succeed, + // causing infinite loops in lookup. + ++NumEntries; + if (NumEntries*4 >= NumBuckets*3) { + this->grow(NumBuckets * 2); + LookupBucketFor(Key, TheBucket); + } + if (NumBuckets-(NumEntries+NumTombstones) < NumBuckets/8) { + this->grow(NumBuckets); + LookupBucketFor(Key, TheBucket); + } + + // If we are writing over a tombstone, remember this. + if (!KeyInfoT::isEqual(TheBucket->first, getEmptyKey())) + --NumTombstones; + + TheBucket->first = Key; + new (&TheBucket->second) ValueT(Value); + return TheBucket; + } + + static unsigned getHashValue(const KeyT &Val) { + return KeyInfoT::getHashValue(Val); + } + static const KeyT getEmptyKey() { + return KeyInfoT::getEmptyKey(); + } + static const KeyT getTombstoneKey() { + return KeyInfoT::getTombstoneKey(); + } + + /// LookupBucketFor - Lookup the appropriate bucket for Val, returning it in + /// FoundBucket. If the bucket contains the key and a value, this returns + /// true, otherwise it returns a bucket with an empty marker or tombstone and + /// returns false. + bool LookupBucketFor(const KeyT &Val, BucketT *&FoundBucket) const { + unsigned BucketNo = getHashValue(Val); + unsigned ProbeAmt = 1; + BucketT *BucketsPtr = Buckets; + + if (NumBuckets == 0) { + FoundBucket = 0; + return false; + } + + // FoundTombstone - Keep track of whether we find a tombstone while probing. + BucketT *FoundTombstone = 0; + const KeyT EmptyKey = getEmptyKey(); + const KeyT TombstoneKey = getTombstoneKey(); + assert(!KeyInfoT::isEqual(Val, EmptyKey) && + !KeyInfoT::isEqual(Val, TombstoneKey) && + "Empty/Tombstone value shouldn't be inserted into map!"); + + while (1) { + BucketT *ThisBucket = BucketsPtr + (BucketNo & (NumBuckets-1)); + // Found Val's bucket? If so, return it. + if (KeyInfoT::isEqual(ThisBucket->first, Val)) { + FoundBucket = ThisBucket; + return true; + } + + // If we found an empty bucket, the key doesn't exist in the set. + // Insert it and return the default value. + if (KeyInfoT::isEqual(ThisBucket->first, EmptyKey)) { + // If we've already seen a tombstone while probing, fill it in instead + // of the empty bucket we eventually probed to. + if (FoundTombstone) ThisBucket = FoundTombstone; + FoundBucket = FoundTombstone ? FoundTombstone : ThisBucket; + return false; + } + + // If this is a tombstone, remember it. If Val ends up not in the map, we + // prefer to return it than something that would require more probing. + if (KeyInfoT::isEqual(ThisBucket->first, TombstoneKey) && !FoundTombstone) + FoundTombstone = ThisBucket; // Remember the first tombstone found. + + // Otherwise, it's a hash collision or a tombstone, continue quadratic + // probing. + BucketNo += ProbeAmt++; + } + } + + void init(unsigned InitBuckets) { + NumEntries = 0; + NumTombstones = 0; + NumBuckets = InitBuckets; + + if (InitBuckets == 0) { + Buckets = 0; + return; + } + + assert(InitBuckets && (InitBuckets & (InitBuckets-1)) == 0 && + "# initial buckets must be a power of two!"); + Buckets = static_cast(operator new(sizeof(BucketT)*InitBuckets)); + // Initialize all the keys to EmptyKey. + const KeyT EmptyKey = getEmptyKey(); + for (unsigned i = 0; i != InitBuckets; ++i) + new (&Buckets[i].first) KeyT(EmptyKey); + } + + void grow(unsigned AtLeast) { + unsigned OldNumBuckets = NumBuckets; + BucketT *OldBuckets = Buckets; + + if (NumBuckets < 64) + NumBuckets = 64; + + // Double the number of buckets. + while (NumBuckets < AtLeast) + NumBuckets <<= 1; + NumTombstones = 0; + Buckets = static_cast(operator new(sizeof(BucketT)*NumBuckets)); + + // Initialize all the keys to EmptyKey. + const KeyT EmptyKey = getEmptyKey(); + for (unsigned i = 0, e = NumBuckets; i != e; ++i) + new (&Buckets[i].first) KeyT(EmptyKey); + + // Insert all the old elements. + const KeyT TombstoneKey = getTombstoneKey(); + for (BucketT *B = OldBuckets, *E = OldBuckets+OldNumBuckets; B != E; ++B) { + if (!KeyInfoT::isEqual(B->first, EmptyKey) && + !KeyInfoT::isEqual(B->first, TombstoneKey)) { + // Insert the key/value into the new table. + BucketT *DestBucket; + bool FoundVal = LookupBucketFor(B->first, DestBucket); + (void)FoundVal; // silence warning. + assert(!FoundVal && "Key already in new map?"); + DestBucket->first = B->first; + new (&DestBucket->second) ValueT(B->second); + + // Free the value. + B->second.~ValueT(); + } + B->first.~KeyT(); + } + +#ifndef NDEBUG + if (OldNumBuckets) + memset((void*)OldBuckets, 0x5a, sizeof(BucketT)*OldNumBuckets); +#endif + // Free the old table. + if (!IsPrecompiled) { + operator delete(OldBuckets); + } else { + IsPrecompiled = false; + } + } + + void shrink_and_clear() { + unsigned OldNumBuckets = NumBuckets; + BucketT *OldBuckets = Buckets; + + // Reduce the number of buckets. + NumBuckets = NumEntries > 32 ? 1 << (llvm::Log2_32_Ceil(NumEntries) + 1) + : 64; + NumTombstones = 0; + Buckets = static_cast(operator new(sizeof(BucketT)*NumBuckets)); + + // Initialize all the keys to EmptyKey. + const KeyT EmptyKey = getEmptyKey(); + for (unsigned i = 0, e = NumBuckets; i != e; ++i) + new (&Buckets[i].first) KeyT(EmptyKey); + + // Free the old buckets. + const KeyT TombstoneKey = getTombstoneKey(); + for (BucketT *B = OldBuckets, *E = OldBuckets+OldNumBuckets; B != E; ++B) { + if (!KeyInfoT::isEqual(B->first, EmptyKey) && + !KeyInfoT::isEqual(B->first, TombstoneKey)) { + // Free the value. + B->second.~ValueT(); + } + B->first.~KeyT(); + } + +#ifndef NDEBUG + memset((void*)OldBuckets, 0x5a, sizeof(BucketT)*OldNumBuckets); +#endif + if (!IsPrecompiled) { + // Free the old table. + operator delete(OldBuckets); + } else { + IsPrecompiled = false; + } + + NumEntries = 0; + } + +public: + /// Return the approximate size (in bytes) of the actual map. + /// This is just the raw memory used by MvmDenseMap. + /// If entries are pointers to objects, the size of the referenced objects + /// are not included. + size_t getMemorySize() const { + return NumBuckets * sizeof(BucketT); + } +}; + +template +class MvmDenseMapIterator { + typedef MvmPair Bucket; + typedef MvmDenseMapIterator ConstIterator; + friend class MvmDenseMapIterator; +public: + typedef ptrdiff_t difference_type; + typedef typename llvm::conditional::type value_type; + typedef value_type *pointer; + typedef value_type &reference; + typedef std::forward_iterator_tag iterator_category; +private: + pointer Ptr, End; +public: + MvmDenseMapIterator() : Ptr(0), End(0) {} + + MvmDenseMapIterator(pointer Pos, pointer E) : Ptr(Pos), End(E) { + AdvancePastEmptyBuckets(); + } + + // If IsConst is true this is a converting constructor from iterator to + // const_iterator and the default copy constructor is used. + // Otherwise this is a copy constructor for iterator. + MvmDenseMapIterator(const MvmDenseMapIterator& I) + : Ptr(I.Ptr), End(I.End) {} + + reference operator*() const { + return *Ptr; + } + pointer operator->() const { + return Ptr; + } + + bool operator==(const ConstIterator &RHS) const { + return Ptr == RHS.operator->(); + } + bool operator!=(const ConstIterator &RHS) const { + return Ptr != RHS.operator->(); + } + + inline MvmDenseMapIterator& operator++() { // Preincrement + ++Ptr; + AdvancePastEmptyBuckets(); + return *this; + } + MvmDenseMapIterator operator++(int) { // Postincrement + MvmDenseMapIterator tmp = *this; ++*this; return tmp; + } + +private: + void AdvancePastEmptyBuckets() { + const KeyT Empty = KeyInfoT::getEmptyKey(); + const KeyT Tombstone = KeyInfoT::getTombstoneKey(); + + while (Ptr != End && + (KeyInfoT::isEqual(Ptr->first, Empty) || + KeyInfoT::isEqual(Ptr->first, Tombstone))) + ++Ptr; + } +}; + +} // end namespace j3 + +#endif Modified: vmkit/trunk/include/mvm/UTF8.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/UTF8.h?rev=136594&r1=136593&r2=136594&view=diff ============================================================================== --- vmkit/trunk/include/mvm/UTF8.h (original) +++ vmkit/trunk/include/mvm/UTF8.h Sun Jul 31 11:56:00 2011 @@ -3,6 +3,7 @@ #include #include "mvm/Allocator.h" +#include "mvm/MvmDenseMap.h" namespace mvm { @@ -20,15 +21,14 @@ } public: - /// size - The (constant) size of the array. + /// size - The (constant) size of the UTF8. ssize_t size; - /// elements - Elements of this array. The size here is different than the - /// actual size of the Java array. This is to facilitate Java array accesses - /// in JnJVM code. The size should be set to zero, but this is invalid C99. + /// elements - Elements of this UTF8. + /// The size should be set to zero, but this is invalid C99. uint16 elements[1]; - /// extract - Similar, but creates it in the map. + /// extract - Extracts an UTF8 from the current UTF8 const UTF8* extract(UTF8Map* map, uint32 start, uint32 len) const; /// equals - Are the two UTF8s equal? @@ -65,6 +65,47 @@ } }; +extern "C" const UTF8 TombstoneKey; +extern "C" const UTF8 EmptyKey; + +// Provide MvmDenseMapInfo for UTF8. +template<> +struct MvmDenseMapInfo { + static inline const UTF8* getEmptyKey() { + return &EmptyKey; + } + static inline const UTF8* getTombstoneKey() { + return &TombstoneKey; + } + static unsigned getHashValue(const UTF8* PtrVal) { + return PtrVal->hash(); + } + static bool isEqual(const UTF8* LHS, const UTF8* RHS) { return LHS->equals(RHS); } +}; + + +struct UTF8MapKey { + uint32_t hash; + const UTF8* data; + UTF8MapKey(uint32_t h, const UTF8* d) : hash(h), data(d) {} +}; + +// Provide MvmDenseMapInfo for UTF8MapKey. +template<> +struct MvmDenseMapInfo { + static inline const UTF8MapKey getEmptyKey() { + static UTF8MapKey EmptyKey(0, NULL); + return EmptyKey; + } + static inline const UTF8MapKey getTombstoneKey() { + static UTF8MapKey TombstoneKey(-1, NULL); + return TombstoneKey; + } + static unsigned getHashValue(const UTF8MapKey& key) { + return key.data->hash(); + } + static bool isEqual(const UTF8MapKey& LHS, const UTF8MapKey& RHS) { return LHS.data->equals(RHS.data); } +}; class UTF8Map : public mvm::PermanentObject { private: Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=136594&r1=136593&r2=136594&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Sun Jul 31 11:56:00 2011 @@ -1099,7 +1099,7 @@ return ConstantStruct::get(STy, ClassElts); } -Constant* JavaAOTCompiler::CreateConstantFromClassMap(const J3DenseMap& map) { +Constant* JavaAOTCompiler::CreateConstantFromClassMap(const mvm::MvmDenseMap& map) { StructType* STy = dyn_cast(JavaIntrinsics.J3DenseMapType->getContainedType(0)); Module& Mod = *getLLVMModule(); @@ -1113,15 +1113,15 @@ ArrayType* ATy = ArrayType::get(JavaIntrinsics.ptrType, map.NumBuckets * 2); for (uint32 i = 0; i < map.NumBuckets; ++i) { - J3Pair pair = map.Buckets[i]; - if (pair.first == &TombstoneKey) { + mvm::MvmPair pair = map.Buckets[i]; + if (pair.first == &mvm::TombstoneKey) { static GlobalVariable* gv = new GlobalVariable(Mod, JavaIntrinsics.UTF8Type->getContainedType(0), false, GlobalValue::ExternalLinkage, NULL, "TombstoneKey"); TempElts.push_back(ConstantExpr::getCast(Instruction::BitCast, gv, JavaIntrinsics.ptrType)); TempElts.push_back(Constant::getNullValue(JavaIntrinsics.ptrType)); - } else if (pair.first == &EmptyKey) { + } else if (pair.first == &mvm::EmptyKey) { static GlobalVariable* gv = new GlobalVariable(Mod, JavaIntrinsics.UTF8Type->getContainedType(0), false, GlobalValue::ExternalLinkage, NULL, Modified: vmkit/trunk/lib/J3/VMCore/LockedMap.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/LockedMap.cpp?rev=136594&r1=136593&r2=136594&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/LockedMap.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/LockedMap.cpp Sun Jul 31 11:56:00 2011 @@ -15,9 +15,6 @@ namespace j3 { -extern "C" const UTF8 TombstoneKey(0); -extern "C" const UTF8 EmptyKey(0); - bool ltarray16::operator()(const ArrayUInt16* s1, const ArrayUInt16* s2) const { llvm_gcroot(s1, 0); llvm_gcroot(s2, 0); Modified: vmkit/trunk/lib/J3/VMCore/LockedMap.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/LockedMap.h?rev=136594&r1=136593&r2=136594&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/LockedMap.h (original) +++ vmkit/trunk/lib/J3/VMCore/LockedMap.h Sun Jul 31 11:56:00 2011 @@ -16,7 +16,6 @@ #ifndef JNJVM_LOCKED_MAP_H #define JNJVM_LOCKED_MAP_H -#include "j3/J3DenseMap.h" #include @@ -25,30 +24,12 @@ #include "types.h" #include "mvm/Allocator.h" +#include "mvm/MvmDenseMap.h" #include "mvm/Threads/Locks.h" #include "UTF8.h" -extern "C" const j3::UTF8 TombstoneKey; -extern "C" const j3::UTF8 EmptyKey; - namespace j3 { -// Provide J3DenseMapInfo for UTF8. -template<> -struct J3DenseMapInfo { - static inline const j3::UTF8* getEmptyKey() { - return &EmptyKey; - } - static inline const j3::UTF8* getTombstoneKey() { - return &TombstoneKey; - } - static unsigned getHashValue(const j3::UTF8* PtrVal) { - return PtrVal->hash(); - } - static bool isEqual(const j3::UTF8* LHS, const j3::UTF8* RHS) { return LHS->equals(RHS); } -}; - - class ArrayUInt16; class JavaString; class JnjvmClassLoader; @@ -130,25 +111,25 @@ class ClassMap : public mvm::PermanentObject { public: ClassMap() {} - ClassMap(J3DenseMap* precompiled) : map(*precompiled) {} + ClassMap(mvm::MvmDenseMap* precompiled) : map(*precompiled) {} mvm::LockRecursive lock; - J3DenseMap map; - typedef J3DenseMap::iterator iterator; + mvm::MvmDenseMap map; + typedef mvm::MvmDenseMap::iterator iterator; }; class TypeMap : public mvm::PermanentObject { public: mvm::LockNormal lock; - J3DenseMap map; - typedef J3DenseMap::iterator iterator; + mvm::MvmDenseMap map; + typedef mvm::MvmDenseMap::iterator iterator; }; class SignMap : public mvm::PermanentObject { public: mvm::LockNormal lock; - J3DenseMap map; - typedef J3DenseMap::iterator iterator; + mvm::MvmDenseMap map; + typedef mvm::MvmDenseMap::iterator iterator; }; } // end namespace j3 Modified: vmkit/trunk/lib/J3/VMCore/Precompiled.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Precompiled.cpp?rev=136594&r1=136593&r2=136594&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/Precompiled.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/Precompiled.cpp Sun Jul 31 11:56:00 2011 @@ -352,8 +352,8 @@ upcalls->OfLong->classLoader = loader; upcalls->OfDouble->classLoader = loader; - J3DenseMap* precompiledClassMap = - reinterpret_cast*>(dlsym(nativeHandle, "ClassMap")); + mvm::MvmDenseMap* precompiledClassMap = + reinterpret_cast*>(dlsym(nativeHandle, "ClassMap")); loader->classes = new (loader->allocator, "ClassMap") ClassMap(precompiledClassMap); for (ClassMap::iterator i = loader->getClasses()->map.begin(), e = loader->getClasses()->map.end(); i != e; i++) { Modified: vmkit/trunk/lib/Mvm/Runtime/UTF8.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/UTF8.cpp?rev=136594&r1=136593&r2=136594&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Runtime/UTF8.cpp (original) +++ vmkit/trunk/lib/Mvm/Runtime/UTF8.cpp Sun Jul 31 11:56:00 2011 @@ -11,7 +11,11 @@ #include "mvm/UTF8.h" #include "mvm/PrintBuffer.h" -using namespace mvm; +namespace mvm { + +extern "C" const UTF8 TombstoneKey(0); +extern "C" const UTF8 EmptyKey(0); + void UTF8::print(PrintBuffer *pb) const { pb->writeUTF8(this); @@ -162,3 +166,5 @@ void UTF8Map::insert(const UTF8* val) { map.insert(std::make_pair(val->hash(), val)); } + +} From nicolas.geoffray at lip6.fr Sun Jul 31 10:50:43 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 31 Jul 2011 17:50:43 -0000 Subject: [vmkit-commits] [vmkit] r136598 - /vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp Message-ID: <20110731175043.4716F2A6C12C@llvm.org> Author: geoffray Date: Sun Jul 31 12:50:43 2011 New Revision: 136598 URL: http://llvm.org/viewvc/llvm-project?rev=136598&view=rev Log: Don't forget to increment i. Modified: vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp Modified: vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp?rev=136598&r1=136597&r2=136598&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp Sun Jul 31 12:50:43 2011 @@ -646,18 +646,18 @@ uint32 i = 0; - ArrayUInt16::setElement(msg, 't', i); - ArrayUInt16::setElement(msg, 'r', i); - ArrayUInt16::setElement(msg, 'y', i); - ArrayUInt16::setElement(msg, ' ', i); - ArrayUInt16::setElement(msg, 't', i); - ArrayUInt16::setElement(msg, 'o', i); - ArrayUInt16::setElement(msg, ' ', i); - ArrayUInt16::setElement(msg, 'l', i); - ArrayUInt16::setElement(msg, 'o', i); - ArrayUInt16::setElement(msg, 'a', i); - ArrayUInt16::setElement(msg, 'd', i); - ArrayUInt16::setElement(msg, ' ', i); + ArrayUInt16::setElement(msg, 't', i); i++; + ArrayUInt16::setElement(msg, 'r', i); i++; + ArrayUInt16::setElement(msg, 'y', i); i++; + ArrayUInt16::setElement(msg, ' ', i); i++; + ArrayUInt16::setElement(msg, 't', i); i++; + ArrayUInt16::setElement(msg, 'o', i); i++; + ArrayUInt16::setElement(msg, ' ', i); i++; + ArrayUInt16::setElement(msg, 'l', i); i++; + ArrayUInt16::setElement(msg, 'o', i); i++; + ArrayUInt16::setElement(msg, 'a', i); i++; + ArrayUInt16::setElement(msg, 'd', i); i++; + ArrayUInt16::setElement(msg, ' ', i); i++; for (sint32 j = 0; j < cl->name->size; ++j) { if (cl->name->elements[j] == '/') { From nicolas.geoffray at lip6.fr Sun Jul 31 10:57:57 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 31 Jul 2011 17:57:57 -0000 Subject: [vmkit-commits] [vmkit] r136599 - in /vmkit/trunk: include/mvm/UTF8.h lib/Mvm/Runtime/UTF8.cpp Message-ID: <20110731175758.0B09C2A6C12C@llvm.org> Author: geoffray Date: Sun Jul 31 12:57:57 2011 New Revision: 136599 URL: http://llvm.org/viewvc/llvm-project?rev=136599&view=rev Log: Move UTF8Map to a DenseMap. Modified: vmkit/trunk/include/mvm/UTF8.h vmkit/trunk/lib/Mvm/Runtime/UTF8.cpp Modified: vmkit/trunk/include/mvm/UTF8.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/UTF8.h?rev=136599&r1=136598&r2=136599&view=diff ============================================================================== --- vmkit/trunk/include/mvm/UTF8.h (original) +++ vmkit/trunk/include/mvm/UTF8.h Sun Jul 31 12:57:57 2011 @@ -85,35 +85,44 @@ struct UTF8MapKey { - uint32_t hash; - const UTF8* data; - UTF8MapKey(uint32_t h, const UTF8* d) : hash(h), data(d) {} + ssize_t length; + const uint16_t* data; + + UTF8MapKey(const uint16_t* d, ssize_t l) { + data = d; + length = l; + } }; // Provide MvmDenseMapInfo for UTF8MapKey. template<> struct MvmDenseMapInfo { static inline const UTF8MapKey getEmptyKey() { - static UTF8MapKey EmptyKey(0, NULL); + static UTF8MapKey EmptyKey(NULL, -1); return EmptyKey; } static inline const UTF8MapKey getTombstoneKey() { - static UTF8MapKey TombstoneKey(-1, NULL); + static UTF8MapKey TombstoneKey(NULL, -2); return TombstoneKey; } static unsigned getHashValue(const UTF8MapKey& key) { - return key.data->hash(); + return UTF8::readerHasher(key.data, key.length); + } + static bool isEqual(const UTF8MapKey& LHS, const UTF8MapKey& RHS) { + if (LHS.data == RHS.data) return true; + if (LHS.length != RHS.length) return false; + return !memcmp(LHS.data, RHS.data, RHS.length * sizeof(uint16)); } - static bool isEqual(const UTF8MapKey& LHS, const UTF8MapKey& RHS) { return LHS.data->equals(RHS.data); } }; class UTF8Map : public mvm::PermanentObject { private: - typedef std::multimap::iterator iterator; + typedef MvmDenseMap::iterator iterator; - mvm::LockNormal lock; - mvm::BumpPtrAllocator& allocator; - std::multimap map; + LockNormal lock; + BumpPtrAllocator& allocator; + // TODO(ngeoffray): This should really be a set. + MvmDenseMap map; public: const UTF8* lookupOrCreateAsciiz(const char* asciiz); @@ -121,7 +130,7 @@ const UTF8* lookupAsciiz(const char* asciiz); const UTF8* lookupReader(const uint16* buf, uint32 size); - UTF8Map(mvm::BumpPtrAllocator& A) : allocator(A) {} + UTF8Map(BumpPtrAllocator& A) : allocator(A) {} ~UTF8Map() { for (iterator i = map.begin(), e = map.end(); i!= e; ++i) { Modified: vmkit/trunk/lib/Mvm/Runtime/UTF8.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/UTF8.cpp?rev=136599&r1=136598&r2=136599&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Runtime/UTF8.cpp (original) +++ vmkit/trunk/lib/Mvm/Runtime/UTF8.cpp Sun Jul 31 12:57:57 2011 @@ -34,15 +34,6 @@ return map->lookupOrCreateReader(buf, len); } -static uint32 asciizHasher(const char* asciiz, sint32 size) { - uint32 r0 = 0, r1 = 0; - for (sint32 i = 0; i < size; i++) { - char c = asciiz[i]; - r0 += c; - r1 ^= c; - } - return (r1 & 255) + ((r0 & 255) << 8); -} uint32 UTF8::readerHasher(const uint16* buf, sint32 size) { uint32 r0 = 0, r1 = 0; @@ -54,117 +45,63 @@ return (r1 & 255) + ((r0 & 255) << 8); } -static bool asciizEqual(const UTF8* val, const char* asciiz, sint32 size) { - sint32 len = val->size; - if (len != size) return false; - else { - for (sint32 i = 0; i < len; i++) { - if (asciiz[i] != val->elements[i]) return false; - } - return true; - } -} - -static bool readerEqual(const UTF8* val, const uint16* buf, sint32 size) { - sint32 len = val->size; - if (len != size) return false; - else return !(memcmp(val->elements, buf, len * sizeof(uint16))); -} const UTF8* UTF8Map::lookupOrCreateAsciiz(const char* asciiz) { sint32 size = strlen(asciiz); - uint32 key = asciizHasher(asciiz, size); - const UTF8* res = 0; - lock.lock(); - - std::pair p = map.equal_range(key); - - for (UTF8Map::iterator i = p.first; i != p.second; i++) { - if (asciizEqual(i->second, asciiz, size)) { - res = i->second; - break; - } - } - - if (res == 0) { - UTF8* tmp = new(allocator, size) UTF8(size); - for (sint32 i = 0; i < size; i++) { - tmp->elements[i] = asciiz[i]; - } - res = (const UTF8*)tmp; - map.insert(std::make_pair(key, res)); + ThreadAllocator tempAllocator; + uint16_t* data = reinterpret_cast( + tempAllocator.Allocate(size * sizeof(uint16_t))); + for (int i = 0; i < size; i++) { + data[i] = asciiz[i]; } - - lock.unlock(); - return res; + return lookupOrCreateReader(data, size); } + const UTF8* UTF8Map::lookupOrCreateReader(const uint16* buf, uint32 len) { sint32 size = (sint32)len; - uint32 key = UTF8::readerHasher(buf, size); - const UTF8* res = 0; + UTF8MapKey key(buf, size); lock.lock(); - - std::pair p = map.equal_range(key); - - for (UTF8Map::iterator i = p.first; i != p.second; i++) { - if (readerEqual(i->second, buf, size)) { - res = i->second; - break; - } - } - if (res == 0) { + const UTF8* res = map.lookup(key); + if (res == NULL) { UTF8* tmp = new(allocator, size) UTF8(size); memcpy(tmp->elements, buf, len * sizeof(uint16)); res = (const UTF8*)tmp; - map.insert(std::make_pair(key, res)); + key.data = res->elements; + map[key] = res; } lock.unlock(); return res; } + const UTF8* UTF8Map::lookupAsciiz(const char* asciiz) { sint32 size = strlen(asciiz); - uint32 key = asciizHasher(asciiz, size); - const UTF8* res = 0; - lock.lock(); - - std::pair p = map.equal_range(key); - - for (UTF8Map::iterator i = p.first; i != p.second; i++) { - if (asciizEqual(i->second, asciiz, size)) { - res = i->second; - break; - } + ThreadAllocator tempAllocator; + uint16_t* data = reinterpret_cast( + tempAllocator.Allocate(size * sizeof(uint16_t))); + for (int i = 0; i < size; i++) { + data[i] = asciiz[i]; } - - lock.unlock(); - return res; + return lookupReader(data, size); } + const UTF8* UTF8Map::lookupReader(const uint16* buf, uint32 len) { sint32 size = (sint32)len; - uint32 key = UTF8::readerHasher(buf, size); - const UTF8* res = 0; + UTF8MapKey key(buf, size); lock.lock(); - - std::pair p = map.equal_range(key); - - for (UTF8Map::iterator i = p.first; i != p.second; i++) { - if (readerEqual(i->second, buf, size)) { - res = i->second; - break; - } - } - + const UTF8* res = map.lookup(key); lock.unlock(); return res; } + void UTF8Map::insert(const UTF8* val) { - map.insert(std::make_pair(val->hash(), val)); + UTF8MapKey key(val->elements, val->size); + map[key] = val; } -} +} // namespace mvm From nicolas.geoffray at lip6.fr Sun Jul 31 13:10:14 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 31 Jul 2011 20:10:14 -0000 Subject: [vmkit-commits] [vmkit] r136601 - in /vmkit/trunk: include/j3/JavaAOTCompiler.h include/mvm/UTF8.h lib/J3/Compiler/JavaAOTCompiler.cpp lib/J3/LLVMRuntime/runtime-default.ll lib/J3/VMCore/JnjvmClassLoader.cpp lib/J3/VMCore/Precompiled.cpp Message-ID: <20110731201014.5EBB02A6C12C@llvm.org> Author: geoffray Date: Sun Jul 31 15:10:14 2011 New Revision: 136601 URL: http://llvm.org/viewvc/llvm-project?rev=136601&view=rev Log: Precompiled UTF8 map. Modified: vmkit/trunk/include/j3/JavaAOTCompiler.h vmkit/trunk/include/mvm/UTF8.h vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp vmkit/trunk/lib/J3/LLVMRuntime/runtime-default.ll vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp vmkit/trunk/lib/J3/VMCore/Precompiled.cpp Modified: vmkit/trunk/include/j3/JavaAOTCompiler.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/JavaAOTCompiler.h?rev=136601&r1=136600&r2=136601&view=diff ============================================================================== --- vmkit/trunk/include/j3/JavaAOTCompiler.h (original) +++ vmkit/trunk/include/j3/JavaAOTCompiler.h Sun Jul 31 15:10:14 2011 @@ -11,6 +11,7 @@ #define J3_AOT_COMPILER_H #include "mvm/MvmDenseMap.h" +#include "mvm/UTF8.h" #include "j3/JavaLLVMCompiler.h" namespace j3 { @@ -101,6 +102,7 @@ llvm::Constant* CreateConstantFromClassBytes(ClassBytes* bytes); llvm::Constant* CreateConstantFromJavaConstantPool(JavaConstantPool* ctp); llvm::Constant* CreateConstantFromClassMap(const mvm::MvmDenseMap& map); + llvm::Constant* CreateConstantFromUTF8Map(const mvm::MvmDenseMap& map); void AddInitializerToClass(llvm::GlobalVariable* varGV, CommonClass* classDef); llvm::Constant* getUTF8(const UTF8* val); Modified: vmkit/trunk/include/mvm/UTF8.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/UTF8.h?rev=136601&r1=136600&r2=136601&view=diff ============================================================================== --- vmkit/trunk/include/mvm/UTF8.h (original) +++ vmkit/trunk/include/mvm/UTF8.h Sun Jul 31 15:10:14 2011 @@ -116,14 +116,13 @@ }; class UTF8Map : public mvm::PermanentObject { -private: +public: typedef MvmDenseMap::iterator iterator; LockNormal lock; BumpPtrAllocator& allocator; // TODO(ngeoffray): This should really be a set. MvmDenseMap map; -public: const UTF8* lookupOrCreateAsciiz(const char* asciiz); const UTF8* lookupOrCreateReader(const uint16* buf, uint32 size); @@ -131,6 +130,8 @@ const UTF8* lookupReader(const uint16* buf, uint32 size); UTF8Map(BumpPtrAllocator& A) : allocator(A) {} + UTF8Map(BumpPtrAllocator& A, MvmDenseMap* m) + : allocator(A), map(*m) {} ~UTF8Map() { for (iterator i = map.begin(), e = map.end(); i!= e; ++i) { Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=136601&r1=136600&r2=136601&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Sun Jul 31 15:10:14 2011 @@ -15,6 +15,7 @@ #include "llvm/PassManager.h" #include "llvm/Support/raw_ostream.h" +#include "mvm/UTF8.h" #include "mvm/Threads/Thread.h" #include "j3/J3Intrinsics.h" @@ -1152,6 +1153,60 @@ ConstantStruct::get(STy, elements), "ClassMap"); } +Constant* JavaAOTCompiler::CreateConstantFromUTF8Map(const mvm::MvmDenseMap& map) { + StructType* STy = + dyn_cast(JavaIntrinsics.J3DenseMapType->getContainedType(0)); + Module& Mod = *getLLVMModule(); + + std::vector elements; + elements.push_back(ConstantInt::get(Type::getInt32Ty(getLLVMContext()), map.NumBuckets)); + + Constant* buckets; + if (map.NumBuckets > 0) { + std::vector TempElts; + ArrayType* ATy = ArrayType::get(JavaIntrinsics.ptrType, map.NumBuckets * 3); + + for (uint32 i = 0; i < map.NumBuckets; ++i) { + mvm::MvmPair& pair = map.Buckets[i]; + TempElts.push_back(ConstantExpr::getCast( + Instruction::IntToPtr, + ConstantInt::get(JavaIntrinsics.pointerSizeType, pair.first.length), + JavaIntrinsics.ptrType)); + + if (mvm::MvmDenseMapInfo::isEqual(pair.first, + mvm::MvmDenseMapInfo::getEmptyKey()) + || mvm::MvmDenseMapInfo::isEqual(pair.first, + mvm::MvmDenseMapInfo::getTombstoneKey())) { + TempElts.push_back(Constant::getNullValue(JavaIntrinsics.ptrType)); + TempElts.push_back(Constant::getNullValue(JavaIntrinsics.ptrType)); + } else { + Constant* gv = getUTF8(pair.second); + Constant* GEP[2] = { JavaIntrinsics.constantZero, JavaIntrinsics.constantOne }; + + TempElts.push_back(ConstantExpr::getCast(Instruction::BitCast, + ConstantExpr::getGetElementPtr(gv, GEP, 2), JavaIntrinsics.ptrType)); + TempElts.push_back(ConstantExpr::getCast(Instruction::BitCast, gv, JavaIntrinsics.ptrType)); + } + } + + buckets = ConstantArray::get(ATy, TempElts); + + GlobalVariable* gv = new GlobalVariable(Mod, ATy, false, GlobalValue::InternalLinkage, buckets, ""); + buckets = ConstantExpr::getCast(Instruction::BitCast, gv, JavaIntrinsics.ptrType); + } else { + buckets = Constant::getNullValue(JavaIntrinsics.ptrType); + } + + elements.push_back(buckets); + elements.push_back(ConstantInt::get(Type::getInt32Ty(getLLVMContext()), map.NumEntries)); + elements.push_back(ConstantInt::get(Type::getInt32Ty(getLLVMContext()), map.NumTombstones)); + elements.push_back(ConstantInt::get(Type::getInt1Ty(getLLVMContext()), 1)); + + return new GlobalVariable(Mod, STy, false, + GlobalValue::ExternalLinkage, + ConstantStruct::get(STy, elements), "UTF8Map"); +} + Constant* JavaAOTCompiler::CreateConstantFromClass(Class* cl) { StructType* STy = dyn_cast(JavaIntrinsics.JavaClassType->getContainedType(0)); @@ -2362,6 +2417,9 @@ // Emit the class map. CreateConstantFromClassMap(loader->classes->map); + + // Emit the UTF8 map. + CreateConstantFromUTF8Map(loader->hashUTF8->map); } /// compileAllStubs - Compile all the native -> Java stubs. Modified: vmkit/trunk/lib/J3/LLVMRuntime/runtime-default.ll URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/LLVMRuntime/runtime-default.ll?rev=136601&r1=136600&r2=136601&view=diff ============================================================================== --- vmkit/trunk/lib/J3/LLVMRuntime/runtime-default.ll (original) +++ vmkit/trunk/lib/J3/LLVMRuntime/runtime-default.ll Sun Jul 31 15:10:14 2011 @@ -49,7 +49,7 @@ %Attribut = type { %UTF8*, i32, i32 } -%UTF8 = type { %JavaObject, i8*, [0 x i16] } +%UTF8 = type { i8*, [0 x i16] } %JavaField = type { i8*, i16, %UTF8*, %UTF8*, %Attribut*, i16, %JavaClass*, i32, Modified: vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp?rev=136601&r1=136600&r2=136601&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp Sun Jul 31 15:10:14 2011 @@ -65,7 +65,6 @@ TheCompiler = Comp; - hashUTF8 = new(allocator, "UTF8Map") UTF8Map(allocator); javaTypes = new(allocator, "TypeMap") TypeMap(); javaSignatures = new(allocator, "SignMap") SignMap(); strings = new(allocator, "StringList") StringList(); @@ -84,6 +83,7 @@ if (!bootLoaded) { classes = new(allocator, "ClassMap") ClassMap(); + hashUTF8 = new(allocator, "UTF8Map") UTF8Map(allocator); // Analyze the boot classpath, we know bootstrap classes are not in the // executable. analyseClasspathEnv(bootClasspathEnv); Modified: vmkit/trunk/lib/J3/VMCore/Precompiled.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Precompiled.cpp?rev=136601&r1=136600&r2=136601&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/Precompiled.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/Precompiled.cpp Sun Jul 31 15:10:14 2011 @@ -90,53 +90,14 @@ extern "C" void vmjcAddPreCompiledClass(JnjvmClassLoader* JCL, CommonClass* cl) { cl->classLoader = JCL; - - JCL->hashUTF8->insert(cl->name); - - if (cl->isClass()) { - Class* realCl = cl->asClass(); - - for (uint32 i = 0; i< realCl->nbStaticMethods; ++i) { - JavaMethod& meth = realCl->staticMethods[i]; - JCL->hashUTF8->insert(meth.name); - JCL->hashUTF8->insert(meth.type); - } - - for (uint32 i = 0; i< realCl->nbVirtualMethods; ++i) { - JavaMethod& meth = realCl->virtualMethods[i]; - JCL->hashUTF8->insert(meth.name); - JCL->hashUTF8->insert(meth.type); - } - - for (uint32 i = 0; i< realCl->nbStaticFields; ++i) { - JavaField& field = realCl->staticFields[i]; - JCL->hashUTF8->insert(field.name); - JCL->hashUTF8->insert(field.type); - } - - for (uint32 i = 0; i< realCl->nbVirtualFields; ++i) { - JavaField& field = realCl->virtualFields[i]; - JCL->hashUTF8->insert(field.name); - JCL->hashUTF8->insert(field.type); - } - } } extern "C" void vmjcGetClassArray(JnjvmClassLoader* JCL, ClassArray** ptr, const UTF8* name) { - JCL->hashUTF8->insert(name); *ptr = JCL->constructArray(name); } -extern "C" void vmjcAddUTF8(JnjvmClassLoader* JCL, const UTF8* val) { - JCL->hashUTF8->insert(val); -} - -extern "C" void vmjcAddString(JnjvmClassLoader* JCL, JavaString* val) { - JCL->strings->addString(JCL, val); -} - extern "C" intptr_t vmjcNativeLoader(JavaMethod* meth) { bool j3 = false; const UTF8* jniConsClName = meth->classDef->name; @@ -351,15 +312,20 @@ upcalls->OfFloat->classLoader = loader; upcalls->OfLong->classLoader = loader; upcalls->OfDouble->classLoader = loader; + + mvm::MvmDenseMap* precompiledUTF8Map = + reinterpret_cast*>(dlsym(nativeHandle, "UTF8Map")); + loader->hashUTF8 = new (loader->allocator, "UTF8Map") UTF8Map(loader->allocator, precompiledUTF8Map); mvm::MvmDenseMap* precompiledClassMap = reinterpret_cast*>(dlsym(nativeHandle, "ClassMap")); loader->classes = new (loader->allocator, "ClassMap") ClassMap(precompiledClassMap); + for (ClassMap::iterator i = loader->getClasses()->map.begin(), e = loader->getClasses()->map.end(); i != e; i++) { - vmjcAddPreCompiledClass(loader, i->second); + i->second->classLoader = loader; } - + // Get the base object arrays after the init, because init puts arrays // in the class loader map. upcalls->ArrayOfString = From nicolas.geoffray at lip6.fr Sun Jul 31 15:50:08 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 31 Jul 2011 22:50:08 -0000 Subject: [vmkit-commits] [vmkit] r136604 - in /vmkit/trunk: include/j3/JavaAOTCompiler.h include/mvm/MvmDenseSet.h include/mvm/UTF8.h lib/J3/Compiler/JavaAOTCompiler.cpp lib/J3/VMCore/Precompiled.cpp Message-ID: <20110731225008.5EC5A2A6C12C@llvm.org> Author: geoffray Date: Sun Jul 31 17:50:08 2011 New Revision: 136604 URL: http://llvm.org/viewvc/llvm-project?rev=136604&view=rev Log: Use a set instead of a map for utf8. Added: vmkit/trunk/include/mvm/MvmDenseSet.h Modified: vmkit/trunk/include/j3/JavaAOTCompiler.h vmkit/trunk/include/mvm/UTF8.h vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp vmkit/trunk/lib/J3/VMCore/Precompiled.cpp Modified: vmkit/trunk/include/j3/JavaAOTCompiler.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/JavaAOTCompiler.h?rev=136604&r1=136603&r2=136604&view=diff ============================================================================== --- vmkit/trunk/include/j3/JavaAOTCompiler.h (original) +++ vmkit/trunk/include/j3/JavaAOTCompiler.h Sun Jul 31 17:50:08 2011 @@ -102,7 +102,7 @@ llvm::Constant* CreateConstantFromClassBytes(ClassBytes* bytes); llvm::Constant* CreateConstantFromJavaConstantPool(JavaConstantPool* ctp); llvm::Constant* CreateConstantFromClassMap(const mvm::MvmDenseMap& map); - llvm::Constant* CreateConstantFromUTF8Map(const mvm::MvmDenseMap& map); + llvm::Constant* CreateConstantFromUTF8Map(const mvm::MvmDenseSet& set); void AddInitializerToClass(llvm::GlobalVariable* varGV, CommonClass* classDef); llvm::Constant* getUTF8(const UTF8* val); @@ -178,6 +178,8 @@ llvm::Function* RegularObjectTracer; llvm::Function* JavaObjectTracer; llvm::Function* ReferenceObjectTracer; + llvm::GlobalVariable* UTF8TombstoneGV; + llvm::GlobalVariable* UTF8EmptyGV; bool generateStubs; bool assumeCompiled; Added: vmkit/trunk/include/mvm/MvmDenseSet.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/MvmDenseSet.h?rev=136604&view=auto ============================================================================== --- vmkit/trunk/include/mvm/MvmDenseSet.h (added) +++ vmkit/trunk/include/mvm/MvmDenseSet.h Sun Jul 31 17:50:08 2011 @@ -0,0 +1,491 @@ +//===- MvmDenseSet.h - Dense probed hash set --------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines the MvmDenseMap copied from llvm/ADT/DenseMap.h, but +// without storing pairs. +// +//===----------------------------------------------------------------------===// + +#ifndef MVM_DENSESET_H +#define MVM_DENSESET_H + +#include "llvm/ADT/DenseMapInfo.h" +#include "llvm/Support/MathExtras.h" +#include "llvm/Support/PointerLikeTypeTraits.h" +#include "llvm/Support/type_traits.h" +#include +#include +#include +#include +#include +#include +#include + +namespace mvm { + +template, + bool IsConst = false> +class MvmDenseSetIterator; + +template, + typename ValueInfoT = MvmDenseMapInfo > +class MvmDenseSet { +public: + typedef ValueT BucketT; + uint32_t NumBuckets; + BucketT *Buckets; + + uint32_t NumEntries; + uint32_t NumTombstones; + bool IsPrecompiled; + + typedef KeyT key_type; + typedef ValueT mapped_type; + typedef BucketT value_type; + + explicit MvmDenseSet(unsigned NumInitBuckets = 0) { + IsPrecompiled = false; + init(NumInitBuckets); + } + + ~MvmDenseSet() { + const ValueT EmptyValue = getEmptyValue(), TombstoneValue = getTombstoneValue(); + for (BucketT *P = Buckets, *E = Buckets+NumBuckets; P != E; ++P) { + if (!ValueInfoT::isEqual(*P, EmptyValue) && + !ValueInfoT::isEqual(*P, TombstoneValue)) + (*P).~ValueT(); + } +#ifndef NDEBUG + if (NumBuckets) + memset((void*)Buckets, 0x5a, sizeof(BucketT)*NumBuckets); +#endif + if (!IsPrecompiled) { + operator delete(Buckets); + } + } + + typedef MvmDenseSetIterator iterator; + typedef MvmDenseSetIterator const_iterator; + inline iterator begin() { + // When the map is empty, avoid the overhead of AdvancePastEmptyBuckets(). + return empty() ? end() : iterator(Buckets, Buckets+NumBuckets); + } + inline iterator end() { + return iterator(Buckets+NumBuckets, Buckets+NumBuckets); + } + inline const_iterator begin() const { + return empty() ? end() : const_iterator(Buckets, Buckets+NumBuckets); + } + inline const_iterator end() const { + return const_iterator(Buckets+NumBuckets, Buckets+NumBuckets); + } + + bool empty() const { return NumEntries == 0; } + unsigned size() const { return NumEntries; } + + /// Grow the denseset so that it has at least Size buckets. Does not shrink + void resize(size_t Size) { + if (Size > NumBuckets) + grow(Size); + } + + void clear() { + if (NumEntries == 0 && NumTombstones == 0) return; + + // If the capacity of the array is huge, and the # elements used is small, + // shrink the array. + if (NumEntries * 4 < NumBuckets && NumBuckets > 64) { + shrink_and_clear(); + return; + } + + const ValueT EmptyValue = getEmptyValue(), TombstoneValue = getTombstoneValue(); + for (BucketT *P = Buckets, *E = Buckets+NumBuckets; P != E; ++P) { + if (!ValueInfoT::isEqual(*P, EmptyValue)) { + if (!ValueInfoT::isEqual(*P, TombstoneValue)) { + P->~ValueT(); + --NumEntries; + } + *P = EmptyValue; + } + } + assert(NumEntries == 0 && "Node count imbalance!"); + NumTombstones = 0; + } + + /// count - Return true if the specified key is in the set. + bool count(const KeyT &Val) const { + BucketT *TheBucket; + return LookupBucketFor(Val, TheBucket); + } + + iterator find(const KeyT &Val) { + BucketT *TheBucket; + if (LookupBucketFor(Val, TheBucket)) + return iterator(TheBucket, Buckets+NumBuckets); + return end(); + } + const_iterator find(const KeyT &Val) const { + BucketT *TheBucket; + if (LookupBucketFor(Val, TheBucket)) + return const_iterator(TheBucket, Buckets+NumBuckets); + return end(); + } + + /// lookup - Return the entry for the specified key, or a default + /// constructed value if no such entry exists. + ValueT lookup(const KeyT &Val) const { + BucketT *TheBucket; + if (LookupBucketFor(Val, TheBucket)) + return *TheBucket; + return ValueT(); + } + + // Inserts key,value pair into the map if the key isn't already in the map. + // If the key is already in the map, it returns false and doesn't update the + // value. + std::pair insert(const std::pair &KV) { + BucketT *TheBucket; + if (LookupBucketFor(KV.first, TheBucket)) + return std::make_pair(iterator(TheBucket, Buckets+NumBuckets), + false); // Already in map. + + // Otherwise, insert the new element. + TheBucket = InsertIntoBucket(KV.first, KV.second, TheBucket); + return std::make_pair(iterator(TheBucket, Buckets+NumBuckets), + true); + } + + /// insert - Range insertion of pairs. + template + void insert(InputIt I, InputIt E) { + for (; I != E; ++I) + insert(*I); + } + + + bool erase(const KeyT &Val) { + BucketT *TheBucket; + if (!LookupBucketFor(Val, TheBucket)) + return false; // not in map. + + (*TheBucket).~ValueT(); + *TheBucket = getTombstoneValue(); + --NumEntries; + ++NumTombstones; + return true; + } + void erase(iterator I) { + BucketT *TheBucket = &*I; + (*TheBucket).~ValueT(); + *TheBucket = getTombstoneValue(); + --NumEntries; + ++NumTombstones; + } + + void swap(MvmDenseSet& RHS) { + std::swap(NumBuckets, RHS.NumBuckets); + std::swap(Buckets, RHS.Buckets); + std::swap(NumEntries, RHS.NumEntries); + std::swap(NumTombstones, RHS.NumTombstones); + } + + value_type& FindAndConstruct(const KeyT &Key) { + BucketT *TheBucket; + if (LookupBucketFor(Key, TheBucket)) + return *TheBucket; + + return *InsertIntoBucket(Key, ValueT(), TheBucket); + } + + ValueT &operator[](const KeyT &Key) { + return FindAndConstruct(Key); + } + + /// isPointerIntoBucketsArray - Return true if the specified pointer points + /// somewhere into the MvmDenseSet's array of buckets. + bool isPointerIntoBucketsArray(const void *Ptr) const { + return Ptr >= Buckets && Ptr < Buckets+NumBuckets; + } + + /// getPointerIntoBucketsArray() - Return an opaque pointer into the buckets + /// array. In conjunction with the previous method, this can be used to + /// determine whether an insertion caused the MvmDenseSet to reallocate. + const void *getPointerIntoBucketsArray() const { return Buckets; } + +private: + BucketT *InsertIntoBucket(const KeyT &Key, const ValueT &Value, + BucketT *TheBucket) { + // If the load of the hash table is more than 3/4, or if fewer than 1/8 of + // the buckets are empty (meaning that many are filled with tombstones), + // grow the table. + // + // The later case is tricky. For example, if we had one empty bucket with + // tons of tombstones, failing lookups (e.g. for insertion) would have to + // probe almost the entire table until it found the empty bucket. If the + // table completely filled with tombstones, no lookup would ever succeed, + // causing infinite loops in lookup. + ++NumEntries; + if (NumEntries*4 >= NumBuckets*3) { + this->grow(NumBuckets * 2); + LookupBucketFor(Key, TheBucket); + } + if (NumBuckets-(NumEntries+NumTombstones) < NumBuckets/8) { + this->grow(NumBuckets); + LookupBucketFor(Key, TheBucket); + } + + // If we are writing over a tombstone, remember this. + if (!ValueInfoT::isEqual(*TheBucket, getEmptyValue())) + --NumTombstones; + + new (TheBucket) ValueT(Value); + return TheBucket; + } + + static unsigned getHashValue(const KeyT &Val) { + return KeyInfoT::getHashValue(Val); + } + static const ValueT getEmptyValue() { + return ValueInfoT::getEmptyKey(); + } + static const ValueT getTombstoneValue() { + return ValueInfoT::getTombstoneKey(); + } + + /// LookupBucketFor - Lookup the appropriate bucket for Val, returning it in + /// FoundBucket. If the bucket contains the key and a value, this returns + /// true, otherwise it returns a bucket with an empty marker or tombstone and + /// returns false. + bool LookupBucketFor(const KeyT &Key, BucketT *&FoundBucket) const { + unsigned BucketNo = getHashValue(Key); + unsigned ProbeAmt = 1; + BucketT *BucketsPtr = Buckets; + + if (NumBuckets == 0) { + FoundBucket = 0; + return false; + } + + // FoundTombstone - Keep track of whether we find a tombstone while probing. + BucketT *FoundTombstone = 0; + const ValueT EmptyValue = getEmptyValue(); + const ValueT TombstoneValue = getTombstoneValue(); + + while (1) { + BucketT *ThisBucket = BucketsPtr + (BucketNo & (NumBuckets-1)); + // Found Val's bucket? If so, return it. + if (ValueInfoT::isEqualKey(*ThisBucket, Key)) { + FoundBucket = ThisBucket; + return true; + } + + // If we found an empty bucket, the key doesn't exist in the set. + // Insert it and return the default value. + if (ValueInfoT::isEqual(*ThisBucket, EmptyValue)) { + // If we've already seen a tombstone while probing, fill it in instead + // of the empty bucket we eventually probed to. + if (FoundTombstone) ThisBucket = FoundTombstone; + FoundBucket = FoundTombstone ? FoundTombstone : ThisBucket; + return false; + } + + // If this is a tombstone, remember it. If Val ends up not in the map, we + // prefer to return it than something that would require more probing. + if (ValueInfoT::isEqual(*ThisBucket, TombstoneValue) && !FoundTombstone) + FoundTombstone = ThisBucket; // Remember the first tombstone found. + + // Otherwise, it's a hash collision or a tombstone, continue quadratic + // probing. + BucketNo += ProbeAmt++; + } + } + + void init(unsigned InitBuckets) { + NumEntries = 0; + NumTombstones = 0; + NumBuckets = InitBuckets; + + if (InitBuckets == 0) { + Buckets = 0; + return; + } + + assert(InitBuckets && (InitBuckets & (InitBuckets-1)) == 0 && + "# initial buckets must be a power of two!"); + Buckets = static_cast(operator new(sizeof(BucketT)*InitBuckets)); + // Initialize all the entries to EmptyValue. + const ValueT EmptyValue = getEmptyValue(); + for (unsigned i = 0; i != InitBuckets; ++i) + new (&Buckets[i]) ValueT(EmptyValue); + } + + void grow(unsigned AtLeast) { + unsigned OldNumBuckets = NumBuckets; + BucketT *OldBuckets = Buckets; + + if (NumBuckets < 64) + NumBuckets = 64; + + // Double the number of buckets. + while (NumBuckets < AtLeast) + NumBuckets <<= 1; + NumTombstones = 0; + Buckets = static_cast(operator new(sizeof(BucketT)*NumBuckets)); + + // Initialize all the values to EmptyValue. + const ValueT EmptyValue = getEmptyValue(); + for (unsigned i = 0, e = NumBuckets; i != e; ++i) + new (&Buckets[i]) ValueT(EmptyValue); + + // Insert all the old elements. + const ValueT TombstoneValue = getTombstoneValue(); + for (BucketT *B = OldBuckets, *E = OldBuckets+OldNumBuckets; B != E; ++B) { + if (!ValueInfoT::isEqual(*B, EmptyValue) && + !ValueInfoT::isEqual(*B, TombstoneValue)) { + // Insert the value into the new table. + BucketT *DestBucket; + KeyT key = ValueInfoT::toKey(*B); + bool FoundVal = LookupBucketFor(key, DestBucket); + (void)FoundVal; // silence warning. + assert(!FoundVal && "Key already in new map?"); + new (DestBucket) ValueT(*B); + + // Free the value. + (*B).~ValueT(); + } + } + +#ifndef NDEBUG + if (OldNumBuckets) + memset((void*)OldBuckets, 0x5a, sizeof(BucketT)*OldNumBuckets); +#endif + // Free the old table. + if (!IsPrecompiled) { + operator delete(OldBuckets); + } else { + IsPrecompiled = false; + } + } + + void shrink_and_clear() { + unsigned OldNumBuckets = NumBuckets; + BucketT *OldBuckets = Buckets; + + // Reduce the number of buckets. + NumBuckets = NumEntries > 32 ? 1 << (llvm::Log2_32_Ceil(NumEntries) + 1) + : 64; + NumTombstones = 0; + Buckets = static_cast(operator new(sizeof(BucketT)*NumBuckets)); + + // Initialize all the entries to EmptyValue. + const ValueT EmptyValue = getEmptyValue(); + for (unsigned i = 0, e = NumBuckets; i != e; ++i) + new (&Buckets[i]) ValueT(EmptyValue); + + // Free the old buckets. + const ValueT TombstoneValue = getTombstoneValue(); + for (BucketT *B = OldBuckets, *E = OldBuckets+OldNumBuckets; B != E; ++B) { + if (!ValueInfoT::isEqual(*B, EmptyValue) && + !ValueInfoT::isEqual(*B, TombstoneValue)) { + // Free the value. + (*B).~ValueT(); + } + } + +#ifndef NDEBUG + memset((void*)OldBuckets, 0x5a, sizeof(BucketT)*OldNumBuckets); +#endif + if (!IsPrecompiled) { + // Free the old table. + operator delete(OldBuckets); + } else { + IsPrecompiled = false; + } + + NumEntries = 0; + } + +public: + /// Return the approximate size (in bytes) of the actual map. + /// This is just the raw memory used by MvmDenseSet. + /// If entries are pointers to objects, the size of the referenced objects + /// are not included. + size_t getMemorySize() const { + return NumBuckets * sizeof(BucketT); + } +}; + +template +class MvmDenseSetIterator { + typedef ValueT Bucket; + typedef MvmDenseSetIterator ConstIterator; + friend class MvmDenseSetIterator; +public: + typedef ptrdiff_t difference_type; + typedef typename llvm::conditional::type value_type; + typedef value_type *pointer; + typedef value_type &reference; + typedef std::forward_iterator_tag iterator_category; +private: + pointer Ptr, End; +public: + MvmDenseSetIterator() : Ptr(0), End(0) {} + + MvmDenseSetIterator(pointer Pos, pointer E) : Ptr(Pos), End(E) { + AdvancePastEmptyBuckets(); + } + + // If IsConst is true this is a converting constructor from iterator to + // const_iterator and the default copy constructor is used. + // Otherwise this is a copy constructor for iterator. + MvmDenseSetIterator(const MvmDenseSetIterator& I) + : Ptr(I.Ptr), End(I.End) {} + + reference operator*() const { + return *Ptr; + } + pointer operator->() const { + return Ptr; + } + + bool operator==(const ConstIterator &RHS) const { + return Ptr == RHS.operator->(); + } + bool operator!=(const ConstIterator &RHS) const { + return Ptr != RHS.operator->(); + } + + inline MvmDenseSetIterator& operator++() { // Preincrement + ++Ptr; + AdvancePastEmptyBuckets(); + return *this; + } + MvmDenseSetIterator operator++(int) { // Postincrement + MvmDenseSetIterator tmp = *this; ++*this; return tmp; + } + +private: + void AdvancePastEmptyBuckets() { + const ValueT Empty = ValueInfoT::getEmptyKey(); + const ValueT Tombstone = ValueInfoT::getTombstoneKey(); + + while (Ptr != End && + (ValueInfoT::isEqual(*Ptr, Empty) || + ValueInfoT::isEqual(*Ptr, Tombstone))) + ++Ptr; + } +}; + +} // end namespace mvm + +#endif Modified: vmkit/trunk/include/mvm/UTF8.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/UTF8.h?rev=136604&r1=136603&r2=136604&view=diff ============================================================================== --- vmkit/trunk/include/mvm/UTF8.h (original) +++ vmkit/trunk/include/mvm/UTF8.h Sun Jul 31 17:50:08 2011 @@ -4,6 +4,7 @@ #include #include "mvm/Allocator.h" #include "mvm/MvmDenseMap.h" +#include "mvm/MvmDenseSet.h" namespace mvm { @@ -68,6 +69,16 @@ extern "C" const UTF8 TombstoneKey; extern "C" const UTF8 EmptyKey; +struct UTF8MapKey { + ssize_t length; + const uint16_t* data; + + UTF8MapKey(const uint16_t* d, ssize_t l) { + data = d; + length = l; + } +}; + // Provide MvmDenseMapInfo for UTF8. template<> struct MvmDenseMapInfo { @@ -81,19 +92,15 @@ return PtrVal->hash(); } static bool isEqual(const UTF8* LHS, const UTF8* RHS) { return LHS->equals(RHS); } -}; - - -struct UTF8MapKey { - ssize_t length; - const uint16_t* data; - - UTF8MapKey(const uint16_t* d, ssize_t l) { - data = d; - length = l; + static bool isEqualKey(const UTF8* LHS, const UTF8MapKey& Key) { + return LHS->equals(Key.data, Key.length); + } + static UTF8MapKey toKey(const UTF8* utf8) { + return UTF8MapKey(utf8->elements, utf8->size); } }; + // Provide MvmDenseMapInfo for UTF8MapKey. template<> struct MvmDenseMapInfo { @@ -117,12 +124,11 @@ class UTF8Map : public mvm::PermanentObject { public: - typedef MvmDenseMap::iterator iterator; + typedef MvmDenseSet::iterator iterator; LockNormal lock; BumpPtrAllocator& allocator; - // TODO(ngeoffray): This should really be a set. - MvmDenseMap map; + MvmDenseSet map; const UTF8* lookupOrCreateAsciiz(const char* asciiz); const UTF8* lookupOrCreateReader(const uint16* buf, uint32 size); @@ -130,12 +136,12 @@ const UTF8* lookupReader(const uint16* buf, uint32 size); UTF8Map(BumpPtrAllocator& A) : allocator(A) {} - UTF8Map(BumpPtrAllocator& A, MvmDenseMap* m) + UTF8Map(BumpPtrAllocator& A, MvmDenseSet* m) : allocator(A), map(*m) {} ~UTF8Map() { for (iterator i = map.begin(), e = map.end(); i!= e; ++i) { - allocator.Deallocate((void*)i->second); + allocator.Deallocate((void*)*i); } } Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=136604&r1=136603&r2=136604&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Sun Jul 31 17:50:08 2011 @@ -1116,18 +1116,10 @@ for (uint32 i = 0; i < map.NumBuckets; ++i) { mvm::MvmPair pair = map.Buckets[i]; if (pair.first == &mvm::TombstoneKey) { - static GlobalVariable* gv = - new GlobalVariable(Mod, JavaIntrinsics.UTF8Type->getContainedType(0), - false, GlobalValue::ExternalLinkage, NULL, - "TombstoneKey"); - TempElts.push_back(ConstantExpr::getCast(Instruction::BitCast, gv, JavaIntrinsics.ptrType)); + TempElts.push_back(ConstantExpr::getCast(Instruction::BitCast, UTF8TombstoneGV, JavaIntrinsics.ptrType)); TempElts.push_back(Constant::getNullValue(JavaIntrinsics.ptrType)); } else if (pair.first == &mvm::EmptyKey) { - static GlobalVariable* gv = - new GlobalVariable(Mod, JavaIntrinsics.UTF8Type->getContainedType(0), - false, GlobalValue::ExternalLinkage, NULL, - "EmptyKey"); - TempElts.push_back(ConstantExpr::getCast(Instruction::BitCast, gv, JavaIntrinsics.ptrType)); + TempElts.push_back(ConstantExpr::getCast(Instruction::BitCast, UTF8EmptyGV, JavaIntrinsics.ptrType)); TempElts.push_back(Constant::getNullValue(JavaIntrinsics.ptrType)); } else { TempElts.push_back(ConstantExpr::getCast(Instruction::BitCast, getUTF8(pair.first), JavaIntrinsics.ptrType)); @@ -1153,39 +1145,27 @@ ConstantStruct::get(STy, elements), "ClassMap"); } -Constant* JavaAOTCompiler::CreateConstantFromUTF8Map(const mvm::MvmDenseMap& map) { +Constant* JavaAOTCompiler::CreateConstantFromUTF8Map(const mvm::MvmDenseSet& set) { StructType* STy = dyn_cast(JavaIntrinsics.J3DenseMapType->getContainedType(0)); Module& Mod = *getLLVMModule(); std::vector elements; - elements.push_back(ConstantInt::get(Type::getInt32Ty(getLLVMContext()), map.NumBuckets)); + elements.push_back(ConstantInt::get(Type::getInt32Ty(getLLVMContext()), set.NumBuckets)); Constant* buckets; - if (map.NumBuckets > 0) { + if (set.NumBuckets > 0) { std::vector TempElts; - ArrayType* ATy = ArrayType::get(JavaIntrinsics.ptrType, map.NumBuckets * 3); + ArrayType* ATy = ArrayType::get(JavaIntrinsics.ptrType, set.NumBuckets); - for (uint32 i = 0; i < map.NumBuckets; ++i) { - mvm::MvmPair& pair = map.Buckets[i]; - TempElts.push_back(ConstantExpr::getCast( - Instruction::IntToPtr, - ConstantInt::get(JavaIntrinsics.pointerSizeType, pair.first.length), - JavaIntrinsics.ptrType)); - - if (mvm::MvmDenseMapInfo::isEqual(pair.first, - mvm::MvmDenseMapInfo::getEmptyKey()) - || mvm::MvmDenseMapInfo::isEqual(pair.first, - mvm::MvmDenseMapInfo::getTombstoneKey())) { - TempElts.push_back(Constant::getNullValue(JavaIntrinsics.ptrType)); - TempElts.push_back(Constant::getNullValue(JavaIntrinsics.ptrType)); + for (uint32 i = 0; i < set.NumBuckets; ++i) { + const UTF8* utf8 = set.Buckets[i]; + if (utf8 == &mvm::EmptyKey) { + TempElts.push_back(ConstantExpr::getCast(Instruction::BitCast, UTF8EmptyGV, JavaIntrinsics.ptrType)); + } else if (utf8 == &mvm::TombstoneKey) { + TempElts.push_back(ConstantExpr::getCast(Instruction::BitCast, UTF8TombstoneGV, JavaIntrinsics.ptrType)); } else { - Constant* gv = getUTF8(pair.second); - Constant* GEP[2] = { JavaIntrinsics.constantZero, JavaIntrinsics.constantOne }; - - TempElts.push_back(ConstantExpr::getCast(Instruction::BitCast, - ConstantExpr::getGetElementPtr(gv, GEP, 2), JavaIntrinsics.ptrType)); - TempElts.push_back(ConstantExpr::getCast(Instruction::BitCast, gv, JavaIntrinsics.ptrType)); + TempElts.push_back(ConstantExpr::getCast(Instruction::BitCast, getUTF8(utf8), JavaIntrinsics.ptrType)); } } @@ -1198,8 +1178,8 @@ } elements.push_back(buckets); - elements.push_back(ConstantInt::get(Type::getInt32Ty(getLLVMContext()), map.NumEntries)); - elements.push_back(ConstantInt::get(Type::getInt32Ty(getLLVMContext()), map.NumTombstones)); + elements.push_back(ConstantInt::get(Type::getInt32Ty(getLLVMContext()), set.NumEntries)); + elements.push_back(ConstantInt::get(Type::getInt32Ty(getLLVMContext()), set.NumTombstones)); elements.push_back(ConstantInt::get(Type::getInt1Ty(getLLVMContext()), 1)); return new GlobalVariable(Mod, STy, false, @@ -1873,6 +1853,16 @@ GlobalValue::ExternalLinkage, "ReferenceObjectTracer", getLLVMModule()); + + UTF8EmptyGV = new GlobalVariable(*getLLVMModule(), + JavaIntrinsics.UTF8Type->getContainedType(0), + false, GlobalValue::ExternalLinkage, NULL, + "EmptyKey"); + + UTF8TombstoneGV = new GlobalVariable(*getLLVMModule(), + JavaIntrinsics.UTF8Type->getContainedType(0), + false, GlobalValue::ExternalLinkage, NULL, + "TombstoneKey"); } void JavaAOTCompiler::printStats() { Modified: vmkit/trunk/lib/J3/VMCore/Precompiled.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Precompiled.cpp?rev=136604&r1=136603&r2=136604&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/Precompiled.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/Precompiled.cpp Sun Jul 31 17:50:08 2011 @@ -313,8 +313,8 @@ upcalls->OfLong->classLoader = loader; upcalls->OfDouble->classLoader = loader; - mvm::MvmDenseMap* precompiledUTF8Map = - reinterpret_cast*>(dlsym(nativeHandle, "UTF8Map")); + mvm::MvmDenseSet* precompiledUTF8Map = + reinterpret_cast*>(dlsym(nativeHandle, "UTF8Map")); loader->hashUTF8 = new (loader->allocator, "UTF8Map") UTF8Map(loader->allocator, precompiledUTF8Map); mvm::MvmDenseMap* precompiledClassMap =