[vmkit-commits] [vmkit] r198112 - Inline Thread::get() in the generated code
Gael Thomas
gael.thomas at lip6.fr
Sat Dec 28 03:03:10 PST 2013
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) {
More information about the vmkit-commits
mailing list