[vmkit-commits] [vmkit] r198363 - a J3MethodType does not embedded the type of this anymore
Gael Thomas
gael.thomas at lip6.fr
Thu Jan 2 14:15:42 PST 2014
Author: gthomas
Date: Thu Jan 2 16:15:41 2014
New Revision: 198363
URL: http://llvm.org/viewvc/llvm-project?rev=198363&view=rev
Log:
a J3MethodType does not embedded the type of this anymore
Modified:
vmkit/branches/mcjit/include/j3/j3codegen.h
vmkit/branches/mcjit/include/j3/j3method.h
vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc
vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc
vmkit/branches/mcjit/lib/j3/vm/j3mangler.cc
vmkit/branches/mcjit/lib/j3/vm/j3method.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=198363&r1=198362&r2=198363&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3codegen.h (original)
+++ vmkit/branches/mcjit/include/j3/j3codegen.h Thu Jan 2 16:15:41 2014
@@ -81,7 +81,7 @@ namespace j3 {
uint32_t wideReadU1();
uint32_t wideReadS1();
- llvm::FunctionType* llvmFunctionType(J3MethodType* type);
+ llvm::FunctionType* llvmFunctionType(J3Method* method);
llvm::Function* buildFunction(J3Method* method, bool isStub=1);
llvm::Value* methodDescriptor(J3Method* method);
llvm::Value* typeDescriptor(J3ObjectType* objectType, llvm::Type* type);
@@ -127,7 +127,7 @@ namespace j3 {
void putField(uint32_t idx);
void putStatic(uint32_t idx);
- void invoke(J3Method* method, llvm::Value* func);
+ void invoke(uint32_t access, J3Method* method, llvm::Value* func);
void invokeVirtual(uint32_t idx);
void invokeStatic(uint32_t idx);
void invokeSpecial(uint32_t idx);
Modified: vmkit/branches/mcjit/include/j3/j3method.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3method.h?rev=198363&r1=198362&r2=198363&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3method.h (original)
+++ vmkit/branches/mcjit/include/j3/j3method.h Thu Jan 2 16:15:41 2014
@@ -36,8 +36,8 @@ namespace j3 {
void setLLVMSignature(J3LLVMSignature* llvmSignature) { _llvmSignature = llvmSignature; }
J3LLVMSignature* llvmSignature() { return _llvmSignature; }
- uint32_t nbIns() { return _nbIns; }
J3Type* out() { return _out; }
+ uint32_t nbIns() { return _nbIns; }
J3Type* ins(uint32_t idx) { return _ins[idx]; }
void* operator new(size_t unused, vmkit::BumpAllocator* allocator, size_t n) {
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=198363&r1=198362&r2=198363&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc (original)
+++ vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc Thu Jan 2 16:15:41 2014
@@ -48,6 +48,7 @@ jobject JNICALL JVM_Clone(JNIEnv* env, j
enterJVM();
res = obj->vt()->type()->asObjectType()->clone(obj);
leaveJVM();
+ NYI();
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=198363&r1=198362&r2=198363&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Thu Jan 2 16:15:41 2014
@@ -187,13 +187,19 @@ llvm::Value* J3CodeGen::unflatten(llvm::
}
}
-llvm::FunctionType* J3CodeGen::llvmFunctionType(J3MethodType* type) {
+llvm::FunctionType* J3CodeGen::llvmFunctionType(J3Method* method) {
+ J3MethodType* type = method->methodType(cl);
J3LLVMSignature* res = type->llvmSignature();
if(!res) {
std::vector<llvm::Type*> in;
+
+ if(!J3Cst::isStatic(method->access()))
+ in.push_back(vm->typeJ3ObjectPtr);
+
for(uint32_t i=0; i<type->nbIns(); i++)
in.push_back(type->ins(i)->llvmType());
+
llvm::FunctionType* funcType = llvm::FunctionType::get(type->out()->llvmType(), in, 0);
res = vm->llvmSignatures[funcType];
if(!res)
@@ -205,7 +211,7 @@ llvm::FunctionType* J3CodeGen::llvmFunct
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)));
+ return (llvm::Function*)module->getOrInsertFunction(id, llvmFunctionType(method));
}
llvm::Value* J3CodeGen::typeDescriptor(J3ObjectType* objectType, llvm::Type* type) {
@@ -381,14 +387,20 @@ llvm::Value* J3CodeGen::nullCheck(llvm::
#define nyi() J3::internalError("not yet implemented: '%s' (%d)", J3Cst::opcodeNames[bc], bc);
-void J3CodeGen::invoke(J3Method* target, llvm::Value* func) {
+void J3CodeGen::invoke(uint32_t access, J3Method* target, llvm::Value* func) {
J3MethodType* type = target->methodType(cl);
std::vector<llvm::Value*> args;
+ uint32_t d = 0;
+
+ if(!J3Cst::isStatic(access)) {
+ args.push_back(unflatten(stack.top(type->nbIns()), target->cl()));
+ d = 1;
+ }
for(uint32_t i=0; i<type->nbIns(); i++)
args.push_back(unflatten(stack.top(type->nbIns() - i - 1), type->ins(i)));
- stack.drop(type->nbIns());
+ stack.drop(d + type->nbIns());
llvm::Value* res;
@@ -415,14 +427,14 @@ void J3CodeGen::invokeInterface(uint32_t
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* obj = nullCheck(stack.top(type->nbIns()));
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)),
- llvmFunctionType(type)->getPointerTo());
+ llvmFunctionType(target)->getPointerTo());
- invoke(target, func);
+ invoke(0, target, func);
}
void J3CodeGen::invokeVirtual(uint32_t idx) {
@@ -435,33 +447,33 @@ void J3CodeGen::invokeVirtual(uint32_t i
else
funcEntry = builder->CreateCall(funcJ3MethodIndex, methodDescriptor(target));
- llvm::Value* obj = nullCheck(stack.top(type->nbIns() - 1));
+ llvm::Value* obj = nullCheck(stack.top(type->nbIns()));
llvm::Value* gepFunc[] = { builder->getInt32(0),
builder->getInt32(J3VirtualTable::gepVirtualMethods),
funcEntry };
llvm::Value* func = builder->CreateBitCast(builder->CreateLoad(builder->CreateGEP(vt(obj), gepFunc)),
- llvmFunctionType(type)->getPointerTo());
-
+ llvmFunctionType(target)->getPointerTo());
+ char buf[65536]; snprintf(buf, 65536, "%s::%s%s", target->cl()->name()->cStr(), target->name()->cStr(), target->sign()->cStr());
builder->CreateCall5(funcEchoDebugExecute,
builder->getInt32(2),
- buildString("Invoking %p::%d %p\n"),
+ buildString("Invoking %s %p::%d\n"),
+ buildString(buf),
vt(obj),
- funcEntry,
- func);
+ funcEntry);
- invoke(target, func);
+ invoke(0, target, func);
}
void J3CodeGen::invokeStatic(uint32_t idx) {
J3Method* target = cl->methodAt(idx, J3Cst::ACC_STATIC);
initialiseJ3ObjectType(target->cl());
- invoke(target, buildFunction(target));
+ invoke(J3Cst::ACC_STATIC, target, buildFunction(target));
}
void J3CodeGen::invokeSpecial(uint32_t idx) {
J3Method* target = cl->methodAt(idx, 0);
- invoke(target, buildFunction(target));
+ invoke(0, target, buildFunction(target));
}
llvm::Value* J3CodeGen::fieldOffset(llvm::Value* obj, J3Field* f) {
@@ -1600,8 +1612,14 @@ void J3CodeGen::generateJava() {
}
uint32_t n=0, pos=0;
- for(llvm::Function::arg_iterator cur=llvmFunction->arg_begin(); cur!=llvmFunction->arg_end(); cur++, n++) {
- J3Type* type = methodType->ins(n);
+ for(llvm::Function::arg_iterator cur=llvmFunction->arg_begin(); cur!=llvmFunction->arg_end(); cur++) {
+ J3Type* type;
+
+ if(!pos && !J3Cst::isStatic(method->access()))
+ type = method->cl();
+ else
+ type = methodType->ins(n++);
+
locals.setAt(flatten(cur, type), pos);
if(vm->options()->debugExecute)
@@ -1696,6 +1714,8 @@ llvm::Function* J3CodeGen::lookupNative(
if(J3Cst::isStatic(method->access()))
nativeIns.push_back(doNativeType(vm->classClass));
+ else
+ nativeIns.push_back(vm->typeJ3ObjectHandlePtr);
for(int i=0; i<methodType->nbIns(); i++)
nativeIns.push_back(doNativeType(methodType->ins(i)));
@@ -1735,19 +1755,23 @@ void J3CodeGen::generateNative() {
args.push_back(builder->CreateCall(funcJniEnv));
if(J3Cst::isStatic(method->access()))
- args.push_back(builder->CreateCall2(funcJ3ThreadPushHandle, thread, javaClass(cl))); /* avoid harakiri */
+ args.push_back(builder->CreateCall2(funcJ3ThreadPushHandle, thread, javaClass(cl)));
- if(methodType->nbIns()) {
- uint32_t i = 0;
+ uint32_t i = 0, selfDone = 0;
- for(llvm::Function::arg_iterator cur=llvmFunction->arg_begin(); cur!=llvmFunction->arg_end(); cur++, i++) {
- llvm::Value* a;
+ for(llvm::Function::arg_iterator cur=llvmFunction->arg_begin(); cur!=llvmFunction->arg_end(); cur++) {
+ llvm::Value* a;
+ if(!selfDone && !J3Cst::isStatic(method->access())) {
+ selfDone = 1;
+ a = builder->CreateCall2(funcJ3ThreadPush, thread, flatten(cur, method->cl()));
+ } else {
if(methodType->ins(i)->llvmType()->isPointerTy())
a = builder->CreateCall2(funcJ3ThreadPush, thread, flatten(cur, methodType->ins(i)));
else
a = cur;
- args.push_back(a);
+ i++;
}
+ args.push_back(a);
}
res = builder->CreateCall(nat, args);
Modified: vmkit/branches/mcjit/lib/j3/vm/j3mangler.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3mangler.cc?rev=198363&r1=198362&r2=198363&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3mangler.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3mangler.cc Thu Jan 2 16:15:41 2014
@@ -48,6 +48,7 @@ J3Mangler* J3Mangler::mangle(J3Method* m
memcpy(cur, method->cl()->nativeName() + 1, method->cl()->nativeNameLength() - 3);
*next = '_';
cur = next+1;
+
mangle(method->name());
return this;
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=198363&r1=198362&r2=198363&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3method.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3method.cc Thu Jan 2 16:15:41 2014
@@ -134,44 +134,44 @@ J3Value J3Method::internalInvoke(bool st
J3Value J3Method::internalInvoke(bool statically, J3ObjectHandle* handle, J3Value* inArgs) {
J3Value* reIn;
if(handle) {
- reIn = (J3Value*)alloca(methodType()->nbIns()*sizeof(J3Value));
+ reIn = (J3Value*)alloca((methodType()->nbIns()+1)*sizeof(J3Value));
reIn[0].valObject = handle;
- memcpy(reIn+1, inArgs, (methodType()->nbIns() - 1)*sizeof(J3Value));
+ memcpy(reIn+1, inArgs, methodType()->nbIns()*sizeof(J3Value));
} else
reIn = inArgs;
return internalInvoke(statically, reIn);
}
J3Value J3Method::internalInvoke(bool statically, J3ObjectHandle* handle, va_list va) {
- J3Value* args = (J3Value*)alloca(sizeof(J3Value)*methodType()->nbIns());
+ J3Value* args = (J3Value*)alloca(sizeof(J3Value)*(methodType()->nbIns() + 1));
J3* vm = cl()->loader()->vm();
J3Type* cur;
- uint32_t i = 0;
+ uint32_t d = 0;
if(handle)
- args[i++].valObject = handle;
+ args[d++].valObject = handle;
- for(; i<methodType()->nbIns(); i++) {
+ for(uint32_t i=0; i<methodType()->nbIns(); 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, args);
@@ -235,9 +235,6 @@ J3MethodType* J3Method::methodType(J3Cla
if(sign()->cStr()[0] != J3Cst::ID_Left)
loader->wrongType(from, sign());
- if(!J3Cst::isStatic(access()))
- args[nbArgs++] = cl();
-
while(sign()->cStr()[cur] != J3Cst::ID_Right) {
args[nbArgs++] = loader->getTypeInternal(from, sign(), cur, &cur);
}
@@ -305,17 +302,11 @@ J3ObjectHandle* J3Method::javaMethod() {
J3* vm = cl()->loader()->vm();
uint32_t nbIns = methodType()->nbIns();
- uint32_t d = 0;
-
- if(!J3Cst::isStatic(access())) {
- nbIns--;
- d = 1;
- }
J3ObjectHandle* parameters = J3ObjectHandle::doNewArray(vm->classClass->getArray(), nbIns);
for(uint32_t i=0; i<nbIns; i++)
- parameters->setObjectAt(i, methodType()->ins(i+d)->javaClass());
+ parameters->setObjectAt(i, methodType()->ins(i)->javaClass());
J3Attribute* exceptionAttribute = attributes()->lookup(vm->exceptionsAttribute);
J3ObjectHandle* exceptions;
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=198363&r1=198362&r2=198363&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3options.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3options.cc Thu Jan 2 16:15:41 2014
@@ -15,7 +15,7 @@ J3Options::J3Options() {
debugEnterIndent = 1;
- debugExecute = 2;
+ debugExecute = 0;
debugLoad = 0;
debugResolve = 0;
debugIniting = 0;
More information about the vmkit-commits
mailing list