From gael.thomas at lip6.fr Tue Dec 3 04:34:42 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Tue, 03 Dec 2013 12:34:42 -0000 Subject: [vmkit-commits] [vmkit] r196271 - route getSymbolAddress to the appropriate symbol, resolution is not yet implemented Message-ID: <20131203123442.85AB92A6C029@llvm.org> Author: gthomas Date: Tue Dec 3 06:34:41 2013 New Revision: 196271 URL: http://llvm.org/viewvc/llvm-project?rev=196271&view=rev Log: route getSymbolAddress to the appropriate symbol, resolution is not yet implemented Added: vmkit/branches/mcjit/lib/j3/vm/j3symbol.cc Modified: vmkit/branches/mcjit/include/j3/j3classloader.h vmkit/branches/mcjit/include/j3/j3codegen.h vmkit/branches/mcjit/include/j3/j3symbol.h vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc Modified: vmkit/branches/mcjit/include/j3/j3classloader.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3classloader.h?rev=196271&r1=196270&r2=196271&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3classloader.h (original) +++ vmkit/branches/mcjit/include/j3/j3classloader.h Tue Dec 3 06:34:41 2013 @@ -4,6 +4,8 @@ #include #include +#include "llvm/ExecutionEngine/SectionMemoryManager.h" + #include "vmkit/allocator.h" #include "vmkit/names.h" @@ -31,7 +33,7 @@ namespace j3 { class J3Class; class J3Symbol; - class J3ClassLoader { + class J3ClassLoader : public llvm::SectionMemoryManager { struct J3MethodLess : public std::binary_function { bool operator()(const J3Method* lhs, const J3Method* rhs) const; }; @@ -63,6 +65,9 @@ namespace j3 { void wrongType(J3Class* from, const vmkit::Name* type); J3Type* getTypeInternal(J3Class* from, const vmkit::Name* type, uint32_t start, uint32_t* end); + + uint64_t getSymbolAddress(const std::string &Name); + protected: std::vector > nativeLibraries; @@ -71,7 +76,6 @@ namespace j3 { J3ClassLoader(J3* vm, J3ObjectHandle* javaClassLoader, vmkit::BumpAllocator* allocator); void addSymbol(const char* id, J3Symbol* symbol); - J3Symbol* getSymbol(const char* id); static void destroy(J3ClassLoader* loader); Modified: vmkit/branches/mcjit/include/j3/j3codegen.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3codegen.h?rev=196271&r1=196270&r2=196271&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3codegen.h (original) +++ vmkit/branches/mcjit/include/j3/j3codegen.h Tue Dec 3 06:34:41 2013 @@ -96,73 +96,73 @@ namespace j3 { bool isWide; - uint32_t wideReadU1(); - uint32_t wideReadS1(); + uint32_t wideReadU1(); + uint32_t wideReadS1(); - llvm::Value* nullCheck(llvm::Value* obj); + llvm::Value* nullCheck(llvm::Value* obj); - bool onEndPoint(); - llvm::BasicBlock* forwardBranch(const char* id, uint32_t pc, bool doAlloc, bool doPush); - void condBr(llvm::Value* op); + bool onEndPoint(); + llvm::BasicBlock* forwardBranch(const char* id, uint32_t pc, bool doAlloc, bool doPush); + void condBr(llvm::Value* op); - llvm::Value* flatten(llvm::Value* v, J3Type* type); - llvm::Value* unflatten(llvm::Value* v, J3Type* type); + llvm::Value* flatten(llvm::Value* v, J3Type* type); + llvm::Value* unflatten(llvm::Value* v, J3Type* type); - llvm::Value* handleToObject(llvm::Value* obj); - llvm::Value* javaClass(J3ObjectType* type); - llvm::Value* staticInstance(J3Class* cl); - llvm::Value* vt(J3Type* cl); - llvm::Value* vt(llvm::Value* obj); - void initialiseJ3Type(J3Type* cl); + llvm::Value* handleToObject(llvm::Value* obj); + llvm::Value* javaClass(J3ObjectType* type); + llvm::Value* staticInstance(J3Class* cl); + llvm::Value* vt(J3Type* cl); + llvm::Value* vt(llvm::Value* obj); + void initialiseJ3Type(J3Type* cl); - llvm::Value* isAssignableTo(llvm::Value* obj, J3Type* type); - void instanceof(llvm::Value* obj, J3Type* type); - void checkCast(llvm::Value* obj, J3Type* type); + llvm::Value* isAssignableTo(llvm::Value* obj, J3Type* type); + void instanceof(llvm::Value* obj, J3Type* type); + void checkCast(llvm::Value* obj, J3Type* type); - void floatToInteger(J3Type* from, J3Type* to); - void compareFP(bool isL); - void compareLong(); + void floatToInteger(J3Type* from, J3Type* to); + void compareFP(bool isL); + void compareLong(); - void get(llvm::Value* obj, J3Field* field); - void getField(uint32_t idx); - void getStatic(uint32_t idx); + void get(llvm::Value* obj, J3Field* field); + void getField(uint32_t idx); + void getStatic(uint32_t idx); - void put(llvm::Value* obj, llvm::Value* val, J3Field* field); - void putField(uint32_t idx); - void putStatic(uint32_t idx); + void put(llvm::Value* obj, llvm::Value* val, J3Field* field); + void putField(uint32_t idx); + void putStatic(uint32_t idx); - void invoke(J3Method* method, llvm::Value* func); - void invokeVirtual(uint32_t idx); - void invokeStatic(uint32_t idx); - void invokeSpecial(uint32_t idx); + void invoke(J3Method* method, llvm::Value* func); + void invokeVirtual(uint32_t idx); + void invokeStatic(uint32_t idx); + void invokeSpecial(uint32_t idx); - llvm::Value* arrayContent(J3Type* cType, llvm::Value* array, llvm::Value* idx); + llvm::Value* arrayContent(J3Type* cType, llvm::Value* array, llvm::Value* idx); - void arrayBoundCheck(llvm::Value* obj, llvm::Value* idx); - llvm::Value* arrayLength(llvm::Value* obj); - llvm::Value* arrayLengthPtr(llvm::Value* obj); - void arrayStore(J3Type* cType); - void arrayLoad(J3Type* cType); + void arrayBoundCheck(llvm::Value* obj, llvm::Value* idx); + llvm::Value* arrayLength(llvm::Value* obj); + llvm::Value* arrayLengthPtr(llvm::Value* obj); + void arrayStore(J3Type* cType); + void arrayLoad(J3Type* cType); - void newArray(uint8_t atype); - void newArray(J3ArrayClass* type); - void newObject(J3Class* cl); + void newArray(uint8_t atype); + void newArray(J3ArrayClass* type); + void newObject(J3Class* cl); - void ldc(uint32_t idx); + void ldc(uint32_t idx); - void translate(); + void translate(); - void initExceptionNode(J3ExceptionNode** pnode, uint32_t pc, J3ExceptionNode* node); - void addToExceptionNode(J3ExceptionNode* node, J3ExceptionEntry* entry); - void closeExceptionNode(J3ExceptionNode* node); + void initExceptionNode(J3ExceptionNode** pnode, uint32_t pc, J3ExceptionNode* node); + void addToExceptionNode(J3ExceptionNode* node, J3ExceptionEntry* entry); + void closeExceptionNode(J3ExceptionNode* node); - void generateJava(); - void generateNative(); + void generateJava(); + void generateNative(); - llvm::Value* buildString(const char* msg); + llvm::Value* buildString(const char* msg); - static void echoDebugEnter(uint32_t isLeave, const char* msg, ...); - static void echoDebugExecute(uint32_t level, const char* msg, ...); + static void echoDebugEnter(uint32_t isLeave, const char* msg, ...); + static void echoDebugExecute(uint32_t level, const char* msg, ...); llvm::Function* funcJ3MethodIndex; llvm::Function* funcJ3TypeVT; Modified: vmkit/branches/mcjit/include/j3/j3symbol.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3symbol.h?rev=196271&r1=196270&r2=196271&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3symbol.h (original) +++ vmkit/branches/mcjit/include/j3/j3symbol.h Tue Dec 3 06:34:41 2013 @@ -6,9 +6,7 @@ namespace j3 { class J3Symbol : public vmkit::PermanentObject { public: - virtual int isMethodPointer() { return 0; } - virtual int isMethodDescriptor() { return 0; } - virtual int isTypeDescriptor() { return 0; } + uint64_t getSymbolAddress(); }; }; Modified: vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc?rev=196271&r1=196270&r2=196271&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc Tue Dec 3 06:34:41 2013 @@ -69,11 +69,11 @@ void J3ClassLoader::addSymbol(const char pthread_mutex_unlock(&_mutexSymbolTable); } -J3Symbol* J3ClassLoader::getSymbol(const char* id) { +uint64_t J3ClassLoader::getSymbolAddress(const std::string &Name) { pthread_mutex_lock(&_mutexSymbolTable); - J3Symbol* res = _symbolTable[id]; + J3Symbol* res = _symbolTable[Name.c_str()]; pthread_mutex_unlock(&_mutexSymbolTable); - return res; + return res->getSymbolAddress(); } void* J3ClassLoader::lookupNativeFunctionPointer(J3Method* method, const char* symbol) { Added: vmkit/branches/mcjit/lib/j3/vm/j3symbol.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3symbol.cc?rev=196271&view=auto ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3symbol.cc (added) +++ vmkit/branches/mcjit/lib/j3/vm/j3symbol.cc Tue Dec 3 06:34:41 2013 @@ -0,0 +1,9 @@ +#include "j3/j3symbol.h" +#include "j3/j3thread.h" +#include "j3/j3.h" + +using namespace j3; + +uint64_t J3Symbol::getSymbolAddress() { + J3Thread::get()->vm()->internalError(L"implement me: getSymbolAddress"); +} From gael.thomas at lip6.fr Tue Dec 3 07:40:05 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Tue, 03 Dec 2013 15:40:05 -0000 Subject: [vmkit-commits] [vmkit] r196289 - retreive the function pointer after compilation from a J3CodeGen Message-ID: <20131203154005.CFCC92A6C02A@llvm.org> Author: gthomas Date: Tue Dec 3 09:40:05 2013 New Revision: 196289 URL: http://llvm.org/viewvc/llvm-project?rev=196289&view=rev Log: retreive the function pointer after compilation from a J3CodeGen Modified: vmkit/branches/mcjit/include/j3/j3codegen.h vmkit/branches/mcjit/include/j3/j3method.h vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc vmkit/branches/mcjit/lib/j3/vm/j3method.cc Modified: vmkit/branches/mcjit/include/j3/j3codegen.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3codegen.h?rev=196289&r1=196288&r2=196289&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3codegen.h (original) +++ vmkit/branches/mcjit/include/j3/j3codegen.h Tue Dec 3 09:40:05 2013 @@ -60,7 +60,7 @@ namespace j3 { llvm::Module* module; llvm::BasicBlock* bb; llvm::IRBuilder<>* builder; - llvm::Function* llvmFunction; + llvm::Function* _llvmFunction; J3* vm; J3Class* cl; @@ -202,7 +202,8 @@ namespace j3 { static J3CodeGen* create(J3Method* method); static void destroy(J3CodeGen* codeGen); - llvm::Function* generate(); + llvm::Function* llvmFunction() { return _llvmFunction; } + uint8_t* fnPtr(); }; } Modified: vmkit/branches/mcjit/include/j3/j3method.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3method.h?rev=196289&r1=196288&r2=196289&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3method.h (original) +++ vmkit/branches/mcjit/include/j3/j3method.h Tue Dec 3 09:40:05 2013 @@ -65,7 +65,8 @@ namespace j3 { J3MethodType* _methodType; J3Attributes* _attributes; uint32_t _index; - llvm::Function* _compiledFunction; + llvm::Function* _llvmFunction; + uint8_t* _fnPtr; char* volatile _llvmAllNames; /* md_ + llvm Name */ size_t _llvmAllNamesLength; void* _nativeFnPtr; Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=196289&r1=196288&r2=196289&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Tue Dec 3 09:40:05 2013 @@ -12,11 +12,15 @@ #include "j3/j3jni.h" #include "j3/j3object.h" +#include "llvm/ExecutionEngine/ExecutionEngine.h" + #include "llvm/IR/Function.h" #include "llvm/IR/Module.h" #include "llvm/IR/Argument.h" + #include "llvm/DebugInfo.h" #include "llvm/DIBuilder.h" +#include "llvm/PassManager.h" using namespace j3; @@ -40,8 +44,8 @@ J3CodeGen::J3CodeGen(vmkit::BumpAllocato module = loader->module(); vm = loader->vm(); - llvmFunction = method->llvmFunction(0, module); - llvmFunction->setGC("vmkit"); + _llvmFunction = method->llvmFunction(0, module); + llvmFunction()->setGC("vmkit"); bbCheckCastFailed = 0; bbNullCheckFailed = 0; @@ -87,6 +91,19 @@ J3CodeGen::J3CodeGen(vmkit::BumpAllocato ziTry = (llvm::Function*)module->getOrInsertFunction("vmkit.try", llvm::FunctionType::get(llvm::Type::getVoidTy(module->getContext()), 0)); + + bb = llvm::BasicBlock::Create(llvmFunction()->getContext(), "entry", llvmFunction()); + llvm::IRBuilder<> _builder(bb); + + builder = &_builder; + + if(J3Cst::isNative(method->access())) + generateNative(); + else + generateJava(); + + loader->pm()->run(*llvmFunction()); + vm->ee()->recompileAndRelinkFunction(llvmFunction()); } J3CodeGen::~J3CodeGen() { @@ -110,6 +127,10 @@ void J3CodeGen::destroy(J3CodeGen* codeG vmkit::BumpAllocator::destroy(allocator); } +uint8_t* J3CodeGen::fnPtr() { + return (uint8_t*)vm->ee()->getPointerToFunction(llvmFunction()); +} + uint32_t J3CodeGen::wideReadU1() { if(isWide) { isWide = 0; @@ -193,10 +214,10 @@ llvm::Value* J3CodeGen::vt(J3Type* type) llvm::Value* J3CodeGen::nullCheck(llvm::Value* obj) { if(exceptionNodes[curExceptionNode]->landingPad) { - llvm::BasicBlock* succeed = llvm::BasicBlock::Create(llvmFunction->getContext(), "nullcheck-succeed", llvmFunction); + llvm::BasicBlock* succeed = llvm::BasicBlock::Create(llvmFunction()->getContext(), "nullcheck-succeed", llvmFunction()); if(!bbNullCheckFailed) { - bbNullCheckFailed = llvm::BasicBlock::Create(llvmFunction->getContext(), "nullcheck-failed", llvmFunction); + bbNullCheckFailed = llvm::BasicBlock::Create(llvmFunction()->getContext(), "nullcheck-failed", llvmFunction()); builder->SetInsertPoint(bbNullCheckFailed); builder->CreateInvoke(funcNullPointerException, bbRet, exceptionNodes[curExceptionNode]->landingPad); builder->SetInsertPoint(bb); @@ -225,7 +246,7 @@ void J3CodeGen::invoke(J3Method* target, llvm::Value* res; if(exceptionNodes[curExceptionNode]->landingPad) { - llvm::BasicBlock* after = llvm::BasicBlock::Create(llvmFunction->getContext(), "invoke-after", llvmFunction); + llvm::BasicBlock* after = llvm::BasicBlock::Create(llvmFunction()->getContext(), "invoke-after", llvmFunction()); res = builder->CreateInvoke(func, after, exceptionNodes[curExceptionNode]->landingPad, args); bb = after; builder->SetInsertPoint(bb); @@ -405,8 +426,8 @@ llvm::Value* J3CodeGen::isAssignableTo(l void J3CodeGen::instanceof(llvm::Value* obj, J3Type* type) { llvm::BasicBlock* after = forwardBranch("instanceof-after", codeReader->tell(), 0, 0); - llvm::BasicBlock* ok = llvm::BasicBlock::Create(llvmFunction->getContext(), "instanceof-ok", llvmFunction); - llvm::BasicBlock* test = llvm::BasicBlock::Create(llvmFunction->getContext(), "instanceof", llvmFunction); + llvm::BasicBlock* ok = llvm::BasicBlock::Create(llvmFunction()->getContext(), "instanceof-ok", llvmFunction()); + llvm::BasicBlock* test = llvm::BasicBlock::Create(llvmFunction()->getContext(), "instanceof", llvmFunction()); builder->CreateCondBr(builder->CreateIsNull(obj), ok, test); @@ -422,12 +443,12 @@ void J3CodeGen::instanceof(llvm::Value* void J3CodeGen::checkCast(llvm::Value* obj, J3Type* type) { llvm::BasicBlock* succeed = forwardBranch("checkcast-succeed", codeReader->tell(), 0, 0); - llvm::BasicBlock* test = llvm::BasicBlock::Create(llvmFunction->getContext(), "checkcast", llvmFunction); + llvm::BasicBlock* test = llvm::BasicBlock::Create(llvmFunction()->getContext(), "checkcast", llvmFunction()); builder->CreateCondBr(builder->CreateIsNull(obj), succeed, test); if(!bbCheckCastFailed) { - bbCheckCastFailed = llvm::BasicBlock::Create(llvmFunction->getContext(), "checkcast-failed", llvmFunction); + bbCheckCastFailed = llvm::BasicBlock::Create(llvmFunction()->getContext(), "checkcast-failed", llvmFunction()); builder->SetInsertPoint(bbCheckCastFailed); builder->CreateCall(funcClassCastException); builder->CreateBr(bbRet); @@ -539,7 +560,7 @@ llvm::BasicBlock* J3CodeGen::forwardBran opInfos[pc].bb = after; return after; } else { - llvm::BasicBlock* res = llvm::BasicBlock::Create(llvmFunction->getContext(), id, llvmFunction); + llvm::BasicBlock* res = llvm::BasicBlock::Create(llvmFunction()->getContext(), id, llvmFunction()); if(doAlloc) { opInfos[pc].metaStack = (llvm::Type**)allocator->allocate(sizeof(llvm::Type**)*stack.topStack); @@ -701,7 +722,7 @@ void J3CodeGen::translate() { switch(vm->options()->debugTranslate) { case 4: fprintf(stderr, "--------------------------------------------\n"); - llvmFunction->dump(); + llvmFunction()->dump(); case 3: fprintf(stderr, "stack:\n"); stack.dump(); @@ -1298,7 +1319,7 @@ void J3CodeGen::initExceptionNode(J3Exce void J3CodeGen::addToExceptionNode(J3ExceptionNode* node, J3ExceptionEntry* entry) { if(!node->nbEntries) { - node->landingPad = llvm::BasicBlock::Create(llvmFunction->getContext(), "landing-pad", llvmFunction); + node->landingPad = llvm::BasicBlock::Create(llvmFunction()->getContext(), "landing-pad", llvmFunction()); node->curCheck = node->landingPad; builder->SetInsertPoint(node->landingPad); @@ -1322,7 +1343,7 @@ void J3CodeGen::addToExceptionNode(J3Exc if(node->curCheck) { /* = 0 if I already have a finally */ builder->SetInsertPoint(node->curCheck); - node->curCheck = llvm::BasicBlock::Create(llvmFunction->getContext(), "next-exception-check", llvmFunction); + node->curCheck = llvm::BasicBlock::Create(llvmFunction()->getContext(), "next-exception-check", llvmFunction()); if(entry->catchType) { stack.metaStack[0] = vm->typeJ3ObjectPtr; @@ -1362,8 +1383,8 @@ void J3CodeGen::generateJava() { dbgInfo = loader->dbgBuilder()->createFunction(llvm::DIDescriptor(), // Function scope - llvmFunction->getName(), // Function name - llvmFunction->getName(), // Mangled name + llvmFunction()->getName(), // Function name + llvmFunction()->getName(), // Mangled name llvm::DIFile(), // File where this variable is defined 0, // Line number loader->dbgBuilder() // Function type. @@ -1384,7 +1405,7 @@ void J3CodeGen::generateJava() { ret.init(this, 1, allocator->allocate(J3CodeGenVar::reservedSize(1))); uint32_t n=0; - for(llvm::Function::arg_iterator cur=llvmFunction->arg_begin(); cur!=llvmFunction->arg_end(); cur++, n++) { + for(llvm::Function::arg_iterator cur=llvmFunction()->arg_begin(); cur!=llvmFunction()->arg_end(); cur++, n++) { locals.setAt(flatten(cur, methodType->ins(n)), n); } @@ -1397,7 +1418,7 @@ void J3CodeGen::generateJava() { J3Reader codeReaderTmp(cl->bytes(), reader.tell(), codeLength); codeReader = &codeReaderTmp; - bbRet = llvm::BasicBlock::Create(llvmFunction->getContext(), "ret", llvmFunction); + bbRet = llvm::BasicBlock::Create(llvmFunction()->getContext(), "ret", llvmFunction()); builder->SetInsertPoint(bbRet); if(vm->options()->genDebugExecute) { char buf[256]; @@ -1527,7 +1548,7 @@ void J3CodeGen::generateNative() { if(methodType->nbIns()) { uint32_t i = 0; - for(llvm::Function::arg_iterator cur=llvmFunction->arg_begin(); cur!=llvmFunction->arg_end(); cur++, i++) { + for(llvm::Function::arg_iterator cur=llvmFunction()->arg_begin(); cur!=llvmFunction()->arg_end(); cur++, i++) { llvm::Value* a; if(methodType->ins(i)->llvmType()->isPointerTy()) a = builder->CreateCall2(funcJ3ThreadPush, thread, flatten(cur, methodType->ins(i))); @@ -1546,8 +1567,8 @@ void J3CodeGen::generateNative() { builder->CreateCall2(funcJ3ThreadRestore, thread, frame); if(methodType->out()->llvmType()->isPointerTy()) { - llvm::BasicBlock* ifnull = llvm::BasicBlock::Create(llvmFunction->getContext(), "ifnull", llvmFunction); - llvm::BasicBlock* ifnotnull = llvm::BasicBlock::Create(llvmFunction->getContext(), "ifnotnull", llvmFunction); + llvm::BasicBlock* ifnull = llvm::BasicBlock::Create(llvmFunction()->getContext(), "ifnull", llvmFunction()); + llvm::BasicBlock* ifnotnull = llvm::BasicBlock::Create(llvmFunction()->getContext(), "ifnotnull", llvmFunction()); builder->CreateCondBr(builder->CreateIsNull(res), ifnull, ifnotnull); builder->SetInsertPoint(bb = ifnull); @@ -1559,20 +1580,3 @@ void J3CodeGen::generateNative() { builder->CreateRet(res); } } - -llvm::Function* J3CodeGen::generate() { - bb = llvm::BasicBlock::Create(llvmFunction->getContext(), "entry", llvmFunction); - llvm::IRBuilder<> _builder(bb); - - builder = &_builder; - - if(J3Cst::isNative(method->access())) - generateNative(); - else - generateJava(); - - //llvmFunction->dump(); - //module->dump(); - - return llvmFunction; -} Modified: vmkit/branches/mcjit/lib/j3/vm/j3method.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3method.cc?rev=196289&r1=196288&r2=196289&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3method.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3method.cc Tue Dec 3 09:40:05 2013 @@ -46,8 +46,8 @@ uint32_t J3Method::index() { void* J3Method::fnPtr() { void* res; - - if(!_compiledFunction) { + + if(!_fnPtr) { //fprintf(stderr, "materializing: %ls::%ls%ls\n", cl()->name()->cStr(), name()->cStr(), sign()->cStr()); if(!isResolved()) { if(cl()->loader()->vm()->options()->debugLinking) @@ -59,22 +59,16 @@ void* J3Method::fnPtr() { } J3CodeGen* codeGen = J3CodeGen::create(this); - _compiledFunction = codeGen->generate(); + _llvmFunction = codeGen->llvmFunction(); + _fnPtr = codeGen->fnPtr(); J3CodeGen::destroy(codeGen); + } - cl()->loader()->pm()->run(*_compiledFunction); - - //_compiledFunction->dump(); - - res = cl()->loader()->vm()->ee()->recompileAndRelinkFunction(_compiledFunction); - } else - res = cl()->loader()->vm()->ee()->getPointerToFunction(_compiledFunction); - - return res; + return _fnPtr; } void* J3Method::functionPointerOrTrampoline() { - return _compiledFunction ? fnPtr() : _trampoline; + return _fnPtr ? _fnPtr : _trampoline; } void J3Method::setResolved(uint32_t index) { @@ -151,9 +145,8 @@ J3Value J3Method::internalInvoke(bool st target = resolve(self); } - if(!_compiledFunction) - fnPtr(); /* ensure that the function is fully compiled */ - llvm::GenericValue res = cl()->loader()->vm()->ee()->runFunction(_compiledFunction, *args); + fnPtr(); /* ensure that the function is compiled */ + llvm::GenericValue res = cl()->loader()->vm()->ee()->runFunction(_llvmFunction, *args); J3Value holder; J3* vm = cl()->loader()->vm(); @@ -355,7 +348,7 @@ llvm::GlobalValue* J3Method::llvmDescrip llvm::Function* J3Method::llvmFunction(bool isStub, llvm::Module* module, J3Class* from) { llvm::Function* res; - if(isStub && !_compiledFunction) { + if(isStub) { char id[llvmFunctionNameLength() + 16]; memcpy(id, llvmFunctionName(), llvmFunctionNameLength()); memcpy(id + llvmFunctionNameLength(), "_stub", 6); From gael.thomas at lip6.fr Tue Dec 3 07:52:53 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Tue, 03 Dec 2013 15:52:53 -0000 Subject: [vmkit-commits] [vmkit] r196290 - J3CodeGen is only used to translate a Java bytecode into a llvm bitcode Message-ID: <20131203155253.425CB2A6C029@llvm.org> Author: gthomas Date: Tue Dec 3 09:52:52 2013 New Revision: 196290 URL: http://llvm.org/viewvc/llvm-project?rev=196290&view=rev Log: J3CodeGen is only used to translate a Java bytecode into a llvm bitcode Modified: vmkit/branches/mcjit/include/j3/j3codegen.h vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc vmkit/branches/mcjit/lib/j3/vm/j3method.cc Modified: vmkit/branches/mcjit/include/j3/j3codegen.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3codegen.h?rev=196290&r1=196289&r2=196290&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3codegen.h (original) +++ vmkit/branches/mcjit/include/j3/j3codegen.h Tue Dec 3 09:52:52 2013 @@ -56,45 +56,45 @@ namespace j3 { class J3CodeGen { friend class J3CodeGenVar; - vmkit::BumpAllocator* allocator; - llvm::Module* module; - llvm::BasicBlock* bb; - llvm::IRBuilder<>* builder; - llvm::Function* _llvmFunction; - - J3* vm; - J3Class* cl; - J3ClassLoader* loader; - J3Method* method; - J3MethodType* methodType; - J3Reader* codeReader; - - llvm::BasicBlock* bbCheckCastFailed; - llvm::BasicBlock* bbNullCheckFailed; - llvm::BasicBlock* bbRet; - - J3ExceptionEntry* exceptionEntries; - J3ExceptionNode** exceptionNodes; - uint32_t nbExceptionEntries; - uint32_t nbExceptionNodes; - uint32_t curExceptionNode; - - J3OpInfo* opInfos; - uint32_t* pendingBranchs; - uint32_t topPendingBranchs; - - llvm::Value* nullValue; - - llvm::MDNode* dbgInfo; - uint32_t javaPC; - - J3CodeGenVar locals; - J3CodeGenVar stack; - J3CodeGenVar ret; + vmkit::BumpAllocator* allocator; + llvm::Module* module; + llvm::BasicBlock* bb; + llvm::IRBuilder<>* builder; + llvm::Function* _llvmFunction; + + J3* vm; + J3Class* cl; + J3ClassLoader* loader; + J3Method* method; + J3MethodType* methodType; + J3Reader* codeReader; + + llvm::BasicBlock* bbCheckCastFailed; + llvm::BasicBlock* bbNullCheckFailed; + llvm::BasicBlock* bbRet; + + J3ExceptionEntry* exceptionEntries; + J3ExceptionNode** exceptionNodes; + uint32_t nbExceptionEntries; + uint32_t nbExceptionNodes; + uint32_t curExceptionNode; + + J3OpInfo* opInfos; + uint32_t* pendingBranchs; + uint32_t topPendingBranchs; + + llvm::Value* nullValue; + + llvm::MDNode* dbgInfo; + uint32_t javaPC; + + J3CodeGenVar locals; + J3CodeGenVar stack; + J3CodeGenVar ret; - bool closeBB; + bool closeBB; - bool isWide; + bool isWide; uint32_t wideReadU1(); uint32_t wideReadS1(); @@ -203,7 +203,6 @@ namespace j3 { static void destroy(J3CodeGen* codeGen); llvm::Function* llvmFunction() { return _llvmFunction; } - uint8_t* fnPtr(); }; } Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=196290&r1=196289&r2=196290&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Tue Dec 3 09:52:52 2013 @@ -101,9 +101,6 @@ J3CodeGen::J3CodeGen(vmkit::BumpAllocato generateNative(); else generateJava(); - - loader->pm()->run(*llvmFunction()); - vm->ee()->recompileAndRelinkFunction(llvmFunction()); } J3CodeGen::~J3CodeGen() { @@ -127,10 +124,6 @@ void J3CodeGen::destroy(J3CodeGen* codeG vmkit::BumpAllocator::destroy(allocator); } -uint8_t* J3CodeGen::fnPtr() { - return (uint8_t*)vm->ee()->getPointerToFunction(llvmFunction()); -} - uint32_t J3CodeGen::wideReadU1() { if(isWide) { isWide = 0; Modified: vmkit/branches/mcjit/lib/j3/vm/j3method.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3method.cc?rev=196290&r1=196289&r2=196290&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3method.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3method.cc Tue Dec 3 09:52:52 2013 @@ -60,8 +60,11 @@ void* J3Method::fnPtr() { J3CodeGen* codeGen = J3CodeGen::create(this); _llvmFunction = codeGen->llvmFunction(); - _fnPtr = codeGen->fnPtr(); J3CodeGen::destroy(codeGen); + + cl()->loader()->pm()->run(*_llvmFunction); + llvm::ExecutionEngine* ee = cl()->loader()->vm()->ee(); + _fnPtr = (uint8_t*)ee->recompileAndRelinkFunction(_llvmFunction); } return _fnPtr; From gael.thomas at lip6.fr Tue Dec 3 08:02:44 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Tue, 03 Dec 2013 16:02:44 -0000 Subject: [vmkit-commits] [vmkit] r196291 - create the llvmFunction and its module in J3Method::fnPtr. Message-ID: <20131203160244.ADA322A6C029@llvm.org> Author: gthomas Date: Tue Dec 3 10:02:44 2013 New Revision: 196291 URL: http://llvm.org/viewvc/llvm-project?rev=196291&view=rev Log: create the llvmFunction and its module in J3Method::fnPtr. Modified: vmkit/branches/mcjit/include/j3/j3codegen.h vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc vmkit/branches/mcjit/lib/j3/vm/j3method.cc Modified: vmkit/branches/mcjit/include/j3/j3codegen.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3codegen.h?rev=196291&r1=196290&r2=196291&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3codegen.h (original) +++ vmkit/branches/mcjit/include/j3/j3codegen.h Tue Dec 3 10:02:44 2013 @@ -60,7 +60,7 @@ namespace j3 { llvm::Module* module; llvm::BasicBlock* bb; llvm::IRBuilder<>* builder; - llvm::Function* _llvmFunction; + llvm::Function* llvmFunction; J3* vm; J3Class* cl; @@ -193,16 +193,13 @@ namespace j3 { llvm::Function* ziTry; llvm::GlobalValue* gvTypeInfo; /* typename void* */ - J3CodeGen(vmkit::BumpAllocator* _allocator, J3Method* method); + J3CodeGen(vmkit::BumpAllocator* _allocator, J3Method* method, llvm::Function* _llvmFunction); ~J3CodeGen(); void* operator new(size_t n, vmkit::BumpAllocator* _allocator); void operator delete(void* ptr); public: - static J3CodeGen* create(J3Method* method); - static void destroy(J3CodeGen* codeGen); - - llvm::Function* llvmFunction() { return _llvmFunction; } + static void translate(J3Method* method, llvm::Function* llvmFunction); }; } Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=196291&r1=196290&r2=196291&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Tue Dec 3 10:02:44 2013 @@ -34,18 +34,18 @@ void J3ExceptionEntry::dump() { fprintf(stderr, " catchType: %u\n", catchType); } -J3CodeGen::J3CodeGen(vmkit::BumpAllocator* _allocator, J3Method* m) { +J3CodeGen::J3CodeGen(vmkit::BumpAllocator* _allocator, J3Method* m, llvm::Function* _llvmFunction) { allocator = _allocator; method = m; cl = method->cl(); methodType = method->methodType(); loader = cl->loader(); - module = loader->module(); vm = loader->vm(); - _llvmFunction = method->llvmFunction(0, module); - llvmFunction()->setGC("vmkit"); + llvmFunction = _llvmFunction; + llvmFunction->setGC("vmkit"); + module = llvmFunction->getParent(); bbCheckCastFailed = 0; bbNullCheckFailed = 0; @@ -92,7 +92,7 @@ J3CodeGen::J3CodeGen(vmkit::BumpAllocato (llvm::Function*)module->getOrInsertFunction("vmkit.try", llvm::FunctionType::get(llvm::Type::getVoidTy(module->getContext()), 0)); - bb = llvm::BasicBlock::Create(llvmFunction()->getContext(), "entry", llvmFunction()); + bb = llvm::BasicBlock::Create(llvmFunction->getContext(), "entry", llvmFunction); llvm::IRBuilder<> _builder(bb); builder = &_builder; @@ -113,14 +113,9 @@ void* J3CodeGen::operator new(size_t n, void J3CodeGen::operator delete(void* ptr) { } -J3CodeGen* J3CodeGen::create(J3Method* method) { +void J3CodeGen::translate(J3Method* method, llvm::Function* llvmFunction) { vmkit::BumpAllocator* allocator = vmkit::BumpAllocator::create(); - return new(allocator) J3CodeGen(allocator, method); -} - -void J3CodeGen::destroy(J3CodeGen* codeGen) { - vmkit::BumpAllocator* allocator = codeGen->allocator; - delete codeGen; + delete new(allocator) J3CodeGen(allocator, method, llvmFunction); vmkit::BumpAllocator::destroy(allocator); } @@ -207,10 +202,10 @@ llvm::Value* J3CodeGen::vt(J3Type* type) llvm::Value* J3CodeGen::nullCheck(llvm::Value* obj) { if(exceptionNodes[curExceptionNode]->landingPad) { - llvm::BasicBlock* succeed = llvm::BasicBlock::Create(llvmFunction()->getContext(), "nullcheck-succeed", llvmFunction()); + llvm::BasicBlock* succeed = llvm::BasicBlock::Create(llvmFunction->getContext(), "nullcheck-succeed", llvmFunction); if(!bbNullCheckFailed) { - bbNullCheckFailed = llvm::BasicBlock::Create(llvmFunction()->getContext(), "nullcheck-failed", llvmFunction()); + bbNullCheckFailed = llvm::BasicBlock::Create(llvmFunction->getContext(), "nullcheck-failed", llvmFunction); builder->SetInsertPoint(bbNullCheckFailed); builder->CreateInvoke(funcNullPointerException, bbRet, exceptionNodes[curExceptionNode]->landingPad); builder->SetInsertPoint(bb); @@ -239,7 +234,7 @@ void J3CodeGen::invoke(J3Method* target, llvm::Value* res; if(exceptionNodes[curExceptionNode]->landingPad) { - llvm::BasicBlock* after = llvm::BasicBlock::Create(llvmFunction()->getContext(), "invoke-after", llvmFunction()); + llvm::BasicBlock* after = llvm::BasicBlock::Create(llvmFunction->getContext(), "invoke-after", llvmFunction); res = builder->CreateInvoke(func, after, exceptionNodes[curExceptionNode]->landingPad, args); bb = after; builder->SetInsertPoint(bb); @@ -419,8 +414,8 @@ llvm::Value* J3CodeGen::isAssignableTo(l void J3CodeGen::instanceof(llvm::Value* obj, J3Type* type) { llvm::BasicBlock* after = forwardBranch("instanceof-after", codeReader->tell(), 0, 0); - llvm::BasicBlock* ok = llvm::BasicBlock::Create(llvmFunction()->getContext(), "instanceof-ok", llvmFunction()); - llvm::BasicBlock* test = llvm::BasicBlock::Create(llvmFunction()->getContext(), "instanceof", llvmFunction()); + llvm::BasicBlock* ok = llvm::BasicBlock::Create(llvmFunction->getContext(), "instanceof-ok", llvmFunction); + llvm::BasicBlock* test = llvm::BasicBlock::Create(llvmFunction->getContext(), "instanceof", llvmFunction); builder->CreateCondBr(builder->CreateIsNull(obj), ok, test); @@ -436,12 +431,12 @@ void J3CodeGen::instanceof(llvm::Value* void J3CodeGen::checkCast(llvm::Value* obj, J3Type* type) { llvm::BasicBlock* succeed = forwardBranch("checkcast-succeed", codeReader->tell(), 0, 0); - llvm::BasicBlock* test = llvm::BasicBlock::Create(llvmFunction()->getContext(), "checkcast", llvmFunction()); + llvm::BasicBlock* test = llvm::BasicBlock::Create(llvmFunction->getContext(), "checkcast", llvmFunction); builder->CreateCondBr(builder->CreateIsNull(obj), succeed, test); if(!bbCheckCastFailed) { - bbCheckCastFailed = llvm::BasicBlock::Create(llvmFunction()->getContext(), "checkcast-failed", llvmFunction()); + bbCheckCastFailed = llvm::BasicBlock::Create(llvmFunction->getContext(), "checkcast-failed", llvmFunction); builder->SetInsertPoint(bbCheckCastFailed); builder->CreateCall(funcClassCastException); builder->CreateBr(bbRet); @@ -553,7 +548,7 @@ llvm::BasicBlock* J3CodeGen::forwardBran opInfos[pc].bb = after; return after; } else { - llvm::BasicBlock* res = llvm::BasicBlock::Create(llvmFunction()->getContext(), id, llvmFunction()); + llvm::BasicBlock* res = llvm::BasicBlock::Create(llvmFunction->getContext(), id, llvmFunction); if(doAlloc) { opInfos[pc].metaStack = (llvm::Type**)allocator->allocate(sizeof(llvm::Type**)*stack.topStack); @@ -715,7 +710,7 @@ void J3CodeGen::translate() { switch(vm->options()->debugTranslate) { case 4: fprintf(stderr, "--------------------------------------------\n"); - llvmFunction()->dump(); + llvmFunction->dump(); case 3: fprintf(stderr, "stack:\n"); stack.dump(); @@ -1312,7 +1307,7 @@ void J3CodeGen::initExceptionNode(J3Exce void J3CodeGen::addToExceptionNode(J3ExceptionNode* node, J3ExceptionEntry* entry) { if(!node->nbEntries) { - node->landingPad = llvm::BasicBlock::Create(llvmFunction()->getContext(), "landing-pad", llvmFunction()); + node->landingPad = llvm::BasicBlock::Create(llvmFunction->getContext(), "landing-pad", llvmFunction); node->curCheck = node->landingPad; builder->SetInsertPoint(node->landingPad); @@ -1336,7 +1331,7 @@ void J3CodeGen::addToExceptionNode(J3Exc if(node->curCheck) { /* = 0 if I already have a finally */ builder->SetInsertPoint(node->curCheck); - node->curCheck = llvm::BasicBlock::Create(llvmFunction()->getContext(), "next-exception-check", llvmFunction()); + node->curCheck = llvm::BasicBlock::Create(llvmFunction->getContext(), "next-exception-check", llvmFunction); if(entry->catchType) { stack.metaStack[0] = vm->typeJ3ObjectPtr; @@ -1376,8 +1371,8 @@ void J3CodeGen::generateJava() { dbgInfo = loader->dbgBuilder()->createFunction(llvm::DIDescriptor(), // Function scope - llvmFunction()->getName(), // Function name - llvmFunction()->getName(), // Mangled name + llvmFunction->getName(), // Function name + llvmFunction->getName(), // Mangled name llvm::DIFile(), // File where this variable is defined 0, // Line number loader->dbgBuilder() // Function type. @@ -1398,7 +1393,7 @@ void J3CodeGen::generateJava() { ret.init(this, 1, allocator->allocate(J3CodeGenVar::reservedSize(1))); uint32_t n=0; - for(llvm::Function::arg_iterator cur=llvmFunction()->arg_begin(); cur!=llvmFunction()->arg_end(); cur++, n++) { + for(llvm::Function::arg_iterator cur=llvmFunction->arg_begin(); cur!=llvmFunction->arg_end(); cur++, n++) { locals.setAt(flatten(cur, methodType->ins(n)), n); } @@ -1411,7 +1406,7 @@ void J3CodeGen::generateJava() { J3Reader codeReaderTmp(cl->bytes(), reader.tell(), codeLength); codeReader = &codeReaderTmp; - bbRet = llvm::BasicBlock::Create(llvmFunction()->getContext(), "ret", llvmFunction()); + bbRet = llvm::BasicBlock::Create(llvmFunction->getContext(), "ret", llvmFunction); builder->SetInsertPoint(bbRet); if(vm->options()->genDebugExecute) { char buf[256]; @@ -1541,7 +1536,7 @@ void J3CodeGen::generateNative() { if(methodType->nbIns()) { uint32_t i = 0; - for(llvm::Function::arg_iterator cur=llvmFunction()->arg_begin(); cur!=llvmFunction()->arg_end(); cur++, i++) { + for(llvm::Function::arg_iterator cur=llvmFunction->arg_begin(); cur!=llvmFunction->arg_end(); cur++, i++) { llvm::Value* a; if(methodType->ins(i)->llvmType()->isPointerTy()) a = builder->CreateCall2(funcJ3ThreadPush, thread, flatten(cur, methodType->ins(i))); @@ -1560,8 +1555,8 @@ void J3CodeGen::generateNative() { builder->CreateCall2(funcJ3ThreadRestore, thread, frame); if(methodType->out()->llvmType()->isPointerTy()) { - llvm::BasicBlock* ifnull = llvm::BasicBlock::Create(llvmFunction()->getContext(), "ifnull", llvmFunction()); - llvm::BasicBlock* ifnotnull = llvm::BasicBlock::Create(llvmFunction()->getContext(), "ifnotnull", llvmFunction()); + llvm::BasicBlock* ifnull = llvm::BasicBlock::Create(llvmFunction->getContext(), "ifnull", llvmFunction); + llvm::BasicBlock* ifnotnull = llvm::BasicBlock::Create(llvmFunction->getContext(), "ifnotnull", llvmFunction); builder->CreateCondBr(builder->CreateIsNull(res), ifnull, ifnotnull); builder->SetInsertPoint(bb = ifnull); Modified: vmkit/branches/mcjit/lib/j3/vm/j3method.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3method.cc?rev=196291&r1=196290&r2=196291&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3method.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3method.cc Tue Dec 3 10:02:44 2013 @@ -58,9 +58,10 @@ void* J3Method::fnPtr() { J3::noSuchMethodError(L"unable to find method", cl(), name(), sign()); } - J3CodeGen* codeGen = J3CodeGen::create(this); - _llvmFunction = codeGen->llvmFunction(); - J3CodeGen::destroy(codeGen); + llvm::Module* module = cl()->loader()->module(); + _llvmFunction = llvmFunction(0, module); + + J3CodeGen::translate(this, _llvmFunction); cl()->loader()->pm()->run(*_llvmFunction); llvm::ExecutionEngine* ee = cl()->loader()->vm()->ee(); From gael.thomas at lip6.fr Tue Dec 3 08:47:22 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Tue, 03 Dec 2013 16:47:22 -0000 Subject: [vmkit-commits] [vmkit] r196295 - each Java method has its own compilation module Message-ID: <20131203164722.901E12A6C029@llvm.org> Author: gthomas Date: Tue Dec 3 10:47:22 2013 New Revision: 196295 URL: http://llvm.org/viewvc/llvm-project?rev=196295&view=rev Log: each Java method has its own compilation module Modified: vmkit/branches/mcjit/include/j3/j3classloader.h vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc vmkit/branches/mcjit/lib/j3/vm/j3method.cc Modified: vmkit/branches/mcjit/include/j3/j3classloader.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3classloader.h?rev=196295&r1=196294&r2=196295&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3classloader.h (original) +++ vmkit/branches/mcjit/include/j3/j3classloader.h Tue Dec 3 10:47:22 2013 @@ -15,7 +15,6 @@ namespace llvm { class DataLayout; class Type; class Function; - class DIBuilder; namespace legacy { class FunctionPassManager; @@ -59,7 +58,6 @@ namespace j3 { vmkit::NameMap::map types; /* shortcut to find types */ vmkit::NameMap::map methodTypes; /* shortcut to find method types - REMOVE */ llvm::Module* _module; /* the associated llvm module */ - llvm::DIBuilder* _dbgBuilder; MethodRefMap methods; /* all te known method */ void wrongType(J3Class* from, const vmkit::Name* type); @@ -79,8 +77,6 @@ namespace j3 { static void destroy(J3ClassLoader* loader); - llvm::DIBuilder* dbgBuilder() const { return _dbgBuilder; } - J3FixedPoint* fixedPoint() { return &_fixedPoint; } J3ObjectHandle* javaClassLoader() { return _javaClassLoader; } Modified: vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc?rev=196295&r1=196294&r2=196295&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc Tue Dec 3 10:47:22 2013 @@ -10,7 +10,6 @@ #include "llvm/IR/Module.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/DerivedTypes.h" -#include "llvm/DIBuilder.h" #include "vmkit/allocator.h" @@ -57,10 +56,6 @@ J3ClassLoader::J3ClassLoader(J3* v, J3Ob _vm = v; _module = new llvm::Module("j3", vm()->self()->getContext()); - _dbgBuilder = new llvm::DIBuilder(*module()); - _pm = vm()->preparePM(module()); - - vm()->ee()->addModule(module()); } void J3ClassLoader::addSymbol(const char* id, J3Symbol* symbol) { Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=196295&r1=196294&r2=196295&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Tue Dec 3 10:47:22 2013 @@ -1369,20 +1369,22 @@ void J3CodeGen::generateJava() { ->CreateIntToPtr(llvm::ConstantInt::get(vm->dataLayout()->getIntPtrType(module->getContext()), (uintptr_t)0), vm->typeJ3ObjectPtr); + llvm::DIBuilder* dbgBuilder = new llvm::DIBuilder(*module); + dbgInfo = - loader->dbgBuilder()->createFunction(llvm::DIDescriptor(), // Function scope - llvmFunction->getName(), // Function name - llvmFunction->getName(), // Mangled name - llvm::DIFile(), // File where this variable is defined - 0, // Line number - loader->dbgBuilder() // Function type. + dbgBuilder->createFunction(llvm::DIDescriptor(), // Function scope + llvmFunction->getName(), // Function name + llvmFunction->getName(), // Mangled name + llvm::DIFile(), // File where this variable is defined + 0, // Line number + dbgBuilder // Function type. ->createSubroutineType(llvm::DIFile(), // File in which this subroutine is defined llvm::DIArray()), // An array of subroutine parameter types. // This includes return type at 0th index. - false, // True if this function is not externally visible - false, // True if this is a function definition - 0 // Set to the beginning of the scope this starts - ); + false, // True if this function is not externally visible + false, // True if this is a function definition + 0 // Set to the beginning of the scope this starts + ); uint32_t maxStack = reader.readU2(); uint32_t nbLocals = reader.readU2(); Modified: vmkit/branches/mcjit/lib/j3/vm/j3method.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3method.cc?rev=196295&r1=196294&r2=196295&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3method.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3method.cc Tue Dec 3 10:47:22 2013 @@ -58,13 +58,14 @@ void* J3Method::fnPtr() { J3::noSuchMethodError(L"unable to find method", cl(), name(), sign()); } - llvm::Module* module = cl()->loader()->module(); + llvm::Module* module = new llvm::Module(llvmFunctionName(), cl()->loader()->vm()->self()->getContext()); _llvmFunction = llvmFunction(0, module); J3CodeGen::translate(this, _llvmFunction); - cl()->loader()->pm()->run(*_llvmFunction); + cl()->loader()->vm()->preparePM(module)->run(*_llvmFunction); /* TODO, check memory */ llvm::ExecutionEngine* ee = cl()->loader()->vm()->ee(); + ee->addModule(module); _fnPtr = (uint8_t*)ee->recompileAndRelinkFunction(_llvmFunction); } From gael.thomas at lip6.fr Tue Dec 3 14:23:08 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Tue, 03 Dec 2013 22:23:08 -0000 Subject: [vmkit-commits] [vmkit] r196324 - define a llvmContext in vmkit and uses it Message-ID: <20131203222308.46EEB2A6C029@llvm.org> Author: gthomas Date: Tue Dec 3 16:23:07 2013 New Revision: 196324 URL: http://llvm.org/viewvc/llvm-project?rev=196324&view=rev Log: define a llvmContext in vmkit and uses it Modified: vmkit/branches/mcjit/include/j3/j3codegen.h vmkit/branches/mcjit/include/vmkit/vmkit.h vmkit/branches/mcjit/lib/j3/vm/j3.cc vmkit/branches/mcjit/lib/j3/vm/j3class.cc vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc vmkit/branches/mcjit/lib/j3/vm/j3method.cc vmkit/branches/mcjit/lib/vmkit/vmkit.cc Modified: vmkit/branches/mcjit/include/j3/j3codegen.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3codegen.h?rev=196324&r1=196323&r2=196324&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3codegen.h (original) +++ vmkit/branches/mcjit/include/j3/j3codegen.h Tue Dec 3 16:23:07 2013 @@ -101,6 +101,7 @@ namespace j3 { llvm::Value* nullCheck(llvm::Value* obj); + llvm::BasicBlock* newBB(const char* name); bool onEndPoint(); llvm::BasicBlock* forwardBranch(const char* id, uint32_t pc, bool doAlloc, bool doPush); void condBr(llvm::Value* op); Modified: vmkit/branches/mcjit/include/vmkit/vmkit.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/vmkit.h?rev=196324&r1=196323&r2=196324&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/vmkit.h (original) +++ vmkit/branches/mcjit/include/vmkit/vmkit.h Tue Dec 3 16:23:07 2013 @@ -7,6 +7,7 @@ #include "llvm/ExecutionEngine/JITEventListener.h" namespace llvm { + class LLVMContext; class Module; class ExecutionEngine; class DataLayout; @@ -74,6 +75,7 @@ namespace vmkit { void vmkitBootstrap(Thread* initialThread, const char* selfBitCodePath); llvm::DataLayout* dataLayout() { return _dataLayout; } + llvm::LLVMContext& llvmContext(); llvm::Module* self() { return _self; } llvm::ExecutionEngine* ee() { return _ee; } llvm::FunctionPassManager* preparePM(llvm::Module* mod); Modified: vmkit/branches/mcjit/lib/j3/vm/j3.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3.cc?rev=196324&r1=196323&r2=196324&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3.cc Tue Dec 3 16:23:07 2013 @@ -53,8 +53,8 @@ void J3::introspect() { typeJ3ObjectPtr = llvm::PointerType::getUnqual(typeJ3Object); typeJ3ObjectHandlePtr = llvm::PointerType::getUnqual(introspectType("class.j3::J3ObjectHandle")); - typeGXXException = llvm::StructType::get(llvm::Type::getInt8Ty(self()->getContext())->getPointerTo(), - llvm::Type::getInt32Ty(self()->getContext()), NULL); + typeGXXException = llvm::StructType::get(llvm::Type::getInt8Ty(llvmContext())->getPointerTo(), + llvm::Type::getInt32Ty(llvmContext()), NULL); } void J3::start(int argc, char** argv) { @@ -72,7 +72,7 @@ void J3::start(int argc, char** argv) { vmkit::BumpAllocator* a = initialClassLoader->allocator(); #define defPrimitive(name, ctype, llvmtype) \ - type##name = new(a) J3Primitive(initialClassLoader, J3Cst::ID_##name, llvm::Type::get##llvmtype##Ty(self()->getContext())); + type##name = new(a) J3Primitive(initialClassLoader, J3Cst::ID_##name, llvm::Type::get##llvmtype##Ty(llvmContext())); onJavaTypes(defPrimitive) #undef defPrimitive Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=196324&r1=196323&r2=196324&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Tue Dec 3 16:23:07 2013 @@ -730,8 +730,8 @@ void J3Class::createLLVMTypes() { mangler.mangle("static_")->mangle(name()); staticLayout._llvmType = - llvm::PointerType::getUnqual(llvm::StructType::create(loader()->module()->getContext(), mangler.cStr())); - _llvmType = llvm::PointerType::getUnqual(llvm::StructType::create(loader()->module()->getContext(), mangler.cStr()+7)); + llvm::PointerType::getUnqual(llvm::StructType::create(loader()->vm()->llvmContext(), mangler.cStr())); + _llvmType = llvm::PointerType::getUnqual(llvm::StructType::create(loader()->vm()->llvmContext(), mangler.cStr()+7)); mangler.mangle("_2"); @@ -854,7 +854,7 @@ llvm::Type* J3ArrayClass::llvmType() { memcpy(_nativeName+2, component()->nativeName(), len); _nativeName[_nativeNameLength] = 0; - _llvmType = llvm::PointerType::getUnqual(llvm::StructType::create(loader()->module()->getContext(), + _llvmType = llvm::PointerType::getUnqual(llvm::StructType::create(loader()->vm()->llvmContext(), body, _nativeName)); Modified: vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc?rev=196324&r1=196323&r2=196324&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc Tue Dec 3 16:23:07 2013 @@ -55,7 +55,7 @@ J3ClassLoader::J3ClassLoader(J3* v, J3Ob _vm = v; - _module = new llvm::Module("j3", vm()->self()->getContext()); + _module = new llvm::Module("j3", vm()->llvmContext()); } void J3ClassLoader::addSymbol(const char* id, J3Symbol* symbol) { Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=196324&r1=196323&r2=196324&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Tue Dec 3 16:23:07 2013 @@ -90,9 +90,9 @@ J3CodeGen::J3CodeGen(vmkit::BumpAllocato ziTry = (llvm::Function*)module->getOrInsertFunction("vmkit.try", - llvm::FunctionType::get(llvm::Type::getVoidTy(module->getContext()), 0)); + llvm::FunctionType::get(llvm::Type::getVoidTy(llvmFunction->getContext()), 0)); - bb = llvm::BasicBlock::Create(llvmFunction->getContext(), "entry", llvmFunction); + bb = newBB("entry"); llvm::IRBuilder<> _builder(bb); builder = &_builder; @@ -202,10 +202,10 @@ llvm::Value* J3CodeGen::vt(J3Type* type) llvm::Value* J3CodeGen::nullCheck(llvm::Value* obj) { if(exceptionNodes[curExceptionNode]->landingPad) { - llvm::BasicBlock* succeed = llvm::BasicBlock::Create(llvmFunction->getContext(), "nullcheck-succeed", llvmFunction); + llvm::BasicBlock* succeed = newBB("nullcheck-succeed"); if(!bbNullCheckFailed) { - bbNullCheckFailed = llvm::BasicBlock::Create(llvmFunction->getContext(), "nullcheck-failed", llvmFunction); + bbNullCheckFailed = newBB("nullcheck-failed"); builder->SetInsertPoint(bbNullCheckFailed); builder->CreateInvoke(funcNullPointerException, bbRet, exceptionNodes[curExceptionNode]->landingPad); builder->SetInsertPoint(bb); @@ -234,7 +234,7 @@ void J3CodeGen::invoke(J3Method* target, llvm::Value* res; if(exceptionNodes[curExceptionNode]->landingPad) { - llvm::BasicBlock* after = llvm::BasicBlock::Create(llvmFunction->getContext(), "invoke-after", llvmFunction); + llvm::BasicBlock* after = newBB("invoke-after"); res = builder->CreateInvoke(func, after, exceptionNodes[curExceptionNode]->landingPad, args); bb = after; builder->SetInsertPoint(bb); @@ -414,8 +414,8 @@ llvm::Value* J3CodeGen::isAssignableTo(l void J3CodeGen::instanceof(llvm::Value* obj, J3Type* type) { llvm::BasicBlock* after = forwardBranch("instanceof-after", codeReader->tell(), 0, 0); - llvm::BasicBlock* ok = llvm::BasicBlock::Create(llvmFunction->getContext(), "instanceof-ok", llvmFunction); - llvm::BasicBlock* test = llvm::BasicBlock::Create(llvmFunction->getContext(), "instanceof", llvmFunction); + llvm::BasicBlock* ok = newBB("instanceof-ok"); + llvm::BasicBlock* test = newBB("instanceof"); builder->CreateCondBr(builder->CreateIsNull(obj), ok, test); @@ -431,12 +431,12 @@ void J3CodeGen::instanceof(llvm::Value* void J3CodeGen::checkCast(llvm::Value* obj, J3Type* type) { llvm::BasicBlock* succeed = forwardBranch("checkcast-succeed", codeReader->tell(), 0, 0); - llvm::BasicBlock* test = llvm::BasicBlock::Create(llvmFunction->getContext(), "checkcast", llvmFunction); + llvm::BasicBlock* test = newBB("checkcast"); builder->CreateCondBr(builder->CreateIsNull(obj), succeed, test); if(!bbCheckCastFailed) { - bbCheckCastFailed = llvm::BasicBlock::Create(llvmFunction->getContext(), "checkcast-failed", llvmFunction); + bbCheckCastFailed = newBB("checkcast-failed"); builder->SetInsertPoint(bbCheckCastFailed); builder->CreateCall(funcClassCastException); builder->CreateBr(bbRet); @@ -518,6 +518,10 @@ void J3CodeGen::ldc(uint32_t idx) { stack.push(res); } +llvm::BasicBlock* J3CodeGen::newBB(const char* name) { + return llvm::BasicBlock::Create(llvmFunction->getContext(), name, llvmFunction); +} + void J3CodeGen::condBr(llvm::Value* op) { builder->CreateCondBr(op, forwardBranch("if-true", javaPC + codeReader->readS2(), 1, 1), @@ -548,7 +552,7 @@ llvm::BasicBlock* J3CodeGen::forwardBran opInfos[pc].bb = after; return after; } else { - llvm::BasicBlock* res = llvm::BasicBlock::Create(llvmFunction->getContext(), id, llvmFunction); + llvm::BasicBlock* res = newBB(id); if(doAlloc) { opInfos[pc].metaStack = (llvm::Type**)allocator->allocate(sizeof(llvm::Type**)*stack.topStack); @@ -1307,7 +1311,7 @@ void J3CodeGen::initExceptionNode(J3Exce void J3CodeGen::addToExceptionNode(J3ExceptionNode* node, J3ExceptionEntry* entry) { if(!node->nbEntries) { - node->landingPad = llvm::BasicBlock::Create(llvmFunction->getContext(), "landing-pad", llvmFunction); + node->landingPad = newBB("landing-pad"); node->curCheck = node->landingPad; builder->SetInsertPoint(node->landingPad); @@ -1331,7 +1335,7 @@ void J3CodeGen::addToExceptionNode(J3Exc if(node->curCheck) { /* = 0 if I already have a finally */ builder->SetInsertPoint(node->curCheck); - node->curCheck = llvm::BasicBlock::Create(llvmFunction->getContext(), "next-exception-check", llvmFunction); + node->curCheck = newBB("next-exception-check"); if(entry->catchType) { stack.metaStack[0] = vm->typeJ3ObjectPtr; @@ -1408,7 +1412,7 @@ void J3CodeGen::generateJava() { J3Reader codeReaderTmp(cl->bytes(), reader.tell(), codeLength); codeReader = &codeReaderTmp; - bbRet = llvm::BasicBlock::Create(llvmFunction->getContext(), "ret", llvmFunction); + bbRet = newBB("ret"); builder->SetInsertPoint(bbRet); if(vm->options()->genDebugExecute) { char buf[256]; @@ -1557,8 +1561,8 @@ void J3CodeGen::generateNative() { builder->CreateCall2(funcJ3ThreadRestore, thread, frame); if(methodType->out()->llvmType()->isPointerTy()) { - llvm::BasicBlock* ifnull = llvm::BasicBlock::Create(llvmFunction->getContext(), "ifnull", llvmFunction); - llvm::BasicBlock* ifnotnull = llvm::BasicBlock::Create(llvmFunction->getContext(), "ifnotnull", llvmFunction); + llvm::BasicBlock* ifnull = newBB("ifnull"); + llvm::BasicBlock* ifnotnull = newBB("ifnotnull"); builder->CreateCondBr(builder->CreateIsNull(res), ifnull, ifnotnull); builder->SetInsertPoint(bb = ifnull); Modified: vmkit/branches/mcjit/lib/j3/vm/j3method.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3method.cc?rev=196324&r1=196323&r2=196324&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3method.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3method.cc Tue Dec 3 16:23:07 2013 @@ -58,7 +58,7 @@ void* J3Method::fnPtr() { J3::noSuchMethodError(L"unable to find method", cl(), name(), sign()); } - llvm::Module* module = new llvm::Module(llvmFunctionName(), cl()->loader()->vm()->self()->getContext()); + llvm::Module* module = new llvm::Module(llvmFunctionName(), cl()->loader()->vm()->llvmContext()); _llvmFunction = llvmFunction(0, module); J3CodeGen::translate(this, _llvmFunction); Modified: vmkit/branches/mcjit/lib/vmkit/vmkit.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/vmkit.cc?rev=196324&r1=196323&r2=196324&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/vmkit.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/vmkit.cc Tue Dec 3 16:23:07 2013 @@ -43,6 +43,9 @@ void VMKit::destroy(VMKit* vm) { vmkit::BumpAllocator::destroy(vm->allocator()); } +llvm::LLVMContext& VMKit::llvmContext() { + return self()->getContext(); +} llvm::Type* VMKit::introspectType(const char* name) { llvm::Type* res = self()->getTypeByName(name); From gael.thomas at lip6.fr Tue Dec 3 14:24:18 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Tue, 03 Dec 2013 22:24:18 -0000 Subject: [vmkit-commits] [vmkit] r196325 - each function has its own module, remove the module from class loader Message-ID: <20131203222418.7FA162A6C029@llvm.org> Author: gthomas Date: Tue Dec 3 16:24:18 2013 New Revision: 196325 URL: http://llvm.org/viewvc/llvm-project?rev=196325&view=rev Log: each function has its own module, remove the module from class loader Modified: vmkit/branches/mcjit/include/j3/j3classloader.h vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc Modified: vmkit/branches/mcjit/include/j3/j3classloader.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3classloader.h?rev=196325&r1=196324&r2=196325&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3classloader.h (original) +++ vmkit/branches/mcjit/include/j3/j3classloader.h Tue Dec 3 16:24:18 2013 @@ -57,8 +57,7 @@ namespace j3 { vmkit::NameMap::map classes; /* classes managed by this class loader */ vmkit::NameMap::map types; /* shortcut to find types */ vmkit::NameMap::map methodTypes; /* shortcut to find method types - REMOVE */ - llvm::Module* _module; /* the associated llvm module */ - MethodRefMap methods; /* all te known method */ + MethodRefMap methods; /* all te known method */ void wrongType(J3Class* from, const vmkit::Name* type); J3Type* getTypeInternal(J3Class* from, const vmkit::Name* type, uint32_t start, uint32_t* end); @@ -97,7 +96,6 @@ namespace j3 { J3Class* getClass(const vmkit::Name* name); /* find a class */ J3Type* getType(J3Class* from, const vmkit::Name* type); /* find a type */ J3MethodType* getMethodType(J3Class* from, const vmkit::Name* sign); /* get a method type */ - llvm::Module* module() { return _module; } virtual J3ClassBytes* lookup(const vmkit::Name* name); Modified: vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc?rev=196325&r1=196324&r2=196325&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc Tue Dec 3 16:24:18 2013 @@ -7,7 +7,6 @@ #include "llvm/ExecutionEngine/JIT.h" #include "llvm/ExecutionEngine/ExecutionEngine.h" -#include "llvm/IR/Module.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/DerivedTypes.h" @@ -54,8 +53,6 @@ J3ClassLoader::J3ClassLoader(J3* v, J3Ob pthread_mutex_init(&_mutexSymbolTable, 0); _vm = v; - - _module = new llvm::Module("j3", vm()->llvmContext()); } void J3ClassLoader::addSymbol(const char* id, J3Symbol* symbol) { From gael.thomas at lip6.fr Tue Dec 3 14:55:44 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Tue, 03 Dec 2013 22:55:44 -0000 Subject: [vmkit-commits] [vmkit] r196326 - cleanup includes Message-ID: <20131203225545.074772A6C029@llvm.org> Author: gthomas Date: Tue Dec 3 16:55:44 2013 New Revision: 196326 URL: http://llvm.org/viewvc/llvm-project?rev=196326&view=rev Log: cleanup includes Modified: vmkit/branches/mcjit/include/j3/j3class.h vmkit/branches/mcjit/include/j3/j3classloader.h vmkit/branches/mcjit/lib/j3/vm/j3.cc vmkit/branches/mcjit/lib/j3/vm/j3class.cc vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc vmkit/branches/mcjit/lib/vmkit/vmkit.cc Modified: vmkit/branches/mcjit/include/j3/j3class.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3class.h?rev=196326&r1=196325&r2=196326&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3class.h (original) +++ vmkit/branches/mcjit/include/j3/j3class.h Tue Dec 3 16:55:44 2013 @@ -8,7 +8,6 @@ #include "j3/j3symbol.h" namespace llvm { - class StructType; class Type; class GlobalValue; class Module; Modified: vmkit/branches/mcjit/include/j3/j3classloader.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3classloader.h?rev=196326&r1=196325&r2=196326&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3classloader.h (original) +++ vmkit/branches/mcjit/include/j3/j3classloader.h Tue Dec 3 16:55:44 2013 @@ -11,17 +11,6 @@ #include "j3/j3object.h" -namespace llvm { - class DataLayout; - class Type; - class Function; - - namespace legacy { - class FunctionPassManager; - } - using legacy::FunctionPassManager; -} - namespace j3 { class J3ZipArchive; class J3ClassBytes; @@ -50,7 +39,6 @@ namespace j3 { J3ObjectHandle* _javaClassLoader; J3FixedPoint _fixedPoint; - llvm::FunctionPassManager* _pm; pthread_mutex_t _mutex; /* a lock */ vmkit::BumpAllocator* _allocator; /* the local allocator */ J3* _vm; /* my vm */ @@ -85,7 +73,6 @@ namespace j3 { vmkit::BumpAllocator* allocator() { return _allocator; } J3* vm() const { return _vm; }; - llvm::FunctionPassManager* pm() { return _pm; } J3Method* method(uint16_t access, J3Class* cl, const vmkit::Name* name, const vmkit::Name* sign); /* find a method ref */ Modified: vmkit/branches/mcjit/lib/j3/vm/j3.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3.cc?rev=196326&r1=196325&r2=196326&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3.cc Tue Dec 3 16:55:44 2013 @@ -8,12 +8,9 @@ #include "j3/j3method.h" #include "j3/j3thread.h" -#include "llvm/IR/Module.h" #include "llvm/IR/Type.h" #include "llvm/IR/DerivedTypes.h" -#include "llvm/ExecutionEngine/ExecutionEngine.h" - using namespace j3; vmkit::T_ptr_less_t J3::charArrayLess; Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=196326&r1=196325&r2=196326&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Tue Dec 3 16:55:44 2013 @@ -3,8 +3,6 @@ #include #include "llvm/ExecutionEngine/ExecutionEngine.h" -#include "llvm/ExecutionEngine/GenericValue.h" -#include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Module.h" #include "llvm/IR/DataLayout.h" Modified: vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc?rev=196326&r1=196325&r2=196326&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc Tue Dec 3 16:55:44 2013 @@ -1,15 +1,6 @@ #include #include -#include "llvm/PassManager.h" -#include "llvm/Linker.h" - -#include "llvm/ExecutionEngine/JIT.h" -#include "llvm/ExecutionEngine/ExecutionEngine.h" - -#include "llvm/IR/LLVMContext.h" -#include "llvm/IR/DerivedTypes.h" - #include "vmkit/allocator.h" #include "j3/j3classloader.h" @@ -242,8 +233,6 @@ bool J3ClassLoader::J3MethodLess::operat J3InitialClassLoader::J3InitialClassLoader(J3* v, const char* rtjar, vmkit::BumpAllocator* _alloc) : J3ClassLoader(v, 0, _alloc) { - llvm::llvm_start_multithreaded(); - const char** archives = J3Lib::systemClassesArchives(); J3ClassBytes* bytes = J3Reader::openFile(allocator(), archives[0]); Modified: vmkit/branches/mcjit/lib/vmkit/vmkit.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/vmkit.cc?rev=196326&r1=196325&r2=196326&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/vmkit.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/vmkit.cc Tue Dec 3 16:55:44 2013 @@ -32,6 +32,7 @@ using namespace vmkit; VMKit::VMKit(vmkit::BumpAllocator* allocator) : mangleMap(Util::char_less, allocator) { llvm::InitializeNativeTarget(); + llvm::llvm_start_multithreaded(); _allocator = allocator; } From gael.thomas at lip6.fr Tue Dec 3 15:06:34 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Tue, 03 Dec 2013 23:06:34 -0000 Subject: [vmkit-commits] [vmkit] r196327 - invokeInternal with a va_list uses now the invokeInternal with a J3Value* Message-ID: <20131203230634.4BDF72A6C029@llvm.org> Author: gthomas Date: Tue Dec 3 17:06:34 2013 New Revision: 196327 URL: http://llvm.org/viewvc/llvm-project?rev=196327&view=rev Log: invokeInternal with a va_list uses now the invokeInternal with a J3Value* Modified: vmkit/branches/mcjit/lib/j3/vm/j3method.cc Modified: vmkit/branches/mcjit/lib/j3/vm/j3method.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3method.cc?rev=196327&r1=196326&r2=196327&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3method.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3method.cc Tue Dec 3 17:06:34 2013 @@ -180,38 +180,38 @@ J3Value J3Method::internalInvoke(bool st } J3Value J3Method::internalInvoke(bool statically, J3ObjectHandle* handle, va_list va) { - std::vector args(methodType()->nbIns()); + J3Value* args = (J3Value*)alloca(sizeof(J3Value)*methodType()->nbIns()); J3* vm = cl()->loader()->vm(); J3Type* cur; uint32_t i = 0; if(handle) - args[i++].PointerVal = handle->obj(); + args[i++].valObject = handle; for(; inbIns(); i++) { /* have to avoid collection at this point */ cur = methodType()->ins(i); if(cur == vm->typeBoolean) - args[i].IntVal = va_arg(va, bool); + args[i].valBoolean = va_arg(va, bool); else if(cur == vm->typeByte) - args[i].IntVal = va_arg(va, int8_t); + args[i].valByte = va_arg(va, int8_t); else if(cur == vm->typeShort) - args[i].IntVal = va_arg(va, int16_t); + args[i].valShort = va_arg(va, int16_t); else if(cur == vm->typeChar) - args[i].IntVal = va_arg(va, uint16_t); + args[i].valChar = va_arg(va, uint16_t); else if(cur == vm->typeInteger) - args[i].IntVal = va_arg(va, int32_t); + args[i].valInteger = va_arg(va, int32_t); else if(cur == vm->typeLong) - args[i].IntVal = va_arg(va, int64_t); + args[i].valLong = va_arg(va, int64_t); else if(cur == vm->typeFloat) - args[i].FloatVal = va_arg(va, float); + args[i].valFloat = va_arg(va, float); else if(cur == vm->typeDouble) - args[i].FloatVal = va_arg(va, double); + args[i].valDouble = va_arg(va, double); else - args[i].PointerVal = va_arg(va, J3ObjectHandle*)->obj(); + args[i].valObject = va_arg(va, J3ObjectHandle*); } - return internalInvoke(statically, &args); + return internalInvoke(statically, 0, args); } J3Value J3Method::internalInvoke(bool statically, J3ObjectHandle* handle, J3Value* inArgs) { From gael.thomas at lip6.fr Tue Dec 3 15:24:15 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Tue, 03 Dec 2013 23:24:15 -0000 Subject: [vmkit-commits] [vmkit] r196330 - Unify invokeInternal with J3Value* and with std::vector Message-ID: <20131203232415.DC0852A6C029@llvm.org> Author: gthomas Date: Tue Dec 3 17:24:15 2013 New Revision: 196330 URL: http://llvm.org/viewvc/llvm-project?rev=196330&view=rev Log: Unify invokeInternal with J3Value* and with std::vector Modified: vmkit/branches/mcjit/include/j3/j3method.h vmkit/branches/mcjit/lib/j3/vm/j3method.cc Modified: vmkit/branches/mcjit/include/j3/j3method.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3method.h?rev=196330&r1=196329&r2=196330&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3method.h (original) +++ vmkit/branches/mcjit/include/j3/j3method.h Tue Dec 3 17:24:15 2013 @@ -75,7 +75,6 @@ namespace j3 { llvm::Type* doNativeType(J3Type* type); - J3Value internalInvoke(bool statically, std::vector* args); J3Value internalInvoke(bool statically, J3ObjectHandle* handle, va_list va); J3Value internalInvoke(bool statically, J3ObjectHandle* handle, J3Value* args); Modified: vmkit/branches/mcjit/lib/j3/vm/j3method.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3method.cc?rev=196330&r1=196329&r2=196330&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3method.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3method.cc Tue Dec 3 17:24:15 2013 @@ -139,23 +139,54 @@ J3Method* J3Method::newMethod(vmkit::Bum return res; } -J3Value J3Method::internalInvoke(bool statically, std::vector* args) { + +J3Value J3Method::internalInvoke(bool statically, J3ObjectHandle* handle, J3Value* inArgs) { + std::vector args(methodType()->nbIns()); + J3* vm = cl()->loader()->vm(); + J3Type* cur; + uint32_t i = 0; + + if(handle) + args[i++].PointerVal = handle->obj(); + + for(; inbIns(); i++) { /* have to avoid collection at this point */ + cur = methodType()->ins(i); + + if(cur == vm->typeBoolean) + args[i].IntVal = inArgs[i].valBoolean; + else if(cur == vm->typeByte) + args[i].IntVal = inArgs[i].valByte; + else if(cur == vm->typeShort) + args[i].IntVal = inArgs[i].valShort; + else if(cur == vm->typeChar) + args[i].IntVal = inArgs[i].valChar; + else if(cur == vm->typeInteger) + args[i].IntVal = inArgs[i].valInteger; + else if(cur == vm->typeLong) + args[i].IntVal = inArgs[i].valLong; + else if(cur == vm->typeFloat) + args[i].FloatVal = inArgs[i].valFloat; + else if(cur == vm->typeDouble) + args[i].FloatVal = inArgs[i].valDouble; + else + args[i].PointerVal = inArgs[i].valObject->obj(); + } + J3Method* target; if(statically) target = this; else { /* can not use trampoline here */ - J3ObjectHandle* self = (J3ObjectHandle*)(*args)[0].PointerVal; + J3ObjectHandle* self = (J3ObjectHandle*)args[0].PointerVal; target = resolve(self); } - fnPtr(); /* ensure that the function is compiled */ - llvm::GenericValue res = cl()->loader()->vm()->ee()->runFunction(_llvmFunction, *args); + target->fnPtr(); /* ensure that the function is compiled */ + llvm::GenericValue res = cl()->loader()->vm()->ee()->runFunction(target->_llvmFunction, args); J3Value holder; - J3* vm = cl()->loader()->vm(); - J3Type* cur = methodType()->out(); + cur = methodType()->out(); if(cur == vm->typeBoolean) holder.valBoolean = (bool)res.IntVal.getZExtValue(); @@ -214,41 +245,6 @@ J3Value J3Method::internalInvoke(bool st return internalInvoke(statically, 0, args); } -J3Value J3Method::internalInvoke(bool statically, J3ObjectHandle* handle, J3Value* inArgs) { - std::vector args(methodType()->nbIns()); - J3* vm = cl()->loader()->vm(); - J3Type* cur; - uint32_t i = 0; - - if(handle) - args[i++].PointerVal = handle->obj(); - - for(; inbIns(); i++) { /* have to avoid collection at this point */ - cur = methodType()->ins(i); - - if(cur == vm->typeBoolean) - args[i].IntVal = inArgs[i].valBoolean; - else if(cur == vm->typeByte) - args[i].IntVal = inArgs[i].valByte; - else if(cur == vm->typeShort) - args[i].IntVal = inArgs[i].valShort; - else if(cur == vm->typeChar) - args[i].IntVal = inArgs[i].valChar; - else if(cur == vm->typeInteger) - args[i].IntVal = inArgs[i].valInteger; - else if(cur == vm->typeLong) - args[i].IntVal = inArgs[i].valLong; - else if(cur == vm->typeFloat) - args[i].FloatVal = inArgs[i].valFloat; - else if(cur == vm->typeDouble) - args[i].FloatVal = inArgs[i].valDouble; - else - args[i].PointerVal = inArgs[i].valObject->obj(); - } - - return internalInvoke(statically, &args); -} - J3Value J3Method::invokeStatic(J3Value* args) { return internalInvoke(1, 0, args); } From gael.thomas at lip6.fr Sun Dec 15 01:39:05 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sun, 15 Dec 2013 09:39:05 -0000 Subject: [vmkit-commits] [vmkit] r197333 - MCJIT works! Message-ID: <20131215093906.00B043128075@llvm.org> Author: gthomas Date: Sun Dec 15 03:39:03 2013 New Revision: 197333 URL: http://llvm.org/viewvc/llvm-project?rev=197333&view=rev Log: MCJIT works! Modified: vmkit/branches/mcjit/ (props changed) vmkit/branches/mcjit/include/j3/j3class.h vmkit/branches/mcjit/include/j3/j3classloader.h vmkit/branches/mcjit/include/j3/j3method.h vmkit/branches/mcjit/include/j3/j3symbol.h vmkit/branches/mcjit/include/vmkit/util.h vmkit/branches/mcjit/include/vmkit/vmkit.h vmkit/branches/mcjit/lib/j3/vm/j3class.cc vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc vmkit/branches/mcjit/lib/j3/vm/j3method.cc vmkit/branches/mcjit/lib/j3/vm/j3options.cc vmkit/branches/mcjit/lib/j3/vm/j3symbol.cc vmkit/branches/mcjit/lib/vmkit/util.cc vmkit/branches/mcjit/lib/vmkit/vmkit.cc Propchange: vmkit/branches/mcjit/ ------------------------------------------------------------------------------ --- svn:ignore (original) +++ svn:ignore Sun Dec 15 03:39:03 2013 @@ -2,3 +2,5 @@ Makefile.config Debug+Asserts config.log config.status +.git +.gitignore Modified: vmkit/branches/mcjit/include/j3/j3class.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3class.h?rev=197333&r1=197332&r2=197333&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3class.h (original) +++ vmkit/branches/mcjit/include/j3/j3class.h Sun Dec 15 03:39:03 2013 @@ -52,6 +52,8 @@ namespace j3 { public: J3Type(J3ClassLoader* loader, const vmkit::Name* name); + uint8_t* getSymbolAddress(); + virtual llvm::GlobalValue* llvmDescriptor(llvm::Module* module) { return 0; } int isTypeDescriptor() { return 1; } Modified: vmkit/branches/mcjit/include/j3/j3classloader.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3classloader.h?rev=197333&r1=197332&r2=197333&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3classloader.h (original) +++ vmkit/branches/mcjit/include/j3/j3classloader.h Sun Dec 15 03:39:03 2013 @@ -11,6 +11,10 @@ #include "j3/j3object.h" +namespace llvm { + class ExecutionEngine; +} + namespace j3 { class J3ZipArchive; class J3ClassBytes; @@ -47,6 +51,9 @@ namespace j3 { vmkit::NameMap::map methodTypes; /* shortcut to find method types - REMOVE */ MethodRefMap methods; /* all te known method */ + llvm::ExecutionEngine* _ee; + llvm::ExecutionEngine* _oldee; + void wrongType(J3Class* from, const vmkit::Name* type); J3Type* getTypeInternal(J3Class* from, const vmkit::Name* type, uint32_t start, uint32_t* end); @@ -60,6 +67,9 @@ namespace j3 { void* operator new(size_t n, vmkit::BumpAllocator* allocator); J3ClassLoader(J3* vm, J3ObjectHandle* javaClassLoader, vmkit::BumpAllocator* allocator); + llvm::ExecutionEngine* ee() { return _ee; } + llvm::ExecutionEngine* oldee() { return _oldee; } + void addSymbol(const char* id, J3Symbol* symbol); static void destroy(J3ClassLoader* loader); Modified: vmkit/branches/mcjit/include/j3/j3method.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3method.h?rev=197333&r1=197332&r2=197333&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3method.h (original) +++ vmkit/branches/mcjit/include/j3/j3method.h Sun Dec 15 03:39:03 2013 @@ -52,7 +52,7 @@ namespace j3 { J3MethodCode(J3Method* _self) { self = _self; } - int isMethodPointer() { return 1; } + uint8_t* getSymbolAddress(); }; class J3Method : public J3Symbol { @@ -67,8 +67,7 @@ namespace j3 { uint32_t _index; llvm::Function* _llvmFunction; uint8_t* _fnPtr; - char* volatile _llvmAllNames; /* md_ + llvm Name */ - size_t _llvmAllNamesLength; + char* volatile _llvmAllNames; /* stub + _ + native_name */ void* _nativeFnPtr; uint8_t _trampoline[1]; @@ -84,7 +83,7 @@ namespace j3 { public: J3Method(uint16_t access, J3Class* cl, const vmkit::Name* name, const vmkit::Name* sign); - int isMethodDescriptor() { return 1; } + uint8_t* getSymbolAddress(); static J3Method* newMethod(vmkit::BumpAllocator* allocator, uint16_t access, @@ -92,9 +91,9 @@ namespace j3 { const vmkit::Name* name, const vmkit::Name* sign); - size_t llvmFunctionNameLength(J3Class* from=0); char* llvmFunctionName(J3Class* from=0); char* llvmDescriptorName(J3Class* from=0); + char* llvmStubName(J3Class* from=0); llvm::FunctionType* llvmType(J3Class* from=0); void postInitialise(uint32_t access, J3Attributes* attributes); @@ -129,8 +128,8 @@ namespace j3 { J3Value invokeVirtual(J3ObjectHandle* obj, J3Value* args); J3Value invokeVirtual(J3ObjectHandle* obj, va_list va); - void* fnPtr(); - void* functionPointerOrTrampoline(); + uint8_t* fnPtr(); + uint8_t* functionPointerOrTrampoline(); void dump(); }; Modified: vmkit/branches/mcjit/include/j3/j3symbol.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3symbol.h?rev=197333&r1=197332&r2=197333&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3symbol.h (original) +++ vmkit/branches/mcjit/include/j3/j3symbol.h Sun Dec 15 03:39:03 2013 @@ -6,7 +6,15 @@ namespace j3 { class J3Symbol : public vmkit::PermanentObject { public: - uint64_t getSymbolAddress(); + virtual uint8_t* getSymbolAddress(); + }; + + class J3NativeSymbol : public J3Symbol { + uint8_t* addr; + public: + J3NativeSymbol(uint8_t* _addr) { addr = _addr; } + + uint8_t* getSymbolAddress() { return addr; } }; }; Modified: vmkit/branches/mcjit/include/vmkit/util.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/util.h?rev=197333&r1=197332&r2=197333&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/util.h (original) +++ vmkit/branches/mcjit/include/vmkit/util.h Sun Dec 15 03:39:03 2013 @@ -8,12 +8,17 @@ namespace vmkit { bool operator()(const char* s1, const char* s2) const; }; + struct char_less_t_dbg { + bool operator()(const char* s1, const char* s2) const; + }; + struct wchar_t_less_t { bool operator()(const wchar_t* lhs, const wchar_t* rhs) const; }; - static struct char_less_t char_less; - static struct wchar_t_less_t wchar_t_less; + static struct char_less_t char_less; + static struct char_less_t_dbg char_less_dbg; + static struct wchar_t_less_t wchar_t_less; }; }; Modified: vmkit/branches/mcjit/include/vmkit/vmkit.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/vmkit.h?rev=197333&r1=197332&r2=197333&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/vmkit.h (original) +++ vmkit/branches/mcjit/include/vmkit/vmkit.h Sun Dec 15 03:39:03 2013 @@ -9,7 +9,6 @@ namespace llvm { class LLVMContext; class Module; - class ExecutionEngine; class DataLayout; class GlobalValue; class Function; @@ -55,13 +54,12 @@ namespace vmkit { MangleMap mangleMap; BumpAllocator* _allocator; llvm::Module* _self; - llvm::ExecutionEngine* _ee; llvm::DataLayout* _dataLayout; void* ptrTypeInfo; - uintptr_t addSymbol(llvm::GlobalValue* gv); + void addSymbol(llvm::GlobalValue* gv); - static void defaultInternalError(const wchar_t* msg, va_list va) __attribute__((noreturn)); + static void defaultInternalError(const wchar_t* msg, va_list va) __attribute__((noreturn)); protected: void* operator new(size_t n, BumpAllocator* allocator); @@ -77,7 +75,6 @@ namespace vmkit { llvm::DataLayout* dataLayout() { return _dataLayout; } llvm::LLVMContext& llvmContext(); llvm::Module* self() { return _self; } - llvm::ExecutionEngine* ee() { return _ee; } llvm::FunctionPassManager* preparePM(llvm::Module* mod); llvm::Function* getGCRoot(llvm::Module* mod); llvm::Function* introspectFunction(llvm::Module* dest, const char* name); Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=197333&r1=197332&r2=197333&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Sun Dec 15 03:39:03 2013 @@ -30,6 +30,10 @@ J3Type::J3Type(J3ClassLoader* loader, co _name = name; } +uint8_t* J3Type::getSymbolAddress() { + return (uint8_t*)this; +} + J3VirtualTable* J3Type::vt() { return _vt; } @@ -196,9 +200,7 @@ size_t J3Class::size() { } llvm::GlobalValue* J3Class::llvmDescriptor(llvm::Module* module) { - llvm::GlobalValue* res = llvm::cast(module->getOrInsertGlobal(nativeName(), loader()->vm()->typeJ3Class)); - loader()->vm()->ee()->updateGlobalMapping(res, this); - return res; + return llvm::cast(module->getOrInsertGlobal(nativeName(), loader()->vm()->typeJ3Class)); } @@ -734,10 +736,10 @@ void J3Class::createLLVMTypes() { mangler.mangle("_2"); _nativeNameLength = mangler.length() - 6; - _nativeName = (char*)loader()->allocator()->allocate(mangler.length() + 1); + _nativeName = (char*)loader()->allocator()->allocate(_nativeNameLength + 1); _nativeName[0] = 'L'; - memcpy(_nativeName + 1, mangler.cStr()+7, mangler.length()); + memcpy(_nativeName + 1, mangler.cStr()+7, _nativeNameLength); /* copy the 0 */ loader()->addSymbol(_nativeName, this); } @@ -832,9 +834,7 @@ void J3ArrayClass::doInitialise() { } llvm::GlobalValue* J3ArrayClass::llvmDescriptor(llvm::Module* module) { - llvm::GlobalValue* res = llvm::cast(module->getOrInsertGlobal(nativeName(), loader()->vm()->typeJ3ArrayClass)); - loader()->vm()->ee()->updateGlobalMapping(res, this); - return res; + return llvm::cast(module->getOrInsertGlobal(nativeName(), loader()->vm()->typeJ3ArrayClass)); } llvm::Type* J3ArrayClass::llvmType() { Modified: vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc?rev=197333&r1=197332&r2=197333&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc Sun Dec 15 03:39:03 2013 @@ -1,6 +1,9 @@ #include #include +#include "llvm/IR/Module.h" +#include "llvm/ExecutionEngine/ExecutionEngine.h" + #include "vmkit/allocator.h" #include "j3/j3classloader.h" @@ -44,6 +47,27 @@ J3ClassLoader::J3ClassLoader(J3* v, J3Ob pthread_mutex_init(&_mutexSymbolTable, 0); _vm = v; + + std::string err; + _ee = llvm::EngineBuilder(new llvm::Module("class-loader", vm()->llvmContext())) + .setUseMCJIT(1) + .setMCJITMemoryManager(this) + .setErrorStr(&err) + .create(); + + if (!ee()) + vm()->internalError(L"Error while creating execution engine: %s\n", err.c_str()); + + ee()->RegisterJITEventListener(vm()); + + _oldee = llvm::EngineBuilder(new llvm::Module("old ee", vm()->llvmContext())) + .setErrorStr(&err) + .create(); + + if (!oldee()) + vm()->internalError(L"Error while creating execution engine: %s\n", err.c_str()); + + oldee()->DisableLazyCompilation(0); } void J3ClassLoader::addSymbol(const char* id, J3Symbol* symbol) { @@ -54,9 +78,25 @@ void J3ClassLoader::addSymbol(const char uint64_t J3ClassLoader::getSymbolAddress(const std::string &Name) { pthread_mutex_lock(&_mutexSymbolTable); - J3Symbol* res = _symbolTable[Name.c_str()]; + const char* id = Name.c_str() + 1; + + std::map::iterator it = _symbolTable.find(id); + J3Symbol* res; + + if(it == _symbolTable.end()) { + uint8_t* addr = (uint8_t*)dlsym(RTLD_SELF, id); + if(!addr) + vm()->internalError(L"unable to resolve native symbol: %s", id); + res = new(allocator()) J3NativeSymbol(addr); + size_t len = strlen(id); + char* buf = (char*)allocator()->allocate(len+1); + memcpy(buf, id, len+1); + _symbolTable[buf] = res; + } else + res = it->second; + pthread_mutex_unlock(&_mutexSymbolTable); - return res->getSymbolAddress(); + return (uint64_t)(uintptr_t)res->getSymbolAddress(); } void* J3ClassLoader::lookupNativeFunctionPointer(J3Method* method, const char* symbol) { Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=197333&r1=197332&r2=197333&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Sun Dec 15 03:39:03 2013 @@ -612,7 +612,7 @@ void J3CodeGen::echoDebugEnter(uint32_t fprintf(stderr, "%*s", prof, ""); if(isLeave) prof -= J3Thread::get()->vm()->options()->debugEnterIndent; - + fprintf(stderr, "%s ", enter); vfprintf(stderr, msg, va); va_end(va); @@ -631,6 +631,7 @@ void J3CodeGen::echoDebugExecute(uint32_ void J3CodeGen::translate() { if(vm->options()->debugTranslate) { fprintf(stderr, " translating bytecode of: %ls::%ls%ls\n", method->cl()->name()->cStr(), method->name()->cStr(), method->sign()->cStr()); + if(vm->options()->debugTranslate > 1) { fprintf(stderr, " exception table:\n"); for(uint32_t i=0; iname()->cStr(), name()->cStr(), sign()->cStr()); if(!isResolved()) { @@ -64,18 +62,27 @@ void* J3Method::fnPtr() { J3CodeGen::translate(this, _llvmFunction); cl()->loader()->vm()->preparePM(module)->run(*_llvmFunction); /* TODO, check memory */ - llvm::ExecutionEngine* ee = cl()->loader()->vm()->ee(); + + llvm::ExecutionEngine* ee = cl()->loader()->ee(); ee->addModule(module); - _fnPtr = (uint8_t*)ee->recompileAndRelinkFunction(_llvmFunction); + _fnPtr = (uint8_t*)ee->getFunctionAddress(_llvmFunction->getName().data()); } return _fnPtr; } -void* J3Method::functionPointerOrTrampoline() { +uint8_t* J3Method::functionPointerOrTrampoline() { return _fnPtr ? _fnPtr : _trampoline; } +uint8_t* J3MethodCode::getSymbolAddress() { + return self->functionPointerOrTrampoline(); +} + +uint8_t* J3Method::getSymbolAddress() { + return (uint8_t*)this; +} + void J3Method::setResolved(uint32_t index) { if(isResolved()) J3::internalError(L"trying to re-resolve a resolved method, should not happen"); @@ -183,7 +190,8 @@ J3Value J3Method::internalInvoke(bool st } target->fnPtr(); /* ensure that the function is compiled */ - llvm::GenericValue res = cl()->loader()->vm()->ee()->runFunction(target->_llvmFunction, args); + cl()->loader()->oldee()->updateGlobalMapping(target->_llvmFunction, target->fnPtr()); + llvm::GenericValue res = cl()->loader()->oldee()->runFunction(target->_llvmFunction, args); J3Value holder; cur = methodType()->out(); @@ -312,54 +320,42 @@ void J3Method::buildLLVMNames(J3Class* f mangler.mangle(mangler.j3Id)->mangle(this)->mangleType(this); - _llvmAllNamesLength = mangler.length() + 18; - _llvmAllNames = (char*)cl()->loader()->allocator()->allocate(_llvmAllNamesLength + 1); - memcpy(_llvmAllNames, "method_descriptor_", 18); - memcpy(_llvmAllNames+18, mangler.cStr(), mangler.length()); - _llvmAllNames[_llvmAllNamesLength] = 0; - - cl()->loader()->addSymbol(_llvmAllNames, this); - cl()->loader()->addSymbol(_llvmAllNames+18, &_selfCode); -} - -size_t J3Method::llvmFunctionNameLength(J3Class* from) { - llvmFunctionName(from); - return _llvmAllNamesLength - 18; + uint32_t length = mangler.length() + 5; + _llvmAllNames = (char*)cl()->loader()->allocator()->allocate(length + 1); + memcpy(_llvmAllNames, "stub_", 5); + memcpy(_llvmAllNames+5, mangler.cStr(), mangler.length()); + _llvmAllNames[length] = 0; + + cl()->loader()->addSymbol(_llvmAllNames, &_selfCode); + cl()->loader()->addSymbol(_llvmAllNames+4, this); + cl()->loader()->addSymbol(_llvmAllNames+5, &_selfCode); } char* J3Method::llvmFunctionName(J3Class* from) { if(!_llvmAllNames) buildLLVMNames(from ? from : cl()); - return _llvmAllNames + 18; + return _llvmAllNames + 5; } char* J3Method::llvmDescriptorName(J3Class* from) { if(!_llvmAllNames) buildLLVMNames(from ? from : cl()); + return _llvmAllNames + 4; +} + +char* J3Method::llvmStubName(J3Class* from) { + if(!_llvmAllNames) + buildLLVMNames(from ? from : cl()); return _llvmAllNames; } llvm::GlobalValue* J3Method::llvmDescriptor(llvm::Module* module) { - J3ClassLoader* loader = cl()->loader(); - llvm::GlobalValue* res = llvm::cast(module->getOrInsertGlobal(llvmDescriptorName(), loader->vm()->typeJ3Method)); - loader->vm()->ee()->updateGlobalMapping(res, this); - return res; + return llvm::cast(module->getOrInsertGlobal(llvmDescriptorName(), cl()->loader()->vm()->typeJ3Method)); } llvm::Function* J3Method::llvmFunction(bool isStub, llvm::Module* module, J3Class* from) { - llvm::Function* res; - - if(isStub) { - char id[llvmFunctionNameLength() + 16]; - memcpy(id, llvmFunctionName(), llvmFunctionNameLength()); - memcpy(id + llvmFunctionNameLength(), "_stub", 6); - res = (llvm::Function*)module->getOrInsertFunction(id, methodType(from ? from : cl())->llvmType()); - } else - res = (llvm::Function*)module->getOrInsertFunction(llvmFunctionName(from), methodType(from ? from : cl())->llvmType()); - - cl()->loader()->vm()->ee()->updateGlobalMapping(res, functionPointerOrTrampoline()); - - return res; + const char* id = (isStub && !_fnPtr) ? llvmStubName(from) : llvmFunctionName(from); + return (llvm::Function*)module->getOrInsertFunction(id, methodType(from ? from : cl())->llvmType()); } void J3Method::dump() { @@ -416,13 +412,16 @@ llvm::Function* J3Method::nativeLLVMFunc nativeOut = doNativeType(type->out()); + char* buf = (char*)cl()->loader()->allocator()->allocate(mangler.length()+1); + memcpy(buf, mangler.cStr(), mangler.length()+1); + llvm::FunctionType* fType = llvm::FunctionType::get(nativeOut, nativeIns, 0); llvm::Function* res = llvm::Function::Create(fType, llvm::GlobalValue::ExternalLinkage, - mangler.cStr(), + buf, module); - loader->vm()->ee()->addGlobalMapping(res, fnPtr); + cl()->loader()->addSymbol(buf, new(cl()->loader()->allocator()) J3NativeSymbol((uint8_t*)fnPtr)); return res; } Modified: vmkit/branches/mcjit/lib/j3/vm/j3options.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3options.cc?rev=197333&r1=197332&r2=197333&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3options.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3options.cc Sun Dec 15 03:39:03 2013 @@ -18,8 +18,8 @@ J3Options::J3Options() { debugLoad = 0; debugResolve = 0; debugIniting = 0; - debugTranslate = 1; - debugLinking = 1; + debugTranslate = 0; + debugLinking = 0; } #define nyi(cmd) ({ fprintf(stderr, "option '%s' not yet implemented\n", cmd); }) Modified: vmkit/branches/mcjit/lib/j3/vm/j3symbol.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3symbol.cc?rev=197333&r1=197332&r2=197333&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3symbol.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3symbol.cc Sun Dec 15 03:39:03 2013 @@ -4,6 +4,6 @@ using namespace j3; -uint64_t J3Symbol::getSymbolAddress() { +uint8_t* J3Symbol::getSymbolAddress() { J3Thread::get()->vm()->internalError(L"implement me: getSymbolAddress"); } Modified: vmkit/branches/mcjit/lib/vmkit/util.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/util.cc?rev=197333&r1=197332&r2=197333&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/util.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/util.cc Sun Dec 15 03:39:03 2013 @@ -5,11 +5,18 @@ using namespace vmkit; -struct Util::char_less_t Util::char_less; -struct Util::wchar_t_less_t Util::wchar_t_less; +struct Util::char_less_t Util::char_less; +struct Util::char_less_t_dbg Util::char_less_dbg; +struct Util::wchar_t_less_t Util::wchar_t_less; -bool Util::char_less_t::operator()(const char* s1, const char* s2) const { - return strcmp(s1, s2) < 0; +bool Util::char_less_t::operator()(const char* lhs, const char* rhs) const { + //printf("Compare: %s - %s - %d\n", lhs, rhs, strcmp(lhs, rhs)); + return strcmp(lhs, rhs) < 0; +} + +bool Util::char_less_t_dbg::operator()(const char* lhs, const char* rhs) const { + printf("Compare: %s - %s - %d\n", lhs, rhs, strcmp(lhs, rhs)); + return strcmp(lhs, rhs) < 0; } bool Util::wchar_t_less_t::operator()(const wchar_t* lhs, const wchar_t* rhs) const { Modified: vmkit/branches/mcjit/lib/vmkit/vmkit.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/vmkit.cc?rev=197333&r1=197332&r2=197333&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/vmkit.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/vmkit.cc Sun Dec 15 03:39:03 2013 @@ -32,6 +32,9 @@ using namespace vmkit; VMKit::VMKit(vmkit::BumpAllocator* allocator) : mangleMap(Util::char_less, allocator) { llvm::InitializeNativeTarget(); + llvm::InitializeNativeTargetAsmPrinter(); + llvm::InitializeNativeTargetAsmParser(); + llvm::InitializeNativeTargetDisassembler(); llvm::llvm_start_multithreaded(); _allocator = allocator; } @@ -60,35 +63,27 @@ llvm::Function* VMKit::introspectFunctio if(!orig) internalError(L"unable to find internal function: %s", name); - return orig; - // return (llvm::Function*)dest->getOrInsertFunction(orig->getName(), orig->getFunctionType()); + return (llvm::Function*)dest->getOrInsertFunction(orig->getName(), orig->getFunctionType()); } llvm::GlobalValue* VMKit::introspectGlobalValue(llvm::Module* dest, const char* name) { - llvm::GlobalValue* res = mangleMap[name]; - if(!res) + llvm::GlobalValue* orig = mangleMap[name]; + if(!orig) internalError(L"unable to find internal global value: %s", name); - return res; + return (llvm::GlobalValue*)dest->getOrInsertGlobal(orig->getName(), orig->getType()); } -uintptr_t VMKit::addSymbol(llvm::GlobalValue* gv) { +void VMKit::addSymbol(llvm::GlobalValue* gv) { const char* id = gv->getName().data(); - void* ptr = dlsym(RTLD_SELF, id); - - if(ptr) { - ee()->updateGlobalMapping(gv, ptr); - int status; - char* realname; - realname = abi::__cxa_demangle(id, 0, 0, &status); - const char* tmp = realname ? realname : id; - uint32_t length = strlen(tmp); - char* mangled = (char*)allocator()->allocate(length+1); - strcpy(mangled, tmp); - mangleMap[mangled] = gv; - free(realname); - return (uintptr_t)ptr; - } else - return 0; + int status; + char* realname; + realname = abi::__cxa_demangle(id, 0, 0, &status); + const char* tmp = realname ? realname : id; + uint32_t length = strlen(tmp); + char* mangled = (char*)allocator()->allocate(length+1); + strcpy(mangled, tmp); + mangleMap[mangled] = gv; + free(realname); } void VMKit::vmkitBootstrap(Thread* initialThread, const char* selfBitCodePath) { @@ -103,13 +98,6 @@ void VMKit::vmkitBootstrap(Thread* initi if(!self()) VMKit::internalError(L"Error while reading bitcode file %s: %s\n", selfBitCodePath, err.c_str()); - _ee = llvm::EngineBuilder(self()).setErrorStr(&err).create(); - if (!ee()) - VMKit::internalError(L"Error while creating execution engine: %s\n", err.c_str()); - - ee()->DisableLazyCompilation(0); - ee()->RegisterJITEventListener(this); - for(llvm::Module::iterator cur=self()->begin(); cur!=self()->end(); cur++) addSymbol(cur); @@ -118,19 +106,11 @@ void VMKit::vmkitBootstrap(Thread* initi _dataLayout = new llvm::DataLayout(self()); - ptrTypeInfo = ee()->getPointerToGlobal(introspectGlobalValue(self(), "typeinfo for void*")); + llvm::GlobalValue* typeInfoGV = mangleMap["typeinfo for void*"]; + ptrTypeInfo = typeInfoGV ? dlsym(RTLD_SELF, typeInfoGV->getName().data()) : 0; if(!ptrTypeInfo) internalError(L"unable to find typeinfo for void*"); - -#if 0 - llvm::Linker* linker = new llvm::Linker(new llvm::Module("linker", vm()->self()->getContext())); - std::string err; - if(linker->linkInModule(vm()->self(), llvm::Linker::PreserveSource, &err)) - J3::internalError(L"unable to add self to linker: %s", err.c_str()); - if(linker->linkInModule(module(), llvm::Linker::PreserveSource, &err)) - J3::internalError(L"unable to add module to linker: %s", err.c_str()); -#endif } From gael.thomas at lip6.fr Sun Dec 15 01:51:18 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sun, 15 Dec 2013 09:51:18 -0000 Subject: [vmkit-commits] [vmkit] r197334 - move symbols in vmkit Message-ID: <20131215095118.389233128075@llvm.org> Author: gthomas Date: Sun Dec 15 03:51:17 2013 New Revision: 197334 URL: http://llvm.org/viewvc/llvm-project?rev=197334&view=rev Log: move symbols in vmkit Added: vmkit/branches/mcjit/include/vmkit/compiler.h vmkit/branches/mcjit/lib/vmkit/compiler.cc Removed: vmkit/branches/mcjit/include/j3/j3symbol.h vmkit/branches/mcjit/lib/j3/vm/j3symbol.cc Modified: vmkit/branches/mcjit/include/j3/j3class.h vmkit/branches/mcjit/include/j3/j3classloader.h vmkit/branches/mcjit/include/j3/j3method.h vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc vmkit/branches/mcjit/lib/j3/vm/j3method.cc Modified: vmkit/branches/mcjit/include/j3/j3class.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3class.h?rev=197334&r1=197333&r2=197334&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3class.h (original) +++ vmkit/branches/mcjit/include/j3/j3class.h Sun Dec 15 03:51:17 2013 @@ -5,7 +5,7 @@ #include #include -#include "j3/j3symbol.h" +#include "vmkit/compiler.h" namespace llvm { class Type; @@ -31,7 +31,7 @@ namespace j3 { class J3ObjectHandle; class J3Field; - class J3Type : public J3Symbol { + class J3Type : public vmkit::Symbol { pthread_mutex_t _mutex; J3ClassLoader* _loader; J3ArrayClass* volatile _array; Modified: vmkit/branches/mcjit/include/j3/j3classloader.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3classloader.h?rev=197334&r1=197333&r2=197334&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3classloader.h (original) +++ vmkit/branches/mcjit/include/j3/j3classloader.h Sun Dec 15 03:51:17 2013 @@ -11,6 +11,10 @@ #include "j3/j3object.h" +namespace vmkit { + class Symbol; +} + namespace llvm { class ExecutionEngine; } @@ -23,7 +27,6 @@ namespace j3 { class J3Type; class J3; class J3Class; - class J3Symbol; class J3ClassLoader : public llvm::SectionMemoryManager { struct J3MethodLess : public std::binary_function { @@ -33,8 +36,8 @@ namespace j3 { typedef std::map > > MethodRefMap; - typedef std::map > > SymbolMap; + typedef std::map > > SymbolMap; static J3MethodLess j3MethodLess; @@ -70,7 +73,7 @@ namespace j3 { llvm::ExecutionEngine* ee() { return _ee; } llvm::ExecutionEngine* oldee() { return _oldee; } - void addSymbol(const char* id, J3Symbol* symbol); + void addSymbol(const char* id, vmkit::Symbol* symbol); static void destroy(J3ClassLoader* loader); Modified: vmkit/branches/mcjit/include/j3/j3method.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3method.h?rev=197334&r1=197333&r2=197334&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3method.h (original) +++ vmkit/branches/mcjit/include/j3/j3method.h Sun Dec 15 03:51:17 2013 @@ -4,7 +4,7 @@ #include #include -#include "j3/j3symbol.h" +#include "vmkit/compiler.h" namespace llvm { class FunctionType; @@ -46,7 +46,7 @@ namespace j3 { } }; - class J3MethodCode : public J3Symbol { + class J3MethodCode : public vmkit::Symbol { public: J3Method* self; @@ -55,7 +55,7 @@ namespace j3 { uint8_t* getSymbolAddress(); }; - class J3Method : public J3Symbol { + class J3Method : public vmkit::Symbol { public: J3MethodCode _selfCode; uint16_t _access; Removed: vmkit/branches/mcjit/include/j3/j3symbol.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3symbol.h?rev=197333&view=auto ============================================================================== --- vmkit/branches/mcjit/include/j3/j3symbol.h (original) +++ vmkit/branches/mcjit/include/j3/j3symbol.h (removed) @@ -1,21 +0,0 @@ -#ifndef _J3_SYMBOL_H_ -#define _J3_SYMBOL_H_ - -#include "vmkit/allocator.h" - -namespace j3 { - class J3Symbol : public vmkit::PermanentObject { - public: - virtual uint8_t* getSymbolAddress(); - }; - - class J3NativeSymbol : public J3Symbol { - uint8_t* addr; - public: - J3NativeSymbol(uint8_t* _addr) { addr = _addr; } - - uint8_t* getSymbolAddress() { return addr; } - }; -}; - -#endif Added: vmkit/branches/mcjit/include/vmkit/compiler.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/compiler.h?rev=197334&view=auto ============================================================================== --- vmkit/branches/mcjit/include/vmkit/compiler.h (added) +++ vmkit/branches/mcjit/include/vmkit/compiler.h Sun Dec 15 03:51:17 2013 @@ -0,0 +1,33 @@ +#ifndef _COMPILER_H_ +#define _COMPILER_H_ + +#include "allocator.h" + +namespace vmkit { + class Symbol : public PermanentObject { + public: + virtual uint8_t* getSymbolAddress(); + }; + + class NativeSymbol : public Symbol { + uint8_t* addr; + public: + NativeSymbol(uint8_t* _addr) { addr = _addr; } + + uint8_t* getSymbolAddress() { return addr; } + }; + +#if 0 + class CompilationFragment { + llvm::Module* _module; + public: + CompilationFragment(); + }; + + class CompilationUnit : public llvm::SectionMemoryManager { + typedef std::map > > SymbolMap; + }; +#endif +} + +#endif Modified: vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc?rev=197334&r1=197333&r2=197334&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc Sun Dec 15 03:51:17 2013 @@ -70,7 +70,7 @@ J3ClassLoader::J3ClassLoader(J3* v, J3Ob oldee()->DisableLazyCompilation(0); } -void J3ClassLoader::addSymbol(const char* id, J3Symbol* symbol) { +void J3ClassLoader::addSymbol(const char* id, vmkit::Symbol* symbol) { pthread_mutex_lock(&_mutexSymbolTable); _symbolTable[id] = symbol; pthread_mutex_unlock(&_mutexSymbolTable); @@ -80,14 +80,14 @@ uint64_t J3ClassLoader::getSymbolAddress pthread_mutex_lock(&_mutexSymbolTable); const char* id = Name.c_str() + 1; - std::map::iterator it = _symbolTable.find(id); - J3Symbol* res; + std::map::iterator it = _symbolTable.find(id); + vmkit::Symbol* res; if(it == _symbolTable.end()) { uint8_t* addr = (uint8_t*)dlsym(RTLD_SELF, id); if(!addr) vm()->internalError(L"unable to resolve native symbol: %s", id); - res = new(allocator()) J3NativeSymbol(addr); + res = new(allocator()) vmkit::NativeSymbol(addr); size_t len = strlen(id); char* buf = (char*)allocator()->allocate(len+1); memcpy(buf, id, len+1); Modified: vmkit/branches/mcjit/lib/j3/vm/j3method.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3method.cc?rev=197334&r1=197333&r2=197334&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3method.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3method.cc Sun Dec 15 03:51:17 2013 @@ -421,7 +421,7 @@ llvm::Function* J3Method::nativeLLVMFunc buf, module); - cl()->loader()->addSymbol(buf, new(cl()->loader()->allocator()) J3NativeSymbol((uint8_t*)fnPtr)); + cl()->loader()->addSymbol(buf, new(cl()->loader()->allocator()) vmkit::NativeSymbol((uint8_t*)fnPtr)); return res; } Removed: vmkit/branches/mcjit/lib/j3/vm/j3symbol.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3symbol.cc?rev=197333&view=auto ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3symbol.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3symbol.cc (removed) @@ -1,9 +0,0 @@ -#include "j3/j3symbol.h" -#include "j3/j3thread.h" -#include "j3/j3.h" - -using namespace j3; - -uint8_t* J3Symbol::getSymbolAddress() { - J3Thread::get()->vm()->internalError(L"implement me: getSymbolAddress"); -} Added: vmkit/branches/mcjit/lib/vmkit/compiler.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/compiler.cc?rev=197334&view=auto ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/compiler.cc (added) +++ vmkit/branches/mcjit/lib/vmkit/compiler.cc Sun Dec 15 03:51:17 2013 @@ -0,0 +1,9 @@ +#include "vmkit/compiler.h" +#include "vmkit/thread.h" +#include "vmkit/vmkit.h" + +using namespace vmkit; + +uint8_t* Symbol::getSymbolAddress() { + Thread::get()->vm()->internalError(L"implement me: getSymbolAddress"); +} From gael.thomas at lip6.fr Sun Dec 15 03:08:02 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sun, 15 Dec 2013 11:08:02 -0000 Subject: [vmkit-commits] [vmkit] r197337 - assesor for module in J3CodeGen Message-ID: <20131215110802.8BE693128075@llvm.org> Author: gthomas Date: Sun Dec 15 05:08:02 2013 New Revision: 197337 URL: http://llvm.org/viewvc/llvm-project?rev=197337&view=rev Log: assesor for module in J3CodeGen Modified: vmkit/branches/mcjit/include/j3/j3codegen.h vmkit/branches/mcjit/include/vmkit/compiler.h vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Modified: vmkit/branches/mcjit/include/j3/j3codegen.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3codegen.h?rev=197337&r1=197336&r2=197337&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3codegen.h (original) +++ vmkit/branches/mcjit/include/j3/j3codegen.h Sun Dec 15 05:08:02 2013 @@ -57,7 +57,7 @@ namespace j3 { friend class J3CodeGenVar; vmkit::BumpAllocator* allocator; - llvm::Module* module; + llvm::Module* _module; llvm::BasicBlock* bb; llvm::IRBuilder<>* builder; llvm::Function* llvmFunction; @@ -96,6 +96,8 @@ namespace j3 { bool isWide; + llvm::Module* module(); + uint32_t wideReadU1(); uint32_t wideReadS1(); Modified: vmkit/branches/mcjit/include/vmkit/compiler.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/compiler.h?rev=197337&r1=197336&r2=197337&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/compiler.h (original) +++ vmkit/branches/mcjit/include/vmkit/compiler.h Sun Dec 15 05:08:02 2013 @@ -1,7 +1,15 @@ #ifndef _COMPILER_H_ #define _COMPILER_H_ +#include "llvm/ExecutionEngine/SectionMemoryManager.h" + #include "allocator.h" +#include "util.h" + +namespace llvm { + class Module; + class ExecutionEngine; +}; namespace vmkit { class Symbol : public PermanentObject { @@ -19,15 +27,29 @@ namespace vmkit { #if 0 class CompilationFragment { + BumpAllocator* _allocator; llvm::Module* _module; + public: - CompilationFragment(); + CompilationFragment(BumpAllocator* allocator); + + BumpAllocator* allocator() { return _allocator; } + llvm::Module* module() { return _module; } }; +#endif class CompilationUnit : public llvm::SectionMemoryManager { - typedef std::map > > SymbolMap; + typedef std::map > > SymbolMap; + + SymbolMap _symbolTable; + pthread_mutex_t _mutexSymbolTable; + llvm::ExecutionEngine* _ee; + llvm::ExecutionEngine* _oldee; + + public: + llvm::ExecutionEngine* ee() { return _ee; } + llvm::ExecutionEngine* oldee() { return _oldee; } }; -#endif } #endif Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=197337&r1=197336&r2=197337&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Sun Dec 15 05:08:02 2013 @@ -45,52 +45,52 @@ J3CodeGen::J3CodeGen(vmkit::BumpAllocato llvmFunction = _llvmFunction; llvmFunction->setGC("vmkit"); - module = llvmFunction->getParent(); + _module = llvmFunction->getParent(); bbCheckCastFailed = 0; bbNullCheckFailed = 0; topPendingBranchs = 0; isWide = 0; - funcJ3MethodIndex = vm->introspectFunction(module, "j3::J3Method::index()"); - funcJ3TypeVT = vm->introspectFunction(module, "j3::J3Type::vt()"); - funcJ3TypeInitialise = vm->introspectFunction(module, "j3::J3Type::initialise()"); - funcJ3ClassSize = vm->introspectFunction(module, "j3::J3Class::size()"); - funcJ3ClassStaticInstance = vm->introspectFunction(module, "j3::J3Class::staticInstance()"); - funcJ3ClassStringAt = vm->introspectFunction(module, "j3::J3Class::stringAt(unsigned short)"); - funcJ3ObjectTypeJavaClass = vm->introspectFunction(module, "j3::J3ObjectType::javaClass()"); - funcJniEnv = vm->introspectFunction(module, "j3::J3::jniEnv()"); - funcJ3ObjectAllocate = vm->introspectFunction(module, "j3::J3Object::allocate(j3::J3VirtualTable*, unsigned long)"); + funcJ3MethodIndex = vm->introspectFunction(module(), "j3::J3Method::index()"); + funcJ3TypeVT = vm->introspectFunction(module(), "j3::J3Type::vt()"); + funcJ3TypeInitialise = vm->introspectFunction(module(), "j3::J3Type::initialise()"); + funcJ3ClassSize = vm->introspectFunction(module(), "j3::J3Class::size()"); + funcJ3ClassStaticInstance = vm->introspectFunction(module(), "j3::J3Class::staticInstance()"); + funcJ3ClassStringAt = vm->introspectFunction(module(), "j3::J3Class::stringAt(unsigned short)"); + funcJ3ObjectTypeJavaClass = vm->introspectFunction(module(), "j3::J3ObjectType::javaClass()"); + funcJniEnv = vm->introspectFunction(module(), "j3::J3::jniEnv()"); + funcJ3ObjectAllocate = vm->introspectFunction(module(), "j3::J3Object::allocate(j3::J3VirtualTable*, unsigned long)"); - funcThrowException = vm->introspectFunction(module, "vmkit::VMKit::throwException(void*)"); - funcClassCastException = vm->introspectFunction(module, "j3::J3::classCastException()"); - funcNullPointerException = vm->introspectFunction(module, "j3::J3::nullPointerException()"); - - funcJ3ThreadPushHandle = vm->introspectFunction(module, "j3::J3Thread::push(j3::J3ObjectHandle*)"); - funcJ3ThreadPush = vm->introspectFunction(module, "j3::J3Thread::push(j3::J3Object*)"); - funcJ3ThreadTell = vm->introspectFunction(module, "j3::J3Thread::tell()"); - funcJ3ThreadRestore = vm->introspectFunction(module, "j3::J3Thread::restore(j3::J3ObjectHandle*)"); - funcJ3ThreadGet = vm->introspectFunction(module, "j3::J3Thread::get()"); - funcEchoDebugEnter = vm->introspectFunction(module, "j3::J3CodeGen::echoDebugEnter(unsigned int, char const*, ...)"); - funcEchoDebugExecute = vm->introspectFunction(module, "j3::J3CodeGen::echoDebugExecute(unsigned int, char const*, ...)"); + funcThrowException = vm->introspectFunction(module(), "vmkit::VMKit::throwException(void*)"); + funcClassCastException = vm->introspectFunction(module(), "j3::J3::classCastException()"); + funcNullPointerException = vm->introspectFunction(module(), "j3::J3::nullPointerException()"); + + funcJ3ThreadPushHandle = vm->introspectFunction(module(), "j3::J3Thread::push(j3::J3ObjectHandle*)"); + funcJ3ThreadPush = vm->introspectFunction(module(), "j3::J3Thread::push(j3::J3Object*)"); + funcJ3ThreadTell = vm->introspectFunction(module(), "j3::J3Thread::tell()"); + funcJ3ThreadRestore = vm->introspectFunction(module(), "j3::J3Thread::restore(j3::J3ObjectHandle*)"); + funcJ3ThreadGet = vm->introspectFunction(module(), "j3::J3Thread::get()"); + funcEchoDebugEnter = vm->introspectFunction(module(), "j3::J3CodeGen::echoDebugEnter(unsigned int, char const*, ...)"); + funcEchoDebugExecute = vm->introspectFunction(module(), "j3::J3CodeGen::echoDebugExecute(unsigned int, char const*, ...)"); - funcSlowIsAssignableTo = vm->introspectFunction(module, "j3::J3VirtualTable::slowIsAssignableTo(j3::J3VirtualTable*)"); + funcSlowIsAssignableTo = vm->introspectFunction(module(), "j3::J3VirtualTable::slowIsAssignableTo(j3::J3VirtualTable*)"); funcFastIsAssignableToPrimaryChecker = - vm->introspectFunction(module, "j3::J3VirtualTable::fastIsAssignableToPrimaryChecker(j3::J3VirtualTable*, unsigned int)"); + vm->introspectFunction(module(), "j3::J3VirtualTable::fastIsAssignableToPrimaryChecker(j3::J3VirtualTable*, unsigned int)"); funcFastIsAssignableToNonPrimaryChecker = - vm->introspectFunction(module, "j3::J3VirtualTable::fastIsAssignableToNonPrimaryChecker(j3::J3VirtualTable*)"); + vm->introspectFunction(module(), "j3::J3VirtualTable::fastIsAssignableToNonPrimaryChecker(j3::J3VirtualTable*)"); - funcGXXPersonality = vm->introspectFunction(module, "__gxx_personality_v0"); - funcCXABeginCatch = vm->introspectFunction(module, "__cxa_begin_catch"); - funcCXAEndCatch = vm->introspectFunction(module, "__cxa_end_catch"); + funcGXXPersonality = vm->introspectFunction(module(), "__gxx_personality_v0"); + funcCXABeginCatch = vm->introspectFunction(module(), "__cxa_begin_catch"); + funcCXAEndCatch = vm->introspectFunction(module(), "__cxa_end_catch"); - gvTypeInfo = vm->introspectGlobalValue(module, "typeinfo for void*"); + gvTypeInfo = vm->introspectGlobalValue(module(), "typeinfo for void*"); - gcRoot = vm->getGCRoot(module); + gcRoot = vm->getGCRoot(module()); ziTry = - (llvm::Function*)module->getOrInsertFunction("vmkit.try", - llvm::FunctionType::get(llvm::Type::getVoidTy(llvmFunction->getContext()), 0)); + (llvm::Function*)module()->getOrInsertFunction("vmkit.try", + llvm::FunctionType::get(llvm::Type::getVoidTy(llvmFunction->getContext()), 0)); bb = newBB("entry"); llvm::IRBuilder<> _builder(bb); @@ -168,12 +168,12 @@ llvm::Value* J3CodeGen::unflatten(llvm:: void J3CodeGen::initialiseJ3Type(J3Type* cl) { if(!cl->isInitialised()) - builder->CreateCall(funcJ3TypeInitialise, builder->CreateBitCast(cl->llvmDescriptor(module), vm->typeJ3TypePtr)); + builder->CreateCall(funcJ3TypeInitialise, builder->CreateBitCast(cl->llvmDescriptor(module()), vm->typeJ3TypePtr)); } llvm::Value* J3CodeGen::javaClass(J3ObjectType* type) { return builder->CreateCall(funcJ3ObjectTypeJavaClass, - builder->CreateBitCast(type->llvmDescriptor(module), vm->typeJ3ObjectTypePtr)); + builder->CreateBitCast(type->llvmDescriptor(module()), vm->typeJ3ObjectTypePtr)); } llvm::Value* J3CodeGen::handleToObject(llvm::Value* obj) { @@ -184,7 +184,7 @@ llvm::Value* J3CodeGen::handleToObject(l llvm::Value* J3CodeGen::staticInstance(J3Class* cl) { initialiseJ3Type(cl); return builder->CreateBitCast(handleToObject(builder->CreateCall(funcJ3ClassStaticInstance, - cl->llvmDescriptor(module))), + cl->llvmDescriptor(module()))), cl->staticLLVMType()); } @@ -197,7 +197,7 @@ llvm::Value* J3CodeGen::vt(llvm::Value* } llvm::Value* J3CodeGen::vt(J3Type* type) { - return builder->CreateCall(funcJ3TypeVT, builder->CreateBitCast(type->llvmDescriptor(module), vm->typeJ3TypePtr)); + return builder->CreateCall(funcJ3TypeVT, builder->CreateBitCast(type->llvmDescriptor(module()), vm->typeJ3TypePtr)); } llvm::Value* J3CodeGen::nullCheck(llvm::Value* obj) { @@ -254,7 +254,7 @@ void J3CodeGen::invokeVirtual(uint32_t i if(target->isResolved()) funcEntry = builder->getInt32(target->index()); else - funcEntry = builder->CreateCall(funcJ3MethodIndex, target->llvmDescriptor(module)); + funcEntry = builder->CreateCall(funcJ3MethodIndex, target->llvmDescriptor(module())); llvm::Value* obj = nullCheck(stack.top(type->nbIns() - 1)); llvm::Value* gepFunc[] = { builder->getInt32(0), @@ -269,12 +269,12 @@ void J3CodeGen::invokeVirtual(uint32_t i void J3CodeGen::invokeStatic(uint32_t idx) { J3Method* target = cl->methodAt(idx, J3Cst::ACC_STATIC); initialiseJ3Type(target->cl()); - invoke(target, target->llvmFunction(1, module, cl)); + invoke(target, target->llvmFunction(1, module(), cl)); } void J3CodeGen::invokeSpecial(uint32_t idx) { J3Method* target = cl->methodAt(idx, 0); - invoke(target, target->llvmFunction(1, module, cl)); + invoke(target, target->llvmFunction(1, module(), cl)); } void J3CodeGen::get(llvm::Value* src, J3Field* f) { @@ -387,7 +387,7 @@ void J3CodeGen::newObject(J3Class* cl) { llvm::Value* size; if(!cl->isResolved()) { - size = builder->CreateCall(funcJ3ClassSize, cl->llvmDescriptor(module)); + size = builder->CreateCall(funcJ3ClassSize, cl->llvmDescriptor(module())); } else { size = builder->getInt64(cl->size()); } @@ -510,7 +510,7 @@ void J3CodeGen::ldc(uint32_t idx) { case J3Cst::CONSTANT_Double: res = llvm::ConstantFP::get(builder->getDoubleTy(), cl->doubleAt(idx)); break; case J3Cst::CONSTANT_Class: res = handleToObject(javaClass(cl->classAt(idx))); break; case J3Cst::CONSTANT_String: - res = handleToObject(builder->CreateCall2(funcJ3ClassStringAt, cl->llvmDescriptor(module), builder->getInt16(idx))); + res = handleToObject(builder->CreateCall2(funcJ3ClassStringAt, cl->llvmDescriptor(module()), builder->getInt16(idx))); break; default: J3::classFormatError(cl, L"wrong ldc type: %d\n", cl->getCtpType(idx)); @@ -590,7 +590,7 @@ llvm::Value* J3CodeGen::buildString(cons elmts.push_back(builder->getInt8(0)); llvm::Constant* str = llvm::ConstantArray::get(llvm::ArrayType::get(builder->getInt8Ty(), n+1), elmts); - llvm::Value* var = new llvm::GlobalVariable(*module, + llvm::Value* var = new llvm::GlobalVariable(*module(), str->getType(), 1, llvm::GlobalVariable::InternalLinkage, @@ -1371,10 +1371,10 @@ void J3CodeGen::generateJava() { J3::classFormatError(cl, L"Code attribute of %ls %ls is too large (%d)", method->name()->cStr(), method->sign()->cStr(), length); nullValue = builder - ->CreateIntToPtr(llvm::ConstantInt::get(vm->dataLayout()->getIntPtrType(module->getContext()), (uintptr_t)0), + ->CreateIntToPtr(llvm::ConstantInt::get(vm->dataLayout()->getIntPtrType(module()->getContext()), (uintptr_t)0), vm->typeJ3ObjectPtr); - llvm::DIBuilder* dbgBuilder = new llvm::DIBuilder(*module); + llvm::DIBuilder* dbgBuilder = new llvm::DIBuilder(*module()); dbgInfo = dbgBuilder->createFunction(llvm::DIDescriptor(), // Function scope @@ -1522,7 +1522,7 @@ void J3CodeGen::generateJava() { void J3CodeGen::generateNative() { std::vector args; - llvm::Function* nat = method->nativeLLVMFunction(module); + llvm::Function* nat = method->nativeLLVMFunction(module()); llvm::Value* res; llvm::Value* thread = builder->CreateCall(funcJ3ThreadGet); From gael.thomas at lip6.fr Sun Dec 15 03:19:31 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sun, 15 Dec 2013 11:19:31 -0000 Subject: [vmkit-commits] [vmkit] r197338 - create a usefull compilation unit class Message-ID: <20131215111931.4551D3128075@llvm.org> Author: gthomas Date: Sun Dec 15 05:19:30 2013 New Revision: 197338 URL: http://llvm.org/viewvc/llvm-project?rev=197338&view=rev Log: create a usefull compilation unit class Modified: vmkit/branches/mcjit/include/j3/j3codegen.h vmkit/branches/mcjit/include/vmkit/compiler.h vmkit/branches/mcjit/lib/vmkit/compiler.cc Modified: vmkit/branches/mcjit/include/j3/j3codegen.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3codegen.h?rev=197338&r1=197337&r2=197338&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3codegen.h (original) +++ vmkit/branches/mcjit/include/j3/j3codegen.h Sun Dec 15 05:19:30 2013 @@ -96,7 +96,7 @@ namespace j3 { bool isWide; - llvm::Module* module(); + llvm::Module* module() { return _module; } uint32_t wideReadU1(); uint32_t wideReadS1(); Modified: vmkit/branches/mcjit/include/vmkit/compiler.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/compiler.h?rev=197338&r1=197337&r2=197338&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/compiler.h (original) +++ vmkit/branches/mcjit/include/vmkit/compiler.h Sun Dec 15 05:19:30 2013 @@ -41,12 +41,25 @@ namespace vmkit { class CompilationUnit : public llvm::SectionMemoryManager { typedef std::map > > SymbolMap; + BumpAllocator* _allocator; SymbolMap _symbolTable; pthread_mutex_t _mutexSymbolTable; llvm::ExecutionEngine* _ee; llvm::ExecutionEngine* _oldee; + void operator delete(void* self); public: + void* operator new(size_t n, BumpAllocator* allocator); + + CompilationUnit(BumpAllocator* allocator, const char* id); + ~CompilationUnit(); + + static void destroy(CompilationUnit* unit); + + void addSymbol(const char* id, vmkit::Symbol* symbol); + uint64_t getSymbolAddress(const std::string &Name); + + BumpAllocator* allocator() { return _allocator; } llvm::ExecutionEngine* ee() { return _ee; } llvm::ExecutionEngine* oldee() { return _oldee; } }; Modified: vmkit/branches/mcjit/lib/vmkit/compiler.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/compiler.cc?rev=197338&r1=197337&r2=197338&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/compiler.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/compiler.cc Sun Dec 15 05:19:30 2013 @@ -1,9 +1,85 @@ +#include + #include "vmkit/compiler.h" #include "vmkit/thread.h" #include "vmkit/vmkit.h" +#include "llvm/ExecutionEngine/ExecutionEngine.h" +#include "llvm/IR/Module.h" + using namespace vmkit; uint8_t* Symbol::getSymbolAddress() { Thread::get()->vm()->internalError(L"implement me: getSymbolAddress"); } + +void* CompilationUnit::operator new(size_t n, BumpAllocator* allocator) { + return allocator->allocate(n); +} + +void CompilationUnit::operator delete(void* self) { +} + +CompilationUnit::CompilationUnit(BumpAllocator* allocator, const char* id) : + _symbolTable(vmkit::Util::char_less, allocator) { + _allocator = allocator; + pthread_mutex_init(&_mutexSymbolTable, 0); + + std::string err; + _ee = llvm::EngineBuilder(new llvm::Module(id, Thread::get()->vm()->llvmContext())) + .setUseMCJIT(1) + .setMCJITMemoryManager(this) + .setErrorStr(&err) + .create(); + + if (!ee()) + Thread::get()->vm()->internalError(L"Error while creating execution engine: %s\n", err.c_str()); + + ee()->RegisterJITEventListener(Thread::get()->vm()); + + _oldee = llvm::EngineBuilder(new llvm::Module("old ee", Thread::get()->vm()->llvmContext())) + .setErrorStr(&err) + .create(); + + if (!oldee()) + Thread::get()->vm()->internalError(L"Error while creating execution engine: %s\n", err.c_str()); + + oldee()->DisableLazyCompilation(0); +} + +CompilationUnit::~CompilationUnit() { +} + +void CompilationUnit::destroy(CompilationUnit* unit) { + delete unit; + BumpAllocator::destroy(unit->allocator()); +} + +void CompilationUnit::addSymbol(const char* id, vmkit::Symbol* symbol) { + pthread_mutex_lock(&_mutexSymbolTable); + _symbolTable[id] = symbol; + pthread_mutex_unlock(&_mutexSymbolTable); +} + +uint64_t CompilationUnit::getSymbolAddress(const std::string &Name) { + pthread_mutex_lock(&_mutexSymbolTable); + const char* id = Name.c_str() + 1; + + std::map::iterator it = _symbolTable.find(id); + vmkit::Symbol* res; + + if(it == _symbolTable.end()) { + uint8_t* addr = (uint8_t*)dlsym(RTLD_SELF, id); + if(!addr) + Thread::get()->vm()->internalError(L"unable to resolve native symbol: %s", id); + res = new(allocator()) vmkit::NativeSymbol(addr); + size_t len = strlen(id); + char* buf = (char*)allocator()->allocate(len+1); + memcpy(buf, id, len+1); + _symbolTable[buf] = res; + } else + res = it->second; + + pthread_mutex_unlock(&_mutexSymbolTable); + return (uint64_t)(uintptr_t)res->getSymbolAddress(); +} From gael.thomas at lip6.fr Sun Dec 15 03:27:15 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sun, 15 Dec 2013 11:27:15 -0000 Subject: [vmkit-commits] [vmkit] r197339 - use my CompilationUnit Message-ID: <20131215112715.3FAA83128075@llvm.org> Author: gthomas Date: Sun Dec 15 05:27:14 2013 New Revision: 197339 URL: http://llvm.org/viewvc/llvm-project?rev=197339&view=rev Log: use my CompilationUnit Modified: vmkit/branches/mcjit/include/j3/j3classloader.h vmkit/branches/mcjit/include/vmkit/compiler.h vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc Modified: vmkit/branches/mcjit/include/j3/j3classloader.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3classloader.h?rev=197339&r1=197338&r2=197339&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3classloader.h (original) +++ vmkit/branches/mcjit/include/j3/j3classloader.h Sun Dec 15 05:27:14 2013 @@ -4,10 +4,9 @@ #include #include -#include "llvm/ExecutionEngine/SectionMemoryManager.h" - #include "vmkit/allocator.h" #include "vmkit/names.h" +#include "vmkit/compiler.h" #include "j3/j3object.h" @@ -28,7 +27,7 @@ namespace j3 { class J3; class J3Class; - class J3ClassLoader : public llvm::SectionMemoryManager { + class J3ClassLoader : public vmkit::CompilationUnit { struct J3MethodLess : public std::binary_function { bool operator()(const J3Method* lhs, const J3Method* rhs) const; }; @@ -36,18 +35,11 @@ namespace j3 { typedef std::map > > MethodRefMap; - typedef std::map > > SymbolMap; - static J3MethodLess j3MethodLess; - SymbolMap _symbolTable; - pthread_mutex_t _mutexSymbolTable; - J3ObjectHandle* _javaClassLoader; J3FixedPoint _fixedPoint; pthread_mutex_t _mutex; /* a lock */ - vmkit::BumpAllocator* _allocator; /* the local allocator */ J3* _vm; /* my vm */ vmkit::NameMap::map classes; /* classes managed by this class loader */ vmkit::NameMap::map types; /* shortcut to find types */ @@ -60,23 +52,12 @@ namespace j3 { void wrongType(J3Class* from, const vmkit::Name* type); J3Type* getTypeInternal(J3Class* from, const vmkit::Name* type, uint32_t start, uint32_t* end); - - uint64_t getSymbolAddress(const std::string &Name); - protected: std::vector > nativeLibraries; public: - void* operator new(size_t n, vmkit::BumpAllocator* allocator); J3ClassLoader(J3* vm, J3ObjectHandle* javaClassLoader, vmkit::BumpAllocator* allocator); - llvm::ExecutionEngine* ee() { return _ee; } - llvm::ExecutionEngine* oldee() { return _oldee; } - - void addSymbol(const char* id, vmkit::Symbol* symbol); - - static void destroy(J3ClassLoader* loader); - J3FixedPoint* fixedPoint() { return &_fixedPoint; } J3ObjectHandle* javaClassLoader() { return _javaClassLoader; } @@ -84,7 +65,6 @@ namespace j3 { void lock() { pthread_mutex_lock(&_mutex); } void unlock() { pthread_mutex_unlock(&_mutex); } - vmkit::BumpAllocator* allocator() { return _allocator; } J3* vm() const { return _vm; }; J3Method* method(uint16_t access, J3Class* cl, @@ -116,7 +96,6 @@ namespace j3 { const char* cmangled(const char* demangled) { return _cmangled[demangled]; } - void makeLLVMFunctions_j3(); void registerCMangling(const char* mangled, const char* demangled); }; } Modified: vmkit/branches/mcjit/include/vmkit/compiler.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/compiler.h?rev=197339&r1=197338&r2=197339&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/compiler.h (original) +++ vmkit/branches/mcjit/include/vmkit/compiler.h Sun Dec 15 05:27:14 2013 @@ -47,7 +47,9 @@ namespace vmkit { llvm::ExecutionEngine* _ee; llvm::ExecutionEngine* _oldee; + protected: void operator delete(void* self); + public: void* operator new(size_t n, BumpAllocator* allocator); Modified: vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc?rev=197339&r1=197338&r2=197339&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc Sun Dec 15 05:27:14 2013 @@ -20,83 +20,22 @@ using namespace j3; J3ClassLoader::J3MethodLess J3ClassLoader::j3MethodLess; -void J3ClassLoader::destroy(J3ClassLoader* loader) { - vmkit::BumpAllocator::destroy(loader->allocator()); -} - -void* J3ClassLoader::operator new(size_t n, vmkit::BumpAllocator* allocator) { - return allocator->allocate(n); -} - J3ClassLoader::J3ClassLoader(J3* v, J3ObjectHandle* javaClassLoader, vmkit::BumpAllocator* allocator) - : _symbolTable(vmkit::Util::char_less, allocator), + : CompilationUnit(allocator, "class-loader"), _fixedPoint(allocator), classes(vmkit::Name::less, allocator), types(vmkit::Name::less, allocator), methodTypes(vmkit::Name::less, allocator), methods(j3MethodLess, allocator), nativeLibraries(allocator) { - _allocator = allocator; - _javaClassLoader = javaClassLoader; // pthread_mutexattr_t attr; // pthread_mutexattr_init(&attr); // pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); pthread_mutex_init(&_mutex, 0);//&attr); - pthread_mutex_init(&_mutexSymbolTable, 0); _vm = v; - - std::string err; - _ee = llvm::EngineBuilder(new llvm::Module("class-loader", vm()->llvmContext())) - .setUseMCJIT(1) - .setMCJITMemoryManager(this) - .setErrorStr(&err) - .create(); - - if (!ee()) - vm()->internalError(L"Error while creating execution engine: %s\n", err.c_str()); - - ee()->RegisterJITEventListener(vm()); - - _oldee = llvm::EngineBuilder(new llvm::Module("old ee", vm()->llvmContext())) - .setErrorStr(&err) - .create(); - - if (!oldee()) - vm()->internalError(L"Error while creating execution engine: %s\n", err.c_str()); - - oldee()->DisableLazyCompilation(0); -} - -void J3ClassLoader::addSymbol(const char* id, vmkit::Symbol* symbol) { - pthread_mutex_lock(&_mutexSymbolTable); - _symbolTable[id] = symbol; - pthread_mutex_unlock(&_mutexSymbolTable); -} - -uint64_t J3ClassLoader::getSymbolAddress(const std::string &Name) { - pthread_mutex_lock(&_mutexSymbolTable); - const char* id = Name.c_str() + 1; - - std::map::iterator it = _symbolTable.find(id); - vmkit::Symbol* res; - - if(it == _symbolTable.end()) { - uint8_t* addr = (uint8_t*)dlsym(RTLD_SELF, id); - if(!addr) - vm()->internalError(L"unable to resolve native symbol: %s", id); - res = new(allocator()) vmkit::NativeSymbol(addr); - size_t len = strlen(id); - char* buf = (char*)allocator()->allocate(len+1); - memcpy(buf, id, len+1); - _symbolTable[buf] = res; - } else - res = it->second; - - pthread_mutex_unlock(&_mutexSymbolTable); - return (uint64_t)(uintptr_t)res->getSymbolAddress(); } void* J3ClassLoader::lookupNativeFunctionPointer(J3Method* method, const char* symbol) { From gael.thomas at lip6.fr Sun Dec 15 04:24:20 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sun, 15 Dec 2013 12:24:20 -0000 Subject: [vmkit-commits] [vmkit] r197341 - use a module pass manager instead of a functionpassmanager Message-ID: <20131215122420.BCC523128075@llvm.org> Author: gthomas Date: Sun Dec 15 06:24:20 2013 New Revision: 197341 URL: http://llvm.org/viewvc/llvm-project?rev=197341&view=rev Log: use a module pass manager instead of a functionpassmanager Modified: vmkit/branches/mcjit/include/vmkit/compiler.h vmkit/branches/mcjit/include/vmkit/vmkit.h vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc vmkit/branches/mcjit/lib/j3/vm/j3method.cc vmkit/branches/mcjit/lib/vmkit/compiler.cc vmkit/branches/mcjit/lib/vmkit/vmkit.cc Modified: vmkit/branches/mcjit/include/vmkit/compiler.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/compiler.h?rev=197341&r1=197340&r2=197341&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/compiler.h (original) +++ vmkit/branches/mcjit/include/vmkit/compiler.h Sun Dec 15 06:24:20 2013 @@ -9,6 +9,12 @@ namespace llvm { class Module; class ExecutionEngine; + + namespace legacy { + class PassManager; + } + using legacy::PassManager; + }; namespace vmkit { @@ -25,19 +31,6 @@ namespace vmkit { uint8_t* getSymbolAddress() { return addr; } }; -#if 0 - class CompilationFragment { - BumpAllocator* _allocator; - llvm::Module* _module; - - public: - CompilationFragment(BumpAllocator* allocator); - - BumpAllocator* allocator() { return _allocator; } - llvm::Module* module() { return _module; } - }; -#endif - class CompilationUnit : public llvm::SectionMemoryManager { typedef std::map > > SymbolMap; @@ -46,6 +39,7 @@ namespace vmkit { pthread_mutex_t _mutexSymbolTable; llvm::ExecutionEngine* _ee; llvm::ExecutionEngine* _oldee; + llvm::PassManager* pm; protected: void operator delete(void* self); @@ -64,6 +58,8 @@ namespace vmkit { BumpAllocator* allocator() { return _allocator; } llvm::ExecutionEngine* ee() { return _ee; } llvm::ExecutionEngine* oldee() { return _oldee; } + + void addModule(llvm::Module* module); }; } Modified: vmkit/branches/mcjit/include/vmkit/vmkit.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/vmkit.h?rev=197341&r1=197340&r2=197341&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/vmkit.h (original) +++ vmkit/branches/mcjit/include/vmkit/vmkit.h Sun Dec 15 06:24:20 2013 @@ -13,10 +13,6 @@ namespace llvm { class GlobalValue; class Function; class Type; - namespace legacy { - class FunctionPassManager; - } - using legacy::FunctionPassManager; } namespace vmkit { @@ -75,7 +71,6 @@ namespace vmkit { llvm::DataLayout* dataLayout() { return _dataLayout; } llvm::LLVMContext& llvmContext(); llvm::Module* self() { return _self; } - llvm::FunctionPassManager* preparePM(llvm::Module* mod); llvm::Function* getGCRoot(llvm::Module* mod); llvm::Function* introspectFunction(llvm::Module* dest, const char* name); llvm::GlobalValue* introspectGlobalValue(llvm::Module* dest, const char* name); Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=197341&r1=197340&r2=197341&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Sun Dec 15 06:24:20 2013 @@ -20,7 +20,6 @@ #include "llvm/DebugInfo.h" #include "llvm/DIBuilder.h" -#include "llvm/PassManager.h" using namespace j3; Modified: vmkit/branches/mcjit/lib/j3/vm/j3method.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3method.cc?rev=197341&r1=197340&r2=197341&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3method.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3method.cc Sun Dec 15 06:24:20 2013 @@ -7,8 +7,6 @@ #include "j3/j3thread.h" #include "j3/j3codegen.h" -#include "llvm/PassManager.h" - #include "llvm/IR/Type.h" #include "llvm/IR/Module.h" #include "llvm/IR/Function.h" @@ -61,10 +59,8 @@ uint8_t* J3Method::fnPtr() { J3CodeGen::translate(this, _llvmFunction); - cl()->loader()->vm()->preparePM(module)->run(*_llvmFunction); /* TODO, check memory */ - llvm::ExecutionEngine* ee = cl()->loader()->ee(); - ee->addModule(module); + cl()->loader()->addModule(module); _fnPtr = (uint8_t*)ee->getFunctionAddress(_llvmFunction->getName().data()); } Modified: vmkit/branches/mcjit/lib/vmkit/compiler.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/compiler.cc?rev=197341&r1=197340&r2=197341&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/compiler.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/compiler.cc Sun Dec 15 06:24:20 2013 @@ -4,7 +4,11 @@ #include "vmkit/thread.h" #include "vmkit/vmkit.h" +#include "llvm/LinkAllPasses.h" +#include "llvm/PassManager.h" + #include "llvm/ExecutionEngine/ExecutionEngine.h" + #include "llvm/IR/Module.h" using namespace vmkit; @@ -45,6 +49,42 @@ CompilationUnit::CompilationUnit(BumpAll Thread::get()->vm()->internalError(L"Error while creating execution engine: %s\n", err.c_str()); oldee()->DisableLazyCompilation(0); + + pm = new llvm::PassManager(); + //pm->add(new llvm::TargetData(*ee->getTargetData())); + + pm->add(llvm::createBasicAliasAnalysisPass()); + + pm->add(llvm::createCFGSimplificationPass()); // Clean up disgusting code + pm->add(llvm::createPromoteMemoryToRegisterPass());// Kill useless allocas + pm->add(llvm::createInstructionCombiningPass()); // Cleanup for scalarrepl. + pm->add(llvm::createScalarReplAggregatesPass()); // Break up aggregate allocas + pm->add(llvm::createInstructionCombiningPass()); // Cleanup for scalarrepl. + pm->add(llvm::createJumpThreadingPass()); // Thread jumps. + pm->add(llvm::createCFGSimplificationPass()); // Merge & remove BBs + pm->add(llvm::createInstructionCombiningPass()); // Combine silly seq's + pm->add(llvm::createCFGSimplificationPass()); // Merge & remove BBs + + pm->add(llvm::createReassociatePass()); // Reassociate expressions + pm->add(llvm::createLoopRotatePass()); // Rotate loops. + pm->add(llvm::createLICMPass()); // Hoist loop invariants + pm->add(llvm::createLoopUnswitchPass()); // Unswitch loops. + pm->add(llvm::createInstructionCombiningPass()); + pm->add(llvm::createIndVarSimplifyPass()); // Canonicalize indvars + pm->add(llvm::createLoopDeletionPass()); // Delete dead loops + pm->add(llvm::createLoopUnrollPass()); // Unroll small loops*/ + pm->add(llvm::createInstructionCombiningPass()); // Clean up after the unroller + pm->add(llvm::createGVNPass()); // Remove redundancies + pm->add(llvm::createMemCpyOptPass()); // Remove memcpy / form memset + pm->add(llvm::createSCCPPass()); // Constant prop with SCCP + + // Run instcombine after redundancy elimination to exploit opportunities + // opened up by them. + pm->add(llvm::createInstructionCombiningPass()); + pm->add(llvm::createJumpThreadingPass()); // Thread jumps + pm->add(llvm::createDeadStoreEliminationPass()); // Delete dead stores + pm->add(llvm::createAggressiveDCEPass()); // Delete dead instructions + pm->add(llvm::createCFGSimplificationPass()); // Merge & remove BBs } CompilationUnit::~CompilationUnit() { @@ -83,3 +123,8 @@ uint64_t CompilationUnit::getSymbolAddre pthread_mutex_unlock(&_mutexSymbolTable); return (uint64_t)(uintptr_t)res->getSymbolAddress(); } + +void CompilationUnit::addModule(llvm::Module* module) { + pm->run(*module); + ee()->addModule(module); +} Modified: vmkit/branches/mcjit/lib/vmkit/vmkit.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/vmkit.cc?rev=197341&r1=197340&r2=197341&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/vmkit.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/vmkit.cc Sun Dec 15 06:24:20 2013 @@ -8,12 +8,10 @@ #include "vmkit/vmkit.h" #include "vmkit/thread.h" -#include "llvm/LinkAllPasses.h" -#include "llvm/PassManager.h" - #include "llvm/IR/Module.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Intrinsics.h" +#include "llvm/IR/DataLayout.h" #include "llvm/ExecutionEngine/ExecutionEngine.h" @@ -118,48 +116,6 @@ llvm::Function* VMKit::getGCRoot(llvm::M return llvm::Intrinsic::getDeclaration(mod, llvm::Intrinsic::gcroot); } -llvm::FunctionPassManager* VMKit::preparePM(llvm::Module* mod) { - llvm::FunctionPassManager* pm = new llvm::FunctionPassManager(mod); - //pm->add(new llvm::TargetData(*ee->getTargetData())); - - pm->add(llvm::createBasicAliasAnalysisPass()); - - pm->add(llvm::createCFGSimplificationPass()); // Clean up disgusting code - pm->add(llvm::createPromoteMemoryToRegisterPass());// Kill useless allocas - pm->add(llvm::createInstructionCombiningPass()); // Cleanup for scalarrepl. - pm->add(llvm::createScalarReplAggregatesPass()); // Break up aggregate allocas - pm->add(llvm::createInstructionCombiningPass()); // Cleanup for scalarrepl. - pm->add(llvm::createJumpThreadingPass()); // Thread jumps. - pm->add(llvm::createCFGSimplificationPass()); // Merge & remove BBs - pm->add(llvm::createInstructionCombiningPass()); // Combine silly seq's - pm->add(llvm::createCFGSimplificationPass()); // Merge & remove BBs - - pm->add(llvm::createReassociatePass()); // Reassociate expressions - pm->add(llvm::createLoopRotatePass()); // Rotate loops. - pm->add(llvm::createLICMPass()); // Hoist loop invariants - pm->add(llvm::createLoopUnswitchPass()); // Unswitch loops. - pm->add(llvm::createInstructionCombiningPass()); - pm->add(llvm::createIndVarSimplifyPass()); // Canonicalize indvars - pm->add(llvm::createLoopDeletionPass()); // Delete dead loops - pm->add(llvm::createLoopUnrollPass()); // Unroll small loops*/ - pm->add(llvm::createInstructionCombiningPass()); // Clean up after the unroller - pm->add(llvm::createGVNPass()); // Remove redundancies - pm->add(llvm::createMemCpyOptPass()); // Remove memcpy / form memset - pm->add(llvm::createSCCPPass()); // Constant prop with SCCP - - // Run instcombine after redundancy elimination to exploit opportunities - // opened up by them. - pm->add(llvm::createInstructionCombiningPass()); - pm->add(llvm::createJumpThreadingPass()); // Thread jumps - pm->add(llvm::createDeadStoreEliminationPass()); // Delete dead stores - pm->add(llvm::createAggressiveDCEPass()); // Delete dead instructions - pm->add(llvm::createCFGSimplificationPass()); // Merge & remove BBs - - pm->doInitialization(); - - return pm; -} - void VMKit::NotifyFunctionEmitted(const llvm::Function &F, void *Code, size_t Size, From gael.thomas at lip6.fr Sun Dec 15 12:47:47 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sun, 15 Dec 2013 20:47:47 -0000 Subject: [vmkit-commits] [vmkit] r197349 - try to retrieve GCMethodInfo Message-ID: <20131215204747.E5D6A2A6C029@llvm.org> Author: gthomas Date: Sun Dec 15 14:47:47 2013 New Revision: 197349 URL: http://llvm.org/viewvc/llvm-project?rev=197349&view=rev Log: try to retrieve GCMethodInfo Modified: vmkit/branches/mcjit/include/vmkit/vmkit.h vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc vmkit/branches/mcjit/lib/vmkit/compiler.cc vmkit/branches/mcjit/lib/vmkit/vmkit.cc Modified: vmkit/branches/mcjit/include/vmkit/vmkit.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/vmkit.h?rev=197349&r1=197348&r2=197349&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/vmkit.h (original) +++ vmkit/branches/mcjit/include/vmkit/vmkit.h Sun Dec 15 14:47:47 2013 @@ -88,6 +88,7 @@ namespace vmkit { size_t Size, const llvm::JITEventListener::EmittedFunctionDetails &Details); + void NotifyObjectEmitted(const llvm::ObjectImage &obj); }; }; Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=197349&r1=197348&r2=197349&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Sun Dec 15 14:47:47 2013 @@ -17,6 +17,7 @@ #include "llvm/IR/Function.h" #include "llvm/IR/Module.h" #include "llvm/IR/Argument.h" +#include "llvm/IR/Intrinsics.h" #include "llvm/DebugInfo.h" #include "llvm/DIBuilder.h" @@ -87,6 +88,9 @@ J3CodeGen::J3CodeGen(vmkit::BumpAllocato gcRoot = vm->getGCRoot(module()); + //llvm::Intrinsic::getDeclaration(module(), llvm::Intrinsic::experimental_patchpoint_i64); + + ziTry = (llvm::Function*)module()->getOrInsertFunction("vmkit.try", llvm::FunctionType::get(llvm::Type::getVoidTy(llvmFunction->getContext()), 0)); Modified: vmkit/branches/mcjit/lib/vmkit/compiler.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/compiler.cc?rev=197349&r1=197348&r2=197349&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/compiler.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/compiler.cc Sun Dec 15 14:47:47 2013 @@ -88,6 +88,9 @@ CompilationUnit::CompilationUnit(BumpAll } CompilationUnit::~CompilationUnit() { + delete pm; + delete _ee; + delete _oldee; } void CompilationUnit::destroy(CompilationUnit* unit) { Modified: vmkit/branches/mcjit/lib/vmkit/vmkit.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/vmkit.cc?rev=197349&r1=197348&r2=197349&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/vmkit.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/vmkit.cc Sun Dec 15 14:47:47 2013 @@ -116,10 +116,17 @@ llvm::Function* VMKit::getGCRoot(llvm::M return llvm::Intrinsic::getDeclaration(mod, llvm::Intrinsic::gcroot); } +void VMKit::NotifyObjectEmitted(const llvm::ObjectImage &obj) { + fprintf(stderr, "**** object jit event listener!\n"); +} + void VMKit::NotifyFunctionEmitted(const llvm::Function &F, void *Code, size_t Size, const llvm::JITEventListener::EmittedFunctionDetails &Details) { + + fprintf(stderr, "**** jit event listener!\n"); + const llvm::MachineFunction* mf = Details.MF; const std::vector& landingPads = mf->getMMI().getLandingPads(); const llvm::MachineCodeEmitter* mce = Details.MCE; From gael.thomas at lip6.fr Fri Dec 20 05:43:30 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Fri, 20 Dec 2013 13:43:30 -0000 Subject: [vmkit-commits] [vmkit] r197811 - A lot of changes: Message-ID: <20131220134330.253812A6C029@llvm.org> Author: gthomas Date: Fri Dec 20 07:43:29 2013 New Revision: 197811 URL: http://llvm.org/viewvc/llvm-project?rev=197811&view=rev Log: A lot of changes: * add a configure option to link vmkit with a different llvm library. Usefull to use an optimized version of llvm for compilation and a debug version of llvm at runtime * find safepoint intrinsics. Not very interesting as I don't use them for the moment. * save mmx registers in the trampoline (was a bug). * generate stack map directly in the section data with MCJIT through GCMetadatPrinter::finishAssembly. * generate safepoint with MCJIT. Safepoint are just printed for the moment. Modified: vmkit/branches/mcjit/autoconf/configure.ac vmkit/branches/mcjit/configure vmkit/branches/mcjit/include/j3/j3codegen.h vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc vmkit/branches/mcjit/lib/j3/vm/j3method.cc vmkit/branches/mcjit/lib/j3/vm/j3object.cc vmkit/branches/mcjit/lib/j3/vm/j3options.cc vmkit/branches/mcjit/lib/vmkit/gcrootpass.cc vmkit/branches/mcjit/lib/vmkit/vmkit.cc Modified: vmkit/branches/mcjit/autoconf/configure.ac URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/autoconf/configure.ac?rev=197811&r1=197810&r2=197811&view=diff ============================================================================== --- vmkit/branches/mcjit/autoconf/configure.ac (original) +++ vmkit/branches/mcjit/autoconf/configure.ac Fri Dec 20 07:43:29 2013 @@ -160,17 +160,28 @@ if test ! -x "$LLVM_CONFIG"; then AC_MSG_ERROR([Cannot find $LLVM_CONFIG (or not executable)]) fi +AC_ARG_WITH(llvm-runtime-config-path, + [AS_HELP_STRING(--with-llvm-runtime-config-path=path, + [llvm-runtime-config path (use llvm-config-path)])], + [[LLVM_RUNTIME_CONFIG=$with_llvm_runtime_config_path]], + [[LLVM_RUNTIME_CONFIG="$LLVM_CONFIG"]] +) + +if test ! -x "$LLVM_RUNTIME_CONFIG"; then + AC_MSG_ERROR([Cannot find $LLVM_RUNTIME_CONFIG (or not executable)]) +fi + LLVM_PATH="`$LLVM_CONFIG --bindir`" -llvm_cfg=`$LLVM_CONFIG --cxxflags | sed -e 's/-O3//'` +llvm_cfg=`$LLVM_RUNTIME_CONFIG --cxxflags | sed -e 's/-O3//'` if ! test -z "`echo $llvm_cfg | grep -- -fno-exceptions`"; then AC_MSG_ERROR([You have to compile LLVM with exception enabled, please compile it with 'make REQUIRES_EH=1']) fi -AC_SUBST(LLVM_CXXFLAGS, [$llvm_cfg" "-I`$LLVM_CONFIG --src-root`/include]) -AC_SUBST(LLVM_LIBS, [`$LLVM_CONFIG --libs`]) -AC_SUBST(LLVM_LDFLAGS, [`$LLVM_CONFIG --ldflags`]) +AC_SUBST(LLVM_CXXFLAGS, [$llvm_cfg" "-I`$LLVM_RUNTIME_CONFIG --src-root`/include]) +AC_SUBST(LLVM_LIBS, [`$LLVM_RUNTIME_CONFIG --libs | tr '\n' ' '`]) +AC_SUBST(LLVM_LDFLAGS, [`$LLVM_RUNTIME_CONFIG --ldflags`]) dnl ************************************************************************** dnl clang Modified: vmkit/branches/mcjit/configure URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/configure?rev=197811&r1=197810&r2=197811&view=diff ============================================================================== --- vmkit/branches/mcjit/configure (original) +++ vmkit/branches/mcjit/configure Fri Dec 20 07:43:29 2013 @@ -677,6 +677,7 @@ enable_optimized enable_debug enable_assert with_llvm_config_path +with_llvm_runtime_config_path with_clang_path with_jdkhome ' @@ -1313,6 +1314,8 @@ Optional Packages: --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --with-llvm-config-path=path llvm-config path (use default path) + --with-llvm-runtime-config-path=path + llvm-runtime-config path (use llvm-config-path) --with-clang-path=path clang path (use llvm-config --bindir and then default path) --with-jdkhome Build J3 with OpenJDK JRE install (default is @@ -2113,19 +2116,33 @@ if test ! -x "$LLVM_CONFIG"; then as_fn_error $? "Cannot find $LLVM_CONFIG (or not executable)" "$LINENO" 5 fi + +# Check whether --with-llvm-runtime-config-path was given. +if test "${with_llvm_runtime_config_path+set}" = set; then : + withval=$with_llvm_runtime_config_path; LLVM_RUNTIME_CONFIG=$with_llvm_runtime_config_path +else + LLVM_RUNTIME_CONFIG="$LLVM_CONFIG" + +fi + + +if test ! -x "$LLVM_RUNTIME_CONFIG"; then + as_fn_error $? "Cannot find $LLVM_RUNTIME_CONFIG (or not executable)" "$LINENO" 5 +fi + LLVM_PATH="`$LLVM_CONFIG --bindir`" -llvm_cfg=`$LLVM_CONFIG --cxxflags | sed -e 's/-O3//'` +llvm_cfg=`$LLVM_RUNTIME_CONFIG --cxxflags | sed -e 's/-O3//'` if ! test -z "`echo $llvm_cfg | grep -- -fno-exceptions`"; then as_fn_error $? "You have to compile LLVM with exception enabled, please compile it with 'make REQUIRES_EH=1'" "$LINENO" 5 fi -LLVM_CXXFLAGS=$llvm_cfg" "-I`$LLVM_CONFIG --src-root`/include +LLVM_CXXFLAGS=$llvm_cfg" "-I`$LLVM_RUNTIME_CONFIG --src-root`/include -LLVM_LIBS=`$LLVM_CONFIG --libs` +LLVM_LIBS=`$LLVM_RUNTIME_CONFIG --libs | tr '\n' ' '` -LLVM_LDFLAGS=`$LLVM_CONFIG --ldflags` +LLVM_LDFLAGS=`$LLVM_RUNTIME_CONFIG --ldflags` Modified: vmkit/branches/mcjit/include/j3/j3codegen.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3codegen.h?rev=197811&r1=197810&r2=197811&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3codegen.h (original) +++ vmkit/branches/mcjit/include/j3/j3codegen.h Fri Dec 20 07:43:29 2013 @@ -193,6 +193,9 @@ namespace j3 { llvm::Function* funcCXAEndCatch; /* __cxa_end_catch */ llvm::Function* funcGXXPersonality; /* __gxx_personality_v0 */ llvm::Function* gcRoot; + llvm::Function* stackMap; + llvm::Function* patchPoint64; + llvm::Function* patchPointVoid; llvm::Function* ziTry; llvm::GlobalValue* gvTypeInfo; /* typename void* */ Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=197811&r1=197810&r2=197811&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Fri Dec 20 07:43:29 2013 @@ -52,6 +52,11 @@ J3CodeGen::J3CodeGen(vmkit::BumpAllocato topPendingBranchs = 0; isWide = 0; + bb = newBB("entry"); + llvm::IRBuilder<> _builder(bb); + + builder = &_builder; + funcJ3MethodIndex = vm->introspectFunction(module(), "j3::J3Method::index()"); funcJ3TypeVT = vm->introspectFunction(module(), "j3::J3Type::vt()"); funcJ3TypeInitialise = vm->introspectFunction(module(), "j3::J3Type::initialise()"); @@ -88,18 +93,26 @@ J3CodeGen::J3CodeGen(vmkit::BumpAllocato gcRoot = vm->getGCRoot(module()); - //llvm::Intrinsic::getDeclaration(module(), llvm::Intrinsic::experimental_patchpoint_i64); - +#if 0 + //stackMap = llvm::Intrinsic::getDeclaration(module(), llvm::Intrinsic::experimental_stackmap); + //patchPointVoid = llvm::Intrinsic::getDeclaration(module(), llvm::Intrinsic::experimental_patchpoint_i64); + { + llvm::Type* ins[] = { + builder->getInt64Ty(), + builder->getInt32Ty(), + builder->getInt8PtrTy(), + builder->getInt32Ty() + }; + patchPointVoid = (llvm::Function*) + module()->getOrInsertFunction(llvm::Intrinsic::getName(llvm::Intrinsic::experimental_patchpoint_void), + llvm::FunctionType::get(builder->getVoidTy(), ins, 1)); + } +#endif ziTry = (llvm::Function*)module()->getOrInsertFunction("vmkit.try", llvm::FunctionType::get(llvm::Type::getVoidTy(llvmFunction->getContext()), 0)); - bb = newBB("entry"); - llvm::IRBuilder<> _builder(bb); - - builder = &_builder; - if(J3Cst::isNative(method->access())) generateNative(); else @@ -655,10 +668,28 @@ void J3CodeGen::translate() { if(vm->options()->genDebugExecute) { char buf[256]; snprintf(buf, 256, "%ls::%ls", method->cl()->name()->cStr(), method->name()->cStr()); +#if 0 + + fprintf(stderr, "bitcast: "); + builder->CreateBitCast(funcEchoDebugEnter, builder->getInt8PtrTy())->dump(); + fprintf(stderr, "\n"); + + llvm::Value* args[] = { + builder->getInt64(42), /* patch point id */ + builder->getInt32(0), /* pad */ + builder->CreateBitCast(funcEchoDebugEnter, builder->getInt8PtrTy()), /* function funcEchoDebugEnter */ + builder->getInt32(3), /* number of args */ + builder->getInt32(0), /* arg[0] */ + buildString("bip %s\n"), /* arg[1] */ + buildString(buf) /* arg[2] */ + }; + builder->CreateCall(patchPointVoid, args)->dump(); +#else builder->CreateCall3(funcEchoDebugEnter, builder->getInt32(0), buildString("%s\n"), buildString(buf)); +#endif } while(codeReader->remaining()) { Modified: vmkit/branches/mcjit/lib/j3/vm/j3method.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3method.cc?rev=197811&r1=197810&r2=197811&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3method.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3method.cc Fri Dec 20 07:43:29 2013 @@ -42,6 +42,14 @@ uint32_t J3Method::index() { return _index; } +struct safepoint_t { + void* addr; + void* metaData; + uint32_t sourceIndex; + uint32_t nbLives; + uint32_t lives[2]; +}; /* aligned on a 8-byte boundary on a 64 bit machine, on a 4-byte boundary otherwise */ + uint8_t* J3Method::fnPtr() { if(!_fnPtr) { //fprintf(stderr, "materializing: %ls::%ls%ls\n", cl()->name()->cStr(), name()->cStr(), sign()->cStr()); @@ -62,6 +70,29 @@ uint8_t* J3Method::fnPtr() { llvm::ExecutionEngine* ee = cl()->loader()->ee(); cl()->loader()->addModule(module); _fnPtr = (uint8_t*)ee->getFunctionAddress(_llvmFunction->getName().data()); + +#if 1 + fprintf(stderr, "%s is generated at %p\n", llvmFunctionName(), _fnPtr); + llvm::SmallString<256> symName; + symName += module->getModuleIdentifier(); + symName += "__frametable"; + struct safepoint_t* sf = (safepoint_t*)ee->getGlobalValueAddress(symName.c_str()); + + if(!sf) + cl()->loader()->vm()->internalError(L"unable to find safepoints"); + + while(sf->addr) { + fprintf(stderr, " [%p] safepoint at %p for function %p::%d\n", sf, sf->addr, sf->metaData, sf->sourceIndex); + for(uint32_t i=0; inbLives; i++) + fprintf(stderr, " live at %d\n", sf->lives[i]); + + uintptr_t next = (uintptr_t)sf + sizeof(struct safepoint_t) - 2*sizeof(uint32_t) + sf->nbLives*sizeof(uint32_t); + //fprintf(stderr, "next at 0x%lx %ld %ld %ld\n", next, + //sizeof(struct safepoint_t), sf->nbLives*sizeof(uint32_t), 2*sizeof(uint32_t)); + sf = (struct safepoint_t*)(((next - 1) & -sizeof(uintptr_t)) + sizeof(uintptr_t)); + //fprintf(stderr, "=> %p\n", sf); + } +#endif } return _fnPtr; @@ -108,7 +139,7 @@ J3Method* J3Method::newMethod(vmkit::Bum J3Class* cl, const vmkit::Name* name, const vmkit::Name* sign) { - size_t trampolineSize = 48; + size_t trampolineSize = 148; void* tra = (void*)J3ObjectHandle::trampoline; J3Method* res = new(allocator, trampolineSize) J3Method(access, cl, name, sign); @@ -121,19 +152,35 @@ J3Method* J3Method::newMethod(vmkit::Bum 0x51, // 3: push %rcx 0x41, 0x50, // 4: push %r8 0x41, 0x51, // 6: push %r9 - 0x48, 0x83, 0xc4, 0x08, // 8: sub %esp, 8 - 0x48, 0xbe, dd(res, 0), dd(res, 8), dd(res, 16), dd(res, 24), dd(res, 32), dd(res, 40), dd(res, 48), dd(res, 56), // 12: mov -> %rsi - 0x48, 0xb8, dd(tra, 0), dd(tra, 8), dd(tra, 16), dd(tra, 24), dd(tra, 32), dd(tra, 40), dd(tra, 48), dd(tra, 56), // 22: mov -> %rax - 0xff, 0xd0, // 32: call %rax - 0x48, 0x83, 0xec, 0x08, // 34: add %esp, 8 - 0x41, 0x59, // 38: pop %r9 - 0x41, 0x58, // 40: pop %r8 - 0x59, // 42: pop %rcx - 0x5a, // 43: pop %rdx - 0x5e, // 44: pop %rsi - 0x5f, // 45: pop %rdi - 0xff, 0xe0 // 46: jmp %rax - // total: 48 + 0x48, 0x81, 0xec, 0x88, 0x00, 0x00, 0x00, // 8: sub $128+8, %esp + 0xf3, 0x0f, 0x11, 0x04, 0x24, // 15: movss %xmm0, (%rsp) + 0xf3, 0x0f, 0x11, 0x4c, 0x24, 0x10, // 20: movss %xmm1, 16(%rsp) + 0xf3, 0x0f, 0x11, 0x54, 0x24, 0x20, // 26: movss %xmm2, 32(%rsp) + 0xf3, 0x0f, 0x11, 0x5c, 0x24, 0x30, // 32: movss %xmm3, 48(%rsp) + 0xf3, 0x0f, 0x11, 0x64, 0x24, 0x40, // 38: movss %xmm4, 64(%rsp) + 0xf3, 0x0f, 0x11, 0x6c, 0x24, 0x50, // 44: movss %xmm5, 80(%rsp) + 0xf3, 0x0f, 0x11, 0x74, 0x24, 0x60, // 50: movss %xmm6, 96(%rsp) + 0xf3, 0x0f, 0x11, 0x7c, 0x24, 0x70, // 56: movss %xmm7, 112(%rsp) + 0x48, 0xbe, dd(res, 0), dd(res, 8), dd(res, 16), dd(res, 24), dd(res, 32), dd(res, 40), dd(res, 48), dd(res, 56), // 62: mov -> %rsi + 0x48, 0xb8, dd(tra, 0), dd(tra, 8), dd(tra, 16), dd(tra, 24), dd(tra, 32), dd(tra, 40), dd(tra, 48), dd(tra, 56), // 72: mov -> %rax + 0xff, 0xd0, // 82: call %rax + 0xf3, 0x0f, 0x10, 0x04, 0x24, // 84: movss (%rsp), %xmm0 + 0xf3, 0x0f, 0x10, 0x4c, 0x24, 0x10, // 89: movss 16(%rsp), %xmm1 + 0xf3, 0x0f, 0x10, 0x54, 0x24, 0x20, // 95: movss 32(%rsp), %xmm2 + 0xf3, 0x0f, 0x10, 0x5c, 0x24, 0x30, // 101: movss 48(%rsp), %xmm3 + 0xf3, 0x0f, 0x10, 0x64, 0x24, 0x40, // 107: movss 64(%rsp), %xmm4 + 0xf3, 0x0f, 0x10, 0x6c, 0x24, 0x50, // 113: movss 80(%rsp), %xmm5 + 0xf3, 0x0f, 0x10, 0x74, 0x24, 0x60, // 119: movss 96(%rsp), %xmm6 + 0xf3, 0x0f, 0x10, 0x7c, 0x24, 0x70, // 125: movss 112(%rsp), %xmm7 + 0x48, 0x81, 0xc4, 0x88, 0x00, 0x00, 0x00, // 131: add $128+8, %esp + 0x41, 0x59, // 138: pop %r9 + 0x41, 0x58, // 140: pop %r8 + 0x59, // 142: pop %rcx + 0x5a, // 143: pop %rdx + 0x5e, // 144: pop %rsi + 0x5f, // 145: pop %rdi + 0xff, 0xe0 // 146: jmp %rax + // total: 148 }; #undef dd @@ -312,19 +359,21 @@ J3MethodType* J3Method::methodType(J3Cla } void J3Method::buildLLVMNames(J3Class* from) { + const char* prefix = "stub_"; + uint32_t plen = 5; J3Mangler mangler(from); mangler.mangle(mangler.j3Id)->mangle(this)->mangleType(this); - uint32_t length = mangler.length() + 5; + uint32_t length = mangler.length() + plen; _llvmAllNames = (char*)cl()->loader()->allocator()->allocate(length + 1); - memcpy(_llvmAllNames, "stub_", 5); - memcpy(_llvmAllNames+5, mangler.cStr(), mangler.length()); + memcpy(_llvmAllNames, prefix, plen); + memcpy(_llvmAllNames+plen, mangler.cStr(), mangler.length()); _llvmAllNames[length] = 0; - cl()->loader()->addSymbol(_llvmAllNames, &_selfCode); + cl()->loader()->addSymbol(_llvmAllNames+0, &_selfCode); cl()->loader()->addSymbol(_llvmAllNames+4, this); - cl()->loader()->addSymbol(_llvmAllNames+5, &_selfCode); + cl()->loader()->addSymbol(_llvmAllNames+plen, &_selfCode); } char* J3Method::llvmFunctionName(J3Class* from) { @@ -342,7 +391,7 @@ char* J3Method::llvmDescriptorName(J3Cla char* J3Method::llvmStubName(J3Class* from) { if(!_llvmAllNames) buildLLVMNames(from ? from : cl()); - return _llvmAllNames; + return _llvmAllNames + 0; } llvm::GlobalValue* J3Method::llvmDescriptor(llvm::Module* module) { Modified: vmkit/branches/mcjit/lib/j3/vm/j3object.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3object.cc?rev=197811&r1=197810&r2=197811&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3object.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3object.cc Fri Dec 20 07:43:29 2013 @@ -1,4 +1,5 @@ #include +#include #include "llvm/IR/DataLayout.h" #include "llvm/ExecutionEngine/ExecutionEngine.h" Modified: vmkit/branches/mcjit/lib/j3/vm/j3options.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3options.cc?rev=197811&r1=197810&r2=197811&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3options.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3options.cc Fri Dec 20 07:43:29 2013 @@ -13,13 +13,14 @@ J3Options::J3Options() { debugEnterIndent = 1; - genDebugExecute = 1; debugExecute = 0; debugLoad = 0; debugResolve = 0; debugIniting = 0; debugTranslate = 0; debugLinking = 0; + + genDebugExecute = debugExecute ? 1 : 0; } #define nyi(cmd) ({ fprintf(stderr, "option '%s' not yet implemented\n", cmd); }) Modified: vmkit/branches/mcjit/lib/vmkit/gcrootpass.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/gcrootpass.cc?rev=197811&r1=197810&r2=197811&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/gcrootpass.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/gcrootpass.cc Fri Dec 20 07:43:29 2013 @@ -1,14 +1,28 @@ +#include "llvm/IR/Function.h" +#include "llvm/IR/Constants.h" +#include "llvm/IR/Module.h" +#include "llvm/IR/DataLayout.h" + #include "llvm/CodeGen/GCs.h" #include "llvm/CodeGen/GCStrategy.h" +#include "llvm/CodeGen/AsmPrinter.h" +#include "llvm/CodeGen/GCMetadataPrinter.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineInstrBuilder.h" #include "llvm/MC/MCContext.h" +#include "llvm/MC/MCAsmInfo.h" +#include "llvm/MC/MCExpr.h" +#include "llvm/MC/MCSymbol.h" +#include "llvm/MC/MCStreamer.h" +#include "llvm/MC/MCSection.h" #include "llvm/Support/Compiler.h" #include "llvm/Target/TargetInstrInfo.h" #include "llvm/Target/TargetMachine.h" +#include "llvm/Target/Mangler.h" +#include "llvm/Target/TargetLoweringObjectFile.h" using namespace llvm; @@ -25,6 +39,7 @@ namespace vmkit { VmkitGCPass::VmkitGCPass() { CustomSafePoints = true; + UsesMetadata = true; InitRoots = 1; } @@ -55,4 +70,66 @@ namespace vmkit { return false; } + + class VmkitGCMetadataPrinter : public GCMetadataPrinter { + public: + void beginAssembly(AsmPrinter &AP); + void finishAssembly(AsmPrinter &AP); + }; + + static GCMetadataPrinterRegistry::Add + Y("vmkit", "VMKit garbage-collector"); + + void VmkitGCMetadataPrinter::beginAssembly(AsmPrinter &AP) {} + + void VmkitGCMetadataPrinter::finishAssembly(AsmPrinter &AP) { + AP.OutStreamer.SwitchSection(AP.getObjFileLowering().getDataSection()); + + unsigned IntPtrSize = AP.TM.getDataLayout()->getPointerSize(0); + + SmallString<256> symName("_"); + symName += getModule().getModuleIdentifier(); + symName += "__frametable"; + + MCSymbol *sym = AP.OutContext.GetOrCreateSymbol(symName); + AP.OutStreamer.EmitSymbolAttribute(sym, MCSA_Global); + + AP.EmitAlignment(IntPtrSize == 4 ? 2 : 3); + + AP.OutStreamer.AddComment("--- module frame tables ---"); + AP.OutStreamer.AddBlankLine(); + AP.OutStreamer.EmitLabel(sym); + + for (iterator I = begin(), IE = end(); I != IE; ++I) { + GCFunctionInfo* gcInfo = *I; + + if(gcInfo->getFunction().hasGC()) { + AP.OutStreamer.AddComment("live roots for " + Twine(gcInfo->getFunction().getName())); + AP.OutStreamer.AddBlankLine(); + for(llvm::GCFunctionInfo::iterator safepoint=gcInfo->begin(); safepoint!=gcInfo->end(); safepoint++) { + DebugLoc* debug = &safepoint->Loc; + uint32_t kind = safepoint->Kind; + + const MCExpr* address = MCSymbolRefExpr::Create(safepoint->Label, AP.OutStreamer.getContext()); + if (debug->getCol() == 1) { + const MCExpr* one = MCConstantExpr::Create(1, AP.OutStreamer.getContext()); + address = MCBinaryExpr::CreateAdd(address, one, AP.OutStreamer.getContext()); + } + + AP.OutStreamer.EmitValue(address, IntPtrSize); + AP.EmitGlobalConstant(&gcInfo->getFunction()); + AP.EmitInt32(debug->getLine()); + AP.EmitInt32(gcInfo->live_size(safepoint)); + + //fprintf(stderr, "emitting %lu lives\n", gcInfo->live_size(safepoint)); + for(GCFunctionInfo::live_iterator live=gcInfo->live_begin(safepoint); live!=gcInfo->live_end(safepoint); live++) { + AP.EmitInt32(live->StackOffset); + } + AP.EmitAlignment(IntPtrSize == 4 ? 2 : 3); + } + } + } + + AP.OutStreamer.EmitValue(MCConstantExpr::Create(0, AP.OutStreamer.getContext()), IntPtrSize); + } } Modified: vmkit/branches/mcjit/lib/vmkit/vmkit.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/vmkit.cc?rev=197811&r1=197810&r2=197811&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/vmkit.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/vmkit.cc Fri Dec 20 07:43:29 2013 @@ -117,7 +117,7 @@ llvm::Function* VMKit::getGCRoot(llvm::M } void VMKit::NotifyObjectEmitted(const llvm::ObjectImage &obj) { - fprintf(stderr, "**** object jit event listener!\n"); + //fprintf(stderr, "**** object jit event listener!\n"); } void VMKit::NotifyFunctionEmitted(const llvm::Function &F, @@ -126,7 +126,7 @@ void VMKit::NotifyFunctionEmitted(const const llvm::JITEventListener::EmittedFunctionDetails &Details) { fprintf(stderr, "**** jit event listener!\n"); - +#if 0 const llvm::MachineFunction* mf = Details.MF; const std::vector& landingPads = mf->getMMI().getLandingPads(); const llvm::MachineCodeEmitter* mce = Details.MCE; @@ -166,6 +166,7 @@ void VMKit::NotifyFunctionEmitted(const safepointMap[addr] = sf; } } +#endif } void VMKit::log(const wchar_t* msg, ...) { From gael.thomas at lip6.fr Fri Dec 20 06:01:59 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Fri, 20 Dec 2013 14:01:59 -0000 Subject: [vmkit-commits] [vmkit] r197812 - rename gcrootpass into safepoint Message-ID: <20131220140159.7FF162A6C029@llvm.org> Author: gthomas Date: Fri Dec 20 08:01:59 2013 New Revision: 197812 URL: http://llvm.org/viewvc/llvm-project?rev=197812&view=rev Log: rename gcrootpass into safepoint Added: vmkit/branches/mcjit/include/vmkit/safepoint.h vmkit/branches/mcjit/lib/vmkit/safpoint.cc Removed: vmkit/branches/mcjit/lib/vmkit/gcrootpass.cc Modified: vmkit/branches/mcjit/include/vmkit/vmkit.h vmkit/branches/mcjit/lib/vmkit/vmkit.cc Added: vmkit/branches/mcjit/include/vmkit/safepoint.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/safepoint.h?rev=197812&view=auto ============================================================================== --- vmkit/branches/mcjit/include/vmkit/safepoint.h (added) +++ vmkit/branches/mcjit/include/vmkit/safepoint.h Fri Dec 20 08:01:59 2013 @@ -0,0 +1,25 @@ +#ifndef _SAFEPOINT_H_ +#define _SAFEPOINT_H_ + +#include + +namespace vmkit { + class Safepoint { /* directly in the data sections */ + void* _addr; + void* _metaData; + uint32_t _sourceIndex; + uint32_t _nbLives; + uint32_t _lives[2]; + + public: + void* addr() { return _addr; } + void* metaData() { return _metaData; } + void updateMetaData(void* metaData) { _metaData = metaData; } + uint32_t nbLives() { return _nbLives; } + uint32_t liveAt(uint32_t i) { return _lives[i]; } + + Safepoint* getNext(); + }; +} + +#endif Modified: vmkit/branches/mcjit/include/vmkit/vmkit.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/vmkit.h?rev=197812&r1=197811&r2=197812&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/vmkit.h (original) +++ vmkit/branches/mcjit/include/vmkit/vmkit.h Fri Dec 20 08:01:59 2013 @@ -17,21 +17,7 @@ namespace llvm { namespace vmkit { class Thread; - - class Safepoint { /* managed with malloc/free */ - const llvm::Function* _llvmFunction; - uintptr_t _address; - size_t _nbSlots; - uintptr_t _offsets[1]; - - void* operator new(size_t unused, size_t nbSlots); - Safepoint(const llvm::Function* llvmFunction, uintptr_t address, size_t nbSlots); - - public: - static Safepoint* create(const llvm::Function* llvmFunction, uintptr_t address, size_t nbSlots); - - void setAt(size_t idx, uintptr_t offset) { _offsets[idx] = idx; } - }; + class Safepoint; class ExceptionDescriptor { /* managed with malloc/free */ const llvm::Function* _llvmFunction; Removed: vmkit/branches/mcjit/lib/vmkit/gcrootpass.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/gcrootpass.cc?rev=197811&view=auto ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/gcrootpass.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/gcrootpass.cc (removed) @@ -1,135 +0,0 @@ -#include "llvm/IR/Function.h" -#include "llvm/IR/Constants.h" -#include "llvm/IR/Module.h" -#include "llvm/IR/DataLayout.h" - -#include "llvm/CodeGen/GCs.h" -#include "llvm/CodeGen/GCStrategy.h" -#include "llvm/CodeGen/AsmPrinter.h" -#include "llvm/CodeGen/GCMetadataPrinter.h" -#include "llvm/CodeGen/MachineFunction.h" -#include "llvm/CodeGen/MachineInstrBuilder.h" - -#include "llvm/MC/MCContext.h" -#include "llvm/MC/MCAsmInfo.h" -#include "llvm/MC/MCExpr.h" -#include "llvm/MC/MCSymbol.h" -#include "llvm/MC/MCStreamer.h" -#include "llvm/MC/MCSection.h" - -#include "llvm/Support/Compiler.h" - -#include "llvm/Target/TargetInstrInfo.h" -#include "llvm/Target/TargetMachine.h" -#include "llvm/Target/Mangler.h" -#include "llvm/Target/TargetLoweringObjectFile.h" - -using namespace llvm; - -namespace vmkit { - class VmkitGCPass : public GCStrategy { - public: - VmkitGCPass(); - bool findCustomSafePoints(GCFunctionInfo& FI, MachineFunction &MF); - }; - - void linkVmkitGC() { } - - static GCRegistry::Add X("vmkit", "VMKit GC for JIT-generated functions"); - - VmkitGCPass::VmkitGCPass() { - CustomSafePoints = true; - UsesMetadata = true; - InitRoots = 1; - } - - static MCSymbol *InsertLabel(MachineBasicBlock &MBB, - MachineBasicBlock::iterator MI, - DebugLoc DL) { - const TargetInstrInfo* TII = MBB.getParent()->getTarget().getInstrInfo(); - MCSymbol *Label = MBB.getParent()->getContext().CreateTempSymbol(); - BuildMI(MBB, MI, DL, TII->get(TargetOpcode::GC_LABEL)).addSym(Label); - return Label; - } - - bool VmkitGCPass::findCustomSafePoints(GCFunctionInfo& FI, MachineFunction &MF) { - for (MachineFunction::iterator BBI = MF.begin(), - BBE = MF.end(); BBI != BBE; ++BBI) { - for (MachineBasicBlock::iterator MI = BBI->begin(), - ME = BBI->end(); MI != ME; ++MI) { - if (MI->getDesc().isCall()) { - MachineBasicBlock::iterator RAI = MI; ++RAI; - MCSymbol* Label = InsertLabel(*MI->getParent(), RAI, MI->getDebugLoc()); - FI.addSafePoint(GC::PostCall, Label, MI->getDebugLoc()); - } else if (MI->getDebugLoc().getCol() == 1) { - MCSymbol* Label = InsertLabel(*MI->getParent(), MI, MI->getDebugLoc()); - FI.addSafePoint(GC::Loop, Label, MI->getDebugLoc()); - } - } - } - - return false; - } - - class VmkitGCMetadataPrinter : public GCMetadataPrinter { - public: - void beginAssembly(AsmPrinter &AP); - void finishAssembly(AsmPrinter &AP); - }; - - static GCMetadataPrinterRegistry::Add - Y("vmkit", "VMKit garbage-collector"); - - void VmkitGCMetadataPrinter::beginAssembly(AsmPrinter &AP) {} - - void VmkitGCMetadataPrinter::finishAssembly(AsmPrinter &AP) { - AP.OutStreamer.SwitchSection(AP.getObjFileLowering().getDataSection()); - - unsigned IntPtrSize = AP.TM.getDataLayout()->getPointerSize(0); - - SmallString<256> symName("_"); - symName += getModule().getModuleIdentifier(); - symName += "__frametable"; - - MCSymbol *sym = AP.OutContext.GetOrCreateSymbol(symName); - AP.OutStreamer.EmitSymbolAttribute(sym, MCSA_Global); - - AP.EmitAlignment(IntPtrSize == 4 ? 2 : 3); - - AP.OutStreamer.AddComment("--- module frame tables ---"); - AP.OutStreamer.AddBlankLine(); - AP.OutStreamer.EmitLabel(sym); - - for (iterator I = begin(), IE = end(); I != IE; ++I) { - GCFunctionInfo* gcInfo = *I; - - if(gcInfo->getFunction().hasGC()) { - AP.OutStreamer.AddComment("live roots for " + Twine(gcInfo->getFunction().getName())); - AP.OutStreamer.AddBlankLine(); - for(llvm::GCFunctionInfo::iterator safepoint=gcInfo->begin(); safepoint!=gcInfo->end(); safepoint++) { - DebugLoc* debug = &safepoint->Loc; - uint32_t kind = safepoint->Kind; - - const MCExpr* address = MCSymbolRefExpr::Create(safepoint->Label, AP.OutStreamer.getContext()); - if (debug->getCol() == 1) { - const MCExpr* one = MCConstantExpr::Create(1, AP.OutStreamer.getContext()); - address = MCBinaryExpr::CreateAdd(address, one, AP.OutStreamer.getContext()); - } - - AP.OutStreamer.EmitValue(address, IntPtrSize); - AP.EmitGlobalConstant(&gcInfo->getFunction()); - AP.EmitInt32(debug->getLine()); - AP.EmitInt32(gcInfo->live_size(safepoint)); - - //fprintf(stderr, "emitting %lu lives\n", gcInfo->live_size(safepoint)); - for(GCFunctionInfo::live_iterator live=gcInfo->live_begin(safepoint); live!=gcInfo->live_end(safepoint); live++) { - AP.EmitInt32(live->StackOffset); - } - AP.EmitAlignment(IntPtrSize == 4 ? 2 : 3); - } - } - } - - AP.OutStreamer.EmitValue(MCConstantExpr::Create(0, AP.OutStreamer.getContext()), IntPtrSize); - } -} Added: vmkit/branches/mcjit/lib/vmkit/safpoint.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/safpoint.cc?rev=197812&view=auto ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/safpoint.cc (added) +++ vmkit/branches/mcjit/lib/vmkit/safpoint.cc Fri Dec 20 08:01:59 2013 @@ -0,0 +1,149 @@ +#include "vmkit/safepoint.h" + +#include "llvm/IR/Function.h" +#include "llvm/IR/Constants.h" +#include "llvm/IR/Module.h" +#include "llvm/IR/DataLayout.h" + +#include "llvm/CodeGen/GCs.h" +#include "llvm/CodeGen/GCStrategy.h" +#include "llvm/CodeGen/AsmPrinter.h" +#include "llvm/CodeGen/GCMetadataPrinter.h" +#include "llvm/CodeGen/MachineFunction.h" +#include "llvm/CodeGen/MachineInstrBuilder.h" + +#include "llvm/MC/MCContext.h" +#include "llvm/MC/MCAsmInfo.h" +#include "llvm/MC/MCExpr.h" +#include "llvm/MC/MCSymbol.h" +#include "llvm/MC/MCStreamer.h" +#include "llvm/MC/MCSection.h" + +#include "llvm/Support/Compiler.h" + +#include "llvm/Target/TargetInstrInfo.h" +#include "llvm/Target/TargetMachine.h" +#include "llvm/Target/Mangler.h" +#include "llvm/Target/TargetLoweringObjectFile.h" + +namespace vmkit { + class VmkitGCPass : public llvm::GCStrategy { + public: + static llvm::MCSymbol *InsertLabel(llvm::MachineBasicBlock &MBB, + llvm::MachineBasicBlock::iterator MI, + llvm::DebugLoc DL); + + VmkitGCPass(); + bool findCustomSafePoints(llvm::GCFunctionInfo& FI, llvm::MachineFunction &MF); + }; + + class VmkitGCMetadataPrinter : public llvm::GCMetadataPrinter { + public: + void beginAssembly(llvm::AsmPrinter &AP) {} + void finishAssembly(llvm::AsmPrinter &AP); + }; +} + +using namespace vmkit; + +static llvm::GCRegistry::Add X("vmkit", "VMKit GC for JIT-generated functions"); +static llvm::GCMetadataPrinterRegistry::Add Y("vmkit", "VMKit garbage-collector"); + +/* + * VmkitGCPass + */ +VmkitGCPass::VmkitGCPass() { + CustomSafePoints = true; + UsesMetadata = true; + InitRoots = 1; +} + +llvm::MCSymbol *VmkitGCPass::InsertLabel(llvm::MachineBasicBlock &MBB, + llvm::MachineBasicBlock::iterator MI, + llvm::DebugLoc DL) { + const llvm::TargetInstrInfo* TII = MBB.getParent()->getTarget().getInstrInfo(); + llvm::MCSymbol *Label = MBB.getParent()->getContext().CreateTempSymbol(); + BuildMI(MBB, MI, DL, TII->get(llvm::TargetOpcode::GC_LABEL)).addSym(Label); + return Label; +} + +bool VmkitGCPass::findCustomSafePoints(llvm::GCFunctionInfo& FI, llvm::MachineFunction &MF) { + for (llvm::MachineFunction::iterator BBI = MF.begin(), + BBE = MF.end(); BBI != BBE; ++BBI) { + for (llvm::MachineBasicBlock::iterator MI = BBI->begin(), + ME = BBI->end(); MI != ME; ++MI) { + if (MI->getDesc().isCall()) { + llvm::MachineBasicBlock::iterator RAI = MI; ++RAI; + llvm::MCSymbol* Label = InsertLabel(*MI->getParent(), RAI, MI->getDebugLoc()); + FI.addSafePoint(llvm::GC::PostCall, Label, MI->getDebugLoc()); + } else if (MI->getDebugLoc().getCol() == 1) { + llvm::MCSymbol* Label = InsertLabel(*MI->getParent(), MI, MI->getDebugLoc()); + FI.addSafePoint(llvm::GC::Loop, Label, MI->getDebugLoc()); + } + } + } + + return false; +} + +/* + * VmkitGCMetadataPrinter + */ +void VmkitGCMetadataPrinter::finishAssembly(llvm::AsmPrinter &AP) { + AP.OutStreamer.SwitchSection(AP.getObjFileLowering().getDataSection()); + + unsigned IntPtrSize = AP.TM.getDataLayout()->getPointerSize(0); + + llvm::SmallString<256> symName("_"); + symName += getModule().getModuleIdentifier(); + symName += "__frametable"; + + llvm::MCSymbol *sym = AP.OutContext.GetOrCreateSymbol(symName); + AP.OutStreamer.EmitSymbolAttribute(sym, llvm::MCSA_Global); + + AP.EmitAlignment(IntPtrSize == 4 ? 2 : 3); + + AP.OutStreamer.AddComment("--- module frame tables ---"); + AP.OutStreamer.AddBlankLine(); + AP.OutStreamer.EmitLabel(sym); + + for (iterator I = begin(), IE = end(); I != IE; ++I) { + llvm::GCFunctionInfo* gcInfo = *I; + + if(gcInfo->getFunction().hasGC()) { + AP.OutStreamer.AddComment("live roots for " + llvm::Twine(gcInfo->getFunction().getName())); + AP.OutStreamer.AddBlankLine(); + for(llvm::GCFunctionInfo::iterator safepoint=gcInfo->begin(); safepoint!=gcInfo->end(); safepoint++) { + llvm::DebugLoc* debug = &safepoint->Loc; + uint32_t kind = safepoint->Kind; + + const llvm::MCExpr* address = llvm::MCSymbolRefExpr::Create(safepoint->Label, AP.OutStreamer.getContext()); + if (debug->getCol() == 1) { + const llvm::MCExpr* one = llvm::MCConstantExpr::Create(1, AP.OutStreamer.getContext()); + address = llvm::MCBinaryExpr::CreateAdd(address, one, AP.OutStreamer.getContext()); + } + + AP.OutStreamer.EmitValue(address, IntPtrSize); + AP.EmitGlobalConstant(&gcInfo->getFunction()); + AP.EmitInt32(debug->getLine()); + AP.EmitInt32(gcInfo->live_size(safepoint)); + + //fprintf(stderr, "emitting %lu lives\n", gcInfo->live_size(safepoint)); + for(llvm::GCFunctionInfo::live_iterator live=gcInfo->live_begin(safepoint); live!=gcInfo->live_end(safepoint); live++) { + AP.EmitInt32(live->StackOffset); + } + AP.EmitAlignment(IntPtrSize == 4 ? 2 : 3); + } + } + } + + AP.OutStreamer.EmitValue(llvm::MCConstantExpr::Create(0, AP.OutStreamer.getContext()), IntPtrSize); +} + +/* + * Safepoint + */ +Safepoint* Safepoint::getNext() { + uintptr_t next = (uintptr_t)this + sizeof(Safepoint) - 2*sizeof(uint32_t) + nbLives()*sizeof(uint32_t); + return (Safepoint*)(((next - 1) & -sizeof(uintptr_t)) + sizeof(uintptr_t)); +} Modified: vmkit/branches/mcjit/lib/vmkit/vmkit.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/vmkit.cc?rev=197812&r1=197811&r2=197812&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/vmkit.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/vmkit.cc Fri Dec 20 08:01:59 2013 @@ -209,20 +209,6 @@ void VMKit::throwException(void* obj) { } -void* Safepoint::operator new(size_t unused, size_t nbSlots) { - return ::operator new(sizeof(Safepoint) + nbSlots*sizeof(uintptr_t) - sizeof(uintptr_t)); -} - -Safepoint::Safepoint(const llvm::Function* llvmFunction, uintptr_t address, size_t nbSlots) { - _llvmFunction = llvmFunction; - _address = address; - _nbSlots = nbSlots; -} - -Safepoint* Safepoint::create(const llvm::Function* llvmFunction, uintptr_t address, size_t nbSlots) { - return new(nbSlots) Safepoint(llvmFunction, address, nbSlots); -} - ExceptionDescriptor::ExceptionDescriptor(const llvm::Function* llvmFunction, uintptr_t point, uintptr_t landingPad) { _llvmFunction = llvmFunction; _point = point; From gael.thomas at lip6.fr Fri Dec 20 06:04:34 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Fri, 20 Dec 2013 14:04:34 -0000 Subject: [vmkit-commits] [vmkit] r197813 - use my new safepoint class Message-ID: <20131220140434.8D45A2A6C029@llvm.org> Author: gthomas Date: Fri Dec 20 08:04:34 2013 New Revision: 197813 URL: http://llvm.org/viewvc/llvm-project?rev=197813&view=rev Log: use my new safepoint class Modified: vmkit/branches/mcjit/include/vmkit/safepoint.h vmkit/branches/mcjit/lib/j3/vm/j3method.cc Modified: vmkit/branches/mcjit/include/vmkit/safepoint.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/safepoint.h?rev=197813&r1=197812&r2=197813&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/safepoint.h (original) +++ vmkit/branches/mcjit/include/vmkit/safepoint.h Fri Dec 20 08:04:34 2013 @@ -15,6 +15,7 @@ namespace vmkit { void* addr() { return _addr; } void* metaData() { return _metaData; } void updateMetaData(void* metaData) { _metaData = metaData; } + uint32_t sourceIndex() { return _sourceIndex; } uint32_t nbLives() { return _nbLives; } uint32_t liveAt(uint32_t i) { return _lives[i]; } Modified: vmkit/branches/mcjit/lib/j3/vm/j3method.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3method.cc?rev=197813&r1=197812&r2=197813&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3method.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3method.cc Fri Dec 20 08:04:34 2013 @@ -1,3 +1,5 @@ +#include "vmkit/safepoint.h" + #include "j3/j3method.h" #include "j3/j3class.h" #include "j3/j3classloader.h" @@ -42,14 +44,6 @@ uint32_t J3Method::index() { return _index; } -struct safepoint_t { - void* addr; - void* metaData; - uint32_t sourceIndex; - uint32_t nbLives; - uint32_t lives[2]; -}; /* aligned on a 8-byte boundary on a 64 bit machine, on a 4-byte boundary otherwise */ - uint8_t* J3Method::fnPtr() { if(!_fnPtr) { //fprintf(stderr, "materializing: %ls::%ls%ls\n", cl()->name()->cStr(), name()->cStr(), sign()->cStr()); @@ -76,21 +70,17 @@ uint8_t* J3Method::fnPtr() { llvm::SmallString<256> symName; symName += module->getModuleIdentifier(); symName += "__frametable"; - struct safepoint_t* sf = (safepoint_t*)ee->getGlobalValueAddress(symName.c_str()); + vmkit::Safepoint* sf = (vmkit::Safepoint*)ee->getGlobalValueAddress(symName.c_str()); if(!sf) cl()->loader()->vm()->internalError(L"unable to find safepoints"); - while(sf->addr) { - fprintf(stderr, " [%p] safepoint at %p for function %p::%d\n", sf, sf->addr, sf->metaData, sf->sourceIndex); - for(uint32_t i=0; inbLives; i++) - fprintf(stderr, " live at %d\n", sf->lives[i]); - - uintptr_t next = (uintptr_t)sf + sizeof(struct safepoint_t) - 2*sizeof(uint32_t) + sf->nbLives*sizeof(uint32_t); - //fprintf(stderr, "next at 0x%lx %ld %ld %ld\n", next, - //sizeof(struct safepoint_t), sf->nbLives*sizeof(uint32_t), 2*sizeof(uint32_t)); - sf = (struct safepoint_t*)(((next - 1) & -sizeof(uintptr_t)) + sizeof(uintptr_t)); - //fprintf(stderr, "=> %p\n", sf); + while(sf->addr()) { + fprintf(stderr, " [%p] safepoint at %p for function %p::%d\n", sf, sf->addr(), sf->metaData(), sf->sourceIndex()); + for(uint32_t i=0; inbLives(); i++) + fprintf(stderr, " live at %d\n", sf->liveAt(i)); + + sf = sf->getNext(); } #endif } From gael.thomas at lip6.fr Fri Dec 20 08:49:17 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Fri, 20 Dec 2013 16:49:17 -0000 Subject: [vmkit-commits] [vmkit] r197816 - register the safepoints in vmkit Message-ID: <20131220164917.9AF7F2A6C029@llvm.org> Author: gthomas Date: Fri Dec 20 10:49:17 2013 New Revision: 197816 URL: http://llvm.org/viewvc/llvm-project?rev=197816&view=rev Log: register the safepoints in vmkit Modified: vmkit/branches/mcjit/include/j3/j3classloader.h vmkit/branches/mcjit/include/vmkit/compiler.h vmkit/branches/mcjit/include/vmkit/safepoint.h vmkit/branches/mcjit/include/vmkit/vmkit.h vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc vmkit/branches/mcjit/lib/j3/vm/j3method.cc vmkit/branches/mcjit/lib/vmkit/compiler.cc vmkit/branches/mcjit/lib/vmkit/safpoint.cc vmkit/branches/mcjit/lib/vmkit/vmkit.cc Modified: vmkit/branches/mcjit/include/j3/j3classloader.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3classloader.h?rev=197816&r1=197815&r2=197816&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3classloader.h (original) +++ vmkit/branches/mcjit/include/j3/j3classloader.h Fri Dec 20 10:49:17 2013 @@ -40,7 +40,6 @@ namespace j3 { J3ObjectHandle* _javaClassLoader; J3FixedPoint _fixedPoint; pthread_mutex_t _mutex; /* a lock */ - J3* _vm; /* my vm */ vmkit::NameMap::map classes; /* classes managed by this class loader */ vmkit::NameMap::map types; /* shortcut to find types */ vmkit::NameMap::map methodTypes; /* shortcut to find method types - REMOVE */ @@ -65,7 +64,7 @@ namespace j3 { void lock() { pthread_mutex_lock(&_mutex); } void unlock() { pthread_mutex_unlock(&_mutex); } - J3* vm() const { return _vm; }; + J3* vm() const { return (J3*)vmkit::CompilationUnit::vm(); }; J3Method* method(uint16_t access, J3Class* cl, const vmkit::Name* name, const vmkit::Name* sign); /* find a method ref */ Modified: vmkit/branches/mcjit/include/vmkit/compiler.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/compiler.h?rev=197816&r1=197815&r2=197816&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/compiler.h (original) +++ vmkit/branches/mcjit/include/vmkit/compiler.h Fri Dec 20 10:49:17 2013 @@ -18,6 +18,8 @@ namespace llvm { }; namespace vmkit { + class VMKit; + class Symbol : public PermanentObject { public: virtual uint8_t* getSymbolAddress(); @@ -34,6 +36,7 @@ namespace vmkit { class CompilationUnit : public llvm::SectionMemoryManager { typedef std::map > > SymbolMap; + VMKit* _vmkit; BumpAllocator* _allocator; SymbolMap _symbolTable; pthread_mutex_t _mutexSymbolTable; @@ -47,11 +50,13 @@ namespace vmkit { public: void* operator new(size_t n, BumpAllocator* allocator); - CompilationUnit(BumpAllocator* allocator, const char* id); + CompilationUnit(BumpAllocator* allocator, VMKit* vmkit, const char* id); ~CompilationUnit(); static void destroy(CompilationUnit* unit); + VMKit* vm() const { return _vmkit; } + void addSymbol(const char* id, vmkit::Symbol* symbol); uint64_t getSymbolAddress(const std::string &Name); @@ -59,7 +64,7 @@ namespace vmkit { llvm::ExecutionEngine* ee() { return _ee; } llvm::ExecutionEngine* oldee() { return _oldee; } - void addModule(llvm::Module* module); + void compileModule(llvm::Module* module); }; } Modified: vmkit/branches/mcjit/include/vmkit/safepoint.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/safepoint.h?rev=197816&r1=197815&r2=197816&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/safepoint.h (original) +++ vmkit/branches/mcjit/include/vmkit/safepoint.h Fri Dec 20 10:49:17 2013 @@ -3,23 +3,33 @@ #include +namespace llvm { + class Module; +} + namespace vmkit { + class CompilationUnit; + class Safepoint { /* directly in the data sections */ - void* _addr; - void* _metaData; - uint32_t _sourceIndex; - uint32_t _nbLives; - uint32_t _lives[2]; + uintptr_t _addr; + void* _code; + CompilationUnit* _unit; + uint32_t _sourceIndex; + uint32_t _nbLives; public: - void* addr() { return _addr; } - void* metaData() { return _metaData; } - void updateMetaData(void* metaData) { _metaData = metaData; } - uint32_t sourceIndex() { return _sourceIndex; } - uint32_t nbLives() { return _nbLives; } - uint32_t liveAt(uint32_t i) { return _lives[i]; } + void setUnit(CompilationUnit* unit) { _unit = unit; } + + uintptr_t addr() { return _addr; } + void* code() { return _code; } + uint32_t sourceIndex() { return _sourceIndex; } + uint32_t nbLives() { return _nbLives; } + uint32_t liveAt(uint32_t i) { return ((uint32_t*)(this + 1))[i]; } Safepoint* getNext(); + void dump(); + + static Safepoint* get(CompilationUnit* unit, llvm::Module* module); }; } Modified: vmkit/branches/mcjit/include/vmkit/vmkit.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/vmkit.h?rev=197816&r1=197815&r2=197816&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/vmkit.h (original) +++ vmkit/branches/mcjit/include/vmkit/vmkit.h Fri Dec 20 10:49:17 2013 @@ -31,8 +31,9 @@ namespace vmkit { typedef std::map > > MangleMap; - std::map safepointMap; /* managed with malloc/free */ - std::map exceptionTable; /* managed with malloc/free */ + std::map safepointMap; + pthread_mutex_t safepointMapLock; + std::map exceptionTable; /* managed with malloc/free */ MangleMap mangleMap; BumpAllocator* _allocator; llvm::Module* _self; @@ -50,6 +51,9 @@ namespace vmkit { VMKit(BumpAllocator* allocator); + void addSafepoint(Safepoint* sf); + Safepoint* getSafepoint(uintptr_t addr); + BumpAllocator* allocator() { return _allocator; } void vmkitBootstrap(Thread* initialThread, const char* selfBitCodePath); Modified: vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc?rev=197816&r1=197815&r2=197816&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc Fri Dec 20 10:49:17 2013 @@ -21,7 +21,7 @@ using namespace j3; J3ClassLoader::J3MethodLess J3ClassLoader::j3MethodLess; J3ClassLoader::J3ClassLoader(J3* v, J3ObjectHandle* javaClassLoader, vmkit::BumpAllocator* allocator) - : CompilationUnit(allocator, "class-loader"), + : CompilationUnit(allocator, v, "class-loader"), _fixedPoint(allocator), classes(vmkit::Name::less, allocator), types(vmkit::Name::less, allocator), @@ -34,8 +34,6 @@ J3ClassLoader::J3ClassLoader(J3* v, J3Ob // pthread_mutexattr_init(&attr); // pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); pthread_mutex_init(&_mutex, 0);//&attr); - - _vm = v; } void* J3ClassLoader::lookupNativeFunctionPointer(J3Method* method, const char* symbol) { Modified: vmkit/branches/mcjit/lib/j3/vm/j3method.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3method.cc?rev=197816&r1=197815&r2=197816&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3method.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3method.cc Fri Dec 20 10:49:17 2013 @@ -61,29 +61,10 @@ uint8_t* J3Method::fnPtr() { J3CodeGen::translate(this, _llvmFunction); - llvm::ExecutionEngine* ee = cl()->loader()->ee(); - cl()->loader()->addModule(module); - _fnPtr = (uint8_t*)ee->getFunctionAddress(_llvmFunction->getName().data()); + cl()->loader()->compileModule(module); -#if 1 - fprintf(stderr, "%s is generated at %p\n", llvmFunctionName(), _fnPtr); - llvm::SmallString<256> symName; - symName += module->getModuleIdentifier(); - symName += "__frametable"; - vmkit::Safepoint* sf = (vmkit::Safepoint*)ee->getGlobalValueAddress(symName.c_str()); - - if(!sf) - cl()->loader()->vm()->internalError(L"unable to find safepoints"); - - while(sf->addr()) { - fprintf(stderr, " [%p] safepoint at %p for function %p::%d\n", sf, sf->addr(), sf->metaData(), sf->sourceIndex()); - for(uint32_t i=0; inbLives(); i++) - fprintf(stderr, " live at %d\n", sf->liveAt(i)); - - sf = sf->getNext(); - } -#endif - } + _fnPtr = (uint8_t*)cl()->loader()->ee()->getFunctionAddress(_llvmFunction->getName().data()); + } return _fnPtr; } Modified: vmkit/branches/mcjit/lib/vmkit/compiler.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/compiler.cc?rev=197816&r1=197815&r2=197816&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/compiler.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/compiler.cc Fri Dec 20 10:49:17 2013 @@ -3,6 +3,7 @@ #include "vmkit/compiler.h" #include "vmkit/thread.h" #include "vmkit/vmkit.h" +#include "vmkit/safepoint.h" #include "llvm/LinkAllPasses.h" #include "llvm/PassManager.h" @@ -24,11 +25,13 @@ void* CompilationUnit::operator new(size void CompilationUnit::operator delete(void* self) { } -CompilationUnit::CompilationUnit(BumpAllocator* allocator, const char* id) : +CompilationUnit::CompilationUnit(BumpAllocator* allocator, VMKit* vmkit, const char* id) : _symbolTable(vmkit::Util::char_less, allocator) { _allocator = allocator; pthread_mutex_init(&_mutexSymbolTable, 0); + _vmkit = vmkit; + std::string err; _ee = llvm::EngineBuilder(new llvm::Module(id, Thread::get()->vm()->llvmContext())) .setUseMCJIT(1) @@ -40,6 +43,7 @@ CompilationUnit::CompilationUnit(BumpAll Thread::get()->vm()->internalError(L"Error while creating execution engine: %s\n", err.c_str()); ee()->RegisterJITEventListener(Thread::get()->vm()); + ee()->finalizeObject(); _oldee = llvm::EngineBuilder(new llvm::Module("old ee", Thread::get()->vm()->llvmContext())) .setErrorStr(&err) @@ -127,7 +131,20 @@ uint64_t CompilationUnit::getSymbolAddre return (uint64_t)(uintptr_t)res->getSymbolAddress(); } -void CompilationUnit::addModule(llvm::Module* module) { +void CompilationUnit::compileModule(llvm::Module* module) { pm->run(*module); ee()->addModule(module); + ee()->finalizeObject(); + + vmkit::Safepoint* sf = Safepoint::get(this, module); + + if(!sf) + vm()->internalError(L"unable to find safepoints"); + + while(sf->addr()) { + sf->setUnit(this); + vm()->addSafepoint(sf); + vm()->getSafepoint(sf->addr())->dump(); + sf = sf->getNext(); + } } Modified: vmkit/branches/mcjit/lib/vmkit/safpoint.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/safpoint.cc?rev=197816&r1=197815&r2=197816&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/safpoint.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/safpoint.cc Fri Dec 20 10:49:17 2013 @@ -1,4 +1,5 @@ #include "vmkit/safepoint.h" +#include "vmkit/compiler.h" #include "llvm/IR/Function.h" #include "llvm/IR/Constants.h" @@ -26,6 +27,8 @@ #include "llvm/Target/Mangler.h" #include "llvm/Target/TargetLoweringObjectFile.h" +#include "llvm/ExecutionEngine/ExecutionEngine.h" + namespace vmkit { class VmkitGCPass : public llvm::GCStrategy { public: @@ -94,6 +97,7 @@ void VmkitGCMetadataPrinter::finishAssem unsigned IntPtrSize = AP.TM.getDataLayout()->getPointerSize(0); + fprintf(stderr, "generating frame tables for: %s\n", getModule().getModuleIdentifier().c_str()); llvm::SmallString<256> symName("_"); symName += getModule().getModuleIdentifier(); symName += "__frametable"; @@ -125,6 +129,9 @@ void VmkitGCMetadataPrinter::finishAssem AP.OutStreamer.EmitValue(address, IntPtrSize); AP.EmitGlobalConstant(&gcInfo->getFunction()); + AP.EmitInt32(0); + if(IntPtrSize == 8) + AP.EmitInt32(0); AP.EmitInt32(debug->getLine()); AP.EmitInt32(gcInfo->live_size(safepoint)); @@ -144,6 +151,19 @@ void VmkitGCMetadataPrinter::finishAssem * Safepoint */ Safepoint* Safepoint::getNext() { - uintptr_t next = (uintptr_t)this + sizeof(Safepoint) - 2*sizeof(uint32_t) + nbLives()*sizeof(uint32_t); + uintptr_t next = (uintptr_t)this + sizeof(Safepoint) + nbLives()*sizeof(uint32_t); return (Safepoint*)(((next - 1) & -sizeof(uintptr_t)) + sizeof(uintptr_t)); } + +Safepoint* Safepoint::get(CompilationUnit* unit, llvm::Module* module) { + llvm::SmallString<256> symName; + symName += module->getModuleIdentifier(); + symName += "__frametable"; + return (vmkit::Safepoint*)unit->ee()->getGlobalValueAddress(symName.c_str()); +} + +void Safepoint::dump() { + fprintf(stderr, " [%p] safepoint at 0x%lx for function %p::%d\n", this, addr(), code(), sourceIndex()); + for(uint32_t i=0; iallocator()); } +void VMKit::addSafepoint(Safepoint* sf) { + pthread_mutex_lock(&safepointMapLock); + safepointMap[sf->addr()] = sf; + pthread_mutex_unlock(&safepointMapLock); +} + +Safepoint* VMKit::getSafepoint(uintptr_t addr) { + pthread_mutex_lock(&safepointMapLock); + Safepoint* res = safepointMap[addr]; + pthread_mutex_unlock(&safepointMapLock); + return res; +} + llvm::LLVMContext& VMKit::llvmContext() { return self()->getContext(); } @@ -117,7 +132,7 @@ llvm::Function* VMKit::getGCRoot(llvm::M } void VMKit::NotifyObjectEmitted(const llvm::ObjectImage &obj) { - //fprintf(stderr, "**** object jit event listener!\n"); + fprintf(stderr, "**** object jit event listener!\n"); } void VMKit::NotifyFunctionEmitted(const llvm::Function &F, From gael.thomas at lip6.fr Fri Dec 20 10:04:53 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Fri, 20 Dec 2013 18:04:53 -0000 Subject: [vmkit-commits] [vmkit] r197822 - a safepoint now references its function name directly in the object file Message-ID: <20131220180453.EE4282A6C029@llvm.org> Author: gthomas Date: Fri Dec 20 12:04:53 2013 New Revision: 197822 URL: http://llvm.org/viewvc/llvm-project?rev=197822&view=rev Log: a safepoint now references its function name directly in the object file Modified: vmkit/branches/mcjit/include/vmkit/safepoint.h vmkit/branches/mcjit/lib/vmkit/compiler.cc vmkit/branches/mcjit/lib/vmkit/safpoint.cc Modified: vmkit/branches/mcjit/include/vmkit/safepoint.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/safepoint.h?rev=197822&r1=197821&r2=197822&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/safepoint.h (original) +++ vmkit/branches/mcjit/include/vmkit/safepoint.h Fri Dec 20 12:04:53 2013 @@ -12,22 +12,22 @@ namespace vmkit { class Safepoint { /* directly in the data sections */ uintptr_t _addr; - void* _code; + const char* _functionName; CompilationUnit* _unit; uint32_t _sourceIndex; uint32_t _nbLives; public: - void setUnit(CompilationUnit* unit) { _unit = unit; } + void setUnit(CompilationUnit* unit) { _unit = unit; } - uintptr_t addr() { return _addr; } - void* code() { return _code; } - uint32_t sourceIndex() { return _sourceIndex; } - uint32_t nbLives() { return _nbLives; } - uint32_t liveAt(uint32_t i) { return ((uint32_t*)(this + 1))[i]; } + uintptr_t addr() { return _addr; } + const char* functionName() { return _functionName; } + uint32_t sourceIndex() { return _sourceIndex; } + uint32_t nbLives() { return _nbLives; } + uint32_t liveAt(uint32_t i) { return ((uint32_t*)(this + 1))[i]; } - Safepoint* getNext(); - void dump(); + Safepoint* getNext(); + void dump(); static Safepoint* get(CompilationUnit* unit, llvm::Module* module); }; Modified: vmkit/branches/mcjit/lib/vmkit/compiler.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/compiler.cc?rev=197822&r1=197821&r2=197822&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/compiler.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/compiler.cc Fri Dec 20 12:04:53 2013 @@ -144,6 +144,7 @@ void CompilationUnit::compileModule(llvm while(sf->addr()) { sf->setUnit(this); vm()->addSafepoint(sf); + vm()->getSafepoint(sf->addr())->dump(); sf = sf->getNext(); } Modified: vmkit/branches/mcjit/lib/vmkit/safpoint.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/safpoint.cc?rev=197822&r1=197821&r2=197822&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/safpoint.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/safpoint.cc Fri Dec 20 12:04:53 2013 @@ -93,10 +93,31 @@ bool VmkitGCPass::findCustomSafePoints(l * VmkitGCMetadataPrinter */ void VmkitGCMetadataPrinter::finishAssembly(llvm::AsmPrinter &AP) { - AP.OutStreamer.SwitchSection(AP.getObjFileLowering().getDataSection()); - unsigned IntPtrSize = AP.TM.getDataLayout()->getPointerSize(0); + uint32_t i = 0; + AP.OutStreamer.AddComment("--- function names for the frame tables ---"); + AP.OutStreamer.AddBlankLine(); + AP.OutStreamer.SwitchSection(AP.getObjFileLowering().getSectionForConstant(llvm::SectionKind::getMergeable1ByteCString())); + for (iterator I = begin(), IE = end(); I != IE; ++I, i++) { + llvm::GCFunctionInfo* gcInfo = *I; + if(gcInfo->getFunction().hasGC()) { + llvm::SmallString<256> id("gcFunc"); + id += i; + + llvm::MCSymbol *sym = AP.OutContext.GetOrCreateSymbol(id); + AP.OutStreamer.EmitLabel(sym); + + llvm::StringRef ref = gcInfo->getFunction().getName(); + uint32_t len = ref.size(); + for(uint32_t n=0; n symName("_"); symName += getModule().getModuleIdentifier(); @@ -111,12 +132,19 @@ void VmkitGCMetadataPrinter::finishAssem AP.OutStreamer.AddBlankLine(); AP.OutStreamer.EmitLabel(sym); - for (iterator I = begin(), IE = end(); I != IE; ++I) { + i = 0; + for (iterator I = begin(), IE = end(); I != IE; ++I, i++) { llvm::GCFunctionInfo* gcInfo = *I; if(gcInfo->getFunction().hasGC()) { AP.OutStreamer.AddComment("live roots for " + llvm::Twine(gcInfo->getFunction().getName())); AP.OutStreamer.AddBlankLine(); + + llvm::SmallString<256> id("gcFunc"); + id += i; + + const llvm::MCExpr* funcName = llvm::MCSymbolRefExpr::Create(AP.OutContext.GetOrCreateSymbol(id), AP.OutStreamer.getContext()); + for(llvm::GCFunctionInfo::iterator safepoint=gcInfo->begin(); safepoint!=gcInfo->end(); safepoint++) { llvm::DebugLoc* debug = &safepoint->Loc; uint32_t kind = safepoint->Kind; @@ -128,7 +156,8 @@ void VmkitGCMetadataPrinter::finishAssem } AP.OutStreamer.EmitValue(address, IntPtrSize); - AP.EmitGlobalConstant(&gcInfo->getFunction()); + AP.OutStreamer.EmitValue(funcName, IntPtrSize); + // AP.EmitGlobalConstant(&gcInfo->getFunction()); AP.EmitInt32(0); if(IntPtrSize == 8) AP.EmitInt32(0); @@ -163,7 +192,7 @@ Safepoint* Safepoint::get(CompilationUni } void Safepoint::dump() { - fprintf(stderr, " [%p] safepoint at 0x%lx for function %p::%d\n", this, addr(), code(), sourceIndex()); + fprintf(stderr, " [%p] safepoint at 0x%lx for %s::%d\n", this, addr(), functionName(), sourceIndex()); for(uint32_t i=0; i Author: gthomas Date: Fri Dec 20 12:06:40 2013 New Revision: 197823 URL: http://llvm.org/viewvc/llvm-project?rev=197823&view=rev Log: don't use the jit event listeners anymore Modified: vmkit/branches/mcjit/include/vmkit/vmkit.h vmkit/branches/mcjit/lib/vmkit/compiler.cc vmkit/branches/mcjit/lib/vmkit/vmkit.cc Modified: vmkit/branches/mcjit/include/vmkit/vmkit.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/vmkit.h?rev=197823&r1=197822&r2=197823&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/vmkit.h (original) +++ vmkit/branches/mcjit/include/vmkit/vmkit.h Fri Dec 20 12:06:40 2013 @@ -4,8 +4,6 @@ #include "vmkit/util.h" #include "vmkit/allocator.h" -#include "llvm/ExecutionEngine/JITEventListener.h" - namespace llvm { class LLVMContext; class Module; @@ -27,7 +25,7 @@ namespace vmkit { ExceptionDescriptor(const llvm::Function* llvmFunction, uintptr_t point, uintptr_t landingPad); }; - class VMKit : public llvm::JITEventListener { + class VMKit { typedef std::map > > MangleMap; @@ -72,13 +70,6 @@ namespace vmkit { static void internalError(const wchar_t* msg, ...) __attribute__((noreturn)); static void throwException(void* obj) __attribute__((noreturn)); - - void NotifyFunctionEmitted(const llvm::Function &F, - void *Code, - size_t Size, - const llvm::JITEventListener::EmittedFunctionDetails &Details); - - void NotifyObjectEmitted(const llvm::ObjectImage &obj); }; }; Modified: vmkit/branches/mcjit/lib/vmkit/compiler.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/compiler.cc?rev=197823&r1=197822&r2=197823&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/compiler.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/compiler.cc Fri Dec 20 12:06:40 2013 @@ -42,7 +42,6 @@ CompilationUnit::CompilationUnit(BumpAll if (!ee()) Thread::get()->vm()->internalError(L"Error while creating execution engine: %s\n", err.c_str()); - ee()->RegisterJITEventListener(Thread::get()->vm()); ee()->finalizeObject(); _oldee = llvm::EngineBuilder(new llvm::Module("old ee", Thread::get()->vm()->llvmContext())) Modified: vmkit/branches/mcjit/lib/vmkit/vmkit.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/vmkit.cc?rev=197823&r1=197822&r2=197823&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/vmkit.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/vmkit.cc Fri Dec 20 12:06:40 2013 @@ -131,59 +131,6 @@ llvm::Function* VMKit::getGCRoot(llvm::M return llvm::Intrinsic::getDeclaration(mod, llvm::Intrinsic::gcroot); } -void VMKit::NotifyObjectEmitted(const llvm::ObjectImage &obj) { - fprintf(stderr, "**** object jit event listener!\n"); -} - -void VMKit::NotifyFunctionEmitted(const llvm::Function &F, - void *Code, - size_t Size, - const llvm::JITEventListener::EmittedFunctionDetails &Details) { - - fprintf(stderr, "**** jit event listener!\n"); -#if 0 - const llvm::MachineFunction* mf = Details.MF; - const std::vector& landingPads = mf->getMMI().getLandingPads(); - const llvm::MachineCodeEmitter* mce = Details.MCE; - - for(std::vector::const_iterator i=landingPads.begin(); i!=landingPads.end(); i++) { - uintptr_t dest = mce->getLabelAddress(i->LandingPadLabel); - - for(uint32_t j=0; jBeginLabels.size(); j++) { - uintptr_t point = mce->getLabelAddress(i->EndLabels[j]); - ExceptionDescriptor* e = new ExceptionDescriptor(&F, point, dest); - exceptionTable[point] = e; - fprintf(stderr, " exceptionpoint at 0x%lx goes to 0x%lx\n", point, dest); - } - } - - if(F.hasGC()) { - llvm::GCFunctionInfo* gcInfo = &mf->getGMI()->getFunctionInfo(F); - uintptr_t start = (uintptr_t)Code; - uintptr_t end = start + Size; - - for(llvm::GCFunctionInfo::iterator safepoint=gcInfo->begin(); safepoint!=gcInfo->end(); safepoint++) { - uint32_t kind = safepoint->Kind; - llvm::MCSymbol* label = safepoint->Label; - uintptr_t addr = mce->getLabelAddress(label); - - if(addr < start || addr > end) - internalError(L"safe point is not inside the function (%p %p %p)", start, addr, end); - - Safepoint* sf = Safepoint::create(&F, addr, gcInfo->live_size(safepoint)); - uint32_t i=0; - - //fprintf(stderr, " safepoint at 0x%lx\n", addr); - for(llvm::GCFunctionInfo::live_iterator live=gcInfo->live_begin(safepoint); live!=gcInfo->live_end(safepoint); live++, i++) { - sf->setAt(i, live->StackOffset); - //fprintf(stderr, " offset: %d\n", live->StackOffset); - } - safepointMap[addr] = sf; - } - } -#endif -} - void VMKit::log(const wchar_t* msg, ...) { va_list va; va_start(va, msg); From gael.thomas at lip6.fr Fri Dec 20 12:07:28 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Fri, 20 Dec 2013 20:07:28 -0000 Subject: [vmkit-commits] [vmkit] r197830 - begin the implementation of stack walker Message-ID: <20131220200728.A1E9A2A6C029@llvm.org> Author: gthomas Date: Fri Dec 20 14:07:27 2013 New Revision: 197830 URL: http://llvm.org/viewvc/llvm-project?rev=197830&view=rev Log: begin the implementation of stack walker Modified: vmkit/branches/mcjit/include/j3/j3class.h vmkit/branches/mcjit/include/j3/j3method.h vmkit/branches/mcjit/include/j3/j3thread.h vmkit/branches/mcjit/include/vmkit/compiler.h vmkit/branches/mcjit/include/vmkit/safepoint.h vmkit/branches/mcjit/include/vmkit/thread.h vmkit/branches/mcjit/include/vmkit/vmkit.h vmkit/branches/mcjit/lib/j3/vm/j3class.cc vmkit/branches/mcjit/lib/j3/vm/j3jni.cc vmkit/branches/mcjit/lib/j3/vm/j3method.cc vmkit/branches/mcjit/lib/j3/vm/j3thread.cc vmkit/branches/mcjit/lib/vmkit/compiler.cc vmkit/branches/mcjit/lib/vmkit/safpoint.cc vmkit/branches/mcjit/lib/vmkit/thread.cc vmkit/branches/mcjit/lib/vmkit/vmkit.cc Modified: vmkit/branches/mcjit/include/j3/j3class.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3class.h?rev=197830&r1=197829&r2=197830&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3class.h (original) +++ vmkit/branches/mcjit/include/j3/j3class.h Fri Dec 20 14:07:27 2013 @@ -52,7 +52,7 @@ namespace j3 { public: J3Type(J3ClassLoader* loader, const vmkit::Name* name); - uint8_t* getSymbolAddress(); + void* getSymbolAddress(); virtual llvm::GlobalValue* llvmDescriptor(llvm::Module* module) { return 0; } Modified: vmkit/branches/mcjit/include/j3/j3method.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3method.h?rev=197830&r1=197829&r2=197830&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3method.h (original) +++ vmkit/branches/mcjit/include/j3/j3method.h Fri Dec 20 14:07:27 2013 @@ -52,7 +52,7 @@ namespace j3 { J3MethodCode(J3Method* _self) { self = _self; } - uint8_t* getSymbolAddress(); + void* getSymbolAddress(); }; class J3Method : public vmkit::Symbol { @@ -66,7 +66,7 @@ namespace j3 { J3Attributes* _attributes; uint32_t _index; llvm::Function* _llvmFunction; - uint8_t* _fnPtr; + void* _fnPtr; char* volatile _llvmAllNames; /* stub + _ + native_name */ void* _nativeFnPtr; @@ -83,7 +83,7 @@ namespace j3 { public: J3Method(uint16_t access, J3Class* cl, const vmkit::Name* name, const vmkit::Name* sign); - uint8_t* getSymbolAddress(); + void* getSymbolAddress(); static J3Method* newMethod(vmkit::BumpAllocator* allocator, uint16_t access, @@ -128,8 +128,8 @@ namespace j3 { J3Value invokeVirtual(J3ObjectHandle* obj, J3Value* args); J3Value invokeVirtual(J3ObjectHandle* obj, va_list va); - uint8_t* fnPtr(); - uint8_t* functionPointerOrTrampoline(); + void* fnPtr(); + void* functionPointerOrTrampoline(); void dump(); }; Modified: vmkit/branches/mcjit/include/j3/j3thread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3thread.h?rev=197830&r1=197829&r2=197830&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3thread.h (original) +++ vmkit/branches/mcjit/include/j3/j3thread.h Fri Dec 20 14:07:27 2013 @@ -6,6 +6,10 @@ #include "j3/j3object.h" #include "j3/j3jni.h" +namespace vmkit { + class Safepoint; +} + namespace j3 { class J3; @@ -17,17 +21,19 @@ namespace j3 { J3Thread(J3* vm, vmkit::BumpAllocator* allocator); public: - static J3Thread* create(J3* j3); + static J3Thread* create(J3* j3); + + vmkit::Safepoint* getJavaCaller(uint32_t level=0); - void ensureCapacity(uint32_t capacity); - J3ObjectHandle* pendingException() { return _pendingException; } - void setPendingException(J3ObjectHandle* handle) { _pendingException = handle; } - J3FixedPoint* fixedPoint() { return &_fixedPoint; } - - J3ObjectHandle* push(J3ObjectHandle* handle); - J3ObjectHandle* push(J3Object* obj); - J3ObjectHandle* tell(); - void restore(J3ObjectHandle* obj); + void ensureCapacity(uint32_t capacity); + J3ObjectHandle* pendingException() { return _pendingException; } + void setPendingException(J3ObjectHandle* handle) { _pendingException = handle; } + J3FixedPoint* fixedPoint() { return &_fixedPoint; } + + J3ObjectHandle* push(J3ObjectHandle* handle); + J3ObjectHandle* push(J3Object* obj); + J3ObjectHandle* tell(); + void restore(J3ObjectHandle* obj); J3* vm() { return (J3*)Thread::vm(); } Modified: vmkit/branches/mcjit/include/vmkit/compiler.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/compiler.h?rev=197830&r1=197829&r2=197830&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/compiler.h (original) +++ vmkit/branches/mcjit/include/vmkit/compiler.h Fri Dec 20 14:07:27 2013 @@ -22,15 +22,15 @@ namespace vmkit { class Symbol : public PermanentObject { public: - virtual uint8_t* getSymbolAddress(); + virtual void* getSymbolAddress(); }; class NativeSymbol : public Symbol { - uint8_t* addr; + void* addr; public: - NativeSymbol(uint8_t* _addr) { addr = _addr; } + NativeSymbol(void* _addr) { addr = _addr; } - uint8_t* getSymbolAddress() { return addr; } + void* getSymbolAddress() { return addr; } }; class CompilationUnit : public llvm::SectionMemoryManager { @@ -58,6 +58,7 @@ namespace vmkit { VMKit* vm() const { return _vmkit; } void addSymbol(const char* id, vmkit::Symbol* symbol); + Symbol* getSymbol(const std::string &Name); uint64_t getSymbolAddress(const std::string &Name); BumpAllocator* allocator() { return _allocator; } Modified: vmkit/branches/mcjit/include/vmkit/safepoint.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/safepoint.h?rev=197830&r1=197829&r2=197830&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/safepoint.h (original) +++ vmkit/branches/mcjit/include/vmkit/safepoint.h Fri Dec 20 14:07:27 2013 @@ -11,7 +11,7 @@ namespace vmkit { class CompilationUnit; class Safepoint { /* directly in the data sections */ - uintptr_t _addr; + void* _addr; const char* _functionName; CompilationUnit* _unit; uint32_t _sourceIndex; @@ -20,7 +20,7 @@ namespace vmkit { public: void setUnit(CompilationUnit* unit) { _unit = unit; } - uintptr_t addr() { return _addr; } + void* addr() { return _addr; } const char* functionName() { return _functionName; } uint32_t sourceIndex() { return _sourceIndex; } uint32_t nbLives() { return _nbLives; } Modified: vmkit/branches/mcjit/include/vmkit/thread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/thread.h?rev=197830&r1=197829&r2=197830&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/thread.h (original) +++ vmkit/branches/mcjit/include/vmkit/thread.h Fri Dec 20 14:07:27 2013 @@ -26,13 +26,13 @@ namespace vmkit { }; class StackWalker { - uintptr_t framePointer; + void** framePointer; public: - StackWalker(uint32_t initialPop=1); + StackWalker(uint32_t initialPop=0) __attribute__((noinline)); - void next(uint32_t nbPop=1); - uintptr_t ip(); + bool next(uint32_t nbPop=1); + void* ip(); }; } Modified: vmkit/branches/mcjit/include/vmkit/vmkit.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/vmkit.h?rev=197830&r1=197829&r2=197830&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/vmkit.h (original) +++ vmkit/branches/mcjit/include/vmkit/vmkit.h Fri Dec 20 14:07:27 2013 @@ -29,7 +29,7 @@ namespace vmkit { typedef std::map > > MangleMap; - std::map safepointMap; + std::map safepointMap; pthread_mutex_t safepointMapLock; std::map exceptionTable; /* managed with malloc/free */ MangleMap mangleMap; @@ -50,7 +50,7 @@ namespace vmkit { VMKit(BumpAllocator* allocator); void addSafepoint(Safepoint* sf); - Safepoint* getSafepoint(uintptr_t addr); + Safepoint* getSafepoint(void* addr); BumpAllocator* allocator() { return _allocator; } Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=197830&r1=197829&r2=197830&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Fri Dec 20 14:07:27 2013 @@ -30,8 +30,8 @@ J3Type::J3Type(J3ClassLoader* loader, co _name = name; } -uint8_t* J3Type::getSymbolAddress() { - return (uint8_t*)this; +void* J3Type::getSymbolAddress() { + return this; } J3VirtualTable* J3Type::vt() { Modified: vmkit/branches/mcjit/lib/j3/vm/j3jni.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3jni.cc?rev=197830&r1=197829&r2=197830&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3jni.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3jni.cc Fri Dec 20 14:07:27 2013 @@ -18,9 +18,13 @@ jint JNICALL GetVersion(JNIEnv* env) { e jclass JNICALL DefineClass(JNIEnv* env, const char* name, jobject loader, const jbyte* buf, jsize len) { enterJVM(); leaveJVM(); NYI(); } jclass JNICALL FindClass(JNIEnv* env, const char* name) { + vmkit::Safepoint* sf = J3Thread::get()->getJavaCaller(); + + printf("---> %p\n", sf); //jclass res; enterJVM(); //J3Class* cl = + fprintf(stderr, "find class: %s\n", name); leaveJVM(); NYI(); } Modified: vmkit/branches/mcjit/lib/j3/vm/j3method.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3method.cc?rev=197830&r1=197829&r2=197830&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3method.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3method.cc Fri Dec 20 14:07:27 2013 @@ -44,7 +44,7 @@ uint32_t J3Method::index() { return _index; } -uint8_t* J3Method::fnPtr() { +void* J3Method::fnPtr() { if(!_fnPtr) { //fprintf(stderr, "materializing: %ls::%ls%ls\n", cl()->name()->cStr(), name()->cStr(), sign()->cStr()); if(!isResolved()) { @@ -63,22 +63,22 @@ uint8_t* J3Method::fnPtr() { cl()->loader()->compileModule(module); - _fnPtr = (uint8_t*)cl()->loader()->ee()->getFunctionAddress(_llvmFunction->getName().data()); + _fnPtr = (void*)cl()->loader()->ee()->getFunctionAddress(_llvmFunction->getName().data()); } return _fnPtr; } -uint8_t* J3Method::functionPointerOrTrampoline() { +void* J3Method::functionPointerOrTrampoline() { return _fnPtr ? _fnPtr : _trampoline; } -uint8_t* J3MethodCode::getSymbolAddress() { +void* J3MethodCode::getSymbolAddress() { return self->functionPointerOrTrampoline(); } -uint8_t* J3Method::getSymbolAddress() { - return (uint8_t*)this; +void* J3Method::getSymbolAddress() { + return this; } void J3Method::setResolved(uint32_t index) { @@ -437,7 +437,7 @@ llvm::Function* J3Method::nativeLLVMFunc buf, module); - cl()->loader()->addSymbol(buf, new(cl()->loader()->allocator()) vmkit::NativeSymbol((uint8_t*)fnPtr)); + cl()->loader()->addSymbol(buf, new(cl()->loader()->allocator()) vmkit::NativeSymbol(fnPtr)); return res; } Modified: vmkit/branches/mcjit/lib/j3/vm/j3thread.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3thread.cc?rev=197830&r1=197829&r2=197830&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3thread.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3thread.cc Fri Dec 20 14:07:27 2013 @@ -14,6 +14,22 @@ J3Thread* J3Thread::create(J3* j3) { return new(allocator) J3Thread(j3, allocator); } +vmkit::Safepoint* J3Thread::getJavaCaller(uint32_t level) { + vmkit::Safepoint* sf = 0; + vmkit::StackWalker walker; + + while(walker.next()) { + vmkit::Safepoint* sf = vm()->getSafepoint(walker.ip()); + + if(sf && !level--) { + //((J3ClassLoader*)sf->unit())-> + return sf; + } + } + + return 0; +} + void J3Thread::ensureCapacity(uint32_t capacity) { _fixedPoint.unsyncEnsureCapacity(capacity); } Modified: vmkit/branches/mcjit/lib/vmkit/compiler.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/compiler.cc?rev=197830&r1=197829&r2=197830&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/compiler.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/compiler.cc Fri Dec 20 14:07:27 2013 @@ -14,7 +14,7 @@ using namespace vmkit; -uint8_t* Symbol::getSymbolAddress() { +void* Symbol::getSymbolAddress() { Thread::get()->vm()->internalError(L"implement me: getSymbolAddress"); } @@ -107,7 +107,7 @@ void CompilationUnit::addSymbol(const ch pthread_mutex_unlock(&_mutexSymbolTable); } -uint64_t CompilationUnit::getSymbolAddress(const std::string &Name) { +Symbol* CompilationUnit::getSymbol(const std::string &Name) { pthread_mutex_lock(&_mutexSymbolTable); const char* id = Name.c_str() + 1; @@ -127,7 +127,11 @@ uint64_t CompilationUnit::getSymbolAddre res = it->second; pthread_mutex_unlock(&_mutexSymbolTable); - return (uint64_t)(uintptr_t)res->getSymbolAddress(); + return res; +} + +uint64_t CompilationUnit::getSymbolAddress(const std::string &Name) { + return (uint64_t)(uintptr_t)getSymbol(Name)->getSymbolAddress(); } void CompilationUnit::compileModule(llvm::Module* module) { Modified: vmkit/branches/mcjit/lib/vmkit/safpoint.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/safpoint.cc?rev=197830&r1=197829&r2=197830&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/safpoint.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/safpoint.cc Fri Dec 20 14:07:27 2013 @@ -192,7 +192,7 @@ Safepoint* Safepoint::get(CompilationUni } void Safepoint::dump() { - fprintf(stderr, " [%p] safepoint at 0x%lx for %s::%d\n", this, addr(), functionName(), sourceIndex()); + fprintf(stderr, " [%p] safepoint at %p for %s::%d\n", this, addr(), functionName(), sourceIndex()); for(uint32_t i=0; iallocator()); } +StackWalker::StackWalker(uint32_t initialPop) { + framePointer = (void**)__builtin_frame_address(1); + next(initialPop); +} + +bool StackWalker::next(uint32_t nbPop) { + while(nbPop--) { + void* next = framePointer[0]; + if(!next) + return 0; + framePointer = (void**)next; + } + return 1; +} + +void* StackWalker::ip() { + return framePointer[1]; +} Modified: vmkit/branches/mcjit/lib/vmkit/vmkit.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/vmkit.cc?rev=197830&r1=197829&r2=197830&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/vmkit.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/vmkit.cc Fri Dec 20 14:07:27 2013 @@ -53,7 +53,7 @@ void VMKit::addSafepoint(Safepoint* sf) pthread_mutex_unlock(&safepointMapLock); } -Safepoint* VMKit::getSafepoint(uintptr_t addr) { +Safepoint* VMKit::getSafepoint(void* addr) { pthread_mutex_lock(&safepointMapLock); Safepoint* res = safepointMap[addr]; pthread_mutex_unlock(&safepointMapLock); From gael.thomas at lip6.fr Fri Dec 20 13:07:51 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Fri, 20 Dec 2013 21:07:51 -0000 Subject: [vmkit-commits] [vmkit] r197835 - pretty stack traces Message-ID: <20131220210752.4C7AC2A6C029@llvm.org> Author: gthomas Date: Fri Dec 20 15:07:51 2013 New Revision: 197835 URL: http://llvm.org/viewvc/llvm-project?rev=197835&view=rev Log: pretty stack traces Modified: vmkit/branches/mcjit/include/j3/j3.h vmkit/branches/mcjit/include/j3/j3thread.h vmkit/branches/mcjit/include/vmkit/compiler.h vmkit/branches/mcjit/include/vmkit/safepoint.h vmkit/branches/mcjit/include/vmkit/vmkit.h vmkit/branches/mcjit/lib/j3/vm/j3.cc vmkit/branches/mcjit/lib/j3/vm/j3jni.cc vmkit/branches/mcjit/lib/j3/vm/j3thread.cc vmkit/branches/mcjit/lib/vmkit/compiler.cc vmkit/branches/mcjit/lib/vmkit/safpoint.cc vmkit/branches/mcjit/lib/vmkit/thread.cc vmkit/branches/mcjit/lib/vmkit/vmkit.cc Modified: vmkit/branches/mcjit/include/j3/j3.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3.h?rev=197835&r1=197834&r2=197835&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3.h (original) +++ vmkit/branches/mcjit/include/j3/j3.h Fri Dec 20 15:07:51 2013 @@ -94,6 +94,8 @@ namespace j3 { void start(int argc, char** argv); + void vinternalError(const wchar_t* msg, va_list va) __attribute__((noreturn)); + static JNIEnv* jniEnv(); static void noClassDefFoundError(J3Class* cl) __attribute__((noreturn)); Modified: vmkit/branches/mcjit/include/j3/j3thread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3thread.h?rev=197835&r1=197834&r2=197835&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3thread.h (original) +++ vmkit/branches/mcjit/include/j3/j3thread.h Fri Dec 20 15:07:51 2013 @@ -23,7 +23,7 @@ namespace j3 { public: static J3Thread* create(J3* j3); - vmkit::Safepoint* getJavaCaller(uint32_t level=0); + J3Method* getJavaCaller(uint32_t level=0); void ensureCapacity(uint32_t capacity); J3ObjectHandle* pendingException() { return _pendingException; } Modified: vmkit/branches/mcjit/include/vmkit/compiler.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/compiler.h?rev=197835&r1=197834&r2=197835&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/compiler.h (original) +++ vmkit/branches/mcjit/include/vmkit/compiler.h Fri Dec 20 15:07:51 2013 @@ -58,7 +58,7 @@ namespace vmkit { VMKit* vm() const { return _vmkit; } void addSymbol(const char* id, vmkit::Symbol* symbol); - Symbol* getSymbol(const std::string &Name); + Symbol* getSymbol(const char* id); uint64_t getSymbolAddress(const std::string &Name); BumpAllocator* allocator() { return _allocator; } Modified: vmkit/branches/mcjit/include/vmkit/safepoint.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/safepoint.h?rev=197835&r1=197834&r2=197835&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/safepoint.h (original) +++ vmkit/branches/mcjit/include/vmkit/safepoint.h Fri Dec 20 15:07:51 2013 @@ -18,16 +18,17 @@ namespace vmkit { uint32_t _nbLives; public: - void setUnit(CompilationUnit* unit) { _unit = unit; } + void setUnit(CompilationUnit* unit) { _unit = unit; } - void* addr() { return _addr; } - const char* functionName() { return _functionName; } - uint32_t sourceIndex() { return _sourceIndex; } - uint32_t nbLives() { return _nbLives; } - uint32_t liveAt(uint32_t i) { return ((uint32_t*)(this + 1))[i]; } + CompilationUnit* unit() { return _unit; } + void* addr() { return _addr; } + const char* functionName() { return _functionName; } + uint32_t sourceIndex() { return _sourceIndex; } + uint32_t nbLives() { return _nbLives; } + uint32_t liveAt(uint32_t i) { return ((uint32_t*)(this + 1))[i]; } - Safepoint* getNext(); - void dump(); + Safepoint* getNext(); + void dump(); static Safepoint* get(CompilationUnit* unit, llvm::Module* module); }; Modified: vmkit/branches/mcjit/include/vmkit/vmkit.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/vmkit.h?rev=197835&r1=197834&r2=197835&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/vmkit.h (original) +++ vmkit/branches/mcjit/include/vmkit/vmkit.h Fri Dec 20 15:07:51 2013 @@ -66,7 +66,7 @@ namespace vmkit { void log(const wchar_t* msg, ...); - virtual void internalError(const wchar_t* msg, va_list va) __attribute__((noreturn)); + virtual void vinternalError(const wchar_t* msg, va_list va) __attribute__((noreturn)); static void internalError(const wchar_t* msg, ...) __attribute__((noreturn)); static void throwException(void* obj) __attribute__((noreturn)); Modified: vmkit/branches/mcjit/lib/j3/vm/j3.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3.cc?rev=197835&r1=197834&r2=197835&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3.cc Fri Dec 20 15:07:51 2013 @@ -1,4 +1,5 @@ #include +#include #include #include "j3/j3class.h" @@ -11,6 +12,8 @@ #include "llvm/IR/Type.h" #include "llvm/IR/DerivedTypes.h" +#include "vmkit/safepoint.h" + using namespace j3; vmkit::T_ptr_less_t J3::charArrayLess; @@ -171,3 +174,34 @@ void J3::classFormatError(J3Class* cl, c void J3::linkageError(J3Method* method) { internalError(L"unable to find native method '%ls::%ls%ls'", method->cl()->name()->cStr(), method->name()->cStr(), method->sign()->cStr()); } + +void J3::vinternalError(const wchar_t* msg, va_list va) { + vmkit::Safepoint* sf = 0; + vmkit::StackWalker walker; + + fprintf(stderr, "Internal error: "); + vfwprintf(stderr, msg, va); + fprintf(stderr, "\n"); + + while(walker.next()) { + vmkit::Safepoint* sf = getSafepoint(walker.ip()); + + if(sf) { + J3Method* m = ((J3MethodCode*)sf->unit()->getSymbol(sf->functionName()))->self; + fprintf(stderr, " in %ls %ls::%ls index %d\n", m->sign()->cStr(), m->cl()->name()->cStr(), m->name()->cStr(), + sf->sourceIndex()); + } else { + Dl_info info; + + if(dladdr(walker.ip(), &info)) { + int status; + const char* demangled = abi::__cxa_demangle(info.dli_sname, 0, 0, &status); + const char* name = demangled ? demangled : info.dli_sname; + fprintf(stderr, " in %s + %lu\n", name, (uintptr_t)walker.ip() - (uintptr_t)info.dli_saddr); + } else { + fprintf(stderr, " in %p\n", walker.ip()); + } + } + } + abort(); +} Modified: vmkit/branches/mcjit/lib/j3/vm/j3jni.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3jni.cc?rev=197835&r1=197834&r2=197835&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3jni.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3jni.cc Fri Dec 20 15:07:51 2013 @@ -10,7 +10,7 @@ #define enterJVM() try { #define leaveJVM() } catch(void* e) { J3Thread::get()->setPendingException(J3Thread::get()->push((J3Object*)e)); } -#define NYI() { fprintf(stderr, "-- not yet implemented: %s --\n", __PRETTY_FUNCTION__); abort(); } +#define NYI() { J3Thread::get()->vm()->internalError(L"not yet implemented: '%s'", __PRETTY_FUNCTION__); } namespace j3 { @@ -18,15 +18,17 @@ jint JNICALL GetVersion(JNIEnv* env) { e jclass JNICALL DefineClass(JNIEnv* env, const char* name, jobject loader, const jbyte* buf, jsize len) { enterJVM(); leaveJVM(); NYI(); } jclass JNICALL FindClass(JNIEnv* env, const char* name) { - vmkit::Safepoint* sf = J3Thread::get()->getJavaCaller(); + jclass res; - printf("---> %p\n", sf); - //jclass res; enterJVM(); - //J3Class* cl = - fprintf(stderr, "find class: %s\n", name); + J3Method* m = J3Thread::get()->getJavaCaller(); + J3ClassLoader* loader = m ? m->cl()->loader() : J3Thread::get()->vm()->initialClassLoader; + J3Class* cl = loader->getClass(loader->vm()->names()->get(name)); + cl->initialise(); + res = cl->javaClass(); leaveJVM(); - NYI(); + + return res; } jmethodID JNICALL FromReflectedMethod(JNIEnv* env, jobject method) { enterJVM(); leaveJVM(); NYI(); } Modified: vmkit/branches/mcjit/lib/j3/vm/j3thread.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3thread.cc?rev=197835&r1=197834&r2=197835&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3thread.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3thread.cc Fri Dec 20 15:07:51 2013 @@ -1,6 +1,10 @@ #include "j3/j3thread.h" +#include "j3/j3method.h" #include "j3/j3.h" +#include "vmkit/safepoint.h" +#include "vmkit/compiler.h" + using namespace j3; J3Thread::J3Thread(J3* vm, vmkit::BumpAllocator* allocator) : @@ -14,17 +18,15 @@ J3Thread* J3Thread::create(J3* j3) { return new(allocator) J3Thread(j3, allocator); } -vmkit::Safepoint* J3Thread::getJavaCaller(uint32_t level) { +J3Method* J3Thread::getJavaCaller(uint32_t level) { vmkit::Safepoint* sf = 0; vmkit::StackWalker walker; while(walker.next()) { vmkit::Safepoint* sf = vm()->getSafepoint(walker.ip()); - if(sf && !level--) { - //((J3ClassLoader*)sf->unit())-> - return sf; - } + if(sf && !level--) + return ((J3MethodCode*)sf->unit()->getSymbol(sf->functionName()))->self; } return 0; Modified: vmkit/branches/mcjit/lib/vmkit/compiler.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/compiler.cc?rev=197835&r1=197834&r2=197835&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/compiler.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/compiler.cc Fri Dec 20 15:07:51 2013 @@ -107,9 +107,8 @@ void CompilationUnit::addSymbol(const ch pthread_mutex_unlock(&_mutexSymbolTable); } -Symbol* CompilationUnit::getSymbol(const std::string &Name) { +Symbol* CompilationUnit::getSymbol(const char* id) { pthread_mutex_lock(&_mutexSymbolTable); - const char* id = Name.c_str() + 1; std::map::iterator it = _symbolTable.find(id); vmkit::Symbol* res; @@ -131,7 +130,7 @@ Symbol* CompilationUnit::getSymbol(const } uint64_t CompilationUnit::getSymbolAddress(const std::string &Name) { - return (uint64_t)(uintptr_t)getSymbol(Name)->getSymbolAddress(); + return (uint64_t)(uintptr_t)getSymbol(Name.c_str() + 1)->getSymbolAddress(); } void CompilationUnit::compileModule(llvm::Module* module) { @@ -148,7 +147,7 @@ void CompilationUnit::compileModule(llvm sf->setUnit(this); vm()->addSafepoint(sf); - vm()->getSafepoint(sf->addr())->dump(); + //vm()->getSafepoint(sf->addr())->dump(); sf = sf->getNext(); } } Modified: vmkit/branches/mcjit/lib/vmkit/safpoint.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/safpoint.cc?rev=197835&r1=197834&r2=197835&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/safpoint.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/safpoint.cc Fri Dec 20 15:07:51 2013 @@ -118,7 +118,6 @@ void VmkitGCMetadataPrinter::finishAssem AP.OutStreamer.SwitchSection(AP.getObjFileLowering().getDataSection()); - fprintf(stderr, "generating frame tables for: %s\n", getModule().getModuleIdentifier().c_str()); llvm::SmallString<256> symName("_"); symName += getModule().getModuleIdentifier(); symName += "__frametable"; @@ -128,7 +127,7 @@ void VmkitGCMetadataPrinter::finishAssem AP.EmitAlignment(IntPtrSize == 4 ? 2 : 3); - AP.OutStreamer.AddComment("--- module frame tables ---"); + AP.OutStreamer.AddComment("--- frame tables ---"); AP.OutStreamer.AddBlankLine(); AP.OutStreamer.EmitLabel(sym); Modified: vmkit/branches/mcjit/lib/vmkit/thread.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/thread.cc?rev=197835&r1=197834&r2=197835&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/thread.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/thread.cc Fri Dec 20 15:07:51 2013 @@ -20,10 +20,10 @@ StackWalker::StackWalker(uint32_t initia bool StackWalker::next(uint32_t nbPop) { while(nbPop--) { - void* next = framePointer[0]; - if(!next) + void** next = (void**)framePointer[0]; + if(!next || !next[0]) return 0; - framePointer = (void**)next; + framePointer = next; } return 1; } Modified: vmkit/branches/mcjit/lib/vmkit/vmkit.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/vmkit.cc?rev=197835&r1=197834&r2=197835&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/vmkit.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/vmkit.cc Fri Dec 20 15:07:51 2013 @@ -140,7 +140,7 @@ void VMKit::log(const wchar_t* msg, ...) va_end(va); } -void VMKit::internalError(const wchar_t* msg, va_list va) { +void VMKit::vinternalError(const wchar_t* msg, va_list va) { defaultInternalError(msg, va); } @@ -155,7 +155,7 @@ void VMKit::internalError(const wchar_t* va_list va; va_start(va, msg); if(Thread::get() && Thread::get()->vm()) - Thread::get()->vm()->internalError(msg, va); + Thread::get()->vm()->vinternalError(msg, va); else defaultInternalError(msg, va); va_end(va); From gael.thomas at lip6.fr Sat Dec 21 00:41:23 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sat, 21 Dec 2013 08:41:23 -0000 Subject: [vmkit-commits] [vmkit] r197861 - implement GetStaticMethod Message-ID: <20131221084123.D951D2A6C029@llvm.org> Author: gthomas Date: Sat Dec 21 02:41:23 2013 New Revision: 197861 URL: http://llvm.org/viewvc/llvm-project?rev=197861&view=rev Log: implement GetStaticMethod Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc vmkit/branches/mcjit/lib/j3/vm/j3jni.cc Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=197861&r1=197860&r2=197861&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Sat Dec 21 02:41:23 2013 @@ -141,6 +141,7 @@ J3ObjectType* J3ObjectType::nativeClass( } J3ObjectHandle* J3ObjectType::javaClass() { + fprintf(stderr, "javaClass: %p %p %ls\n", _javaClass, this, name()->cStr()); if(!_javaClass) { lock(); if(!_javaClass) { @@ -149,7 +150,9 @@ J3ObjectHandle* J3ObjectType::javaClass( loader()->fixedPoint()->syncPush(_javaClass); J3Thread::get()->restore(prev); _javaClass->setLong(loader()->vm()->classVMData, (int64_t)(uintptr_t)this); + fprintf(stderr, " -> native class is %p\n", nativeClass(_javaClass)); loader()->vm()->classInit->invokeSpecial(_javaClass); + fprintf(stderr, " %p -> native class is %p\n", _javaClass, nativeClass(_javaClass)); } unlock(); } Modified: vmkit/branches/mcjit/lib/j3/vm/j3jni.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3jni.cc?rev=197861&r1=197860&r2=197861&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3jni.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3jni.cc Sat Dec 21 02:41:23 2013 @@ -27,7 +27,9 @@ jclass JNICALL FindClass(JNIEnv* env, co cl->initialise(); res = cl->javaClass(); leaveJVM(); - + + fprintf(stderr, "find class --> %p %p\n", res, J3ObjectType::nativeClass(res)); + return res; } @@ -98,6 +100,7 @@ jmethodID JNICALL GetMethodID(JNIEnv* en vmkit::Names* n = cl->loader()->vm()->names(); res = cl->findVirtualMethod(n->get(name), n->get(sig)); leaveJVM(); + return res; } @@ -223,7 +226,21 @@ void JNICALL SetLongField(JNIEnv* env, j void JNICALL SetFloatField(JNIEnv* env, jobject obj, jfieldID fieldID, jfloat val) { enterJVM(); leaveJVM(); NYI(); } void JNICALL SetDoubleField(JNIEnv* env, jobject obj, jfieldID fieldID, jdouble val) { enterJVM(); leaveJVM(); NYI(); } -jmethodID JNICALL GetStaticMethodID(JNIEnv* env, jclass clazz, const char* name, const char* sig) { enterJVM(); leaveJVM(); NYI(); } +jmethodID JNICALL GetStaticMethodID(JNIEnv* env, jclass clazz, const char* name, const char* sig) { + jmethodID res; + + enterJVM(); + + J3ObjectType* cl = J3ObjectType::nativeClass(clazz); + fprintf(stderr, "cl: %p %p\n", clazz, cl); + cl->initialise(); + vmkit::Names* n = cl->loader()->vm()->names(); + res = cl->findStaticMethod(n->get(name), n->get(sig)); + + leaveJVM(); + + return res; +} jobject JNICALL CallStaticObjectMethod(JNIEnv* env, jclass clazz, jmethodID methodID, ...) { enterJVM(); leaveJVM(); NYI(); } jobject JNICALL CallStaticObjectMethodV(JNIEnv* env, jclass clazz, jmethodID methodID, va_list args) { enterJVM(); leaveJVM(); NYI(); } From gael.thomas at lip6.fr Sat Dec 21 09:13:09 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sat, 21 Dec 2013 17:13:09 -0000 Subject: [vmkit-commits] [vmkit] r197865 - Port on Linux Message-ID: <20131221171309.BE0912A6C029@llvm.org> Author: gthomas Date: Sat Dec 21 11:13:08 2013 New Revision: 197865 URL: http://llvm.org/viewvc/llvm-project?rev=197865&view=rev Log: Port on Linux Added: vmkit/branches/mcjit/include/vmkit/config.h.in vmkit/branches/mcjit/include/vmkit/system.h Modified: vmkit/branches/mcjit/Makefile.config.in vmkit/branches/mcjit/Makefile.rules vmkit/branches/mcjit/autoconf/configure.ac vmkit/branches/mcjit/configure vmkit/branches/mcjit/include/j3/j3config.h.in vmkit/branches/mcjit/include/j3/j3lib.h vmkit/branches/mcjit/include/vmkit/ (props changed) vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc vmkit/branches/mcjit/lib/j3/vm/j3.cc vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc vmkit/branches/mcjit/lib/j3/vm/j3options.cc vmkit/branches/mcjit/lib/j3/vm/j3zip.cc vmkit/branches/mcjit/lib/vmkit/compiler.cc vmkit/branches/mcjit/lib/vmkit/names.cc vmkit/branches/mcjit/lib/vmkit/safpoint.cc vmkit/branches/mcjit/lib/vmkit/thread.cc vmkit/branches/mcjit/lib/vmkit/util.cc vmkit/branches/mcjit/lib/vmkit/vmkit.cc Modified: vmkit/branches/mcjit/Makefile.config.in URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/Makefile.config.in?rev=197865&r1=197864&r2=197865&view=diff ============================================================================== --- vmkit/branches/mcjit/Makefile.config.in (original) +++ vmkit/branches/mcjit/Makefile.config.in Sat Dec 21 11:13:08 2013 @@ -1,5 +1,6 @@ -SHOPT=@SHOPT@ +SHALL=@SHALL@ +SHNOALL=@SHNOALL@ EXEEXT=@EXEEXT@ SHLIBEXT=@SHLIBEXT@ Modified: vmkit/branches/mcjit/Makefile.rules URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/Makefile.rules?rev=197865&r1=197864&r2=197865&view=diff ============================================================================== --- vmkit/branches/mcjit/Makefile.rules (original) +++ vmkit/branches/mcjit/Makefile.rules Sat Dec 21 11:13:08 2013 @@ -35,7 +35,7 @@ endif ############################################################################### COMMON_FLAGS:=-Wall -Wno-return-type-c-linkage -Wno-varargs -Wno-unused-private-field -Werror -Wno-unused-variable \ -I$(PROJ_SRC_ROOT)/include -I$(OPENJDK_HOME)/include -I$(OPENJDK_HOME)/include/$(OS) $(COMMON_FLAGS) \ - -fno-omit-frame-pointer + -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer ifeq ($(OPTIMIZED),1) COMMON_FLAGS+=-O3 @@ -52,11 +52,8 @@ endif LLCFLAGS+=-disable-cfi -disable-fp-elim -relocation-model=pic OPTFLAGS+=-disable-cfi -disable-fp-elim -disable-opt -#LDFLAGS=-fno-common -Wl,-flat_namespace -Wl,-undefined,suppress -Wl,-rpath,$(OPENJDK_HOME)/jre/lib/server -#LDFLAGS=-Wl,-rpath,$(OPENJDK_HOME)/jre/lib/server -#LDFLAGS=-Wl,-flat_namespace -rdynamic -CXXFLAGS=$(COMMON_FLAGS) $(LLVM_CXXFLAGS) -std=gnu++98 -fPIC -SHFLAGS=$(SHOPT) -fno-common -Wl,-flat_namespace -Wl,-undefined,suppress +CXXFLAGS=$(LLVM_CXXFLAGS) $(COMMON_FLAGS) -std=gnu++98 -fPIC +SHFLAGS=-lpthread -ldl -lz -lncurses -fno-common -Wl,-flat_namespace -Wl,-undefined,suppress ############################################################################### # Targets @@ -93,7 +90,7 @@ RECURSIVE_TARGETS=all clean define do_sub_target $1:: #$(Echo) "Entering directory $$(PROF)/$2" - $(Verb) $(MAKE) $(SUB_OPT) -C $2 $1 PROF=$(PROF)/$2; \ + $(Verb) +$(MAKE) $(SUB_OPT) -C $2 $1 PROF=$(PROF)/$2; \ if [ $$$$? != 0 ]; then echo "$$(EchoMsg) abort with errors in $$(PROF)/$2"; exit 1; fi endef @@ -141,8 +138,6 @@ define find-sources $(basename $(notdir $(wildcard $(PROJ_SRC_CWD)/*$1))) endef -# $(wildcard $(BUILD_DIR)/*$1))) - ifndef BASE_OBJ_FILES BASE_OBJ_FILES=$(call find-sources,.cc) endif @@ -279,7 +274,7 @@ DOM=then mv -f "$(BUILD_DIR)/$$*.d.tmp" $(SONAME)$(SHLIBEXT): $(SO_FILES) $(Echo) "Linking shared library '$(notdir $@)'" - $(Verb) $(CLANGXX) -shared $(LLVM_LDFLAGS) $(SHFLAGS) -o $@ $(SHFLAGS) $^ $(SO_LIBS) + $(Verb) $(CLANGXX) -shared $(LLVM_LDFLAGS) $(SHFLAGS) -o $@ $(SHALL) $^ $(SHNOALL) $(SO_LIBS) $(GEN_MODULE).bc: $(BC_FILES) $(Echo) "Linking bc module '$(notdir $@)'" @@ -287,7 +282,7 @@ $(GEN_MODULE).bc: $(BC_FILES) $(GEN_MODULE).a: $(GC_OBJ_FILES) $(Echo) "Linking module '$(notdir $@)'" - $(Verb) libtool -static -o $@ $^ + $(Verb) ar cru $@ $^ && ranlib $@ %.o: %.bc $(Echo) "Assembling '$(notdir $<)'" Modified: vmkit/branches/mcjit/autoconf/configure.ac URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/autoconf/configure.ac?rev=197865&r1=197864&r2=197865&view=diff ============================================================================== --- vmkit/branches/mcjit/autoconf/configure.ac (original) +++ vmkit/branches/mcjit/autoconf/configure.ac Sat Dec 21 11:13:08 2013 @@ -44,6 +44,7 @@ AC_CANONICAL_TARGET dnl Determine the platform type and cache its value. This helps us configure dnl the System library to the correct build platform. +dnl Make sure we aren't attempting to configure for an unknown system AC_CACHE_CHECK([type of operating system we're going to host on], [vmkit_cv_os_type], [case $host in @@ -56,8 +57,8 @@ AC_CACHE_CHECK([type of operating system *-*-darwin*) OS="darwin" SHLIBEXT=".dylib" -# SHOPT="-fno-common -Wl,-flat_namespace -Wl,-undefined,suppress" - SHOPT="-Wl,-all_load -Wl,-compatibility_version,1 -Wl,-current_version,1" + SHALL="-Wl,-all_load -Wl,-compatibility_version,1 -Wl,-current_version,1" + SHNOALL="" EXEEXT="" ;; *-*-freebsd*) AC_MSG_ERROR([Good luck porting vmkit to your host!]) ;; @@ -70,7 +71,11 @@ AC_CACHE_CHECK([type of operating system *-*-interix*) AC_MSG_ERROR([Good luck porting vmkit to your host!]) ;; *-*-linux*) - AC_MSG_ERROR([Good luck porting vmkit to your host!]) ;; + OS="linux" + SHLIBEXT=".so" + SHALL="-Wl,--whole-archive" + SHNOALL="-Wl,--no-whole-archive" + EXEEXT="" ;; *-*-solaris*) AC_MSG_ERROR([Good luck porting vmkit to your host!]) ;; *-*-win32*) @@ -81,10 +86,10 @@ AC_CACHE_CHECK([type of operating system AC_MSG_ERROR([Good luck porting vmkit to your host!]) ;; esac]) -dnl Make sure we aren't attempting to configure for an unknown system AC_SUBST([OS]) AC_SUBST([SHLIBEXT]) -AC_SUBST([SHOPT]) +AC_SUBST([SHALL]) +AC_SUBST([SHNOALL]) AC_SUBST([EXEEXT]) dnl===-----------------------------------------------------------------------=== @@ -222,10 +227,7 @@ dnl=== dnl=== SECTION 4: Check for programs we need and that they are the right version dnl=== dnl===-----------------------------------------------------------------------=== -dnl Check for compilation tools AC_PROG_CPP - -dnl Find the install program AC_PROG_INSTALL dnl AC_SUBST(SHLIBEXT,$libltdl_cv_shlibext) @@ -233,7 +235,7 @@ dnl AC_SUBST(SHLIBEXT,$libltdl_cv_shlibe AC_DEFUN([AX_PATH_PROG_FAIL_OR_SUBST], [ AC_PATH_PROG([$1], [$2], [no], [$3:$PATH]) if test x"${$1}" == x"no"; then - AC_MSG_ERROR([Unable to find $2, please install $2]) + AC_MSG_ERROR([Unable to find $2, please install it]) fi AC_SUBST([$1]) ]) @@ -252,6 +254,8 @@ dnl=== SECTION 5: Check for libraries dnl=== dnl===-----------------------------------------------------------------------=== +dnl have to check: zlib, ncurses + dnl===-----------------------------------------------------------------------=== dnl=== dnl=== SECTION 6: Check for header files @@ -283,7 +287,7 @@ dnl=== dnl===-----------------------------------------------------------------------=== dnl Configure header files -AC_CONFIG_FILES([Makefile.config include/j3/j3config.h]) +AC_CONFIG_FILES([Makefile.config include/vmkit/config.h include/j3/j3config.h]) AC_SUBST([ac_config_files]) AC_SUBST([ac_config_headers]) Modified: vmkit/branches/mcjit/configure URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/configure?rev=197865&r1=197864&r2=197865&view=diff ============================================================================== --- vmkit/branches/mcjit/configure (original) +++ vmkit/branches/mcjit/configure Sat Dec 21 11:13:08 2013 @@ -1,11 +1,13 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for vmkit 0.1. +# Generated by GNU Autoconf 2.68 for vmkit 0.1. # # Report bugs to . # # -# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, +# 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software +# Foundation, Inc. # # # This configure script is free software; the Free Software Foundation @@ -136,31 +138,6 @@ export LANGUAGE # CDPATH. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH -# Use a proper internal environment variable to ensure we don't fall - # into an infinite loop, continuously re-executing ourselves. - if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then - _as_can_reexec=no; export _as_can_reexec; - # We cannot yet assume a decent shell, so we have to provide a -# neutralization value for shells without unset; and this also -# works around shells that cannot unset nonexistent variables. -# Preserve -v and -x to the replacement shell. -BASH_ENV=/dev/null -ENV=/dev/null -(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV -case $- in # (((( - *v*x* | *x*v* ) as_opts=-vx ;; - *v* ) as_opts=-v ;; - *x* ) as_opts=-x ;; - * ) as_opts= ;; -esac -exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} -# Admittedly, this is quite paranoid, since all the known shells bail -# out after a failed `exec'. -$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 -as_fn_exit 255 - fi - # We don't want this to propagate to other subprocesses. - { _as_can_reexec=; unset _as_can_reexec;} if test "x$CONFIG_SHELL" = x; then as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then : emulate sh @@ -194,8 +171,7 @@ if ( set x; as_fn_ret_success y && test else exitcode=1; echo positional parameters were not saved. fi -test x\$exitcode = x0 || exit 1 -test -x / || exit 1" +test x\$exitcode = x0 || exit 1" as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" && @@ -239,25 +215,21 @@ IFS=$as_save_IFS if test "x$CONFIG_SHELL" != x; then : - export CONFIG_SHELL - # We cannot yet assume a decent shell, so we have to provide a -# neutralization value for shells without unset; and this also -# works around shells that cannot unset nonexistent variables. -# Preserve -v and -x to the replacement shell. -BASH_ENV=/dev/null -ENV=/dev/null -(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV -case $- in # (((( - *v*x* | *x*v* ) as_opts=-vx ;; - *v* ) as_opts=-v ;; - *x* ) as_opts=-x ;; - * ) as_opts= ;; -esac -exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} -# Admittedly, this is quite paranoid, since all the known shells bail -# out after a failed `exec'. -$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 -exit 255 + # We cannot yet assume a decent shell, so we have to provide a + # neutralization value for shells without unset; and this also + # works around shells that cannot unset nonexistent variables. + # Preserve -v and -x to the replacement shell. + BASH_ENV=/dev/null + ENV=/dev/null + (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV + export CONFIG_SHELL + case $- in # (((( + *v*x* | *x*v* ) as_opts=-vx ;; + *v* ) as_opts=-v ;; + *x* ) as_opts=-x ;; + * ) as_opts= ;; + esac + exec "$CONFIG_SHELL" $as_opts "$as_myself" ${1+"$@"} fi if test x$as_have_required = xno; then : @@ -360,14 +332,6 @@ $as_echo X"$as_dir" | } # as_fn_mkdir_p - -# as_fn_executable_p FILE -# ----------------------- -# Test if FILE is an executable regular file. -as_fn_executable_p () -{ - test -f "$1" && test -x "$1" -} # as_fn_executable_p # as_fn_append VAR VALUE # ---------------------- # Append the text in VALUE to the end of the definition contained in VAR. Take @@ -489,10 +453,6 @@ as_cr_alnum=$as_cr_Letters$as_cr_digits chmod +x "$as_me.lineno" || { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } - # If we had to re-execute with $CONFIG_SHELL, we're ensured to have - # already done that, so ensure we don't try to do so again and fall - # in an infinite loop. This has already happened in practice. - _as_can_reexec=no; export _as_can_reexec # Don't try to exec as it changes $[0], causing all sort of problems # (the dirname of $[0] is not the place where we might find the # original and so on. Autoconf is especially sensitive to this). @@ -527,16 +487,16 @@ if (echo >conf$$.file) 2>/dev/null; then # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. - # In both cases, we have to default to `cp -pR'. + # In both cases, we have to default to `cp -p'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || - as_ln_s='cp -pR' + as_ln_s='cp -p' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else - as_ln_s='cp -pR' + as_ln_s='cp -p' fi else - as_ln_s='cp -pR' + as_ln_s='cp -p' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null @@ -548,8 +508,28 @@ else as_mkdir_p=false fi -as_test_x='test -x' -as_executable_p=as_fn_executable_p +if test -x / >/dev/null 2>&1; then + as_test_x='test -x' +else + if ls -dL / >/dev/null 2>&1; then + as_ls_L_option=L + else + as_ls_L_option= + fi + as_test_x=' + eval sh -c '\'' + if test -d "$1"; then + test -d "$1/."; + else + case $1 in #( + -*)set "./$1";; + esac; + case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #(( + ???[sx]*):;;*)false;;esac;fi + '\'' sh + ' +fi +as_executable_p=$as_test_x # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" @@ -617,7 +597,8 @@ ASSERT DEBUG OPTIMIZED EXEEXT -SHOPT +SHNOALL +SHALL SHLIBEXT OS target_os @@ -1145,6 +1126,8 @@ target=$target_alias if test "x$host_alias" != x; then if test "x$build_alias" = x; then cross_compiling=maybe + $as_echo "$as_me: WARNING: if you wanted to set the --build type, don't use --host. + If a cross compiler is detected then cross compile mode will be used" >&2 elif test "x$build_alias" != "x$host_alias"; then cross_compiling=yes fi @@ -1398,9 +1381,9 @@ test -n "$ac_init_help" && exit $ac_stat if $ac_init_version; then cat <<\_ACEOF vmkit configure 0.1 -generated by GNU Autoconf 2.69 +generated by GNU Autoconf 2.68 -Copyright (C) 2012 Free Software Foundation, Inc. +Copyright (C) 2010 Free Software Foundation, Inc. This configure script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. @@ -1492,7 +1475,7 @@ This file contains any messages produced running configure, to aid debugging if configure makes a mistake. It was created by vmkit $as_me 0.1, which was -generated by GNU Autoconf 2.69. Invocation command line was +generated by GNU Autoconf 2.68. Invocation command line was $ $0 $@ @@ -2002,8 +1985,8 @@ else *-*-darwin*) OS="darwin" SHLIBEXT=".dylib" -# SHOPT="-fno-common -Wl,-flat_namespace -Wl,-undefined,suppress" - SHOPT="-Wl,-all_load -Wl,-compatibility_version,1 -Wl,-current_version,1" + SHALL="-Wl,-all_load -Wl,-compatibility_version,1 -Wl,-current_version,1" + SHNOALL="" EXEEXT="" ;; *-*-freebsd*) as_fn_error $? "Good luck porting vmkit to your host!" "$LINENO" 5 ;; @@ -2016,7 +1999,11 @@ else *-*-interix*) as_fn_error $? "Good luck porting vmkit to your host!" "$LINENO" 5 ;; *-*-linux*) - as_fn_error $? "Good luck porting vmkit to your host!" "$LINENO" 5 ;; + OS="linux" + SHLIBEXT=".so" + SHALL="-Wl,--whole-archive" + SHNOALL="-Wl,--no-whole-archive" + EXEEXT="" ;; *-*-solaris*) as_fn_error $? "Good luck porting vmkit to your host!" "$LINENO" 5 ;; *-*-win32*) @@ -2036,6 +2023,7 @@ $as_echo "$vmkit_cv_os_type" >&6; } + # Check whether --enable-optimized was given. if test "${enable_optimized+set}" = set; then : enableval=$enable_optimized; @@ -2200,7 +2188,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CC="${ac_tool_prefix}gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2240,7 +2228,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_CC="gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2293,7 +2281,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CC="${ac_tool_prefix}cc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2334,7 +2322,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then ac_prog_rejected=yes continue @@ -2392,7 +2380,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CC="$ac_tool_prefix$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2436,7 +2424,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_CC="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2882,7 +2870,8 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ /* end confdefs.h. */ #include #include -struct stat; +#include +#include /* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ struct buf { int x; }; FILE * (*rcsopen) (struct buf *, struct stat *, int); @@ -3104,7 +3093,6 @@ ac_compile='$CC -c $CFLAGS $CPPFLAGS con ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu - # Find a good install program. We prefer a C program (faster), # so one script is as good as another. But avoid the broken or # incompatible versions: @@ -3142,7 +3130,7 @@ case $as_dir/ in #(( # by default. for ac_prog in ginstall scoinst install; do for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext"; then + if { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; }; then if test $ac_prog = install && grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then # AIX install. It has an incompatible calling convention. @@ -3222,7 +3210,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_path_LLC="$as_dir/$ac_word$ac_exec_ext" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3246,7 +3234,7 @@ fi if test x"${LLC}" == x"no"; then - as_fn_error $? "Unable to find llc, please install llc" "$LINENO" 5 + as_fn_error $? "Unable to find llc, please install it" "$LINENO" 5 fi @@ -3270,7 +3258,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_path_LLOPT="$as_dir/$ac_word$ac_exec_ext" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3294,7 +3282,7 @@ fi if test x"${LLOPT}" == x"no"; then - as_fn_error $? "Unable to find opt, please install opt" "$LINENO" 5 + as_fn_error $? "Unable to find opt, please install it" "$LINENO" 5 fi @@ -3318,7 +3306,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_path_LLLINK="$as_dir/$ac_word$ac_exec_ext" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3342,7 +3330,7 @@ fi if test x"${LLLINK}" == x"no"; then - as_fn_error $? "Unable to find llvm-link, please install llvm-link" "$LINENO" 5 + as_fn_error $? "Unable to find llvm-link, please install it" "$LINENO" 5 fi @@ -3366,7 +3354,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_path_LLNM="$as_dir/$ac_word$ac_exec_ext" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3390,7 +3378,7 @@ fi if test x"${LLNM}" == x"no"; then - as_fn_error $? "Unable to find llvm-nm, please install llvm-nm" "$LINENO" 5 + as_fn_error $? "Unable to find llvm-nm, please install it" "$LINENO" 5 fi @@ -3414,7 +3402,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_path_CLANG="$as_dir/$ac_word$ac_exec_ext" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3438,7 +3426,7 @@ fi if test x"${CLANG}" == x"no"; then - as_fn_error $? "Unable to find clang, please install clang" "$LINENO" 5 + as_fn_error $? "Unable to find clang, please install it" "$LINENO" 5 fi @@ -3462,7 +3450,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_path_CLANGXX="$as_dir/$ac_word$ac_exec_ext" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3486,7 +3474,7 @@ fi if test x"${CLANGXX}" == x"no"; then - as_fn_error $? "Unable to find clang++, please install clang++" "$LINENO" 5 + as_fn_error $? "Unable to find clang++, please install it" "$LINENO" 5 fi @@ -3510,7 +3498,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_path_GAWK="$as_dir/$ac_word$ac_exec_ext" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3534,7 +3522,7 @@ fi if test x"${GAWK}" == x"no"; then - as_fn_error $? "Unable to find gawk, please install gawk" "$LINENO" 5 + as_fn_error $? "Unable to find gawk, please install it" "$LINENO" 5 fi @@ -3545,7 +3533,8 @@ fi -ac_config_files="$ac_config_files Makefile.config include/j3/j3config.h" + +ac_config_files="$ac_config_files Makefile.config include/vmkit/config.h include/j3/j3config.h" @@ -3994,16 +3983,16 @@ if (echo >conf$$.file) 2>/dev/null; then # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. - # In both cases, we have to default to `cp -pR'. + # In both cases, we have to default to `cp -p'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || - as_ln_s='cp -pR' + as_ln_s='cp -p' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else - as_ln_s='cp -pR' + as_ln_s='cp -p' fi else - as_ln_s='cp -pR' + as_ln_s='cp -p' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null @@ -4063,16 +4052,28 @@ else as_mkdir_p=false fi - -# as_fn_executable_p FILE -# ----------------------- -# Test if FILE is an executable regular file. -as_fn_executable_p () -{ - test -f "$1" && test -x "$1" -} # as_fn_executable_p -as_test_x='test -x' -as_executable_p=as_fn_executable_p +if test -x / >/dev/null 2>&1; then + as_test_x='test -x' +else + if ls -dL / >/dev/null 2>&1; then + as_ls_L_option=L + else + as_ls_L_option= + fi + as_test_x=' + eval sh -c '\'' + if test -d "$1"; then + test -d "$1/."; + else + case $1 in #( + -*)set "./$1";; + esac; + case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #(( + ???[sx]*):;;*)false;;esac;fi + '\'' sh + ' +fi +as_executable_p=$as_test_x # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" @@ -4094,7 +4095,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_wri # values after options handling. ac_log=" This file was extended by vmkit $as_me 0.1, which was -generated by GNU Autoconf 2.69. Invocation command line was +generated by GNU Autoconf 2.68. Invocation command line was CONFIG_FILES = $CONFIG_FILES CONFIG_HEADERS = $CONFIG_HEADERS @@ -4147,10 +4148,10 @@ cat >>$CONFIG_STATUS <<_ACEOF || ac_writ ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ vmkit config.status 0.1 -configured by $0, generated by GNU Autoconf 2.69, +configured by $0, generated by GNU Autoconf 2.68, with options \\"\$ac_cs_config\\" -Copyright (C) 2012 Free Software Foundation, Inc. +Copyright (C) 2010 Free Software Foundation, Inc. This config.status script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it." @@ -4228,7 +4229,7 @@ fi _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 if \$ac_cs_recheck; then - set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion + set X '$SHELL' '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion shift \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6 CONFIG_SHELL='$SHELL' @@ -4258,6 +4259,7 @@ for ac_config_target in $ac_config_targe do case $ac_config_target in "Makefile.config") CONFIG_FILES="$CONFIG_FILES Makefile.config" ;; + "include/vmkit/config.h") CONFIG_FILES="$CONFIG_FILES include/vmkit/config.h" ;; "include/j3/j3config.h") CONFIG_FILES="$CONFIG_FILES include/j3/j3config.h" ;; *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; Modified: vmkit/branches/mcjit/include/j3/j3config.h.in URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3config.h.in?rev=197865&r1=197864&r2=197865&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3config.h.in (original) +++ vmkit/branches/mcjit/include/j3/j3config.h.in Sat Dec 21 11:13:08 2013 @@ -1,6 +1,7 @@ -#define SHLIBEXT "@SHLIBEXT@" -#define OPENJDK_HOME "@jdkhome@" +#define SELF_LIBJVM "@abs_top_builddir@/@BUILD_NAME@/lib/libjvm at SHLIBEXT@" +#define SELF_BITCODE "@abs_top_builddir@/@BUILD_NAME@/lib/libjvm.bc" +#define OPENJDK_HOME "@jdkhome@/" Modified: vmkit/branches/mcjit/include/j3/j3lib.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3lib.h?rev=197865&r1=197864&r2=197865&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3lib.h (original) +++ vmkit/branches/mcjit/include/j3/j3lib.h Sat Dec 21 11:13:08 2013 @@ -9,7 +9,7 @@ namespace j3 { class J3Lib { public: - static const char** systemClassesArchives(); + static const char* systemClassesArchives(); static int loadSystemLibraries(std::vector >* handles); }; } Propchange: vmkit/branches/mcjit/include/vmkit/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Sat Dec 21 11:13:08 2013 @@ -0,0 +1 @@ +config.h Added: vmkit/branches/mcjit/include/vmkit/config.h.in URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/config.h.in?rev=197865&view=auto ============================================================================== --- vmkit/branches/mcjit/include/vmkit/config.h.in (added) +++ vmkit/branches/mcjit/include/vmkit/config.h.in Sat Dec 21 11:13:08 2013 @@ -0,0 +1,3 @@ + + +#define SHLIBEXT "@SHLIBEXT@" \ No newline at end of file Added: vmkit/branches/mcjit/include/vmkit/system.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/system.h?rev=197865&view=auto ============================================================================== --- vmkit/branches/mcjit/include/vmkit/system.h (added) +++ vmkit/branches/mcjit/include/vmkit/system.h Sat Dec 21 11:13:08 2013 @@ -0,0 +1,51 @@ +#ifndef _SYSTEM_H_ +#define _SYSTEM_H_ + +#include + +#if defined(__linux__) || defined(__FreeBSD__) +#define LINUX_OS 1 +#elif defined(__APPLE__) +#define MACOS_OS 1 +#else +#error OS detection failed. +#endif + +#include + +#if defined(MACOS_OS) +#define SELF_HANDLE RTLD_SELF +#elif defined(LINUX_OS) +#define SELF_HANDLE 0 +#else +#error Please define constants for your OS. +#endif + +namespace vmkit { + class System { + public: + static const char* mcjitSymbol(const std::string &Name) { +#if defined(MACOS_OS) + return Name.c_str() + 1; +#elif defined(LINUX_OS) + return Name.c_str(); +#else +#error "what is the correct symbol for your os?" +#endif + } + + static void** current_fp() __attribute__((always_inline)) { + return (void**)__builtin_frame_address(0); + } + + static void** fp_to_next_fp(void** fp) { + return (void**)fp[0]; + } + + static void* fp_to_ip(void**fp) { + return fp[1]; + } + }; +} + +#endif Modified: vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc?rev=197865&r1=197864&r2=197865&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc (original) +++ vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc Sat Dec 21 11:13:08 2013 @@ -1,3 +1,5 @@ +#include "vmkit/config.h" +#include "vmkit/system.h" #include "j3/j3object.h" #include "j3/j3lib.h" #include "j3/j3config.h" @@ -14,19 +16,17 @@ using namespace j3; #define enterJVM() #define leaveJVM() -#define NYI() { fprintf(stderr, "++ not yet implemented: %s ++\n", __PRETTY_FUNCTION__); abort(); } +#define NYI() { J3Thread::get()->vm()->internalError(L"not yet implemented: '%s'", __PRETTY_FUNCTION__); } -#define OPENJDK_PATH OPENJDK_HOME"/jre" -#define OPENJDK_LIBPATH OPENJDK_PATH"/lib" -#define OPENJDK_RT OPENJDK_LIBPATH"/rt.jar" -#define OPENJDK_LIB OPENJDK_LIBPATH"/libjava"SHLIBEXT - -static const char* rtjar[] = { - OPENJDK_LIBPATH"/rt.jar", - 0 -}; +#ifdef LINUX_OS +#define OPENJDK_LIBPATH OPENJDK_HOME"jre/lib/amd64" +#else +#define OPENJDK_LIBPATH OPENJDK_HOME"jre/lib" +#endif -const char** J3Lib::systemClassesArchives() { +static const char* rtjar = OPENJDK_HOME"jre/lib/rt.jar"; + +const char* J3Lib::systemClassesArchives() { return rtjar; } Modified: vmkit/branches/mcjit/lib/j3/vm/j3.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3.cc?rev=197865&r1=197864&r2=197865&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3.cc Sat Dec 21 11:13:08 2013 @@ -178,10 +178,11 @@ void J3::linkageError(J3Method* method) void J3::vinternalError(const wchar_t* msg, va_list va) { vmkit::Safepoint* sf = 0; vmkit::StackWalker walker; + wchar_t buf[65536]; - fprintf(stderr, "Internal error: "); - vfwprintf(stderr, msg, va); - fprintf(stderr, "\n"); + vswprintf(buf, 65536, msg, va); + + fprintf(stderr, "Internal error: %ls\n", buf); while(walker.next()) { vmkit::Safepoint* sf = getSafepoint(walker.ip()); Modified: vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc?rev=197865&r1=197864&r2=197865&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc Sat Dec 21 11:13:08 2013 @@ -210,8 +210,8 @@ bool J3ClassLoader::J3MethodLess::operat J3InitialClassLoader::J3InitialClassLoader(J3* v, const char* rtjar, vmkit::BumpAllocator* _alloc) : J3ClassLoader(v, 0, _alloc) { - const char** archives = J3Lib::systemClassesArchives(); - J3ClassBytes* bytes = J3Reader::openFile(allocator(), archives[0]); + const char* archives = vm()->options()->rtJar; + J3ClassBytes* bytes = J3Reader::openFile(allocator(), archives); //makeLLVMFunctions_j3(); Modified: vmkit/branches/mcjit/lib/j3/vm/j3options.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3options.cc?rev=197865&r1=197864&r2=197865&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3options.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3options.cc Sat Dec 21 11:13:08 2013 @@ -1,4 +1,6 @@ #include "j3/j3options.h" +#include "j3/j3config.h" +#include "j3/j3lib.h" #include #include @@ -8,12 +10,12 @@ using namespace j3; J3Options::J3Options() { assertionsEnabled = 1; - selfBitCodePath = "/Users/gthomas/research/vmkit4/vmkit/Debug+Asserts/lib/libjvm.bc"; - rtJar = "/Users/gthomas/research/vmkit4/jdk8/build/macosx-x86_64-normal-server-release/images/lib/rt.jar"; + selfBitCodePath = SELF_BITCODE; + rtJar = J3Lib::systemClassesArchives(); debugEnterIndent = 1; - debugExecute = 0; + debugExecute = 2; debugLoad = 0; debugResolve = 0; debugIniting = 0; Modified: vmkit/branches/mcjit/lib/j3/vm/j3zip.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3zip.cc?rev=197865&r1=197864&r2=197865&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3zip.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3zip.cc Sat Dec 21 11:13:08 2013 @@ -5,6 +5,7 @@ //===----------------------------------------------------------------------===// #include +#include #include "j3/j3reader.h" #include "j3/j3zip.h" Modified: vmkit/branches/mcjit/lib/vmkit/compiler.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/compiler.cc?rev=197865&r1=197864&r2=197865&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/compiler.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/compiler.cc Sat Dec 21 11:13:08 2013 @@ -1,5 +1,6 @@ #include +#include "vmkit/system.h" #include "vmkit/compiler.h" #include "vmkit/thread.h" #include "vmkit/vmkit.h" @@ -9,6 +10,8 @@ #include "llvm/PassManager.h" #include "llvm/ExecutionEngine/ExecutionEngine.h" +#include "llvm/ExecutionEngine/MCJIT.h" +#include "llvm/ExecutionEngine/JIT.h" #include "llvm/IR/Module.h" @@ -114,7 +117,7 @@ Symbol* CompilationUnit::getSymbol(const vmkit::Symbol* res; if(it == _symbolTable.end()) { - uint8_t* addr = (uint8_t*)dlsym(RTLD_SELF, id); + uint8_t* addr = (uint8_t*)dlsym(SELF_HANDLE, id); if(!addr) Thread::get()->vm()->internalError(L"unable to resolve native symbol: %s", id); res = new(allocator()) vmkit::NativeSymbol(addr); @@ -130,7 +133,7 @@ Symbol* CompilationUnit::getSymbol(const } uint64_t CompilationUnit::getSymbolAddress(const std::string &Name) { - return (uint64_t)(uintptr_t)getSymbol(Name.c_str() + 1)->getSymbolAddress(); + return (uint64_t)(uintptr_t)getSymbol(System::mcjitSymbol(Name))->getSymbolAddress(); } void CompilationUnit::compileModule(llvm::Module* module) { Modified: vmkit/branches/mcjit/lib/vmkit/names.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/names.cc?rev=197865&r1=197864&r2=197865&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/names.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/names.cc Sat Dec 21 11:13:08 2013 @@ -1,4 +1,5 @@ #include +#include #include "vmkit/names.h" Modified: vmkit/branches/mcjit/lib/vmkit/safpoint.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/safpoint.cc?rev=197865&r1=197864&r2=197865&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/safpoint.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/safpoint.cc Sat Dec 21 11:13:08 2013 @@ -1,5 +1,6 @@ #include "vmkit/safepoint.h" #include "vmkit/compiler.h" +#include "vmkit/system.h" #include "llvm/IR/Function.h" #include "llvm/IR/Constants.h" @@ -184,10 +185,11 @@ Safepoint* Safepoint::getNext() { } Safepoint* Safepoint::get(CompilationUnit* unit, llvm::Module* module) { - llvm::SmallString<256> symName; + std::string symName; + symName += '_'; symName += module->getModuleIdentifier(); symName += "__frametable"; - return (vmkit::Safepoint*)unit->ee()->getGlobalValueAddress(symName.c_str()); + return (vmkit::Safepoint*)unit->ee()->getGlobalValueAddress(System::mcjitSymbol(symName)); } void Safepoint::dump() { Modified: vmkit/branches/mcjit/lib/vmkit/thread.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/thread.cc?rev=197865&r1=197864&r2=197865&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/thread.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/thread.cc Sat Dec 21 11:13:08 2013 @@ -1,4 +1,5 @@ #include "vmkit/thread.h" +#include "vmkit/system.h" using namespace vmkit; @@ -14,14 +15,14 @@ void Thread::destroy(Thread* thread) { } StackWalker::StackWalker(uint32_t initialPop) { - framePointer = (void**)__builtin_frame_address(1); - next(initialPop); + framePointer = System::current_fp(); + next(initialPop+1); } bool StackWalker::next(uint32_t nbPop) { while(nbPop--) { - void** next = (void**)framePointer[0]; - if(!next || !next[0]) + void** next = (void**)System::fp_to_next_fp(framePointer); + if(!next || !System::fp_to_next_fp(next)) return 0; framePointer = next; } @@ -29,5 +30,5 @@ bool StackWalker::next(uint32_t nbPop) { } void* StackWalker::ip() { - return framePointer[1]; + return System::fp_to_ip(framePointer); } Modified: vmkit/branches/mcjit/lib/vmkit/util.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/util.cc?rev=197865&r1=197864&r2=197865&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/util.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/util.cc Sat Dec 21 11:13:08 2013 @@ -1,5 +1,6 @@ #include "vmkit/util.h" +#include #include #include Modified: vmkit/branches/mcjit/lib/vmkit/vmkit.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/vmkit.cc?rev=197865&r1=197864&r2=197865&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/vmkit.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/vmkit.cc Sat Dec 21 11:13:08 2013 @@ -3,8 +3,8 @@ #include #include #include -#include +#include "vmkit/system.h" #include "vmkit/vmkit.h" #include "vmkit/thread.h" #include "vmkit/safepoint.h" @@ -105,11 +105,11 @@ void VMKit::vmkitBootstrap(Thread* initi std::string err; llvm::OwningPtr buf; if (llvm::MemoryBuffer::getFile(selfBitCodePath, buf)) - VMKit::internalError(L"Error while opening bitcode file %s\n", selfBitCodePath); + VMKit::internalError(L"Error while opening bitcode file %s", selfBitCodePath); _self = llvm::getLazyBitcodeModule(buf.take(), llvm::getGlobalContext(), &err); if(!self()) - VMKit::internalError(L"Error while reading bitcode file %s: %s\n", selfBitCodePath, err.c_str()); + VMKit::internalError(L"Error while reading bitcode file %s: %s", selfBitCodePath, err.c_str()); for(llvm::Module::iterator cur=self()->begin(); cur!=self()->end(); cur++) addSymbol(cur); @@ -120,7 +120,7 @@ void VMKit::vmkitBootstrap(Thread* initi _dataLayout = new llvm::DataLayout(self()); llvm::GlobalValue* typeInfoGV = mangleMap["typeinfo for void*"]; - ptrTypeInfo = typeInfoGV ? dlsym(RTLD_SELF, typeInfoGV->getName().data()) : 0; + ptrTypeInfo = typeInfoGV ? dlsym(SELF_HANDLE, typeInfoGV->getName().data()) : 0; if(!ptrTypeInfo) internalError(L"unable to find typeinfo for void*"); @@ -164,9 +164,12 @@ void VMKit::internalError(const wchar_t* } void VMKit::throwException(void* obj) { +#if 0 void** exception = (void**)abi::__cxa_allocate_exception(sizeof(void*)); *exception = obj; abi::__cxa_throw(exception, (std::type_info*)Thread::get()->vm()->ptrTypeInfo, 0); +#endif + fprintf(stderr, " throw exception...\n"); abort(); } From gael.thomas at lip6.fr Sat Dec 21 10:25:45 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sat, 21 Dec 2013 18:25:45 -0000 Subject: [vmkit-commits] [vmkit] r197867 - * Define a guard to explore the stack Message-ID: <20131221182545.5085A2A6C029@llvm.org> Author: gthomas Date: Sat Dec 21 12:25:44 2013 New Revision: 197867 URL: http://llvm.org/viewvc/llvm-project?rev=197867&view=rev Log: * Define a guard to explore the stack * Keep a ObjectReference from the loader instead of the thread Modified: vmkit/branches/mcjit/include/vmkit/thread.h vmkit/branches/mcjit/lib/j3/vm/j3.cc vmkit/branches/mcjit/lib/j3/vm/j3class.cc vmkit/branches/mcjit/lib/j3/vm/j3options.cc vmkit/branches/mcjit/lib/vmkit/compiler.cc vmkit/branches/mcjit/lib/vmkit/thread.cc Modified: vmkit/branches/mcjit/include/vmkit/thread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/thread.h?rev=197867&r1=197866&r2=197867&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/thread.h (original) +++ vmkit/branches/mcjit/include/vmkit/thread.h Sat Dec 21 12:25:44 2013 @@ -9,6 +9,7 @@ namespace vmkit { class Thread : protected PermanentObject { BumpAllocator* _allocator; VMKit* _vm; + void* _baseFramePointer; protected: Thread(VMKit* vm, BumpAllocator* allocator); @@ -16,6 +17,9 @@ namespace vmkit { public: static void destroy(Thread* thread); + void setBaseFramePointer(void* fp) { _baseFramePointer = fp; } + void* baseFramePointer() { return _baseFramePointer; } + VMKit* vm() { return _vm; } BumpAllocator* allocator() { return _allocator; } @@ -33,6 +37,7 @@ namespace vmkit { bool next(uint32_t nbPop=1); void* ip(); + void* fp() { return framePointer; } }; } Modified: vmkit/branches/mcjit/lib/j3/vm/j3.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3.cc?rev=197867&r1=197866&r2=197867&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3.cc Sat Dec 21 12:25:44 2013 @@ -13,6 +13,7 @@ #include "llvm/IR/DerivedTypes.h" #include "vmkit/safepoint.h" +#include "vmkit/system.h" using namespace j3; @@ -60,7 +61,11 @@ void J3::introspect() { void J3::start(int argc, char** argv) { _options.process(argc, argv); - vmkitBootstrap(J3Thread::create(this), options()->selfBitCodePath); + J3Thread* thread = J3Thread::create(this); + + thread->setBaseFramePointer(vmkit::System::current_fp()); + + vmkitBootstrap(thread, options()->selfBitCodePath); introspect(); Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=197867&r1=197866&r2=197867&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Sat Dec 21 12:25:44 2013 @@ -141,18 +141,15 @@ J3ObjectType* J3ObjectType::nativeClass( } J3ObjectHandle* J3ObjectType::javaClass() { - fprintf(stderr, "javaClass: %p %p %ls\n", _javaClass, this, name()->cStr()); if(!_javaClass) { lock(); if(!_javaClass) { J3ObjectHandle* prev = J3Thread::get()->tell(); _javaClass = J3ObjectHandle::doNewObject(loader()->vm()->classClass); - loader()->fixedPoint()->syncPush(_javaClass); + _javaClass = loader()->fixedPoint()->syncPush(_javaClass); J3Thread::get()->restore(prev); _javaClass->setLong(loader()->vm()->classVMData, (int64_t)(uintptr_t)this); - fprintf(stderr, " -> native class is %p\n", nativeClass(_javaClass)); loader()->vm()->classInit->invokeSpecial(_javaClass); - fprintf(stderr, " %p -> native class is %p\n", _javaClass, nativeClass(_javaClass)); } unlock(); } Modified: vmkit/branches/mcjit/lib/j3/vm/j3options.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3options.cc?rev=197867&r1=197866&r2=197867&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3options.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3options.cc Sat Dec 21 12:25:44 2013 @@ -15,7 +15,7 @@ J3Options::J3Options() { debugEnterIndent = 1; - debugExecute = 2; + debugExecute = 0; debugLoad = 0; debugResolve = 0; debugIniting = 0; Modified: vmkit/branches/mcjit/lib/vmkit/compiler.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/compiler.cc?rev=197867&r1=197866&r2=197867&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/compiler.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/compiler.cc Sat Dec 21 12:25:44 2013 @@ -59,9 +59,13 @@ CompilationUnit::CompilationUnit(BumpAll pm = new llvm::PassManager(); //pm->add(new llvm::TargetData(*ee->getTargetData())); +#if 0 pm->add(llvm::createBasicAliasAnalysisPass()); +#endif pm->add(llvm::createCFGSimplificationPass()); // Clean up disgusting code + +#if 0 pm->add(llvm::createPromoteMemoryToRegisterPass());// Kill useless allocas pm->add(llvm::createInstructionCombiningPass()); // Cleanup for scalarrepl. pm->add(llvm::createScalarReplAggregatesPass()); // Break up aggregate allocas @@ -91,6 +95,7 @@ CompilationUnit::CompilationUnit(BumpAll pm->add(llvm::createDeadStoreEliminationPass()); // Delete dead stores pm->add(llvm::createAggressiveDCEPass()); // Delete dead instructions pm->add(llvm::createCFGSimplificationPass()); // Merge & remove BBs +#endif } CompilationUnit::~CompilationUnit() { Modified: vmkit/branches/mcjit/lib/vmkit/thread.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/thread.cc?rev=197867&r1=197866&r2=197867&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/thread.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/thread.cc Sat Dec 21 12:25:44 2013 @@ -8,6 +8,7 @@ __thread Thread* Thread::_thread = 0; Thread::Thread(VMKit* vm, BumpAllocator* allocator) { _allocator = allocator; _vm = vm; + _baseFramePointer = 0; } void Thread::destroy(Thread* thread) { @@ -21,10 +22,10 @@ StackWalker::StackWalker(uint32_t initia bool StackWalker::next(uint32_t nbPop) { while(nbPop--) { - void** next = (void**)System::fp_to_next_fp(framePointer); - if(!next || !System::fp_to_next_fp(next)) + fprintf(stderr, "%p and %p => %p\n", framePointer, Thread::get()->baseFramePointer(), ip()); + if(framePointer == Thread::get()->baseFramePointer()) return 0; - framePointer = next; + framePointer = (void**)System::fp_to_next_fp(framePointer); } return 1; } From gael.thomas at lip6.fr Sat Dec 21 10:31:58 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sat, 21 Dec 2013 18:31:58 -0000 Subject: [vmkit-commits] [vmkit] r197868 - StackWalker have to stop at baseFramePointer Message-ID: <20131221183158.E4A8A2A6C029@llvm.org> Author: gthomas Date: Sat Dec 21 12:31:58 2013 New Revision: 197868 URL: http://llvm.org/viewvc/llvm-project?rev=197868&view=rev Log: StackWalker have to stop at baseFramePointer Modified: vmkit/branches/mcjit/lib/vmkit/thread.cc Modified: vmkit/branches/mcjit/lib/vmkit/thread.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/thread.cc?rev=197868&r1=197867&r2=197868&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/thread.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/thread.cc Sat Dec 21 12:31:58 2013 @@ -22,12 +22,11 @@ StackWalker::StackWalker(uint32_t initia bool StackWalker::next(uint32_t nbPop) { while(nbPop--) { - fprintf(stderr, "%p and %p => %p\n", framePointer, Thread::get()->baseFramePointer(), ip()); if(framePointer == Thread::get()->baseFramePointer()) return 0; framePointer = (void**)System::fp_to_next_fp(framePointer); } - return 1; + return framePointer != Thread::get()->baseFramePointer(); } void* StackWalker::ip() { From gael.thomas at lip6.fr Sat Dec 21 11:29:33 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sat, 21 Dec 2013 19:29:33 -0000 Subject: [vmkit-commits] [vmkit] r197871 - no fp elim in jit Message-ID: <20131221192933.3B0C42A6C029@llvm.org> Author: gthomas Date: Sat Dec 21 13:29:33 2013 New Revision: 197871 URL: http://llvm.org/viewvc/llvm-project?rev=197871&view=rev Log: no fp elim in jit Modified: vmkit/branches/mcjit/lib/vmkit/compiler.cc Modified: vmkit/branches/mcjit/lib/vmkit/compiler.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/compiler.cc?rev=197871&r1=197870&r2=197871&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/compiler.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/compiler.cc Sat Dec 21 13:29:33 2013 @@ -15,6 +15,8 @@ #include "llvm/IR/Module.h" +#include "llvm/Target/TargetOptions.h" + using namespace vmkit; void* Symbol::getSymbolAddress() { @@ -35,10 +37,15 @@ CompilationUnit::CompilationUnit(BumpAll _vmkit = vmkit; + llvm::TargetOptions opt; + opt.NoFramePointerElim = 1; + std::string err; _ee = llvm::EngineBuilder(new llvm::Module(id, Thread::get()->vm()->llvmContext())) .setUseMCJIT(1) .setMCJITMemoryManager(this) + .setOptLevel(llvm::CodeGenOpt::None) /* Aggressive */ + .setTargetOptions(opt) .setErrorStr(&err) .create(); From gael.thomas at lip6.fr Sun Dec 22 07:43:34 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sun, 22 Dec 2013 15:43:34 -0000 Subject: [vmkit-commits] [vmkit] r197880 - check REQUIRES_FRAME Message-ID: <20131222154334.3926F2A6C029@llvm.org> Author: gthomas Date: Sun Dec 22 09:43:33 2013 New Revision: 197880 URL: http://llvm.org/viewvc/llvm-project?rev=197880&view=rev Log: check REQUIRES_FRAME Modified: vmkit/branches/mcjit/autoconf/configure.ac vmkit/branches/mcjit/configure Modified: vmkit/branches/mcjit/autoconf/configure.ac URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/autoconf/configure.ac?rev=197880&r1=197879&r2=197880&view=diff ============================================================================== --- vmkit/branches/mcjit/autoconf/configure.ac (original) +++ vmkit/branches/mcjit/autoconf/configure.ac Sun Dec 22 09:43:33 2013 @@ -181,7 +181,11 @@ LLVM_PATH="`$LLVM_CONFIG --bindir`" llvm_cfg=`$LLVM_RUNTIME_CONFIG --cxxflags | sed -e 's/-O3//'` if ! test -z "`echo $llvm_cfg | grep -- -fno-exceptions`"; then - AC_MSG_ERROR([You have to compile LLVM with exception enabled, please compile it with 'make REQUIRES_EH=1']) + AC_MSG_ERROR([You have to compile LLVM with exception enabled, please compile it with 'make REQUIRES_EH=1 REQUIRES_FRAME_POINTER=1']) +fi + +if ! test -z "`echo $llvm_cfg | grep -- -fomit-frame-pointer`"; then + AC_MSG_ERROR([You have to compile LLVM with frame pointers, please compile it with 'make REQUIRES_EH=1 REQUIRES_FRAME_POINTER=1']) fi AC_SUBST(LLVM_CXXFLAGS, [$llvm_cfg" "-I`$LLVM_RUNTIME_CONFIG --src-root`/include]) Modified: vmkit/branches/mcjit/configure URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/configure?rev=197880&r1=197879&r2=197880&view=diff ============================================================================== --- vmkit/branches/mcjit/configure (original) +++ vmkit/branches/mcjit/configure Sun Dec 22 09:43:33 2013 @@ -2123,7 +2123,11 @@ LLVM_PATH="`$LLVM_CONFIG --bindir`" llvm_cfg=`$LLVM_RUNTIME_CONFIG --cxxflags | sed -e 's/-O3//'` if ! test -z "`echo $llvm_cfg | grep -- -fno-exceptions`"; then - as_fn_error $? "You have to compile LLVM with exception enabled, please compile it with 'make REQUIRES_EH=1'" "$LINENO" 5 + as_fn_error $? "You have to compile LLVM with exception enabled, please compile it with 'make REQUIRES_EH=1 REQUIRES_FRAME_POINTER=1'" "$LINENO" 5 +fi + +if ! test -z "`echo $llvm_cfg | grep -- -fomit-frame-pointer`"; then + as_fn_error $? "You have to compile LLVM with frame pointers, please compile it with 'make REQUIRES_EH=1 REQUIRES_FRAME_POINTER=1'" "$LINENO" 5 fi LLVM_CXXFLAGS=$llvm_cfg" "-I`$LLVM_RUNTIME_CONFIG --src-root`/include From gael.thomas at lip6.fr Sun Dec 22 08:48:30 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sun, 22 Dec 2013 16:48:30 -0000 Subject: [vmkit-commits] [vmkit] r197881 - add few jni functions Message-ID: <20131222164830.7F9AF2A6C029@llvm.org> Author: gthomas Date: Sun Dec 22 10:48:30 2013 New Revision: 197881 URL: http://llvm.org/viewvc/llvm-project?rev=197881&view=rev Log: add few jni functions Modified: vmkit/branches/mcjit/include/j3/j3object.h vmkit/branches/mcjit/include/j3/j3thread.h vmkit/branches/mcjit/lib/j3/vm/j3jni.cc vmkit/branches/mcjit/lib/j3/vm/j3thread.cc Modified: vmkit/branches/mcjit/include/j3/j3object.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3object.h?rev=197881&r1=197880&r2=197881&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3object.h (original) +++ vmkit/branches/mcjit/include/j3/j3object.h Sun Dec 22 10:48:30 2013 @@ -161,9 +161,9 @@ namespace j3 { class J3FixedPoint { static const uint32_t defaultNodeCapacity = 256; - pthread_mutex_t mutex; + pthread_mutex_t mutex; vmkit::BumpAllocator* allocator; - J3FixedPointNode* head; + J3FixedPointNode* head; void createNode(uint32_t capacity=defaultNodeCapacity); public: Modified: vmkit/branches/mcjit/include/j3/j3thread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3thread.h?rev=197881&r1=197880&r2=197881&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3thread.h (original) +++ vmkit/branches/mcjit/include/j3/j3thread.h Sun Dec 22 10:48:30 2013 @@ -26,7 +26,8 @@ namespace j3 { J3Method* getJavaCaller(uint32_t level=0); void ensureCapacity(uint32_t capacity); - J3ObjectHandle* pendingException() { return _pendingException; } + J3ObjectHandle* pendingException(); + bool hasPendingException() { return _pendingException; } void setPendingException(J3ObjectHandle* handle) { _pendingException = handle; } J3FixedPoint* fixedPoint() { return &_fixedPoint; } Modified: vmkit/branches/mcjit/lib/j3/vm/j3jni.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3jni.cc?rev=197881&r1=197880&r2=197881&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3jni.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3jni.cc Sun Dec 22 10:48:30 2013 @@ -28,8 +28,6 @@ jclass JNICALL FindClass(JNIEnv* env, co res = cl->javaClass(); leaveJVM(); - fprintf(stderr, "find class --> %p %p\n", res, J3ObjectType::nativeClass(res)); - return res; } @@ -121,12 +119,49 @@ jmethodID JNICALL GetMethodID(JNIEnv* en leaveJVM(); \ \ return res.val##j3type; \ + } \ + \ + jtype JNICALL Call##id##MethodA(JNIEnv* env, jobject obj, jmethodID methodID, const jvalue* args) { \ + jvalue res; \ + \ + enterJVM(); \ + res = methodID->invokeVirtual(obj, args); \ + leaveJVM(); \ + \ + return res.val##j3type; \ + } \ + \ + jtype JNICALL CallStatic##id##Method(JNIEnv* env, jclass clazz, jmethodID methodID, ...) { \ + va_list va; \ + va_start(va, methodID); \ + jobject res = env->CallStatic##id##MethodV(clazz, methodID, va); \ + va_end(va); \ + return res; \ + } \ + \ + jtype JNICALL CallStatic##id##MethodV(JNIEnv* env, jclass clazz, jmethodID methodID, va_list args) { \ + jvalue res; \ + \ + enterJVM(); \ + res = methodID->invokeStatic(args); \ + leaveJVM(); \ + \ + return res.val##j3type; \ + } \ + \ + jtype JNICALL CallStatic##id##MethodA(JNIEnv* env, jclass clazz, jmethodID methodID, const jvalue* args) { \ + jvalue res; \ + \ + enterJVM(); \ + res = methodID->invokeStatic(args); \ + leaveJVM(); \ + \ + return res.val##j3type; \ } doInvoke(jobject, Object, Object); -jobject JNICALL CallObjectMethodA(JNIEnv* env, jobject obj, jmethodID methodID, const jvalue* args) { enterJVM(); leaveJVM(); NYI(); } jboolean JNICALL CallBooleanMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) { enterJVM(); leaveJVM(); NYI(); } jboolean JNICALL CallBooleanMethodV(JNIEnv* env, jobject obj, jmethodID methodID, va_list args) { enterJVM(); leaveJVM(); NYI(); } @@ -242,10 +277,6 @@ jmethodID JNICALL GetStaticMethodID(JNIE return res; } -jobject JNICALL CallStaticObjectMethod(JNIEnv* env, jclass clazz, jmethodID methodID, ...) { enterJVM(); leaveJVM(); NYI(); } -jobject JNICALL CallStaticObjectMethodV(JNIEnv* env, jclass clazz, jmethodID methodID, va_list args) { enterJVM(); leaveJVM(); NYI(); } -jobject JNICALL CallStaticObjectMethodA(JNIEnv* env, jclass clazz, jmethodID methodID, const jvalue* args) { enterJVM(); leaveJVM(); NYI(); } - jboolean JNICALL CallStaticBooleanMethod(JNIEnv* env, jclass clazz, jmethodID methodID, ...) { enterJVM(); leaveJVM(); NYI(); } jboolean JNICALL CallStaticBooleanMethodV(JNIEnv* env, jclass clazz, jmethodID methodID, va_list args) { enterJVM(); leaveJVM(); NYI(); } jboolean JNICALL CallStaticBooleanMethodA(JNIEnv* env, jclass clazz, jmethodID methodID, const jvalue* args) { enterJVM(); leaveJVM(); NYI(); } @@ -431,7 +462,9 @@ void JNICALL ReleaseStringCritical(JNIEn jweak JNICALL NewWeakGlobalRef(JNIEnv* env, jobject obj) { enterJVM(); leaveJVM(); NYI(); } void JNICALL DeleteWeakGlobalRef(JNIEnv* env, jweak ref) { enterJVM(); leaveJVM(); NYI(); } -jboolean JNICALL ExceptionCheck(JNIEnv* env) { enterJVM(); leaveJVM(); NYI(); } +jboolean JNICALL ExceptionCheck(JNIEnv* env) { + return J3Thread::get()->hasPendingException(); +} jobject JNICALL NewDirectByteBuffer(JNIEnv* env, void* address, jlong capacity) { enterJVM(); leaveJVM(); NYI(); } void* JNICALL GetDirectBufferAddress(JNIEnv* env, jobject buf) { enterJVM(); leaveJVM(); NYI(); } Modified: vmkit/branches/mcjit/lib/j3/vm/j3thread.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3thread.cc?rev=197881&r1=197880&r2=197881&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3thread.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3thread.cc Sun Dec 22 10:48:30 2013 @@ -32,6 +32,13 @@ J3Method* J3Thread::getJavaCaller(uint32 return 0; } +J3ObjectHandle* J3Thread::pendingException() { + if(_pendingException) { + return push(_pendingException); + } else + return 0; +} + void J3Thread::ensureCapacity(uint32_t capacity) { _fixedPoint.unsyncEnsureCapacity(capacity); } From gael.thomas at lip6.fr Sun Dec 22 09:07:23 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sun, 22 Dec 2013 17:07:23 -0000 Subject: [vmkit-commits] [vmkit] r197882 - defines a stack class and uses it to implement J3FixedPoint Message-ID: <20131222170724.1543A2A6C029@llvm.org> Author: gthomas Date: Sun Dec 22 11:07:23 2013 New Revision: 197882 URL: http://llvm.org/viewvc/llvm-project?rev=197882&view=rev Log: defines a stack class and uses it to implement J3FixedPoint Added: vmkit/branches/mcjit/include/vmkit/stack.h Modified: vmkit/branches/mcjit/include/j3/j3object.h vmkit/branches/mcjit/lib/j3/vm/j3jni.cc vmkit/branches/mcjit/lib/j3/vm/j3object.cc Modified: vmkit/branches/mcjit/include/j3/j3object.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3object.h?rev=197882&r1=197881&r2=197882&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3object.h (original) +++ vmkit/branches/mcjit/include/j3/j3object.h Sun Dec 22 11:07:23 2013 @@ -4,6 +4,8 @@ #include #include +#include "vmkit/stack.h" + #include "j3/j3typesdef.h" namespace vmkit { @@ -150,35 +152,15 @@ namespace j3 { #undef defAccessor }; - class J3FixedPointNode { - public: - J3FixedPointNode* nextFree; - J3FixedPointNode* nextBusy; - J3ObjectHandle* top; - J3ObjectHandle* max; - }; - - class J3FixedPoint { - static const uint32_t defaultNodeCapacity = 256; - - pthread_mutex_t mutex; - vmkit::BumpAllocator* allocator; - J3FixedPointNode* head; - - void createNode(uint32_t capacity=defaultNodeCapacity); + class J3FixedPoint : public vmkit::Stack { public: - J3FixedPoint(vmkit::BumpAllocator* _allocator); - - void unsyncEnsureCapacity(uint32_t capacity); + J3FixedPoint(vmkit::BumpAllocator* _allocator) : vmkit::Stack(_allocator) {} J3ObjectHandle* syncPush(J3ObjectHandle* handle) { return syncPush(handle->obj()); } - J3ObjectHandle* syncPush(J3Object* obj); J3ObjectHandle* unsyncPush(J3ObjectHandle* handle) { return unsyncPush(handle->obj()); } - J3ObjectHandle* unsyncPush(J3Object* obj); - void unsyncPop(); - J3ObjectHandle* unsyncTell() { return head->top; } - void unsyncRestore(J3ObjectHandle* ptr); + J3ObjectHandle* syncPush(J3Object* obj); + J3ObjectHandle* unsyncPush(J3Object* obj); }; class J3Value { Added: vmkit/branches/mcjit/include/vmkit/stack.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/stack.h?rev=197882&view=auto ============================================================================== --- vmkit/branches/mcjit/include/vmkit/stack.h (added) +++ vmkit/branches/mcjit/include/vmkit/stack.h Sun Dec 22 11:07:23 2013 @@ -0,0 +1,100 @@ +#ifndef _STACK_H_ +#define _STACK_H_ + +#include "vmkit/allocator.h" + +namespace vmkit { + template + class StackNode { + public: + StackNode* nextFree; + StackNode* nextBusy; + T* top; + T* max; + }; + + template + class Stack { + static const uint32_t defaultNodeCapacity = 256; + + pthread_mutex_t mutex; + BumpAllocator* allocator; + StackNode* head; + + void createNode(uint32_t capacity=defaultNodeCapacity) { + uint64_t size = capacity * sizeof(T) + sizeof(StackNode); + StackNode* nn = (StackNode*)allocator->allocate(size); + nn->top = (T*)(nn + 1); + nn->max = (T*)((uintptr_t)nn + size); + nn->nextFree = 0; + nn->nextBusy = head; + if(head) + head->nextFree = nn; + head = nn; + } + + public: + Stack(BumpAllocator* _allocator) { + pthread_mutex_init(&mutex, 0); + allocator = _allocator; + head = 0; + createNode(); + } + + void unsyncEnsureCapacity(uint32_t capacity) { + T* reserve = head->top + capacity; + if(reserve > head->max) + createNode(capacity); + } + + T* syncPush() { + StackNode* cur = head; + T* res = (T*)__sync_fetch_and_add((uintptr_t*)&cur->top, (uintptr_t)sizeof(T)); + + if(res < cur->max) + return res; + + pthread_mutex_lock(&mutex); + if(cur->nextFree) + head = cur->nextFree; + else + createNode(); + pthread_mutex_unlock(&mutex); + return syncPush(); + } + + T* unsyncPush() { + T* res = head->top++; + + if(res < head->max) + return res; + + if(head->nextFree) + head = head->nextFree; + else + createNode(); + return unsyncPush(); + } + + void unsyncPop() { + T* res = head->top - 1; + if(res < (T*)(head + 1)) { + head = head->nextBusy; + head->top = (T*)(head+1); + } else + head->top = res; + } + + T* unsyncTell() { + return head->top; + } + + void unsyncRestore(T* ptr) { + while(ptr <= (T*)head || ptr > head->max) + head = head->nextBusy; + head->top = ptr; + } + }; +} + +#endif Modified: vmkit/branches/mcjit/lib/j3/vm/j3jni.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3jni.cc?rev=197882&r1=197881&r2=197882&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3jni.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3jni.cc Sun Dec 22 11:07:23 2013 @@ -267,7 +267,6 @@ jmethodID JNICALL GetStaticMethodID(JNIE enterJVM(); J3ObjectType* cl = J3ObjectType::nativeClass(clazz); - fprintf(stderr, "cl: %p %p\n", clazz, cl); cl->initialise(); vmkit::Names* n = cl->loader()->vm()->names(); res = cl->findStaticMethod(n->get(name), n->get(sig)); Modified: vmkit/branches/mcjit/lib/j3/vm/j3object.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3object.cc?rev=197882&r1=197881&r2=197882&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3object.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3object.cc Sun Dec 22 11:07:23 2013 @@ -396,79 +396,16 @@ void* J3ObjectHandle::trampoline(J3Objec /* * J3FixedPoint */ -J3FixedPoint::J3FixedPoint(vmkit::BumpAllocator* _allocator) { - pthread_mutex_init(&mutex, 0); - allocator = _allocator; - head = 0; - createNode(); -} - -void J3FixedPoint::unsyncEnsureCapacity(uint32_t capacity) { - J3ObjectHandle* reserve = head->top + capacity; - if(reserve > head->max) - createNode(capacity); -} - -void J3FixedPoint::createNode(uint32_t capacity) { - uint64_t size = capacity * sizeof(J3Object*) + sizeof(J3FixedPointNode); - J3FixedPointNode* nn = (J3FixedPointNode*)allocator->allocate(size); - nn->top = (J3ObjectHandle*)(nn + 1); - nn->max = (J3ObjectHandle*)((uintptr_t)nn + size); - nn->nextFree = 0; - nn->nextBusy = head; - if(head) - head->nextFree = nn; - head = nn; -} - J3ObjectHandle* J3FixedPoint::syncPush(J3Object* obj) { - J3FixedPointNode* cur = head; - J3ObjectHandle* res = (J3ObjectHandle*)__sync_fetch_and_add((uintptr_t*)&cur->top, (uintptr_t)sizeof(J3ObjectHandle)); - - if(res >= cur->max) { - pthread_mutex_lock(&mutex); - if(cur->nextFree) - head = cur->nextFree; - else - createNode(); - pthread_mutex_unlock(&mutex); - return syncPush(obj); - } else { - res->_obj = obj; - return res; - } + J3ObjectHandle* res = Stack::syncPush(); + res->_obj = obj; + return res; } J3ObjectHandle* J3FixedPoint::unsyncPush(J3Object* obj) { - J3ObjectHandle* res = head->top++; - - if(res >= head->max) { - if(head->nextFree) - head = head->nextFree; - else - createNode(); - return unsyncPush(obj); - } else { - res->_obj = obj; - return res; - } -} - -void J3FixedPoint::unsyncPop() { - J3ObjectHandle* res = head->top - 1; - if(res < (J3ObjectHandle*)(head + 1)) { - head = head->nextBusy; - head->top = (J3ObjectHandle*)(head+1); - } else - head->top = res; -} - -void J3FixedPoint::unsyncRestore(J3ObjectHandle* obj) { - while(obj <= (J3ObjectHandle*)head || obj > head->max) { - head = head->nextBusy; - head->top = (J3ObjectHandle*)(head+1); - } - head->top = obj; + J3ObjectHandle* res = Stack::unsyncPush(); + res->_obj = obj; + return res; } From gael.thomas at lip6.fr Sun Dec 22 09:34:39 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sun, 22 Dec 2013 17:34:39 -0000 Subject: [vmkit-commits] [vmkit] r197883 - defines a J3LocalReferences class and uses it Message-ID: <20131222173440.0B56C2A6C029@llvm.org> Author: gthomas Date: Sun Dec 22 11:34:38 2013 New Revision: 197883 URL: http://llvm.org/viewvc/llvm-project?rev=197883&view=rev Log: defines a J3LocalReferences class and uses it Modified: vmkit/branches/mcjit/include/j3/j3classloader.h vmkit/branches/mcjit/include/j3/j3object.h vmkit/branches/mcjit/include/j3/j3thread.h vmkit/branches/mcjit/include/vmkit/stack.h vmkit/branches/mcjit/lib/j3/vm/j3.cc vmkit/branches/mcjit/lib/j3/vm/j3class.cc vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc vmkit/branches/mcjit/lib/j3/vm/j3object.cc vmkit/branches/mcjit/lib/j3/vm/j3thread.cc Modified: vmkit/branches/mcjit/include/j3/j3classloader.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3classloader.h?rev=197883&r1=197882&r2=197883&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3classloader.h (original) +++ vmkit/branches/mcjit/include/j3/j3classloader.h Sun Dec 22 11:34:38 2013 @@ -38,7 +38,7 @@ namespace j3 { static J3MethodLess j3MethodLess; J3ObjectHandle* _javaClassLoader; - J3FixedPoint _fixedPoint; + J3LocalReferences _globalReferences; pthread_mutex_t _mutex; /* a lock */ vmkit::NameMap::map classes; /* classes managed by this class loader */ vmkit::NameMap::map types; /* shortcut to find types */ @@ -57,7 +57,7 @@ namespace j3 { public: J3ClassLoader(J3* vm, J3ObjectHandle* javaClassLoader, vmkit::BumpAllocator* allocator); - J3FixedPoint* fixedPoint() { return &_fixedPoint; } + J3LocalReferences* globalReferences() { return &_globalReferences; } J3ObjectHandle* javaClassLoader() { return _javaClassLoader; } Modified: vmkit/branches/mcjit/include/j3/j3object.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3object.h?rev=197883&r1=197882&r2=197883&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3object.h (original) +++ vmkit/branches/mcjit/include/j3/j3object.h Sun Dec 22 11:34:38 2013 @@ -109,7 +109,8 @@ namespace j3 { }; class J3ObjectHandle { - friend class J3FixedPoint; + friend class J3LocalReferences; + friend class J3GlobalReferences; friend class J3Method; public: @@ -152,15 +153,12 @@ namespace j3 { #undef defAccessor }; - class J3FixedPoint : public vmkit::Stack { + class J3LocalReferences : public vmkit::Stack { public: - J3FixedPoint(vmkit::BumpAllocator* _allocator) : vmkit::Stack(_allocator) {} + J3LocalReferences(vmkit::BumpAllocator* _allocator) : vmkit::Stack(_allocator) {} - J3ObjectHandle* syncPush(J3ObjectHandle* handle) { return syncPush(handle->obj()); } - J3ObjectHandle* unsyncPush(J3ObjectHandle* handle) { return unsyncPush(handle->obj()); } - - J3ObjectHandle* syncPush(J3Object* obj); - J3ObjectHandle* unsyncPush(J3Object* obj); + J3ObjectHandle* push(J3ObjectHandle* handle) { return push(handle->obj()); } + J3ObjectHandle* push(J3Object* obj); }; class J3Value { Modified: vmkit/branches/mcjit/include/j3/j3thread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3thread.h?rev=197883&r1=197882&r2=197883&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3thread.h (original) +++ vmkit/branches/mcjit/include/j3/j3thread.h Sun Dec 22 11:34:38 2013 @@ -16,7 +16,7 @@ namespace j3 { class J3Thread : public vmkit::Thread { vmkit::BumpAllocator* allocator; JNIEnv _jniEnv; - J3FixedPoint _fixedPoint; + J3LocalReferences _localReferences; J3ObjectHandle* _pendingException; J3Thread(J3* vm, vmkit::BumpAllocator* allocator); @@ -25,16 +25,15 @@ namespace j3 { J3Method* getJavaCaller(uint32_t level=0); - void ensureCapacity(uint32_t capacity); - J3ObjectHandle* pendingException(); - bool hasPendingException() { return _pendingException; } - void setPendingException(J3ObjectHandle* handle) { _pendingException = handle; } - J3FixedPoint* fixedPoint() { return &_fixedPoint; } - - J3ObjectHandle* push(J3ObjectHandle* handle); - J3ObjectHandle* push(J3Object* obj); - J3ObjectHandle* tell(); - void restore(J3ObjectHandle* obj); + void ensureCapacity(uint32_t capacity); + J3ObjectHandle* pendingException(); + bool hasPendingException() { return _pendingException; } + void setPendingException(J3ObjectHandle* handle) { _pendingException = handle; } + + J3ObjectHandle* push(J3ObjectHandle* handle); + J3ObjectHandle* push(J3Object* obj); + J3ObjectHandle* tell(); + void restore(J3ObjectHandle* ptr); J3* vm() { return (J3*)Thread::vm(); } Modified: vmkit/branches/mcjit/include/vmkit/stack.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/stack.h?rev=197883&r1=197882&r2=197883&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/stack.h (original) +++ vmkit/branches/mcjit/include/vmkit/stack.h Sun Dec 22 11:34:38 2013 @@ -17,7 +17,6 @@ namespace vmkit { class Stack { static const uint32_t defaultNodeCapacity = 256; - pthread_mutex_t mutex; BumpAllocator* allocator; StackNode* head; @@ -35,35 +34,18 @@ namespace vmkit { public: Stack(BumpAllocator* _allocator) { - pthread_mutex_init(&mutex, 0); allocator = _allocator; head = 0; createNode(); } - void unsyncEnsureCapacity(uint32_t capacity) { + void ensureCapacity(uint32_t capacity) { T* reserve = head->top + capacity; if(reserve > head->max) createNode(capacity); } - T* syncPush() { - StackNode* cur = head; - T* res = (T*)__sync_fetch_and_add((uintptr_t*)&cur->top, (uintptr_t)sizeof(T)); - - if(res < cur->max) - return res; - - pthread_mutex_lock(&mutex); - if(cur->nextFree) - head = cur->nextFree; - else - createNode(); - pthread_mutex_unlock(&mutex); - return syncPush(); - } - - T* unsyncPush() { + T* push() { T* res = head->top++; if(res < head->max) @@ -73,10 +55,10 @@ namespace vmkit { head = head->nextFree; else createNode(); - return unsyncPush(); + return push(); } - void unsyncPop() { + void pop() { T* res = head->top - 1; if(res < (T*)(head + 1)) { head = head->nextBusy; @@ -85,11 +67,11 @@ namespace vmkit { head->top = res; } - T* unsyncTell() { + T* tell() { return head->top; } - void unsyncRestore(T* ptr) { + void restore(T* ptr) { while(ptr <= (T*)head || ptr > head->max) head = head->nextBusy; head->top = ptr; Modified: vmkit/branches/mcjit/lib/j3/vm/j3.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3.cc?rev=197883&r1=197882&r2=197883&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3.cc Sun Dec 22 11:34:38 2013 @@ -120,7 +120,7 @@ J3ObjectHandle* J3::arrayToString(J3Obje J3ObjectHandle* res = charArrayToStrings[array]; if(!res) { J3ObjectHandle* prev = J3Thread::get()->tell(); - res = initialClassLoader->fixedPoint()->syncPush(J3ObjectHandle::doNewObject(stringClass)); + res = initialClassLoader->globalReferences()->push(J3ObjectHandle::doNewObject(stringClass)); J3Thread::get()->restore(prev); stringInit->invokeSpecial(res, array, 0); @@ -136,7 +136,7 @@ J3ObjectHandle* J3::nameToString(const v J3ObjectHandle* res = nameToCharArrays[name]; if(!res) { J3ObjectHandle* prev = J3Thread::get()->tell(); - res = initialClassLoader->fixedPoint()->syncPush(J3ObjectHandle::doNewArray(charArrayClass, name->length())); + res = initialClassLoader->globalReferences()->push(J3ObjectHandle::doNewArray(charArrayClass, name->length())); J3Thread::get()->restore(prev); for(uint32_t i=0; ilength(); i++) Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=197883&r1=197882&r2=197883&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Sun Dec 22 11:34:38 2013 @@ -146,7 +146,7 @@ J3ObjectHandle* J3ObjectType::javaClass( if(!_javaClass) { J3ObjectHandle* prev = J3Thread::get()->tell(); _javaClass = J3ObjectHandle::doNewObject(loader()->vm()->classClass); - _javaClass = loader()->fixedPoint()->syncPush(_javaClass); + _javaClass = loader()->globalReferences()->push(_javaClass); J3Thread::get()->restore(prev); _javaClass->setLong(loader()->vm()->classVMData, (int64_t)(uintptr_t)this); loader()->vm()->classInit->invokeSpecial(_javaClass); @@ -291,7 +291,7 @@ void J3Class::doInitialise() { J3ObjectHandle* stacked = J3ObjectHandle::allocate(staticLayout.vt(), loader()->vm()->dataLayout()->getTypeAllocSize(staticLayout.llvmType() ->getContainedType(0))); - _staticInstance = loader()->fixedPoint()->syncPush(stacked); + _staticInstance = loader()->globalReferences()->push(stacked); J3Thread::get()->restore(prev); for(size_t i=0; i::syncPush(); - res->_obj = obj; - return res; -} - -J3ObjectHandle* J3FixedPoint::unsyncPush(J3Object* obj) { - J3ObjectHandle* res = Stack::unsyncPush(); +J3ObjectHandle* J3LocalReferences::push(J3Object* obj) { + J3ObjectHandle* res = Stack::push(); res->_obj = obj; return res; } Modified: vmkit/branches/mcjit/lib/j3/vm/j3thread.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3thread.cc?rev=197883&r1=197882&r2=197883&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3thread.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3thread.cc Sun Dec 22 11:34:38 2013 @@ -9,7 +9,7 @@ using namespace j3; J3Thread::J3Thread(J3* vm, vmkit::BumpAllocator* allocator) : Thread(vm, allocator), - _fixedPoint(allocator) { + _localReferences(allocator) { _jniEnv.functions = &jniEnvTable; } @@ -40,23 +40,23 @@ J3ObjectHandle* J3Thread::pendingExcepti } void J3Thread::ensureCapacity(uint32_t capacity) { - _fixedPoint.unsyncEnsureCapacity(capacity); + _localReferences.ensureCapacity(capacity); } J3ObjectHandle* J3Thread::push(J3ObjectHandle* handle) { - return _fixedPoint.unsyncPush(handle); + return _localReferences.push(handle); } J3ObjectHandle* J3Thread::push(J3Object* obj) { - return _fixedPoint.unsyncPush(obj); + return _localReferences.push(obj); } J3ObjectHandle* J3Thread::tell() { - return _fixedPoint.unsyncTell(); + return _localReferences.tell(); } -void J3Thread::restore(J3ObjectHandle* obj) { - _fixedPoint.unsyncRestore(obj); +void J3Thread::restore(J3ObjectHandle* ptr) { + _localReferences.restore(ptr); } J3Thread* J3Thread::get() { From gael.thomas at lip6.fr Sun Dec 22 09:49:48 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sun, 22 Dec 2013 17:49:48 -0000 Subject: [vmkit-commits] [vmkit] r197884 - add global references in JNI Message-ID: <20131222174948.C935C2A6C029@llvm.org> Author: gthomas Date: Sun Dec 22 11:49:48 2013 New Revision: 197884 URL: http://llvm.org/viewvc/llvm-project?rev=197884&view=rev Log: add global references in JNI Modified: vmkit/branches/mcjit/include/j3/j3classloader.h vmkit/branches/mcjit/include/j3/j3object.h vmkit/branches/mcjit/include/vmkit/stack.h vmkit/branches/mcjit/lib/j3/vm/j3.cc vmkit/branches/mcjit/lib/j3/vm/j3class.cc vmkit/branches/mcjit/lib/j3/vm/j3jni.cc vmkit/branches/mcjit/lib/j3/vm/j3object.cc Modified: vmkit/branches/mcjit/include/j3/j3classloader.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3classloader.h?rev=197884&r1=197883&r2=197884&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3classloader.h (original) +++ vmkit/branches/mcjit/include/j3/j3classloader.h Sun Dec 22 11:49:48 2013 @@ -38,7 +38,7 @@ namespace j3 { static J3MethodLess j3MethodLess; J3ObjectHandle* _javaClassLoader; - J3LocalReferences _globalReferences; + J3GlobalReferences _globalReferences; pthread_mutex_t _mutex; /* a lock */ vmkit::NameMap::map classes; /* classes managed by this class loader */ vmkit::NameMap::map types; /* shortcut to find types */ @@ -57,8 +57,8 @@ namespace j3 { public: J3ClassLoader(J3* vm, J3ObjectHandle* javaClassLoader, vmkit::BumpAllocator* allocator); - J3LocalReferences* globalReferences() { return &_globalReferences; } - + J3GlobalReferences* globalReferences() { return &_globalReferences; } + J3ObjectHandle* javaClassLoader() { return _javaClassLoader; } void lock() { pthread_mutex_lock(&_mutex); } Modified: vmkit/branches/mcjit/include/j3/j3object.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3object.h?rev=197884&r1=197883&r2=197884&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3object.h (original) +++ vmkit/branches/mcjit/include/j3/j3object.h Sun Dec 22 11:49:48 2013 @@ -161,6 +161,17 @@ namespace j3 { J3ObjectHandle* push(J3Object* obj); }; + class J3GlobalReferences { + pthread_mutex_t mutex; + vmkit::Stack references; + vmkit::Stack emptySlots; + public: + J3GlobalReferences(vmkit::BumpAllocator* _allocator); + + J3ObjectHandle* add(J3ObjectHandle* handle); + void del(J3ObjectHandle* handle); + }; + class J3Value { public: union { Modified: vmkit/branches/mcjit/include/vmkit/stack.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/stack.h?rev=197884&r1=197883&r2=197884&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/stack.h (original) +++ vmkit/branches/mcjit/include/vmkit/stack.h Sun Dec 22 11:49:48 2013 @@ -45,6 +45,10 @@ namespace vmkit { createNode(capacity); } + bool isEmpty() { + return head->top == (T*)(head+1) && !head->nextBusy; + } + T* push() { T* res = head->top++; @@ -58,13 +62,14 @@ namespace vmkit { return push(); } - void pop() { + T* pop() { T* res = head->top - 1; if(res < (T*)(head + 1)) { head = head->nextBusy; head->top = (T*)(head+1); } else head->top = res; + return head->top; } T* tell() { Modified: vmkit/branches/mcjit/lib/j3/vm/j3.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3.cc?rev=197884&r1=197883&r2=197884&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3.cc Sun Dec 22 11:49:48 2013 @@ -120,7 +120,7 @@ J3ObjectHandle* J3::arrayToString(J3Obje J3ObjectHandle* res = charArrayToStrings[array]; if(!res) { J3ObjectHandle* prev = J3Thread::get()->tell(); - res = initialClassLoader->globalReferences()->push(J3ObjectHandle::doNewObject(stringClass)); + res = initialClassLoader->globalReferences()->add(J3ObjectHandle::doNewObject(stringClass)); J3Thread::get()->restore(prev); stringInit->invokeSpecial(res, array, 0); @@ -136,7 +136,7 @@ J3ObjectHandle* J3::nameToString(const v J3ObjectHandle* res = nameToCharArrays[name]; if(!res) { J3ObjectHandle* prev = J3Thread::get()->tell(); - res = initialClassLoader->globalReferences()->push(J3ObjectHandle::doNewArray(charArrayClass, name->length())); + res = initialClassLoader->globalReferences()->add(J3ObjectHandle::doNewArray(charArrayClass, name->length())); J3Thread::get()->restore(prev); for(uint32_t i=0; ilength(); i++) Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=197884&r1=197883&r2=197884&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Sun Dec 22 11:49:48 2013 @@ -146,7 +146,7 @@ J3ObjectHandle* J3ObjectType::javaClass( if(!_javaClass) { J3ObjectHandle* prev = J3Thread::get()->tell(); _javaClass = J3ObjectHandle::doNewObject(loader()->vm()->classClass); - _javaClass = loader()->globalReferences()->push(_javaClass); + _javaClass = loader()->globalReferences()->add(_javaClass); J3Thread::get()->restore(prev); _javaClass->setLong(loader()->vm()->classVMData, (int64_t)(uintptr_t)this); loader()->vm()->classInit->invokeSpecial(_javaClass); @@ -291,7 +291,7 @@ void J3Class::doInitialise() { J3ObjectHandle* stacked = J3ObjectHandle::allocate(staticLayout.vt(), loader()->vm()->dataLayout()->getTypeAllocSize(staticLayout.llvmType() ->getContainedType(0))); - _staticInstance = loader()->globalReferences()->push(stacked); + _staticInstance = loader()->globalReferences()->add(stacked); J3Thread::get()->restore(prev); for(size_t i=0; igetJavaCaller(); + J3ClassLoader* loader = m ? m->cl()->loader() : J3Thread::get()->vm()->initialClassLoader; + res = loader->globalReferences()->add(lobj); + leaveJVM(); + return res; +} + +void JNICALL DeleteGlobalRef(JNIEnv* env, jobject gref) { + enterJVM(); + J3Method* m = J3Thread::get()->getJavaCaller(); + J3ClassLoader* loader = m ? m->cl()->loader() : J3Thread::get()->vm()->initialClassLoader; + loader->globalReferences()->del(gref); + leaveJVM(); +} + void JNICALL DeleteLocalRef(JNIEnv* env, jobject obj) { enterJVM(); if(obj) obj->harakiri(); Modified: vmkit/branches/mcjit/lib/j3/vm/j3object.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3object.cc?rev=197884&r1=197883&r2=197884&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3object.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3object.cc Sun Dec 22 11:49:48 2013 @@ -402,4 +402,27 @@ J3ObjectHandle* J3LocalReferences::push( return res; } +/* + * J3GlobalReferences + */ +J3GlobalReferences::J3GlobalReferences(vmkit::BumpAllocator* _allocator) : + references(_allocator), + emptySlots(_allocator) { + pthread_mutex_init(&mutex, 0); +} + +J3ObjectHandle* J3GlobalReferences::add(J3ObjectHandle* handle) { + pthread_mutex_lock(&mutex); + J3ObjectHandle* res = emptySlots.isEmpty() ? references.push() : *emptySlots.pop(); + res->_obj = handle->_obj; + pthread_mutex_unlock(&mutex); + return res; +} + +void J3GlobalReferences::del(J3ObjectHandle* handle) { + handle->harakiri(); + pthread_mutex_lock(&mutex); + *emptySlots.push() = handle; + pthread_mutex_unlock(&mutex); +} From gael.thomas at lip6.fr Sun Dec 22 10:11:07 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sun, 22 Dec 2013 18:11:07 -0000 Subject: [vmkit-commits] [vmkit] r197885 - implement all jni call methods Message-ID: <20131222181107.7A9CE2A6C029@llvm.org> Author: gthomas Date: Sun Dec 22 12:11:07 2013 New Revision: 197885 URL: http://llvm.org/viewvc/llvm-project?rev=197885&view=rev Log: implement all jni call methods Modified: vmkit/branches/mcjit/lib/j3/vm/j3jni.cc Modified: vmkit/branches/mcjit/lib/j3/vm/j3jni.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3jni.cc?rev=197885&r1=197884&r2=197885&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3jni.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3jni.cc Sun Dec 22 12:11:07 2013 @@ -118,11 +118,26 @@ jmethodID JNICALL GetMethodID(JNIEnv* en return res; } -#define doInvoke(jtype, id, j3type) \ +jmethodID JNICALL GetStaticMethodID(JNIEnv* env, jclass clazz, const char* name, const char* sig) { + jmethodID res; + + enterJVM(); + + J3ObjectType* cl = J3ObjectType::nativeClass(clazz); + cl->initialise(); + vmkit::Names* n = cl->loader()->vm()->names(); + res = cl->findStaticMethod(n->get(name), n->get(sig)); + + leaveJVM(); + + return res; +} + +#define defCall(jtype, id, j3type) \ jtype JNICALL Call##id##Method(JNIEnv* env, jobject obj, jmethodID methodID, ...) { \ va_list va; \ va_start(va, methodID); \ - jobject res = env->Call##id##MethodV(obj, methodID, va); \ + jtype res = env->Call##id##MethodV(obj, methodID, va); \ va_end(va); \ return res; \ } \ @@ -145,12 +160,13 @@ jmethodID JNICALL GetMethodID(JNIEnv* en leaveJVM(); \ \ return res.val##j3type; \ - } \ - \ + } + +#define defStaticCall(jtype, id, j3type) \ jtype JNICALL CallStatic##id##Method(JNIEnv* env, jclass clazz, jmethodID methodID, ...) { \ va_list va; \ va_start(va, methodID); \ - jobject res = env->CallStatic##id##MethodV(clazz, methodID, va); \ + jtype res = env->CallStatic##id##MethodV(clazz, methodID, va); \ va_end(va); \ return res; \ } \ @@ -175,85 +191,106 @@ jmethodID JNICALL GetMethodID(JNIEnv* en return res.val##j3type; \ } - doInvoke(jobject, Object, Object); - - - -jboolean JNICALL CallBooleanMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) { enterJVM(); leaveJVM(); NYI(); } -jboolean JNICALL CallBooleanMethodV(JNIEnv* env, jobject obj, jmethodID methodID, va_list args) { enterJVM(); leaveJVM(); NYI(); } -jboolean JNICALL CallBooleanMethodA(JNIEnv* env, jobject obj, jmethodID methodID, const jvalue* args) { enterJVM(); leaveJVM(); NYI(); } - -jbyte JNICALL CallByteMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) { enterJVM(); leaveJVM(); NYI(); } -jbyte JNICALL CallByteMethodV(JNIEnv* env, jobject obj, jmethodID methodID, va_list args) { enterJVM(); leaveJVM(); NYI(); } -jbyte JNICALL CallByteMethodA(JNIEnv* env, jobject obj, jmethodID methodID, const jvalue* args) { enterJVM(); leaveJVM(); NYI(); } - -jchar JNICALL CallCharMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) { enterJVM(); leaveJVM(); NYI(); } -jchar JNICALL CallCharMethodV(JNIEnv* env, jobject obj, jmethodID methodID, va_list args) { enterJVM(); leaveJVM(); NYI(); } -jchar JNICALL CallCharMethodA(JNIEnv* env, jobject obj, jmethodID methodID, const jvalue* args) { enterJVM(); leaveJVM(); NYI(); } - -jshort JNICALL CallShortMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) { enterJVM(); leaveJVM(); NYI(); } -jshort JNICALL CallShortMethodV(JNIEnv* env, jobject obj, jmethodID methodID, va_list args) { enterJVM(); leaveJVM(); NYI(); } -jshort JNICALL CallShortMethodA(JNIEnv* env, jobject obj, jmethodID methodID, const jvalue* args) { enterJVM(); leaveJVM(); NYI(); } - -jint JNICALL CallIntMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) { enterJVM(); leaveJVM(); NYI(); } -jint JNICALL CallIntMethodV(JNIEnv* env, jobject obj, jmethodID methodID, va_list args) { enterJVM(); leaveJVM(); NYI(); } -jint JNICALL CallIntMethodA(JNIEnv* env, jobject obj, jmethodID methodID, const jvalue* args) { enterJVM(); leaveJVM(); NYI(); } - -jlong JNICALL CallLongMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) { enterJVM(); leaveJVM(); NYI(); } -jlong JNICALL CallLongMethodV(JNIEnv* env, jobject obj, jmethodID methodID, va_list args) { enterJVM(); leaveJVM(); NYI(); } -jlong JNICALL CallLongMethodA(JNIEnv* env, jobject obj, jmethodID methodID, const jvalue* args) { enterJVM(); leaveJVM(); NYI(); } - -jfloat JNICALL CallFloatMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) { enterJVM(); leaveJVM(); NYI(); } -jfloat JNICALL CallFloatMethodV(JNIEnv* env, jobject obj, jmethodID methodID, va_list args) { enterJVM(); leaveJVM(); NYI(); } -jfloat JNICALL CallFloatMethodA(JNIEnv* env, jobject obj, jmethodID methodID, const jvalue* args) { enterJVM(); leaveJVM(); NYI(); } - -jdouble JNICALL CallDoubleMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) { enterJVM(); leaveJVM(); NYI(); } -jdouble JNICALL CallDoubleMethodV(JNIEnv* env, jobject obj, jmethodID methodID, va_list args) { enterJVM(); leaveJVM(); NYI(); } -jdouble JNICALL CallDoubleMethodA(JNIEnv* env, jobject obj, jmethodID methodID, const jvalue* args) { enterJVM(); leaveJVM(); NYI(); } - -void JNICALL CallVoidMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) { enterJVM(); leaveJVM(); NYI(); } -void JNICALL CallVoidMethodV(JNIEnv* env, jobject obj, jmethodID methodID, va_list args) { enterJVM(); leaveJVM(); NYI(); } -void JNICALL CallVoidMethodA(JNIEnv* env, jobject obj, jmethodID methodID, const jvalue* args) { enterJVM(); leaveJVM(); NYI(); } - -jobject JNICALL CallNonvirtualObjectMethod(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID, ...) { enterJVM(); leaveJVM(); NYI(); } -jobject JNICALL CallNonvirtualObjectMethodV(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID, va_list args) { enterJVM(); leaveJVM(); NYI(); } -jobject JNICALL CallNonvirtualObjectMethodA(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID, const jvalue* args) { enterJVM(); leaveJVM(); NYI(); } +#define defNonVirtualCall(jtype, id, j3type) \ + jtype JNICALL CallNonvirtual##id##Method(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID, ...) { \ + va_list va; \ + va_start(va, methodID); \ + jtype res = env->CallNonvirtual##id##MethodV(obj, clazz, methodID, va); \ + va_end(va); \ + return res; \ + } \ + \ + jtype JNICALL CallNonvirtual##id##MethodV(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID, va_list args) { \ + jvalue res; \ + \ + enterJVM(); \ + res = methodID->invokeSpecial(obj, args); \ + leaveJVM(); \ + \ + return res.val##j3type; \ + } \ + \ + jtype JNICALL CallNonvirtual##id##MethodA(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID, const jvalue* args) { \ + jvalue res; \ + \ + enterJVM(); \ + res = methodID->invokeSpecial(obj, args); \ + leaveJVM(); \ + \ + return res.val##j3type; \ + } -jboolean JNICALL CallNonvirtualBooleanMethod(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID, ...) { enterJVM(); leaveJVM(); NYI(); } -jboolean JNICALL CallNonvirtualBooleanMethodV(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID, va_list args) { enterJVM(); leaveJVM(); NYI(); } -jboolean JNICALL CallNonvirtualBooleanMethodA(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID, const jvalue* args) { enterJVM(); leaveJVM(); NYI(); } +#define defJNI(jtype, id, j3type) \ + defCall(jtype, id, j3type) \ + defNonVirtualCall(jtype, id, j3type) \ + defStaticCall(jtype, id, j3type) + + defJNI(jobject, Object, Object); + defJNI(jboolean, Boolean, Boolean); + defJNI(jbyte, Byte, Byte); + defJNI(jchar, Char, Char); + defJNI(jshort, Short, Short); + defJNI(jint, Int, Integer); + defJNI(jlong, Long, Long); + defJNI(jfloat, Float, Float); + defJNI(jdouble, Double, Double); + +void JNICALL CallVoidMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) { + va_list va; + va_start(va, methodID); + env->CallVoidMethodV(obj, methodID, va); + va_end(va); +} -jbyte JNICALL CallNonvirtualByteMethod(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID, ...) { enterJVM(); leaveJVM(); NYI(); } -jbyte JNICALL CallNonvirtualByteMethodV(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID, va_list args) { enterJVM(); leaveJVM(); NYI(); } -jbyte JNICALL CallNonvirtualByteMethodA(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID, const jvalue* args) { enterJVM(); leaveJVM(); NYI(); } +void JNICALL CallVoidMethodV(JNIEnv* env, jobject obj, jmethodID methodID, va_list args) { + enterJVM(); + methodID->invokeVirtual(obj, args); + leaveJVM(); +} -jchar JNICALL CallNonvirtualCharMethod(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID, ...) { enterJVM(); leaveJVM(); NYI(); } -jchar JNICALL CallNonvirtualCharMethodV(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID, va_list args) { enterJVM(); leaveJVM(); NYI(); } -jchar CallNonvirtualCharMethodA(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID, const jvalue* args) { enterJVM(); leaveJVM(); NYI(); } +void JNICALL CallVoidMethodA(JNIEnv* env, jobject obj, jmethodID methodID, const jvalue* args) { + enterJVM(); + methodID->invokeVirtual(obj, args); + leaveJVM(); +} -jshort JNICALL CallNonvirtualShortMethod(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID, ...) { enterJVM(); leaveJVM(); NYI(); } -jshort JNICALL CallNonvirtualShortMethodV(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID, va_list args) { enterJVM(); leaveJVM(); NYI(); } -jshort JNICALL CallNonvirtualShortMethodA(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID, const jvalue* args) { enterJVM(); leaveJVM(); NYI(); } +void JNICALL CallNonvirtualVoidMethod(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID, ...) { + va_list va; + va_start(va, methodID); + env->CallNonvirtualVoidMethodV(obj, clazz, methodID, va); + va_end(va); +} -jint JNICALL CallNonvirtualIntMethod(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID, ...) { enterJVM(); leaveJVM(); NYI(); } -jint JNICALL CallNonvirtualIntMethodV(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID, va_list args) { enterJVM(); leaveJVM(); NYI(); } -jint JNICALL CallNonvirtualIntMethodA(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID, const jvalue* args) { enterJVM(); leaveJVM(); NYI(); } +void JNICALL CallNonvirtualVoidMethodV(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID, va_list args) { + enterJVM(); + methodID->invokeSpecial(obj, args); + leaveJVM(); +} -jlong JNICALL CallNonvirtualLongMethod(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID, ...) { enterJVM(); leaveJVM(); NYI(); } -jlong JNICALL CallNonvirtualLongMethodV(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID, va_list args) { enterJVM(); leaveJVM(); NYI(); } -jlong JNICALL CallNonvirtualLongMethodA(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID, const jvalue* args) { enterJVM(); leaveJVM(); NYI(); } +void JNICALL CallNonvirtualVoidMethodA(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID, const jvalue* args) { + enterJVM(); + methodID->invokeSpecial(obj, args); + leaveJVM(); +} -jfloat JNICALL CallNonvirtualFloatMethod(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID, ...) { enterJVM(); leaveJVM(); NYI(); } -jfloat JNICALL CallNonvirtualFloatMethodV(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID, va_list args) { enterJVM(); leaveJVM(); NYI(); } -jfloat JNICALL CallNonvirtualFloatMethodA(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID, const jvalue* args) { enterJVM(); leaveJVM(); NYI(); } +void JNICALL CallStaticVoidMethod(JNIEnv* env, jclass cls, jmethodID methodID, ...) { + va_list va; + va_start(va, methodID); + env->CallStaticVoidMethodV(cls, methodID, va); + va_end(va); +} -jdouble JNICALL CallNonvirtualDoubleMethod(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID, ...) { enterJVM(); leaveJVM(); NYI(); } -jdouble JNICALL CallNonvirtualDoubleMethodV(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID, va_list args) { enterJVM(); leaveJVM(); NYI(); } -jdouble JNICALL CallNonvirtualDoubleMethodA(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID, const jvalue* args) { enterJVM(); leaveJVM(); NYI(); } +void JNICALL CallStaticVoidMethodV(JNIEnv* env, jclass cls, jmethodID methodID, va_list args) { + enterJVM(); + methodID->invokeStatic(args); + leaveJVM(); +} -void JNICALL CallNonvirtualVoidMethod(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID, ...) { enterJVM(); leaveJVM(); NYI(); } -void JNICALL CallNonvirtualVoidMethodV(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID, va_list args) { enterJVM(); leaveJVM(); NYI(); } -void JNICALL CallNonvirtualVoidMethodA(JNIEnv* env, jobject obj, jclass clazz, jmethodID methodID, const jvalue* args) { enterJVM(); leaveJVM(); NYI(); } +void JNICALL CallStaticVoidMethodA(JNIEnv* env, jclass cls, jmethodID methodID, const jvalue* args) { + enterJVM(); + methodID->invokeStatic(args); + leaveJVM(); +} jfieldID JNICALL GetFieldID(JNIEnv* env, jclass clazz, const char* name, const char* sig) { enterJVM(); leaveJVM(); NYI(); } @@ -277,57 +314,6 @@ void JNICALL SetLongField(JNIEnv* env, j void JNICALL SetFloatField(JNIEnv* env, jobject obj, jfieldID fieldID, jfloat val) { enterJVM(); leaveJVM(); NYI(); } void JNICALL SetDoubleField(JNIEnv* env, jobject obj, jfieldID fieldID, jdouble val) { enterJVM(); leaveJVM(); NYI(); } -jmethodID JNICALL GetStaticMethodID(JNIEnv* env, jclass clazz, const char* name, const char* sig) { - jmethodID res; - - enterJVM(); - - J3ObjectType* cl = J3ObjectType::nativeClass(clazz); - cl->initialise(); - vmkit::Names* n = cl->loader()->vm()->names(); - res = cl->findStaticMethod(n->get(name), n->get(sig)); - - leaveJVM(); - - return res; -} - -jboolean JNICALL CallStaticBooleanMethod(JNIEnv* env, jclass clazz, jmethodID methodID, ...) { enterJVM(); leaveJVM(); NYI(); } -jboolean JNICALL CallStaticBooleanMethodV(JNIEnv* env, jclass clazz, jmethodID methodID, va_list args) { enterJVM(); leaveJVM(); NYI(); } -jboolean JNICALL CallStaticBooleanMethodA(JNIEnv* env, jclass clazz, jmethodID methodID, const jvalue* args) { enterJVM(); leaveJVM(); NYI(); } - -jbyte JNICALL CallStaticByteMethod(JNIEnv* env, jclass clazz, jmethodID methodID, ...) { enterJVM(); leaveJVM(); NYI(); } -jbyte JNICALL CallStaticByteMethodV(JNIEnv* env, jclass clazz, jmethodID methodID, va_list args) { enterJVM(); leaveJVM(); NYI(); } -jbyte JNICALL CallStaticByteMethodA(JNIEnv* env, jclass clazz, jmethodID methodID, const jvalue* args) { enterJVM(); leaveJVM(); NYI(); } - -jchar JNICALL CallStaticCharMethod(JNIEnv* env, jclass clazz, jmethodID methodID, ...) { enterJVM(); leaveJVM(); NYI(); } -jchar JNICALL CallStaticCharMethodV(JNIEnv* env, jclass clazz, jmethodID methodID, va_list args) { enterJVM(); leaveJVM(); NYI(); } -jchar JNICALL CallStaticCharMethodA(JNIEnv* env, jclass clazz, jmethodID methodID, const jvalue* args) { enterJVM(); leaveJVM(); NYI(); } - -jshort JNICALL CallStaticShortMethod(JNIEnv* env, jclass clazz, jmethodID methodID, ...) { enterJVM(); leaveJVM(); NYI(); } -jshort JNICALL CallStaticShortMethodV(JNIEnv* env, jclass clazz, jmethodID methodID, va_list args) { enterJVM(); leaveJVM(); NYI(); } -jshort JNICALL CallStaticShortMethodA(JNIEnv* env, jclass clazz, jmethodID methodID, const jvalue* args) { enterJVM(); leaveJVM(); NYI(); } - -jint JNICALL CallStaticIntMethod(JNIEnv* env, jclass clazz, jmethodID methodID, ...) { enterJVM(); leaveJVM(); NYI(); } -jint JNICALL CallStaticIntMethodV(JNIEnv* env, jclass clazz, jmethodID methodID, va_list args) { enterJVM(); leaveJVM(); NYI(); } -jint JNICALL CallStaticIntMethodA(JNIEnv* env, jclass clazz, jmethodID methodID, const jvalue* args) { enterJVM(); leaveJVM(); NYI(); } - -jlong JNICALL CallStaticLongMethod(JNIEnv* env, jclass clazz, jmethodID methodID, ...) { enterJVM(); leaveJVM(); NYI(); } -jlong JNICALL CallStaticLongMethodV(JNIEnv* env, jclass clazz, jmethodID methodID, va_list args) { enterJVM(); leaveJVM(); NYI(); } -jlong JNICALL CallStaticLongMethodA(JNIEnv* env, jclass clazz, jmethodID methodID, const jvalue* args) { enterJVM(); leaveJVM(); NYI(); } - -jfloat JNICALL CallStaticFloatMethod(JNIEnv* env, jclass clazz, jmethodID methodID, ...) { enterJVM(); leaveJVM(); NYI(); } -jfloat JNICALL CallStaticFloatMethodV(JNIEnv* env, jclass clazz, jmethodID methodID, va_list args) { enterJVM(); leaveJVM(); NYI(); } -jfloat JNICALL CallStaticFloatMethodA(JNIEnv* env, jclass clazz, jmethodID methodID, const jvalue* args) { enterJVM(); leaveJVM(); NYI(); } - -jdouble JNICALL CallStaticDoubleMethod(JNIEnv* env, jclass clazz, jmethodID methodID, ...) { enterJVM(); leaveJVM(); NYI(); } -jdouble JNICALL CallStaticDoubleMethodV(JNIEnv* env, jclass clazz, jmethodID methodID, va_list args) { enterJVM(); leaveJVM(); NYI(); } -jdouble JNICALL CallStaticDoubleMethodA(JNIEnv* env, jclass clazz, jmethodID methodID, const jvalue* args) { enterJVM(); leaveJVM(); NYI(); } - -void JNICALL CallStaticVoidMethod(JNIEnv* env, jclass cls, jmethodID methodID, ...) { enterJVM(); leaveJVM(); NYI(); } -void JNICALL CallStaticVoidMethodV(JNIEnv* env, jclass cls, jmethodID methodID, va_list args) { enterJVM(); leaveJVM(); NYI(); } -void JNICALL CallStaticVoidMethodA(JNIEnv* env, jclass cls, jmethodID methodID, const jvalue* args) { enterJVM(); leaveJVM(); NYI(); } - jfieldID JNICALL GetStaticFieldID(JNIEnv* env, jclass clazz, const char* name, const char* sig) { enterJVM(); leaveJVM(); NYI(); } jobject JNICALL GetStaticObjectField(JNIEnv* env, jclass clazz, jfieldID fieldID) { enterJVM(); leaveJVM(); NYI(); } jboolean JNICALL GetStaticBooleanField(JNIEnv* env, jclass clazz, jfieldID fieldID) { enterJVM(); leaveJVM(); NYI(); } @@ -402,7 +388,15 @@ jobject JNICALL GetObjectArrayElement(JN void JNICALL SetObjectArrayElement(JNIEnv* env, jobjectArray array, jsize index, jobject val) { enterJVM(); leaveJVM(); NYI(); } jbooleanArray JNICALL NewBooleanArray(JNIEnv* env, jsize len) { enterJVM(); leaveJVM(); NYI(); } -jbyteArray JNICALL NewByteArray(JNIEnv* env, jsize len) { enterJVM(); leaveJVM(); NYI(); } +jbyteArray JNICALL NewByteArray(JNIEnv* env, jsize len) { + jbyteArray res; + enterJVM(); + res = J3ObjectHandle::doNewArray(J3Thread::get()->vm()->typeBoolean->getArray(), len); + fprintf(stderr, " ---> %p\n", res); + leaveJVM(); + return res; +} + jcharArray JNICALL NewCharArray(JNIEnv* env, jsize len) { enterJVM(); leaveJVM(); NYI(); } jshortArray JNICALL NewShortArray(JNIEnv* env, jsize len) { enterJVM(); leaveJVM(); NYI(); } jintArray JNICALL NewIntArray(JNIEnv* env, jsize len) { enterJVM(); leaveJVM(); NYI(); } From gael.thomas at lip6.fr Sun Dec 22 10:17:05 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sun, 22 Dec 2013 18:17:05 -0000 Subject: [vmkit-commits] [vmkit] r197886 - add jni new array methods Message-ID: <20131222181705.61D612A6C029@llvm.org> Author: gthomas Date: Sun Dec 22 12:17:05 2013 New Revision: 197886 URL: http://llvm.org/viewvc/llvm-project?rev=197886&view=rev Log: add jni new array methods Modified: vmkit/branches/mcjit/lib/j3/vm/j3jni.cc Modified: vmkit/branches/mcjit/lib/j3/vm/j3jni.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3jni.cc?rev=197886&r1=197885&r2=197886&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3jni.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3jni.cc Sun Dec 22 12:17:05 2013 @@ -220,20 +220,33 @@ jmethodID JNICALL GetStaticMethodID(JNIE return res.val##j3type; \ } -#define defJNI(jtype, id, j3type) \ +#define defNewArray(jtype, id, j3type) \ + jtype##Array JNICALL New##id##Array(JNIEnv* env, jsize len) { \ + jtype##Array res; \ + enterJVM(); \ + res = J3ObjectHandle::doNewArray(J3Thread::get()->vm()->type##j3type->getArray(), len); \ + leaveJVM(); \ + return res; \ + } + +#define defJNIObj(jtype, id, j3type) \ defCall(jtype, id, j3type) \ defNonVirtualCall(jtype, id, j3type) \ - defStaticCall(jtype, id, j3type) + defStaticCall(jtype, id, j3type) \ - defJNI(jobject, Object, Object); - defJNI(jboolean, Boolean, Boolean); - defJNI(jbyte, Byte, Byte); - defJNI(jchar, Char, Char); - defJNI(jshort, Short, Short); - defJNI(jint, Int, Integer); - defJNI(jlong, Long, Long); - defJNI(jfloat, Float, Float); - defJNI(jdouble, Double, Double); +#define defJNI(jtype, id, j3type) \ + defJNIObj(jtype, id, j3type) \ + defNewArray(jtype, id, j3type) + + defJNIObj(jobject, Object, Object); + defJNI (jboolean, Boolean, Boolean); + defJNI (jbyte, Byte, Byte); + defJNI (jchar, Char, Char); + defJNI (jshort, Short, Short); + defJNI (jint, Int, Integer); + defJNI (jlong, Long, Long); + defJNI (jfloat, Float, Float); + defJNI (jdouble, Double, Double); void JNICALL CallVoidMethod(JNIEnv* env, jobject obj, jmethodID methodID, ...) { va_list va; @@ -387,23 +400,6 @@ jobjectArray JNICALL NewObjectArray(JNIE jobject JNICALL GetObjectArrayElement(JNIEnv* env, jobjectArray array, jsize index) { enterJVM(); leaveJVM(); NYI(); } void JNICALL SetObjectArrayElement(JNIEnv* env, jobjectArray array, jsize index, jobject val) { enterJVM(); leaveJVM(); NYI(); } -jbooleanArray JNICALL NewBooleanArray(JNIEnv* env, jsize len) { enterJVM(); leaveJVM(); NYI(); } -jbyteArray JNICALL NewByteArray(JNIEnv* env, jsize len) { - jbyteArray res; - enterJVM(); - res = J3ObjectHandle::doNewArray(J3Thread::get()->vm()->typeBoolean->getArray(), len); - fprintf(stderr, " ---> %p\n", res); - leaveJVM(); - return res; -} - -jcharArray JNICALL NewCharArray(JNIEnv* env, jsize len) { enterJVM(); leaveJVM(); NYI(); } -jshortArray JNICALL NewShortArray(JNIEnv* env, jsize len) { enterJVM(); leaveJVM(); NYI(); } -jintArray JNICALL NewIntArray(JNIEnv* env, jsize len) { enterJVM(); leaveJVM(); NYI(); } -jlongArray JNICALL NewLongArray(JNIEnv* env, jsize len) { enterJVM(); leaveJVM(); NYI(); } -jfloatArray JNICALL NewFloatArray(JNIEnv* env, jsize len) { enterJVM(); leaveJVM(); NYI(); } -jdoubleArray JNICALL NewDoubleArray(JNIEnv* env, jsize len) { enterJVM(); leaveJVM(); NYI(); } - jboolean* JNICALL GetBooleanArrayElements(JNIEnv* env, jbooleanArray array, jboolean* isCopy) { enterJVM(); leaveJVM(); NYI(); } jbyte* JNICALL GetByteArrayElements(JNIEnv* env, jbyteArray array, jboolean* isCopy) { enterJVM(); leaveJVM(); NYI(); } jchar* JNICALL GetCharArrayElements(JNIEnv* env, jcharArray array, jboolean* isCopy) { enterJVM(); leaveJVM(); NYI(); } From gael.thomas at lip6.fr Sun Dec 22 12:25:39 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sun, 22 Dec 2013 20:25:39 -0000 Subject: [vmkit-commits] [vmkit] r197887 - more jni functions Message-ID: <20131222202539.B14062A6C029@llvm.org> Author: gthomas Date: Sun Dec 22 14:25:38 2013 New Revision: 197887 URL: http://llvm.org/viewvc/llvm-project?rev=197887&view=rev Log: more jni functions Modified: vmkit/branches/mcjit/include/j3/j3.h vmkit/branches/mcjit/include/j3/j3object.h vmkit/branches/mcjit/lib/j3/vm/j3jni.cc vmkit/branches/mcjit/lib/j3/vm/j3object.cc Modified: vmkit/branches/mcjit/include/j3/j3.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3.h?rev=197887&r1=197886&r2=197887&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3.h (original) +++ vmkit/branches/mcjit/include/j3/j3.h Sun Dec 22 14:25:38 2013 @@ -106,6 +106,8 @@ namespace j3 { static void nullPointerException() __attribute__((noreturn)); static void classCastException() __attribute__((noreturn)); + + static void arrayBoundCheckException() __attribute__((noreturn)); }; } Modified: vmkit/branches/mcjit/include/j3/j3object.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3object.h?rev=197887&r1=197886&r2=197887&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3object.h (original) +++ vmkit/branches/mcjit/include/j3/j3object.h Sun Dec 22 14:25:38 2013 @@ -106,6 +106,7 @@ namespace j3 { public: uint32_t length() { return _length; } + void* content() { return this+1; } }; class J3ObjectHandle { @@ -142,13 +143,15 @@ namespace j3 { void setObjectAt(uint32_t idx, J3ObjectHandle* v); J3ObjectHandle* getObjectAt(uint32_t idx); -#define defAccessor(name, ctype, llvmtype) \ - void rawSet##name(uint32_t offset, ctype value); \ - ctype rawGet##name(uint32_t offset); \ - void set##name(J3Field* f, ctype value); \ - ctype get##name(J3Field* f); \ - void set##name##At(uint32_t idx, ctype value); \ - ctype get##name##At(uint32_t idx); +#define defAccessor(name, ctype, llvmtype) \ + void rawSet##name(uint32_t offset, ctype value); \ + ctype rawGet##name(uint32_t offset); \ + void set##name(J3Field* f, ctype value); \ + ctype get##name(J3Field* f); \ + void set##name##At(uint32_t idx, ctype value); \ + ctype get##name##At(uint32_t idx); \ + void setRegion##name(uint32_t selfIdx, const ctype* buf, uint32_t bufIdx, uint32_t len); \ + void getRegion##name(uint32_t selfIdx, const ctype* buf, uint32_t bufIdx, uint32_t len); onJavaPrimitives(defAccessor); #undef defAccessor }; Modified: vmkit/branches/mcjit/lib/j3/vm/j3jni.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3jni.cc?rev=197887&r1=197886&r2=197887&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3jni.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3jni.cc Sun Dec 22 14:25:38 2013 @@ -229,6 +229,13 @@ jmethodID JNICALL GetStaticMethodID(JNIE return res; \ } +#define defArrayRegion(jtype, id, j3type) \ + void JNICALL Set##id##ArrayRegion(JNIEnv* env, jtype##Array array, jsize start, jsize len, const jtype* buf) { \ + enterJVM(); \ + array->setRegion##j3type(0, buf, start, len); \ + leaveJVM(); \ + } + #define defJNIObj(jtype, id, j3type) \ defCall(jtype, id, j3type) \ defNonVirtualCall(jtype, id, j3type) \ @@ -236,7 +243,8 @@ jmethodID JNICALL GetStaticMethodID(JNIE #define defJNI(jtype, id, j3type) \ defJNIObj(jtype, id, j3type) \ - defNewArray(jtype, id, j3type) + defNewArray(jtype, id, j3type) \ + defArrayRegion(jtype, id, j3type) defJNIObj(jobject, Object, Object); defJNI (jboolean, Boolean, Boolean); @@ -427,15 +435,6 @@ void JNICALL GetLongArrayRegion(JNIEnv* void JNICALL GetFloatArrayRegion(JNIEnv* env, jfloatArray array, jsize start, jsize len, jfloat* buf) { enterJVM(); leaveJVM(); NYI(); } void JNICALL GetDoubleArrayRegion(JNIEnv* env, jdoubleArray array, jsize start, jsize len, jdouble* buf) { enterJVM(); leaveJVM(); NYI(); } -void JNICALL SetBooleanArrayRegion(JNIEnv* env, jbooleanArray array, jsize start, jsize l, const jboolean* buf) { enterJVM(); leaveJVM(); NYI(); } -void JNICALL SetByteArrayRegion(JNIEnv* env, jbyteArray array, jsize start, jsize len, const jbyte* buf) { enterJVM(); leaveJVM(); NYI(); } -void JNICALL SetCharArrayRegion(JNIEnv* env, jcharArray array, jsize start, jsize len, const jchar* buf) { enterJVM(); leaveJVM(); NYI(); } -void JNICALL SetShortArrayRegion(JNIEnv* env, jshortArray array, jsize start, jsize len, const jshort* buf) { enterJVM(); leaveJVM(); NYI(); } -void JNICALL SetIntArrayRegion(JNIEnv* env, jintArray array, jsize start, jsize len, const jint* buf) { enterJVM(); leaveJVM(); NYI(); } -void JNICALL SetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start, jsize len, const jlong* buf) { enterJVM(); leaveJVM(); NYI(); } -void JNICALL SetFloatArrayRegion(JNIEnv* env, jfloatArray array, jsize start, jsize len, const jfloat* buf) { enterJVM(); leaveJVM(); NYI(); } -void JNICALL SetDoubleArrayRegion(JNIEnv* env, jdoubleArray array, jsize start, jsize len, const jdouble* buf) { enterJVM(); leaveJVM(); NYI(); } - jint JNICALL RegisterNatives(JNIEnv* env, jclass clazz, const JNINativeMethod* methods, jint nMethods) { enterJVM(); J3Class* cl = J3Class::nativeClass(clazz)->asClass(); Modified: vmkit/branches/mcjit/lib/j3/vm/j3object.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3object.cc?rev=197887&r1=197886&r2=197887&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3object.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3object.cc Sun Dec 22 14:25:38 2013 @@ -344,6 +344,22 @@ J3ObjectHandle* J3ObjectHandle::doNewArr \ ctype J3ObjectHandle::get##name##At(uint32_t idx) { \ return rawGet##name(sizeof(J3ArrayObject) + idx*sizeof(ctype)); \ + } \ + \ + void J3ObjectHandle::setRegion##name(uint32_t selfIdx, const ctype* buf, uint32_t bufIdx, uint32_t len) { \ + if(selfIdx + len > arrayLength()) \ + J3::arrayBoundCheckException(); \ + memcpy((uint8_t*)array() + sizeof(J3ArrayObject) + selfIdx*sizeof(ctype), \ + (uint8_t*)buf + bufIdx*sizeof(ctype), \ + len*sizeof(ctype)); \ + } \ + \ + void J3ObjectHandle::getRegion##name(uint32_t selfIdx, const ctype* buf, uint32_t bufIdx, uint32_t len) { \ + if(selfIdx + len > arrayLength()) \ + J3::arrayBoundCheckException(); \ + memcpy((uint8_t*)buf + bufIdx*sizeof(ctype), \ + (uint8_t*)array() + sizeof(J3ArrayObject) + selfIdx*sizeof(ctype), \ + len*sizeof(ctype)); \ } onJavaPrimitives(defAccessor) From gael.thomas at lip6.fr Sun Dec 22 12:48:58 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sun, 22 Dec 2013 20:48:58 -0000 Subject: [vmkit-commits] [vmkit] r197888 - define a trampoline helper Message-ID: <20131222204858.697A62A6C029@llvm.org> Author: gthomas Date: Sun Dec 22 14:48:57 2013 New Revision: 197888 URL: http://llvm.org/viewvc/llvm-project?rev=197888&view=rev Log: define a trampoline helper Added: vmkit/branches/mcjit/include/j3/j3trampoline.h vmkit/branches/mcjit/lib/j3/vm/j3trampoline.cc Modified: vmkit/branches/mcjit/lib/j3/vm/j3object.cc Added: vmkit/branches/mcjit/include/j3/j3trampoline.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3trampoline.h?rev=197888&view=auto ============================================================================== --- vmkit/branches/mcjit/include/j3/j3trampoline.h (added) +++ vmkit/branches/mcjit/include/j3/j3trampoline.h Sun Dec 22 14:48:57 2013 @@ -0,0 +1,23 @@ +#ifndef _J3_TRAMPOLINE_H_ +#define _J3_TRAMPOLINE_H_ + +namespace vmkit { + class BumpAllocator; +} + +namespace j3 { + class J3Method; + class J3Object; + + class J3Trampoline { + static void* staticTrampoline(J3Object* obj, J3Method* ref); + static void* virtualTrampoline(J3Object* obj, J3Method* ref); + + static void* buildTrampoline(vmkit::BumpAllocator* allocator, J3Method* method, void* tra); + public: + static void* buildStaticTrampoline(vmkit::BumpAllocator* allocator, J3Method* target); + static void* buildVirtualTrampoline(vmkit::BumpAllocator* allocator, J3Method* target); + }; +}; + +#endif Modified: vmkit/branches/mcjit/lib/j3/vm/j3object.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3object.cc?rev=197888&r1=197887&r2=197888&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3object.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3object.cc Sun Dec 22 14:48:57 2013 @@ -401,6 +401,8 @@ void* J3ObjectHandle::trampoline(J3Objec J3ObjectHandle* prev = J3Thread::get()->tell(); J3ObjectHandle* handle = J3Thread::get()->push(obj); + fprintf(stderr, "target: %ls::%ls\n", target->cl()->name()->cStr(), target->name()->cStr()); + void* res = target->fnPtr(); if(!J3Cst::isStatic(target->access())) Added: vmkit/branches/mcjit/lib/j3/vm/j3trampoline.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3trampoline.cc?rev=197888&view=auto ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3trampoline.cc (added) +++ vmkit/branches/mcjit/lib/j3/vm/j3trampoline.cc Sun Dec 22 14:48:57 2013 @@ -0,0 +1,86 @@ +#include "j3/j3trampoline.h" +#include "j3/j3object.h" +#include "j3/j3method.h" +#include "j3/j3.h" + +using namespace j3; + +void* J3Trampoline::staticTrampoline(J3Object* obj, J3Method* target) { + return target->fnPtr(); +} + +void* J3Trampoline::virtualTrampoline(J3Object* obj, J3Method* target) { + J3::internalError(L"implement me: virtualTrampoline"); +#if 0 + J3ObjectHandle* prev = J3Thread::get()->tell(); + J3ObjectHandle* handle = J3Thread::get()->push(obj); + + fprintf(stderr, "target: %ls::%ls\n", target->cl()->name()->cStr(), target->name()->cStr()); + + void* res = target->fnPtr(); + + if(!J3Cst::isStatic(target->access())) + handle->vt()->virtualMethods()[target->index()] = res; + + J3Thread::get()->restore(prev); + + return res; +#endif +} + +void* J3Trampoline::buildTrampoline(vmkit::BumpAllocator* allocator, J3Method* m, void* tra) { + size_t trampolineSize = 148; + void* res = allocator->allocate(trampolineSize); + +#define dd(p, n) ((((uintptr_t)p) >> n) & 0xff) + uint8_t code[] = { + 0x57, // 0: push %rdi + 0x56, // 1: push %rsi + 0x52, // 2: push %rdx + 0x51, // 3: push %rcx + 0x41, 0x50, // 4: push %r8 + 0x41, 0x51, // 6: push %r9 + 0x48, 0x81, 0xec, 0x88, 0x00, 0x00, 0x00, // 8: sub $128+8, %esp + 0xf3, 0x0f, 0x11, 0x04, 0x24, // 15: movss %xmm0, (%rsp) + 0xf3, 0x0f, 0x11, 0x4c, 0x24, 0x10, // 20: movss %xmm1, 16(%rsp) + 0xf3, 0x0f, 0x11, 0x54, 0x24, 0x20, // 26: movss %xmm2, 32(%rsp) + 0xf3, 0x0f, 0x11, 0x5c, 0x24, 0x30, // 32: movss %xmm3, 48(%rsp) + 0xf3, 0x0f, 0x11, 0x64, 0x24, 0x40, // 38: movss %xmm4, 64(%rsp) + 0xf3, 0x0f, 0x11, 0x6c, 0x24, 0x50, // 44: movss %xmm5, 80(%rsp) + 0xf3, 0x0f, 0x11, 0x74, 0x24, 0x60, // 50: movss %xmm6, 96(%rsp) + 0xf3, 0x0f, 0x11, 0x7c, 0x24, 0x70, // 56: movss %xmm7, 112(%rsp) + 0x48, 0xbe, dd(m, 0), dd(m, 8), dd(m, 16), dd(m, 24), dd(m, 32), dd(m, 40), dd(m, 48), dd(m, 56), // 62: mov -> %rsi + 0x48, 0xb8, dd(tra, 0), dd(tra, 8), dd(tra, 16), dd(tra, 24), dd(tra, 32), dd(tra, 40), dd(tra, 48), dd(tra, 56), // 72: mov -> %rax + 0xff, 0xd0, // 82: call %rax + 0xf3, 0x0f, 0x10, 0x04, 0x24, // 84: movss (%rsp), %xmm0 + 0xf3, 0x0f, 0x10, 0x4c, 0x24, 0x10, // 89: movss 16(%rsp), %xmm1 + 0xf3, 0x0f, 0x10, 0x54, 0x24, 0x20, // 95: movss 32(%rsp), %xmm2 + 0xf3, 0x0f, 0x10, 0x5c, 0x24, 0x30, // 101: movss 48(%rsp), %xmm3 + 0xf3, 0x0f, 0x10, 0x64, 0x24, 0x40, // 107: movss 64(%rsp), %xmm4 + 0xf3, 0x0f, 0x10, 0x6c, 0x24, 0x50, // 113: movss 80(%rsp), %xmm5 + 0xf3, 0x0f, 0x10, 0x74, 0x24, 0x60, // 119: movss 96(%rsp), %xmm6 + 0xf3, 0x0f, 0x10, 0x7c, 0x24, 0x70, // 125: movss 112(%rsp), %xmm7 + 0x48, 0x81, 0xc4, 0x88, 0x00, 0x00, 0x00, // 131: add $128+8, %esp + 0x41, 0x59, // 138: pop %r9 + 0x41, 0x58, // 140: pop %r8 + 0x59, // 142: pop %rcx + 0x5a, // 143: pop %rdx + 0x5e, // 144: pop %rsi + 0x5f, // 145: pop %rdi + 0xff, 0xe0 // 146: jmp %rax + // total: 148 + }; +#undef dd + + memcpy(res, code, trampolineSize); + + return res; +} + +void* J3Trampoline::buildStaticTrampoline(vmkit::BumpAllocator* allocator, J3Method* method) { + return buildTrampoline(allocator, method, (void*)staticTrampoline); +} + +void* J3Trampoline::buildVirtualTrampoline(vmkit::BumpAllocator* allocator, J3Method* method) { + return buildTrampoline(allocator, method, (void*)virtualTrampoline); +} From gael.thomas at lip6.fr Sun Dec 22 12:55:36 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sun, 22 Dec 2013 20:55:36 -0000 Subject: [vmkit-commits] [vmkit] r197889 - use the new trampoline builder Message-ID: <20131222205536.6FEF52A6C029@llvm.org> Author: gthomas Date: Sun Dec 22 14:55:36 2013 New Revision: 197889 URL: http://llvm.org/viewvc/llvm-project?rev=197889&view=rev Log: use the new trampoline builder Modified: vmkit/branches/mcjit/include/j3/j3method.h vmkit/branches/mcjit/include/j3/j3object.h vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc vmkit/branches/mcjit/lib/j3/vm/j3method.cc vmkit/branches/mcjit/lib/j3/vm/j3object.cc Modified: vmkit/branches/mcjit/include/j3/j3method.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3method.h?rev=197889&r1=197888&r2=197889&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3method.h (original) +++ vmkit/branches/mcjit/include/j3/j3method.h Sun Dec 22 14:55:36 2013 @@ -69,28 +69,19 @@ namespace j3 { void* _fnPtr; char* volatile _llvmAllNames; /* stub + _ + native_name */ void* _nativeFnPtr; - - uint8_t _trampoline[1]; + void* volatile _staticTrampoline; + void* volatile _virtualTrampoline; llvm::Type* doNativeType(J3Type* type); J3Value internalInvoke(bool statically, J3ObjectHandle* handle, va_list va); J3Value internalInvoke(bool statically, J3ObjectHandle* handle, J3Value* args); - - void* operator new(size_t size, vmkit::BumpAllocator* allocator, size_t trampolineSize); - void buildLLVMNames(J3Class* from); public: J3Method(uint16_t access, J3Class* cl, const vmkit::Name* name, const vmkit::Name* sign); void* getSymbolAddress(); - static J3Method* newMethod(vmkit::BumpAllocator* allocator, - uint16_t access, - J3Class* cl, - const vmkit::Name* name, - const vmkit::Name* sign); - char* llvmFunctionName(J3Class* from=0); char* llvmDescriptorName(J3Class* from=0); char* llvmStubName(J3Class* from=0); Modified: vmkit/branches/mcjit/include/j3/j3object.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3object.h?rev=197889&r1=197888&r2=197889&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3object.h (original) +++ vmkit/branches/mcjit/include/j3/j3object.h Sun Dec 22 14:55:36 2013 @@ -130,8 +130,6 @@ namespace j3 { static J3ObjectHandle* doNewObject(J3Class* cl); static J3ObjectHandle* doNewArray(J3ArrayClass* cl, uint32_t length); - static void* trampoline(J3Object* obj, J3Method* ref); - void harakiri() { _obj = 0; } uint32_t hashCode(); Modified: vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc?rev=197889&r1=197888&r2=197889&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc Sun Dec 22 14:55:36 2013 @@ -179,7 +179,7 @@ J3Method* J3ClassLoader::method(uint16_t std::map::iterator it = methods.find(&method); if(it == methods.end()) { - res = J3Method::newMethod(allocator(), access, cl, name, sign); + res = new(allocator()) J3Method(access, cl, name, sign); methods[res] = res; } else { res = it->second; Modified: vmkit/branches/mcjit/lib/j3/vm/j3method.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3method.cc?rev=197889&r1=197888&r2=197889&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3method.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3method.cc Sun Dec 22 14:55:36 2013 @@ -8,6 +8,7 @@ #include "j3/j3mangler.h" #include "j3/j3thread.h" #include "j3/j3codegen.h" +#include "j3/j3trampoline.h" #include "llvm/IR/Type.h" #include "llvm/IR/Module.h" @@ -70,7 +71,9 @@ void* J3Method::fnPtr() { } void* J3Method::functionPointerOrTrampoline() { - return _fnPtr ? _fnPtr : _trampoline; + if(!_staticTrampoline) + _staticTrampoline = J3Trampoline::buildStaticTrampoline(cl()->loader()->allocator(), this); + return _fnPtr ? _fnPtr : _staticTrampoline; } void* J3MethodCode::getSymbolAddress() { @@ -101,65 +104,6 @@ J3Method* J3Method::resolve(J3ObjectHand return cl()->findVirtualMethod(name(), sign()); } -void* J3Method::operator new(size_t size, vmkit::BumpAllocator* allocator, size_t trampolineSize) { - return allocator->allocate(size + (trampolineSize - 1)*sizeof(uint8_t)); -} - -J3Method* J3Method::newMethod(vmkit::BumpAllocator* allocator, - uint16_t access, - J3Class* cl, - const vmkit::Name* name, - const vmkit::Name* sign) { - size_t trampolineSize = 148; - - void* tra = (void*)J3ObjectHandle::trampoline; - J3Method* res = new(allocator, trampolineSize) J3Method(access, cl, name, sign); - -#define dd(p, n) ((((uintptr_t)p) >> n) & 0xff) - uint8_t code[] = { - 0x57, // 0: push %rdi - 0x56, // 1: push %rsi - 0x52, // 2: push %rdx - 0x51, // 3: push %rcx - 0x41, 0x50, // 4: push %r8 - 0x41, 0x51, // 6: push %r9 - 0x48, 0x81, 0xec, 0x88, 0x00, 0x00, 0x00, // 8: sub $128+8, %esp - 0xf3, 0x0f, 0x11, 0x04, 0x24, // 15: movss %xmm0, (%rsp) - 0xf3, 0x0f, 0x11, 0x4c, 0x24, 0x10, // 20: movss %xmm1, 16(%rsp) - 0xf3, 0x0f, 0x11, 0x54, 0x24, 0x20, // 26: movss %xmm2, 32(%rsp) - 0xf3, 0x0f, 0x11, 0x5c, 0x24, 0x30, // 32: movss %xmm3, 48(%rsp) - 0xf3, 0x0f, 0x11, 0x64, 0x24, 0x40, // 38: movss %xmm4, 64(%rsp) - 0xf3, 0x0f, 0x11, 0x6c, 0x24, 0x50, // 44: movss %xmm5, 80(%rsp) - 0xf3, 0x0f, 0x11, 0x74, 0x24, 0x60, // 50: movss %xmm6, 96(%rsp) - 0xf3, 0x0f, 0x11, 0x7c, 0x24, 0x70, // 56: movss %xmm7, 112(%rsp) - 0x48, 0xbe, dd(res, 0), dd(res, 8), dd(res, 16), dd(res, 24), dd(res, 32), dd(res, 40), dd(res, 48), dd(res, 56), // 62: mov -> %rsi - 0x48, 0xb8, dd(tra, 0), dd(tra, 8), dd(tra, 16), dd(tra, 24), dd(tra, 32), dd(tra, 40), dd(tra, 48), dd(tra, 56), // 72: mov -> %rax - 0xff, 0xd0, // 82: call %rax - 0xf3, 0x0f, 0x10, 0x04, 0x24, // 84: movss (%rsp), %xmm0 - 0xf3, 0x0f, 0x10, 0x4c, 0x24, 0x10, // 89: movss 16(%rsp), %xmm1 - 0xf3, 0x0f, 0x10, 0x54, 0x24, 0x20, // 95: movss 32(%rsp), %xmm2 - 0xf3, 0x0f, 0x10, 0x5c, 0x24, 0x30, // 101: movss 48(%rsp), %xmm3 - 0xf3, 0x0f, 0x10, 0x64, 0x24, 0x40, // 107: movss 64(%rsp), %xmm4 - 0xf3, 0x0f, 0x10, 0x6c, 0x24, 0x50, // 113: movss 80(%rsp), %xmm5 - 0xf3, 0x0f, 0x10, 0x74, 0x24, 0x60, // 119: movss 96(%rsp), %xmm6 - 0xf3, 0x0f, 0x10, 0x7c, 0x24, 0x70, // 125: movss 112(%rsp), %xmm7 - 0x48, 0x81, 0xc4, 0x88, 0x00, 0x00, 0x00, // 131: add $128+8, %esp - 0x41, 0x59, // 138: pop %r9 - 0x41, 0x58, // 140: pop %r8 - 0x59, // 142: pop %rcx - 0x5a, // 143: pop %rdx - 0x5e, // 144: pop %rsi - 0x5f, // 145: pop %rdi - 0xff, 0xe0 // 146: jmp %rax - // total: 148 - }; -#undef dd - - memcpy(res->_trampoline, code, trampolineSize); - - return res; -} - J3Value J3Method::internalInvoke(bool statically, J3ObjectHandle* handle, J3Value* inArgs) { std::vector args(methodType()->nbIns()); Modified: vmkit/branches/mcjit/lib/j3/vm/j3object.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3object.cc?rev=197889&r1=197888&r2=197889&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3object.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3object.cc Sun Dec 22 14:55:36 2013 @@ -397,20 +397,6 @@ J3ObjectHandle* J3ObjectHandle::getObjec return rawGetObject(sizeof(J3ArrayObject) + idx*sizeof(J3Object*)); } -void* J3ObjectHandle::trampoline(J3Object* obj, J3Method* target) { - J3ObjectHandle* prev = J3Thread::get()->tell(); - J3ObjectHandle* handle = J3Thread::get()->push(obj); - - fprintf(stderr, "target: %ls::%ls\n", target->cl()->name()->cStr(), target->name()->cStr()); - - void* res = target->fnPtr(); - - if(!J3Cst::isStatic(target->access())) - handle->vt()->virtualMethods()[target->index()] = res; - - return res; -} - /* * J3LocalReferences */ From gael.thomas at lip6.fr Sun Dec 22 13:01:33 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sun, 22 Dec 2013 21:01:33 -0000 Subject: [vmkit-commits] [vmkit] r197890 - define a static and a virtual trampoline Message-ID: <20131222210133.667E52A6C029@llvm.org> Author: gthomas Date: Sun Dec 22 15:01:32 2013 New Revision: 197890 URL: http://llvm.org/viewvc/llvm-project?rev=197890&view=rev Log: define a static and a virtual trampoline Modified: vmkit/branches/mcjit/include/j3/j3method.h vmkit/branches/mcjit/lib/j3/vm/j3method.cc vmkit/branches/mcjit/lib/j3/vm/j3object.cc vmkit/branches/mcjit/lib/j3/vm/j3trampoline.cc Modified: vmkit/branches/mcjit/include/j3/j3method.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3method.h?rev=197890&r1=197889&r2=197890&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3method.h (original) +++ vmkit/branches/mcjit/include/j3/j3method.h Sun Dec 22 15:01:32 2013 @@ -120,7 +120,8 @@ namespace j3 { J3Value invokeVirtual(J3ObjectHandle* obj, va_list va); void* fnPtr(); - void* functionPointerOrTrampoline(); + void* functionPointerOrStaticTrampoline(); + void* functionPointerOrVirtualTrampoline(); void dump(); }; Modified: vmkit/branches/mcjit/lib/j3/vm/j3method.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3method.cc?rev=197890&r1=197889&r2=197890&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3method.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3method.cc Sun Dec 22 15:01:32 2013 @@ -70,14 +70,24 @@ void* J3Method::fnPtr() { return _fnPtr; } -void* J3Method::functionPointerOrTrampoline() { +void* J3Method::functionPointerOrStaticTrampoline() { + if(_fnPtr) + return _fnPtr; if(!_staticTrampoline) _staticTrampoline = J3Trampoline::buildStaticTrampoline(cl()->loader()->allocator(), this); - return _fnPtr ? _fnPtr : _staticTrampoline; + return _staticTrampoline; +} + +void* J3Method::functionPointerOrVirtualTrampoline() { + if(_fnPtr) + return _fnPtr; + if(!_virtualTrampoline) + _virtualTrampoline = J3Trampoline::buildVirtualTrampoline(cl()->loader()->allocator(), this); + return _virtualTrampoline; } void* J3MethodCode::getSymbolAddress() { - return self->functionPointerOrTrampoline(); + return self->functionPointerOrStaticTrampoline(); } void* J3Method::getSymbolAddress() { Modified: vmkit/branches/mcjit/lib/j3/vm/j3object.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3object.cc?rev=197890&r1=197889&r2=197890&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3object.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3object.cc Sun Dec 22 15:01:32 2013 @@ -72,7 +72,7 @@ J3VirtualTable* J3VirtualTable::create(J memcpy(res->_virtualMethods, super->vt()->_virtualMethods, sizeof(void*)*super->vt()->nbVirtualMethods()); for(uint32_t i=0; inbMethods(); i++) - res->_virtualMethods[pm[i]->index()] = pm[i]->functionPointerOrTrampoline(); + res->_virtualMethods[pm[i]->index()] = pm[i]->functionPointerOrVirtualTrampoline(); return res; } Modified: vmkit/branches/mcjit/lib/j3/vm/j3trampoline.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3trampoline.cc?rev=197890&r1=197889&r2=197890&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3trampoline.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3trampoline.cc Sun Dec 22 15:01:32 2013 @@ -10,6 +10,7 @@ void* J3Trampoline::staticTrampoline(J3O } void* J3Trampoline::virtualTrampoline(J3Object* obj, J3Method* target) { + return staticTrampoline(obj, target); J3::internalError(L"implement me: virtualTrampoline"); #if 0 J3ObjectHandle* prev = J3Thread::get()->tell(); From gael.thomas at lip6.fr Sun Dec 22 13:09:21 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sun, 22 Dec 2013 21:09:21 -0000 Subject: [vmkit-commits] [vmkit] r197891 - correctly handle virtual calls Message-ID: <20131222210921.ACCC12A6C029@llvm.org> Author: gthomas Date: Sun Dec 22 15:09:21 2013 New Revision: 197891 URL: http://llvm.org/viewvc/llvm-project?rev=197891&view=rev Log: correctly handle virtual calls Modified: vmkit/branches/mcjit/lib/j3/vm/j3options.cc vmkit/branches/mcjit/lib/j3/vm/j3trampoline.cc Modified: vmkit/branches/mcjit/lib/j3/vm/j3options.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3options.cc?rev=197891&r1=197890&r2=197891&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3options.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3options.cc Sun Dec 22 15:09:21 2013 @@ -19,7 +19,7 @@ J3Options::J3Options() { debugLoad = 0; debugResolve = 0; debugIniting = 0; - debugTranslate = 0; + debugTranslate = 1; debugLinking = 0; genDebugExecute = debugExecute ? 1 : 0; Modified: vmkit/branches/mcjit/lib/j3/vm/j3trampoline.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3trampoline.cc?rev=197891&r1=197890&r2=197891&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3trampoline.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3trampoline.cc Sun Dec 22 15:09:21 2013 @@ -1,6 +1,8 @@ #include "j3/j3trampoline.h" #include "j3/j3object.h" #include "j3/j3method.h" +#include "j3/j3thread.h" +#include "j3/j3class.h" #include "j3/j3.h" using namespace j3; @@ -10,23 +12,17 @@ void* J3Trampoline::staticTrampoline(J3O } void* J3Trampoline::virtualTrampoline(J3Object* obj, J3Method* target) { - return staticTrampoline(obj, target); - J3::internalError(L"implement me: virtualTrampoline"); -#if 0 J3ObjectHandle* prev = J3Thread::get()->tell(); J3ObjectHandle* handle = J3Thread::get()->push(obj); + J3ObjectType* cl = handle->vt()->type()->asObjectType(); + J3Method* impl = cl == target->cl() ? target : cl->findVirtualMethod(target->name(), target->sign()); - fprintf(stderr, "target: %ls::%ls\n", target->cl()->name()->cStr(), target->name()->cStr()); - - void* res = target->fnPtr(); - - if(!J3Cst::isStatic(target->access())) - handle->vt()->virtualMethods()[target->index()] = res; + void* res = impl->fnPtr(); + handle->vt()->virtualMethods()[impl->index()] = res; J3Thread::get()->restore(prev); return res; -#endif } void* J3Trampoline::buildTrampoline(vmkit::BumpAllocator* allocator, J3Method* m, void* tra) { From gael.thomas at lip6.fr Sun Dec 22 13:17:59 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sun, 22 Dec 2013 21:17:59 -0000 Subject: [vmkit-commits] [vmkit] r197892 - correct two bugs Message-ID: <20131222211759.AE2852A6C029@llvm.org> Author: gthomas Date: Sun Dec 22 15:17:59 2013 New Revision: 197892 URL: http://llvm.org/viewvc/llvm-project?rev=197892&view=rev Log: correct two bugs Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc vmkit/branches/mcjit/lib/j3/vm/j3options.cc vmkit/branches/mcjit/lib/vmkit/allocator.cc Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=197892&r1=197891&r2=197892&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Sun Dec 22 15:17:59 2013 @@ -883,15 +883,15 @@ void J3CodeGen::translate() { break; case J3Cst::BC_baload: /* 0x33 */ - arrayStore(vm->typeByte); + arrayLoad(vm->typeByte); break; case J3Cst::BC_caload: /* 0x34 */ - arrayStore(vm->typeChar); + arrayLoad(vm->typeChar); break; case J3Cst::BC_saload: /* 0x35 */ - arrayStore(vm->typeShort); + arrayLoad(vm->typeShort); break; case J3Cst::BC_istore: /* 0x36 wide */ Modified: vmkit/branches/mcjit/lib/j3/vm/j3options.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3options.cc?rev=197892&r1=197891&r2=197892&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3options.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3options.cc Sun Dec 22 15:17:59 2013 @@ -19,7 +19,7 @@ J3Options::J3Options() { debugLoad = 0; debugResolve = 0; debugIniting = 0; - debugTranslate = 1; + debugTranslate = 0; debugLinking = 0; genDebugExecute = debugExecute ? 1 : 0; Modified: vmkit/branches/mcjit/lib/vmkit/allocator.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/allocator.cc?rev=197892&r1=197891&r2=197892&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/allocator.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/allocator.cc Sun Dec 22 15:17:59 2013 @@ -27,6 +27,7 @@ BumpAllocator::~BumpAllocator() { while(current->next) { BumpAllocatorNode* tmp = current->next; unmap(current, (uintptr_t)current->top - (uintptr_t)current); + current = tmp; } } From gael.thomas at lip6.fr Sun Dec 22 13:28:29 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sun, 22 Dec 2013 21:28:29 -0000 Subject: [vmkit-commits] [vmkit] r197893 - classAt is now able to find array classes Message-ID: <20131222212829.588102A6C029@llvm.org> Author: gthomas Date: Sun Dec 22 15:28:29 2013 New Revision: 197893 URL: http://llvm.org/viewvc/llvm-project?rev=197893&view=rev Log: classAt is now able to find array classes Modified: vmkit/branches/mcjit/include/j3/j3class.h vmkit/branches/mcjit/lib/j3/vm/j3.cc vmkit/branches/mcjit/lib/j3/vm/j3class.cc vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Modified: vmkit/branches/mcjit/include/j3/j3class.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3class.h?rev=197893&r1=197892&r2=197893&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3class.h (original) +++ vmkit/branches/mcjit/include/j3/j3class.h Sun Dec 22 15:28:29 2013 @@ -243,7 +243,7 @@ namespace j3 { uint32_t integerAt(uint16_t idx); uint64_t longAt(uint16_t idx); J3ObjectHandle* stringAt(uint16_t idx); - J3Class* classAt(uint16_t idx); + J3ObjectType* classAt(uint16_t idx); J3Method* methodAt(uint16_t idx, uint16_t access); J3Field* fieldAt(uint16_t idx, uint16_t access); Modified: vmkit/branches/mcjit/lib/j3/vm/j3.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3.cc?rev=197893&r1=197892&r2=197893&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3.cc Sun Dec 22 15:28:29 2013 @@ -100,15 +100,6 @@ void J3::start(int argc, char** argv) { classVMData = classClass->findVirtualField(hf.name(), hf.type()); initialClassLoader->method(J3Cst::ACC_STATIC, L"java/lang/System", L"initializeSystemClass", L"()V")->invokeStatic(); - -#if 0 - J3Method* m = initialClassLoader->method(J3Cst::ACC_STATIC, - L"java/lang/ClassLoader", - L"getSystemClassLoader", - L"()Ljava/lang/ClassLoader;"); - - m->invokeStatic(); -#endif } JNIEnv* J3::jniEnv() { Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=197893&r1=197892&r2=197893&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Sun Dec 22 15:28:29 2013 @@ -448,20 +448,20 @@ void J3Class::readClassBytes(std::vector _access = reader.readU2(); - J3Class* self = classAt(reader.readU2()); + J3ObjectType* self = classAt(reader.readU2()); if(self != this) J3::classFormatError(this, L"wrong class file (describes class %ls)", self->name()->cStr()); uint16_t superIdx = reader.readU2(); - _super = superIdx ? classAt(superIdx) : this; + _super = superIdx ? classAt(superIdx)->asClass() : this; _nbInterfaces = reader.readU2(); _interfaces = (J3Class**)loader()->allocator()->allocate(nbInterfaces()*sizeof(J3Class*)); for(size_t i=0; iasClass(); } size_t n = nbHiddenFields + reader.readU2(), nbStaticFields = 0, nbVirtualFields = 0; @@ -648,7 +648,7 @@ J3Method* J3Class::methodAt(uint16_t idx } uint16_t ntIdx = ctpValues[idx] & 0xffff; - J3Class* cl = classAt(ctpValues[idx] >> 16); + J3Class* cl = classAt(ctpValues[idx] >> 16)->asClass(); check(ntIdx, J3Cst::CONSTANT_NameAndType); const vmkit::Name* name = nameAt(ctpValues[ntIdx] >> 16); @@ -670,7 +670,7 @@ J3Field* J3Class::fieldAt(uint16_t idx, } uint16_t ntIdx = ctpValues[idx] & 0xffff; - J3Class* cl = classAt(ctpValues[idx] >> 16); + J3Class* cl = classAt(ctpValues[idx] >> 16)->asClass(); check(ntIdx, J3Cst::CONSTANT_NameAndType); const vmkit::Name* name = nameAt(ctpValues[ntIdx] >> 16); @@ -681,16 +681,16 @@ J3Field* J3Class::fieldAt(uint16_t idx, return res; } -J3Class* J3Class::classAt(uint16_t idx) { +J3ObjectType* J3Class::classAt(uint16_t idx) { check(idx, J3Cst::CONSTANT_Class); - J3Class* res = (J3Class*)ctpResolved[idx]; + J3ObjectType* res = (J3ObjectType*)ctpResolved[idx]; if(res) return res; const vmkit::Name* name = nameAt(ctpValues[idx]); if(name->cStr()[0] == J3Cst::ID_Array) - J3::internalError(L"implement me: classAt with array"); + res = loader()->getType(this, name)->asObjectType(); else res = loader()->getClass(name); Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=197893&r1=197892&r2=197893&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Sun Dec 22 15:28:29 2013 @@ -1252,7 +1252,7 @@ void J3CodeGen::translate() { case J3Cst::BC_invokeinterface: nyi(); /* 0xb9 */ case J3Cst::BC_new: /* 0xbb */ - newObject(cl->classAt(codeReader->readU2())); + newObject(cl->classAt(codeReader->readU2())->asClass()); break; case J3Cst::BC_newarray: /* 0xbc */ From gael.thomas at lip6.fr Sun Dec 22 13:36:18 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sun, 22 Dec 2013 21:36:18 -0000 Subject: [vmkit-commits] [vmkit] r197894 - begin the implementation of unsafe Message-ID: <20131222213618.2F45E2A6C029@llvm.org> Author: gthomas Date: Sun Dec 22 15:36:17 2013 New Revision: 197894 URL: http://llvm.org/viewvc/llvm-project?rev=197894&view=rev Log: begin the implementation of unsafe Added: vmkit/branches/mcjit/lib/j3/openjdk/j3unsafe.cc Added: vmkit/branches/mcjit/lib/j3/openjdk/j3unsafe.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/openjdk/j3unsafe.cc?rev=197894&view=auto ============================================================================== --- vmkit/branches/mcjit/lib/j3/openjdk/j3unsafe.cc (added) +++ vmkit/branches/mcjit/lib/j3/openjdk/j3unsafe.cc Sun Dec 22 15:36:17 2013 @@ -0,0 +1,10 @@ +#include "j3/j3jni.h" +#include "j3/j3object.h" + +using namespace j3; + +extern "C" { + JNIEXPORT void JNICALL Java_sun_misc_Unsafe_registerNatives(J3Object*) { + // Nothing, we define the Unsafe methods with the expected signatures. + } +} From gael.thomas at lip6.fr Mon Dec 23 12:04:41 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Mon, 23 Dec 2013 20:04:41 -0000 Subject: [vmkit-commits] [vmkit] r197917 - use finer locks and define a map to record all the interface types Message-ID: <20131223200443.197532A6C028@llvm.org> Author: gthomas Date: Mon Dec 23 14:04:40 2013 New Revision: 197917 URL: http://llvm.org/viewvc/llvm-project?rev=197917&view=rev Log: use finer locks and define a map to record all the interface types Modified: vmkit/branches/mcjit/include/j3/j3class.h vmkit/branches/mcjit/include/j3/j3classloader.h vmkit/branches/mcjit/include/j3/j3codegen.h vmkit/branches/mcjit/include/j3/j3method.h vmkit/branches/mcjit/lib/j3/vm/j3class.cc vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc vmkit/branches/mcjit/lib/j3/vm/j3method.cc Modified: vmkit/branches/mcjit/include/j3/j3class.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3class.h?rev=197917&r1=197916&r2=197917&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3class.h (original) +++ vmkit/branches/mcjit/include/j3/j3class.h Mon Dec 23 14:04:40 2013 @@ -220,6 +220,8 @@ namespace j3 { void load(); void doResolve(J3Field* hiddenFields, size_t nbHiddenFields); void doInitialise(); + + J3Method* interfaceOrMethodAt(uint16_t idx, uint16_t access); public: J3Class(J3ClassLoader* loader, const vmkit::Name* name); @@ -244,6 +246,7 @@ namespace j3 { uint64_t longAt(uint16_t idx); J3ObjectHandle* stringAt(uint16_t idx); J3ObjectType* classAt(uint16_t idx); + J3Method* interfaceMethodAt(uint16_t idx, uint16_t access); J3Method* methodAt(uint16_t idx, uint16_t access); J3Field* fieldAt(uint16_t idx, uint16_t access); Modified: vmkit/branches/mcjit/include/j3/j3classloader.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3classloader.h?rev=197917&r1=197916&r2=197917&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3classloader.h (original) +++ vmkit/branches/mcjit/include/j3/j3classloader.h Mon Dec 23 14:04:40 2013 @@ -39,10 +39,20 @@ namespace j3 { J3ObjectHandle* _javaClassLoader; J3GlobalReferences _globalReferences; - pthread_mutex_t _mutex; /* a lock */ + + pthread_mutex_t _mutexClasses; vmkit::NameMap::map classes; /* classes managed by this class loader */ + + pthread_mutex_t _mutexTypes; vmkit::NameMap::map types; /* shortcut to find types */ + + pthread_mutex_t _mutexMethodTypes; vmkit::NameMap::map methodTypes; /* shortcut to find method types - REMOVE */ + + pthread_mutex_t _mutexInterfaceSignatures; + vmkit::NameMap::map interfaceSignatures; + + pthread_mutex_t _mutexMethods; MethodRefMap methods; /* all te known method */ llvm::ExecutionEngine* _ee; @@ -57,13 +67,12 @@ namespace j3 { public: J3ClassLoader(J3* vm, J3ObjectHandle* javaClassLoader, vmkit::BumpAllocator* allocator); + uint32_t interfaceIndex(const vmkit::Name* sign); + J3GlobalReferences* globalReferences() { return &_globalReferences; } J3ObjectHandle* javaClassLoader() { return _javaClassLoader; } - void lock() { pthread_mutex_lock(&_mutex); } - void unlock() { pthread_mutex_unlock(&_mutex); } - J3* vm() const { return (J3*)vmkit::CompilationUnit::vm(); }; J3Method* method(uint16_t access, J3Class* cl, Modified: vmkit/branches/mcjit/include/j3/j3codegen.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3codegen.h?rev=197917&r1=197916&r2=197917&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3codegen.h (original) +++ vmkit/branches/mcjit/include/j3/j3codegen.h Mon Dec 23 14:04:40 2013 @@ -138,6 +138,7 @@ namespace j3 { void invokeVirtual(uint32_t idx); void invokeStatic(uint32_t idx); void invokeSpecial(uint32_t idx); + void invokeInterface(uint32_t idx); llvm::Value* arrayContent(J3Type* cType, llvm::Value* array, llvm::Value* idx); Modified: vmkit/branches/mcjit/include/j3/j3method.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3method.h?rev=197917&r1=197916&r2=197917&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3method.h (original) +++ vmkit/branches/mcjit/include/j3/j3method.h Mon Dec 23 14:04:40 2013 @@ -80,6 +80,8 @@ namespace j3 { public: J3Method(uint16_t access, J3Class* cl, const vmkit::Name* name, const vmkit::Name* sign); + uint32_t interfaceIndex(); + void* getSymbolAddress(); char* llvmFunctionName(J3Class* from=0); Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=197917&r1=197916&r2=197917&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Mon Dec 23 14:04:40 2013 @@ -637,13 +637,12 @@ uint64_t J3Class::longAt(uint16_t idx) { return ((uint64_t)ctpValues[idx] << 32) + (uint64_t)ctpValues[idx+1]; } -J3Method* J3Class::methodAt(uint16_t idx, uint16_t access) { - check(idx, J3Cst::CONSTANT_Methodref); +J3Method* J3Class::interfaceOrMethodAt(uint16_t idx, uint16_t access) { J3Method* res = (J3Method*)ctpResolved[idx]; if(res) { if((res->access() & J3Cst::ACC_STATIC) != (access & J3Cst::ACC_STATIC)) - J3::classFormatError(this, L"inconstitent use of virtual and static methods"); + J3::classFormatError(this, L"inconsistent use of virtual and static methods"); return res; } @@ -659,6 +658,16 @@ J3Method* J3Class::methodAt(uint16_t idx return res; } +J3Method* J3Class::methodAt(uint16_t idx, uint16_t access) { + check(idx, J3Cst::CONSTANT_Methodref); + return interfaceOrMethodAt(idx, access); +} + +J3Method* J3Class::interfaceMethodAt(uint16_t idx, uint16_t access) { + check(idx, J3Cst::CONSTANT_InterfaceMethodref); + return interfaceOrMethodAt(idx, access); +} + J3Field* J3Class::fieldAt(uint16_t idx, uint16_t access) { check(idx, J3Cst::CONSTANT_Fieldref); J3Field* res = (J3Field*)ctpResolved[idx]; Modified: vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc?rev=197917&r1=197916&r2=197917&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc Mon Dec 23 14:04:40 2013 @@ -26,14 +26,33 @@ J3ClassLoader::J3ClassLoader(J3* v, J3Ob classes(vmkit::Name::less, allocator), types(vmkit::Name::less, allocator), methodTypes(vmkit::Name::less, allocator), + interfaceSignatures(vmkit::Name::less, allocator), methods(j3MethodLess, allocator), nativeLibraries(allocator) { _javaClassLoader = javaClassLoader; - // pthread_mutexattr_t attr; - // pthread_mutexattr_init(&attr); - // pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); - pthread_mutex_init(&_mutex, 0);//&attr); + pthread_mutex_init(&_mutexClasses, 0); + pthread_mutex_init(&_mutexTypes, 0); + pthread_mutex_init(&_mutexMethodTypes, 0); + pthread_mutex_init(&_mutexInterfaceSignatures, 0); + pthread_mutex_init(&_mutexMethods, 0); +} + +uint32_t J3ClassLoader::interfaceIndex(const vmkit::Name* sign) { + pthread_mutex_lock(&_mutexInterfaceSignatures); + std::map::iterator it = interfaceSignatures.find(sign); + uint32_t res; + + if(it == interfaceSignatures.end()) { + res = interfaceSignatures.size(); + interfaceSignatures[sign] = res; + } else { + res = it->second; + } + + pthread_mutex_unlock(&_mutexInterfaceSignatures); + + return res; } void* J3ClassLoader::lookupNativeFunctionPointer(J3Method* method, const char* symbol) { @@ -47,11 +66,11 @@ void* J3ClassLoader::lookupNativeFunctio } J3Class* J3ClassLoader::getClass(const vmkit::Name* name) { - lock(); + pthread_mutex_lock(&_mutexClasses); J3Class* res = classes[name]; if(!res) classes[name] = res = new(allocator()) J3Class(this, name); - unlock(); + pthread_mutex_unlock(&_mutexClasses); return res; } @@ -119,9 +138,9 @@ J3Type* J3ClassLoader::getTypeInternal(J } J3Type* J3ClassLoader::getType(J3Class* from, const vmkit::Name* type) { - lock(); + pthread_mutex_lock(&_mutexTypes); J3Type* res = types[type]; - unlock(); + pthread_mutex_unlock(&_mutexTypes); if(!res) { uint32_t end; @@ -132,18 +151,18 @@ J3Type* J3ClassLoader::getType(J3Class* //printf("Analyse %ls => %ls\n", type->cStr(), res->name()->cStr()); - lock(); + pthread_mutex_lock(&_mutexTypes); types[type] = res; - unlock(); + pthread_mutex_unlock(&_mutexTypes); } return res; } J3MethodType* J3ClassLoader::getMethodType(J3Class* from, const vmkit::Name* sign) { - lock(); + pthread_mutex_lock(&_mutexMethodTypes); J3MethodType* res = methodTypes[sign]; - unlock(); + pthread_mutex_unlock(&_mutexMethodTypes); if(!res) { J3Type* args[sign->length()]; @@ -160,13 +179,13 @@ J3MethodType* J3ClassLoader::getMethodTy if(cur != sign->length()) wrongType(from, sign); - lock(); + pthread_mutex_lock(&_mutexMethodTypes); J3MethodType* tmp = methodTypes[sign]; if(tmp) res = tmp; else res = new(allocator(), nbArgs - 1) J3MethodType(args, nbArgs); - unlock(); + pthread_mutex_unlock(&_mutexMethodTypes); } return res; @@ -175,7 +194,7 @@ J3MethodType* J3ClassLoader::getMethodTy J3Method* J3ClassLoader::method(uint16_t access, J3Class* cl, const vmkit::Name* name, const vmkit::Name* sign) { J3Method method(access, cl, name, sign), *res; - lock(); + pthread_mutex_lock(&_mutexMethods); std::map::iterator it = methods.find(&method); if(it == methods.end()) { @@ -184,7 +203,7 @@ J3Method* J3ClassLoader::method(uint16_t } else { res = it->second; } - unlock(); + pthread_mutex_unlock(&_mutexMethods); return res; } Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=197917&r1=197916&r2=197917&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Mon Dec 23 14:04:40 2013 @@ -262,6 +262,12 @@ void J3CodeGen::invoke(J3Method* target, } } +void J3CodeGen::invokeInterface(uint32_t idx) { + J3Method* target = cl->interfaceMethodAt(idx, 0); + fprintf(stderr, "---> %d\n", target->interfaceIndex()); + J3::internalError(L"implement me: invokeInterface"); +} + void J3CodeGen::invokeVirtual(uint32_t idx) { J3Method* target = cl->methodAt(idx, 0); J3MethodType* type = target->methodType(cl); @@ -1250,7 +1256,11 @@ void J3CodeGen::translate() { invokeStatic(codeReader->readU2()); break; - case J3Cst::BC_invokeinterface: nyi(); /* 0xb9 */ + case J3Cst::BC_invokeinterface: /* 0xb9 */ + invokeInterface(codeReader->readU2()); + codeReader->readU2(); + break; + case J3Cst::BC_new: /* 0xbb */ newObject(cl->classAt(codeReader->readU2())->asClass()); break; Modified: vmkit/branches/mcjit/lib/j3/vm/j3method.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3method.cc?rev=197917&r1=197916&r2=197917&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3method.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3method.cc Mon Dec 23 14:04:40 2013 @@ -41,6 +41,10 @@ J3Method::J3Method(uint16_t access, J3Cl _index = -1; } +uint32_t J3Method::interfaceIndex() { + return cl()->loader()->interfaceIndex(name()); +} + uint32_t J3Method::index() { return _index; } From gael.thomas at lip6.fr Mon Dec 23 12:21:02 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Mon, 23 Dec 2013 20:21:02 -0000 Subject: [vmkit-commits] [vmkit] r197919 - hash interface methods with their name and signature, add an interface method dispatch table in the virtual table Message-ID: <20131223202102.4029F2A6C029@llvm.org> Author: gthomas Date: Mon Dec 23 14:21:01 2013 New Revision: 197919 URL: http://llvm.org/viewvc/llvm-project?rev=197919&view=rev Log: hash interface methods with their name and signature, add an interface method dispatch table in the virtual table Modified: vmkit/branches/mcjit/include/j3/j3classloader.h vmkit/branches/mcjit/include/j3/j3object.h vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc vmkit/branches/mcjit/lib/j3/vm/j3method.cc vmkit/branches/mcjit/lib/j3/vm/j3object.cc Modified: vmkit/branches/mcjit/include/j3/j3classloader.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3classloader.h?rev=197919&r1=197918&r2=197919&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3classloader.h (original) +++ vmkit/branches/mcjit/include/j3/j3classloader.h Mon Dec 23 14:21:01 2013 @@ -32,10 +32,18 @@ namespace j3 { bool operator()(const J3Method* lhs, const J3Method* rhs) const; }; + struct J3InterfaceMethodLess : public std::binary_function { + bool operator()(const J3Method* lhs, const J3Method* rhs) const; + }; + typedef std::map > > MethodRefMap; - static J3MethodLess j3MethodLess; + typedef std::map > > InterfaceMethodRefMap; + + static J3MethodLess j3MethodLess; + static J3InterfaceMethodLess j3InterfaceMethodLess; J3ObjectHandle* _javaClassLoader; J3GlobalReferences _globalReferences; @@ -49,8 +57,8 @@ namespace j3 { pthread_mutex_t _mutexMethodTypes; vmkit::NameMap::map methodTypes; /* shortcut to find method types - REMOVE */ - pthread_mutex_t _mutexInterfaceSignatures; - vmkit::NameMap::map interfaceSignatures; + pthread_mutex_t _mutexInterfaces; + InterfaceMethodRefMap interfaces; pthread_mutex_t _mutexMethods; MethodRefMap methods; /* all te known method */ @@ -67,7 +75,7 @@ namespace j3 { public: J3ClassLoader(J3* vm, J3ObjectHandle* javaClassLoader, vmkit::BumpAllocator* allocator); - uint32_t interfaceIndex(const vmkit::Name* sign); + uint32_t interfaceIndex(J3Method* sign); J3GlobalReferences* globalReferences() { return &_globalReferences; } Modified: vmkit/branches/mcjit/include/j3/j3object.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3object.h?rev=197919&r1=197918&r2=197919&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3object.h (original) +++ vmkit/branches/mcjit/include/j3/j3object.h Mon Dec 23 14:21:01 2013 @@ -40,12 +40,14 @@ namespace j3 { class J3VirtualTable { public: + static const uint32_t nbInterfaceMethodTable = 23; static const uint32_t gepObjectClass = 0; - static const uint32_t gepVirtualMethods = 3; + static const uint32_t gepVirtualMethods = 4; private: J3Type* _type; J3TypeChecker checker; + void* _interfaceMethodTable[nbInterfaceMethodTable]; size_t _nbVirtualMethods; void* _virtualMethods[1]; Modified: vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc?rev=197919&r1=197918&r2=197919&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc Mon Dec 23 14:21:01 2013 @@ -18,7 +18,8 @@ using namespace j3; -J3ClassLoader::J3MethodLess J3ClassLoader::j3MethodLess; +J3ClassLoader::J3MethodLess J3ClassLoader::j3MethodLess; +J3ClassLoader::J3InterfaceMethodLess J3ClassLoader::j3InterfaceMethodLess; J3ClassLoader::J3ClassLoader(J3* v, J3ObjectHandle* javaClassLoader, vmkit::BumpAllocator* allocator) : CompilationUnit(allocator, v, "class-loader"), @@ -26,7 +27,7 @@ J3ClassLoader::J3ClassLoader(J3* v, J3Ob classes(vmkit::Name::less, allocator), types(vmkit::Name::less, allocator), methodTypes(vmkit::Name::less, allocator), - interfaceSignatures(vmkit::Name::less, allocator), + interfaces(j3InterfaceMethodLess, allocator), methods(j3MethodLess, allocator), nativeLibraries(allocator) { _javaClassLoader = javaClassLoader; @@ -34,23 +35,23 @@ J3ClassLoader::J3ClassLoader(J3* v, J3Ob pthread_mutex_init(&_mutexClasses, 0); pthread_mutex_init(&_mutexTypes, 0); pthread_mutex_init(&_mutexMethodTypes, 0); - pthread_mutex_init(&_mutexInterfaceSignatures, 0); + pthread_mutex_init(&_mutexInterfaces, 0); pthread_mutex_init(&_mutexMethods, 0); } -uint32_t J3ClassLoader::interfaceIndex(const vmkit::Name* sign) { - pthread_mutex_lock(&_mutexInterfaceSignatures); - std::map::iterator it = interfaceSignatures.find(sign); +uint32_t J3ClassLoader::interfaceIndex(J3Method* method) { + pthread_mutex_lock(&_mutexInterfaces); + InterfaceMethodRefMap::iterator it = interfaces.find(method); uint32_t res; - if(it == interfaceSignatures.end()) { - res = interfaceSignatures.size(); - interfaceSignatures[sign] = res; + if(it == interfaces.end()) { + res = interfaces.size(); + interfaces[method] = res; } else { res = it->second; } - pthread_mutex_unlock(&_mutexInterfaceSignatures); + pthread_mutex_unlock(&_mutexInterfaces); return res; } @@ -217,6 +218,12 @@ J3Method* J3ClassLoader::method(uint16_t return method(access, names->get(clName), names->get(name), names->get(sign)); } +bool J3ClassLoader::J3InterfaceMethodLess::operator()(j3::J3Method const* lhs, j3::J3Method const* rhs) const { + return lhs->name() < rhs->name() + || (lhs->name() == rhs->name() + && (lhs->sign() < rhs->sign())); +} + bool J3ClassLoader::J3MethodLess::operator()(j3::J3Method const* lhs, j3::J3Method const* rhs) const { return lhs->name() < rhs->name() || (lhs->name() == rhs->name() @@ -267,11 +274,6 @@ J3ClassBytes* J3InitialClassLoader::look return 0; } -bool char_ptr_less::operator()(const char* lhs, const char* rhs) const { - //printf("Compare: %ls - %ls - %d\n", lhs, rhs, wcscmp(lhs, rhs)); - return strcmp(lhs, rhs) < 0; -} - void J3InitialClassLoader::registerCMangling(const char* mangled, const char* demangled) { _cmangled[demangled] = mangled; } Modified: vmkit/branches/mcjit/lib/j3/vm/j3method.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3method.cc?rev=197919&r1=197918&r2=197919&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3method.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3method.cc Mon Dec 23 14:21:01 2013 @@ -42,7 +42,7 @@ J3Method::J3Method(uint16_t access, J3Cl } uint32_t J3Method::interfaceIndex() { - return cl()->loader()->interfaceIndex(name()); + return cl()->loader()->interfaceIndex(this); } uint32_t J3Method::index() { Modified: vmkit/branches/mcjit/lib/j3/vm/j3object.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3object.cc?rev=197919&r1=197918&r2=197919&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3object.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3object.cc Mon Dec 23 14:21:01 2013 @@ -71,6 +71,9 @@ J3VirtualTable* J3VirtualTable::create(J if(super != cl) /* super->vt() is not yet allocated for Object */ memcpy(res->_virtualMethods, super->vt()->_virtualMethods, sizeof(void*)*super->vt()->nbVirtualMethods()); + // for(uint32_t i=0; i_interfaceMethodTable[i] = + for(uint32_t i=0; inbMethods(); i++) res->_virtualMethods[pm[i]->index()] = pm[i]->functionPointerOrVirtualTrampoline(); From gael.thomas at lip6.fr Mon Dec 23 14:41:02 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Mon, 23 Dec 2013 22:41:02 -0000 Subject: [vmkit-commits] [vmkit] r197924 - Generate an invoke interface with the IMT algorithm. Not yet resolved. Message-ID: <20131223224102.2D4332A6C029@llvm.org> Author: gthomas Date: Mon Dec 23 16:41:01 2013 New Revision: 197924 URL: http://llvm.org/viewvc/llvm-project?rev=197924&view=rev Log: Generate an invoke interface with the IMT algorithm. Not yet resolved. Modified: vmkit/branches/mcjit/include/j3/j3.h vmkit/branches/mcjit/include/j3/j3object.h vmkit/branches/mcjit/include/j3/j3thread.h vmkit/branches/mcjit/include/j3/j3trampoline.h vmkit/branches/mcjit/lib/j3/vm/j3.cc vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc vmkit/branches/mcjit/lib/j3/vm/j3object.cc vmkit/branches/mcjit/lib/j3/vm/j3trampoline.cc Modified: vmkit/branches/mcjit/include/j3/j3.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3.h?rev=197924&r1=197923&r2=197924&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3.h (original) +++ vmkit/branches/mcjit/include/j3/j3.h Mon Dec 23 16:41:01 2013 @@ -50,6 +50,8 @@ namespace j3 { onJavaTypes(defPrimitive) #undef defPrimitive + void* interfaceTrampoline; + J3Type** arrayInterfaces; uint32_t nbArrayInterfaces; J3Class* objectClass; Modified: vmkit/branches/mcjit/include/j3/j3object.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3object.h?rev=197924&r1=197923&r2=197924&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3object.h (original) +++ vmkit/branches/mcjit/include/j3/j3object.h Mon Dec 23 16:41:01 2013 @@ -42,11 +42,14 @@ namespace j3 { public: static const uint32_t nbInterfaceMethodTable = 23; static const uint32_t gepObjectClass = 0; + static const uint32_t gepInterfaceMethods = 2; static const uint32_t gepVirtualMethods = 4; private: J3Type* _type; J3TypeChecker checker; + // see: Bowen Alpern, Anthony Cocchi, Stephen Fink, and David Grove. 2001. + // Efficient implementation of Java interfaces: Invokeinterface considered harmless. OOPSLA 2001. void* _interfaceMethodTable[nbInterfaceMethodTable]; size_t _nbVirtualMethods; void* _virtualMethods[1]; Modified: vmkit/branches/mcjit/include/j3/j3thread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3thread.h?rev=197924&r1=197923&r2=197924&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3thread.h (original) +++ vmkit/branches/mcjit/include/j3/j3thread.h Mon Dec 23 16:41:01 2013 @@ -14,6 +14,11 @@ namespace j3 { class J3; class J3Thread : public vmkit::Thread { + public: + static const uint32_t gepInterfaceMethodIndex = 1; + + private: + uint32_t _interfaceMethodIndex; vmkit::BumpAllocator* allocator; JNIEnv _jniEnv; J3LocalReferences _localReferences; @@ -23,7 +28,9 @@ namespace j3 { public: static J3Thread* create(J3* j3); - J3Method* getJavaCaller(uint32_t level=0); + J3Method* getJavaCaller(uint32_t level=0); + + uint32_t interfaceMethodIndex() { return _interfaceMethodIndex; } void ensureCapacity(uint32_t capacity); J3ObjectHandle* pendingException(); Modified: vmkit/branches/mcjit/include/j3/j3trampoline.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3trampoline.h?rev=197924&r1=197923&r2=197924&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3trampoline.h (original) +++ vmkit/branches/mcjit/include/j3/j3trampoline.h Mon Dec 23 16:41:01 2013 @@ -10,6 +10,7 @@ namespace j3 { class J3Object; class J3Trampoline { + static void* interfaceTrampoline(J3Object* obj); static void* staticTrampoline(J3Object* obj, J3Method* ref); static void* virtualTrampoline(J3Object* obj, J3Method* ref); @@ -17,6 +18,7 @@ namespace j3 { public: static void* buildStaticTrampoline(vmkit::BumpAllocator* allocator, J3Method* target); static void* buildVirtualTrampoline(vmkit::BumpAllocator* allocator, J3Method* target); + static void* buildInterfaceTrampoline(vmkit::BumpAllocator* allocator); }; }; Modified: vmkit/branches/mcjit/lib/j3/vm/j3.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3.cc?rev=197924&r1=197923&r2=197924&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3.cc Mon Dec 23 16:41:01 2013 @@ -8,6 +8,7 @@ #include "j3/j3constants.h" #include "j3/j3method.h" #include "j3/j3thread.h" +#include "j3/j3trampoline.h" #include "llvm/IR/Type.h" #include "llvm/IR/DerivedTypes.h" @@ -30,6 +31,7 @@ J3::J3(vmkit::BumpAllocator* allocator) clinitName = names()->get(J3Cst::clinitName); clinitSign = names()->get(J3Cst::clinitSign); initName = names()->get(J3Cst::initName); + interfaceTrampoline = J3Trampoline::buildInterfaceTrampoline(allocator); } J3* J3::create() { Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=197924&r1=197923&r2=197924&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Mon Dec 23 16:41:01 2013 @@ -263,9 +263,22 @@ void J3CodeGen::invoke(J3Method* target, } void J3CodeGen::invokeInterface(uint32_t idx) { - J3Method* target = cl->interfaceMethodAt(idx, 0); - fprintf(stderr, "---> %d\n", target->interfaceIndex()); - J3::internalError(L"implement me: invokeInterface"); + J3Method* target = cl->interfaceMethodAt(idx, 0); + J3MethodType* type = target->methodType(cl); + + uint32_t index = target->interfaceIndex(); + llvm::Value* thread = builder->CreateCall(funcJ3ThreadGet); + llvm::Value* gep[] = { builder->getInt32(0), builder->getInt32(J3Thread::gepInterfaceMethodIndex) }; + builder->CreateStore(builder->getInt32(index), builder->CreateGEP(thread, gep)); + + llvm::Value* obj = nullCheck(stack.top(type->nbIns() - 1)); + llvm::Value* gepFunc[] = { builder->getInt32(0), + builder->getInt32(J3VirtualTable::gepInterfaceMethods), + builder->getInt32(index % J3VirtualTable::nbInterfaceMethodTable) }; + llvm::Value* func = builder->CreateBitCast(builder->CreateLoad(builder->CreateGEP(vt(obj), gepFunc)), + type->llvmType()->getPointerTo()); + + invoke(target, func); } void J3CodeGen::invokeVirtual(uint32_t idx) { Modified: vmkit/branches/mcjit/lib/j3/vm/j3object.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3object.cc?rev=197924&r1=197923&r2=197924&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3object.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3object.cc Mon Dec 23 16:41:01 2013 @@ -65,14 +65,32 @@ J3VirtualTable* J3VirtualTable::create(J J3VirtualTable* res = new(cl->loader()->allocator(), n) J3VirtualTable(cl, cl->super(), (J3Type**)cl->interfaces(), cl->nbInterfaces(), J3Cst::isInterface(cl->access()) ? 1 : 0); - /* virtual table */ res->_nbVirtualMethods = n; if(super != cl) /* super->vt() is not yet allocated for Object */ memcpy(res->_virtualMethods, super->vt()->_virtualMethods, sizeof(void*)*super->vt()->nbVirtualMethods()); - // for(uint32_t i=0; i_interfaceMethodTable[i] = + struct { + uint32_t nbSlots; + J3Method** slots; + } slots[nbInterfaceMethodTable]; + + for(uint32_t i=0; ichecker.nbSecondaryTypes; i++) { + J3Class* cl = res->checker.secondaryTypes[i]->type()->asClass(); + if(J3Cst::isInterface(cl->access())) { + for(uint32_t j=0; jnbMethods(); j++) { + J3Method* m = cl->methods()[j]; + fprintf(stderr, "[%d] method: %ls::%ls\n", i, cl->name()->cStr(), m->name()->cStr()); + } + } + } + + void* interfaceTrampoline = cl->loader()->vm()->interfaceTrampoline; + for(uint32_t i=0; i_interfaceMethodTable[i] = interfaceTrampoline; for(uint32_t i=0; inbMethods(); i++) res->_virtualMethods[pm[i]->index()] = pm[i]->functionPointerOrVirtualTrampoline(); @@ -187,16 +205,16 @@ J3VirtualTable::J3VirtualTable(J3Type* t checker.display[checker.offset] = this; } - for(uint32_t i=0; ivt()->checker.secondaryTypes, + super->vt()->checker.nbSecondaryTypes*sizeof(J3VirtualTable*)); + + for(uint32_t i=0, n=isSecondary+super->vt()->checker.nbSecondaryTypes; iname()->cStr(), sec->name()->cStr(), isSecondary+i); sec->resolve(); - checker.secondaryTypes[isSecondary+i] = sec->vt(); + checker.secondaryTypes[n++] = sec->vt(); } - - memcpy(checker.secondaryTypes + nbInterfaces + isSecondary, - super->vt()->checker.secondaryTypes, - super->vt()->checker.nbSecondaryTypes*sizeof(J3VirtualTable*)); } //dump(); Modified: vmkit/branches/mcjit/lib/j3/vm/j3trampoline.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3trampoline.cc?rev=197924&r1=197923&r2=197924&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3trampoline.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3trampoline.cc Mon Dec 23 16:41:01 2013 @@ -7,6 +7,16 @@ using namespace j3; +void* J3Trampoline::interfaceTrampoline(J3Object* obj) { + J3ObjectHandle* prev = J3Thread::get()->tell(); + J3ObjectHandle* handle = J3Thread::get()->push(obj); + uint32_t index = J3Thread::get()->interfaceMethodIndex(); + fprintf(stderr, "%d - %ls\n", index, handle->vt()->type()->name()->cStr()); + + J3Thread::get()->restore(prev); + J3::internalError(L"implement me: interface Trampoline"); +} + void* J3Trampoline::staticTrampoline(J3Object* obj, J3Method* target) { return target->fnPtr(); } @@ -81,3 +91,7 @@ void* J3Trampoline::buildStaticTrampolin void* J3Trampoline::buildVirtualTrampoline(vmkit::BumpAllocator* allocator, J3Method* method) { return buildTrampoline(allocator, method, (void*)virtualTrampoline); } + +void* J3Trampoline::buildInterfaceTrampoline(vmkit::BumpAllocator* allocator) { + return buildTrampoline(allocator, 0, (void*)interfaceTrampoline); +} From gael.thomas at lip6.fr Tue Dec 24 00:56:29 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Tue, 24 Dec 2013 08:56:29 -0000 Subject: [vmkit-commits] [vmkit] r197968 - avoid duplicate entries in J3TypeChecker::secondaryTypes Message-ID: <20131224085629.ECCA72A6C029@llvm.org> Author: gthomas Date: Tue Dec 24 02:56:28 2013 New Revision: 197968 URL: http://llvm.org/viewvc/llvm-project?rev=197968&view=rev Log: avoid duplicate entries in J3TypeChecker::secondaryTypes Modified: vmkit/branches/mcjit/lib/j3/vm/j3object.cc Modified: vmkit/branches/mcjit/lib/j3/vm/j3object.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3object.cc?rev=197968&r1=197967&r2=197968&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3object.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3object.cc Tue Dec 24 02:56:28 2013 @@ -217,6 +217,12 @@ J3VirtualTable::J3VirtualTable(J3Type* t } } + if(checker.nbSecondaryTypes) { + std::sort(checker.secondaryTypes, &checker.secondaryTypes[checker.nbSecondaryTypes]); + J3VirtualTable** it = std::unique(checker.secondaryTypes, &checker.secondaryTypes[checker.nbSecondaryTypes]); + checker.nbSecondaryTypes = std::distance(checker.secondaryTypes, it); + } + //dump(); } From gael.thomas at lip6.fr Tue Dec 24 01:34:45 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Tue, 24 Dec 2013 09:34:45 -0000 Subject: [vmkit-commits] [vmkit] r197971 - better method lookup + create the vt of an object array Message-ID: <20131224093445.B56BD2A6C029@llvm.org> Author: gthomas Date: Tue Dec 24 03:34:44 2013 New Revision: 197971 URL: http://llvm.org/viewvc/llvm-project?rev=197971&view=rev Log: better method lookup + create the vt of an object array Modified: vmkit/branches/mcjit/include/j3/j3class.h vmkit/branches/mcjit/lib/j3/vm/j3class.cc vmkit/branches/mcjit/lib/j3/vm/j3object.cc Modified: vmkit/branches/mcjit/include/j3/j3class.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3class.h?rev=197971&r1=197970&r2=197971&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3class.h (original) +++ vmkit/branches/mcjit/include/j3/j3class.h Tue Dec 24 03:34:44 2013 @@ -153,6 +153,8 @@ namespace j3 { public: J3ObjectType(J3ClassLoader* loader, const vmkit::Name* name); + void prepareInterfaceTable(); + virtual J3Method* findVirtualMethod(const vmkit::Name* name, const vmkit::Name* sign, bool error=1); virtual J3Method* findStaticMethod(const vmkit::Name* name, const vmkit::Name* sign, bool error=1); Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=197971&r1=197970&r2=197971&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Tue Dec 24 03:34:44 2013 @@ -156,6 +156,32 @@ J3ObjectHandle* J3ObjectType::javaClass( return _javaClass; } +void J3ObjectType::prepareInterfaceTable() { +#if 0 + struct { + uint32_t nbSlots; + J3Method** slots; + } slots[nbInterfaceMethodTable]; + + for(uint32_t i=0; ichecker.nbSecondaryTypes; i++) { + J3Class* ifce = res->checker.secondaryTypes[i]->type()->asClass(); + fprintf(stderr, "processing: %ls from %ls\n", ifce->name()->cStr(), cl->name()->cStr()); + if(J3Cst::isInterface(ifce->access())) { + for(uint32_t j=0; jnbMethods(); j++) { + J3Method* base = ifce->methods()[j]; + fprintf(stderr, " %s lookup %ls %ls::%ls in %ls\n", + J3Cst::isAbstract(base->access()) ? "abstract" : "concrete", + base->sign()->cStr(), base->cl()->name()->cStr(), base->name()->cStr(), cl->name()->cStr()); + J3Method* method = cl->findVirtualMethod(base->name(), base->sign(), 1); + } + } + } +#endif +} + /* * ------------ J3Layout ------------ */ @@ -208,29 +234,44 @@ J3Method* J3Class::findVirtualMethod(con //loader()->vm()->log(L"Lookup: %ls %ls in %ls (%d)", methName->cStr(), methSign->cStr(), name()->cStr(), nbVirtualMethods); resolve(); - J3Method* res = findMethod(name, sign); + J3Class* cur = this; + J3Method* res; + while(1) { + res = cur->findMethod(name, sign); - if(!res) { - if(super() == this) { + if(res) + return res; + + if(cur == cur->super()) { if(error) J3::noSuchMethodError(L"no such method", this, name, sign); else return 0; } - res = super()->findVirtualMethod(name, sign, error); + cur = cur->super(); } - - return res; } J3Method* J3Class::findStaticMethod(const vmkit::Name* name, const vmkit::Name* sign, bool error) { //loader()->vm()->log(L"Lookup: %ls %ls in %ls", methName->cStr(), methSign->cStr(), name()->cStr()); resolve(); - J3Method* res = staticLayout.findMethod(name, sign); + J3Class* cur = this; + J3Method* res; + while(1) { + res = cur->staticLayout.findMethod(name, sign); - if(!res) - J3::internalError(L"implement me"); + if(res) + return res; + + if(cur == cur->super()) { + if(error) + J3::noSuchMethodError(L"no such method", this, name, sign); + else + return 0; + } + cur = cur->super(); + } return res; } @@ -372,6 +413,8 @@ void J3Class::doResolve(J3Field* hiddenF _vt = J3VirtualTable::create(this); + prepareInterfaceTable(); + //fprintf(stderr, "virtual part of %ls: ", name()->cStr()); //llvmType()->getContainedType(0)->dump(); //fprintf(stderr, "\n"); @@ -379,17 +422,6 @@ void J3Class::doResolve(J3Field* hiddenF unlock(); } -#if 0 -void J3Class::addHiddenField(J3Field* f, uint32_t num) { - if(this == loader()->vm()->classClass) { - f->_access = J3Cst::ACC_PRIVATE; - f->_name = loader()->vm()->names()->get(L"vmData"); - f->_type = (sizeof(uintptr_t) == 8) ? loader()->vm()->typeLong : loader()->vm()->typeInteger; - f->_attributes = new (loader()->allocator(), 0) J3Attributes(0); - } -} -#endif - void J3Class::readClassBytes(std::vector* virtualBody, J3Field* hiddenFields, uint32_t nbHiddenFields) { J3Reader reader(_bytes); @@ -833,6 +865,7 @@ void J3ArrayClass::doResolve(J3Field* hi J3Class* objectClass = loader()->vm()->objectClass; objectClass->resolve(); _vt = J3VirtualTable::create(this); + prepareInterfaceTable(); } unlock(); } Modified: vmkit/branches/mcjit/lib/j3/vm/j3object.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3object.cc?rev=197971&r1=197970&r2=197971&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3object.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3object.cc Tue Dec 24 03:34:44 2013 @@ -62,38 +62,26 @@ J3VirtualTable* J3VirtualTable::create(J } } + /* virtual table */ + uint32_t isConcrete = !J3Cst::isInterface(cl->access()) && ! J3Cst::isAbstract(cl->access()); + + n = isConcrete ? n : 0; + J3VirtualTable* res = new(cl->loader()->allocator(), n) J3VirtualTable(cl, cl->super(), (J3Type**)cl->interfaces(), cl->nbInterfaces(), J3Cst::isInterface(cl->access()) ? 1 : 0); - - /* virtual table */ res->_nbVirtualMethods = n; - if(super != cl) /* super->vt() is not yet allocated for Object */ - memcpy(res->_virtualMethods, super->vt()->_virtualMethods, sizeof(void*)*super->vt()->nbVirtualMethods()); - struct { - uint32_t nbSlots; - J3Method** slots; - } slots[nbInterfaceMethodTable]; - - for(uint32_t i=0; ichecker.nbSecondaryTypes; i++) { - J3Class* cl = res->checker.secondaryTypes[i]->type()->asClass(); - if(J3Cst::isInterface(cl->access())) { - for(uint32_t j=0; jnbMethods(); j++) { - J3Method* m = cl->methods()[j]; - fprintf(stderr, "[%d] method: %ls::%ls\n", i, cl->name()->cStr(), m->name()->cStr()); - } - } - } - - void* interfaceTrampoline = cl->loader()->vm()->interfaceTrampoline; - for(uint32_t i=0; i_interfaceMethodTable[i] = interfaceTrampoline; + if(isConcrete) { + if(super != cl) /* super->vt() is not yet allocated for Object */ + memcpy(res->_virtualMethods, super->vt()->_virtualMethods, sizeof(void*)*super->vt()->nbVirtualMethods()); + + void* interfaceTrampoline = cl->loader()->vm()->interfaceTrampoline; + for(uint32_t i=0; i_interfaceMethodTable[i] = interfaceTrampoline; - for(uint32_t i=0; inbMethods(); i++) - res->_virtualMethods[pm[i]->index()] = pm[i]->functionPointerOrVirtualTrampoline(); + for(uint32_t i=0; inbMethods(); i++) + res->_virtualMethods[pm[i]->index()] = pm[i]->functionPointerOrVirtualTrampoline(); + } return res; } @@ -159,8 +147,10 @@ J3VirtualTable* J3VirtualTable::create(J super->resolve(); - J3VirtualTable* res = new(cl->loader()->allocator(), 0) J3VirtualTable(cl, super, secondaries, nbSecondaries, isSecondary); - //memcpy(_virtualMethods, objClass->vt()->virtualMethods(), sizeof(void*)*objClass->nbVt()); + J3VirtualTable* res = new(cl->loader()->allocator(), objClass->vt()->_nbVirtualMethods) + J3VirtualTable(cl, super, secondaries, nbSecondaries, isSecondary); + + memcpy(res->_virtualMethods, objClass->vt()->_virtualMethods, sizeof(void*)*objClass->vt()->_nbVirtualMethods); return res; } From gael.thomas at lip6.fr Tue Dec 24 02:01:52 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Tue, 24 Dec 2013 10:01:52 -0000 Subject: [vmkit-commits] [vmkit] r197973 - define a vt even for abstract classes Message-ID: <20131224100152.5CD9B2A6C029@llvm.org> Author: gthomas Date: Tue Dec 24 04:01:52 2013 New Revision: 197973 URL: http://llvm.org/viewvc/llvm-project?rev=197973&view=rev Log: define a vt even for abstract classes Modified: vmkit/branches/mcjit/include/j3/j3object.h vmkit/branches/mcjit/lib/j3/vm/j3class.cc vmkit/branches/mcjit/lib/j3/vm/j3object.cc Modified: vmkit/branches/mcjit/include/j3/j3object.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3object.h?rev=197973&r1=197972&r2=197973&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3object.h (original) +++ vmkit/branches/mcjit/include/j3/j3object.h Tue Dec 24 04:01:52 2013 @@ -47,7 +47,7 @@ namespace j3 { private: J3Type* _type; - J3TypeChecker checker; + J3TypeChecker _checker; // see: Bowen Alpern, Anthony Cocchi, Stephen Fink, and David Grove. 2001. // Efficient implementation of Java interfaces: Invokeinterface considered harmless. OOPSLA 2001. void* _interfaceMethodTable[nbInterfaceMethodTable]; @@ -62,8 +62,10 @@ namespace j3 { static J3VirtualTable* create(J3ArrayClass* cl); static J3VirtualTable* create(J3Primitive* prim); - uint32_t offset() { return checker.offset; } - bool isPrimaryChecker() { return checker.offset < J3TypeChecker::cacheOffset; } + J3TypeChecker* checker() { return &_checker; } + + uint32_t offset() { return _checker.offset; } + bool isPrimaryChecker() { return _checker.offset < J3TypeChecker::cacheOffset; } bool slowIsAssignableTo(J3VirtualTable* parent); bool fastIsAssignableToPrimaryChecker(J3VirtualTable* parent, uint32_t parentOffset); Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=197973&r1=197972&r2=197973&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Tue Dec 24 04:01:52 2013 @@ -158,28 +158,28 @@ J3ObjectHandle* J3ObjectType::javaClass( void J3ObjectType::prepareInterfaceTable() { #if 0 - struct { - uint32_t nbSlots; - J3Method** slots; - } slots[nbInterfaceMethodTable]; - for(uint32_t i=0; ichecker.nbSecondaryTypes; i++) { - J3Class* ifce = res->checker.secondaryTypes[i]->type()->asClass(); - fprintf(stderr, "processing: %ls from %ls\n", ifce->name()->cStr(), cl->name()->cStr()); - if(J3Cst::isInterface(ifce->access())) { - for(uint32_t j=0; jnbMethods(); j++) { - J3Method* base = ifce->methods()[j]; - fprintf(stderr, " %s lookup %ls %ls::%ls in %ls\n", - J3Cst::isAbstract(base->access()) ? "abstract" : "concrete", - base->sign()->cStr(), base->cl()->name()->cStr(), base->name()->cStr(), cl->name()->cStr()); - J3Method* method = cl->findVirtualMethod(base->name(), base->sign(), 1); + for(uint32_t i=0; ichecker()->nbSecondaryTypes; i++) { + J3Type* type = vt()->checker()->secondaryTypes[i]->type(); + // fprintf(stderr, " %p %ls type is %p - %p\n", vt(), name()->cStr(), vt()->checker()->secondaryTypes[i], type); + + if(type->isClass()) { + J3Class* ifce = vt()->checker()->secondaryTypes[i]->type()->asClass(); + // fprintf(stderr, "processing: %ls from %ls\n", ifce->name()->cStr(), name()->cStr()); + if(J3Cst::isInterface(ifce->access())) { + for(uint32_t j=0; jnbMethods(); j++) { + J3Method* base = ifce->methods()[j]; + // fprintf(stderr, " %s lookup %ls %ls::%ls in %ls\n", + // J3Cst::isAbstract(base->access()) ? "abstract" : "concrete", + // base->sign()->cStr(), base->cl()->name()->cStr(), base->name()->cStr(), name()->cStr()); + J3Method* method = findVirtualMethod(base->name(), base->sign(), J3Cst::isAbstract(base->access())); + } } } } -#endif } /* @@ -413,7 +413,8 @@ void J3Class::doResolve(J3Field* hiddenF _vt = J3VirtualTable::create(this); - prepareInterfaceTable(); + if(!J3Cst::isInterface(access()) && !J3Cst::isAbstract(access())) + prepareInterfaceTable(); //fprintf(stderr, "virtual part of %ls: ", name()->cStr()); //llvmType()->getContainedType(0)->dump(); Modified: vmkit/branches/mcjit/lib/j3/vm/j3object.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3object.cc?rev=197973&r1=197972&r2=197973&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3object.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3object.cc Tue Dec 24 04:01:52 2013 @@ -63,7 +63,7 @@ J3VirtualTable* J3VirtualTable::create(J } /* virtual table */ - uint32_t isConcrete = !J3Cst::isInterface(cl->access()) && ! J3Cst::isAbstract(cl->access()); + uint32_t isConcrete = !J3Cst::isInterface(cl->access()); n = isConcrete ? n : 0; @@ -79,8 +79,9 @@ J3VirtualTable* J3VirtualTable::create(J for(uint32_t i=0; i_interfaceMethodTable[i] = interfaceTrampoline; - for(uint32_t i=0; inbMethods(); i++) + for(uint32_t i=0; inbMethods(); i++) { res->_virtualMethods[pm[i]->index()] = pm[i]->functionPointerOrVirtualTrampoline(); + } } return res; @@ -133,11 +134,11 @@ J3VirtualTable* J3VirtualTable::create(J super->resolve(); //printf("%ls super is %ls (%d)\n", cl->name()->cStr(), super->name()->cStr(), isSecondary); - uint32_t n = baseClass->vt()->checker.nbSecondaryTypes; + uint32_t n = baseClass->vt()->checker()->nbSecondaryTypes; secondaries = (J3Type**)alloca(n*sizeof(J3Type*)); for(uint32_t i=0; ivt()->checker.secondaryTypes[i]->type(); + secondaries[nbSecondaries] = baseClass->vt()->checker()->secondaryTypes[i]->type(); if(secondaries[i] != baseClass) { /* don't add myself */ secondaries[nbSecondaries] = secondaries[nbSecondaries]->getArray(dim); nbSecondaries++; @@ -166,71 +167,70 @@ void* J3VirtualTable::operator new(size_ J3VirtualTable::J3VirtualTable(J3Type* type, J3Type* super, J3Type** interfaces, uint32_t nbInterfaces, bool isSecondary) { _type = type; - //printf("*** Building the vt of %ls based on %ls\n", type->name()->cStr(), super->name()->cStr()); + // printf("*** Building the vt of %ls based on %ls at %p\n", type->name()->cStr(), super->name()->cStr(), this); if(super == type) { - checker.offset = 0; - checker.display[checker.offset] = this; + checker()->offset = 0; + checker()->display[checker()->offset] = this; if(nbInterfaces) J3::internalError(L"a root J3VirtualTable should not have interfaces"); } else { - uint32_t parentDisplayLength = super->vt()->checker.offset + 1; + uint32_t parentDisplayLength = super->vt()->checker()->offset + 1; - //printf("%ls (%p) secondary: %p %p (%d)\n", type->name()->cStr(), this, checker.secondaryTypes, checker.display[6], parentDisplayLength); + //printf("%ls (%p) secondary: %p %p (%d)\n", type->name()->cStr(), this, checker()->secondaryTypes, checker()->display[6], parentDisplayLength); if(parentDisplayLength >= J3TypeChecker::cacheOffset) isSecondary = 1; - memcpy(checker.display, super->vt()->checker.display, parentDisplayLength*sizeof(J3VirtualTable*)); + memcpy(checker()->display, super->vt()->checker()->display, parentDisplayLength*sizeof(J3VirtualTable*)); - checker.nbSecondaryTypes = super->vt()->checker.nbSecondaryTypes + nbInterfaces + isSecondary; - checker.secondaryTypes = (J3VirtualTable**)super->loader()->allocator()->allocate(checker.nbSecondaryTypes*sizeof(J3VirtualTable*)); + checker()->nbSecondaryTypes = super->vt()->checker()->nbSecondaryTypes + nbInterfaces + isSecondary; + checker()->secondaryTypes = (J3VirtualTable**)super->loader()->allocator()->allocate(checker()->nbSecondaryTypes*sizeof(J3VirtualTable*)); //printf("%ls: %d - %d %d\n", type->name()->cStr(), isSecondary, parentDisplayLength, J3TypeChecker::displayLength); if(isSecondary) { - checker.offset = J3TypeChecker::cacheOffset; - checker.secondaryTypes[0] = this; + checker()->offset = J3TypeChecker::cacheOffset; + checker()->secondaryTypes[0] = this; } else { - checker.offset = parentDisplayLength; - checker.display[checker.offset] = this; + checker()->offset = parentDisplayLength; + checker()->display[checker()->offset] = this; } - memcpy(checker.secondaryTypes + isSecondary, - super->vt()->checker.secondaryTypes, - super->vt()->checker.nbSecondaryTypes*sizeof(J3VirtualTable*)); + memcpy(checker()->secondaryTypes + isSecondary, + super->vt()->checker()->secondaryTypes, + super->vt()->checker()->nbSecondaryTypes*sizeof(J3VirtualTable*)); - for(uint32_t i=0, n=isSecondary+super->vt()->checker.nbSecondaryTypes; ivt()->checker()->nbSecondaryTypes; iname()->cStr(), sec->name()->cStr(), isSecondary+i); sec->resolve(); - checker.secondaryTypes[n++] = sec->vt(); + checker()->secondaryTypes[n++] = sec->vt(); } } - if(checker.nbSecondaryTypes) { - std::sort(checker.secondaryTypes, &checker.secondaryTypes[checker.nbSecondaryTypes]); - J3VirtualTable** it = std::unique(checker.secondaryTypes, &checker.secondaryTypes[checker.nbSecondaryTypes]); - checker.nbSecondaryTypes = std::distance(checker.secondaryTypes, it); + if(checker()->nbSecondaryTypes) { + std::sort(checker()->secondaryTypes, &checker()->secondaryTypes[checker()->nbSecondaryTypes]); + J3VirtualTable** it = std::unique(checker()->secondaryTypes, &checker()->secondaryTypes[checker()->nbSecondaryTypes]); + checker()->nbSecondaryTypes = std::distance(checker()->secondaryTypes, it); } //dump(); } bool J3VirtualTable::slowIsAssignableTo(J3VirtualTable* parent) { - for(uint32_t i=0; inbSecondaryTypes; i++) + if(checker()->secondaryTypes[i] == parent) { + checker()->display[J3TypeChecker::cacheOffset] = parent; return true; } return false; } bool J3VirtualTable::fastIsAssignableToPrimaryChecker(J3VirtualTable* parent, uint32_t parentOffset) { - return checker.display[parentOffset] == parent; + return checker()->display[parentOffset] == parent; } bool J3VirtualTable::fastIsAssignableToNonPrimaryChecker(J3VirtualTable* parent) { - if(checker.display[J3TypeChecker::cacheOffset] == parent) + if(checker()->display[J3TypeChecker::cacheOffset] == parent) return true; else if(parent == this) return true; @@ -239,8 +239,8 @@ bool J3VirtualTable::fastIsAssignableToN } bool J3VirtualTable::isAssignableTo(J3VirtualTable* parent) { - uint32_t parentOffset = parent->checker.offset; - if(checker.display[parentOffset] == parent) + uint32_t parentOffset = parent->checker()->offset; + if(checker()->display[parentOffset] == parent) return true; else if(parentOffset != J3TypeChecker::cacheOffset) return false; @@ -254,7 +254,7 @@ void J3VirtualTable::dump() { fprintf(stderr, "VirtualTable: %s%ls (%p)\n", type()->isLayout() && !type()->isClass() ? "static_" : "", type()->name()->cStr(), this); - checker.dump(); + checker()->dump(); } From gael.thomas at lip6.fr Tue Dec 24 02:56:05 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Tue, 24 Dec 2013 10:56:05 -0000 Subject: [vmkit-commits] [vmkit] r197974 - build the interface method descriptor Message-ID: <20131224105605.291D22A6C029@llvm.org> Author: gthomas Date: Tue Dec 24 04:56:04 2013 New Revision: 197974 URL: http://llvm.org/viewvc/llvm-project?rev=197974&view=rev Log: build the interface method descriptor Modified: vmkit/branches/mcjit/include/j3/j3class.h vmkit/branches/mcjit/lib/j3/vm/j3class.cc vmkit/branches/mcjit/lib/j3/vm/j3object.cc Modified: vmkit/branches/mcjit/include/j3/j3class.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3class.h?rev=197974&r1=197973&r2=197974&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3class.h (original) +++ vmkit/branches/mcjit/include/j3/j3class.h Tue Dec 24 04:56:04 2013 @@ -7,6 +7,8 @@ #include "vmkit/compiler.h" +#include "j3/j3object.h" + namespace llvm { class Type; class GlobalValue; @@ -27,8 +29,6 @@ namespace j3 { class J3ArrayClass; class J3ObjectType; class J3Method; - class J3VirtualTable; - class J3ObjectHandle; class J3Field; class J3Type : public vmkit::Symbol { @@ -147,8 +147,15 @@ namespace j3 { void dump(); }; + class J3InterfaceSlotDescriptor { + public: + uint32_t nbMethods; + J3Method** methods; + }; + class J3ObjectType : public J3Type { - J3ObjectHandle* _javaClass; + J3ObjectHandle* _javaClass; + J3InterfaceSlotDescriptor _interfaceSlotDescriptors[J3VirtualTable::nbInterfaceMethodTable]; public: J3ObjectType(J3ClassLoader* loader, const vmkit::Name* name); @@ -163,6 +170,8 @@ namespace j3 { J3ObjectHandle* javaClass(); static J3ObjectType* nativeClass(J3ObjectHandle* handle); + + void dumpInterfaceSlotDescriptors(); }; class J3Layout : public J3ObjectType { Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=197974&r1=197973&r2=197974&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Tue Dec 24 04:56:04 2013 @@ -157,29 +157,65 @@ J3ObjectHandle* J3ObjectType::javaClass( } void J3ObjectType::prepareInterfaceTable() { -#if 0 - for(uint32_t i=0; icStr()); + + uint32_t total = 0; + J3InterfaceSlotDescriptor* slots = _interfaceSlotDescriptors; for(uint32_t i=0; ichecker()->nbSecondaryTypes; i++) { J3Type* type = vt()->checker()->secondaryTypes[i]->type(); - // fprintf(stderr, " %p %ls type is %p - %p\n", vt(), name()->cStr(), vt()->checker()->secondaryTypes[i], type); if(type->isClass()) { J3Class* ifce = vt()->checker()->secondaryTypes[i]->type()->asClass(); - // fprintf(stderr, "processing: %ls from %ls\n", ifce->name()->cStr(), name()->cStr()); if(J3Cst::isInterface(ifce->access())) { + //fprintf(stderr, " processing interface: %ls\n", ifce->name()->cStr()); for(uint32_t j=0; jnbMethods(); j++) { J3Method* base = ifce->methods()[j]; - // fprintf(stderr, " %s lookup %ls %ls::%ls in %ls\n", - // J3Cst::isAbstract(base->access()) ? "abstract" : "concrete", - // base->sign()->cStr(), base->cl()->name()->cStr(), base->name()->cStr(), name()->cStr()); + //fprintf(stderr, " processing %s method %ls %ls\n", + //J3Cst::isAbstract(base->access()) ? "abstract" : "concrete", + //base->sign()->cStr(), base->name()->cStr()); J3Method* method = findVirtualMethod(base->name(), base->sign(), J3Cst::isAbstract(base->access())); + + if(!method) + method = base; + + total++; + uint32_t index = base->interfaceIndex() % J3VirtualTable::nbInterfaceMethodTable; + J3Method** tmp = (J3Method**)alloca(sizeof(J3Method*)*(slots[index].nbMethods+1)); + memcpy(tmp, slots[index].methods, sizeof(J3Method*)*slots[index].nbMethods); + tmp[slots[index].nbMethods] = method; + slots[index].methods = tmp; + slots[index].nbMethods++; } } } } + + J3Method** methods = (J3Method**)loader()->allocator()->allocate(total*sizeof(J3Method*)); + uint32_t cur = 0; + + for(uint32_t i=0; icStr()); + for(uint32_t i=0; icl()->name()->cStr(), + slots[i].methods[j]->name()->cStr(), + slots[i].methods[j]->sign()->cStr()); + } + } } /* Modified: vmkit/branches/mcjit/lib/j3/vm/j3object.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3object.cc?rev=197974&r1=197973&r2=197974&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3object.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3object.cc Tue Dec 24 04:56:04 2013 @@ -75,9 +75,11 @@ J3VirtualTable* J3VirtualTable::create(J if(super != cl) /* super->vt() is not yet allocated for Object */ memcpy(res->_virtualMethods, super->vt()->_virtualMethods, sizeof(void*)*super->vt()->nbVirtualMethods()); - void* interfaceTrampoline = cl->loader()->vm()->interfaceTrampoline; - for(uint32_t i=0; i_interfaceMethodTable[i] = interfaceTrampoline; + if(!J3Cst::isAbstract(cl->access())) { + void* interfaceTrampoline = cl->loader()->vm()->interfaceTrampoline; + for(uint32_t i=0; i_interfaceMethodTable[i] = interfaceTrampoline; + } for(uint32_t i=0; inbMethods(); i++) { res->_virtualMethods[pm[i]->index()] = pm[i]->functionPointerOrVirtualTrampoline(); From gael.thomas at lip6.fr Tue Dec 24 03:03:27 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Tue, 24 Dec 2013 11:03:27 -0000 Subject: [vmkit-commits] [vmkit] r197975 - Interface method dispatch table is ok, but type is not checked and do not yet handle collision. Message-ID: <20131224110327.B26102A6C029@llvm.org> Author: gthomas Date: Tue Dec 24 05:03:27 2013 New Revision: 197975 URL: http://llvm.org/viewvc/llvm-project?rev=197975&view=rev Log: Interface method dispatch table is ok, but type is not checked and do not yet handle collision. Modified: vmkit/branches/mcjit/include/j3/j3class.h vmkit/branches/mcjit/include/j3/j3object.h vmkit/branches/mcjit/lib/j3/vm/j3class.cc vmkit/branches/mcjit/lib/j3/vm/j3trampoline.cc Modified: vmkit/branches/mcjit/include/j3/j3class.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3class.h?rev=197975&r1=197974&r2=197975&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3class.h (original) +++ vmkit/branches/mcjit/include/j3/j3class.h Tue Dec 24 05:03:27 2013 @@ -160,18 +160,19 @@ namespace j3 { public: J3ObjectType(J3ClassLoader* loader, const vmkit::Name* name); - void prepareInterfaceTable(); + J3InterfaceSlotDescriptor* slotDescriptorAt(uint32_t index) { return &_interfaceSlotDescriptors[index]; } + void prepareInterfaceTable(); - virtual J3Method* findVirtualMethod(const vmkit::Name* name, const vmkit::Name* sign, bool error=1); - virtual J3Method* findStaticMethod(const vmkit::Name* name, const vmkit::Name* sign, bool error=1); + virtual J3Method* findVirtualMethod(const vmkit::Name* name, const vmkit::Name* sign, bool error=1); + virtual J3Method* findStaticMethod(const vmkit::Name* name, const vmkit::Name* sign, bool error=1); - bool isObjectType() { return 1; } + bool isObjectType() { return 1; } - J3ObjectHandle* javaClass(); + J3ObjectHandle* javaClass(); - static J3ObjectType* nativeClass(J3ObjectHandle* handle); + static J3ObjectType* nativeClass(J3ObjectHandle* handle); - void dumpInterfaceSlotDescriptors(); + void dumpInterfaceSlotDescriptors(); }; class J3Layout : public J3ObjectType { Modified: vmkit/branches/mcjit/include/j3/j3object.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3object.h?rev=197975&r1=197974&r2=197975&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3object.h (original) +++ vmkit/branches/mcjit/include/j3/j3object.h Tue Dec 24 05:03:27 2013 @@ -39,6 +39,8 @@ namespace j3 { }; class J3VirtualTable { + friend class J3Trampoline; + public: static const uint32_t nbInterfaceMethodTable = 23; static const uint32_t gepObjectClass = 0; Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=197975&r1=197974&r2=197975&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Tue Dec 24 05:03:27 2013 @@ -200,7 +200,7 @@ void J3ObjectType::prepareInterfaceTable cur += slots[i].nbMethods; } - dumpInterfaceSlotDescriptors(); + //dumpInterfaceSlotDescriptors(); } void J3ObjectType::dumpInterfaceSlotDescriptors() { Modified: vmkit/branches/mcjit/lib/j3/vm/j3trampoline.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3trampoline.cc?rev=197975&r1=197974&r2=197975&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3trampoline.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3trampoline.cc Tue Dec 24 05:03:27 2013 @@ -10,11 +10,20 @@ using namespace j3; void* J3Trampoline::interfaceTrampoline(J3Object* obj) { J3ObjectHandle* prev = J3Thread::get()->tell(); J3ObjectHandle* handle = J3Thread::get()->push(obj); - uint32_t index = J3Thread::get()->interfaceMethodIndex(); - fprintf(stderr, "%d - %ls\n", index, handle->vt()->type()->name()->cStr()); + J3ObjectType* type = obj->vt()->type()->asObjectType(); + uint32_t index = J3Thread::get()->interfaceMethodIndex() % J3VirtualTable::nbInterfaceMethodTable; + J3InterfaceSlotDescriptor* desc = type->slotDescriptorAt(index); + void* res; + + if(desc->nbMethods == 1) { + res = desc->methods[0]->fnPtr(); + handle->vt()->_interfaceMethodTable[index] = res; + } else + J3::internalError(L"implement me: interface Trampoline with collision"); J3Thread::get()->restore(prev); - J3::internalError(L"implement me: interface Trampoline"); + + return res; } void* J3Trampoline::staticTrampoline(J3Object* obj, J3Method* target) { From gael.thomas at lip6.fr Tue Dec 24 03:07:18 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Tue, 24 Dec 2013 11:07:18 -0000 Subject: [vmkit-commits] [vmkit] r197976 - implement dup_x1 Message-ID: <20131224110718.4DB142A6C029@llvm.org> Author: gthomas Date: Tue Dec 24 05:07:18 2013 New Revision: 197976 URL: http://llvm.org/viewvc/llvm-project?rev=197976&view=rev Log: implement dup_x1 Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc vmkit/branches/mcjit/lib/j3/vm/j3options.cc Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=197976&r1=197975&r2=197976&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Tue Dec 24 05:07:18 2013 @@ -997,7 +997,11 @@ void J3CodeGen::translate() { stack.push(stack.top()); break; - case J3Cst::BC_dup_x1: nyi(); /* 0x5a */ + case J3Cst::BC_dup_x1: /* 0x5a */ + val1 = stack.pop(); val2 = stack.pop(); + stack.push(val1); stack.push(val2); stack.push(val1); + break; + case J3Cst::BC_dup_x2: nyi(); /* 0x5b */ case J3Cst::BC_dup2: nyi(); /* 0x5c */ case J3Cst::BC_dup2_x1: nyi(); /* 0x5d */ Modified: vmkit/branches/mcjit/lib/j3/vm/j3options.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3options.cc?rev=197976&r1=197975&r2=197976&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3options.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3options.cc Tue Dec 24 05:07:18 2013 @@ -19,7 +19,7 @@ J3Options::J3Options() { debugLoad = 0; debugResolve = 0; debugIniting = 0; - debugTranslate = 0; + debugTranslate = 2; debugLinking = 0; genDebugExecute = debugExecute ? 1 : 0; From gael.thomas at lip6.fr Tue Dec 24 07:12:13 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Tue, 24 Dec 2013 15:12:13 -0000 Subject: [vmkit-commits] [vmkit] r197983 - Fix a bug in checkcast/instanceof: use isAssignableTo instead of slowIsAssignableTo Message-ID: <20131224151213.F2C682A6C029@llvm.org> Author: gthomas Date: Tue Dec 24 09:12:13 2013 New Revision: 197983 URL: http://llvm.org/viewvc/llvm-project?rev=197983&view=rev Log: Fix a bug in checkcast/instanceof: use isAssignableTo instead of slowIsAssignableTo Fix a bug in vt(J3Type): force the resolution of the class for checkcast/instanceof Modified: vmkit/branches/mcjit/include/j3/j3.h vmkit/branches/mcjit/include/j3/j3class.h vmkit/branches/mcjit/include/j3/j3codegen.h vmkit/branches/mcjit/include/j3/j3object.h vmkit/branches/mcjit/lib/j3/vm/j3.cc vmkit/branches/mcjit/lib/j3/vm/j3class.cc vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc vmkit/branches/mcjit/lib/j3/vm/j3options.cc Modified: vmkit/branches/mcjit/include/j3/j3.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3.h?rev=197983&r1=197982&r2=197983&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3.h (original) +++ vmkit/branches/mcjit/include/j3/j3.h Tue Dec 24 09:12:13 2013 @@ -110,6 +110,8 @@ namespace j3 { static void classCastException() __attribute__((noreturn)); static void arrayBoundCheckException() __attribute__((noreturn)); + + static void printStackTrace(); }; } Modified: vmkit/branches/mcjit/include/j3/j3class.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3class.h?rev=197983&r1=197982&r2=197983&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3class.h (original) +++ vmkit/branches/mcjit/include/j3/j3class.h Tue Dec 24 09:12:13 2013 @@ -65,6 +65,7 @@ namespace j3 { J3Type* initialise(); J3VirtualTable* vt(); + J3VirtualTable* vtAndResolve(); bool isAssignableTo(J3Type* parent); Modified: vmkit/branches/mcjit/include/j3/j3codegen.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3codegen.h?rev=197983&r1=197982&r2=197983&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3codegen.h (original) +++ vmkit/branches/mcjit/include/j3/j3codegen.h Tue Dec 24 09:12:13 2013 @@ -114,7 +114,7 @@ namespace j3 { llvm::Value* handleToObject(llvm::Value* obj); llvm::Value* javaClass(J3ObjectType* type); llvm::Value* staticInstance(J3Class* cl); - llvm::Value* vt(J3Type* cl); + llvm::Value* vt(J3Type* cl, bool resolve=0); llvm::Value* vt(llvm::Value* obj); void initialiseJ3Type(J3Type* cl); @@ -170,6 +170,7 @@ namespace j3 { llvm::Function* funcJ3MethodIndex; llvm::Function* funcJ3TypeVT; + llvm::Function* funcJ3TypeVTAndResolve; llvm::Function* funcJ3TypeInitialise; llvm::Function* funcJ3ObjectTypeJavaClass; llvm::Function* funcJ3ClassSize; @@ -180,7 +181,7 @@ namespace j3 { llvm::Function* funcClassCastException; llvm::Function* funcNullPointerException; llvm::Function* funcThrowException; - llvm::Function* funcSlowIsAssignableTo; + llvm::Function* funcIsAssignableTo; llvm::Function* funcFastIsAssignableToPrimaryChecker; llvm::Function* funcFastIsAssignableToNonPrimaryChecker; llvm::Function* funcJ3ThreadPushHandle; Modified: vmkit/branches/mcjit/include/j3/j3object.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3object.h?rev=197983&r1=197982&r2=197983&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3object.h (original) +++ vmkit/branches/mcjit/include/j3/j3object.h Tue Dec 24 09:12:13 2013 @@ -42,7 +42,7 @@ namespace j3 { friend class J3Trampoline; public: - static const uint32_t nbInterfaceMethodTable = 23; + static const uint32_t nbInterfaceMethodTable = 41; static const uint32_t gepObjectClass = 0; static const uint32_t gepInterfaceMethods = 2; static const uint32_t gepVirtualMethods = 4; Modified: vmkit/branches/mcjit/lib/j3/vm/j3.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3.cc?rev=197983&r1=197982&r2=197983&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3.cc Tue Dec 24 09:12:13 2013 @@ -174,16 +174,18 @@ void J3::linkageError(J3Method* method) } void J3::vinternalError(const wchar_t* msg, va_list va) { - vmkit::Safepoint* sf = 0; - vmkit::StackWalker walker; wchar_t buf[65536]; - vswprintf(buf, 65536, msg, va); - fprintf(stderr, "Internal error: %ls\n", buf); + printStackTrace(); + abort(); +} + +void J3::printStackTrace() { + vmkit::StackWalker walker; while(walker.next()) { - vmkit::Safepoint* sf = getSafepoint(walker.ip()); + vmkit::Safepoint* sf = J3Thread::get()->vm()->getSafepoint(walker.ip()); if(sf) { J3Method* m = ((J3MethodCode*)sf->unit()->getSymbol(sf->functionName()))->self; @@ -202,5 +204,5 @@ void J3::vinternalError(const wchar_t* m } } } - abort(); } + Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=197983&r1=197982&r2=197983&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Tue Dec 24 09:12:13 2013 @@ -38,6 +38,11 @@ J3VirtualTable* J3Type::vt() { return _vt; } +J3VirtualTable* J3Type::vtAndResolve() { + resolve(); + return vt(); +} + void J3Type::dump() { fprintf(stderr, "Type: %ls", name()->cStr()); } Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=197983&r1=197982&r2=197983&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Tue Dec 24 09:12:13 2013 @@ -59,6 +59,7 @@ J3CodeGen::J3CodeGen(vmkit::BumpAllocato funcJ3MethodIndex = vm->introspectFunction(module(), "j3::J3Method::index()"); funcJ3TypeVT = vm->introspectFunction(module(), "j3::J3Type::vt()"); + funcJ3TypeVTAndResolve = vm->introspectFunction(module(), "j3::J3Type::vtAndResolve()"); funcJ3TypeInitialise = vm->introspectFunction(module(), "j3::J3Type::initialise()"); funcJ3ClassSize = vm->introspectFunction(module(), "j3::J3Class::size()"); funcJ3ClassStaticInstance = vm->introspectFunction(module(), "j3::J3Class::staticInstance()"); @@ -79,7 +80,7 @@ J3CodeGen::J3CodeGen(vmkit::BumpAllocato funcEchoDebugEnter = vm->introspectFunction(module(), "j3::J3CodeGen::echoDebugEnter(unsigned int, char const*, ...)"); funcEchoDebugExecute = vm->introspectFunction(module(), "j3::J3CodeGen::echoDebugExecute(unsigned int, char const*, ...)"); - funcSlowIsAssignableTo = vm->introspectFunction(module(), "j3::J3VirtualTable::slowIsAssignableTo(j3::J3VirtualTable*)"); + funcIsAssignableTo = vm->introspectFunction(module(), "j3::J3VirtualTable::isAssignableTo(j3::J3VirtualTable*)"); funcFastIsAssignableToPrimaryChecker = vm->introspectFunction(module(), "j3::J3VirtualTable::fastIsAssignableToPrimaryChecker(j3::J3VirtualTable*, unsigned int)"); funcFastIsAssignableToNonPrimaryChecker = @@ -212,8 +213,9 @@ llvm::Value* J3CodeGen::vt(llvm::Value* return res; } -llvm::Value* J3CodeGen::vt(J3Type* type) { - return builder->CreateCall(funcJ3TypeVT, builder->CreateBitCast(type->llvmDescriptor(module()), vm->typeJ3TypePtr)); +llvm::Value* J3CodeGen::vt(J3Type* type, bool doResolve) { + llvm::Value* func = doResolve && !type->isResolved() ? funcJ3TypeVTAndResolve : funcJ3TypeVT; + return builder->CreateCall(func, builder->CreateBitCast(type->llvmDescriptor(module()), vm->typeJ3TypePtr)); } llvm::Value* J3CodeGen::nullCheck(llvm::Value* obj) { @@ -381,6 +383,22 @@ llvm::Value* J3CodeGen::arrayLength(llvm return builder->CreateLoad(arrayLengthPtr(obj)); } +void J3CodeGen::newArray(J3ArrayClass* array) { + initialiseJ3Type(array); + llvm::DataLayout* layout = vm->dataLayout(); + llvm::Value* length = stack.pop(); + llvm::Value* nbb = + builder->CreateAdd(builder->getInt64(layout->getTypeAllocSize(array->llvmType()->getContainedType(0))), + builder->CreateMul(builder->getInt64(layout->getTypeAllocSize(array->component()->llvmType())), + builder->CreateZExtOrBitCast(length, builder->getInt64Ty()))); + + llvm::Value* res = builder->CreateCall2(funcJ3ObjectAllocate, vt(array), nbb); + + builder->CreateStore(length, arrayLengthPtr(res)); + + stack.push(res); +} + void J3CodeGen::newArray(uint8_t atype) { J3Primitive* prim = 0; @@ -400,22 +418,6 @@ void J3CodeGen::newArray(uint8_t atype) newArray(prim->getArray()); } -void J3CodeGen::newArray(J3ArrayClass* array) { - initialiseJ3Type(array); - llvm::DataLayout* layout = vm->dataLayout(); - llvm::Value* length = stack.pop(); - llvm::Value* arraySize = - builder->CreateAdd(builder->getInt64(layout->getTypeAllocSize(array->llvmType()->getContainedType(0))), - builder->CreateMul(builder->getInt64(layout->getTypeAllocSize(array->component()->llvmType())), - builder->CreateZExtOrBitCast(length, builder->getInt64Ty()))); - - llvm::Value* res = builder->CreateCall2(funcJ3ObjectAllocate, vt(array), arraySize); - - builder->CreateStore(length, arrayLengthPtr(res)); - - stack.push(res); -} - void J3CodeGen::newObject(J3Class* cl) { initialiseJ3Type(cl); @@ -433,8 +435,9 @@ void J3CodeGen::newObject(J3Class* cl) { } llvm::Value* J3CodeGen::isAssignableTo(llvm::Value* obj, J3Type* type) { - llvm::Value* vtType = vt(type); + llvm::Value* vtType = vt(type, 1); llvm::Value* vtObj = vt(obj); + if(type->isResolved()) { if(type->vt()->isPrimaryChecker()) return builder->CreateCall3(funcFastIsAssignableToPrimaryChecker, @@ -443,8 +446,9 @@ llvm::Value* J3CodeGen::isAssignableTo(l builder->getInt32(type->vt()->offset())); else return builder->CreateCall2(funcFastIsAssignableToNonPrimaryChecker, vtObj, vtType); - } else - return builder->CreateCall2(funcSlowIsAssignableTo, vtObj, vtType); + } else { + return builder->CreateCall2(funcIsAssignableTo, vtObj, vtType); + } } void J3CodeGen::instanceof(llvm::Value* obj, J3Type* type) { @@ -480,6 +484,7 @@ void J3CodeGen::checkCast(llvm::Value* o builder->SetInsertPoint(test); llvm::Value* res = isAssignableTo(obj, type); + builder->CreateCondBr(res, succeed, bbCheckCastFailed); builder->SetInsertPoint(bb); Modified: vmkit/branches/mcjit/lib/j3/vm/j3options.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3options.cc?rev=197983&r1=197982&r2=197983&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3options.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3options.cc Tue Dec 24 09:12:13 2013 @@ -19,7 +19,7 @@ J3Options::J3Options() { debugLoad = 0; debugResolve = 0; debugIniting = 0; - debugTranslate = 2; + debugTranslate = 0; debugLinking = 0; genDebugExecute = debugExecute ? 1 : 0; From gael.thomas at lip6.fr Tue Dec 24 11:02:34 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Tue, 24 Dec 2013 19:02:34 -0000 Subject: [vmkit-commits] [vmkit] r197987 - Add few jni and jvm functions. Execute more than 20115 opcodes! Happy christmas :) Message-ID: <20131224190234.5E52F2A6C029@llvm.org> Author: gthomas Date: Tue Dec 24 13:02:33 2013 New Revision: 197987 URL: http://llvm.org/viewvc/llvm-project?rev=197987&view=rev Log: Add few jni and jvm functions. Execute more than 20115 opcodes! Happy christmas :) Modified: vmkit/branches/mcjit/include/j3/j3class.h vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc vmkit/branches/mcjit/lib/j3/openjdk/j3unsafe.cc vmkit/branches/mcjit/lib/j3/vm/j3class.cc vmkit/branches/mcjit/lib/j3/vm/j3options.cc Modified: vmkit/branches/mcjit/include/j3/j3class.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3class.h?rev=197987&r1=197986&r2=197987&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3class.h (original) +++ vmkit/branches/mcjit/include/j3/j3class.h Tue Dec 24 13:02:33 2013 @@ -52,6 +52,9 @@ namespace j3 { public: J3Type(J3ClassLoader* loader, const vmkit::Name* name); + uint64_t getLogSize(); + uint64_t getSizeInBits(); + void* getSymbolAddress(); virtual llvm::GlobalValue* llvmDescriptor(llvm::Module* module) { return 0; } Modified: vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc?rev=197987&r1=197986&r2=197987&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc (original) +++ vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc Tue Dec 24 13:02:33 2013 @@ -1,5 +1,6 @@ #include "vmkit/config.h" #include "vmkit/system.h" +#include "vmkit/safepoint.h" #include "j3/j3object.h" #include "j3/j3lib.h" #include "j3/j3config.h" @@ -7,6 +8,7 @@ #include "j3/j3thread.h" #include "j3/j3classloader.h" #include "j3/j3class.h" +#include "j3/j3method.h" #include "jvm.h" #include @@ -220,7 +222,37 @@ jobject JNICALL JVM_NewMultiArray(JNIEnv * to be marked with sun.reflect.CallerSensitive. The JVM will throw * an error if it is not marked propertly. */ -jclass JNICALL JVM_GetCallerClass(JNIEnv* env, int depth) { enterJVM(); NYI(); leaveJVM(); } +jclass JNICALL JVM_GetCallerClass(JNIEnv* env, int depth) { + jclass res; + enterJVM(); + + if(depth != -1) + J3::internalError(L"depth should be -1 while it is %d", depth); + + depth = 3; + J3Method* caller = 0; + J3* vm = J3Thread::get()->vm(); + vmkit::Safepoint* sf = 0; + vmkit::StackWalker walker; + + while(!caller && walker.next()) { + vmkit::Safepoint* sf = vm->getSafepoint(walker.ip()); + + if(sf) { + if(!--depth) + caller = ((J3MethodCode*)sf->unit()->getSymbol(sf->functionName()))->self; + } + } + + if(!caller) + J3::internalError(L"unable to find caller class, what should I do?"); + + res = caller->cl()->javaClass(); + + leaveJVM(); + + return res; +} /* @@ -914,4 +946,18 @@ jobjectArray JNICALL JVM_GetThreadStateN * * ========================================================================== */ -void JNICALL JVM_GetVersionInfo(JNIEnv* env, jvm_version_info* info, size_t info_size) { enterJVM(); NYI(); leaveJVM(); } +void JNICALL JVM_GetVersionInfo(JNIEnv* env, jvm_version_info* info, size_t info_size) { + enterJVM(); + memset(info, 0, sizeof(info_size)); + + info->jvm_version = (8 << 24) | (0 << 16) | 0; + info->update_version = 0; + info->special_update_version = 0; + + // when we add a new capability in the jvm_version_info struct, we should also + // consider to expose this new capability in the sun.rt.jvmCapabilities jvmstat + // counter defined in runtimeService.cpp. + info->is_attach_supported = 0;//AttachListener::is_attach_supported(); + + leaveJVM(); +} Modified: vmkit/branches/mcjit/lib/j3/openjdk/j3unsafe.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/openjdk/j3unsafe.cc?rev=197987&r1=197986&r2=197987&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/openjdk/j3unsafe.cc (original) +++ vmkit/branches/mcjit/lib/j3/openjdk/j3unsafe.cc Tue Dec 24 13:02:33 2013 @@ -1,10 +1,37 @@ #include "j3/j3jni.h" #include "j3/j3object.h" +#include "j3/j3thread.h" +#include "j3/j3class.h" +#include "j3/j3classloader.h" +#include "j3/j3.h" + +#include "llvm/IR/DataLayout.h" using namespace j3; extern "C" { - JNIEXPORT void JNICALL Java_sun_misc_Unsafe_registerNatives(J3Object*) { + JNIEXPORT void JNICALL Java_sun_misc_Unsafe_registerNatives(JNIEnv* env, jclass cls) { // Nothing, we define the Unsafe methods with the expected signatures. } + + /// arrayBaseOffset - Offset from the array object where the actual + /// element data begins. + /// + JNIEXPORT jlong JNICALL Java_sun_misc_Unsafe_arrayBaseOffset(JNIEnv* env, jobject unsafe, jclass clazz) { + return sizeof(J3ArrayObject); + } + + /// arrayIndexScale - Indexing scale for the element type in + /// the specified array. For use with arrayBaseOffset, + /// NthElementPtr = ArrayObject + BaseOffset + N*IndexScale + /// Return '0' if our JVM stores the elements in a way that + /// makes this type of access impossible or unsupported. + /// + JNIEXPORT jlong JNICALL Java_sun_misc_Unsafe_arrayIndexScale(JNIEnv* env, jobject unsafe, jclass clazz) { + return J3ObjectType::nativeClass(clazz)->asArrayClass()->component()->getLogSize(); + } + + JNIEXPORT jint JNICALL Java_sun_misc_Unsafe_addressSize(JNIEnv* env, jobject unsafe) { + return J3Thread::get()->vm()->objectClass->getSizeInBits()>>3; + } } Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=197987&r1=197986&r2=197987&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Tue Dec 24 13:02:33 2013 @@ -71,6 +71,24 @@ J3ArrayClass* J3Type::getArray(uint32_t return prof > 1 ? _array->getArray(prof-1) : _array; } +uint64_t J3Type::getLogSize() { + uint32_t res = getSizeInBits(); + + switch(res) { + case 1: + case 8: return 0; + case 16: return 1; + case 32: return 2; + case 64: return 3; + default: + J3::internalError(L"unexpected type"); + } +} + +uint64_t J3Type::getSizeInBits() { + return loader()->vm()->dataLayout()->getTypeSizeInBits(llvmType()); +} + bool J3Type::isAssignableTo(J3Type* parent) { resolve(); parent->resolve(); @@ -956,3 +974,4 @@ J3Primitive::J3Primitive(J3ClassLoader* _nativeNameLength = 1; _vt = J3VirtualTable::create(this); } + Modified: vmkit/branches/mcjit/lib/j3/vm/j3options.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3options.cc?rev=197987&r1=197986&r2=197987&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3options.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3options.cc Tue Dec 24 13:02:33 2013 @@ -15,7 +15,7 @@ J3Options::J3Options() { debugEnterIndent = 1; - debugExecute = 0; + debugExecute = 2; debugLoad = 0; debugResolve = 0; debugIniting = 0; From gael.thomas at lip6.fr Wed Dec 25 10:54:58 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Wed, 25 Dec 2013 18:54:58 -0000 Subject: [vmkit-commits] [vmkit] r198023 - begin to bootstrap the thread system Message-ID: <20131225185458.50C352A6C029@llvm.org> Author: gthomas Date: Wed Dec 25 12:54:57 2013 New Revision: 198023 URL: http://llvm.org/viewvc/llvm-project?rev=198023&view=rev Log: begin to bootstrap the thread system Added: vmkit/branches/mcjit/lib/j3/openjdk/j3lib.cc Modified: vmkit/branches/mcjit/include/j3/j3.h vmkit/branches/mcjit/include/j3/j3lib.h vmkit/branches/mcjit/include/j3/j3thread.h vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc vmkit/branches/mcjit/lib/j3/vm/j3.cc vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc vmkit/branches/mcjit/lib/j3/vm/j3method.cc vmkit/branches/mcjit/lib/j3/vm/j3options.cc vmkit/branches/mcjit/lib/j3/vm/j3thread.cc Modified: vmkit/branches/mcjit/include/j3/j3.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3.h?rev=198023&r1=198022&r2=198023&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3.h (original) +++ vmkit/branches/mcjit/include/j3/j3.h Wed Dec 25 12:54:57 2013 @@ -65,6 +65,8 @@ namespace j3 { J3Method* classInit; J3Field* classVMData; + J3Field* threadVMData; + const vmkit::Name* codeAttr; const vmkit::Name* constantValueAttr; const vmkit::Name* initName; Modified: vmkit/branches/mcjit/include/j3/j3lib.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3lib.h?rev=198023&r1=198022&r2=198023&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3lib.h (original) +++ vmkit/branches/mcjit/include/j3/j3lib.h Wed Dec 25 12:54:57 2013 @@ -5,12 +5,15 @@ #include namespace j3 { + class J3; class J3ClassBytes; class J3Lib { public: static const char* systemClassesArchives(); static int loadSystemLibraries(std::vector >* handles); + + static void bootstrap(J3* vm); }; } Modified: vmkit/branches/mcjit/include/j3/j3thread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3thread.h?rev=198023&r1=198022&r2=198023&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3thread.h (original) +++ vmkit/branches/mcjit/include/j3/j3thread.h Wed Dec 25 12:54:57 2013 @@ -23,11 +23,15 @@ namespace j3 { JNIEnv _jniEnv; J3LocalReferences _localReferences; J3ObjectHandle* _pendingException; + J3ObjectHandle* _javaThread; J3Thread(J3* vm, vmkit::BumpAllocator* allocator); public: static J3Thread* create(J3* j3); + void assocJavaThread(J3ObjectHandle* javaThread); + J3ObjectHandle* javaThread() { return _javaThread; } + J3Method* getJavaCaller(uint32_t level=0); uint32_t interfaceMethodIndex() { return _interfaceMethodIndex; } Added: vmkit/branches/mcjit/lib/j3/openjdk/j3lib.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/openjdk/j3lib.cc?rev=198023&view=auto ============================================================================== --- vmkit/branches/mcjit/lib/j3/openjdk/j3lib.cc (added) +++ vmkit/branches/mcjit/lib/j3/openjdk/j3lib.cc Wed Dec 25 12:54:57 2013 @@ -0,0 +1,109 @@ +#include "vmkit/config.h" + +#include "j3/j3.h" +#include "j3/j3lib.h" +#include "j3/j3config.h" +#include "j3/j3constants.h" +#include "j3/j3classloader.h" +#include "j3/j3method.h" +#include "j3/j3class.h" +#include "j3/j3thread.h" + +#include + +using namespace j3; + +#ifdef LINUX_OS +#define OPENJDK_LIBPATH OPENJDK_HOME"jre/lib/amd64" +#else +#define OPENJDK_LIBPATH OPENJDK_HOME"jre/lib" +#endif + +static const char* rtjar = OPENJDK_HOME"jre/lib/rt.jar"; + +void J3Lib::bootstrap(J3* vm) { + J3ObjectHandle* prev = J3Thread::get()->tell(); + + J3Method* sysThreadGroupInit = vm->initialClassLoader->method(0, + L"java/lang/ThreadGroup", + J3Cst::initName, + L"()V"); + J3ObjectHandle* sysThreadGroup = J3ObjectHandle::doNewObject(sysThreadGroupInit->cl()); + sysThreadGroupInit->invokeSpecial(sysThreadGroup); + + + J3Method* appThreadGroupInit = vm->initialClassLoader->method(0, + L"java/lang/ThreadGroup", + J3Cst::initName, + L"(Ljava/lang/ThreadGroup;Ljava/lang/String;)V"); + J3ObjectHandle* appThreadGroup = J3ObjectHandle::doNewObject(appThreadGroupInit->cl()); + appThreadGroupInit->invokeSpecial(appThreadGroup, sysThreadGroup, vm->utfToString("main")); + + J3Method* threadInit = vm->initialClassLoader->method(0, + L"java/lang/Thread", + J3Cst::initName, + L"(Ljava/lang/ThreadGroup;Ljava/lang/String;)V"); + J3ObjectHandle* mainThread = vm->initialClassLoader->globalReferences()->add(J3ObjectHandle::doNewObject(threadInit->cl())); + + J3Thread::get()->assocJavaThread(mainThread); + mainThread->setInteger(threadInit->cl()->findVirtualField(vm->names()->get(L"priority"), vm->typeInteger), 5); + + threadInit->invokeSpecial(mainThread, appThreadGroup, vm->utfToString("main")); + + fprintf(stderr, "main thread is at %p\n", threadInit); + abort(); + + vm->initialClassLoader->method(J3Cst::ACC_STATIC, L"java/lang/System", L"initializeSystemClass", L"()V")->invokeStatic(); + + J3Thread::get()->restore(prev); +} + +const char* J3Lib::systemClassesArchives() { + return rtjar; +} + +int J3Lib::loadSystemLibraries(std::vector >* nativeLibraries) { + /* JavaRuntimeSupport checks for a symbol defined in this library */ + void* h0 = dlopen(OPENJDK_LIBPATH"/libinstrument"SHLIBEXT, RTLD_LAZY | RTLD_GLOBAL); + void* handle = dlopen(OPENJDK_LIBPATH"/libjava"SHLIBEXT, RTLD_LAZY | RTLD_LOCAL); + + if(!handle || !h0) { + fprintf(stderr, "Fatal: unable to find java system library: %s\n", dlerror()); + abort(); + } + + nativeLibraries->push_back(handle); + + return 0; +} + + +#if 0 +// from openjdk + + +// Creates the initial Thread +static oop create_initial_thread(Handle thread_group, JavaThread* thread, TRAPS) { + Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), true, CHECK_NULL); + instanceKlassHandle klass (THREAD, k); + instanceHandle thread_oop = klass->allocate_instance_handle(CHECK_NULL); + + java_lang_Thread::set_thread(thread_oop(), thread); + java_lang_Thread::set_priority(thread_oop(), NormPriority); + thread->set_threadObj(thread_oop()); + + Handle string = java_lang_String::create_from_str("main", CHECK_NULL); + + JavaValue result(T_VOID); + JavaCalls::call_special(&result, thread_oop, + klass, + vmSymbols::object_initializer_name(), + vmSymbols::threadgroup_string_void_signature(), + thread_group, + string, + CHECK_NULL); + return thread_oop(); +} + +// Creates the initial ThreadGroup +#endif Modified: vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc?rev=198023&r1=198022&r2=198023&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc (original) +++ vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc Wed Dec 25 12:54:57 2013 @@ -1,9 +1,4 @@ -#include "vmkit/config.h" -#include "vmkit/system.h" #include "vmkit/safepoint.h" -#include "j3/j3object.h" -#include "j3/j3lib.h" -#include "j3/j3config.h" #include "j3/j3.h" #include "j3/j3thread.h" #include "j3/j3classloader.h" @@ -11,8 +6,6 @@ #include "j3/j3method.h" #include "jvm.h" -#include - using namespace j3; #define enterJVM() @@ -20,33 +13,6 @@ using namespace j3; #define NYI() { J3Thread::get()->vm()->internalError(L"not yet implemented: '%s'", __PRETTY_FUNCTION__); } -#ifdef LINUX_OS -#define OPENJDK_LIBPATH OPENJDK_HOME"jre/lib/amd64" -#else -#define OPENJDK_LIBPATH OPENJDK_HOME"jre/lib" -#endif - -static const char* rtjar = OPENJDK_HOME"jre/lib/rt.jar"; - -const char* J3Lib::systemClassesArchives() { - return rtjar; -} - -int J3Lib::loadSystemLibraries(std::vector >* nativeLibraries) { - /* JavaRuntimeSupport checks for a symbol defined in this library */ - void* h0 = dlopen(OPENJDK_LIBPATH"/libinstrument"SHLIBEXT, RTLD_LAZY | RTLD_GLOBAL); - void* handle = dlopen(OPENJDK_LIBPATH"/libjava"SHLIBEXT, RTLD_LAZY | RTLD_LOCAL); - - if(!handle || !h0) { - fprintf(stderr, "Fatal: unable to find java system library: %s\n", dlerror()); - abort(); - } - - nativeLibraries->push_back(handle); - - return 0; -} - /************************************************************************* PART 0 @@ -82,7 +48,20 @@ jstring JNICALL JVM_InternString(JNIEnv* */ jlong JNICALL JVM_CurrentTimeMillis(JNIEnv* env, jclass ignored) { enterJVM(); NYI(); leaveJVM(); } jlong JNICALL JVM_NanoTime(JNIEnv* env, jclass ignored) { enterJVM(); NYI(); leaveJVM(); } -void JNICALL JVM_ArrayCopy(JNIEnv* env, jclass ignored, jobject src, jint src_pos, jobject dst, jint dst_pos, jint length) { enterJVM(); NYI(); leaveJVM(); } +void JNICALL JVM_ArrayCopy(JNIEnv* env, jclass ignored, jobject src, jint src_pos, jobject dst, jint dst_pos, jint length) { + enterJVM(); + + printf("to array copy: %p and %p\n", src->vt(), dst->vt()); + + J3Type* srcType = src->vt()->type(); + J3Type* dstType = dst->vt()->type(); + + fprintf(stderr, "%ls to %ls\n", srcType->name()->cStr(), dstType->name()->cStr()); + + NYI(); + leaveJVM(); +} + jobject JNICALL JVM_InitProperties(JNIEnv* env, jobject p) { enterJVM(); NYI(); leaveJVM(); } /* @@ -157,7 +136,15 @@ void JNICALL JVM_ResumeThread(JNIEnv* en void JNICALL JVM_SetThreadPriority(JNIEnv* env, jobject thread, jint prio) { enterJVM(); NYI(); leaveJVM(); } void JNICALL JVM_Yield(JNIEnv* env, jclass threadClass) { enterJVM(); NYI(); leaveJVM(); } void JNICALL JVM_Sleep(JNIEnv* env, jclass threadClass, jlong millis) { enterJVM(); NYI(); leaveJVM(); } -jobject JNICALL JVM_CurrentThread(JNIEnv* env, jclass threadClass) { enterJVM(); NYI(); leaveJVM(); } + +jobject JNICALL JVM_CurrentThread(JNIEnv* env, jclass threadClass) { + jobject res; + enterJVM(); + res = J3Thread::get()->javaThread(); + leaveJVM(); + return res; +} + jint JNICALL JVM_CountStackFrames(JNIEnv* env, jobject thread) { enterJVM(); NYI(); leaveJVM(); } void JNICALL JVM_Interrupt(JNIEnv* env, jobject thread) { enterJVM(); NYI(); leaveJVM(); } jboolean JNICALL JVM_IsInterrupted(JNIEnv* env, jobject thread, jboolean clearInterrupted) { enterJVM(); NYI(); leaveJVM(); } Modified: vmkit/branches/mcjit/lib/j3/vm/j3.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3.cc?rev=198023&r1=198022&r2=198023&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3.cc Wed Dec 25 12:54:57 2013 @@ -9,6 +9,7 @@ #include "j3/j3method.h" #include "j3/j3thread.h" #include "j3/j3trampoline.h" +#include "j3/j3lib.h" #include "llvm/IR/Type.h" #include "llvm/IR/DerivedTypes.h" @@ -101,7 +102,10 @@ void J3::start(int argc, char** argv) { classInit = initialClassLoader->method(0, classClass, initName, names()->get(L"()V")); classVMData = classClass->findVirtualField(hf.name(), hf.type()); - initialClassLoader->method(J3Cst::ACC_STATIC, L"java/lang/System", L"initializeSystemClass", L"()V")->invokeStatic(); + threadVMData = initialClassLoader->getClass(names()->get("java/lang/Thread")) + ->findVirtualField(names()->get(L"eetop"), typeLong); + + J3Lib::bootstrap(this); } JNIEnv* J3::jniEnv() { @@ -205,4 +209,3 @@ void J3::printStackTrace() { } } } - Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=198023&r1=198022&r2=198023&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Wed Dec 25 12:54:57 2013 @@ -252,6 +252,7 @@ void J3CodeGen::invoke(J3Method* target, llvm::Value* res; if(exceptionNodes[curExceptionNode]->landingPad) { + //llvm::BasicBlock* after = forwardBranch("invoke-after", codeReader->tell(), 0, 0); llvm::BasicBlock* after = newBB("invoke-after"); res = builder->CreateInvoke(func, after, exceptionNodes[curExceptionNode]->landingPad, args); bb = after; @@ -763,9 +764,9 @@ void J3CodeGen::translate() { //printf("Meta stack after: %p\n", metaStack); } - if(opInfos[javaPC].bb) + if(opInfos[javaPC].bb || bb->empty()) opInfos[javaPC].insn = bb->begin(); - else + else opInfos[javaPC].insn = bb->end()->getPrevNode(); uint8_t bc = codeReader->readU1(); Modified: vmkit/branches/mcjit/lib/j3/vm/j3method.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3method.cc?rev=198023&r1=198022&r2=198023&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3method.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3method.cc Wed Dec 25 12:54:57 2013 @@ -51,7 +51,7 @@ uint32_t J3Method::index() { void* J3Method::fnPtr() { if(!_fnPtr) { - //fprintf(stderr, "materializing: %ls::%ls%ls\n", cl()->name()->cStr(), name()->cStr(), sign()->cStr()); + //fprintf(stderr, "materializing: %ls::%ls%ls\n", this, cl()->name()->cStr(), name()->cStr(), sign()->cStr()); if(!isResolved()) { if(cl()->loader()->vm()->options()->debugLinking) fprintf(stderr, "linking %ls::%ls\n", cl()->name()->cStr(), name()->cStr()); Modified: vmkit/branches/mcjit/lib/j3/vm/j3options.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3options.cc?rev=198023&r1=198022&r2=198023&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3options.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3options.cc Wed Dec 25 12:54:57 2013 @@ -19,7 +19,7 @@ J3Options::J3Options() { debugLoad = 0; debugResolve = 0; debugIniting = 0; - debugTranslate = 0; + debugTranslate = 3; debugLinking = 0; genDebugExecute = debugExecute ? 1 : 0; Modified: vmkit/branches/mcjit/lib/j3/vm/j3thread.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3thread.cc?rev=198023&r1=198022&r2=198023&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3thread.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3thread.cc Wed Dec 25 12:54:57 2013 @@ -43,6 +43,11 @@ void J3Thread::ensureCapacity(uint32_t c _localReferences.ensureCapacity(capacity); } +void J3Thread::assocJavaThread(J3ObjectHandle* javaThread) { + _javaThread = javaThread; + _javaThread->setLong(vm()->threadVMData, (int64_t)(uintptr_t)this); +} + J3ObjectHandle* J3Thread::push(J3ObjectHandle* handle) { return _localReferences.push(handle); } From gael.thomas at lip6.fr Wed Dec 25 13:49:34 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Wed, 25 Dec 2013 21:49:34 -0000 Subject: [vmkit-commits] [vmkit] r198026 - implement arraycopy Message-ID: <20131225214934.7921C2A6C029@llvm.org> Author: gthomas Date: Wed Dec 25 15:49:33 2013 New Revision: 198026 URL: http://llvm.org/viewvc/llvm-project?rev=198026&view=rev Log: implement arraycopy Modified: vmkit/branches/mcjit/include/j3/j3.h vmkit/branches/mcjit/include/j3/j3object.h vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc vmkit/branches/mcjit/lib/j3/vm/j3.cc vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc vmkit/branches/mcjit/lib/j3/vm/j3object.cc vmkit/branches/mcjit/lib/j3/vm/j3options.cc Modified: vmkit/branches/mcjit/include/j3/j3.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3.h?rev=198026&r1=198025&r2=198026&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3.h (original) +++ vmkit/branches/mcjit/include/j3/j3.h Wed Dec 25 15:49:33 2013 @@ -111,7 +111,8 @@ namespace j3 { static void nullPointerException() __attribute__((noreturn)); static void classCastException() __attribute__((noreturn)); - static void arrayBoundCheckException() __attribute__((noreturn)); + static void arrayStoreException() __attribute__((noreturn)); + static void arrayIndexOutOfBoundsException() __attribute__((noreturn)); static void printStackTrace(); }; Modified: vmkit/branches/mcjit/include/j3/j3object.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3object.h?rev=198026&r1=198025&r2=198026&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3object.h (original) +++ vmkit/branches/mcjit/include/j3/j3object.h Wed Dec 25 15:49:33 2013 @@ -129,6 +129,7 @@ namespace j3 { private: J3Object* volatile _obj; + public: J3Object* obj() { return _obj; } J3ArrayObject* array() { return (J3ArrayObject*)_obj; } public: @@ -139,10 +140,14 @@ namespace j3 { static J3ObjectHandle* doNewObject(J3Class* cl); static J3ObjectHandle* doNewArray(J3ArrayClass* cl, uint32_t length); + bool isSame(J3ObjectHandle* handle) { return obj() == handle->obj(); } + void harakiri() { _obj = 0; } uint32_t hashCode(); + void rawArrayCopyTo(uint32_t fromOffset, J3ObjectHandle* to, uint32_t toOffset, uint32_t nbb); + void rawSetObject(uint32_t offset, J3ObjectHandle* v); J3ObjectHandle* rawGetObject(uint32_t offset); void setObject(J3Field* f, J3ObjectHandle* v); Modified: vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc?rev=198026&r1=198025&r2=198026&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc (original) +++ vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc Wed Dec 25 15:49:33 2013 @@ -51,14 +51,22 @@ jlong JNICALL JVM_NanoTime(JNIEnv* env, void JNICALL JVM_ArrayCopy(JNIEnv* env, jclass ignored, jobject src, jint src_pos, jobject dst, jint dst_pos, jint length) { enterJVM(); - printf("to array copy: %p and %p\n", src->vt(), dst->vt()); + J3Type* srcType0 = src->vt()->type(); + J3Type* dstType0 = dst->vt()->type(); - J3Type* srcType = src->vt()->type(); - J3Type* dstType = dst->vt()->type(); + if(!srcType0->isArrayClass() || !dstType0->isArrayClass() || !srcType0->isAssignableTo(dstType0)) + J3::arrayStoreException(); - fprintf(stderr, "%ls to %ls\n", srcType->name()->cStr(), dstType->name()->cStr()); + if(src_pos >= src->arrayLength() || + dst_pos >= dst->arrayLength() || + (src_pos + length) > src->arrayLength() || + (dst_pos + length) > dst->arrayLength()) + J3::arrayIndexOutOfBoundsException(); + + uint32_t scale = srcType0->asArrayClass()->component()->getLogSize(); + + src->rawArrayCopyTo(src_pos << scale, dst, dst_pos << scale, length << scale); - NYI(); leaveJVM(); } @@ -133,7 +141,13 @@ void JNICALL JVM_StopThread(JNIEnv* env, jboolean JNICALL JVM_IsThreadAlive(JNIEnv* env, jobject thread) { enterJVM(); NYI(); leaveJVM(); } void JNICALL JVM_SuspendThread(JNIEnv* env, jobject thread) { enterJVM(); NYI(); leaveJVM(); } void JNICALL JVM_ResumeThread(JNIEnv* env, jobject thread) { enterJVM(); NYI(); leaveJVM(); } -void JNICALL JVM_SetThreadPriority(JNIEnv* env, jobject thread, jint prio) { enterJVM(); NYI(); leaveJVM(); } + +void JNICALL JVM_SetThreadPriority(JNIEnv* env, jobject thread, jint prio) { + enterJVM(); + // not yet implemented + leaveJVM(); +} + void JNICALL JVM_Yield(JNIEnv* env, jclass threadClass) { enterJVM(); NYI(); leaveJVM(); } void JNICALL JVM_Sleep(JNIEnv* env, jclass threadClass, jlong millis) { enterJVM(); NYI(); leaveJVM(); } @@ -415,7 +429,12 @@ jobject JNICALL JVM_DoPrivileged(JNIEnv* } jobject JNICALL JVM_GetInheritedAccessControlContext(JNIEnv* env, jclass cls) { enterJVM(); NYI(); leaveJVM(); } -jobject JNICALL JVM_GetStackAccessControlContext(JNIEnv* env, jclass cls) { enterJVM(); NYI(); leaveJVM(); } +jobject JNICALL JVM_GetStackAccessControlContext(JNIEnv* env, jclass cls) { + enterJVM(); + // not yet implemented + leaveJVM(); + return 0; +} /* * Signal support, used to implement the shutdown sequence. Every VM must Modified: vmkit/branches/mcjit/lib/j3/vm/j3.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3.cc?rev=198026&r1=198025&r2=198026&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3.cc Wed Dec 25 15:49:33 2013 @@ -177,6 +177,14 @@ void J3::linkageError(J3Method* method) internalError(L"unable to find native method '%ls::%ls%ls'", method->cl()->name()->cStr(), method->name()->cStr(), method->sign()->cStr()); } +void J3::arrayStoreException() { + internalError(L"array store exception"); +} + +void J3::arrayIndexOutOfBoundsException() { + internalError(L"array bound check exception"); +} + void J3::vinternalError(const wchar_t* msg, va_list va) { wchar_t buf[65536]; vswprintf(buf, 65536, msg, va); Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=198026&r1=198025&r2=198026&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Wed Dec 25 15:49:33 2013 @@ -848,7 +848,7 @@ void J3CodeGen::translate() { case J3Cst::BC_lload: /* 0x16 wide */ case J3Cst::BC_fload: /* 0x17 wide */ case J3Cst::BC_dload: /* 0x18 wide */ - case J3Cst::BC_aload: /* 0x19 wide */ + case J3Cst::BC_aload: /* 0x19 wide */ stack.push(locals.at(wideReadU1())); break; Modified: vmkit/branches/mcjit/lib/j3/vm/j3object.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3object.cc?rev=198026&r1=198025&r2=198026&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3object.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3object.cc Wed Dec 25 15:49:33 2013 @@ -278,7 +278,7 @@ J3Object* J3Object::allocate(J3VirtualTa } J3Object* J3Object::doNewNoInit(J3Class* cl) { - return allocate(cl->vt(), cl->size()); + return allocate(cl->vtAndResolve(), cl->size()); } J3Object* J3Object::doNew(J3Class* cl) { @@ -292,7 +292,7 @@ J3Object* J3Object::doNew(J3Class* cl) { J3Object* J3ArrayObject::doNew(J3ArrayClass* cl, uint32_t length) { llvm::DataLayout* layout = cl->loader()->vm()->dataLayout(); J3ArrayObject* res = - (J3ArrayObject*)allocate(cl->vt(), + (J3ArrayObject*)allocate(cl->vtAndResolve(), layout->getTypeAllocSize(cl->llvmType()->getContainedType(0)) + layout->getTypeAllocSize(cl->component()->llvmType()) * length); @@ -367,7 +367,7 @@ J3ObjectHandle* J3ObjectHandle::doNewArr \ void J3ObjectHandle::setRegion##name(uint32_t selfIdx, const ctype* buf, uint32_t bufIdx, uint32_t len) { \ if(selfIdx + len > arrayLength()) \ - J3::arrayBoundCheckException(); \ + J3::arrayIndexOutOfBoundsException(); \ memcpy((uint8_t*)array() + sizeof(J3ArrayObject) + selfIdx*sizeof(ctype), \ (uint8_t*)buf + bufIdx*sizeof(ctype), \ len*sizeof(ctype)); \ @@ -375,7 +375,7 @@ J3ObjectHandle* J3ObjectHandle::doNewArr \ void J3ObjectHandle::getRegion##name(uint32_t selfIdx, const ctype* buf, uint32_t bufIdx, uint32_t len) { \ if(selfIdx + len > arrayLength()) \ - J3::arrayBoundCheckException(); \ + J3::arrayIndexOutOfBoundsException(); \ memcpy((uint8_t*)buf + bufIdx*sizeof(ctype), \ (uint8_t*)array() + sizeof(J3ArrayObject) + selfIdx*sizeof(ctype), \ len*sizeof(ctype)); \ @@ -385,6 +385,13 @@ onJavaPrimitives(defAccessor) #undef defAccessor +void J3ObjectHandle::rawArrayCopyTo(uint32_t fromOffset, J3ObjectHandle* to, uint32_t toOffset, uint32_t nbb) { + if(isSame(to)) + memmove((uint8_t*)(to->array()+1) + toOffset, (uint8_t*)(array()+1) + fromOffset, nbb); + else + memcpy((uint8_t*)(to->array()+1) + toOffset, (uint8_t*)(array()+1) + fromOffset, nbb); +} + void J3ObjectHandle::rawSetObject(uint32_t offset, J3ObjectHandle* value) { *((J3Object**)((uintptr_t)obj() + offset)) = value->obj(); } Modified: vmkit/branches/mcjit/lib/j3/vm/j3options.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3options.cc?rev=198026&r1=198025&r2=198026&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3options.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3options.cc Wed Dec 25 15:49:33 2013 @@ -15,11 +15,11 @@ J3Options::J3Options() { debugEnterIndent = 1; - debugExecute = 2; + debugExecute = 0; debugLoad = 0; debugResolve = 0; debugIniting = 0; - debugTranslate = 3; + debugTranslate = 0; debugLinking = 0; genDebugExecute = debugExecute ? 1 : 0; From gael.thomas at lip6.fr Wed Dec 25 13:55:13 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Wed, 25 Dec 2013 21:55:13 -0000 Subject: [vmkit-commits] [vmkit] r198027 - terminate the bootstrap of the thread system Message-ID: <20131225215513.601BB2A6C029@llvm.org> Author: gthomas Date: Wed Dec 25 15:55:12 2013 New Revision: 198027 URL: http://llvm.org/viewvc/llvm-project?rev=198027&view=rev Log: terminate the bootstrap of the thread system Modified: vmkit/branches/mcjit/lib/j3/openjdk/j3lib.cc vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Modified: vmkit/branches/mcjit/lib/j3/openjdk/j3lib.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/openjdk/j3lib.cc?rev=198027&r1=198026&r2=198027&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/openjdk/j3lib.cc (original) +++ vmkit/branches/mcjit/lib/j3/openjdk/j3lib.cc Wed Dec 25 15:55:12 2013 @@ -50,9 +50,6 @@ void J3Lib::bootstrap(J3* vm) { threadInit->invokeSpecial(mainThread, appThreadGroup, vm->utfToString("main")); - fprintf(stderr, "main thread is at %p\n", threadInit); - abort(); - vm->initialClassLoader->method(J3Cst::ACC_STATIC, L"java/lang/System", L"initializeSystemClass", L"()V")->invokeStatic(); J3Thread::get()->restore(prev); Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=198027&r1=198026&r2=198027&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Wed Dec 25 15:55:12 2013 @@ -1009,7 +1009,17 @@ void J3CodeGen::translate() { break; case J3Cst::BC_dup_x2: nyi(); /* 0x5b */ - case J3Cst::BC_dup2: nyi(); /* 0x5c */ + + case J3Cst::BC_dup2: /* 0x5c */ + val1 = stack.top(); + if(val1->getType()->isDoubleTy() || val1->getType()->isIntegerTy(64)) { + stack.push(val1); + } else { + val2 = stack.top(1); + stack.push(val2); stack.push(val1); + } + break; + case J3Cst::BC_dup2_x1: nyi(); /* 0x5d */ case J3Cst::BC_dup2_x2: nyi(); /* 0x5e */ case J3Cst::BC_swap: nyi(); /* 0x5f */ From gael.thomas at lip6.fr Thu Dec 26 01:42:29 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Thu, 26 Dec 2013 09:42:29 -0000 Subject: [vmkit-commits] [vmkit] r198042 - for field access from c++ code, use the field to find the class instead of the vt of the object. Avoids a lookup. Message-ID: <20131226094229.B541D2A6C029@llvm.org> Author: gthomas Date: Thu Dec 26 03:42:28 2013 New Revision: 198042 URL: http://llvm.org/viewvc/llvm-project?rev=198042&view=rev Log: for field access from c++ code, use the field to find the class instead of the vt of the object. Avoids a lookup. Modified: vmkit/branches/mcjit/include/j3/j3class.h vmkit/branches/mcjit/include/j3/j3thread.h vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc vmkit/branches/mcjit/lib/j3/vm/j3class.cc vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc vmkit/branches/mcjit/lib/j3/vm/j3method.cc vmkit/branches/mcjit/lib/j3/vm/j3object.cc vmkit/branches/mcjit/lib/j3/vm/j3options.cc vmkit/branches/mcjit/lib/j3/vm/j3thread.cc Modified: vmkit/branches/mcjit/include/j3/j3class.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3class.h?rev=198042&r1=198041&r2=198042&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3class.h (original) +++ vmkit/branches/mcjit/include/j3/j3class.h Thu Dec 26 03:42:28 2013 @@ -26,6 +26,7 @@ namespace j3 { class J3Primitive; class J3Class; class J3Layout; + class J3StaticLayout; class J3ArrayClass; class J3ObjectType; class J3Method; @@ -88,9 +89,11 @@ namespace j3 { J3Primitive* asPrimitive(); J3ArrayClass* asArrayClass(); J3Layout* asLayout(); + J3StaticLayout* asStaticLayout(); virtual bool isObjectType() { return 0; } virtual bool isArrayClass() { return 0; } + virtual bool isStaticLayout() { return 0; } virtual bool isLayout() { return 0; } virtual bool isClass() { return 0; } virtual bool isPrimitive() { return 0; } @@ -129,7 +132,7 @@ namespace j3 { class J3Field : public vmkit::PermanentObject { friend class J3Class; - J3Class* _cl; + J3Layout* _layout; uint16_t _access; const vmkit::Name* _name; J3Type* _type; @@ -142,7 +145,7 @@ namespace j3 { J3Attributes* attributes() const { return _attributes; } uint16_t access() { return _access; } - J3Class* cl() { return _cl; } + J3Layout* layout() { return _layout; } const vmkit::Name* name() { return _name; } J3Type* type() { return _type; } @@ -202,8 +205,18 @@ namespace j3 { llvm::Type* llvmType() { return _llvmType; } }; + class J3StaticLayout : public J3Layout { + J3Class* _cl; + public: + J3StaticLayout(J3ClassLoader* loader, J3Class* cl, const vmkit::Name* name); + + J3Class* cl() { return _cl; } + + virtual bool isStaticLayout() { return 1; } + }; + class J3Class : public J3Layout { - J3Layout staticLayout; + J3StaticLayout staticLayout; uint16_t _access; Modified: vmkit/branches/mcjit/include/j3/j3thread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3thread.h?rev=198042&r1=198041&r2=198042&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3thread.h (original) +++ vmkit/branches/mcjit/include/j3/j3thread.h Thu Dec 26 03:42:28 2013 @@ -31,6 +31,7 @@ namespace j3 { void assocJavaThread(J3ObjectHandle* javaThread); J3ObjectHandle* javaThread() { return _javaThread; } + static J3Thread* nativeThread(J3ObjectHandle* handle); J3Method* getJavaCaller(uint32_t level=0); Modified: vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc?rev=198042&r1=198041&r2=198042&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc (original) +++ vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc Thu Dec 26 03:42:28 2013 @@ -138,7 +138,16 @@ void JNICALL JVM_DisableCompiler(JNIEnv* */ void JNICALL JVM_StartThread(JNIEnv* env, jobject thread) { enterJVM(); NYI(); leaveJVM(); } void JNICALL JVM_StopThread(JNIEnv* env, jobject thread, jobject exception) { enterJVM(); NYI(); leaveJVM(); } -jboolean JNICALL JVM_IsThreadAlive(JNIEnv* env, jobject thread) { enterJVM(); NYI(); leaveJVM(); } +jboolean JNICALL JVM_IsThreadAlive(JNIEnv* env, jobject thread) { + jboolean res; + + enterJVM(); + res = (jboolean)J3Thread::nativeThread(thread); + leaveJVM(); + + return res; +} + void JNICALL JVM_SuspendThread(JNIEnv* env, jobject thread) { enterJVM(); NYI(); leaveJVM(); } void JNICALL JVM_ResumeThread(JNIEnv* env, jobject thread) { enterJVM(); NYI(); leaveJVM(); } Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=198042&r1=198041&r2=198042&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Thu Dec 26 03:42:28 2013 @@ -127,6 +127,12 @@ J3Layout* J3Type::asLayout() { return (J3Layout*)this; } +J3StaticLayout* J3Type::asStaticLayout() { + if(!isStaticLayout()) + J3::internalError(L"should not happen"); + return (J3StaticLayout*)this; +} + J3Primitive* J3Type::asPrimitive() { if(!isPrimitive()) J3::internalError(L"should not happen"); @@ -168,8 +174,7 @@ J3ObjectHandle* J3ObjectType::javaClass( lock(); if(!_javaClass) { J3ObjectHandle* prev = J3Thread::get()->tell(); - _javaClass = J3ObjectHandle::doNewObject(loader()->vm()->classClass); - _javaClass = loader()->globalReferences()->add(_javaClass); + _javaClass = loader()->globalReferences()->add(J3ObjectHandle::doNewObject(loader()->vm()->classClass)); J3Thread::get()->restore(prev); _javaClass->setLong(loader()->vm()->classVMData, (int64_t)(uintptr_t)this); loader()->vm()->classInit->invokeSpecial(_javaClass); @@ -244,6 +249,10 @@ void J3ObjectType::dumpInterfaceSlotDesc /* * ------------ J3Layout ------------ */ +J3StaticLayout::J3StaticLayout(J3ClassLoader* loader, J3Class* cl, const vmkit::Name* name) : J3Layout(loader, name) { + _cl = cl; +} + J3Layout::J3Layout(J3ClassLoader* loader, const vmkit::Name* name) : J3ObjectType(loader, name) { } @@ -264,8 +273,8 @@ J3Field* J3Layout::findField(const vmkit for(size_t i=0; iname()->cStr(), cur->sign()->cStr()); - //printf("%ls - %ls\n", name->cStr(), sign->cStr()); + //printf("Compare %ls - %ls\n", cur->name()->cStr(), cur->type()->name()->cStr()); + //printf(" with %ls - %ls\n", name->cStr(), type->name()->cStr()); if(cur->name() == name && cur->type() == type) { return cur; } @@ -276,7 +285,7 @@ J3Field* J3Layout::findField(const vmkit /* * ------------ J3Class ------------ */ -J3Class::J3Class(J3ClassLoader* loader, const vmkit::Name* name) : J3Layout(loader, name), staticLayout(loader, name) { +J3Class::J3Class(J3ClassLoader* loader, const vmkit::Name* name) : J3Layout(loader, name), staticLayout(loader, this, name) { status = CITED; } @@ -570,23 +579,24 @@ void J3Class::readClassBytes(std::vector J3Field* f = fields + i; if(i < nbHiddenFields) { - f->_cl = this; f->_access = hiddenFields[i].access(); f->_name = hiddenFields[i].name(); f->_type = hiddenFields[i].type(); f->_attributes = new (loader()->allocator(), 0) J3Attributes(0); } else { - f->_cl = this; f->_access = reader.readU2(); f->_name = nameAt(reader.readU2()); f->_type = loader()->getType(this, nameAt(reader.readU2())); f->_attributes = readAttributes(&reader); } - if(J3Cst::isStatic(f->access())) + if(J3Cst::isStatic(f->access())) { + f->_layout = &staticLayout; nbStaticFields++; - else + } else { + f->_layout = this; nbVirtualFields++; + } switch(loader()->vm()->dataLayout()->getTypeSizeInBits(f->_type->llvmType())) { case 1: pFields0[i0++] = f; break; @@ -646,7 +656,11 @@ void J3Class::readClassBytes(std::vector _methods = (J3Method**)loader()->allocator()->allocate(sizeof(J3Method*)*nbVirtualMethods); for(int i=0; iaccess()) ? &staticLayout : this; + J3Layout* layout; + if(J3Cst::isStatic(methodsTmp[i]->access())) + layout = &staticLayout; + else + layout = this; layout->_methods[layout->_nbMethods++] = methodsTmp[i]; } @@ -872,7 +886,7 @@ llvm::Type* J3Class::llvmType() { } void J3Field::dump() { - printf("Field: %ls %ls::%ls (%d)\n", type()->name()->cStr(), cl()->name()->cStr(), name()->cStr(), access()); + printf("Field: %ls %ls::%ls (%d)\n", type()->name()->cStr(), layout()->name()->cStr(), name()->cStr(), access()); } Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=198042&r1=198041&r2=198042&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Thu Dec 26 03:42:28 2013 @@ -43,6 +43,9 @@ J3CodeGen::J3CodeGen(vmkit::BumpAllocato loader = cl->loader(); vm = loader->vm(); + if(vm->options()->debugTranslate) + fprintf(stderr, " translating bytecode of: %ls::%ls%ls\n", method->cl()->name()->cStr(), method->name()->cStr(), method->sign()->cStr()); + llvmFunction = _llvmFunction; llvmFunction->setGC("vmkit"); _module = llvmFunction->getParent(); @@ -324,12 +327,12 @@ void J3CodeGen::get(llvm::Value* src, J3 void J3CodeGen::getField(uint32_t idx) { llvm::Value* obj = stack.pop(); J3Field* f = cl->fieldAt(idx, 0); - get(unflatten(nullCheck(obj), f->cl()), f); + get(unflatten(nullCheck(obj), f->layout()), f); } void J3CodeGen::getStatic(uint32_t idx) { J3Field* f = cl->fieldAt(idx, J3Cst::ACC_STATIC); - get(staticInstance(f->cl()), f); + get(staticInstance(f->layout()->asStaticLayout()->cl()), f); } void J3CodeGen::put(llvm::Value* dest, llvm::Value* val, J3Field* f) { @@ -339,14 +342,14 @@ void J3CodeGen::put(llvm::Value* dest, l void J3CodeGen::putStatic(uint32_t idx) { J3Field* f = cl->fieldAt(idx, J3Cst::ACC_STATIC); - put(staticInstance(f->cl()), stack.pop(), f); + put(staticInstance(f->layout()->asStaticLayout()->cl()), stack.pop(), f); } void J3CodeGen::putField(uint32_t idx) { J3Field* f = cl->fieldAt(idx, 0); llvm::Value* val = stack.pop(); llvm::Value* obj = nullCheck(stack.pop()); - put(unflatten(obj, f->cl()), val, f); + put(unflatten(obj, f->layout()), val, f); } void J3CodeGen::arrayBoundCheck(llvm::Value* obj, llvm::Value* idx) { @@ -670,17 +673,13 @@ void J3CodeGen::echoDebugExecute(uint32_ } void J3CodeGen::translate() { - if(vm->options()->debugTranslate) { - fprintf(stderr, " translating bytecode of: %ls::%ls%ls\n", method->cl()->name()->cStr(), method->name()->cStr(), method->sign()->cStr()); - - if(vm->options()->debugTranslate > 1) { - fprintf(stderr, " exception table:\n"); - for(uint32_t i=0; ipc); - for(uint32_t j=0; jnbEntries; j++) - fprintf(stderr, " %u", exceptionNodes[i]->entries[j]->catchType); - fprintf(stderr, exceptionNodes[i]->nbEntries ? "\n" : " \n"); - } + if(vm->options()->debugTranslate > 1) { + fprintf(stderr, " exception table:\n"); + for(uint32_t i=0; ipc); + for(uint32_t j=0; jnbEntries; j++) + fprintf(stderr, " %u", exceptionNodes[i]->entries[j]->catchType); + fprintf(stderr, exceptionNodes[i]->nbEntries ? "\n" : " \n"); } } Modified: vmkit/branches/mcjit/lib/j3/vm/j3method.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3method.cc?rev=198042&r1=198041&r2=198042&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3method.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3method.cc Thu Dec 26 03:42:28 2013 @@ -161,6 +161,7 @@ J3Value J3Method::internalInvoke(bool st target = resolve(self); } + //fprintf(stderr, "invoke: %ls::%ls%ls\n", target->cl()->name()->cStr(), target->name()->cStr(), target->sign()->cStr()); target->fnPtr(); /* ensure that the function is compiled */ cl()->loader()->oldee()->updateGlobalMapping(target->_llvmFunction, target->fnPtr()); llvm::GenericValue res = cl()->loader()->oldee()->runFunction(target->_llvmFunction, args); Modified: vmkit/branches/mcjit/lib/j3/vm/j3object.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3object.cc?rev=198042&r1=198041&r2=198042&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3object.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3object.cc Thu Dec 26 03:42:28 2013 @@ -344,7 +344,7 @@ J3ObjectHandle* J3ObjectHandle::doNewArr void J3ObjectHandle::set##name(J3Field* field, ctype value) { \ const llvm::StructLayout* layout = \ obj()->vt()->type()->loader()->vm()->dataLayout()-> \ - getStructLayout((llvm::StructType*)(obj()->vt()->type()->llvmType()->getContainedType(0))); \ + getStructLayout((llvm::StructType*)(field->layout()->llvmType()->getContainedType(0))); \ uint32_t offset = layout->getElementOffset(field->num()); \ rawSet##name(offset, value); \ } \ @@ -352,7 +352,7 @@ J3ObjectHandle* J3ObjectHandle::doNewArr ctype J3ObjectHandle::get##name(J3Field* field) { \ const llvm::StructLayout* layout = \ obj()->vt()->type()->loader()->vm()->dataLayout()-> \ - getStructLayout((llvm::StructType*)(obj()->vt()->type()->llvmType()->getContainedType(0))); \ + getStructLayout((llvm::StructType*)(field->layout()->llvmType()->getContainedType(0))); \ uint32_t offset = layout->getElementOffset(field->num()); \ return rawGet##name(offset); \ } \ @@ -403,7 +403,7 @@ J3ObjectHandle* J3ObjectHandle::rawGetOb void J3ObjectHandle::setObject(J3Field* field, J3ObjectHandle* value) { const llvm::StructLayout* layout = obj()->vt()->type()->loader()->vm()->dataLayout()-> - getStructLayout((llvm::StructType*)(obj()->vt()->type()->llvmType()->getContainedType(0))); + getStructLayout((llvm::StructType*)(field->layout()->llvmType()->getContainedType(0))); uint32_t offset = layout->getElementOffset(field->num()); rawSetObject(offset, value); } @@ -411,7 +411,7 @@ void J3ObjectHandle::setObject(J3Field* J3ObjectHandle* J3ObjectHandle::getObject(J3Field* field) { const llvm::StructLayout* layout = obj()->vt()->type()->loader()->vm()->dataLayout()-> - getStructLayout((llvm::StructType*)(obj()->vt()->type()->llvmType()->getContainedType(0))); + getStructLayout((llvm::StructType*)(field->layout()->llvmType()->getContainedType(0))); return rawGetObject(layout->getElementOffset(field->num())); } Modified: vmkit/branches/mcjit/lib/j3/vm/j3options.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3options.cc?rev=198042&r1=198041&r2=198042&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3options.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3options.cc Thu Dec 26 03:42:28 2013 @@ -19,7 +19,7 @@ J3Options::J3Options() { debugLoad = 0; debugResolve = 0; debugIniting = 0; - debugTranslate = 0; + debugTranslate = 2; debugLinking = 0; genDebugExecute = debugExecute ? 1 : 0; Modified: vmkit/branches/mcjit/lib/j3/vm/j3thread.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3thread.cc?rev=198042&r1=198041&r2=198042&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3thread.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3thread.cc Thu Dec 26 03:42:28 2013 @@ -1,5 +1,6 @@ #include "j3/j3thread.h" #include "j3/j3method.h" +#include "j3/j3class.h" #include "j3/j3.h" #include "vmkit/safepoint.h" @@ -43,6 +44,10 @@ void J3Thread::ensureCapacity(uint32_t c _localReferences.ensureCapacity(capacity); } +J3Thread* J3Thread::nativeThread(J3ObjectHandle* handle) { + return (J3Thread*)handle->getLong(get()->vm()->threadVMData); +} + void J3Thread::assocJavaThread(J3ObjectHandle* javaThread) { _javaThread = javaThread; _javaThread->setLong(vm()->threadVMData, (int64_t)(uintptr_t)this); From gael.thomas at lip6.fr Thu Dec 26 12:59:12 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Thu, 26 Dec 2013 20:59:12 -0000 Subject: [vmkit-commits] [vmkit] r198057 - new exception reader, not yet used in codeGen Message-ID: <20131226205912.CCB572A6C029@llvm.org> Author: gthomas Date: Thu Dec 26 14:59:12 2013 New Revision: 198057 URL: http://llvm.org/viewvc/llvm-project?rev=198057&view=rev Log: new exception reader, not yet used in codeGen Modified: vmkit/branches/mcjit/include/j3/j3codegen.h vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc vmkit/branches/mcjit/lib/j3/vm/j3options.cc Modified: vmkit/branches/mcjit/include/j3/j3codegen.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3codegen.h?rev=198057&r1=198056&r2=198057&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3codegen.h (original) +++ vmkit/branches/mcjit/include/j3/j3codegen.h Thu Dec 26 14:59:12 2013 @@ -55,6 +55,7 @@ namespace j3 { class J3CodeGen { friend class J3CodeGenVar; + friend class ZJ3ExceptionTable; vmkit::BumpAllocator* allocator; llvm::Module* _module; Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=198057&r1=198056&r2=198057&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Thu Dec 26 14:59:12 2013 @@ -1432,6 +1432,120 @@ void J3CodeGen::closeExceptionNode(J3Exc } } + +namespace j3 { +class ZJ3ExceptionEntry { +public: + uint32_t startPC; + uint32_t endPC; + uint32_t handlerPC; + uint32_t catchType; + llvm::BasicBlock* bb; + + void dump(uint32_t i); +}; + +class ZJ3ExceptionNode { +public: + uint32_t pc; + uint32_t nbEntries; + ZJ3ExceptionEntry** entries; +}; + +class ZJ3ExceptionTable { +public: + J3CodeGen* codeGen; + uint32_t nbEntries; + ZJ3ExceptionEntry* entries; + ZJ3ExceptionNode* _exceptionNodes; + ZJ3ExceptionNode** nodes; + uint32_t nbNodes; + + ZJ3ExceptionTable(J3CodeGen* _codeGen) { codeGen = _codeGen; } + + ZJ3ExceptionNode** newNode(uint32_t pos, uint32_t pc); + + ZJ3ExceptionNode** findPos(uint32_t pc); + void read(J3Reader* reader); + + void dump(bool verbose=0); +}; +} + +void ZJ3ExceptionEntry::dump(uint32_t i) { + fprintf(stderr, " entry[%d]: %d %d %d %d\n", i, startPC, endPC, handlerPC, catchType); +} + +ZJ3ExceptionNode** ZJ3ExceptionTable::newNode(uint32_t pos, uint32_t pc) { + ZJ3ExceptionNode* res = &_exceptionNodes[nbNodes++]; + res->pc = pc; + res->entries = (ZJ3ExceptionEntry**)codeGen->allocator->allocate(sizeof(J3ExceptionEntry*)*nbEntries); + nodes[pos] = res; + if(pos > 1 && nodes[pos-1]->nbEntries) { + res->nbEntries = nodes[pos-1]->nbEntries; + memcpy(res->entries, nodes[pos-1]->entries, sizeof(J3ExceptionEntry*)*res->nbEntries); + } + return nodes+pos; +} + +ZJ3ExceptionNode** ZJ3ExceptionTable::findPos(uint32_t pc) { + for(uint32_t i=0; ipc == pc) + return nodes+i; + if(pc < nodes[i]->pc) { + memmove(nodes+i+1, nodes+i, (nbNodes-i)*sizeof(ZJ3ExceptionNode*)); + return newNode(i, pc); + } + } + return newNode(nbNodes, pc); +} + +void ZJ3ExceptionTable::read(J3Reader* reader) { + nbEntries = reader->readU2(); + entries = (ZJ3ExceptionEntry*)codeGen->allocator->allocate(sizeof(ZJ3ExceptionEntry)*nbEntries); + _exceptionNodes = (ZJ3ExceptionNode*)codeGen->allocator->allocate(sizeof(J3ExceptionNode)*(nbEntries*2 + 2)); + nodes = (ZJ3ExceptionNode**)codeGen->allocator->allocate(sizeof(J3ExceptionNode*)*(nbEntries*2 + 2)); + nbNodes = 0; + + newNode(0, 0); + for(uint32_t i=0; ireadU2(); + entries[i].endPC = reader->readU2(); + entries[i].handlerPC = reader->readU2(); + entries[i].catchType = reader->readU2(); + entries[i].bb = codeGen->forwardBranch("exception-handler", entries[i].handlerPC, 0, 1); + codeGen->opInfos[entries[i].handlerPC].topStack = -1; + + ZJ3ExceptionNode** cur = findPos(entries[i].startPC); + ZJ3ExceptionNode** end = findPos(entries[i].endPC); + + for(; curentries[(*cur)->nbEntries++] = entries+i; + } + + dump(1); +} + +void ZJ3ExceptionTable::dump(bool verbose) { + if(nbEntries) { + fprintf(stderr, "ExceptionTable of %ls::%ls%ls:\n", + codeGen->method->cl()->name()->cStr(), + codeGen->method->name()->cStr(), + codeGen->method->sign()->cStr()); + + if(verbose) { + for(uint32_t i=0; ipc); + for(uint32_t j=0; jnbEntries; j++) + fprintf(stderr, " catch %d at %d\n", nodes[i]->entries[j]->catchType, nodes[i]->entries[j]->handlerPC); + } + } +} + void J3CodeGen::generateJava() { J3Attribute* attr = method->attributes()->lookup(vm->codeAttr); @@ -1515,6 +1629,14 @@ void J3CodeGen::generateJava() { } reader.seek(codeLength, reader.SeekCur); + + uint32_t orig = reader.tell(); + + ZJ3ExceptionTable table(this); + table.read(&reader); + + reader.seek(orig, J3Reader::SeekSet); + nbExceptionEntries = reader.readU2(); exceptionEntries = (J3ExceptionEntry*)allocator->allocate(sizeof(J3ExceptionEntry) * nbExceptionEntries); exceptionNodes = (J3ExceptionNode**)allocator->allocate(sizeof(J3ExceptionNode*) * (nbExceptionEntries * 2 + 2)); @@ -1557,7 +1679,7 @@ void J3CodeGen::generateJava() { found = 0; create = 1; for(; curpc, exceptionEntries[i].startPC, exceptionEntries[i].endPC); if(exceptionEntries[i].endPC == exceptionNodes[cur]->pc) { create = 0; found = 1; Modified: vmkit/branches/mcjit/lib/j3/vm/j3options.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3options.cc?rev=198057&r1=198056&r2=198057&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3options.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3options.cc Thu Dec 26 14:59:12 2013 @@ -15,11 +15,11 @@ J3Options::J3Options() { debugEnterIndent = 1; - debugExecute = 0; + debugExecute = 2; debugLoad = 0; debugResolve = 0; debugIniting = 0; - debugTranslate = 2; + debugTranslate = 0; debugLinking = 0; genDebugExecute = debugExecute ? 1 : 0; From gael.thomas at lip6.fr Thu Dec 26 13:49:33 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Thu, 26 Dec 2013 21:49:33 -0000 Subject: [vmkit-commits] [vmkit] r198058 - use my new infrastructure for exception Message-ID: <20131226214933.1EDD02A6C029@llvm.org> Author: gthomas Date: Thu Dec 26 15:49:32 2013 New Revision: 198058 URL: http://llvm.org/viewvc/llvm-project?rev=198058&view=rev Log: use my new infrastructure for exception Added: vmkit/branches/mcjit/include/j3/j3codegenexception.h vmkit/branches/mcjit/lib/j3/vm/j3codegenexception.cc Modified: vmkit/branches/mcjit/include/j3/j3codegen.h vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc vmkit/branches/mcjit/lib/j3/vm/j3options.cc Modified: vmkit/branches/mcjit/include/j3/j3codegen.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3codegen.h?rev=198058&r1=198057&r2=198058&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3codegen.h (original) +++ vmkit/branches/mcjit/include/j3/j3codegen.h Thu Dec 26 15:49:32 2013 @@ -3,6 +3,7 @@ #include "llvm/IR/IRBuilder.h" #include "j3/j3codegenvar.h" +#include "j3/j3codegenexception.h" namespace llvm { class Function; @@ -25,26 +26,6 @@ namespace j3 { class J3Reader; class J3ObjectType; - class J3ExceptionEntry { - public: - uint32_t startPC; - uint32_t endPC; - uint32_t handlerPC; - uint32_t catchType; - llvm::BasicBlock* bb; - - void dump(); - }; - - class J3ExceptionNode { - public: - uint32_t pc; - uint32_t nbEntries; - llvm::BasicBlock* landingPad; - llvm::BasicBlock* curCheck; - J3ExceptionEntry* entries[1]; - }; - class J3OpInfo { public: llvm::Instruction* insn; @@ -55,7 +36,8 @@ namespace j3 { class J3CodeGen { friend class J3CodeGenVar; - friend class ZJ3ExceptionTable; + friend class J3ExceptionTable; + friend class J3ExceptionNode; vmkit::BumpAllocator* allocator; llvm::Module* _module; @@ -74,10 +56,7 @@ namespace j3 { llvm::BasicBlock* bbNullCheckFailed; llvm::BasicBlock* bbRet; - J3ExceptionEntry* exceptionEntries; - J3ExceptionNode** exceptionNodes; - uint32_t nbExceptionEntries; - uint32_t nbExceptionNodes; + J3ExceptionTable exceptions; uint32_t curExceptionNode; J3OpInfo* opInfos; Added: vmkit/branches/mcjit/include/j3/j3codegenexception.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3codegenexception.h?rev=198058&view=auto ============================================================================== --- vmkit/branches/mcjit/include/j3/j3codegenexception.h (added) +++ vmkit/branches/mcjit/include/j3/j3codegenexception.h Thu Dec 26 15:49:32 2013 @@ -0,0 +1,57 @@ +#ifndef _J3_CODEGEN_EXCEPTION_H_ +#define _J3_CODEGEN_EXCEPTION_H_ + +#include + +namespace llvm { + class BasicBlock; +} + +namespace j3 { + class J3CodeGen; + class J3Reader; + + class J3ExceptionEntry { + public: + uint32_t startPC; + uint32_t endPC; + uint32_t handlerPC; + uint32_t catchType; + llvm::BasicBlock* bb; + + void dump(uint32_t i); + }; + + class J3ExceptionNode { + public: + uint32_t pc; + uint32_t nbEntries; + J3ExceptionEntry** entries; + llvm::BasicBlock* landingPad; + llvm::BasicBlock* curCheck; /* last of the linked list of checker */ + + void close(J3CodeGen* codeGen); + void addEntry(J3CodeGen* codeGen, J3ExceptionEntry* entry); + }; + + class J3ExceptionTable { + public: + J3CodeGen* codeGen; + uint32_t nbEntries; + J3ExceptionEntry* entries; + J3ExceptionNode* _exceptionNodes; + J3ExceptionNode** nodes; + uint32_t nbNodes; + + J3ExceptionTable(J3CodeGen* _codeGen) { codeGen = _codeGen; } + + J3ExceptionNode** newNode(uint32_t pos, uint32_t pc); + + J3ExceptionNode** findPos(uint32_t pc); + void read(J3Reader* reader, uint32_t codeLength); + + void dump(bool verbose=0); + }; +} + +#endif Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=198058&r1=198057&r2=198058&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Thu Dec 26 15:49:32 2013 @@ -26,15 +26,9 @@ using namespace j3; #define _onEndPoint() ({ if(onEndPoint()) return; }) -void J3ExceptionEntry::dump() { - fprintf(stderr, " exception entry:\n"); - fprintf(stderr, " start_pc: %u\n", startPC); - fprintf(stderr, " end_pc: %u\n", endPC); - fprintf(stderr, " handler_pc: %u\n", handlerPC); - fprintf(stderr, " catchType: %u\n", catchType); -} - -J3CodeGen::J3CodeGen(vmkit::BumpAllocator* _allocator, J3Method* m, llvm::Function* _llvmFunction) { +J3CodeGen::J3CodeGen(vmkit::BumpAllocator* _allocator, J3Method* m, llvm::Function* _llvmFunction) : + exceptions(this) { + allocator = _allocator; method = m; @@ -43,6 +37,11 @@ J3CodeGen::J3CodeGen(vmkit::BumpAllocato loader = cl->loader(); vm = loader->vm(); +#if 0 + if(m->cl()->name() == vm->names()->get(L"java/util/concurrent/atomic/AtomicInteger")) + vm->options()->debugTranslate = 4; +#endif + if(vm->options()->debugTranslate) fprintf(stderr, " translating bytecode of: %ls::%ls%ls\n", method->cl()->name()->cStr(), method->name()->cStr(), method->sign()->cStr()); @@ -121,6 +120,9 @@ J3CodeGen::J3CodeGen(vmkit::BumpAllocato generateNative(); else generateJava(); + + if(vm->options()->debugTranslate > 3) + llvmFunction->dump(); } J3CodeGen::~J3CodeGen() { @@ -222,13 +224,13 @@ llvm::Value* J3CodeGen::vt(J3Type* type, } llvm::Value* J3CodeGen::nullCheck(llvm::Value* obj) { - if(exceptionNodes[curExceptionNode]->landingPad) { + if(exceptions.nodes[curExceptionNode]->landingPad) { llvm::BasicBlock* succeed = newBB("nullcheck-succeed"); if(!bbNullCheckFailed) { bbNullCheckFailed = newBB("nullcheck-failed"); builder->SetInsertPoint(bbNullCheckFailed); - builder->CreateInvoke(funcNullPointerException, bbRet, exceptionNodes[curExceptionNode]->landingPad); + builder->CreateInvoke(funcNullPointerException, bbRet, exceptions.nodes[curExceptionNode]->landingPad); builder->SetInsertPoint(bb); } @@ -254,10 +256,10 @@ void J3CodeGen::invoke(J3Method* target, llvm::Value* res; - if(exceptionNodes[curExceptionNode]->landingPad) { + if(exceptions.nodes[curExceptionNode]->landingPad) { //llvm::BasicBlock* after = forwardBranch("invoke-after", codeReader->tell(), 0, 0); llvm::BasicBlock* after = newBB("invoke-after"); - res = builder->CreateInvoke(func, after, exceptionNodes[curExceptionNode]->landingPad, args); + res = builder->CreateInvoke(func, after, exceptions.nodes[curExceptionNode]->landingPad, args); bb = after; builder->SetInsertPoint(bb); } else @@ -550,7 +552,9 @@ void J3CodeGen::ldc(uint32_t idx) { switch(cl->getCtpType(idx)) { case J3Cst::CONSTANT_Long: res = builder->getInt64(cl->longAt(idx)); break; case J3Cst::CONSTANT_Integer: res = builder->getInt32(cl->integerAt(idx)); break; - case J3Cst::CONSTANT_Float: res = llvm::ConstantFP::get(builder->getFloatTy(), cl->floatAt(idx)); break; + case J3Cst::CONSTANT_Float: + fprintf(stderr, "generate float: %lf\n", cl->floatAt(idx)); + res = llvm::ConstantFP::get(builder->getFloatTy(), cl->floatAt(idx)); break; case J3Cst::CONSTANT_Double: res = llvm::ConstantFP::get(builder->getDoubleTy(), cl->doubleAt(idx)); break; case J3Cst::CONSTANT_Class: res = handleToObject(javaClass(cl->classAt(idx))); break; case J3Cst::CONSTANT_String: @@ -673,15 +677,8 @@ void J3CodeGen::echoDebugExecute(uint32_ } void J3CodeGen::translate() { - if(vm->options()->debugTranslate > 1) { - fprintf(stderr, " exception table:\n"); - for(uint32_t i=0; ipc); - for(uint32_t j=0; jnbEntries; j++) - fprintf(stderr, " %u", exceptionNodes[i]->entries[j]->catchType); - fprintf(stderr, exceptionNodes[i]->nbEntries ? "\n" : " \n"); - } - } + if(vm->options()->debugTranslate > 1) + exceptions.dump(vm->options()->debugTranslate-1); curExceptionNode = 0; @@ -722,12 +719,12 @@ void J3CodeGen::translate() { javaPC = codeReader->tell(); - if(javaPC < exceptionNodes[curExceptionNode]->pc || javaPC >= exceptionNodes[curExceptionNode+1]->pc) { - if(javaPC == exceptionNodes[curExceptionNode+1]->pc) + if(javaPC < exceptions.nodes[curExceptionNode]->pc || javaPC >= exceptions.nodes[curExceptionNode+1]->pc) { + if(javaPC == exceptions.nodes[curExceptionNode+1]->pc) curExceptionNode++; else - for(uint32_t i=0; ipc <= javaPC && javaPC < exceptionNodes[i+1]->pc) { + for(uint32_t i=0; ipc <= javaPC && javaPC < exceptions.nodes[i+1]->pc) { curExceptionNode = i; break; } @@ -771,15 +768,20 @@ void J3CodeGen::translate() { uint8_t bc = codeReader->readU1(); switch(vm->options()->debugTranslate) { - case 4: + default: + case 5: fprintf(stderr, "--------------------------------------------\n"); llvmFunction->dump(); + case 4: case 3: fprintf(stderr, "stack:\n"); stack.dump(); case 2: fprintf(stderr, " [%4d] decoding: %s\n", javaPC, J3Cst::opcodeNames[bc]); break; + case 1: + case 0: + break; } if(vm->options()->genDebugExecute) { @@ -1377,175 +1379,6 @@ void J3CodeGen::explore() { } #endif -void J3CodeGen::initExceptionNode(J3ExceptionNode** pnode, uint32_t pc, J3ExceptionNode* node) { - *pnode = node; - nbExceptionNodes++; - node->pc = pc; - node->nbEntries = 0; - node->landingPad = 0; - node->curCheck = 0; -} - -void J3CodeGen::addToExceptionNode(J3ExceptionNode* node, J3ExceptionEntry* entry) { - if(!node->nbEntries) { - node->landingPad = newBB("landing-pad"); - node->curCheck = node->landingPad; - builder->SetInsertPoint(node->landingPad); - - llvm::LandingPadInst *caughtResult = builder->CreateLandingPad(vm->typeGXXException, funcGXXPersonality, 1, "landing-pad"); - caughtResult->addClause(gvTypeInfo); - llvm::Value* excp = builder->CreateBitCast(builder->CreateCall(funcCXABeginCatch, - builder->CreateExtractValue(caughtResult, 0)), - vm->typeJ3ObjectPtr); - - builder->CreateCall(funcCXAEndCatch); - - builder->CreateCall2(funcEchoDebugExecute, - builder->getInt32(0), /* just to see my first exception :) */ - buildString("entering launchpad!\n")); - - stack.topStack = 0; - stack.push(excp); - } - - node->entries[node->nbEntries++] = entry; - - if(node->curCheck) { /* = 0 if I already have a finally */ - builder->SetInsertPoint(node->curCheck); - node->curCheck = newBB("next-exception-check"); - - if(entry->catchType) { - stack.metaStack[0] = vm->typeJ3ObjectPtr; - stack.topStack = 1; - builder->CreateCondBr(isAssignableTo(stack.top(0), cl->classAt(entry->catchType)), entry->bb, node->curCheck); - } else { - builder->CreateBr(entry->bb); - node->curCheck = 0; - } - } -} - -void J3CodeGen::closeExceptionNode(J3ExceptionNode* node) { - if(node->curCheck) { - builder->SetInsertPoint(node->curCheck); - builder->CreateBr(bbRet); - } -} - - -namespace j3 { -class ZJ3ExceptionEntry { -public: - uint32_t startPC; - uint32_t endPC; - uint32_t handlerPC; - uint32_t catchType; - llvm::BasicBlock* bb; - - void dump(uint32_t i); -}; - -class ZJ3ExceptionNode { -public: - uint32_t pc; - uint32_t nbEntries; - ZJ3ExceptionEntry** entries; -}; - -class ZJ3ExceptionTable { -public: - J3CodeGen* codeGen; - uint32_t nbEntries; - ZJ3ExceptionEntry* entries; - ZJ3ExceptionNode* _exceptionNodes; - ZJ3ExceptionNode** nodes; - uint32_t nbNodes; - - ZJ3ExceptionTable(J3CodeGen* _codeGen) { codeGen = _codeGen; } - - ZJ3ExceptionNode** newNode(uint32_t pos, uint32_t pc); - - ZJ3ExceptionNode** findPos(uint32_t pc); - void read(J3Reader* reader); - - void dump(bool verbose=0); -}; -} - -void ZJ3ExceptionEntry::dump(uint32_t i) { - fprintf(stderr, " entry[%d]: %d %d %d %d\n", i, startPC, endPC, handlerPC, catchType); -} - -ZJ3ExceptionNode** ZJ3ExceptionTable::newNode(uint32_t pos, uint32_t pc) { - ZJ3ExceptionNode* res = &_exceptionNodes[nbNodes++]; - res->pc = pc; - res->entries = (ZJ3ExceptionEntry**)codeGen->allocator->allocate(sizeof(J3ExceptionEntry*)*nbEntries); - nodes[pos] = res; - if(pos > 1 && nodes[pos-1]->nbEntries) { - res->nbEntries = nodes[pos-1]->nbEntries; - memcpy(res->entries, nodes[pos-1]->entries, sizeof(J3ExceptionEntry*)*res->nbEntries); - } - return nodes+pos; -} - -ZJ3ExceptionNode** ZJ3ExceptionTable::findPos(uint32_t pc) { - for(uint32_t i=0; ipc == pc) - return nodes+i; - if(pc < nodes[i]->pc) { - memmove(nodes+i+1, nodes+i, (nbNodes-i)*sizeof(ZJ3ExceptionNode*)); - return newNode(i, pc); - } - } - return newNode(nbNodes, pc); -} - -void ZJ3ExceptionTable::read(J3Reader* reader) { - nbEntries = reader->readU2(); - entries = (ZJ3ExceptionEntry*)codeGen->allocator->allocate(sizeof(ZJ3ExceptionEntry)*nbEntries); - _exceptionNodes = (ZJ3ExceptionNode*)codeGen->allocator->allocate(sizeof(J3ExceptionNode)*(nbEntries*2 + 2)); - nodes = (ZJ3ExceptionNode**)codeGen->allocator->allocate(sizeof(J3ExceptionNode*)*(nbEntries*2 + 2)); - nbNodes = 0; - - newNode(0, 0); - for(uint32_t i=0; ireadU2(); - entries[i].endPC = reader->readU2(); - entries[i].handlerPC = reader->readU2(); - entries[i].catchType = reader->readU2(); - entries[i].bb = codeGen->forwardBranch("exception-handler", entries[i].handlerPC, 0, 1); - codeGen->opInfos[entries[i].handlerPC].topStack = -1; - - ZJ3ExceptionNode** cur = findPos(entries[i].startPC); - ZJ3ExceptionNode** end = findPos(entries[i].endPC); - - for(; curentries[(*cur)->nbEntries++] = entries+i; - } - - dump(1); -} - -void ZJ3ExceptionTable::dump(bool verbose) { - if(nbEntries) { - fprintf(stderr, "ExceptionTable of %ls::%ls%ls:\n", - codeGen->method->cl()->name()->cStr(), - codeGen->method->name()->cStr(), - codeGen->method->sign()->cStr()); - - if(verbose) { - for(uint32_t i=0; ipc); - for(uint32_t j=0; jnbEntries; j++) - fprintf(stderr, " catch %d at %d\n", nodes[i]->entries[j]->catchType, nodes[i]->entries[j]->handlerPC); - } - } -} - void J3CodeGen::generateJava() { J3Attribute* attr = method->attributes()->lookup(vm->codeAttr); @@ -1630,84 +1463,7 @@ void J3CodeGen::generateJava() { reader.seek(codeLength, reader.SeekCur); - uint32_t orig = reader.tell(); - - ZJ3ExceptionTable table(this); - table.read(&reader); - - reader.seek(orig, J3Reader::SeekSet); - - nbExceptionEntries = reader.readU2(); - exceptionEntries = (J3ExceptionEntry*)allocator->allocate(sizeof(J3ExceptionEntry) * nbExceptionEntries); - exceptionNodes = (J3ExceptionNode**)allocator->allocate(sizeof(J3ExceptionNode*) * (nbExceptionEntries * 2 + 2)); - nbExceptionNodes = 0; - - initExceptionNode(exceptionNodes, - 0, - (J3ExceptionNode*)allocator->allocate(sizeof(J3ExceptionNode) - - sizeof(J3ExceptionEntry*) + - nbExceptionEntries * sizeof(J3ExceptionEntry*))); - - for(uint32_t i=0; ipc) { - create = 0; - found = 1; - } else if(exceptionNodes[cur]->pc > exceptionEntries[i].startPC) { - memmove(exceptionNodes + cur + 1, exceptionNodes + cur, (nbExceptionNodes - cur) * sizeof(J3ExceptionNode*)); - found = 1; - } - } - - if(create) { - initExceptionNode(exceptionNodes+cur, - exceptionEntries[i].startPC, - (J3ExceptionNode*)allocator->allocate(sizeof(J3ExceptionNode) + (nbExceptionEntries - 1)*sizeof(J3ExceptionEntry*))); - if(cur > 0) - for(uint32_t k=0; knbEntries; k++) - addToExceptionNode(exceptionNodes[cur], exceptionNodes[cur-1]->entries[k]); - } - - found = 0; create = 1; - for(; curpc, exceptionEntries[i].startPC, exceptionEntries[i].endPC); - if(exceptionEntries[i].endPC == exceptionNodes[cur]->pc) { - create = 0; - found = 1; - } else if(exceptionEntries[i].endPC < exceptionNodes[cur]->pc) { - memmove(exceptionNodes + cur + 1, exceptionNodes + cur, (nbExceptionNodes - cur) * sizeof(J3ExceptionNode*)); - found = 1; - } else - addToExceptionNode(exceptionNodes[cur], exceptionEntries + i); - } - - if(create) { - initExceptionNode(exceptionNodes+cur, - exceptionEntries[i].endPC, - (J3ExceptionNode*)allocator->allocate(sizeof(J3ExceptionNode) + (nbExceptionEntries - 1)*sizeof(J3ExceptionEntry*))); - for(uint32_t k=0; knbEntries-1; k++) - addToExceptionNode(exceptionNodes[cur], exceptionNodes[cur-1]->entries[k]); - } - } - - if(exceptionNodes[nbExceptionNodes-1]->pc != codeLength) - initExceptionNode(exceptionNodes + nbExceptionNodes, - codeLength, - (J3ExceptionNode*)allocator->allocate(sizeof(J3ExceptionNode) - - sizeof(J3ExceptionEntry*) + - nbExceptionEntries * sizeof(J3ExceptionEntry*))); - - for(uint32_t i=0; itell(); translate(); Added: vmkit/branches/mcjit/lib/j3/vm/j3codegenexception.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegenexception.cc?rev=198058&view=auto ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegenexception.cc (added) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegenexception.cc Thu Dec 26 15:49:32 2013 @@ -0,0 +1,139 @@ +#include "j3/j3codegenexception.h" +#include "j3/j3codegen.h" +#include "j3/j3reader.h" +#include "j3/j3method.h" +#include "j3/j3class.h" +#include "j3/j3.h" + +#include "vmkit/allocator.h" +#include "vmkit/names.h" + +#include "llvm/IR/Function.h" + +using namespace j3; + +void J3ExceptionEntry::dump(uint32_t i) { + fprintf(stderr, " entry[%d]: %d %d %d %d\n", i, startPC, endPC, handlerPC, catchType); +} + +void J3ExceptionNode::addEntry(J3CodeGen* codeGen, J3ExceptionEntry* entry) { + if(!nbEntries) { + landingPad = codeGen->newBB("landing-pad"); + curCheck = landingPad; + codeGen->builder->SetInsertPoint(landingPad); + + llvm::LandingPadInst *caughtResult = codeGen->builder->CreateLandingPad(codeGen->vm->typeGXXException, + codeGen->funcGXXPersonality, + 1, + "landing-pad"); + caughtResult->addClause(codeGen->gvTypeInfo); + llvm::Value* excp = codeGen->builder->CreateBitCast(codeGen->builder->CreateCall(codeGen->funcCXABeginCatch, + codeGen->builder->CreateExtractValue(caughtResult, 0)), + codeGen->vm->typeJ3ObjectPtr); + + codeGen->builder->CreateCall(codeGen->funcCXAEndCatch); + + codeGen->builder->CreateCall2(codeGen->funcEchoDebugExecute, + codeGen->builder->getInt32(0), /* just to see my first exception :) */ + codeGen->buildString("entering launchpad!\n")); + } + + entries[nbEntries++] = entry; + + if(curCheck) { /* = 0 if I already have a finally */ + codeGen->builder->SetInsertPoint(curCheck); + curCheck = codeGen->newBB("next-exception-check"); + + if(entry->catchType) { + codeGen->stack.metaStack[0] = codeGen->vm->typeJ3ObjectPtr; + codeGen->stack.topStack = 1; + codeGen->builder->CreateCondBr(codeGen->isAssignableTo(codeGen->stack.top(0), + codeGen->cl->classAt(entry->catchType)), + entry->bb, + curCheck); + } else { + codeGen->builder->CreateBr(entry->bb); + curCheck = 0; + } + } +} + +void J3ExceptionNode::close(J3CodeGen* codeGen) { + if(curCheck) { + codeGen->builder->SetInsertPoint(curCheck); + codeGen->builder->CreateBr(codeGen->bbRet); + } +} + +J3ExceptionNode** J3ExceptionTable::newNode(uint32_t pos, uint32_t pc) { + J3ExceptionNode* res = &_exceptionNodes[nbNodes++]; + res->pc = pc; + res->entries = (J3ExceptionEntry**)codeGen->allocator->allocate(sizeof(J3ExceptionEntry*)*nbEntries); + nodes[pos] = res; + if(pos > 1) { + for(uint32_t i=0; inbEntries; i++) + res->addEntry(codeGen, nodes[pos-1]->entries[i]); + } + return nodes+pos; +} + +J3ExceptionNode** J3ExceptionTable::findPos(uint32_t pc) { + for(uint32_t i=0; ipc == pc) + return nodes+i; + if(pc < nodes[i]->pc) { + memmove(nodes+i+1, nodes+i, (nbNodes-i)*sizeof(J3ExceptionNode*)); + return newNode(i, pc); + } + } + return newNode(nbNodes, pc); +} + +void J3ExceptionTable::read(J3Reader* reader, uint32_t codeLength) { + nbEntries = reader->readU2(); + entries = (J3ExceptionEntry*)codeGen->allocator->allocate(sizeof(J3ExceptionEntry)*nbEntries); + _exceptionNodes = (J3ExceptionNode*)codeGen->allocator->allocate(sizeof(J3ExceptionNode)*(nbEntries*2 + 2)); + nodes = (J3ExceptionNode**)codeGen->allocator->allocate(sizeof(J3ExceptionNode*)*(nbEntries*2 + 2)); + nbNodes = 0; + + newNode(nbNodes, 0); + for(uint32_t i=0; ireadU2(); + entries[i].endPC = reader->readU2(); + entries[i].handlerPC = reader->readU2(); + entries[i].catchType = reader->readU2(); + entries[i].bb = codeGen->forwardBranch("exception-handler", entries[i].handlerPC, 0, 1); + codeGen->opInfos[entries[i].handlerPC].topStack = -1; + + J3ExceptionNode** cur = findPos(entries[i].startPC); + J3ExceptionNode** end = findPos(entries[i].endPC); + + for(; curaddEntry(codeGen, entries+i); + } + newNode(nbNodes, codeLength); + + for(uint32_t i=0; iclose(codeGen); +} + +void J3ExceptionTable::dump(bool verbose) { + if(nbEntries) { + fprintf(stderr, " ExceptionTable of %ls::%ls%ls:\n", + codeGen->method->cl()->name()->cStr(), + codeGen->method->name()->cStr(), + codeGen->method->sign()->cStr()); + + if(verbose) { + for(uint32_t i=0; ipc); + for(uint32_t j=0; jnbEntries; j++) + fprintf(stderr, " catch %d at %d\n", nodes[i]->entries[j]->catchType, nodes[i]->entries[j]->handlerPC); + } + } +} + Modified: vmkit/branches/mcjit/lib/j3/vm/j3options.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3options.cc?rev=198058&r1=198057&r2=198058&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3options.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3options.cc Thu Dec 26 15:49:32 2013 @@ -15,11 +15,11 @@ J3Options::J3Options() { debugEnterIndent = 1; - debugExecute = 2; + debugExecute = 0; debugLoad = 0; debugResolve = 0; debugIniting = 0; - debugTranslate = 0; + debugTranslate = 2; debugLinking = 0; genDebugExecute = debugExecute ? 1 : 0; From gael.thomas at lip6.fr Thu Dec 26 14:41:20 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Thu, 26 Dec 2013 22:41:20 -0000 Subject: [vmkit-commits] [vmkit] r198061 - only explore exception handler after having explored their try clauses. Ensures that the its locals exists. Message-ID: <20131226224120.23ACB2A6C029@llvm.org> Author: gthomas Date: Thu Dec 26 16:41:19 2013 New Revision: 198061 URL: http://llvm.org/viewvc/llvm-project?rev=198061&view=rev Log: only explore exception handler after having explored their try clauses. Ensures that the its locals exists. Modified: vmkit/branches/mcjit/include/j3/j3codegen.h vmkit/branches/mcjit/include/j3/j3codegenexception.h vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc vmkit/branches/mcjit/lib/j3/vm/j3codegenexception.cc Modified: vmkit/branches/mcjit/include/j3/j3codegen.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3codegen.h?rev=198061&r1=198060&r2=198061&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3codegen.h (original) +++ vmkit/branches/mcjit/include/j3/j3codegen.h Thu Dec 26 16:41:19 2013 @@ -134,6 +134,8 @@ namespace j3 { void ldc(uint32_t idx); + void selectExceptionNode(uint32_t idx); + void translate(); void initExceptionNode(J3ExceptionNode** pnode, uint32_t pc, J3ExceptionNode* node); Modified: vmkit/branches/mcjit/include/j3/j3codegenexception.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3codegenexception.h?rev=198061&r1=198060&r2=198061&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3codegenexception.h (original) +++ vmkit/branches/mcjit/include/j3/j3codegenexception.h Thu Dec 26 16:41:19 2013 @@ -18,6 +18,7 @@ namespace j3 { uint32_t handlerPC; uint32_t catchType; llvm::BasicBlock* bb; + bool isAdded; void dump(uint32_t i); }; @@ -29,6 +30,7 @@ namespace j3 { J3ExceptionEntry** entries; llvm::BasicBlock* landingPad; llvm::BasicBlock* curCheck; /* last of the linked list of checker */ + bool isAdded; void close(J3CodeGen* codeGen); void addEntry(J3CodeGen* codeGen, J3ExceptionEntry* entry); Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=198061&r1=198060&r2=198061&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Thu Dec 26 16:41:19 2013 @@ -552,9 +552,7 @@ void J3CodeGen::ldc(uint32_t idx) { switch(cl->getCtpType(idx)) { case J3Cst::CONSTANT_Long: res = builder->getInt64(cl->longAt(idx)); break; case J3Cst::CONSTANT_Integer: res = builder->getInt32(cl->integerAt(idx)); break; - case J3Cst::CONSTANT_Float: - fprintf(stderr, "generate float: %lf\n", cl->floatAt(idx)); - res = llvm::ConstantFP::get(builder->getFloatTy(), cl->floatAt(idx)); break; + case J3Cst::CONSTANT_Float: res = llvm::ConstantFP::get(builder->getFloatTy(), cl->floatAt(idx)); break; case J3Cst::CONSTANT_Double: res = llvm::ConstantFP::get(builder->getDoubleTy(), cl->doubleAt(idx)); break; case J3Cst::CONSTANT_Class: res = handleToObject(javaClass(cl->classAt(idx))); break; case J3Cst::CONSTANT_String: @@ -628,6 +626,21 @@ bool J3CodeGen::onEndPoint() { return 0; } +void J3CodeGen::selectExceptionNode(uint32_t idx) { + curExceptionNode = idx; + + if(!exceptions.nodes[idx]->isAdded) { + exceptions.nodes[idx]->isAdded = 1; + for(uint32_t i=0; inbEntries; i++) { + J3ExceptionEntry* e = exceptions.nodes[idx]->entries[i]; + if(!e->isAdded) { + e->isAdded = 1; + pendingBranchs[topPendingBranchs++] = e->handlerPC; + } + } + } +} + llvm::Value* J3CodeGen::buildString(const char* msg) { std::vector elmts; uint32_t n; @@ -680,7 +693,7 @@ void J3CodeGen::translate() { if(vm->options()->debugTranslate > 1) exceptions.dump(vm->options()->debugTranslate-1); - curExceptionNode = 0; + selectExceptionNode(0); stack.topStack = 0; builder->SetInsertPoint(bb); @@ -721,11 +734,11 @@ void J3CodeGen::translate() { if(javaPC < exceptions.nodes[curExceptionNode]->pc || javaPC >= exceptions.nodes[curExceptionNode+1]->pc) { if(javaPC == exceptions.nodes[curExceptionNode+1]->pc) - curExceptionNode++; + selectExceptionNode(curExceptionNode+1); else for(uint32_t i=0; ipc <= javaPC && javaPC < exceptions.nodes[i+1]->pc) { - curExceptionNode = i; + selectExceptionNode(i); break; } //printf("cur exception node: %d\n", curExceptionNode); Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegenexception.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegenexception.cc?rev=198061&r1=198060&r2=198061&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegenexception.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegenexception.cc Thu Dec 26 16:41:19 2013 @@ -62,7 +62,7 @@ void J3ExceptionNode::close(J3CodeGen* c if(curCheck) { codeGen->builder->SetInsertPoint(curCheck); codeGen->builder->CreateBr(codeGen->bbRet); - } + } } J3ExceptionNode** J3ExceptionTable::newNode(uint32_t pos, uint32_t pc) { From gael.thomas at lip6.fr Thu Dec 26 15:23:12 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Thu, 26 Dec 2013 23:23:12 -0000 Subject: [vmkit-commits] [vmkit] r198062 - Able to start a Java thread, that's cool, but I have a bug in invokeVirtual that leads to the execution of Thread::run instead of the run() method of the thread object. Message-ID: <20131226232313.2442C2A6C029@llvm.org> Author: gthomas Date: Thu Dec 26 17:23:12 2013 New Revision: 198062 URL: http://llvm.org/viewvc/llvm-project?rev=198062&view=rev Log: Able to start a Java thread, that's cool, but I have a bug in invokeVirtual that leads to the execution of Thread::run instead of the run() method of the thread object. Modified: vmkit/branches/mcjit/include/j3/j3.h vmkit/branches/mcjit/include/j3/j3thread.h vmkit/branches/mcjit/include/vmkit/thread.h vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc vmkit/branches/mcjit/lib/j3/vm/j3.cc vmkit/branches/mcjit/lib/j3/vm/j3options.cc vmkit/branches/mcjit/lib/j3/vm/j3thread.cc vmkit/branches/mcjit/lib/vmkit/thread.cc Modified: vmkit/branches/mcjit/include/j3/j3.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3.h?rev=198062&r1=198061&r2=198062&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3.h (original) +++ vmkit/branches/mcjit/include/j3/j3.h Thu Dec 26 17:23:12 2013 @@ -66,6 +66,7 @@ namespace j3 { J3Field* classVMData; J3Field* threadVMData; + J3Method* threadRun; const vmkit::Name* codeAttr; const vmkit::Name* constantValueAttr; Modified: vmkit/branches/mcjit/include/j3/j3thread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3thread.h?rev=198062&r1=198061&r2=198062&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3thread.h (original) +++ vmkit/branches/mcjit/include/j3/j3thread.h Thu Dec 26 17:23:12 2013 @@ -25,6 +25,8 @@ namespace j3 { J3ObjectHandle* _pendingException; J3ObjectHandle* _javaThread; + static void doRun(); + J3Thread(J3* vm, vmkit::BumpAllocator* allocator); public: static J3Thread* create(J3* j3); @@ -52,6 +54,8 @@ namespace j3 { JNIEnv* jniEnv() { return &_jniEnv; } static J3Thread* get(); + + static void start(J3ObjectHandle* handle); }; } Modified: vmkit/branches/mcjit/include/vmkit/thread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/thread.h?rev=198062&r1=198061&r2=198062&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/thread.h (original) +++ vmkit/branches/mcjit/include/vmkit/thread.h Thu Dec 26 17:23:12 2013 @@ -7,9 +7,14 @@ namespace vmkit { class VMKit; class Thread : protected PermanentObject { + typedef void (*entryPoint_t)(); + BumpAllocator* _allocator; VMKit* _vm; void* _baseFramePointer; + entryPoint_t _entryPoint; + + static void* doRun(void* thread); protected: Thread(VMKit* vm, BumpAllocator* allocator); @@ -27,6 +32,8 @@ namespace vmkit { static Thread* get() { return _thread; } static void set(Thread* thread) { _thread = thread; } + + static void start(entryPoint_t entryPoint, Thread* thread); }; class StackWalker { Modified: vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc?rev=198062&r1=198061&r2=198062&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc (original) +++ vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc Thu Dec 26 17:23:12 2013 @@ -136,7 +136,12 @@ void JNICALL JVM_DisableCompiler(JNIEnv* /* * java.lang.Thread */ -void JNICALL JVM_StartThread(JNIEnv* env, jobject thread) { enterJVM(); NYI(); leaveJVM(); } +void JNICALL JVM_StartThread(JNIEnv* env, jobject thread) { + enterJVM(); + J3Thread::start(thread); + leaveJVM(); +} + void JNICALL JVM_StopThread(JNIEnv* env, jobject thread, jobject exception) { enterJVM(); NYI(); leaveJVM(); } jboolean JNICALL JVM_IsThreadAlive(JNIEnv* env, jobject thread) { jboolean res; Modified: vmkit/branches/mcjit/lib/j3/vm/j3.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3.cc?rev=198062&r1=198061&r2=198062&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3.cc Thu Dec 26 17:23:12 2013 @@ -104,6 +104,7 @@ void J3::start(int argc, char** argv) { threadVMData = initialClassLoader->getClass(names()->get("java/lang/Thread")) ->findVirtualField(names()->get(L"eetop"), typeLong); + threadRun = initialClassLoader->method(0, L"java/lang/Thread", L"run", L"()V"); J3Lib::bootstrap(this); } Modified: vmkit/branches/mcjit/lib/j3/vm/j3options.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3options.cc?rev=198062&r1=198061&r2=198062&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3options.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3options.cc Thu Dec 26 17:23:12 2013 @@ -19,8 +19,8 @@ J3Options::J3Options() { debugLoad = 0; debugResolve = 0; debugIniting = 0; - debugTranslate = 2; - debugLinking = 0; + debugTranslate = 1; + debugLinking = 1; genDebugExecute = debugExecute ? 1 : 0; } Modified: vmkit/branches/mcjit/lib/j3/vm/j3thread.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3thread.cc?rev=198062&r1=198061&r2=198062&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3thread.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3thread.cc Thu Dec 26 17:23:12 2013 @@ -19,6 +19,18 @@ J3Thread* J3Thread::create(J3* j3) { return new(allocator) J3Thread(j3, allocator); } +void J3Thread::doRun() { + J3ObjectHandle* handle = get()->javaThread(); + get()->vm()->threadRun->invokeVirtual(handle); +} + +void J3Thread::start(J3ObjectHandle* handle) { + J3Thread* thread = create(J3Thread::get()->vm()); + thread->assocJavaThread(handle); + Thread::start(doRun, thread); + while(1); +} + J3Method* J3Thread::getJavaCaller(uint32_t level) { vmkit::Safepoint* sf = 0; vmkit::StackWalker walker; Modified: vmkit/branches/mcjit/lib/vmkit/thread.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/thread.cc?rev=198062&r1=198061&r2=198062&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/thread.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/thread.cc Thu Dec 26 17:23:12 2013 @@ -15,6 +15,19 @@ void Thread::destroy(Thread* thread) { BumpAllocator::destroy(thread->allocator()); } +void* Thread::doRun(void* _thread) { + Thread* thread = (Thread*)_thread; + set(thread); + thread->_entryPoint(); + return 0; +} + +void Thread::start(entryPoint_t entryPoint, Thread* thread) { + thread->_entryPoint = entryPoint; + pthread_t tid; + pthread_create(&tid, 0, doRun, thread); +} + StackWalker::StackWalker(uint32_t initialPop) { framePointer = System::current_fp(); next(initialPop+1); From gael.thomas at lip6.fr Thu Dec 26 15:47:07 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Thu, 26 Dec 2013 23:47:07 -0000 Subject: [vmkit-commits] [vmkit] r198064 - fix the bug in invokeVirtual Message-ID: <20131226234707.835372A6C029@llvm.org> Author: gthomas Date: Thu Dec 26 17:47:07 2013 New Revision: 198064 URL: http://llvm.org/viewvc/llvm-project?rev=198064&view=rev Log: fix the bug in invokeVirtual Modified: vmkit/branches/mcjit/lib/j3/vm/j3method.cc Modified: vmkit/branches/mcjit/lib/j3/vm/j3method.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3method.cc?rev=198064&r1=198063&r2=198064&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3method.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3method.cc Thu Dec 26 17:47:07 2013 @@ -115,7 +115,7 @@ J3Method* J3Method::resolve(J3ObjectHand if(cl()->loader()->vm()->options()->debugLinking) fprintf(stderr, "virtual linking %ls::%ls\n", cl()->name()->cStr(), name()->cStr()); vmkit::Names* n = cl()->loader()->vm()->names(); - return cl()->findVirtualMethod(name(), sign()); + return obj->vt()->type()->asObjectType()->findVirtualMethod(name(), sign()); } @@ -157,7 +157,7 @@ J3Value J3Method::internalInvoke(bool st target = this; else { /* can not use trampoline here */ - J3ObjectHandle* self = (J3ObjectHandle*)args[0].PointerVal; + J3ObjectHandle* self = handle ? handle : inArgs[0].valObject; target = resolve(self); } From gael.thomas at lip6.fr Thu Dec 26 16:21:40 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Fri, 27 Dec 2013 00:21:40 -0000 Subject: [vmkit-commits] [vmkit] r198065 - fix another bug in invokeInternal Message-ID: <20131227002140.932E52A6C029@llvm.org> Author: gthomas Date: Thu Dec 26 18:21:40 2013 New Revision: 198065 URL: http://llvm.org/viewvc/llvm-project?rev=198065&view=rev Log: fix another bug in invokeInternal Modified: vmkit/branches/mcjit/lib/j3/vm/j3method.cc Modified: vmkit/branches/mcjit/lib/j3/vm/j3method.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3method.cc?rev=198065&r1=198064&r2=198065&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3method.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3method.cc Thu Dec 26 18:21:40 2013 @@ -123,32 +123,34 @@ J3Value J3Method::internalInvoke(bool st std::vector args(methodType()->nbIns()); J3* vm = cl()->loader()->vm(); J3Type* cur; - uint32_t i = 0; + uint32_t i = 0, d = 0; - if(handle) + if(handle) { args[i++].PointerVal = handle->obj(); + d = 1; + } for(; inbIns(); i++) { /* have to avoid collection at this point */ cur = methodType()->ins(i); if(cur == vm->typeBoolean) - args[i].IntVal = inArgs[i].valBoolean; + args[i].IntVal = inArgs[i-d].valBoolean; else if(cur == vm->typeByte) - args[i].IntVal = inArgs[i].valByte; + args[i].IntVal = inArgs[i-d].valByte; else if(cur == vm->typeShort) - args[i].IntVal = inArgs[i].valShort; + args[i].IntVal = inArgs[i-d].valShort; else if(cur == vm->typeChar) - args[i].IntVal = inArgs[i].valChar; + args[i].IntVal = inArgs[i-d].valChar; else if(cur == vm->typeInteger) - args[i].IntVal = inArgs[i].valInteger; + args[i].IntVal = inArgs[i-d].valInteger; else if(cur == vm->typeLong) - args[i].IntVal = inArgs[i].valLong; + args[i].IntVal = inArgs[i-d].valLong; else if(cur == vm->typeFloat) - args[i].FloatVal = inArgs[i].valFloat; + args[i].FloatVal = inArgs[i-d].valFloat; else if(cur == vm->typeDouble) - args[i].FloatVal = inArgs[i].valDouble; + args[i].FloatVal = inArgs[i-d].valDouble; else - args[i].PointerVal = inArgs[i].valObject->obj(); + args[i].PointerVal = inArgs[i-d].valObject->obj(); } J3Method* target; @@ -156,7 +158,6 @@ J3Value J3Method::internalInvoke(bool st if(statically) target = this; else { - /* can not use trampoline here */ J3ObjectHandle* self = handle ? handle : inArgs[0].valObject; target = resolve(self); } @@ -195,35 +196,35 @@ J3Value J3Method::internalInvoke(bool st J3Value* args = (J3Value*)alloca(sizeof(J3Value)*methodType()->nbIns()); J3* vm = cl()->loader()->vm(); J3Type* cur; - uint32_t i = 0; + uint32_t i = 0, d = 0; if(handle) - args[i++].valObject = handle; + i = d = 1; - for(; inbIns(); i++) { /* have to avoid collection at this point */ + for(; inbIns(); i++) { cur = methodType()->ins(i); if(cur == vm->typeBoolean) - args[i].valBoolean = va_arg(va, bool); + args[i-d].valBoolean = va_arg(va, bool); else if(cur == vm->typeByte) - args[i].valByte = va_arg(va, int8_t); + args[i-d].valByte = va_arg(va, int8_t); else if(cur == vm->typeShort) - args[i].valShort = va_arg(va, int16_t); + args[i-d].valShort = va_arg(va, int16_t); else if(cur == vm->typeChar) - args[i].valChar = va_arg(va, uint16_t); + args[i-d].valChar = va_arg(va, uint16_t); else if(cur == vm->typeInteger) - args[i].valInteger = va_arg(va, int32_t); + args[i-d].valInteger = va_arg(va, int32_t); else if(cur == vm->typeLong) - args[i].valLong = va_arg(va, int64_t); + args[i-d].valLong = va_arg(va, int64_t); else if(cur == vm->typeFloat) - args[i].valFloat = va_arg(va, float); + args[i-d].valFloat = va_arg(va, float); else if(cur == vm->typeDouble) - args[i].valDouble = va_arg(va, double); + args[i-d].valDouble = va_arg(va, double); else - args[i].valObject = va_arg(va, J3ObjectHandle*); + args[i-d].valObject = va_arg(va, J3ObjectHandle*); } - return internalInvoke(statically, 0, args); + return internalInvoke(statically, handle, args); } J3Value J3Method::invokeStatic(J3Value* args) { From gael.thomas at lip6.fr Fri Dec 27 09:39:52 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Fri, 27 Dec 2013 17:39:52 -0000 Subject: [vmkit-commits] [vmkit] r198077 - Use libunwind to inspect the stack. Message-ID: <20131227173952.CDAED2A6C029@llvm.org> Author: gthomas Date: Fri Dec 27 11:39:52 2013 New Revision: 198077 URL: http://llvm.org/viewvc/llvm-project?rev=198077&view=rev Log: Use libunwind to inspect the stack. Modified: vmkit/branches/mcjit/Makefile.rules vmkit/branches/mcjit/autoconf/configure.ac vmkit/branches/mcjit/configure vmkit/branches/mcjit/include/vmkit/system.h vmkit/branches/mcjit/include/vmkit/thread.h vmkit/branches/mcjit/lib/j3/vm/j3.cc vmkit/branches/mcjit/lib/vmkit/thread.cc Modified: vmkit/branches/mcjit/Makefile.rules URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/Makefile.rules?rev=198077&r1=198076&r2=198077&view=diff ============================================================================== --- vmkit/branches/mcjit/Makefile.rules (original) +++ vmkit/branches/mcjit/Makefile.rules Fri Dec 27 11:39:52 2013 @@ -34,8 +34,7 @@ endif # Compilation flags ############################################################################### COMMON_FLAGS:=-Wall -Wno-return-type-c-linkage -Wno-varargs -Wno-unused-private-field -Werror -Wno-unused-variable \ - -I$(PROJ_SRC_ROOT)/include -I$(OPENJDK_HOME)/include -I$(OPENJDK_HOME)/include/$(OS) $(COMMON_FLAGS) \ - -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer + -I$(PROJ_SRC_ROOT)/include -I$(OPENJDK_HOME)/include -I$(OPENJDK_HOME)/include/$(OS) $(COMMON_FLAGS) ifeq ($(OPTIMIZED),1) COMMON_FLAGS+=-O3 @@ -49,8 +48,11 @@ ifneq ($(DEBUG),0) COMMON_FLAGS+=-g endif -LLCFLAGS+=-disable-cfi -disable-fp-elim -relocation-model=pic -OPTFLAGS+=-disable-cfi -disable-fp-elim -disable-opt +#LLCFLAGS+=-disable-cfi -disable-fp-elim -relocation-model=pic +#OPTFLAGS+=-disable-cfi -disable-fp-elim -disable-opt + +LLCFLAGS+=-relocation-model=pic +OPTFLAGS+=-disable-opt CXXFLAGS=$(LLVM_CXXFLAGS) $(COMMON_FLAGS) -std=gnu++98 -fPIC SHFLAGS=-lpthread -ldl -lz -lncurses -fno-common -Wl,-flat_namespace -Wl,-undefined,suppress Modified: vmkit/branches/mcjit/autoconf/configure.ac URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/autoconf/configure.ac?rev=198077&r1=198076&r2=198077&view=diff ============================================================================== --- vmkit/branches/mcjit/autoconf/configure.ac (original) +++ vmkit/branches/mcjit/autoconf/configure.ac Fri Dec 27 11:39:52 2013 @@ -181,11 +181,7 @@ LLVM_PATH="`$LLVM_CONFIG --bindir`" llvm_cfg=`$LLVM_RUNTIME_CONFIG --cxxflags | sed -e 's/-O3//'` if ! test -z "`echo $llvm_cfg | grep -- -fno-exceptions`"; then - AC_MSG_ERROR([You have to compile LLVM with exception enabled, please compile it with 'make REQUIRES_EH=1 REQUIRES_FRAME_POINTER=1']) -fi - -if ! test -z "`echo $llvm_cfg | grep -- -fomit-frame-pointer`"; then - AC_MSG_ERROR([You have to compile LLVM with frame pointers, please compile it with 'make REQUIRES_EH=1 REQUIRES_FRAME_POINTER=1']) + AC_MSG_ERROR([You have to compile LLVM with exception enabled, please compile it with 'make REQUIRES_EH=1']) fi AC_SUBST(LLVM_CXXFLAGS, [$llvm_cfg" "-I`$LLVM_RUNTIME_CONFIG --src-root`/include]) Modified: vmkit/branches/mcjit/configure URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/configure?rev=198077&r1=198076&r2=198077&view=diff ============================================================================== --- vmkit/branches/mcjit/configure (original) +++ vmkit/branches/mcjit/configure Fri Dec 27 11:39:52 2013 @@ -1,13 +1,11 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.68 for vmkit 0.1. +# Generated by GNU Autoconf 2.69 for vmkit 0.1. # # Report bugs to . # # -# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, -# 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software -# Foundation, Inc. +# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. # # # This configure script is free software; the Free Software Foundation @@ -138,6 +136,31 @@ export LANGUAGE # CDPATH. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH +# Use a proper internal environment variable to ensure we don't fall + # into an infinite loop, continuously re-executing ourselves. + if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then + _as_can_reexec=no; export _as_can_reexec; + # We cannot yet assume a decent shell, so we have to provide a +# neutralization value for shells without unset; and this also +# works around shells that cannot unset nonexistent variables. +# Preserve -v and -x to the replacement shell. +BASH_ENV=/dev/null +ENV=/dev/null +(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV +case $- in # (((( + *v*x* | *x*v* ) as_opts=-vx ;; + *v* ) as_opts=-v ;; + *x* ) as_opts=-x ;; + * ) as_opts= ;; +esac +exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} +# Admittedly, this is quite paranoid, since all the known shells bail +# out after a failed `exec'. +$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 +as_fn_exit 255 + fi + # We don't want this to propagate to other subprocesses. + { _as_can_reexec=; unset _as_can_reexec;} if test "x$CONFIG_SHELL" = x; then as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then : emulate sh @@ -171,7 +194,8 @@ if ( set x; as_fn_ret_success y && test else exitcode=1; echo positional parameters were not saved. fi -test x\$exitcode = x0 || exit 1" +test x\$exitcode = x0 || exit 1 +test -x / || exit 1" as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" && @@ -215,21 +239,25 @@ IFS=$as_save_IFS if test "x$CONFIG_SHELL" != x; then : - # We cannot yet assume a decent shell, so we have to provide a - # neutralization value for shells without unset; and this also - # works around shells that cannot unset nonexistent variables. - # Preserve -v and -x to the replacement shell. - BASH_ENV=/dev/null - ENV=/dev/null - (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV - export CONFIG_SHELL - case $- in # (((( - *v*x* | *x*v* ) as_opts=-vx ;; - *v* ) as_opts=-v ;; - *x* ) as_opts=-x ;; - * ) as_opts= ;; - esac - exec "$CONFIG_SHELL" $as_opts "$as_myself" ${1+"$@"} + export CONFIG_SHELL + # We cannot yet assume a decent shell, so we have to provide a +# neutralization value for shells without unset; and this also +# works around shells that cannot unset nonexistent variables. +# Preserve -v and -x to the replacement shell. +BASH_ENV=/dev/null +ENV=/dev/null +(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV +case $- in # (((( + *v*x* | *x*v* ) as_opts=-vx ;; + *v* ) as_opts=-v ;; + *x* ) as_opts=-x ;; + * ) as_opts= ;; +esac +exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} +# Admittedly, this is quite paranoid, since all the known shells bail +# out after a failed `exec'. +$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 +exit 255 fi if test x$as_have_required = xno; then : @@ -332,6 +360,14 @@ $as_echo X"$as_dir" | } # as_fn_mkdir_p + +# as_fn_executable_p FILE +# ----------------------- +# Test if FILE is an executable regular file. +as_fn_executable_p () +{ + test -f "$1" && test -x "$1" +} # as_fn_executable_p # as_fn_append VAR VALUE # ---------------------- # Append the text in VALUE to the end of the definition contained in VAR. Take @@ -453,6 +489,10 @@ as_cr_alnum=$as_cr_Letters$as_cr_digits chmod +x "$as_me.lineno" || { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } + # If we had to re-execute with $CONFIG_SHELL, we're ensured to have + # already done that, so ensure we don't try to do so again and fall + # in an infinite loop. This has already happened in practice. + _as_can_reexec=no; export _as_can_reexec # Don't try to exec as it changes $[0], causing all sort of problems # (the dirname of $[0] is not the place where we might find the # original and so on. Autoconf is especially sensitive to this). @@ -487,16 +527,16 @@ if (echo >conf$$.file) 2>/dev/null; then # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. - # In both cases, we have to default to `cp -p'. + # In both cases, we have to default to `cp -pR'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || - as_ln_s='cp -p' + as_ln_s='cp -pR' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else - as_ln_s='cp -p' + as_ln_s='cp -pR' fi else - as_ln_s='cp -p' + as_ln_s='cp -pR' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null @@ -508,28 +548,8 @@ else as_mkdir_p=false fi -if test -x / >/dev/null 2>&1; then - as_test_x='test -x' -else - if ls -dL / >/dev/null 2>&1; then - as_ls_L_option=L - else - as_ls_L_option= - fi - as_test_x=' - eval sh -c '\'' - if test -d "$1"; then - test -d "$1/."; - else - case $1 in #( - -*)set "./$1";; - esac; - case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #(( - ???[sx]*):;;*)false;;esac;fi - '\'' sh - ' -fi -as_executable_p=$as_test_x +as_test_x='test -x' +as_executable_p=as_fn_executable_p # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" @@ -1126,8 +1146,6 @@ target=$target_alias if test "x$host_alias" != x; then if test "x$build_alias" = x; then cross_compiling=maybe - $as_echo "$as_me: WARNING: if you wanted to set the --build type, don't use --host. - If a cross compiler is detected then cross compile mode will be used" >&2 elif test "x$build_alias" != "x$host_alias"; then cross_compiling=yes fi @@ -1381,9 +1399,9 @@ test -n "$ac_init_help" && exit $ac_stat if $ac_init_version; then cat <<\_ACEOF vmkit configure 0.1 -generated by GNU Autoconf 2.68 +generated by GNU Autoconf 2.69 -Copyright (C) 2010 Free Software Foundation, Inc. +Copyright (C) 2012 Free Software Foundation, Inc. This configure script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. @@ -1475,7 +1493,7 @@ This file contains any messages produced running configure, to aid debugging if configure makes a mistake. It was created by vmkit $as_me 0.1, which was -generated by GNU Autoconf 2.68. Invocation command line was +generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -2123,11 +2141,7 @@ LLVM_PATH="`$LLVM_CONFIG --bindir`" llvm_cfg=`$LLVM_RUNTIME_CONFIG --cxxflags | sed -e 's/-O3//'` if ! test -z "`echo $llvm_cfg | grep -- -fno-exceptions`"; then - as_fn_error $? "You have to compile LLVM with exception enabled, please compile it with 'make REQUIRES_EH=1 REQUIRES_FRAME_POINTER=1'" "$LINENO" 5 -fi - -if ! test -z "`echo $llvm_cfg | grep -- -fomit-frame-pointer`"; then - as_fn_error $? "You have to compile LLVM with frame pointers, please compile it with 'make REQUIRES_EH=1 REQUIRES_FRAME_POINTER=1'" "$LINENO" 5 + as_fn_error $? "You have to compile LLVM with exception enabled, please compile it with 'make REQUIRES_EH=1'" "$LINENO" 5 fi LLVM_CXXFLAGS=$llvm_cfg" "-I`$LLVM_RUNTIME_CONFIG --src-root`/include @@ -2192,7 +2206,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_CC="${ac_tool_prefix}gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2232,7 +2246,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_CC="gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2285,7 +2299,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_CC="${ac_tool_prefix}cc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2326,7 +2340,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then ac_prog_rejected=yes continue @@ -2384,7 +2398,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_CC="$ac_tool_prefix$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2428,7 +2442,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_CC="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2874,8 +2888,7 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ /* end confdefs.h. */ #include #include -#include -#include +struct stat; /* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ struct buf { int x; }; FILE * (*rcsopen) (struct buf *, struct stat *, int); @@ -3134,7 +3147,7 @@ case $as_dir/ in #(( # by default. for ac_prog in ginstall scoinst install; do for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; }; then + if as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext"; then if test $ac_prog = install && grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then # AIX install. It has an incompatible calling convention. @@ -3214,7 +3227,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_path_LLC="$as_dir/$ac_word$ac_exec_ext" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3262,7 +3275,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_path_LLOPT="$as_dir/$ac_word$ac_exec_ext" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3310,7 +3323,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_path_LLLINK="$as_dir/$ac_word$ac_exec_ext" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3358,7 +3371,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_path_LLNM="$as_dir/$ac_word$ac_exec_ext" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3406,7 +3419,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_path_CLANG="$as_dir/$ac_word$ac_exec_ext" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3454,7 +3467,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_path_CLANGXX="$as_dir/$ac_word$ac_exec_ext" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3502,7 +3515,7 @@ do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_path_GAWK="$as_dir/$ac_word$ac_exec_ext" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -3987,16 +4000,16 @@ if (echo >conf$$.file) 2>/dev/null; then # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. - # In both cases, we have to default to `cp -p'. + # In both cases, we have to default to `cp -pR'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || - as_ln_s='cp -p' + as_ln_s='cp -pR' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else - as_ln_s='cp -p' + as_ln_s='cp -pR' fi else - as_ln_s='cp -p' + as_ln_s='cp -pR' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null @@ -4056,28 +4069,16 @@ else as_mkdir_p=false fi -if test -x / >/dev/null 2>&1; then - as_test_x='test -x' -else - if ls -dL / >/dev/null 2>&1; then - as_ls_L_option=L - else - as_ls_L_option= - fi - as_test_x=' - eval sh -c '\'' - if test -d "$1"; then - test -d "$1/."; - else - case $1 in #( - -*)set "./$1";; - esac; - case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #(( - ???[sx]*):;;*)false;;esac;fi - '\'' sh - ' -fi -as_executable_p=$as_test_x + +# as_fn_executable_p FILE +# ----------------------- +# Test if FILE is an executable regular file. +as_fn_executable_p () +{ + test -f "$1" && test -x "$1" +} # as_fn_executable_p +as_test_x='test -x' +as_executable_p=as_fn_executable_p # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" @@ -4099,7 +4100,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_wri # values after options handling. ac_log=" This file was extended by vmkit $as_me 0.1, which was -generated by GNU Autoconf 2.68. Invocation command line was +generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES CONFIG_HEADERS = $CONFIG_HEADERS @@ -4152,10 +4153,10 @@ cat >>$CONFIG_STATUS <<_ACEOF || ac_writ ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ vmkit config.status 0.1 -configured by $0, generated by GNU Autoconf 2.68, +configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" -Copyright (C) 2010 Free Software Foundation, Inc. +Copyright (C) 2012 Free Software Foundation, Inc. This config.status script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it." @@ -4233,7 +4234,7 @@ fi _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 if \$ac_cs_recheck; then - set X '$SHELL' '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion + set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion shift \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6 CONFIG_SHELL='$SHELL' Modified: vmkit/branches/mcjit/include/vmkit/system.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/system.h?rev=198077&r1=198076&r2=198077&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/system.h (original) +++ vmkit/branches/mcjit/include/vmkit/system.h Fri Dec 27 11:39:52 2013 @@ -33,18 +33,6 @@ namespace vmkit { #error "what is the correct symbol for your os?" #endif } - - static void** current_fp() __attribute__((always_inline)) { - return (void**)__builtin_frame_address(0); - } - - static void** fp_to_next_fp(void** fp) { - return (void**)fp[0]; - } - - static void* fp_to_ip(void**fp) { - return fp[1]; - } }; } Modified: vmkit/branches/mcjit/include/vmkit/thread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/thread.h?rev=198077&r1=198076&r2=198077&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/thread.h (original) +++ vmkit/branches/mcjit/include/vmkit/thread.h Fri Dec 27 11:39:52 2013 @@ -1,6 +1,9 @@ #ifndef _THREAD_H_ #define _THREAD_H_ +#define UNW_LOCAL_ONLY +#include + #include "vmkit/allocator.h" namespace vmkit { @@ -11,7 +14,6 @@ namespace vmkit { BumpAllocator* _allocator; VMKit* _vm; - void* _baseFramePointer; entryPoint_t _entryPoint; static void* doRun(void* thread); @@ -22,9 +24,6 @@ namespace vmkit { public: static void destroy(Thread* thread); - void setBaseFramePointer(void* fp) { _baseFramePointer = fp; } - void* baseFramePointer() { return _baseFramePointer; } - VMKit* vm() { return _vm; } BumpAllocator* allocator() { return _allocator; } @@ -37,14 +36,15 @@ namespace vmkit { }; class StackWalker { - void** framePointer; + unw_cursor_t cursor; + unw_context_t uc; public: StackWalker(uint32_t initialPop=0) __attribute__((noinline)); bool next(uint32_t nbPop=1); void* ip(); - void* fp() { return framePointer; } + void* sp(); }; } Modified: vmkit/branches/mcjit/lib/j3/vm/j3.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3.cc?rev=198077&r1=198076&r2=198077&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3.cc Fri Dec 27 11:39:52 2013 @@ -66,8 +66,6 @@ void J3::start(int argc, char** argv) { J3Thread* thread = J3Thread::create(this); - thread->setBaseFramePointer(vmkit::System::current_fp()); - vmkitBootstrap(thread, options()->selfBitCodePath); introspect(); Modified: vmkit/branches/mcjit/lib/vmkit/thread.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/thread.cc?rev=198077&r1=198076&r2=198077&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/thread.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/thread.cc Fri Dec 27 11:39:52 2013 @@ -1,5 +1,6 @@ #include "vmkit/thread.h" #include "vmkit/system.h" +#include "vmkit/vmkit.h" using namespace vmkit; @@ -8,7 +9,6 @@ __thread Thread* Thread::_thread = 0; Thread::Thread(VMKit* vm, BumpAllocator* allocator) { _allocator = allocator; _vm = vm; - _baseFramePointer = 0; } void Thread::destroy(Thread* thread) { @@ -29,19 +29,27 @@ void Thread::start(entryPoint_t entryPoi } StackWalker::StackWalker(uint32_t initialPop) { - framePointer = System::current_fp(); + unw_getcontext(&uc); + unw_init_local(&cursor, &uc); next(initialPop+1); } bool StackWalker::next(uint32_t nbPop) { while(nbPop--) { - if(framePointer == Thread::get()->baseFramePointer()) + if(unw_step(&cursor) <= 0) return 0; - framePointer = (void**)System::fp_to_next_fp(framePointer); } - return framePointer != Thread::get()->baseFramePointer(); + return 1; } void* StackWalker::ip() { - return System::fp_to_ip(framePointer); + unw_word_t ip; + unw_get_reg(&cursor, UNW_REG_IP, &ip); + return (void*)ip; +} + +void* StackWalker::sp() { + unw_word_t sp; + unw_get_reg(&cursor, UNW_REG_SP, &sp); + return (void*)sp; } From gael.thomas at lip6.fr Fri Dec 27 16:33:17 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sat, 28 Dec 2013 00:33:17 -0000 Subject: [vmkit-commits] [vmkit] r198090 - simplify thread::start Message-ID: <20131228003317.EA61B2A6C029@llvm.org> Author: gthomas Date: Fri Dec 27 18:33:17 2013 New Revision: 198090 URL: http://llvm.org/viewvc/llvm-project?rev=198090&view=rev Log: simplify thread::start Modified: vmkit/branches/mcjit/include/j3/j3thread.h vmkit/branches/mcjit/include/vmkit/thread.h vmkit/branches/mcjit/lib/j3/vm/j3thread.cc vmkit/branches/mcjit/lib/vmkit/thread.cc Modified: vmkit/branches/mcjit/include/j3/j3thread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3thread.h?rev=198090&r1=198089&r2=198090&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3thread.h (original) +++ vmkit/branches/mcjit/include/j3/j3thread.h Fri Dec 27 18:33:17 2013 @@ -19,12 +19,13 @@ namespace j3 { private: uint32_t _interfaceMethodIndex; - vmkit::BumpAllocator* allocator; + vmkit::BumpAllocator* _allocator; JNIEnv _jniEnv; J3LocalReferences _localReferences; J3ObjectHandle* _pendingException; J3ObjectHandle* _javaThread; + virtual void run(); static void doRun(); J3Thread(J3* vm, vmkit::BumpAllocator* allocator); Modified: vmkit/branches/mcjit/include/vmkit/thread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/thread.h?rev=198090&r1=198089&r2=198090&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/thread.h (original) +++ vmkit/branches/mcjit/include/vmkit/thread.h Fri Dec 27 18:33:17 2013 @@ -10,11 +10,8 @@ namespace vmkit { class VMKit; class Thread : protected PermanentObject { - typedef void (*entryPoint_t)(); - BumpAllocator* _allocator; VMKit* _vm; - entryPoint_t _entryPoint; static void* doRun(void* thread); @@ -24,6 +21,8 @@ namespace vmkit { public: static void destroy(Thread* thread); + virtual void run() {} + VMKit* vm() { return _vm; } BumpAllocator* allocator() { return _allocator; } @@ -32,7 +31,7 @@ namespace vmkit { static Thread* get() { return _thread; } static void set(Thread* thread) { _thread = thread; } - static void start(entryPoint_t entryPoint, Thread* thread); + void start(); }; class StackWalker { Modified: vmkit/branches/mcjit/lib/j3/vm/j3thread.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3thread.cc?rev=198090&r1=198089&r2=198090&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3thread.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3thread.cc Fri Dec 27 18:33:17 2013 @@ -10,7 +10,8 @@ using namespace j3; J3Thread::J3Thread(J3* vm, vmkit::BumpAllocator* allocator) : Thread(vm, allocator), - _localReferences(allocator) { + _allocator(allocator), + _localReferences(_allocator) { _jniEnv.functions = &jniEnvTable; } @@ -24,10 +25,15 @@ void J3Thread::doRun() { get()->vm()->threadRun->invokeVirtual(handle); } +void J3Thread::run() { + J3ObjectHandle* handle = javaThread(); + vm()->threadRun->invokeVirtual(handle); +} + void J3Thread::start(J3ObjectHandle* handle) { J3Thread* thread = create(J3Thread::get()->vm()); thread->assocJavaThread(handle); - Thread::start(doRun, thread); + thread->Thread::start(); while(1); } Modified: vmkit/branches/mcjit/lib/vmkit/thread.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/thread.cc?rev=198090&r1=198089&r2=198090&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/thread.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/thread.cc Fri Dec 27 18:33:17 2013 @@ -18,14 +18,13 @@ void Thread::destroy(Thread* thread) { void* Thread::doRun(void* _thread) { Thread* thread = (Thread*)_thread; set(thread); - thread->_entryPoint(); + thread->run(); return 0; } -void Thread::start(entryPoint_t entryPoint, Thread* thread) { - thread->_entryPoint = entryPoint; +void Thread::start() { pthread_t tid; - pthread_create(&tid, 0, doRun, thread); + pthread_create(&tid, 0, doRun, this); } StackWalker::StackWalker(uint32_t initialPop) { From gael.thomas at lip6.fr Sat Dec 28 00:58:30 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sat, 28 Dec 2013 08:58:30 -0000 Subject: [vmkit-commits] [vmkit] r198106 - simplify thread allocation Message-ID: <20131228085830.914BF2A6C029@llvm.org> Author: gthomas Date: Sat Dec 28 02:58:30 2013 New Revision: 198106 URL: http://llvm.org/viewvc/llvm-project?rev=198106&view=rev Log: simplify thread allocation Modified: vmkit/branches/mcjit/include/j3/j3.h vmkit/branches/mcjit/include/j3/j3thread.h vmkit/branches/mcjit/include/vmkit/thread.h vmkit/branches/mcjit/lib/j3/vm/j3.cc vmkit/branches/mcjit/lib/j3/vm/j3thread.cc vmkit/branches/mcjit/lib/vmkit/thread.cc Modified: vmkit/branches/mcjit/include/j3/j3.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3.h?rev=198106&r1=198105&r2=198106&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3.h (original) +++ vmkit/branches/mcjit/include/j3/j3.h Sat Dec 28 02:58:30 2013 @@ -97,6 +97,7 @@ namespace j3 { J3ObjectHandle* nameToString(const vmkit::Name* name); J3ObjectHandle* arrayToString(J3ObjectHandle* array); + void run(); void start(int argc, char** argv); void vinternalError(const wchar_t* msg, va_list va) __attribute__((noreturn)); Modified: vmkit/branches/mcjit/include/j3/j3thread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3thread.h?rev=198106&r1=198105&r2=198106&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3thread.h (original) +++ vmkit/branches/mcjit/include/j3/j3thread.h Sat Dec 28 02:58:30 2013 @@ -28,9 +28,8 @@ namespace j3 { virtual void run(); static void doRun(); - J3Thread(J3* vm, vmkit::BumpAllocator* allocator); public: - static J3Thread* create(J3* j3); + J3Thread(J3* vm, vmkit::BumpAllocator* allocator); void assocJavaThread(J3ObjectHandle* javaThread); J3ObjectHandle* javaThread() { return _javaThread; } @@ -58,6 +57,13 @@ namespace j3 { static void start(J3ObjectHandle* handle); }; + + class J3ThreadBootstrap : public J3Thread { + public: + J3ThreadBootstrap(J3* j3, vmkit::BumpAllocator* allocator); + + void run(); + }; } #endif Modified: vmkit/branches/mcjit/include/vmkit/thread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/thread.h?rev=198106&r1=198105&r2=198106&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/thread.h (original) +++ vmkit/branches/mcjit/include/vmkit/thread.h Sat Dec 28 02:58:30 2013 @@ -10,21 +10,21 @@ namespace vmkit { class VMKit; class Thread : protected PermanentObject { - BumpAllocator* _allocator; VMKit* _vm; + pthread_t _tid; static void* doRun(void* thread); - protected: - Thread(VMKit* vm, BumpAllocator* allocator); - public: - static void destroy(Thread* thread); + Thread(VMKit* vm); + virtual ~Thread() {} + + void* operator new(size_t n, BumpAllocator* allocator); + void operator delete(void* p); virtual void run() {} VMKit* vm() { return _vm; } - BumpAllocator* allocator() { return _allocator; } static __thread Thread* _thread; @@ -32,6 +32,7 @@ namespace vmkit { static void set(Thread* thread) { _thread = thread; } void start(); + void join(); }; class StackWalker { Modified: vmkit/branches/mcjit/lib/j3/vm/j3.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3.cc?rev=198106&r1=198105&r2=198106&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3.cc Sat Dec 28 02:58:30 2013 @@ -64,10 +64,17 @@ void J3::introspect() { void J3::start(int argc, char** argv) { _options.process(argc, argv); - J3Thread* thread = J3Thread::create(this); + vmkit::BumpAllocator* threadAllocator = vmkit::BumpAllocator::create(); + J3Thread* thread = new(threadAllocator) J3ThreadBootstrap(this, threadAllocator); vmkitBootstrap(thread, options()->selfBitCodePath); + + //thread->start(); + //thread->join(); + run(); +} +void J3::run() { introspect(); vmkit::BumpAllocator* loaderAllocator = vmkit::BumpAllocator::create(); Modified: vmkit/branches/mcjit/lib/j3/vm/j3thread.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3thread.cc?rev=198106&r1=198105&r2=198106&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3thread.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3thread.cc Sat Dec 28 02:58:30 2013 @@ -9,17 +9,12 @@ using namespace j3; J3Thread::J3Thread(J3* vm, vmkit::BumpAllocator* allocator) : - Thread(vm, allocator), + Thread(vm), _allocator(allocator), _localReferences(_allocator) { _jniEnv.functions = &jniEnvTable; } -J3Thread* J3Thread::create(J3* j3) { - vmkit::BumpAllocator* allocator = vmkit::BumpAllocator::create(); - return new(allocator) J3Thread(j3, allocator); -} - void J3Thread::doRun() { J3ObjectHandle* handle = get()->javaThread(); get()->vm()->threadRun->invokeVirtual(handle); @@ -31,7 +26,8 @@ void J3Thread::run() { } void J3Thread::start(J3ObjectHandle* handle) { - J3Thread* thread = create(J3Thread::get()->vm()); + vmkit::BumpAllocator* allocator = vmkit::BumpAllocator::create(); + J3Thread* thread = new(allocator) J3Thread(get()->vm(), allocator); thread->assocJavaThread(handle); thread->Thread::start(); while(1); @@ -90,3 +86,10 @@ void J3Thread::restore(J3ObjectHandle* p J3Thread* J3Thread::get() { return (J3Thread*)Thread::get(); } + +J3ThreadBootstrap::J3ThreadBootstrap(J3* vm, vmkit::BumpAllocator* allocator) : J3Thread(vm, allocator) { +} + +void J3ThreadBootstrap::run() { + vm()->run(); +} Modified: vmkit/branches/mcjit/lib/vmkit/thread.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/thread.cc?rev=198106&r1=198105&r2=198106&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/thread.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/thread.cc Sat Dec 28 02:58:30 2013 @@ -6,13 +6,16 @@ using namespace vmkit; __thread Thread* Thread::_thread = 0; -Thread::Thread(VMKit* vm, BumpAllocator* allocator) { - _allocator = allocator; +Thread::Thread(VMKit* vm) { _vm = vm; } -void Thread::destroy(Thread* thread) { - BumpAllocator::destroy(thread->allocator()); +void* Thread::operator new(size_t n, BumpAllocator* allocator) { + return allocator->allocate(n); +} + +void Thread::operator delete(void* p) { + VMKit::internalError(L"not yet implemented"); } void* Thread::doRun(void* _thread) { @@ -23,8 +26,12 @@ void* Thread::doRun(void* _thread) { } void Thread::start() { - pthread_t tid; - pthread_create(&tid, 0, doRun, this); + pthread_create(&_tid, 0, doRun, this); +} + +void Thread::join() { + void* res; + pthread_join(_tid, &res); } StackWalker::StackWalker(uint32_t initialPop) { From gael.thomas at lip6.fr Sat Dec 28 01:06:19 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sat, 28 Dec 2013 09:06:19 -0000 Subject: [vmkit-commits] [vmkit] r198107 - Bootstrap j3 in a different thread Message-ID: <20131228090621.11EAF2A6C029@llvm.org> Author: gthomas Date: Sat Dec 28 03:06:18 2013 New Revision: 198107 URL: http://llvm.org/viewvc/llvm-project?rev=198107&view=rev Log: Bootstrap j3 in a different thread Modified: vmkit/branches/mcjit/Makefile.rules vmkit/branches/mcjit/lib/j3/vm/j3.cc Modified: vmkit/branches/mcjit/Makefile.rules URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/Makefile.rules?rev=198107&r1=198106&r2=198107&view=diff ============================================================================== --- vmkit/branches/mcjit/Makefile.rules (original) +++ vmkit/branches/mcjit/Makefile.rules Sat Dec 28 03:06:18 2013 @@ -55,7 +55,7 @@ LLCFLAGS+=-relocation-model=pic OPTFLAGS+=-disable-opt CXXFLAGS=$(LLVM_CXXFLAGS) $(COMMON_FLAGS) -std=gnu++98 -fPIC -SHFLAGS=-lpthread -ldl -lz -lncurses -fno-common -Wl,-flat_namespace -Wl,-undefined,suppress +SHFLAGS=-lpthread -ldl -lz -lncurses -framework CoreFoundation -fno-common -Wl,-flat_namespace -Wl,-undefined,suppress ############################################################################### # Targets Modified: vmkit/branches/mcjit/lib/j3/vm/j3.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3.cc?rev=198107&r1=198106&r2=198107&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3.cc Sat Dec 28 03:06:18 2013 @@ -69,12 +69,12 @@ void J3::start(int argc, char** argv) { vmkitBootstrap(thread, options()->selfBitCodePath); - //thread->start(); - //thread->join(); - run(); + thread->Thread::start(); + thread->join(); } void J3::run() { + fprintf(stderr, " Bootstraping j3....\n"); introspect(); vmkit::BumpAllocator* loaderAllocator = vmkit::BumpAllocator::create(); From gael.thomas at lip6.fr Sat Dec 28 02:23:48 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sat, 28 Dec 2013 10:23:48 -0000 Subject: [vmkit-commits] [vmkit] r198109 - allocate my thread through a custom allocator Message-ID: <20131228102348.2FB432A6C029@llvm.org> Author: gthomas Date: Sat Dec 28 04:23:47 2013 New Revision: 198109 URL: http://llvm.org/viewvc/llvm-project?rev=198109&view=rev Log: allocate my thread through a custom allocator Modified: vmkit/branches/mcjit/include/j3/j3options.h vmkit/branches/mcjit/include/vmkit/allocator.h vmkit/branches/mcjit/include/vmkit/thread.h vmkit/branches/mcjit/include/vmkit/vmkit.h vmkit/branches/mcjit/lib/j3/vm/j3.cc vmkit/branches/mcjit/lib/j3/vm/j3options.cc vmkit/branches/mcjit/lib/vmkit/allocator.cc vmkit/branches/mcjit/lib/vmkit/thread.cc vmkit/branches/mcjit/lib/vmkit/vmkit.cc Modified: vmkit/branches/mcjit/include/j3/j3options.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3options.h?rev=198109&r1=198108&r2=198109&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3options.h (original) +++ vmkit/branches/mcjit/include/j3/j3options.h Sat Dec 28 04:23:47 2013 @@ -34,6 +34,8 @@ namespace j3 { uint32_t debugIniting; uint32_t debugTranslate; uint32_t debugLinking; + + uintptr_t stackSize; J3Options(); Modified: vmkit/branches/mcjit/include/vmkit/allocator.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/allocator.h?rev=198109&r1=198108&r2=198109&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/allocator.h (original) +++ vmkit/branches/mcjit/include/vmkit/allocator.h Sat Dec 28 04:23:47 2013 @@ -13,6 +13,7 @@ #include #include #include +#include namespace vmkit { class BumpAllocatorNode { /* always the first bytes of a bucket */ @@ -114,6 +115,31 @@ namespace vmkit { struct T_ptr_less_t : public PermanentObject { bool operator()(const T& lhs, const T& rhs) const { return lhs < rhs; } }; + + class ThreadAllocator { + static const uint32_t refill = 128; + + static ThreadAllocator* _allocator; + + pthread_mutex_t mutex; + std::vector spaces; + std::vector freeThreads; + uintptr_t baseStack; + uintptr_t topStack; + + ThreadAllocator(uintptr_t minThreadStruct, uintptr_t minFullSize); + public: + static void initialize(uintptr_t minThreadStruct, uintptr_t minFullSize); + static ThreadAllocator* allocator() { return _allocator; } + + void* allocate(); + void release(void* thread); + + void* stackAddr(void* thread); + size_t stackSize(void* thread); + + uintptr_t magic() { return -topStack; } + }; } // end namespace vmkit #endif // VMKIT_ALLOCATOR_H Modified: vmkit/branches/mcjit/include/vmkit/thread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/thread.h?rev=198109&r1=198108&r2=198109&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/thread.h (original) +++ vmkit/branches/mcjit/include/vmkit/thread.h Sat Dec 28 04:23:47 2013 @@ -9,7 +9,7 @@ namespace vmkit { class VMKit; - class Thread : protected PermanentObject { + class Thread { VMKit* _vm; pthread_t _tid; Modified: vmkit/branches/mcjit/include/vmkit/vmkit.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/vmkit.h?rev=198109&r1=198108&r2=198109&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/vmkit.h (original) +++ vmkit/branches/mcjit/include/vmkit/vmkit.h Sat Dec 28 04:23:47 2013 @@ -17,30 +17,21 @@ namespace vmkit { class Thread; class Safepoint; - class ExceptionDescriptor { /* managed with malloc/free */ - const llvm::Function* _llvmFunction; - uintptr_t _point; - uintptr_t _landingPad; - public: - ExceptionDescriptor(const llvm::Function* llvmFunction, uintptr_t point, uintptr_t landingPad); - }; - class VMKit { typedef std::map > > MangleMap; - std::map safepointMap; - pthread_mutex_t safepointMapLock; - std::map exceptionTable; /* managed with malloc/free */ - MangleMap mangleMap; - BumpAllocator* _allocator; - llvm::Module* _self; - llvm::DataLayout* _dataLayout; - void* ptrTypeInfo; + std::map safepointMap; + pthread_mutex_t safepointMapLock; + MangleMap mangleMap; + BumpAllocator* _allocator; + llvm::Module* _self; + llvm::DataLayout* _dataLayout; + void* ptrTypeInfo; - void addSymbol(llvm::GlobalValue* gv); + void addSymbol(llvm::GlobalValue* gv); - static void defaultInternalError(const wchar_t* msg, va_list va) __attribute__((noreturn)); + static void defaultInternalError(const wchar_t* msg, va_list va) __attribute__((noreturn)); protected: void* operator new(size_t n, BumpAllocator* allocator); Modified: vmkit/branches/mcjit/lib/j3/vm/j3.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3.cc?rev=198109&r1=198108&r2=198109&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3.cc Sat Dec 28 04:23:47 2013 @@ -64,17 +64,16 @@ void J3::introspect() { void J3::start(int argc, char** argv) { _options.process(argc, argv); + vmkit::ThreadAllocator::initialize(sizeof(J3Thread), options()->stackSize); + vmkit::BumpAllocator* threadAllocator = vmkit::BumpAllocator::create(); J3Thread* thread = new(threadAllocator) J3ThreadBootstrap(this, threadAllocator); - vmkitBootstrap(thread, options()->selfBitCodePath); - - thread->Thread::start(); - thread->join(); + + vmkitBootstrap(thread, options()->selfBitCodePath); } void J3::run() { - fprintf(stderr, " Bootstraping j3....\n"); introspect(); vmkit::BumpAllocator* loaderAllocator = vmkit::BumpAllocator::create(); Modified: vmkit/branches/mcjit/lib/j3/vm/j3options.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3options.cc?rev=198109&r1=198108&r2=198109&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3options.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3options.cc Sat Dec 28 04:23:47 2013 @@ -23,6 +23,8 @@ J3Options::J3Options() { debugLinking = 1; genDebugExecute = debugExecute ? 1 : 0; + + stackSize = 0x80*0x1000; } #define nyi(cmd) ({ fprintf(stderr, "option '%s' not yet implemented\n", cmd); }) Modified: vmkit/branches/mcjit/lib/vmkit/allocator.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/allocator.cc?rev=198109&r1=198108&r2=198109&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/allocator.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/allocator.cc Sat Dec 28 04:23:47 2013 @@ -8,6 +8,8 @@ using namespace vmkit; +ThreadAllocator* ThreadAllocator::_allocator = 0; + void* BumpAllocator::operator new(size_t n) { return (void*)((uintptr_t)map(bucketSize) + sizeof(BumpAllocatorNode)); } @@ -91,3 +93,68 @@ void PermanentObject::operator delete(vo void PermanentObject::operator delete[](void* ptr) { Thread::get()->vm()->internalError(L"should not happen"); } + +ThreadAllocator::ThreadAllocator(uintptr_t minThreadStruct, uintptr_t minFullSize) { + pthread_mutex_init(&mutex, 0); + spaces.reserve(1); + freeThreads.reserve(refill); + + minThreadStruct = ((minThreadStruct - 1) & -PAGE_SIZE) + PAGE_SIZE; + baseStack = minThreadStruct; + + uintptr_t min = PTHREAD_STACK_MIN + minThreadStruct + PAGE_SIZE; + if(minFullSize < min) + minFullSize = min; + + topStack = 1L << (__builtin_clzl(0) - __builtin_clzl(minFullSize-1)); +} + +void ThreadAllocator::initialize(uintptr_t minThreadStruct, uintptr_t minFullSize) { + if(_allocator) { + fprintf(stderr, "Never try to modify the thread structure layout dynamically\n"); + abort(); + } + _allocator = new ThreadAllocator(minThreadStruct, minFullSize); +} + +void* ThreadAllocator::allocate() { + pthread_mutex_lock(&mutex); + if(!freeThreads.size()) { + void* space = mmap(0, topStack*refill, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0); + + if(space == MAP_FAILED) { + fprintf(stderr, "unable to allocate a thread\n"); + abort(); + } + + spaces.push_back(space); + + uintptr_t base = (((uintptr_t)space - 1) & -PAGE_SIZE) + PAGE_SIZE; + uint32_t n = (base == (uintptr_t)space) ? refill : (refill - 1); + + for(uint32_t i=0; iallocate(n); + return ThreadAllocator::allocator()->allocate(); } void Thread::operator delete(void* p) { Modified: vmkit/branches/mcjit/lib/vmkit/vmkit.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/vmkit.cc?rev=198109&r1=198108&r2=198109&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/vmkit.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/vmkit.cc Sat Dec 28 04:23:47 2013 @@ -124,6 +124,9 @@ void VMKit::vmkitBootstrap(Thread* initi if(!ptrTypeInfo) internalError(L"unable to find typeinfo for void*"); + + initialThread->start(); + initialThread->join(); } @@ -172,10 +175,3 @@ void VMKit::throwException(void* obj) { fprintf(stderr, " throw exception...\n"); abort(); } - - -ExceptionDescriptor::ExceptionDescriptor(const llvm::Function* llvmFunction, uintptr_t point, uintptr_t landingPad) { - _llvmFunction = llvmFunction; - _point = point; - _landingPad = landingPad; -} From gael.thomas at lip6.fr Sat Dec 28 02:28:11 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sat, 28 Dec 2013 10:28:11 -0000 Subject: [vmkit-commits] [vmkit] r198110 - remove the useless vmkit::BumpAllocator from vmkit::Thread Message-ID: <20131228102811.7FE102A6C029@llvm.org> Author: gthomas Date: Sat Dec 28 04:28:11 2013 New Revision: 198110 URL: http://llvm.org/viewvc/llvm-project?rev=198110&view=rev Log: remove the useless vmkit::BumpAllocator from vmkit::Thread Modified: vmkit/branches/mcjit/include/j3/j3thread.h vmkit/branches/mcjit/include/vmkit/thread.h vmkit/branches/mcjit/lib/j3/vm/j3.cc vmkit/branches/mcjit/lib/j3/vm/j3thread.cc vmkit/branches/mcjit/lib/vmkit/thread.cc Modified: vmkit/branches/mcjit/include/j3/j3thread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3thread.h?rev=198110&r1=198109&r2=198110&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3thread.h (original) +++ vmkit/branches/mcjit/include/j3/j3thread.h Sat Dec 28 04:28:11 2013 @@ -29,7 +29,8 @@ namespace j3 { static void doRun(); public: - J3Thread(J3* vm, vmkit::BumpAllocator* allocator); + J3Thread(J3* vm); + ~J3Thread(); void assocJavaThread(J3ObjectHandle* javaThread); J3ObjectHandle* javaThread() { return _javaThread; } @@ -60,7 +61,7 @@ namespace j3 { class J3ThreadBootstrap : public J3Thread { public: - J3ThreadBootstrap(J3* j3, vmkit::BumpAllocator* allocator); + J3ThreadBootstrap(J3* j3); void run(); }; Modified: vmkit/branches/mcjit/include/vmkit/thread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/thread.h?rev=198110&r1=198109&r2=198110&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/thread.h (original) +++ vmkit/branches/mcjit/include/vmkit/thread.h Sat Dec 28 04:28:11 2013 @@ -19,7 +19,7 @@ namespace vmkit { Thread(VMKit* vm); virtual ~Thread() {} - void* operator new(size_t n, BumpAllocator* allocator); + void* operator new(size_t n); void operator delete(void* p); virtual void run() {} Modified: vmkit/branches/mcjit/lib/j3/vm/j3.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3.cc?rev=198110&r1=198109&r2=198110&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3.cc Sat Dec 28 04:28:11 2013 @@ -66,9 +66,7 @@ void J3::start(int argc, char** argv) { vmkit::ThreadAllocator::initialize(sizeof(J3Thread), options()->stackSize); - vmkit::BumpAllocator* threadAllocator = vmkit::BumpAllocator::create(); - J3Thread* thread = new(threadAllocator) J3ThreadBootstrap(this, threadAllocator); - + J3Thread* thread = new J3ThreadBootstrap(this); vmkitBootstrap(thread, options()->selfBitCodePath); } Modified: vmkit/branches/mcjit/lib/j3/vm/j3thread.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3thread.cc?rev=198110&r1=198109&r2=198110&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3thread.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3thread.cc Sat Dec 28 04:28:11 2013 @@ -8,13 +8,17 @@ using namespace j3; -J3Thread::J3Thread(J3* vm, vmkit::BumpAllocator* allocator) : +J3Thread::J3Thread(J3* vm) : Thread(vm), - _allocator(allocator), + _allocator(vmkit::BumpAllocator::create()), _localReferences(_allocator) { _jniEnv.functions = &jniEnvTable; } +J3Thread::~J3Thread() { + vmkit::BumpAllocator::destroy(_allocator); +} + void J3Thread::doRun() { J3ObjectHandle* handle = get()->javaThread(); get()->vm()->threadRun->invokeVirtual(handle); @@ -27,7 +31,7 @@ void J3Thread::run() { void J3Thread::start(J3ObjectHandle* handle) { vmkit::BumpAllocator* allocator = vmkit::BumpAllocator::create(); - J3Thread* thread = new(allocator) J3Thread(get()->vm(), allocator); + J3Thread* thread = new J3Thread(get()->vm()); thread->assocJavaThread(handle); thread->Thread::start(); while(1); @@ -87,7 +91,7 @@ J3Thread* J3Thread::get() { return (J3Thread*)Thread::get(); } -J3ThreadBootstrap::J3ThreadBootstrap(J3* vm, vmkit::BumpAllocator* allocator) : J3Thread(vm, allocator) { +J3ThreadBootstrap::J3ThreadBootstrap(J3* vm) : J3Thread(vm) { } void J3ThreadBootstrap::run() { Modified: vmkit/branches/mcjit/lib/vmkit/thread.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/thread.cc?rev=198110&r1=198109&r2=198110&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/thread.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/thread.cc Sat Dec 28 04:28:11 2013 @@ -10,12 +10,12 @@ Thread::Thread(VMKit* vm) { _vm = vm; } -void* Thread::operator new(size_t n, BumpAllocator* allocator) { +void* Thread::operator new(size_t n) { return ThreadAllocator::allocator()->allocate(); } void Thread::operator delete(void* p) { - VMKit::internalError(L"not yet implemented"); + ThreadAllocator::allocator()->release(p); } void* Thread::doRun(void* _thread) { From gael.thomas at lip6.fr Sat Dec 28 02:41:15 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sat, 28 Dec 2013 10:41:15 -0000 Subject: [vmkit-commits] [vmkit] r198111 - execute on my custom stacks Message-ID: <20131228104115.DD3222A6C029@llvm.org> Author: gthomas Date: Sat Dec 28 04:41:15 2013 New Revision: 198111 URL: http://llvm.org/viewvc/llvm-project?rev=198111&view=rev Log: execute on my custom stacks Modified: vmkit/branches/mcjit/include/vmkit/thread.h vmkit/branches/mcjit/lib/vmkit/allocator.cc vmkit/branches/mcjit/lib/vmkit/thread.cc vmkit/branches/mcjit/lib/vmkit/vmkit.cc Modified: vmkit/branches/mcjit/include/vmkit/thread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/thread.h?rev=198111&r1=198110&r2=198111&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/thread.h (original) +++ vmkit/branches/mcjit/include/vmkit/thread.h Sat Dec 28 04:41:15 2013 @@ -26,10 +26,7 @@ namespace vmkit { VMKit* vm() { return _vm; } - static __thread Thread* _thread; - - static Thread* get() { return _thread; } - static void set(Thread* thread) { _thread = thread; } + static Thread* get(); void start(); void join(); Modified: vmkit/branches/mcjit/lib/vmkit/allocator.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/allocator.cc?rev=198111&r1=198110&r2=198111&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/allocator.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/allocator.cc Sat Dec 28 04:41:15 2013 @@ -46,7 +46,6 @@ void* BumpAllocator::allocate(size_t siz pthread_mutex_lock(&mutex); size_t total = round((uintptr_t)size + sizeof(BumpAllocatorNode), 4096); BumpAllocatorNode* newBucket = (BumpAllocatorNode*)map(total); - //memset(newBucket, 0, total); newBucket->next = current->next; current->next = newBucket; newBucket->top = (uint8_t*)((uintptr_t)newBucket + bucketSize); @@ -59,11 +58,8 @@ void* BumpAllocator::allocate(size_t siz uint8_t* res = __sync_fetch_and_add(&node->top, (uint8_t*)round(size, 8)); uint8_t* end = res + size; - if(res >= (uint8_t*)node && (res + size) < ((uint8_t*)node) + bucketSize) { - //printf("%p -> %lu %lu (%p -> %p)\n", res, size, round((uintptr_t)size, 64), node, ((uint8_t*)node) + bucketSize); - //memset(res, 0, size); + if(res >= (uint8_t*)node && (res + size) < ((uint8_t*)node) + bucketSize) return res; - } pthread_mutex_lock(&mutex); BumpAllocatorNode* newBucket = (BumpAllocatorNode*)map(bucketSize); @@ -78,7 +74,6 @@ void* BumpAllocator::map(size_t n) { void* res = mmap(0, n, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE, 0, 0); if(res == MAP_FAILED) Thread::get()->vm()->internalError(L"unable to map %ld bytes", n); - //memset(res, 0, n); return res; } @@ -129,7 +124,7 @@ void* ThreadAllocator::allocate() { spaces.push_back(space); - uintptr_t base = (((uintptr_t)space - 1) & -PAGE_SIZE) + PAGE_SIZE; + uintptr_t base = (((uintptr_t)space - 1) & -topStack) + topStack; uint32_t n = (base == (uintptr_t)space) ? refill : (refill - 1); for(uint32_t i=0; irelease(p); } +Thread* Thread::get() { + return (Thread*)((uintptr_t)__builtin_frame_address(0) & ThreadAllocator::allocator()->magic()); +} + void* Thread::doRun(void* _thread) { Thread* thread = (Thread*)_thread; - set(thread); thread->run(); return 0; } void Thread::start() { - pthread_create(&_tid, 0, doRun, this); + pthread_attr_t attr; + + pthread_attr_init(&attr); + pthread_attr_setstack(&attr, ThreadAllocator::allocator()->stackAddr(this), ThreadAllocator::allocator()->stackSize(this)); + + pthread_create(&_tid, &attr, doRun, this); + + pthread_attr_destroy(&attr); } void Thread::join() { Modified: vmkit/branches/mcjit/lib/vmkit/vmkit.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/vmkit.cc?rev=198111&r1=198110&r2=198111&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/vmkit.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/vmkit.cc Sat Dec 28 04:41:15 2013 @@ -100,8 +100,6 @@ void VMKit::addSymbol(llvm::GlobalValue* } void VMKit::vmkitBootstrap(Thread* initialThread, const char* selfBitCodePath) { - Thread::set(initialThread); - std::string err; llvm::OwningPtr buf; if (llvm::MemoryBuffer::getFile(selfBitCodePath, buf)) From gael.thomas at lip6.fr Sat Dec 28 03:03:10 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sat, 28 Dec 2013 11:03:10 -0000 Subject: [vmkit-commits] [vmkit] r198112 - Inline Thread::get() in the generated code Message-ID: <20131228110310.D18122A6C029@llvm.org> Author: gthomas Date: Sat Dec 28 05:03:10 2013 New Revision: 198112 URL: http://llvm.org/viewvc/llvm-project?rev=198112&view=rev Log: Inline Thread::get() in the generated code Modified: vmkit/branches/mcjit/include/j3/j3.h vmkit/branches/mcjit/include/j3/j3codegen.h vmkit/branches/mcjit/include/vmkit/thread.h vmkit/branches/mcjit/lib/j3/vm/j3.cc vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc vmkit/branches/mcjit/lib/vmkit/thread.cc Modified: vmkit/branches/mcjit/include/j3/j3.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3.h?rev=198112&r1=198111&r2=198112&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3.h (original) +++ vmkit/branches/mcjit/include/j3/j3.h Sat Dec 28 05:03:10 2013 @@ -78,6 +78,7 @@ namespace j3 { llvm::Type* typeJ3VirtualTablePtr; llvm::Type* typeJ3Type; llvm::Type* typeJ3TypePtr; + llvm::Type* typeJ3Thread; llvm::Type* typeJ3ObjectTypePtr; llvm::Type* typeJ3Class; llvm::Type* typeJ3ClassPtr; Modified: vmkit/branches/mcjit/include/j3/j3codegen.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3codegen.h?rev=198112&r1=198111&r2=198112&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3codegen.h (original) +++ vmkit/branches/mcjit/include/j3/j3codegen.h Sat Dec 28 05:03:10 2013 @@ -81,6 +81,8 @@ namespace j3 { uint32_t wideReadU1(); uint32_t wideReadS1(); + llvm::Value* currentThread(); + llvm::Value* nullCheck(llvm::Value* obj); llvm::BasicBlock* newBB(const char* name); @@ -170,13 +172,13 @@ namespace j3 { llvm::Function* funcJ3ThreadPush; llvm::Function* funcJ3ThreadTell; llvm::Function* funcJ3ThreadRestore; - llvm::Function* funcJ3ThreadGet; llvm::Function* funcEchoDebugExecute; llvm::Function* funcEchoDebugEnter; llvm::Function* funcCXABeginCatch; /* __cxa_begin_catch */ llvm::Function* funcCXAEndCatch; /* __cxa_end_catch */ llvm::Function* funcGXXPersonality; /* __gxx_personality_v0 */ llvm::Function* gcRoot; + llvm::Function* frameAddress; llvm::Function* stackMap; llvm::Function* patchPoint64; llvm::Function* patchPointVoid; Modified: vmkit/branches/mcjit/include/vmkit/thread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/thread.h?rev=198112&r1=198111&r2=198112&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/thread.h (original) +++ vmkit/branches/mcjit/include/vmkit/thread.h Sat Dec 28 05:03:10 2013 @@ -30,6 +30,8 @@ namespace vmkit { void start(); void join(); + + static uintptr_t getThreadMask(); }; class StackWalker { Modified: vmkit/branches/mcjit/lib/j3/vm/j3.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3.cc?rev=198112&r1=198111&r2=198112&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3.cc Sat Dec 28 05:03:10 2013 @@ -46,6 +46,7 @@ void J3::introspect() { typeJ3Type = introspectType("class.j3::J3Type"); typeJ3TypePtr = llvm::PointerType::getUnqual(typeJ3Type); typeJ3ObjectTypePtr = llvm::PointerType::getUnqual(introspectType("class.j3::J3ObjectType")); + typeJ3Thread = llvm::PointerType::getUnqual(introspectType("class.j3::J3Thread")); typeJ3Class = introspectType("class.j3::J3Class"); typeJ3ClassPtr = llvm::PointerType::getUnqual(typeJ3Class); typeJ3ArrayClass = introspectType("class.j3::J3ArrayClass"); Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=198112&r1=198111&r2=198112&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Sat Dec 28 05:03:10 2013 @@ -78,7 +78,6 @@ J3CodeGen::J3CodeGen(vmkit::BumpAllocato funcJ3ThreadPush = vm->introspectFunction(module(), "j3::J3Thread::push(j3::J3Object*)"); funcJ3ThreadTell = vm->introspectFunction(module(), "j3::J3Thread::tell()"); funcJ3ThreadRestore = vm->introspectFunction(module(), "j3::J3Thread::restore(j3::J3ObjectHandle*)"); - funcJ3ThreadGet = vm->introspectFunction(module(), "j3::J3Thread::get()"); funcEchoDebugEnter = vm->introspectFunction(module(), "j3::J3CodeGen::echoDebugEnter(unsigned int, char const*, ...)"); funcEchoDebugExecute = vm->introspectFunction(module(), "j3::J3CodeGen::echoDebugExecute(unsigned int, char const*, ...)"); @@ -96,6 +95,8 @@ J3CodeGen::J3CodeGen(vmkit::BumpAllocato gcRoot = vm->getGCRoot(module()); + frameAddress = llvm::Intrinsic::getDeclaration(module(), llvm::Intrinsic::frameaddress); + #if 0 //stackMap = llvm::Intrinsic::getDeclaration(module(), llvm::Intrinsic::experimental_stackmap); //patchPointVoid = llvm::Intrinsic::getDeclaration(module(), llvm::Intrinsic::experimental_patchpoint_i64); @@ -188,6 +189,15 @@ llvm::Value* J3CodeGen::unflatten(llvm:: } } +llvm::Value* J3CodeGen::currentThread() { + llvm::Type* type = vm->dataLayout()->getIntPtrType(module()->getContext()); + + return builder->CreateIntToPtr(builder->CreateAnd(builder->CreatePtrToInt(builder->CreateCall(frameAddress, builder->getInt32(0)), + type), + llvm::ConstantInt::get(type, vmkit::Thread::getThreadMask())), + vm->typeJ3Thread); +} + void J3CodeGen::initialiseJ3Type(J3Type* cl) { if(!cl->isInitialised()) builder->CreateCall(funcJ3TypeInitialise, builder->CreateBitCast(cl->llvmDescriptor(module()), vm->typeJ3TypePtr)); @@ -275,7 +285,7 @@ void J3CodeGen::invokeInterface(uint32_t J3MethodType* type = target->methodType(cl); uint32_t index = target->interfaceIndex(); - llvm::Value* thread = builder->CreateCall(funcJ3ThreadGet); + llvm::Value* thread = currentThread(); llvm::Value* gep[] = { builder->getInt32(0), builder->getInt32(J3Thread::gepInterfaceMethodIndex) }; builder->CreateStore(builder->getInt32(index), builder->CreateGEP(thread, gep)); @@ -1492,7 +1502,7 @@ void J3CodeGen::generateNative() { llvm::Function* nat = method->nativeLLVMFunction(module()); llvm::Value* res; - llvm::Value* thread = builder->CreateCall(funcJ3ThreadGet); + llvm::Value* thread = currentThread(); llvm::Value* frame = builder->CreateCall(funcJ3ThreadTell, thread); if(J3Cst::isSynchronized(method->access())) { Modified: vmkit/branches/mcjit/lib/vmkit/thread.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/thread.cc?rev=198112&r1=198111&r2=198112&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/thread.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/thread.cc Sat Dec 28 05:03:10 2013 @@ -17,7 +17,11 @@ void Thread::operator delete(void* p) { } Thread* Thread::get() { - return (Thread*)((uintptr_t)__builtin_frame_address(0) & ThreadAllocator::allocator()->magic()); + return (Thread*)((uintptr_t)__builtin_frame_address(0) & getThreadMask()); +} + +uintptr_t Thread::getThreadMask() { + return ThreadAllocator::allocator()->magic(); } void* Thread::doRun(void* _thread) { From gael.thomas at lip6.fr Sat Dec 28 14:08:51 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sat, 28 Dec 2013 22:08:51 -0000 Subject: [vmkit-commits] [vmkit] r198129 - add an extractor tool to only keep the interesting runtime part of j3 Message-ID: <20131228220852.2CF0C19BE002@llvm.org> Author: gthomas Date: Sat Dec 28 16:08:51 2013 New Revision: 198129 URL: http://llvm.org/viewvc/llvm-project?rev=198129&view=rev Log: add an extractor tool to only keep the interesting runtime part of j3 Added: vmkit/branches/mcjit/include/j3/j3meta.def vmkit/branches/mcjit/tools/vmkit-extract/ (with props) vmkit/branches/mcjit/tools/vmkit-extract/Makefile vmkit/branches/mcjit/tools/vmkit-extract/main.cc Modified: vmkit/branches/mcjit/Makefile vmkit/branches/mcjit/Makefile.rules vmkit/branches/mcjit/include/j3/j3.h vmkit/branches/mcjit/lib/j3/vm/j3.cc vmkit/branches/mcjit/lib/vmkit/compiler.cc vmkit/branches/mcjit/lib/vmkit/vmkit.cc vmkit/branches/mcjit/tools/j3/Makefile Modified: vmkit/branches/mcjit/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/Makefile?rev=198129&r1=198128&r2=198129&view=diff ============================================================================== --- vmkit/branches/mcjit/Makefile (original) +++ vmkit/branches/mcjit/Makefile Sat Dec 28 16:08:51 2013 @@ -5,6 +5,6 @@ LEVEL := . -DIRS := lib tools +DIRS := tools/vmkit-extract lib tools include $(LEVEL)/Makefile.rules Modified: vmkit/branches/mcjit/Makefile.rules URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/Makefile.rules?rev=198129&r1=198128&r2=198129&view=diff ============================================================================== --- vmkit/branches/mcjit/Makefile.rules (original) +++ vmkit/branches/mcjit/Makefile.rules Sat Dec 28 16:08:51 2013 @@ -228,18 +228,40 @@ endif ifdef TOOL TOOL_OUT=$(BIN_DIR)/$(TOOL)$(EXEEXT) -GEN_MODULE=$(LIB_DIR)/libjvm -SONAME=$(GEN_MODULE) +FINAL_MODULE=$(LIB_DIR)/libjvm +STRIP_MODULE=$(BUILD_DIR)/libjvm +GEN_MODULE=$(BUILD_DIR)/libjvm-no-strip +SONAME=$(FINAL_MODULE) BC_FILES+=$(addsuffix .bc,$(addprefix $(LIB_DIR)/,$(LIBS))) SO_FILES=$(addsuffix .a,$(addprefix $(LIB_DIR)/,$(LIBS))) SO_LIBS=$(LLVM_LIBS) -all:: $(BIN_DIR)/.dir $(TOOL_OUT) $(GEN_MODULE).bc +TOOL_ALL=$(BIN_DIR)/.dir $(TOOL_OUT) +TOOL_DEP=$(OBJ_FILES) -$(TOOL_OUT): $(OBJ_FILES) $(SONAME)$(SHLIBEXT) +ifdef WITH_DYLIB +TOOL_ALL+=$(FINAL_MODULE).bc +TOOL_DEP+=$(SONAME)$(SHLIBEXT) +else +TOOL_DEP+=$(SO_FILES) +TOOL_FLAGS=$(LLVM_LDFLAGS) $(SHFLAGS) +LDFLAGS=$(SO_LIBS) +endif + +all:: $(TOOL_ALL) + +$(TOOL_OUT): $(TOOL_DEP) $(Echo) "Linking '$(notdir $@)'" - $(Verb) $(CLANGXX) -o $@ -Wl,-rpath,$(LIB_DIR) $(LDFLAGS) $^ + $(Verb) $(CLANGXX) $(TOOL_FLAGS) -o $@ -Wl,-rpath,$(LIB_DIR) $(LDFLAGS) $^ + +$(FINAL_MODULE).bc: $(STRIP_MODULE).bc $(BIN_DIR)/vmkit-extract $(PROJ_SRC_ROOT)/$(EXTRACTOR) + $(Echo) "Extracting runtime function to '$(notdir $@)'" + $(Verb) $(BIN_DIR)/vmkit-extract $< $(PROJ_SRC_ROOT)/$(EXTRACTOR) > $@ + +$(STRIP_MODULE).bc: $(GEN_MODULE).bc + $(Echo) "Strip debug info from '$(notdir $<)'" + $(Verb) $(LLOPT) -strip-debug $< -o $@ endif Modified: vmkit/branches/mcjit/include/j3/j3.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3.h?rev=198129&r1=198128&r2=198129&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3.h (original) +++ vmkit/branches/mcjit/include/j3/j3.h Sat Dec 28 16:08:51 2013 @@ -118,6 +118,8 @@ namespace j3 { static void arrayIndexOutOfBoundsException() __attribute__((noreturn)); static void printStackTrace(); + + void forceSymbolDefinition(); }; } Added: vmkit/branches/mcjit/include/j3/j3meta.def URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3meta.def?rev=198129&view=auto ============================================================================== --- vmkit/branches/mcjit/include/j3/j3meta.def (added) +++ vmkit/branches/mcjit/include/j3/j3meta.def Sat Dec 28 16:08:51 2013 @@ -0,0 +1,27 @@ +_x(funcJ3MethodIndex, "j3::J3Method::index()") +_x(funcJ3TypeVT, "j3::J3Type::vt()") +_x(funcJ3TypeVTAndResolve, "j3::J3Type::vtAndResolve()") +_x(funcJ3TypeInitialise, "j3::J3Type::initialise()") +_x(funcJ3ClassSize, "j3::J3Class::size()") +_x(funcJ3ClassStaticInstance, "j3::J3Class::staticInstance()") +_x(funcJ3ClassStringAt, "j3::J3Class::stringAt(unsigned short)") +_x(funcJ3ObjectTypeJavaClass, "j3::J3ObjectType::javaClass()") +_x(funcJniEnv, "j3::J3::jniEnv()") +_x(funcJ3ObjectAllocate, "j3::J3Object::allocate(j3::J3VirtualTable*, unsigned long)") +_x(funcThrowException, "vmkit::VMKit::throwException(void*)") +_x(funcClassCastException, "j3::J3::classCastException()") +_x(funcNullPointerException, "j3::J3::nullPointerException()") +_x(funcJ3ThreadPushHandle, "j3::J3Thread::push(j3::J3ObjectHandle*)") +_x(funcJ3ThreadPush, "j3::J3Thread::push(j3::J3Object*)") +_x(funcJ3ThreadTell, "j3::J3Thread::tell()") +_x(funcJ3ThreadRestore, "j3::J3Thread::restore(j3::J3ObjectHandle*)") +_x(funcEchoDebugEnter, "j3::J3CodeGen::echoDebugEnter(unsigned int, char const*, ...)") +_x(funcEchoDebugExecute, "j3::J3CodeGen::echoDebugExecute(unsigned int, char const*, ...)") +_x(funcIsAssignableTo, "j3::J3VirtualTable::isAssignableTo(j3::J3VirtualTable*)") +_x(funcFastIsAssignableToPrimaryChecker, "j3::J3VirtualTable::fastIsAssignableToPrimaryChecker(j3::J3VirtualTable*, unsigned int)") +_x(funcFastIsAssignableToNonPrimaryChecker, "j3::J3VirtualTable::fastIsAssignableToNonPrimaryChecker(j3::J3VirtualTable*)") +_x(funcGXXPersonality, "__gxx_personality_v0") +_x(funcCXABeginCatch, "__cxa_begin_catch") +_x(funcCXAEndCatch, "__cxa_end_catch") +_x(gvTypeInfo, "typeinfo for void*") +_x(funcFake, "j3::J3::forceSymbolDefinition()") \ No newline at end of file Modified: vmkit/branches/mcjit/lib/j3/vm/j3.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3.cc?rev=198129&r1=198128&r2=198129&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3.cc Sat Dec 28 16:08:51 2013 @@ -221,3 +221,13 @@ void J3::printStackTrace() { } } } + +void J3::forceSymbolDefinition() { + J3ArrayObject a; a.length(); /* J3ArrayObject */ + try { + throw (void*)0; + } catch(void* e) { + } +} + + Modified: vmkit/branches/mcjit/lib/vmkit/compiler.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/compiler.cc?rev=198129&r1=198128&r2=198129&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/compiler.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/compiler.cc Sat Dec 28 16:08:51 2013 @@ -13,6 +13,7 @@ #include "llvm/ExecutionEngine/MCJIT.h" #include "llvm/ExecutionEngine/JIT.h" +#include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" #include "llvm/Target/TargetOptions.h" Modified: vmkit/branches/mcjit/lib/vmkit/vmkit.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/vmkit.cc?rev=198129&r1=198128&r2=198129&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/vmkit.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/vmkit.cc Sat Dec 28 16:08:51 2013 @@ -164,6 +164,8 @@ void VMKit::internalError(const wchar_t* abort(); } +static int fake = 0; + void VMKit::throwException(void* obj) { #if 0 void** exception = (void**)abi::__cxa_allocate_exception(sizeof(void*)); @@ -171,5 +173,7 @@ void VMKit::throwException(void* obj) { abi::__cxa_throw(exception, (std::type_info*)Thread::get()->vm()->ptrTypeInfo, 0); #endif fprintf(stderr, " throw exception...\n"); + if(fake) + throw (void*)0; /* force the symbol typeinfo for void* to be conserved in the bc file */ abort(); } Modified: vmkit/branches/mcjit/tools/j3/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/tools/j3/Makefile?rev=198129&r1=198128&r2=198129&view=diff ============================================================================== --- vmkit/branches/mcjit/tools/j3/Makefile (original) +++ vmkit/branches/mcjit/tools/j3/Makefile Sat Dec 28 16:08:51 2013 @@ -7,5 +7,7 @@ LEVEL := ../.. LIBS := vmkit j3 openjdk TOOL := j3 +WITH_DYLIB=1 +EXTRACTOR=include/j3/j3meta.def include $(LEVEL)/Makefile.rules Propchange: vmkit/branches/mcjit/tools/vmkit-extract/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Sat Dec 28 16:08:51 2013 @@ -0,0 +1 @@ +Debug+Asserts Added: vmkit/branches/mcjit/tools/vmkit-extract/Makefile URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/tools/vmkit-extract/Makefile?rev=198129&view=auto ============================================================================== --- vmkit/branches/mcjit/tools/vmkit-extract/Makefile (added) +++ vmkit/branches/mcjit/tools/vmkit-extract/Makefile Sat Dec 28 16:08:51 2013 @@ -0,0 +1,11 @@ +#===- ./Makefile -------------------------------------------*- Makefile -*--===# +# +# The vmkit project +#===------------------------------------------------------------------------===# + +LEVEL := ../.. + +LIBS := +TOOL := vmkit-extract + +include $(LEVEL)/Makefile.rules Added: vmkit/branches/mcjit/tools/vmkit-extract/main.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/tools/vmkit-extract/main.cc?rev=198129&view=auto ============================================================================== --- vmkit/branches/mcjit/tools/vmkit-extract/main.cc (added) +++ vmkit/branches/mcjit/tools/vmkit-extract/main.cc Sat Dec 28 16:08:51 2013 @@ -0,0 +1,107 @@ +#include +#include +#include +#include + +#include "llvm/IR/LLVMContext.h" +//#include "llvm/ADT/SetVector.h" +//#include "llvm/ADT/SmallPtrSet.h" +#include "llvm/Assembly/PrintModulePass.h" +#include "llvm/Bitcode/ReaderWriter.h" +#include "llvm/IR/DataLayout.h" +#include "llvm/IR/Module.h" +#include "llvm/IRReader/IRReader.h" +#include "llvm/PassManager.h" +//#include "llvm/Support/CommandLine.h" +//#include "llvm/Support/ManagedStatic.h" +//#include "llvm/Support/PrettyStackTrace.h" +//#include "llvm/Support/Regex.h" +//#include "llvm/Support/Signals.h" +#include "llvm/Support/SourceMgr.h" +//#include "llvm/Support/SystemUtils.h" +#include "llvm/Support/ToolOutputFile.h" +#include "llvm/Transforms/IPO.h" +//#include + +void add(std::map& mangler, llvm::GlobalValue* cur) { + const char* id = cur->getName().data(); + int status; + char* realname; + realname = abi::__cxa_demangle(id, 0, 0, &status); + const char* tmp = realname ? realname : id; + mangler[std::string(tmp)] = cur; +} + +int main(int argc, char** argv) { + if(argc != 3) { + fprintf(stderr, "usage: %s input.bc file.def\n", argv[0]); + abort(); + } + + llvm::LLVMContext& context = llvm::getGlobalContext(); + llvm::SMDiagnostic err; + llvm::OwningPtr module; + module.reset(llvm::getLazyIRFileModule(argv[1], err, context)); + + std::map mangler; + std::vector extracted; + + for(llvm::Module::iterator cur=module->begin(); cur!=module->end(); cur++) + add(mangler, cur); + + for(llvm::Module::global_iterator cur=module->global_begin(); cur!=module->global_end(); cur++) + add(mangler, cur); + + FILE* fp = fopen(argv[2], "r"); + size_t linecapp = 0; + char* buf; + + while(getline(&buf, &linecapp, fp) > 0) { + char* p = strchr(buf, '"') + 1; + char* e = strchr(p, '"'); + *e = 0; + llvm::GlobalValue* gv = mangler[p]; + + if(gv) { + extracted.push_back(gv); + if (gv->isMaterializable()) { + std::string ErrInfo; + if(gv->Materialize(&ErrInfo)) { + fprintf(stderr, "%s: error reading input: %s\n", argv[0], ErrInfo.c_str()); + return 1; + } + } + //fprintf(stderr, "extracting: %s (%s)\n", p, gv->getName().data()); + //gv->dump(); + } else { + fprintf(stderr, "unable to find symbol %s\n", p); + return 1; + } + } + + // directly from llvm-extract + llvm::PassManager Passes; + Passes.add(new llvm::DataLayout(module.get())); // Use correct DataLayout + + Passes.add(llvm::createGVExtractionPass(extracted, 0)); + Passes.add(llvm::createGlobalDCEPass()); // Delete unreachable globals + Passes.add(llvm::createStripDeadDebugInfoPass()); // Remove dead debug info + Passes.add(llvm::createStripDeadPrototypesPass()); // Remove dead func decls + + std::string ErrorInfo; + llvm::tool_output_file Out("-", ErrorInfo, llvm::sys::fs::F_Binary); + if (!ErrorInfo.empty()) { + llvm::errs() << ErrorInfo << '\n'; + return 1; + } + + //Passes.add(llvm::createPrintModulePass(&Out.os())); + Passes.add(createBitcodeWriterPass(Out.os())); + + Passes.run(*module.get()); + + // Declare success. + Out.keep(); + + return 0; +} From gael.thomas at lip6.fr Sat Dec 28 14:14:18 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sat, 28 Dec 2013 22:14:18 -0000 Subject: [vmkit-commits] [vmkit] r198130 - use j3meta.def to generate both the extractor and to retreive the runtime function Message-ID: <20131228221418.12DB019BE002@llvm.org> Author: gthomas Date: Sat Dec 28 16:14:17 2013 New Revision: 198130 URL: http://llvm.org/viewvc/llvm-project?rev=198130&view=rev Log: use j3meta.def to generate both the extractor and to retreive the runtime function Modified: vmkit/branches/mcjit/include/j3/j3codegen.h vmkit/branches/mcjit/include/j3/j3meta.def vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Modified: vmkit/branches/mcjit/include/j3/j3codegen.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3codegen.h?rev=198130&r1=198129&r2=198130&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3codegen.h (original) +++ vmkit/branches/mcjit/include/j3/j3codegen.h Sat Dec 28 16:14:17 2013 @@ -152,38 +152,16 @@ namespace j3 { static void echoDebugEnter(uint32_t isLeave, const char* msg, ...); static void echoDebugExecute(uint32_t level, const char* msg, ...); - llvm::Function* funcJ3MethodIndex; - llvm::Function* funcJ3TypeVT; - llvm::Function* funcJ3TypeVTAndResolve; - llvm::Function* funcJ3TypeInitialise; - llvm::Function* funcJ3ObjectTypeJavaClass; - llvm::Function* funcJ3ClassSize; - llvm::Function* funcJ3ClassStaticInstance; - llvm::Function* funcJ3ClassStringAt; - llvm::Function* funcJ3ObjectAllocate; - llvm::Function* funcJniEnv; - llvm::Function* funcClassCastException; - llvm::Function* funcNullPointerException; - llvm::Function* funcThrowException; - llvm::Function* funcIsAssignableTo; - llvm::Function* funcFastIsAssignableToPrimaryChecker; - llvm::Function* funcFastIsAssignableToNonPrimaryChecker; - llvm::Function* funcJ3ThreadPushHandle; - llvm::Function* funcJ3ThreadPush; - llvm::Function* funcJ3ThreadTell; - llvm::Function* funcJ3ThreadRestore; - llvm::Function* funcEchoDebugExecute; - llvm::Function* funcEchoDebugEnter; - llvm::Function* funcCXABeginCatch; /* __cxa_begin_catch */ - llvm::Function* funcCXAEndCatch; /* __cxa_end_catch */ - llvm::Function* funcGXXPersonality; /* __gxx_personality_v0 */ +#define _x(name, id) \ + llvm::Function* name; +#include "j3/j3meta.def" +#undef _x + llvm::GlobalValue* gvTypeInfo; /* typename void* */ llvm::Function* gcRoot; llvm::Function* frameAddress; llvm::Function* stackMap; llvm::Function* patchPoint64; llvm::Function* patchPointVoid; - llvm::Function* ziTry; - llvm::GlobalValue* gvTypeInfo; /* typename void* */ J3CodeGen(vmkit::BumpAllocator* _allocator, J3Method* method, llvm::Function* _llvmFunction); ~J3CodeGen(); Modified: vmkit/branches/mcjit/include/j3/j3meta.def URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3meta.def?rev=198130&r1=198129&r2=198130&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3meta.def (original) +++ vmkit/branches/mcjit/include/j3/j3meta.def Sat Dec 28 16:14:17 2013 @@ -23,5 +23,4 @@ _x(funcFastIsAssignableToNonPrimaryCheck _x(funcGXXPersonality, "__gxx_personality_v0") _x(funcCXABeginCatch, "__cxa_begin_catch") _x(funcCXAEndCatch, "__cxa_end_catch") -_x(gvTypeInfo, "typeinfo for void*") _x(funcFake, "j3::J3::forceSymbolDefinition()") \ No newline at end of file Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=198130&r1=198129&r2=198130&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Sat Dec 28 16:14:17 2013 @@ -59,37 +59,10 @@ J3CodeGen::J3CodeGen(vmkit::BumpAllocato builder = &_builder; - funcJ3MethodIndex = vm->introspectFunction(module(), "j3::J3Method::index()"); - funcJ3TypeVT = vm->introspectFunction(module(), "j3::J3Type::vt()"); - funcJ3TypeVTAndResolve = vm->introspectFunction(module(), "j3::J3Type::vtAndResolve()"); - funcJ3TypeInitialise = vm->introspectFunction(module(), "j3::J3Type::initialise()"); - funcJ3ClassSize = vm->introspectFunction(module(), "j3::J3Class::size()"); - funcJ3ClassStaticInstance = vm->introspectFunction(module(), "j3::J3Class::staticInstance()"); - funcJ3ClassStringAt = vm->introspectFunction(module(), "j3::J3Class::stringAt(unsigned short)"); - funcJ3ObjectTypeJavaClass = vm->introspectFunction(module(), "j3::J3ObjectType::javaClass()"); - funcJniEnv = vm->introspectFunction(module(), "j3::J3::jniEnv()"); - funcJ3ObjectAllocate = vm->introspectFunction(module(), "j3::J3Object::allocate(j3::J3VirtualTable*, unsigned long)"); - - funcThrowException = vm->introspectFunction(module(), "vmkit::VMKit::throwException(void*)"); - funcClassCastException = vm->introspectFunction(module(), "j3::J3::classCastException()"); - funcNullPointerException = vm->introspectFunction(module(), "j3::J3::nullPointerException()"); - - funcJ3ThreadPushHandle = vm->introspectFunction(module(), "j3::J3Thread::push(j3::J3ObjectHandle*)"); - funcJ3ThreadPush = vm->introspectFunction(module(), "j3::J3Thread::push(j3::J3Object*)"); - funcJ3ThreadTell = vm->introspectFunction(module(), "j3::J3Thread::tell()"); - funcJ3ThreadRestore = vm->introspectFunction(module(), "j3::J3Thread::restore(j3::J3ObjectHandle*)"); - funcEchoDebugEnter = vm->introspectFunction(module(), "j3::J3CodeGen::echoDebugEnter(unsigned int, char const*, ...)"); - funcEchoDebugExecute = vm->introspectFunction(module(), "j3::J3CodeGen::echoDebugExecute(unsigned int, char const*, ...)"); - - funcIsAssignableTo = vm->introspectFunction(module(), "j3::J3VirtualTable::isAssignableTo(j3::J3VirtualTable*)"); - funcFastIsAssignableToPrimaryChecker = - vm->introspectFunction(module(), "j3::J3VirtualTable::fastIsAssignableToPrimaryChecker(j3::J3VirtualTable*, unsigned int)"); - funcFastIsAssignableToNonPrimaryChecker = - vm->introspectFunction(module(), "j3::J3VirtualTable::fastIsAssignableToNonPrimaryChecker(j3::J3VirtualTable*)"); - - funcGXXPersonality = vm->introspectFunction(module(), "__gxx_personality_v0"); - funcCXABeginCatch = vm->introspectFunction(module(), "__cxa_begin_catch"); - funcCXAEndCatch = vm->introspectFunction(module(), "__cxa_end_catch"); +#define _x(name, id) \ + name = vm->introspectFunction(module(), id); +#include "j3/j3meta.def" +#undef _x gvTypeInfo = vm->introspectGlobalValue(module(), "typeinfo for void*"); @@ -113,10 +86,6 @@ J3CodeGen::J3CodeGen(vmkit::BumpAllocato } #endif - ziTry = - (llvm::Function*)module()->getOrInsertFunction("vmkit.try", - llvm::FunctionType::get(llvm::Type::getVoidTy(llvmFunction->getContext()), 0)); - if(J3Cst::isNative(method->access())) generateNative(); else From gael.thomas at lip6.fr Sat Dec 28 14:57:01 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sat, 28 Dec 2013 22:57:01 -0000 Subject: [vmkit-commits] [vmkit] r198134 - replicate the code to load the runtime bc file from vmkit to a compilation unit Message-ID: <20131228225701.BB772312807B@llvm.org> Author: gthomas Date: Sat Dec 28 16:57:01 2013 New Revision: 198134 URL: http://llvm.org/viewvc/llvm-project?rev=198134&view=rev Log: replicate the code to load the runtime bc file from vmkit to a compilation unit Modified: vmkit/branches/mcjit/include/vmkit/compiler.h vmkit/branches/mcjit/include/vmkit/vmkit.h vmkit/branches/mcjit/lib/vmkit/compiler.cc vmkit/branches/mcjit/lib/vmkit/vmkit.cc vmkit/branches/mcjit/tools/vmkit-extract/main.cc Modified: vmkit/branches/mcjit/include/vmkit/compiler.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/compiler.h?rev=198134&r1=198133&r2=198134&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/compiler.h (original) +++ vmkit/branches/mcjit/include/vmkit/compiler.h Sat Dec 28 16:57:01 2013 @@ -9,6 +9,7 @@ namespace llvm { class Module; class ExecutionEngine; + class GlobalValue; namespace legacy { class PassManager; @@ -34,16 +35,21 @@ namespace vmkit { }; class CompilationUnit : public llvm::SectionMemoryManager { + typedef std::map > > MangleMap; typedef std::map > > SymbolMap; VMKit* _vmkit; BumpAllocator* _allocator; + MangleMap _mangleMap; SymbolMap _symbolTable; pthread_mutex_t _mutexSymbolTable; llvm::ExecutionEngine* _ee; llvm::ExecutionEngine* _oldee; llvm::PassManager* pm; + void addSymbol(llvm::GlobalValue* gv); + protected: void operator delete(void* self); Modified: vmkit/branches/mcjit/include/vmkit/vmkit.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/vmkit.h?rev=198134&r1=198133&r2=198134&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/vmkit.h (original) +++ vmkit/branches/mcjit/include/vmkit/vmkit.h Sat Dec 28 16:57:01 2013 @@ -25,6 +25,7 @@ namespace vmkit { pthread_mutex_t safepointMapLock; MangleMap mangleMap; BumpAllocator* _allocator; + const char* _selfBitCodePath; llvm::Module* _self; llvm::DataLayout* _dataLayout; void* ptrTypeInfo; @@ -40,6 +41,8 @@ namespace vmkit { VMKit(BumpAllocator* allocator); + const char* selfBitCodePath() { return _selfBitCodePath; } + void addSafepoint(Safepoint* sf); Safepoint* getSafepoint(void* addr); Modified: vmkit/branches/mcjit/lib/vmkit/compiler.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/compiler.cc?rev=198134&r1=198133&r2=198134&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/compiler.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/compiler.cc Sat Dec 28 16:57:01 2013 @@ -13,6 +13,8 @@ #include "llvm/ExecutionEngine/MCJIT.h" #include "llvm/ExecutionEngine/JIT.h" +#include "llvm/Bitcode/ReaderWriter.h" + #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" @@ -31,17 +33,43 @@ void* CompilationUnit::operator new(size void CompilationUnit::operator delete(void* self) { } +#include + CompilationUnit::CompilationUnit(BumpAllocator* allocator, VMKit* vmkit, const char* id) : + _mangleMap(Util::char_less, allocator), _symbolTable(vmkit::Util::char_less, allocator) { _allocator = allocator; pthread_mutex_init(&_mutexSymbolTable, 0); _vmkit = vmkit; + std::string err; + + struct timeval start, end; + gettimeofday(&start, 0); + + llvm::LLVMContext* context = new llvm::LLVMContext(); + llvm::OwningPtr buf; + if (llvm::MemoryBuffer::getFile(vm()->selfBitCodePath(), buf)) + VMKit::internalError(L"Error while opening bitcode file %s", vm()->selfBitCodePath()); + llvm::Module* module = llvm::getLazyBitcodeModule(buf.take(), *context, &err); + + if(!module) + VMKit::internalError(L"Error while reading bitcode file %s: %s", vm()->selfBitCodePath(), err.c_str()); + + for(llvm::Module::iterator cur=module->begin(); cur!=module->end(); cur++) + addSymbol(cur); + + for(llvm::Module::global_iterator cur=module->global_begin(); cur!=module->global_end(); cur++) + addSymbol(cur); + + gettimeofday(&end, 0); + double d = start.tv_sec*1. + start.tv_usec*1e-6 - end.tv_sec*1. -end.tv_usec*1e-6; + fprintf(stderr, " took: %lf\n", d); + llvm::TargetOptions opt; opt.NoFramePointerElim = 1; - std::string err; _ee = llvm::EngineBuilder(new llvm::Module(id, Thread::get()->vm()->llvmContext())) .setUseMCJIT(1) .setMCJITMemoryManager(this) @@ -112,6 +140,19 @@ CompilationUnit::~CompilationUnit() { delete _oldee; } +void CompilationUnit::addSymbol(llvm::GlobalValue* gv) { + const char* id = gv->getName().data(); + int status; + char* realname; + realname = abi::__cxa_demangle(id, 0, 0, &status); + const char* tmp = realname ? realname : id; + uint32_t length = strlen(tmp); + char* mangled = (char*)allocator()->allocate(length+1); + strcpy(mangled, tmp); + _mangleMap[mangled] = gv; + free(realname); +} + void CompilationUnit::destroy(CompilationUnit* unit) { delete unit; BumpAllocator::destroy(unit->allocator()); Modified: vmkit/branches/mcjit/lib/vmkit/vmkit.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/vmkit.cc?rev=198134&r1=198133&r2=198134&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/vmkit.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/vmkit.cc Sat Dec 28 16:57:01 2013 @@ -100,7 +100,9 @@ void VMKit::addSymbol(llvm::GlobalValue* } void VMKit::vmkitBootstrap(Thread* initialThread, const char* selfBitCodePath) { + _selfBitCodePath = selfBitCodePath; std::string err; + llvm::OwningPtr buf; if (llvm::MemoryBuffer::getFile(selfBitCodePath, buf)) VMKit::internalError(L"Error while opening bitcode file %s", selfBitCodePath); Modified: vmkit/branches/mcjit/tools/vmkit-extract/main.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/tools/vmkit-extract/main.cc?rev=198134&r1=198133&r2=198134&view=diff ============================================================================== --- vmkit/branches/mcjit/tools/vmkit-extract/main.cc (original) +++ vmkit/branches/mcjit/tools/vmkit-extract/main.cc Sat Dec 28 16:57:01 2013 @@ -49,8 +49,8 @@ int main(int argc, char** argv) { for(llvm::Module::iterator cur=module->begin(); cur!=module->end(); cur++) add(mangler, cur); - for(llvm::Module::global_iterator cur=module->global_begin(); cur!=module->global_end(); cur++) - add(mangler, cur); + // for(llvm::Module::global_iterator cur=module->global_begin(); cur!=module->global_end(); cur++) + // add(mangler, cur); FILE* fp = fopen(argv[2], "r"); size_t linecapp = 0; From gael.thomas at lip6.fr Sun Dec 29 01:33:22 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sun, 29 Dec 2013 09:33:22 -0000 Subject: [vmkit-commits] [vmkit] r198161 - abort most of the stupid ideas that I have tested in r198134 Message-ID: <20131229093322.52EF019BE002@llvm.org> Author: gthomas Date: Sun Dec 29 03:33:20 2013 New Revision: 198161 URL: http://llvm.org/viewvc/llvm-project?rev=198161&view=rev Log: abort most of the stupid ideas that I have tested in r198134 Modified: vmkit/branches/mcjit/include/vmkit/compiler.h vmkit/branches/mcjit/lib/vmkit/compiler.cc vmkit/branches/mcjit/tools/vmkit-extract/main.cc Modified: vmkit/branches/mcjit/include/vmkit/compiler.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/compiler.h?rev=198161&r1=198160&r2=198161&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/compiler.h (original) +++ vmkit/branches/mcjit/include/vmkit/compiler.h Sun Dec 29 03:33:20 2013 @@ -35,21 +35,16 @@ namespace vmkit { }; class CompilationUnit : public llvm::SectionMemoryManager { - typedef std::map > > MangleMap; typedef std::map > > SymbolMap; VMKit* _vmkit; BumpAllocator* _allocator; - MangleMap _mangleMap; SymbolMap _symbolTable; pthread_mutex_t _mutexSymbolTable; llvm::ExecutionEngine* _ee; llvm::ExecutionEngine* _oldee; llvm::PassManager* pm; - void addSymbol(llvm::GlobalValue* gv); - protected: void operator delete(void* self); Modified: vmkit/branches/mcjit/lib/vmkit/compiler.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/compiler.cc?rev=198161&r1=198160&r2=198161&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/compiler.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/compiler.cc Sun Dec 29 03:33:20 2013 @@ -33,10 +33,7 @@ void* CompilationUnit::operator new(size void CompilationUnit::operator delete(void* self) { } -#include - CompilationUnit::CompilationUnit(BumpAllocator* allocator, VMKit* vmkit, const char* id) : - _mangleMap(Util::char_less, allocator), _symbolTable(vmkit::Util::char_less, allocator) { _allocator = allocator; pthread_mutex_init(&_mutexSymbolTable, 0); @@ -45,28 +42,6 @@ CompilationUnit::CompilationUnit(BumpAll std::string err; - struct timeval start, end; - gettimeofday(&start, 0); - - llvm::LLVMContext* context = new llvm::LLVMContext(); - llvm::OwningPtr buf; - if (llvm::MemoryBuffer::getFile(vm()->selfBitCodePath(), buf)) - VMKit::internalError(L"Error while opening bitcode file %s", vm()->selfBitCodePath()); - llvm::Module* module = llvm::getLazyBitcodeModule(buf.take(), *context, &err); - - if(!module) - VMKit::internalError(L"Error while reading bitcode file %s: %s", vm()->selfBitCodePath(), err.c_str()); - - for(llvm::Module::iterator cur=module->begin(); cur!=module->end(); cur++) - addSymbol(cur); - - for(llvm::Module::global_iterator cur=module->global_begin(); cur!=module->global_end(); cur++) - addSymbol(cur); - - gettimeofday(&end, 0); - double d = start.tv_sec*1. + start.tv_usec*1e-6 - end.tv_sec*1. -end.tv_usec*1e-6; - fprintf(stderr, " took: %lf\n", d); - llvm::TargetOptions opt; opt.NoFramePointerElim = 1; @@ -140,19 +115,6 @@ CompilationUnit::~CompilationUnit() { delete _oldee; } -void CompilationUnit::addSymbol(llvm::GlobalValue* gv) { - const char* id = gv->getName().data(); - int status; - char* realname; - realname = abi::__cxa_demangle(id, 0, 0, &status); - const char* tmp = realname ? realname : id; - uint32_t length = strlen(tmp); - char* mangled = (char*)allocator()->allocate(length+1); - strcpy(mangled, tmp); - _mangleMap[mangled] = gv; - free(realname); -} - void CompilationUnit::destroy(CompilationUnit* unit) { delete unit; BumpAllocator::destroy(unit->allocator()); Modified: vmkit/branches/mcjit/tools/vmkit-extract/main.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/tools/vmkit-extract/main.cc?rev=198161&r1=198160&r2=198161&view=diff ============================================================================== --- vmkit/branches/mcjit/tools/vmkit-extract/main.cc (original) +++ vmkit/branches/mcjit/tools/vmkit-extract/main.cc Sun Dec 29 03:33:20 2013 @@ -62,6 +62,8 @@ int main(int argc, char** argv) { *e = 0; llvm::GlobalValue* gv = mangler[p]; + //gv->setName(p); + if(gv) { extracted.push_back(gv); if (gv->isMaterializable()) { From gael.thomas at lip6.fr Sun Dec 29 10:18:24 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sun, 29 Dec 2013 18:18:24 -0000 Subject: [vmkit-commits] [vmkit] r198173 - ensures that a class is defined in its class loader Message-ID: <20131229181825.0336C2A6C029@llvm.org> Author: gthomas Date: Sun Dec 29 12:18:24 2013 New Revision: 198173 URL: http://llvm.org/viewvc/llvm-project?rev=198173&view=rev Log: ensures that a class is defined in its class loader Modified: vmkit/branches/mcjit/include/j3/j3.h vmkit/branches/mcjit/include/j3/j3class.h vmkit/branches/mcjit/include/j3/j3classloader.h vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc vmkit/branches/mcjit/lib/j3/vm/j3.cc vmkit/branches/mcjit/lib/j3/vm/j3class.cc vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc vmkit/branches/mcjit/lib/j3/vm/j3jni.cc Modified: vmkit/branches/mcjit/include/j3/j3.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3.h?rev=198173&r1=198172&r2=198173&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3.h (original) +++ vmkit/branches/mcjit/include/j3/j3.h Sun Dec 29 12:18:24 2013 @@ -105,7 +105,7 @@ namespace j3 { static JNIEnv* jniEnv(); - static void noClassDefFoundError(J3Class* cl) __attribute__((noreturn)); + static void noClassDefFoundError(const vmkit::Name* name) __attribute__((noreturn)); static void classFormatError(J3Class* cl, const wchar_t* reason, ...) __attribute__((noreturn)); static void noSuchMethodError(const wchar_t* msg, J3Class* clName, const vmkit::Name* name, const vmkit::Name* sign) __attribute__((noreturn)); Modified: vmkit/branches/mcjit/include/j3/j3class.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3class.h?rev=198173&r1=198172&r2=198173&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3class.h (original) +++ vmkit/branches/mcjit/include/j3/j3class.h Sun Dec 29 12:18:24 2013 @@ -38,7 +38,7 @@ namespace j3 { J3ArrayClass* volatile _array; protected: - enum { CITED, LOADED, RESOLVED, INITED }; + enum { LOADED, RESOLVED, INITED }; const vmkit::Name* _name; char* _nativeName; @@ -246,13 +246,12 @@ namespace j3 { void createLLVMTypes(); - void load(); void doResolve(J3Field* hiddenFields, size_t nbHiddenFields); void doInitialise(); J3Method* interfaceOrMethodAt(uint16_t idx, uint16_t access); public: - J3Class(J3ClassLoader* loader, const vmkit::Name* name); + J3Class(J3ClassLoader* loader, const vmkit::Name* name, J3ClassBytes* bytes); size_t nbInterfaces() { return _nbInterfaces; } J3Class** interfaces() { return _interfaces; } Modified: vmkit/branches/mcjit/include/j3/j3classloader.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3classloader.h?rev=198173&r1=198172&r2=198173&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3classloader.h (original) +++ vmkit/branches/mcjit/include/j3/j3classloader.h Sun Dec 29 12:18:24 2013 @@ -89,12 +89,13 @@ namespace j3 { const vmkit::Name* name, const vmkit::Name* sign); J3Method* method(uint16_t access, const wchar_t* clName, const wchar_t* name, const wchar_t* sign); - J3Class* getClass(const vmkit::Name* name); /* find a class */ + J3Class* defineClass(const vmkit::Name* name, J3ClassBytes* bytes); + J3Class* findLoadedClass(const vmkit::Name* name); + virtual J3Class* loadClass(const vmkit::Name* name); + J3Type* getType(J3Class* from, const vmkit::Name* type); /* find a type */ J3MethodType* getMethodType(J3Class* from, const vmkit::Name* sign); /* get a method type */ - virtual J3ClassBytes* lookup(const vmkit::Name* name); - void* lookupNativeFunctionPointer(J3Method* method, const char* symb); }; @@ -108,11 +109,9 @@ namespace j3 { public: J3InitialClassLoader(J3* vm, const char* rtjar, vmkit::BumpAllocator* allocator); - J3ClassBytes* lookup(const vmkit::Name* name); - + J3Class* loadClass(const vmkit::Name* name); const char* cmangled(const char* demangled) { return _cmangled[demangled]; } - - void registerCMangling(const char* mangled, const char* demangled); + void registerCMangling(const char* mangled, const char* demangled); }; } Modified: vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc?rev=198173&r1=198172&r2=198173&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc (original) +++ vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc Sun Dec 29 12:18:24 2013 @@ -283,23 +283,23 @@ jclass JNICALL JVM_FindPrimitiveClass(JN J3Class* res; if(!strcmp(utf, "boolean")) - res = loader->getClass(names->get(L"java/lang/Boolean")); + res = loader->loadClass(names->get(L"java/lang/Boolean")); else if(!strcmp(utf, "byte")) - res = loader->getClass(names->get(L"java/lang/Byte")); + res = loader->loadClass(names->get(L"java/lang/Byte")); else if(!strcmp(utf, "char")) - res = loader->getClass(names->get(L"java/lang/Character")); + res = loader->loadClass(names->get(L"java/lang/Character")); else if(!strcmp(utf, "short")) - res = loader->getClass(names->get(L"java/lang/Short")); + res = loader->loadClass(names->get(L"java/lang/Short")); else if(!strcmp(utf, "int")) - res = loader->getClass(names->get(L"java/lang/Integer")); + res = loader->loadClass(names->get(L"java/lang/Integer")); else if(!strcmp(utf, "long")) - res = loader->getClass(names->get(L"java/lang/Long")); + res = loader->loadClass(names->get(L"java/lang/Long")); else if(!strcmp(utf, "float")) - res = loader->getClass(names->get(L"java/lang/Float")); + res = loader->loadClass(names->get(L"java/lang/Float")); else if(!strcmp(utf, "double")) - res = loader->getClass(names->get(L"java/lang/Double")); + res = loader->loadClass(names->get(L"java/lang/Double")); else if(!strcmp(utf, "void")) - res = loader->getClass(names->get(L"java/lang/Void")); + res = loader->loadClass(names->get(L"java/lang/Void")); else J3::internalError(L"unsupported primitive: %s", utf); Modified: vmkit/branches/mcjit/lib/j3/vm/j3.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3.cc?rev=198173&r1=198172&r2=198173&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3.cc Sun Dec 29 12:18:24 2013 @@ -89,23 +89,23 @@ void J3::run() { nbArrayInterfaces = 2; arrayInterfaces = (J3Type**)initialClassLoader->allocator()->allocate(2*sizeof(J3Type*)); - arrayInterfaces[0] = initialClassLoader->getClass(names()->get(L"java/lang/Cloneable")); - arrayInterfaces[1] = initialClassLoader->getClass(names()->get(L"java/io/Serializable")); + arrayInterfaces[0] = initialClassLoader->loadClass(names()->get(L"java/lang/Cloneable")); + arrayInterfaces[1] = initialClassLoader->loadClass(names()->get(L"java/io/Serializable")); charArrayClass = typeChar->getArray(); - objectClass = initialClassLoader->getClass(names()->get(L"java/lang/Object")); + objectClass = initialClassLoader->loadClass(names()->get(L"java/lang/Object")); - stringClass = initialClassLoader->getClass(names()->get(L"java/lang/String")); + stringClass = initialClassLoader->loadClass(names()->get(L"java/lang/String")); stringInit = initialClassLoader->method(0, stringClass, initName, names()->get(L"([CZ)V")); stringValue = stringClass->findVirtualField(names()->get(L"value"), typeChar->getArray()); - classClass = initialClassLoader->getClass(names()->get(L"java/lang/Class")); + classClass = initialClassLoader->loadClass(names()->get(L"java/lang/Class")); J3Field hf(J3Cst::ACC_PRIVATE, names()->get(L"** vmData **"), typeLong); classClass->resolve(&hf, 1); classInit = initialClassLoader->method(0, classClass, initName, names()->get(L"()V")); classVMData = classClass->findVirtualField(hf.name(), hf.type()); - threadVMData = initialClassLoader->getClass(names()->get("java/lang/Thread")) + threadVMData = initialClassLoader->loadClass(names()->get("java/lang/Thread")) ->findVirtualField(names()->get(L"eetop"), typeLong); threadRun = initialClassLoader->method(0, L"java/lang/Thread", L"run", L"()V"); @@ -160,8 +160,8 @@ void J3::nullPointerException() { internalError(L"implement me: null pointer exception"); } -void J3::noClassDefFoundError(J3Class* cl) { - internalError(L"NoClassDefFoundError: %ls (%p - %p)", cl->name()->cStr(), cl, cl->name()); +void J3::noClassDefFoundError(const vmkit::Name* name) { + internalError(L"NoClassDefFoundError: %ls", name); } void J3::noSuchMethodError(const wchar_t* msg, J3Class* cl, const vmkit::Name* name, const vmkit::Name* sign) { Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=198173&r1=198172&r2=198173&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Sun Dec 29 12:18:24 2013 @@ -285,8 +285,11 @@ J3Field* J3Layout::findField(const vmkit /* * ------------ J3Class ------------ */ -J3Class::J3Class(J3ClassLoader* loader, const vmkit::Name* name) : J3Layout(loader, name), staticLayout(loader, this, name) { - status = CITED; +J3Class::J3Class(J3ClassLoader* loader, const vmkit::Name* name, J3ClassBytes* bytes) : + J3Layout(loader, name), + staticLayout(loader, this, name){ + _bytes = bytes; + status = LOADED; } size_t J3Class::size() { @@ -437,26 +440,7 @@ void J3Class::doInitialise() { unlock(); } -void J3Class::load() { - if(status < LOADED) { - lock(); - if(status < LOADED) { - if(loader()->vm()->options()->debugLoad) - fprintf(stderr, "Loading: %ls\n", name()->cStr()); - - _bytes = loader()->lookup(name()); - - if(!_bytes) - J3::noClassDefFoundError(this); - - status = LOADED; - } - unlock(); - } -} - void J3Class::doResolve(J3Field* hiddenFields, size_t nbHiddenFields) { - load(); lock(); if(status < RESOLVED) { if(loader()->vm()->options()->debugResolve) @@ -807,7 +791,7 @@ J3ObjectType* J3Class::classAt(uint16_t if(name->cStr()[0] == J3Cst::ID_Array) res = loader()->getType(this, name)->asObjectType(); else - res = loader()->getClass(name); + res = loader()->loadClass(name); ctpResolved[idx] = res; Modified: vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc?rev=198173&r1=198172&r2=198173&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3classloader.cc Sun Dec 29 12:18:24 2013 @@ -66,17 +66,25 @@ void* J3ClassLoader::lookupNativeFunctio return 0; } -J3Class* J3ClassLoader::getClass(const vmkit::Name* name) { +J3Class* J3ClassLoader::findLoadedClass(const vmkit::Name* name) { + pthread_mutex_lock(&_mutexClasses); + std::map::iterator it = classes.find(name); + J3Class* res = it == classes.end() ? 0 : it->second; + pthread_mutex_unlock(&_mutexClasses); + return res; +} + +J3Class* J3ClassLoader::defineClass(const vmkit::Name* name, J3ClassBytes* bytes) { pthread_mutex_lock(&_mutexClasses); J3Class* res = classes[name]; if(!res) - classes[name] = res = new(allocator()) J3Class(this, name); + classes[name] = res = new(allocator()) J3Class(this, name, bytes); pthread_mutex_unlock(&_mutexClasses); return res; } -J3ClassBytes* J3ClassLoader::lookup(const vmkit::Name* name) { - J3::internalError(L"should not happen"); +J3Class* J3ClassLoader::loadClass(const vmkit::Name* name) { + J3::internalError(L"implement me: loadClass from a Java class loader"); } void J3ClassLoader::wrongType(J3Class* from, const vmkit::Name* type) { @@ -120,7 +128,7 @@ J3Type* J3ClassLoader::getTypeInternal(J buf[pos++ - start] = 0; - res = getClass(vm()->names()->get(buf)); + res = loadClass(vm()->names()->get(buf)); } break; case J3Cst::ID_Left: @@ -210,7 +218,7 @@ J3Method* J3ClassLoader::method(uint16_t } J3Method* J3ClassLoader::method(uint16_t access, const vmkit::Name* clName, const vmkit::Name* name, const vmkit::Name* sign) { - return method(access, getClass(clName), name, sign); + return method(access, loadClass(clName), name, sign); } J3Method* J3ClassLoader::method(uint16_t access, const wchar_t* clName, const wchar_t* name, const wchar_t* sign) { @@ -253,9 +261,14 @@ J3InitialClassLoader::J3InitialClassLoad J3::internalError(L"unable to find java library"); } -J3ClassBytes* J3InitialClassLoader::lookup(const vmkit::Name* name) { - char tmp[name->length()+16]; +J3Class* J3InitialClassLoader::loadClass(const vmkit::Name* name) { + J3Class* res = findLoadedClass(name); + if(res) + return res; + + char tmp[name->length()+16]; + //printf("L: %ls\n", name->cStr()); for(int i=0; ilength(); i++) { char c = name->cStr()[i] & 0xff; @@ -265,10 +278,10 @@ J3ClassBytes* J3InitialClassLoader::look J3ZipFile* file = archive->getFile(tmp); if(file) { - J3ClassBytes* res = new(allocator(), file->ucsize) J3ClassBytes(file->ucsize); - - if(archive->readFile(res, file)) - return res; + J3ClassBytes* bytes = new(allocator(), file->ucsize) J3ClassBytes(file->ucsize); + + if(archive->readFile(bytes, file)) + return defineClass(name, bytes); } return 0; Modified: vmkit/branches/mcjit/lib/j3/vm/j3jni.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3jni.cc?rev=198173&r1=198172&r2=198173&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3jni.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3jni.cc Sun Dec 29 12:18:24 2013 @@ -23,7 +23,7 @@ jclass JNICALL FindClass(JNIEnv* env, co enterJVM(); J3Method* m = J3Thread::get()->getJavaCaller(); J3ClassLoader* loader = m ? m->cl()->loader() : J3Thread::get()->vm()->initialClassLoader; - J3Class* cl = loader->getClass(loader->vm()->names()->get(name)); + J3Class* cl = loader->loadClass(loader->vm()->names()->get(name)); cl->initialise(); res = cl->javaClass(); leaveJVM(); From gael.thomas at lip6.fr Sun Dec 29 14:15:59 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Sun, 29 Dec 2013 22:15:59 -0000 Subject: [vmkit-commits] [vmkit] r198179 - First J3Monitor implementation. Not yet used. Message-ID: <20131229221559.B469F2A6C029@llvm.org> Author: gthomas Date: Sun Dec 29 16:15:59 2013 New Revision: 198179 URL: http://llvm.org/viewvc/llvm-project?rev=198179&view=rev Log: First J3Monitor implementation. Not yet used. Added: vmkit/branches/mcjit/include/j3/j3monitor.h vmkit/branches/mcjit/lib/j3/vm/j3monitor.cc Modified: vmkit/branches/mcjit/include/j3/j3.h vmkit/branches/mcjit/include/j3/j3object.h vmkit/branches/mcjit/include/j3/j3thread.h vmkit/branches/mcjit/lib/j3/vm/j3.cc Modified: vmkit/branches/mcjit/include/j3/j3.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3.h?rev=198179&r1=198178&r2=198179&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3.h (original) +++ vmkit/branches/mcjit/include/j3/j3.h Sun Dec 29 16:15:59 2013 @@ -11,7 +11,7 @@ #include "j3/j3options.h" #include "j3/j3typesdef.h" #include "j3/j3jni.h" - +#include "j3/j3monitor.h" namespace j3 { class J3InitialClassLoader; @@ -30,7 +30,7 @@ namespace j3 { static vmkit::T_ptr_less_t charArrayLess; - J3Options _options; + J3Options _options; pthread_mutex_t stringsMutex; vmkit::NameMap::map nameToCharArrays; @@ -50,6 +50,8 @@ namespace j3 { onJavaTypes(defPrimitive) #undef defPrimitive + J3MonitorManager monitorManager; + void* interfaceTrampoline; J3Type** arrayInterfaces; @@ -117,6 +119,8 @@ namespace j3 { static void arrayStoreException() __attribute__((noreturn)); static void arrayIndexOutOfBoundsException() __attribute__((noreturn)); + static void illegalMonitorStateException() __attribute__((noreturn)); + static void printStackTrace(); void forceSymbolDefinition(); Added: vmkit/branches/mcjit/include/j3/j3monitor.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3monitor.h?rev=198179&view=auto ============================================================================== --- vmkit/branches/mcjit/include/j3/j3monitor.h (added) +++ vmkit/branches/mcjit/include/j3/j3monitor.h Sun Dec 29 16:15:59 2013 @@ -0,0 +1,57 @@ +#ifndef _J3_MONITOR_H_ +#define _J3_MONITOR_H_ + +#include +#include + +namespace vmkit { + class BumpAllocator; +} + +namespace j3 { + class J3Thread; + class J3Object; + + class J3Monitor { + friend class J3MonitorManager; + + J3Monitor* _next; + + J3Thread* owner; + uint32_t recursiveCount; + pthread_mutex_t mutex; + pthread_cond_t cond; + uintptr_t header; + J3Object* object; + + void init(J3Monitor* next); /* acquire the lock for the next inflate */ + public: + bool isDeflatable(); /* acquire the lock for the next inflate */ + void prepare(J3Object* _object, J3Thread* _owner, uint32_t _recursiveCount, uintptr_t _header); + + void lock(); + void unlock(); + + void wait(); + void timed_wait(uint64_t ms, uint32_t ns); + + void notify(); + void notifyAll(); + }; + + class J3MonitorManager { + static const uint32_t monitorsBucket = 256; + pthread_mutex_t mutex; + vmkit::BumpAllocator* allocator; + J3Monitor* head; + + public: + J3MonitorManager(vmkit::BumpAllocator* _allocator); + + J3Monitor* allocate(); + void release(J3Monitor* monitor); + }; + +} + +#endif Modified: vmkit/branches/mcjit/include/j3/j3object.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3object.h?rev=198179&r1=198178&r2=198179&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3object.h (original) +++ vmkit/branches/mcjit/include/j3/j3object.h Sun Dec 29 16:15:59 2013 @@ -86,10 +86,18 @@ namespace j3 { friend class J3ObjectHandle; public: static const uint32_t gepVT = 0; + static const uint32_t gepHeader = 1; private: J3VirtualTable* _vt; uintptr_t _header; + /* + * biased (not yet implemented): 0 | epoch | age | 101 + * thread_id | epoch | age | 101 + * not locked: hash-code 24 bits | age 5 bits | 001 + * stack locked: pointer to lock record | 00 + * inflated: pointer to monitor | 01 + */ J3Object(); /* never directly allocate an object */ Modified: vmkit/branches/mcjit/include/j3/j3thread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3thread.h?rev=198179&r1=198178&r2=198179&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3thread.h (original) +++ vmkit/branches/mcjit/include/j3/j3thread.h Sun Dec 29 16:15:59 2013 @@ -14,6 +14,8 @@ namespace j3 { class J3; class J3Thread : public vmkit::Thread { + friend class J3Monitor; + public: static const uint32_t gepInterfaceMethodIndex = 1; @@ -24,6 +26,7 @@ namespace j3 { J3LocalReferences _localReferences; J3ObjectHandle* _pendingException; J3ObjectHandle* _javaThread; + J3Thread* _nextLocked; virtual void run(); static void doRun(); Modified: vmkit/branches/mcjit/lib/j3/vm/j3.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3.cc?rev=198179&r1=198178&r2=198179&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3.cc Sun Dec 29 16:15:59 2013 @@ -25,7 +25,8 @@ J3::J3(vmkit::BumpAllocator* allocator) VMKit(allocator), nameToCharArrays(vmkit::Name::less, allocator), charArrayToStrings(charArrayLess, allocator), - _names(allocator) { + _names(allocator), + monitorManager(allocator) { pthread_mutex_init(&stringsMutex, 0); constantValueAttr = names()->get(J3Cst::constantValueAttr); codeAttr = names()->get(J3Cst::codeAttr); @@ -189,6 +190,10 @@ void J3::arrayIndexOutOfBoundsException( internalError(L"array bound check exception"); } +void J3::illegalMonitorStateException() { + internalError(L"illegal monitor state exception"); +} + void J3::vinternalError(const wchar_t* msg, va_list va) { wchar_t buf[65536]; vswprintf(buf, 65536, msg, va); Added: vmkit/branches/mcjit/lib/j3/vm/j3monitor.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3monitor.cc?rev=198179&view=auto ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3monitor.cc (added) +++ vmkit/branches/mcjit/lib/j3/vm/j3monitor.cc Sun Dec 29 16:15:59 2013 @@ -0,0 +1,124 @@ +#include "j3/j3monitor.h" +#include "j3/j3thread.h" +#include "j3/j3.h" + +#include + +using namespace j3; + +void J3Monitor::init(J3Monitor* next) { + pthread_mutex_init(&mutex, 0); + pthread_cond_init(&cond, 0); + pthread_mutex_lock(&mutex); +} + +bool J3Monitor::isDeflatable() { + return pthread_mutex_trylock(&mutex) == 0; +} + +void J3Monitor::prepare(J3Object* _object, J3Thread* _owner, uint32_t _recursiveCount, uintptr_t _header) { + object = _object; + owner = _owner; + recursiveCount = _recursiveCount; + header = _header; +} + +void J3Monitor::lock() { + J3Thread* self = J3Thread::get(); + if(owner == self) { + recursiveCount++; + } else { + pthread_mutex_lock(&mutex); + recursiveCount++; + owner = self; + } +} + +void J3Monitor::unlock() { + J3Thread* self = J3Thread::get(); + if(owner != self) + J3::illegalMonitorStateException(); + if(!--recursiveCount) { + owner = 0; + pthread_mutex_unlock(&mutex); + } else + __sync_synchronize(); /* JMM */ +} + +void J3Monitor::wait() { + timed_wait(0, 0); +} + +void J3Monitor::timed_wait(uint64_t ms, uint32_t ns) { + J3Thread* self = J3Thread::get(); + + if(owner != self) + J3::illegalMonitorStateException(); + + uint32_t r = recursiveCount; + owner = 0; + + if(ms || ns) { + struct timeval tv; + struct timespec ts; + gettimeofday(&tv, 0); + ts.tv_sec = tv.tv_sec + ms / 1000; + ts.tv_nsec = tv.tv_usec*1000 + ms % 1000 + ns; + if(ts.tv_nsec > 1e9) { + ts.tv_sec++; + ts.tv_nsec -= 1e9; + } + pthread_cond_timedwait(&cond, &mutex, &ts); + } else + pthread_cond_wait(&cond, &mutex); + + owner = self; + recursiveCount = r; +} + +void J3Monitor::notify() { + if(owner != J3Thread::get()) + J3::illegalMonitorStateException(); + pthread_cond_signal(&cond); +} + +void J3Monitor::notifyAll() { + if(owner != J3Thread::get()) + J3::illegalMonitorStateException(); + pthread_cond_broadcast(&cond); +} + + +J3MonitorManager::J3MonitorManager(vmkit::BumpAllocator* _allocator) { + pthread_mutex_init(&mutex, 0); + allocator = _allocator; +} + +J3Monitor* J3MonitorManager::allocate() { + pthread_mutex_lock(&mutex); + + J3Monitor* res = head; + + if(!res) { + uint32_t n = monitorsBucket; + J3Monitor* bucket = (J3Monitor*)allocator->allocate(sizeof(J3Monitor)*n); + + for(uint32_t i=0; i_next; + pthread_mutex_unlock(&mutex); + return res; +} + +void J3MonitorManager::release(J3Monitor* monitor) { + pthread_mutex_lock(&mutex); + monitor->_next = head; + head = monitor; + pthread_mutex_unlock(&mutex); +} + From gael.thomas at lip6.fr Mon Dec 30 03:34:19 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Mon, 30 Dec 2013 11:34:19 -0000 Subject: [vmkit-commits] [vmkit] r198210 - First version of stack locking algorithm. Inflation is not yet tested. Message-ID: <20131230113419.C444B2A6C029@llvm.org> Author: gthomas Date: Mon Dec 30 05:34:18 2013 New Revision: 198210 URL: http://llvm.org/viewvc/llvm-project?rev=198210&view=rev Log: First version of stack locking algorithm. Inflation is not yet tested. Modified: vmkit/branches/mcjit/include/j3/j3.h vmkit/branches/mcjit/include/j3/j3codegen.h vmkit/branches/mcjit/include/j3/j3meta.def vmkit/branches/mcjit/include/j3/j3monitor.h vmkit/branches/mcjit/include/j3/j3object.h vmkit/branches/mcjit/include/j3/j3thread.h vmkit/branches/mcjit/lib/j3/vm/j3.cc vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc vmkit/branches/mcjit/lib/j3/vm/j3object.cc Modified: vmkit/branches/mcjit/include/j3/j3.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3.h?rev=198210&r1=198209&r2=198210&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3.h (original) +++ vmkit/branches/mcjit/include/j3/j3.h Mon Dec 30 05:34:18 2013 @@ -92,6 +92,7 @@ namespace j3 { llvm::Type* typeJ3Object; llvm::Type* typeJ3ObjectPtr; llvm::Type* typeJ3ObjectHandlePtr; + llvm::Type* typeJ3LockRecord; llvm::Type* typeGXXException; J3Options* options() { return &_options; } Modified: vmkit/branches/mcjit/include/j3/j3codegen.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3codegen.h?rev=198210&r1=198209&r2=198210&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3codegen.h (original) +++ vmkit/branches/mcjit/include/j3/j3codegen.h Mon Dec 30 05:34:18 2013 @@ -81,6 +81,7 @@ namespace j3 { uint32_t wideReadU1(); uint32_t wideReadS1(); + llvm::Value* spToCurrentThread(llvm::Value* sp); llvm::Value* currentThread(); llvm::Value* nullCheck(llvm::Value* obj); @@ -100,6 +101,9 @@ namespace j3 { llvm::Value* vt(llvm::Value* obj); void initialiseJ3Type(J3Type* cl); + void monitorEnter(llvm::Value* obj); + void monitorExit(llvm::Value* obj); + llvm::Value* isAssignableTo(llvm::Value* obj, J3Type* type); void instanceof(llvm::Value* obj, J3Type* type); void checkCast(llvm::Value* obj, J3Type* type); Modified: vmkit/branches/mcjit/include/j3/j3meta.def URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3meta.def?rev=198210&r1=198209&r2=198210&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3meta.def (original) +++ vmkit/branches/mcjit/include/j3/j3meta.def Mon Dec 30 05:34:18 2013 @@ -8,6 +8,8 @@ _x(funcJ3ClassStringAt, "j3::J3 _x(funcJ3ObjectTypeJavaClass, "j3::J3ObjectType::javaClass()") _x(funcJniEnv, "j3::J3::jniEnv()") _x(funcJ3ObjectAllocate, "j3::J3Object::allocate(j3::J3VirtualTable*, unsigned long)") +_x(funcJ3ObjectMonitorEnter, "j3::J3Object::monitorEnter(j3::J3Object*)") +_x(funcJ3ObjectMonitorExit, "j3::J3Object::monitorExit(j3::J3Object*)") _x(funcThrowException, "vmkit::VMKit::throwException(void*)") _x(funcClassCastException, "j3::J3::classCastException()") _x(funcNullPointerException, "j3::J3::nullPointerException()") Modified: vmkit/branches/mcjit/include/j3/j3monitor.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3monitor.h?rev=198210&r1=198209&r2=198210&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3monitor.h (original) +++ vmkit/branches/mcjit/include/j3/j3monitor.h Mon Dec 30 05:34:18 2013 @@ -12,6 +12,15 @@ namespace j3 { class J3Thread; class J3Object; + class J3LockRecord { + public: + static const uint32_t gepHeader = 0; + static const uint32_t gepLockCount = 1; + + uintptr_t header; + uint32_t lockCount; + }; + class J3Monitor { friend class J3MonitorManager; Modified: vmkit/branches/mcjit/include/j3/j3object.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3object.h?rev=198210&r1=198209&r2=198210&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3object.h (original) +++ vmkit/branches/mcjit/include/j3/j3object.h Mon Dec 30 05:34:18 2013 @@ -92,15 +92,18 @@ namespace j3 { J3VirtualTable* _vt; uintptr_t _header; /* - * biased (not yet implemented): 0 | epoch | age | 101 - * thread_id | epoch | age | 101 - * not locked: hash-code 24 bits | age 5 bits | 001 - * stack locked: pointer to lock record | 00 - * inflated: pointer to monitor | 01 + * biasable (not yet implemented): 0 | epoch | age | 101 + * biased (not yet implemented): thread_id | epoch | age | 101 + * not locked: hash-code 24 bits | age 5 bits | 001 + * stack locked: pointer to lock record | 00 + * inflated: pointer to monitor | 10 */ J3Object(); /* never directly allocate an object */ + static void monitorEnter(J3Object* obj); + static void monitorExit(J3Object* obj); + static J3Object* allocate(J3VirtualTable* vt, size_t n); static J3Object* doNewNoInit(J3Class* cl); static J3Object* doNew(J3Class* cl); Modified: vmkit/branches/mcjit/include/j3/j3thread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3thread.h?rev=198210&r1=198209&r2=198210&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3thread.h (original) +++ vmkit/branches/mcjit/include/j3/j3thread.h Mon Dec 30 05:34:18 2013 @@ -15,12 +15,11 @@ namespace j3 { class J3Thread : public vmkit::Thread { friend class J3Monitor; + friend class J3CodeGen; - public: static const uint32_t gepInterfaceMethodIndex = 1; + uint32_t _interfaceMethodIndex; - private: - uint32_t _interfaceMethodIndex; vmkit::BumpAllocator* _allocator; JNIEnv _jniEnv; J3LocalReferences _localReferences; Modified: vmkit/branches/mcjit/lib/j3/vm/j3.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3.cc?rev=198210&r1=198209&r2=198210&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3.cc Mon Dec 30 05:34:18 2013 @@ -58,6 +58,7 @@ void J3::introspect() { typeJ3Object = introspectType("class.j3::J3Object"); typeJ3ObjectPtr = llvm::PointerType::getUnqual(typeJ3Object); typeJ3ObjectHandlePtr = llvm::PointerType::getUnqual(introspectType("class.j3::J3ObjectHandle")); + typeJ3LockRecord = introspectType("class.j3::J3LockRecord"); typeGXXException = llvm::StructType::get(llvm::Type::getInt8Ty(llvmContext())->getPointerTo(), llvm::Type::getInt32Ty(llvmContext()), NULL); @@ -229,6 +230,7 @@ void J3::printStackTrace() { void J3::forceSymbolDefinition() { J3ArrayObject a; a.length(); /* J3ArrayObject */ + J3LockRecord* l = new J3LockRecord(); /* J3LockRecord */ try { throw (void*)0; } catch(void* e) { Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=198210&r1=198209&r2=198210&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Mon Dec 30 05:34:18 2013 @@ -158,15 +158,116 @@ llvm::Value* J3CodeGen::unflatten(llvm:: } } -llvm::Value* J3CodeGen::currentThread() { - llvm::Type* type = vm->dataLayout()->getIntPtrType(module()->getContext()); +llvm::Value* J3CodeGen::spToCurrentThread(llvm::Value* sp) { + llvm::Type* type = builder->getIntPtrTy(vm->dataLayout()); - return builder->CreateIntToPtr(builder->CreateAnd(builder->CreatePtrToInt(builder->CreateCall(frameAddress, builder->getInt32(0)), - type), + return builder->CreateIntToPtr(builder->CreateAnd(builder->CreatePtrToInt(sp, type), llvm::ConstantInt::get(type, vmkit::Thread::getThreadMask())), vm->typeJ3Thread); } +llvm::Value* J3CodeGen::currentThread() { + return spToCurrentThread(builder->CreateCall(frameAddress, builder->getInt32(0))); +} + +void J3CodeGen::monitorEnter(llvm::Value* obj) { + llvm::Type* uintPtrTy = builder->getIntPtrTy(vm->dataLayout()); + llvm::Type* recordTy = vm->typeJ3LockRecord; + llvm::Type* recordPtrTy = vm->typeJ3LockRecord->getPointerTo(); + + llvm::AllocaInst* recordPtr = builder->CreateAlloca(recordPtrTy); + + llvm::BasicBlock* ok = forwardBranch("lock-ok", codeReader->tell(), 0, 0); + llvm::BasicBlock* stackLocked = newBB("stack-locked"); + llvm::BasicBlock* tryStackLock = newBB("try-stack-lock"); + llvm::BasicBlock* stackFail = newBB("stack-lock-fail"); + + /* already stack locked by myself? */ + llvm::Value* gepH[] = { builder->getInt32(0), builder->getInt32(J3Object::gepHeader) }; + llvm::Value* headerPtr = builder->CreateGEP(obj, gepH); + llvm::Value* header = builder->CreateLoad(headerPtr); + + builder->CreateStore(builder->CreateIntToPtr(header, recordPtrTy), recordPtr); + builder->CreateCondBr(builder->CreateICmpEQ(currentThread(), spToCurrentThread(header)), + stackLocked, tryStackLock); + + /* try to stack lock */ + builder->SetInsertPoint(tryStackLock); + llvm::AllocaInst* record = builder->CreateAlloca(recordTy); + builder->CreateStore(record, recordPtr); + llvm::Value* gepR[] = { builder->getInt32(0), builder->getInt32(J3LockRecord::gepHeader) }; + builder->CreateStore(header, builder->CreateGEP(record, gepR)); + llvm::Value* orig = builder->CreateOr(builder->CreateAnd(header, llvm::ConstantInt::get(uintPtrTy, ~6)), + llvm::ConstantInt::get(uintPtrTy, 1)); /* ...001 */ + llvm::Value* res = builder->CreateAtomicCmpXchg(headerPtr, + orig, + builder->CreatePtrToInt(record, uintPtrTy), + llvm::SequentiallyConsistent, + llvm::CrossThread); + builder->CreateCondBr(builder->CreateICmpEQ(res, orig), stackLocked, stackFail); + + /* stack locked, increment the counter */ + builder->SetInsertPoint(stackLocked); + llvm::Value* gepC[] = { builder->getInt32(0), builder->getInt32(J3LockRecord::gepLockCount) }; + llvm::Value* countPtr = builder->CreateGEP(builder->CreateLoad(recordPtr), gepC); + builder->CreateStore(builder->CreateAdd(builder->CreateLoad(countPtr), builder->getInt32(1)), countPtr); + builder->CreateBr(ok); + + /* unable to stack lock, fall back to monitor */ + builder->SetInsertPoint(stackFail); + builder->CreateCall(funcJ3ObjectMonitorEnter, obj); + builder->CreateBr(ok); +} + +void J3CodeGen::monitorExit(llvm::Value* obj) { + llvm::Type* uintPtrTy = builder->getIntPtrTy(vm->dataLayout()); + llvm::Type* recordPtrTy = vm->typeJ3LockRecord->getPointerTo(); + + llvm::BasicBlock* ok = forwardBranch("unlock-ok", codeReader->tell(), 0, 0); + llvm::BasicBlock* stackUnlock = newBB("stack-unlock"); + //llvm::BasicBlock* tryStackLock = newBB("try-stack-lock"); + llvm::BasicBlock* monitorUnlock = newBB("monitor-unlock"); + llvm::BasicBlock* stackRelease = newBB("stack-release"); + llvm::BasicBlock* stackRec = newBB("stack-rec"); + + /* stack locked by myself? */ + llvm::Value* gepH[] = { builder->getInt32(0), builder->getInt32(J3Object::gepHeader) }; + llvm::Value* headerPtr = builder->CreateGEP(obj, gepH); + llvm::Value* header = builder->CreateLoad(headerPtr); + + builder->CreateCondBr(builder->CreateICmpEQ(currentThread(), spToCurrentThread(header)), + stackUnlock, monitorUnlock); + + /* ok, I'm the owner */ + builder->SetInsertPoint(stackUnlock); + llvm::Value* gepC[] = { builder->getInt32(0), builder->getInt32(J3LockRecord::gepLockCount) }; + llvm::Value* recordPtr = builder->CreateIntToPtr(header, recordPtrTy); + llvm::Value* countPtr = builder->CreateGEP(recordPtr, gepC); + llvm::Value* count = builder->CreateSub(builder->CreateLoad(countPtr), builder->getInt32(1)); + builder->CreateCondBr(builder->CreateICmpEQ(count, builder->getInt32(0)), stackRelease, stackRec); + + /* last unlock */ + builder->SetInsertPoint(stackRelease); + llvm::Value* gepR[] = { builder->getInt32(0), builder->getInt32(J3LockRecord::gepHeader) }; + llvm::Value* orig = builder->CreateLoad(builder->CreateGEP(recordPtr, gepR)); + llvm::Value* res = builder->CreateAtomicCmpXchg(headerPtr, + header, + orig, + llvm::SequentiallyConsistent, + llvm::CrossThread); + builder->CreateCondBr(builder->CreateICmpEQ(res, header), ok, monitorUnlock); + + /* recursive unlock */ + builder->SetInsertPoint(stackRec); + builder->CreateStore(count, countPtr); + builder->CreateBr(ok); + + /* monitor unlock */ + builder->SetInsertPoint(monitorUnlock); + builder->CreateCall(funcJ3ObjectMonitorExit, obj); + builder->CreateBr(ok); +} + void J3CodeGen::initialiseJ3Type(J3Type* cl) { if(!cl->isInitialised()) builder->CreateCall(funcJ3TypeInitialise, builder->CreateBitCast(cl->llvmDescriptor(module()), vm->typeJ3TypePtr)); @@ -1320,11 +1421,11 @@ void J3CodeGen::translate() { break; case J3Cst::BC_monitorenter: /* 0xc2 */ - stack.pop(); + monitorEnter(stack.pop()); break; case J3Cst::BC_monitorexit: /* 0xc3 */ - stack.pop(); + monitorExit(stack.pop()); break; case J3Cst::BC_wide: nyi(); /* 0xc4 */ @@ -1386,7 +1487,7 @@ void J3CodeGen::generateJava() { J3::classFormatError(cl, L"Code attribute of %ls %ls is too large (%d)", method->name()->cStr(), method->sign()->cStr(), length); nullValue = builder - ->CreateIntToPtr(llvm::ConstantInt::get(vm->dataLayout()->getIntPtrType(module()->getContext()), (uintptr_t)0), + ->CreateIntToPtr(llvm::ConstantInt::get(builder->getIntPtrTy(vm->dataLayout()), (uintptr_t)0), vm->typeJ3ObjectPtr); llvm::DIBuilder* dbgBuilder = new llvm::DIBuilder(*module()); Modified: vmkit/branches/mcjit/lib/j3/vm/j3object.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3object.cc?rev=198210&r1=198209&r2=198210&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3object.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3object.cc Mon Dec 30 05:34:18 2013 @@ -274,6 +274,7 @@ uintptr_t* J3Object::header() { J3Object* J3Object::allocate(J3VirtualTable* vt, size_t n) { J3Object* res = (J3Object*)vmkit::GC::allocate(n); res->_vt = vt; + res->_header = 1; return res; } @@ -286,6 +287,14 @@ J3Object* J3Object::doNew(J3Class* cl) { return doNewNoInit(cl); } +void J3Object::monitorEnter(J3Object* obj) { + J3::internalError(L"implement me: monitorenter"); +} + +void J3Object::monitorExit(J3Object* obj) { + J3::internalError(L"implement me: monitorexit"); +} + /* * --- J3ArrayObject --- */ From gael.thomas at lip6.fr Mon Dec 30 07:35:03 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Mon, 30 Dec 2013 15:35:03 -0000 Subject: [vmkit-commits] [vmkit] r198211 - hashCode and wait are working with my stack locking/thin lock algorithm. Message-ID: <20131230153504.2956D2A6C029@llvm.org> Author: gthomas Date: Mon Dec 30 09:35:02 2013 New Revision: 198211 URL: http://llvm.org/viewvc/llvm-project?rev=198211&view=rev Log: hashCode and wait are working with my stack locking/thin lock algorithm. Modified: vmkit/branches/mcjit/include/j3/j3monitor.h vmkit/branches/mcjit/include/j3/j3object.h vmkit/branches/mcjit/include/j3/j3thread.h vmkit/branches/mcjit/include/vmkit/thread.h vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc vmkit/branches/mcjit/lib/j3/vm/j3monitor.cc vmkit/branches/mcjit/lib/j3/vm/j3object.cc vmkit/branches/mcjit/lib/j3/vm/j3thread.cc vmkit/branches/mcjit/lib/vmkit/thread.cc Modified: vmkit/branches/mcjit/include/j3/j3monitor.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3monitor.h?rev=198211&r1=198210&r2=198211&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3monitor.h (original) +++ vmkit/branches/mcjit/include/j3/j3monitor.h Mon Dec 30 09:35:02 2013 @@ -23,20 +23,24 @@ namespace j3 { class J3Monitor { friend class J3MonitorManager; + friend class J3Object; J3Monitor* _next; J3Thread* owner; - uint32_t recursiveCount; + uint32_t lockCount; pthread_mutex_t mutex; pthread_cond_t cond; uintptr_t header; J3Object* object; + J3LockRecord* record; + + void checkRecord(); void init(J3Monitor* next); /* acquire the lock for the next inflate */ public: bool isDeflatable(); /* acquire the lock for the next inflate */ - void prepare(J3Object* _object, J3Thread* _owner, uint32_t _recursiveCount, uintptr_t _header); + void prepare(J3Object* _object, uintptr_t header, J3LockRecord* _record); void lock(); void unlock(); Modified: vmkit/branches/mcjit/include/j3/j3object.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3object.h?rev=198211&r1=198210&r2=198211&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3object.h (original) +++ vmkit/branches/mcjit/include/j3/j3object.h Mon Dec 30 09:35:02 2013 @@ -22,6 +22,7 @@ namespace j3 { class J3VirtualTable; class J3FixedPoint; class J3Method; + class J3Monitor; // see: Cliff Click and John Rose. 2002. Fast subtype checking in the HotSpot JVM. // In Proceedings of the 2002 joint ACM-ISCOPE conference on Java Grande (JGI '02). ACM, New York, NY, USA, 96-107. @@ -89,8 +90,8 @@ namespace j3 { static const uint32_t gepHeader = 1; private: - J3VirtualTable* _vt; - uintptr_t _header; + J3VirtualTable* _vt; + volatile uintptr_t _header; /* * biasable (not yet implemented): 0 | epoch | age | 101 * biased (not yet implemented): thread_id | epoch | age | 101 @@ -101,6 +102,9 @@ namespace j3 { J3Object(); /* never directly allocate an object */ + J3Monitor* monitor(); + uint32_t hashCode(); + static void monitorEnter(J3Object* obj); static void monitorExit(J3Object* obj); @@ -109,8 +113,8 @@ namespace j3 { static J3Object* doNew(J3Class* cl); public: - J3VirtualTable* vt(); - uintptr_t* header(); + J3VirtualTable* vt(); + volatile uintptr_t* header(); }; class J3ArrayObject : public J3Object { @@ -151,6 +155,8 @@ namespace j3 { static J3ObjectHandle* doNewObject(J3Class* cl); static J3ObjectHandle* doNewArray(J3ArrayClass* cl, uint32_t length); + void wait(); + bool isSame(J3ObjectHandle* handle) { return obj() == handle->obj(); } void harakiri() { _obj = 0; } Modified: vmkit/branches/mcjit/include/j3/j3thread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3thread.h?rev=198211&r1=198210&r2=198211&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3thread.h (original) +++ vmkit/branches/mcjit/include/j3/j3thread.h Mon Dec 30 09:35:02 2013 @@ -25,7 +25,6 @@ namespace j3 { J3LocalReferences _localReferences; J3ObjectHandle* _pendingException; J3ObjectHandle* _javaThread; - J3Thread* _nextLocked; virtual void run(); static void doRun(); @@ -57,6 +56,7 @@ namespace j3 { JNIEnv* jniEnv() { return &_jniEnv; } static J3Thread* get(); + static J3Thread* get(void* ptr); static void start(J3ObjectHandle* handle); }; Modified: vmkit/branches/mcjit/include/vmkit/thread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/thread.h?rev=198211&r1=198210&r2=198211&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/thread.h (original) +++ vmkit/branches/mcjit/include/vmkit/thread.h Mon Dec 30 09:35:02 2013 @@ -26,12 +26,13 @@ namespace vmkit { VMKit* vm() { return _vm; } + static uintptr_t getThreadMask(); + static Thread* get(void* ptr); static Thread* get(); void start(); void join(); - static uintptr_t getThreadMask(); }; class StackWalker { Modified: vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc?rev=198211&r1=198210&r2=198211&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc (original) +++ vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc Mon Dec 30 09:35:02 2013 @@ -33,7 +33,12 @@ jint JNICALL JVM_IHashCode(JNIEnv* env, return res; } -void JNICALL JVM_MonitorWait(JNIEnv* env, jobject obj, jlong ms) { enterJVM(); NYI(); leaveJVM(); } +void JNICALL JVM_MonitorWait(JNIEnv* env, jobject obj, jlong ms) { + enterJVM(); + obj->wait(); + leaveJVM(); +} + void JNICALL JVM_MonitorNotify(JNIEnv* env, jobject obj) { enterJVM(); NYI(); leaveJVM(); } void JNICALL JVM_MonitorNotifyAll(JNIEnv* env, jobject obj) { enterJVM(); NYI(); leaveJVM(); } jobject JNICALL JVM_Clone(JNIEnv* env, jobject obj) { enterJVM(); NYI(); leaveJVM(); } Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=198211&r1=198210&r2=198211&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Mon Dec 30 09:35:02 2013 @@ -197,6 +197,8 @@ void J3CodeGen::monitorEnter(llvm::Value builder->CreateStore(record, recordPtr); llvm::Value* gepR[] = { builder->getInt32(0), builder->getInt32(J3LockRecord::gepHeader) }; builder->CreateStore(header, builder->CreateGEP(record, gepR)); + llvm::Value* gepC[] = { builder->getInt32(0), builder->getInt32(J3LockRecord::gepLockCount) }; + builder->CreateStore(builder->getInt32(0), builder->CreateGEP(record, gepC)); llvm::Value* orig = builder->CreateOr(builder->CreateAnd(header, llvm::ConstantInt::get(uintPtrTy, ~6)), llvm::ConstantInt::get(uintPtrTy, 1)); /* ...001 */ llvm::Value* res = builder->CreateAtomicCmpXchg(headerPtr, @@ -208,7 +210,6 @@ void J3CodeGen::monitorEnter(llvm::Value /* stack locked, increment the counter */ builder->SetInsertPoint(stackLocked); - llvm::Value* gepC[] = { builder->getInt32(0), builder->getInt32(J3LockRecord::gepLockCount) }; llvm::Value* countPtr = builder->CreateGEP(builder->CreateLoad(recordPtr), gepC); builder->CreateStore(builder->CreateAdd(builder->CreateLoad(countPtr), builder->getInt32(1)), countPtr); builder->CreateBr(ok); Modified: vmkit/branches/mcjit/lib/j3/vm/j3monitor.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3monitor.cc?rev=198211&r1=198210&r2=198211&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3monitor.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3monitor.cc Mon Dec 30 09:35:02 2013 @@ -16,29 +16,39 @@ bool J3Monitor::isDeflatable() { return pthread_mutex_trylock(&mutex) == 0; } -void J3Monitor::prepare(J3Object* _object, J3Thread* _owner, uint32_t _recursiveCount, uintptr_t _header) { +void J3Monitor::prepare(J3Object* _object, uintptr_t _header, J3LockRecord* _record) { object = _object; - owner = _owner; - recursiveCount = _recursiveCount; + record = _record; header = _header; + owner = _record ? J3Thread::get(_record) : 0; +} + +void J3Monitor::checkRecord() { + if(record) { + lockCount = record->lockCount; + record = 0; + } } void J3Monitor::lock() { J3Thread* self = J3Thread::get(); - if(owner == self) { - recursiveCount++; - } else { + + if(owner == self) + checkRecord(); + else { pthread_mutex_lock(&mutex); - recursiveCount++; owner = self; } + lockCount++; } void J3Monitor::unlock() { J3Thread* self = J3Thread::get(); if(owner != self) J3::illegalMonitorStateException(); - if(!--recursiveCount) { + + checkRecord(); + if(!--lockCount) { owner = 0; pthread_mutex_unlock(&mutex); } else @@ -55,7 +65,9 @@ void J3Monitor::timed_wait(uint64_t ms, if(owner != self) J3::illegalMonitorStateException(); - uint32_t r = recursiveCount; + checkRecord(); + + uint32_t r = lockCount; owner = 0; if(ms || ns) { @@ -69,11 +81,12 @@ void J3Monitor::timed_wait(uint64_t ms, ts.tv_nsec -= 1e9; } pthread_cond_timedwait(&cond, &mutex, &ts); + } else pthread_cond_wait(&cond, &mutex); owner = self; - recursiveCount = r; + lockCount = r; } void J3Monitor::notify() { Modified: vmkit/branches/mcjit/lib/j3/vm/j3object.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3object.cc?rev=198211&r1=198210&r2=198211&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3object.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3object.cc Mon Dec 30 09:35:02 2013 @@ -13,6 +13,7 @@ #include "j3/j3.h" #include "j3/j3constants.h" #include "j3/j3thread.h" +#include "j3/j3monitor.h" using namespace j3; @@ -267,7 +268,7 @@ J3VirtualTable* J3Object::vt() { return _vt; } -uintptr_t* J3Object::header() { +volatile uintptr_t* J3Object::header() { return &_header; } @@ -295,6 +296,73 @@ void J3Object::monitorExit(J3Object* obj J3::internalError(L"implement me: monitorexit"); } +uint32_t J3Object::hashCode() { + static uint32_t curHashCode = 0; + + while(1) { + uintptr_t header = _header; + if((header & 0x7) == 1) { /* not locked, not inflated */ + uint32_t res = header >> 8; + if(res) + return res; + do { + res = __sync_add_and_fetch(&curHashCode, 1) & 0xffffff; + } while(!res); + + if(__sync_val_compare_and_swap(&_header, header, res<<8 | (header & 0xff)) == header) + return res; + } else { + /* if stack locked, force the inflation because I can not modify the stack of the owner */ + J3Monitor* m = monitor(); + + header = m->header; + + uint32_t res = header >> 8; + if(res) + return res; + do { + res = __sync_add_and_fetch(&curHashCode, 1) & 0xffffff; + } while(!res); + + if(__sync_val_compare_and_swap(&m->header, header, res<<8 | (header & 0xff)) == header) + return res; + } + } +} + +J3Monitor* J3Object::monitor() { + uintptr_t header = _header; + + while(1) { + uintptr_t header = _header; + + if((header & 0x3) == 2) { /* already inflated */ + J3Monitor* res = (J3Monitor*)(header & -2); + if(res) + return res; + else + sched_yield(); /* another guy is trying to inflate this monitor */ + } else if(__sync_val_compare_and_swap(&_header, header, 2) == header) { + /* ok, I'm the boss */ + J3Monitor* monitor = J3Thread::get()->vm()->monitorManager.allocate(); + + if(!(header & 3)) { /* stack locked */ + J3LockRecord* record = (J3LockRecord*)header; + fprintf(stderr, " preparing monitor with %p\n", record); + /* I can read record->header because, in the worst case, the owner is blocked in the sched_yield loop */ + monitor->prepare(this, record->header, record); + } else { /* not locked at all */ + if((header & 7) != 1) + J3::internalError(L"should not happen"); + monitor->prepare(this, header, 0); + } + _header = (uintptr_t)monitor | 2; + + return monitor; + } + } +} + /* * --- J3ArrayObject --- */ @@ -313,15 +381,12 @@ J3Object* J3ArrayObject::doNew(J3ArrayCl /* * J3ObjectHandle */ +void J3ObjectHandle::wait() { + obj()->monitor()->wait(); +} + uint32_t J3ObjectHandle::hashCode() { - do { - uintptr_t oh = *obj()->header(); - uintptr_t res = oh; - if(res) - return res; - uintptr_t nh = oh + 256; - __sync_val_compare_and_swap(obj()->header(), oh, nh); - } while(1); + return obj()->hashCode(); } J3ObjectHandle* J3ObjectHandle::allocate(J3VirtualTable* vt, size_t n) { Modified: vmkit/branches/mcjit/lib/j3/vm/j3thread.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3thread.cc?rev=198211&r1=198210&r2=198211&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3thread.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3thread.cc Mon Dec 30 09:35:02 2013 @@ -87,6 +87,10 @@ void J3Thread::restore(J3ObjectHandle* p _localReferences.restore(ptr); } +J3Thread* J3Thread::get(void* ptr) { + return (J3Thread*)Thread::get(ptr); +} + J3Thread* J3Thread::get() { return (J3Thread*)Thread::get(); } Modified: vmkit/branches/mcjit/lib/vmkit/thread.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/thread.cc?rev=198211&r1=198210&r2=198211&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/thread.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/thread.cc Mon Dec 30 09:35:02 2013 @@ -17,7 +17,11 @@ void Thread::operator delete(void* p) { } Thread* Thread::get() { - return (Thread*)((uintptr_t)__builtin_frame_address(0) & getThreadMask()); + return get(__builtin_frame_address(0)); +} + +Thread* Thread::get(void* ptr) { + return (Thread*)((uintptr_t)ptr & getThreadMask()); } uintptr_t Thread::getThreadMask() { From gael.thomas at lip6.fr Mon Dec 30 07:36:21 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Mon, 30 Dec 2013 15:36:21 -0000 Subject: [vmkit-commits] [vmkit] r198212 - Add an interesting comment. Message-ID: <20131230153621.C93692A6C029@llvm.org> Author: gthomas Date: Mon Dec 30 09:36:21 2013 New Revision: 198212 URL: http://llvm.org/viewvc/llvm-project?rev=198212&view=rev Log: Add an interesting comment. Modified: vmkit/branches/mcjit/lib/j3/vm/j3object.cc Modified: vmkit/branches/mcjit/lib/j3/vm/j3object.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3object.cc?rev=198212&r1=198211&r2=198212&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3object.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3object.cc Mon Dec 30 09:36:21 2013 @@ -348,8 +348,8 @@ J3Monitor* J3Object::monitor() { if(!(header & 3)) { /* stack locked */ J3LockRecord* record = (J3LockRecord*)header; - fprintf(stderr, " preparing monitor with %p\n", record); /* I can read record->header because, in the worst case, the owner is blocked in the sched_yield loop */ + /* however, I can not read lockCount because the owner is maybe playing with this value */ monitor->prepare(this, record->header, record); } else { /* not locked at all */ if((header & 7) != 1) From gael.thomas at lip6.fr Mon Dec 30 08:05:59 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Mon, 30 Dec 2013 16:05:59 -0000 Subject: [vmkit-commits] [vmkit] r198213 - Preserve the java thread handle directly in the J3Thread structure Message-ID: <20131230160559.A29272A6C029@llvm.org> Author: gthomas Date: Mon Dec 30 10:05:59 2013 New Revision: 198213 URL: http://llvm.org/viewvc/llvm-project?rev=198213&view=rev Log: Preserve the java thread handle directly in the J3Thread structure Modified: vmkit/branches/mcjit/include/j3/j3object.h vmkit/branches/mcjit/include/j3/j3thread.h vmkit/branches/mcjit/lib/j3/openjdk/j3lib.cc vmkit/branches/mcjit/lib/j3/vm/j3class.cc vmkit/branches/mcjit/lib/j3/vm/j3thread.cc Modified: vmkit/branches/mcjit/include/j3/j3object.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3object.h?rev=198213&r1=198212&r2=198213&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3object.h (original) +++ vmkit/branches/mcjit/include/j3/j3object.h Mon Dec 30 10:05:59 2013 @@ -151,6 +151,8 @@ namespace j3 { J3VirtualTable* vt() { return obj()->vt(); } uint32_t arrayLength() { return array()->length(); } + J3ObjectHandle& operator=(const J3ObjectHandle& h) { _obj = h._obj; return *this; } + static J3ObjectHandle* allocate(J3VirtualTable* vt, size_t n); static J3ObjectHandle* doNewObject(J3Class* cl); static J3ObjectHandle* doNewArray(J3ArrayClass* cl, uint32_t length); Modified: vmkit/branches/mcjit/include/j3/j3thread.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3thread.h?rev=198213&r1=198212&r2=198213&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3thread.h (original) +++ vmkit/branches/mcjit/include/j3/j3thread.h Mon Dec 30 10:05:59 2013 @@ -24,7 +24,7 @@ namespace j3 { JNIEnv _jniEnv; J3LocalReferences _localReferences; J3ObjectHandle* _pendingException; - J3ObjectHandle* _javaThread; + J3ObjectHandle _javaThread; virtual void run(); static void doRun(); @@ -34,7 +34,7 @@ namespace j3 { ~J3Thread(); void assocJavaThread(J3ObjectHandle* javaThread); - J3ObjectHandle* javaThread() { return _javaThread; } + J3ObjectHandle* javaThread() { return &_javaThread; } static J3Thread* nativeThread(J3ObjectHandle* handle); J3Method* getJavaCaller(uint32_t level=0); Modified: vmkit/branches/mcjit/lib/j3/openjdk/j3lib.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/openjdk/j3lib.cc?rev=198213&r1=198212&r2=198213&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/openjdk/j3lib.cc (original) +++ vmkit/branches/mcjit/lib/j3/openjdk/j3lib.cc Mon Dec 30 10:05:59 2013 @@ -43,7 +43,7 @@ void J3Lib::bootstrap(J3* vm) { L"java/lang/Thread", J3Cst::initName, L"(Ljava/lang/ThreadGroup;Ljava/lang/String;)V"); - J3ObjectHandle* mainThread = vm->initialClassLoader->globalReferences()->add(J3ObjectHandle::doNewObject(threadInit->cl())); + J3ObjectHandle* mainThread = J3ObjectHandle::doNewObject(threadInit->cl()); J3Thread::get()->assocJavaThread(mainThread); mainThread->setInteger(threadInit->cl()->findVirtualField(vm->names()->get(L"priority"), vm->typeInteger), 5); Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=198213&r1=198212&r2=198213&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Mon Dec 30 10:05:59 2013 @@ -158,7 +158,7 @@ J3ObjectType::J3ObjectType(J3ClassLoader } J3Method* J3ObjectType::findVirtualMethod(const vmkit::Name* name, const vmkit::Name* sign, bool error) { - J3::internalError(L"should not happen"); + J3::internalError(L"should not happe: %ls::%ls\n", J3ObjectType::name()->cStr(), name->cStr()); } J3Method* J3ObjectType::findStaticMethod(const vmkit::Name* name, const vmkit::Name* sign, bool error) { Modified: vmkit/branches/mcjit/lib/j3/vm/j3thread.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3thread.cc?rev=198213&r1=198212&r2=198213&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3thread.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3thread.cc Mon Dec 30 10:05:59 2013 @@ -21,6 +21,7 @@ J3Thread::~J3Thread() { void J3Thread::doRun() { J3ObjectHandle* handle = get()->javaThread(); + fprintf(stderr, " *** target is %ls\n", handle->vt()->type()->name()->cStr()); get()->vm()->threadRun->invokeVirtual(handle); } @@ -30,11 +31,11 @@ void J3Thread::run() { } void J3Thread::start(J3ObjectHandle* handle) { + fprintf(stderr, " start %ls\n", handle->vt()->type()->name()->cStr()); vmkit::BumpAllocator* allocator = vmkit::BumpAllocator::create(); J3Thread* thread = new J3Thread(get()->vm()); thread->assocJavaThread(handle); thread->Thread::start(); - while(1); } J3Method* J3Thread::getJavaCaller(uint32_t level) { @@ -67,8 +68,8 @@ J3Thread* J3Thread::nativeThread(J3Objec } void J3Thread::assocJavaThread(J3ObjectHandle* javaThread) { - _javaThread = javaThread; - _javaThread->setLong(vm()->threadVMData, (int64_t)(uintptr_t)this); + _javaThread = *javaThread; + _javaThread.setLong(vm()->threadVMData, (int64_t)(uintptr_t)this); } J3ObjectHandle* J3Thread::push(J3ObjectHandle* handle) { From gael.thomas at lip6.fr Mon Dec 30 08:31:27 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Mon, 30 Dec 2013 16:31:27 -0000 Subject: [vmkit-commits] [vmkit] r198215 - Add a compiler lock, but it's not enough. LLVMContext is definitly not thread safe... Message-ID: <20131230163127.B10EE2A6C029@llvm.org> Author: gthomas Date: Mon Dec 30 10:31:27 2013 New Revision: 198215 URL: http://llvm.org/viewvc/llvm-project?rev=198215&view=rev Log: Add a compiler lock, but it's not enough. LLVMContext is definitly not thread safe... Modified: vmkit/branches/mcjit/include/j3/j3.h vmkit/branches/mcjit/include/vmkit/vmkit.h vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc vmkit/branches/mcjit/lib/j3/vm/j3.cc vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc vmkit/branches/mcjit/lib/vmkit/vmkit.cc Modified: vmkit/branches/mcjit/include/j3/j3.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3.h?rev=198215&r1=198214&r2=198215&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3.h (original) +++ vmkit/branches/mcjit/include/j3/j3.h Mon Dec 30 10:31:27 2013 @@ -70,6 +70,8 @@ namespace j3 { J3Field* threadVMData; J3Method* threadRun; + J3Class* fieldClass; + const vmkit::Name* codeAttr; const vmkit::Name* constantValueAttr; const vmkit::Name* initName; Modified: vmkit/branches/mcjit/include/vmkit/vmkit.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/vmkit.h?rev=198215&r1=198214&r2=198215&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/vmkit.h (original) +++ vmkit/branches/mcjit/include/vmkit/vmkit.h Mon Dec 30 10:31:27 2013 @@ -29,6 +29,7 @@ namespace vmkit { llvm::Module* _self; llvm::DataLayout* _dataLayout; void* ptrTypeInfo; + pthread_mutex_t _compilerLock; void addSymbol(llvm::GlobalValue* gv); @@ -41,6 +42,9 @@ namespace vmkit { VMKit(BumpAllocator* allocator); + void lockCompiler(); + void unlockCompiler(); + const char* selfBitCodePath() { return _selfBitCodePath; } void addSafepoint(Safepoint* sf); Modified: vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc?rev=198215&r1=198214&r2=198215&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc (original) +++ vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc Mon Dec 30 10:31:27 2013 @@ -384,7 +384,14 @@ jbyteArray JNICALL JVM_GetClassTypeAnnot */ jobjectArray JNICALL JVM_GetClassDeclaredMethods(JNIEnv* env, jclass ofClass, jboolean publicOnly) { enterJVM(); NYI(); leaveJVM(); } -jobjectArray JNICALL JVM_GetClassDeclaredFields(JNIEnv* env, jclass ofClass, jboolean publicOnly) { enterJVM(); NYI(); leaveJVM(); } +jobjectArray JNICALL JVM_GetClassDeclaredFields(JNIEnv* env, jclass ofClass, jboolean publicOnly) { + enterJVM(); + J3ObjectType* type = J3ObjectType::nativeClass(ofClass); + + NYI(); + leaveJVM(); +} + jobjectArray JNICALL JVM_GetClassDeclaredConstructors(JNIEnv* env, jclass ofClass, jboolean publicOnly) { enterJVM(); NYI(); leaveJVM(); } /* Differs from JVM_GetClassModifiers in treatment of inner classes. Modified: vmkit/branches/mcjit/lib/j3/vm/j3.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3.cc?rev=198215&r1=198214&r2=198215&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3.cc Mon Dec 30 10:31:27 2013 @@ -111,6 +111,8 @@ void J3::run() { ->findVirtualField(names()->get(L"eetop"), typeLong); threadRun = initialClassLoader->method(0, L"java/lang/Thread", L"run", L"()V"); + fieldClass = initialClassLoader->loadClass(names()->get("java/lang/reflect/Field")); + J3Lib::bootstrap(this); } Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=198215&r1=198214&r2=198215&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Mon Dec 30 10:31:27 2013 @@ -107,7 +107,9 @@ void J3CodeGen::operator delete(void* pt void J3CodeGen::translate(J3Method* method, llvm::Function* llvmFunction) { vmkit::BumpAllocator* allocator = vmkit::BumpAllocator::create(); + method->cl()->loader()->vm()->lockCompiler(); delete new(allocator) J3CodeGen(allocator, method, llvmFunction); + method->cl()->loader()->vm()->unlockCompiler(); vmkit::BumpAllocator::destroy(allocator); } Modified: vmkit/branches/mcjit/lib/vmkit/vmkit.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/vmkit.cc?rev=198215&r1=198214&r2=198215&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/vmkit.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/vmkit.cc Mon Dec 30 10:31:27 2013 @@ -37,6 +37,7 @@ VMKit::VMKit(vmkit::BumpAllocator* alloc llvm::llvm_start_multithreaded(); _allocator = allocator; pthread_mutex_init(&safepointMapLock, 0); + pthread_mutex_init(&_compilerLock, 0); } void* VMKit::operator new(size_t n, vmkit::BumpAllocator* allocator) { @@ -47,6 +48,14 @@ void VMKit::destroy(VMKit* vm) { vmkit::BumpAllocator::destroy(vm->allocator()); } +void VMKit::lockCompiler() { + pthread_mutex_lock(&_compilerLock); +} + +void VMKit::unlockCompiler() { + pthread_mutex_unlock(&_compilerLock); +} + void VMKit::addSafepoint(Safepoint* sf) { pthread_mutex_lock(&safepointMapLock); safepointMap[sf->addr()] = sf; From gael.thomas at lip6.fr Mon Dec 30 08:38:12 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Mon, 30 Dec 2013 16:38:12 -0000 Subject: [vmkit-commits] [vmkit] r198216 - move J3Class::size into J3Layout Message-ID: <20131230163812.967A02A6C029@llvm.org> Author: gthomas Date: Mon Dec 30 10:38:12 2013 New Revision: 198216 URL: http://llvm.org/viewvc/llvm-project?rev=198216&view=rev Log: move J3Class::size into J3Layout Modified: vmkit/branches/mcjit/include/j3/j3class.h vmkit/branches/mcjit/include/j3/j3meta.def vmkit/branches/mcjit/lib/j3/vm/j3class.cc vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc vmkit/branches/mcjit/lib/j3/vm/j3thread.cc Modified: vmkit/branches/mcjit/include/j3/j3class.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3class.h?rev=198216&r1=198215&r2=198216&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3class.h (original) +++ vmkit/branches/mcjit/include/j3/j3class.h Mon Dec 30 10:38:12 2013 @@ -138,6 +138,7 @@ namespace j3 { J3Type* _type; J3Attributes* _attributes; uint32_t _num; + uint32_t _offset; public: J3Field() {} @@ -192,11 +193,15 @@ namespace j3 { size_t _nbMethods; J3Method** _methods; + + size_t _size; public: J3Layout(J3ClassLoader* loader, const vmkit::Name* name); virtual bool isLayout() { return 1; } + size_t size(); + size_t nbMethods() { return _nbMethods; } J3Method** methods() { return _methods; } @@ -220,8 +225,6 @@ namespace j3 { uint16_t _access; - size_t _size; - size_t _nbInterfaces; J3Class** _interfaces; J3Class* _super; /* this for root */ @@ -258,8 +261,6 @@ namespace j3 { J3Class* super() { return _super; } uint16_t access() { return _access; } - void adjustSize(uint32_t n) { _size += n; } - size_t size(); J3ObjectHandle* staticInstance(); void registerNative(const vmkit::Name* methName, const vmkit::Name* methSign, void* fnPtr); Modified: vmkit/branches/mcjit/include/j3/j3meta.def URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3meta.def?rev=198216&r1=198215&r2=198216&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3meta.def (original) +++ vmkit/branches/mcjit/include/j3/j3meta.def Mon Dec 30 10:38:12 2013 @@ -2,7 +2,7 @@ _x(funcJ3MethodIndex, "j3::J3 _x(funcJ3TypeVT, "j3::J3Type::vt()") _x(funcJ3TypeVTAndResolve, "j3::J3Type::vtAndResolve()") _x(funcJ3TypeInitialise, "j3::J3Type::initialise()") -_x(funcJ3ClassSize, "j3::J3Class::size()") +_x(funcJ3LayoutSize, "j3::J3Layout::size()") _x(funcJ3ClassStaticInstance, "j3::J3Class::staticInstance()") _x(funcJ3ClassStringAt, "j3::J3Class::stringAt(unsigned short)") _x(funcJ3ObjectTypeJavaClass, "j3::J3ObjectType::javaClass()") Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=198216&r1=198215&r2=198216&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Mon Dec 30 10:38:12 2013 @@ -256,6 +256,10 @@ J3StaticLayout::J3StaticLayout(J3ClassLo J3Layout::J3Layout(J3ClassLoader* loader, const vmkit::Name* name) : J3ObjectType(loader, name) { } +size_t J3Layout::size() { + return _size; +} + J3Method* J3Layout::findMethod(const vmkit::Name* name, const vmkit::Name* sign) { for(size_t i=0; i(module->getOrInsertGlobal(nativeName(), loader()->vm()->typeJ3Class)); } Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=198216&r1=198215&r2=198216&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Mon Dec 30 10:38:12 2013 @@ -513,7 +513,7 @@ void J3CodeGen::newObject(J3Class* cl) { llvm::Value* size; if(!cl->isResolved()) { - size = builder->CreateCall(funcJ3ClassSize, cl->llvmDescriptor(module())); + size = builder->CreateCall(funcJ3LayoutSize, cl->llvmDescriptor(module())); } else { size = builder->getInt64(cl->size()); } Modified: vmkit/branches/mcjit/lib/j3/vm/j3thread.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3thread.cc?rev=198216&r1=198215&r2=198216&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3thread.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3thread.cc Mon Dec 30 10:38:12 2013 @@ -35,7 +35,7 @@ void J3Thread::start(J3ObjectHandle* han vmkit::BumpAllocator* allocator = vmkit::BumpAllocator::create(); J3Thread* thread = new J3Thread(get()->vm()); thread->assocJavaThread(handle); - thread->Thread::start(); + //thread->Thread::start(); } J3Method* J3Thread::getJavaCaller(uint32_t level) { From gael.thomas at lip6.fr Mon Dec 30 08:47:22 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Mon, 30 Dec 2013 16:47:22 -0000 Subject: [vmkit-commits] [vmkit] r198217 - cast the llvmDescriptor into a J3LayoutPtr before calling size() Message-ID: <20131230164722.B8B5C2A6C029@llvm.org> Author: gthomas Date: Mon Dec 30 10:47:22 2013 New Revision: 198217 URL: http://llvm.org/viewvc/llvm-project?rev=198217&view=rev Log: cast the llvmDescriptor into a J3LayoutPtr before calling size() Modified: vmkit/branches/mcjit/include/j3/j3.h vmkit/branches/mcjit/lib/j3/vm/j3.cc vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Modified: vmkit/branches/mcjit/include/j3/j3.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3.h?rev=198217&r1=198216&r2=198217&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3.h (original) +++ vmkit/branches/mcjit/include/j3/j3.h Mon Dec 30 10:47:22 2013 @@ -82,6 +82,7 @@ namespace j3 { llvm::Type* typeJ3VirtualTablePtr; llvm::Type* typeJ3Type; llvm::Type* typeJ3TypePtr; + llvm::Type* typeJ3LayoutPtr; llvm::Type* typeJ3Thread; llvm::Type* typeJ3ObjectTypePtr; llvm::Type* typeJ3Class; Modified: vmkit/branches/mcjit/lib/j3/vm/j3.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3.cc?rev=198217&r1=198216&r2=198217&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3.cc Mon Dec 30 10:47:22 2013 @@ -46,6 +46,7 @@ void J3::introspect() { typeJ3VirtualTablePtr = llvm::PointerType::getUnqual(introspectType("class.j3::J3VirtualTable")); typeJ3Type = introspectType("class.j3::J3Type"); typeJ3TypePtr = llvm::PointerType::getUnqual(typeJ3Type); + typeJ3LayoutPtr = llvm::PointerType::getUnqual(introspectType("class.j3::J3Layout")); typeJ3ObjectTypePtr = llvm::PointerType::getUnqual(introspectType("class.j3::J3ObjectType")); typeJ3Thread = llvm::PointerType::getUnqual(introspectType("class.j3::J3Thread")); typeJ3Class = introspectType("class.j3::J3Class"); Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=198217&r1=198216&r2=198217&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Mon Dec 30 10:47:22 2013 @@ -513,7 +513,7 @@ void J3CodeGen::newObject(J3Class* cl) { llvm::Value* size; if(!cl->isResolved()) { - size = builder->CreateCall(funcJ3LayoutSize, cl->llvmDescriptor(module())); + size = builder->CreateCall(funcJ3LayoutSize, builder->CreateBitCast(cl->llvmDescriptor(module()), vm->typeJ3LayoutPtr)); } else { size = builder->getInt64(cl->size()); } From gael.thomas at lip6.fr Mon Dec 30 08:49:31 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Mon, 30 Dec 2013 16:49:31 -0000 Subject: [vmkit-commits] [vmkit] r198218 - Lazily allocate the llvm type of a Java method. Message-ID: <20131230164931.B0D912A6C029@llvm.org> Author: gthomas Date: Mon Dec 30 10:49:31 2013 New Revision: 198218 URL: http://llvm.org/viewvc/llvm-project?rev=198218&view=rev Log: Lazily allocate the llvm type of a Java method. Modified: vmkit/branches/mcjit/include/j3/j3method.h vmkit/branches/mcjit/lib/j3/vm/j3method.cc Modified: vmkit/branches/mcjit/include/j3/j3method.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3method.h?rev=198218&r1=198217&r2=198218&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3method.h (original) +++ vmkit/branches/mcjit/include/j3/j3method.h Mon Dec 30 10:49:31 2013 @@ -28,15 +28,15 @@ namespace j3 { class J3ObjectHandle; class J3MethodType : public vmkit::PermanentObject { - llvm::FunctionType* _llvmType; - J3Type* _out; - uint32_t _nbIns; - J3Type* _ins[1]; + llvm::FunctionType* volatile _llvmType; + J3Type* _out; + uint32_t _nbIns; + J3Type* _ins[1]; public: J3MethodType(J3Type** args, size_t nbArgs); - llvm::FunctionType* llvmType() { return _llvmType; } + llvm::FunctionType* llvmType(); uint32_t nbIns() { return _nbIns; } J3Type* out() { return _out; } J3Type* ins(uint32_t idx) { return _ins[idx]; } Modified: vmkit/branches/mcjit/lib/j3/vm/j3method.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3method.cc?rev=198218&r1=198217&r2=198218&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3method.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3method.cc Mon Dec 30 10:49:31 2013 @@ -26,10 +26,16 @@ J3MethodType::J3MethodType(J3Type** args _nbIns = nbArgs-1; memcpy(_ins, args, (nbArgs-1)*sizeof(J3Type*)); - std::vector in; - for(uint32_t i=0; illvmType()); - _llvmType = llvm::FunctionType::get(out()->llvmType(), in, 0); +} + +llvm::FunctionType* J3MethodType::llvmType() { + if(!_llvmType) { + std::vector in; + for(uint32_t i=0; illvmType()); + _llvmType = llvm::FunctionType::get(out()->llvmType(), in, 0); + } + return _llvmType; } J3Method::J3Method(uint16_t access, J3Class* cl, const vmkit::Name* name, const vmkit::Name* sign) : From gael.thomas at lip6.fr Mon Dec 30 09:02:13 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Mon, 30 Dec 2013 17:02:13 -0000 Subject: [vmkit-commits] [vmkit] r198219 - ensure that llvmFunction and llvmFunctionType are only called while the compiler lock is held Message-ID: <20131230170213.EC93C2A6C029@llvm.org> Author: gthomas Date: Mon Dec 30 11:02:13 2013 New Revision: 198219 URL: http://llvm.org/viewvc/llvm-project?rev=198219&view=rev Log: ensure that llvmFunction and llvmFunctionType are only called while the compiler lock is held Modified: vmkit/branches/mcjit/include/j3/j3method.h vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc vmkit/branches/mcjit/lib/j3/vm/j3method.cc Modified: vmkit/branches/mcjit/include/j3/j3method.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3method.h?rev=198219&r1=198218&r2=198219&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3method.h (original) +++ vmkit/branches/mcjit/include/j3/j3method.h Mon Dec 30 11:02:13 2013 @@ -28,7 +28,7 @@ namespace j3 { class J3ObjectHandle; class J3MethodType : public vmkit::PermanentObject { - llvm::FunctionType* volatile _llvmType; + llvm::FunctionType* volatile _llvmFunctionType; J3Type* _out; uint32_t _nbIns; J3Type* _ins[1]; @@ -36,7 +36,7 @@ namespace j3 { public: J3MethodType(J3Type** args, size_t nbArgs); - llvm::FunctionType* llvmType(); + llvm::FunctionType* llvmFunctionType(); /* only call this function from j3codegen */ uint32_t nbIns() { return _nbIns; } J3Type* out() { return _out; } J3Type* ins(uint32_t idx) { return _ins[idx]; } @@ -96,7 +96,7 @@ namespace j3 { llvm::Function* nativeLLVMFunction(llvm::Module* module); llvm::GlobalValue* llvmDescriptor(llvm::Module* module); - llvm::Function* llvmFunction(bool isStub, llvm::Module* module, J3Class* from=0); + llvm::Function* llvmFunction(bool isStub, llvm::Module* module, J3Class* from=0); /* only call from J3CodeGen */ uint32_t index(); uint32_t* indexPtr() { return &_index; } Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=198219&r1=198218&r2=198219&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Mon Dec 30 11:02:13 2013 @@ -107,9 +107,7 @@ void J3CodeGen::operator delete(void* pt void J3CodeGen::translate(J3Method* method, llvm::Function* llvmFunction) { vmkit::BumpAllocator* allocator = vmkit::BumpAllocator::create(); - method->cl()->loader()->vm()->lockCompiler(); delete new(allocator) J3CodeGen(allocator, method, llvmFunction); - method->cl()->loader()->vm()->unlockCompiler(); vmkit::BumpAllocator::destroy(allocator); } @@ -367,7 +365,7 @@ void J3CodeGen::invokeInterface(uint32_t builder->getInt32(J3VirtualTable::gepInterfaceMethods), builder->getInt32(index % J3VirtualTable::nbInterfaceMethodTable) }; llvm::Value* func = builder->CreateBitCast(builder->CreateLoad(builder->CreateGEP(vt(obj), gepFunc)), - type->llvmType()->getPointerTo()); + type->llvmFunctionType()->getPointerTo()); invoke(target, func); } @@ -387,7 +385,7 @@ void J3CodeGen::invokeVirtual(uint32_t i builder->getInt32(J3VirtualTable::gepVirtualMethods), funcEntry }; llvm::Value* func = builder->CreateBitCast(builder->CreateLoad(builder->CreateGEP(vt(obj), gepFunc)), - type->llvmType()->getPointerTo()); + type->llvmFunctionType()->getPointerTo()); invoke(target, func); } Modified: vmkit/branches/mcjit/lib/j3/vm/j3method.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3method.cc?rev=198219&r1=198218&r2=198219&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3method.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3method.cc Mon Dec 30 11:02:13 2013 @@ -28,14 +28,14 @@ J3MethodType::J3MethodType(J3Type** args } -llvm::FunctionType* J3MethodType::llvmType() { - if(!_llvmType) { +llvm::FunctionType* J3MethodType::llvmFunctionType() { + if(!_llvmFunctionType) { std::vector in; for(uint32_t i=0; illvmType()); - _llvmType = llvm::FunctionType::get(out()->llvmType(), in, 0); + _llvmFunctionType = llvm::FunctionType::get(out()->llvmType(), in, 0); } - return _llvmType; + return _llvmFunctionType; } J3Method::J3Method(uint16_t access, J3Class* cl, const vmkit::Name* name, const vmkit::Name* sign) : @@ -67,6 +67,7 @@ void* J3Method::fnPtr() { J3::noSuchMethodError(L"unable to find method", cl(), name(), sign()); } + cl()->loader()->vm()->lockCompiler(); llvm::Module* module = new llvm::Module(llvmFunctionName(), cl()->loader()->vm()->llvmContext()); _llvmFunction = llvmFunction(0, module); @@ -75,6 +76,7 @@ void* J3Method::fnPtr() { cl()->loader()->compileModule(module); _fnPtr = (void*)cl()->loader()->ee()->getFunctionAddress(_llvmFunction->getName().data()); + cl()->loader()->vm()->unlockCompiler(); } return _fnPtr; @@ -337,7 +339,7 @@ llvm::GlobalValue* J3Method::llvmDescrip llvm::Function* J3Method::llvmFunction(bool isStub, llvm::Module* module, J3Class* from) { const char* id = (isStub && !_fnPtr) ? llvmStubName(from) : llvmFunctionName(from); - return (llvm::Function*)module->getOrInsertFunction(id, methodType(from ? from : cl())->llvmType()); + return (llvm::Function*)module->getOrInsertFunction(id, methodType(from ? from : cl())->llvmFunctionType()); } void J3Method::dump() { From gael.thomas at lip6.fr Mon Dec 30 09:07:54 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Mon, 30 Dec 2013 17:07:54 -0000 Subject: [vmkit-commits] [vmkit] r198220 - also protect the updateGlobalMapping (this last will be removed as soon as possible) + prefix llvmFunction and llvmFunctionType with unsafe_ Message-ID: <20131230170754.6CD252A6C029@llvm.org> Author: gthomas Date: Mon Dec 30 11:07:54 2013 New Revision: 198220 URL: http://llvm.org/viewvc/llvm-project?rev=198220&view=rev Log: also protect the updateGlobalMapping (this last will be removed as soon as possible) + prefix llvmFunction and llvmFunctionType with unsafe_ Modified: vmkit/branches/mcjit/include/j3/j3method.h vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc vmkit/branches/mcjit/lib/j3/vm/j3method.cc Modified: vmkit/branches/mcjit/include/j3/j3method.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3method.h?rev=198220&r1=198219&r2=198220&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3method.h (original) +++ vmkit/branches/mcjit/include/j3/j3method.h Mon Dec 30 11:07:54 2013 @@ -36,7 +36,7 @@ namespace j3 { public: J3MethodType(J3Type** args, size_t nbArgs); - llvm::FunctionType* llvmFunctionType(); /* only call this function from j3codegen */ + llvm::FunctionType* unsafe_llvmFunctionType(); /* only call while compiler locked */ uint32_t nbIns() { return _nbIns; } J3Type* out() { return _out; } J3Type* ins(uint32_t idx) { return _ins[idx]; } @@ -96,7 +96,7 @@ namespace j3 { llvm::Function* nativeLLVMFunction(llvm::Module* module); llvm::GlobalValue* llvmDescriptor(llvm::Module* module); - llvm::Function* llvmFunction(bool isStub, llvm::Module* module, J3Class* from=0); /* only call from J3CodeGen */ + llvm::Function* unsafe_llvmFunction(bool isStub, llvm::Module* module, J3Class* from=0); /* only call while compiler locked */ uint32_t index(); uint32_t* indexPtr() { return &_index; } Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=198220&r1=198219&r2=198220&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Mon Dec 30 11:07:54 2013 @@ -365,7 +365,7 @@ void J3CodeGen::invokeInterface(uint32_t builder->getInt32(J3VirtualTable::gepInterfaceMethods), builder->getInt32(index % J3VirtualTable::nbInterfaceMethodTable) }; llvm::Value* func = builder->CreateBitCast(builder->CreateLoad(builder->CreateGEP(vt(obj), gepFunc)), - type->llvmFunctionType()->getPointerTo()); + type->unsafe_llvmFunctionType()->getPointerTo()); invoke(target, func); } @@ -385,7 +385,7 @@ void J3CodeGen::invokeVirtual(uint32_t i builder->getInt32(J3VirtualTable::gepVirtualMethods), funcEntry }; llvm::Value* func = builder->CreateBitCast(builder->CreateLoad(builder->CreateGEP(vt(obj), gepFunc)), - type->llvmFunctionType()->getPointerTo()); + type->unsafe_llvmFunctionType()->getPointerTo()); invoke(target, func); } @@ -393,12 +393,12 @@ void J3CodeGen::invokeVirtual(uint32_t i void J3CodeGen::invokeStatic(uint32_t idx) { J3Method* target = cl->methodAt(idx, J3Cst::ACC_STATIC); initialiseJ3Type(target->cl()); - invoke(target, target->llvmFunction(1, module(), cl)); + invoke(target, target->unsafe_llvmFunction(1, module(), cl)); } void J3CodeGen::invokeSpecial(uint32_t idx) { J3Method* target = cl->methodAt(idx, 0); - invoke(target, target->llvmFunction(1, module(), cl)); + invoke(target, target->unsafe_llvmFunction(1, module(), cl)); } void J3CodeGen::get(llvm::Value* src, J3Field* f) { Modified: vmkit/branches/mcjit/lib/j3/vm/j3method.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3method.cc?rev=198220&r1=198219&r2=198220&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3method.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3method.cc Mon Dec 30 11:07:54 2013 @@ -28,7 +28,7 @@ J3MethodType::J3MethodType(J3Type** args } -llvm::FunctionType* J3MethodType::llvmFunctionType() { +llvm::FunctionType* J3MethodType::unsafe_llvmFunctionType() { if(!_llvmFunctionType) { std::vector in; for(uint32_t i=0; iloader()->vm()->lockCompiler(); llvm::Module* module = new llvm::Module(llvmFunctionName(), cl()->loader()->vm()->llvmContext()); - _llvmFunction = llvmFunction(0, module); + _llvmFunction = unsafe_llvmFunction(0, module); J3CodeGen::translate(this, _llvmFunction); @@ -172,7 +172,9 @@ J3Value J3Method::internalInvoke(bool st //fprintf(stderr, "invoke: %ls::%ls%ls\n", target->cl()->name()->cStr(), target->name()->cStr(), target->sign()->cStr()); target->fnPtr(); /* ensure that the function is compiled */ + cl()->loader()->vm()->lockCompiler(); cl()->loader()->oldee()->updateGlobalMapping(target->_llvmFunction, target->fnPtr()); + cl()->loader()->vm()->unlockCompiler(); llvm::GenericValue res = cl()->loader()->oldee()->runFunction(target->_llvmFunction, args); J3Value holder; @@ -337,9 +339,9 @@ llvm::GlobalValue* J3Method::llvmDescrip return llvm::cast(module->getOrInsertGlobal(llvmDescriptorName(), cl()->loader()->vm()->typeJ3Method)); } -llvm::Function* J3Method::llvmFunction(bool isStub, llvm::Module* module, J3Class* from) { +llvm::Function* J3Method::unsafe_llvmFunction(bool isStub, llvm::Module* module, J3Class* from) { const char* id = (isStub && !_fnPtr) ? llvmStubName(from) : llvmFunctionName(from); - return (llvm::Function*)module->getOrInsertFunction(id, methodType(from ? from : cl())->llvmFunctionType()); + return (llvm::Function*)module->getOrInsertFunction(id, methodType(from ? from : cl())->unsafe_llvmFunctionType()); } void J3Method::dump() { From gael.thomas at lip6.fr Mon Dec 30 09:24:22 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Mon, 30 Dec 2013 17:24:22 -0000 Subject: [vmkit-commits] [vmkit] r198223 - Don't use the data layout to find the size of the Java types Message-ID: <20131230172422.5C3F82A6C029@llvm.org> Author: gthomas Date: Mon Dec 30 11:24:21 2013 New Revision: 198223 URL: http://llvm.org/viewvc/llvm-project?rev=198223&view=rev Log: Don't use the data layout to find the size of the Java types Modified: vmkit/branches/mcjit/include/j3/j3.h vmkit/branches/mcjit/include/j3/j3class.h vmkit/branches/mcjit/include/j3/j3object.h vmkit/branches/mcjit/include/j3/j3typesdef.h vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc vmkit/branches/mcjit/lib/j3/openjdk/j3unsafe.cc vmkit/branches/mcjit/lib/j3/vm/j3.cc vmkit/branches/mcjit/lib/j3/vm/j3class.cc vmkit/branches/mcjit/lib/j3/vm/j3object.cc Modified: vmkit/branches/mcjit/include/j3/j3.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3.h?rev=198223&r1=198222&r2=198223&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3.h (original) +++ vmkit/branches/mcjit/include/j3/j3.h Mon Dec 30 11:24:21 2013 @@ -45,7 +45,7 @@ namespace j3 { static J3* create(); -#define defPrimitive(name, ctype, llvmtype) \ +#define defPrimitive(name, ctype, llvmtype, scale) \ J3Primitive* type##name; onJavaTypes(defPrimitive) #undef defPrimitive Modified: vmkit/branches/mcjit/include/j3/j3class.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3class.h?rev=198223&r1=198222&r2=198223&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3class.h (original) +++ vmkit/branches/mcjit/include/j3/j3class.h Mon Dec 30 11:24:21 2013 @@ -53,7 +53,7 @@ namespace j3 { public: J3Type(J3ClassLoader* loader, const vmkit::Name* name); - uint64_t getLogSize(); + virtual uint32_t logSize() = 0; uint64_t getSizeInBits(); void* getSymbolAddress(); @@ -168,6 +168,8 @@ namespace j3 { public: J3ObjectType(J3ClassLoader* loader, const vmkit::Name* name); + uint32_t logSize() { return sizeof(uintptr_t) == 8 ? 3 : 2; } + J3InterfaceSlotDescriptor* slotDescriptorAt(uint32_t index) { return &_interfaceSlotDescriptors[index]; } void prepareInterfaceTable(); @@ -312,11 +314,13 @@ namespace j3 { }; class J3Primitive : public J3Type { + uint32_t _logSize; llvm::Type* _llvmType; public: - J3Primitive(J3ClassLoader* loader, char id, llvm::Type* type); + J3Primitive(J3ClassLoader* loader, char id, llvm::Type* type, uint32_t logSize); + uint32_t logSize() { return _logSize; } bool isPrimitive() { return 1; } llvm::Type* llvmType() { return _llvmType; } }; Modified: vmkit/branches/mcjit/include/j3/j3object.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3object.h?rev=198223&r1=198222&r2=198223&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3object.h (original) +++ vmkit/branches/mcjit/include/j3/j3object.h Mon Dec 30 11:24:21 2013 @@ -174,7 +174,7 @@ namespace j3 { void setObjectAt(uint32_t idx, J3ObjectHandle* v); J3ObjectHandle* getObjectAt(uint32_t idx); -#define defAccessor(name, ctype, llvmtype) \ +#define defAccessor(name, ctype, llvmtype, scale) \ void rawSet##name(uint32_t offset, ctype value); \ ctype rawGet##name(uint32_t offset); \ void set##name(J3Field* f, ctype value); \ @@ -209,13 +209,13 @@ namespace j3 { class J3Value { public: union { -#define doIt(name, ctype, llvmtype) \ +#define doIt(name, ctype, llvmtype, scale) \ ctype val##name; onJavaFields(doIt); #undef doIt }; -#define doIt(name, ctype, llvmtype) \ +#define doIt(name, ctype, llvmtype, scale) \ J3Value(ctype val) { val##name = val; } onJavaFields(doIt); #undef doIt Modified: vmkit/branches/mcjit/include/j3/j3typesdef.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3typesdef.h?rev=198223&r1=198222&r2=198223&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3typesdef.h (original) +++ vmkit/branches/mcjit/include/j3/j3typesdef.h Mon Dec 30 11:24:21 2013 @@ -3,21 +3,21 @@ namespace j3 { -#define onJavaPrimitives(_) \ - _(Boolean, bool, Int1) \ - _(Byte, int8_t, Int8) \ - _(Short, int16_t, Int16) \ - _(Char, uint16_t, Int16) \ - _(Integer, int32_t, Int32) \ - _(Long, int64_t, Int64) \ - _(Float, float, Float) \ - _(Double, double, Double) \ +#define onJavaPrimitives(_) \ + _(Boolean, bool, Int1, 0) \ + _(Byte, int8_t, Int8, 0) \ + _(Short, int16_t, Int16, 1) \ + _(Char, uint16_t, Int16, 1) \ + _(Integer, int32_t, Int32, 2) \ + _(Long, int64_t, Int64, 3) \ + _(Float, float, Float, 2) \ + _(Double, double, Double, 3) \ #define onJavaObject(_) \ - _(Object, J3ObjectHandle*, Fatal) + _(Object, J3ObjectHandle*, Fatal, 3) #define onJavaVoid(_) \ - _(Void, void, Void) + _(Void, void, Void, 0) #define onJavaTypes(_) \ onJavaPrimitives(_) \ Modified: vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc?rev=198223&r1=198222&r2=198223&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc (original) +++ vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc Mon Dec 30 11:24:21 2013 @@ -68,7 +68,7 @@ void JNICALL JVM_ArrayCopy(JNIEnv* env, (dst_pos + length) > dst->arrayLength()) J3::arrayIndexOutOfBoundsException(); - uint32_t scale = srcType0->asArrayClass()->component()->getLogSize(); + uint32_t scale = srcType0->asArrayClass()->component()->logSize(); src->rawArrayCopyTo(src_pos << scale, dst, dst_pos << scale, length << scale); Modified: vmkit/branches/mcjit/lib/j3/openjdk/j3unsafe.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/openjdk/j3unsafe.cc?rev=198223&r1=198222&r2=198223&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/openjdk/j3unsafe.cc (original) +++ vmkit/branches/mcjit/lib/j3/openjdk/j3unsafe.cc Mon Dec 30 11:24:21 2013 @@ -28,7 +28,7 @@ extern "C" { /// makes this type of access impossible or unsupported. /// JNIEXPORT jlong JNICALL Java_sun_misc_Unsafe_arrayIndexScale(JNIEnv* env, jobject unsafe, jclass clazz) { - return J3ObjectType::nativeClass(clazz)->asArrayClass()->component()->getLogSize(); + return J3ObjectType::nativeClass(clazz)->asArrayClass()->component()->logSize(); } JNIEXPORT jint JNICALL Java_sun_misc_Unsafe_addressSize(JNIEnv* env, jobject unsafe) { Modified: vmkit/branches/mcjit/lib/j3/vm/j3.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3.cc?rev=198223&r1=198222&r2=198223&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3.cc Mon Dec 30 11:24:21 2013 @@ -85,8 +85,8 @@ void J3::run() { vmkit::BumpAllocator* a = initialClassLoader->allocator(); -#define defPrimitive(name, ctype, llvmtype) \ - type##name = new(a) J3Primitive(initialClassLoader, J3Cst::ID_##name, llvm::Type::get##llvmtype##Ty(llvmContext())); +#define defPrimitive(name, ctype, llvmtype, scale) \ + type##name = new(a) J3Primitive(initialClassLoader, J3Cst::ID_##name, llvm::Type::get##llvmtype##Ty(llvmContext()), scale); onJavaTypes(defPrimitive) #undef defPrimitive Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=198223&r1=198222&r2=198223&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Mon Dec 30 11:24:21 2013 @@ -71,22 +71,8 @@ J3ArrayClass* J3Type::getArray(uint32_t return prof > 1 ? _array->getArray(prof-1) : _array; } -uint64_t J3Type::getLogSize() { - uint32_t res = getSizeInBits(); - - switch(res) { - case 1: - case 8: return 0; - case 16: return 1; - case 32: return 2; - case 64: return 3; - default: - J3::internalError(L"unexpected type"); - } -} - uint64_t J3Type::getSizeInBits() { - return loader()->vm()->dataLayout()->getTypeSizeInBits(llvmType()); + return 1 << (logSize()+3); } bool J3Type::isAssignableTo(J3Type* parent) { @@ -964,12 +950,14 @@ llvm::Type* J3ArrayClass::llvmType() { /* * ------------ J3Primitive ------------ */ -J3Primitive::J3Primitive(J3ClassLoader* loader, char id, llvm::Type* type) : J3Type(loader, loader->vm()->names()->get(id)) { +J3Primitive::J3Primitive(J3ClassLoader* loader, char id, llvm::Type* type, uint32_t logSize) : + J3Type(loader, loader->vm()->names()->get(id)) { _llvmType = type; _nativeName = (char*)loader->allocator()->allocate(2); _nativeName[0] = id; _nativeName[1] = 0; _nativeNameLength = 1; _vt = J3VirtualTable::create(this); + _logSize = logSize; } Modified: vmkit/branches/mcjit/lib/j3/vm/j3object.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3object.cc?rev=198223&r1=198222&r2=198223&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3object.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3object.cc Mon Dec 30 11:24:21 2013 @@ -406,7 +406,7 @@ J3ObjectHandle* J3ObjectHandle::doNewArr -#define defAccessor(name, ctype, llvmtype) \ +#define defAccessor(name, ctype, llvmtype, scale) \ void J3ObjectHandle::rawSet##name(uint32_t offset, ctype value) { \ *((ctype*)((uintptr_t)obj() + offset)) = value; \ } \ From gael.thomas at lip6.fr Mon Dec 30 09:28:21 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Mon, 30 Dec 2013 17:28:21 -0000 Subject: [vmkit-commits] [vmkit] r198225 - Rename size() into structSize() to avoid any ambiguity Message-ID: <20131230172821.330BA2A6C029@llvm.org> Author: gthomas Date: Mon Dec 30 11:28:20 2013 New Revision: 198225 URL: http://llvm.org/viewvc/llvm-project?rev=198225&view=rev Log: Rename size() into structSize() to avoid any ambiguity Modified: vmkit/branches/mcjit/include/j3/j3class.h vmkit/branches/mcjit/include/j3/j3meta.def vmkit/branches/mcjit/lib/j3/vm/j3class.cc vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc vmkit/branches/mcjit/lib/j3/vm/j3object.cc Modified: vmkit/branches/mcjit/include/j3/j3class.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3class.h?rev=198225&r1=198224&r2=198225&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3class.h (original) +++ vmkit/branches/mcjit/include/j3/j3class.h Mon Dec 30 11:28:20 2013 @@ -196,13 +196,13 @@ namespace j3 { size_t _nbMethods; J3Method** _methods; - size_t _size; + size_t _structSize; public: J3Layout(J3ClassLoader* loader, const vmkit::Name* name); virtual bool isLayout() { return 1; } - size_t size(); + size_t structSize(); size_t nbMethods() { return _nbMethods; } J3Method** methods() { return _methods; } Modified: vmkit/branches/mcjit/include/j3/j3meta.def URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3meta.def?rev=198225&r1=198224&r2=198225&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3meta.def (original) +++ vmkit/branches/mcjit/include/j3/j3meta.def Mon Dec 30 11:28:20 2013 @@ -2,7 +2,7 @@ _x(funcJ3MethodIndex, "j3::J3 _x(funcJ3TypeVT, "j3::J3Type::vt()") _x(funcJ3TypeVTAndResolve, "j3::J3Type::vtAndResolve()") _x(funcJ3TypeInitialise, "j3::J3Type::initialise()") -_x(funcJ3LayoutSize, "j3::J3Layout::size()") +_x(funcJ3LayoutStructSize, "j3::J3Layout::structSize()") _x(funcJ3ClassStaticInstance, "j3::J3Class::staticInstance()") _x(funcJ3ClassStringAt, "j3::J3Class::stringAt(unsigned short)") _x(funcJ3ObjectTypeJavaClass, "j3::J3ObjectType::javaClass()") Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=198225&r1=198224&r2=198225&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Mon Dec 30 11:28:20 2013 @@ -242,8 +242,8 @@ J3StaticLayout::J3StaticLayout(J3ClassLo J3Layout::J3Layout(J3ClassLoader* loader, const vmkit::Name* name) : J3ObjectType(loader, name) { } -size_t J3Layout::size() { - return _size; +size_t J3Layout::structSize() { + return _structSize; } J3Method* J3Layout::findMethod(const vmkit::Name* name, const vmkit::Name* sign) { @@ -445,7 +445,7 @@ void J3Class::doResolve(J3Field* hiddenF llvm::cast(llvmType()->getContainedType(0))->setBody(virtualBody); - _size = loader()->vm()->dataLayout()->getTypeAllocSize(llvmType()->getContainedType(0)); + _structSize = loader()->vm()->dataLayout()->getTypeAllocSize(llvmType()->getContainedType(0)); staticLayout._vt = J3VirtualTable::create(&staticLayout); Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=198225&r1=198224&r2=198225&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Mon Dec 30 11:28:20 2013 @@ -511,9 +511,9 @@ void J3CodeGen::newObject(J3Class* cl) { llvm::Value* size; if(!cl->isResolved()) { - size = builder->CreateCall(funcJ3LayoutSize, builder->CreateBitCast(cl->llvmDescriptor(module()), vm->typeJ3LayoutPtr)); + size = builder->CreateCall(funcJ3LayoutStructSize, builder->CreateBitCast(cl->llvmDescriptor(module()), vm->typeJ3LayoutPtr)); } else { - size = builder->getInt64(cl->size()); + size = builder->getInt64(cl->structSize()); } llvm::Value* res = builder->CreateCall2(funcJ3ObjectAllocate, vt(cl), size); Modified: vmkit/branches/mcjit/lib/j3/vm/j3object.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3object.cc?rev=198225&r1=198224&r2=198225&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3object.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3object.cc Mon Dec 30 11:28:20 2013 @@ -280,7 +280,7 @@ J3Object* J3Object::allocate(J3VirtualTa } J3Object* J3Object::doNewNoInit(J3Class* cl) { - return allocate(cl->vtAndResolve(), cl->size()); + return allocate(cl->vtAndResolve(), cl->structSize()); } J3Object* J3Object::doNew(J3Class* cl) { From gael.thomas at lip6.fr Mon Dec 30 09:49:22 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Mon, 30 Dec 2013 17:49:22 -0000 Subject: [vmkit-commits] [vmkit] r198228 - Create the native names in separated functions in J3ClassArray and J3Class Message-ID: <20131230174922.75E752A6C029@llvm.org> Author: gthomas Date: Mon Dec 30 11:49:22 2013 New Revision: 198228 URL: http://llvm.org/viewvc/llvm-project?rev=198228&view=rev Log: Create the native names in separated functions in J3ClassArray and J3Class Modified: vmkit/branches/mcjit/include/j3/j3class.h vmkit/branches/mcjit/lib/j3/vm/j3class.cc vmkit/branches/mcjit/lib/j3/vm/j3options.cc vmkit/branches/mcjit/lib/j3/vm/j3thread.cc Modified: vmkit/branches/mcjit/include/j3/j3class.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3class.h?rev=198228&r1=198227&r2=198228&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3class.h (original) +++ vmkit/branches/mcjit/include/j3/j3class.h Mon Dec 30 11:49:22 2013 @@ -250,6 +250,7 @@ namespace j3 { void fillFields(std::vector* staticBody, std::vector* virtualBody, J3Field** fields, size_t n); void createLLVMTypes(); + void doNativeName(); void doResolve(J3Field* hiddenFields, size_t nbHiddenFields); void doInitialise(); @@ -302,6 +303,8 @@ namespace j3 { void doResolve(J3Field* hiddenFields, size_t nbHiddenFields); void doInitialise(); + + void doNativeName(); public: J3ArrayClass(J3ClassLoader* loader, J3Type* component, const vmkit::Name* name); Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=198228&r1=198227&r2=198228&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Mon Dec 30 11:49:22 2013 @@ -809,6 +809,23 @@ void J3Class::check(uint16_t idx, uint32 J3::classFormatError(this, L"wrong constant pool type %d at index %d for %d", id, idx, nbCtp); } +void J3Class::doNativeName() { + J3Mangler mangler(this); + + mangler.mangle(name()); + + _nativeNameLength = mangler.length() + 3; + _nativeName = (char*)loader()->allocator()->allocate(_nativeNameLength + 1); + + _nativeName[0] = 'L'; + memcpy(_nativeName + 1, mangler.cStr(), mangler.length()); + _nativeName[_nativeNameLength-2] = '_'; + _nativeName[_nativeNameLength-1] = '2'; + _nativeName[_nativeNameLength] = 0; + + loader()->addSymbol(_nativeName, this); +} + void J3Class::createLLVMTypes() { J3Mangler mangler(this); @@ -818,15 +835,7 @@ void J3Class::createLLVMTypes() { llvm::PointerType::getUnqual(llvm::StructType::create(loader()->vm()->llvmContext(), mangler.cStr())); _llvmType = llvm::PointerType::getUnqual(llvm::StructType::create(loader()->vm()->llvmContext(), mangler.cStr()+7)); - mangler.mangle("_2"); - - _nativeNameLength = mangler.length() - 6; - _nativeName = (char*)loader()->allocator()->allocate(_nativeNameLength + 1); - - _nativeName[0] = 'L'; - memcpy(_nativeName + 1, mangler.cStr()+7, _nativeNameLength); /* copy the 0 */ - - loader()->addSymbol(_nativeName, this); + doNativeName(); } llvm::Type* J3Class::staticLLVMType() { @@ -923,26 +932,28 @@ llvm::GlobalValue* J3ArrayClass::llvmDes return llvm::cast(module->getOrInsertGlobal(nativeName(), loader()->vm()->typeJ3ArrayClass)); } +void J3ArrayClass::doNativeName() { + uint32_t len = component()->nativeNameLength(); + _nativeNameLength = len + 2; + _nativeName = (char*)loader()->allocator()->allocate(_nativeNameLength + 1); + _nativeName[0] = '_'; + _nativeName[1] = '3'; + memcpy(_nativeName+2, component()->nativeName(), len); + _nativeName[_nativeNameLength] = 0; + loader()->addSymbol(_nativeName, this); +} + llvm::Type* J3ArrayClass::llvmType() { if(!_llvmType) { llvm::Type* body[2] = { loader()->vm()->typeJ3ArrayObject, llvm::ArrayType::get(component()->llvmType(), 0) /* has to be called first */ }; - uint32_t len = component()->nativeNameLength(); - - _nativeNameLength = len + 2; - _nativeName = (char*)loader()->allocator()->allocate(_nativeNameLength + 1); - _nativeName[0] = '_'; - _nativeName[1] = '3'; - memcpy(_nativeName+2, component()->nativeName(), len); - _nativeName[_nativeNameLength] = 0; - + + doNativeName(); _llvmType = llvm::PointerType::getUnqual(llvm::StructType::create(loader()->vm()->llvmContext(), body, _nativeName)); - - loader()->addSymbol(_nativeName, this); } return _llvmType; } Modified: vmkit/branches/mcjit/lib/j3/vm/j3options.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3options.cc?rev=198228&r1=198227&r2=198228&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3options.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3options.cc Mon Dec 30 11:49:22 2013 @@ -19,8 +19,8 @@ J3Options::J3Options() { debugLoad = 0; debugResolve = 0; debugIniting = 0; - debugTranslate = 1; - debugLinking = 1; + debugTranslate = 0; + debugLinking = 0; genDebugExecute = debugExecute ? 1 : 0; Modified: vmkit/branches/mcjit/lib/j3/vm/j3thread.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3thread.cc?rev=198228&r1=198227&r2=198228&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3thread.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3thread.cc Mon Dec 30 11:49:22 2013 @@ -21,7 +21,6 @@ J3Thread::~J3Thread() { void J3Thread::doRun() { J3ObjectHandle* handle = get()->javaThread(); - fprintf(stderr, " *** target is %ls\n", handle->vt()->type()->name()->cStr()); get()->vm()->threadRun->invokeVirtual(handle); } @@ -31,7 +30,6 @@ void J3Thread::run() { } void J3Thread::start(J3ObjectHandle* handle) { - fprintf(stderr, " start %ls\n", handle->vt()->type()->name()->cStr()); vmkit::BumpAllocator* allocator = vmkit::BumpAllocator::create(); J3Thread* thread = new J3Thread(get()->vm()); thread->assocJavaThread(handle); From gael.thomas at lip6.fr Mon Dec 30 09:51:34 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Mon, 30 Dec 2013 17:51:34 -0000 Subject: [vmkit-commits] [vmkit] r198229 - native name now uses doNativeName Message-ID: <20131230175134.C13062A6C029@llvm.org> Author: gthomas Date: Mon Dec 30 11:51:34 2013 New Revision: 198229 URL: http://llvm.org/viewvc/llvm-project?rev=198229&view=rev Log: native name now uses doNativeName Modified: vmkit/branches/mcjit/include/j3/j3class.h vmkit/branches/mcjit/lib/j3/vm/j3class.cc Modified: vmkit/branches/mcjit/include/j3/j3class.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3class.h?rev=198229&r1=198228&r2=198229&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3class.h (original) +++ vmkit/branches/mcjit/include/j3/j3class.h Mon Dec 30 11:51:34 2013 @@ -50,6 +50,7 @@ namespace j3 { virtual void doResolve(J3Field* hiddenFields, size_t nbHiddenFields) { status = RESOLVED; } virtual void doInitialise() { status = INITED; } + virtual void doNativeName(); public: J3Type(J3ClassLoader* loader, const vmkit::Name* name); Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=198229&r1=198228&r2=198229&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Mon Dec 30 11:51:34 2013 @@ -47,15 +47,19 @@ void J3Type::dump() { fprintf(stderr, "Type: %ls", name()->cStr()); } +void J3Type::doNativeName() { + J3::internalError(L"should not happen"); +} + char* J3Type::nativeName() { if(!_nativeName) - llvmType(); + doNativeName(); return _nativeName; } uint32_t J3Type::nativeNameLength() { if(!_nativeNameLength) - llvmType(); + doNativeName(); return _nativeNameLength; } From gael.thomas at lip6.fr Mon Dec 30 09:59:01 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Mon, 30 Dec 2013 17:59:01 -0000 Subject: [vmkit-commits] [vmkit] r198230 - Use logSize to sort the fields Message-ID: <20131230175901.7E87D2A6C029@llvm.org> Author: gthomas Date: Mon Dec 30 11:59:01 2013 New Revision: 198230 URL: http://llvm.org/viewvc/llvm-project?rev=198230&view=rev Log: Use logSize to sort the fields Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=198230&r1=198229&r2=198230&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Mon Dec 30 11:59:01 2013 @@ -544,8 +544,7 @@ void J3Class::readClassBytes(std::vector J3Field* pFields0[n]; size_t i0 = 0; /* sort fields by reverse size */ J3Field* pFields1[n]; size_t i1 = 0; J3Field* pFields2[n]; size_t i2 = 0; - J3Field* pFields4[n]; size_t i4 = 0; - J3Field* pFields8[n]; size_t i8 = 0; + J3Field* pFields3[n]; size_t i3 = 0; memset(fields, 0, sizeof(J3Field)*n); @@ -572,12 +571,11 @@ void J3Class::readClassBytes(std::vector nbVirtualFields++; } - switch(loader()->vm()->dataLayout()->getTypeSizeInBits(f->_type->llvmType())) { - case 1: pFields0[i0++] = f; break; - case 8: pFields1[i1++] = f; break; - case 16: pFields2[i2++] = f; break; - case 32: pFields4[i4++] = f; break; - case 64: pFields8[i8++] = f; break; + switch(f->_type->logSize()) { + case 0: pFields0[i0++] = f; break; + case 1: pFields1[i1++] = f; break; + case 2: pFields2[i2++] = f; break; + case 3: pFields3[i3++] = f; break; default: J3::internalError(L"should not happen"); } } @@ -590,8 +588,7 @@ void J3Class::readClassBytes(std::vector staticBody.push_back(loader()->vm()->typeJ3Object); virtualBody->push_back(0); - fillFields(&staticBody, virtualBody, pFields8, i8); - fillFields(&staticBody, virtualBody, pFields4, i4); + fillFields(&staticBody, virtualBody, pFields3, i3); fillFields(&staticBody, virtualBody, pFields2, i2); fillFields(&staticBody, virtualBody, pFields1, i1); fillFields(&staticBody, virtualBody, pFields0, i0); From gael.thomas at lip6.fr Mon Dec 30 10:09:53 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Mon, 30 Dec 2013 18:09:53 -0000 Subject: [vmkit-commits] [vmkit] r198231 - Compute my own field offsets Message-ID: <20131230180953.53D002A6C029@llvm.org> Author: gthomas Date: Mon Dec 30 12:09:53 2013 New Revision: 198231 URL: http://llvm.org/viewvc/llvm-project?rev=198231&view=rev Log: Compute my own field offsets Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=198231&r1=198230&r2=198231&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Mon Dec 30 12:09:53 2013 @@ -443,13 +443,14 @@ void J3Class::doResolve(J3Field* hiddenF if(super() == this) { virtualBody[0] = loader()->vm()->typeJ3Object; } else { - super()->resolve(); virtualBody[0] = super()->llvmType()->getContainedType(0); } llvm::cast(llvmType()->getContainedType(0))->setBody(virtualBody); - _structSize = loader()->vm()->dataLayout()->getTypeAllocSize(llvmType()->getContainedType(0)); + uint64_t kkk = loader()->vm()->dataLayout()->getTypeAllocSize(llvmType()->getContainedType(0)); + if(kkk != structSize()) + J3::internalError(L"should not happen"); staticLayout._vt = J3VirtualTable::create(&staticLayout); @@ -588,11 +589,21 @@ void J3Class::readClassBytes(std::vector staticBody.push_back(loader()->vm()->typeJ3Object); virtualBody->push_back(0); + if(super() == this) + _structSize = sizeof(J3Object); + else { + super()->resolve(); + _structSize = super()->structSize(); + } + fillFields(&staticBody, virtualBody, pFields3, i3); fillFields(&staticBody, virtualBody, pFields2, i2); fillFields(&staticBody, virtualBody, pFields1, i1); fillFields(&staticBody, virtualBody, pFields0, i0); + _structSize = ((_structSize - 1) & -sizeof(uintptr_t)) + sizeof(uintptr_t); + staticLayout._structSize = ((staticLayout._structSize - 1) & -sizeof(uintptr_t)) + sizeof(uintptr_t); + staticLLVMType()->getContainedType(0); llvm::cast(staticLLVMType()->getContainedType(0))->setBody(staticBody); @@ -654,7 +665,8 @@ void J3Class::fillFields(std::vectorpush_back(cur->type()->llvmType()); } layout->fields[layout->nbFields++] = *fields[i]; - + cur->_offset = layout->structSize(); + layout->_structSize += 1 << fields[i]->type()->logSize(); } } From gael.thomas at lip6.fr Mon Dec 30 10:12:15 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Mon, 30 Dec 2013 18:12:15 -0000 Subject: [vmkit-commits] [vmkit] r198232 - round the parent size to uintptr_t Message-ID: <20131230181215.6477B2A6C029@llvm.org> Author: gthomas Date: Mon Dec 30 12:12:15 2013 New Revision: 198232 URL: http://llvm.org/viewvc/llvm-project?rev=198232&view=rev Log: round the parent size to uintptr_t Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=198232&r1=198231&r2=198232&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Mon Dec 30 12:12:15 2013 @@ -448,10 +448,6 @@ void J3Class::doResolve(J3Field* hiddenF llvm::cast(llvmType()->getContainedType(0))->setBody(virtualBody); - uint64_t kkk = loader()->vm()->dataLayout()->getTypeAllocSize(llvmType()->getContainedType(0)); - if(kkk != structSize()) - J3::internalError(L"should not happen"); - staticLayout._vt = J3VirtualTable::create(&staticLayout); _vt = J3VirtualTable::create(this); @@ -596,14 +592,13 @@ void J3Class::readClassBytes(std::vector _structSize = super()->structSize(); } + _structSize = ((_structSize - 1) & -sizeof(uintptr_t)) + sizeof(uintptr_t); + fillFields(&staticBody, virtualBody, pFields3, i3); fillFields(&staticBody, virtualBody, pFields2, i2); fillFields(&staticBody, virtualBody, pFields1, i1); fillFields(&staticBody, virtualBody, pFields0, i0); - _structSize = ((_structSize - 1) & -sizeof(uintptr_t)) + sizeof(uintptr_t); - staticLayout._structSize = ((staticLayout._structSize - 1) & -sizeof(uintptr_t)) + sizeof(uintptr_t); - staticLLVMType()->getContainedType(0); llvm::cast(staticLLVMType()->getContainedType(0))->setBody(staticBody); From gael.thomas at lip6.fr Mon Dec 30 10:34:44 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Mon, 30 Dec 2013 18:34:44 -0000 Subject: [vmkit-commits] [vmkit] r198234 - don't use llvm structures to find the field offsets Message-ID: <20131230183445.05A2C2A6C029@llvm.org> Author: gthomas Date: Mon Dec 30 12:34:44 2013 New Revision: 198234 URL: http://llvm.org/viewvc/llvm-project?rev=198234&view=rev Log: don't use llvm structures to find the field offsets Modified: vmkit/branches/mcjit/include/j3/j3class.h vmkit/branches/mcjit/include/j3/j3codegen.h vmkit/branches/mcjit/lib/j3/vm/j3class.cc vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc vmkit/branches/mcjit/lib/j3/vm/j3object.cc Modified: vmkit/branches/mcjit/include/j3/j3class.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3class.h?rev=198234&r1=198233&r2=198234&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3class.h (original) +++ vmkit/branches/mcjit/include/j3/j3class.h Mon Dec 30 12:34:44 2013 @@ -138,8 +138,7 @@ namespace j3 { const vmkit::Name* _name; J3Type* _type; J3Attributes* _attributes; - uint32_t _num; - uint32_t _offset; + uintptr_t _offset; public: J3Field() {} @@ -151,7 +150,7 @@ namespace j3 { const vmkit::Name* name() { return _name; } J3Type* type() { return _type; } - uint32_t num() { return _num; } + uintptr_t offset() { return _offset; } void dump(); }; @@ -197,13 +196,13 @@ namespace j3 { size_t _nbMethods; J3Method** _methods; - size_t _structSize; + uintptr_t _structSize; public: J3Layout(J3ClassLoader* loader, const vmkit::Name* name); virtual bool isLayout() { return 1; } - size_t structSize(); + uintptr_t structSize(); size_t nbMethods() { return _nbMethods; } J3Method** methods() { return _methods; } Modified: vmkit/branches/mcjit/include/j3/j3codegen.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3codegen.h?rev=198234&r1=198233&r2=198234&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3codegen.h (original) +++ vmkit/branches/mcjit/include/j3/j3codegen.h Mon Dec 30 12:34:44 2013 @@ -112,6 +112,8 @@ namespace j3 { void compareFP(bool isL); void compareLong(); + llvm::Value* fieldOffset(llvm::Value* obj, J3Field* f); + void get(llvm::Value* obj, J3Field* field); void getField(uint32_t idx); void getStatic(uint32_t idx); Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=198234&r1=198233&r2=198234&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Mon Dec 30 12:34:44 2013 @@ -246,7 +246,7 @@ J3StaticLayout::J3StaticLayout(J3ClassLo J3Layout::J3Layout(J3ClassLoader* loader, const vmkit::Name* name) : J3ObjectType(loader, name) { } -size_t J3Layout::structSize() { +uintptr_t J3Layout::structSize() { return _structSize; } @@ -651,17 +651,15 @@ void J3Class::fillFields(std::vectoraccess())) { //fprintf(stderr, " adding static field: %ls %ls::%ls\n", cur->type()->name()->cStr(), name()->cStr(), cur->name()->cStr()); - cur->_num = staticBody->size(); layout = &staticLayout; staticBody->push_back(cur->type()->llvmType()); } else { - cur->_num = virtualBody->size(); layout = this; virtualBody->push_back(cur->type()->llvmType()); } - layout->fields[layout->nbFields++] = *fields[i]; cur->_offset = layout->structSize(); layout->_structSize += 1 << fields[i]->type()->logSize(); + layout->fields[layout->nbFields++] = *fields[i]; } } Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=198234&r1=198233&r2=198234&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Mon Dec 30 12:34:44 2013 @@ -401,9 +401,15 @@ void J3CodeGen::invokeSpecial(uint32_t i invoke(target, target->unsafe_llvmFunction(1, module(), cl)); } +llvm::Value* J3CodeGen::fieldOffset(llvm::Value* obj, J3Field* f) { + llvm::Type* uintPtrTy = builder->getIntPtrTy(vm->dataLayout()); + return builder->CreateIntToPtr(builder->CreateAdd(builder->CreatePtrToInt(obj, uintPtrTy), + llvm::ConstantInt::get(uintPtrTy, f->offset())), + f->type()->llvmType()->getPointerTo()); +} + void J3CodeGen::get(llvm::Value* src, J3Field* f) { - llvm::Value* gep[2] = { builder->getInt32(0), builder->getInt32(f->num()) }; - llvm::Value* res = flatten(builder->CreateLoad(builder->CreateGEP(src, gep)), f->type()); + llvm::Value* res = flatten(builder->CreateLoad(fieldOffset(src, f)), f->type()); stack.push(res); } @@ -419,8 +425,7 @@ void J3CodeGen::getStatic(uint32_t idx) } void J3CodeGen::put(llvm::Value* dest, llvm::Value* val, J3Field* f) { - llvm::Value* gep[2] = { builder->getInt32(0), builder->getInt32(f->num()) }; - builder->CreateStore(unflatten(val, f->type()), builder->CreateGEP(dest, gep)); + builder->CreateStore(unflatten(val, f->type()), fieldOffset(dest, f)); } void J3CodeGen::putStatic(uint32_t idx) { Modified: vmkit/branches/mcjit/lib/j3/vm/j3object.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3object.cc?rev=198234&r1=198233&r2=198234&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3object.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3object.cc Mon Dec 30 12:34:44 2013 @@ -416,19 +416,11 @@ J3ObjectHandle* J3ObjectHandle::doNewArr } \ \ void J3ObjectHandle::set##name(J3Field* field, ctype value) { \ - const llvm::StructLayout* layout = \ - obj()->vt()->type()->loader()->vm()->dataLayout()-> \ - getStructLayout((llvm::StructType*)(field->layout()->llvmType()->getContainedType(0))); \ - uint32_t offset = layout->getElementOffset(field->num()); \ - rawSet##name(offset, value); \ + rawSet##name(field->offset(), value); \ } \ \ ctype J3ObjectHandle::get##name(J3Field* field) { \ - const llvm::StructLayout* layout = \ - obj()->vt()->type()->loader()->vm()->dataLayout()-> \ - getStructLayout((llvm::StructType*)(field->layout()->llvmType()->getContainedType(0))); \ - uint32_t offset = layout->getElementOffset(field->num()); \ - return rawGet##name(offset); \ + return rawGet##name(field->offset()); \ } \ \ void J3ObjectHandle::set##name##At(uint32_t idx, ctype value) { \ @@ -475,18 +467,11 @@ J3ObjectHandle* J3ObjectHandle::rawGetOb } void J3ObjectHandle::setObject(J3Field* field, J3ObjectHandle* value) { - const llvm::StructLayout* layout = - obj()->vt()->type()->loader()->vm()->dataLayout()-> - getStructLayout((llvm::StructType*)(field->layout()->llvmType()->getContainedType(0))); - uint32_t offset = layout->getElementOffset(field->num()); - rawSetObject(offset, value); + rawSetObject(field->offset(), value); } J3ObjectHandle* J3ObjectHandle::getObject(J3Field* field) { - const llvm::StructLayout* layout = - obj()->vt()->type()->loader()->vm()->dataLayout()-> - getStructLayout((llvm::StructType*)(field->layout()->llvmType()->getContainedType(0))); - return rawGetObject(layout->getElementOffset(field->num())); + return rawGetObject(field->offset()); } void J3ObjectHandle::setObjectAt(uint32_t idx, J3ObjectHandle* value) { From gael.thomas at lip6.fr Mon Dec 30 10:56:46 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Mon, 30 Dec 2013 18:56:46 -0000 Subject: [vmkit-commits] [vmkit] r198236 - use nullValue when a native call return a null handle Message-ID: <20131230185646.1E5662A6C029@llvm.org> Author: gthomas Date: Mon Dec 30 12:56:45 2013 New Revision: 198236 URL: http://llvm.org/viewvc/llvm-project?rev=198236&view=rev Log: use nullValue when a native call return a null handle Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=198236&r1=198235&r2=198236&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Mon Dec 30 12:56:45 2013 @@ -86,6 +86,10 @@ J3CodeGen::J3CodeGen(vmkit::BumpAllocato } #endif + nullValue = builder + ->CreateIntToPtr(llvm::ConstantInt::get(builder->getIntPtrTy(vm->dataLayout()), (uintptr_t)0), + vm->typeJ3ObjectPtr); + if(J3Cst::isNative(method->access())) generateNative(); else @@ -1492,10 +1496,6 @@ void J3CodeGen::generateJava() { if(!reader.adjustSize(length)) J3::classFormatError(cl, L"Code attribute of %ls %ls is too large (%d)", method->name()->cStr(), method->sign()->cStr(), length); - nullValue = builder - ->CreateIntToPtr(llvm::ConstantInt::get(builder->getIntPtrTy(vm->dataLayout()), (uintptr_t)0), - vm->typeJ3ObjectPtr); - llvm::DIBuilder* dbgBuilder = new llvm::DIBuilder(*module()); dbgInfo = @@ -1620,7 +1620,7 @@ void J3CodeGen::generateNative() { builder->CreateCondBr(builder->CreateIsNull(res), ifnull, ifnotnull); builder->SetInsertPoint(bb = ifnull); - builder->CreateRet(unflatten(res, methodType->out())); + builder->CreateRet(unflatten(nullValue, methodType->out())); builder->SetInsertPoint(bb = ifnotnull); res = unflatten(handleToObject(res), methodType->out()); From gael.thomas at lip6.fr Mon Dec 30 11:02:53 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Mon, 30 Dec 2013 19:02:53 -0000 Subject: [vmkit-commits] [vmkit] r198237 - Don't fill the body of the Java llvm types anymore. Message-ID: <20131230190253.B88DD2A6C029@llvm.org> Author: gthomas Date: Mon Dec 30 13:02:53 2013 New Revision: 198237 URL: http://llvm.org/viewvc/llvm-project?rev=198237&view=rev Log: Don't fill the body of the Java llvm types anymore. Modified: vmkit/branches/mcjit/include/j3/j3class.h vmkit/branches/mcjit/lib/j3/vm/j3class.cc Modified: vmkit/branches/mcjit/include/j3/j3class.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3class.h?rev=198237&r1=198236&r2=198237&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3class.h (original) +++ vmkit/branches/mcjit/include/j3/j3class.h Mon Dec 30 13:02:53 2013 @@ -243,11 +243,11 @@ namespace j3 { J3ObjectHandle* _staticInstance; J3Attributes* readAttributes(J3Reader* reader); - void readClassBytes(std::vector* virtualBody, J3Field* hiddenFields, uint32_t nbHiddenFields); + void readClassBytes(J3Field* hiddenFields, uint32_t nbHiddenFields); void check(uint16_t idx, uint32_t id=-1); - void fillFields(std::vector* staticBody, std::vector* virtualBody, J3Field** fields, size_t n); + void fillFields(J3Field** fields, size_t n); void createLLVMTypes(); void doNativeName(); Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=198237&r1=198236&r2=198237&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Mon Dec 30 13:02:53 2013 @@ -390,9 +390,8 @@ void J3Class::doInitialise() { interfaces()[i]->initialise(); J3ObjectHandle* prev = J3Thread::get()->tell(); - J3ObjectHandle* stacked = J3ObjectHandle::allocate(staticLayout.vt(), - loader()->vm()->dataLayout()->getTypeAllocSize(staticLayout.llvmType() - ->getContainedType(0))); + J3ObjectHandle* stacked = J3ObjectHandle::allocate(staticLayout.vt(), staticLayout.structSize()); + _staticInstance = loader()->globalReferences()->add(stacked); J3Thread::get()->restore(prev); @@ -436,18 +435,9 @@ void J3Class::doResolve(J3Field* hiddenF if(loader()->vm()->options()->debugResolve) fprintf(stderr, "Resolving: %ls\n", name()->cStr()); - std::vector virtualBody; status = RESOLVED; - readClassBytes(&virtualBody, hiddenFields, nbHiddenFields); + readClassBytes(hiddenFields, nbHiddenFields); - if(super() == this) { - virtualBody[0] = loader()->vm()->typeJ3Object; - } else { - virtualBody[0] = super()->llvmType()->getContainedType(0); - } - - llvm::cast(llvmType()->getContainedType(0))->setBody(virtualBody); - staticLayout._vt = J3VirtualTable::create(&staticLayout); _vt = J3VirtualTable::create(this); @@ -462,7 +452,7 @@ void J3Class::doResolve(J3Field* hiddenF unlock(); } -void J3Class::readClassBytes(std::vector* virtualBody, J3Field* hiddenFields, uint32_t nbHiddenFields) { +void J3Class::readClassBytes(J3Field* hiddenFields, uint32_t nbHiddenFields) { J3Reader reader(_bytes); uint32_t magic = reader.readU4(); @@ -580,11 +570,6 @@ void J3Class::readClassBytes(std::vector staticLayout.fields = new(loader()->allocator()) J3Field[nbStaticFields]; fields = new(loader()->allocator()) J3Field[nbVirtualFields]; - std::vector staticBody; - - staticBody.push_back(loader()->vm()->typeJ3Object); - virtualBody->push_back(0); - if(super() == this) _structSize = sizeof(J3Object); else { @@ -594,15 +579,13 @@ void J3Class::readClassBytes(std::vector _structSize = ((_structSize - 1) & -sizeof(uintptr_t)) + sizeof(uintptr_t); - fillFields(&staticBody, virtualBody, pFields3, i3); - fillFields(&staticBody, virtualBody, pFields2, i2); - fillFields(&staticBody, virtualBody, pFields1, i1); - fillFields(&staticBody, virtualBody, pFields0, i0); + fillFields(pFields3, i3); + fillFields(pFields2, i2); + fillFields(pFields1, i1); + fillFields(pFields0, i0); staticLLVMType()->getContainedType(0); - llvm::cast(staticLLVMType()->getContainedType(0))->setBody(staticBody); - //fprintf(stderr, "static part of %ls: ", name()->cStr()); //staticLayout.llvmType()->getContainedType(0)->dump(); //fprintf(stderr, "\n"); @@ -644,7 +627,7 @@ void J3Class::readClassBytes(std::vector _attributes = readAttributes(&reader); } -void J3Class::fillFields(std::vector* staticBody, std::vector* virtualBody, J3Field** fields, size_t n) { +void J3Class::fillFields(J3Field** fields, size_t n) { for(size_t i=0; iaccess())) { //fprintf(stderr, " adding static field: %ls %ls::%ls\n", cur->type()->name()->cStr(), name()->cStr(), cur->name()->cStr()); layout = &staticLayout; - staticBody->push_back(cur->type()->llvmType()); } else { layout = this; - virtualBody->push_back(cur->type()->llvmType()); } cur->_offset = layout->structSize(); layout->_structSize += 1 << fields[i]->type()->logSize(); From gael.thomas at lip6.fr Mon Dec 30 11:37:07 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Mon, 30 Dec 2013 19:37:07 -0000 Subject: [vmkit-commits] [vmkit] r198239 - remove staticLLVMType Message-ID: <20131230193707.856102A6C029@llvm.org> Author: gthomas Date: Mon Dec 30 13:37:07 2013 New Revision: 198239 URL: http://llvm.org/viewvc/llvm-project?rev=198239&view=rev Log: remove staticLLVMType Modified: vmkit/branches/mcjit/include/j3/j3class.h vmkit/branches/mcjit/lib/j3/vm/j3class.cc vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Modified: vmkit/branches/mcjit/include/j3/j3class.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3class.h?rev=198239&r1=198238&r2=198239&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3class.h (original) +++ vmkit/branches/mcjit/include/j3/j3class.h Mon Dec 30 13:37:07 2013 @@ -220,6 +220,8 @@ namespace j3 { J3Class* cl() { return _cl; } virtual bool isStaticLayout() { return 1; } + + llvm::Type* llvmType(); }; class J3Class : public J3Layout { @@ -283,7 +285,6 @@ namespace j3 { J3Field* fieldAt(uint16_t idx, uint16_t access); llvm::Type* llvmType(); - llvm::Type* staticLLVMType(); llvm::Type* virtualLLVMType(); llvm::GlobalValue* llvmDescriptor(llvm::Module* module); Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=198239&r1=198238&r2=198239&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Mon Dec 30 13:37:07 2013 @@ -243,6 +243,10 @@ J3StaticLayout::J3StaticLayout(J3ClassLo _cl = cl; } +llvm::Type* J3StaticLayout::llvmType() { + return loader()->vm()->typeJ3ObjectPtr; +} + J3Layout::J3Layout(J3ClassLoader* loader, const vmkit::Name* name) : J3ObjectType(loader, name) { } @@ -584,8 +588,6 @@ void J3Class::readClassBytes(J3Field* hi fillFields(pFields1, i1); fillFields(pFields0, i0); - staticLLVMType()->getContainedType(0); - //fprintf(stderr, "static part of %ls: ", name()->cStr()); //staticLayout.llvmType()->getContainedType(0)->dump(); //fprintf(stderr, "\n"); @@ -825,17 +827,6 @@ void J3Class::createLLVMTypes() { doNativeName(); } -llvm::Type* J3Class::staticLLVMType() { - llvm::Type* res = staticLayout._llvmType; - - if(!res) { - createLLVMTypes(); - res = staticLayout._llvmType; - } - - return res; -} - llvm::Type* J3Class::virtualLLVMType() { llvm::Type* res = _llvmType; Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=198239&r1=198238&r2=198239&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Mon Dec 30 13:37:07 2013 @@ -290,9 +290,8 @@ llvm::Value* J3CodeGen::handleToObject(l llvm::Value* J3CodeGen::staticInstance(J3Class* cl) { initialiseJ3Type(cl); - return builder->CreateBitCast(handleToObject(builder->CreateCall(funcJ3ClassStaticInstance, - cl->llvmDescriptor(module()))), - cl->staticLLVMType()); + return handleToObject(builder->CreateCall(funcJ3ClassStaticInstance, + cl->llvmDescriptor(module()))); } llvm::Value* J3CodeGen::vt(llvm::Value* obj) { From gael.thomas at lip6.fr Mon Dec 30 11:39:21 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Mon, 30 Dec 2013 19:39:21 -0000 Subject: [vmkit-commits] [vmkit] r198240 - don't use virtual llvm typeanymore Message-ID: <20131230193921.82FC42A6C029@llvm.org> Author: gthomas Date: Mon Dec 30 13:39:21 2013 New Revision: 198240 URL: http://llvm.org/viewvc/llvm-project?rev=198240&view=rev Log: don't use virtual llvm typeanymore Modified: vmkit/branches/mcjit/include/j3/j3class.h vmkit/branches/mcjit/lib/j3/vm/j3class.cc vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Modified: vmkit/branches/mcjit/include/j3/j3class.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3class.h?rev=198240&r1=198239&r2=198240&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3class.h (original) +++ vmkit/branches/mcjit/include/j3/j3class.h Mon Dec 30 13:39:21 2013 @@ -285,7 +285,6 @@ namespace j3 { J3Field* fieldAt(uint16_t idx, uint16_t access); llvm::Type* llvmType(); - llvm::Type* virtualLLVMType(); llvm::GlobalValue* llvmDescriptor(llvm::Module* module); J3ClassBytes* bytes() { return _bytes; } Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=198240&r1=198239&r2=198240&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Mon Dec 30 13:39:21 2013 @@ -820,14 +820,12 @@ void J3Class::createLLVMTypes() { mangler.mangle("static_")->mangle(name()); - staticLayout._llvmType = - llvm::PointerType::getUnqual(llvm::StructType::create(loader()->vm()->llvmContext(), mangler.cStr())); - _llvmType = llvm::PointerType::getUnqual(llvm::StructType::create(loader()->vm()->llvmContext(), mangler.cStr()+7)); + _llvmType = loader()->vm()->typeJ3ObjectPtr; doNativeName(); } -llvm::Type* J3Class::virtualLLVMType() { +llvm::Type* J3Class::llvmType() { llvm::Type* res = _llvmType; if(!res) { @@ -838,10 +836,6 @@ llvm::Type* J3Class::virtualLLVMType() { return res; } -llvm::Type* J3Class::llvmType() { - return virtualLLVMType(); -} - void J3Field::dump() { printf("Field: %ls %ls::%ls (%d)\n", type()->name()->cStr(), layout()->name()->cStr(), name()->cStr(), access()); } Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=198240&r1=198239&r2=198240&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Mon Dec 30 13:39:21 2013 @@ -150,7 +150,7 @@ llvm::Value* J3CodeGen::flatten(llvm::Va llvm::Value* J3CodeGen::unflatten(llvm::Value* v, J3Type* type) { if(type == vm->typeInteger || type == vm->typeLong || type == vm->typeFloat || type == vm->typeDouble) return v; - else if(type->llvmType()->isPointerTy() && v->getType() != type->llvmType()) + else if(type->llvmType()->isPointerTy()) return builder->CreateBitCast(v, type->llvmType()); else if(type == vm->typeBoolean || type == vm->typeByte || type == vm->typeShort) return builder->CreateSExtOrTrunc(v, type->llvmType()); From gael.thomas at lip6.fr Mon Dec 30 11:47:59 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Mon, 30 Dec 2013 19:47:59 -0000 Subject: [vmkit-commits] [vmkit] r198242 - remove the llvm types from J3Class Message-ID: <20131230194759.1DD9F2A6C029@llvm.org> Author: gthomas Date: Mon Dec 30 13:47:58 2013 New Revision: 198242 URL: http://llvm.org/viewvc/llvm-project?rev=198242&view=rev Log: remove the llvm types from J3Class Modified: vmkit/branches/mcjit/include/j3/j3class.h vmkit/branches/mcjit/lib/j3/vm/j3class.cc Modified: vmkit/branches/mcjit/include/j3/j3class.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3class.h?rev=198242&r1=198241&r2=198242&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3class.h (original) +++ vmkit/branches/mcjit/include/j3/j3class.h Mon Dec 30 13:47:58 2013 @@ -169,6 +169,7 @@ namespace j3 { J3ObjectType(J3ClassLoader* loader, const vmkit::Name* name); uint32_t logSize() { return sizeof(uintptr_t) == 8 ? 3 : 2; } + llvm::Type* llvmType(); J3InterfaceSlotDescriptor* slotDescriptorAt(uint32_t index) { return &_interfaceSlotDescriptors[index]; } void prepareInterfaceTable(); @@ -188,8 +189,6 @@ namespace j3 { class J3Layout : public J3ObjectType { friend class J3Class; - llvm::Type* _llvmType; - size_t nbFields; J3Field* fields; @@ -209,7 +208,6 @@ namespace j3 { J3Method* findMethod(const vmkit::Name* name, const vmkit::Name* sign); J3Field* findField(const vmkit::Name* name, const J3Type* type); - llvm::Type* llvmType() { return _llvmType; } }; class J3StaticLayout : public J3Layout { @@ -220,8 +218,6 @@ namespace j3 { J3Class* cl() { return _cl; } virtual bool isStaticLayout() { return 1; } - - llvm::Type* llvmType(); }; class J3Class : public J3Layout { @@ -251,7 +247,6 @@ namespace j3 { void fillFields(J3Field** fields, size_t n); - void createLLVMTypes(); void doNativeName(); void doResolve(J3Field* hiddenFields, size_t nbHiddenFields); @@ -284,7 +279,6 @@ namespace j3 { J3Method* methodAt(uint16_t idx, uint16_t access); J3Field* fieldAt(uint16_t idx, uint16_t access); - llvm::Type* llvmType(); llvm::GlobalValue* llvmDescriptor(llvm::Module* module); J3ClassBytes* bytes() { return _bytes; } Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=198242&r1=198241&r2=198242&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Mon Dec 30 13:47:58 2013 @@ -147,6 +147,10 @@ J3ObjectType* J3Type::asObjectType() { J3ObjectType::J3ObjectType(J3ClassLoader* loader, const vmkit::Name* name) : J3Type(loader, name) { } +llvm::Type* J3ObjectType::llvmType() { + return loader()->vm()->typeJ3ObjectPtr; +} + J3Method* J3ObjectType::findVirtualMethod(const vmkit::Name* name, const vmkit::Name* sign, bool error) { J3::internalError(L"should not happe: %ls::%ls\n", J3ObjectType::name()->cStr(), name->cStr()); } @@ -243,10 +247,6 @@ J3StaticLayout::J3StaticLayout(J3ClassLo _cl = cl; } -llvm::Type* J3StaticLayout::llvmType() { - return loader()->vm()->typeJ3ObjectPtr; -} - J3Layout::J3Layout(J3ClassLoader* loader, const vmkit::Name* name) : J3ObjectType(loader, name) { } @@ -448,10 +448,6 @@ void J3Class::doResolve(J3Field* hiddenF if(!J3Cst::isInterface(access()) && !J3Cst::isAbstract(access())) prepareInterfaceTable(); - - //fprintf(stderr, "virtual part of %ls: ", name()->cStr()); - //llvmType()->getContainedType(0)->dump(); - //fprintf(stderr, "\n"); } unlock(); } @@ -587,10 +583,6 @@ void J3Class::readClassBytes(J3Field* hi fillFields(pFields2, i2); fillFields(pFields1, i1); fillFields(pFields0, i0); - - //fprintf(stderr, "static part of %ls: ", name()->cStr()); - //staticLayout.llvmType()->getContainedType(0)->dump(); - //fprintf(stderr, "\n"); size_t nbVirtualMethods = 0, nbStaticMethods = 0; @@ -815,27 +807,6 @@ void J3Class::doNativeName() { loader()->addSymbol(_nativeName, this); } -void J3Class::createLLVMTypes() { - J3Mangler mangler(this); - - mangler.mangle("static_")->mangle(name()); - - _llvmType = loader()->vm()->typeJ3ObjectPtr; - - doNativeName(); -} - -llvm::Type* J3Class::llvmType() { - llvm::Type* res = _llvmType; - - if(!res) { - createLLVMTypes(); - res = _llvmType; - } - - return res; -} - void J3Field::dump() { printf("Field: %ls %ls::%ls (%d)\n", type()->name()->cStr(), layout()->name()->cStr(), name()->cStr(), access()); } @@ -927,6 +898,7 @@ llvm::Type* J3ArrayClass::llvmType() { body, _nativeName)); } + //return loader()->vm()->typeJ3ObjectPtr; return _llvmType; } From gael.thomas at lip6.fr Mon Dec 30 12:39:07 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Mon, 30 Dec 2013 20:39:07 -0000 Subject: [vmkit-commits] [vmkit] r198244 - remove most of the uses of the data layout Message-ID: <20131230203907.97C462A6C029@llvm.org> Author: gthomas Date: Mon Dec 30 14:39:07 2013 New Revision: 198244 URL: http://llvm.org/viewvc/llvm-project?rev=198244&view=rev Log: remove most of the uses of the data layout Modified: vmkit/branches/mcjit/include/j3/j3codegen.h vmkit/branches/mcjit/include/j3/j3method.h vmkit/branches/mcjit/include/j3/j3object.h vmkit/branches/mcjit/include/vmkit/gc.h vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc vmkit/branches/mcjit/lib/j3/vm/j3method.cc vmkit/branches/mcjit/lib/j3/vm/j3object.cc vmkit/branches/mcjit/lib/vmkit/gc.cc Modified: vmkit/branches/mcjit/include/j3/j3codegen.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3codegen.h?rev=198244&r1=198243&r2=198244&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3codegen.h (original) +++ vmkit/branches/mcjit/include/j3/j3codegen.h Mon Dec 30 14:39:07 2013 @@ -63,6 +63,7 @@ namespace j3 { uint32_t* pendingBranchs; uint32_t topPendingBranchs; + llvm::Type* uintPtrTy; llvm::Value* nullValue; llvm::MDNode* dbgInfo; Modified: vmkit/branches/mcjit/include/j3/j3method.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3method.h?rev=198244&r1=198243&r2=198244&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3method.h (original) +++ vmkit/branches/mcjit/include/j3/j3method.h Mon Dec 30 14:39:07 2013 @@ -36,7 +36,7 @@ namespace j3 { public: J3MethodType(J3Type** args, size_t nbArgs); - llvm::FunctionType* unsafe_llvmFunctionType(); /* only call while compiler locked */ + llvm::FunctionType* unsafe_llvmFunctionType(); /* call only while compiler locked */ uint32_t nbIns() { return _nbIns; } J3Type* out() { return _out; } J3Type* ins(uint32_t idx) { return _ins[idx]; } @@ -94,9 +94,9 @@ namespace j3 { J3Method* resolve(J3ObjectHandle* obj); - llvm::Function* nativeLLVMFunction(llvm::Module* module); + llvm::Function* unsafe_nativeLLVMFunction(llvm::Module* module); /* call only while compiler locked */ llvm::GlobalValue* llvmDescriptor(llvm::Module* module); - llvm::Function* unsafe_llvmFunction(bool isStub, llvm::Module* module, J3Class* from=0); /* only call while compiler locked */ + llvm::Function* unsafe_llvmFunction(bool isStub, llvm::Module* module, J3Class* from=0); /* call only while compiler locked */ uint32_t index(); uint32_t* indexPtr() { return &_index; } Modified: vmkit/branches/mcjit/include/j3/j3object.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3object.h?rev=198244&r1=198243&r2=198244&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3object.h (original) +++ vmkit/branches/mcjit/include/j3/j3object.h Mon Dec 30 14:39:07 2013 @@ -108,7 +108,7 @@ namespace j3 { static void monitorEnter(J3Object* obj); static void monitorExit(J3Object* obj); - static J3Object* allocate(J3VirtualTable* vt, size_t n); + static J3Object* allocate(J3VirtualTable* vt, uintptr_t n); static J3Object* doNewNoInit(J3Class* cl); static J3Object* doNew(J3Class* cl); public: @@ -125,7 +125,7 @@ namespace j3 { private: uint32_t _length; - static J3Object* doNew(J3ArrayClass* cl, uint32_t length); + static J3Object* doNew(J3ArrayClass* cl, uintptr_t length); public: Modified: vmkit/branches/mcjit/include/vmkit/gc.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/gc.h?rev=198244&r1=198243&r2=198244&view=diff ============================================================================== --- vmkit/branches/mcjit/include/vmkit/gc.h (original) +++ vmkit/branches/mcjit/include/vmkit/gc.h Mon Dec 30 14:39:07 2013 @@ -6,7 +6,7 @@ namespace vmkit { class GC { public: - static void* allocate(size_t sz); + static void* allocate(uintptr_t sz); }; }; Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=198244&r1=198243&r2=198244&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Mon Dec 30 14:39:07 2013 @@ -59,6 +59,8 @@ J3CodeGen::J3CodeGen(vmkit::BumpAllocato builder = &_builder; + uintPtrTy = builder->getIntPtrTy(vm->dataLayout()); + #define _x(name, id) \ name = vm->introspectFunction(module(), id); #include "j3/j3meta.def" @@ -87,7 +89,7 @@ J3CodeGen::J3CodeGen(vmkit::BumpAllocato #endif nullValue = builder - ->CreateIntToPtr(llvm::ConstantInt::get(builder->getIntPtrTy(vm->dataLayout()), (uintptr_t)0), + ->CreateIntToPtr(llvm::ConstantInt::get(uintPtrTy, (uintptr_t)0), vm->typeJ3ObjectPtr); if(J3Cst::isNative(method->access())) @@ -163,10 +165,8 @@ llvm::Value* J3CodeGen::unflatten(llvm:: } llvm::Value* J3CodeGen::spToCurrentThread(llvm::Value* sp) { - llvm::Type* type = builder->getIntPtrTy(vm->dataLayout()); - - return builder->CreateIntToPtr(builder->CreateAnd(builder->CreatePtrToInt(sp, type), - llvm::ConstantInt::get(type, vmkit::Thread::getThreadMask())), + return builder->CreateIntToPtr(builder->CreateAnd(builder->CreatePtrToInt(sp, uintPtrTy), + llvm::ConstantInt::get(uintPtrTy, vmkit::Thread::getThreadMask())), vm->typeJ3Thread); } @@ -175,7 +175,6 @@ llvm::Value* J3CodeGen::currentThread() } void J3CodeGen::monitorEnter(llvm::Value* obj) { - llvm::Type* uintPtrTy = builder->getIntPtrTy(vm->dataLayout()); llvm::Type* recordTy = vm->typeJ3LockRecord; llvm::Type* recordPtrTy = vm->typeJ3LockRecord->getPointerTo(); @@ -225,7 +224,6 @@ void J3CodeGen::monitorEnter(llvm::Value } void J3CodeGen::monitorExit(llvm::Value* obj) { - llvm::Type* uintPtrTy = builder->getIntPtrTy(vm->dataLayout()); llvm::Type* recordPtrTy = vm->typeJ3LockRecord->getPointerTo(); llvm::BasicBlock* ok = forwardBranch("unlock-ok", codeReader->tell(), 0, 0); @@ -405,7 +403,6 @@ void J3CodeGen::invokeSpecial(uint32_t i } llvm::Value* J3CodeGen::fieldOffset(llvm::Value* obj, J3Field* f) { - llvm::Type* uintPtrTy = builder->getIntPtrTy(vm->dataLayout()); return builder->CreateIntToPtr(builder->CreateAdd(builder->CreatePtrToInt(obj, uintPtrTy), llvm::ConstantInt::get(uintPtrTy, f->offset())), f->type()->llvmType()->getPointerTo()); @@ -480,12 +477,11 @@ llvm::Value* J3CodeGen::arrayLength(llvm void J3CodeGen::newArray(J3ArrayClass* array) { initialiseJ3Type(array); - llvm::DataLayout* layout = vm->dataLayout(); llvm::Value* length = stack.pop(); llvm::Value* nbb = - builder->CreateAdd(builder->getInt64(layout->getTypeAllocSize(array->llvmType()->getContainedType(0))), - builder->CreateMul(builder->getInt64(layout->getTypeAllocSize(array->component()->llvmType())), - builder->CreateZExtOrBitCast(length, builder->getInt64Ty()))); + builder->CreateAdd(llvm::ConstantInt::get(uintPtrTy, sizeof(J3ArrayObject)), + builder->CreateMul(llvm::ConstantInt::get(uintPtrTy, 1 << array->component()->logSize()), + builder->CreateZExtOrBitCast(length, uintPtrTy))); llvm::Value* res = builder->CreateCall2(funcJ3ObjectAllocate, vt(array), nbb); @@ -1574,7 +1570,7 @@ void J3CodeGen::generateJava() { void J3CodeGen::generateNative() { std::vector args; - llvm::Function* nat = method->nativeLLVMFunction(module()); + llvm::Function* nat = method->unsafe_nativeLLVMFunction(module()); llvm::Value* res; llvm::Value* thread = currentThread(); Modified: vmkit/branches/mcjit/lib/j3/vm/j3method.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3method.cc?rev=198244&r1=198243&r2=198244&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3method.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3method.cc Mon Dec 30 14:39:07 2013 @@ -363,7 +363,7 @@ llvm::Type* J3Method::doNativeType(J3Typ return t; } -llvm::Function* J3Method::nativeLLVMFunction(llvm::Module* module) { +llvm::Function* J3Method::unsafe_nativeLLVMFunction(llvm::Module* module) { J3ClassLoader* loader = cl()->loader(); J3Mangler mangler(cl()); Modified: vmkit/branches/mcjit/lib/j3/vm/j3object.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3object.cc?rev=198244&r1=198243&r2=198244&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3object.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3object.cc Mon Dec 30 14:39:07 2013 @@ -272,7 +272,7 @@ volatile uintptr_t* J3Object::header() { return &_header; } -J3Object* J3Object::allocate(J3VirtualTable* vt, size_t n) { +J3Object* J3Object::allocate(J3VirtualTable* vt, uintptr_t n) { J3Object* res = (J3Object*)vmkit::GC::allocate(n); res->_vt = vt; res->_header = 1; @@ -366,12 +366,8 @@ J3Monitor* J3Object::monitor() { /* * --- J3ArrayObject --- */ -J3Object* J3ArrayObject::doNew(J3ArrayClass* cl, uint32_t length) { - llvm::DataLayout* layout = cl->loader()->vm()->dataLayout(); - J3ArrayObject* res = - (J3ArrayObject*)allocate(cl->vtAndResolve(), - layout->getTypeAllocSize(cl->llvmType()->getContainedType(0)) - + layout->getTypeAllocSize(cl->component()->llvmType()) * length); +J3Object* J3ArrayObject::doNew(J3ArrayClass* cl, uintptr_t length) { + J3ArrayObject* res = (J3ArrayObject*)allocate(cl->vtAndResolve(), sizeof(J3ArrayObject) + (1 << cl->component()->logSize()) * length); res->_length = length; Modified: vmkit/branches/mcjit/lib/vmkit/gc.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/gc.cc?rev=198244&r1=198243&r2=198244&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/vmkit/gc.cc (original) +++ vmkit/branches/mcjit/lib/vmkit/gc.cc Mon Dec 30 14:39:07 2013 @@ -3,6 +3,6 @@ using namespace vmkit; -void* GC::allocate(size_t sz) { +void* GC::allocate(uintptr_t sz) { return calloc(sz, 1); } From gael.thomas at lip6.fr Mon Dec 30 12:40:54 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Mon, 30 Dec 2013 20:40:54 -0000 Subject: [vmkit-commits] [vmkit] r198245 - an array has now also the J3Object* type Message-ID: <20131230204054.AFC6C2A6C029@llvm.org> Author: gthomas Date: Mon Dec 30 14:40:54 2013 New Revision: 198245 URL: http://llvm.org/viewvc/llvm-project?rev=198245&view=rev Log: an array has now also the J3Object* type Modified: vmkit/branches/mcjit/include/j3/j3class.h vmkit/branches/mcjit/lib/j3/vm/j3class.cc Modified: vmkit/branches/mcjit/include/j3/j3class.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3class.h?rev=198245&r1=198244&r2=198245&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3class.h (original) +++ vmkit/branches/mcjit/include/j3/j3class.h Mon Dec 30 14:40:54 2013 @@ -292,7 +292,6 @@ namespace j3 { }; class J3ArrayClass : public J3ObjectType { - llvm::Type* _llvmType; J3Type* _component; void doResolve(J3Field* hiddenFields, size_t nbHiddenFields); @@ -307,7 +306,6 @@ namespace j3 { J3Type* component() { return _component; } bool isArrayClass() { return 1; } - llvm::Type* llvmType(); }; class J3Primitive : public J3Type { Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=198245&r1=198244&r2=198245&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Mon Dec 30 14:40:54 2013 @@ -886,22 +886,6 @@ void J3ArrayClass::doNativeName() { loader()->addSymbol(_nativeName, this); } -llvm::Type* J3ArrayClass::llvmType() { - if(!_llvmType) { - llvm::Type* body[2] = { - loader()->vm()->typeJ3ArrayObject, - llvm::ArrayType::get(component()->llvmType(), 0) /* has to be called first */ - }; - - doNativeName(); - _llvmType = llvm::PointerType::getUnqual(llvm::StructType::create(loader()->vm()->llvmContext(), - body, - _nativeName)); - } - //return loader()->vm()->typeJ3ObjectPtr; - return _llvmType; -} - /* * ------------ J3Primitive ------------ */ From gael.thomas at lip6.fr Mon Dec 30 12:45:31 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Mon, 30 Dec 2013 20:45:31 -0000 Subject: [vmkit-commits] [vmkit] r198247 - Unify access for locals and stack Message-ID: <20131230204531.A39FB2A6C029@llvm.org> Author: gthomas Date: Mon Dec 30 14:45:31 2013 New Revision: 198247 URL: http://llvm.org/viewvc/llvm-project?rev=198247&view=rev Log: Unify access for locals and stack Modified: vmkit/branches/mcjit/include/j3/j3codegenvar.h vmkit/branches/mcjit/lib/j3/vm/j3codegenvar.cc Modified: vmkit/branches/mcjit/include/j3/j3codegenvar.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3codegenvar.h?rev=198247&r1=198246&r2=198247&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3codegenvar.h (original) +++ vmkit/branches/mcjit/include/j3/j3codegenvar.h Mon Dec 30 14:45:31 2013 @@ -14,6 +14,8 @@ namespace j3 { class J3CodeGenVar { void killUnused(llvm::AllocaInst** stack, bool isObj); + + llvm::AllocaInst** stackOf(llvm::Type* t); public: J3CodeGen* codeGen; llvm::AllocaInst** intStack; Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegenvar.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegenvar.cc?rev=198247&r1=198246&r2=198247&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegenvar.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegenvar.cc Mon Dec 30 14:45:31 2013 @@ -97,58 +97,31 @@ void J3CodeGenVar::drop(uint32_t n) { topStack -= n; } -void J3CodeGenVar::setAt(llvm::Value* value, uint32_t idx) { - //if(idx >= nbLocals + maxStack) - //J3::classFormatError(cl, L"bad index %lu", idx); - llvm::Type* t = value->getType(); - llvm::AllocaInst** stack; - +llvm::AllocaInst** J3CodeGenVar::stackOf(llvm::Type* t) { if(t->isIntegerTy(64)) { - stack = longStack; + return longStack; } else if(t->isIntegerTy()) { - stack = intStack; + return intStack; } else if(t->isFloatTy()) { - stack = floatStack; + return floatStack; } else if(t->isDoubleTy()) { - stack = doubleStack; + return doubleStack; } else if(t->isPointerTy()) { - stack = refStack; - } else - J3::internalError(L"should not happen"); - - // fprintf(stderr, "setAt[%u]: ", idx); - // value->dump(); - // fprintf(stderr, "\n"); + return refStack; + } + + J3::internalError(L"should not happen"); +} +void J3CodeGenVar::setAt(llvm::Value* value, uint32_t idx) { + llvm::Type* t = value->getType(); metaStack[idx] = t; - - codeGen->builder->CreateStore(value, stack[idx]); + codeGen->builder->CreateStore(value, stackOf(t)[idx]); } llvm::Value* J3CodeGenVar::at(uint32_t idx) { - //if(idx >= nbLocals + maxStack) - //vm->classFormatError(cl, L"bad index %lu", idx); llvm::Type* t = metaStack[idx]; - llvm::Value* res; - - if(t->isIntegerTy(64)) { - res = codeGen->builder->CreateLoad(longStack[idx]); - } else if(t->isIntegerTy()) { - res = codeGen->builder->CreateLoad(intStack[idx]); - } else if(t->isFloatTy()) { - res = codeGen->builder->CreateLoad(floatStack[idx]); - } else if(t->isDoubleTy()) { - res = codeGen->builder->CreateLoad(doubleStack[idx]); - } else if(t->isPointerTy()) { - res = codeGen->builder->CreateLoad(refStack[idx]); - } else - J3::internalError(L"should not happen"); - - // fprintf(stderr, "top: "); - // res->dump(); - // fprintf(stderr, "\n"); - - return res; + return codeGen->builder->CreateLoad(stackOf(t)[idx]); } void J3CodeGenVar::push(llvm::Value* value) { From gael.thomas at lip6.fr Mon Dec 30 13:13:46 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Mon, 30 Dec 2013 21:13:46 -0000 Subject: [vmkit-commits] [vmkit] r198250 - Better typing for llvmDescriptor Message-ID: <20131230211346.B45DA2A6C029@llvm.org> Author: gthomas Date: Mon Dec 30 15:13:46 2013 New Revision: 198250 URL: http://llvm.org/viewvc/llvm-project?rev=198250&view=rev Log: Better typing for llvmDescriptor Modified: vmkit/branches/mcjit/include/j3/j3.h vmkit/branches/mcjit/include/j3/j3class.h vmkit/branches/mcjit/include/j3/j3codegen.h vmkit/branches/mcjit/include/j3/j3method.h vmkit/branches/mcjit/lib/j3/vm/j3.cc vmkit/branches/mcjit/lib/j3/vm/j3class.cc vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc vmkit/branches/mcjit/lib/j3/vm/j3method.cc Modified: vmkit/branches/mcjit/include/j3/j3.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3.h?rev=198250&r1=198249&r2=198250&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3.h (original) +++ vmkit/branches/mcjit/include/j3/j3.h Mon Dec 30 15:13:46 2013 @@ -84,6 +84,7 @@ namespace j3 { llvm::Type* typeJ3TypePtr; llvm::Type* typeJ3LayoutPtr; llvm::Type* typeJ3Thread; + llvm::Type* typeJ3ObjectType; llvm::Type* typeJ3ObjectTypePtr; llvm::Type* typeJ3Class; llvm::Type* typeJ3ClassPtr; Modified: vmkit/branches/mcjit/include/j3/j3class.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3class.h?rev=198250&r1=198249&r2=198250&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3class.h (original) +++ vmkit/branches/mcjit/include/j3/j3class.h Mon Dec 30 15:13:46 2013 @@ -59,8 +59,6 @@ namespace j3 { void* getSymbolAddress(); - virtual llvm::GlobalValue* llvmDescriptor(llvm::Module* module) { return 0; } - int isTypeDescriptor() { return 1; } bool isResolved() { return status >= RESOLVED; } @@ -170,6 +168,7 @@ namespace j3 { uint32_t logSize() { return sizeof(uintptr_t) == 8 ? 3 : 2; } llvm::Type* llvmType(); + llvm::GlobalValue* unsafe_llvmDescriptor(llvm::Module* module); J3InterfaceSlotDescriptor* slotDescriptorAt(uint32_t index) { return &_interfaceSlotDescriptors[index]; } void prepareInterfaceTable(); @@ -279,8 +278,6 @@ namespace j3 { J3Method* methodAt(uint16_t idx, uint16_t access); J3Field* fieldAt(uint16_t idx, uint16_t access); - llvm::GlobalValue* llvmDescriptor(llvm::Module* module); - J3ClassBytes* bytes() { return _bytes; } bool isClass() { return 1; } @@ -301,9 +298,6 @@ namespace j3 { public: J3ArrayClass(J3ClassLoader* loader, J3Type* component, const vmkit::Name* name); - - llvm::GlobalValue* llvmDescriptor(llvm::Module* module); - J3Type* component() { return _component; } bool isArrayClass() { return 1; } }; Modified: vmkit/branches/mcjit/include/j3/j3codegen.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3codegen.h?rev=198250&r1=198249&r2=198250&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3codegen.h (original) +++ vmkit/branches/mcjit/include/j3/j3codegen.h Mon Dec 30 15:13:46 2013 @@ -98,16 +98,16 @@ namespace j3 { llvm::Value* handleToObject(llvm::Value* obj); llvm::Value* javaClass(J3ObjectType* type); llvm::Value* staticInstance(J3Class* cl); - llvm::Value* vt(J3Type* cl, bool resolve=0); + llvm::Value* vt(J3ObjectType* cl, bool resolve=0); llvm::Value* vt(llvm::Value* obj); - void initialiseJ3Type(J3Type* cl); + void initialiseJ3ObjectType(J3ObjectType* cl); void monitorEnter(llvm::Value* obj); void monitorExit(llvm::Value* obj); - llvm::Value* isAssignableTo(llvm::Value* obj, J3Type* type); - void instanceof(llvm::Value* obj, J3Type* type); - void checkCast(llvm::Value* obj, J3Type* type); + llvm::Value* isAssignableTo(llvm::Value* obj, J3ObjectType* type); + void instanceof(llvm::Value* obj, J3ObjectType* type); + void checkCast(llvm::Value* obj, J3ObjectType* type); void floatToInteger(J3Type* from, J3Type* to); void compareFP(bool isL); Modified: vmkit/branches/mcjit/include/j3/j3method.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3method.h?rev=198250&r1=198249&r2=198250&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3method.h (original) +++ vmkit/branches/mcjit/include/j3/j3method.h Mon Dec 30 15:13:46 2013 @@ -95,7 +95,7 @@ namespace j3 { J3Method* resolve(J3ObjectHandle* obj); llvm::Function* unsafe_nativeLLVMFunction(llvm::Module* module); /* call only while compiler locked */ - llvm::GlobalValue* llvmDescriptor(llvm::Module* module); + llvm::GlobalValue* unsafe_llvmDescriptor(llvm::Module* module); llvm::Function* unsafe_llvmFunction(bool isStub, llvm::Module* module, J3Class* from=0); /* call only while compiler locked */ uint32_t index(); Modified: vmkit/branches/mcjit/lib/j3/vm/j3.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3.cc?rev=198250&r1=198249&r2=198250&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3.cc Mon Dec 30 15:13:46 2013 @@ -47,7 +47,8 @@ void J3::introspect() { typeJ3Type = introspectType("class.j3::J3Type"); typeJ3TypePtr = llvm::PointerType::getUnqual(typeJ3Type); typeJ3LayoutPtr = llvm::PointerType::getUnqual(introspectType("class.j3::J3Layout")); - typeJ3ObjectTypePtr = llvm::PointerType::getUnqual(introspectType("class.j3::J3ObjectType")); + typeJ3ObjectType = introspectType("class.j3::J3ObjectType"); + typeJ3ObjectTypePtr = llvm::PointerType::getUnqual(typeJ3ObjectType); typeJ3Thread = llvm::PointerType::getUnqual(introspectType("class.j3::J3Thread")); typeJ3Class = introspectType("class.j3::J3Class"); typeJ3ClassPtr = llvm::PointerType::getUnqual(typeJ3Class); Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=198250&r1=198249&r2=198250&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Mon Dec 30 15:13:46 2013 @@ -151,6 +151,10 @@ llvm::Type* J3ObjectType::llvmType() { return loader()->vm()->typeJ3ObjectPtr; } +llvm::GlobalValue* J3ObjectType::unsafe_llvmDescriptor(llvm::Module* module) { + return llvm::cast(module->getOrInsertGlobal(nativeName(), loader()->vm()->typeJ3ObjectType)); +} + J3Method* J3ObjectType::findVirtualMethod(const vmkit::Name* name, const vmkit::Name* sign, bool error) { J3::internalError(L"should not happe: %ls::%ls\n", J3ObjectType::name()->cStr(), name->cStr()); } @@ -290,11 +294,6 @@ J3Class::J3Class(J3ClassLoader* loader, status = LOADED; } -llvm::GlobalValue* J3Class::llvmDescriptor(llvm::Module* module) { - return llvm::cast(module->getOrInsertGlobal(nativeName(), loader()->vm()->typeJ3Class)); -} - - J3Method* J3Class::findVirtualMethod(const vmkit::Name* name, const vmkit::Name* sign, bool error) { //loader()->vm()->log(L"Lookup: %ls %ls in %ls (%d)", methName->cStr(), methSign->cStr(), name()->cStr(), nbVirtualMethods); resolve(); @@ -871,10 +870,6 @@ void J3ArrayClass::doInitialise() { status = INITED; } -llvm::GlobalValue* J3ArrayClass::llvmDescriptor(llvm::Module* module) { - return llvm::cast(module->getOrInsertGlobal(nativeName(), loader()->vm()->typeJ3ArrayClass)); -} - void J3ArrayClass::doNativeName() { uint32_t len = component()->nativeNameLength(); _nativeNameLength = len + 2; Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=198250&r1=198249&r2=198250&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Mon Dec 30 15:13:46 2013 @@ -271,14 +271,13 @@ void J3CodeGen::monitorExit(llvm::Value* builder->CreateBr(ok); } -void J3CodeGen::initialiseJ3Type(J3Type* cl) { +void J3CodeGen::initialiseJ3ObjectType(J3ObjectType* cl) { if(!cl->isInitialised()) - builder->CreateCall(funcJ3TypeInitialise, builder->CreateBitCast(cl->llvmDescriptor(module()), vm->typeJ3TypePtr)); + builder->CreateCall(funcJ3TypeInitialise, builder->CreateBitCast(cl->unsafe_llvmDescriptor(module()), vm->typeJ3TypePtr)); } llvm::Value* J3CodeGen::javaClass(J3ObjectType* type) { - return builder->CreateCall(funcJ3ObjectTypeJavaClass, - builder->CreateBitCast(type->llvmDescriptor(module()), vm->typeJ3ObjectTypePtr)); + return builder->CreateCall(funcJ3ObjectTypeJavaClass, type->unsafe_llvmDescriptor(module())); } llvm::Value* J3CodeGen::handleToObject(llvm::Value* obj) { @@ -287,9 +286,9 @@ llvm::Value* J3CodeGen::handleToObject(l } llvm::Value* J3CodeGen::staticInstance(J3Class* cl) { - initialiseJ3Type(cl); + initialiseJ3ObjectType(cl); return handleToObject(builder->CreateCall(funcJ3ClassStaticInstance, - cl->llvmDescriptor(module()))); + builder->CreateBitCast(cl->unsafe_llvmDescriptor(module()), vm->typeJ3ClassPtr))); } llvm::Value* J3CodeGen::vt(llvm::Value* obj) { @@ -300,9 +299,9 @@ llvm::Value* J3CodeGen::vt(llvm::Value* return res; } -llvm::Value* J3CodeGen::vt(J3Type* type, bool doResolve) { +llvm::Value* J3CodeGen::vt(J3ObjectType* type, bool doResolve) { llvm::Value* func = doResolve && !type->isResolved() ? funcJ3TypeVTAndResolve : funcJ3TypeVT; - return builder->CreateCall(func, builder->CreateBitCast(type->llvmDescriptor(module()), vm->typeJ3TypePtr)); + return builder->CreateCall(func, builder->CreateBitCast(type->unsafe_llvmDescriptor(module()), vm->typeJ3TypePtr)); } llvm::Value* J3CodeGen::nullCheck(llvm::Value* obj) { @@ -379,7 +378,7 @@ void J3CodeGen::invokeVirtual(uint32_t i if(target->isResolved()) funcEntry = builder->getInt32(target->index()); else - funcEntry = builder->CreateCall(funcJ3MethodIndex, target->llvmDescriptor(module())); + funcEntry = builder->CreateCall(funcJ3MethodIndex, target->unsafe_llvmDescriptor(module())); llvm::Value* obj = nullCheck(stack.top(type->nbIns() - 1)); llvm::Value* gepFunc[] = { builder->getInt32(0), @@ -393,7 +392,7 @@ void J3CodeGen::invokeVirtual(uint32_t i void J3CodeGen::invokeStatic(uint32_t idx) { J3Method* target = cl->methodAt(idx, J3Cst::ACC_STATIC); - initialiseJ3Type(target->cl()); + initialiseJ3ObjectType(target->cl()); invoke(target, target->unsafe_llvmFunction(1, module(), cl)); } @@ -476,7 +475,7 @@ llvm::Value* J3CodeGen::arrayLength(llvm } void J3CodeGen::newArray(J3ArrayClass* array) { - initialiseJ3Type(array); + initialiseJ3ObjectType(array); llvm::Value* length = stack.pop(); llvm::Value* nbb = builder->CreateAdd(llvm::ConstantInt::get(uintPtrTy, sizeof(J3ArrayObject)), @@ -510,12 +509,12 @@ void J3CodeGen::newArray(uint8_t atype) } void J3CodeGen::newObject(J3Class* cl) { - initialiseJ3Type(cl); + initialiseJ3ObjectType(cl); llvm::Value* size; if(!cl->isResolved()) { - size = builder->CreateCall(funcJ3LayoutStructSize, builder->CreateBitCast(cl->llvmDescriptor(module()), vm->typeJ3LayoutPtr)); + size = builder->CreateCall(funcJ3LayoutStructSize, builder->CreateBitCast(cl->unsafe_llvmDescriptor(module()), vm->typeJ3LayoutPtr)); } else { size = builder->getInt64(cl->structSize()); } @@ -525,7 +524,7 @@ void J3CodeGen::newObject(J3Class* cl) { stack.push(res); } -llvm::Value* J3CodeGen::isAssignableTo(llvm::Value* obj, J3Type* type) { +llvm::Value* J3CodeGen::isAssignableTo(llvm::Value* obj, J3ObjectType* type) { llvm::Value* vtType = vt(type, 1); llvm::Value* vtObj = vt(obj); @@ -542,7 +541,7 @@ llvm::Value* J3CodeGen::isAssignableTo(l } } -void J3CodeGen::instanceof(llvm::Value* obj, J3Type* type) { +void J3CodeGen::instanceof(llvm::Value* obj, J3ObjectType* type) { llvm::BasicBlock* after = forwardBranch("instanceof-after", codeReader->tell(), 0, 0); llvm::BasicBlock* ok = newBB("instanceof-ok"); llvm::BasicBlock* test = newBB("instanceof"); @@ -559,7 +558,7 @@ void J3CodeGen::instanceof(llvm::Value* builder->CreateBr(after); } -void J3CodeGen::checkCast(llvm::Value* obj, J3Type* type) { +void J3CodeGen::checkCast(llvm::Value* obj, J3ObjectType* type) { llvm::BasicBlock* succeed = forwardBranch("checkcast-succeed", codeReader->tell(), 0, 0); llvm::BasicBlock* test = newBB("checkcast"); @@ -641,7 +640,9 @@ void J3CodeGen::ldc(uint32_t idx) { case J3Cst::CONSTANT_Double: res = llvm::ConstantFP::get(builder->getDoubleTy(), cl->doubleAt(idx)); break; case J3Cst::CONSTANT_Class: res = handleToObject(javaClass(cl->classAt(idx))); break; case J3Cst::CONSTANT_String: - res = handleToObject(builder->CreateCall2(funcJ3ClassStringAt, cl->llvmDescriptor(module()), builder->getInt16(idx))); + res = handleToObject(builder->CreateCall2(funcJ3ClassStringAt, + builder->CreateBitCast(cl->unsafe_llvmDescriptor(module()), vm->typeJ3ClassPtr), + builder->getInt16(idx))); break; default: J3::classFormatError(cl, L"wrong ldc type: %d\n", cl->getCtpType(idx)); Modified: vmkit/branches/mcjit/lib/j3/vm/j3method.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3method.cc?rev=198250&r1=198249&r2=198250&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3method.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3method.cc Mon Dec 30 15:13:46 2013 @@ -335,7 +335,7 @@ char* J3Method::llvmStubName(J3Class* fr return _llvmAllNames + 0; } -llvm::GlobalValue* J3Method::llvmDescriptor(llvm::Module* module) { +llvm::GlobalValue* J3Method::unsafe_llvmDescriptor(llvm::Module* module) { return llvm::cast(module->getOrInsertGlobal(llvmDescriptorName(), cl()->loader()->vm()->typeJ3Method)); } From gael.thomas at lip6.fr Mon Dec 30 14:10:22 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Mon, 30 Dec 2013 22:10:22 -0000 Subject: [vmkit-commits] [vmkit] r198251 - remove last unsafe llvm functions from J3Class and J3Method. The code is now probably thread safe for llvm. Message-ID: <20131230221022.918032A6C029@llvm.org> Author: gthomas Date: Mon Dec 30 16:10:21 2013 New Revision: 198251 URL: http://llvm.org/viewvc/llvm-project?rev=198251&view=rev Log: remove last unsafe llvm functions from J3Class and J3Method. The code is now probably thread safe for llvm. Modified: vmkit/branches/mcjit/include/j3/j3class.h vmkit/branches/mcjit/include/j3/j3codegen.h vmkit/branches/mcjit/include/j3/j3method.h vmkit/branches/mcjit/lib/j3/vm/j3class.cc vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc vmkit/branches/mcjit/lib/j3/vm/j3method.cc vmkit/branches/mcjit/lib/j3/vm/j3thread.cc Modified: vmkit/branches/mcjit/include/j3/j3class.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3class.h?rev=198251&r1=198250&r2=198251&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3class.h (original) +++ vmkit/branches/mcjit/include/j3/j3class.h Mon Dec 30 16:10:21 2013 @@ -11,8 +11,6 @@ namespace llvm { class Type; - class GlobalValue; - class Module; } namespace vmkit { @@ -168,7 +166,6 @@ namespace j3 { uint32_t logSize() { return sizeof(uintptr_t) == 8 ? 3 : 2; } llvm::Type* llvmType(); - llvm::GlobalValue* unsafe_llvmDescriptor(llvm::Module* module); J3InterfaceSlotDescriptor* slotDescriptorAt(uint32_t index) { return &_interfaceSlotDescriptors[index]; } void prepareInterfaceTable(); Modified: vmkit/branches/mcjit/include/j3/j3codegen.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3codegen.h?rev=198251&r1=198250&r2=198251&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3codegen.h (original) +++ vmkit/branches/mcjit/include/j3/j3codegen.h Mon Dec 30 16:10:21 2013 @@ -40,7 +40,7 @@ namespace j3 { friend class J3ExceptionNode; vmkit::BumpAllocator* allocator; - llvm::Module* _module; + llvm::Module* module; llvm::BasicBlock* bb; llvm::IRBuilder<>* builder; llvm::Function* llvmFunction; @@ -77,87 +77,92 @@ namespace j3 { bool isWide; - llvm::Module* module() { return _module; } + uint32_t wideReadU1(); + uint32_t wideReadS1(); - uint32_t wideReadU1(); - uint32_t wideReadS1(); + llvm::FunctionType* llvmFunctionType(J3MethodType* type); + llvm::Function* buildFunction(J3Method* method, bool isStub=1); + llvm::Value* methodDescriptor(J3Method* method); + llvm::Value* typeDescriptor(J3ObjectType* objectType, llvm::Type* type); - llvm::Value* spToCurrentThread(llvm::Value* sp); - llvm::Value* currentThread(); + llvm::Value* spToCurrentThread(llvm::Value* sp); + llvm::Value* currentThread(); - llvm::Value* nullCheck(llvm::Value* obj); + llvm::Value* nullCheck(llvm::Value* obj); - llvm::BasicBlock* newBB(const char* name); - bool onEndPoint(); - llvm::BasicBlock* forwardBranch(const char* id, uint32_t pc, bool doAlloc, bool doPush); - void condBr(llvm::Value* op); + llvm::BasicBlock* newBB(const char* name); + bool onEndPoint(); + llvm::BasicBlock* forwardBranch(const char* id, uint32_t pc, bool doAlloc, bool doPush); + void condBr(llvm::Value* op); - llvm::Value* flatten(llvm::Value* v, J3Type* type); - llvm::Value* unflatten(llvm::Value* v, J3Type* type); + llvm::Value* flatten(llvm::Value* v, J3Type* type); + llvm::Value* unflatten(llvm::Value* v, J3Type* type); - llvm::Value* handleToObject(llvm::Value* obj); - llvm::Value* javaClass(J3ObjectType* type); - llvm::Value* staticInstance(J3Class* cl); - llvm::Value* vt(J3ObjectType* cl, bool resolve=0); - llvm::Value* vt(llvm::Value* obj); - void initialiseJ3ObjectType(J3ObjectType* cl); + llvm::Value* handleToObject(llvm::Value* obj); + llvm::Value* javaClass(J3ObjectType* type); + llvm::Value* staticInstance(J3Class* cl); + llvm::Value* vt(J3ObjectType* cl, bool resolve=0); + llvm::Value* vt(llvm::Value* obj); + void initialiseJ3ObjectType(J3ObjectType* cl); - void monitorEnter(llvm::Value* obj); - void monitorExit(llvm::Value* obj); + void monitorEnter(llvm::Value* obj); + void monitorExit(llvm::Value* obj); - llvm::Value* isAssignableTo(llvm::Value* obj, J3ObjectType* type); - void instanceof(llvm::Value* obj, J3ObjectType* type); - void checkCast(llvm::Value* obj, J3ObjectType* type); + llvm::Value* isAssignableTo(llvm::Value* obj, J3ObjectType* type); + void instanceof(llvm::Value* obj, J3ObjectType* type); + void checkCast(llvm::Value* obj, J3ObjectType* type); - void floatToInteger(J3Type* from, J3Type* to); - void compareFP(bool isL); - void compareLong(); + void floatToInteger(J3Type* from, J3Type* to); + void compareFP(bool isL); + void compareLong(); - llvm::Value* fieldOffset(llvm::Value* obj, J3Field* f); + llvm::Value* fieldOffset(llvm::Value* obj, J3Field* f); - void get(llvm::Value* obj, J3Field* field); - void getField(uint32_t idx); - void getStatic(uint32_t idx); + void get(llvm::Value* obj, J3Field* field); + void getField(uint32_t idx); + void getStatic(uint32_t idx); - void put(llvm::Value* obj, llvm::Value* val, J3Field* field); - void putField(uint32_t idx); - void putStatic(uint32_t idx); + void put(llvm::Value* obj, llvm::Value* val, J3Field* field); + void putField(uint32_t idx); + void putStatic(uint32_t idx); - void invoke(J3Method* method, llvm::Value* func); - void invokeVirtual(uint32_t idx); - void invokeStatic(uint32_t idx); - void invokeSpecial(uint32_t idx); - void invokeInterface(uint32_t idx); + void invoke(J3Method* method, llvm::Value* func); + void invokeVirtual(uint32_t idx); + void invokeStatic(uint32_t idx); + void invokeSpecial(uint32_t idx); + void invokeInterface(uint32_t idx); - llvm::Value* arrayContent(J3Type* cType, llvm::Value* array, llvm::Value* idx); + llvm::Value* arrayContent(J3Type* cType, llvm::Value* array, llvm::Value* idx); - void arrayBoundCheck(llvm::Value* obj, llvm::Value* idx); - llvm::Value* arrayLength(llvm::Value* obj); - llvm::Value* arrayLengthPtr(llvm::Value* obj); - void arrayStore(J3Type* cType); - void arrayLoad(J3Type* cType); + void arrayBoundCheck(llvm::Value* obj, llvm::Value* idx); + llvm::Value* arrayLength(llvm::Value* obj); + llvm::Value* arrayLengthPtr(llvm::Value* obj); + void arrayStore(J3Type* cType); + void arrayLoad(J3Type* cType); - void newArray(uint8_t atype); - void newArray(J3ArrayClass* type); - void newObject(J3Class* cl); + void newArray(uint8_t atype); + void newArray(J3ArrayClass* type); + void newObject(J3Class* cl); - void ldc(uint32_t idx); + void ldc(uint32_t idx); - void selectExceptionNode(uint32_t idx); + void selectExceptionNode(uint32_t idx); - void translate(); + void translate(); - void initExceptionNode(J3ExceptionNode** pnode, uint32_t pc, J3ExceptionNode* node); - void addToExceptionNode(J3ExceptionNode* node, J3ExceptionEntry* entry); - void closeExceptionNode(J3ExceptionNode* node); + void initExceptionNode(J3ExceptionNode** pnode, uint32_t pc, J3ExceptionNode* node); + void addToExceptionNode(J3ExceptionNode* node, J3ExceptionEntry* entry); + void closeExceptionNode(J3ExceptionNode* node); - void generateJava(); - void generateNative(); + void generateJava(); + void generateNative(); + llvm::Function* lookupNative(); + llvm::Type* doNativeType(J3Type* type); - llvm::Value* buildString(const char* msg); + llvm::Value* buildString(const char* msg); - static void echoDebugEnter(uint32_t isLeave, const char* msg, ...); - static void echoDebugExecute(uint32_t level, const char* msg, ...); + static void echoDebugEnter(uint32_t isLeave, const char* msg, ...); + static void echoDebugExecute(uint32_t level, const char* msg, ...); #define _x(name, id) \ llvm::Function* name; @@ -170,13 +175,13 @@ namespace j3 { llvm::Function* patchPoint64; llvm::Function* patchPointVoid; - J3CodeGen(vmkit::BumpAllocator* _allocator, J3Method* method, llvm::Function* _llvmFunction); + J3CodeGen(vmkit::BumpAllocator* _allocator, J3Method* method); ~J3CodeGen(); void* operator new(size_t n, vmkit::BumpAllocator* _allocator); void operator delete(void* ptr); public: - static void translate(J3Method* method, llvm::Function* llvmFunction); + static void translate(J3Method* method); }; } Modified: vmkit/branches/mcjit/include/j3/j3method.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3method.h?rev=198251&r1=198250&r2=198251&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3method.h (original) +++ vmkit/branches/mcjit/include/j3/j3method.h Mon Dec 30 16:10:21 2013 @@ -9,10 +9,6 @@ namespace llvm { class FunctionType; class Function; - class Type; - class GlobalValue; - class Module; - struct GenericValue; } namespace vmkit { @@ -36,7 +32,8 @@ namespace j3 { public: J3MethodType(J3Type** args, size_t nbArgs); - llvm::FunctionType* unsafe_llvmFunctionType(); /* call only while compiler locked */ + void setFunctionType(llvm::FunctionType* functionType) { _llvmFunctionType = functionType; } + llvm::FunctionType* functionType() { return _llvmFunctionType; } uint32_t nbIns() { return _nbIns; } J3Type* out() { return _out; } J3Type* ins(uint32_t idx) { return _ins[idx]; } @@ -72,14 +69,16 @@ namespace j3 { void* volatile _staticTrampoline; void* volatile _virtualTrampoline; - llvm::Type* doNativeType(J3Type* type); - J3Value internalInvoke(bool statically, J3ObjectHandle* handle, va_list va); J3Value internalInvoke(bool statically, J3ObjectHandle* handle, J3Value* args); void buildLLVMNames(J3Class* from); public: J3Method(uint16_t access, J3Class* cl, const vmkit::Name* name, const vmkit::Name* sign); + void* nativeFnPtr() { return _nativeFnPtr; } + + void markCompiled(llvm::Function* llvmFunction, void* fnPtr); + uint32_t interfaceIndex(); void* getSymbolAddress(); @@ -87,20 +86,16 @@ namespace j3 { char* llvmFunctionName(J3Class* from=0); char* llvmDescriptorName(J3Class* from=0); char* llvmStubName(J3Class* from=0); - llvm::FunctionType* llvmType(J3Class* from=0); void postInitialise(uint32_t access, J3Attributes* attributes); void setResolved(uint32_t index); J3Method* resolve(J3ObjectHandle* obj); - llvm::Function* unsafe_nativeLLVMFunction(llvm::Module* module); /* call only while compiler locked */ - llvm::GlobalValue* unsafe_llvmDescriptor(llvm::Module* module); - llvm::Function* unsafe_llvmFunction(bool isStub, llvm::Module* module, J3Class* from=0); /* call only while compiler locked */ - uint32_t index(); uint32_t* indexPtr() { return &_index; } bool isResolved() { return _index != -1; } + bool isCompiled() { return _fnPtr; } J3Attributes* attributes() const { return _attributes; } uint16_t access() const { return _access; } Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=198251&r1=198250&r2=198251&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Mon Dec 30 16:10:21 2013 @@ -151,10 +151,6 @@ llvm::Type* J3ObjectType::llvmType() { return loader()->vm()->typeJ3ObjectPtr; } -llvm::GlobalValue* J3ObjectType::unsafe_llvmDescriptor(llvm::Module* module) { - return llvm::cast(module->getOrInsertGlobal(nativeName(), loader()->vm()->typeJ3ObjectType)); -} - J3Method* J3ObjectType::findVirtualMethod(const vmkit::Name* name, const vmkit::Name* sign, bool error) { J3::internalError(L"should not happe: %ls::%ls\n", J3ObjectType::name()->cStr(), name->cStr()); } Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=198251&r1=198250&r2=198251&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Mon Dec 30 16:10:21 2013 @@ -26,7 +26,7 @@ using namespace j3; #define _onEndPoint() ({ if(onEndPoint()) return; }) -J3CodeGen::J3CodeGen(vmkit::BumpAllocator* _allocator, J3Method* m, llvm::Function* _llvmFunction) : +J3CodeGen::J3CodeGen(vmkit::BumpAllocator* _allocator, J3Method* m) : exceptions(this) { allocator = _allocator; @@ -45,9 +45,9 @@ J3CodeGen::J3CodeGen(vmkit::BumpAllocato if(vm->options()->debugTranslate) fprintf(stderr, " translating bytecode of: %ls::%ls%ls\n", method->cl()->name()->cStr(), method->name()->cStr(), method->sign()->cStr()); - llvmFunction = _llvmFunction; + module = new llvm::Module(method->llvmFunctionName(), vm->llvmContext()); + llvmFunction = buildFunction(method, 0); llvmFunction->setGC("vmkit"); - _module = llvmFunction->getParent(); bbCheckCastFailed = 0; bbNullCheckFailed = 0; @@ -62,19 +62,19 @@ J3CodeGen::J3CodeGen(vmkit::BumpAllocato uintPtrTy = builder->getIntPtrTy(vm->dataLayout()); #define _x(name, id) \ - name = vm->introspectFunction(module(), id); + name = vm->introspectFunction(module, id); #include "j3/j3meta.def" #undef _x - gvTypeInfo = vm->introspectGlobalValue(module(), "typeinfo for void*"); + gvTypeInfo = vm->introspectGlobalValue(module, "typeinfo for void*"); - gcRoot = vm->getGCRoot(module()); + gcRoot = vm->getGCRoot(module); - frameAddress = llvm::Intrinsic::getDeclaration(module(), llvm::Intrinsic::frameaddress); + frameAddress = llvm::Intrinsic::getDeclaration(module, llvm::Intrinsic::frameaddress); #if 0 - //stackMap = llvm::Intrinsic::getDeclaration(module(), llvm::Intrinsic::experimental_stackmap); - //patchPointVoid = llvm::Intrinsic::getDeclaration(module(), llvm::Intrinsic::experimental_patchpoint_i64); + //stackMap = llvm::Intrinsic::getDeclaration(module, llvm::Intrinsic::experimental_stackmap); + //patchPointVoid = llvm::Intrinsic::getDeclaration(module, llvm::Intrinsic::experimental_patchpoint_i64); { llvm::Type* ins[] = { builder->getInt64Ty(), @@ -83,7 +83,7 @@ J3CodeGen::J3CodeGen(vmkit::BumpAllocato builder->getInt32Ty() }; patchPointVoid = (llvm::Function*) - module()->getOrInsertFunction(llvm::Intrinsic::getName(llvm::Intrinsic::experimental_patchpoint_void), + module->getOrInsertFunction(llvm::Intrinsic::getName(llvm::Intrinsic::experimental_patchpoint_void), llvm::FunctionType::get(builder->getVoidTy(), ins, 1)); } #endif @@ -99,6 +99,11 @@ J3CodeGen::J3CodeGen(vmkit::BumpAllocato if(vm->options()->debugTranslate > 3) llvmFunction->dump(); + + loader->compileModule(module); + void* fnPtr = (void*)loader->ee()->getFunctionAddress(llvmFunction->getName().data()); + + method->markCompiled(llvmFunction, fnPtr); } J3CodeGen::~J3CodeGen() { @@ -111,10 +116,14 @@ void* J3CodeGen::operator new(size_t n, void J3CodeGen::operator delete(void* ptr) { } -void J3CodeGen::translate(J3Method* method, llvm::Function* llvmFunction) { +void J3CodeGen::translate(J3Method* method) { + method->cl()->loader()->vm()->lockCompiler(); + vmkit::BumpAllocator* allocator = vmkit::BumpAllocator::create(); - delete new(allocator) J3CodeGen(allocator, method, llvmFunction); + delete new(allocator) J3CodeGen(allocator, method); vmkit::BumpAllocator::destroy(allocator); + + method->cl()->loader()->vm()->unlockCompiler(); } uint32_t J3CodeGen::wideReadU1() { @@ -164,6 +173,34 @@ llvm::Value* J3CodeGen::unflatten(llvm:: } } +llvm::FunctionType* J3CodeGen::llvmFunctionType(J3MethodType* type) { + llvm::FunctionType* res = type->functionType(); + + if(!res) { + std::vector in; + for(uint32_t i=0; inbIns(); i++) + in.push_back(type->ins(i)->llvmType()); + res = llvm::FunctionType::get(type->out()->llvmType(), in, 0); + type->setFunctionType(res); + } + return res; +} + +llvm::Function* J3CodeGen::buildFunction(J3Method* method, bool isStub) { + const char* id = (isStub && !method->isCompiled()) ? method->llvmStubName(cl) : method->llvmFunctionName(cl); + return (llvm::Function*)module->getOrInsertFunction(id, llvmFunctionType(method->methodType(cl))); +} + +llvm::Value* J3CodeGen::typeDescriptor(J3ObjectType* objectType, llvm::Type* type) { + llvm::Value* v = module->getOrInsertGlobal(objectType->nativeName(), + vm->typeJ3ObjectType); + return type == vm->typeJ3ObjectTypePtr ? v : builder->CreateBitCast(v, type); +} + +llvm::Value* J3CodeGen::methodDescriptor(J3Method* method) { + return module->getOrInsertGlobal(method->llvmDescriptorName(), vm->typeJ3Method); +} + llvm::Value* J3CodeGen::spToCurrentThread(llvm::Value* sp) { return builder->CreateIntToPtr(builder->CreateAnd(builder->CreatePtrToInt(sp, uintPtrTy), llvm::ConstantInt::get(uintPtrTy, vmkit::Thread::getThreadMask())), @@ -273,11 +310,11 @@ void J3CodeGen::monitorExit(llvm::Value* void J3CodeGen::initialiseJ3ObjectType(J3ObjectType* cl) { if(!cl->isInitialised()) - builder->CreateCall(funcJ3TypeInitialise, builder->CreateBitCast(cl->unsafe_llvmDescriptor(module()), vm->typeJ3TypePtr)); + builder->CreateCall(funcJ3TypeInitialise, typeDescriptor(cl, vm->typeJ3TypePtr)); } llvm::Value* J3CodeGen::javaClass(J3ObjectType* type) { - return builder->CreateCall(funcJ3ObjectTypeJavaClass, type->unsafe_llvmDescriptor(module())); + return builder->CreateCall(funcJ3ObjectTypeJavaClass, typeDescriptor(type, vm->typeJ3ObjectTypePtr)); } llvm::Value* J3CodeGen::handleToObject(llvm::Value* obj) { @@ -288,7 +325,7 @@ llvm::Value* J3CodeGen::handleToObject(l llvm::Value* J3CodeGen::staticInstance(J3Class* cl) { initialiseJ3ObjectType(cl); return handleToObject(builder->CreateCall(funcJ3ClassStaticInstance, - builder->CreateBitCast(cl->unsafe_llvmDescriptor(module()), vm->typeJ3ClassPtr))); + typeDescriptor(cl, vm->typeJ3ClassPtr))); } llvm::Value* J3CodeGen::vt(llvm::Value* obj) { @@ -301,7 +338,7 @@ llvm::Value* J3CodeGen::vt(llvm::Value* llvm::Value* J3CodeGen::vt(J3ObjectType* type, bool doResolve) { llvm::Value* func = doResolve && !type->isResolved() ? funcJ3TypeVTAndResolve : funcJ3TypeVT; - return builder->CreateCall(func, builder->CreateBitCast(type->unsafe_llvmDescriptor(module()), vm->typeJ3TypePtr)); + return builder->CreateCall(func, typeDescriptor(type, vm->typeJ3TypePtr)); } llvm::Value* J3CodeGen::nullCheck(llvm::Value* obj) { @@ -365,7 +402,7 @@ void J3CodeGen::invokeInterface(uint32_t builder->getInt32(J3VirtualTable::gepInterfaceMethods), builder->getInt32(index % J3VirtualTable::nbInterfaceMethodTable) }; llvm::Value* func = builder->CreateBitCast(builder->CreateLoad(builder->CreateGEP(vt(obj), gepFunc)), - type->unsafe_llvmFunctionType()->getPointerTo()); + llvmFunctionType(type)->getPointerTo()); invoke(target, func); } @@ -378,14 +415,14 @@ void J3CodeGen::invokeVirtual(uint32_t i if(target->isResolved()) funcEntry = builder->getInt32(target->index()); else - funcEntry = builder->CreateCall(funcJ3MethodIndex, target->unsafe_llvmDescriptor(module())); + funcEntry = builder->CreateCall(funcJ3MethodIndex, methodDescriptor(target)); llvm::Value* obj = nullCheck(stack.top(type->nbIns() - 1)); llvm::Value* gepFunc[] = { builder->getInt32(0), builder->getInt32(J3VirtualTable::gepVirtualMethods), funcEntry }; llvm::Value* func = builder->CreateBitCast(builder->CreateLoad(builder->CreateGEP(vt(obj), gepFunc)), - type->unsafe_llvmFunctionType()->getPointerTo()); + llvmFunctionType(type)->getPointerTo()); invoke(target, func); } @@ -393,12 +430,12 @@ void J3CodeGen::invokeVirtual(uint32_t i void J3CodeGen::invokeStatic(uint32_t idx) { J3Method* target = cl->methodAt(idx, J3Cst::ACC_STATIC); initialiseJ3ObjectType(target->cl()); - invoke(target, target->unsafe_llvmFunction(1, module(), cl)); + invoke(target, buildFunction(target)); } void J3CodeGen::invokeSpecial(uint32_t idx) { J3Method* target = cl->methodAt(idx, 0); - invoke(target, target->unsafe_llvmFunction(1, module(), cl)); + invoke(target, buildFunction(target)); } llvm::Value* J3CodeGen::fieldOffset(llvm::Value* obj, J3Field* f) { @@ -514,7 +551,7 @@ void J3CodeGen::newObject(J3Class* cl) { llvm::Value* size; if(!cl->isResolved()) { - size = builder->CreateCall(funcJ3LayoutStructSize, builder->CreateBitCast(cl->unsafe_llvmDescriptor(module()), vm->typeJ3LayoutPtr)); + size = builder->CreateCall(funcJ3LayoutStructSize, typeDescriptor(cl, vm->typeJ3LayoutPtr)); } else { size = builder->getInt64(cl->structSize()); } @@ -641,7 +678,7 @@ void J3CodeGen::ldc(uint32_t idx) { case J3Cst::CONSTANT_Class: res = handleToObject(javaClass(cl->classAt(idx))); break; case J3Cst::CONSTANT_String: res = handleToObject(builder->CreateCall2(funcJ3ClassStringAt, - builder->CreateBitCast(cl->unsafe_llvmDescriptor(module()), vm->typeJ3ClassPtr), + typeDescriptor(cl, vm->typeJ3ClassPtr), builder->getInt16(idx))); break; default: @@ -737,7 +774,7 @@ llvm::Value* J3CodeGen::buildString(cons elmts.push_back(builder->getInt8(0)); llvm::Constant* str = llvm::ConstantArray::get(llvm::ArrayType::get(builder->getInt8Ty(), n+1), elmts); - llvm::Value* var = new llvm::GlobalVariable(*module(), + llvm::Value* var = new llvm::GlobalVariable(*module, str->getType(), 1, llvm::GlobalVariable::InternalLinkage, @@ -1492,7 +1529,7 @@ void J3CodeGen::generateJava() { if(!reader.adjustSize(length)) J3::classFormatError(cl, L"Code attribute of %ls %ls is too large (%d)", method->name()->cStr(), method->sign()->cStr(), length); - llvm::DIBuilder* dbgBuilder = new llvm::DIBuilder(*module()); + llvm::DIBuilder* dbgBuilder = new llvm::DIBuilder(*module); dbgInfo = dbgBuilder->createFunction(llvm::DIDescriptor(), // Function scope @@ -1568,10 +1605,66 @@ void J3CodeGen::generateJava() { ret.killUnused(); } +llvm::Type* J3CodeGen::doNativeType(J3Type* type) { + llvm::Type* t = type->llvmType(); + + if(t->isPointerTy()) + return vm->typeJ3ObjectHandlePtr; + else + return t; +} + +llvm::Function* J3CodeGen::lookupNative() { + J3Mangler mangler(cl); + + mangler.mangle(mangler.javaId)->mangle(method); + uint32_t length = mangler.length(); + mangler.mangleType(method); + + void* fnPtr = method->nativeFnPtr(); + + if(!fnPtr) + fnPtr = loader->lookupNativeFunctionPointer(method, mangler.cStr()); + + if(!fnPtr) { + mangler.cStr()[length] = 0; + fnPtr = loader->lookupNativeFunctionPointer(method, mangler.mangleType(method)->cStr()); + } + + if(!fnPtr) + J3::linkageError(method); + + std::vector nativeIns; + llvm::Type* nativeOut; + + nativeIns.push_back(vm->typeJNIEnvPtr); + + if(J3Cst::isStatic(method->access())) + nativeIns.push_back(doNativeType(vm->classClass)); + + for(int i=0; inbIns(); i++) + nativeIns.push_back(doNativeType(methodType->ins(i))); + + nativeOut = doNativeType(methodType->out()); + + char* buf = (char*)loader->allocator()->allocate(mangler.length()+1); + memcpy(buf, mangler.cStr(), mangler.length()+1); + + llvm::FunctionType* fType = llvm::FunctionType::get(nativeOut, nativeIns, 0); + llvm::Function* res = llvm::Function::Create(fType, + llvm::GlobalValue::ExternalLinkage, + buf, + module); + + loader->addSymbol(buf, new(loader->allocator()) vmkit::NativeSymbol(fnPtr)); + + return res; +} + void J3CodeGen::generateNative() { std::vector args; - llvm::Function* nat = method->unsafe_nativeLLVMFunction(module()); + llvm::Function* nat = lookupNative(); llvm::Value* res; llvm::Value* thread = currentThread(); Modified: vmkit/branches/mcjit/lib/j3/vm/j3method.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3method.cc?rev=198251&r1=198250&r2=198251&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3method.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3method.cc Mon Dec 30 16:10:21 2013 @@ -28,16 +28,6 @@ J3MethodType::J3MethodType(J3Type** args } -llvm::FunctionType* J3MethodType::unsafe_llvmFunctionType() { - if(!_llvmFunctionType) { - std::vector in; - for(uint32_t i=0; illvmType()); - _llvmFunctionType = llvm::FunctionType::get(out()->llvmType(), in, 0); - } - return _llvmFunctionType; -} - J3Method::J3Method(uint16_t access, J3Class* cl, const vmkit::Name* name, const vmkit::Name* sign) : _selfCode(this) { _access = access; @@ -55,8 +45,13 @@ uint32_t J3Method::index() { return _index; } +void J3Method::markCompiled(llvm::Function* llvmFunction, void* fnPtr) { + _llvmFunction = llvmFunction; + _fnPtr = fnPtr; +} + void* J3Method::fnPtr() { - if(!_fnPtr) { + if(!isCompiled()) { //fprintf(stderr, "materializing: %ls::%ls%ls\n", this, cl()->name()->cStr(), name()->cStr(), sign()->cStr()); if(!isResolved()) { if(cl()->loader()->vm()->options()->debugLinking) @@ -67,23 +62,14 @@ void* J3Method::fnPtr() { J3::noSuchMethodError(L"unable to find method", cl(), name(), sign()); } - cl()->loader()->vm()->lockCompiler(); - llvm::Module* module = new llvm::Module(llvmFunctionName(), cl()->loader()->vm()->llvmContext()); - _llvmFunction = unsafe_llvmFunction(0, module); - - J3CodeGen::translate(this, _llvmFunction); - - cl()->loader()->compileModule(module); - - _fnPtr = (void*)cl()->loader()->ee()->getFunctionAddress(_llvmFunction->getName().data()); - cl()->loader()->vm()->unlockCompiler(); + J3CodeGen::translate(this); } return _fnPtr; } void* J3Method::functionPointerOrStaticTrampoline() { - if(_fnPtr) + if(isCompiled()) return _fnPtr; if(!_staticTrampoline) _staticTrampoline = J3Trampoline::buildStaticTrampoline(cl()->loader()->allocator(), this); @@ -91,7 +77,7 @@ void* J3Method::functionPointerOrStaticT } void* J3Method::functionPointerOrVirtualTrampoline() { - if(_fnPtr) + if(isCompiled()) return _fnPtr; if(!_virtualTrampoline) _virtualTrampoline = J3Trampoline::buildVirtualTrampoline(cl()->loader()->allocator(), this); @@ -335,15 +321,6 @@ char* J3Method::llvmStubName(J3Class* fr return _llvmAllNames + 0; } -llvm::GlobalValue* J3Method::unsafe_llvmDescriptor(llvm::Module* module) { - return llvm::cast(module->getOrInsertGlobal(llvmDescriptorName(), cl()->loader()->vm()->typeJ3Method)); -} - -llvm::Function* J3Method::unsafe_llvmFunction(bool isStub, llvm::Module* module, J3Class* from) { - const char* id = (isStub && !_fnPtr) ? llvmStubName(from) : llvmFunctionName(from); - return (llvm::Function*)module->getOrInsertFunction(id, methodType(from ? from : cl())->unsafe_llvmFunctionType()); -} - void J3Method::dump() { printf("Method: %ls %ls::%ls\n", sign()->cStr(), cl()->name()->cStr(), name()->cStr()); } @@ -353,61 +330,3 @@ void J3Method::registerNative(void* fnPt J3::noSuchMethodError(L"unable to dynamically modify a native function", cl(), name(), sign()); _nativeFnPtr = fnPtr; } - -llvm::Type* J3Method::doNativeType(J3Type* type) { - llvm::Type* t = type->llvmType(); - - if(t->isPointerTy()) - return cl()->loader()->vm()->typeJ3ObjectHandlePtr; - else - return t; -} - -llvm::Function* J3Method::unsafe_nativeLLVMFunction(llvm::Module* module) { - J3ClassLoader* loader = cl()->loader(); - J3Mangler mangler(cl()); - - mangler.mangle(mangler.javaId)->mangle(this); - uint32_t length = mangler.length(); - mangler.mangleType(this); - - void* fnPtr = _nativeFnPtr; - - if(!fnPtr) - fnPtr = loader->lookupNativeFunctionPointer(this, mangler.cStr()); - - if(!fnPtr) { - mangler.cStr()[length] = 0; - fnPtr = loader->lookupNativeFunctionPointer(this, mangler.mangleType(this)->cStr()); - } - - if(!fnPtr) - J3::linkageError(this); - - J3MethodType* type = methodType(); - std::vector nativeIns; - llvm::Type* nativeOut; - - nativeIns.push_back(loader->vm()->typeJNIEnvPtr); - - if(J3Cst::isStatic(access())) - nativeIns.push_back(doNativeType(loader->vm()->classClass)); - - for(int i=0; inbIns(); i++) - nativeIns.push_back(doNativeType(type->ins(i))); - - nativeOut = doNativeType(type->out()); - - char* buf = (char*)cl()->loader()->allocator()->allocate(mangler.length()+1); - memcpy(buf, mangler.cStr(), mangler.length()+1); - - llvm::FunctionType* fType = llvm::FunctionType::get(nativeOut, nativeIns, 0); - llvm::Function* res = llvm::Function::Create(fType, - llvm::GlobalValue::ExternalLinkage, - buf, - module); - - cl()->loader()->addSymbol(buf, new(cl()->loader()->allocator()) vmkit::NativeSymbol(fnPtr)); - - return res; -} Modified: vmkit/branches/mcjit/lib/j3/vm/j3thread.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3thread.cc?rev=198251&r1=198250&r2=198251&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3thread.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3thread.cc Mon Dec 30 16:10:21 2013 @@ -33,7 +33,7 @@ void J3Thread::start(J3ObjectHandle* han vmkit::BumpAllocator* allocator = vmkit::BumpAllocator::create(); J3Thread* thread = new J3Thread(get()->vm()); thread->assocJavaThread(handle); - //thread->Thread::start(); + thread->Thread::start(); } J3Method* J3Thread::getJavaCaller(uint32_t level) { From gael.thomas at lip6.fr Tue Dec 31 00:16:09 2013 From: gael.thomas at lip6.fr (Gael Thomas) Date: Tue, 31 Dec 2013 08:16:09 -0000 Subject: [vmkit-commits] [vmkit] r198260 - some cleanup Message-ID: <20131231081609.D87E72A6C029@llvm.org> Author: gthomas Date: Tue Dec 31 02:16:09 2013 New Revision: 198260 URL: http://llvm.org/viewvc/llvm-project?rev=198260&view=rev Log: some cleanup Added: vmkit/branches/mcjit/include/j3/j3attribute.h vmkit/branches/mcjit/include/j3/j3field.h vmkit/branches/mcjit/lib/j3/vm/j3attribute.cc vmkit/branches/mcjit/lib/j3/vm/j3field.cc Modified: vmkit/branches/mcjit/include/j3/j3class.h vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc vmkit/branches/mcjit/lib/j3/vm/j3.cc vmkit/branches/mcjit/lib/j3/vm/j3class.cc vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc vmkit/branches/mcjit/lib/j3/vm/j3object.cc Added: vmkit/branches/mcjit/include/j3/j3attribute.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3attribute.h?rev=198260&view=auto ============================================================================== --- vmkit/branches/mcjit/include/j3/j3attribute.h (added) +++ vmkit/branches/mcjit/include/j3/j3attribute.h Tue Dec 31 02:16:09 2013 @@ -0,0 +1,39 @@ +#ifndef _J3_ATTRIBUTE_H_ +#define _J3_ATTRIBUTE_H_ + +#include "vmkit/allocator.h" + +namespace vmkit { + class Name; +} + +namespace j3 { + class J3Attribute : public vmkit::PermanentObject { + friend class J3Class; + + const vmkit::Name* _id; + uint32_t _offset; + public: + + const vmkit::Name* id() { return _id; } + uint32_t offset() { return _offset; } + }; + + class J3Attributes : public vmkit::PermanentObject { + size_t _nbAttributes; + J3Attribute _attributes[1]; + public: + J3Attributes(size_t n) { _nbAttributes = n; } + + void* operator new(size_t unused, vmkit::BumpAllocator* allocator, size_t n) { + return vmkit::PermanentObject::operator new(sizeof(J3Attributes) + (n - 1) * sizeof(J3Attribute), allocator); + } + + size_t nbAttributes() { return _nbAttributes; } + J3Attribute* attribute(size_t n); + + J3Attribute* lookup(const vmkit::Name* attr); + }; +} + +#endif Modified: vmkit/branches/mcjit/include/j3/j3class.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3class.h?rev=198260&r1=198259&r2=198260&view=diff ============================================================================== --- vmkit/branches/mcjit/include/j3/j3class.h (original) +++ vmkit/branches/mcjit/include/j3/j3class.h Tue Dec 31 02:16:09 2013 @@ -29,6 +29,14 @@ namespace j3 { class J3ObjectType; class J3Method; class J3Field; + class J3Attributes; + + class J3InterfaceSlotDescriptor { + public: + uint32_t nbMethods; + J3Method** methods; + }; + class J3Type : public vmkit::Symbol { pthread_mutex_t _mutex; @@ -94,71 +102,14 @@ namespace j3 { virtual bool isLayout() { return 0; } virtual bool isClass() { return 0; } virtual bool isPrimitive() { return 0; } + virtual llvm::Type* llvmType() = 0; void dump(); }; - class J3Attribute : public vmkit::PermanentObject { - friend class J3Class; - - const vmkit::Name* _id; - uint32_t _offset; - public: - - const vmkit::Name* id() { return _id; } - uint32_t offset() { return _offset; } - }; - - class J3Attributes : public vmkit::PermanentObject { - size_t _nbAttributes; - J3Attribute _attributes[1]; - public: - J3Attributes(size_t n) { _nbAttributes = n; } - - void* operator new(size_t unused, vmkit::BumpAllocator* allocator, size_t n) { - return vmkit::PermanentObject::operator new(sizeof(J3Attributes) + (n - 1) * sizeof(J3Attribute), allocator); - } - - size_t nbAttributes() { return _nbAttributes; } - J3Attribute* attribute(size_t n); - - J3Attribute* lookup(const vmkit::Name* attr); - }; - - class J3Field : public vmkit::PermanentObject { - friend class J3Class; - - J3Layout* _layout; - uint16_t _access; - const vmkit::Name* _name; - J3Type* _type; - J3Attributes* _attributes; - uintptr_t _offset; - - public: - J3Field() {} - J3Field(uint16_t access, const vmkit::Name* name, J3Type* type) { _access = access; _name = name; _type = type; } - - J3Attributes* attributes() const { return _attributes; } - uint16_t access() { return _access; } - J3Layout* layout() { return _layout; } - const vmkit::Name* name() { return _name; } - J3Type* type() { return _type; } - - uintptr_t offset() { return _offset; } - - void dump(); - }; - - class J3InterfaceSlotDescriptor { - public: - uint32_t nbMethods; - J3Method** methods; - }; - class J3ObjectType : public J3Type { - J3ObjectHandle* _javaClass; + J3ObjectHandle* volatile _javaClass; J3InterfaceSlotDescriptor _interfaceSlotDescriptors[J3VirtualTable::nbInterfaceMethodTable]; public: @@ -185,10 +136,12 @@ namespace j3 { class J3Layout : public J3ObjectType { friend class J3Class; - size_t nbFields; - J3Field* fields; + size_t _nbFields; + size_t _nbPublicFields; + J3Field* _fields; size_t _nbMethods; + size_t _nbPublicMethods; J3Method** _methods; uintptr_t _structSize; @@ -199,7 +152,12 @@ namespace j3 { uintptr_t structSize(); + size_t nbFields() { return _nbFields; } + size_t nbPublicFields() { return _nbPublicFields; } + J3Field* fields() { return _fields; } + size_t nbMethods() { return _nbMethods; } + size_t nbPublicMethods() { return _nbPublicMethods; } J3Method** methods() { return _methods; } J3Method* findMethod(const vmkit::Name* name, const vmkit::Name* sign); @@ -217,7 +175,7 @@ namespace j3 { }; class J3Class : public J3Layout { - J3StaticLayout staticLayout; + J3StaticLayout _staticLayout; uint16_t _access; @@ -252,6 +210,8 @@ namespace j3 { public: J3Class(J3ClassLoader* loader, const vmkit::Name* name, J3ClassBytes* bytes); + J3StaticLayout* staticLayout() { return &_staticLayout; } + size_t nbInterfaces() { return _nbInterfaces; } J3Class** interfaces() { return _interfaces; } J3Class* super() { return _super; } Added: vmkit/branches/mcjit/include/j3/j3field.h URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3field.h?rev=198260&view=auto ============================================================================== --- vmkit/branches/mcjit/include/j3/j3field.h (added) +++ vmkit/branches/mcjit/include/j3/j3field.h Tue Dec 31 02:16:09 2013 @@ -0,0 +1,44 @@ +#ifndef _J3_FIELD_H_ +#define _J3_FIELD_H_ + +#include "vmkit/allocator.h" + +namespace vmkit { + class Name; +} + +namespace j3 { + class J3Layout; + class J3Type; + class J3Attributes; + class J3ObjectHandle; + + class J3Field : public vmkit::PermanentObject { + friend class J3Class; + + J3Layout* _layout; + uint16_t _access; + const vmkit::Name* _name; + J3Type* _type; + J3Attributes* _attributes; + uintptr_t _offset; + J3ObjectHandle* volatile _javaField; + + public: + J3Field() {} + J3Field(uint16_t access, const vmkit::Name* name, J3Type* type) { _access = access; _name = name; _type = type; } + + J3ObjectHandle* javaField(); + J3Attributes* attributes() const { return _attributes; } + uint16_t access() { return _access; } + J3Layout* layout() { return _layout; } + const vmkit::Name* name() { return _name; } + J3Type* type() { return _type; } + + uintptr_t offset() { return _offset; } + + void dump(); + }; +} + +#endif Modified: vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc?rev=198260&r1=198259&r2=198260&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc (original) +++ vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc Tue Dec 31 02:16:09 2013 @@ -4,6 +4,8 @@ #include "j3/j3classloader.h" #include "j3/j3class.h" #include "j3/j3method.h" +#include "j3/j3constants.h" +#include "j3/j3field.h" #include "jvm.h" using namespace j3; @@ -385,11 +387,31 @@ jbyteArray JNICALL JVM_GetClassTypeAnnot jobjectArray JNICALL JVM_GetClassDeclaredMethods(JNIEnv* env, jclass ofClass, jboolean publicOnly) { enterJVM(); NYI(); leaveJVM(); } jobjectArray JNICALL JVM_GetClassDeclaredFields(JNIEnv* env, jclass ofClass, jboolean publicOnly) { + jobjectArray res; + enterJVM(); J3ObjectType* type = J3ObjectType::nativeClass(ofClass); + if(type->isClass()) { + J3Class* cl = type->asClass(); + cl->resolve(); + size_t total = publicOnly ? + cl->nbPublicFields() + cl->staticLayout()->nbPublicFields() : + cl->nbFields() + cl->staticLayout()->nbFields(); + + res = J3ObjectHandle::doNewArray(type->loader()->vm()->fieldClass->getArray(), total); + + size_t cur = 0; + for(uint32_t i=0; inbFields(); i++) + if(!publicOnly || J3Cst::isPublic(cl->fields()[i].access())) + res->setObjectAt(i, cl->fields()[i].javaField()); + } else + res = J3ObjectHandle::doNewArray(type->loader()->vm()->fieldClass->getArray(), 0); + NYI(); - leaveJVM(); + leaveJVM(); + + return res; } jobjectArray JNICALL JVM_GetClassDeclaredConstructors(JNIEnv* env, jclass ofClass, jboolean publicOnly) { enterJVM(); NYI(); leaveJVM(); } Modified: vmkit/branches/mcjit/lib/j3/vm/j3.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3.cc?rev=198260&r1=198259&r2=198260&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3.cc Tue Dec 31 02:16:09 2013 @@ -10,6 +10,7 @@ #include "j3/j3thread.h" #include "j3/j3trampoline.h" #include "j3/j3lib.h" +#include "j3/j3field.h" #include "llvm/IR/Type.h" #include "llvm/IR/DerivedTypes.h" Added: vmkit/branches/mcjit/lib/j3/vm/j3attribute.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3attribute.cc?rev=198260&view=auto ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3attribute.cc (added) +++ vmkit/branches/mcjit/lib/j3/vm/j3attribute.cc Tue Dec 31 02:16:09 2013 @@ -0,0 +1,20 @@ +#include "j3/j3attribute.h" +#include "j3/j3.h" + +using namespace j3; + +J3Attribute* J3Attributes::attribute(size_t n) { + if(n >= _nbAttributes) + J3::internalError(L"should not happen"); + return _attributes + n; +} + +J3Attribute* J3Attributes::lookup(const vmkit::Name* id) { + for(size_t i=0; i<_nbAttributes; i++) { + if(_attributes[i].id() == id) + return _attributes+i; + } + + return 0; +} + Modified: vmkit/branches/mcjit/lib/j3/vm/j3class.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3class.cc?rev=198260&r1=198259&r2=198260&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Tue Dec 31 02:16:09 2013 @@ -15,6 +15,8 @@ #include "j3/j3mangler.h" #include "j3/j3object.h" #include "j3/j3thread.h" +#include "j3/j3field.h" +#include "j3/j3attribute.h" using namespace j3; @@ -170,8 +172,8 @@ J3ObjectHandle* J3ObjectType::javaClass( J3ObjectHandle* prev = J3Thread::get()->tell(); _javaClass = loader()->globalReferences()->add(J3ObjectHandle::doNewObject(loader()->vm()->classClass)); J3Thread::get()->restore(prev); - _javaClass->setLong(loader()->vm()->classVMData, (int64_t)(uintptr_t)this); - loader()->vm()->classInit->invokeSpecial(_javaClass); + javaClass()->setLong(loader()->vm()->classVMData, (int64_t)(uintptr_t)this); + loader()->vm()->classInit->invokeSpecial(javaClass()); } unlock(); } @@ -268,8 +270,8 @@ J3Method* J3Layout::findMethod(const vmk } J3Field* J3Layout::findField(const vmkit::Name* name, const J3Type* type) { - for(size_t i=0; iname()->cStr(), cur->type()->name()->cStr()); //printf(" with %ls - %ls\n", name->cStr(), type->name()->cStr()); @@ -285,7 +287,7 @@ J3Field* J3Layout::findField(const vmkit */ J3Class::J3Class(J3ClassLoader* loader, const vmkit::Name* name, J3ClassBytes* bytes) : J3Layout(loader, name), - staticLayout(loader, this, name){ + _staticLayout(loader, this, name){ _bytes = bytes; status = LOADED; } @@ -319,7 +321,7 @@ J3Method* J3Class::findStaticMethod(cons J3Class* cur = this; J3Method* res; while(1) { - res = cur->staticLayout.findMethod(name, sign); + res = cur->staticLayout()->findMethod(name, sign); if(res) return res; @@ -352,7 +354,7 @@ J3Field* J3Class::findStaticField(const //fprintf(stderr, "Lookup static field %ls %ls::%ls\n", ftype->name()->cStr(), name()->cStr(), fname->cStr()); resolve(); - J3Field* res = staticLayout.findField(fname, ftype); + J3Field* res = staticLayout()->findField(fname, ftype); if(!res) J3::internalError(L"implement me"); @@ -362,7 +364,7 @@ J3Field* J3Class::findStaticField(const void J3Class::registerNative(const vmkit::Name* methName, const vmkit::Name* methSign, void* fnPtr) { resolve(); - J3Method* res = staticLayout.findMethod(methName, methSign); + J3Method* res = staticLayout()->findMethod(methName, methSign); if(!res) res = findMethod(methName, methSign); if(!res || !J3Cst::isNative(res->access())) @@ -389,13 +391,13 @@ void J3Class::doInitialise() { interfaces()[i]->initialise(); J3ObjectHandle* prev = J3Thread::get()->tell(); - J3ObjectHandle* stacked = J3ObjectHandle::allocate(staticLayout.vt(), staticLayout.structSize()); + J3ObjectHandle* stacked = J3ObjectHandle::allocate(staticLayout()->vt(), staticLayout()->structSize()); _staticInstance = loader()->globalReferences()->add(stacked); J3Thread::get()->restore(prev); - for(size_t i=0; inbFields(); i++) { + J3Field* cur = staticLayout()->fields() + i; J3Attribute* attr = cur->attributes()->lookup(loader()->vm()->constantValueAttr); if(attr) { @@ -420,7 +422,7 @@ void J3Class::doInitialise() { } } - J3Method* clinit = staticLayout.findMethod(loader()->vm()->clinitName, loader()->vm()->clinitSign); + J3Method* clinit = staticLayout()->findMethod(loader()->vm()->clinitName, loader()->vm()->clinitSign); if(clinit) clinit->invokeStatic(); @@ -437,7 +439,7 @@ void J3Class::doResolve(J3Field* hiddenF status = RESOLVED; readClassBytes(hiddenFields, nbHiddenFields); - staticLayout._vt = J3VirtualTable::create(&staticLayout); + staticLayout()->_vt = J3VirtualTable::create(staticLayout()); _vt = J3VirtualTable::create(this); @@ -522,16 +524,16 @@ void J3Class::readClassBytes(J3Field* hi } size_t n = nbHiddenFields + reader.readU2(), nbStaticFields = 0, nbVirtualFields = 0; - fields = (J3Field*)alloca(sizeof(J3Field)*n); + _fields = (J3Field*)alloca(sizeof(J3Field)*n); J3Field* pFields0[n]; size_t i0 = 0; /* sort fields by reverse size */ J3Field* pFields1[n]; size_t i1 = 0; J3Field* pFields2[n]; size_t i2 = 0; J3Field* pFields3[n]; size_t i3 = 0; - memset(fields, 0, sizeof(J3Field)*n); + memset(fields(), 0, sizeof(J3Field)*n); for(size_t i=0; i_access = hiddenFields[i].access(); @@ -546,7 +548,7 @@ void J3Class::readClassBytes(J3Field* hi } if(J3Cst::isStatic(f->access())) { - f->_layout = &staticLayout; + f->_layout = staticLayout(); nbStaticFields++; } else { f->_layout = this; @@ -562,8 +564,8 @@ void J3Class::readClassBytes(J3Field* hi } } - staticLayout.fields = new(loader()->allocator()) J3Field[nbStaticFields]; - fields = new(loader()->allocator()) J3Field[nbVirtualFields]; + staticLayout()->_fields = new(loader()->allocator()) J3Field[nbStaticFields]; + _fields = new(loader()->allocator()) J3Field[nbVirtualFields]; if(super() == this) _structSize = sizeof(J3Object); @@ -601,16 +603,18 @@ void J3Class::readClassBytes(J3Field* hi nbVirtualMethods++; } - staticLayout._methods = (J3Method**)loader()->allocator()->allocate(sizeof(J3Method*)*nbStaticMethods); + staticLayout()->_methods = (J3Method**)loader()->allocator()->allocate(sizeof(J3Method*)*nbStaticMethods); _methods = (J3Method**)loader()->allocator()->allocate(sizeof(J3Method*)*nbVirtualMethods); for(int i=0; iaccess())) - layout = &staticLayout; + layout = staticLayout(); else layout = this; layout->_methods[layout->_nbMethods++] = methodsTmp[i]; + if(J3Cst::isPublic(methodsTmp[i]->access())) + layout->_nbPublicMethods++; } _attributes = readAttributes(&reader); @@ -623,13 +627,16 @@ void J3Class::fillFields(J3Field** field if(J3Cst::isStatic(fields[i]->access())) { //fprintf(stderr, " adding static field: %ls %ls::%ls\n", cur->type()->name()->cStr(), name()->cStr(), cur->name()->cStr()); - layout = &staticLayout; + layout = staticLayout(); } else { layout = this; } cur->_offset = layout->structSize(); layout->_structSize += 1 << fields[i]->type()->logSize(); - layout->fields[layout->nbFields++] = *fields[i]; + layout->fields()[layout->_nbFields++] = *fields[i]; + + if(J3Cst::isPublic(fields[i]->access())) + layout->_nbPublicFields++; } } @@ -802,26 +809,6 @@ void J3Class::doNativeName() { loader()->addSymbol(_nativeName, this); } -void J3Field::dump() { - printf("Field: %ls %ls::%ls (%d)\n", type()->name()->cStr(), layout()->name()->cStr(), name()->cStr(), access()); -} - - -J3Attribute* J3Attributes::attribute(size_t n) { - if(n >= _nbAttributes) - J3::internalError(L"should not happen"); - return _attributes + n; -} - -J3Attribute* J3Attributes::lookup(const vmkit::Name* id) { - for(size_t i=0; i<_nbAttributes; i++) { - if(_attributes[i].id() == id) - return _attributes+i; - } - - return 0; -} - /* * ------------ J3ArrayClass ------------ */ Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=198260&r1=198259&r2=198260&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Tue Dec 31 02:16:09 2013 @@ -11,6 +11,8 @@ #include "j3/j3mangler.h" #include "j3/j3jni.h" #include "j3/j3object.h" +#include "j3/j3field.h" +#include "j3/j3attribute.h" #include "llvm/ExecutionEngine/ExecutionEngine.h" Added: vmkit/branches/mcjit/lib/j3/vm/j3field.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3field.cc?rev=198260&view=auto ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3field.cc (added) +++ vmkit/branches/mcjit/lib/j3/vm/j3field.cc Tue Dec 31 02:16:09 2013 @@ -0,0 +1,21 @@ +#include "j3/j3field.h" +#include "j3/j3class.h" +#include "j3/j3classloader.h" +#include "j3/j3.h" + +using namespace j3; + +J3ObjectHandle* J3Field::javaField() { + if(!_javaField) { + layout()->lock(); + _javaField = J3ObjectHandle::doNewObject(layout()->loader()->vm()->fieldClass); + J3::internalError(L"implement me: javaField"); + layout()->unlock(); + } + return _javaField; +} + +void J3Field::dump() { + printf("Field: %ls %ls::%ls (%d)\n", type()->name()->cStr(), layout()->name()->cStr(), name()->cStr(), access()); +} + Modified: vmkit/branches/mcjit/lib/j3/vm/j3object.cc URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3object.cc?rev=198260&r1=198259&r2=198260&view=diff ============================================================================== --- vmkit/branches/mcjit/lib/j3/vm/j3object.cc (original) +++ vmkit/branches/mcjit/lib/j3/vm/j3object.cc Tue Dec 31 02:16:09 2013 @@ -14,6 +14,7 @@ #include "j3/j3constants.h" #include "j3/j3thread.h" #include "j3/j3monitor.h" +#include "j3/j3field.h" using namespace j3; @@ -455,11 +456,11 @@ void J3ObjectHandle::rawArrayCopyTo(uint } void J3ObjectHandle::rawSetObject(uint32_t offset, J3ObjectHandle* value) { - *((J3Object**)((uintptr_t)obj() + offset)) = value->obj(); + *((J3Object**)((uintptr_t)obj() + offset)) = value ? value->obj() : 0; } J3ObjectHandle* J3ObjectHandle::rawGetObject(uint32_t offset) { - return J3Thread::get()->push(*((J3Object**)((uintptr_t)obj() + offset))); + return obj() ? J3Thread::get()->push(*((J3Object**)((uintptr_t)obj() + offset))) : 0; } void J3ObjectHandle::setObject(J3Field* field, J3ObjectHandle* value) {