[vmkit-commits] [vmkit] r197889 - use the new trampoline builder
Gael Thomas
gael.thomas at lip6.fr
Sun Dec 22 12:55:36 PST 2013
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<J3Method*, J3Method*>::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<llvm::GenericValue> 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
*/
More information about the vmkit-commits
mailing list