[vmkit-commits] [vmkit] r199545 - Fix a bug in J3Object::clone (I was casting the object as an array...)
Gael Thomas
gael.thomas at lip6.fr
Sat Jan 18 04:38:17 PST 2014
Author: gthomas
Date: Sat Jan 18 06:38:16 2014
New Revision: 199545
URL: http://llvm.org/viewvc/llvm-project?rev=199545&view=rev
Log:
Fix a bug in J3Object::clone (I was casting the object as an array...)
Implements uncaughtException
Modified:
vmkit/branches/mcjit/include/j3/j3.h
vmkit/branches/mcjit/include/j3/j3object.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/j3codegen-debug.cc
vmkit/branches/mcjit/lib/j3/vm/j3codegenexception.cc
vmkit/branches/mcjit/lib/j3/vm/j3object.cc
vmkit/branches/mcjit/lib/j3/vm/j3thread.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=199545&r1=199544&r2=199545&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3.h (original)
+++ vmkit/branches/mcjit/include/j3/j3.h Sat Jan 18 06:38:16 2014
@@ -164,6 +164,7 @@ namespace j3 {
static void illegalArgumentException(const char* msg) __attribute__((noreturn));
void printStackTrace();
+ void uncatchedException(void* e);
void forceSymbolDefinition();
};
Modified: vmkit/branches/mcjit/include/j3/j3object.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3object.h?rev=199545&r1=199544&r2=199545&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3object.h (original)
+++ vmkit/branches/mcjit/include/j3/j3object.h Sat Jan 18 06:38:16 2014
@@ -44,7 +44,7 @@ namespace j3 {
friend class J3Trampoline;
public:
- static const uint32_t nbInterfaceMethodTable = 43;
+ static const uint32_t nbInterfaceMethodTable = 173;
static const uint32_t gepObjectClass = 0;
static const uint32_t gepInterfaceMethods = 2;
static const uint32_t gepVirtualMethods = 4;
Modified: vmkit/branches/mcjit/include/vmkit/vmkit.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/vmkit.h?rev=199545&r1=199544&r2=199545&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/vmkit/vmkit.h (original)
+++ vmkit/branches/mcjit/include/vmkit/vmkit.h Sat Jan 18 06:38:16 2014
@@ -67,7 +67,8 @@ namespace vmkit {
virtual void vinternalError(const char* msg, va_list va) __attribute__((noreturn));
virtual void sigsegv(uintptr_t addr) __attribute__((noreturn));
virtual void sigend() __attribute__((noreturn));
- virtual void printStackTrace() = 0;
+ virtual void printStackTrace();
+ virtual void uncatchedException(void* e);
static void internalError(const char* 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=199545&r1=199544&r2=199545&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3.cc Sat Jan 18 06:38:16 2014
@@ -334,6 +334,33 @@ void J3::printStackTrace() {
}
}
+void J3::uncatchedException(void* e) {
+ J3Thread* thread = J3Thread::get();
+ J3ObjectHandle* prev = thread->tell();
+
+ try {
+ J3ObjectHandle* excp = thread->push((J3Object*)e);
+
+ J3ObjectHandle* handler =
+ thread->javaThread()->vt()->type()->asObjectType()
+ ->findMethod(0,
+ names()->get("getUncaughtExceptionHandler"),
+ initialClassLoader->getSignature(0, names()->get("()Ljava/lang/Thread$UncaughtExceptionHandler;")))
+ ->invokeVirtual(thread->javaThread())
+ .valObject;
+
+ handler->vt()->type()->asObjectType()
+ ->findMethod(0,
+ names()->get("uncaughtException"),
+ initialClassLoader->getSignature(0, names()->get("(Ljava/lang/Thread;Ljava/lang/Throwable;)V")))
+ ->invokeVirtual(handler, thread->javaThread(), excp);
+
+ } catch(void* e2) {
+ fprintf(stderr, "Fatal: double exception %p and %p\n", e, e2);
+ }
+ thread->restore(prev);
+}
+
void J3::forceSymbolDefinition() {
J3ArrayObject a; a.length(); /* J3ArrayObject */
J3LockRecord* l = new J3LockRecord(); /* J3LockRecord */
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=199545&r1=199544&r2=199545&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3class.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3class.cc Sat Jan 18 06:38:16 2014
@@ -330,6 +330,7 @@ uint16_t J3Class::modifiers() {
}
J3ObjectHandle* J3Class::clone(J3ObjectHandle* obj) {
+ //fprintf(stderr, " cloning %p with %lu bytes\n", obj->obj(), structSize());
J3ObjectHandle* res = J3ObjectHandle::doNewObject(this);
obj->rawObjectCopyTo(0, res, 0, structSize() - sizeof(J3Object));
return res;
Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen-debug.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen-debug.cc?rev=199545&r1=199544&r2=199545&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3codegen-debug.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3codegen-debug.cc Sat Jan 18 06:38:16 2014
@@ -76,6 +76,8 @@ void J3CodeGen::echoElement(uint32_t lev
J3* vm = J3Thread::get()->vm();
J3ObjectHandle* prev = J3Thread::get()->tell();
J3ObjectHandle* content = 0;
+
+ fprintf(stderr, " %p - ", pobj);
if(pobj->vt()->type() == vm->typeCharacter->getArray())
content = J3Thread::get()->push(pobj);
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=199545&r1=199544&r2=199545&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3codegenexception.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3codegenexception.cc Sat Jan 18 06:38:16 2014
@@ -29,11 +29,13 @@ void J3ExceptionNode::addEntry(J3CodeGen
caughtResult->addClause(codeGen->gvTypeInfo);
-#if 0
- codeGen->builder->CreateCall2(codeGen->funcEchoDebugExecute,
- codeGen->builder->getInt32(-1), /* just to see my first exception :) */
- codeGen->buildString("catching exception!\n"));
-#endif
+ if(codeGen->vm->options()->debugExecute) {
+ char buf[256];
+ snprintf(buf, 256, " catching exceptions in %s::%s", codeGen->cl->name()->cStr(), codeGen->method->name()->cStr());
+ codeGen->builder->CreateCall2(codeGen->funcEchoDebugExecute,
+ codeGen->builder->getInt32(1),
+ codeGen->buildString(buf));
+ }
llvm::Value* excp = codeGen->builder->CreateBitCast(codeGen->builder->CreateCall(codeGen->funcCXABeginCatch,
codeGen->builder->CreateExtractValue(caughtResult, 0)),
@@ -68,11 +70,16 @@ void J3ExceptionNode::addEntry(J3CodeGen
void J3ExceptionNode::close(J3CodeGen* codeGen) {
if(curCheck) {
codeGen->builder->SetInsertPoint(curCheck);
-#if 0
- codeGen->builder->CreateCall2(codeGen->funcEchoDebugExecute,
- codeGen->builder->getInt32(-1),
- codeGen->buildString(" not catched here, rethrow\n"));
-#endif
+
+ if(codeGen->vm->options()->debugExecute) {
+ char buf[256];
+ snprintf(buf, 256, " exceptions not catched in %s::%s, rethrowing",
+ codeGen->cl->name()->cStr(), codeGen->method->name()->cStr());
+ codeGen->builder->CreateCall2(codeGen->funcEchoDebugExecute,
+ codeGen->builder->getInt32(1),
+ codeGen->buildString(buf));
+ }
+
codeGen->stack.metaStack[0] = codeGen->vm->typeJ3ObjectPtr;
codeGen->stack.topStack = 1;
codeGen->builder->CreateCall(codeGen->funcThrowException,
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=199545&r1=199544&r2=199545&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3object.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3object.cc Sat Jan 18 06:38:16 2014
@@ -513,9 +513,9 @@ J3ObjectHandle* J3ObjectHandle::getObjec
void J3ObjectHandle::rawObjectCopyTo(uint32_t fromOffset, J3ObjectHandle* to, uint32_t toOffset, uint32_t nbb) {
if(isSame(to))
- memmove((uint8_t*)(to->obj()+1) + toOffset, (uint8_t*)(array()+1) + fromOffset, nbb);
+ memmove((uint8_t*)(to->obj()+1) + toOffset, (uint8_t*)(obj()+1) + fromOffset, nbb);
else
- memcpy((uint8_t*)(to->obj()+1) + toOffset, (uint8_t*)(array()+1) + fromOffset, nbb);
+ memcpy((uint8_t*)(to->obj()+1) + toOffset, (uint8_t*)(obj()+1) + fromOffset, nbb);
}
void J3ObjectHandle::rawArrayCopyTo(uint32_t fromOffset, J3ObjectHandle* to, uint32_t toOffset, uint32_t nbb) {
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=199545&r1=199544&r2=199545&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3thread.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3thread.cc Sat Jan 18 06:38:16 2014
@@ -20,11 +20,6 @@ J3Thread::~J3Thread() {
vmkit::BumpAllocator::destroy(_allocator);
}
-void J3Thread::doRun() {
- J3ObjectHandle* handle = get()->javaThread();
- get()->vm()->threadClassRun->invokeVirtual(handle);
-}
-
void J3Thread::run() {
J3ObjectHandle* handle = javaThread();
vm()->threadClassRun->invokeVirtual(handle);
Modified: vmkit/branches/mcjit/lib/vmkit/thread.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/thread.cc?rev=199545&r1=199544&r2=199545&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/vmkit/thread.cc (original)
+++ vmkit/branches/mcjit/lib/vmkit/thread.cc Sat Jan 18 06:38:16 2014
@@ -66,7 +66,11 @@ void* Thread::doRun(void* _thread) {
thread->registerSignalInternal(SIGSEGV, sigsegvHandler, 1);
thread->registerSignalInternal(SIGBUS, sigsegvHandler, 1);
- thread->run();
+ try {
+ thread->run();
+ } catch(void* e) {
+ thread->vm()->uncatchedException(e);
+ }
return 0;
}
Modified: vmkit/branches/mcjit/lib/vmkit/vmkit.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/vmkit.cc?rev=199545&r1=199544&r2=199545&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/vmkit/vmkit.cc (original)
+++ vmkit/branches/mcjit/lib/vmkit/vmkit.cc Sat Jan 18 06:38:16 2014
@@ -189,3 +189,11 @@ void VMKit::throwException(void* obj) {
//Thread::get()->vm()->printStackTrace();
throw obj;
}
+
+void VMKit::printStackTrace() {
+ fprintf(stderr, " TODO: baseline printStackTrace\n");
+}
+
+void VMKit::uncatchedException(void* e) {
+ fprintf(stderr, "Uncatched exception: %p\n", e);
+}
More information about the vmkit-commits
mailing list