From nicolas.geoffray at lip6.fr Fri Sep 2 12:23:22 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Fri, 02 Sep 2011 19:23:22 -0000 Subject: [vmkit-commits] [vmkit] r139025 - in /vmkit/trunk: include/j3/ include/mvm/ include/mvm/Threads/ lib/J3/Classpath/ lib/J3/Compiler/ lib/J3/VMCore/ lib/Mvm/CommonThread/ lib/Mvm/Compiler/ lib/Mvm/Runtime/ mmtk/mmtk-j3/ Message-ID: <20110902192322.498052A6C12C@llvm.org> Author: geoffray Date: Fri Sep 2 14:23:21 2011 New Revision: 139025 URL: http://llvm.org/viewvc/llvm-project?rev=139025&view=rev Log: Move OS related code to mvm/System.h, Modified: vmkit/trunk/include/j3/LLVMInfo.h vmkit/trunk/include/mvm/Allocator.h vmkit/trunk/include/mvm/MethodInfo.h vmkit/trunk/include/mvm/System.h vmkit/trunk/include/mvm/Threads/CollectionRV.h vmkit/trunk/include/mvm/Threads/ObjectLocks.h vmkit/trunk/include/mvm/Threads/Thread.h vmkit/trunk/include/mvm/VirtualMachine.h vmkit/trunk/lib/J3/Classpath/ClasspathVMRuntime.inc vmkit/trunk/lib/J3/Classpath/ClasspathVMThrowable.inc vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp vmkit/trunk/lib/J3/VMCore/JavaArray.h vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp vmkit/trunk/lib/J3/VMCore/JavaThread.h vmkit/trunk/lib/J3/VMCore/Jni.cpp vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp vmkit/trunk/lib/J3/VMCore/Jnjvm.h vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp vmkit/trunk/lib/J3/VMCore/Precompiled.cpp vmkit/trunk/lib/J3/VMCore/Reader.h vmkit/trunk/lib/J3/VMCore/ReferenceQueue.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 vmkit/trunk/lib/Mvm/Compiler/JIT.cpp vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp vmkit/trunk/mmtk/mmtk-j3/Memory.cpp vmkit/trunk/mmtk/mmtk-j3/ObjectModel.cpp vmkit/trunk/mmtk/mmtk-j3/VM.cpp Modified: vmkit/trunk/include/j3/LLVMInfo.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/LLVMInfo.h?rev=139025&r1=139024&r2=139025&view=diff ============================================================================== --- vmkit/trunk/include/j3/LLVMInfo.h (original) +++ vmkit/trunk/include/j3/LLVMInfo.h Fri Sep 2 14:23:21 2011 @@ -36,7 +36,7 @@ uint8_t logSizeInBytesConstant; }; -class LLVMClassInfo : public mvm::JITInfo { +class LLVMClassInfo : public mvm::PermanentObject { friend class JavaAOTCompiler; friend class JavaJITCompiler; friend class JavaLLVMCompiler; @@ -75,7 +75,7 @@ } }; -class LLVMMethodInfo : public mvm::JITInfo { +class LLVMMethodInfo : public mvm::PermanentObject { private: /// Compiler - The compiler for this method info. JavaLLVMCompiler* Compiler; @@ -110,7 +110,7 @@ }; -class LLVMFieldInfo : public mvm::JITInfo { +class LLVMFieldInfo : public mvm::PermanentObject { private: /// Compiler - The compiler for this field info. JavaLLVMCompiler* Compiler; @@ -132,7 +132,7 @@ } }; -class LLVMSignatureInfo : public mvm::JITInfo { +class LLVMSignatureInfo : public mvm::PermanentObject { private: /// Compiler - The compiler for this signature info. JavaLLVMCompiler* Compiler; Modified: vmkit/trunk/include/mvm/Allocator.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Allocator.h?rev=139025&r1=139024&r2=139025&view=diff ============================================================================== --- vmkit/trunk/include/mvm/Allocator.h (original) +++ vmkit/trunk/include/mvm/Allocator.h Fri Sep 2 14:23:21 2011 @@ -10,17 +10,12 @@ #ifndef MVM_ALLOCATOR_H #define MVM_ALLOCATOR_H -#include -#include -#include - #include "llvm/Support/Allocator.h" - #include "mvm/Threads/Locks.h" -class VirtualTable; +#include -#define declare_gcroot(type, name) type name; llvm_gcroot(name, 0); name +class VirtualTable; namespace mvm { @@ -80,14 +75,6 @@ } }; -/// JITInfo - This class can be derived from to hold private JIT-specific -/// information. Objects of type are accessed/created with -/// ::getInfo and destroyed when the object is destroyed. -struct JITInfo : public mvm::PermanentObject { - virtual ~JITInfo() {} - virtual void clear() {} -}; - } // end namespace mvm #endif // MVM_ALLOCATOR_H Modified: vmkit/trunk/include/mvm/MethodInfo.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/MethodInfo.h?rev=139025&r1=139024&r2=139025&view=diff ============================================================================== --- vmkit/trunk/include/mvm/MethodInfo.h (original) +++ vmkit/trunk/include/mvm/MethodInfo.h Fri Sep 2 14:23:21 2011 @@ -19,7 +19,7 @@ class FrameInfo { public: void* Metadata; - void* ReturnAddress; + intptr_t ReturnAddress; uint16_t SourceIndex; uint16_t FrameSize; uint16_t NumLiveOffsets; @@ -28,9 +28,9 @@ class MethodInfoHelper { public: - static void print(void* ip, void* addr); + static void print(intptr_t ip, intptr_t addr); - static void scan(uintptr_t closure, FrameInfo* FI, void* ip, void* addr); + static void scan(uintptr_t closure, FrameInfo* FI, intptr_t ip, intptr_t addr); static uint32_t FrameInfoSize(uint32_t NumOffsets) { uint32_t FrameInfoSize = sizeof(FrameInfo) + (NumOffsets - 1) * sizeof(int16_t); Modified: vmkit/trunk/include/mvm/System.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/System.h?rev=139025&r1=139024&r2=139025&view=diff ============================================================================== --- vmkit/trunk/include/mvm/System.h (original) +++ vmkit/trunk/include/mvm/System.h Fri Sep 2 14:23:21 2011 @@ -10,6 +10,10 @@ #ifndef MVM_SYSTEM_H #define MVM_SYSTEM_H +#include +#include +#include +#include #include namespace mvm { @@ -17,6 +21,69 @@ const int kWordSize = sizeof(intptr_t); const int kWordSizeLog2 = kWordSize == 4 ? 2 : 3; +#if defined(__linux__) || defined(__FreeBSD__) +#define LINUX_OS 1 +#elif defined(__APPLE__) +#define MACOS_OS 1 +#else +#error OS detection failed. +#endif + +#if (__WORDSIZE == 32) +#define ARCH_32 1 +#elif (__WORDSIZE == 64) +#define ARCH_64 1 +#else +#error Word size not supported. +#endif + +#if defined(_M_X64) || defined(__x86_64__) +#define ARCH_X64 1 +#elif defined(_M_IX86) || defined(__i386__) +#define ARCH_X86 1 +#elif defined (__PPC__) && ARCH_32 +#define ARCH_PPC 1 +#define ARCH_PPC_32 1 +#elif defined (__PPC__) && ARCH_64 +#define ARCH_PPC 1 +#define ARCH_PPC_64 1 +#else +#error Architecture detection failed. +#endif + + + +#if 0//def ARCH_X64 +const intptr_t kThreadStart = 0x110000000; +const intptr_t kThreadIDMask = 0xF7FF00000; +const uintptr_t kMvmThreadMask = 0xFF0000000; +#else +const intptr_t kThreadStart = 0x10000000; +const intptr_t kThreadIDMask = 0x7FF00000; +const intptr_t kMvmThreadMask = 0xF0000000; +#endif + +#if defined(MACOS_OS) + #define LONGJMP _longjmp + #define SETJMP _setjmp + #define DYLD_EXTENSION ".dylib" + #define SELF_HANDLE RTLD_DEFAULT + const intptr_t kGCMemoryStart = 0x30000000; +#else + #define LONGJMP longjmp + #define SETJMP setjmp + #define DYLD_EXTENSION ".so" + #define SELF_HANDLE 0 + const intptr_t kGCMemoryStart = 0x50000000; +#endif + +static const intptr_t kGCMemorySize = 0x30000000; + +#define TRY { mvm::ExceptionBuffer __buffer__; if (!SETJMP(__buffer__.buffer)) +#define CATCH else +#define IGNORE else { mvm::Thread::get()->clearException(); }} +#define END_CATCH } + class System { public: static bool IsWordAligned(intptr_t ptr) { @@ -29,6 +96,101 @@ } return ptr; } + + // Apply this mask to the stack pointer to get the Thread object. + static intptr_t GetThreadIDMask() { + return kThreadIDMask; + } + + // Apply this mask to verify that the current thread was created by Mvm. + static intptr_t GetMvmThreadMask() { + return kMvmThreadMask; + } + + // Get the memory start of thread stack addresses. + static intptr_t GetThreadStart() { + return kThreadStart; + } + + static intptr_t GetCallerAddress() { +#if defined(ARCH_X86) || defined(ARCH_X64) + return (intptr_t)__builtin_frame_address(0); +#else + return ((intptr_t*)__builtin_frame_address(0))[0]; +#endif + } + + static intptr_t GetCallerOfAddress(intptr_t addr) { + return ((intptr_t*)addr)[0]; + } + + static intptr_t GetIPFromCallerAddress(intptr_t addr) { +#if defined(MACOS_OS) && defined(ARCH_PPC) + return ((intptr_t*)addr)[2]; +#else + return ((intptr_t*)addr)[1]; +#endif + } + + static int SetJmp(jmp_buf buffer) { +#if defined(MACOS_OS) + return _setjmp(buffer); +#else + return setjmp(buffer); +#endif + } + + static void LongJmp(jmp_buf buffer, int val) { +#if defined(MACOS_OS) + _longjmp(buffer, val); +#else + longjmp(buffer, val); +#endif + } + + static void* GetSelfHandle() { + return SELF_HANDLE; + } + + static const char* GetDyLibExtension() { + return DYLD_EXTENSION; + } + + static double ReadDouble(int first, int second) { + int values[2]; + double res[1]; +#if ARCH_PPC + values[0] = second; + values[1] = first; +#else + values[0] = first; + values[1] = second; +#endif + memcpy(res, values, 8); + return res[0]; + } + + static int64_t ReadLong(int first, int second) { + int values[2]; + int64_t res[1]; +#if ARCH_PPC + values[0] = second; + values[1] = first; +#else + values[0] = first; + values[1] = second; +#endif + memcpy(res, values, 8); + return res[0]; + } + + static uint8_t* GetLastBytePtr(uintptr_t ptr) { +#if ARCH_PPC + return ((uint8_t*)ptr) + 2 * mvm::kWordSize - 1; +#else + return ((uint8_t*)ptr) + mvm::kWordSize; +#endif + } }; } Modified: vmkit/trunk/include/mvm/Threads/CollectionRV.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Threads/CollectionRV.h?rev=139025&r1=139024&r2=139025&view=diff ============================================================================== --- vmkit/trunk/include/mvm/Threads/CollectionRV.h (original) +++ vmkit/trunk/include/mvm/Threads/CollectionRV.h Fri Sep 2 14:23:21 2011 @@ -62,7 +62,7 @@ virtual void synchronize() = 0; virtual void join() = 0; - virtual void joinAfterUncooperative(void* SP) = 0; + virtual void joinAfterUncooperative(intptr_t SP) = 0; virtual void joinBeforeUncooperative() = 0; virtual void addThread(Thread* th) = 0; @@ -74,7 +74,7 @@ void synchronize(); void join(); - void joinAfterUncooperative(void* SP); + void joinAfterUncooperative(intptr_t SP); void joinBeforeUncooperative(); void addThread(Thread* th); Modified: vmkit/trunk/include/mvm/Threads/ObjectLocks.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Threads/ObjectLocks.h?rev=139025&r1=139024&r2=139025&view=diff ============================================================================== --- vmkit/trunk/include/mvm/Threads/ObjectLocks.h (original) +++ vmkit/trunk/include/mvm/Threads/ObjectLocks.h Fri Sep 2 14:23:21 2011 @@ -166,7 +166,7 @@ static const uint32_t NonLockBits = HashBits + GCBits; static const uint64_t NonLockBitsMask = ((1 << NonLockBits) - 1); - static const uint64_t ThinCountMask = ~(FatMask + Thread::IDMask + NonLockBitsMask); + static const uint64_t ThinCountMask = ~(FatMask + kThreadIDMask + NonLockBitsMask); static const uint64_t ThinCountShift = NonLockBits; static const uint64_t ThinCountAdd = 1 << NonLockBits; Modified: vmkit/trunk/include/mvm/Threads/Thread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Threads/Thread.h?rev=139025&r1=139024&r2=139025&view=diff ============================================================================== --- vmkit/trunk/include/mvm/Threads/Thread.h (original) +++ vmkit/trunk/include/mvm/Threads/Thread.h Fri Sep 2 14:23:21 2011 @@ -17,15 +17,8 @@ #include "debug.h" #include "types.h" -#include -#if defined(__MACH__) - #define TRY { mvm::ExceptionBuffer __buffer__; if (!_setjmp(__buffer__.buffer)) -#else - #define TRY { mvm::ExceptionBuffer __buffer__; if (!setjmp(__buffer__.buffer)) -#endif -#define CATCH else -#define IGNORE else { mvm::Thread::get()->clearException(); }} -#define END_CATCH } +#include "mvm/System.h" + namespace mvm { @@ -106,27 +99,10 @@ }; - -#if defined(__MACH__) && (defined(__PPC__) || defined(__ppc__)) -#define FRAME_IP(fp) (fp[2]) -#else -#define FRAME_IP(fp) (fp[1]) -#endif - -// Apparently gcc for i386 and family considers __builtin_frame_address(0) to -// return the caller, not the current function. -#if defined(__i386__) || defined(i386) || defined(_M_IX86) || \ - defined(__x86_64__) || defined(_M_AMD64) -#define FRAME_PTR() __builtin_frame_address(0) -#else -#define FRAME_PTR() (((void**)__builtin_frame_address(0))[0]) -#endif - - class KnownFrame { public: - void* currentFP; - void* currentIP; + intptr_t currentFP; + intptr_t currentIP; KnownFrame* previousFrame; }; @@ -177,7 +153,7 @@ /// baseSP - The base stack pointer. /// - void* baseSP; + intptr_t baseSP; /// doYield - Flag to tell the thread to yield for GC reasons. /// @@ -194,7 +170,7 @@ /// get - Get the thread specific data of the current thread. /// static Thread* get() { - return (Thread*)((uintptr_t)__builtin_frame_address(0) & IDMask); + return (Thread*)(System::GetCallerAddress() & System::GetThreadIDMask()); } private: @@ -203,7 +179,7 @@ /// interrupted, lastSP is not null and contains the value of the /// stack pointer before entering native. /// - void* lastSP; + intptr_t lastSP; /// internalThreadID - The implementation specific thread id. /// @@ -226,16 +202,16 @@ virtual void tracer(uintptr_t closure) {} void scanStack(uintptr_t closure); - void* getLastSP() { return lastSP; } - void setLastSP(void* V) { lastSP = V; } + intptr_t getLastSP() { return lastSP; } + void setLastSP(intptr_t V) { lastSP = V; } void joinRVBeforeEnter(); - void joinRVAfterLeave(void* savedSP); + void joinRVAfterLeave(intptr_t savedSP); void enterUncooperativeCode(unsigned level = 0) __attribute__ ((noinline)); - void enterUncooperativeCode(void* SP); + void enterUncooperativeCode(intptr_t SP); void leaveUncooperativeCode(); - void* waitOnSP(); + intptr_t waitOnSP(); /// clearException - Clear any pending exception of the current thread. @@ -245,24 +221,12 @@ bool isMvmThread() { if (!baseAddr) return false; - else return (((uintptr_t)this) & MvmThreadMask) == baseAddr; + else return (((uintptr_t)this) & System::GetMvmThreadMask()) == baseAddr; } /// baseAddr - The base address for all threads. static uintptr_t baseAddr; - /// IDMask - Apply this mask to the stack pointer to get the Thread object. - /// -#if 0//(__WORDSIZE == 64) - static const uint64_t IDMask = 0xF7FF00000; -#else - static const uint64_t IDMask = 0x7FF00000; -#endif - /// MvmThreadMask - Apply this mask to verify that the current thread was - /// created by Mvm. - /// - static const uint64_t MvmThreadMask = 0xF0000000; - /// OverflowMask - Apply this mask to implement overflow checks. For /// efficiency, we lower the available size of the stack: it can never go /// under 0xC0000 @@ -272,7 +236,7 @@ /// stackOverflow - Returns if there is a stack overflow in Java land. /// bool stackOverflow() { - return ((uintptr_t)__builtin_frame_address(0) & StackOverflowMask) == 0; + return (System::GetCallerAddress() & StackOverflowMask) == 0; } /// operator new - Allocate the Thread object as well as the stack for this @@ -295,7 +259,7 @@ /// getFrameContext - Fill the buffer with frames currently on the stack. /// - void getFrameContext(void** buffer); + void getFrameContext(intptr_t* buffer); /// getFrameContextLength - Get the length of the frame context. /// @@ -339,14 +303,14 @@ /// class StackWalker { public: - void** addr; - void* ip; + intptr_t addr; + intptr_t ip; KnownFrame* frame; mvm::Thread* thread; StackWalker(mvm::Thread* th) __attribute__ ((noinline)); void operator++(); - void* operator*(); + intptr_t operator*(); FrameInfo* get(); }; Modified: vmkit/trunk/include/mvm/VirtualMachine.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/VirtualMachine.h?rev=139025&r1=139024&r2=139025&view=diff ============================================================================== --- vmkit/trunk/include/mvm/VirtualMachine.h (original) +++ vmkit/trunk/include/mvm/VirtualMachine.h Fri Sep 2 14:23:21 2011 @@ -32,7 +32,7 @@ /// used when walking the stack so that VMKit knows which applicative method /// is executing on the stack. /// - llvm::DenseMap Functions; + llvm::DenseMap Functions; /// FunctionMapLock - Spin lock to protect the Functions map. /// @@ -40,12 +40,12 @@ /// IPToFrameInfo - Map a code start instruction instruction to the FrameInfo. /// - FrameInfo* IPToFrameInfo(void* ip); + FrameInfo* IPToFrameInfo(intptr_t ip); /// addFrameInfo - A new instruction pointer in the function map. /// - void addFrameInfo(void* ip, FrameInfo* meth); - void addFrameInfoNoLock(void* ip, FrameInfo* meth) { + void addFrameInfo(intptr_t ip, FrameInfo* meth); + void addFrameInfoNoLock(intptr_t ip, FrameInfo* meth) { Functions[ip] = meth; } /// removeFrameInfos - Remove all FrameInfo owned by the given owner. @@ -208,14 +208,14 @@ //===----------------------------------------------------------------------===// FunctionMap FunctionsCache; - FrameInfo* IPToFrameInfo(void* ip) { + FrameInfo* IPToFrameInfo(intptr_t ip) { return FunctionsCache.IPToFrameInfo(ip); } void removeFrameInfos(void* owner) { FunctionsCache.removeFrameInfos(owner); } - virtual void printMethod(FrameInfo* FI, void* ip, void* addr) = 0; + virtual void printMethod(FrameInfo* FI, intptr_t ip, intptr_t addr) = 0; //===----------------------------------------------------------------------===// // (4) Launch-related methods. Modified: vmkit/trunk/lib/J3/Classpath/ClasspathVMRuntime.inc URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Classpath/ClasspathVMRuntime.inc?rev=139025&r1=139024&r2=139025&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Classpath/ClasspathVMRuntime.inc (original) +++ vmkit/trunk/lib/J3/Classpath/ClasspathVMRuntime.inc Fri Sep 2 14:23:21 2011 @@ -21,7 +21,6 @@ #include "JavaUpcalls.h" #include "Jnjvm.h" -#include #include #include Modified: vmkit/trunk/lib/J3/Classpath/ClasspathVMThrowable.inc URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Classpath/ClasspathVMThrowable.inc?rev=139025&r1=139024&r2=139025&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Classpath/ClasspathVMThrowable.inc (original) +++ vmkit/trunk/lib/J3/Classpath/ClasspathVMThrowable.inc Fri Sep 2 14:23:21 2011 @@ -50,7 +50,7 @@ mvm::StackWalker Walker(th); uint32_t i = 0; - while (void* ip = *Walker) { + while (intptr_t ip = *Walker) { ArrayPtr::setElement(result, ip, i); ++i; ++Walker; @@ -83,7 +83,7 @@ } -JavaObject* consStackElement(mvm::FrameInfo* FI, void* ip) { +JavaObject* consStackElement(mvm::FrameInfo* FI, intptr_t ip) { JavaString* methodName = 0; JavaString* className = 0; Modified: vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp?rev=139025&r1=139024&r2=139025&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp Fri Sep 2 14:23:21 2011 @@ -2062,17 +2062,10 @@ uint8 id = reader.readU1(); i += 1; uint8 charId = arrayType(compilingMethod, id); -#ifndef ISOLATE_SHARING JnjvmBootstrapLoader* loader = compilingClass->classLoader->bootstrapLoader; dcl = loader->getArrayClass(id); valCl = TheCompiler->getNativeClass(dcl); -#else - Value* args[2] = { isolateLocal, - ConstantInt::get(Type::getInt32Ty(*llvmContext), id - 4) }; - valCl = CallInst::Create(intrinsics->GetJnjvmArrayClassFunction, - args, "", currentBlock); -#endif LLVMAssessorInfo& LAI = TheCompiler->AssessorInfo[charId]; sizeElement = ConstantInt::get(Type::getInt32Ty(*llvmContext), Modified: vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp?rev=139025&r1=139024&r2=139025&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp Fri Sep 2 14:23:21 2011 @@ -157,7 +157,7 @@ bool j3 = false; if (isNative(methodDef->access)) { - // Verify if it's defined by JnJVM + // Verify if it's defined by J3 JCL->nativeLookup(methodDef, j3, buf); } Modified: vmkit/trunk/lib/J3/VMCore/JavaArray.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaArray.h?rev=139025&r1=139024&r2=139025&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaArray.h (original) +++ vmkit/trunk/lib/J3/VMCore/JavaArray.h Fri Sep 2 14:23:21 2011 @@ -117,7 +117,7 @@ ARRAYCLASS(ArrayLong, sint64); ARRAYCLASS(ArrayFloat, float); ARRAYCLASS(ArrayDouble, double); -ARRAYCLASS(ArrayPtr, void*); +ARRAYCLASS(ArrayPtr, intptr_t); #undef ARRAYCLASS Modified: vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp?rev=139025&r1=139024&r2=139025&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp Fri Sep 2 14:23:21 2011 @@ -343,15 +343,15 @@ th->currentAddedReferences = *oldLRN; } -extern "C" void* j3StartJNI(uint32* localReferencesNumber, - uint32** oldLocalReferencesNumber, - mvm::KnownFrame* Frame) +extern "C" intptr_t j3StartJNI(uint32* localReferencesNumber, + uint32** oldLocalReferencesNumber, + mvm::KnownFrame* Frame) __attribute__((noinline)); // Never throws. Does not call Java code. Can not yield a GC. May join a GC. -extern "C" void* j3StartJNI(uint32* localReferencesNumber, - uint32** oldLocalReferencesNumber, - mvm::KnownFrame* Frame) { +extern "C" intptr_t j3StartJNI(uint32* localReferencesNumber, + uint32** oldLocalReferencesNumber, + mvm::KnownFrame* Frame) { JavaThread* th = JavaThread::get(); Modified: vmkit/trunk/lib/J3/VMCore/JavaThread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaThread.h?rev=139025&r1=139024&r2=139025&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaThread.h (original) +++ vmkit/trunk/lib/J3/VMCore/JavaThread.h Fri Sep 2 14:23:21 2011 @@ -39,7 +39,7 @@ #define BEGIN_JNI_EXCEPTION \ JavaThread* th = JavaThread::get(); \ - void* SP = th->getLastSP(); \ + intptr_t SP = th->getLastSP(); \ th->leaveUncooperativeCode(); \ mvm::KnownFrame Frame; \ th->startKnownFrame(Frame); \ @@ -157,7 +157,7 @@ /// throwFromJNI - Throw an exception after executing JNI code. /// - void throwFromJNI(void* SP) { + void throwFromJNI(intptr_t SP) { endKnownFrame(); enterUncooperativeCode(SP); } Modified: vmkit/trunk/lib/J3/VMCore/Jni.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Jni.cpp?rev=139025&r1=139024&r2=139025&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/Jni.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/Jni.cpp Fri Sep 2 14:23:21 2011 @@ -9,6 +9,8 @@ #include +#include "mvm/System.h" + #include "ClasspathReflect.h" #include "JavaArray.h" #include "JavaClass.h" @@ -3602,11 +3604,11 @@ res = BB->doNew(myvm); -#if (__WORDSIZE == 32) +#if ARCH_32 UserClass* PP = myvm->upcalls->newPointer32; p = PP->doNew(myvm); myvm->upcalls->dataPointer32->setInstanceInt32Field(p, (uint32)address); -#else +#elif ARCH_64 UserClass* PP = myvm->upcalls->newPointer64; p = PP->doNew(myvm); myvm->upcalls->dataPointer64->setInstanceLongField(p, (jlong)address); Modified: vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp?rev=139025&r1=139024&r2=139025&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp Fri Sep 2 14:23:21 2011 @@ -1443,14 +1443,16 @@ return 0; } -void Jnjvm::printMethod(mvm::FrameInfo* FI, void* ip, void* addr) { +void Jnjvm::printMethod(mvm::FrameInfo* FI, intptr_t ip, intptr_t addr) { if (FI->Metadata == NULL) { mvm::MethodInfoHelper::print(ip, addr); return; } JavaMethod* meth = (JavaMethod*)FI->Metadata; - fprintf(stderr, "; %p (%p) in %s.%s (line %d, bytecode %d, code start %p)", ip, addr, + fprintf(stderr, "; %p (%p) in %s.%s (line %d, bytecode %d, code start %p)", + (void*)ip, + (void*)addr, UTF8Buffer(meth->classDef->name).cString(), UTF8Buffer(meth->name).cString(), meth->lookupLineNumber(FI), Modified: vmkit/trunk/lib/J3/VMCore/Jnjvm.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Jnjvm.h?rev=139025&r1=139024&r2=139025&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/Jnjvm.h (original) +++ vmkit/trunk/lib/J3/VMCore/Jnjvm.h Fri Sep 2 14:23:21 2011 @@ -130,7 +130,7 @@ virtual void addFinalizationCandidate(gc* obj); virtual size_t getObjectSize(gc* obj); virtual const char* getObjectTypeName(gc* obj); - virtual void printMethod(mvm::FrameInfo* FI, void* ip, void* addr); + virtual void printMethod(mvm::FrameInfo* FI, intptr_t ip, intptr_t addr); /// CreateError - Creates a Java object of the specified exception class Modified: vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp?rev=139025&r1=139024&r2=139025&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp Fri Sep 2 14:23:21 2011 @@ -23,14 +23,6 @@ #include -#if defined(__MACH__) -#define SELF_HANDLE RTLD_DEFAULT -#define DYLD_EXTENSION ".dylib" -#else -#define SELF_HANDLE 0 -#define DYLD_EXTENSION ".so" -#endif - #include "debug.h" #include "mvm/Allocator.h" @@ -170,7 +162,7 @@ clinitType = asciizConstructUTF8("()V"); runName = asciizConstructUTF8("run"); prelib = asciizConstructUTF8("lib"); - postlib = asciizConstructUTF8(DYLD_EXTENSION); + postlib = asciizConstructUTF8(mvm::System::GetDyLibExtension()); mathName = asciizConstructUTF8("java/lang/Math"); stackWalkerName = asciizConstructUTF8("gnu/classpath/VMStackWalker"); NoClassDefFoundError = asciizConstructUTF8("java/lang/NoClassDefFoundError"); @@ -239,7 +231,7 @@ } ClassBytes* JnjvmBootstrapLoader::openName(const UTF8* utf8) { - ClassBytes* res = reinterpret_cast(dlsym(SELF_HANDLE, + ClassBytes* res = reinterpret_cast(dlsym(mvm::System::GetSelfHandle(), UTF8Buffer(utf8).toCompileName("_bytes")->cString())); if (res != NULL) return res; @@ -977,7 +969,7 @@ } intptr_t JnjvmClassLoader::loadInLib(const char* buf, bool& j3) { - uintptr_t res = (uintptr_t)TheCompiler->loadMethod(SELF_HANDLE, buf); + uintptr_t res = (uintptr_t)TheCompiler->loadMethod(mvm::System::GetSelfHandle(), buf); if (!res) { for (std::vector::iterator i = nativeLibs.begin(), Modified: vmkit/trunk/lib/J3/VMCore/Precompiled.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Precompiled.cpp?rev=139025&r1=139024&r2=139025&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/Precompiled.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/Precompiled.cpp Fri Sep 2 14:23:21 2011 @@ -9,15 +9,6 @@ // 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" @@ -123,7 +114,7 @@ bool Precompiled::Init(JnjvmBootstrapLoader* loader) { Class* javaLangObject = (Class*)dlsym(SELF_HANDLE, "java_lang_Object"); - void* nativeHandle = SELF_HANDLE; + void* nativeHandle = mvm::System::GetSelfHandle(); if (javaLangObject == NULL) { void* handle = dlopen("libvmjc"DYLD_EXTENSION, RTLD_LAZY | RTLD_GLOBAL); if (handle != NULL) { Modified: vmkit/trunk/lib/J3/VMCore/Reader.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Reader.h?rev=139025&r1=139024&r2=139025&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/Reader.h (original) +++ vmkit/trunk/lib/J3/VMCore/Reader.h Fri Sep 2 14:23:21 2011 @@ -59,32 +59,12 @@ } static double readDouble(int first, int second) { - int values[2]; - double res[1]; -#if defined(__PPC__) - values[0] = second; - values[1] = first; -#else - values[0] = first; - values[1] = second; -#endif - memcpy(res, values, 8); - return res[0]; - } + return mvm::System::ReadDouble(first, second); + } static sint64 readLong(int first, int second) { - int values[2]; - sint64 res[1]; -#if defined(__PPC__) - values[0] = second; - values[1] = first; -#else - values[0] = first; - values[1] = second; -#endif - memcpy(res, values, 8); - return res[0]; + return mvm::System::ReadLong(first, second); } static const int SeekSet; @@ -149,7 +129,6 @@ } void seek(uint32 pos, int from); - }; } // end namespace j3 Modified: vmkit/trunk/lib/J3/VMCore/ReferenceQueue.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/ReferenceQueue.h?rev=139025&r1=139024&r2=139025&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/ReferenceQueue.h (original) +++ vmkit/trunk/lib/J3/VMCore/ReferenceQueue.h Fri Sep 2 14:23:21 2011 @@ -57,11 +57,11 @@ if (CurrentIndex >= QueueLength) { uint32 newLength = QueueLength * GROW_FACTOR; gc** newQueue = new gc*[newLength]; - memset(newQueue, 0, newLength * sizeof(gc*)); if (!newQueue) { fprintf(stderr, "I don't know how to handle reference overflow yet!\n"); abort(); } + memset(newQueue, 0, newLength * sizeof(gc*)); for (uint32 i = 0; i < QueueLength; ++i) newQueue[i] = References[i]; delete[] References; References = newQueue; Modified: vmkit/trunk/lib/Mvm/CommonThread/CollectionRV.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommonThread/CollectionRV.cpp?rev=139025&r1=139024&r2=139025&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/CommonThread/CollectionRV.cpp (original) +++ vmkit/trunk/lib/Mvm/CommonThread/CollectionRV.cpp Fri Sep 2 14:23:21 2011 @@ -15,11 +15,11 @@ #include "debug.h" -using namespace mvm; +namespace mvm { void CollectionRV::another_mark() { mvm::Thread* th = mvm::Thread::get(); - assert(th->getLastSP() != NULL); + assert(th->getLastSP() != 0); assert(nbJoined < th->MyVM->numberOfThreads); nbJoined++; if (nbJoined == th->MyVM->numberOfThreads) { @@ -29,7 +29,7 @@ void CollectionRV::waitEndOfRV() { mvm::Thread* th = mvm::Thread::get(); - assert(th->getLastSP() != NULL); + assert(th->getLastSP() != 0); while (th->doYield) { condEndRV.wait(&_lockRV); @@ -85,12 +85,12 @@ void CooperativeCollectionRV::join() { mvm::Thread* th = mvm::Thread::get(); assert(th->doYield && "No yield"); - assert((th->getLastSP() == NULL) && "SP present in cooperative code"); + assert((th->getLastSP() == 0) && "SP present in cooperative code"); th->inRV = true; lockRV(); - th->setLastSP(FRAME_PTR()); + th->setLastSP(System::GetCallerAddress()); th->joinedRV = true; another_mark(); waitEndOfRV(); @@ -102,7 +102,7 @@ void CooperativeCollectionRV::joinBeforeUncooperative() { mvm::Thread* th = mvm::Thread::get(); - assert((th->getLastSP() != NULL) && + assert((th->getLastSP() != 0) && "SP not set before entering uncooperative code"); th->inRV = true; @@ -120,9 +120,9 @@ th->inRV = false; } -void CooperativeCollectionRV::joinAfterUncooperative(void* SP) { +void CooperativeCollectionRV::joinAfterUncooperative(intptr_t SP) { mvm::Thread* th = mvm::Thread::get(); - assert((th->getLastSP() == NULL) && + assert((th->getLastSP() == 0) && "SP set after entering uncooperative code"); th->inRV = true; @@ -135,7 +135,7 @@ another_mark(); } waitEndOfRV(); - th->setLastSP(NULL); + th->setLastSP(0); } unlockRV(); @@ -172,3 +172,5 @@ void CooperativeCollectionRV::addThread(Thread* th) { // Nothing to do. } + +} Modified: vmkit/trunk/lib/Mvm/CommonThread/ObjectLocks.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommonThread/ObjectLocks.cpp?rev=139025&r1=139024&r2=139025&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/CommonThread/ObjectLocks.cpp (original) +++ vmkit/trunk/lib/Mvm/CommonThread/ObjectLocks.cpp Fri Sep 2 14:23:21 2011 @@ -20,7 +20,7 @@ #include -using namespace mvm; +namespace mvm { void ThinLock::overflowThinLock(gc* object, LockSystem& table) { llvm_gcroot(object, 0); @@ -109,7 +109,7 @@ uintptr_t newValue = 0; uintptr_t yieldedValue = 0; - if ((object->header & Thread::IDMask) == id) { + if ((object->header & System::GetThreadIDMask()) == id) { assert(owner(object, table) && "Inconsistent lock"); if ((object->header & ThinCountMask) != ThinCountMask) { uint32 count = object->header & ThinCountMask; @@ -225,7 +225,7 @@ if (obj != NULL) return obj->owner(); } else { uint64 id = mvm::Thread::get()->getThreadID(); - if ((object->header & Thread::IDMask) == id) return true; + if ((object->header & System::GetThreadIDMask()) == id) return true; } return false; } @@ -534,3 +534,5 @@ l->firstThread = NULL; assert(mvm::ThinLock::owner(self, table) && "Not owner after notifyAll"); } + +} Modified: vmkit/trunk/lib/Mvm/CommonThread/ctlock.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommonThread/ctlock.cpp?rev=139025&r1=139024&r2=139025&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/CommonThread/ctlock.cpp (original) +++ vmkit/trunk/lib/Mvm/CommonThread/ctlock.cpp Fri Sep 2 14:23:21 2011 @@ -19,7 +19,7 @@ #include -using namespace mvm; +namespace mvm { Lock::Lock() { pthread_mutexattr_t attr; @@ -187,3 +187,5 @@ return res; } + +} Modified: vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp?rev=139025&r1=139024&r2=139025&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp (original) +++ vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp Fri Sep 2 14:23:21 2011 @@ -17,10 +17,7 @@ #include "mvm/Threads/Thread.h" #include -#include #include -#include -#include #include #include #include @@ -56,47 +53,43 @@ MyVM->rendezvous.joinBeforeUncooperative(); } -void Thread::joinRVAfterLeave(void* savedSP) { +void Thread::joinRVAfterLeave(intptr_t savedSP) { MyVM->rendezvous.joinAfterUncooperative(savedSP); } void Thread::startKnownFrame(KnownFrame& F) { // Get the caller of this function - void** cur = (void**)FRAME_PTR(); + intptr_t cur = System::GetCallerAddress(); F.previousFrame = lastKnownFrame; F.currentFP = cur; // This is used as a marker. - F.currentIP = NULL; + F.currentIP = 0; lastKnownFrame = &F; } void Thread::endKnownFrame() { - assert(lastKnownFrame->currentIP == NULL); + assert(lastKnownFrame->currentIP == 0); lastKnownFrame = lastKnownFrame->previousFrame; } void Thread::startUnknownFrame(KnownFrame& F) { // Get the caller of this function - void** cur = (void**)FRAME_PTR(); + intptr_t cur = System::GetCallerAddress(); // Get the caller of the caller. - cur = (void**)cur[0]; + cur = System::GetCallerOfAddress(cur); F.previousFrame = lastKnownFrame; F.currentFP = cur; - F.currentIP = FRAME_IP(cur); + F.currentIP = System::GetIPFromCallerAddress(cur); lastKnownFrame = &F; } void Thread::endUnknownFrame() { - assert(lastKnownFrame->currentIP != NULL); + assert(lastKnownFrame->currentIP != 0); lastKnownFrame = lastKnownFrame->previousFrame; } void Thread::internalThrowException() { -#if defined(__MACH__) - _longjmp(lastExceptionBuffer->buffer, 1); -#else - longjmp(lastExceptionBuffer->buffer, 1); -#endif + LONGJMP(lastExceptionBuffer->buffer, 1); } void Thread::printBacktrace() { @@ -108,11 +101,11 @@ } } -void Thread::getFrameContext(void** buffer) { +void Thread::getFrameContext(intptr_t* buffer) { mvm::StackWalker Walker(this); uint32_t i = 0; - while (void* ip = *Walker) { + while (intptr_t ip = *Walker) { buffer[i++] = ip; ++Walker; } @@ -131,29 +124,29 @@ FrameInfo* StackWalker::get() { if (addr == thread->baseSP) return 0; - ip = FRAME_IP(addr); + ip = System::GetIPFromCallerAddress(addr); return thread->MyVM->IPToFrameInfo(ip); } -void* StackWalker::operator*() { +intptr_t StackWalker::operator*() { if (addr == thread->baseSP) return 0; - ip = FRAME_IP(addr); + ip = System::GetIPFromCallerAddress(addr); return ip; } void StackWalker::operator++() { if (addr != thread->baseSP) { assert((addr < thread->baseSP) && "Corrupted stack"); - assert((addr < addr[0]) && "Corrupted stack"); + assert((addr < System::GetCallerOfAddress(addr)) && "Corrupted stack"); if ((frame != NULL) && (addr == frame->currentFP)) { - assert(frame->currentIP == NULL); + assert(frame->currentIP == 0); frame = frame->previousFrame; assert(frame != NULL); - assert(frame->currentIP != NULL); - addr = (void**)frame->currentFP; + assert(frame->currentIP != 0); + addr = frame->currentFP; frame = frame->previousFrame; } else { - addr = (void**)addr[0]; + addr = System::GetCallerOfAddress(addr); } } } @@ -162,16 +155,16 @@ thread = th; frame = th->lastKnownFrame; if (mvm::Thread::get() == th) { - addr = (void**)FRAME_PTR(); - addr = (void**)addr[0]; + addr = System::GetCallerAddress(); + addr = System::GetCallerOfAddress(addr); } else { - addr = (void**)th->waitOnSP(); + addr = th->waitOnSP(); if (frame) { assert(frame->currentFP >= addr); } if (frame && (addr == frame->currentFP)) { frame = frame->previousFrame; - assert((frame == NULL) || (frame->currentIP == NULL)); + assert((frame == NULL) || (frame->currentIP == 0)); } } assert(addr && "No address to start with"); @@ -191,10 +184,10 @@ if (!inRV) { assert(!lastSP && "SP already set when entering uncooperative code"); // Get the caller. - void* temp = FRAME_PTR(); + intptr_t temp = System::GetCallerAddress(); // Make sure to at least get the caller of the caller. ++level; - while (level--) temp = ((void**)temp)[0]; + while (level--) temp = System::GetCallerOfAddress(temp); // The cas is not necessary, but it does a memory barrier. __sync_bool_compare_and_swap(&lastSP, 0, temp); if (doYield) joinRVBeforeEnter(); @@ -203,7 +196,7 @@ } } -void Thread::enterUncooperativeCode(void* SP) { +void Thread::enterUncooperativeCode(intptr_t SP) { if (isMvmThread()) { if (!inRV) { assert(!lastSP && "SP already set when entering uncooperative code"); @@ -219,7 +212,7 @@ if (isMvmThread()) { if (!inRV) { assert(lastSP && "No last SP when leaving uncooperative code"); - void* savedSP = lastSP; + intptr_t savedSP = lastSP; // The cas is not necessary, but it does a memory barrier. __sync_bool_compare_and_swap(&lastSP, lastSP, 0); // A rendezvous has just been initiated, join it. @@ -229,9 +222,9 @@ } } -void* Thread::waitOnSP() { +intptr_t Thread::waitOnSP() { // First see if we can get lastSP directly. - void* sp = lastSP; + intptr_t sp = lastSP; if (sp) return sp; // Then loop a fixed number of iterations to get lastSP. @@ -241,9 +234,9 @@ } // Finally, yield until lastSP is not set. - while ((sp = lastSP) == NULL) mvm::Thread::yield(); + while ((sp = lastSP) == 0) mvm::Thread::yield(); - assert(sp != NULL && "Still no sp"); + assert(sp != 0 && "Still no sp"); return sp; } @@ -254,14 +247,6 @@ #define STACK_SIZE 0x100000 #define NR_THREADS 255 -#if 0//(__WORDSIZE == 64) -#define START_ADDR 0x110000000 -#define END_ADDR 0x170000000 -#else -#define START_ADDR 0x10000000 -#define END_ADDR 0x70000000 -#endif - /// StackThreadManager - This class allocates all stacks for threads. Because /// we want fast access to thread local data, and can not rely on platform /// dependent thread local storage (eg pthread keys are inefficient, tls is @@ -282,13 +267,9 @@ StackThreadManager() { baseAddr = 0; - uintptr_t ptr = START_ADDR; + uintptr_t ptr = kThreadStart; -#if defined (__MACH__) uint32 flags = MAP_PRIVATE | MAP_ANON | MAP_FIXED; -#else - uint32 flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED; -#endif baseAddr = (uintptr_t)mmap((void*)ptr, STACK_SIZE * NR_THREADS, PROT_READ | PROT_WRITE, flags, -1, 0); @@ -344,7 +325,7 @@ /// given routine of th. /// void Thread::internalThreadStart(mvm::Thread* th) { - th->baseSP = FRAME_PTR(); + th->baseSP = System::GetCallerAddress(); // Set the SIGSEGV handler to diagnose errors. struct sigaction sa; @@ -405,7 +386,7 @@ // Wait for the thread to die. pthread_join((pthread_t)thread_id, NULL); } - uintptr_t index = ((uintptr_t)th & Thread::IDMask); + uintptr_t index = ((uintptr_t)th & System::GetThreadIDMask()); index = (index & ~TheStackManager.baseAddr) >> 20; TheStackManager.used[index] = 0; } Modified: vmkit/trunk/lib/Mvm/Compiler/JIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Compiler/JIT.cpp?rev=139025&r1=139024&r2=139025&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Compiler/JIT.cpp (original) +++ vmkit/trunk/lib/Mvm/Compiler/JIT.cpp Fri Sep 2 14:23:21 2011 @@ -39,6 +39,7 @@ #include "mvm/JIT.h" #include "mvm/Threads/Locks.h" +#include "mvm/Threads/ObjectLocks.h" #include "mvm/Threads/Thread.h" #include "mvm/VirtualMachine.h" #include "mvm/GC/GC.h" @@ -303,17 +304,16 @@ constantDoubleMinusInfinity = ConstantFP::get(Type::getDoubleTy(Context), MinDouble); constantDoubleMinusZero = ConstantFP::get(Type::getDoubleTy(Context), -0.0); constantFloatMinusZero = ConstantFP::get(Type::getFloatTy(Context), -0.0f); - constantThreadIDMask = ConstantInt::get(pointerSizeType, mvm::Thread::IDMask); + constantThreadIDMask = ConstantInt::get(pointerSizeType, mvm::System::GetThreadIDMask()); constantStackOverflowMask = - ConstantInt::get(pointerSizeType, mvm::Thread::StackOverflowMask); - constantFatMask = ConstantInt::get(pointerSizeType, - pointerSizeType == Type::getInt32Ty(Context) ? 0x80000000 : 0x8000000000000000LL); + ConstantInt::get(pointerSizeType, Thread::StackOverflowMask); + constantFatMask = ConstantInt::get(pointerSizeType, ThinLock::FatMask); constantPtrOne = ConstantInt::get(pointerSizeType, 1); constantPtrZero = ConstantInt::get(pointerSizeType, 0); constantPtrNull = Constant::getNullValue(ptrType); constantPtrLogSize = - ConstantInt::get(Type::getInt32Ty(Context), sizeof(void*) == 8 ? 3 : 2); + ConstantInt::get(Type::getInt32Ty(Context), kWordSizeLog2); arrayPtrType = PointerType::getUnqual(ArrayType::get(Type::getInt8Ty(Context), 0)); printFloatLLVM = module->getFunction("printFloat"); @@ -403,7 +403,7 @@ frame->FrameSize = FI->getFrameSize(); frame->Metadata = meta; frame->SourceIndex = I->Loc.getLine(); - frame->ReturnAddress = reinterpret_cast(JCE->getLabelAddress(I->Label)); + frame->ReturnAddress = JCE->getLabelAddress(I->Label); int i = 0; for (llvm::GCFunctionInfo::live_iterator KI = FI->live_begin(I), KE = FI->live_end(I); KI != KE; ++KI) { Modified: vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp?rev=139025&r1=139024&r2=139025&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp (original) +++ vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp Fri Sep 2 14:23:21 2011 @@ -16,13 +16,12 @@ #include "MvmGC.h" #include -#include -using namespace mvm; +namespace mvm { -void MethodInfoHelper::scan(uintptr_t closure, FrameInfo* FI, void* ip, void* addr) { +void MethodInfoHelper::scan(uintptr_t closure, FrameInfo* FI, intptr_t ip, intptr_t addr) { //uintptr_t spaddr = (uintptr_t)addr + FI->FrameSize + sizeof(void*); - uintptr_t spaddr = ((uintptr_t*)addr)[0]; + uintptr_t spaddr = System::GetCallerOfAddress(addr); for (uint16 i = 0; i < FI->NumLiveOffsets; ++i) { intptr_t obj = *(intptr_t*)(spaddr + FI->LiveOffsets[i]); // Verify that obj does not come from a JSR bytecode. @@ -32,13 +31,13 @@ } } -void MethodInfoHelper::print(void* ip, void* addr) { +void MethodInfoHelper::print(intptr_t ip, intptr_t addr) { Dl_info info; - int res = dladdr(ip, &info); + int res = dladdr((void*)ip, &info); if (res != 0 && info.dli_sname != NULL) { - fprintf(stderr, "; %p (%p) in %s\n", ip, addr, info.dli_sname); + fprintf(stderr, "; %p (%p) in %s\n", (void*)ip, (void*)addr, info.dli_sname); } else { - fprintf(stderr, "; %p in Unknown method\n", ip); + fprintf(stderr, "; %p in Unknown method\n", (void*)ip); } } @@ -72,9 +71,9 @@ // Create a dummy FrameInfo, so that methods don't have to null check. static FrameInfo emptyInfo; -FrameInfo* FunctionMap::IPToFrameInfo(void* ip) { +FrameInfo* FunctionMap::IPToFrameInfo(intptr_t ip) { FunctionMapLock.acquire(); - llvm::DenseMap::iterator I = Functions.find(ip); + llvm::DenseMap::iterator I = Functions.find(ip); FrameInfo* res = NULL; if (I != Functions.end()) { res = I->second; @@ -88,8 +87,10 @@ } -void FunctionMap::addFrameInfo(void* ip, FrameInfo* meth) { +void FunctionMap::addFrameInfo(intptr_t ip, FrameInfo* meth) { FunctionMapLock.acquire(); addFrameInfoNoLock(ip, meth); FunctionMapLock.release(); } + +} Modified: vmkit/trunk/mmtk/mmtk-j3/Memory.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/mmtk-j3/Memory.cpp?rev=139025&r1=139024&r2=139025&view=diff ============================================================================== --- vmkit/trunk/mmtk/mmtk-j3/Memory.cpp (original) +++ vmkit/trunk/mmtk/mmtk-j3/Memory.cpp Fri Sep 2 14:23:21 2011 @@ -15,26 +15,14 @@ namespace mmtk { -#if defined (__MACH__) -static const uintptr_t MemoryStart = 0x30000000; -#else -static const uintptr_t MemoryStart = 0x50000000; -#endif - -static const uintptr_t MemorySize = 0x30000000; - 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, + void* baseAddr = mmap((void*)mvm::kGCMemoryStart, mvm::kGCMemorySize, PROT_READ | PROT_WRITE, flags, -1, 0); if (baseAddr == MAP_FAILED) { - perror("mmap"); + perror("mmap for GC memory"); abort(); } } @@ -44,11 +32,11 @@ InitCollector initCollector; extern "C" uintptr_t Java_org_j3_mmtk_Memory_getHeapStartConstant__ (MMTkObject* M) { - return MemoryStart; + return mvm::kGCMemoryStart; } extern "C" uintptr_t Java_org_j3_mmtk_Memory_getHeapEndConstant__ (MMTkObject* M) { - return MemoryStart + MemorySize; + return mvm::kGCMemoryStart + mvm::kGCMemorySize; } extern "C" uintptr_t Java_org_j3_mmtk_Memory_getAvailableStartConstant__ (MMTkObject* M) { Modified: vmkit/trunk/mmtk/mmtk-j3/ObjectModel.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/mmtk-j3/ObjectModel.cpp?rev=139025&r1=139024&r2=139025&view=diff ============================================================================== --- vmkit/trunk/mmtk/mmtk-j3/ObjectModel.cpp (original) +++ vmkit/trunk/mmtk/mmtk-j3/ObjectModel.cpp Fri Sep 2 14:23:21 2011 @@ -40,19 +40,11 @@ } extern "C" uint8_t Java_org_j3_mmtk_ObjectModel_readAvailableByte__Lorg_vmmagic_unboxed_ObjectReference_2 (MMTkObject* OM, gc* obj) { -#if defined(__PPC__) - return ((uint8_t*)obj)[2 * mvm::kWordSize - 1]; -#else - return ((uint8_t*)obj)[mvm::kWordSize]; -#endif + return *mvm::System::GetLastBytePtr(reinterpret_cast(obj)); } extern "C" void Java_org_j3_mmtk_ObjectModel_writeAvailableByte__Lorg_vmmagic_unboxed_ObjectReference_2B (MMTkObject* OM, gc* obj, uint8_t val) { -#if defined(__PPC__) - ((uint8_t*)obj)[2 * mvm::kWordSize - 1] = val; -#else - ((uint8_t*)obj)[mvm::kWordSize] = val; -#endif + *mvm::System::GetLastBytePtr(reinterpret_cast(obj)) = val; } extern "C" gc* Java_org_j3_mmtk_ObjectModel_getObjectFromStartAddress__Lorg_vmmagic_unboxed_Address_2 (MMTkObject* OM, gc* obj) { Modified: vmkit/trunk/mmtk/mmtk-j3/VM.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/mmtk-j3/VM.cpp?rev=139025&r1=139024&r2=139025&view=diff ============================================================================== --- vmkit/trunk/mmtk/mmtk-j3/VM.cpp (original) +++ vmkit/trunk/mmtk/mmtk-j3/VM.cpp Fri Sep 2 14:23:21 2011 @@ -64,15 +64,11 @@ } extern "C" bool Java_org_j3_runtime_VM_buildFor64Addr__ () { -#if (__WORDSIZE==64) - return true; -#else - return false; -#endif + return mvm::kWordSize == 8; } extern "C" bool Java_org_j3_runtime_VM_buildForIA32__ () { -#if defined(__i386__) || defined(i386) || defined(_M_IX86) +#if ARCH_X86 return true; #else return false; From nicolas.geoffray at lip6.fr Fri Sep 2 13:08:23 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Fri, 02 Sep 2011 20:08:23 -0000 Subject: [vmkit-commits] [vmkit] r139030 - /vmkit/trunk/include/mvm/System.h Message-ID: <20110902200823.921642A6C12C@llvm.org> Author: geoffray Date: Fri Sep 2 15:08:23 2011 New Revision: 139030 URL: http://llvm.org/viewvc/llvm-project?rev=139030&view=rev Log: Fix compilation warning. Modified: vmkit/trunk/include/mvm/System.h Modified: vmkit/trunk/include/mvm/System.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/System.h?rev=139030&r1=139029&r2=139030&view=diff ============================================================================== --- vmkit/trunk/include/mvm/System.h (original) +++ vmkit/trunk/include/mvm/System.h Fri Sep 2 15:08:23 2011 @@ -68,16 +68,16 @@ #define SETJMP _setjmp #define DYLD_EXTENSION ".dylib" #define SELF_HANDLE RTLD_DEFAULT - const intptr_t kGCMemoryStart = 0x30000000; + const uintptr_t kGCMemoryStart = 0x30000000; #else #define LONGJMP longjmp #define SETJMP setjmp #define DYLD_EXTENSION ".so" #define SELF_HANDLE 0 - const intptr_t kGCMemoryStart = 0x50000000; + const uintptr_t kGCMemoryStart = 0x50000000; #endif -static const intptr_t kGCMemorySize = 0x30000000; +static const uintptr_t kGCMemorySize = 0x30000000; #define TRY { mvm::ExceptionBuffer __buffer__; if (!SETJMP(__buffer__.buffer)) #define CATCH else From nicolas.geoffray at lip6.fr Sat Sep 3 05:56:24 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 03 Sep 2011 12:56:24 -0000 Subject: [vmkit-commits] [vmkit] r139081 - in /vmkit/trunk: include/mvm/System.h include/mvm/Threads/ObjectLocks.h lib/Mvm/CommonThread/ObjectLocks.cpp lib/Mvm/CommonThread/ctthread.cpp Message-ID: <20110903125624.2B96E2A6C12C@llvm.org> Author: geoffray Date: Sat Sep 3 07:56:23 2011 New Revision: 139081 URL: http://llvm.org/viewvc/llvm-project?rev=139081&view=rev Log: Support wider thread ID for Macos/x64. Also remove the sigsegv handler, which is not helping when debugging. Modified: vmkit/trunk/include/mvm/System.h vmkit/trunk/include/mvm/Threads/ObjectLocks.h vmkit/trunk/lib/Mvm/CommonThread/ObjectLocks.cpp vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp Modified: vmkit/trunk/include/mvm/System.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/System.h?rev=139081&r1=139080&r2=139081&view=diff ============================================================================== --- vmkit/trunk/include/mvm/System.h (original) +++ vmkit/trunk/include/mvm/System.h Sat Sep 3 07:56:23 2011 @@ -12,7 +12,6 @@ #include #include -#include #include #include @@ -53,10 +52,10 @@ -#if 0//def ARCH_X64 -const intptr_t kThreadStart = 0x110000000; -const intptr_t kThreadIDMask = 0xF7FF00000; -const uintptr_t kMvmThreadMask = 0xFF0000000; +#if MACOS_OS && ARCH_X64 +const intptr_t kThreadStart = 0x110000000LL; +const intptr_t kThreadIDMask = 0xF7FF00000LL; +const uintptr_t kMvmThreadMask = 0xFF0000000LL; #else const intptr_t kThreadStart = 0x10000000; const intptr_t kThreadIDMask = 0x7FF00000; @@ -68,16 +67,24 @@ #define SETJMP _setjmp #define DYLD_EXTENSION ".dylib" #define SELF_HANDLE RTLD_DEFAULT - const uintptr_t kGCMemoryStart = 0x30000000; #else #define LONGJMP longjmp #define SETJMP setjmp #define DYLD_EXTENSION ".so" #define SELF_HANDLE 0 +#endif + +#if MACOS_OS + #if ARCH_X64 + const uintptr_t kGCMemoryStart = 0x300000000LL; + #else + const uintptr_t kGCMemoryStart = 0x30000000; + #endif +#else const uintptr_t kGCMemoryStart = 0x50000000; #endif -static const uintptr_t kGCMemorySize = 0x30000000; +const uintptr_t kGCMemorySize = 0x30000000; #define TRY { mvm::ExceptionBuffer __buffer__; if (!SETJMP(__buffer__.buffer)) #define CATCH else Modified: vmkit/trunk/include/mvm/Threads/ObjectLocks.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Threads/ObjectLocks.h?rev=139081&r1=139080&r2=139081&view=diff ============================================================================== --- vmkit/trunk/include/mvm/Threads/ObjectLocks.h (original) +++ vmkit/trunk/include/mvm/Threads/ObjectLocks.h Sat Sep 3 07:56:23 2011 @@ -80,7 +80,7 @@ uintptr_t getID(); int tryAcquire() { return internalLock.tryLock(); } bool acquire(gc* object); - void acquireAll(gc* object, uint32_t count); + void acquireAll(gc* object, uintptr_t count); void release(gc* object, LockSystem& table); mvm::Thread* getOwner(); bool owner(); @@ -161,14 +161,14 @@ // 1 11 12 8 // fat lock thread id thin lock count + hash GC bits - static const uint64_t FatMask = 1 << 31; + static const uint64_t FatMask = 1LL << (kThreadStart > 0xFFFFFFFFLL ? 61LL : 31LL); static const uint32_t NonLockBits = HashBits + GCBits; - static const uint64_t NonLockBitsMask = ((1 << NonLockBits) - 1); + static const uint64_t NonLockBitsMask = ((1LL << NonLockBits) - 1LL); static const uint64_t ThinCountMask = ~(FatMask + kThreadIDMask + NonLockBitsMask); static const uint64_t ThinCountShift = NonLockBits; - static const uint64_t ThinCountAdd = 1 << NonLockBits; + static const uint64_t ThinCountAdd = 1LL << NonLockBits; /// initialise - Initialise the value of the lock. /// Modified: vmkit/trunk/lib/Mvm/CommonThread/ObjectLocks.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommonThread/ObjectLocks.cpp?rev=139081&r1=139080&r2=139081&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/CommonThread/ObjectLocks.cpp (original) +++ vmkit/trunk/lib/Mvm/CommonThread/ObjectLocks.cpp Sat Sep 3 07:56:23 2011 @@ -240,7 +240,7 @@ } } -void FatLock::acquireAll(gc* object, uint32 nb) { +void FatLock::acquireAll(gc* object, uintptr_t nb) { assert(associatedObject == object); llvm_gcroot(object, 0); internalLock.lockAll(nb); Modified: vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp?rev=139081&r1=139080&r2=139081&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp (original) +++ vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp Sat Sep 3 07:56:23 2011 @@ -318,8 +318,6 @@ /// machine specific. StackThreadManager TheStackManager; -extern void sigsegvHandler(int, siginfo_t*, void*); - /// internalThreadStart - The initial function called by a thread. Sets some /// thread specific data, registers the thread to the GC and calls the /// given routine of th. @@ -327,16 +325,6 @@ void Thread::internalThreadStart(mvm::Thread* th) { th->baseSP = System::GetCallerAddress(); - // Set the SIGSEGV handler to diagnose errors. - struct sigaction sa; - sigset_t mask; - sigfillset(&mask); - sa.sa_flags = SA_SIGINFO; - sa.sa_mask = mask; - sa.sa_sigaction = sigsegvHandler; - sigaction(SIGSEGV, &sa, NULL); - - assert(th->MyVM && "VM not set in a thread"); th->MyVM->rendezvous.addThread(th); th->routine(th); From nicolas.geoffray at lip6.fr Sat Sep 3 06:21:10 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 03 Sep 2011 13:21:10 -0000 Subject: [vmkit-commits] [vmkit] r139082 - /vmkit/trunk/Makefile.rules Message-ID: <20110903132110.661D32A6C12C@llvm.org> Author: geoffray Date: Sat Sep 3 08:21:10 2011 New Revision: 139082 URL: http://llvm.org/viewvc/llvm-project?rev=139082&view=rev Log: disable CFI when using LLC. Modified: vmkit/trunk/Makefile.rules Modified: vmkit/trunk/Makefile.rules URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/Makefile.rules?rev=139082&r1=139081&r2=139082&view=diff ============================================================================== --- vmkit/trunk/Makefile.rules (original) +++ vmkit/trunk/Makefile.rules Sat Sep 3 08:21:10 2011 @@ -44,7 +44,7 @@ glibj.zip.s : glibj-optimized.zip.bc $(Echo) "Compiling glibj.zip.bc to native" - $(Verb) $(LLC) -relocation-model=pic -disable-fp-elim glibj-optimized.zip.bc -o glibj.zip.s + $(Verb) $(LLC) -disable-cfi -relocation-model=pic -disable-fp-elim glibj-optimized.zip.bc -o glibj.zip.s $(ObjDir)/%.o: %.s $(ObjDir)/.dir $(BUILT_SOURCES) $(Echo) "Compiling $*.s for $(BuildMode) build" $(PIC_FLAG) @@ -108,7 +108,7 @@ $(ObjectsSWithGC): $(ObjDir)/%_gc.s: $(ObjDir)/%_gc.bc $(LLC) $(Echo) "Compiling $*.bc to $*.s for $(BuildMode) build" - $(Verb) $(LLC) -disable-fp-elim -load=$(LibDir)/StaticGCPrinter$(SHLIBEXT) $< -o $@ + $(Verb) $(LLC) -disable-cfi -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) From nicolas.geoffray at lip6.fr Sat Sep 3 09:26:58 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 03 Sep 2011 16:26:58 -0000 Subject: [vmkit-commits] [vmkit] r139083 - /vmkit/trunk/lib/J3/VMCore/JavaClass.h Message-ID: <20110903162658.612BA2A6C12C@llvm.org> Author: geoffray Date: Sat Sep 3 11:26:58 2011 New Revision: 139083 URL: http://llvm.org/viewvc/llvm-project?rev=139083&view=rev Log: A class does not have to be resolved to get the pointer of a static field. Modified: vmkit/trunk/lib/J3/VMCore/JavaClass.h Modified: vmkit/trunk/lib/J3/VMCore/JavaClass.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaClass.h?rev=139083&r1=139082&r2=139083&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaClass.h (original) +++ vmkit/trunk/lib/J3/VMCore/JavaClass.h Sat Sep 3 11:26:58 2011 @@ -1155,7 +1155,7 @@ Attribut* lookupAttribut(const UTF8* key); JavaObject** getStaticObjectFieldPtr() { - assert(classDef->isResolved()); + assert(classDef->getStaticInstance()); return (JavaObject**)((uint64)classDef->getStaticInstance() + ptrOffset); } From nicolas.geoffray at lip6.fr Sun Sep 4 02:19:51 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 04 Sep 2011 09:19:51 -0000 Subject: [vmkit-commits] [vmkit] r139089 - /vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp Message-ID: <20110904091951.A266C2A6C12C@llvm.org> Author: geoffray Date: Sun Sep 4 04:19:51 2011 New Revision: 139089 URL: http://llvm.org/viewvc/llvm-project?rev=139089&view=rev Log: Remove asserts from critical path. Add comment. Modified: vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp Modified: vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp?rev=139089&r1=139088&r2=139089&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp Sun Sep 4 04:19:51 2011 @@ -694,10 +694,6 @@ extern "C" void* j3ResolveInterface(JavaObject* obj, JavaMethod* meth, uint32_t index) { uintptr_t result = NULL; InterfaceMethodTable* IMT = JavaObject::getClass(obj)->virtualVT->IMT; - assert(JavaObject::instanceOf(obj, meth->classDef)); - assert(meth->classDef->isInterface() || - (meth->classDef == meth->classDef->classLoader->bootstrapLoader->upcalls->OfObject)); - assert(index == InterfaceMethodTable::getIndex(meth->name, meth->type)); if ((IMT->contents[index] & 1) == 0) { result = IMT->contents[index]; } else { @@ -707,7 +703,15 @@ assert(table[i] != 0); result = table[i + 1]; } - assert((result != 0) && "Bad IMT"); + // TODO(ngeoffray): This code is too performance critical to get asserts. + // Ideally, it would be inlined by the compiler, so this method is + // only for debugging. + // + // assert(JavaObject::instanceOf(obj, meth->classDef)); + // assert(meth->classDef->isInterface() || + // (meth->classDef == meth->classDef->classLoader->bootstrapLoader->upcalls->OfObject)); + // assert(index == InterfaceMethodTable::getIndex(meth->name, meth->type)); + // assert((result != 0) && "Bad IMT"); return (void*)result; } From nicolas.geoffray at lip6.fr Sun Sep 4 02:48:02 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 04 Sep 2011 09:48:02 -0000 Subject: [vmkit-commits] [vmkit] r139091 - /vmkit/trunk/mmtk/java/src/org/j3/options/OptionSet.java Message-ID: <20110904094802.4FB822A6C12C@llvm.org> Author: geoffray Date: Sun Sep 4 04:48:02 2011 New Revision: 139091 URL: http://llvm.org/viewvc/llvm-project?rev=139091&view=rev Log: Support hexa integers. Modified: vmkit/trunk/mmtk/java/src/org/j3/options/OptionSet.java Modified: vmkit/trunk/mmtk/java/src/org/j3/options/OptionSet.java URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/java/src/org/j3/options/OptionSet.java?rev=139091&r1=139090&r2=139091&view=diff ============================================================================== --- vmkit/trunk/mmtk/java/src/org/j3/options/OptionSet.java (original) +++ vmkit/trunk/mmtk/java/src/org/j3/options/OptionSet.java Sun Sep 4 04:48:02 2011 @@ -275,6 +275,12 @@ case '7': value += 7; break; case '8': value += 8; break; case '9': value += 9; break; + case 'a': value += 0xa; break; + case 'b': value += 0xb; break; + case 'c': value += 0xc; break; + case 'd': value += 0xd; break; + case 'e': value += 0xe; break; + case 'f': value += 0xf; break; default: return -1; } From nicolas.geoffray at lip6.fr Sun Sep 4 05:18:23 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 04 Sep 2011 12:18:23 -0000 Subject: [vmkit-commits] [vmkit] r139098 - in /vmkit/trunk: include/mvm/MethodInfo.h lib/Mvm/CommonThread/ObjectLocks.cpp lib/Mvm/Runtime/MethodInfo.cpp Message-ID: <20110904121823.7087C2A6C12C@llvm.org> Author: geoffray Date: Sun Sep 4 07:18:23 2011 New Revision: 139098 URL: http://llvm.org/viewvc/llvm-project?rev=139098&view=rev Log: Bugfixes in the frametable iterator: on x64 not all frames were registered due to alignment problems. Modified: vmkit/trunk/include/mvm/MethodInfo.h vmkit/trunk/lib/Mvm/CommonThread/ObjectLocks.cpp 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=139098&r1=139097&r2=139098&view=diff ============================================================================== --- vmkit/trunk/include/mvm/MethodInfo.h (original) +++ vmkit/trunk/include/mvm/MethodInfo.h Sun Sep 4 07:18:23 2011 @@ -61,7 +61,7 @@ uint32_t NumCompiledFrames; Frames* frames() const { return reinterpret_cast( - reinterpret_cast(this) + sizeof(CompiledFrames)); + reinterpret_cast(this) + kWordSize); } }; Modified: vmkit/trunk/lib/Mvm/CommonThread/ObjectLocks.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommonThread/ObjectLocks.cpp?rev=139098&r1=139097&r2=139098&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/CommonThread/ObjectLocks.cpp (original) +++ vmkit/trunk/lib/Mvm/CommonThread/ObjectLocks.cpp Sun Sep 4 07:18:23 2011 @@ -429,6 +429,7 @@ varcondThread.wait(&l->internalLock); } } + assert(mvm::ThinLock::owner(self, table) && "Not owner after wait"); l->waitingThreads--; Modified: vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp?rev=139098&r1=139097&r2=139098&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp (original) +++ vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp Sun Sep 4 07:18:23 2011 @@ -61,8 +61,8 @@ currentFrames = reinterpret_cast( reinterpret_cast(frame) + MethodInfoHelper::FrameInfoSize(frame->NumLiveOffsets)); } else { - currentFrames = reinterpret_cast( - reinterpret_cast(currentFrames) + sizeof(Frames)); + currentFrames = reinterpret_cast(System::WordAlignUp( + reinterpret_cast(currentFrames) + sizeof(Frames))); } } } From nicolas.geoffray at lip6.fr Sun Sep 4 06:20:25 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 04 Sep 2011 13:20:25 -0000 Subject: [vmkit-commits] [vmkit] r139099 - in /vmkit/trunk/lib/J3: Classpath/JavaUpcalls.cpp Compiler/JavaJIT.cpp Compiler/JavaJIT.h VMCore/Jnjvm.cpp VMCore/JnjvmClassLoader.cpp VMCore/JnjvmClassLoader.h Message-ID: <20110904132025.D23712A6C12C@llvm.org> Author: geoffray Date: Sun Sep 4 08:20:25 2011 New Revision: 139099 URL: http://llvm.org/viewvc/llvm-project?rev=139099&view=rev Log: Intrinsify some VMFloat and BMDouble methods. Modified: vmkit/trunk/lib/J3/Classpath/JavaUpcalls.cpp vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp vmkit/trunk/lib/J3/Compiler/JavaJIT.h 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/Classpath/JavaUpcalls.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Classpath/JavaUpcalls.cpp?rev=139099&r1=139098&r2=139099&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Classpath/JavaUpcalls.cpp (original) +++ vmkit/trunk/lib/J3/Classpath/JavaUpcalls.cpp Sun Sep 4 08:20:25 2011 @@ -746,6 +746,9 @@ UPCALL_METHOD(loader, "java/lang/Class", "isArray", "()Z", ACC_VIRTUAL); isArray->setNative(); + // Make sure classes the JIT optimizes on are loaded. + UPCALL_CLASS(loader, "java/lang/VMFloat"); + UPCALL_CLASS(loader, "java/lang/VMDouble"); UPCALL_REFLECT_CLASS_EXCEPTION(loader, InvocationTargetException); UPCALL_CLASS_EXCEPTION(loader, ArrayStoreException); Modified: vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp?rev=139099&r1=139098&r2=139099&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp Sun Sep 4 08:20:25 2011 @@ -1451,7 +1451,29 @@ } return 0; +} + + +Instruction* JavaJIT::lowerFloatOps(const UTF8* name, + std::vector& args) { + JnjvmBootstrapLoader* loader = compilingClass->classLoader->bootstrapLoader; + if (name->equals(loader->floatToRawIntBits)) { + return new BitCastInst(args[0], Type::getInt32Ty(*llvmContext), "", currentBlock); + } else if (name->equals(loader->intBitsToFloat)) { + return new BitCastInst(args[0], Type::getFloatTy(*llvmContext), "", currentBlock); + } + return NULL; +} +Instruction* JavaJIT::lowerDoubleOps(const UTF8* name, + std::vector& args) { + JnjvmBootstrapLoader* loader = compilingClass->classLoader->bootstrapLoader; + if (name->equals(loader->doubleToRawLongBits)) { + return new BitCastInst(args[0], Type::getInt64Ty(*llvmContext), "", currentBlock); + } else if (name->equals(loader->longBitsToDouble)) { + return new BitCastInst(args[0], Type::getDoubleTy(*llvmContext), "", currentBlock); + } + return NULL; } @@ -1573,6 +1595,10 @@ if (className->equals(loader->mathName)) { val = lowerMathOps(name, args); + } else if (className->equals(loader->VMFloatName)) { + val = lowerFloatOps(name, args); + } else if (className->equals(loader->VMDoubleName)) { + val = lowerDoubleOps(name, args); } if (val == NULL) { Modified: vmkit/trunk/lib/J3/Compiler/JavaJIT.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJIT.h?rev=139099&r1=139098&r2=139099&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJIT.h (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJIT.h Sun Sep 4 08:20:25 2011 @@ -486,6 +486,10 @@ /// lowerMathOps - Map Java Math operations to LLVM intrinsics. llvm::Instruction* lowerMathOps(const UTF8* name, std::vector& args); + llvm::Instruction* lowerFloatOps(const UTF8* name, + std::vector& args); + llvm::Instruction* lowerDoubleOps(const UTF8* name, + std::vector& args); /// lowerArraycopy - Create a fast path for System.arraycopy. void lowerArraycopy(std::vector& args); Modified: vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp?rev=139099&r1=139098&r2=139099&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp Sun Sep 4 08:20:25 2011 @@ -1053,7 +1053,7 @@ JavaObject* javaLoader = NULL; llvm_gcroot(obj, 0); llvm_gcroot(javaLoader, 0); - JnjvmClassLoader* loader = bootstrapLoader; + JnjvmBootstrapLoader* loader = bootstrapLoader; // First create system threads. finalizerThread = new FinalizerThread(this); @@ -1159,8 +1159,7 @@ obj, &javaLoader); // load and initialise math since it is responsible for dlopen'ing // libjavalang.so and we are optimizing some math operations - UserCommonClass* math = loader->loadName( - loader->asciizConstructUTF8("java/lang/Math"), true, true, NULL); + UserCommonClass* math = loader->loadName(loader->mathName, true, true, NULL); math->asClass()->initialiseClass(this); } Modified: vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp?rev=139099&r1=139098&r2=139099&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp Sun Sep 4 08:20:25 2011 @@ -164,6 +164,8 @@ prelib = asciizConstructUTF8("lib"); postlib = asciizConstructUTF8(mvm::System::GetDyLibExtension()); mathName = asciizConstructUTF8("java/lang/Math"); + VMFloatName = asciizConstructUTF8("java/lang/VMFloat"); + VMDoubleName = asciizConstructUTF8("java/lang/VMDouble"); stackWalkerName = asciizConstructUTF8("gnu/classpath/VMStackWalker"); NoClassDefFoundError = asciizConstructUTF8("java/lang/NoClassDefFoundError"); @@ -194,6 +196,10 @@ DEF_UTF8(sinh); DEF_UTF8(tanh); DEF_UTF8(finalize); + DEF_UTF8(floatToRawIntBits); + DEF_UTF8(doubleToRawLongBits); + DEF_UTF8(intBitsToFloat); + DEF_UTF8(longBitsToDouble); #undef DEF_UTF8 } Modified: vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h?rev=139099&r1=139098&r2=139099&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h (original) +++ vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h Sun Sep 4 08:20:25 2011 @@ -373,6 +373,8 @@ const UTF8* prelib; const UTF8* postlib; const UTF8* mathName; + const UTF8* VMFloatName; + const UTF8* VMDoubleName; const UTF8* stackWalkerName; const UTF8* abs; const UTF8* sqrt; @@ -398,6 +400,10 @@ const UTF8* sinh; const UTF8* tanh; const UTF8* finalize; + const UTF8* floatToRawIntBits; + const UTF8* doubleToRawLongBits; + const UTF8* intBitsToFloat; + const UTF8* longBitsToDouble; /// primitiveMap - Map of primitive classes, hashed by id. std::map primitiveMap; From nicolas.geoffray at lip6.fr Sun Sep 4 09:34:07 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 04 Sep 2011 16:34:07 -0000 Subject: [vmkit-commits] [vmkit] r139100 - /vmkit/trunk/mmtk/mmtk-j3/ActivePlan.cpp Message-ID: <20110904163407.569102A6C12C@llvm.org> Author: geoffray Date: Sun Sep 4 11:34:07 2011 New Revision: 139100 URL: http://llvm.org/viewvc/llvm-project?rev=139100&view=rev Log: Implement ActivePlan.collectorCount. Modified: vmkit/trunk/mmtk/mmtk-j3/ActivePlan.cpp Modified: vmkit/trunk/mmtk/mmtk-j3/ActivePlan.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/mmtk-j3/ActivePlan.cpp?rev=139100&r1=139099&r2=139100&view=diff ============================================================================== --- vmkit/trunk/mmtk/mmtk-j3/ActivePlan.cpp (original) +++ vmkit/trunk/mmtk/mmtk-j3/ActivePlan.cpp Sun Sep 4 11:34:07 2011 @@ -36,8 +36,9 @@ A->current = NULL; } -extern "C" void Java_org_j3_mmtk_ActivePlan_collectorCount__ (MMTkActivePlan* A) { - UNIMPLEMENTED(); +extern "C" int Java_org_j3_mmtk_ActivePlan_collectorCount__ (MMTkActivePlan* A) { + // We do not support parallel GC yet. + return 1; } } From willdtz at gmail.com Sun Sep 4 21:48:57 2011 From: willdtz at gmail.com (Will Dietz) Date: Sun, 4 Sep 2011 23:48:57 -0500 Subject: [vmkit-commits] Processor count support Message-ID: Hi, While using vmkit (thanks for getting it working on 64bit again, by the way!), I encountered a desire to have vmkit report the proper number of processors. Attached is the small/trivial fix for this, just in case that's useful/saves you the bother. ~Will -------------- next part -------------- A non-text attachment was scrubbed... Name: 0001-Fix-host-processor-count-detection.patch Type: application/octet-stream Size: 722 bytes Desc: not available URL: From nicolas.geoffray at lip6.fr Mon Sep 5 10:53:26 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Mon, 05 Sep 2011 17:53:26 -0000 Subject: [vmkit-commits] [vmkit] r139119 - in /vmkit/trunk: include/mvm/System.h lib/J3/Classpath/ClasspathVMRuntime.inc Message-ID: <20110905175326.2D7D02A6C12C@llvm.org> Author: geoffray Date: Mon Sep 5 12:53:25 2011 New Revision: 139119 URL: http://llvm.org/viewvc/llvm-project?rev=139119&view=rev Log: Detect the number of processors. Patch (derived) from Will Dietz! Modified: vmkit/trunk/include/mvm/System.h vmkit/trunk/lib/J3/Classpath/ClasspathVMRuntime.inc Modified: vmkit/trunk/include/mvm/System.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/System.h?rev=139119&r1=139118&r2=139119&view=diff ============================================================================== --- vmkit/trunk/include/mvm/System.h (original) +++ vmkit/trunk/include/mvm/System.h Mon Sep 5 12:53:25 2011 @@ -14,6 +14,7 @@ #include #include #include +#include namespace mvm { @@ -62,7 +63,7 @@ const intptr_t kMvmThreadMask = 0xF0000000; #endif -#if defined(MACOS_OS) +#if MACOS_OS #define LONGJMP _longjmp #define SETJMP _setjmp #define DYLD_EXTENSION ".dylib" @@ -198,6 +199,10 @@ return ((uint8_t*)ptr) + mvm::kWordSize; #endif } + + static int GetNumberOfProcessors() { + return sysconf(_SC_NPROCESSORS_ONLN); + } }; } Modified: vmkit/trunk/lib/J3/Classpath/ClasspathVMRuntime.inc URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Classpath/ClasspathVMRuntime.inc?rev=139119&r1=139118&r2=139119&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Classpath/ClasspathVMRuntime.inc (original) +++ vmkit/trunk/lib/J3/Classpath/ClasspathVMRuntime.inc Mon Sep 5 12:53:25 2011 @@ -223,7 +223,7 @@ JNIEnv *env, jclass clazz, #endif - return 1; + return mvm::System::GetNumberOfProcessors(); } } From nicolas.geoffray at gmail.com Mon Sep 5 10:55:32 2011 From: nicolas.geoffray at gmail.com (Nicolas Geoffray) Date: Mon, 5 Sep 2011 19:55:32 +0200 Subject: [vmkit-commits] Processor count support In-Reply-To: References: Message-ID: Thanks Will! (Slightly modified) patch applied! http://lists.cs.uiuc.edu/pipermail/vmkit-commits/2011-September/002130.html On Mon, Sep 5, 2011 at 6:48 AM, Will Dietz wrote: > Hi, > > While using vmkit (thanks for getting it working on 64bit again, by > the way!), I encountered a desire to have vmkit report the proper > number of processors. > > Attached is the small/trivial fix for this, just in case that's > useful/saves you the bother. > > ~Will > > _______________________________________________ > vmkit-commits mailing list > vmkit-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/vmkit-commits > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nicolas.geoffray at lip6.fr Mon Sep 5 11:48:20 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Mon, 05 Sep 2011 18:48:20 -0000 Subject: [vmkit-commits] [vmkit] r139123 - /vmkit/trunk/include/mvm/Threads/ObjectLocks.h Message-ID: <20110905184820.1A0B62A6C12C@llvm.org> Author: geoffray Date: Mon Sep 5 13:48:19 2011 New Revision: 139123 URL: http://llvm.org/viewvc/llvm-project?rev=139123&view=rev Log: Fix mask for ThinCount on x64. Modified: vmkit/trunk/include/mvm/Threads/ObjectLocks.h Modified: vmkit/trunk/include/mvm/Threads/ObjectLocks.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Threads/ObjectLocks.h?rev=139123&r1=139122&r2=139123&view=diff ============================================================================== --- vmkit/trunk/include/mvm/Threads/ObjectLocks.h (original) +++ vmkit/trunk/include/mvm/Threads/ObjectLocks.h Mon Sep 5 13:48:19 2011 @@ -166,7 +166,7 @@ static const uint32_t NonLockBits = HashBits + GCBits; static const uint64_t NonLockBitsMask = ((1LL << NonLockBits) - 1LL); - static const uint64_t ThinCountMask = ~(FatMask + kThreadIDMask + NonLockBitsMask); + static const uint32_t ThinCountMask = ~((1 << 31) + kThreadIDMask + NonLockBitsMask); static const uint64_t ThinCountShift = NonLockBits; static const uint64_t ThinCountAdd = 1LL << NonLockBits; From nicolas.geoffray at lip6.fr Tue Sep 6 10:28:39 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Tue, 06 Sep 2011 17:28:39 -0000 Subject: [vmkit-commits] [vmkit] r139146 - in /vmkit/trunk/lib/J3: Classpath/ClasspathVMClassLoader.inc Compiler/JavaJIT.cpp Compiler/JavaJIT.h Compiler/JavaJITOpcodes.cpp VMCore/JavaClass.cpp Message-ID: <20110906172839.F10C72A6C12C@llvm.org> Author: geoffray Date: Tue Sep 6 12:28:39 2011 New Revision: 139146 URL: http://llvm.org/viewvc/llvm-project?rev=139146&view=rev Log: Fix off by one line tester, NPEs check and guard against segfault in defineClass. Modified: vmkit/trunk/lib/J3/Classpath/ClasspathVMClassLoader.inc vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp vmkit/trunk/lib/J3/Compiler/JavaJIT.h vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp vmkit/trunk/lib/J3/VMCore/JavaClass.cpp Modified: vmkit/trunk/lib/J3/Classpath/ClasspathVMClassLoader.inc URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Classpath/ClasspathVMClassLoader.inc?rev=139146&r1=139145&r2=139146&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Classpath/ClasspathVMClassLoader.inc (original) +++ vmkit/trunk/lib/J3/Classpath/ClasspathVMClassLoader.inc Tue Sep 6 12:28:39 2011 @@ -129,6 +129,9 @@ llvm_gcroot(excp, 0); BEGIN_NATIVE_EXCEPTION(0) + + // We need a name, which is unfortunately not required by the spec. + verifyNull(str); Jnjvm* vm = JavaThread::get()->getJVM(); Modified: vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp?rev=139146&r1=139145&r2=139146&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp Tue Sep 6 12:28:39 2011 @@ -1272,8 +1272,10 @@ } Value* JavaJIT::verifyAndComputePtr(Value* obj, Value* index, - Type* arrayType, bool verif) { - JITVerifyNull(obj); + Type* arrayType, bool doNullCheck) { + if (doNullCheck) { + JITVerifyNull(obj); + } if (index->getType() != Type::getInt32Ty(*llvmContext)) { index = new SExtInst(index, Type::getInt32Ty(*llvmContext), "", currentBlock); @@ -1813,6 +1815,7 @@ if (!stat) { object = new LoadInst( object, "", TheCompiler->useCooperativeGC(), currentBlock); + JITVerifyNull(object); Value* tmp = new BitCastInst(object, Pty, "", currentBlock); Value* args[2] = { zero, ptr }; ptr = GetElementPtrInst::Create(tmp, args, "", currentBlock); Modified: vmkit/trunk/lib/J3/Compiler/JavaJIT.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJIT.h?rev=139146&r1=139145&r2=139146&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJIT.h (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJIT.h Tue Sep 6 12:28:39 2011 @@ -220,7 +220,7 @@ /// throw an exception. llvm::Value* verifyAndComputePtr(llvm::Value* obj, llvm::Value* index, llvm::Type* arrayType, - bool verif = true); + bool doNullCheck = true); /// compareFP - Do float comparisons. void compareFP(llvm::Value*, llvm::Value*, llvm::Type*, bool l); Modified: vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp?rev=139146&r1=139145&r2=139146&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp Tue Sep 6 12:28:39 2011 @@ -686,6 +686,7 @@ Value* obj = new LoadInst(objectStack[currentStackIndex - 3], "", TheCompiler->useCooperativeGC(), currentBlock); + JITVerifyNull(obj); Value* cmp = new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, val, intrinsics->JavaObjectNullConstant, ""); @@ -720,7 +721,7 @@ Value* index = pop(); Value* obj = pop(); Value* ptr = verifyAndComputePtr(obj, index, - intrinsics->JavaArrayObjectType); + intrinsics->JavaArrayObjectType, false); if (mvm::Collector::needsWriteBarrier()) { ptr = new BitCastInst(ptr, intrinsics->ptrPtrType, "", currentBlock); val = new BitCastInst(val, intrinsics->ptrType, "", currentBlock); Modified: vmkit/trunk/lib/J3/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaClass.cpp?rev=139146&r1=139145&r2=139146&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JavaClass.cpp Tue Sep 6 12:28:39 2011 @@ -1717,7 +1717,7 @@ uint16_t currentLine = 0; for (uint16 j = 0; j < lineLength; ++j) { uint16 pc = reader.readU2(); - if (pc > info->SourceIndex + 1) return currentLine; + if (pc > info->SourceIndex) return currentLine; currentLine = reader.readU2(); } return currentLine; From willdtz at gmail.com Thu Sep 8 20:25:48 2011 From: willdtz at gmail.com (Will Dietz) Date: Thu, 8 Sep 2011 22:25:48 -0500 Subject: [vmkit-commits] [PATCH] Fix infinite loop in zip.cpp Message-ID: Hi, Attached is a patch that fixes an infinite loop in Zip.cpp when processing some archives. Looks like what was intended anyway :). ~Will -------------- next part -------------- A non-text attachment was scrubbed... Name: 0001-Fix-infinite-loop-in-Zip-processing.patch Type: application/octet-stream Size: 617 bytes Desc: not available URL: From nicolas.geoffray at lip6.fr Sat Sep 10 02:28:26 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 10 Sep 2011 09:28:26 -0000 Subject: [vmkit-commits] [vmkit] r139469 - in /vmkit/trunk: include/mvm/System.h include/mvm/Threads/ObjectLocks.h lib/J3/Classpath/Classpath.inc lib/J3/Classpath/ClasspathVMClass.inc lib/J3/VMCore/JavaClass.cpp lib/J3/VMCore/JnjvmClassLoader.cpp lib/Mvm/Runtime/UTF8.cpp Message-ID: <20110910092826.992B72A6C12C@llvm.org> Author: geoffray Date: Sat Sep 10 04:28:26 2011 New Revision: 139469 URL: http://llvm.org/viewvc/llvm-project?rev=139469&view=rev Log: - Small bugfixes here and there. - X64 archs now always have the same thread start address. Modified: vmkit/trunk/include/mvm/System.h vmkit/trunk/include/mvm/Threads/ObjectLocks.h vmkit/trunk/lib/J3/Classpath/Classpath.inc vmkit/trunk/lib/J3/Classpath/ClasspathVMClass.inc vmkit/trunk/lib/J3/VMCore/JavaClass.cpp vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp vmkit/trunk/lib/Mvm/Runtime/UTF8.cpp Modified: vmkit/trunk/include/mvm/System.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/System.h?rev=139469&r1=139468&r2=139469&view=diff ============================================================================== --- vmkit/trunk/include/mvm/System.h (original) +++ vmkit/trunk/include/mvm/System.h Sat Sep 10 04:28:26 2011 @@ -53,13 +53,13 @@ -#if MACOS_OS && ARCH_X64 -const intptr_t kThreadStart = 0x110000000LL; -const intptr_t kThreadIDMask = 0xF7FF00000LL; -const uintptr_t kMvmThreadMask = 0xFF0000000LL; +#if ARCH_X64 +const intptr_t kThreadStart = 0x0000000110000000LL; +const intptr_t kThreadIDMask = 0xFFFFFFFFFFF00000LL; +const intptr_t kMvmThreadMask = 0xFFFFFFFFF0000000LL; #else -const intptr_t kThreadStart = 0x10000000; -const intptr_t kThreadIDMask = 0x7FF00000; +const intptr_t kThreadStart = 0x10000000; +const intptr_t kThreadIDMask = 0x7FF00000; const intptr_t kMvmThreadMask = 0xF0000000; #endif Modified: vmkit/trunk/include/mvm/Threads/ObjectLocks.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Threads/ObjectLocks.h?rev=139469&r1=139468&r2=139469&view=diff ============================================================================== --- vmkit/trunk/include/mvm/Threads/ObjectLocks.h (original) +++ vmkit/trunk/include/mvm/Threads/ObjectLocks.h Sat Sep 10 04:28:26 2011 @@ -163,10 +163,10 @@ static const uint64_t FatMask = 1LL << (kThreadStart > 0xFFFFFFFFLL ? 61LL : 31LL); - static const uint32_t NonLockBits = HashBits + GCBits; + static const uint64_t NonLockBits = HashBits + GCBits; static const uint64_t NonLockBitsMask = ((1LL << NonLockBits) - 1LL); - static const uint32_t ThinCountMask = ~((1 << 31) + kThreadIDMask + NonLockBitsMask); + static const uint64_t ThinCountMask = 0xFFFFFFFFLL & ~(FatMask | kThreadIDMask | NonLockBitsMask); static const uint64_t ThinCountShift = NonLockBits; static const uint64_t ThinCountAdd = 1LL << NonLockBits; Modified: vmkit/trunk/lib/J3/Classpath/Classpath.inc URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Classpath/Classpath.inc?rev=139469&r1=139468&r2=139469&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Classpath/Classpath.inc (original) +++ vmkit/trunk/lib/J3/Classpath/Classpath.inc Sat Sep 10 04:28:26 2011 @@ -260,6 +260,12 @@ UserCommonClass::resolvedImplClass(vm, arrayType, true); JnjvmClassLoader* loader = base->classLoader; const UTF8* name = base->getName(); + // -1 because we're adding a new dimension in this method. + const int kLimit = 255 - 1; + const uint16* elements = name->elements; + if (name->size > kLimit && elements[kLimit] == '[') { + vm->illegalArgumentException("Too many dimensions for array"); + } const UTF8* arrayName = loader->constructArrayName(1, name); UserClassArray* array = loader->constructArray(arrayName, base); res = array->doNew(arrayLength, vm); Modified: vmkit/trunk/lib/J3/Classpath/ClasspathVMClass.inc URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Classpath/ClasspathVMClass.inc?rev=139469&r1=139468&r2=139469&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Classpath/ClasspathVMClass.inc (original) +++ vmkit/trunk/lib/J3/Classpath/ClasspathVMClass.inc Sat Sep 10 04:28:26 2011 @@ -63,7 +63,7 @@ JnjvmClassLoader::getJnjvmLoaderFromJavaObject(loader, vm); UserCommonClass* cl = JCL->loadClassFromJavaString(str, true, false); - if (cl != 0) { + if (cl != NULL && !cl->isPrimitive()) { if (clinit && cl->asClass()) { cl->asClass()->initialiseClass(vm); } Modified: vmkit/trunk/lib/J3/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaClass.cpp?rev=139469&r1=139468&r2=139469&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JavaClass.cpp Sat Sep 10 04:28:26 2011 @@ -1594,27 +1594,7 @@ // Put Cloneable[...] and Serializable[...] at the end of the list. secondaryTypes[index] = firstInterface->virtualVT; secondaryTypes[index + 1] = secondInterface->virtualVT; - - // If the depth is greater than the display size, - // Cloneable[...] and Serializable[...] have their own list of - // secondary types, and we must therefore tell them that they - // implement themselves. - // If the depth is less than than the display size, there is nothing - // to do: the array of secondary types has been created before loading - // the interface arrays, so the interface arrays already reference - // the array. - if (outOfDepth) { - firstInterface->virtualVT->secondaryTypes[index] = - firstInterface->virtualVT; - firstInterface->virtualVT->secondaryTypes[index + 1] = - secondInterface->virtualVT; - secondInterface->virtualVT->secondaryTypes[index] = - firstInterface->virtualVT; - secondInterface->virtualVT->secondaryTypes[index + 1] = - secondInterface->virtualVT; - } } - } else { // This is java.lang.Object[]. depth = 1; Modified: vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp?rev=139469&r1=139468&r2=139469&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp Sat Sep 10 04:28:26 2011 @@ -316,9 +316,8 @@ cl = JavaObjectClass::getClass(((JavaObjectClass*)obj)); } - if (cl) { - assert(!cl->isArray()); - if (doResolve) cl->asClass()->resolveClass(); + if (cl && doResolve && cl->isClass()) { + cl->asClass()->resolveClass(); } return (UserClass*)cl; Modified: vmkit/trunk/lib/Mvm/Runtime/UTF8.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/UTF8.cpp?rev=139469&r1=139468&r2=139469&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Runtime/UTF8.cpp (original) +++ vmkit/trunk/lib/Mvm/Runtime/UTF8.cpp Sat Sep 10 04:28:26 2011 @@ -12,8 +12,8 @@ namespace mvm { -extern "C" const UTF8 TombstoneKey(0); -extern "C" const UTF8 EmptyKey(0); +extern "C" const UTF8 TombstoneKey(-1); +extern "C" const UTF8 EmptyKey(-1); const UTF8* UTF8::extract(UTF8Map* map, uint32 start, uint32 end) const { From nicolas.geoffray at lip6.fr Sat Sep 10 03:02:08 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 10 Sep 2011 10:02:08 -0000 Subject: [vmkit-commits] [vmkit] r139471 - /vmkit/trunk/lib/J3/VMCore/Zip.cpp Message-ID: <20110910100208.D8BFC2A6C12C@llvm.org> Author: geoffray Date: Sat Sep 10 05:02:08 2011 New Revision: 139471 URL: http://llvm.org/viewvc/llvm-project?rev=139471&view=rev Log: Fix infinite loop in zip file parsing. Patch by Will Dietz! Modified: vmkit/trunk/lib/J3/VMCore/Zip.cpp Modified: vmkit/trunk/lib/J3/VMCore/Zip.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Zip.cpp?rev=139471&r1=139470&r2=139471&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/Zip.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/Zip.cpp Sat Sep 10 05:02:08 2011 @@ -110,6 +110,7 @@ this->ofscd = readEndianDep4(reader); return; } + searchPtr--; } } } From nicolas.geoffray at gmail.com Sat Sep 10 03:04:30 2011 From: nicolas.geoffray at gmail.com (Nicolas Geoffray) Date: Sat, 10 Sep 2011 12:04:30 +0200 Subject: [vmkit-commits] [PATCH] Fix infinite loop in zip.cpp In-Reply-To: References: Message-ID: Thanks Will! Patch applied: http://lists.cs.uiuc.edu/pipermail/vmkit-commits/2011-September/002136.html On Fri, Sep 9, 2011 at 5:25 AM, Will Dietz wrote: > Hi, > > Attached is a patch that fixes an infinite loop in Zip.cpp when > processing some archives. Looks like what was intended anyway :). > > ~Will > > _______________________________________________ > vmkit-commits mailing list > vmkit-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/vmkit-commits > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nicolas.geoffray at lip6.fr Sat Sep 10 15:27:00 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 10 Sep 2011 22:27:00 -0000 Subject: [vmkit-commits] [vmkit] r139475 - in /vmkit/trunk: include/mvm/System.h lib/J3/Classpath/ClasspathVMRuntime.inc lib/J3/VMCore/JavaClass.cpp lib/J3/VMCore/Jni.cpp lib/J3/VMCore/Jnjvm.cpp tools/j3/Main.cpp Message-ID: <20110910222700.67DD72A6C12C@llvm.org> Author: geoffray Date: Sat Sep 10 17:27:00 2011 New Revision: 139475 URL: http://llvm.org/viewvc/llvm-project?rev=139475&view=rev Log: Another few bug fixes. Modified: vmkit/trunk/include/mvm/System.h vmkit/trunk/lib/J3/Classpath/ClasspathVMRuntime.inc vmkit/trunk/lib/J3/VMCore/JavaClass.cpp vmkit/trunk/lib/J3/VMCore/Jni.cpp vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp vmkit/trunk/tools/j3/Main.cpp Modified: vmkit/trunk/include/mvm/System.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/System.h?rev=139475&r1=139474&r2=139475&view=diff ============================================================================== --- vmkit/trunk/include/mvm/System.h (original) +++ vmkit/trunk/include/mvm/System.h Sat Sep 10 17:27:00 2011 @@ -203,6 +203,10 @@ static int GetNumberOfProcessors() { return sysconf(_SC_NPROCESSORS_ONLN); } + + static void Exit(int value) { + _exit(value); + } }; } Modified: vmkit/trunk/lib/J3/Classpath/ClasspathVMRuntime.inc URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Classpath/ClasspathVMRuntime.inc?rev=139475&r1=139474&r2=139475&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Classpath/ClasspathVMRuntime.inc (original) +++ vmkit/trunk/lib/J3/Classpath/ClasspathVMRuntime.inc Sat Sep 10 17:27:00 2011 @@ -188,7 +188,7 @@ jclass clazz, #endif jint par1) { - exit(par1); + mvm::System::Exit(par1); } JNIEXPORT jlong Java_java_lang_VMRuntime_freeMemory( Modified: vmkit/trunk/lib/J3/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaClass.cpp?rev=139475&r1=139474&r2=139475&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JavaClass.cpp Sat Sep 10 17:27:00 2011 @@ -1060,14 +1060,25 @@ for (sint32 i =0; i < clen; ++i) { cur = jniConsClName->elements[i]; - if (cur == '/') ptr[0] = '_'; - else if (cur == '_') { + if (cur == '/') { + ptr[0] = '_'; + ptr++; + } else if (cur == '_') { ptr[0] = '_'; ptr[1] = '1'; - ++ptr; + ptr += 2; + } else if (cur == '$') { + ptr[0] = '_'; + ptr[1] = '0'; + ptr[2] = '0'; + ptr[3] = '0'; + ptr[4] = '2'; + ptr[5] = '4'; + ptr += 6; + } else { + ptr[0] = (uint8)cur; + ptr++; } - else ptr[0] = (uint8)cur; - ++ptr; } ptr[0] = '_'; Modified: vmkit/trunk/lib/J3/VMCore/Jni.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Jni.cpp?rev=139475&r1=139474&r2=139475&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/Jni.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/Jni.cpp Sat Sep 10 17:27:00 2011 @@ -146,6 +146,7 @@ BEGIN_JNI_EXCEPTION + verifyNull(_Cl); // Local object references. JavaObject* Cl = *(JavaObject**)_Cl; JavaObject* res = 0; @@ -156,7 +157,6 @@ Jnjvm* vm = JavaThread::get()->getJVM(); - verifyNull(Cl); UserCommonClass* cl = UserCommonClass::resolvedImplClass(vm, Cl, true); if (!cl->isClass()) RETURN_FROM_JNI(0); @@ -231,9 +231,9 @@ jboolean IsSameObject(JNIEnv *env, jobject ref1, jobject ref2) { BEGIN_JNI_EXCEPTION - - JavaObject* Ref1 = *(JavaObject**)ref1; - JavaObject* Ref2 = *(JavaObject**)ref2; + + JavaObject* Ref1 = ref1 ? *(JavaObject**)ref1 : NULL; + JavaObject* Ref2 = ref2 ? *(JavaObject**)ref2 : NULL; llvm_gcroot(Ref1, 0); llvm_gcroot(Ref2, 0); @@ -492,11 +492,29 @@ } -jobject CallObjectMethodA(JNIEnv *env, jobject obj, jmethodID methodID, +jobject CallObjectMethodA(JNIEnv *env, jobject _obj, jmethodID methodID, const jvalue * args) { - fprintf(stderr, "Implement me\n"); - abort(); - return 0; + BEGIN_JNI_EXCEPTION + + verifyNull(_obj); + + // Local object references. + JavaObject* obj = *(JavaObject**)_obj; + JavaObject* res = 0; + llvm_gcroot(obj, 0); + llvm_gcroot(res, 0); + + JavaMethod* meth = (JavaMethod*)methodID; + Jnjvm* vm = JavaThread::get()->getJVM(); + UserClass* cl = getClassFromVirtualMethod(vm, meth, JavaObject::getClass(obj)); + res = meth->invokeJavaObjectVirtualBuf(vm, cl, obj, (void*)args); + + jobject ret = (jobject)th->pushJNIRef(res); + RETURN_FROM_JNI(ret); + + END_JNI_EXCEPTION + + RETURN_FROM_JNI(0); } @@ -551,11 +569,26 @@ } -jboolean CallBooleanMethodA(JNIEnv *env, jobject obj, jmethodID methodID, +jboolean CallBooleanMethodA(JNIEnv *env, jobject _obj, jmethodID methodID, const jvalue * args) { - fprintf(stderr, "Implement me\n"); - abort(); - return 0; + BEGIN_JNI_EXCEPTION + + verifyNull(_obj); + + // Local object references. + JavaObject* obj = *(JavaObject**)_obj; + llvm_gcroot(obj, 0); + + JavaMethod* meth = (JavaMethod*)methodID; + Jnjvm* vm = JavaThread::get()->getJVM(); + UserClass* cl = getClassFromVirtualMethod(vm, meth, JavaObject::getClass(obj)); + jboolean res = (jboolean)meth->invokeIntVirtualBuf(vm, cl, obj, (void*)args); + + RETURN_FROM_JNI(res); + + END_JNI_EXCEPTION + + RETURN_FROM_JNI(0); } @@ -588,11 +621,26 @@ } -jbyte CallByteMethodA(JNIEnv *env, jobject obj, jmethodID methodID, +jbyte CallByteMethodA(JNIEnv *env, jobject _obj, jmethodID methodID, const jvalue *args) { - fprintf(stderr, "Implement me\n"); - abort(); - return 0; + BEGIN_JNI_EXCEPTION + + verifyNull(_obj); + + // Local object references. + JavaObject* obj = *(JavaObject**)_obj; + llvm_gcroot(obj, 0); + + JavaMethod* meth = (JavaMethod*)methodID; + Jnjvm* vm = JavaThread::get()->getJVM(); + UserClass* cl = getClassFromVirtualMethod(vm, meth, JavaObject::getClass(obj)); + jbyte res = (jbyte)meth->invokeIntVirtualBuf(vm, cl, obj, (void*)args); + + RETURN_FROM_JNI(res); + + END_JNI_EXCEPTION + + RETURN_FROM_JNI(0); } @@ -626,11 +674,26 @@ } -jchar CallCharMethodA(JNIEnv *env, jobject obj, jmethodID methodID, +jchar CallCharMethodA(JNIEnv *env, jobject _obj, jmethodID methodID, const jvalue *args) { - fprintf(stderr, "Implement me\n"); - abort(); - return 0; + BEGIN_JNI_EXCEPTION + + verifyNull(_obj); + + // Local object references. + JavaObject* obj = *(JavaObject**)_obj; + llvm_gcroot(obj, 0); + + JavaMethod* meth = (JavaMethod*)methodID; + Jnjvm* vm = JavaThread::get()->getJVM(); + UserClass* cl = getClassFromVirtualMethod(vm, meth, JavaObject::getClass(obj)); + jchar res = (jchar)meth->invokeIntVirtualBuf(vm, cl, obj, (void*)args); + + RETURN_FROM_JNI(res); + + END_JNI_EXCEPTION + + RETURN_FROM_JNI(0); } @@ -664,11 +727,26 @@ } -jshort CallShortMethodA(JNIEnv *env, jobject obj, jmethodID methodID, +jshort CallShortMethodA(JNIEnv *env, jobject _obj, jmethodID methodID, const jvalue *args) { - fprintf(stderr, "Implement me\n"); - abort(); - return 0; + BEGIN_JNI_EXCEPTION + + verifyNull(_obj); + + // Local object references. + JavaObject* obj = *(JavaObject**)_obj; + llvm_gcroot(obj, 0); + + JavaMethod* meth = (JavaMethod*)methodID; + Jnjvm* vm = JavaThread::get()->getJVM(); + UserClass* cl = getClassFromVirtualMethod(vm, meth, JavaObject::getClass(obj)); + jshort res = (jshort)meth->invokeIntVirtualBuf(vm, cl, obj, (void*)args); + + RETURN_FROM_JNI(res); + + END_JNI_EXCEPTION + + RETURN_FROM_JNI(0); } @@ -726,9 +804,24 @@ jint CallIntMethodA(JNIEnv *env, jobject _obj, jmethodID methodID, const jvalue *args) { - fprintf(stderr, "Implement me\n"); - abort(); - return 0; + BEGIN_JNI_EXCEPTION + + verifyNull(_obj); + + // Local object references. + JavaObject* obj = *(JavaObject**)_obj; + llvm_gcroot(obj, 0); + + JavaMethod* meth = (JavaMethod*)methodID; + Jnjvm* vm = JavaThread::get()->getJVM(); + UserClass* cl = getClassFromVirtualMethod(vm, meth, JavaObject::getClass(obj)); + jint res = (jint)meth->invokeIntVirtualBuf(vm, cl, obj, (void*)args); + + RETURN_FROM_JNI(res); + + END_JNI_EXCEPTION + + RETURN_FROM_JNI(0); } @@ -763,11 +856,26 @@ } -jlong CallLongMethodA(JNIEnv *env, jobject obj, jmethodID methodID, +jlong CallLongMethodA(JNIEnv *env, jobject _obj, jmethodID methodID, const jvalue *args) { - fprintf(stderr, "Implement me\n"); - abort(); - return 0; + BEGIN_JNI_EXCEPTION + + verifyNull(_obj); + + // Local object references. + JavaObject* obj = *(JavaObject**)_obj; + llvm_gcroot(obj, 0); + + JavaMethod* meth = (JavaMethod*)methodID; + Jnjvm* vm = JavaThread::get()->getJVM(); + UserClass* cl = getClassFromVirtualMethod(vm, meth, JavaObject::getClass(obj)); + jlong res = (jlong)meth->invokeLongVirtualBuf(vm, cl, obj, (void*)args); + + RETURN_FROM_JNI(res); + + END_JNI_EXCEPTION + + RETURN_FROM_JNI(0); } @@ -822,9 +930,24 @@ jfloat CallFloatMethodA(JNIEnv *env, jobject _obj, jmethodID methodID, const jvalue *args) { - fprintf(stderr, "Implement me\n"); - abort(); - return 0; + BEGIN_JNI_EXCEPTION + + verifyNull(_obj); + + // Local object references. + JavaObject* obj = *(JavaObject**)_obj; + llvm_gcroot(obj, 0); + + JavaMethod* meth = (JavaMethod*)methodID; + Jnjvm* vm = JavaThread::get()->getJVM(); + UserClass* cl = getClassFromVirtualMethod(vm, meth, JavaObject::getClass(obj)); + jfloat res = (jfloat)meth->invokeFloatVirtualBuf(vm, cl, obj, (void*)args); + + RETURN_FROM_JNI(res); + + END_JNI_EXCEPTION + + RETURN_FROM_JNI(0.0f); } @@ -879,9 +1002,24 @@ jdouble CallDoubleMethodA(JNIEnv *env, jobject _obj, jmethodID methodID, const jvalue *args) { - fprintf(stderr, "Implement me\n"); - abort(); - return 0; + BEGIN_JNI_EXCEPTION + + verifyNull(_obj); + + // Local object references. + JavaObject* obj = *(JavaObject**)_obj; + llvm_gcroot(obj, 0); + + JavaMethod* meth = (JavaMethod*)methodID; + Jnjvm* vm = JavaThread::get()->getJVM(); + UserClass* cl = getClassFromVirtualMethod(vm, meth, JavaObject::getClass(obj)); + jdouble res = (jdouble)meth->invokeDoubleVirtualBuf(vm, cl, obj, (void*)args); + + RETURN_FROM_JNI(res); + + END_JNI_EXCEPTION + + RETURN_FROM_JNI(0.0); } @@ -1679,11 +1817,27 @@ } -jobject CallStaticObjectMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, +jobject CallStaticObjectMethodA(JNIEnv *env, jclass _clazz, jmethodID methodID, const jvalue *args) { - fprintf(stderr, "Implement me\n"); - abort(); - return 0; + BEGIN_JNI_EXCEPTION + + // Local object references. + JavaObject* clazz = *(JavaObject**)_clazz; + JavaObject* res = 0; + llvm_gcroot(clazz, 0); + llvm_gcroot(res, 0); + + JavaMethod* meth = (JavaMethod*)methodID; + Jnjvm* vm = JavaThread::get()->getJVM(); + UserClass* cl = getClassFromStaticMethod(vm, meth, clazz); + + res = meth->invokeJavaObjectStaticBuf(vm, cl, (void*)args); + + jobject ret = (jobject)th->pushJNIRef(res); + RETURN_FROM_JNI(ret); + + END_JNI_EXCEPTION + RETURN_FROM_JNI(0); } @@ -1731,11 +1885,23 @@ } -jboolean CallStaticBooleanMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, +jboolean CallStaticBooleanMethodA(JNIEnv *env, jclass _clazz, jmethodID methodID, const jvalue *args) { - fprintf(stderr, "Implement me\n"); - abort(); - return 0; + BEGIN_JNI_EXCEPTION + + // Local object references. + JavaObject* clazz = *(JavaObject**)_clazz; + llvm_gcroot(clazz, 0); + + JavaMethod* meth = (JavaMethod*)methodID; + Jnjvm* vm = JavaThread::get()->getJVM(); + UserClass* cl = getClassFromStaticMethod(vm, meth, clazz); + jboolean res = (jboolean) meth->invokeIntStaticBuf(vm, cl, (void*)args); + + RETURN_FROM_JNI(res); + + END_JNI_EXCEPTION + RETURN_FROM_JNI(0); } @@ -1781,11 +1947,23 @@ } -jbyte CallStaticByteMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, +jbyte CallStaticByteMethodA(JNIEnv *env, jclass _clazz, jmethodID methodID, const jvalue *args) { - fprintf(stderr, "Implement me\n"); - abort(); - return 0; + BEGIN_JNI_EXCEPTION + + // Local object references. + JavaObject* clazz = *(JavaObject**)_clazz; + llvm_gcroot(clazz, 0); + + JavaMethod* meth = (JavaMethod*)methodID; + Jnjvm* vm = JavaThread::get()->getJVM(); + UserClass* cl = getClassFromStaticMethod(vm, meth, clazz); + jbyte res = (jbyte) meth->invokeIntStaticBuf(vm, cl, (void*)args); + + RETURN_FROM_JNI(res); + + END_JNI_EXCEPTION + RETURN_FROM_JNI(0); } @@ -1833,9 +2011,21 @@ jchar CallStaticCharMethodA(JNIEnv *env, jclass _clazz, jmethodID methodID, const jvalue *args) { - fprintf(stderr, "Implement me\n"); - abort(); - return 0; + BEGIN_JNI_EXCEPTION + + // Local object references. + JavaObject* clazz = *(JavaObject**)_clazz; + llvm_gcroot(clazz, 0); + + JavaMethod* meth = (JavaMethod*)methodID; + Jnjvm* vm = JavaThread::get()->getJVM(); + UserClass* cl = getClassFromStaticMethod(vm, meth, clazz); + jchar res = (jchar) meth->invokeIntStaticBuf(vm, cl, (void*)args); + + RETURN_FROM_JNI(res); + + END_JNI_EXCEPTION + RETURN_FROM_JNI(0); } @@ -1883,11 +2073,23 @@ } -jshort CallStaticShortMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, +jshort CallStaticShortMethodA(JNIEnv *env, jclass _clazz, jmethodID methodID, const jvalue *args) { - fprintf(stderr, "Implement me\n"); - abort(); - return 0; + BEGIN_JNI_EXCEPTION + + // Local object references. + JavaObject* clazz = *(JavaObject**)_clazz; + llvm_gcroot(clazz, 0); + + JavaMethod* meth = (JavaMethod*)methodID; + Jnjvm* vm = JavaThread::get()->getJVM(); + UserClass* cl = getClassFromStaticMethod(vm, meth, clazz); + jshort res = (jshort) meth->invokeIntStaticBuf(vm, cl, (void*)args); + + RETURN_FROM_JNI(res); + + END_JNI_EXCEPTION + RETURN_FROM_JNI(0); } @@ -1934,11 +2136,23 @@ } -jint CallStaticIntMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, +jint CallStaticIntMethodA(JNIEnv *env, jclass _clazz, jmethodID methodID, const jvalue *args) { - fprintf(stderr, "Implement me\n"); - abort(); - return 0; + BEGIN_JNI_EXCEPTION + + // Local object references. + JavaObject* clazz = *(JavaObject**)_clazz; + llvm_gcroot(clazz, 0); + + JavaMethod* meth = (JavaMethod*)methodID; + Jnjvm* vm = JavaThread::get()->getJVM(); + UserClass* cl = getClassFromStaticMethod(vm, meth, clazz); + jint res = (jint) meth->invokeIntStaticBuf(vm, cl, (void*)args); + + RETURN_FROM_JNI(res); + + END_JNI_EXCEPTION + RETURN_FROM_JNI(0); } @@ -1986,11 +2200,23 @@ } -jlong CallStaticLongMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, +jlong CallStaticLongMethodA(JNIEnv *env, jclass _clazz, jmethodID methodID, const jvalue *args) { - fprintf(stderr, "Implement me\n"); - abort(); - return 0; + BEGIN_JNI_EXCEPTION + + // Local object references. + JavaObject* clazz = *(JavaObject**)_clazz; + llvm_gcroot(clazz, 0); + + JavaMethod* meth = (JavaMethod*)methodID; + Jnjvm* vm = JavaThread::get()->getJVM(); + UserClass* cl = getClassFromStaticMethod(vm, meth, clazz); + jlong res = (jlong) meth->invokeLongStaticBuf(vm, cl, (void*)args); + + RETURN_FROM_JNI(res); + + END_JNI_EXCEPTION + RETURN_FROM_JNI(0); } @@ -2040,11 +2266,23 @@ } -jfloat CallStaticFloatMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, +jfloat CallStaticFloatMethodA(JNIEnv *env, jclass _clazz, jmethodID methodID, const jvalue *args) { - fprintf(stderr, "Implement me\n"); - abort(); - return 0; + BEGIN_JNI_EXCEPTION + + // Local object references. + JavaObject* clazz = *(JavaObject**)_clazz; + llvm_gcroot(clazz, 0); + + JavaMethod* meth = (JavaMethod*)methodID; + Jnjvm* vm = JavaThread::get()->getJVM(); + UserClass* cl = getClassFromStaticMethod(vm, meth, clazz); + jfloat res = (jfloat) meth->invokeFloatStaticBuf(vm, cl, (void*)args); + + RETURN_FROM_JNI(res); + + END_JNI_EXCEPTION + RETURN_FROM_JNI(0); } @@ -2092,11 +2330,23 @@ } -jdouble CallStaticDoubleMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, +jdouble CallStaticDoubleMethodA(JNIEnv *env, jclass _clazz, jmethodID methodID, const jvalue *args) { - fprintf(stderr, "Implement me\n"); - abort(); - return 0; + BEGIN_JNI_EXCEPTION + + // Local object references. + JavaObject* clazz = *(JavaObject**)_clazz; + llvm_gcroot(clazz, 0); + + JavaMethod* meth = (JavaMethod*)methodID; + Jnjvm* vm = JavaThread::get()->getJVM(); + UserClass* cl = getClassFromStaticMethod(vm, meth, clazz); + jdouble res = (jdouble) meth->invokeDoubleStaticBuf(vm, cl, (void*)args); + + RETURN_FROM_JNI(res); + + END_JNI_EXCEPTION + RETURN_FROM_JNI(0); } @@ -2147,10 +2397,24 @@ } -void CallStaticVoidMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, +void CallStaticVoidMethodA(JNIEnv *env, jclass _clazz, jmethodID methodID, const jvalue * args) { - fprintf(stderr, "Implement me\n"); - abort(); + BEGIN_JNI_EXCEPTION + + // Local object references. + JavaObject* clazz = *(JavaObject**)_clazz; + llvm_gcroot(clazz, 0); + + JavaMethod* meth = (JavaMethod*)methodID; + Jnjvm* vm = JavaThread::get()->getJVM(); + UserClass* cl = getClassFromStaticMethod(vm, meth, clazz); + meth->invokeIntStaticBuf(vm, cl, (void*)args); + + RETURN_VOID_FROM_JNI; + + END_JNI_EXCEPTION + + RETURN_VOID_FROM_JNI; } @@ -2461,10 +2725,17 @@ } -jsize GetStringLength(JNIEnv *env, jstring str) { - fprintf(stderr, "Implement me\n"); - abort(); - return 0; +jsize GetStringLength(JNIEnv *env, jstring _str) { + BEGIN_JNI_EXCEPTION + + // Local object references. + JavaString* str = *(JavaString**)_str; + llvm_gcroot(str, 0); + + RETURN_FROM_JNI(str->count); + + END_JNI_EXCEPTION + RETURN_FROM_JNI(0); } Modified: vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp?rev=139475&r1=139474&r2=139475&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp Sat Sep 10 17:27:00 2011 @@ -1193,6 +1193,7 @@ method->invokeIntStatic(this, method->classDef, &args); } else { fprintf(stderr, "Main method not public.\n"); + mvm::System::Exit(1); } } CATCH { } END_CATCH; @@ -1210,6 +1211,8 @@ fprintf(stderr, "Exception in thread \"main\": " "Can not print stack trace.\n"); } END_CATCH; + // Program failed. Exit with return code not 0. + mvm::System::Exit(1); } } Modified: vmkit/trunk/tools/j3/Main.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/j3/Main.cpp?rev=139475&r1=139474&r2=139475&view=diff ============================================================================== --- vmkit/trunk/tools/j3/Main.cpp (original) +++ vmkit/trunk/tools/j3/Main.cpp Sat Sep 10 17:27:00 2011 @@ -47,7 +47,7 @@ // Run the application. vm->runApplication(argc, argv); vm->waitForExit(); - exit(0); + System::Exit(0); // Destroy everyone. // vm->~Jnjvm(); From nicolas.geoffray at lip6.fr Sun Sep 11 09:22:57 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 11 Sep 2011 16:22:57 -0000 Subject: [vmkit-commits] [vmkit] r139482 - in /vmkit/trunk/lib/J3: Classpath/ClasspathMethod.inc Classpath/ClasspathVMClass.inc Classpath/JavaUpcalls.cpp Classpath/JavaUpcalls.h Compiler/JavaAOTCompiler.cpp LLVMRuntime/runtime-single.ll VMCore/JavaAccess.h VMCore/JavaClass.cpp VMCore/JavaClass.h Message-ID: <20110911162257.327552A6C12C@llvm.org> Author: geoffray Date: Sun Sep 11 11:22:56 2011 New Revision: 139482 URL: http://llvm.org/viewvc/llvm-project?rev=139482&view=rev Log: Small fixes again. Modified: vmkit/trunk/lib/J3/Classpath/ClasspathMethod.inc vmkit/trunk/lib/J3/Classpath/ClasspathVMClass.inc vmkit/trunk/lib/J3/Classpath/JavaUpcalls.cpp vmkit/trunk/lib/J3/Classpath/JavaUpcalls.h vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp vmkit/trunk/lib/J3/LLVMRuntime/runtime-single.ll vmkit/trunk/lib/J3/VMCore/JavaAccess.h vmkit/trunk/lib/J3/VMCore/JavaClass.cpp vmkit/trunk/lib/J3/VMCore/JavaClass.h Modified: vmkit/trunk/lib/J3/Classpath/ClasspathMethod.inc URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Classpath/ClasspathMethod.inc?rev=139482&r1=139481&r2=139482&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Classpath/ClasspathMethod.inc (original) +++ vmkit/trunk/lib/J3/Classpath/ClasspathMethod.inc Sun Sep 11 11:22:56 2011 @@ -168,13 +168,8 @@ exc = th->getJavaException(); \ } END_CATCH; \ if (exc) { \ - if (JavaObject::getClass(exc)->isAssignableFrom( \ - vm->upcalls->newException)) { \ - th->clearException(); \ - th->getJVM()->invocationTargetException(exc); \ - } else { \ - th->throwPendingException(); \ - } \ + th->clearException(); \ + th->getJVM()->invocationTargetException(exc); \ return NULL; \ } Modified: vmkit/trunk/lib/J3/Classpath/ClasspathVMClass.inc URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Classpath/ClasspathVMClass.inc?rev=139482&r1=139481&r2=139482&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Classpath/ClasspathVMClass.inc (original) +++ vmkit/trunk/lib/J3/Classpath/ClasspathVMClass.inc Sun Sep 11 11:22:56 2011 @@ -216,6 +216,11 @@ UserCommonClass* cl = UserCommonClass::resolvedImplClass(vm, Cl, false); res = cl->getAccess(); + if (isEnum(res) && cl->getSuper() != vm->upcalls->EnumClass) { + // javac may put that flag to inner classes of enum classes. + res &= ~ACC_ENUM; + } + END_NATIVE_EXCEPTION return res; } Modified: vmkit/trunk/lib/J3/Classpath/JavaUpcalls.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Classpath/JavaUpcalls.cpp?rev=139482&r1=139481&r2=139482&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Classpath/JavaUpcalls.cpp (original) +++ vmkit/trunk/lib/J3/Classpath/JavaUpcalls.cpp Sun Sep 11 11:22:56 2011 @@ -190,6 +190,7 @@ JavaMethod* Classpath::SystemArraycopy; JavaMethod* Classpath::VMSystemArraycopy; Class* Classpath::SystemClass; +Class* Classpath::EnumClass; JavaMethod* Classpath::ErrorWithExcpNoClassDefFoundError; JavaMethod* Classpath::ErrorWithExcpExceptionInInitializerError; @@ -838,6 +839,7 @@ ACC_STATIC); SystemClass = UPCALL_CLASS(loader, "java/lang/System"); + EnumClass = UPCALL_CLASS(loader, "java/lang/Enum"); newThread = UPCALL_CLASS(loader, "java/lang/Thread"); Modified: vmkit/trunk/lib/J3/Classpath/JavaUpcalls.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Classpath/JavaUpcalls.h?rev=139482&r1=139481&r2=139482&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Classpath/JavaUpcalls.h (original) +++ vmkit/trunk/lib/J3/Classpath/JavaUpcalls.h Sun Sep 11 11:22:56 2011 @@ -103,6 +103,7 @@ ISOLATE_STATIC UserClass* newDirectByteBuffer; ISOLATE_STATIC JavaMethod* InitDirectByteBuffer; ISOLATE_STATIC JavaField* vmdataClassLoader; + ISOLATE_STATIC UserClass* enumClass; ISOLATE_STATIC JavaField* boolValue; ISOLATE_STATIC JavaField* byteValue; @@ -264,6 +265,8 @@ ISOLATE_STATIC JavaMethod* EnqueueReference; ISOLATE_STATIC Class* newReference; + ISOLATE_STATIC UserClass* EnumClass; + private: ISOLATE_STATIC void CreateJavaThread(Jnjvm* vm, JavaThread* myth, const char* name, JavaObject* Group); Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=139482&r1=139481&r2=139482&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Sun Sep 11 11:22:56 2011 @@ -896,7 +896,7 @@ CommonClassElts.push_back(ConstantArray::get(ATy, TCM)); // access - CommonClassElts.push_back(ConstantInt::get(Type::getInt16Ty(getLLVMContext()), cl->access)); + CommonClassElts.push_back(ConstantInt::get(Type::getInt32Ty(getLLVMContext()), cl->access)); // interfaces if (cl->nbInterfaces) { 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=139482&r1=139481&r2=139482&view=diff ============================================================================== --- vmkit/trunk/lib/J3/LLVMRuntime/runtime-single.ll (original) +++ vmkit/trunk/lib/J3/LLVMRuntime/runtime-single.ll Sun Sep 11 11:22:56 2011 @@ -2,7 +2,7 @@ ;;;;;;;;;;;;;;;;;;;;;;;;; Isolate specific types ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -%JavaCommonClass = type { [1 x %JavaObject*], i16, +%JavaCommonClass = type { [1 x %JavaObject*], i32, %JavaClass**, i16, %UTF8*, %JavaClass*, i8*, %VT* } %ClassBytes = type { i32, i8* } Modified: vmkit/trunk/lib/J3/VMCore/JavaAccess.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaAccess.h?rev=139482&r1=139481&r2=139482&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaAccess.h (original) +++ vmkit/trunk/lib/J3/VMCore/JavaAccess.h Sun Sep 11 11:22:56 2011 @@ -32,10 +32,11 @@ #define ACC_ABSTRACT 0x0400 #define ACC_STRICT 0x0800 #define ACC_SYNTHETIC 0x1000 +#define ACC_ENUM 0x4000 -#define JNJVM_CLASS 0x1000 -#define JNJVM_ARRAY 0x2000 -#define JNJVM_PRIMITIVE 0x4000 +#define JNJVM_CLASS 0x10000 +#define JNJVM_ARRAY 0x20000 +#define JNJVM_PRIMITIVE 0x40000 #define MK_VERIFIER(name, flag) \ inline bool name(unsigned int param) { \ @@ -53,6 +54,7 @@ MK_VERIFIER(isFinal, ACC_FINAL) MK_VERIFIER(isSuper, ACC_SUPER) MK_VERIFIER(isSynthetic, ACC_SYNTHETIC) +MK_VERIFIER(isEnum, ACC_ENUM) inline bool isVirtual(unsigned int param) { Modified: vmkit/trunk/lib/J3/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaClass.cpp?rev=139482&r1=139481&r2=139482&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JavaClass.cpp Sun Sep 11 11:22:56 2011 @@ -884,7 +884,7 @@ uint32 ctpSize = reader.readU2(); ctpInfo = new(classLoader->allocator, ctpSize) JavaConstantPool(this, reader, ctpSize); - access |= (reader.readU2() & 0x0FFF); + access |= reader.readU2(); if (!isPublic(access)) access |= ACC_PRIVATE; @@ -1559,7 +1559,14 @@ } else { // If the super is not a secondary type and the base class does not // implement any interface, we can reuse the list of secondary types - // of super. + // of super. If the base class is a primitive, the array class shares + // the same secondary types than the super of the current superVT + // (eg Object[][] for int[][]). + if (base->isPrimitive()) { + const UTF8* superName = JCL->constructArrayName(dim + 1, C->super->name); + super = JCL->constructArray(superName); + superVT = super->virtualVT; + } nbSecondaryTypes = superVT->nbSecondaryTypes; secondaryTypes = superVT->secondaryTypes; } Modified: vmkit/trunk/lib/J3/VMCore/JavaClass.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaClass.h?rev=139482&r1=139481&r2=139482&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaClass.h (original) +++ vmkit/trunk/lib/J3/VMCore/JavaClass.h Sun Sep 11 11:22:56 2011 @@ -174,7 +174,7 @@ /// access - {public, private, protected}. /// - uint16 access; + uint32 access; /// interfaces - The interfaces this class implements. /// @@ -209,7 +209,7 @@ } // Assessor methods. - uint32 getAccess() const { return access; } + uint32 getAccess() const { return access & 0xFFFF; } Class** getInterfaces() const { return interfaces; } const UTF8* getName() const { return name; } Class* getSuper() const { return super; } From nicolas.geoffray at lip6.fr Mon Sep 12 13:19:54 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Mon, 12 Sep 2011 20:19:54 -0000 Subject: [vmkit-commits] [vmkit] r139532 - in /vmkit/trunk/lib/J3: Classpath/ClasspathVMClass.inc Classpath/JavaUpcalls.cpp Classpath/JavaUpcalls.h Compiler/JavaJITCompiler.cpp VMCore/JavaClass.cpp VMCore/JavaRuntimeJIT.cpp VMCore/Jnjvm.cpp Message-ID: <20110912201954.B13922A6C12C@llvm.org> Author: geoffray Date: Mon Sep 12 15:19:54 2011 New Revision: 139532 URL: http://llvm.org/viewvc/llvm-project?rev=139532&view=rev Log: Some small compatibility fixes. Modified: vmkit/trunk/lib/J3/Classpath/ClasspathVMClass.inc vmkit/trunk/lib/J3/Classpath/JavaUpcalls.cpp vmkit/trunk/lib/J3/Classpath/JavaUpcalls.h vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp vmkit/trunk/lib/J3/VMCore/JavaClass.cpp vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp Modified: vmkit/trunk/lib/J3/Classpath/ClasspathVMClass.inc URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Classpath/ClasspathVMClass.inc?rev=139532&r1=139531&r2=139532&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Classpath/ClasspathVMClass.inc (original) +++ vmkit/trunk/lib/J3/Classpath/ClasspathVMClass.inc Mon Sep 12 15:19:54 2011 @@ -168,6 +168,7 @@ JavaMethod* meth = &realCl->virtualMethods[i]; bool pub = isPublic(meth->access); if (!(meth->name->equals(classLoader->bootstrapLoader->initName)) && + !(meth->name->equals(classLoader->bootstrapLoader->clinitName)) && (!publicOnly || pub)) { ++size; } @@ -182,6 +183,7 @@ JavaMethod* meth = &realCl->virtualMethods[i]; bool pub = isPublic(meth->access); if (!(meth->name->equals(classLoader->bootstrapLoader->initName)) && + !(meth->name->equals(classLoader->bootstrapLoader->clinitName)) && (!publicOnly || pub)) { // TODO: check parameter types UserClass* Meth = vm->upcalls->newMethod; Modified: vmkit/trunk/lib/J3/Classpath/JavaUpcalls.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Classpath/JavaUpcalls.cpp?rev=139532&r1=139531&r2=139532&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Classpath/JavaUpcalls.cpp (original) +++ vmkit/trunk/lib/J3/Classpath/JavaUpcalls.cpp Mon Sep 12 15:19:54 2011 @@ -37,6 +37,7 @@ JavaField* Classpath::vmdataVMThread; JavaMethod* Classpath::finaliseCreateInitialThread; JavaMethod* Classpath::initVMThread; +JavaMethod* Classpath::initThread; JavaMethod* Classpath::groupAddThread; JavaField* Classpath::threadName; JavaField* Classpath::groupName; @@ -48,6 +49,7 @@ Class* Classpath::threadGroup; JavaField* Classpath::rootGroup; JavaField* Classpath::vmThread; +JavaMethod* Classpath::getUncaughtExceptionHandler; JavaMethod* Classpath::uncaughtException; Class* Classpath::inheritableThreadLocal; @@ -240,10 +242,8 @@ myth->javaThread = th; vmth = (JavaObjectVMThread*)newVMThread->doNew(vm); name = vm->asciizToStr(thName); - - threadName->setInstanceObjectField(th, name); - priority->setInstanceInt32Field(th, (uint32)1); - daemon->setInstanceInt8Field(th, (uint32)0); + + initThread->invokeIntSpecial(vm, newThread, th, &vmth, &name, 1, 0); vmThread->setInstanceObjectField(th, vmth); assocThread->setInstanceObjectField(vmth, th); running->setInstanceInt8Field(vmth, (uint32)1); @@ -862,6 +862,10 @@ UPCALL_METHOD(loader, "java/lang/InheritableThreadLocal", "newChildThread", "(Ljava/lang/Thread;)V", ACC_STATIC); + initThread = + UPCALL_METHOD(loader, "java/lang/Thread", "", + "(Ljava/lang/VMThread;Ljava/lang/String;IZ)V", ACC_VIRTUAL); + initVMThread = UPCALL_METHOD(loader, "java/lang/VMThread", "", "(Ljava/lang/Thread;)V", ACC_VIRTUAL); @@ -911,8 +915,13 @@ UPCALL_FIELD(loader, "java/lang/Thread", "vmThread", "Ljava/lang/VMThread;", ACC_VIRTUAL); + getUncaughtExceptionHandler = + UPCALL_METHOD(loader, "java/lang/Thread", "getUncaughtExceptionHandler", + "()Ljava/lang/Thread$UncaughtExceptionHandler;", ACC_VIRTUAL); + uncaughtException = - UPCALL_METHOD(loader, "java/lang/ThreadGroup", "uncaughtException", + UPCALL_METHOD(loader, "java/lang/Thread$UncaughtExceptionHandler", + "uncaughtException", "(Ljava/lang/Thread;Ljava/lang/Throwable;)V", ACC_VIRTUAL); Modified: vmkit/trunk/lib/J3/Classpath/JavaUpcalls.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Classpath/JavaUpcalls.h?rev=139532&r1=139531&r2=139532&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Classpath/JavaUpcalls.h (original) +++ vmkit/trunk/lib/J3/Classpath/JavaUpcalls.h Mon Sep 12 15:19:54 2011 @@ -137,6 +137,7 @@ ISOLATE_STATIC JavaField* assocThread; ISOLATE_STATIC JavaField* vmdataVMThread; ISOLATE_STATIC JavaMethod* finaliseCreateInitialThread; + ISOLATE_STATIC JavaMethod* initThread; ISOLATE_STATIC JavaMethod* initVMThread; ISOLATE_STATIC JavaMethod* runVMThread; ISOLATE_STATIC JavaMethod* groupAddThread; @@ -150,6 +151,7 @@ ISOLATE_STATIC UserClass* threadGroup; ISOLATE_STATIC JavaField* rootGroup; ISOLATE_STATIC JavaField* vmThread; + ISOLATE_STATIC JavaMethod* getUncaughtExceptionHandler; ISOLATE_STATIC JavaMethod* uncaughtException; ISOLATE_STATIC UserClass* inheritableThreadLocal; Modified: vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp?rev=139532&r1=139531&r2=139532&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp Mon Sep 12 15:19:54 2011 @@ -217,7 +217,28 @@ } extern "C" void ThrowUnfoundInterface() { - abort(); + JavaThread *th = JavaThread::get(); + + BEGIN_NATIVE_EXCEPTION(1); + + // Lookup the caller of this class. + mvm::StackWalker Walker(th); + mvm::FrameInfo* FI = Walker.get(); + assert(FI->Metadata != NULL && "Wrong stack trace"); + JavaMethod* meth = (JavaMethod*)FI->Metadata; + + // Lookup the method info in the constant pool of the caller. + uint16 ctpIndex = meth->lookupCtpIndex(FI); + assert(ctpIndex && "No constant pool index"); + JavaConstantPool* ctpInfo = meth->classDef->getConstantPool(); + CommonClass* ctpCl = 0; + const UTF8* utf8 = 0; + Signdef* sign = 0; + ctpInfo->resolveMethod(ctpIndex, ctpCl, utf8, sign); + + JavaThread::get()->getJVM()->abstractMethodError(ctpCl, utf8); + + END_NATIVE_EXCEPTION } void JavaJITCompiler::makeIMT(Class* cl) { Modified: vmkit/trunk/lib/J3/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaClass.cpp?rev=139532&r1=139531&r2=139532&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JavaClass.cpp Mon Sep 12 15:19:54 2011 @@ -247,7 +247,8 @@ uint32 size = JavaVirtualTable::getBaseSize(); virtualVT = new(loader->allocator, size) JavaVirtualTable(this); - access = ACC_FINAL | ACC_ABSTRACT | ACC_PUBLIC | JNJVM_ARRAY; + access = ACC_FINAL | ACC_ABSTRACT | JNJVM_ARRAY | base->getAccess(); + access &= ~ACC_INTERFACE; } JavaObject* UserClassArray::doNew(sint32 n, Jnjvm* vm) { Modified: vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp?rev=139532&r1=139531&r2=139532&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp Mon Sep 12 15:19:54 2011 @@ -579,6 +579,10 @@ UserClass* lookup = cl->isArray() ? cl->super : cl->asClass(); JavaMethod* Virt = lookup->lookupMethod(utf8, sign->keyName, false, true, 0); + if (isAbstract(Virt->access)) { + JavaThread::get()->getJVM()->abstractMethodError(Virt->classDef, Virt->name); + } + // Compile the found method. result = Virt->compiledPtr(); @@ -678,6 +682,9 @@ if (!callee) { th->getJVM()->noSuchMethodError(lookup, utf8); } + if (isAbstract(callee->access)) { + JavaThread::get()->getJVM()->abstractMethodError(callee->classDef, callee->name); + } // Compile the found method. result = callee->compiledPtr(); Modified: vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp?rev=139532&r1=139531&r2=139532&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp Mon Sep 12 15:19:54 2011 @@ -506,7 +506,7 @@ ArrayUInt16::setElement(msg, '.', i); i++; } else { - ArrayUInt16::setElement(msg, cl->name->elements[i], i); + ArrayUInt16::setElement(msg, cl->name->elements[j], i); i++; } } @@ -1166,12 +1166,12 @@ void Jnjvm::executeClass(const char* className, ArrayObject* args) { JavaObject* exc = NULL; JavaObject* obj = NULL; - JavaObject* group = NULL; + JavaObject* handler = NULL; llvm_gcroot(args, 0); llvm_gcroot(exc, 0); llvm_gcroot(obj, 0); - llvm_gcroot(group, 0); + llvm_gcroot(handler, 0); TRY { // First try to see if we are a self-contained executable. @@ -1203,10 +1203,10 @@ JavaThread* th = JavaThread::get(); th->clearException(); obj = th->currentThread(); - group = upcalls->group->getInstanceObjectField(obj); TRY { - upcalls->uncaughtException->invokeIntSpecial(this, upcalls->threadGroup, - group, &obj, &exc); + handler = upcalls->getUncaughtExceptionHandler->invokeJavaObjectVirtual(this, upcalls->newThread, obj); + verifyNull(handler); + upcalls->uncaughtException->invokeIntVirtual(this, upcalls->uncaughtException->classDef, handler, &obj, &exc); } CATCH { fprintf(stderr, "Exception in thread \"main\": " "Can not print stack trace.\n"); From nicolas.geoffray at lip6.fr Mon Sep 12 13:27:42 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Mon, 12 Sep 2011 20:27:42 -0000 Subject: [vmkit-commits] [vmkit] r139536 - /vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp Message-ID: <20110912202742.866152A6C12C@llvm.org> Author: geoffray Date: Mon Sep 12 15:27:42 2011 New Revision: 139536 URL: http://llvm.org/viewvc/llvm-project?rev=139536&view=rev Log: Spec change: do the mash for ISHR and ISHL. Modified: vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp Modified: vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp?rev=139536&r1=139535&r2=139536&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp Mon Sep 12 15:27:42 2011 @@ -1176,6 +1176,8 @@ case ISHL : { Value* val2 = popAsInt(); Value* val1 = popAsInt(); + Value* mask = ConstantInt::get(Type::getInt32Ty(*llvmContext), 0x1F); + val2 = BinaryOperator::CreateAnd(val2, mask, "", currentBlock); push(BinaryOperator::CreateShl(val1, val2, "", currentBlock), false); break; @@ -1194,6 +1196,8 @@ case ISHR : { Value* val2 = popAsInt(); Value* val1 = popAsInt(); + Value* mask = ConstantInt::get(Type::getInt32Ty(*llvmContext), 0x1F); + val2 = BinaryOperator::CreateAnd(val2, mask, "", currentBlock); push(BinaryOperator::CreateAShr(val1, val2, "", currentBlock), false); break; From nicolas.geoffray at lip6.fr Wed Sep 14 12:49:54 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Wed, 14 Sep 2011 19:49:54 -0000 Subject: [vmkit-commits] [vmkit] r139719 - /vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp Message-ID: <20110914194954.A97C62A6C12C@llvm.org> Author: geoffray Date: Wed Sep 14 14:49:54 2011 New Revision: 139719 URL: http://llvm.org/viewvc/llvm-project?rev=139719&view=rev Log: Don't detach threads since we're joining them. 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=139719&r1=139718&r2=139719&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp (original) +++ vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp Wed Sep 14 14:49:54 2011 @@ -334,8 +334,6 @@ /// start - Called by the creator of the thread to run the new thread. -/// The thread is in a detached state, because each virtual machine has -/// its own way of waiting for created threads. int Thread::start(void (*fct)(mvm::Thread*)) { pthread_attr_t attributs; pthread_attr_init(&attributs); @@ -346,7 +344,6 @@ MyVM->addThread(this); int res = pthread_create((pthread_t*)(void*)(&internalThreadID), &attributs, (void* (*)(void *))internalThreadStart, this); - pthread_detach((pthread_t)internalThreadID); pthread_attr_destroy(&attributs); return res; } From nicolas.geoffray at lip6.fr Sun Sep 18 12:11:13 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 18 Sep 2011 19:11:13 -0000 Subject: [vmkit-commits] [vmkit] r140004 - in /vmkit/trunk/lib/J3/Compiler: JavaAOTCompiler.cpp JavaJIT.cpp JavaJIT.h JavaJITOpcodes.cpp Message-ID: <20110918191114.089B12A6C12C@llvm.org> Author: geoffray Date: Sun Sep 18 14:11:13 2011 New Revision: 140004 URL: http://llvm.org/viewvc/llvm-project?rev=140004&view=rev Log: Add an inlining framework. Currently inlines simple methods that don't go into runtime and don't call non-inlineable Java methods. Modified: 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/JavaJITOpcodes.cpp Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=140004&r1=140003&r2=140004&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Sun Sep 18 14:11:13 2011 @@ -2178,6 +2178,8 @@ Function* F = M->getMethod(&cl->virtualMethods[i]); M->setMethod(F, ptr, F->getName().data()); cl->virtualMethods[i].compiledPtr(); + // Set native so that we don't try to inline it. + cl->virtualMethods[i].setNative(); } } @@ -2186,6 +2188,8 @@ Function* F = M->getMethod(&cl->staticMethods[i]); M->setMethod(F, ptr, F->getName().data()); cl->staticMethods[i].compiledPtr(); + // Set native so that we don't try to inline it. + cl->staticMethods[i].setNative(); } } } @@ -2372,7 +2376,7 @@ gv->setInitializer(CreateConstantFromVT(VT)); } - // Finally add used stubs to the image. + // 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; @@ -2400,7 +2404,7 @@ } } - // Finally emit the stub for the main signature. + // Emit the stub for the main signature. Signdef* mainSignature = loader->constructSign(loader->asciizConstructUTF8("([Ljava/lang/String;)V")); getSignatureInfo(mainSignature)->getStaticBuf(); @@ -2410,6 +2414,13 @@ // Emit the UTF8 map. CreateConstantFromUTF8Map(loader->hashUTF8->map); + + // Check that we have compiled everything. + for (Module::iterator I = TheModule->begin(), E = TheModule->end(); + I != E; + I++) { + assert(!I->hasExternalWeakLinkage()); + } } void JavaAOTCompiler::generateClassBytes(JnjvmBootstrapLoader* loader) { Modified: vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp?rev=140004&r1=140003&r2=140004&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp Sun Sep 18 14:11:13 2011 @@ -44,7 +44,7 @@ using namespace j3; using namespace llvm; -static bool needsInitialisationCheck(Class* cl, Class* compilingClass) { +bool JavaJIT::needsInitialisationCheck(Class* cl) { if (cl->isReadyForCompilation() || (!cl->isInterface() && compilingClass->isAssignableFrom(cl))) { return false; @@ -61,11 +61,29 @@ } bool JavaJIT::canBeInlined(JavaMethod* meth) { - JnjvmClassLoader* loader = meth->classDef->classLoader; - return (meth->canBeInlined && - meth != compilingMethod && inlineMethods[meth] == 0 && - (loader == compilingClass->classLoader || - loader == compilingClass->classLoader->bootstrapLoader)); + if (inlineMethods[meth]) return false; + if (isSynchro(meth->access)) return false; + if (isNative(meth->access)) return false; + + Attribut* codeAtt = meth->lookupAttribut(Attribut::codeAttribut); + if (codeAtt == NULL) return false; + + Reader reader(codeAtt, meth->classDef->bytes); + /* uint16 maxStack = */ reader.readU2(); + /* uint16 maxLocals = */ reader.readU2(); + uint32 codeLen = reader.readU4(); + uint32 start = reader.cursor; + reader.seek(codeLen, Reader::SeekCur); + uint16 nbHandlers = reader.readU2(); + if (nbHandlers != 0) return false; + reader.cursor = start; + + JavaJIT jit(TheCompiler, meth, llvmFunction); + jit.inlineMethods = inlineMethods; + jit.inlineMethods[meth] = true; + if (!jit.analyzeForInlining(reader, codeLen)) return false; + jit.inlineMethods[meth] = false; + return true; } void JavaJIT::invokeVirtual(uint16 index) { @@ -119,7 +137,11 @@ llvm::Type* retType = virtualType->getReturnType(); bool needsInit = false; - if (canBeDirect && meth && !TheCompiler->needsCallback(meth, &needsInit)) { + if (canBeDirect && canBeInlined(meth)) { + makeArgs(it, index, args, signature->nbArguments + 1); + JITVerifyNull(args[0]); + val = invokeInline(meth, args); + } else if (canBeDirect && !TheCompiler->needsCallback(meth, &needsInit)) { makeArgs(it, index, args, signature->nbArguments + 1); JITVerifyNull(args[0]); val = invoke(TheCompiler->getMethod(meth), args, "", currentBlock); @@ -707,35 +729,18 @@ Instruction* JavaJIT::inlineCompile(BasicBlock*& curBB, BasicBlock* endExBlock, std::vector& args) { - DbgSubprogram = TheCompiler->GetDbgSubprogram(compilingMethod); - - PRINT_DEBUG(JNJVM_COMPILE, 1, COLOR_NORMAL, "inline compile %s.%s\n", - UTF8Buffer(compilingClass->name).cString(), - UTF8Buffer(compilingMethod->name).cString()); - Attribut* codeAtt = compilingMethod->lookupAttribut(Attribut::codeAttribut); - - if (!codeAtt) { - fprintf(stderr, "I haven't verified your class file and it's malformed:" - " no code attribut found for %s.%s!\n", - UTF8Buffer(compilingClass->name).cString(), - UTF8Buffer(compilingMethod->name).cString()); - abort(); - } - Reader reader(codeAtt, compilingClass->bytes); uint16 maxStack = reader.readU2(); uint16 maxLocals = reader.readU2(); uint32 codeLen = reader.readU4(); - uint32 start = reader.cursor; - + uint32 start = reader.cursor; reader.seek(codeLen, Reader::SeekCur); - LLVMMethodInfo* LMI = TheCompiler->getMethodInfo(compilingMethod); - assert(LMI); - Function* func = LMI->getMethod(); + LLVMAssessorInfo& LAI = TheCompiler->getTypedefInfo( + compilingMethod->getSignature()->getReturnType()); + Type* returnType = LAI.llvmType; - Type* returnType = func->getReturnType(); endBlock = createBasicBlock("end"); currentBlock = curBB; @@ -888,7 +893,6 @@ delete[] opcodeInfos; return endNode; - } llvm::Function* JavaJIT::javaCompile() { @@ -1157,11 +1161,7 @@ PRINT_DEBUG(JNJVM_COMPILE, 1, COLOR_NORMAL, "--> end compiling %s.%s\n", UTF8Buffer(compilingClass->name).cString(), UTF8Buffer(compilingMethod->name).cString()); - - if (codeLen < 5 && !callsStackWalker && !TheCompiler->isStaticCompiling()) { - compilingMethod->canBeInlined = false; - } - + Attribut* annotationsAtt = compilingMethod->lookupAttribut(Attribut::annotationsAttribut); @@ -1486,6 +1486,17 @@ jit.inlineMethods = inlineMethods; jit.inlineMethods[meth] = true; jit.inlining = true; + jit.DbgSubprogram = DbgSubprogram; +#if DEBUG + static int inlineNb = 0; + fprintf(stderr, "inline compile %d %s.%s%s from %s.%s\n", inlineNb++, + UTF8Buffer(meth->classDef->name).cString(), + UTF8Buffer(meth->name).cString(), + UTF8Buffer(meth->getSignature()->keyName).cString(), + UTF8Buffer(compilingClass->name).cString(), + UTF8Buffer(compilingMethod->name).cString()); +#endif + Instruction* ret = jit.inlineCompile(currentBlock, currentExceptionBlock, args); inlineMethods[meth] = false; @@ -1577,7 +1588,7 @@ uint32 clIndex = ctpInfo->getClassIndexFromMethod(index); UserClass* cl = 0; Value* Cl = getResolvedClass(clIndex, true, true, &cl); - if (!meth || (cl && needsInitialisationCheck(cl, compilingClass))) { + if (!meth || (cl && needsInitialisationCheck(cl))) { CallInst::Create(intrinsics->ForceInitialisationCheckFunction, Cl, "", currentBlock); } @@ -1701,7 +1712,7 @@ if (cl && cl->isResolved()) { if (alreadyResolved) (*alreadyResolved) = cl; node = TheCompiler->getNativeClass(cl); - needsInit = needsInitialisationCheck(cl, compilingClass); + needsInit = needsInitialisationCheck(cl); } else { node = getConstantPoolAt(index, intrinsics->ClassLookupFunction, intrinsics->JavaClassType, 0, doThrow); @@ -1732,7 +1743,7 @@ LLVMClassInfo* LCI = TheCompiler->getClassInfo(cl); Size = LCI->getVirtualSize(); - bool needsCheck = needsInitialisationCheck(cl, compilingClass); + bool needsCheck = needsInitialisationCheck(cl); if (needsCheck) { Cl = invoke(intrinsics->ForceInitialisationCheckFunction, Cl, "", currentBlock); @@ -1773,8 +1784,7 @@ if (stat) { type = LCI->getStaticType(); Value* Cl = TheCompiler->getNativeClass(field->classDef); - bool needsCheck = needsInitialisationCheck(field->classDef, - compilingClass); + bool needsCheck = needsInitialisationCheck(field->classDef); if (needsCheck) { Cl = invoke(intrinsics->InitialisationCheckFunction, Cl, "", currentBlock); @@ -2434,6 +2444,7 @@ Instruction* JavaJIT::invoke(Value *F, std::vector& args, const char* Name, BasicBlock *InsertAtEnd) { + assert(!inlining); Instruction* res = CallInst::Create(F, args, Name, InsertAtEnd); DebugLoc DL = CreateLocation(); @@ -2487,6 +2498,7 @@ Instruction* JavaJIT::invoke(Value *F, Value* arg1, const char* Name, BasicBlock *InsertAtEnd) { + assert(!inlining); Instruction* res = CallInst::Create(F, arg1, Name, InsertAtEnd); DebugLoc DL = CreateLocation(); @@ -2532,6 +2544,7 @@ Instruction* JavaJIT::invoke(Value *F, Value* arg1, Value* arg2, const char* Name, BasicBlock *InsertAtEnd) { + assert(!inlining); Value* args[2] = { arg1, arg2 }; @@ -2579,6 +2592,7 @@ Instruction* JavaJIT::invoke(Value *F, const char* Name, BasicBlock *InsertAtEnd) { + assert(!inlining); Instruction* res = llvm::CallInst::Create(F, Name, InsertAtEnd); DebugLoc DL = CreateLocation(); res->setDebugLoc(DL); Modified: vmkit/trunk/lib/J3/Compiler/JavaJIT.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJIT.h?rev=140004&r1=140003&r2=140004&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJIT.h (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJIT.h Sun Sep 18 14:11:13 2011 @@ -157,7 +157,8 @@ /// getJavaExceptionPtr - Emit code to get a pointer to the Java pending exception llvm::Value* getJavaExceptionPtr(llvm::Value* javaThreadPtr); - + + bool needsInitialisationCheck(Class* cl); //===------------------------- Debugging support --------------------------===// @@ -193,7 +194,9 @@ /// then this method can not be inlined. bool callsStackWalker; - + bool analyzeForInlining(Reader& reader, uint32_t codeLength); + bool canInlineLoadConstant(uint16 index); + //===------------------------- Bytecode parsing ---------------------------===// /// compileOpcodes - Parse the bytecode and create LLVM instructions. Modified: vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp?rev=140004&r1=140003&r2=140004&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp Sun Sep 18 14:11:13 2011 @@ -36,9 +36,7 @@ #include "j3/J3Intrinsics.h" -#if DEBUG > 0 && (JNJVM_COMPILE > 0 || JNJVM_EXECUTE > 0) #include "j3/OpcodeNames.def" -#endif using namespace j3; using namespace llvm; @@ -2728,3 +2726,679 @@ } } } + +bool JavaJIT::canInlineLoadConstant(uint16 index) { + JavaConstantPool* ctpInfo = compilingClass->ctpInfo; + uint8 type = ctpInfo->typeAt(index); + if (type == JavaConstantPool::ConstantString + || type == JavaConstantPool::ConstantClass) { + return false; + } else { + return true; + } +} + +static uint8 getReceiver(const std::vector& stack, Signdef* signature) { + uint32_t index = stack.size() - 1; + Typedef* const* arguments = signature->getArgumentsType(); + for (uint32 i = 0; i < signature->nbArguments; i++) { + index--; + if (arguments[i]->isDouble() || arguments[i]->isLong()) { + index--; + } + } + return stack[index]; +} + +static void updateStack(std::vector& stack, Signdef* signature, uint8 bytecode) { + Typedef* const* arguments = signature->getArgumentsType(); + if (bytecode != INVOKESTATIC) { + stack.pop_back(); + } + for (uint32 i = 0; i < signature->nbArguments; i++) { + stack.pop_back(); + if (arguments[i]->isDouble() || arguments[i]->isLong()) { + stack.pop_back(); + } + } + if (!signature->getReturnType()->isVoid()) { + stack.push_back(bytecode); + if (signature->getReturnType()->isLong() + || signature->getReturnType()->isDouble()) { + stack.push_back(bytecode); + } + } +} + +bool JavaJIT::analyzeForInlining(Reader& reader, uint32 codeLength) { + JavaConstantPool* ctpInfo = compilingClass->ctpInfo; + bool wide = false; + uint32 start = reader.cursor; + std::vector stack; + for(uint32 i = 0; i < codeLength; ++i) { + reader.cursor = start + i; + uint8 bytecode = reader.readU1(); + + switch (bytecode) { + case NOP : + break; + + case ACONST_NULL : + case ICONST_M1 : + case ICONST_0 : + case ICONST_1 : + case ICONST_2 : + case ICONST_3 : + case ICONST_4 : + case ICONST_5 : + case FCONST_0 : + case FCONST_1 : + case FCONST_2 : + stack.push_back(bytecode); + break; + + case LCONST_0 : + case LCONST_1 : + case DCONST_0 : + case DCONST_1 : + stack.push_back(bytecode); + stack.push_back(bytecode); + break; + + case BIPUSH : + ++i; + stack.push_back(bytecode); + break; + + case SIPUSH : + i += 2; + stack.push_back(bytecode); + break; + + case LDC : + i++; + stack.push_back(bytecode); + if (!canInlineLoadConstant(reader.readU1())) return false; + break; + + case LDC_W : + i += 2; + stack.push_back(bytecode); + if (!canInlineLoadConstant(reader.readS2())) return false; + break; + + + case LDC2_W : + i += 2; + stack.push_back(bytecode); + stack.push_back(bytecode); + if (!canInlineLoadConstant(reader.readS2())) return false; + break; + + case ILOAD : + case FLOAD : + case ALOAD : + i += WCALC(1, wide); + stack.push_back(bytecode); + break; + + case LLOAD : + case DLOAD : + i += WCALC(1, wide); + stack.push_back(bytecode); + stack.push_back(bytecode); + break; + + case ILOAD_0 : + case ILOAD_1 : + case ILOAD_2 : + case ILOAD_3 : + case FLOAD_0 : + case FLOAD_1 : + case FLOAD_2 : + case FLOAD_3 : + case ALOAD_0 : + case ALOAD_1 : + case ALOAD_2 : + case ALOAD_3 : + stack.push_back(bytecode); + break; + + case LLOAD_0 : + case LLOAD_1 : + case LLOAD_2 : + case LLOAD_3 : + case DLOAD_0 : + case DLOAD_1 : + case DLOAD_2 : + case DLOAD_3 : + stack.push_back(bytecode); + stack.push_back(bytecode); + break; + + case IALOAD : + case FALOAD : + case AALOAD : + case BALOAD : + case CALOAD : + case SALOAD : + stack.pop_back(); + stack.pop_back(); + stack.push_back(bytecode); + return false; + + case LALOAD : + case DALOAD : + stack.pop_back(); + stack.pop_back(); + stack.push_back(bytecode); + stack.push_back(bytecode); + return false; + + case ISTORE : + case FSTORE : + case ASTORE : + stack.pop_back(); + i += WCALC(1, wide); + break; + + case LSTORE : + case DSTORE : + stack.pop_back(); + stack.pop_back(); + i += WCALC(1, wide); + break; + + case ISTORE_0 : + case ISTORE_1 : + case ISTORE_2 : + case ISTORE_3 : + case FSTORE_0 : + case FSTORE_1 : + case FSTORE_2 : + case FSTORE_3 : + case ASTORE_0 : + case ASTORE_1 : + case ASTORE_2 : + case ASTORE_3 : + stack.pop_back(); + break; + + case DSTORE_0 : + case DSTORE_1 : + case DSTORE_2 : + case DSTORE_3 : + case LSTORE_0 : + case LSTORE_1 : + case LSTORE_2 : + case LSTORE_3 : + stack.pop_back(); + stack.pop_back(); + break; + + case IASTORE : + case FASTORE : + case AASTORE : + case BASTORE : + case CASTORE : + case SASTORE : + stack.pop_back(); + stack.pop_back(); + stack.pop_back(); + return false; + + case LASTORE : + case DASTORE : + stack.pop_back(); + stack.pop_back(); + stack.pop_back(); + stack.pop_back(); + return false; + + case POP : + stack.pop_back(); + break; + + case POP2 : + stack.pop_back(); + stack.pop_back(); + break; + + case DUP : + stack.push_back(stack.back()); + break; + + case DUP_X1 : { + uint8 one = stack.back(); stack.pop_back(); + uint8 two = stack.back(); stack.pop_back(); + + stack.push_back(one); + stack.push_back(two); + stack.push_back(one); + break; + } + + case DUP_X2 : { + uint8 one = stack.back(); stack.pop_back(); + uint8 two = stack.back(); stack.pop_back(); + uint8 three = stack.back(); stack.pop_back(); + + stack.push_back(one); + stack.push_back(three); + stack.push_back(two); + stack.push_back(one); + break; + } + + case DUP2 : { + uint8 one = stack.back(); stack.pop_back(); + uint8 two = stack.back(); stack.pop_back(); + + stack.push_back(two); + stack.push_back(one); + stack.push_back(two); + stack.push_back(one); + break; + } + + case DUP2_X1 : { + uint8 one = stack.back(); stack.pop_back(); + uint8 two = stack.back(); stack.pop_back(); + uint8 three = stack.back(); stack.pop_back(); + + stack.push_back(two); + stack.push_back(one); + stack.push_back(three); + stack.push_back(two); + stack.push_back(one); + + break; + } + + case DUP2_X2 : { + uint8 one = stack.back(); stack.pop_back(); + uint8 two = stack.back(); stack.pop_back(); + uint8 three = stack.back(); stack.pop_back(); + uint8 four = stack.back(); stack.pop_back(); + + stack.push_back(two); + stack.push_back(one); + stack.push_back(four); + stack.push_back(three); + stack.push_back(two); + stack.push_back(one); + + break; + } + + case SWAP : { + uint8 one = stack.back(); stack.pop_back(); + uint8 two = stack.back(); stack.pop_back(); + stack.push_back(one); + stack.push_back(two); + break; + } + + case IADD : + case FADD : + case ISUB : + case FSUB : + case IMUL : + case FMUL : + case FDIV : + case FREM : + case ISHL : + case ISHR : + case IUSHR : + case IAND : + case IOR : + case IXOR : + stack.pop_back(); + stack.pop_back(); + stack.push_back(bytecode); + break; + + case LADD : + case DADD : + case DDIV : + case LMUL : + case DMUL : + case DREM : + case LSUB : + case DSUB : + stack.pop_back(); + stack.pop_back(); + stack.push_back(bytecode); + stack.push_back(bytecode); + break; + + case IREM : + case IDIV : + case LREM : + case LDIV : + return false; + + case INEG : + case FNEG : + stack.pop_back(); + stack.push_back(bytecode); + break; + + case LNEG : + case DNEG : + stack.pop_back(); + stack.pop_back(); + stack.push_back(bytecode); + stack.push_back(bytecode); + break; + + case LSHL : + case LSHR : + case LUSHR : + case LAND : + case LOR : + case LXOR : + stack.pop_back(); + stack.pop_back(); + stack.pop_back(); + stack.push_back(bytecode); + stack.push_back(bytecode); + break; + + case IINC : + i += WCALC(2, wide); + break; + + case I2L : + case I2D : + case F2L : + case F2D : + stack.pop_back(); + stack.push_back(bytecode); + stack.push_back(bytecode); + break; + + case I2F : + case F2I : + case I2B : + case I2C : + case I2S : + stack.pop_back(); + stack.push_back(bytecode); + break; + + case L2I : + case L2F : + case D2I : + case D2F : + stack.pop_back(); + stack.pop_back(); + stack.push_back(bytecode); + break; + + case L2D : + case D2L : + stack.pop_back(); + stack.pop_back(); + stack.push_back(bytecode); + stack.push_back(bytecode); + break; + + case FCMPL : + case FCMPG : + stack.pop_back(); + stack.pop_back(); + stack.push_back(bytecode); + break; + + case LCMP : + case DCMPL : + case DCMPG : + stack.pop_back(); + stack.pop_back(); + stack.pop_back(); + stack.pop_back(); + stack.push_back(bytecode); + break; + + case IFEQ : + case IFNE : + case IFLT : + case IFGE : + case IFGT : + case IFLE : { + i += 2; + stack.pop_back(); + if (stack.size() > 0) return false; + break; + } + + case IF_ICMPEQ : + case IF_ICMPNE : + case IF_ICMPLT : + case IF_ICMPGE : + case IF_ICMPGT : + case IF_ICMPLE : + case IF_ACMPEQ : + case IF_ACMPNE : { + i += 2; + stack.pop_back(); + stack.pop_back(); + if (stack.size() > 0) return false; + break; + } + case GOTO : { + i += 2; + if (stack.size() > 0) return false; + break; + } + + case JSR : { + i += 2; + return false; + } + + case RET : { + ++i; + return false; + } + + case TABLESWITCH : { + stack.pop_back(); + if (stack.size() > 0) return false; + uint32 tmp = i; + uint32 reste = (i + 1) & 3; + uint32 filled = reste ? (4 - reste) : 0; + i += filled; + reader.cursor += filled; + reader.readU4(); + i += 4; + + sint32 low = reader.readS4(); + i += 4; + sint32 high = reader.readS4() + 1; + i += 4; + for (sint32 cur = low; cur < high; ++cur) { + reader.readU4(); + i += 4; + } + + i = tmp + 12 + filled + ((high - low) << 2); + break; + } + + case LOOKUPSWITCH : { + stack.pop_back(); + if (stack.size() > 0) return false; + uint32 tmp = i; + uint32 filled = (3 - i) & 3; + i += filled; + reader.cursor += filled; + reader.readU4(); + i += 4; + uint32 nbs = reader.readU4(); + i += 4; + for (uint32 cur = 0; cur < nbs; ++cur) { + i += 4; + reader.cursor += 4; + reader.readU4(); + i += 4; + } + + i = tmp + 8 + filled + (nbs << 3); + break; + } + + case IRETURN : + case FRETURN : + case ARETURN : + stack.pop_back(); + break; + + case RETURN : + break; + + case LRETURN : + case DRETURN : + stack.pop_back(); + stack.pop_back(); + break; + + case GETSTATIC : + case PUTSTATIC : { + uint16 index = reader.readU2(); + Typedef* sign = ctpInfo->infoOfField(index); + JavaField* field = ctpInfo->lookupField(index, true); + if (field == NULL) return false; + if (needsInitialisationCheck(field->classDef)) return false; + if (bytecode == GETSTATIC) { + stack.push_back(bytecode); + if (sign->isDouble() || sign->isLong()) { + stack.push_back(bytecode); + } + } else { + stack.pop_back(); + if (sign->isDouble() || sign->isLong()) { + stack.pop_back(); + } + } + i += 2; + break; + } + + case PUTFIELD : { + if (isStatic(compilingMethod->access)) return false; + i += 2; + stack.pop_back(); // value + uint16 index = reader.readU2(); + Typedef* sign = ctpInfo->infoOfField(index); + if (sign->isDouble() || sign->isLong()) { + stack.pop_back(); // value + } + if (stack.back() != ALOAD_0) return false; + stack.pop_back(); // object + break; + } + + case GETFIELD : { + if (isStatic(compilingMethod->access)) return false; + if (stack.back() != ALOAD_0) return false; + i += 2; + stack.pop_back(); // object + uint16 index = reader.readU2(); + Typedef* sign = ctpInfo->infoOfField(index); + stack.push_back(bytecode); + if (sign->isDouble() || sign->isLong()) { + stack.push_back(bytecode); + } + break; + } + + case INVOKEVIRTUAL : + i += 2; + return false; + + case INVOKESPECIAL : { + if (isStatic(compilingMethod->access)) return false; + uint16 index = reader.readU2(); + CommonClass* cl = NULL; + JavaMethod* meth = NULL; + ctpInfo->infoOfMethod(index, ACC_VIRTUAL, cl, meth); + i += 2; + if (meth == NULL) return false; + if (getReceiver(stack, meth->getSignature()) != ALOAD_0) return false; + if (!canBeInlined(meth)) return false; + updateStack(stack, meth->getSignature(), bytecode); + break; + } + + case INVOKESTATIC : { + uint16 index = reader.readU2(); + CommonClass* cl = NULL; + JavaMethod* meth = NULL; + ctpInfo->infoOfMethod(index, ACC_STATIC, cl, meth); + i += 2; + if (meth == NULL) return false; + if (!canBeInlined(meth)) return false; + if (needsInitialisationCheck(cl->asClass())) return false; + updateStack(stack, meth->getSignature(), bytecode); + break; + } + + case INVOKEINTERFACE : + i += 4; + return false; + + case NEW : + i += 2; + return false; + + case NEWARRAY : + ++i; + return false; + + case ANEWARRAY : + i += 2; + return false; + + case ARRAYLENGTH : + stack.pop_back(); + stack.push_back(bytecode); + break; + + case ATHROW : + return false; + + case CHECKCAST : + i += 2; + return false; + + case INSTANCEOF : + i += 2; + return false; + + case MONITORENTER : + case MONITOREXIT : + return false; + + case MULTIANEWARRAY : + i += 3; + return false; + + case WIDE : + wide = true; + break; + + case IFNULL : + case IFNONNULL : + stack.pop_back(); + i += 2; + if (stack.size() > 0) return false; + break; + + default : + return false; + } + } + return true; +} From nicolas.geoffray at lip6.fr Sun Sep 18 14:07:53 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 18 Sep 2011 21:07:53 -0000 Subject: [vmkit-commits] [vmkit] r140006 - /vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp Message-ID: <20110918210753.78C482A6C12C@llvm.org> Author: geoffray Date: Sun Sep 18 16:07:53 2011 New Revision: 140006 URL: http://llvm.org/viewvc/llvm-project?rev=140006&view=rev Log: Also try to inline methods that do INVOKEVIRTUAL calls. Modified: vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp Modified: vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp?rev=140006&r1=140005&r2=140006&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp Sun Sep 18 16:07:53 2011 @@ -3314,9 +3314,20 @@ break; } - case INVOKEVIRTUAL : + case INVOKEVIRTUAL : { + if (isStatic(compilingMethod->access)) return false; + uint16 index = reader.readU2(); + CommonClass* cl = NULL; + JavaMethod* meth = NULL; + ctpInfo->infoOfMethod(index, ACC_VIRTUAL, cl, meth); i += 2; - return false; + if (meth == NULL) return false; + if (getReceiver(stack, meth->getSignature()) != ALOAD_0) return false; + if (!(isFinal(cl->access) || isFinal(meth->access))) return false; + if (!canBeInlined(meth)) return false; + updateStack(stack, meth->getSignature(), bytecode); + break; + } case INVOKESPECIAL : { if (isStatic(compilingMethod->access)) return false; From nicolas.geoffray at lip6.fr Tue Sep 20 09:41:43 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Tue, 20 Sep 2011 16:41:43 -0000 Subject: [vmkit-commits] [vmkit] r140148 - in /vmkit/trunk: include/j3/JavaAOTCompiler.h lib/J3/Compiler/JavaAOTCompiler.cpp lib/J3/Compiler/JavaJIT.cpp lib/J3/Compiler/JavaJITCompiler.cpp lib/J3/VMCore/JavaClass.cpp lib/Mvm/MMTk/MvmGC.cpp lib/Mvm/MMTk/MvmGC.h lib/Mvm/Runtime/Object.cpp mmtk/mmtk-alloc/Selected.cpp tests/ tests/InvokeFinalizerTest.java Message-ID: <20110920164143.D0F962A6C12C@llvm.org> Author: geoffray Date: Tue Sep 20 11:41:43 2011 New Revision: 140148 URL: http://llvm.org/viewvc/llvm-project?rev=140148&view=rev Log: Always put a method for the destructor, in case it gets invoked directly. Added: vmkit/trunk/tests/ vmkit/trunk/tests/InvokeFinalizerTest.java Modified: vmkit/trunk/include/j3/JavaAOTCompiler.h 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/VMCore/JavaClass.cpp vmkit/trunk/lib/Mvm/MMTk/MvmGC.cpp vmkit/trunk/lib/Mvm/MMTk/MvmGC.h vmkit/trunk/lib/Mvm/Runtime/Object.cpp vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp Modified: vmkit/trunk/include/j3/JavaAOTCompiler.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/JavaAOTCompiler.h?rev=140148&r1=140147&r2=140148&view=diff ============================================================================== --- vmkit/trunk/include/j3/JavaAOTCompiler.h (original) +++ vmkit/trunk/include/j3/JavaAOTCompiler.h Tue Sep 20 11:41:43 2011 @@ -175,6 +175,7 @@ llvm::Function* ArrayObjectTracer; llvm::Function* RegularObjectTracer; llvm::Function* JavaObjectTracer; + llvm::Function* EmptyDestructorFunction; llvm::Function* ReferenceObjectTracer; llvm::GlobalVariable* UTF8TombstoneGV; llvm::GlobalVariable* UTF8EmptyGV; Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=140148&r1=140147&r2=140148&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Tue Sep 20 11:41:43 2011 @@ -1603,14 +1603,15 @@ std::vector Elemts; // Destructor - Function* Finalizer = 0; - JavaMethod* meth = (JavaMethod*)(RealVT->destructor); - if (meth) { + Function* Finalizer = NULL; + if (VT->hasDestructor()) { + JavaMethod* meth = (JavaMethod*)(RealVT->destructor); Finalizer = getMethodOrStub(meth); + } else { + Finalizer = EmptyDestructorFunction; } - Elemts.push_back(Finalizer ? - ConstantExpr::getCast(Instruction::BitCast, Finalizer, PTy) : N); + Elemts.push_back(ConstantExpr::getCast(Instruction::BitCast, Finalizer, PTy)); // Delete Elemts.push_back(N); @@ -1869,6 +1870,12 @@ GlobalValue::ExternalLinkage, "ReferenceObjectTracer", getLLVMModule()); + + EmptyDestructorFunction = Function::Create(FTy, + GlobalValue::ExternalLinkage, + "EmptyDestructor", + getLLVMModule()); + UTF8EmptyGV = new GlobalVariable(*getLLVMModule(), JavaIntrinsics.UTF8Type->getContainedType(0), @@ -2004,7 +2011,7 @@ ((void**)VT)[meth.offset] = &meth; } - if (!cl->super) VT->destructor = 0; + if (!cl->super) VT->destructor = reinterpret_cast(EmptyDestructor); } void JavaAOTCompiler::makeIMT(Class* cl) { Modified: vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp?rev=140148&r1=140147&r2=140148&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp Tue Sep 20 11:41:43 2011 @@ -1767,7 +1767,7 @@ // Make sure to add the object to the finalization list after it has been // pushed. - if (cl && cl->virtualVT->destructor) { + if (cl && cl->virtualVT->hasDestructor()) { CallInst::Create(intrinsics->AddFinalizationCandidate, val, "", currentBlock); } } Modified: vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp?rev=140148&r1=140147&r2=140148&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp Tue Sep 20 11:41:43 2011 @@ -203,9 +203,7 @@ // Special handling for finalize method. Don't put a finalizer // if there is none, or if it is empty. if (meth.offset == 0) { - if (!cl->super) { - meth.canBeInlined = true; - } else { + if (cl->super != NULL) { VT->destructor = getPointerOrStub(meth, JavaMethod::Virtual); } } else { Modified: vmkit/trunk/lib/J3/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaClass.cpp?rev=140148&r1=140147&r2=140148&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JavaClass.cpp Tue Sep 20 11:41:43 2011 @@ -1367,7 +1367,6 @@ } else { tracer = (uintptr_t)RegularObjectTracer; } - destructor = 0; operatorDelete = 0; // Set IMT. @@ -1436,7 +1435,6 @@ } else { // Set the tracer, destructor and delete. tracer = (uintptr_t)JavaObjectTracer; - destructor = 0; operatorDelete = 0; // Set the class of this VT. @@ -1447,7 +1445,6 @@ offset = getCacheIndex() + 1; depth = 0; display[0] = this; - destructor = 0; nbSecondaryTypes = 0; } } @@ -1635,7 +1632,6 @@ } else { // Set the tracer, destructor and delete tracer = (uintptr_t)JavaObjectTracer; - destructor = 0; operatorDelete = 0; // Set the class of this VT. Modified: vmkit/trunk/lib/Mvm/MMTk/MvmGC.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/MMTk/MvmGC.cpp?rev=140148&r1=140147&r2=140148&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/MMTk/MvmGC.cpp (original) +++ vmkit/trunk/lib/Mvm/MMTk/MvmGC.cpp Tue Sep 20 11:41:43 2011 @@ -36,7 +36,7 @@ extern "C" void* gcmallocUnresolved(uint32_t sz, VirtualTable* VT) { gc* res = (gc*)gcmalloc(sz, VT); - if (VT->destructor) + if (VT->hasDestructor()) mvm::Thread::get()->MyVM->addFinalizationCandidate(res); return res; } Modified: vmkit/trunk/lib/Mvm/MMTk/MvmGC.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/MMTk/MvmGC.h?rev=140148&r1=140147&r2=140148&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/MMTk/MvmGC.h (original) +++ vmkit/trunk/lib/Mvm/MMTk/MvmGC.h Tue Sep 20 11:41:43 2011 @@ -14,6 +14,8 @@ #include "mvm/GC/GC.h" #include +extern "C" void EmptyDestructor(); + class VirtualTable { public: uintptr_t destructor; @@ -39,7 +41,13 @@ tracer = t; } - VirtualTable() {} + VirtualTable() { + destructor = reinterpret_cast(EmptyDestructor); + } + + bool hasDestructor() { + return destructor != reinterpret_cast(EmptyDestructor); + } static void emptyTracer(void*) {} }; Modified: vmkit/trunk/lib/Mvm/Runtime/Object.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/Object.cpp?rev=140148&r1=140147&r2=140148&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Runtime/Object.cpp (original) +++ vmkit/trunk/lib/Mvm/Runtime/Object.cpp Tue Sep 20 11:41:43 2011 @@ -35,6 +35,9 @@ fprintf(stderr, "%p\n", ptr); } +extern "C" void EmptyDestructor() { +} + void VirtualMachine::waitForExit() { threadLock.lock(); Modified: vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp?rev=140148&r1=140147&r2=140148&view=diff ============================================================================== --- vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp (original) +++ vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp Tue Sep 20 11:41:43 2011 @@ -74,7 +74,7 @@ gc* res = 0; llvm_gcroot(res, 0); res = (gc*)gcmalloc(sz, VT); - if (VT->destructor) addFinalizationCandidate(res); + if (VT->hasDestructor()) addFinalizationCandidate(res); return res; } Added: vmkit/trunk/tests/InvokeFinalizerTest.java URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tests/InvokeFinalizerTest.java?rev=140148&view=auto ============================================================================== --- vmkit/trunk/tests/InvokeFinalizerTest.java (added) +++ vmkit/trunk/tests/InvokeFinalizerTest.java Tue Sep 20 11:41:43 2011 @@ -0,0 +1,5 @@ +public class InvokeFinalizerTest { + public static void main(String[] args) throws Throwable { + new InvokeFinalizerTest().finalize(); + } +} From nicolas.geoffray at lip6.fr Wed Sep 21 12:16:19 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Wed, 21 Sep 2011 19:16:19 -0000 Subject: [vmkit-commits] [vmkit] r140272 - /vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp Message-ID: <20110921191619.D8A7E2A6C12C@llvm.org> Author: geoffray Date: Wed Sep 21 14:16:19 2011 New Revision: 140272 URL: http://llvm.org/viewvc/llvm-project?rev=140272&view=rev Log: Do not inline methods that do ARRAYLENGTH, otherwise a NPE may occur. Modified: vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp Modified: vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp?rev=140272&r1=140271&r2=140272&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp Wed Sep 21 14:16:19 2011 @@ -3375,7 +3375,7 @@ case ARRAYLENGTH : stack.pop_back(); stack.push_back(bytecode); - break; + return false; case ATHROW : return false; From nicolas.geoffray at lip6.fr Wed Sep 21 13:38:12 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Wed, 21 Sep 2011 20:38:12 -0000 Subject: [vmkit-commits] [vmkit] r140274 - /vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp Message-ID: <20110921203812.C27D72A6C12C@llvm.org> Author: geoffray Date: Wed Sep 21 15:38:12 2011 New Revision: 140274 URL: http://llvm.org/viewvc/llvm-project?rev=140274&view=rev Log: Don't inline virtual methods that overwrite 'this'. Modified: vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp Modified: vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp?rev=140274&r1=140273&r2=140274&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp Wed Sep 21 15:38:12 2011 @@ -2917,13 +2917,17 @@ case FSTORE_1 : case FSTORE_2 : case FSTORE_3 : - case ASTORE_0 : case ASTORE_1 : case ASTORE_2 : case ASTORE_3 : stack.pop_back(); break; + case ASTORE_0 : + stack.pop_back(); + if (!isStatic(compilingMethod->access)) return false; + break; + case DSTORE_0 : case DSTORE_1 : case DSTORE_2 : From nicolas.geoffray at lip6.fr Sun Sep 25 02:47:13 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 25 Sep 2011 09:47:13 -0000 Subject: [vmkit-commits] [vmkit] r140468 - in /vmkit/trunk: include/j3/JavaLLVMCompiler.h lib/J3/Compiler/JavaAOTCompiler.cpp tools/precompiler/Precompiler.cpp Message-ID: <20110925094713.A7BB82A6C12C@llvm.org> Author: geoffray Date: Sun Sep 25 04:47:13 2011 New Revision: 140468 URL: http://llvm.org/viewvc/llvm-project?rev=140468&view=rev Log: Use the information of the JIT compiler to know what method to compile. Don't rely on JavaMethod.code. Modified: vmkit/trunk/include/j3/JavaLLVMCompiler.h vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp vmkit/trunk/tools/precompiler/Precompiler.cpp Modified: vmkit/trunk/include/j3/JavaLLVMCompiler.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/JavaLLVMCompiler.h?rev=140468&r1=140467&r2=140468&view=diff ============================================================================== --- vmkit/trunk/include/j3/JavaLLVMCompiler.h (original) +++ vmkit/trunk/include/j3/JavaLLVMCompiler.h Sun Sep 25 04:47:13 2011 @@ -42,6 +42,7 @@ class Signdef; class JavaLLVMCompiler : public JavaCompiler { + friend class JavaAOTCompiler; friend class LLVMClassInfo; friend class LLVMMethodInfo; friend class LLVMSignatureInfo; Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=140468&r1=140467&r2=140468&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Sun Sep 25 04:47:13 2011 @@ -2307,6 +2307,8 @@ } void JavaAOTCompiler::compileClassLoader(JnjvmBootstrapLoader* loader) { + JavaJITCompiler* jitCompiler = (JavaJITCompiler*)loader->getCompiler(); + loader->setCompiler(this); compileRT = true; precompile = true; addJavaPasses(); @@ -2334,34 +2336,15 @@ } } - 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); - } - } - } + for (method_info_iterator I = jitCompiler->method_infos.begin(), + E = jitCompiler->method_infos.end(); I != E; I++) { + if (!isAbstract(I->first->access)) parseFunction(I->first); } while (!toCompile.empty()) { JavaMethod* meth = toCompile.back(); toCompile.pop_back(); - getNativeClass(meth->classDef); - Function* Func = parseFunction(meth); - // Also update code to notify that this function has been emitted. - meth->code = Func; + parseFunction(meth); } // Make sure classes and arrays already referenced in constant pools Modified: vmkit/trunk/tools/precompiler/Precompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/precompiler/Precompiler.cpp?rev=140468&r1=140467&r2=140468&view=diff ============================================================================== --- vmkit/trunk/tools/precompiler/Precompiler.cpp (original) +++ vmkit/trunk/tools/precompiler/Precompiler.cpp Sun Sep 25 04:47:13 2011 @@ -43,8 +43,9 @@ static void mainCompilerLoaderStart(JavaThread* th) { Jnjvm* vm = th->getJVM(); JnjvmBootstrapLoader* bootstrapLoader = vm->bootstrapLoader; - JavaAOTCompiler* M = (JavaAOTCompiler*)bootstrapLoader->getCompiler(); - M->compileClassLoader(bootstrapLoader); + JavaAOTCompiler* AOT = new JavaAOTCompiler("AOT"); + AOT->compileClassLoader(bootstrapLoader); + AOT->printStats(); vm->exit(); } @@ -67,8 +68,9 @@ // Create the allocator that will allocate the bootstrap loader and the JVM. mvm::BumpPtrAllocator Allocator; - JavaAOTCompiler* AOT = new JavaAOTCompiler("AOT"); + JavaAOTCompiler* AOT; if (EmitClassBytes) { + AOT = new JavaAOTCompiler("AOT"); OutputFilename = "classes.bc"; JnjvmBootstrapLoader* loader = new(Allocator, "Bootstrap loader") JnjvmBootstrapLoader(Allocator, AOT, true); @@ -85,16 +87,15 @@ vm->waitForExit(); // Now AOT Compile all compiled methods. - loader->setCompiler(AOT); - vm->doExit = false; JavaThread* th = new JavaThread(vm); vm->setMainThread(th); th->start((void (*)(mvm::Thread*))mainCompilerLoaderStart); vm->waitForExit(); + + AOT = (JavaAOTCompiler*)loader->getCompiler(); } - AOT->printStats(); // Emit the bytecode in file. std::string ErrorInfo; From nicolas.geoffray at lip6.fr Sun Sep 25 13:06:36 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 25 Sep 2011 20:06:36 -0000 Subject: [vmkit-commits] [vmkit] r140473 - in /vmkit/trunk/lib/J3/Compiler: JavaAOTCompiler.cpp LLVMInfo.cpp Message-ID: <20110925200636.DD5282A6C12C@llvm.org> Author: geoffray Date: Sun Sep 25 15:06:36 2011 New Revision: 140473 URL: http://llvm.org/viewvc/llvm-project?rev=140473&view=rev Log: Cleanup and fix bug where the code pointer of methods was not set because of old method.code check. Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=140473&r1=140472&r2=140473&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Sun Sep 25 15:06:36 2011 @@ -1050,7 +1050,7 @@ MethodElts.push_back(ConstantInt::get(Type::getInt8Ty(getLLVMContext()), method.canBeInlined)); // code - if (method.code == NULL) { + if (getMethodInfo(&method)->methodFunction == NULL) { MethodElts.push_back(Constant::getNullValue(JavaIntrinsics.ptrType)); } else { Function* func = getMethod(&method); @@ -2343,6 +2343,8 @@ while (!toCompile.empty()) { JavaMethod* meth = toCompile.back(); + // parseFunction may introduce new functions to compile, so + // pop toCompile before calling parseFunction. toCompile.pop_back(); parseFunction(meth); } Modified: vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp?rev=140473&r1=140472&r2=140473&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp Sun Sep 25 15:06:36 2011 @@ -142,8 +142,6 @@ Function* LLVMMethodInfo::getMethod() { if (!methodFunction) { - mvm::ThreadAllocator allocator; - JnjvmClassLoader* JCL = methodDef->classDef->classLoader; if (Compiler->emitFunctionName() || JITEmitDebugInfo) { const UTF8* jniConsClName = methodDef->classDef->name; const UTF8* jniConsName = methodDef->name; @@ -152,15 +150,10 @@ sint32 mnlen = jniConsName->size; sint32 mtlen = jniConsType->size; + mvm::ThreadAllocator allocator; char* buf = (char*)allocator.Allocate( 3 + JNI_NAME_PRE_LEN + 1 + ((mnlen + clen + mtlen) << 3)); - bool j3 = false; - if (isNative(methodDef->access)) { - // Verify if it's defined by J3 - JCL->nativeLookup(methodDef, j3, buf); - } - methodDef->jniConsFromMethOverloaded(buf + 1); memcpy(buf, "JnJVM", 5); From nicolas.geoffray at lip6.fr Mon Sep 26 12:18:43 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Mon, 26 Sep 2011 19:18:43 -0000 Subject: [vmkit-commits] [vmkit] r140555 - in /vmkit/trunk/lib/J3: Classpath/ClasspathVMClass.inc VMCore/JavaArray.cpp VMCore/JavaArray.h Message-ID: <20110926191843.ADAF02A6C12C@llvm.org> Author: geoffray Date: Mon Sep 26 14:18:43 2011 New Revision: 140555 URL: http://llvm.org/viewvc/llvm-project?rev=140555&view=rev Log: Bugfix in VMClass.getDeclaredClasses, and add asserts to help find these bugs. Modified: vmkit/trunk/lib/J3/Classpath/ClasspathVMClass.inc vmkit/trunk/lib/J3/VMCore/JavaArray.cpp vmkit/trunk/lib/J3/VMCore/JavaArray.h Modified: vmkit/trunk/lib/J3/Classpath/ClasspathVMClass.inc URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Classpath/ClasspathVMClass.inc?rev=140555&r1=140554&r2=140555&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Classpath/ClasspathVMClass.inc (original) +++ vmkit/trunk/lib/J3/Classpath/ClasspathVMClass.inc Mon Sep 26 14:18:43 2011 @@ -566,11 +566,13 @@ } result = (ArrayObject*)array->doNew(sizeArray, vm); + int index = 0; for (uint16 i = 0; i < cl->nbInnerClasses; ++i) { UserClass* klass = cl->innerClasses[i]; if (!publicOnly || isPublic(klass->innerAccess)) - ArrayObject::setElement(result, klass->getClassDelegatee(vm), i); + ArrayObject::setElement(result, klass->getClassDelegatee(vm), index++); } + assert(index == sizeArray); } Modified: vmkit/trunk/lib/J3/VMCore/JavaArray.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaArray.cpp?rev=140555&r1=140554&r2=140555&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaArray.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JavaArray.cpp Mon Sep 26 14:18:43 2011 @@ -38,6 +38,7 @@ void ArrayObject::setElement(ArrayObject* self, JavaObject* value, uint32_t i) { llvm_gcroot(self, 0); llvm_gcroot(value, 0); + assert(i < self->size); 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=140555&r1=140554&r2=140555&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaArray.h (original) +++ vmkit/trunk/lib/J3/VMCore/JavaArray.h Mon Sep 26 14:18:43 2011 @@ -53,11 +53,13 @@ static T getElement(const TJavaArray* self, uint32_t i) { llvm_gcroot(self, 0); + assert(i < self->size); return self->elements[i]; } static void setElement(TJavaArray* self, T value, uint32_t i) { llvm_gcroot(self, 0); + assert(i < self->size); self->elements[i] = value; } @@ -92,6 +94,7 @@ static JavaObject* getElement(const ArrayObject* self, uint32_t i) { llvm_gcroot(self, 0); + assert(i < self->size); return self->elements[i]; } From nicolas.geoffray at lip6.fr Tue Sep 27 11:28:55 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Tue, 27 Sep 2011 18:28:55 -0000 Subject: [vmkit-commits] [vmkit] r140617 - in /vmkit/trunk: include/j3/JavaAOTCompiler.h include/j3/JavaCompiler.h include/j3/JavaJITCompiler.h include/j3/JavaLLVMCompiler.h include/j3/LLVMInfo.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/JavaLLVMCompiler.cpp lib/J3/Compiler/LLVMInfo.cpp lib/J3/VMCore/JavaClass.cpp lib/J3/VMCore/JavaClass.h lib/J3/VMCore/JavaRuntimeJIT.cpp lib/J3/VMCore/Jnjvm.cpp Message-ID: <20110927182855.8AB042A6C12C@llvm.org> Author: geoffray Date: Tue Sep 27 13:28:55 2011 New Revision: 140617 URL: http://llvm.org/viewvc/llvm-project?rev=140617&view=rev Log: Customize methods when jitting. Modified: vmkit/trunk/include/j3/JavaAOTCompiler.h vmkit/trunk/include/j3/JavaCompiler.h vmkit/trunk/include/j3/JavaJITCompiler.h vmkit/trunk/include/j3/JavaLLVMCompiler.h vmkit/trunk/include/j3/LLVMInfo.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/JavaLLVMCompiler.cpp vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp vmkit/trunk/lib/J3/VMCore/JavaClass.cpp vmkit/trunk/lib/J3/VMCore/JavaClass.h vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp Modified: vmkit/trunk/include/j3/JavaAOTCompiler.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/JavaAOTCompiler.h?rev=140617&r1=140616&r2=140617&view=diff ============================================================================== --- vmkit/trunk/include/j3/JavaAOTCompiler.h (original) +++ vmkit/trunk/include/j3/JavaAOTCompiler.h Tue Sep 27 13:28:55 2011 @@ -40,7 +40,7 @@ return new JavaAOTCompiler(ModuleID); } - virtual void* materializeFunction(JavaMethod* meth) { + virtual void* materializeFunction(JavaMethod* meth, Class* customizeFor) { fprintf(stderr, "Can not materiale a function in AOT mode."); abort(); } @@ -52,7 +52,7 @@ virtual llvm::Value* addCallback(Class* cl, uint16 index, Signdef* sign, bool stat, llvm::BasicBlock* insert); - virtual llvm::Function* getMethod(JavaMethod* meth); + virtual llvm::Function* getMethod(JavaMethod* meth, Class* customizeFor); virtual void makeVT(Class* cl); virtual void makeIMT(Class* cl); @@ -125,7 +125,7 @@ std::map virtualMethods; std::map finalObjects; std::map reverseFinalObjects; - std::vector toCompile; + std::vector > toCompile; typedef std::map::iterator final_object_iterator; @@ -201,7 +201,7 @@ private: void compileAllStubs(Signdef* sign); - llvm::Function* getMethodOrStub(JavaMethod* meth); + llvm::Function* getMethodOrStub(JavaMethod* meth, Class* customizeFor); }; } // end namespace j3 Modified: vmkit/trunk/include/j3/JavaCompiler.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/JavaCompiler.h?rev=140617&r1=140616&r2=140617&view=diff ============================================================================== --- vmkit/trunk/include/j3/JavaCompiler.h (original) +++ vmkit/trunk/include/j3/JavaCompiler.h Tue Sep 27 13:28:55 2011 @@ -40,7 +40,7 @@ return this; } - virtual void* materializeFunction(JavaMethod* meth) { + virtual void* materializeFunction(JavaMethod* meth, Class* customizeFor) { fprintf(stderr, "Materializing a function in an empty compiler"); abort(); return 0; Modified: vmkit/trunk/include/j3/JavaJITCompiler.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/JavaJITCompiler.h?rev=140617&r1=140616&r2=140617&view=diff ============================================================================== --- vmkit/trunk/include/j3/JavaJITCompiler.h (original) +++ vmkit/trunk/include/j3/JavaJITCompiler.h Tue Sep 27 13:28:55 2011 @@ -57,7 +57,7 @@ virtual void makeVT(Class* cl); virtual void makeIMT(Class* cl); - virtual void* materializeFunction(JavaMethod* meth); + virtual void* materializeFunction(JavaMethod* meth, Class* customizeFor); virtual llvm::Constant* getFinalObject(JavaObject* obj, CommonClass* cl); virtual JavaObject* getFinalObject(llvm::Value* C); Modified: vmkit/trunk/include/j3/JavaLLVMCompiler.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/JavaLLVMCompiler.h?rev=140617&r1=140616&r2=140617&view=diff ============================================================================== --- vmkit/trunk/include/j3/JavaLLVMCompiler.h (original) +++ vmkit/trunk/include/j3/JavaLLVMCompiler.h Tue Sep 27 13:28:55 2011 @@ -75,9 +75,6 @@ std::map class_infos; typedef std::map::iterator class_info_iterator; - std::map DbgInfos; - typedef std::map::iterator dbg_iterator; - llvm::DenseMap virtualStubs; llvm::DenseMap specialStubs; llvm::DenseMap staticStubs; @@ -131,11 +128,10 @@ virtual ~JavaLLVMCompiler(); JavaMethod* getJavaMethod(const llvm::Function&); - llvm::MDNode* GetDbgSubprogram(JavaMethod* meth); void resolveVirtualClass(Class* cl); void resolveStaticClass(Class* cl); - virtual llvm::Function* getMethod(JavaMethod* meth); + virtual llvm::Function* getMethod(JavaMethod* meth, Class* customizeFor); void initialiseAssessorInfo(); std::map AssessorInfo; @@ -209,8 +205,9 @@ virtual void setMethod(llvm::Function* func, void* ptr, const char* name) = 0; - virtual void* materializeFunction(JavaMethod* meth) = 0; - llvm::Function* parseFunction(JavaMethod* meth); + virtual void* materializeFunction(JavaMethod* meth, + Class* customizeFor) = 0; + llvm::Function* parseFunction(JavaMethod* meth, Class* customizeFor); llvm::FunctionPassManager* JavaFunctionPasses; llvm::FunctionPassManager* JavaNativeFunctionPasses; Modified: vmkit/trunk/include/j3/LLVMInfo.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/LLVMInfo.h?rev=140617&r1=140616&r2=140617&view=diff ============================================================================== --- vmkit/trunk/include/j3/LLVMInfo.h (original) +++ vmkit/trunk/include/j3/LLVMInfo.h Tue Sep 27 13:28:55 2011 @@ -85,27 +85,28 @@ llvm::Function* methodFunction; llvm::Constant* offsetConstant; llvm::FunctionType* functionType; - llvm::MDNode* DbgSubprogram; + std::map customizedVersions; public: - llvm::Function* getMethod(); + llvm::Function* getMethod(Class* customizeFor); llvm::Constant* getOffset(); llvm::FunctionType* getFunctionType(); + bool isCustomizable; LLVMMethodInfo(JavaMethod* M, JavaLLVMCompiler* comp) : Compiler(comp), methodDef(M), methodFunction(0), offsetConstant(0), functionType(0), - DbgSubprogram(0) {} + isCustomizable(false) {} - void setDbgSubprogram(llvm::MDNode* node) { DbgSubprogram = node; } - llvm::MDNode* getDbgSubprogram() { return DbgSubprogram; } - virtual void clear() { methodFunction = 0; offsetConstant = 0; functionType = 0; - DbgSubprogram = 0; + customizedVersions.clear(); + isCustomizable = false; } + void setCustomizedVersion(Class* customizeFor, llvm::Function* F); + friend class JavaAOTCompiler; }; Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=140617&r1=140616&r2=140617&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Tue Sep 27 13:28:55 2011 @@ -1047,13 +1047,13 @@ MethodElts.push_back(getUTF8(method.type)); // canBeInlined - MethodElts.push_back(ConstantInt::get(Type::getInt8Ty(getLLVMContext()), method.canBeInlined)); + MethodElts.push_back(ConstantInt::get(Type::getInt8Ty(getLLVMContext()), method.isCustomizable)); // code if (getMethodInfo(&method)->methodFunction == NULL) { MethodElts.push_back(Constant::getNullValue(JavaIntrinsics.ptrType)); } else { - Function* func = getMethod(&method); + Function* func = getMethod(&method, NULL); MethodElts.push_back(ConstantExpr::getCast(Instruction::BitCast, func, JavaIntrinsics.ptrType)); } @@ -1567,22 +1567,51 @@ } } -Function* JavaAOTCompiler::getMethodOrStub(JavaMethod* meth) { +Function* JavaAOTCompiler::getMethodOrStub(JavaMethod* meth, Class* customizeFor) { assert(!isStatic(meth->access)); - if (precompile - && (meth->code == NULL) - && (getMethodInfo(meth)->methodFunction == NULL)) { - LLVMSignatureInfo* LSI = getSignatureInfo(meth->getSignature()); - return LSI->getVirtualStub(); + LLVMMethodInfo* LMI = getMethodInfo(meth); + LLVMSignatureInfo* LSI = getSignatureInfo(meth->getSignature()); + if (precompile) { + if (customizeFor != NULL) { + if (LMI->isCustomizable) { + if (LMI->customizedVersions[customizeFor] != NULL) { + // We have a customized version, get it. + return getMethod(meth, customizeFor); + } else { + // No customized version, even if there is an uncustomized version, + // we return the stub, so that we get a customized version at + // runtime. + return LSI->getVirtualStub(); + } + } else { + // If we have created a method for it, we know the method is not customizable, + // and we can use the 'general' method. + if (LMI->methodFunction) { + return getMethod(meth, NULL); + } else { + // Otherwise, no method has been created for it. + return LSI->getVirtualStub(); + } + } + } else { + // If we have created a method for it, take it. + if (LMI->methodFunction) { + return getMethod(meth, NULL); + } else { + // Otherwise, no method has been created for it. + return LSI->getVirtualStub(); + } + } } else { - return getMethod(meth); + // We're not precompiling, get the method. + return getMethod(meth, customizeFor); } } -Function* JavaAOTCompiler::getMethod(JavaMethod* meth) { - Function* func = getMethodInfo(meth)->getMethod(); +Function* JavaAOTCompiler::getMethod(JavaMethod* meth, Class* customizeFor) { + Function* func = getMethodInfo(meth)->getMethod(customizeFor); if (func->hasExternalWeakLinkage()) { - toCompile.push_back(meth); + toCompile.push_back(std::make_pair(meth, customizeFor)); } return func; } @@ -1594,6 +1623,8 @@ JavaVirtualTable* RealVT = classDef->isClass() ? VT : ClassArray::SuperArray->virtualVT; + Class* maybeCustomize = classDef->isClass() ? classDef->asClass() : NULL; + ArrayType* ATy = dyn_cast(JavaIntrinsics.VTType->getContainedType(0)); PointerType* PTy = dyn_cast(ATy->getContainedType(0)); @@ -1606,7 +1637,7 @@ Function* Finalizer = NULL; if (VT->hasDestructor()) { JavaMethod* meth = (JavaMethod*)(RealVT->destructor); - Finalizer = getMethodOrStub(meth); + Finalizer = getMethodOrStub(meth, maybeCustomize); } else { Finalizer = EmptyDestructorFunction; } @@ -1729,7 +1760,7 @@ Imeth->type, false, true, 0); assert(meth && "No method found"); - Function* func = getMethodOrStub(meth); + Function* func = getMethodOrStub(meth, maybeCustomize); IElemts.push_back(ConstantExpr::getBitCast(func, PTy)); } else if (size > 1) { std::vector methods; @@ -1750,7 +1781,7 @@ if (SameMethod) { assert(methods[0] && "No method found"); - Function* func = getMethodOrStub(methods[0]); + Function* func = getMethodOrStub(methods[0], maybeCustomize); IElemts.push_back(ConstantExpr::getBitCast(func, PTy)); } else { @@ -1769,7 +1800,7 @@ JavaMethod* Cmeth = *it; assert(Cmeth && "No method found"); - Function* func = getMethodOrStub(Cmeth); + Function* func = getMethodOrStub(Cmeth, maybeCustomize); InternalElemts.push_back( ConstantExpr::getBitCast(getMethodInClass(Imeth), PTy)); InternalElemts.push_back(ConstantExpr::getBitCast(func, PTy)); @@ -1804,10 +1835,10 @@ // methods for (uint32 i = JavaVirtualTable::getFirstJavaMethodIndex(); i < size; ++i) { JavaMethod* meth = ((JavaMethod**)RealVT)[i]; - Function* F = getMethodOrStub(meth); if (isAbstract(meth->access)) { Elemts.push_back(Constant::getNullValue(PTy)); } else { + Function* F = getMethodOrStub(meth, maybeCustomize); Elemts.push_back(ConstantExpr::getCast(Instruction::BitCast, F, PTy)); } } @@ -2054,13 +2085,13 @@ for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) { JavaMethod& meth = cl->virtualMethods[i]; - if (!isAbstract(meth.access)) parseFunction(&meth); + if (!isAbstract(meth.access)) parseFunction(&meth, NULL); if (generateStubs) compileAllStubs(meth.getSignature()); } for (uint32 i = 0; i < cl->nbStaticMethods; ++i) { JavaMethod& meth = cl->staticMethods[i]; - if (!isAbstract(meth.access)) parseFunction(&meth); + if (!isAbstract(meth.access)) parseFunction(&meth, NULL); if (generateStubs) compileAllStubs(meth.getSignature()); } } @@ -2158,11 +2189,11 @@ cl->setOwnerClass(JavaThread::get()); for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) { - M->getMethod(&cl->virtualMethods[i]); + M->getMethod(&cl->virtualMethods[i], NULL); } for (uint32 i = 0; i < cl->nbStaticMethods; ++i) { - M->getMethod(&cl->staticMethods[i]); + M->getMethod(&cl->staticMethods[i], NULL); } } @@ -2182,7 +2213,7 @@ magic.length() - 1)) { for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) { if (!isAbstract(cl->virtualMethods[i].access)) { - Function* F = M->getMethod(&cl->virtualMethods[i]); + Function* F = M->getMethod(&cl->virtualMethods[i], NULL); M->setMethod(F, ptr, F->getName().data()); cl->virtualMethods[i].compiledPtr(); // Set native so that we don't try to inline it. @@ -2192,7 +2223,7 @@ for (uint32 i = 0; i < cl->nbStaticMethods; ++i) { if (!isAbstract(cl->staticMethods[i].access)) { - Function* F = M->getMethod(&cl->staticMethods[i]); + Function* F = M->getMethod(&cl->staticMethods[i], NULL); M->setMethod(F, ptr, F->getName().data()); cl->staticMethods[i].compiledPtr(); // Set native so that we don't try to inline it. @@ -2338,15 +2369,26 @@ for (method_info_iterator I = jitCompiler->method_infos.begin(), E = jitCompiler->method_infos.end(); I != E; I++) { - if (!isAbstract(I->first->access)) parseFunction(I->first); + if (!isAbstract(I->first->access)) { + LLVMMethodInfo* LMI = I->second; + if (LMI->methodFunction) { + parseFunction(I->first, NULL); + } + for (std::map::iterator + CI = LMI->customizedVersions.begin(), + CE = LMI->customizedVersions.end(); CI != CE; CI++) { + parseFunction(I->first, NULL); + } + } } while (!toCompile.empty()) { - JavaMethod* meth = toCompile.back(); + JavaMethod* meth = toCompile.back().first; + // Class* customizeFor = toCompile.back().second; // parseFunction may introduce new functions to compile, so // pop toCompile before calling parseFunction. toCompile.pop_back(); - parseFunction(meth); + parseFunction(meth, NULL); } // Make sure classes and arrays already referenced in constant pools @@ -2368,6 +2410,8 @@ gv->setInitializer(CreateConstantFromVT(VT)); } + assert(toCompile.size() == 0); + // Add used stubs to the image. for (SignMap::iterator i = loader->javaSignatures->map.begin(), e = loader->javaSignatures->map.end(); i != e; i++) { Modified: vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp?rev=140617&r1=140616&r2=140617&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp Tue Sep 27 13:28:55 2011 @@ -21,6 +21,7 @@ #include #include #include +#include "llvm/Analysis/DIBuilder.h" #include #include "mvm/JIT.h" @@ -44,6 +45,20 @@ using namespace j3; using namespace llvm; +void JavaJIT::updateStackInfo(Opinfo& info) { + if (stackSize()) { + if (!info.stack.size()) { + info.stack = stack; + } else { + int size = stack.size(); + info.stack.clear(); + for (int i = 0 ; i < size; i++) { + info.stack.push_back(MetaInfo(stack[i].type, NOP)); + } + } + } +} + bool JavaJIT::needsInitialisationCheck(Class* cl) { if (cl->isReadyForCompilation() || (!cl->isInterface() && compilingClass->isAssignableFrom(cl))) { @@ -60,7 +75,7 @@ return true; } -bool JavaJIT::canBeInlined(JavaMethod* meth) { +bool JavaJIT::canBeInlined(JavaMethod* meth, bool customizing) { if (inlineMethods[meth]) return false; if (isSynchro(meth->access)) return false; if (isNative(meth->access)) return false; @@ -78,7 +93,7 @@ if (nbHandlers != 0) return false; reader.cursor = start; - JavaJIT jit(TheCompiler, meth, llvmFunction); + JavaJIT jit(TheCompiler, meth, llvmFunction, customizing ? customizeFor : NULL); jit.inlineMethods = inlineMethods; jit.inlineMethods[meth] = true; if (!jit.analyzeForInlining(reader, codeLen)) return false; @@ -94,20 +109,39 @@ ctpInfo->infoOfMethod(index, ACC_VIRTUAL, cl, meth); bool canBeDirect = false; Value* val = NULL; // The return from the method. + const UTF8* name = 0; + Signdef* signature = ctpInfo->infoOfInterfaceOrVirtualMethod(index, name); if ((cl && isFinal(cl->access)) || (meth && (isFinal(meth->access) || isPrivate(meth->access)))) { canBeDirect = true; } + bool customized = false; + if (!canBeDirect) { + if (!overridesThis + && (stack[stackSize() - signature->nbArguments - 1].bytecode == ALOAD_0) + && !isStatic(compilingMethod->access)) { + assert(meth != NULL); + isCustomizable = true; + if (customizeFor != NULL) { + meth = customizeFor->lookupMethodDontThrow( + meth->name, meth->type, false, true, NULL); + assert(meth); + canBeDirect = true; + customized = true; + assert(!meth->classDef->isInterface()); + assert(!isAbstract(meth->access)); + } + } + } + if (meth && isInterface(meth->classDef->access)) { // This can happen because we compute miranda methods before resolving // interfaces. return invokeInterface(index); } - const UTF8* name = 0; - Signdef* signature = ctpInfo->infoOfInterfaceOrVirtualMethod(index, name); if (TheCompiler->isStaticCompiling()) { Value* obj = objectStack[stack.size() - signature->nbArguments - 1]; @@ -137,14 +171,14 @@ llvm::Type* retType = virtualType->getReturnType(); bool needsInit = false; - if (canBeDirect && canBeInlined(meth)) { + if (canBeDirect && canBeInlined(meth, customized)) { makeArgs(it, index, args, signature->nbArguments + 1); JITVerifyNull(args[0]); - val = invokeInline(meth, args); + val = invokeInline(meth, args, customized); } else if (canBeDirect && !TheCompiler->needsCallback(meth, &needsInit)) { makeArgs(it, index, args, signature->nbArguments + 1); JITVerifyNull(args[0]); - val = invoke(TheCompiler->getMethod(meth), args, "", currentBlock); + val = invoke(TheCompiler->getMethod(meth, NULL), args, "", currentBlock); } else { BasicBlock* endBlock = 0; @@ -900,7 +934,8 @@ UTF8Buffer(compilingClass->name).cString(), UTF8Buffer(compilingMethod->name).cString()); - DbgSubprogram = TheCompiler->GetDbgSubprogram(compilingMethod); + DbgSubprogram = TheCompiler->getDebugFactory()->createFunction( + DIDescriptor(), "", "", DIFile(), 0, DIType(), false, false); Attribut* codeAtt = compilingMethod->lookupAttribut(Attribut::codeAttribut); @@ -1480,8 +1515,9 @@ Instruction* JavaJIT::invokeInline(JavaMethod* meth, - std::vector& args) { - JavaJIT jit(TheCompiler, meth, llvmFunction); + std::vector& args, + bool customized) { + JavaJIT jit(TheCompiler, meth, llvmFunction, customized ? customizeFor : NULL); jit.unifiedUnreachable = unifiedUnreachable; jit.inlineMethods = inlineMethods; jit.inlineMethods[meth] = true; @@ -1489,12 +1525,13 @@ jit.DbgSubprogram = DbgSubprogram; #if DEBUG static int inlineNb = 0; - fprintf(stderr, "inline compile %d %s.%s%s from %s.%s\n", inlineNb++, + fprintf(stderr, "inline compile %d %s.%s%s from %s.%s (%d)\n", inlineNb++, UTF8Buffer(meth->classDef->name).cString(), UTF8Buffer(meth->name).cString(), UTF8Buffer(meth->getSignature()->keyName).cString(), UTF8Buffer(compilingClass->name).cString(), - UTF8Buffer(compilingMethod->name).cString()); + UTF8Buffer(compilingMethod->name).cString(), + customized); #endif Instruction* ret = jit.inlineCompile(currentBlock, @@ -1531,7 +1568,7 @@ func = TheCompiler->addCallback(compilingClass, index, signature, false, currentBlock); } else { - func = TheCompiler->getMethod(meth); + func = TheCompiler->getMethod(meth, NULL); } std::vector args; @@ -1544,8 +1581,8 @@ } llvm::Instruction* val = 0; - if (meth && canBeInlined(meth)) { - val = invokeInline(meth, args); + if (meth && canBeInlined(meth, false)) { + val = invokeInline(meth, args, false); } else { val = invoke(func, args, "", currentBlock); } @@ -1599,7 +1636,7 @@ func = TheCompiler->addCallback(compilingClass, index, signature, true, currentBlock); } else { - func = TheCompiler->getMethod(meth); + func = TheCompiler->getMethod(meth, NULL); } std::vector args; // size = [signature->nbIn + 2]; @@ -1615,8 +1652,8 @@ } if (val == NULL) { - if (meth != NULL && canBeInlined(meth)) { - val = invokeInline(meth, args); + if (meth != NULL && canBeInlined(meth, false)) { + val = invokeInline(meth, args, false); } else { val = invoke(func, args, "", currentBlock); } @@ -2209,7 +2246,7 @@ } void JavaJIT::lowerArraycopy(std::vector& args) { - Function* meth = TheCompiler->getMethod(upcalls->VMSystemArraycopy); + Function* meth = TheCompiler->getMethod(upcalls->VMSystemArraycopy, NULL); Value* ptr_src = args[0]; Value* int32_start = args[1]; Modified: vmkit/trunk/lib/J3/Compiler/JavaJIT.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJIT.h?rev=140617&r1=140616&r2=140617&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJIT.h (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJIT.h Tue Sep 27 13:28:55 2011 @@ -36,6 +36,12 @@ class JavaMethod; class Reader; +struct MetaInfo { + MetaInfo(CommonClass* t, uint8 b) : type(t), bytecode(b) {} + CommonClass* type; + uint8 bytecode; +}; + /// Opinfo - This class gives for each opcode if it starts a new block and /// its exception destination. /// @@ -57,10 +63,9 @@ /// stack - The stack at this location if there is a new block /// - std::vector stack; + std::vector stack; }; - /// JavaJIT - The compilation engine of J3. Parses the bycode and returns /// its LLVM representation. /// @@ -68,7 +73,10 @@ public: /// JavaJIT - Default constructor. - JavaJIT(JavaLLVMCompiler* C, JavaMethod* meth, llvm::Function* func) { + JavaJIT(JavaLLVMCompiler* C, + JavaMethod* meth, + llvm::Function* func, + Class* customized) { compilingMethod = meth; compilingClass = meth->classDef; upcalls = compilingClass->classLoader->bootstrapLoader->upcalls; @@ -81,7 +89,11 @@ endNode = 0; currentStackIndex = 0; currentBytecodeIndex = 0; + currentBytecode = 0; thisObject = NULL; + customizeFor = customized; + isCustomizable = false; + overridesThis = false; } /// javaCompile - Compile the Java method. @@ -89,8 +101,16 @@ /// nativeCompile - Compile the native method. llvm::Function* nativeCompile(intptr_t natPtr = 0); + + /// isCustomizable - Whether we found the method to be customizable. + bool isCustomizable; private: + /// Whether the method overrides 'this'. + bool overridesThis; + + /// currentBytecode - The current bytecode being processed. + uint16 currentBytecode; /// compilingClass - The class that is defining the method being compiled. Class* compilingClass; @@ -98,6 +118,9 @@ /// compilingMethod - The method being compiled. JavaMethod* compilingMethod; + /// customizeFor - The class we're currently customizing this method for. + Class* customizeFor; + /// upcalls - Upcalls used tp type the stack and locals. Classpath* upcalls; @@ -188,7 +211,7 @@ bool inlining; /// canBeInlined - Can this method's body be inlined? - bool canBeInlined(JavaMethod* meth); + bool canBeInlined(JavaMethod* meth, bool customizing); /// callsStackWalker - Is the method calling a stack walker method? If it is, /// then this method can not be inlined. @@ -232,7 +255,7 @@ //===------------------------- Stack manipulation -------------------------===// /// stack - The compiler stack. - std::vector stack; + std::vector stack; uint32 currentStackIndex; std::vector objectStack; std::vector intStack; @@ -247,36 +270,36 @@ val = new llvm::ZExtInst(val, llvm::Type::getInt32Ty(*llvmContext), "", currentBlock); new llvm::StoreInst(val, intStack[currentStackIndex++], false, currentBlock); - stack.push_back(upcalls->OfInt); + stack.push_back(MetaInfo(upcalls->OfInt, currentBytecode)); } else if (type == llvm::Type::getInt8Ty(*llvmContext) || type == llvm::Type::getInt16Ty(*llvmContext)) { val = new llvm::SExtInst(val, llvm::Type::getInt32Ty(*llvmContext), "", currentBlock); new llvm::StoreInst(val, intStack[currentStackIndex++], false, currentBlock); - stack.push_back(upcalls->OfInt); + stack.push_back(MetaInfo(upcalls->OfInt, currentBytecode)); } else if (type == llvm::Type::getInt32Ty(*llvmContext)) { new llvm::StoreInst(val, intStack[currentStackIndex++], false, currentBlock); - stack.push_back(upcalls->OfInt); + stack.push_back(MetaInfo(upcalls->OfInt, currentBytecode)); } else if (type == llvm::Type::getInt64Ty(*llvmContext)) { new llvm::StoreInst(val, longStack[currentStackIndex++], false, currentBlock); - stack.push_back(upcalls->OfLong); + stack.push_back(MetaInfo(upcalls->OfLong, currentBytecode)); } else if (type == llvm::Type::getFloatTy(*llvmContext)) { new llvm::StoreInst(val, floatStack[currentStackIndex++], false, currentBlock); - stack.push_back(upcalls->OfFloat); + stack.push_back(MetaInfo(upcalls->OfFloat, currentBytecode)); } else if (type == llvm::Type::getDoubleTy(*llvmContext)) { new llvm::StoreInst(val, doubleStack[currentStackIndex++], false, currentBlock); - stack.push_back(upcalls->OfDouble); + stack.push_back(MetaInfo(upcalls->OfDouble, currentBytecode)); } else { assert(type == intrinsics->JavaObjectType && "Can't handle this type"); llvm::Instruction* V = new llvm::StoreInst(val, objectStack[currentStackIndex++], false, currentBlock); - stack.push_back(cl ? cl : upcalls->OfObject); + stack.push_back(MetaInfo(cl ? cl : upcalls->OfObject, currentBytecode)); addHighLevelType(V, topTypeInfo()); if (llvm::Instruction* I = llvm::dyn_cast(val)) { addHighLevelType(I, topTypeInfo()); @@ -305,7 +328,7 @@ /// top - Return the value on top of the stack. llvm::Value* top() { - CommonClass* cl = stack.back(); + CommonClass* cl = stack.back().type; if (cl == upcalls->OfInt) { return new llvm::LoadInst(intStack[currentStackIndex - 1], "", false, currentBlock); @@ -326,6 +349,10 @@ /// topTypeInfo - Return the type of the value on top of the stack. CommonClass* topTypeInfo() { + return stack.back().type; + } + + MetaInfo topInfo() { return stack.back(); } @@ -378,22 +405,20 @@ llvm::BasicBlock* createBasicBlock(const char* name = "") { return llvm::BasicBlock::Create(*llvmContext, name, llvmFunction); } + + void updateStackInfo(Opinfo& info); /// branch - Branch based on a boolean value. void branch(llvm::Value* test, llvm::BasicBlock* ifTrue, llvm::BasicBlock* ifFalse, llvm::BasicBlock* insert, Opinfo& info) { - if (stackSize()) - if (!info.stack.size()) - info.stack = stack; + updateStackInfo(info); llvm::BranchInst::Create(ifTrue, ifFalse, test, insert); } /// branch - Branch to a new block. void branch(Opinfo& info, llvm::BasicBlock* insert) { - if (stackSize()) - if (!info.stack.size()) - info.stack = stack; + updateStackInfo(info); llvm::BranchInst::Create(info.newBlock, insert); } @@ -484,7 +509,8 @@ /// invokeInline - Instead of calling the method, inline it. llvm::Instruction* invokeInline(JavaMethod* meth, - std::vector& args); + std::vector& args, + bool customized); /// lowerMathOps - Map Java Math operations to LLVM intrinsics. llvm::Instruction* lowerMathOps(const UTF8* name, Modified: vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp?rev=140617&r1=140616&r2=140617&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp Tue Sep 27 13:28:55 2011 @@ -185,33 +185,19 @@ // is nothing left to do! return; } - - if (cl->super) { - // Copy the super VT into the current VT. - uint32 size = cl->super->virtualTableSize - - JavaVirtualTable::getFirstJavaMethodIndex(); - memcpy(VT->getFirstJavaMethod(), cl->super->virtualVT->getFirstJavaMethod(), - size * sizeof(uintptr_t)); - VT->destructor = cl->super->virtualVT->destructor; - } - - - // Fill the virtual table with function pointers. - for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) { - JavaMethod& meth = cl->virtualMethods[i]; - - // Special handling for finalize method. Don't put a finalizer - // if there is none, or if it is empty. - if (meth.offset == 0) { - if (cl->super != NULL) { - VT->destructor = getPointerOrStub(meth, JavaMethod::Virtual); + + Class* current = cl; + uintptr_t* functions = VT->getFunctions(); + while (current != NULL) { + // Fill the virtual table with function pointers. + for (uint32 i = 0; i < current->nbVirtualMethods; ++i) { + JavaMethod& meth = current->virtualMethods[i]; + if (meth.offset != 0 || current->super != NULL) { + functions[meth.offset] = getPointerOrStub(meth, JavaMethod::Virtual); } - } else { - VT->getFunctions()[meth.offset] = getPointerOrStub(meth, - JavaMethod::Virtual); } + current = current->super; } - } extern "C" void ThrowUnfoundInterface() { @@ -322,9 +308,9 @@ executionEngine->updateGlobalMapping(func, ptr); } -void* JavaJITCompiler::materializeFunction(JavaMethod* meth) { +void* JavaJITCompiler::materializeFunction(JavaMethod* meth, Class* customizeFor) { mvm::MvmModule::protectIR(); - Function* func = parseFunction(meth); + Function* func = parseFunction(meth, customizeFor); void* res = executionEngine->getPointerToGlobal(func); if (!func->isDeclaration()) { @@ -337,6 +323,9 @@ func->deleteBody(); } mvm::MvmModule::unprotectIR(); + if (customizeFor == NULL || !getMethodInfo(meth)->isCustomizable) { + meth->code = res; + } return res; } Modified: vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp?rev=140617&r1=140616&r2=140617&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp Tue Sep 27 13:28:55 2011 @@ -136,7 +136,7 @@ assert(isa(I) && "Handler marlformed"); // If it's a handler, put the exception object in the stack. new StoreInst(I, objectStack[0], "", currentBlock); - stack.push_back(upcalls->OfObject); + stack.push_back(MetaInfo(upcalls->OfObject, NOP)); currentStackIndex = 1; } else { stack = opinfo->stack; @@ -147,6 +147,7 @@ currentExceptionBlock = opinfo->exceptionBlock; currentBytecodeIndex = i; + currentBytecode = bytecode; // To prevent a gcj bug with useless goto if (currentBlock->getTerminator() != 0) { @@ -786,6 +787,7 @@ break; case DUP : + // TODO: The following bytecodes should push a MetaInfo. push(top(), false, topTypeInfo()); break; @@ -2464,7 +2466,6 @@ case DSTORE_1 : case DSTORE_2 : case DSTORE_3 : - case ASTORE_0 : case ASTORE_1 : case ASTORE_2 : case ASTORE_3 : @@ -2521,6 +2522,10 @@ case LOR : case IXOR : case LXOR : break; + + case ASTORE_0 : + if (!isStatic(compilingMethod->access)) overridesThis = true; + break; case IINC : i += WCALC(2, wide); @@ -3327,8 +3332,17 @@ i += 2; if (meth == NULL) return false; if (getReceiver(stack, meth->getSignature()) != ALOAD_0) return false; - if (!(isFinal(cl->access) || isFinal(meth->access))) return false; - if (!canBeInlined(meth)) return false; + bool customized = false; + if (!(isFinal(cl->access) || isFinal(meth->access))) { + if (customizeFor == NULL) return false; + meth = customizeFor->lookupMethodDontThrow( + meth->name, meth->type, false, true, NULL); + assert(meth); + assert(!meth->classDef->isInterface()); + assert(!isAbstract(meth->access)); + customized = true; + } + if (!canBeInlined(meth, customized)) return false; updateStack(stack, meth->getSignature(), bytecode); break; } @@ -3342,7 +3356,7 @@ i += 2; if (meth == NULL) return false; if (getReceiver(stack, meth->getSignature()) != ALOAD_0) return false; - if (!canBeInlined(meth)) return false; + if (!canBeInlined(meth, false)) return false; updateStack(stack, meth->getSignature(), bytecode); break; } @@ -3354,7 +3368,7 @@ ctpInfo->infoOfMethod(index, ACC_STATIC, cl, meth); i += 2; if (meth == NULL) return false; - if (!canBeInlined(meth)) return false; + if (!canBeInlined(meth, false)) return false; if (needsInitialisationCheck(cl->asClass())) return false; updateStack(stack, meth->getSignature(), bytecode); break; Modified: vmkit/trunk/lib/J3/Compiler/JavaLLVMCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaLLVMCompiler.cpp?rev=140617&r1=140616&r2=140617&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaLLVMCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaLLVMCompiler.cpp Tue Sep 27 13:28:55 2011 @@ -48,18 +48,18 @@ mvm::MvmModule::unprotectIR(); } -Function* JavaLLVMCompiler::getMethod(JavaMethod* meth) { - return getMethodInfo(meth)->getMethod(); +Function* JavaLLVMCompiler::getMethod(JavaMethod* meth, Class* customizeFor) { + return getMethodInfo(meth)->getMethod(customizeFor); } -Function* JavaLLVMCompiler::parseFunction(JavaMethod* meth) { +Function* JavaLLVMCompiler::parseFunction(JavaMethod* meth, Class* customizeFor) { LLVMMethodInfo* LMI = getMethodInfo(meth); - Function* func = LMI->getMethod(); + Function* func = LMI->getMethod(customizeFor); // We are jitting. Take the lock. mvm::MvmModule::protectIR(); if (func->getLinkage() == GlobalValue::ExternalWeakLinkage) { - JavaJIT jit(this, meth, func); + JavaJIT jit(this, meth, func, customizeFor); if (isNative(meth->access)) { jit.nativeCompile(); mvm::MvmModule::runPasses(func, JavaNativeFunctionPasses); @@ -68,6 +68,15 @@ mvm::MvmModule::runPasses(func, JavaFunctionPasses); } func->setLinkage(GlobalValue::ExternalLinkage); + if (!LMI->isCustomizable && jit.isCustomizable) { + // It's the first time we parsed the method and we just found + // out it can be customized. + meth->isCustomizable = true; + LMI->isCustomizable = true; + if (customizeFor != NULL) { + LMI->setCustomizedVersion(customizeFor, func); + } + } } mvm::MvmModule::unprotectIR(); @@ -81,18 +90,6 @@ return I->second; } -MDNode* JavaLLVMCompiler::GetDbgSubprogram(JavaMethod* meth) { - if (getMethodInfo(meth)->getDbgSubprogram() == NULL) { - MDNode* node = DebugFactory->createFunction(DIDescriptor(), "", - "", DIFile(), 0, - DIType(), false, - false); - DbgInfos.insert(std::make_pair(node, meth)); - getMethodInfo(meth)->setDbgSubprogram(node); - } - return getMethodInfo(meth)->getDbgSubprogram(); -} - JavaLLVMCompiler::~JavaLLVMCompiler() { LLVMContext* Context = &(TheModule->getContext()); delete TheModule; Modified: vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp?rev=140617&r1=140616&r2=140617&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp Tue Sep 27 13:28:55 2011 @@ -140,8 +140,17 @@ extern bool JITEmitDebugInfo; } -Function* LLVMMethodInfo::getMethod() { - if (!methodFunction) { +Function* LLVMMethodInfo::getMethod(Class* customizeFor) { + bool customizing = false; + Function* result = NULL; + if (customizeFor != NULL && isCustomizable) { + customizing = true; + result = customizedVersions[customizeFor]; + } else { + result = methodFunction; + } + + if (result == NULL) { if (Compiler->emitFunctionName() || JITEmitDebugInfo) { const UTF8* jniConsClName = methodDef->classDef->name; const UTF8* jniConsName = methodDef->name; @@ -157,25 +166,37 @@ methodDef->jniConsFromMethOverloaded(buf + 1); memcpy(buf, "JnJVM", 5); - methodFunction = Function::Create(getFunctionType(), - GlobalValue::ExternalWeakLinkage, buf, - Compiler->getLLVMModule()); + result = Function::Create(getFunctionType(), + GlobalValue::ExternalWeakLinkage, buf, + Compiler->getLLVMModule()); } else { - methodFunction = Function::Create(getFunctionType(), - GlobalValue::ExternalWeakLinkage, - "", Compiler->getLLVMModule()); + result = Function::Create(getFunctionType(), + GlobalValue::ExternalWeakLinkage, + "", Compiler->getLLVMModule()); } - methodFunction->setGC("vmkit"); - methodFunction->addFnAttr(Attribute::NoInline); - methodFunction->addFnAttr(Attribute::NoUnwind); + result->setGC("vmkit"); + result->addFnAttr(Attribute::NoInline); + result->addFnAttr(Attribute::NoUnwind); - Compiler->functions.insert(std::make_pair(methodFunction, methodDef)); - if (!Compiler->isStaticCompiling() && methodDef->code) { - Compiler->setMethod(methodFunction, methodDef->code, methodFunction->getName().data()); + Compiler->functions.insert(std::make_pair(result, methodDef)); + if (!Compiler->isStaticCompiling() && !customizing && methodDef->code) { + Compiler->setMethod(result, methodDef->code, result->getName().data()); } } - return methodFunction; + + if (customizing) { + customizedVersions[customizeFor] = result; + } else { + methodFunction = result; + } + return result; +} + +void LLVMMethodInfo::setCustomizedVersion(Class* cl, llvm::Function* F) { + assert(customizedVersions.size() == 0); + methodFunction = NULL; + customizedVersions[cl] = F; } FunctionType* LLVMMethodInfo::getFunctionType() { Modified: vmkit/trunk/lib/J3/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaClass.cpp?rev=140617&r1=140616&r2=140617&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JavaClass.cpp Tue Sep 27 13:28:55 2011 @@ -269,9 +269,9 @@ return res; } -void* JavaMethod::compiledPtr() { - if (code == 0) { - code = classDef->classLoader->getCompiler()->materializeFunction(this); +void* JavaMethod::compiledPtr(Class* customizeFor) { + if ((isCustomizable && customizeFor != NULL) || code == 0) { + return classDef->classLoader->getCompiler()->materializeFunction(this, customizeFor); } return code; } @@ -633,7 +633,7 @@ _signature = 0; code = 0; access = A; - canBeInlined = false; + isCustomizable = false; offset = 0; } Modified: vmkit/trunk/lib/J3/VMCore/JavaClass.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaClass.h?rev=140617&r1=140616&r2=140617&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaClass.h (original) +++ vmkit/trunk/lib/J3/VMCore/JavaClass.h Tue Sep 27 13:28:55 2011 @@ -845,7 +845,7 @@ /// compiledPtr - Return a pointer to the compiled code of this Java method, /// compiling it if necessary. /// - void* compiledPtr(); + void* compiledPtr(Class* customizeFor = NULL); /// setNative - Set the method as native. /// @@ -880,9 +880,9 @@ /// const UTF8* type; - /// canBeInlined - Can the method be inlined? + /// isCustomizable - Can the method be customizable? /// - bool canBeInlined; + bool isCustomizable; /// code - Pointer to the compiled code of this method. /// Modified: vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp?rev=140617&r1=140616&r2=140617&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp Tue Sep 27 13:28:55 2011 @@ -584,7 +584,7 @@ } // Compile the found method. - result = Virt->compiledPtr(); + result = Virt->compiledPtr(lookup); // Update the virtual table. assert(lookup->isResolved() && "Class not resolved"); Modified: vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp?rev=140617&r1=140616&r2=140617&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp Tue Sep 27 13:28:55 2011 @@ -1267,7 +1267,7 @@ } END_CATCH; if (exc != NULL) { - fprintf(stderr, "Exception %s while bootstrapping VM.", + fprintf(stderr, "Exception %s while bootstrapping VM.\n", UTF8Buffer(JavaObject::getClass(exc)->name).cString()); } else { ClArgumentsInfo& info = vm->argumentsInfo; From nicolas.geoffray at lip6.fr Wed Sep 28 14:25:02 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Wed, 28 Sep 2011 21:25:02 -0000 Subject: [vmkit-commits] [vmkit] r140727 - in /vmkit/trunk/lib: J3/Compiler/JavaAOTCompiler.cpp J3/Compiler/LLVMInfo.cpp J3/VMCore/JavaClass.cpp J3/VMCore/UTF8.h Mvm/StaticGCPrinter/VmkitGCPrinter.cpp Message-ID: <20110928212502.DC9C72A6C12C@llvm.org> Author: geoffray Date: Wed Sep 28 16:25:02 2011 New Revision: 140727 URL: http://llvm.org/viewvc/llvm-project?rev=140727&view=rev Log: Support customization for precompiled code. 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/UTF8.h vmkit/trunk/lib/Mvm/StaticGCPrinter/VmkitGCPrinter.cpp Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=140727&r1=140726&r2=140727&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Wed Sep 28 16:25:02 2011 @@ -2377,18 +2377,18 @@ for (std::map::iterator CI = LMI->customizedVersions.begin(), CE = LMI->customizedVersions.end(); CI != CE; CI++) { - parseFunction(I->first, NULL); + parseFunction(I->first, CI->first); } } } while (!toCompile.empty()) { JavaMethod* meth = toCompile.back().first; - // Class* customizeFor = toCompile.back().second; + Class* customizeFor = toCompile.back().second; // parseFunction may introduce new functions to compile, so // pop toCompile before calling parseFunction. toCompile.pop_back(); - parseFunction(meth, NULL); + parseFunction(meth, customizeFor); } // Make sure classes and arrays already referenced in constant pools Modified: vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp?rev=140727&r1=140726&r2=140727&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp Wed Sep 28 16:25:02 2011 @@ -140,6 +140,32 @@ extern bool JITEmitDebugInfo; } +static char* GetMethodName(mvm::ThreadAllocator& allocator, + JavaMethod* methodDef, + Class* customizeFor) { + const UTF8* jniConsClName = methodDef->classDef->name; + const UTF8* jniConsName = methodDef->name; + const UTF8* jniConsType = methodDef->type; + sint32 clen = jniConsClName->size; + sint32 mnlen = jniConsName->size; + sint32 mtlen = jniConsType->size; + + char* buf = (char*)allocator.Allocate( + 3 + JNI_NAME_PRE_LEN + 1 + ((mnlen + clen + mtlen) << 3)); + + methodDef->jniConsFromMethOverloaded(buf + 1); + memcpy(buf, "JnJVM", 5); + + if (customizeFor != NULL) { + int len = strlen(buf); + buf[len] = '_'; + buf[len + 1] = '_'; + buf[len + 2] = 0; + } + + return buf; +} + Function* LLVMMethodInfo::getMethod(Class* customizeFor) { bool customizing = false; Function* result = NULL; @@ -152,20 +178,9 @@ if (result == NULL) { if (Compiler->emitFunctionName() || JITEmitDebugInfo) { - const UTF8* jniConsClName = methodDef->classDef->name; - const UTF8* jniConsName = methodDef->name; - const UTF8* jniConsType = methodDef->type; - sint32 clen = jniConsClName->size; - sint32 mnlen = jniConsName->size; - sint32 mtlen = jniConsType->size; - mvm::ThreadAllocator allocator; - char* buf = (char*)allocator.Allocate( - 3 + JNI_NAME_PRE_LEN + 1 + ((mnlen + clen + mtlen) << 3)); - - methodDef->jniConsFromMethOverloaded(buf + 1); - memcpy(buf, "JnJVM", 5); - + char* buf = GetMethodName( + allocator, methodDef, customizing ? customizeFor : NULL); result = Function::Create(getFunctionType(), GlobalValue::ExternalWeakLinkage, buf, Compiler->getLLVMModule()); @@ -195,6 +210,9 @@ void LLVMMethodInfo::setCustomizedVersion(Class* cl, llvm::Function* F) { assert(customizedVersions.size() == 0); + mvm::ThreadAllocator allocator; + char* buf = GetMethodName(allocator, methodDef, cl); + F->setName(buf); methodFunction = NULL; customizedVersions[cl] = F; } Modified: vmkit/trunk/lib/J3/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaClass.cpp?rev=140727&r1=140726&r2=140727&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JavaClass.cpp Wed Sep 28 16:25:02 2011 @@ -1059,7 +1059,7 @@ memcpy(buf, JNI_NAME_PRE, JNI_NAME_PRE_LEN); - for (sint32 i =0; i < clen; ++i) { + for (sint32 i = 0; i < clen; ++i) { cur = jniConsClName->elements[i]; if (cur == '/') { ptr[0] = '_'; @@ -1085,7 +1085,7 @@ ptr[0] = '_'; ++ptr; - for (sint32 i =0; i < mnlen; ++i) { + for (sint32 i = 0; i < mnlen; ++i) { cur = jniConsName->elements[i]; if (cur == '/') { ptr[0] = '_'; @@ -1130,7 +1130,7 @@ memcpy(buf, JNI_NAME_PRE, JNI_NAME_PRE_LEN); - for (sint32 i =0; i < clen; ++i) { + for (sint32 i = 0; i < clen; ++i) { cur = jniConsClName->elements[i]; if (cur == '/') { ptr[0] = '_'; @@ -1156,7 +1156,7 @@ ptr[0] = '_'; ++ptr; - for (sint32 i =0; i < mnlen; ++i) { + for (sint32 i = 0; i < mnlen; ++i) { cur = jniConsName->elements[i]; if (cur == '/') ptr[0] = '_'; else if (cur == '_') { @@ -1228,7 +1228,6 @@ ++ptr; } ptr[0] = 0; - } Modified: vmkit/trunk/lib/J3/VMCore/UTF8.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/UTF8.h?rev=140727&r1=140726&r2=140727&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/UTF8.h (original) +++ vmkit/trunk/lib/J3/VMCore/UTF8.h Wed Sep 28 16:25:02 2011 @@ -44,7 +44,7 @@ const char *buffer = contents; uint32 len = strlen(buffer); uint32 suffixLen = strlen(suffix); - char* newBuffer = new char[(len << 1) + suffixLen + 1]; + char* newBuffer = new char[(len << 3) + suffixLen + 1]; uint32 j = 0; for (uint32 i = 0; i < len; ++i) { if (buffer[i] == '/') { @@ -60,6 +60,10 @@ newBuffer[j++] = '3'; } else if (buffer[i] == '$') { newBuffer[j++] = '_'; + newBuffer[j++] = '0'; + newBuffer[j++] = '0'; + newBuffer[j++] = '0'; + newBuffer[j++] = '2'; newBuffer[j++] = '4'; } else { newBuffer[j++] = buffer[i]; Modified: vmkit/trunk/lib/Mvm/StaticGCPrinter/VmkitGCPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/StaticGCPrinter/VmkitGCPrinter.cpp?rev=140727&r1=140726&r2=140727&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/StaticGCPrinter/VmkitGCPrinter.cpp (original) +++ vmkit/trunk/lib/Mvm/StaticGCPrinter/VmkitGCPrinter.cpp Wed Sep 28 16:25:02 2011 @@ -117,6 +117,58 @@ AP.OutStreamer.EmitLabel(Sym); } +static bool methodNameMatches(StringRef compiledName, + Constant* name, + Constant* type) { + uint32_t size = compiledName.size(); + std::string str; + + for (uint32_t i = 0; i < name->getNumOperands(); ++i) { + int16_t cur = cast(name->getOperand(i))->getZExtValue(); + if (cur == '/') { + str += '_'; + } else if (cur == '_') { + str += "_1"; + } else if (cur == '<') { + str += "_0003C"; + } else if (cur == '>') { + str += "_0003E"; + } else { + str += (char)cur; + } + } + + for (uint32_t i = 0; i < type->getNumOperands(); ++i) { + int16_t cur = cast(type->getOperand(i))->getZExtValue(); + if (cur == '(') { + str += "__"; + } else if (cur == '/') { + str += '_'; + } else if (cur == '_') { + str += "_1"; + } else if (cur == '$') { + str += "_00024"; + } else if (cur == ';') { + str += "_2"; + } else if (cur == '[') { + str += "_3"; + } else if (cur == ')') { + break; + } else { + str += (char)cur; + } + } + + if (str.length() > size) return false; + if (str.compare(compiledName) == 0) return true; + + str += 'S'; + + if (str.compare(compiledName) == 0) return true; + + return false; +} + Constant* FindMetadata(const Function& F) { LLVMContext& context = F.getParent()->getContext(); for (Value::const_use_iterator I = F.use_begin(), E = F.use_end(); I != E; ++I) { @@ -145,6 +197,39 @@ } } } + + StringRef name = F.getName(); + if (name.startswith("JnJVM")) { + // Metadata for customized methods. + StringRef methods = name.substr(0, name.find("__")); + StringRef methodName = name.substr(methods.rfind('_') + 1); + methodName = methodName.substr(0, methodName.rfind("__")); + methods = methods.substr(6, methods.rfind('_') - 5); + methods = std::string(methods) + "VirtualMethods"; + Constant* VirtualMethods = cast(F.getParent()->getNamedValue(methods)); + assert(VirtualMethods); + Constant* MethodsArray = cast(VirtualMethods->getOperand(0)); + for (uint32_t index = 0; index < MethodsArray->getNumOperands(); index++) { + Constant* method = cast(MethodsArray->getOperand(index)); + + Constant* name = cast(method->getOperand(5)); + name = cast(name->getOperand(0)); + name = cast(name->getOperand(0)); + name = cast(name->getOperand(1)); + + Constant* type = cast(method->getOperand(6)); + type = cast(type->getOperand(0)); + type = cast(type->getOperand(0)); + type = cast(type->getOperand(1)); + + if (methodNameMatches(methodName, name, type)) { + Constant* GEPs[2] = { ConstantInt::get(Type::getInt32Ty(context), 0), + ConstantInt::get(Type::getInt32Ty(context), index) }; + return ConstantExpr::getGetElementPtr(VirtualMethods, GEPs, 2); + } + } + assert(0 && "Should have found a JavaMethod"); + } return NULL; } From nicolas.geoffray at lip6.fr Thu Sep 29 10:20:03 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 29 Sep 2011 17:20:03 -0000 Subject: [vmkit-commits] [vmkit] r140791 - in /vmkit/trunk/lib/J3/Compiler: JavaAOTCompiler.cpp JavaLLVMCompiler.cpp LLVMInfo.cpp Message-ID: <20110929172003.60E4C2A6C12C@llvm.org> Author: geoffray Date: Thu Sep 29 12:20:03 2011 New Revision: 140791 URL: http://llvm.org/viewvc/llvm-project?rev=140791&view=rev Log: Do not customize when not precompiling, and don't create a llvm Function if a method is abstract. Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp vmkit/trunk/lib/J3/Compiler/JavaLLVMCompiler.cpp vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=140791&r1=140790&r2=140791&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Thu Sep 29 12:20:03 2011 @@ -1053,6 +1053,7 @@ if (getMethodInfo(&method)->methodFunction == NULL) { MethodElts.push_back(Constant::getNullValue(JavaIntrinsics.ptrType)); } else { + assert(!isAbstract(method.access)); Function* func = getMethod(&method, NULL); MethodElts.push_back(ConstantExpr::getCast(Instruction::BitCast, func, JavaIntrinsics.ptrType)); @@ -1604,7 +1605,7 @@ } } else { // We're not precompiling, get the method. - return getMethod(meth, customizeFor); + return getMethod(meth, NULL); } } @@ -2189,7 +2190,9 @@ cl->setOwnerClass(JavaThread::get()); for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) { - M->getMethod(&cl->virtualMethods[i], NULL); + if (!isAbstract(cl->virtualMethods[i].access)) { + M->getMethod(&cl->virtualMethods[i], NULL); + } } for (uint32 i = 0; i < cl->nbStaticMethods; ++i) { @@ -2222,13 +2225,11 @@ } for (uint32 i = 0; i < cl->nbStaticMethods; ++i) { - if (!isAbstract(cl->staticMethods[i].access)) { - Function* F = M->getMethod(&cl->staticMethods[i], NULL); - M->setMethod(F, ptr, F->getName().data()); - cl->staticMethods[i].compiledPtr(); - // Set native so that we don't try to inline it. - cl->staticMethods[i].setNative(); - } + Function* F = M->getMethod(&cl->staticMethods[i], NULL); + M->setMethod(F, ptr, F->getName().data()); + cl->staticMethods[i].compiledPtr(); + // Set native so that we don't try to inline it. + cl->staticMethods[i].setNative(); } } } Modified: vmkit/trunk/lib/J3/Compiler/JavaLLVMCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaLLVMCompiler.cpp?rev=140791&r1=140790&r2=140791&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaLLVMCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaLLVMCompiler.cpp Thu Sep 29 12:20:03 2011 @@ -53,6 +53,7 @@ } Function* JavaLLVMCompiler::parseFunction(JavaMethod* meth, Class* customizeFor) { + assert(!isAbstract(meth->access)); LLVMMethodInfo* LMI = getMethodInfo(meth); Function* func = LMI->getMethod(customizeFor); Modified: vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp?rev=140791&r1=140790&r2=140791&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp Thu Sep 29 12:20:03 2011 @@ -167,6 +167,7 @@ } Function* LLVMMethodInfo::getMethod(Class* customizeFor) { + assert(!isAbstract(methodDef->access)); bool customizing = false; Function* result = NULL; if (customizeFor != NULL && isCustomizable) {