From nicolas.geoffray at lip6.fr Wed Aug 3 13:46:46 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Wed, 03 Aug 2011 20:46:46 -0000 Subject: [vmkit-commits] [vmkit] r136810 - in /vmkit/trunk/lib/J3/VMCore: JavaString.cpp JavaString.h LockedMap.h Message-ID: <20110803204646.B62222A6C12C@llvm.org> Author: geoffray Date: Wed Aug 3 15:46:46 2011 New Revision: 136810 URL: http://llvm.org/viewvc/llvm-project?rev=136810&view=rev Log: Please g++ 4.0 headers on mac. Modified: vmkit/trunk/lib/J3/VMCore/JavaString.cpp vmkit/trunk/lib/J3/VMCore/JavaString.h vmkit/trunk/lib/J3/VMCore/LockedMap.h Modified: vmkit/trunk/lib/J3/VMCore/JavaString.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaString.cpp?rev=136810&r1=136809&r2=136810&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaString.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JavaString.cpp Wed Aug 3 15:46:46 2011 @@ -19,7 +19,7 @@ JavaVirtualTable* JavaString::internStringVT = 0; -JavaString* JavaString::stringDup(const ArrayUInt16*& _array, Jnjvm* vm) { +JavaString* JavaString::stringDup(const ArrayUInt16 *const& _array, Jnjvm* vm) { JavaString* res = 0; const ArrayUInt16* array = _array; Modified: vmkit/trunk/lib/J3/VMCore/JavaString.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaString.h?rev=136810&r1=136809&r2=136810&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaString.h (original) +++ vmkit/trunk/lib/J3/VMCore/JavaString.h Wed Aug 3 15:46:46 2011 @@ -40,7 +40,7 @@ return self->value; } - static JavaString* stringDup(const ArrayUInt16*& array, Jnjvm* vm); + static JavaString* stringDup(const ArrayUInt16 *const & array, Jnjvm* vm); /// internalToJava - Creates a copy of the UTF8 at its given offset and size /// with all its '.' replaced by '/'. The JVM bytecode reference classes in Modified: vmkit/trunk/lib/J3/VMCore/LockedMap.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/LockedMap.h?rev=136810&r1=136809&r2=136810&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/LockedMap.h (original) +++ vmkit/trunk/lib/J3/VMCore/LockedMap.h Wed Aug 3 15:46:46 2011 @@ -39,19 +39,19 @@ class UserClassArray; struct ltarray16 { - bool operator()(const ArrayUInt16* s1, const ArrayUInt16* s2) const; + bool operator()(const ArrayUInt16 *const s1, const ArrayUInt16 *const s2) const; }; class StringMap : public mvm::PermanentObject { public: - typedef std::map::iterator iterator; - typedef JavaString* (*funcCreate)(const ArrayUInt16*& V, Jnjvm* vm); + typedef std::map::iterator iterator; + typedef JavaString* (*funcCreate)(const ArrayUInt16 *const& V, Jnjvm* vm); mvm::LockNormal lock; - std::map > > map; + std::map > > map; - inline JavaString* lookupOrCreate(const ArrayUInt16* array, Jnjvm* vm, funcCreate func) { + inline JavaString* lookupOrCreate(const ArrayUInt16 *const array, Jnjvm* vm, funcCreate func) { JavaString* res = 0; llvm_gcroot(res, 0); llvm_gcroot(array, 0); @@ -69,14 +69,14 @@ } } - inline void remove(const ArrayUInt16* array) { + inline void remove(const ArrayUInt16 *const array) { llvm_gcroot(array, 0); lock.lock(); map.erase(array); lock.unlock(); } - - inline JavaString* lookup(const ArrayUInt16* array) { + + inline JavaString* lookup(const ArrayUInt16 *const array) { llvm_gcroot(array, 0); lock.lock(); iterator End = map.end(); @@ -85,7 +85,7 @@ return I != End ? ((JavaString*)(I->second)) : 0; } - inline void hash(const ArrayUInt16* array, JavaString* str) { + inline void hash(const ArrayUInt16 *const array, JavaString* str) { llvm_gcroot(array, 0); llvm_gcroot(str, 0); lock.lock(); @@ -93,12 +93,12 @@ lock.unlock(); } - inline void removeUnlocked(const ArrayUInt16* array, JavaString* str) { + inline void removeUnlocked(const ArrayUInt16 *const array, JavaString* str) { llvm_gcroot(str, 0); llvm_gcroot(array, 0); iterator End = map.end(); iterator I = map.find(array); - + if (I != End && I->second == str) map.erase(I); } From nicolas.geoffray at lip6.fr Thu Aug 4 10:39:58 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 04 Aug 2011 17:39:58 -0000 Subject: [vmkit-commits] [vmkit] r136890 - /vmkit/trunk/mmtk/magic/LowerJavaRT.cpp Message-ID: <20110804173958.F366C2A6C12C@llvm.org> Author: geoffray Date: Thu Aug 4 12:39:58 2011 New Revision: 136890 URL: http://llvm.org/viewvc/llvm-project?rev=136890&view=rev Log: Remove addFinalizationCandidate uses in MMTk. Modified: vmkit/trunk/mmtk/magic/LowerJavaRT.cpp Modified: vmkit/trunk/mmtk/magic/LowerJavaRT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/magic/LowerJavaRT.cpp?rev=136890&r1=136889&r2=136890&view=diff ============================================================================== --- vmkit/trunk/mmtk/magic/LowerJavaRT.cpp (original) +++ vmkit/trunk/mmtk/magic/LowerJavaRT.cpp Thu Aug 4 12:39:58 2011 @@ -75,9 +75,14 @@ GV.eraseFromParent(); } } + + // Replace finalization calls with null. + Function* F = M.getFunction("addFinalizationCandidate"); + F->replaceAllUsesWith(Constant::getNullValue(F->getType())); + F->eraseFromParent(); // Replace gcmalloc with the allocator of MMTk objects in VMKit - Function* F = M.getFunction("gcmalloc"); + F = M.getFunction("gcmalloc"); Function* Ma = M.getFunction("AllocateMagicArray"); Function* NewFunction = From nicolas.geoffray at lip6.fr Thu Aug 4 12:15:21 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 04 Aug 2011 19:15:21 -0000 Subject: [vmkit-commits] [vmkit] r136906 - /vmkit/trunk/mmtk/magic/LowerJavaRT.cpp Message-ID: <20110804191521.76E472A6C12C@llvm.org> Author: geoffray Date: Thu Aug 4 14:15:21 2011 New Revision: 136906 URL: http://llvm.org/viewvc/llvm-project?rev=136906&view=rev Log: Rempove GC info to MMTk methods. Modified: vmkit/trunk/mmtk/magic/LowerJavaRT.cpp Modified: vmkit/trunk/mmtk/magic/LowerJavaRT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/magic/LowerJavaRT.cpp?rev=136906&r1=136905&r2=136906&view=diff ============================================================================== --- vmkit/trunk/mmtk/magic/LowerJavaRT.cpp (original) +++ vmkit/trunk/mmtk/magic/LowerJavaRT.cpp Thu Aug 4 14:15:21 2011 @@ -95,6 +95,12 @@ Ma->replaceAllUsesWith(NewFunction); Ma->eraseFromParent(); + // Finally, remove GC info from the methods. They must not have any + // gcroot. + for (Module::iterator I = M.begin(), E = M.end(); I != E; I++) { + I->clearGC(); + } + return Changed; } From nicolas.geoffray at lip6.fr Thu Aug 4 13:29:08 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 04 Aug 2011 20:29:08 -0000 Subject: [vmkit-commits] [vmkit] r136914 - in /vmkit/trunk: ./ include/mvm/ include/mvm/Threads/ lib/J3/Classpath/ lib/J3/Compiler/ lib/J3/Compiler/AOT/ lib/J3/VMCore/ lib/Mvm/CommonThread/ lib/Mvm/Compiler/ lib/Mvm/Runtime/ lib/Mvm/StaticGCPrinter/ tools/j3/ tools/precompiler/ tools/precompiler/trainer/ Message-ID: <20110804202909.042A22A6C12C@llvm.org> Author: geoffray Date: Thu Aug 4 15:29:08 2011 New Revision: 136914 URL: http://llvm.org/viewvc/llvm-project?rev=136914&view=rev Log: Unify GC information between AOT compiled code and JIT compiled. There is now only one type of frame. The function cache is set with FrameInfo objects, and not MethodInfo objects anymore. Removed MethodInfo and all its children classes. Removed: vmkit/trunk/lib/J3/Compiler/AOT/ Modified: vmkit/trunk/Makefile.rules vmkit/trunk/include/mvm/JIT.h vmkit/trunk/include/mvm/MethodInfo.h vmkit/trunk/include/mvm/MvmDenseSet.h vmkit/trunk/include/mvm/Threads/Thread.h vmkit/trunk/include/mvm/VirtualMachine.h vmkit/trunk/lib/J3/Classpath/ClasspathVMThrowable.inc vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp vmkit/trunk/lib/J3/Compiler/Makefile 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/JavaThread.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/Mvm/CommonThread/ctthread.cpp vmkit/trunk/lib/Mvm/Compiler/JIT.cpp vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp vmkit/trunk/lib/Mvm/StaticGCPrinter/VmkitGCPrinter.cpp vmkit/trunk/tools/j3/Main.cpp vmkit/trunk/tools/precompiler/Precompiler.cpp vmkit/trunk/tools/precompiler/trainer/Makefile Modified: vmkit/trunk/Makefile.rules URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/Makefile.rules?rev=136914&r1=136913&r2=136914&view=diff ============================================================================== --- vmkit/trunk/Makefile.rules (original) +++ vmkit/trunk/Makefile.rules Thu Aug 4 15:29:08 2011 @@ -136,7 +136,7 @@ ifdef BUILD_FRAMETABLE FrametablesExterns.inc: $(ProjLibsPaths) - $(Verb) nm $(ProjLibsPaths) | grep __frametable | sed 's/\([a-f0-9]*\) \([a-zA-Z]*\) _*\([a-zA-Z0-9_]*\)/extern "C" CamlFrames \3;/' > $@ + $(Verb) nm $(ProjLibsPaths) | grep __frametable | sed 's/\([a-f0-9]*\) \([a-zA-Z]*\) _*\([a-zA-Z0-9_]*\)/extern "C" CompiledFrames \3;/' > $@ FrametablesSymbols.inc: $(ProjLibsPaths) $(Verb) nm $(ProjLibsPaths) | grep __frametable | sed 's/\([a-f0-9]*\) \([a-zA-Z]*\) _*\([a-zA-Z0-9_]*\)/\&\3,/' > $@ Modified: vmkit/trunk/include/mvm/JIT.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/JIT.h?rev=136914&r1=136913&r2=136914&view=diff ============================================================================== --- vmkit/trunk/include/mvm/JIT.h (original) +++ vmkit/trunk/include/mvm/JIT.h Thu Aug 4 15:29:08 2011 @@ -195,6 +195,11 @@ llvm::Module* TheModule = 0, llvm::TargetMachine* TheTarget = 0); + static Frames* addToVM(VirtualMachine* VM, + llvm::GCFunctionInfo* GFI, + llvm::JIT* jit, + mvm::BumpPtrAllocator& allocator); + static int disassemble(unsigned int* addr); static void protectIR(); @@ -205,26 +210,6 @@ static const char* getHostTriple(); }; -class JITMethodInfo : public MethodInfo { - llvm::GCFunctionInfo* GCInfo; -public: - virtual void scan(uintptr_t closure, void* ip, void* addr); - JITMethodInfo(llvm::GCFunctionInfo* GFI) : GCInfo(GFI) {} - void addToVM(VirtualMachine* vm, llvm::JIT* jit); -}; - -class MvmJITMethodInfo : public JITMethodInfo { -public: - virtual void print(void* ip, void* addr); - MvmJITMethodInfo(llvm::GCFunctionInfo* GFI, - const llvm::Function* F, - void* owner) : - JITMethodInfo(GFI) { - MetaInfo = const_cast(F); - Owner = owner; - } -}; - } // end namespace mvm #endif // MVM_JIT_H Modified: vmkit/trunk/include/mvm/MethodInfo.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/MethodInfo.h?rev=136914&r1=136913&r2=136914&view=diff ============================================================================== --- vmkit/trunk/include/mvm/MethodInfo.h (original) +++ vmkit/trunk/include/mvm/MethodInfo.h Thu Aug 4 15:29:08 2011 @@ -15,59 +15,92 @@ namespace mvm { -class MethodInfo : public PermanentObject { +class FrameInfo { public: - virtual void print(void* ip, void* addr); - virtual void scan(uintptr_t closure, void* ip, void* addr) = 0; - virtual bool isHighLevelMethod() { - return false; - } + void* Metadata; + void* ReturnAddress; + uint16_t SourceIndex; + uint16_t FrameSize; + uint16_t NumLiveOffsets; + int16_t LiveOffsets[1]; +}; + +class MethodInfoHelper { +public: + static void print(void* ip, void* addr); + static void scan(uintptr_t closure, FrameInfo* FI, void* ip, void* addr); + static void* isStub(void* ip, void* addr) { bool isStub = ((unsigned char*)ip)[0] == 0xCE; if (isStub) ip = ((void**)addr)[2]; return ip; } - void* MetaInfo; - void* Owner; + static uint32_t FrameInfoSize(uint32_t NumOffsets) { + uint32_t FrameInfoSize = sizeof(FrameInfo) + (NumOffsets - 1) * sizeof(int16_t); + if (FrameInfoSize & 2) { + FrameInfoSize += sizeof(int16_t); + } + return FrameInfoSize; + } }; -class CamlFrame { -public: - void* ReturnAddress; - uint16_t FrameSize; - uint16_t NumLiveOffsets; - int16_t LiveOffsets[1]; -}; -class CamlFrames { +class Frames { public: - uint16_t NumDescriptors; - CamlFrame* frames() const; + uint32_t NumDescriptors; + FrameInfo* frames() const { + return reinterpret_cast( + reinterpret_cast(this) + sizeof(Frames)); + } + + void* operator new(size_t sz, mvm::BumpPtrAllocator& allocator, uint32_t NumDescriptors, uint32_t NumOffsets) { + Frames* res = reinterpret_cast( + allocator.Allocate(sizeof(Frames) + NumDescriptors * MethodInfoHelper::FrameInfoSize(NumOffsets), "Frames")); + assert((reinterpret_cast(res) & 2) == 0); + return res; + } }; -class CamlMethodInfo : public MethodInfo { +class CompiledFrames { public: - CamlFrame* CF; - virtual void scan(uintptr_t closure, void* ip, void* addr); - CamlMethodInfo(CamlFrame* C) : CF(C) { - Owner = NULL; - MetaInfo = NULL; + uint32_t NumCompiledFrames; + Frames* frames() const { + return reinterpret_cast( + reinterpret_cast(this) + sizeof(CompiledFrames)); } }; -class DefaultMethodInfo : public MethodInfo { +class FrameIterator { public: - virtual void scan(uintptr_t closure, void* ip, void* addr); - static DefaultMethodInfo DM; - - DefaultMethodInfo() { - Owner = NULL; - MetaInfo = NULL; + const Frames& frames; + uint32 currentFrameNumber; + FrameInfo* currentFrame; + + FrameIterator(const Frames& f) + : frames(f), currentFrameNumber(0) , currentFrame(f.frames()) { } -}; + bool hasNext() { + return currentFrameNumber < frames.NumDescriptors; + } + + void advance(int NumLiveOffsets) { + ++currentFrameNumber; + if (!hasNext()) return; + uintptr_t ptr = + reinterpret_cast(currentFrame) + MethodInfoHelper::FrameInfoSize(NumLiveOffsets); + currentFrame = reinterpret_cast(ptr); + } + + FrameInfo* next() { + assert(hasNext()); + FrameInfo* result = currentFrame; + advance(currentFrame->NumLiveOffsets); + return result; + } +}; } // end namespace mvm #endif // MVM_METHODINFO_H Modified: vmkit/trunk/include/mvm/MvmDenseSet.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/MvmDenseSet.h?rev=136914&r1=136913&r2=136914&view=diff ============================================================================== --- vmkit/trunk/include/mvm/MvmDenseSet.h (original) +++ vmkit/trunk/include/mvm/MvmDenseSet.h Thu Aug 4 15:29:08 2011 @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// // -// This file defines the MvmDenseMap copied from llvm/ADT/DenseMap.h, but +// This file defines the MvmDenseSet class copied from llvm/ADT/DenseMap.h, but // without storing pairs. // //===----------------------------------------------------------------------===// Modified: vmkit/trunk/include/mvm/Threads/Thread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Threads/Thread.h?rev=136914&r1=136913&r2=136914&view=diff ============================================================================== --- vmkit/trunk/include/mvm/Threads/Thread.h (original) +++ vmkit/trunk/include/mvm/Threads/Thread.h Thu Aug 4 15:29:08 2011 @@ -29,7 +29,7 @@ namespace mvm { -class MethodInfo; +class FrameInfo; class VirtualMachine; /// CircularBase - This class represents a circular list. Classes that extend @@ -334,7 +334,7 @@ jmp_buf buffer; }; -/// StackWalker - This class walks the stack of threads, returning a MethodInfo +/// StackWalker - This class walks the stack of threads, returning a FrameInfo /// object at each iteration. /// class StackWalker { @@ -347,7 +347,7 @@ StackWalker(mvm::Thread* th) __attribute__ ((noinline)); void operator++(); void* operator*(); - MethodInfo* get(); + FrameInfo* get(); }; Modified: vmkit/trunk/include/mvm/VirtualMachine.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/VirtualMachine.h?rev=136914&r1=136913&r2=136914&view=diff ============================================================================== --- vmkit/trunk/include/mvm/VirtualMachine.h (original) +++ vmkit/trunk/include/mvm/VirtualMachine.h Thu Aug 4 15:29:08 2011 @@ -22,8 +22,9 @@ namespace mvm { -class CamlFrames; -class MethodInfo; +class CompiledFrames; +class FrameInfo; +class Frames; class FunctionMap { public: @@ -31,27 +32,26 @@ /// 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. /// mvm::SpinLock FunctionMapLock; - /// IPToMethodInfo - Map a code start instruction instruction to the MethodInfo. + /// IPToFrameInfo - Map a code start instruction instruction to the FrameInfo. /// - MethodInfo* IPToMethodInfo(void* ip); + FrameInfo* IPToFrameInfo(void* ip); - /// addMethodInfo - A new instruction pointer in the function map. + /// addFrameInfo - A new instruction pointer in the function map. /// - void addMethodInfo(MethodInfo* meth, void* ip); - void addMethodInfoNoLock(MethodInfo* meth, void* ip) { + void addFrameInfo(void* ip, FrameInfo* meth); + void addFrameInfoNoLock(void* ip, FrameInfo* meth) { Functions[ip] = meth; } + /// removeFrameInfos - Remove all FrameInfo owned by the given owner. + void removeFrameInfos(void* owner) {} /* TODO */ - /// removeMethodInfos - Remove all MethodInfo owned by the given owner. - void removeMethodInfos(void* owner); - - FunctionMap(BumpPtrAllocator& allocator, CamlFrames** frames); + FunctionMap(BumpPtrAllocator& allocator, CompiledFrames** frames); }; /// VirtualMachine - This class is the root of virtual machine classes. It @@ -59,7 +59,7 @@ /// class VirtualMachine : public mvm::PermanentObject { protected: - VirtualMachine(mvm::BumpPtrAllocator &Alloc, mvm::CamlFrames** frames) : + VirtualMachine(BumpPtrAllocator &Alloc, CompiledFrames** frames) : allocator(Alloc), FunctionsCache(Alloc, frames) { mainThread = NULL; numberOfThreads = 0; @@ -208,12 +208,14 @@ //===----------------------------------------------------------------------===// FunctionMap FunctionsCache; - MethodInfo* IPToMethodInfo(void* ip) { - return FunctionsCache.IPToMethodInfo(ip); + FrameInfo* IPToFrameInfo(void* ip) { + return FunctionsCache.IPToFrameInfo(ip); } - void removeMethodInfos(void* owner) { - FunctionsCache.removeMethodInfos(owner); + void removeFrameInfos(void* owner) { + FunctionsCache.removeFrameInfos(owner); } + + virtual void printMethod(FrameInfo* FI, void* ip, void* addr) = 0; //===----------------------------------------------------------------------===// // (4) Launch-related methods. Modified: vmkit/trunk/lib/J3/Classpath/ClasspathVMThrowable.inc URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Classpath/ClasspathVMThrowable.inc?rev=136914&r1=136913&r2=136914&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Classpath/ClasspathVMThrowable.inc (original) +++ vmkit/trunk/lib/J3/Classpath/ClasspathVMThrowable.inc Thu Aug 4 15:29:08 2011 @@ -83,7 +83,7 @@ } -JavaObject* consStackElement(JavaMethod* meth, void* ip) { +JavaObject* consStackElement(mvm::FrameInfo* FI, void* ip) { JavaString* methodName = 0; JavaString* className = 0; @@ -95,6 +95,7 @@ llvm_gcroot(res, 0); Jnjvm* vm = JavaThread::get()->getJVM(); + JavaMethod* meth = (JavaMethod*)FI->Metadata; methodName = vm->internalUTF8ToStr(meth->name); Class* cl = meth->classDef; className = JavaString::internalToJava(cl->name, vm); @@ -109,7 +110,7 @@ } bool native = isNative(meth->access); - uint16 lineNumber = meth->lookupLineNumber(reinterpret_cast(ip)); + uint16 lineNumber = meth->lookupLineNumber(FI); UserClass* newS = vm->upcalls->newStackTraceElement; res = newS->doNew(vm); @@ -143,10 +144,10 @@ // on the stack. sint32 index = 2;; while (index != JavaArray::getSize(stack)) { - mvm::MethodInfo* MI = vm->IPToMethodInfo(ArrayPtr::getElement((ArrayPtr*)stack, index)); - if (!MI->isHighLevelMethod()) ++index; + mvm::FrameInfo* FI = vm->IPToFrameInfo(ArrayPtr::getElement((ArrayPtr*)stack, index)); + if (FI->Metadata == NULL) ++index; else { - JavaMethod* meth = (JavaMethod*)MI->MetaInfo; + JavaMethod* meth = (JavaMethod*)FI->Metadata; assert(meth && "Wrong stack trace"); if (meth->classDef->isAssignableFrom(vm->upcalls->newThrowable)) { ++index; @@ -157,9 +158,9 @@ sint32 size = 0; sint32 cur = index; while (cur < JavaArray::getSize(stack)) { - mvm::MethodInfo* MI = vm->IPToMethodInfo(ArrayPtr::getElement((ArrayPtr*)stack, cur)); + mvm::FrameInfo* FI = vm->IPToFrameInfo(ArrayPtr::getElement((ArrayPtr*)stack, cur)); ++cur; - if (MI->isHighLevelMethod()) ++size; + if (FI->Metadata != NULL) ++size; } result = (ArrayObject*) @@ -167,10 +168,9 @@ cur = 0; for (sint32 i = index; i < JavaArray::getSize(stack); ++i) { - mvm::MethodInfo* MI = vm->IPToMethodInfo(ArrayPtr::getElement((ArrayPtr*)stack, i)); - if (MI->isHighLevelMethod()) { - JavaMethod* meth = (JavaMethod*)MI->MetaInfo; - ArrayObject::setElement(result, consStackElement(meth, ArrayPtr::getElement((ArrayPtr*)stack, i)), cur); + mvm::FrameInfo* FI = vm->IPToFrameInfo(ArrayPtr::getElement((ArrayPtr*)stack, i)); + if (FI->Metadata != NULL) { + ArrayObject::setElement(result, consStackElement(FI, ArrayPtr::getElement((ArrayPtr*)stack, i)), cur); cur++; } } Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=136914&r1=136913&r2=136914&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Thu Aug 4 15:29:08 2011 @@ -2325,18 +2325,14 @@ for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) { JavaMethod& meth = cl->virtualMethods[i]; if (meth.code != NULL) { - Function* Func = parseFunction(&meth); - Func->clearGC(); - Func->setGC("java_aot"); + parseFunction(&meth); } } for (uint32 i = 0; i < cl->nbStaticMethods; ++i) { JavaMethod& meth = cl->staticMethods[i]; if (meth.code != NULL) { - Function* Func = parseFunction(&meth); - Func->clearGC(); - Func->setGC("java_aot"); + parseFunction(&meth); } } } @@ -2347,8 +2343,6 @@ toCompile.pop_back(); getNativeClass(meth->classDef); Function* Func = parseFunction(meth); - Func->clearGC(); - Func->setGC("java_aot"); // Also update code to notify that this function has been emitted. meth->code = Func; } Modified: vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp?rev=136914&r1=136913&r2=136914&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp Thu Aug 4 15:29:08 2011 @@ -40,42 +40,6 @@ using namespace j3; using namespace llvm; -class JavaJITMethodInfo : public mvm::JITMethodInfo { -public: - virtual void print(void* ip, void* addr); - virtual bool isHighLevelMethod() { - return true; - } - - JavaJITMethodInfo(llvm::GCFunctionInfo* GFI, - JavaMethod* m) : - mvm::JITMethodInfo(GFI) { - MetaInfo = m; - Owner = m->classDef->classLoader->getCompiler(); - } -}; - -void JavaJITMethodInfo::print(void* ip, void* addr) { - void* new_ip = NULL; - if (ip) new_ip = isStub(ip, addr); - JavaMethod* meth = (JavaMethod*)MetaInfo; - CodeLineInfo* info = meth->lookupCodeLineInfo((uintptr_t)ip); - if (info != NULL) { - fprintf(stderr, "; %p (%p) in %s.%s (line %d, bytecode %d, code start %p)", new_ip, addr, - UTF8Buffer(meth->classDef->name).cString(), - UTF8Buffer(meth->name).cString(), - meth->lookupLineNumber((uintptr_t)ip), - info->bytecodeIndex, meth->code); - } else { - fprintf(stderr, "; %p (%p) in %s.%s (native method, code start %p)", new_ip, addr, - UTF8Buffer(meth->classDef->name).cString(), - UTF8Buffer(meth->name).cString(), meth->code); - } - if (ip != new_ip) fprintf(stderr, " (from stub)"); - fprintf(stderr, "\n"); -} - - void JavaJITListener::NotifyFunctionEmitted(const Function &F, void *Code, size_t Size, const EmittedFunctionDetails &Details) { @@ -347,33 +311,9 @@ assert((GFI != NULL) && "No GC information"); Jnjvm* vm = JavaThread::get()->getJVM(); - mvm::JITMethodInfo* MI = - new(allocator, "JavaJITMethodInfo") JavaJITMethodInfo(GFI, meth); - MI->addToVM(vm, (JIT*)executionEngine); - - uint32_t infoLength = GFI->size(); - meth->codeInfoLength = infoLength; - if (infoLength == 0) { - meth->codeInfo = NULL; - } else { - mvm::BumpPtrAllocator& JavaAlloc = meth->classDef->classLoader->allocator; - CodeLineInfo* infoTable = - new(JavaAlloc, "CodeLineInfo") CodeLineInfo[infoLength]; - uint32_t index = 0; - for (GCFunctionInfo::iterator I = GFI->begin(), E = GFI->end(); - I != E; - I++, index++) { - DebugLoc DL = I->Loc; - uint32_t bytecodeIndex = DL.getLine(); - uint32_t second = DL.getCol(); - assert(second == 0 && "Wrong column number"); - uintptr_t address = - ((JIT*)executionEngine)->getCodeEmitter()->getLabelAddress(I->Label); - infoTable[index].address = address; - infoTable[index].bytecodeIndex = bytecodeIndex; - } - meth->codeInfo = infoTable; - } + mvm::Frames* frames = mvm::MvmModule::addToVM(vm, GFI, (JIT*)executionEngine, allocator); + meth->frames = frames; + meth->updateFrames(); } // Now that it's compiled, we don't need the IR anymore func->deleteBody(); @@ -389,9 +329,7 @@ assert((GFI != NULL) && "No GC information"); Jnjvm* vm = JavaThread::get()->getJVM(); - mvm::JITMethodInfo* MI = - new(allocator, "JITMethodInfo") mvm::MvmJITMethodInfo(GFI, F, this); - MI->addToVM(vm, (JIT*)executionEngine); + mvm::MvmModule::addToVM(vm, GFI, (JIT*)executionEngine, allocator); // Now that it's compiled, we don't need the IR anymore F->deleteBody(); Modified: vmkit/trunk/lib/J3/Compiler/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/Makefile?rev=136914&r1=136913&r2=136914&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/Makefile (original) +++ vmkit/trunk/lib/J3/Compiler/Makefile Thu Aug 4 15:29:08 2011 @@ -10,7 +10,6 @@ include $(LEVEL)/Makefile.config -DIRS = AOT MODULE_WITH_GC = J3Compiler include $(LEVEL)/Makefile.common Modified: vmkit/trunk/lib/J3/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaClass.cpp?rev=136914&r1=136913&r2=136914&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JavaClass.cpp Thu Aug 4 15:29:08 2011 @@ -634,7 +634,7 @@ access = A; canBeInlined = false; offset = 0; - codeInfo = NULL; + frames = NULL; } void JavaField::initialise(Class* cl, const UTF8* N, const UTF8* T, uint16 A) { @@ -1699,59 +1699,51 @@ } } -CodeLineInfo* JavaMethod::lookupCodeLineInfo(uintptr_t ip) { - for(uint16 i = 0; i < codeInfoLength; ++i) { - if (codeInfo[i].address == ip) { - return &(codeInfo[i]); - } - } - return NULL; -} - -uint16 JavaMethod::lookupLineNumber(uintptr_t ip) { - for(uint16 i = 0; i < codeInfoLength; ++i) { - if (codeInfo[i].address == ip) { - Attribut* codeAtt = lookupAttribut(Attribut::codeAttribut); - if (codeAtt == NULL) return 0; - Reader reader(codeAtt, classDef->bytes); - reader.readU2(); // max_stack - reader.readU2(); // max_locals; - uint32_t codeLength = reader.readU4(); - reader.seek(codeLength, Reader::SeekCur); - uint16_t exceptionTableLength = reader.readU2(); - reader.seek(8 * exceptionTableLength, Reader::SeekCur); - uint16_t nba = reader.readU2(); - for (uint16 att = 0; att < nba; ++att) { - const UTF8* attName = classDef->ctpInfo->UTF8At(reader.readU2()); - uint32 attLen = reader.readU4(); - if (attName->equals(Attribut::lineNumberTableAttribut)) { - uint16_t lineLength = reader.readU2(); - uint16_t currentLine = 0; - for (uint16 j = 0; j < lineLength; ++j) { - uint16 pc = reader.readU2(); - if (pc > codeInfo[i].bytecodeIndex + 1) return currentLine; - currentLine = reader.readU2(); - } - return currentLine; - } else { - reader.seek(attLen, Reader::SeekCur); - } +uint16 JavaMethod::lookupLineNumber(mvm::FrameInfo* info) { + Attribut* codeAtt = lookupAttribut(Attribut::codeAttribut); + if (codeAtt == NULL) return 0; + Reader reader(codeAtt, classDef->bytes); + reader.readU2(); // max_stack + reader.readU2(); // max_locals; + uint32_t codeLength = reader.readU4(); + reader.seek(codeLength, Reader::SeekCur); + uint16_t exceptionTableLength = reader.readU2(); + reader.seek(8 * exceptionTableLength, Reader::SeekCur); + uint16_t nba = reader.readU2(); + for (uint16 att = 0; att < nba; ++att) { + const UTF8* attName = classDef->ctpInfo->UTF8At(reader.readU2()); + uint32 attLen = reader.readU4(); + if (attName->equals(Attribut::lineNumberTableAttribut)) { + uint16_t lineLength = reader.readU2(); + uint16_t currentLine = 0; + for (uint16 j = 0; j < lineLength; ++j) { + uint16 pc = reader.readU2(); + if (pc > info->SourceIndex + 1) return currentLine; + currentLine = reader.readU2(); } + return currentLine; + } else { + reader.seek(attLen, Reader::SeekCur); } } return 0; } -uint16 JavaMethod::lookupCtpIndex(uintptr_t ip) { - for(uint16 i = 0; i < codeInfoLength; ++i) { - if (codeInfo[i].address == ip) { - Attribut* codeAtt = lookupAttribut(Attribut::codeAttribut); - Reader reader(codeAtt, classDef->bytes); - reader.cursor = reader.cursor + 2 + 2 + 4 + codeInfo[i].bytecodeIndex + 1; - return reader.readU2(); - } +uint16 JavaMethod::lookupCtpIndex(mvm::FrameInfo* FI) { + Attribut* codeAtt = lookupAttribut(Attribut::codeAttribut); + Reader reader(codeAtt, classDef->bytes); + reader.cursor = reader.cursor + 2 + 2 + 4 + FI->SourceIndex + 1; + return reader.readU2(); +} + + +void JavaMethod::updateFrames() { + mvm::FrameIterator iterator(*frames); + + while (iterator.hasNext()) { + mvm::FrameInfo* frame = iterator.next(); + frame->Metadata = this; } - return 0; } void Class::acquire() { Modified: vmkit/trunk/lib/J3/VMCore/JavaClass.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaClass.h?rev=136914&r1=136913&r2=136914&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaClass.h (original) +++ vmkit/trunk/lib/J3/VMCore/JavaClass.h Thu Aug 4 15:29:08 2011 @@ -821,16 +821,6 @@ }; -class CodeLineInfo : public mvm::PermanentObject { -public: - uintptr_t address; - uint16 bytecodeIndex; - // TODO: Use these fields when inlining. - JavaMethod* executingMethod; - // The code where the inlined method starts. - CodeLineInfo* inlineLocation; -}; - /// JavaMethod - This class represents Java methods. /// class JavaMethod : public mvm::PermanentObject { @@ -899,11 +889,13 @@ /// void* code; - /// codeInfo - Array of CodeLineInfo objects. + /// frames - Frames for this method. + /// TODO: Deprecate? /// - CodeLineInfo* codeInfo; + mvm::Frames* frames; /// codeInfoLength - Number of entries in the codeInfo field. + /// TODO: Deprecate. /// uint16 codeInfoLength; @@ -911,26 +903,24 @@ /// uint32 offset; + /// updateFrames - Set the meta information on frames. + /// + void updateFrames(); + /// lookupAttribut - Look up an attribut in the method's attributs. Returns /// null if the attribut is not found. /// Attribut* lookupAttribut(const UTF8* key); - /// lookupLineNumber - Find the line number based on the given instruction - /// pointer. + /// lookupLineNumber - Find the line number based on the given frame info. /// - uint16 lookupLineNumber(uintptr_t ip); + uint16 lookupLineNumber(mvm::FrameInfo* FI); /// lookupCtpIndex - Lookup the constant pool index pointed by the opcode - /// related to the given instruction pointer. + /// related to the given frame info. /// - uint16 lookupCtpIndex(uintptr_t ip); + uint16 lookupCtpIndex(mvm::FrameInfo* FI); - /// lookupCodeLineInfo - Lookup the code line info related to the given - /// instruction pointer. - /// - CodeLineInfo* lookupCodeLineInfo(uintptr_t ip); - /// getSignature - Get the signature of thes method, resolving it if /// necessary. /// Modified: vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp?rev=136914&r1=136913&r2=136914&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp Thu Aug 4 15:29:08 2011 @@ -560,13 +560,12 @@ // Lookup the caller of this class. mvm::StackWalker Walker(th); ++Walker; // Remove the stub. - mvm::MethodInfo* MI = Walker.get(); - assert(MI->isHighLevelMethod() && "Wrong stack trace"); - JavaMethod* meth = (JavaMethod*)MI->MetaInfo; - void* ip = *Walker; + 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(reinterpret_cast(ip)); + uint16 ctpIndex = meth->lookupCtpIndex(FI); assert(ctpIndex && "No constant pool index"); JavaConstantPool* ctpInfo = meth->classDef->getConstantPool(); CommonClass* ctpCl = 0; @@ -621,13 +620,12 @@ // Lookup the caller of this class. mvm::StackWalker Walker(th); ++Walker; // Remove the stub. - mvm::MethodInfo* MI = Walker.get(); - assert(MI->isHighLevelMethod() && "Wrong stack trace"); - JavaMethod* caller = (JavaMethod*)MI->MetaInfo; - void* ip = *Walker; + mvm::FrameInfo* FI = Walker.get(); + assert(FI->Metadata != NULL && "Wrong stack trace"); + JavaMethod* caller = (JavaMethod*)FI->Metadata; // Lookup the method info in the constant pool of the caller. - uint16 ctpIndex = caller->lookupCtpIndex(reinterpret_cast(ip)); + uint16 ctpIndex = caller->lookupCtpIndex(FI); assert(ctpIndex && "No constant pool index"); JavaConstantPool* ctpInfo = caller->classDef->getConstantPool(); CommonClass* cl = 0; @@ -659,13 +657,12 @@ // Lookup the caller of this class. mvm::StackWalker Walker(th); ++Walker; // Remove the stub. - mvm::MethodInfo* MI = Walker.get(); - assert(MI->isHighLevelMethod() && "Wrong stack trace"); - JavaMethod* caller = (JavaMethod*)MI->MetaInfo; - void* ip = *Walker; + mvm::FrameInfo* FI = Walker.get(); + assert(FI->Metadata != NULL && "Wrong stack trace"); + JavaMethod* caller = (JavaMethod*)FI->Metadata; // Lookup the method info in the constant pool of the caller. - uint16 ctpIndex = caller->lookupCtpIndex(reinterpret_cast(ip)); + uint16 ctpIndex = caller->lookupCtpIndex(FI); assert(ctpIndex && "No constant pool index"); JavaConstantPool* ctpInfo = caller->classDef->getConstantPool(); CommonClass* cl = 0; Modified: vmkit/trunk/lib/J3/VMCore/JavaThread.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaThread.cpp?rev=136914&r1=136913&r2=136914&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaThread.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JavaThread.cpp Thu Aug 4 15:29:08 2011 @@ -70,9 +70,9 @@ mvm::StackWalker Walker(this); uint32 i = 0; - while (mvm::MethodInfo* MI = Walker.get()) { - if (MI->isHighLevelMethod()) { - JavaMethod* M = (JavaMethod*)MI->MetaInfo; + while (mvm::FrameInfo* FI = Walker.get()) { + if (FI->Metadata != NULL) { + JavaMethod* M = (JavaMethod*)FI->Metadata; buffer[i++] = M; } ++Walker; @@ -84,10 +84,10 @@ mvm::StackWalker Walker(this); uint32 index = 0; - while (mvm::MethodInfo* MI = Walker.get()) { - if (MI->isHighLevelMethod()) { + while (mvm::FrameInfo* FI = Walker.get()) { + if (FI->Metadata != NULL) { if (index == level) { - return (JavaMethod*)MI->MetaInfo; + return (JavaMethod*)FI->Metadata; } ++index; } @@ -109,9 +109,9 @@ mvm::StackWalker Walker(this); - while (mvm::MethodInfo* MI = Walker.get()) { - if (MI->isHighLevelMethod() == 1) { - JavaMethod* meth = (JavaMethod*)MI->MetaInfo; + while (mvm::FrameInfo* FI = Walker.get()) { + if (FI->Metadata != NULL) { + JavaMethod* meth = (JavaMethod*)FI->Metadata; JnjvmClassLoader* loader = meth->classDef->classLoader; obj = loader->getJavaClassLoader(); if (obj) return obj; @@ -125,9 +125,10 @@ void JavaThread::printJavaBacktrace() { mvm::StackWalker Walker(this); - while (mvm::MethodInfo* MI = Walker.get()) { - if (MI->isHighLevelMethod()) - MI->print(Walker.ip, Walker.addr); + while (mvm::FrameInfo* FI = Walker.get()) { + if (FI->Metadata != NULL) { + MyVM->printMethod(FI, Walker.ip, Walker.addr); + } ++Walker; } } Modified: vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp?rev=136914&r1=136913&r2=136914&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp Thu Aug 4 15:29:08 2011 @@ -1312,7 +1312,7 @@ } Jnjvm::Jnjvm(mvm::BumpPtrAllocator& Alloc, - mvm::CamlFrames** frames, + mvm::CompiledFrames** frames, JnjvmBootstrapLoader* loader) : VirtualMachine(Alloc, frames), lockSystem(Alloc) { @@ -1444,3 +1444,22 @@ return 0; } + +void Jnjvm::printMethod(mvm::FrameInfo* FI, void* ip, void* addr) { + void* new_ip = NULL; + if (ip) new_ip = mvm::MethodInfoHelper::isStub(ip, 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)", new_ip, addr, + UTF8Buffer(meth->classDef->name).cString(), + UTF8Buffer(meth->name).cString(), + meth->lookupLineNumber(FI), + FI->SourceIndex, meth->code); + + if (ip != new_ip) fprintf(stderr, " (from stub)"); + fprintf(stderr, "\n"); +} Modified: vmkit/trunk/lib/J3/VMCore/Jnjvm.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Jnjvm.h?rev=136914&r1=136913&r2=136914&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/Jnjvm.h (original) +++ vmkit/trunk/lib/J3/VMCore/Jnjvm.h Thu Aug 4 15:29:08 2011 @@ -131,6 +131,8 @@ 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); + /// CreateError - Creates a Java object of the specified exception class /// and calling its function. @@ -337,7 +339,7 @@ /// Jnjvm - Allocates a new JVM. /// Jnjvm(mvm::BumpPtrAllocator& Alloc, - mvm::CamlFrames** frames, + mvm::CompiledFrames** frames, JnjvmBootstrapLoader* loader); /// runApplication - Runs the application with the given command line. Modified: vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp?rev=136914&r1=136913&r2=136914&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp Thu Aug 4 15:29:08 2011 @@ -843,7 +843,7 @@ JnjvmClassLoader::~JnjvmClassLoader() { if (isolate) { - isolate->removeMethodInfos(TheCompiler); + isolate->removeFrameInfos(TheCompiler); } if (classes) { Modified: vmkit/trunk/lib/J3/VMCore/Precompiled.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Precompiled.cpp?rev=136914&r1=136913&r2=136914&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/Precompiled.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/Precompiled.cpp Thu Aug 4 15:29:08 2011 @@ -121,137 +121,6 @@ } -class StaticJ3Frame { -public: - void* ReturnAddress; - uint16_t BytecodeIndex; - uint16_t FrameSize; - uint16_t NumLiveOffsets; - int16_t LiveOffsets[1]; -}; - -class StaticJ3Frames { -public: - void* FunctionAddress; - uint16_t NumDescriptors; - StaticJ3Frame* frames() const; -}; - -class StaticJ3FrameDecoder { -public: - StaticJ3Frames* frames ; - uint32 currentDescriptor; - StaticJ3Frame* currentFrame; - - StaticJ3FrameDecoder(StaticJ3Frames* frames) { - this->frames = frames; - currentDescriptor = 0; - currentFrame = frames->frames(); - } - - bool hasNext() { - return currentDescriptor < frames->NumDescriptors; - } - - void advance() { - ++currentDescriptor; - if (!hasNext()) return; - uintptr_t ptr = reinterpret_cast(currentFrame) - + currentFrame->NumLiveOffsets * sizeof(uint16_t) - + sizeof(void*) // ReturnAddress - + sizeof(uint16_t) // BytecodeIndex - + sizeof(uint16_t) // FrameSize - + sizeof(uint16_t); // NumLiveOffsets - if (ptr & 2) { - ptr += sizeof(uint16_t); - } - currentFrame = reinterpret_cast(ptr); - } - - StaticJ3Frame* next() { - assert(hasNext()); - StaticJ3Frame* result = currentFrame; - advance(); - return result; - } -}; - -StaticJ3Frame* StaticJ3Frames::frames() const { - intptr_t ptr = reinterpret_cast(this) + sizeof(void*) + sizeof(uint16_t); - // If the frames structure was not 4-aligned, manually do it here. - if (ptr & 2) { - ptr += sizeof(uint16_t); - } - return reinterpret_cast(ptr); -} - -class JavaStaticMethodInfo : public mvm::MethodInfo { -private: - StaticJ3Frame* frame; -public: - virtual void print(void* ip, void* addr); - virtual bool isHighLevelMethod() { - return true; - } - - virtual void scan(uintptr_t closure, void* ip, void* addr) { - assert(frame != NULL); - //uintptr_t spaddr = (uintptr_t)addr + CF->FrameSize + sizeof(void*); - uintptr_t spaddr = ((uintptr_t*)addr)[0]; - for (uint16 i = 0; i < frame->NumLiveOffsets; ++i) { - mvm::Collector::scanObject((void**)(spaddr + frame->LiveOffsets[i]), closure); - } - } - - JavaStaticMethodInfo(StaticJ3Frame* F, JavaMethod* M) { - frame = F; - MetaInfo = M; - Owner = M->classDef->classLoader->getCompiler(); - } -}; - - -void JavaStaticMethodInfo::print(void* ip, void* addr) { - JavaMethod* meth = (JavaMethod*)MetaInfo; - CodeLineInfo* info = meth->lookupCodeLineInfo((uintptr_t)ip); - if (info != NULL) { - fprintf(stderr, "; %p (%p) in %s.%s (AOT line %d, bytecode %d, code start %p)", ip, addr, - UTF8Buffer(meth->classDef->name).cString(), - UTF8Buffer(meth->name).cString(), - meth->lookupLineNumber((uintptr_t)ip), - info->bytecodeIndex, meth->code); - } else { - fprintf(stderr, "; %p (%p) in %s.%s (native method, code start %p)", ip, addr, - UTF8Buffer(meth->classDef->name).cString(), - UTF8Buffer(meth->name).cString(), meth->code); - } - fprintf(stderr, "\n"); -} - - -static void ReadFrame(Jnjvm* vm, JnjvmClassLoader* loader, JavaMethod* meth) { - StaticJ3Frames* frames = reinterpret_cast(meth->codeInfo); - StaticJ3FrameDecoder decoder(frames); - mvm::BumpPtrAllocator& allocator = loader->allocator; - meth->codeInfoLength = frames->NumDescriptors; - if (frames->NumDescriptors > 0) { - meth->codeInfo = new(allocator, "CodeLineInfo") CodeLineInfo[frames->NumDescriptors]; - } else { - meth->codeInfo = NULL; - } - - int codeInfoIndex = 0; - while (decoder.hasNext()) { - StaticJ3Frame* frame = decoder.next(); - mvm::MethodInfo* MI = new(allocator, "JavaStaticMethodInfo") JavaStaticMethodInfo(frame, meth); - assert(loader->bootstrapLoader == loader && "Can only add frame without lock for the bootstrap loader"); - vm->FunctionsCache.addMethodInfoNoLock(MI, frame->ReturnAddress); - meth->codeInfo[codeInfoIndex].address = reinterpret_cast(frame->ReturnAddress); - meth->codeInfo[codeInfoIndex++].bytecodeIndex = frame->BytecodeIndex; - } -} - - void Precompiled::ReadFrames(Jnjvm* vm, JnjvmClassLoader* loader) { for (ClassMap::iterator i = loader->getClasses()->map.begin(), e = loader->getClasses()->map.end(); i != e; ++i) { @@ -261,14 +130,14 @@ for (uint32 i = 0; i < C->nbVirtualMethods; ++i) { JavaMethod& meth = C->virtualMethods[i]; if (meth.code != NULL) { - ReadFrame(vm, loader, &meth); + meth.updateFrames(); } } for (uint32 i = 0; i < C->nbStaticMethods; ++i) { JavaMethod& meth = C->staticMethods[i]; if (meth.code != NULL) { - ReadFrame(vm, loader, &meth); + meth.updateFrames(); } } } Modified: vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp?rev=136914&r1=136913&r2=136914&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp (original) +++ vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp Thu Aug 4 15:29:08 2011 @@ -104,8 +104,8 @@ void Thread::printBacktrace() { StackWalker Walker(this); - while (MethodInfo* MI = Walker.get()) { - MI->print(Walker.ip, Walker.addr); + while (FrameInfo* FI = Walker.get()) { + MyVM->printMethod(FI, Walker.ip, Walker.addr); ++Walker; } } @@ -131,12 +131,12 @@ return i; } -MethodInfo* StackWalker::get() { +FrameInfo* StackWalker::get() { if (addr == thread->baseSP) return 0; ip = FRAME_IP(addr); bool isStub = ((unsigned char*)ip)[0] == 0xCE; if (isStub) ip = addr[2]; - return thread->MyVM->IPToMethodInfo(ip); + return thread->MyVM->IPToFrameInfo(ip); } void* StackWalker::operator*() { @@ -186,8 +186,8 @@ void Thread::scanStack(uintptr_t closure) { StackWalker Walker(this); - while (MethodInfo* MI = Walker.get()) { - MI->scan(closure, Walker.ip, Walker.addr); + while (FrameInfo* MI = Walker.get()) { + MethodInfoHelper::scan(closure, MI, Walker.ip, Walker.addr); ++Walker; } } Modified: vmkit/trunk/lib/Mvm/Compiler/JIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Compiler/JIT.cpp?rev=136914&r1=136913&r2=136914&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Compiler/JIT.cpp (original) +++ vmkit/trunk/lib/Mvm/Compiler/JIT.cpp Thu Aug 4 15:29:08 2011 @@ -66,11 +66,6 @@ return LLVM_HOSTTRIPLE; } -void MvmJITMethodInfo::print(void* ip, void* addr) { - fprintf(stderr, "; %p (%p) in %s LLVM method\n", ip, addr, - ((llvm::Function*)MetaInfo)->getName().data()); -} - class MvmJITListener : public llvm::JITEventListener { public: virtual void NotifyFunctionEmitted(const Function &F, @@ -86,22 +81,53 @@ assert(&(*I)->getFunction() == &F && "GC Info and method do not correspond"); llvm::GCFunctionInfo* GFI = *I; - JITMethodInfo* MI = new(*MvmModule::Allocator, "MvmJITMethodInfo") - MvmJITMethodInfo(GFI, &F, MvmModule::executionEngine); - MI->addToVM(mvm::Thread::get()->MyVM, (JIT*)MvmModule::executionEngine); + MvmModule::addToVM(mvm::Thread::get()->MyVM, GFI, (JIT*)MvmModule::executionEngine, *MvmModule::Allocator); } }; -void JITMethodInfo::addToVM(VirtualMachine* VM, JIT* jit) { +Frames* MvmModule::addToVM(VirtualMachine* VM, GCFunctionInfo* FI, JIT* jit, BumpPtrAllocator& allocator) { JITCodeEmitter* JCE = jit->getCodeEmitter(); - assert(GCInfo != NULL); - for (GCFunctionInfo::iterator I = GCInfo->begin(), E = GCInfo->end(); - I != E; - I++) { - uintptr_t address = JCE->getLabelAddress(I->Label); - assert(address != 0); - VM->FunctionsCache.addMethodInfo(this, (void*)address); + int NumDescriptors = 0; + for (GCFunctionInfo::iterator J = FI->begin(), JE = FI->end(); J != JE; ++J) { + NumDescriptors++; + } + // Currently, all frames have the same number of stack offsets. + size_t LiveCount = FI->live_size(FI->begin()); + + Frames* frames = new (allocator, NumDescriptors, LiveCount) Frames(); + frames->NumDescriptors = NumDescriptors; + FrameIterator iterator(*frames); + + GCFunctionInfo::iterator I = FI->begin(); + while (iterator.hasNext()) { + // Manually do the iteration, because NumLiveOffsets has not been set + // on the frames yet. + FrameInfo* frame = iterator.currentFrame; + iterator.advance(LiveCount); + + frame->NumLiveOffsets = LiveCount; + frame->FrameSize = FI->getFrameSize(); + frame->Metadata = NULL; + frame->SourceIndex = I->Loc.getLine(); + frame->ReturnAddress = reinterpret_cast(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) { + frame->LiveOffsets[i++] = KI->StackOffset; + } + VM->FunctionsCache.addFrameInfo(frame->ReturnAddress, frame); + I++; + } + { + FrameIterator iterator(*frames); + while (iterator.hasNext()) { + FrameInfo* frame = iterator.next(); + FrameInfo* other = VM->IPToFrameInfo(frame->ReturnAddress); + assert(frame->ReturnAddress == other->ReturnAddress); + } } + + return frames; } static MvmJITListener JITListener; @@ -426,21 +452,3 @@ void MvmModule::unprotectIR() { protectEngine.unlock(); } - -void JITMethodInfo::scan(uintptr_t closure, void* ip, void* addr) { - if (GCInfo) { - DEBUG(llvm::errs() << GCInfo->getFunction().getName() << '\n'); - // All safe points have the same informations currently in LLVM. - llvm::GCFunctionInfo::iterator J = GCInfo->begin(); - //uintptr_t spaddr = (uintptr_t)addr + GFI->getFrameSize() + sizeof(void*); - uintptr_t spaddr = ((uintptr_t*)addr)[0]; - for (llvm::GCFunctionInfo::live_iterator K = GCInfo->live_begin(J), - KE = GCInfo->live_end(J); K != KE; ++K) { - intptr_t obj = *(intptr_t*)(spaddr + K->StackOffset); - // Verify that obj does not come from a JSR bytecode. - if (!(obj & 1)) { - Collector::scanObject((void**)(spaddr + K->StackOffset), closure); - } - } - } -} Modified: vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp?rev=136914&r1=136913&r2=136914&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp (original) +++ vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp Thu Aug 4 15:29:08 2011 @@ -20,125 +20,75 @@ using namespace mvm; -void CamlMethodInfo::scan(uintptr_t closure, void* ip, void* addr) { - assert(CF != NULL); - //uintptr_t spaddr = (uintptr_t)addr + CF->FrameSize + sizeof(void*); +void MethodInfoHelper::scan(uintptr_t closure, FrameInfo* FI, void* ip, void* addr) { + //uintptr_t spaddr = (uintptr_t)addr + FI->FrameSize + sizeof(void*); uintptr_t spaddr = ((uintptr_t*)addr)[0]; - for (uint16 i = 0; i < CF->NumLiveOffsets; ++i) { - Collector::scanObject((void**)(spaddr + CF->LiveOffsets[i]), closure); + 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. + if (!(obj & 1)) { + Collector::scanObject((void**)(spaddr + FI->LiveOffsets[i]), closure); + } } } -void MethodInfo::print(void* ip, void* addr) { +void MethodInfoHelper::print(void* ip, void* addr) { Dl_info info; int res = dladdr(ip, &info); if (res != 0 && info.dli_sname != NULL) { fprintf(stderr, "; %p (%p) in %s\n", ip, addr, info.dli_sname); } else { - fprintf(stderr, "; %p in Unknown method\n", ip); - } -} - -DefaultMethodInfo DefaultMethodInfo::DM; - -void DefaultMethodInfo::scan(uintptr_t closure, void* ip, void* addr) { -} - -struct CamlFrameDecoder { - CamlFrames* frames ; - uint32 currentDescriptor; - CamlFrame* currentFrame; - - CamlFrameDecoder(CamlFrames* frames) { - this->frames = frames; - currentDescriptor = 0; - currentFrame = frames->frames(); - } - - bool hasNext() { - return currentDescriptor < frames->NumDescriptors; - } - - void advance() { - ++currentDescriptor; - if (!hasNext()) return; - currentFrame = (CamlFrame*) ((char*)currentFrame + - (currentFrame->NumLiveOffsets % 2) * sizeof(uint16_t) + - currentFrame->NumLiveOffsets * sizeof(uint16_t) + - sizeof(void*) + sizeof(uint16_t) + sizeof(uint16_t)); - } - - CamlFrame* next() { - assert(hasNext()); - CamlFrame* result = currentFrame; - advance(); - return result; + fprintf(stderr, "; %p in Unknown method\n", ip); } -}; - -CamlFrame* CamlFrames::frames() const { - intptr_t ptr = reinterpret_cast(this) + sizeof(uint32_t); - // If the frames structure was not 4-aligned, manually do it here. - if (ptr & 2) { - ptr -= sizeof(uint16_t); - } - return reinterpret_cast(ptr); } -static BumpPtrAllocator* StaticAllocator = NULL; -FunctionMap::FunctionMap(BumpPtrAllocator& allocator, CamlFrames** allFrames) { +FunctionMap::FunctionMap(BumpPtrAllocator& allocator, CompiledFrames** allFrames) { if (allFrames == NULL) return; Functions.resize(40000); // Make sure the cache is big enough. int i = 0; - CamlFrames* frames = NULL; - while ((frames = allFrames[i++]) != NULL) { - CamlFrameDecoder decoder(frames); - while (decoder.hasNext()) { - CamlFrame* frame = decoder.next(); - CamlMethodInfo* MI = - new(allocator, "CamlMethodInfo") CamlMethodInfo(frame); - addMethodInfoNoLock(MI, frame->ReturnAddress); + CompiledFrames* compiledFrames = NULL; + while ((compiledFrames = allFrames[i++]) != NULL) { + Frames* currentFrames = compiledFrames->frames(); + for (uint32_t j = 0; j < compiledFrames->NumCompiledFrames; j++) { + FrameIterator iterator(*currentFrames); + FrameInfo* frame = NULL; + while (iterator.hasNext()) { + frame = iterator.next(); + addFrameInfoNoLock(frame->ReturnAddress, frame); + } + if (frame != NULL) { + currentFrames = reinterpret_cast( + reinterpret_cast(frame) + MethodInfoHelper::FrameInfoSize(frame->NumLiveOffsets)); + } else { + currentFrames = reinterpret_cast( + reinterpret_cast(currentFrames) + sizeof(Frames)); + } } } } -MethodInfo* FunctionMap::IPToMethodInfo(void* ip) { +// Create a dummy FrameInfo, so that methods don't have to null check. +static FrameInfo emptyInfo; + +FrameInfo* FunctionMap::IPToFrameInfo(void* ip) { FunctionMapLock.acquire(); - llvm::DenseMap::iterator I = Functions.find(ip); - MethodInfo* res = NULL; + llvm::DenseMap::iterator I = Functions.find(ip); + FrameInfo* res = NULL; if (I != Functions.end()) { res = I->second; } else { - res = &DefaultMethodInfo::DM; + assert(emptyInfo.Metadata == NULL); + assert(emptyInfo.NumLiveOffsets == 0); + res = &emptyInfo; } FunctionMapLock.release(); return res; } -void FunctionMap::addMethodInfo(MethodInfo* meth, void* ip) { +void FunctionMap::addFrameInfo(void* ip, FrameInfo* meth) { FunctionMapLock.acquire(); - addMethodInfoNoLock(meth, ip); - FunctionMapLock.release(); -} - - -void FunctionMap::removeMethodInfos(void* owner) { - FunctionMapLock.acquire(); - llvm::DenseSet toRemove; - for (llvm::DenseMap::iterator i = Functions.begin(), - e = Functions.end(); i != e;) { - mvm::MethodInfo* MI = i->second; - if (MI->Owner == owner) { - toRemove.insert(i->first); - } - } - - for (llvm::DenseSet::iterator i = toRemove.begin(), - e = toRemove.end(); i != e;) { - Functions.erase(*i); - } - + addFrameInfoNoLock(ip, meth); FunctionMapLock.release(); } Modified: vmkit/trunk/lib/Mvm/StaticGCPrinter/VmkitGCPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/StaticGCPrinter/VmkitGCPrinter.cpp?rev=136914&r1=136913&r2=136914&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/StaticGCPrinter/VmkitGCPrinter.cpp (original) +++ vmkit/trunk/lib/Mvm/StaticGCPrinter/VmkitGCPrinter.cpp Thu Aug 4 15:29:08 2011 @@ -1,20 +1,16 @@ -//===-- VmkitGCPrinter.cpp - Vmkit frametable emitter ---------------------===// +//===----- VmkitAOTGC.cpp - Support for Ahead of Time Compiler GC -------===// // -// The LLVM Compiler Infrastructure +// The Vmkit project // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -// -// This file implements printing the assembly code for a Vmkit frametable. -// -//===----------------------------------------------------------------------===// #include "llvm/CodeGen/GCs.h" +#include "llvm/CodeGen/GCStrategy.h" #include "llvm/CodeGen/AsmPrinter.h" #include "llvm/CodeGen/GCMetadataPrinter.h" -#include "llvm/CodeGen/GCStrategy.h" #include "llvm/Module.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCContext.h" @@ -25,18 +21,31 @@ #include "llvm/Target/TargetLoweringObjectFile.h" #include "llvm/Target/TargetMachine.h" #include "llvm/ADT/SmallString.h" +#include "llvm/Support/Compiler.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FormattedStream.h" #include + using namespace llvm; namespace { - class VmkitGC : public GCStrategy { + class VmkitAOTGC : public GCStrategy { public: - VmkitGC(); + VmkitAOTGC(); }; +} + +static GCRegistry::Add +X("vmkit", "Vmkit GC for AOT-generated functions"); - class VmkitGCMetadataPrinter : public GCMetadataPrinter { +VmkitAOTGC::VmkitAOTGC() { + NeededSafePoints = 1 << GC::PostCall; + UsesMetadata = true; +} + +namespace { + + class VmkitAOTGCMetadataPrinter : public GCMetadataPrinter { public: void beginAssembly(AsmPrinter &AP); void finishAssembly(AsmPrinter &AP); @@ -44,21 +53,12 @@ } +static GCMetadataPrinterRegistry::Add +Y("vmkit", "Vmkit GC for AOT-generated functions"); -static GCRegistry::Add -X("vmkit", "VMKit GC for AOT-generated functions"); - - -static GCMetadataPrinterRegistry::Add -Y("vmkit", "VMKit GC for AOT-generated functions"); - - -VmkitGC::VmkitGC() { - NeededSafePoints = 1 << GC::PostCall; - UsesMetadata = true; +void VmkitAOTGCMetadataPrinter::beginAssembly(AsmPrinter &AP) { } - static bool isAcceptableChar(char C) { if ((C < 'a' || C > 'z') && (C < 'A' || C > 'Z') && @@ -112,15 +112,14 @@ AP.OutStreamer.EmitLabel(Sym); } -void VmkitGCMetadataPrinter::beginAssembly(AsmPrinter &AP) { -} - /// emitAssembly - Print the frametable. The ocaml frametable format is thus: /// /// extern "C" struct align(sizeof(intptr_t)) { -/// uint16_t NumDescriptors; +/// uint32_t NumDescriptors; /// struct align(sizeof(intptr_t)) { /// void *ReturnAddress; +/// void *Metadata; +/// uint16_t BytecodeIndex; /// uint16_t FrameSize; /// uint16_t NumLiveOffsets; /// uint16_t LiveOffsets[NumLiveOffsets]; @@ -131,34 +130,45 @@ /// (FrameSize and LiveOffsets would overflow). FrameTablePrinter will abort if /// either condition is detected in a function which uses the GC. /// -void VmkitGCMetadataPrinter::finishAssembly(AsmPrinter &AP) { +void VmkitAOTGCMetadataPrinter::finishAssembly(AsmPrinter &AP) { unsigned IntPtrSize = AP.TM.getTargetData()->getPointerSize(); + AP.OutStreamer.SwitchSection(AP.getObjFileLowering().getDataSection()); + + AP.EmitAlignment(IntPtrSize == 4 ? 2 : 3); EmitVmkitGlobal(getModule(), AP, "frametable"); + int NumMethodFrames = 0; + for (iterator I = begin(), IE = end(); I != IE; ++I) { + NumMethodFrames++; + } + AP.EmitInt32(NumMethodFrames); - int NumDescriptors = 0; for (iterator I = begin(), IE = end(); I != IE; ++I) { GCFunctionInfo &FI = **I; + + // Emit the frame symbol + SmallString<128> TmpStr; + AP.Mang->getNameWithPrefix(TmpStr, FI.getFunction().getName() + "_frame"); + MCSymbol *Sym = AP.OutContext.GetOrCreateSymbol(TmpStr); + AP.OutStreamer.EmitSymbolAttribute(Sym, MCSA_Global); + AP.OutStreamer.EmitLabel(Sym); + + int NumDescriptors = 0; for (GCFunctionInfo::iterator J = FI.begin(), JE = FI.end(); J != JE; ++J) { NumDescriptors++; } - } - - if (NumDescriptors >= 1<<16) { - // Very rude! - report_fatal_error(" Too much descriptor for vmkit GC"); - } - AP.EmitInt16(NumDescriptors); - AP.EmitAlignment(IntPtrSize == 4 ? 2 : 3); - - for (iterator I = begin(), IE = end(); I != IE; ++I) { - GCFunctionInfo &FI = **I; + if (NumDescriptors >= 1<<16) { + // Very rude! + report_fatal_error(" Too much descriptor for J3 AOT GC"); + } + AP.EmitInt32(NumDescriptors); + AP.EmitAlignment(IntPtrSize == 4 ? 2 : 3); uint64_t FrameSize = FI.getFrameSize(); if (FrameSize >= 1<<16) { // Very rude! report_fatal_error("Function '" + FI.getFunction().getName() + - "' is too large for the vmkit GC! " + "' is too large for the Vmkit AOT GC! " "Frame size " + Twine(FrameSize) + ">= 65536.\n" "(" + Twine(uintptr_t(&FI)) + ")"); } @@ -172,11 +182,21 @@ if (LiveCount >= 1<<16) { // Very rude! report_fatal_error("Function '" + FI.getFunction().getName() + - "' is too large for the vmkit GC! " + "' is too large for the Vmkit AOT GC! " "Live root count "+Twine(LiveCount)+" >= 65536."); } + DebugLoc DL = J->Loc; + uint32_t sourceIndex = DL.getLine(); + + // Metada + AP.EmitInt32(0); + if (IntPtrSize == 8) { + AP.EmitInt32(0); + } + // Return address AP.OutStreamer.EmitSymbolValue(J->Label, IntPtrSize, 0); + AP.EmitInt16(sourceIndex); AP.EmitInt16(FrameSize); AP.EmitInt16(LiveCount); @@ -186,7 +206,7 @@ // Very rude! report_fatal_error( "GC root stack offset is outside of fixed stack frame and out " - "of range for vmkit GC!"); + "of range for ocaml GC!"); } AP.EmitInt16(K->StackOffset); } Modified: vmkit/trunk/tools/j3/Main.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/j3/Main.cpp?rev=136914&r1=136913&r2=136914&view=diff ============================================================================== --- vmkit/trunk/tools/j3/Main.cpp (original) +++ vmkit/trunk/tools/j3/Main.cpp Thu Aug 4 15:29:08 2011 @@ -28,8 +28,9 @@ #include "FrametablesExterns.inc" -CamlFrames* frametables[] = { +CompiledFrames* frametables[] = { #include "FrametablesSymbols.inc" + NULL }; int main(int argc, char **argv, char **envp) { @@ -47,7 +48,7 @@ JavaJITCompiler* Comp = JavaJITCompiler::CreateCompiler("JITModule"); JnjvmBootstrapLoader* loader = new(Allocator, "Bootstrap loader") JnjvmBootstrapLoader(Allocator, Comp, true); - Jnjvm* vm = new(Allocator, "VM") Jnjvm(Allocator, (CamlFrames**)frametables, loader); + Jnjvm* vm = new(Allocator, "VM") Jnjvm(Allocator, frametables, loader); // Run the application. vm->runApplication(argc, argv); Modified: vmkit/trunk/tools/precompiler/Precompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/precompiler/Precompiler.cpp?rev=136914&r1=136913&r2=136914&view=diff ============================================================================== --- vmkit/trunk/tools/precompiler/Precompiler.cpp (original) +++ vmkit/trunk/tools/precompiler/Precompiler.cpp Thu Aug 4 15:29:08 2011 @@ -37,8 +37,9 @@ #include "FrametablesExterns.inc" -CamlFrames* frametables[] = { +CompiledFrames* frametables[] = { #include "FrametablesSymbols.inc" + NULL }; @@ -66,7 +67,7 @@ JavaJITCompiler* JIT = JavaJITCompiler::CreateCompiler("JIT"); JnjvmBootstrapLoader* loader = new(Allocator, "Bootstrap loader") JnjvmBootstrapLoader(Allocator, JIT, true); - Jnjvm* vm = new(Allocator, "VM") Jnjvm(Allocator, (CamlFrames**)frametables, loader); + Jnjvm* vm = new(Allocator, "VM") Jnjvm(Allocator, frametables, loader); // Run the application. vm->runApplication(argc, argv); Modified: vmkit/trunk/tools/precompiler/trainer/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/precompiler/trainer/Makefile?rev=136914&r1=136913&r2=136914&view=diff ============================================================================== --- vmkit/trunk/tools/precompiler/trainer/Makefile (original) +++ vmkit/trunk/tools/precompiler/trainer/Makefile Thu Aug 4 15:29:08 2011 @@ -20,13 +20,13 @@ J3.Flags := > /dev/null endif -Precompiled.bc: $(PRECOMPILER) HelloWorld.java $(LibDir)/StaticJ3GC$(SHLIBEXT) $(LibDir)/StaticGCPass$(SHLIBEXT) $(LibDir)/StaticGCPrinter$(SHLIBEXT) +Precompiled.bc: $(PRECOMPILER) HelloWorld.java $(LibDir)/StaticGCPass$(SHLIBEXT) $(LibDir)/StaticGCPrinter$(SHLIBEXT) $(Echo) "Building precompiled bootstrap code" $(Verb) javac HelloWorld.java $(Verb) $(PRECOMPILER) -cp $$PWD HelloWorld $(J3.Flags) $(Verb) $(MKDIR) $(ObjDir) $(Verb) $(LOPT) generated.bc -load=$(LibDir)/StaticGCPass$(SHLIBEXT) -StaticGCPass -o $(LibDir)/Precompiled.bc - $(Verb) $(LLC) -O0 -fast-isel=false -load=$(LibDir)/StaticJ3GC$(SHLIBEXT) -load=$(LibDir)/StaticGCPrinter$(SHLIBEXT) -disable-fp-elim $(LibDir)/Precompiled.bc -o $(ObjDir)/Precompiled.s + $(Verb) $(LLC) -O0 -fast-isel=false -load=$(LibDir)/StaticGCPrinter$(SHLIBEXT) -disable-fp-elim $(LibDir)/Precompiled.bc -o $(ObjDir)/Precompiled.s $(Verb) $(LLVMCC) -c $(ObjDir)/Precompiled.s -o $(ObjDir)/Precompiled.o $(Verb) $(Archive) $(LibDir)/libPrecompiled.a $(ObjDir)/Precompiled.o $(Verb) $(Ranlib) $(LibDir)/libPrecompiled.a From nicolas.geoffray at lip6.fr Thu Aug 4 15:08:56 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 04 Aug 2011 22:08:56 -0000 Subject: [vmkit-commits] [vmkit] r136934 - in /vmkit/trunk: Makefile.rules tools/precompiler/trainer/Makefile Message-ID: <20110804220856.1853E2A6C12C@llvm.org> Author: geoffray Date: Thu Aug 4 17:08:55 2011 New Revision: 136934 URL: http://llvm.org/viewvc/llvm-project?rev=136934&view=rev Log: Disable CFI for vmjc generate files. Modified: vmkit/trunk/Makefile.rules vmkit/trunk/tools/precompiler/trainer/Makefile Modified: vmkit/trunk/Makefile.rules URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/Makefile.rules?rev=136934&r1=136933&r2=136934&view=diff ============================================================================== --- vmkit/trunk/Makefile.rules (original) +++ vmkit/trunk/Makefile.rules Thu Aug 4 17:08:55 2011 @@ -78,7 +78,7 @@ $(Verb) $(LLVMLD) -r -o $(LibDir)/FinalMMTk.bc $(LibDir)/MMTKAlloc.bc $(JARNAME)-optimized.bc $(LibDir)/MMTKRuntime.bc $(Verb) $(LOPT) $(LibDir)/FinalMMTk.bc -load=$(LibDir)/StaticGCPass$(SHLIBEXT) -std-compile-opts -StaticGCPass -o $(LibDir)/FinalMMTk.bc $(Verb) $(MKDIR) $(ObjDir) - $(Verb) $(LLC) -disable-fp-elim -load=$(LibDir)/StaticGCPrinter$(SHLIBEXT) $(LibDir)/FinalMMTk.bc -o $(ObjDir)/FinalMMTk.s + $(Verb) $(LLC) -disable-fp-elim -disable-cfi -load=$(LibDir)/StaticGCPrinter$(SHLIBEXT) $(LibDir)/FinalMMTk.bc -o $(ObjDir)/FinalMMTk.s $(Verb) $(LLVMCC) -c $(ObjDir)/FinalMMTk.s -o $(ObjDir)/FinalMMTk.o $(Verb) $(Archive) $(LibDir)/libFinalMMTk.a $(ObjDir)/FinalMMTk.o $(Verb) $(Ranlib) $(LibDir)/libFinalMMTk.a Modified: vmkit/trunk/tools/precompiler/trainer/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/precompiler/trainer/Makefile?rev=136934&r1=136933&r2=136934&view=diff ============================================================================== --- vmkit/trunk/tools/precompiler/trainer/Makefile (original) +++ vmkit/trunk/tools/precompiler/trainer/Makefile Thu Aug 4 17:08:55 2011 @@ -26,7 +26,7 @@ $(Verb) $(PRECOMPILER) -cp $$PWD HelloWorld $(J3.Flags) $(Verb) $(MKDIR) $(ObjDir) $(Verb) $(LOPT) generated.bc -load=$(LibDir)/StaticGCPass$(SHLIBEXT) -StaticGCPass -o $(LibDir)/Precompiled.bc - $(Verb) $(LLC) -O0 -fast-isel=false -load=$(LibDir)/StaticGCPrinter$(SHLIBEXT) -disable-fp-elim $(LibDir)/Precompiled.bc -o $(ObjDir)/Precompiled.s + $(Verb) $(LLC) -disable-cfi -O0 -fast-isel=false -load=$(LibDir)/StaticGCPrinter$(SHLIBEXT) -disable-fp-elim $(LibDir)/Precompiled.bc -o $(ObjDir)/Precompiled.s $(Verb) $(LLVMCC) -c $(ObjDir)/Precompiled.s -o $(ObjDir)/Precompiled.o $(Verb) $(Archive) $(LibDir)/libPrecompiled.a $(ObjDir)/Precompiled.o $(Verb) $(Ranlib) $(LibDir)/libPrecompiled.a From nicolas.geoffray at lip6.fr Sat Aug 6 01:28:57 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 06 Aug 2011 08:28:57 -0000 Subject: [vmkit-commits] [vmkit] r137015 - in /vmkit/trunk: Makefile.rules lib/J3/Compiler/JavaAOTCompiler.cpp lib/Mvm/StaticGCPass/Makefile mmtk/magic/LowerJavaRT.cpp mmtk/mmtk-j3/Makefile Message-ID: <20110806082857.C8DEA2A6C12D@llvm.org> Author: geoffray Date: Sat Aug 6 03:28:57 2011 New Revision: 137015 URL: http://llvm.org/viewvc/llvm-project?rev=137015&view=rev Log: Make some changes to how we AOT compile MMTk to prepare cleanup: - Remove dependency on a lazy jit compiler by making sure the magic methods are compiled before runnin LowerMagic on JITted methods - Remove dependency on -load-bc by compiling MMTKRuntime to both a shared library and a bytecode library Modified: vmkit/trunk/Makefile.rules vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp vmkit/trunk/lib/Mvm/StaticGCPass/Makefile vmkit/trunk/mmtk/magic/LowerJavaRT.cpp vmkit/trunk/mmtk/mmtk-j3/Makefile Modified: vmkit/trunk/Makefile.rules URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/Makefile.rules?rev=137015&r1=137014&r2=137015&view=diff ============================================================================== --- vmkit/trunk/Makefile.rules (original) +++ vmkit/trunk/Makefile.rules Sat Aug 6 03:28:57 2011 @@ -67,13 +67,11 @@ endif ifeq ($(COMPILE_MMTK), 1) - ADDITIONAL_ARGS := -load-bc=$(LibDir)/MMTKRuntime.bc - all:: $(Verb) $(ANT) -buildfile $(PROJ_OBJ_ROOT)/mmtk/java/build.xml $(Echo) Building $(BuildMode) $(JARNAME).jar $(notdir $@) $(Verb) $(LOPT) -load=$(LibDir)/JITGCPass$(SHLIBEXT) -std-compile-opts -JITGCPass -f $(LibDir)/MMTKAlloc.bc -o $(LibDir)/MMTKAlloc.bc - $(Verb) $(VMJC) -std-compile-opts $(ADDITIONAL_ARGS) -load=$(LibDir)/MMTKMagic$(SHLIBEXT) -LowerMagic $(PROJ_OBJ_ROOT)/mmtk/java/$(JARNAME).jar -disable-exceptions -disable-cooperativegc -with-clinit=org/mmtk/vm/VM,org/mmtk/utility/*,org/mmtk/policy/*,org/j3/config/* -Dmmtk.hostjvm=org.j3.mmtk.Factory -o $(JARNAME).bc -Dmmtk.properties=$(PROJ_SRC_ROOT)/mmtk/java/vmkit.properties -disable-stubs -assume-compiled -llvm-lazy + $(Verb) $(VMJC) -std-compile-opts -load=$(LibDir)/MMTKRuntime$(SHLIBEXT) -load=$(LibDir)/MMTKMagic$(SHLIBEXT) -LowerMagic $(PROJ_OBJ_ROOT)/mmtk/java/$(JARNAME).jar -disable-exceptions -disable-cooperativegc -with-clinit=org/mmtk/vm/VM,org/mmtk/utility/*,org/mmtk/policy/*,org/j3/config/* -Dmmtk.hostjvm=org.j3.mmtk.Factory -o $(JARNAME).bc -Dmmtk.properties=$(PROJ_SRC_ROOT)/mmtk/java/vmkit.properties -disable-stubs -assume-compiled $(Verb) $(LOPT) -load=$(LibDir)/MMTKMagic$(SHLIBEXT) -std-compile-opts -LowerJavaRT -f $(JARNAME).bc -o $(JARNAME)-optimized.bc $(Verb) $(LLVMLD) -r -o $(LibDir)/FinalMMTk.bc $(LibDir)/MMTKAlloc.bc $(JARNAME)-optimized.bc $(LibDir)/MMTKRuntime.bc $(Verb) $(LOPT) $(LibDir)/FinalMMTk.bc -load=$(LibDir)/StaticGCPass$(SHLIBEXT) -std-compile-opts -StaticGCPass -o $(LibDir)/FinalMMTk.bc Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=137015&r1=137014&r2=137015&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Sat Aug 6 03:28:57 2011 @@ -2098,13 +2098,17 @@ static const char* name; +extern "C" void UnreachableMagicMMTk() { + UNREACHABLE(); +} + void mainCompilerStart(JavaThread* th) { Jnjvm* vm = th->getJVM(); JnjvmBootstrapLoader* bootstrapLoader = vm->bootstrapLoader; JavaAOTCompiler* M = (JavaAOTCompiler*)bootstrapLoader->getCompiler(); - JavaJITCompiler* Comp = 0; - mvm::ThreadAllocator allocator; + M->addJavaPasses(); + bootstrapLoader->analyseClasspathEnv(vm->bootstrapLoader->bootClasspathEnv); uint32 size = strlen(name); if (size > 4 && @@ -2112,6 +2116,7 @@ bootstrapLoader->analyseClasspathEnv(name); } + JavaJITCompiler* Comp = NULL; if (!M->clinits->empty()) { Comp = JavaJITCompiler::CreateCompiler("JIT"); Comp->EmitFunctionName = true; @@ -2138,9 +2143,6 @@ } extractFiles(bytes, M, bootstrapLoader, classes); - // Now that we know if we can trust this compiler, add the Java passes. - M->addJavaPasses(); - // First resolve everyone so that there can not be unknown references in // constant pools. @@ -2157,65 +2159,90 @@ for (uint32 i = 0; i < cl->nbStaticMethods; ++i) { M->getMethod(&cl->staticMethods[i]); } - } if (!M->clinits->empty()) { vm->loadBootstrap(); + + // First, if we have the magic classes available, make sure we + // compile them so that we can call them directly and let + // LowerMagic lower them later on. + for (std::vector::iterator ii = classes.begin(), + ee = classes.end(); ii != ee; ++ii) { + Class* cl = *ii; + static const std::string magic = "org/vmmagic"; + static void* ptr = (void*)(uintptr_t)UnreachableMagicMMTk; + if (!strncmp(UTF8Buffer(cl->name).cString(), + magic.c_str(), + magic.length() - 1)) { + for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) { + if (!isAbstract(cl->virtualMethods[i].access)) { + Function* F = M->getMethod(&cl->virtualMethods[i]); + M->setMethod(F, ptr, F->getName().data()); + cl->virtualMethods[i].compiledPtr(); + } + } - for (std::vector::iterator i = M->clinits->begin(), - e = M->clinits->end(); i != e; ++i) { - - if (i->at(i->length() - 1) == '*') { - for (std::vector::iterator ii = classes.begin(), - ee = classes.end(); ii != ee; ++ii) { - Class* cl = *ii; - if (!strncmp(UTF8Buffer(cl->name).cString(), i->c_str(), - i->length() - 1)) { - TRY { - cl->asClass()->initialiseClass(vm); - } CATCH { - fprintf(stderr, "Error when initializing %s\n", - UTF8Buffer(cl->name).cString()); - abort(); - } END_CATCH; + for (uint32 i = 0; i < cl->nbStaticMethods; ++i) { + if (!isAbstract(cl->staticMethods[i].access)) { + Function* F = M->getMethod(&cl->staticMethods[i]); + M->setMethod(F, ptr, F->getName().data()); + cl->staticMethods[i].compiledPtr(); } } - } else { + } + } - const UTF8* name = bootstrapLoader->asciizConstructUTF8(i->c_str()); - CommonClass* cl = bootstrapLoader->lookupClass(name); - if (cl && cl->isClass()) { - TRY { - cl->asClass()->initialiseClass(vm); - } CATCH { - fprintf(stderr, "Error when initializing %s\n", - UTF8Buffer(cl->name).cString()); - abort(); - } END_CATCH; + // Initialize all classes given with with the -with-clinit + // command line argument. + for (std::vector::iterator i = M->clinits->begin(), + e = M->clinits->end(); i != e; ++i) { + Class* cl = NULL; + TRY { + if (i->at(i->length() - 1) == '*') { + for (std::vector::iterator ii = classes.begin(), + ee = classes.end(); ii != ee; ++ii) { + cl = *ii; + if (!strncmp(UTF8Buffer(cl->name).cString(), i->c_str(), + i->length() - 1)) { + cl->initialiseClass(vm); + } + } } else { - fprintf(stderr, "Class %s does not exist or is an array class.\n", - i->c_str()); + const UTF8* name = bootstrapLoader->asciizConstructUTF8(i->c_str()); + CommonClass* cls = bootstrapLoader->lookupClass(name); + if (cls && cls->isClass()) { + cl = cls->asClass(); + cl->initialiseClass(vm); + } else { + fprintf(stderr, "Class %s does not exist or is an array class.\n", + i->c_str()); + } } - } + } CATCH { + fprintf(stderr, "Error when initializing %s\n", + UTF8Buffer(cl->name).cString()); + abort(); + } END_CATCH; } bootstrapLoader->setCompiler(M); } - + + // Set the thread as the owner of the classes, so that it knows it + // has to compile them. for (std::vector::iterator i = classes.begin(), e = classes.end(); i != e; ++i) { - Class* cl = *i; - cl->setOwnerClass(JavaThread::get()); + (*i)->setOwnerClass(JavaThread::get()); } + // Finally, compile all classes. for (std::vector::iterator i = classes.begin(), e = classes.end(); i != e; ++i) { - Class* cl = *i; - M->compileClass(cl); + M->compileClass(*i); } } else { - M->addJavaPasses(); + mvm::ThreadAllocator allocator; char* realName = (char*)allocator.Allocate(size + 1); if (size > 6 && !strcmp(&name[size - 6], ".class")) { memcpy(realName, name, size - 6); Modified: vmkit/trunk/lib/Mvm/StaticGCPass/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/StaticGCPass/Makefile?rev=137015&r1=137014&r2=137015&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/StaticGCPass/Makefile (original) +++ vmkit/trunk/lib/Mvm/StaticGCPass/Makefile Sat Aug 6 03:28:57 2011 @@ -10,7 +10,6 @@ LEVEL = ../../.. LIBRARYNAME = StaticGCPass LOADABLE_MODULE = 1 -USEDLIBS = include $(LEVEL)/Makefile.common Modified: vmkit/trunk/mmtk/magic/LowerJavaRT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/magic/LowerJavaRT.cpp?rev=137015&r1=137014&r2=137015&view=diff ============================================================================== --- vmkit/trunk/mmtk/magic/LowerJavaRT.cpp (original) +++ vmkit/trunk/mmtk/magic/LowerJavaRT.cpp Sat Aug 6 03:28:57 2011 @@ -62,6 +62,16 @@ } } + // Remove all references to magic methods. + for (Module::iterator I = M.begin(), E = M.end(); I != E;) { + Function& GV = *I; + ++I; + if (!strncmp(GV.getName().data(), "JnJVM_org_vmmagic", 17)) { + GV.replaceAllUsesWith(Constant::getNullValue(GV.getType())); + GV.eraseFromParent(); + } + } + for (Module::global_iterator I = M.global_begin(), E = M.global_end(); I != E;) { GlobalValue& GV = *I; @@ -69,7 +79,7 @@ if (!strncmp(GV.getName().data(), "JnJVM_java", 10) || !strncmp(GV.getName().data(), "java", 4) || !strncmp(GV.getName().data(), "JnJVM_gnu", 9) || - !strncmp(GV.getName().data(), "_3", 2) || + !strncmp(GV.getName().data(), "_3", 2) || // Arrays !strncmp(GV.getName().data(), "gnu", 3)) { GV.replaceAllUsesWith(Constant::getNullValue(GV.getType())); GV.eraseFromParent(); Modified: vmkit/trunk/mmtk/mmtk-j3/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/mmtk-j3/Makefile?rev=137015&r1=137014&r2=137015&view=diff ============================================================================== --- vmkit/trunk/mmtk/mmtk-j3/Makefile (original) +++ vmkit/trunk/mmtk/mmtk-j3/Makefile Sat Aug 6 03:28:57 2011 @@ -12,8 +12,8 @@ include $(LEVEL)/Makefile.config MODULE_NAME = MMTKRuntime +LIBRARYNAME = MMTKRuntime LOADABLE_MODULE = 1 -USEDLIBS = CXX.Flags += -I$(PROJ_SRC_DIR)/../../lib/J3/VMCore From nicolas.geoffray at lip6.fr Sat Aug 6 02:01:01 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 06 Aug 2011 09:01:01 -0000 Subject: [vmkit-commits] [vmkit] r137016 - in /vmkit/trunk: include/j3/LLVMMaterializer.h include/mvm/MethodInfo.h lib/J3/Compiler/JavaJITCompiler.cpp lib/J3/Compiler/LLVMMaterializer.cpp lib/J3/VMCore/Jnjvm.cpp tools/vmjc/vmjc.cpp Message-ID: <20110806090101.B70F32A6C12C@llvm.org> Author: geoffray Date: Sat Aug 6 04:01:01 2011 New Revision: 137016 URL: http://llvm.org/viewvc/llvm-project?rev=137016&view=rev Log: Remove -load-bc and the lazy llvm jit compiler. Removed: vmkit/trunk/include/j3/LLVMMaterializer.h vmkit/trunk/lib/J3/Compiler/LLVMMaterializer.cpp Modified: vmkit/trunk/include/mvm/MethodInfo.h vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp vmkit/trunk/tools/vmjc/vmjc.cpp Removed: vmkit/trunk/include/j3/LLVMMaterializer.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/LLVMMaterializer.h?rev=137015&view=auto ============================================================================== --- vmkit/trunk/include/j3/LLVMMaterializer.h (original) +++ vmkit/trunk/include/j3/LLVMMaterializer.h (removed) @@ -1,74 +0,0 @@ -//===---------- LLVMMaterializer.h - LLVM Materializer for J3 -------------===// -// -// The VMKit project -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef J3_LLVM_MATERIALIZER_H -#define J3_LLVM_MATERIALIZER_H - -#include - -#include "j3/JavaJITCompiler.h" - -namespace j3 { - -class LLVMMaterializer; - -struct CallbackInfo { - Class* cl; - uint16 index; - bool stat; - - CallbackInfo(Class* c, uint32 i, bool s) : - cl(c), index(i), stat(s) {} - -}; - -class JavaLLVMLazyJITCompiler : public JavaJITCompiler { -private: - std::map callbacks; - typedef std::map::iterator callback_iterator; - -public: - llvm::GVMaterializer* TheMaterializer; - - virtual llvm::Value* addCallback(Class* cl, uint16 index, Signdef* sign, - bool stat, llvm::BasicBlock* insert); - virtual uintptr_t getPointerOrStub(JavaMethod& meth, int side); - - virtual JavaCompiler* Create(const std::string& ModuleID) { - return new JavaLLVMLazyJITCompiler(ModuleID); - } - - JavaLLVMLazyJITCompiler(const std::string& ModuleID); - - virtual ~JavaLLVMLazyJITCompiler(); - - virtual void* loadMethod(void* handle, const char* symbol); - - friend class LLVMMaterializer; -}; - -class LLVMMaterializer : public llvm::GVMaterializer { -public: - - JavaLLVMLazyJITCompiler* Comp; - llvm::Module* TheModule; - - LLVMMaterializer(llvm::Module* M, JavaLLVMLazyJITCompiler* C); - - virtual bool Materialize(llvm::GlobalValue *GV, std::string *ErrInfo = 0); - virtual bool isMaterializable(const llvm::GlobalValue*) const; - virtual bool isDematerializable(const llvm::GlobalValue*) const { - return false; - } - virtual bool MaterializeModule(llvm::Module*, std::string*) { return true; } -}; - -} // End j3 namespace - -#endif Modified: vmkit/trunk/include/mvm/MethodInfo.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/MethodInfo.h?rev=137016&r1=137015&r2=137016&view=diff ============================================================================== --- vmkit/trunk/include/mvm/MethodInfo.h (original) +++ vmkit/trunk/include/mvm/MethodInfo.h Sat Aug 6 04:01:01 2011 @@ -31,12 +31,6 @@ static void scan(uintptr_t closure, FrameInfo* FI, void* ip, void* addr); - static void* isStub(void* ip, void* addr) { - bool isStub = ((unsigned char*)ip)[0] == 0xCE; - if (isStub) ip = ((void**)addr)[2]; - return ip; - } - static uint32_t FrameInfoSize(uint32_t NumOffsets) { uint32_t FrameInfoSize = sizeof(FrameInfo) + (NumOffsets - 1) * sizeof(int16_t); if (FrameInfoSize & 2) { Modified: vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp?rev=137016&r1=137015&r2=137016&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp Sat Aug 6 04:01:01 2011 @@ -35,7 +35,6 @@ #include "j3/JavaJITCompiler.h" #include "j3/J3Intrinsics.h" -#include "j3/LLVMMaterializer.h" using namespace j3; using namespace llvm; @@ -408,14 +407,6 @@ : JavaJITCompiler(ModuleID) {} -static llvm::cl::opt LLVMLazy("llvm-lazy", - cl::desc("Use LLVM lazy stubs"), - cl::init(false)); - JavaJITCompiler* JavaJITCompiler::CreateCompiler(const std::string& ModuleID) { - // This is called for the first compiler. - if (LLVMLazy) { - return new JavaLLVMLazyJITCompiler(ModuleID); - } return new JavaJ3LazyJITCompiler(ModuleID); } Removed: vmkit/trunk/lib/J3/Compiler/LLVMMaterializer.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/LLVMMaterializer.cpp?rev=137015&view=auto ============================================================================== --- vmkit/trunk/lib/J3/Compiler/LLVMMaterializer.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/LLVMMaterializer.cpp (removed) @@ -1,186 +0,0 @@ -//===-------- LLVMMaterializer.cpp - LLVM Materializer for J3 -------------===// -// -// The VMKit project -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "llvm/Constants.h" -#include "llvm/Module.h" -#include "llvm/ExecutionEngine/ExecutionEngine.h" - -#include "mvm/JIT.h" - -#include "JavaAccess.h" -#include "JavaClass.h" -#include "JavaConstantPool.h" -#include "JavaThread.h" -#include "JavaTypes.h" -#include "Jnjvm.h" - -#include "j3/J3Intrinsics.h" -#include "j3/LLVMMaterializer.h" - -using namespace llvm; -using namespace j3; - - -JavaLLVMLazyJITCompiler::JavaLLVMLazyJITCompiler(const std::string& ModuleID) - : JavaJITCompiler(ModuleID) { - TheMaterializer = new LLVMMaterializer(TheModule, this); - executionEngine->DisableLazyCompilation(false); -} - -JavaLLVMLazyJITCompiler::~JavaLLVMLazyJITCompiler() { - // The module already destroys the materializer. -} - -void* JavaLLVMLazyJITCompiler::loadMethod(void* handle, const char* symbol) { - Function* F = mvm::MvmModule::globalModule->getFunction(symbol); - if (F) { - void* res = executionEngine->getPointerToFunctionOrStub(F); - return res; - } - - return JavaCompiler::loadMethod(handle, symbol); -} - -uintptr_t JavaLLVMLazyJITCompiler::getPointerOrStub(JavaMethod& meth, - int side) { - LLVMMethodInfo* LMI = getMethodInfo(&meth); - Function* func = LMI->getMethod(); - return (uintptr_t)executionEngine->getPointerToFunctionOrStub(func); -} - -static JavaMethod* staticLookup(CallbackInfo& F) { - Class* caller = F.cl; - uint16 index = F.index; - bool isStatic = F.stat; - JavaConstantPool* ctpInfo = caller->getConstantPool(); - - CommonClass* cl = 0; - const UTF8* utf8 = 0; - Signdef* sign = 0; - - ctpInfo->resolveMethod(index, cl, utf8, sign); - UserClass* lookup = cl->isArray() ? cl->super : cl->asClass(); - JavaMethod* meth = lookup->lookupMethod(utf8, sign->keyName, isStatic, true, - 0); - - assert(lookup->isInitializing() && "Class not ready"); - - return meth; -} - - -Value* JavaLLVMLazyJITCompiler::addCallback(Class* cl, uint16 index, - Signdef* sign, bool stat, - BasicBlock* insert) { - - Function* F = 0; - LLVMSignatureInfo* LSI = getSignatureInfo(sign); - mvm::ThreadAllocator allocator; - - const UTF8* name = cl->name; - char* key = (char*)allocator.Allocate(name->size + 16); - for (sint32 i = 0; i < name->size; ++i) - key[i] = name->elements[i]; - sprintf(key + name->size, "%d", index); - F = TheModule->getFunction(key); - if (F) return F; - - FunctionType* type = stat ? LSI->getStaticType() : - LSI->getVirtualType(); - - F = Function::Create(type, GlobalValue::ExternalWeakLinkage, key, TheModule); - - CallbackInfo A(cl, index, stat); - callbacks.insert(std::make_pair(F, A)); - - return F; -} - - -bool LLVMMaterializer::Materialize(GlobalValue *GV, std::string *ErrInfo) { - - Function* F = dyn_cast(GV); - assert(F && "Not a function"); - if (F->getLinkage() == GlobalValue::ExternalLinkage) return false; - - // The caller of materializeFunction *must* always hold the JIT lock. - // Because we are materializing a function here, we must release the - // JIT lock and get the global vmkit lock to be thread-safe. - // This prevents jitting the function while someone else is doing it. - Comp->executionEngine->lock.release(); - mvm::MvmModule::protectIR(); - - // Don't use hasNotBeenReadFromBitcode: materializeFunction is called - // by the pass manager, and we don't want another thread to JIT the - // function while all passes have not been run. - if (!(F->isDeclaration())) { - mvm::MvmModule::unprotectIR(); - // TODO: Is this still valid? - // Reacquire and go back to the JIT function. - // mvm::MvmModule::executionEngine->lock.acquire(); - return false; - } - - if (Comp->executionEngine->getPointerToGlobalIfAvailable(F)) { - mvm::MvmModule::unprotectIR(); - // TODO: Is this still valid? - // Reacquire and go back to the JIT function. - // mvm::MvmModule::executionEngine->lock.acquire(); - return false; - } - - JavaMethod* meth = Comp->getJavaMethod(*F); - - if (!meth) { - // It's a callback - JavaLLVMLazyJITCompiler::callback_iterator I = Comp->callbacks.find(F); - assert(I != Comp->callbacks.end() && "No callbacks found"); - meth = staticLookup(I->second); - } - - void* val = meth->compiledPtr(); - - if (isVirtual(meth->access)) { - LLVMMethodInfo* LMI = Comp->getMethodInfo(meth); - uint64_t offset = dyn_cast(LMI->getOffset())->getZExtValue(); - assert(meth->classDef->isResolved() && "Class not resolved"); -#if !defined(ISOLATE_SHARING) && !defined(SERVICE) - assert(meth->classDef->isInitializing() && "Class not ready"); -#endif - assert(meth->classDef->virtualVT && "Class has no VT"); - assert(meth->classDef->virtualTableSize > offset && - "The method's offset is greater than the virtual table size"); - ((void**)meth->classDef->virtualVT)[offset] = val; - } else { - assert(meth->classDef->isInitializing() && "Class not ready"); - } - - mvm::MvmModule::unprotectIR(); - - // TODO: Is this still valid? - // Reacquire to go back to the JIT function. - // mvm::MvmModule::executionEngine->lock.acquire(); - - if (F->isDeclaration()) - Comp->executionEngine->updateGlobalMapping(F, val); - - return false; -} - -bool LLVMMaterializer::isMaterializable(const llvm::GlobalValue* GV) const { - return GV->getLinkage() == GlobalValue::ExternalWeakLinkage; -} - - -LLVMMaterializer::LLVMMaterializer( - llvm::Module* m, JavaLLVMLazyJITCompiler* C) { - Comp = C; - TheModule = m; - m->setMaterializer(this); -} Modified: vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp?rev=137016&r1=137015&r2=137016&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp Sat Aug 6 04:01:01 2011 @@ -1446,20 +1446,17 @@ } void Jnjvm::printMethod(mvm::FrameInfo* FI, void* ip, void* addr) { - void* new_ip = NULL; - if (ip) new_ip = mvm::MethodInfoHelper::isStub(ip, 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)", new_ip, addr, + fprintf(stderr, "; %p (%p) in %s.%s (line %d, bytecode %d, code start %p)", ip, addr, UTF8Buffer(meth->classDef->name).cString(), UTF8Buffer(meth->name).cString(), meth->lookupLineNumber(FI), FI->SourceIndex, meth->code); - if (ip != new_ip) fprintf(stderr, " (from stub)"); fprintf(stderr, "\n"); } Modified: vmkit/trunk/tools/vmjc/vmjc.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/vmjc/vmjc.cpp?rev=137016&r1=137015&r2=137016&view=diff ============================================================================== --- vmkit/trunk/tools/vmjc/vmjc.cpp (original) +++ vmkit/trunk/tools/vmjc/vmjc.cpp Sat Aug 6 04:01:01 2011 @@ -109,23 +109,6 @@ cl::CommaSeparated); -static cl::list -LoadBytecodeFiles("load-bc", cl::desc("Load bytecode file"), cl::ZeroOrMore, - cl::CommaSeparated); - -static void loadBytecodeFile(const std::string& str) { - SMDiagnostic Err; - Module* M = ParseIRFile(str, Err, mvm::MvmModule::globalModule->getContext()); - if (M) { - M->setTargetTriple(mvm::MvmModule::getHostTriple()); - Linker::LinkModules(mvm::MvmModule::globalModule, M, 0); - delete M; - } else { - Err.Print("load bytecode", errs()); - } -} - - int main(int argc, char **argv) { llvm_shutdown_obj X; // Call llvm_shutdown() on exit. cl::ParseCommandLineOptions(argc, argv, "vmkit .class -> .ll compiler\n"); @@ -141,11 +124,6 @@ mvm::MvmModule::initialise(); - for (std::vector::iterator i = LoadBytecodeFiles.begin(), - e = LoadBytecodeFiles.end(); i != e; ++i) { - loadBytecodeFile(*i); - } - JavaAOTCompiler* Comp = new JavaAOTCompiler("AOT"); mvm::Collector::initialise(); From nicolas.geoffray at lip6.fr Sat Aug 6 05:01:51 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 06 Aug 2011 12:01:51 -0000 Subject: [vmkit-commits] [vmkit] r137017 - in /vmkit/trunk: include/j3/J3Intrinsics.h include/j3/JavaAOTCompiler.h include/j3/JavaLLVMCompiler.h include/mvm/JIT.h lib/J3/Compiler/J3Intrinsics.cpp lib/J3/Compiler/JavaAOTCompiler.cpp lib/J3/Compiler/JavaJITCompiler.cpp lib/J3/Compiler/JavaLLVMCompiler.cpp lib/J3/Compiler/LLVMInfo.cpp lib/Mvm/Compiler/InlineMalloc.cpp lib/Mvm/Compiler/JIT.cpp Message-ID: <20110806120151.3250E2A6C12C@llvm.org> Author: geoffray Date: Sat Aug 6 07:01:50 2011 New Revision: 137017 URL: http://llvm.org/viewvc/llvm-project?rev=137017&view=rev Log: Major cleanup in the MvmModule class: no need to create global variables shared across compilers. Modified: vmkit/trunk/include/j3/J3Intrinsics.h vmkit/trunk/include/j3/JavaAOTCompiler.h vmkit/trunk/include/j3/JavaLLVMCompiler.h vmkit/trunk/include/mvm/JIT.h vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp vmkit/trunk/lib/J3/Compiler/JavaLLVMCompiler.cpp vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp vmkit/trunk/lib/Mvm/Compiler/InlineMalloc.cpp vmkit/trunk/lib/Mvm/Compiler/JIT.cpp Modified: vmkit/trunk/include/j3/J3Intrinsics.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/J3Intrinsics.h?rev=137017&r1=137016&r2=137017&view=diff ============================================================================== --- vmkit/trunk/include/j3/J3Intrinsics.h (original) +++ vmkit/trunk/include/j3/J3Intrinsics.h Sat Aug 6 07:01:50 2011 @@ -17,6 +17,8 @@ class J3Intrinsics : public mvm::BaseIntrinsics { public: + void init(llvm::Module* M); + llvm::Type* JavaArrayUInt8Type; llvm::Type* JavaArraySInt8Type; llvm::Type* JavaArrayUInt16Type; @@ -149,12 +151,6 @@ llvm::Function* ArrayStoreExceptionFunction; llvm::Function* ArithmeticExceptionFunction; llvm::Function* ThrowExceptionFromJITFunction; - - - J3Intrinsics(llvm::Module*); - - static void initialise(); - }; } Modified: vmkit/trunk/include/j3/JavaAOTCompiler.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/JavaAOTCompiler.h?rev=137017&r1=137016&r2=137017&view=diff ============================================================================== --- vmkit/trunk/include/j3/JavaAOTCompiler.h (original) +++ vmkit/trunk/include/j3/JavaAOTCompiler.h Sat Aug 6 07:01:50 2011 @@ -78,8 +78,6 @@ virtual ~JavaAOTCompiler() {} - virtual void* loadMethod(void* handle, const char* symbol); - virtual CommonClass* getUniqueBaseClass(CommonClass* cl); private: Modified: vmkit/trunk/include/j3/JavaLLVMCompiler.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/JavaLLVMCompiler.h?rev=137017&r1=137016&r2=137017&view=diff ============================================================================== --- vmkit/trunk/include/j3/JavaLLVMCompiler.h (original) +++ vmkit/trunk/include/j3/JavaLLVMCompiler.h Sat Aug 6 07:01:50 2011 @@ -48,6 +48,7 @@ llvm::Module* TheModule; llvm::DIBuilder* DebugFactory; J3Intrinsics JavaIntrinsics; + const llvm::TargetData* TheTargetData; private: bool enabledException; @@ -180,7 +181,7 @@ return I->second; } } - + virtual llvm::Constant* getFinalObject(JavaObject* obj, CommonClass* cl) = 0; virtual JavaObject* getFinalObject(llvm::Value* C) = 0; virtual llvm::Constant* getNativeClass(CommonClass* cl) = 0; Modified: vmkit/trunk/include/mvm/JIT.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/JIT.h?rev=137017&r1=137016&r2=137017&view=diff ============================================================================== --- vmkit/trunk/include/mvm/JIT.h (original) +++ vmkit/trunk/include/mvm/JIT.h Sat Aug 6 07:01:50 2011 @@ -65,7 +65,7 @@ public: - explicit BaseIntrinsics(llvm::Module*); + void init(llvm::Module*); llvm::Function* exceptionEndCatch; llvm::Function* exceptionBeginCatch; @@ -181,24 +181,16 @@ class MvmModule { public: - static llvm::GCStrategy* TheGCStrategy; static mvm::LockRecursive protectEngine; - static llvm::Module *globalModule; - static const llvm::TargetData* TheTargetData; - static mvm::BumpPtrAllocator* Allocator; - static llvm::ExecutionEngine* executionEngine; - //static unsigned MetadataTypeKind; - static uint64 getTypeSize(llvm::Type* type); static void runPasses(llvm::Function* func, llvm::FunctionPassManager*); - static void initialise(llvm::CodeGenOpt::Level = llvm::CodeGenOpt::Default, - llvm::Module* TheModule = 0, - llvm::TargetMachine* TheTarget = 0); + static void initialise(); static Frames* addToVM(VirtualMachine* VM, llvm::GCFunctionInfo* GFI, llvm::JIT* jit, - mvm::BumpPtrAllocator& allocator); + mvm::BumpPtrAllocator& allocator, + void* meta); static int disassemble(unsigned int* addr); Modified: vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp?rev=137017&r1=137016&r2=137017&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp Sat Aug 6 07:01:50 2011 @@ -31,8 +31,9 @@ } } -J3Intrinsics::J3Intrinsics(llvm::Module* module) : - BaseIntrinsics(module) { +void J3Intrinsics::init(llvm::Module* module) { + BaseIntrinsics::init(module); + j3::llvm_runtime::makeLLVMModuleContents(module); LLVMContext& Context = module->getContext(); @@ -231,6 +232,5 @@ GetLockFunction = module->getFunction("getLock"); ThrowExceptionFromJITFunction = - module->getFunction("j3ThrowExceptionFromJIT"); - + module->getFunction("j3ThrowExceptionFromJIT"); } Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=137017&r1=137016&r2=137017&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Sat Aug 6 07:01:50 2011 @@ -14,6 +14,8 @@ #include "llvm/Module.h" #include "llvm/PassManager.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/Target/TargetData.h" +#include "llvm/Target/TargetRegistry.h" #include "mvm/UTF8.h" #include "mvm/Threads/Thread.h" @@ -1813,7 +1815,17 @@ JavaAOTCompiler::JavaAOTCompiler(const std::string& ModuleID) : JavaLLVMCompiler(ModuleID) { - + + std::string Error; + const Target* TheTarget(TargetRegistry::lookupTarget(mvm::MvmModule::getHostTriple(), Error)); + TargetMachine* TM = TheTarget->createTargetMachine(mvm::MvmModule::getHostTriple(), "", ""); + TheTargetData = TM->getTargetData(); + TheModule->setDataLayout(TheTargetData->getStringRepresentation()); + TheModule->setTargetTriple(TM->getTargetTriple()); + JavaIntrinsics.init(TheModule); + initialiseAssessorInfo(); + + generateStubs = true; assumeCompiled = false; compileRT = false; @@ -1888,7 +1900,7 @@ Module* Mod = getLLVMModule(); for (Module::const_global_iterator i = Mod->global_begin(), e = Mod->global_end(); i != e; ++i) { - size += mvm::MvmModule::getTypeSize(i->getType()); + size += TheTargetData->getTypeAllocSize(i->getType()); } fprintf(stdout, "%lluB\n", (unsigned long long int)size); } @@ -2489,20 +2501,6 @@ } - -// Use a FakeFunction to return from loadMethod, so that the compiler thinks -// the method is defined by J3. -extern "C" void __JavaAOTFakeFunction__() {} - -void* JavaAOTCompiler::loadMethod(void* handle, const char* symbol) { - Function* F = mvm::MvmModule::globalModule->getFunction(symbol); - if (F) { - return (void*)(uintptr_t)__JavaAOTFakeFunction__; - } - - return JavaCompiler::loadMethod(handle, symbol); -} - // TODO: clean up to have a better interface with the fake GC. #include extern std::set __InternalSet__; Modified: vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp?rev=137017&r1=137016&r2=137017&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp Sat Aug 6 07:01:50 2011 @@ -22,6 +22,7 @@ #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/Target/TargetData.h" #include <../lib/ExecutionEngine/JIT/JIT.h> #include "MvmGC.h" @@ -43,14 +44,11 @@ void *Code, size_t Size, const EmittedFunctionDetails &Details) { - // The following is necessary for -load-bc. - if (F.getParent() != TheCompiler->getLLVMModule()) return; assert(F.hasGC()); - if (TheCompiler->GCInfo != NULL) { - assert(TheCompiler->GCInfo == Details.MF->getGMI()); - return; + if (TheCompiler->GCInfo == NULL) { + TheCompiler->GCInfo = Details.MF->getGMI(); } - TheCompiler->GCInfo = Details.MF->getGMI(); + assert(TheCompiler->GCInfo == Details.MF->getGMI()); } @@ -163,6 +161,11 @@ executionEngine = ExecutionEngine::createJIT(TheModule, 0, 0, llvm::CodeGenOpt::Default, false); executionEngine->RegisterJITEventListener(&listener); + TheTargetData = executionEngine->getTargetData(); + TheModule->setDataLayout(TheTargetData->getStringRepresentation()); + TheModule->setTargetTriple(mvm::MvmModule::getHostTriple()); + JavaIntrinsics.init(TheModule); + initialiseAssessorInfo(); addJavaPasses(); } @@ -306,13 +309,10 @@ void* res = executionEngine->getPointerToGlobal(func); if (!func->isDeclaration()) { - llvm::GCFunctionInfo* GFI = &(GCInfo->getFunctionInfo(*func)); - assert((GFI != NULL) && "No GC information"); + llvm::GCFunctionInfo& GFI = GCInfo->getFunctionInfo(*func); Jnjvm* vm = JavaThread::get()->getJVM(); - mvm::Frames* frames = mvm::MvmModule::addToVM(vm, GFI, (JIT*)executionEngine, allocator); - meth->frames = frames; - meth->updateFrames(); + meth->frames = mvm::MvmModule::addToVM(vm, &GFI, (JIT*)executionEngine, allocator, meth); } // Now that it's compiled, we don't need the IR anymore func->deleteBody(); @@ -324,11 +324,10 @@ mvm::MvmModule::protectIR(); void* res = executionEngine->getPointerToGlobal(F); - llvm::GCFunctionInfo* GFI = &(GCInfo->getFunctionInfo(*F)); - assert((GFI != NULL) && "No GC information"); + llvm::GCFunctionInfo& GFI = GCInfo->getFunctionInfo(*F); Jnjvm* vm = JavaThread::get()->getJVM(); - mvm::MvmModule::addToVM(vm, GFI, (JIT*)executionEngine, allocator); + mvm::MvmModule::addToVM(vm, &GFI, (JIT*)executionEngine, allocator, NULL); // Now that it's compiled, we don't need the IR anymore F->deleteBody(); Modified: vmkit/trunk/lib/J3/Compiler/JavaLLVMCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaLLVMCompiler.cpp?rev=137017&r1=137016&r2=137017&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaLLVMCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaLLVMCompiler.cpp Sat Aug 6 07:01:50 2011 @@ -26,12 +26,10 @@ JavaLLVMCompiler::JavaLLVMCompiler(const std::string& str) : TheModule(new llvm::Module(str, *(new LLVMContext()))), - DebugFactory(new DIBuilder(*TheModule)), - JavaIntrinsics(TheModule) { + DebugFactory(new DIBuilder(*TheModule)) { enabledException = true; cooperativeGC = true; - initialiseAssessorInfo(); } void JavaLLVMCompiler::resolveVirtualClass(Class* cl) { @@ -125,6 +123,7 @@ JavaFunctionPasses->add(mvm::createLoopSafePointsPass()); // Add other passes after the loop pass, because safepoints may move objects. // Moving objects disable many optimizations. + JavaFunctionPasses->add(new TargetData(TheModule)); mvm::MvmModule::addCommandLinePasses(JavaFunctionPasses); // Re-enable this when the pointers in stack-allocated objects can Modified: vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp?rev=137017&r1=137016&r2=137017&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp Sat Aug 6 07:01:50 2011 @@ -38,7 +38,7 @@ Type* LLVMClassInfo::getVirtualType() { if (!virtualType) { std::vector fields; - const TargetData* targetData = mvm::MvmModule::TheTargetData; + const TargetData* targetData = Compiler->TheTargetData; const StructLayout* sl = 0; StructType* structType = 0; LLVMContext& context = Compiler->getLLVMModule()->getContext(); @@ -68,7 +68,7 @@ } - uint64 size = mvm::MvmModule::getTypeSize(structType); + uint64 size = targetData->getTypeAllocSize(structType); virtualSizeConstant = ConstantInt::get(Type::getInt32Ty(context), size); // TODO: put that elsewhere. @@ -109,7 +109,7 @@ StructType* structType = StructType::get(context, fields, false); staticType = PointerType::getUnqual(structType); - const TargetData* targetData = mvm::MvmModule::TheTargetData; + const TargetData* targetData = Compiler->TheTargetData; const StructLayout* sl = targetData->getStructLayout(structType); // TODO: put that elsewhere. @@ -120,7 +120,7 @@ field.ptrOffset = sl->getElementOffset(i); } - uint64 size = mvm::MvmModule::getTypeSize(structType); + uint64 size = targetData->getTypeAllocSize(structType); cl->staticSize = size; } } Modified: vmkit/trunk/lib/Mvm/Compiler/InlineMalloc.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Compiler/InlineMalloc.cpp?rev=137017&r1=137016&r2=137017&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Compiler/InlineMalloc.cpp (original) +++ vmkit/trunk/lib/Mvm/Compiler/InlineMalloc.cpp Sat Aug 6 07:01:50 2011 @@ -16,6 +16,7 @@ #include "llvm/Support/CallSite.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/Target/TargetData.h" #include "llvm/Transforms/Utils/Cloning.h" #include "mvm/JIT.h" @@ -41,6 +42,7 @@ Function* ArrayWriteBarrier = F.getParent()->getFunction("arrayWriteBarrier"); Function* NonHeapWriteBarrier = F.getParent()->getFunction("nonHeapWriteBarrier"); bool Changed = false; + const TargetData *TD = getAnalysisIfAvailable(); for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; BI++) { BasicBlock *Cur = BI; for (BasicBlock::iterator II = Cur->begin(), IE = Cur->end(); II != IE;) { @@ -54,14 +56,14 @@ Function* Temp = Call.getCalledFunction(); if (Temp == Malloc) { if (dyn_cast(Call.getArgument(0))) { - InlineFunctionInfo IFI(NULL, mvm::MvmModule::TheTargetData); + InlineFunctionInfo IFI(NULL, TD); Changed |= InlineFunction(Call, IFI); break; } } else if (Temp == FieldWriteBarrier || Temp == NonHeapWriteBarrier || Temp == ArrayWriteBarrier) { - InlineFunctionInfo IFI(NULL, mvm::MvmModule::TheTargetData); + InlineFunctionInfo IFI(NULL, TD); Changed |= InlineFunction(Call, IFI); break; } Modified: vmkit/trunk/lib/Mvm/Compiler/JIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Compiler/JIT.cpp?rev=137017&r1=137016&r2=137017&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Compiler/JIT.cpp (original) +++ vmkit/trunk/lib/Mvm/Compiler/JIT.cpp Sat Aug 6 07:01:50 2011 @@ -66,26 +66,7 @@ return LLVM_HOSTTRIPLE; } -class MvmJITListener : public llvm::JITEventListener { -public: - virtual void NotifyFunctionEmitted(const Function &F, - void *Code, size_t Size, - const EmittedFunctionDetails &Details) { - assert(F.getParent() == MvmModule::globalModule); - assert(F.hasGC()); - // We know the last GC info is for this method. - GCStrategy::iterator I = mvm::MvmModule::TheGCStrategy->end(); - I--; - DEBUG(errs() << (*I)->getFunction().getName() << '\n'); - DEBUG(errs() << F.getName() << '\n'); - assert(&(*I)->getFunction() == &F && - "GC Info and method do not correspond"); - llvm::GCFunctionInfo* GFI = *I; - MvmModule::addToVM(mvm::Thread::get()->MyVM, GFI, (JIT*)MvmModule::executionEngine, *MvmModule::Allocator); - } -}; - -Frames* MvmModule::addToVM(VirtualMachine* VM, GCFunctionInfo* FI, JIT* jit, BumpPtrAllocator& allocator) { +Frames* MvmModule::addToVM(VirtualMachine* VM, GCFunctionInfo* FI, JIT* jit, BumpPtrAllocator& allocator, void* meta) { JITCodeEmitter* JCE = jit->getCodeEmitter(); int NumDescriptors = 0; for (GCFunctionInfo::iterator J = FI->begin(), JE = FI->end(); J != JE; ++J) { @@ -107,7 +88,7 @@ frame->NumLiveOffsets = LiveCount; frame->FrameSize = FI->getFrameSize(); - frame->Metadata = NULL; + frame->Metadata = meta; frame->SourceIndex = I->Loc.getLine(); frame->ReturnAddress = reinterpret_cast(JCE->getLabelAddress(I->Label)); int i = 0; @@ -130,13 +111,7 @@ return frames; } -static MvmJITListener JITListener; - -typedef void (*BootType)(uintptr_t Plan); -typedef void (*BootHeapType)(intptr_t initial, intptr_t max); - -void MvmModule::initialise(CodeGenOpt::Level level, Module* M, - TargetMachine* T) { +void MvmModule::initialise() { mvm::linkVmkitGC(); llvm_start_multithreaded(); @@ -150,38 +125,13 @@ const char* commands[2] = { "vmkit", "-disable-branch-fold" }; llvm::cl::ParseCommandLineOptions(2, const_cast(commands)); - if (!M) { - globalModule = new Module("bootstrap module", *(new LLVMContext())); - - InitializeNativeTarget(); - - executionEngine = ExecutionEngine::createJIT(globalModule, 0, - 0, level, false); - - Allocator = new BumpPtrAllocator(); - executionEngine->RegisterJITEventListener(&JITListener); - std::string str = - executionEngine->getTargetData()->getStringRepresentation(); - globalModule->setDataLayout(str); - globalModule->setTargetTriple(getHostTriple()); - - TheTargetData = executionEngine->getTargetData(); - } else { - globalModule = M; - TheTargetData = T->getTargetData(); - } - - //LLVMContext& Context = globalModule->getContext(); - //MetadataTypeKind = Context.getMDKindID("HighLevelType"); - + InitializeNativeTarget(); } extern "C" void MMTk_InlineMethods(llvm::Module* module); -BaseIntrinsics::BaseIntrinsics(llvm::Module* module) { +void BaseIntrinsics::init(llvm::Module* module) { - module->setDataLayout(MvmModule::globalModule->getDataLayout()); - module->setTargetTriple(MvmModule::globalModule->getTargetTriple()); LLVMContext& Context = module->getContext(); MMTk_InlineMethods(module); @@ -319,17 +269,7 @@ NonHeapWriteBarrierFunction = module->getFunction("nonHeapWriteBarrier"); } -const llvm::TargetData* MvmModule::TheTargetData; -llvm::GCStrategy* MvmModule::TheGCStrategy; -llvm::Module *MvmModule::globalModule; -llvm::ExecutionEngine* MvmModule::executionEngine; mvm::LockRecursive MvmModule::protectEngine; -mvm::BumpPtrAllocator* MvmModule::Allocator; -//unsigned MvmModule::MetadataTypeKind; - -uint64 MvmModule::getTypeSize(llvm::Type* type) { - return TheTargetData->getTypeAllocSize(type); -} void MvmModule::runPasses(llvm::Function* func, llvm::FunctionPassManager* pm) { @@ -402,8 +342,6 @@ } void MvmModule::addCommandLinePasses(FunctionPassManager* PM) { - addPass(PM, new TargetData(*MvmModule::TheTargetData)); - addPass(PM, createVerifierPass()); // Verify that input is correct addPass(PM, createCFGSimplificationPass()); // Clean up disgusting code From nicolas.geoffray at lip6.fr Sat Aug 6 07:26:14 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 06 Aug 2011 14:26:14 -0000 Subject: [vmkit-commits] [vmkit] r137018 - in /vmkit/trunk: include/mvm/JIT.h lib/Mvm/Compiler/JIT.cpp lib/Mvm/Compiler/LLVMRuntime.ll Message-ID: <20110806142614.B65BE2A6C12C@llvm.org> Author: geoffray Date: Sat Aug 6 09:26:14 2011 New Revision: 137018 URL: http://llvm.org/viewvc/llvm-project?rev=137018&view=rev Log: Remove unused code. Modified: vmkit/trunk/include/mvm/JIT.h vmkit/trunk/lib/Mvm/Compiler/JIT.cpp vmkit/trunk/lib/Mvm/Compiler/LLVMRuntime.ll Modified: vmkit/trunk/include/mvm/JIT.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/JIT.h?rev=137018&r1=137017&r2=137018&view=diff ============================================================================== --- vmkit/trunk/include/mvm/JIT.h (original) +++ vmkit/trunk/include/mvm/JIT.h Sat Aug 6 09:26:14 2011 @@ -67,21 +67,12 @@ void init(llvm::Module*); - llvm::Function* exceptionEndCatch; - llvm::Function* exceptionBeginCatch; - llvm::Function* unwindResume; - llvm::Function* exceptionSelector; - llvm::Function* personality; - llvm::Function* llvmGetException; - llvm::Function* printFloatLLVM; llvm::Function* printDoubleLLVM; llvm::Function* printLongLLVM; llvm::Function* printIntLLVM; llvm::Function* printObjectLLVM; - llvm::Function* setjmpLLVM; - llvm::Function* func_llvm_fabs_f32; llvm::Function* func_llvm_fabs_f64; llvm::Function* func_llvm_sqrt_f64; Modified: vmkit/trunk/lib/Mvm/Compiler/JIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Compiler/JIT.cpp?rev=137018&r1=137017&r2=137018&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Compiler/JIT.cpp (original) +++ vmkit/trunk/lib/Mvm/Compiler/JIT.cpp Sat Aug 6 09:26:14 2011 @@ -202,15 +202,6 @@ printIntLLVM = module->getFunction("printInt"); printObjectLLVM = module->getFunction("printObject"); - unwindResume = module->getFunction("_Unwind_Resume_or_Rethrow"); - - llvmGetException = module->getFunction("llvm.eh.exception"); - exceptionSelector = module->getFunction("llvm.eh.selector"); - - personality = module->getFunction("__gxx_personality_v0"); - exceptionEndCatch = module->getFunction("__cxa_end_catch"); - exceptionBeginCatch = module->getFunction("__cxa_begin_catch"); - func_llvm_sqrt_f64 = module->getFunction("llvm.sqrt.f64"); func_llvm_sin_f64 = module->getFunction("llvm.sin.f64"); func_llvm_cos_f64 = module->getFunction("llvm.cos.f64"); @@ -239,8 +230,6 @@ func_llvm_fabs_f32 = module->getFunction("fabsf"); - setjmpLLVM = module->getFunction("setjmp"); - llvm_memcpy_i32 = module->getFunction("llvm.memcpy.i32"); llvm_memset_i32 = module->getFunction("llvm.memset.i32"); llvm_frameaddress = module->getFunction("llvm.frameaddress"); Modified: vmkit/trunk/lib/Mvm/Compiler/LLVMRuntime.ll URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Compiler/LLVMRuntime.ll?rev=137018&r1=137017&r2=137018&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Compiler/LLVMRuntime.ll (original) +++ vmkit/trunk/lib/Mvm/Compiler/LLVMRuntime.ll Sat Aug 6 09:26:14 2011 @@ -1,11 +1,4 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Common types ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -;;; A virtual table is an array of function pointers. -%VT = type [0 x i32 (...)*] - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Printing functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -16,19 +9,6 @@ declare void @printObject(i8*) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Exceptions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -declare void @_Unwind_Resume_or_Rethrow(i8*) -declare i8* @llvm.eh.exception() nounwind -declare i32 @llvm.eh.selector.i32(i8*, i8*, ...) nounwind -declare i64 @llvm.eh.selector.i64(i8*, i8*, ...) nounwind -declare void @__gxx_personality_v0() -declare i8* @__cxa_begin_catch(i8*) -declare void @__cxa_end_catch() -declare i32 @setjmp(i8*) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Math ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -74,13 +54,13 @@ declare i32 @llvm.atomic.cmp.swap.i32.p0i32(i32*, i32, i32) nounwind declare i64 @llvm.atomic.cmp.swap.i64.p0i64(i64*, i64, i64) nounwind -declare void @unconditionalSafePoint() nounwind -declare void @conditionalSafePoint() nounwind ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; GC ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +declare void @unconditionalSafePoint() nounwind +declare void @conditionalSafePoint() nounwind declare void @llvm.gcroot(i8**, i8*) declare i8* @gcmalloc(i32, i8*) declare i8* @gcmallocUnresolved(i32, i8*) From nicolas.geoffray at lip6.fr Sat Aug 6 07:53:43 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 06 Aug 2011 14:53:43 -0000 Subject: [vmkit-commits] [vmkit] r137019 - in /vmkit/trunk: include/mvm/Object.h include/mvm/PrintBuffer.h include/mvm/UTF8.h lib/J3/VMCore/JavaClass.h lib/J3/VMCore/JavaObject.h lib/J3/VMCore/JavaThread.h lib/J3/VMCore/Jnjvm.h lib/J3/VMCore/JnjvmClassLoader.h lib/J3/VMCore/Reader.h lib/J3/VMCore/UTF8.h lib/Mvm/Runtime/Object.cpp lib/Mvm/Runtime/UTF8.cpp tools/j3/Main.cpp tools/precompiler/Precompiler.cpp tools/vmjc/vmjc.cpp Message-ID: <20110806145343.414E32A6C12C@llvm.org> Author: geoffray Date: Sat Aug 6 09:53:42 2011 New Revision: 137019 URL: http://llvm.org/viewvc/llvm-project?rev=137019&view=rev Log: Remove dead code. Removed: vmkit/trunk/include/mvm/Object.h vmkit/trunk/include/mvm/PrintBuffer.h Modified: vmkit/trunk/include/mvm/UTF8.h vmkit/trunk/lib/J3/VMCore/JavaClass.h vmkit/trunk/lib/J3/VMCore/JavaObject.h vmkit/trunk/lib/J3/VMCore/JavaThread.h vmkit/trunk/lib/J3/VMCore/Jnjvm.h vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h vmkit/trunk/lib/J3/VMCore/Reader.h vmkit/trunk/lib/J3/VMCore/UTF8.h vmkit/trunk/lib/Mvm/Runtime/Object.cpp vmkit/trunk/lib/Mvm/Runtime/UTF8.cpp vmkit/trunk/tools/j3/Main.cpp vmkit/trunk/tools/precompiler/Precompiler.cpp vmkit/trunk/tools/vmjc/vmjc.cpp Removed: vmkit/trunk/include/mvm/Object.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Object.h?rev=137018&view=auto ============================================================================== --- vmkit/trunk/include/mvm/Object.h (original) +++ vmkit/trunk/include/mvm/Object.h (removed) @@ -1,56 +0,0 @@ -//===---------- Object.h - Common layout for all objects ------------------===// -// -// The Micro Virtual Machine -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef MVM_OBJECT_H -#define MVM_OBJECT_H - -#include "types.h" -#include "MvmGC.h" - -namespace mvm { - - -#define VT_DESTRUCTOR_OFFSET 0 -#define VT_OPERATOR_DELETE_OFFSET 1 -#define VT_TRACER_OFFSET 2 -#define VT_PRINT_OFFSET 3 -#define VT_HASHCODE_OFFSET 4 -#define VT_NB_FUNCS 5 -#define VT_SIZE 5 * sizeof(void*) - - -class PrintBuffer; - -/// Object - Root of all objects. Define default implementations of virtual -/// methods and some commodity functions. -/// -class Object : public gc { -public: - static void default_tracer(gc *o, uintptr_t closure) {} - static intptr_t default_hashCode(const gc *o) { return (intptr_t)o; } - static void default_print(const gc *o, PrintBuffer *buf); - - /// tracer - Default implementation of tracer. Does nothing. - /// - virtual void tracer(uintptr_t closure) { default_tracer(this, closure); } - - /// print - Default implementation of print. - /// - virtual void print(PrintBuffer *buf) const { default_print(this, buf); } - - /// hashCode - Default implementation of hashCode. Returns the address - /// of this object. - /// - virtual intptr_t hashCode() const { return default_hashCode(this);} - -}; - -} // end namespace mvm - -#endif // MVM_OBJECT_H Removed: vmkit/trunk/include/mvm/PrintBuffer.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/PrintBuffer.h?rev=137018&view=auto ============================================================================== --- vmkit/trunk/include/mvm/PrintBuffer.h (original) +++ vmkit/trunk/include/mvm/PrintBuffer.h (removed) @@ -1,186 +0,0 @@ -//===--------------- PrintBuffer.h - Printing objects ----------------------===// -// -// The Micro Virtual Machine -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef MVM_PRINTBUFFER_H -#define MVM_PRINTBUFFER_H - -#include // sprintf -#include // memcpy - -#include "types.h" -#include "mvm/Object.h" -#include "mvm/UTF8.h" - -namespace mvm { - -/// PrintBuffer - This class is a buffered string. -/// -class PrintBuffer { -public: - - /// contents - The buffer. - /// - char* contents; - - /// capacity - The capacity of the current buffer. - /// - uint32 capacity; - - /// writePosition - The position in the buffer where the next write will - /// happen. - /// - uint32 writePosition; - - void init() { - capacity = 256; - contents = new char[capacity]; - writePosition = 0; - } - -public: - PrintBuffer() { - init(); - } - - template - PrintBuffer(const T *obj) { - init(); - writeObj(obj); - } - - PrintBuffer(const Object *obj) { - llvm_gcroot(obj, 0); - init(); - writeObj(obj); - } - - virtual ~PrintBuffer() { - delete[] contents; - } - - char *cString() { - return contents; - } - - void ensureCapacity(uint32 len) { - uint32 size = writePosition + len + 1; - if (size >= capacity) { - while (size >= capacity) - capacity*= 4; - char *newContents = new char[capacity]; - memcpy(newContents, contents, writePosition); - delete[] contents; - contents = newContents; - } - } - - /// write - Writes to this PrintBuffer. - /// - virtual PrintBuffer *write(const char *string) { - uint32 len= strlen(string); - ensureCapacity(len); - strcpy(cString() + writePosition, string); - writePosition+= len; - return this; - } - - /// writeChar - Writes a char. - inline PrintBuffer *writeUTF8(const UTF8 *utf8) { - uint32 len = utf8->size; - ensureCapacity(len); - for(uint32 i=0; ielements[i], utf8->elements[i]); - contents[writePosition + i] = utf8->elements[i]; - } - contents[writePosition += len] = 0; - return this; - } - - /// writeChar - Writes a char. - inline PrintBuffer *writeBool(bool v) { - return write(v ? "true" : "false"); - } - - /// writeChar - Writes a char. - inline PrintBuffer *writeChar(char v) { - char buf[32]; - sprintf(buf, "%c", v); - return write(buf); - } - - /// writeChar - Writes a int32. - inline PrintBuffer *writeS4(int v) { - char buf[32]; - sprintf(buf, "%d", v); - return write(buf); - } - - /// writes8 - Writes a int64. - inline PrintBuffer *writeS8(sint64 v) { - char buf[32]; - sprintf(buf, "%lld", (long long int)v); - return write(buf); - } - - /// writeFP - Writes a double. - inline PrintBuffer *writeFP(double v) { - char buf[32]; - sprintf(buf, "%f", v); - return write(buf); - } - - /// writePtr - Writes a pointer. - inline PrintBuffer *writePtr(void *p) { - char buf[32]; - sprintf(buf, "%p", p); - return write(buf); - } - - /// writeBytes - Writes len bytes in the buffer bytes. - inline PrintBuffer *writeBytes(unsigned char *bytes, size_t len) { - write("["); - for (size_t idx= 0; idx < len; ++idx) { - if (idx > 0) - write(" "); - char buf[32]; - sprintf(buf, "%d", bytes[idx]); - write(buf); - } - write("]"); - return this; - } - - /// writeObj - Writes anything (except an object) to the buffer. - /// - template - inline PrintBuffer *writeObj(const T *obj) { - obj->print(this); - return this; - } - - /// writeObj - Writes a gc Object to the buffer. - /// - inline PrintBuffer *writeObj(const Object *obj) { - llvm_gcroot(obj, 0); - obj->print(this); - return this; - } - - - /// replaceWith - replace the content of the buffer and free the old buffer - /// - void replaceWith(char *buffer) { - delete[] this->contents; - this->contents = buffer; - } -}; - -} // end namespace mvm - -#endif // MVM_PRINTBUFFER_H Modified: vmkit/trunk/include/mvm/UTF8.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/UTF8.h?rev=137019&r1=137018&r2=137019&view=diff ============================================================================== --- vmkit/trunk/include/mvm/UTF8.h (original) +++ vmkit/trunk/include/mvm/UTF8.h Sat Aug 6 09:53:42 2011 @@ -8,7 +8,6 @@ namespace mvm { -class PrintBuffer; class UTF8Map; class UTF8 { @@ -53,8 +52,6 @@ size * sizeof(uint16)) < 0; } - void print(PrintBuffer *pb) const; - static uint32_t readerHasher(const uint16* buf, sint32 size); uint32_t hash() const { @@ -144,8 +141,6 @@ allocator.Deallocate((void*)*i); } } - - void insert(const UTF8* val); }; class UTF8Builder { Modified: vmkit/trunk/lib/J3/VMCore/JavaClass.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaClass.h?rev=137019&r1=137018&r2=137019&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaClass.h (original) +++ vmkit/trunk/lib/J3/VMCore/JavaClass.h Sat Aug 6 09:53:42 2011 @@ -15,7 +15,6 @@ #include "mvm/Allocator.h" #include "mvm/MethodInfo.h" -#include "mvm/Object.h" #include "mvm/Threads/Cond.h" #include "mvm/Threads/Locks.h" Modified: vmkit/trunk/lib/J3/VMCore/JavaObject.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaObject.h?rev=137019&r1=137018&r2=137019&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaObject.h (original) +++ vmkit/trunk/lib/J3/VMCore/JavaObject.h Sat Aug 6 09:53:42 2011 @@ -11,10 +11,10 @@ #define JNJVM_JAVA_OBJECT_H #include "mvm/Allocator.h" -#include "mvm/Object.h" #include "mvm/UTF8.h" #include "mvm/Threads/Locks.h" #include "mvm/Threads/Thread.h" +#include "MvmGC.h" #include "types.h" Modified: vmkit/trunk/lib/J3/VMCore/JavaThread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaThread.h?rev=137019&r1=137018&r2=137019&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaThread.h (original) +++ vmkit/trunk/lib/J3/VMCore/JavaThread.h Sat Aug 6 09:53:42 2011 @@ -10,7 +10,6 @@ #ifndef JNJVM_JAVA_THREAD_H #define JNJVM_JAVA_THREAD_H -#include "mvm/Object.h" #include "mvm/Threads/Cond.h" #include "mvm/Threads/Locks.h" #include "mvm/Threads/ObjectLocks.h" Modified: vmkit/trunk/lib/J3/VMCore/Jnjvm.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Jnjvm.h?rev=137019&r1=137018&r2=137019&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/Jnjvm.h (original) +++ vmkit/trunk/lib/J3/VMCore/Jnjvm.h Sat Aug 6 09:53:42 2011 @@ -16,7 +16,6 @@ #include "mvm/Allocator.h" #include "mvm/MethodInfo.h" -#include "mvm/Object.h" #include "mvm/VirtualMachine.h" #include "mvm/Threads/Cond.h" #include "mvm/Threads/Locks.h" Modified: vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h?rev=137019&r1=137018&r2=137019&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h (original) +++ vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h Sat Aug 6 09:53:42 2011 @@ -18,7 +18,6 @@ #include "mvm/Allocator.h" -#include "mvm/Object.h" #include "JavaObject.h" #include "JnjvmConfig.h" Modified: vmkit/trunk/lib/J3/VMCore/Reader.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Reader.h?rev=137019&r1=137018&r2=137019&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/Reader.h (original) +++ vmkit/trunk/lib/J3/VMCore/Reader.h Sat Aug 6 09:53:42 2011 @@ -10,8 +10,6 @@ #ifndef JNJVM_READER_H #define JNJVM_READER_H -#include "mvm/Object.h" - #include "types.h" #include "JavaArray.h" Modified: vmkit/trunk/lib/J3/VMCore/UTF8.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/UTF8.h?rev=137019&r1=137018&r2=137019&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/UTF8.h (original) +++ vmkit/trunk/lib/J3/VMCore/UTF8.h Sat Aug 6 09:53:42 2011 @@ -13,7 +13,6 @@ #include "types.h" #include "mvm/UTF8.h" -#include "mvm/PrintBuffer.h" namespace j3 { using mvm::UTF8; @@ -22,15 +21,27 @@ /// UTF8Buffer - Helper class to create char* buffers suitable for /// printf. /// -class UTF8Buffer : public mvm::PrintBuffer { +class UTF8Buffer { public: + char* contents; + /// UTF8Buffer - Create a buffer with the following UTF8. - UTF8Buffer(const UTF8* val) : mvm::PrintBuffer(val) {} + UTF8Buffer(const UTF8* val) { + contents = new char[val->size + 1]; + for (int i = 0; i < val->size; i++) { + contents[i] = (char)val->elements[i]; + } + contents[val->size] = 0; + } + + char* cString() const { + return contents; + } /// toCompileName - Change the utf8 following JNI conventions. /// UTF8Buffer* toCompileName(const char* suffix = "") { - const char *buffer = cString(); + const char *buffer = contents; uint32 len = strlen(buffer); uint32 suffixLen = strlen(suffix); char* newBuffer = new char[(len << 1) + suffixLen + 1]; @@ -58,9 +69,14 @@ newBuffer[j++] = suffix[i]; } newBuffer[j] = 0; - replaceWith(newBuffer); + delete[] contents; + contents = newBuffer; return this; } + + ~UTF8Buffer() { + delete[] contents; + } }; } Modified: vmkit/trunk/lib/Mvm/Runtime/Object.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/Object.cpp?rev=137019&r1=137018&r2=137019&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Runtime/Object.cpp (original) +++ vmkit/trunk/lib/Mvm/Runtime/Object.cpp Sat Aug 6 09:53:42 2011 @@ -11,8 +11,6 @@ #include #include "MvmGC.h" -#include "mvm/Object.h" -#include "mvm/PrintBuffer.h" #include "mvm/VirtualMachine.h" using namespace mvm; @@ -37,25 +35,6 @@ fprintf(stderr, "%p\n", ptr); } -extern "C" void write_ptr(PrintBuffer* buf, void* obj) { - buf->writePtr(obj); -} - -extern "C" void write_int(PrintBuffer* buf, int a) { - buf->writeS4(a); -} - -extern "C" void write_str(PrintBuffer* buf, char* a) { - buf->write(a); -} - -void Object::default_print(const gc *o, PrintBuffer *buf) { - llvm_gcroot(o, 0); - buf->write("writePtr((void*)o); - buf->write(">"); -} - void VirtualMachine::waitForExit() { threadLock.lock(); Modified: vmkit/trunk/lib/Mvm/Runtime/UTF8.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/UTF8.cpp?rev=137019&r1=137018&r2=137019&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Runtime/UTF8.cpp (original) +++ vmkit/trunk/lib/Mvm/Runtime/UTF8.cpp Sat Aug 6 09:53:42 2011 @@ -9,7 +9,6 @@ #include "mvm/Allocator.h" #include "mvm/UTF8.h" -#include "mvm/PrintBuffer.h" namespace mvm { @@ -17,11 +16,6 @@ extern "C" const UTF8 EmptyKey(0); -void UTF8::print(PrintBuffer *pb) const { - pb->writeUTF8(this); -} - - const UTF8* UTF8::extract(UTF8Map* map, uint32 start, uint32 end) const { uint32 len = end - start; ThreadAllocator allocator; @@ -98,10 +92,4 @@ return res; } - -void UTF8Map::insert(const UTF8* val) { - UTF8MapKey key(val->elements, val->size); - map[key] = val; -} - } // namespace mvm Modified: vmkit/trunk/tools/j3/Main.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/j3/Main.cpp?rev=137019&r1=137018&r2=137019&view=diff ============================================================================== --- vmkit/trunk/tools/j3/Main.cpp (original) +++ vmkit/trunk/tools/j3/Main.cpp Sat Aug 6 09:53:42 2011 @@ -10,7 +10,6 @@ #include "MvmGC.h" #include "mvm/JIT.h" #include "mvm/MethodInfo.h" -#include "mvm/Object.h" #include "mvm/VirtualMachine.h" #include "mvm/Threads/Thread.h" Modified: vmkit/trunk/tools/precompiler/Precompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/precompiler/Precompiler.cpp?rev=137019&r1=137018&r2=137019&view=diff ============================================================================== --- vmkit/trunk/tools/precompiler/Precompiler.cpp (original) +++ vmkit/trunk/tools/precompiler/Precompiler.cpp Sat Aug 6 09:53:42 2011 @@ -18,7 +18,6 @@ #include "MvmGC.h" #include "mvm/JIT.h" #include "mvm/MethodInfo.h" -#include "mvm/Object.h" #include "mvm/VirtualMachine.h" #include "mvm/Threads/Thread.h" Modified: vmkit/trunk/tools/vmjc/vmjc.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/vmjc/vmjc.cpp?rev=137019&r1=137018&r2=137019&view=diff ============================================================================== --- vmkit/trunk/tools/vmjc/vmjc.cpp (original) +++ vmkit/trunk/tools/vmjc/vmjc.cpp Sat Aug 6 09:53:42 2011 @@ -40,7 +40,6 @@ #include "MvmGC.h" #include "mvm/JIT.h" -#include "mvm/Object.h" #include "mvm/VirtualMachine.h" #include "mvm/Threads/Thread.h" From nicolas.geoffray at lip6.fr Sat Aug 6 08:10:24 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 06 Aug 2011 15:10:24 -0000 Subject: [vmkit-commits] [vmkit] r137020 - in /vmkit/trunk: include/j3/J3Intrinsics.h lib/J3/Compiler/J3Intrinsics.cpp lib/J3/Compiler/JavaJIT.cpp lib/J3/Compiler/JavaJIT.h Message-ID: <20110806151024.7B52F2A6C12C@llvm.org> Author: geoffray Date: Sat Aug 6 10:10:24 2011 New Revision: 137020 URL: http://llvm.org/viewvc/llvm-project?rev=137020&view=rev Log: Continue removing dead code. Modified: vmkit/trunk/include/j3/J3Intrinsics.h vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp vmkit/trunk/lib/J3/Compiler/JavaJIT.h Modified: vmkit/trunk/include/j3/J3Intrinsics.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/J3Intrinsics.h?rev=137020&r1=137019&r2=137020&view=diff ============================================================================== --- vmkit/trunk/include/j3/J3Intrinsics.h (original) +++ vmkit/trunk/include/j3/J3Intrinsics.h Sat Aug 6 10:10:24 2011 @@ -121,7 +121,6 @@ llvm::Constant* OffsetDoYieldInThreadConstant; llvm::Constant* OffsetIsolateIDInThreadConstant; llvm::Constant* OffsetVMInThreadConstant; - llvm::Constant* OffsetCXXExceptionInThreadConstant; llvm::Constant* OffsetThreadInMutatorThreadConstant; llvm::Constant* OffsetJNIInJavaThreadConstant; llvm::Constant* OffsetJavaExceptionInJavaThreadConstant; Modified: vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp?rev=137020&r1=137019&r2=137020&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp Sat Aug 6 10:10:24 2011 @@ -151,7 +151,6 @@ OffsetIsolateIDInThreadConstant = ConstantInt::get(Type::getInt32Ty(Context), 1); OffsetVMInThreadConstant = ConstantInt::get(Type::getInt32Ty(Context), 2); OffsetDoYieldInThreadConstant = ConstantInt::get(Type::getInt32Ty(Context), 4); - OffsetCXXExceptionInThreadConstant = ConstantInt::get(Type::getInt32Ty(Context), 11); OffsetThreadInMutatorThreadConstant = ConstantInt::get(Type::getInt32Ty(Context), 0); OffsetJNIInJavaThreadConstant = ConstantInt::get(Type::getInt32Ty(Context), 1); OffsetJavaExceptionInJavaThreadConstant = ConstantInt::get(Type::getInt32Ty(Context), 2); Modified: vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp?rev=137020&r1=137019&r2=137020&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp Sat Aug 6 10:10:24 2011 @@ -243,14 +243,6 @@ return GetElementPtrInst::Create(mutatorThreadPtr, GEP, "", currentBlock); } -llvm::Value* JavaJIT::getCXXExceptionPtr(llvm::Value* mutatorThreadPtr) { - Value* GEP[3] = { intrinsics->constantZero, - intrinsics->OffsetThreadInMutatorThreadConstant, - intrinsics->OffsetCXXExceptionInThreadConstant }; - - return GetElementPtrInst::Create(mutatorThreadPtr, GEP, "", currentBlock); -} - llvm::Value* JavaJIT::getJNIEnvPtr(llvm::Value* javaThreadPtr) { Value* GEP[2] = { intrinsics->constantZero, intrinsics->OffsetJNIInJavaThreadConstant }; @@ -266,8 +258,6 @@ } -extern "C" void j3ThrowExceptionFromJIT(); - llvm::Function* JavaJIT::nativeCompile(intptr_t natPtr) { PRINT_DEBUG(JNJVM_COMPILE, 1, COLOR_NORMAL, "native compile %s.%s\n", Modified: vmkit/trunk/lib/J3/Compiler/JavaJIT.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJIT.h?rev=137020&r1=137019&r2=137020&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJIT.h (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJIT.h Sat Aug 6 10:10:24 2011 @@ -149,9 +149,6 @@ /// getDoYieldPtr - Emit code to get a pointer to doYield. llvm::Value* getDoYieldPtr(llvm::Value* mutatorThreadPtr); - /// getCXXExceptionPtr - Emit code to get a pointer to internalPendingException. - llvm::Value* getCXXExceptionPtr(llvm::Value* mutatorThreadPtr); - /// getJavaThreadPtr - Emit code to get a pointer to the current JavaThread. llvm::Value* getJavaThreadPtr(llvm::Value* mutatorThreadPtr); From nicolas.geoffray at lip6.fr Sat Aug 6 11:17:11 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 06 Aug 2011 18:17:11 -0000 Subject: [vmkit-commits] [vmkit] r137022 - in /vmkit/trunk/lib: J3/VMCore/JavaClass.cpp J3/VMCore/JavaClass.h J3/VMCore/Jnjvm.cpp J3/VMCore/JnjvmClassLoader.h J3/VMCore/Precompiled.cpp Mvm/StaticGCPrinter/VmkitGCPrinter.cpp Message-ID: <20110806181711.769CC2A6C12C@llvm.org> Author: geoffray Date: Sat Aug 6 13:17:11 2011 New Revision: 137022 URL: http://llvm.org/viewvc/llvm-project?rev=137022&view=rev Log: No need to read the frames when reading precompiled methods: the JavaMethod metadata is already encoded. Modified: vmkit/trunk/lib/J3/VMCore/JavaClass.cpp vmkit/trunk/lib/J3/VMCore/JavaClass.h vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h vmkit/trunk/lib/J3/VMCore/Precompiled.cpp vmkit/trunk/lib/Mvm/StaticGCPrinter/VmkitGCPrinter.cpp Modified: vmkit/trunk/lib/J3/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaClass.cpp?rev=137022&r1=137021&r2=137022&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JavaClass.cpp Sat Aug 6 13:17:11 2011 @@ -1737,15 +1737,6 @@ } -void JavaMethod::updateFrames() { - mvm::FrameIterator iterator(*frames); - - while (iterator.hasNext()) { - mvm::FrameInfo* frame = iterator.next(); - frame->Metadata = this; - } -} - void Class::acquire() { JavaObject* delegatee = NULL; llvm_gcroot(delegatee, 0); Modified: vmkit/trunk/lib/J3/VMCore/JavaClass.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaClass.h?rev=137022&r1=137021&r2=137022&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaClass.h (original) +++ vmkit/trunk/lib/J3/VMCore/JavaClass.h Sat Aug 6 13:17:11 2011 @@ -902,10 +902,6 @@ /// uint32 offset; - /// updateFrames - Set the meta information on frames. - /// - void updateFrames(); - /// lookupAttribut - Look up an attribut in the method's attributs. Returns /// null if the attribut is not found. /// Modified: vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp?rev=137022&r1=137021&r2=137022&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp Sat Aug 6 13:17:11 2011 @@ -1326,8 +1326,6 @@ bootstrapLoader = loader; upcalls = bootstrapLoader->upcalls; throwable = upcalls->newThrowable; - - Precompiled::ReadFrames(this, this->bootstrapLoader); } Jnjvm::~Jnjvm() { Modified: vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h?rev=137022&r1=137021&r2=137022&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h (original) +++ vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.h Sat Aug 6 13:17:11 2011 @@ -426,7 +426,6 @@ class Precompiled { public: static bool Init(JnjvmBootstrapLoader* loader); - static void ReadFrames(Jnjvm* vm, JnjvmClassLoader* loader); }; /// VMClassLoader - The vmdata object that will be placed in and will only Modified: vmkit/trunk/lib/J3/VMCore/Precompiled.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Precompiled.cpp?rev=137022&r1=137021&r2=137022&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/Precompiled.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/Precompiled.cpp Sat Aug 6 13:17:11 2011 @@ -121,29 +121,6 @@ } -void Precompiled::ReadFrames(Jnjvm* vm, JnjvmClassLoader* loader) { - for (ClassMap::iterator i = loader->getClasses()->map.begin(), - e = loader->getClasses()->map.end(); i != e; ++i) { - CommonClass* cl = i->second; - if (cl->isClass()) { - Class* C = cl->asClass(); - for (uint32 i = 0; i < C->nbVirtualMethods; ++i) { - JavaMethod& meth = C->virtualMethods[i]; - if (meth.code != NULL) { - meth.updateFrames(); - } - } - - for (uint32 i = 0; i < C->nbStaticMethods; ++i) { - JavaMethod& meth = C->staticMethods[i]; - if (meth.code != NULL) { - meth.updateFrames(); - } - } - } - } -} - bool Precompiled::Init(JnjvmBootstrapLoader* loader) { Class* javaLangObject = (Class*)dlsym(SELF_HANDLE, "java_lang_Object"); void* nativeHandle = SELF_HANDLE; Modified: vmkit/trunk/lib/Mvm/StaticGCPrinter/VmkitGCPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/StaticGCPrinter/VmkitGCPrinter.cpp?rev=137022&r1=137021&r2=137022&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/StaticGCPrinter/VmkitGCPrinter.cpp (original) +++ vmkit/trunk/lib/Mvm/StaticGCPrinter/VmkitGCPrinter.cpp Sat Aug 6 13:17:11 2011 @@ -7,6 +7,9 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Constants.h" +#include "llvm/DerivedTypes.h" +#include "llvm/Type.h" #include "llvm/CodeGen/GCs.h" #include "llvm/CodeGen/GCStrategy.h" #include "llvm/CodeGen/AsmPrinter.h" @@ -24,7 +27,9 @@ #include "llvm/Support/Compiler.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FormattedStream.h" +#include "llvm/Support/raw_ostream.h" #include +#include using namespace llvm; @@ -112,6 +117,37 @@ AP.OutStreamer.EmitLabel(Sym); } +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) { + if (const Constant* C = dyn_cast(*I)) { + if (PointerType* PTy = dyn_cast(C->getType())) { + if (isa(PTy->getContainedType(0))) { + // We have found the bitcast constant that casts the method in a i8* + for (Value::const_use_iterator CI = C->use_begin(), CE = C->use_end(); CI != CE; ++CI) { + if (StructType* STy = dyn_cast((*CI)->getType())) { + if (STy->getName().equals("JavaMethod")) { + const Constant* Method = dyn_cast(*CI); + const Constant* Array = dyn_cast(*((*CI)->use_begin())); + Constant* VirtualMethods = dyn_cast(const_cast((*(Array->use_begin())))); + uint32_t index = 0; + for (; index < Array->getNumOperands(); index++) { + if (Array->getOperand(index) == Method) break; + } + assert(index != Array->getNumOperands()); + Constant* GEPs[2] = { ConstantInt::get(Type::getInt32Ty(context), 0), + ConstantInt::get(Type::getInt32Ty(context), index) }; + return ConstantExpr::getGetElementPtr(VirtualMethods, GEPs, 2); + } + } + } + } + } + } + } + return NULL; +} + /// emitAssembly - Print the frametable. The ocaml frametable format is thus: /// /// extern "C" struct align(sizeof(intptr_t)) { @@ -146,6 +182,8 @@ for (iterator I = begin(), IE = end(); I != IE; ++I) { GCFunctionInfo &FI = **I; + Constant* Metadata = FindMetadata(FI.getFunction()); + // Emit the frame symbol SmallString<128> TmpStr; AP.Mang->getNameWithPrefix(TmpStr, FI.getFunction().getName() + "_frame"); @@ -189,11 +227,16 @@ DebugLoc DL = J->Loc; uint32_t sourceIndex = DL.getLine(); - // Metada - AP.EmitInt32(0); - if (IntPtrSize == 8) { + // Metadata + if (Metadata != NULL) { + AP.EmitGlobalConstant(Metadata); + } else { AP.EmitInt32(0); + if (IntPtrSize == 8) { + AP.EmitInt32(0); + } } + // Return address AP.OutStreamer.EmitSymbolValue(J->Label, IntPtrSize, 0); AP.EmitInt16(sourceIndex); From nicolas.geoffray at lip6.fr Sat Aug 6 11:25:44 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 06 Aug 2011 18:25:44 -0000 Subject: [vmkit-commits] [vmkit] r137024 - in /vmkit/trunk: include/j3/J3Intrinsics.h lib/J3/Compiler/J3Intrinsics.cpp lib/J3/Compiler/JavaAOTCompiler.cpp lib/J3/Compiler/JavaJITCompiler.cpp lib/J3/LLVMRuntime/runtime-default.ll lib/J3/VMCore/JavaClass.cpp lib/J3/VMCore/JavaClass.h Message-ID: <20110806182544.E44192A6C12C@llvm.org> Author: geoffray Date: Sat Aug 6 13:25:44 2011 New Revision: 137024 URL: http://llvm.org/viewvc/llvm-project?rev=137024&view=rev Log: Remove unused fields in JavaMethod. Modified: vmkit/trunk/include/j3/J3Intrinsics.h vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp vmkit/trunk/lib/J3/LLVMRuntime/runtime-default.ll vmkit/trunk/lib/J3/VMCore/JavaClass.cpp vmkit/trunk/lib/J3/VMCore/JavaClass.h Modified: vmkit/trunk/include/j3/J3Intrinsics.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/J3Intrinsics.h?rev=137024&r1=137023&r2=137024&view=diff ============================================================================== --- vmkit/trunk/include/j3/J3Intrinsics.h (original) +++ vmkit/trunk/include/j3/J3Intrinsics.h Sat Aug 6 13:25:44 2011 @@ -40,7 +40,6 @@ llvm::Type* ClassBytesType; llvm::Type* JavaConstantPoolType; llvm::Type* ResolvedConstantPoolType; - llvm::Type* CodeLineInfoType; llvm::Type* UTF8Type; llvm::Type* JavaMethodType; llvm::Type* JavaFieldType; Modified: vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp?rev=137024&r1=137023&r2=137024&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/J3Intrinsics.cpp Sat Aug 6 13:25:44 2011 @@ -95,9 +95,6 @@ MutatorThreadType = PointerType::getUnqual(module->getTypeByName("MutatorThread")); - CodeLineInfoType = - PointerType::getUnqual(module->getTypeByName("CodeLineInfo")); - J3DenseMapType = PointerType::getUnqual(module->getTypeByName("J3DenseMap")); Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=137024&r1=137023&r2=137024&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Sat Aug 6 13:25:44 2011 @@ -1045,20 +1045,6 @@ JavaIntrinsics.ptrType)); } - // codeInfo - if (useCooperativeGC() && method.code != NULL) { - Twine name = getMethodInfo(&method)->getMethod()->getName() + "_frame"; - GlobalVariable* frame = new GlobalVariable( - Mod, JavaIntrinsics.CodeLineInfoType->getContainedType(0), false, - GlobalValue::ExternalLinkage, NULL, name); - MethodElts.push_back(frame); - } else { - MethodElts.push_back(Constant::getNullValue(JavaIntrinsics.CodeLineInfoType)); - } - - // codeInfoLength - MethodElts.push_back(ConstantInt::get(Type::getInt16Ty(getLLVMContext()), 0)); - // offset MethodElts.push_back(ConstantInt::get(Type::getInt32Ty(getLLVMContext()), method.offset)); Modified: vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp?rev=137024&r1=137023&r2=137024&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp Sat Aug 6 13:25:44 2011 @@ -312,7 +312,7 @@ llvm::GCFunctionInfo& GFI = GCInfo->getFunctionInfo(*func); Jnjvm* vm = JavaThread::get()->getJVM(); - meth->frames = mvm::MvmModule::addToVM(vm, &GFI, (JIT*)executionEngine, allocator, meth); + mvm::MvmModule::addToVM(vm, &GFI, (JIT*)executionEngine, allocator, meth); } // Now that it's compiled, we don't need the IR anymore func->deleteBody(); Modified: vmkit/trunk/lib/J3/LLVMRuntime/runtime-default.ll URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/LLVMRuntime/runtime-default.ll?rev=137024&r1=137023&r2=137024&view=diff ============================================================================== --- vmkit/trunk/lib/J3/LLVMRuntime/runtime-default.ll (original) +++ vmkit/trunk/lib/J3/LLVMRuntime/runtime-default.ll Sat Aug 6 13:25:44 2011 @@ -55,10 +55,8 @@ %JavaField = type { i8*, i16, %UTF8*, %UTF8*, %Attribut*, i16, %JavaClass*, i32, i16 } -%CodeLineInfo = type { i8*, %JavaMethod*, %CodeLineInfo* } - %JavaMethod = type { i8*, i16, %Attribut*, i16, %JavaClass*, - %UTF8*, %UTF8*, i8, i8*, %CodeLineInfo*, i16, i32 } + %UTF8*, %UTF8*, i8, i8*, i32 } %JavaClassPrimitive = type { %JavaCommonClass, i32 } %JavaClassArray = type { %JavaCommonClass, %JavaCommonClass* } @@ -93,7 +91,6 @@ %Attribut, %JavaThread, %MutatorThread, - %CodeLineInfo, %J3DenseMap); ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Modified: vmkit/trunk/lib/J3/VMCore/JavaClass.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaClass.cpp?rev=137024&r1=137023&r2=137024&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaClass.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JavaClass.cpp Sat Aug 6 13:25:44 2011 @@ -634,7 +634,6 @@ access = A; canBeInlined = false; offset = 0; - frames = NULL; } void JavaField::initialise(Class* cl, const UTF8* N, const UTF8* T, uint16 A) { Modified: vmkit/trunk/lib/J3/VMCore/JavaClass.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaClass.h?rev=137024&r1=137023&r2=137024&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaClass.h (original) +++ vmkit/trunk/lib/J3/VMCore/JavaClass.h Sat Aug 6 13:25:44 2011 @@ -888,16 +888,6 @@ /// void* code; - /// frames - Frames for this method. - /// TODO: Deprecate? - /// - mvm::Frames* frames; - - /// codeInfoLength - Number of entries in the codeInfo field. - /// TODO: Deprecate. - /// - uint16 codeInfoLength; - /// offset - The index of the method in the virtual table. /// uint32 offset; From nicolas.geoffray at lip6.fr Sat Aug 6 14:36:44 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 06 Aug 2011 21:36:44 -0000 Subject: [vmkit-commits] [vmkit] r137025 - in /vmkit/trunk: lib/Mvm/CommonThread/ObjectLocks.cpp lib/Mvm/Runtime/MethodInfo.cpp mmtk/mmtk-j3/ObjectModel.cpp tools/precompiler/trainer/Makefile Message-ID: <20110806213645.040692A6C12C@llvm.org> Author: geoffray Date: Sat Aug 6 16:36:44 2011 New Revision: 137025 URL: http://llvm.org/viewvc/llvm-project?rev=137025&view=rev Log: Fixes to get vmkit compile on macos. Modified: vmkit/trunk/lib/Mvm/CommonThread/ObjectLocks.cpp vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp vmkit/trunk/mmtk/mmtk-j3/ObjectModel.cpp vmkit/trunk/tools/precompiler/trainer/Makefile Modified: vmkit/trunk/lib/Mvm/CommonThread/ObjectLocks.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommonThread/ObjectLocks.cpp?rev=137025&r1=137024&r2=137025&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/CommonThread/ObjectLocks.cpp (original) +++ vmkit/trunk/lib/Mvm/CommonThread/ObjectLocks.cpp Sat Aug 6 16:36:44 2011 @@ -86,7 +86,7 @@ void printDebugMessage(gc* object, LockSystem& table) { llvm_gcroot(object, 0); fprintf(stderr, - "WARNING: [%p] has been waiting really long for %p (header = %x)\n", + "WARNING: [%p] has been waiting really long for %p (header = %lx)\n", (void*)mvm::Thread::get(), (void*)object, object->header); Modified: vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp?rev=137025&r1=137024&r2=137025&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp (original) +++ vmkit/trunk/lib/Mvm/Runtime/MethodInfo.cpp Sat Aug 6 16:36:44 2011 @@ -45,7 +45,7 @@ FunctionMap::FunctionMap(BumpPtrAllocator& allocator, CompiledFrames** allFrames) { if (allFrames == NULL) return; - Functions.resize(40000); // Make sure the cache is big enough. + Functions.resize(32000); // Make sure the cache is big enough. int i = 0; CompiledFrames* compiledFrames = NULL; while ((compiledFrames = allFrames[i++]) != NULL) { Modified: vmkit/trunk/mmtk/mmtk-j3/ObjectModel.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/mmtk-j3/ObjectModel.cpp?rev=137025&r1=137024&r2=137025&view=diff ============================================================================== --- vmkit/trunk/mmtk/mmtk-j3/ObjectModel.cpp (original) +++ vmkit/trunk/mmtk/mmtk-j3/ObjectModel.cpp Sat Aug 6 16:36:44 2011 @@ -78,7 +78,7 @@ } extern "C" uintptr_t JnJVM_org_j3_bindings_Bindings_copy__Lorg_vmmagic_unboxed_ObjectReference_2Lorg_vmmagic_unboxed_ObjectReference_2II( - gc* obj, VirtualTable* VT, int size, int allocator) ALWAYS_INLINE; + gc* obj, VirtualTable* VT, int size, int allocator); extern "C" uintptr_t Java_org_j3_mmtk_ObjectModel_copy__Lorg_vmmagic_unboxed_ObjectReference_2I ( MMTkObject* OM, gc* src, int allocator) ALWAYS_INLINE; Modified: vmkit/trunk/tools/precompiler/trainer/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/precompiler/trainer/Makefile?rev=137025&r1=137024&r2=137025&view=diff ============================================================================== --- vmkit/trunk/tools/precompiler/trainer/Makefile (original) +++ vmkit/trunk/tools/precompiler/trainer/Makefile Sat Aug 6 16:36:44 2011 @@ -27,7 +27,7 @@ $(Verb) $(MKDIR) $(ObjDir) $(Verb) $(LOPT) generated.bc -load=$(LibDir)/StaticGCPass$(SHLIBEXT) -StaticGCPass -o $(LibDir)/Precompiled.bc $(Verb) $(LLC) -disable-cfi -O0 -fast-isel=false -load=$(LibDir)/StaticGCPrinter$(SHLIBEXT) -disable-fp-elim $(LibDir)/Precompiled.bc -o $(ObjDir)/Precompiled.s - $(Verb) $(LLVMCC) -c $(ObjDir)/Precompiled.s -o $(ObjDir)/Precompiled.o + $(Verb) $(CC) -c $(ObjDir)/Precompiled.s -o $(ObjDir)/Precompiled.o $(Verb) $(Archive) $(LibDir)/libPrecompiled.a $(ObjDir)/Precompiled.o $(Verb) $(Ranlib) $(LibDir)/libPrecompiled.a $(Verb) $(MV) generated.bc Precompiled.bc From nicolas.geoffray at lip6.fr Sat Aug 6 15:03:56 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 06 Aug 2011 22:03:56 -0000 Subject: [vmkit-commits] [vmkit] r137026 - /vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Message-ID: <20110806220356.168102A6C12C@llvm.org> Author: geoffray Date: Sat Aug 6 17:03:55 2011 New Revision: 137026 URL: http://llvm.org/viewvc/llvm-project?rev=137026&view=rev Log: Put UTF8s and class references in the precompiled resolved constant pools. Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=137026&r1=137025&r2=137026&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Sat Aug 6 17:03:55 2011 @@ -183,7 +183,15 @@ ArrayType* ATy = ArrayType::get(JavaIntrinsics.ptrType, ctp->ctpSize); std::vector Vals; for (uint32 i = 0; i < ctp->ctpSize; ++i) { - Vals.push_back(Constant::getNullValue(JavaIntrinsics.ptrType)); + if (ctp->typeAt(i) == JavaConstantPool::ConstantUTF8) { + Vals.push_back(ConstantExpr::getBitCast(getUTF8(ctp->UTF8At(i)), JavaIntrinsics.ptrType)); + } else if (ctp->typeAt(i) == JavaConstantPool::ConstantClass + && (ctp->isClassLoaded(i) != NULL)) { + Vals.push_back(ConstantExpr::getBitCast( + getNativeClass(ctp->isClassLoaded(i)), JavaIntrinsics.ptrType)); + } else { + Vals.push_back(Constant::getNullValue(JavaIntrinsics.ptrType)); + } } Constant* Array = ConstantArray::get(ATy, Vals); @@ -2372,6 +2380,15 @@ meth->code = Func; } + // Make sure classes and arrays already referenced in constant pools + // are loaded. + for (ClassMap::iterator i = loader->getClasses()->map.begin(), + e = loader->getClasses()->map.end(); i!= e; ++i) { + if (i->second->isClass()) { + getResolvedConstantPool(i->second->asClass()->ctpInfo); + } + } + // Add all class initializers. for (ClassMap::iterator i = loader->getClasses()->map.begin(), e = loader->getClasses()->map.end(); i!= e; ++i) { From nicolas.geoffray at lip6.fr Sun Aug 7 01:46:44 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 07 Aug 2011 08:46:44 -0000 Subject: [vmkit-commits] [vmkit] r137030 - in /vmkit/trunk: include/j3/JavaAOTCompiler.h lib/J3/Compiler/JavaAOTCompiler.cpp lib/J3/VMCore/JnjvmClassLoader.cpp tools/j3/Makefile tools/precompiler/Precompiler.cpp tools/precompiler/trainer/Makefile Message-ID: <20110807084644.17CF32A6C12C@llvm.org> Author: geoffray Date: Sun Aug 7 03:46:43 2011 New Revision: 137030 URL: http://llvm.org/viewvc/llvm-project?rev=137030&view=rev Log: Create a different .o file for the class bytes. Modified: vmkit/trunk/include/j3/JavaAOTCompiler.h vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp vmkit/trunk/tools/j3/Makefile vmkit/trunk/tools/precompiler/Precompiler.cpp vmkit/trunk/tools/precompiler/trainer/Makefile Modified: vmkit/trunk/include/j3/JavaAOTCompiler.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/JavaAOTCompiler.h?rev=137030&r1=137029&r2=137030&view=diff ============================================================================== --- vmkit/trunk/include/j3/JavaAOTCompiler.h (original) +++ vmkit/trunk/include/j3/JavaAOTCompiler.h Sun Aug 7 03:46:43 2011 @@ -183,6 +183,7 @@ bool assumeCompiled; bool compileRT; bool precompile; + bool emitClassBytes; std::vector* clinits; @@ -196,6 +197,7 @@ void compileFile(Jnjvm* vm, const char* name); void compileClass(Class* cl); void compileClassLoader(JnjvmBootstrapLoader* loader); + void generateClassBytes(JnjvmBootstrapLoader* loader); void generateMain(const char* name, bool jit); private: Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=137030&r1=137029&r2=137030&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Sun Aug 7 03:46:43 2011 @@ -273,10 +273,15 @@ return CI->second; } - std::string name(UTF8Buffer(className).toCompileName()->cString()); - name += "_bytes"; - Constant* C = CreateConstantFromClassBytes(bytes); - GlobalVariable* varGV = new GlobalVariable(*getLLVMModule(), C->getType(), false, + std::vector Elemts; + ArrayType* ATy = ArrayType::get(Type::getInt8Ty(getLLVMContext()), bytes->size); + Elemts.push_back(Type::getInt32Ty(getLLVMContext())); + Elemts.push_back(ATy); + StructType* STy = StructType::get(getLLVMContext(), Elemts); + + std::string name(UTF8Buffer(className).toCompileName("_bytes")->cString()); + Constant* C = emitClassBytes ? CreateConstantFromClassBytes(bytes) : NULL; + GlobalVariable* varGV = new GlobalVariable(*getLLVMModule(), STy, false, GlobalValue::ExternalLinkage, C, name); classBytes[bytes] = varGV; @@ -1323,9 +1328,12 @@ ClassElts.push_back(Constant::getNullValue(JavaIntrinsics.ptrType)); // bytes - Constant* bytes = ConstantExpr::getBitCast(getClassBytes(cl->name, cl->bytes), - JavaIntrinsics.ClassBytesType); - ClassElts.push_back(bytes); + if (precompile) { + ClassElts.push_back(ConstantExpr::getBitCast(getClassBytes(cl->name, cl->bytes), + JavaIntrinsics.ClassBytesType)); + } else { + ClassElts.push_back(Constant::getNullValue(JavaIntrinsics.ClassBytesType)); + } // ctpInfo Constant* ctpInfo = CreateConstantFromJavaConstantPool(cl->ctpInfo); @@ -1824,6 +1832,7 @@ assumeCompiled = false; compileRT = false; precompile = false; + emitClassBytes = false; std::vector llvmArgs; FunctionType* FTy = FunctionType::get( @@ -2396,18 +2405,6 @@ AddInitializerToClass(gv, i->second); } - // Add the bootstrap classes to the image. - for (std::vector::iterator i = loader->bootArchives.begin(), - e = loader->bootArchives.end(); i != e; ++i) { - ZipArchive* archive = *i; - for (ZipArchive::table_iterator zi = archive->filetable.begin(), - ze = archive->filetable.end(); zi != ze; zi++) { - const char* name = zi->first; - ClassBytes* bytes = Reader::openZip(loader, archive, name); - getClassBytes(loader->asciizConstructUTF8(name), bytes); - } - } - // Finally add used stubs to the image. for (SignMap::iterator i = loader->javaSignatures->map.begin(), e = loader->javaSignatures->map.end(); i != e; i++) { @@ -2448,6 +2445,24 @@ CreateConstantFromUTF8Map(loader->hashUTF8->map); } +void JavaAOTCompiler::generateClassBytes(JnjvmBootstrapLoader* loader) { + emitClassBytes = true; + // Add the bootstrap classes to the image. + for (std::vector::iterator i = loader->bootArchives.begin(), + e = loader->bootArchives.end(); i != e; ++i) { + ZipArchive* archive = *i; + for (ZipArchive::table_iterator zi = archive->filetable.begin(), + ze = archive->filetable.end(); zi != ze; zi++) { + // Remove the '.class'. + const char* name = zi->first; + std::string str(name, strlen(name) - strlen(".class")); + ClassBytes* bytes = Reader::openZip(loader, archive, name); + getClassBytes(loader->asciizConstructUTF8(str.c_str()), bytes); + } + } +} + + /// compileAllStubs - Compile all the native -> Java stubs. /// TODO: Once LLVM supports va_arg, enable AP. /// Modified: vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp?rev=137030&r1=137029&r2=137030&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp Sun Aug 7 03:46:43 2011 @@ -240,7 +240,7 @@ ClassBytes* JnjvmBootstrapLoader::openName(const UTF8* utf8) { ClassBytes* res = reinterpret_cast(dlsym(SELF_HANDLE, - UTF8Buffer(utf8).toCompileName(".class_bytes")->cString())); + UTF8Buffer(utf8).toCompileName("_bytes")->cString())); if (res != NULL) return res; mvm::ThreadAllocator threadAllocator; Modified: vmkit/trunk/tools/j3/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/j3/Makefile?rev=137030&r1=137029&r2=137030&view=diff ============================================================================== --- vmkit/trunk/tools/j3/Makefile (original) +++ vmkit/trunk/tools/j3/Makefile Sun Aug 7 03:46:43 2011 @@ -11,7 +11,7 @@ include $(LEVEL)/Makefile.config TOOLNAME = j3 -USEDLIBS = Classpath.a J3.a J3Compiler.a Mvm.a MvmCompiler.a CommonThread.a FinalMMTk.a InlineMMTk.a Precompiled.a +USEDLIBS = Classpath.a J3.a J3Compiler.a Mvm.a MvmCompiler.a CommonThread.a FinalMMTk.a InlineMMTk.a Precompiled.a BootstrapClasses.a BUILD_FRAMETABLE = 1 LINK_COMPONENTS = jit nativecodegen scalaropts instrumentation ipa ipo Modified: vmkit/trunk/tools/precompiler/Precompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/precompiler/Precompiler.cpp?rev=137030&r1=137029&r2=137030&view=diff ============================================================================== --- vmkit/trunk/tools/precompiler/Precompiler.cpp (original) +++ vmkit/trunk/tools/precompiler/Precompiler.cpp Sun Aug 7 03:46:43 2011 @@ -50,9 +50,18 @@ vm->exit(); } - int main(int argc, char **argv, char **envp) { llvm::llvm_shutdown_obj X; + bool EmitClassBytes = false; + static const char* EmitClassBytesStr = "-emit-class-bytes"; + for (int i = 0; i < argc; i++) { + if (!strncmp(argv[i], EmitClassBytesStr, strlen(EmitClassBytesStr))) { + EmitClassBytes = true; + break; + } + } + + std::string OutputFilename; // Initialize base components. MvmModule::initialise(); @@ -60,32 +69,39 @@ // Tell the compiler to run all optimizations. StandardCompileOpts = true; - + // Create the allocator that will allocate the bootstrap loader and the JVM. mvm::BumpPtrAllocator Allocator; - JavaJITCompiler* JIT = JavaJITCompiler::CreateCompiler("JIT"); - JnjvmBootstrapLoader* loader = new(Allocator, "Bootstrap loader") - JnjvmBootstrapLoader(Allocator, JIT, true); - Jnjvm* vm = new(Allocator, "VM") Jnjvm(Allocator, frametables, loader); - - // Run the application. - vm->runApplication(argc, argv); - vm->waitForExit(); - - // Now AOT Compile all compiled methods. JavaAOTCompiler* AOT = new JavaAOTCompiler("AOT"); - loader->setCompiler(AOT); - - vm->doExit = false; - JavaThread* th = new JavaThread(vm); - vm->setMainThread(th); - th->start((void (*)(mvm::Thread*))mainCompilerLoaderStart); - vm->waitForExit(); + if (EmitClassBytes) { + OutputFilename = "classes.bc"; + JnjvmBootstrapLoader* loader = new(Allocator, "Bootstrap loader") + JnjvmBootstrapLoader(Allocator, AOT, true); + AOT->generateClassBytes(loader); + } else { + OutputFilename = "generated.bc"; + JavaJITCompiler* JIT = JavaJITCompiler::CreateCompiler("JIT"); + JnjvmBootstrapLoader* loader = new(Allocator, "Bootstrap loader") + JnjvmBootstrapLoader(Allocator, JIT, true); + Jnjvm* vm = new(Allocator, "VM") Jnjvm(Allocator, frametables, loader); + + // Run the application. + vm->runApplication(argc, argv); + 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->printStats(); // Emit the bytecode in file. - std::string OutputFilename = "generated.bc"; std::string ErrorInfo; std::auto_ptr Out (new llvm::raw_fd_ostream(OutputFilename.c_str(), ErrorInfo, Modified: vmkit/trunk/tools/precompiler/trainer/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/precompiler/trainer/Makefile?rev=137030&r1=137029&r2=137030&view=diff ============================================================================== --- vmkit/trunk/tools/precompiler/trainer/Makefile (original) +++ vmkit/trunk/tools/precompiler/trainer/Makefile Sun Aug 7 03:46:43 2011 @@ -10,7 +10,7 @@ include $(LEVEL)/Makefile.config -BUILT_SOURCES = Precompiled.bc +BUILT_SOURCES = Precompiled.bc BootstrapClasses.bc include $(LEVEL)/Makefile.common @@ -20,17 +20,35 @@ J3.Flags := > /dev/null endif -Precompiled.bc: $(PRECOMPILER) HelloWorld.java $(LibDir)/StaticGCPass$(SHLIBEXT) $(LibDir)/StaticGCPrinter$(SHLIBEXT) - $(Echo) "Building precompiled bootstrap code" +HelloWorld.class: HelloWorld.java + $(Echo) "Compiling trainer" $(Verb) javac HelloWorld.java + +generated.bc: $(PRECOMPILER) HelloWorld.class + $(Echo) "Pre-compiling bootstrap code" $(Verb) $(PRECOMPILER) -cp $$PWD HelloWorld $(J3.Flags) + +Precompiled.bc: HelloWorld.class $(LibDir)/StaticGCPass$(SHLIBEXT) $(LibDir)/StaticGCPrinter$(SHLIBEXT) generated.bc + $(Echo) "Building precompiled bootstrap code" $(Verb) $(MKDIR) $(ObjDir) - $(Verb) $(LOPT) generated.bc -load=$(LibDir)/StaticGCPass$(SHLIBEXT) -StaticGCPass -o $(LibDir)/Precompiled.bc - $(Verb) $(LLC) -disable-cfi -O0 -fast-isel=false -load=$(LibDir)/StaticGCPrinter$(SHLIBEXT) -disable-fp-elim $(LibDir)/Precompiled.bc -o $(ObjDir)/Precompiled.s + $(Verb) $(LLC) -disable-branch-fold -disable-cfi -O0 -fast-isel=false -load=$(LibDir)/StaticGCPrinter$(SHLIBEXT) -disable-fp-elim generated.bc -o $(ObjDir)/Precompiled.s $(Verb) $(CC) -c $(ObjDir)/Precompiled.s -o $(ObjDir)/Precompiled.o $(Verb) $(Archive) $(LibDir)/libPrecompiled.a $(ObjDir)/Precompiled.o $(Verb) $(Ranlib) $(LibDir)/libPrecompiled.a $(Verb) $(MV) generated.bc Precompiled.bc +classes.bc: $(PRECOMPILER) + $(Echo) "Pre-compiling classes" + $(Verb) $(PRECOMPILER) -emit-class-bytes $(J3.Flags) + +BootstrapClasses.bc: classes.bc + $(Echo) "Building precompiled classes" + $(Verb) $(MKDIR) $(ObjDir) + $(Verb) $(LLC) classes.bc -o $(ObjDir)/BootstrapClasses.s + $(Verb) $(CC) -c $(ObjDir)/BootstrapClasses.s -o $(ObjDir)/BootstrapClasses.o + $(Verb) $(Archive) $(LibDir)/libBootstrapClasses.a $(ObjDir)/BootstrapClasses.o + $(Verb) $(Ranlib) $(LibDir)/libBootstrapClasses.a + $(Verb) $(MV) classes.bc BootstrapClasses.bc + clean-local:: - $(Verb) $(RM) -f HelloWorld.class Precompiled.bc + $(Verb) $(RM) -f HelloWorld.class Precompiled.bc BootstrapClasses.bc From nicolas.geoffray at lip6.fr Sun Aug 7 02:17:09 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 07 Aug 2011 09:17:09 -0000 Subject: [vmkit-commits] [vmkit] r137031 - in /vmkit/trunk: include/j3/LLVMInfo.h lib/J3/Compiler/JavaAOTCompiler.cpp lib/J3/VMCore/JavaTypes.cpp Message-ID: <20110807091709.719672A6C12C@llvm.org> Author: geoffray Date: Sun Aug 7 04:17:09 2011 New Revision: 137031 URL: http://llvm.org/viewvc/llvm-project?rev=137031&view=rev Log: - Create less stubs while precompiling. - Rename stubs when precompiling, so that they don't share the same names. Modified: vmkit/trunk/include/j3/LLVMInfo.h vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp vmkit/trunk/lib/J3/VMCore/JavaTypes.cpp Modified: vmkit/trunk/include/j3/LLVMInfo.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/LLVMInfo.h?rev=137031&r1=137030&r2=137031&view=diff ============================================================================== --- vmkit/trunk/include/j3/LLVMInfo.h (original) +++ vmkit/trunk/include/j3/LLVMInfo.h Sun Aug 7 04:17:09 2011 @@ -105,6 +105,8 @@ functionType = 0; DbgSubprogram = 0; } + + 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=137031&r1=137030&r2=137031&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Sun Aug 7 04:17:09 2011 @@ -1569,8 +1569,9 @@ Function* JavaAOTCompiler::getMethodOrStub(JavaMethod* meth) { assert(!isStatic(meth->access)); - // TODO: check if llvm Function is populated instead of checking code is NULL - if (precompile && (meth->code == NULL)) { + if (precompile + && (meth->code == NULL) + && (getMethodInfo(meth)->methodFunction == NULL)) { LLVMSignatureInfo* LSI = getSignatureInfo(meth->getSignature()); return LSI->getVirtualStub(); } else { Modified: vmkit/trunk/lib/J3/VMCore/JavaTypes.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaTypes.cpp?rev=137031&r1=137030&r2=137031&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaTypes.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JavaTypes.cpp Sun Aug 7 04:17:09 2011 @@ -193,7 +193,9 @@ ptr[1] = '3'; ptr += 2; } else if (c == I_PARD) { - break; + ptr[0] = '_'; + ptr[1] = '_'; + ptr += 2; } else { ptr[0] = c; ++ptr; From nicolas.geoffray at lip6.fr Sun Aug 7 02:25:25 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 07 Aug 2011 09:25:25 -0000 Subject: [vmkit-commits] [vmkit] r137032 - /vmkit/trunk/lib/Mvm/StaticGCPrinter/VmkitGCPrinter.cpp Message-ID: <20110807092525.9E1912A6C12C@llvm.org> Author: geoffray Date: Sun Aug 7 04:25:25 2011 New Revision: 137032 URL: http://llvm.org/viewvc/llvm-project?rev=137032&view=rev Log: Remove (unused) naming of frames. Modified: vmkit/trunk/lib/Mvm/StaticGCPrinter/VmkitGCPrinter.cpp Modified: vmkit/trunk/lib/Mvm/StaticGCPrinter/VmkitGCPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/StaticGCPrinter/VmkitGCPrinter.cpp?rev=137032&r1=137031&r2=137032&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/StaticGCPrinter/VmkitGCPrinter.cpp (original) +++ vmkit/trunk/lib/Mvm/StaticGCPrinter/VmkitGCPrinter.cpp Sun Aug 7 04:25:25 2011 @@ -184,13 +184,6 @@ Constant* Metadata = FindMetadata(FI.getFunction()); - // Emit the frame symbol - SmallString<128> TmpStr; - AP.Mang->getNameWithPrefix(TmpStr, FI.getFunction().getName() + "_frame"); - MCSymbol *Sym = AP.OutContext.GetOrCreateSymbol(TmpStr); - AP.OutStreamer.EmitSymbolAttribute(Sym, MCSA_Global); - AP.OutStreamer.EmitLabel(Sym); - int NumDescriptors = 0; for (GCFunctionInfo::iterator J = FI.begin(), JE = FI.end(); J != JE; ++J) { NumDescriptors++; From nicolas.geoffray at lip6.fr Sun Aug 7 02:46:14 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 07 Aug 2011 09:46:14 -0000 Subject: [vmkit-commits] [vmkit] r137033 - /vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Message-ID: <20110807094614.8D5BC2A6C12C@llvm.org> Author: geoffray Date: Sun Aug 7 04:46:14 2011 New Revision: 137033 URL: http://llvm.org/viewvc/llvm-project?rev=137033&view=rev Log: Create the VT after compiling all methods, to generate even less stubs. Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=137033&r1=137032&r2=137033&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Sun Aug 7 04:46:14 2011 @@ -638,9 +638,9 @@ JavaIntrinsics.VTType); virtualTables.insert(std::make_pair(VT, res)); - if (isCompiling(classDef) || assumeCompiled) { - Constant* C = CreateConstantFromVT(VT); - varGV->setInitializer(C); + if ((precompile && classDef->isPrimitive()) + || (!precompile && (isCompiling(classDef) || assumeCompiled))) { + varGV->setInitializer(CreateConstantFromVT(VT)); } return res; @@ -2399,11 +2399,13 @@ } } - // Add all class initializers. + // Add all class and VT initializers. for (ClassMap::iterator i = loader->getClasses()->map.begin(), e = loader->getClasses()->map.end(); i!= e; ++i) { - GlobalVariable* gv = getNativeClass(i->second); - AddInitializerToClass(gv, i->second); + AddInitializerToClass(getNativeClass(i->second), i->second); + JavaVirtualTable* VT = i->second->virtualVT; + GlobalVariable* gv = dyn_cast(getVirtualTable(VT)->getOperand(0)); + gv->setInitializer(CreateConstantFromVT(VT)); } // Finally add used stubs to the image. From nicolas.geoffray at lip6.fr Sun Aug 7 03:20:32 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 07 Aug 2011 10:20:32 -0000 Subject: [vmkit-commits] [vmkit] r137034 - /vmkit/trunk/tools/precompiler/trainer/Makefile Message-ID: <20110807102032.71F902A6C12C@llvm.org> Author: geoffray Date: Sun Aug 7 05:20:32 2011 New Revision: 137034 URL: http://llvm.org/viewvc/llvm-project?rev=137034&view=rev Log: Change Makefile so that we don't have to recompile everything again. Modified: vmkit/trunk/tools/precompiler/trainer/Makefile Modified: vmkit/trunk/tools/precompiler/trainer/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/precompiler/trainer/Makefile?rev=137034&r1=137033&r2=137034&view=diff ============================================================================== --- vmkit/trunk/tools/precompiler/trainer/Makefile (original) +++ vmkit/trunk/tools/precompiler/trainer/Makefile Sun Aug 7 05:20:32 2011 @@ -35,7 +35,7 @@ $(Verb) $(CC) -c $(ObjDir)/Precompiled.s -o $(ObjDir)/Precompiled.o $(Verb) $(Archive) $(LibDir)/libPrecompiled.a $(ObjDir)/Precompiled.o $(Verb) $(Ranlib) $(LibDir)/libPrecompiled.a - $(Verb) $(MV) generated.bc Precompiled.bc + $(Verb) $(CP) generated.bc Precompiled.bc classes.bc: $(PRECOMPILER) $(Echo) "Pre-compiling classes" @@ -48,7 +48,7 @@ $(Verb) $(CC) -c $(ObjDir)/BootstrapClasses.s -o $(ObjDir)/BootstrapClasses.o $(Verb) $(Archive) $(LibDir)/libBootstrapClasses.a $(ObjDir)/BootstrapClasses.o $(Verb) $(Ranlib) $(LibDir)/libBootstrapClasses.a - $(Verb) $(MV) classes.bc BootstrapClasses.bc + $(Verb) $(CP) classes.bc BootstrapClasses.bc clean-local:: - $(Verb) $(RM) -f HelloWorld.class Precompiled.bc BootstrapClasses.bc + $(Verb) $(RM) -f HelloWorld.class generated.bc classes.bc Precompiled.bc BootstrapClasses.bc From nicolas.geoffray at lip6.fr Sun Aug 7 03:36:52 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 07 Aug 2011 10:36:52 -0000 Subject: [vmkit-commits] [vmkit] r137035 - /vmkit/trunk/lib/J3/Compiler/LowerConstantCalls.cpp Message-ID: <20110807103652.DB6C52A6C12C@llvm.org> Author: geoffray Date: Sun Aug 7 05:36:52 2011 New Revision: 137035 URL: http://llvm.org/viewvc/llvm-project?rev=137035&view=rev Log: Give a name to the pass. Modified: vmkit/trunk/lib/J3/Compiler/LowerConstantCalls.cpp Modified: vmkit/trunk/lib/J3/Compiler/LowerConstantCalls.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/LowerConstantCalls.cpp?rev=137035&r1=137034&r2=137035&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/LowerConstantCalls.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/LowerConstantCalls.cpp Sun Aug 7 05:36:52 2011 @@ -24,17 +24,19 @@ namespace j3 { - class LowerConstantCalls : public FunctionPass { - public: - static char ID; - JavaLLVMCompiler* TheCompiler; - LowerConstantCalls(JavaLLVMCompiler* Compiler) : FunctionPass(ID), - TheCompiler(Compiler) { } - - virtual bool runOnFunction(Function &F); - private: - }; - char LowerConstantCalls::ID = 0; +class LowerConstantCalls : public FunctionPass { +public: + static char ID; + JavaLLVMCompiler* TheCompiler; + LowerConstantCalls(JavaLLVMCompiler* Compiler) : FunctionPass(ID), + TheCompiler(Compiler) { } + + const char* getPassName() const { return "Lower Java calls"; } + + virtual bool runOnFunction(Function &F); +private: +}; +char LowerConstantCalls::ID = 0; static Value* getTCM(J3Intrinsics* intrinsics, Value* Arg, Instruction* CI) { Value* GEP[2] = { intrinsics->constantZero, From nicolas.geoffray at lip6.fr Sun Aug 7 03:44:37 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 07 Aug 2011 10:44:37 -0000 Subject: [vmkit-commits] [vmkit] r137036 - /vmkit/trunk/lib/Mvm/Compiler/InlineMalloc.cpp Message-ID: <20110807104437.BB2F42A6C12C@llvm.org> Author: geoffray Date: Sun Aug 7 05:44:37 2011 New Revision: 137036 URL: http://llvm.org/viewvc/llvm-project?rev=137036&view=rev Log: Give the pass a name. Modified: vmkit/trunk/lib/Mvm/Compiler/InlineMalloc.cpp Modified: vmkit/trunk/lib/Mvm/Compiler/InlineMalloc.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Compiler/InlineMalloc.cpp?rev=137036&r1=137035&r2=137036&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/Compiler/InlineMalloc.cpp (original) +++ vmkit/trunk/lib/Mvm/Compiler/InlineMalloc.cpp Sun Aug 7 05:44:37 2011 @@ -29,6 +29,9 @@ public: static char ID; InlineMalloc() : FunctionPass(ID) {} + virtual const char* getPassName() const { + return "Inline malloc and barriers"; + } virtual bool runOnFunction(Function &F); private: From nicolas.geoffray at lip6.fr Sun Aug 7 04:08:37 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 07 Aug 2011 11:08:37 -0000 Subject: [vmkit-commits] [vmkit] r137037 - in /vmkit/trunk: lib/Mvm/StaticGCPrinter/ tools/precompiler/ tools/precompiler/trainer/ Message-ID: <20110807110837.EAAD22A6C12C@llvm.org> Author: geoffray Date: Sun Aug 7 06:08:37 2011 New Revision: 137037 URL: http://llvm.org/viewvc/llvm-project?rev=137037&view=rev Log: Set ignore properties. Modified: vmkit/trunk/lib/Mvm/StaticGCPrinter/ (props changed) vmkit/trunk/tools/precompiler/ (props changed) vmkit/trunk/tools/precompiler/trainer/ (props changed) Propchange: vmkit/trunk/lib/Mvm/StaticGCPrinter/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Sun Aug 7 06:08:37 2011 @@ -0,0 +1,2 @@ +Release+Asserts +Release Propchange: vmkit/trunk/tools/precompiler/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Sun Aug 7 06:08:37 2011 @@ -0,0 +1,3 @@ +Release+Asserts +Release +*.inc Propchange: vmkit/trunk/tools/precompiler/trainer/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Sun Aug 7 06:08:37 2011 @@ -0,0 +1,4 @@ +Release+Asserts +Release +*.bc +*.class From nicolas.geoffray at lip6.fr Sun Aug 7 08:37:46 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 07 Aug 2011 15:37:46 -0000 Subject: [vmkit-commits] [vmkit] r137038 - in /vmkit/trunk: include/j3/JavaLLVMCompiler.h lib/J3/Compiler/JavaJITCompiler.cpp lib/J3/Compiler/LLVMInfo.cpp lib/J3/VMCore/JavaTypes.cpp lib/J3/VMCore/JavaTypes.h lib/Mvm/CommonThread/ObjectLocks.cpp Message-ID: <20110807153746.528212A6C12C@llvm.org> Author: geoffray Date: Sun Aug 7 10:37:46 2011 New Revision: 137038 URL: http://llvm.org/viewvc/llvm-project?rev=137038&view=rev Log: Avoid duplicated stubs by caching on the llvm::FunctionType. Modified: vmkit/trunk/include/j3/JavaLLVMCompiler.h vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp vmkit/trunk/lib/J3/VMCore/JavaTypes.cpp vmkit/trunk/lib/J3/VMCore/JavaTypes.h vmkit/trunk/lib/Mvm/CommonThread/ObjectLocks.cpp Modified: vmkit/trunk/include/j3/JavaLLVMCompiler.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/JavaLLVMCompiler.h?rev=137038&r1=137037&r2=137038&view=diff ============================================================================== --- vmkit/trunk/include/j3/JavaLLVMCompiler.h (original) +++ vmkit/trunk/include/j3/JavaLLVMCompiler.h Sun Aug 7 10:37:46 2011 @@ -14,6 +14,7 @@ #include "j3/J3Intrinsics.h" #include "j3/LLVMInfo.h" +#include "llvm/ADT/DenseMap.h" #include "llvm/LLVMContext.h" #include "llvm/Module.h" @@ -43,6 +44,7 @@ class JavaLLVMCompiler : public JavaCompiler { friend class LLVMClassInfo; friend class LLVMMethodInfo; + friend class LLVMSignatureInfo; protected: llvm::Module* TheModule; @@ -75,6 +77,14 @@ std::map DbgInfos; typedef std::map::iterator dbg_iterator; + llvm::DenseMap virtualStubs; + llvm::DenseMap specialStubs; + llvm::DenseMap staticStubs; + llvm::DenseMap virtualBufs; + llvm::DenseMap staticBufs; + llvm::DenseMap virtualAPs; + llvm::DenseMap staticAPs; + public: JavaLLVMCompiler(const std::string &ModuleID); Modified: vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp?rev=137038&r1=137037&r2=137038&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp Sun Aug 7 10:37:46 2011 @@ -313,9 +313,10 @@ Jnjvm* vm = JavaThread::get()->getJVM(); mvm::MvmModule::addToVM(vm, &GFI, (JIT*)executionEngine, allocator, meth); - } + // Now that it's compiled, we don't need the IR anymore - func->deleteBody(); + func->deleteBody(); + } mvm::MvmModule::unprotectIR(); return res; } @@ -323,14 +324,18 @@ void* JavaJITCompiler::GenerateStub(llvm::Function* F) { mvm::MvmModule::protectIR(); void* res = executionEngine->getPointerToGlobal(F); + + // If the stub was already generated through an equivalent signature, + // The body has been deleted, so the function just becomes a declaration. + if (!F->isDeclaration()) { + llvm::GCFunctionInfo& GFI = GCInfo->getFunctionInfo(*F); - llvm::GCFunctionInfo& GFI = GCInfo->getFunctionInfo(*F); - - Jnjvm* vm = JavaThread::get()->getJVM(); - mvm::MvmModule::addToVM(vm, &GFI, (JIT*)executionEngine, allocator, NULL); + Jnjvm* vm = JavaThread::get()->getJVM(); + mvm::MvmModule::addToVM(vm, &GFI, (JIT*)executionEngine, allocator, NULL); - // Now that it's compiled, we don't need the IR anymore - F->deleteBody(); + // Now that it's compiled, we don't need the IR anymore + F->deleteBody(); + } mvm::MvmModule::unprotectIR(); return res; } Modified: vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp?rev=137038&r1=137037&r2=137038&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp Sun Aug 7 10:37:46 2011 @@ -311,21 +311,26 @@ LLVMContext& context = Compiler->getLLVMModule()->getContext(); J3Intrinsics& Intrinsics = *Compiler->getIntrinsics(); Function* res = 0; + FunctionType* FTy = virt ? getVirtualBufType() : getStaticBufType(); + if (virt) { + res = Compiler->virtualBufs[FTy]; + } else { + res = Compiler->staticBufs[FTy]; + } + if (res != NULL) { + return res; + } if (Compiler->isStaticCompiling()) { mvm::ThreadAllocator allocator; const char* type = virt ? "virtual_buf" : "static_buf"; char* buf = (char*)allocator.Allocate( (signature->keyName->size << 1) + 1 + 11); signature->nativeName(buf, type); - res = Function::Create(virt ? getVirtualBufType() : getStaticBufType(), - GlobalValue::ExternalLinkage, buf, - Compiler->getLLVMModule()); - - + res = Function::Create( + FTy, GlobalValue::ExternalLinkage, buf, Compiler->getLLVMModule()); } else { - res = Function::Create(virt ? getVirtualBufType() : getStaticBufType(), - GlobalValue::ExternalLinkage, "", - Compiler->getLLVMModule()); + res = Function::Create( + FTy, GlobalValue::ExternalLinkage, "", Compiler->getLLVMModule()); } BasicBlock* currentBlock = BasicBlock::Create(context, "enter", res); @@ -390,6 +395,12 @@ res->setGC("vmkit"); + if (virt) { + Compiler->virtualBufs[FTy] = res; + } else { + Compiler->staticBufs[FTy] = res; + } + return res; } @@ -399,21 +410,26 @@ J3Intrinsics& Intrinsics = *Compiler->getIntrinsics(); Function* res = NULL; + FunctionType* FTy = virt ? getVirtualBufType() : getStaticBufType(); + if (virt) { + res = Compiler->virtualAPs[FTy]; + } else { + res = Compiler->staticAPs[FTy]; + } + if (res != NULL) { + return res; + } if (Compiler->isStaticCompiling()) { mvm::ThreadAllocator allocator; const char* type = virt ? "virtual_ap" : "static_ap"; char* buf = (char*)allocator.Allocate( (signature->keyName->size << 1) + 1 + 11); signature->nativeName(buf, type); - res = Function::Create(virt ? getVirtualBufType() : getStaticBufType(), - GlobalValue::ExternalLinkage, buf, - Compiler->getLLVMModule()); - - + res = Function::Create( + FTy, GlobalValue::ExternalLinkage, buf, Compiler->getLLVMModule()); } else { - res = Function::Create(virt ? getVirtualBufType() : getStaticBufType(), - GlobalValue::ExternalLinkage, "", - Compiler->getLLVMModule()); + res = Function::Create( + FTy, GlobalValue::ExternalLinkage, "", Compiler->getLLVMModule()); } LLVMContext& context = Compiler->getLLVMModule()->getContext(); @@ -467,6 +483,11 @@ res->setGC("vmkit"); + if (virt) { + Compiler->virtualAPs[FTy] = res; + } else { + Compiler->staticAPs[FTy] = res; + } return res; } @@ -478,21 +499,30 @@ J3Intrinsics& Intrinsics = *Compiler->getIntrinsics(); Function* stub = NULL; + FunctionType* FTy = (virt || special)? getVirtualType() : getStaticType(); + if (virt) { + stub = Compiler->virtualStubs[FTy]; + } else if (special) { + stub = Compiler->specialStubs[FTy]; + } else { + stub = Compiler->staticStubs[FTy]; + } + if (stub != NULL) { + return stub; + } if (Compiler->isStaticCompiling()) { mvm::ThreadAllocator allocator; const char* type = virt ? "virtual_stub" : special ? "special_stub" : "static_stub"; char* buf = (char*)allocator.Allocate( (signature->keyName->size << 1) + 1 + 11); signature->nativeName(buf, type); - stub = Function::Create((virt || special)? getVirtualType() : getStaticType(), - GlobalValue::ExternalLinkage, buf, - Compiler->getLLVMModule()); + stub = Function::Create( + FTy, GlobalValue::ExternalLinkage, buf, Compiler->getLLVMModule()); } else { - stub = Function::Create((virt || special)? getVirtualType() : getStaticType(), - GlobalValue::ExternalLinkage, "", - Compiler->getLLVMModule()); + stub = Function::Create( + FTy, GlobalValue::ExternalLinkage, "", Compiler->getLLVMModule()); } LLVMContext& context = Compiler->getLLVMModule()->getContext(); @@ -568,7 +598,14 @@ } stub->setGC("vmkit"); - + + if (virt) { + Compiler->virtualStubs[FTy] = stub; + } else if (special) { + Compiler->specialStubs[FTy] = stub; + } else { + Compiler->staticStubs[FTy] = stub; + } return stub; } Modified: vmkit/trunk/lib/J3/VMCore/JavaTypes.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaTypes.cpp?rev=137038&r1=137037&r2=137038&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaTypes.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/JavaTypes.cpp Sun Aug 7 10:37:46 2011 @@ -170,37 +170,18 @@ } void Signdef::nativeName(char* ptr, const char* ext) const { - sint32 i = 0; - while (i < keyName->size) { - char c = keyName->elements[i++]; - if (c == I_PARG) { - ptr[0] = '_'; - ptr[1] = '_'; - ptr += 2; - } else if (c == '/') { - ptr[0] = '_'; - ++ptr; - } else if (c == '_') { - ptr[0] = '_'; - ptr[1] = '1'; - ptr += 2; - } else if (c == I_END_REF) { - ptr[0] = '_'; - ptr[1] = '2'; - ptr += 2; - } else if (c == I_TAB) { - ptr[0] = '_'; - ptr[1] = '3'; - ptr += 2; - } else if (c == I_PARD) { - ptr[0] = '_'; - ptr[1] = '_'; - ptr += 2; - } else { - ptr[0] = c; - ++ptr; - } + ptr[0] = '_'; + ptr[1] = '_'; + ptr += 2; + for (uint32_t i = 0; i < nbArguments; i++) { + ptr[0] = arguments[i + 1]->getId(); + ++ptr; } + ptr[0] = '_'; + ptr[1] = '_'; + ptr += 2; + ptr[0] = arguments[0]->getId(); + ++ptr; assert(ext && "I need an extension"); memcpy(ptr, ext, strlen(ext) + 1); Modified: vmkit/trunk/lib/J3/VMCore/JavaTypes.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaTypes.h?rev=137038&r1=137037&r2=137038&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/JavaTypes.h (original) +++ vmkit/trunk/lib/J3/VMCore/JavaTypes.h Sun Aug 7 10:37:46 2011 @@ -141,6 +141,8 @@ const UTF8* getKey() const { return keyName; } + + virtual char getId() const = 0; virtual ~Typedef() {} }; @@ -152,6 +154,10 @@ char charId; public: + + virtual char getId() const { + return charId; + } virtual bool trace() const { return false; @@ -231,6 +237,10 @@ ArrayTypedef(const UTF8* name) { keyName = name; } + + virtual char getId() const { + return I_REF; + } }; class ObjectTypedef : public Typedef { @@ -254,6 +264,9 @@ return pseudoAssocClassName; } + virtual char getId() const { + return I_REF; + } }; Modified: vmkit/trunk/lib/Mvm/CommonThread/ObjectLocks.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommonThread/ObjectLocks.cpp?rev=137038&r1=137037&r2=137038&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/CommonThread/ObjectLocks.cpp (original) +++ vmkit/trunk/lib/Mvm/CommonThread/ObjectLocks.cpp Sun Aug 7 10:37:46 2011 @@ -86,10 +86,10 @@ void printDebugMessage(gc* object, LockSystem& table) { llvm_gcroot(object, 0); fprintf(stderr, - "WARNING: [%p] has been waiting really long for %p (header = %lx)\n", + "WARNING: [%p] has been waiting really long for %p (header = %p)\n", (void*)mvm::Thread::get(), (void*)object, - object->header); + (void*)object->header); FatLock* obj = table.getFatLockFromID(object->header); if (obj != NULL) { fprintf(stderr, From nicolas.geoffray at lip6.fr Wed Aug 10 14:34:42 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Wed, 10 Aug 2011 21:34:42 -0000 Subject: [vmkit-commits] [vmkit] r137251 - in /vmkit/trunk: include/j3/JavaAOTCompiler.h lib/J3/Compiler/JavaAOTCompiler.cpp lib/J3/Compiler/JavaJIT.cpp lib/J3/Compiler/LLVMInfo.cpp tools/precompiler/trainer/Makefile Message-ID: <20110810213442.B5C172A6C12C@llvm.org> Author: geoffray Date: Wed Aug 10 16:34:42 2011 New Revision: 137251 URL: http://llvm.org/viewvc/llvm-project?rev=137251&view=rev Log: Set Java methods to NoUnwind and NoInline, so that LLVM does not try to be clever. 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/LLVMInfo.cpp vmkit/trunk/tools/precompiler/trainer/Makefile Modified: vmkit/trunk/include/j3/JavaAOTCompiler.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/JavaAOTCompiler.h?rev=137251&r1=137250&r2=137251&view=diff ============================================================================== --- vmkit/trunk/include/j3/JavaAOTCompiler.h (original) +++ vmkit/trunk/include/j3/JavaAOTCompiler.h Wed Aug 10 16:34:42 2011 @@ -190,8 +190,6 @@ void CreateStaticInitializer(); - void setNoInline(Class* cl); - void printStats(); void compileFile(Jnjvm* vm, const char* name); Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=137251&r1=137250&r2=137251&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Wed Aug 10 16:34:42 2011 @@ -1987,24 +1987,6 @@ ReturnInst::Create(getLLVMContext(), currentBlock); } -void JavaAOTCompiler::setNoInline(Class* cl) { - for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) { - JavaMethod& meth = cl->virtualMethods[i]; - if (!isAbstract(meth.access)) { - Function* func = getMethod(&meth); - func->addFnAttr(Attribute::NoInline); - } - } - - for (uint32 i = 0; i < cl->nbStaticMethods; ++i) { - JavaMethod& meth = cl->staticMethods[i]; - if (!isAbstract(meth.access)) { - Function* func = getMethod(&meth); - func->addFnAttr(Attribute::NoInline); - } - } -} - void JavaAOTCompiler::makeVT(Class* cl) { JavaVirtualTable* VT = cl->virtualVT; @@ -2296,25 +2278,6 @@ M->getNativeClass(bootstrapLoader->upcalls->OfFloat); M->getNativeClass(bootstrapLoader->upcalls->OfLong); M->getNativeClass(bootstrapLoader->upcalls->OfDouble); - - // Also do not allow inling of some functions. -#define SET_INLINE(NAME) { \ - const UTF8* name = bootstrapLoader->asciizConstructUTF8(NAME); \ - Class* cl = (Class*)bootstrapLoader->lookupClass(name); \ - if (cl) M->setNoInline(cl); } - - SET_INLINE("java/util/concurrent/atomic/AtomicReferenceFieldUpdater") - SET_INLINE("java/util/concurrent/atomic/AtomicReferenceFieldUpdater" - "$AtomicReferenceFieldUpdaterImpl") - SET_INLINE("java/util/concurrent/atomic/AtomicIntegerFieldUpdater") - SET_INLINE("java/util/concurrent/atomic/AtomicIntegerFieldUpdater" - "$AtomicIntegerFieldUpdaterImpl") - SET_INLINE("java/util/concurrent/atomic/AtomicLongFieldUpdater") - SET_INLINE("java/util/concurrent/atomic/AtomicLongFieldUpdater" - "$CASUpdater") - SET_INLINE("java/util/concurrent/atomic/AtomicLongFieldUpdater" - "$LockedUpdater") -#undef SET_INLINE } M->CreateStaticInitializer(); @@ -2404,7 +2367,8 @@ e = loader->getClasses()->map.end(); i!= e; ++i) { AddInitializerToClass(getNativeClass(i->second), i->second); JavaVirtualTable* VT = i->second->virtualVT; - GlobalVariable* gv = dyn_cast(getVirtualTable(VT)->getOperand(0)); + GlobalVariable* gv = + dyn_cast(getVirtualTable(VT)->getOperand(0)); gv->setInitializer(CreateConstantFromVT(VT)); } Modified: vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp?rev=137251&r1=137250&r2=137251&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp Wed Aug 10 16:34:42 2011 @@ -1145,6 +1145,7 @@ const UTF8* name = compilingClass->ctpInfo->UTF8At(AR.AnnotationNameIndex); if (name->equals(TheCompiler->InlinePragma)) { + llvmFunction->removeFnAttr(Attribute::NoInline); llvmFunction->addFnAttr(Attribute::AlwaysInline); } else if (name->equals(TheCompiler->NoInlinePragma)) { llvmFunction->addFnAttr(Attribute::NoInline); Modified: vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp?rev=137251&r1=137250&r2=137251&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp Wed Aug 10 16:34:42 2011 @@ -172,6 +172,8 @@ } methodFunction->setGC("vmkit"); + methodFunction->addFnAttr(Attribute::NoInline); + methodFunction->addFnAttr(Attribute::NoUnwind); Compiler->functions.insert(std::make_pair(methodFunction, methodDef)); if (!Compiler->isStaticCompiling() && methodDef->code) { @@ -394,6 +396,8 @@ } res->setGC("vmkit"); + res->addFnAttr(Attribute::NoInline); + res->addFnAttr(Attribute::NoUnwind); if (virt) { Compiler->virtualBufs[FTy] = res; @@ -482,6 +486,8 @@ } res->setGC("vmkit"); + res->addFnAttr(Attribute::NoInline); + res->addFnAttr(Attribute::NoUnwind); if (virt) { Compiler->virtualAPs[FTy] = res; @@ -598,7 +604,9 @@ } stub->setGC("vmkit"); - + stub->addFnAttr(Attribute::NoInline); + stub->addFnAttr(Attribute::NoUnwind); + if (virt) { Compiler->virtualStubs[FTy] = stub; } else if (special) { Modified: vmkit/trunk/tools/precompiler/trainer/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/precompiler/trainer/Makefile?rev=137251&r1=137250&r2=137251&view=diff ============================================================================== --- vmkit/trunk/tools/precompiler/trainer/Makefile (original) +++ vmkit/trunk/tools/precompiler/trainer/Makefile Wed Aug 10 16:34:42 2011 @@ -31,7 +31,7 @@ Precompiled.bc: HelloWorld.class $(LibDir)/StaticGCPass$(SHLIBEXT) $(LibDir)/StaticGCPrinter$(SHLIBEXT) generated.bc $(Echo) "Building precompiled bootstrap code" $(Verb) $(MKDIR) $(ObjDir) - $(Verb) $(LLC) -disable-branch-fold -disable-cfi -O0 -fast-isel=false -load=$(LibDir)/StaticGCPrinter$(SHLIBEXT) -disable-fp-elim generated.bc -o $(ObjDir)/Precompiled.s + $(Verb) $(LLC) -disable-branch-fold -disable-cfi -disable-debug-info-print -O0 -fast-isel=false -load=$(LibDir)/StaticGCPrinter$(SHLIBEXT) -disable-fp-elim generated.bc -o $(ObjDir)/Precompiled.s $(Verb) $(CC) -c $(ObjDir)/Precompiled.s -o $(ObjDir)/Precompiled.o $(Verb) $(Archive) $(LibDir)/libPrecompiled.a $(ObjDir)/Precompiled.o $(Verb) $(Ranlib) $(LibDir)/libPrecompiled.a From nicolas.geoffray at lip6.fr Sat Aug 13 03:28:18 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 13 Aug 2011 10:28:18 -0000 Subject: [vmkit-commits] [vmkit] r137553 - /vmkit/trunk/tools/precompiler/trainer/Makefile Message-ID: <20110813102818.48C4B2A6C12C@llvm.org> Author: geoffray Date: Sat Aug 13 05:28:18 2011 New Revision: 137553 URL: http://llvm.org/viewvc/llvm-project?rev=137553&view=rev Log: LLC can now optimize the precompiled code. Modified: vmkit/trunk/tools/precompiler/trainer/Makefile Modified: vmkit/trunk/tools/precompiler/trainer/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/precompiler/trainer/Makefile?rev=137553&r1=137552&r2=137553&view=diff ============================================================================== --- vmkit/trunk/tools/precompiler/trainer/Makefile (original) +++ vmkit/trunk/tools/precompiler/trainer/Makefile Sat Aug 13 05:28:18 2011 @@ -31,7 +31,7 @@ Precompiled.bc: HelloWorld.class $(LibDir)/StaticGCPass$(SHLIBEXT) $(LibDir)/StaticGCPrinter$(SHLIBEXT) generated.bc $(Echo) "Building precompiled bootstrap code" $(Verb) $(MKDIR) $(ObjDir) - $(Verb) $(LLC) -disable-branch-fold -disable-cfi -disable-debug-info-print -O0 -fast-isel=false -load=$(LibDir)/StaticGCPrinter$(SHLIBEXT) -disable-fp-elim generated.bc -o $(ObjDir)/Precompiled.s + $(Verb) $(LLC) -disable-branch-fold -disable-cfi -disable-debug-info-print -disable-fp-elim -O3 -load=$(LibDir)/StaticGCPrinter$(SHLIBEXT) generated.bc -o $(ObjDir)/Precompiled.s $(Verb) $(CC) -c $(ObjDir)/Precompiled.s -o $(ObjDir)/Precompiled.o $(Verb) $(Archive) $(LibDir)/libPrecompiled.a $(ObjDir)/Precompiled.o $(Verb) $(Ranlib) $(LibDir)/libPrecompiled.a From nicolas.geoffray at lip6.fr Sat Aug 13 07:27:39 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sat, 13 Aug 2011 14:27:39 -0000 Subject: [vmkit-commits] [vmkit] r137555 - in /vmkit/trunk/mmtk/magic: LowerMagic.cpp Makefile Message-ID: <20110813142739.4F4192A6C12C@llvm.org> Author: geoffray Date: Sat Aug 13 09:27:39 2011 New Revision: 137555 URL: http://llvm.org/viewvc/llvm-project?rev=137555&view=rev Log: Remove warnings. Modified: vmkit/trunk/mmtk/magic/LowerMagic.cpp vmkit/trunk/mmtk/magic/Makefile Modified: vmkit/trunk/mmtk/magic/LowerMagic.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/magic/LowerMagic.cpp?rev=137555&r1=137554&r2=137555&view=diff ============================================================================== --- vmkit/trunk/mmtk/magic/LowerMagic.cpp (original) +++ vmkit/trunk/mmtk/magic/LowerMagic.cpp Sat Aug 13 09:27:39 2011 @@ -40,10 +40,10 @@ static const char* AddressZeroMethod = 0; static const char* AddressIsZeroMethod; static const char* AddressMaxMethod; -static const char* AddressIsMaxMethod; -static const char* AddressFromIntSignExtendMethod; +//static const char* AddressIsMaxMethod; +//static const char* AddressFromIntSignExtendMethod; static const char* AddressFromIntZeroExtendMethod; -static const char* AddressFromLongMethod; +//static const char* AddressFromLongMethod; static const char* AddressToObjectReferenceMethod; static const char* AddressToIntMethod; static const char* AddressToLongMethod; @@ -52,7 +52,7 @@ static const char* AddressPlusOffsetMethod; static const char* AddressPlusExtentMethod; static const char* AddressMinusIntMethod; -static const char* AddressMinusOffsetMethod; +//static const char* AddressMinusOffsetMethod; static const char* AddressMinusExtentMethod; static const char* AddressDiffMethod; static const char* AddressLTMethod; @@ -61,63 +61,63 @@ static const char* AddressGEMethod; static const char* AddressEQMethod; static const char* AddressNEMethod; -static const char* AddressPrefetchMethod; +//static const char* AddressPrefetchMethod; static const char* AddressLoadObjectReferenceMethod; static const char* AddressLoadObjectReferenceAtOffsetMethod; static const char* AddressLoadByteMethod; static const char* AddressLoadByteAtOffsetMethod; -static const char* AddressLoadCharMethod; -static const char* AddressLoadCharAtOffsetMethod; +//static const char* AddressLoadCharMethod; +//static const char* AddressLoadCharAtOffsetMethod; static const char* AddressLoadShortMethod; static const char* AddressLoadShortAtOffsetMethod; -static const char* AddressLoadFloatMethod; -static const char* AddressLoadFloatAtOffsetMethod; +//static const char* AddressLoadFloatMethod; +//static const char* AddressLoadFloatAtOffsetMethod; static const char* AddressLoadIntMethod; static const char* AddressLoadIntAtOffsetMethod; -static const char* AddressLoadLongMethod; -static const char* AddressLoadLongAtOffsetMethod; -static const char* AddressLoadDoubleMethod; -static const char* AddressLoadDoubleAtOffsetMethod; +//static const char* AddressLoadLongMethod; +//static const char* AddressLoadLongAtOffsetMethod; +//static const char* AddressLoadDoubleMethod; +//static const char* AddressLoadDoubleAtOffsetMethod; static const char* AddressLoadAddressMethod; static const char* AddressLoadAddressAtOffsetMethod; static const char* AddressLoadWordMethod; static const char* AddressLoadWordAtOffsetMethod; static const char* AddressStoreObjectReferenceMethod; -static const char* AddressStoreObjectReferenceAtOffsetMethod; +//static const char* AddressStoreObjectReferenceAtOffsetMethod; static const char* AddressStoreAddressMethod; static const char* AddressStoreAddressAtOffsetMethod; -static const char* AddressStoreFloatMethod; -static const char* AddressStoreFloatAtOffsetMethod; +//static const char* AddressStoreFloatMethod; +//static const char* AddressStoreFloatAtOffsetMethod; static const char* AddressStoreWordMethod; static const char* AddressStoreWordAtOffsetMethod; static const char* AddressStoreByteMethod; static const char* AddressStoreByteAtOffsetMethod; static const char* AddressStoreIntMethod; -static const char* AddressStoreIntAtOffsetMethod; -static const char* AddressStoreDoubleMethod; -static const char* AddressStoreDoubleAtOffsetMethod; -static const char* AddressStoreLongMethod; -static const char* AddressStoreLongAtOffsetMethod; -static const char* AddressStoreCharMethod; -static const char* AddressStoreCharAtOffsetMethod; +//static const char* AddressStoreIntAtOffsetMethod; +//static const char* AddressStoreDoubleMethod; +//static const char* AddressStoreDoubleAtOffsetMethod; +//static const char* AddressStoreLongMethod; +//static const char* AddressStoreLongAtOffsetMethod; +//static const char* AddressStoreCharMethod; +//static const char* AddressStoreCharAtOffsetMethod; static const char* AddressStoreShortMethod; static const char* AddressStoreShortAtOffsetMethod; static const char* AddressPrepareWordMethod; static const char* AddressPrepareWordAtOffsetMethod; -static const char* AddressPrepareObjectReferenceMethod; -static const char* AddressPrepareObjectReferenceAtOffsetMethod; -static const char* AddressPrepareAddressMethod; -static const char* AddressPrepareAddressAtOffsetMethod; -static const char* AddressPrepareIntMethod; -static const char* AddressPrepareIntAtOffsetMethod; -static const char* AddressAttemptIntMethod; -static const char* AddressAttemptIntAtOffsetMethod; +//static const char* AddressPrepareObjectReferenceMethod; +//static const char* AddressPrepareObjectReferenceAtOffsetMethod; +//static const char* AddressPrepareAddressMethod; +//static const char* AddressPrepareAddressAtOffsetMethod; +//static const char* AddressPrepareIntMethod; +//static const char* AddressPrepareIntAtOffsetMethod; +//static const char* AddressAttemptIntMethod; +//static const char* AddressAttemptIntAtOffsetMethod; static const char* AddressAttemptWordMethod; static const char* AddressAttemptWordAtOffsetMethod; -static const char* AddressAttemptObjectReferenceMethod; -static const char* AddressAttemptObjectReferenceAtOffsetMethod; -static const char* AddressAttemptAddressMethod; -static const char* AddressAttemptAddressAtOffsetMethod; +//static const char* AddressAttemptObjectReferenceMethod; +//static const char* AddressAttemptObjectReferenceAtOffsetMethod; +//static const char* AddressAttemptAddressMethod; +//static const char* AddressAttemptAddressAtOffsetMethod; static const char* ExtentClass = "JnJVM_org_vmmagic_unboxed_Extent_"; static const char* ExtentToWordMethod = 0; @@ -133,9 +133,9 @@ static const char* ExtentMinusIntMethod; static const char* ExtentMinusExtentMethod; static const char* ExtentLTMethod; -static const char* ExtentLEMethod; +//static const char* ExtentLEMethod; static const char* ExtentGTMethod; -static const char* ExtentGEMethod; +//static const char* ExtentGEMethod; static const char* ExtentEQMethod; static const char* ExtentNEMethod; @@ -151,7 +151,7 @@ static const char* OffsetFromIntSignExtendMethod = 0; static const char* OffsetFromIntZeroExtendMethod; static const char* OffsetZeroMethod; -static const char* OffsetMaxMethod; +//static const char* OffsetMaxMethod; static const char* OffsetToIntMethod; static const char* OffsetToLongMethod; static const char* OffsetToWordMethod; @@ -159,18 +159,18 @@ static const char* OffsetMinusIntMethod; static const char* OffsetMinusOffsetMethod; static const char* OffsetEQMethod; -static const char* OffsetNEMethod; +//static const char* OffsetNEMethod; static const char* OffsetSLTMethod; static const char* OffsetSLEMethod; static const char* OffsetSGTMethod; static const char* OffsetSGEMethod; static const char* OffsetIsZeroMethod; -static const char* OffsetIsMaxMethod; +//static const char* OffsetIsMaxMethod; static const char* WordClass = "JnJVM_org_vmmagic_unboxed_Word_"; static const char* WordFromIntSignExtendMethod = 0; static const char* WordFromIntZeroExtendMethod; -static const char* WordFromLongMethod; +//static const char* WordFromLongMethod; static const char* WordZeroMethod; static const char* WordOneMethod; static const char* WordMaxMethod; @@ -180,13 +180,13 @@ static const char* WordToOffsetMethod; static const char* WordToExtentMethod; static const char* WordPlusWordMethod; -static const char* WordPlusOffsetMethod; -static const char* WordPlusExtentMethod; +//static const char* WordPlusOffsetMethod; +//static const char* WordPlusExtentMethod; static const char* WordMinusWordMethod; -static const char* WordMinusOffsetMethod; +//static const char* WordMinusOffsetMethod; static const char* WordMinusExtentMethod; static const char* WordIsZeroMethod; -static const char* WordIsMaxMethod; +//static const char* WordIsMaxMethod; static const char* WordLTMethod; static const char* WordLEMethod; static const char* WordGTMethod; @@ -199,7 +199,7 @@ static const char* WordXorMethod; static const char* WordLshMethod; static const char* WordRshlMethod; -static const char* WordRshaMethod; +//static const char* WordRshaMethod; static Function* CASPtr; static Function* CASInt; Modified: vmkit/trunk/mmtk/magic/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/magic/Makefile?rev=137555&r1=137554&r2=137555&view=diff ============================================================================== --- vmkit/trunk/mmtk/magic/Makefile (original) +++ vmkit/trunk/mmtk/magic/Makefile Sat Aug 13 09:27:39 2011 @@ -10,7 +10,6 @@ LEVEL = ../.. LIBRARYNAME = MMTKMagic LOADABLE_MODULE = 1 -USEDLIBS = include $(LEVEL)/Makefile.common From nicolas.geoffray at lip6.fr Sun Aug 14 08:39:50 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Sun, 14 Aug 2011 15:39:50 -0000 Subject: [vmkit-commits] [vmkit] r137586 - in /vmkit/trunk: lib/J3/LLVMRuntime/runtime-mmtk-thread.ll lib/Mvm/MMTk/MutatorThread.h mmtk/java/src/org/j3/bindings/Bindings.java mmtk/mmtk-alloc/Selected.cpp mmtk/mmtk-j3/Collection.cpp Message-ID: <20110814153950.3EB162A6C12F@llvm.org> Author: geoffray Date: Sun Aug 14 10:39:50 2011 New Revision: 137586 URL: http://llvm.org/viewvc/llvm-project?rev=137586&view=rev Log: Truely support generational GC by allowing full GC heaps to happen. Modified: vmkit/trunk/lib/J3/LLVMRuntime/runtime-mmtk-thread.ll vmkit/trunk/lib/Mvm/MMTk/MutatorThread.h vmkit/trunk/mmtk/java/src/org/j3/bindings/Bindings.java vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp vmkit/trunk/mmtk/mmtk-j3/Collection.cpp Modified: vmkit/trunk/lib/J3/LLVMRuntime/runtime-mmtk-thread.ll URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/LLVMRuntime/runtime-mmtk-thread.ll?rev=137586&r1=137585&r2=137586&view=diff ============================================================================== --- vmkit/trunk/lib/J3/LLVMRuntime/runtime-mmtk-thread.ll (original) +++ vmkit/trunk/lib/J3/LLVMRuntime/runtime-mmtk-thread.ll Sun Aug 14 10:39:50 2011 @@ -4,4 +4,5 @@ ;;; field 1: allocator ;;; field 2: MutatorContext ;;; field 3: realRoutine -%MutatorThread = type { %Thread, %ThreadAllocator, i8*, i8* } +;;; field 4: CollectionAttempts +%MutatorThread = type { %Thread, %ThreadAllocator, i8*, i8*, i32 } Modified: vmkit/trunk/lib/Mvm/MMTk/MutatorThread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/MMTk/MutatorThread.h?rev=137586&r1=137585&r2=137586&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/MMTk/MutatorThread.h (original) +++ vmkit/trunk/lib/Mvm/MMTk/MutatorThread.h Sun Aug 14 10:39:50 2011 @@ -20,6 +20,7 @@ public: MutatorThread() : mvm::Thread() { MutatorContext = 0; + CollectionAttempts = 0; } mvm::ThreadAllocator Allocator; uintptr_t MutatorContext; @@ -28,6 +29,8 @@ /// void (*realRoutine)(mvm::Thread*); + uint32_t CollectionAttempts; + static void init(Thread* _th); static MutatorThread* get() { Modified: vmkit/trunk/mmtk/java/src/org/j3/bindings/Bindings.java URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/java/src/org/j3/bindings/Bindings.java?rev=137586&r1=137585&r2=137586&view=diff ============================================================================== --- vmkit/trunk/mmtk/java/src/org/j3/bindings/Bindings.java (original) +++ vmkit/trunk/mmtk/java/src/org/j3/bindings/Bindings.java Sun Aug 14 10:39:50 2011 @@ -16,6 +16,10 @@ import org.mmtk.plan.TransitiveClosure; import org.mmtk.utility.heap.HeapGrowthManager; import org.mmtk.utility.Constants; +import org.mmtk.utility.Log; +import org.mmtk.utility.options.Options; +import org.mmtk.vm.Collection; +import org.mmtk.vm.VM; import org.vmmagic.pragma.Inline; import org.vmmagic.unboxed.Address; import org.vmmagic.unboxed.Extent; @@ -164,4 +168,37 @@ private static boolean needsNonHeapWriteBarrier() { return Selected.Constraints.get().needsObjectReferenceNonHeapWriteBarrier(); } + + @Inline + private static void collect(int why) { + boolean userTriggered = why == Collection.EXTERNAL_GC_TRIGGER; + boolean internalPhaseTriggered = why == Collection.INTERNAL_PHASE_GC_TRIGGER; + + if (Options.verbose.getValue() == 1 || Options.verbose.getValue() == 2) { + if (userTriggered) { + Log.write("[Forced GC]"); + } else if (internalPhaseTriggered) { + Log.write("[Phase GC]"); + } + } + + Plan.setCollectionTriggered(); + Plan.setCollectionTrigger(why); + + long startTime = VM.statistics.nanoTime(); + Selected.Collector.staticCollect(); + long elapsedTime = VM.statistics.nanoTime() - startTime; + + HeapGrowthManager.recordGCTime(((double)elapsedTime) / 1000000); + + if (Selected.Plan.get().lastCollectionFullHeap() && !internalPhaseTriggered) { + if (Options.variableSizeHeap.getValue() && !userTriggered) { + // Don't consider changing the heap size if gc was forced by System.gc() + HeapGrowthManager.considerHeapSize(); + } + HeapGrowthManager.reset(); + } + + Plan.collectionComplete(); + } } Modified: vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp?rev=137586&r1=137585&r2=137586&view=diff ============================================================================== --- vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp (original) +++ vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp Sun Aug 14 10:39:50 2011 @@ -157,7 +157,7 @@ } void Collector::initialise() { - JnJVM_org_j3_bindings_Bindings_boot__Lorg_vmmagic_unboxed_Extent_2Lorg_vmmagic_unboxed_Extent_2(128 * 1024 * 1024, 1024 * 1024 * 1024); + JnJVM_org_j3_bindings_Bindings_boot__Lorg_vmmagic_unboxed_Extent_2Lorg_vmmagic_unboxed_Extent_2(20 * 1024 * 1024, 100 * 1024 * 1024); } extern "C" void* MMTkMutatorAllocate(uint32_t size, VirtualTable* VT) { Modified: vmkit/trunk/mmtk/mmtk-j3/Collection.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/mmtk-j3/Collection.cpp?rev=137586&r1=137585&r2=137586&view=diff ============================================================================== --- vmkit/trunk/mmtk/mmtk-j3/Collection.cpp (original) +++ vmkit/trunk/mmtk/mmtk-j3/Collection.cpp Sun Aug 14 10:39:50 2011 @@ -14,25 +14,20 @@ namespace mmtk { -extern "C" void JnJVM_org_mmtk_plan_Plan_setCollectionTriggered__(); -extern "C" void JnJVM_org_j3_config_Selected_00024Collector_staticCollect__(); -extern "C" void JnJVM_org_mmtk_plan_Plan_collectionComplete__(); -extern "C" uint8_t JnJVM_org_mmtk_utility_heap_HeapGrowthManager_considerHeapSize__(); -extern "C" void JnJVM_org_mmtk_utility_heap_HeapGrowthManager_reset__(); -extern "C" int64_t Java_org_j3_mmtk_Statistics_nanoTime__ (); -extern "C" void JnJVM_org_mmtk_utility_heap_HeapGrowthManager_recordGCTime__D(double); - extern "C" bool Java_org_j3_mmtk_Collection_isEmergencyAllocation__ (MMTkObject* C) { // TODO: emergency when OOM. return false; } extern "C" void Java_org_j3_mmtk_Collection_reportAllocationSuccess__ (MMTkObject* C) { - // TODO: clear internal data. + mvm::MutatorThread::get()->CollectionAttempts = 0; } +extern "C" void JnJVM_org_j3_bindings_Bindings_collect__I(int why); + extern "C" void Java_org_j3_mmtk_Collection_triggerCollection__I (MMTkObject* C, int why) { - mvm::Thread* th = mvm::Thread::get(); + mvm::MutatorThread* th = mvm::MutatorThread::get(); + if (why > 2) th->CollectionAttempts++; // Verify that another collection is not happening. th->MyVM->rendezvous.startRV(); @@ -43,34 +38,8 @@ } else { th->MyVM->startCollection(); th->MyVM->rendezvous.synchronize(); - - JnJVM_org_mmtk_plan_Plan_setCollectionTriggered__(); - - // Record the starting time - int64_t startTime = Java_org_j3_mmtk_Statistics_nanoTime__(); - - // Collect! - JnJVM_org_j3_config_Selected_00024Collector_staticCollect__(); - - // Record the time to GC. - int64_t elapsedTime = Java_org_j3_mmtk_Statistics_nanoTime__() - startTime; - - JnJVM_org_mmtk_utility_heap_HeapGrowthManager_recordGCTime__D(((double)elapsedTime) / 1000000); - // 2 means called by System.gc(); - if (why != 2) - JnJVM_org_mmtk_utility_heap_HeapGrowthManager_considerHeapSize__(); - - JnJVM_org_mmtk_utility_heap_HeapGrowthManager_reset__(); - - JnJVM_org_mmtk_plan_Plan_collectionComplete__(); - - if (mvm::Collector::verbose > 0) { - static int collectionNum = 1; - if (why == 2) fprintf(stderr, "[Forced] "); - fprintf(stderr, "Collection %d finished in %lld ms.\n", collectionNum++, - elapsedTime / 1000000); - } + JnJVM_org_j3_bindings_Bindings_collect__I(why); th->MyVM->rendezvous.finishRV(); th->MyVM->endCollection(); @@ -89,7 +58,18 @@ } extern "C" int Java_org_j3_mmtk_Collection_maximumCollectionAttempt__ (MMTkObject* C) { - return 0; + mvm::MutatorThread* th = mvm::MutatorThread::get(); + mvm::MutatorThread* tcur = th; + + uint32_t max = 0; + do { + if (tcur->CollectionAttempts > max) { + max = tcur->CollectionAttempts; + } + tcur = (mvm::MutatorThread*)tcur->next(); + } while (tcur != th); + + return max; } extern "C" void Java_org_j3_mmtk_Collection_prepareCollector__Lorg_mmtk_plan_CollectorContext_2 (MMTkObject* C, MMTkObject* CC) { From nicolas.geoffray at lip6.fr Thu Aug 18 13:21:18 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Thu, 18 Aug 2011 20:21:18 -0000 Subject: [vmkit-commits] [vmkit] r137977 - in /vmkit/trunk: Makefile.rules tools/vmjc/Makefile Message-ID: <20110818202118.BD3542A6C12C@llvm.org> Author: geoffray Date: Thu Aug 18 15:21:18 2011 New Revision: 137977 URL: http://llvm.org/viewvc/llvm-project?rev=137977&view=rev Log: - Don't print debug info for mmtk - Don't link vmjc with unused libraries. Modified: vmkit/trunk/Makefile.rules vmkit/trunk/tools/vmjc/Makefile Modified: vmkit/trunk/Makefile.rules URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/Makefile.rules?rev=137977&r1=137976&r2=137977&view=diff ============================================================================== --- vmkit/trunk/Makefile.rules (original) +++ vmkit/trunk/Makefile.rules Thu Aug 18 15:21:18 2011 @@ -76,7 +76,7 @@ $(Verb) $(LLVMLD) -r -o $(LibDir)/FinalMMTk.bc $(LibDir)/MMTKAlloc.bc $(JARNAME)-optimized.bc $(LibDir)/MMTKRuntime.bc $(Verb) $(LOPT) $(LibDir)/FinalMMTk.bc -load=$(LibDir)/StaticGCPass$(SHLIBEXT) -std-compile-opts -StaticGCPass -o $(LibDir)/FinalMMTk.bc $(Verb) $(MKDIR) $(ObjDir) - $(Verb) $(LLC) -disable-fp-elim -disable-cfi -load=$(LibDir)/StaticGCPrinter$(SHLIBEXT) $(LibDir)/FinalMMTk.bc -o $(ObjDir)/FinalMMTk.s + $(Verb) $(LLC) -disable-fp-elim -disable-cfi -disable-debug-info-print -load=$(LibDir)/StaticGCPrinter$(SHLIBEXT) $(LibDir)/FinalMMTk.bc -o $(ObjDir)/FinalMMTk.s $(Verb) $(LLVMCC) -c $(ObjDir)/FinalMMTk.s -o $(ObjDir)/FinalMMTk.o $(Verb) $(Archive) $(LibDir)/libFinalMMTk.a $(ObjDir)/FinalMMTk.o $(Verb) $(Ranlib) $(LibDir)/libFinalMMTk.a Modified: vmkit/trunk/tools/vmjc/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/vmjc/Makefile?rev=137977&r1=137976&r2=137977&view=diff ============================================================================== --- vmkit/trunk/tools/vmjc/Makefile (original) +++ vmkit/trunk/tools/vmjc/Makefile Thu Aug 18 15:21:18 2011 @@ -14,6 +14,6 @@ TOOLNAME = vmjc USEDLIBS = J3.a Classpath.a J3.a J3Compiler.a Mvm.a MvmCompiler.a MMTk.a CommonThread.a -LINK_COMPONENTS = jit nativecodegen scalaropts instrumentation ipa ipo bitwriter bitreader asmparser linker +LINK_COMPONENTS = jit nativecodegen scalaropts instrumentation ipa ipo bitwriter include $(LEVEL)/Makefile.common From nicolas.geoffray at lip6.fr Mon Aug 22 13:09:06 2011 From: nicolas.geoffray at lip6.fr (Nicolas Geoffray) Date: Mon, 22 Aug 2011 20:09:06 -0000 Subject: [vmkit-commits] [vmkit] r138266 - in /vmkit/trunk: lib/J3/Compiler/JavaJITCompiler.cpp lib/J3/VMCore/Jnjvm.cpp lib/Mvm/MMTk/MvmGC.cpp lib/Mvm/MMTk/MvmGC.h mmtk/java/src/org/j3/bindings/Bindings.java mmtk/java/src/org/j3/options/OptionSet.java mmtk/magic/LowerJavaRT.cpp mmtk/mmtk-alloc/Selected.cpp mmtk/mmtk-j3/MMTkObject.h mmtk/mmtk-j3/RuntimeHelpers.cpp mmtk/mmtk-j3/VM.cpp tools/j3/Main.cpp tools/precompiler/Precompiler.cpp tools/vmjc/vmjc.cpp Message-ID: <20110822200906.EDE1E2A6C12C@llvm.org> Author: geoffray Date: Mon Aug 22 15:09:06 2011 New Revision: 138266 URL: http://llvm.org/viewvc/llvm-project?rev=138266&view=rev Log: Parse command line flags for gc. Modified: vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp vmkit/trunk/lib/Mvm/MMTk/MvmGC.cpp vmkit/trunk/lib/Mvm/MMTk/MvmGC.h vmkit/trunk/mmtk/java/src/org/j3/bindings/Bindings.java vmkit/trunk/mmtk/java/src/org/j3/options/OptionSet.java vmkit/trunk/mmtk/magic/LowerJavaRT.cpp vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp vmkit/trunk/mmtk/mmtk-j3/MMTkObject.h vmkit/trunk/mmtk/mmtk-j3/RuntimeHelpers.cpp vmkit/trunk/mmtk/mmtk-j3/VM.cpp vmkit/trunk/tools/j3/Main.cpp vmkit/trunk/tools/precompiler/Precompiler.cpp vmkit/trunk/tools/vmjc/vmjc.cpp Modified: vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp?rev=138266&r1=138265&r2=138266&view=diff ============================================================================== --- vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp (original) +++ vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp Mon Aug 22 15:09:06 2011 @@ -345,7 +345,7 @@ llvm::llvm_shutdown_obj X; mvm::MvmModule::initialise(); - mvm::Collector::initialise(); + mvm::Collector::initialise(argc, argv); mvm::ThreadAllocator allocator; char** newArgv = (char**)allocator.Allocate((argc + 1) * sizeof(char*)); Modified: vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp?rev=138266&r1=138265&r2=138266&view=diff ============================================================================== --- vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp (original) +++ vmkit/trunk/lib/J3/VMCore/Jnjvm.cpp Mon Aug 22 15:09:06 2011 @@ -1423,7 +1423,7 @@ // Helper function to run J3 without JIT. extern "C" int StartJnjvmWithoutJIT(int argc, char** argv, char* mainClass) { - mvm::Collector::initialise(); + mvm::Collector::initialise(argc, argv); mvm::ThreadAllocator allocator; char** newArgv = (char**)allocator.Allocate((argc + 1) * sizeof(char*)); Modified: vmkit/trunk/lib/Mvm/MMTk/MvmGC.cpp URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/MMTk/MvmGC.cpp?rev=138266&r1=138265&r2=138266&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/MMTk/MvmGC.cpp (original) +++ vmkit/trunk/lib/Mvm/MMTk/MvmGC.cpp Mon Aug 22 15:09:06 2011 @@ -143,7 +143,7 @@ // Do nothing. } -void Collector::initialise() { +void Collector::initialise(int argc, char** argv) { } bool Collector::needsWriteBarrier() { Modified: vmkit/trunk/lib/Mvm/MMTk/MvmGC.h URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/MMTk/MvmGC.h?rev=138266&r1=138265&r2=138266&view=diff ============================================================================== --- vmkit/trunk/lib/Mvm/MMTk/MvmGC.h (original) +++ vmkit/trunk/lib/Mvm/MMTk/MvmGC.h Mon Aug 22 15:09:06 2011 @@ -84,7 +84,7 @@ static void collect(); - static void initialise(); + static void initialise(int argc, char** argv); static int getMaxMemory() { return 0; Modified: vmkit/trunk/mmtk/java/src/org/j3/bindings/Bindings.java URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/java/src/org/j3/bindings/Bindings.java?rev=138266&r1=138265&r2=138266&view=diff ============================================================================== --- vmkit/trunk/mmtk/java/src/org/j3/bindings/Bindings.java (original) +++ vmkit/trunk/mmtk/java/src/org/j3/bindings/Bindings.java Mon Aug 22 15:09:06 2011 @@ -10,6 +10,7 @@ package org.j3.bindings; import org.j3.config.Selected; +import org.j3.options.OptionSet; import org.mmtk.plan.MutatorContext; import org.mmtk.plan.Plan; import org.mmtk.plan.TraceLocal; @@ -25,6 +26,17 @@ import org.vmmagic.unboxed.Extent; import org.vmmagic.unboxed.ObjectReference; +import org.vmutil.options.AddressOption; +import org.vmutil.options.BooleanOption; +import org.vmutil.options.EnumOption; +import org.vmutil.options.FloatOption; +import org.vmutil.options.IntOption; +import org.vmutil.options.MicrosecondsOption; +import org.vmutil.options.Option; +import org.vmutil.options.PagesOption; +import org.vmutil.options.StringOption; + + public final class Bindings { @Inline private static Address gcmalloc(int size, ObjectReference virtualTable) { @@ -94,7 +106,10 @@ } @Inline - private static void boot(Extent minSize, Extent maxSize) { + private static void boot(Extent minSize, Extent maxSize, String[] arguments) { + if (arguments != null) { + OptionSet.parseOptions(arguments); + } HeapGrowthManager.boot(minSize, maxSize); Plan plan = Selected.Plan.get(); plan.boot(); 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=138266&r1=138265&r2=138266&view=diff ============================================================================== --- vmkit/trunk/mmtk/java/src/org/j3/options/OptionSet.java (original) +++ vmkit/trunk/mmtk/java/src/org/j3/options/OptionSet.java Mon Aug 22 15:09:06 2011 @@ -124,7 +124,10 @@ * @param message The message associated with the warning. */ protected void warn(Option o, String message) { - VM.sysWriteln("WARNING: Option '" + o.getKey() + "' : " + message); + VM.sysWrite("WARNING: Option '"); + VM.sysWrite(o.getKey()); + VM.sysWrite("' : "); + VM.sysWriteln(message); } /** @@ -135,7 +138,11 @@ * @param message The error message associated with the failure. */ protected void fail(Option o, String message) { - VM.sysFail("ERROR: Option '" + o.getKey() + "' : " + message); + VM.sysWrite("Error: Option '"); + VM.sysWrite(o.getKey()); + VM.sysWrite("' : "); + VM.sysWriteln(message); + VM.sysFail(""); } /** @@ -158,4 +165,325 @@ protected Extent pagesToBytes(int pages) { return Word.fromIntZeroExtend(pages).lsh(Constants.LOG_BYTES_IN_PAGE).toExtent(); } + + public static void parseOptions(String[] args) { + for (int i = 0; i < args.length; i++) { + gc.parseOption(args[i]); + } + } + + private boolean parseOption(String arg) { + // First handle the "option commands" + if (arg.equals("help")) { + printHelp(); + return true; + } + if (arg.equals("printOptions")) { + printOptions(); + return true; + } + if (arg.length() == 0) { + printHelp(); + return true; + } + + // Required format of arg is 'name=value' + // Split into 'name' and 'value' strings + int split = arg.indexOf('='); + if (split == -1) { + VM.sysWrite("Illegal option specification: "); + VM.sysWrite(arg); + VM.sysWriteln(". Must be specified as a name-value pair in the form of option=value"); + return false; + } + + String name = arg.substring(0, split); + String value = arg.substring(split + 1); + + Option o = getOption(name); + + if (o == null) return false; + + switch (o.getType()) { + case Option.BOOLEAN_OPTION: + if (value.equals("true")) { + ((BooleanOption) o).setValue(true); + return true; + } else if (value.equals("false")) { + ((BooleanOption) o).setValue(false); + return true; + } + return false; + + case Option.INT_OPTION: { + int ival = parseInt(value, (IntOption) o); + ((IntOption) o).setValue(ival); + return true; + } + case Option.ADDRESS_OPTION: { + int ival = parseInt(value, null); + if (ival != 0) { + ((AddressOption) o).setValue(ival); + } else { + VM.sysWrite("Invalid value for "); + VM.sysWriteln(o.getName()); + } + return true; + } + case Option.FLOAT_OPTION: { + float fval = parseFloat(value, (FloatOption) o); + ((FloatOption) o).setValue(fval); + return true; + } + case Option.STRING_OPTION: + ((StringOption) o).setValue(value); + return true; + + case Option.ENUM_OPTION: + ((EnumOption) o).setValue(value); + return true; + + case Option.PAGES_OPTION: + long pval = parseMemorySize(o.getName(), name, "b", 1, arg, value); + if (pval < 0) return false; + ((PagesOption) o).setBytes(Extent.fromIntSignExtend((int)pval)); + return true; + + case Option.MICROSECONDS_OPTION: + int mval = parseInt(value, null); + ((MicrosecondsOption) o).setMicroseconds(mval); + return true; + } + + // None of the above tests matched, so this wasn't an option + return false; + } + + private static int parseNumber(String arg, int base, int start, int end) { + int value = 0; + for (int i = start; i < end; i++) { + value = value * base; + char c = arg.charAt(i); + switch (c) { + case '0': break; + case '1': value += 1; break; + case '2': value += 2; break; + case '3': value += 3; break; + case '4': value += 4; break; + case '5': value += 5; break; + case '6': value += 6; break; + case '7': value += 7; break; + case '8': value += 8; break; + case '9': value += 9; break; + default: + return -1; + } + } + return value; + } + + private static int parseInt(String arg, IntOption option) { + int base = 10; + int i = 0; + boolean isNegative = false; + if (arg.charAt(0) == '-') { + i++; + isNegative = true; + } else if (arg.length() > 1 && arg.charAt(0) == '0' && arg.charAt(1) == 'x') { + i += 2; + base = 16; + } + int value = parseNumber(arg, base, i, arg.length()); + if (value == -1) { + if (option != null) { + VM.sysWrite("Invalid value for "); + VM.sysWriteln(option.getName()); + return option.getValue(); + } else { + return 0; + } + } + return isNegative ? -value : value; + } + + private static float parseFloat(String arg, FloatOption option) { + boolean isNegative = false; + int start = 0; + if (arg.charAt(0) == '-') { + start++; + isNegative = true; + } + int dot = arg.indexOf('.'); + if (dot == -1) { + int value = parseNumber(arg, 10, start, arg.length()); + if (value == -1) { + VM.sysWrite("Invalid value for "); + VM.sysWriteln(option.getName()); + return option.getValue(); + } + return (float) (isNegative ? -value : value); + } else { + int value = parseNumber(arg, 10, start, dot); + if (value == -1) { + VM.sysWrite("Invalid value for "); + VM.sysWriteln(option.getName()); + return option.getValue(); + } + int intDecimal = parseNumber(arg, 10, dot + 1, arg.length()); + if (intDecimal == -1) { + VM.sysWrite("Invalid value for "); + VM.sysWriteln(option.getName()); + return option.getValue(); + } + double divide = 1; + for (int i = 1; i < arg.length() - dot; i++) { + divide *= 10; + } + double decimal = ((double) intDecimal) / divide; + return (float)(decimal + value); + } + } + + private static long parseMemorySize(String sizeName, + String sizeFlag, + String defaultFactor, + int roundTo, + String fullArg, + String subArg) { + return 0L; + } + + + private void printHelp() { + VM.sysWriteln("Commands"); + VM.sysWrite(prefix); + VM.sysWriteln("[:help]\t\t\tPrint brief description of arguments"); + VM.sysWrite(prefix); + VM.sysWriteln(":printOptions\t\tPrint the current values of options"); + VM.sysWriteln(); + + //Begin generated help messages + VM.sysWrite("Boolean Options ("); + VM.sysWrite(prefix); + VM.sysWrite(":