[vmkit-commits] [vmkit] r95521 - in /vmkit/trunk/lib/J3: Compiler/JavaJIT.cpp LLVMRuntime/runtime-default.ll VMCore/JavaRuntimeJIT.cpp VMCore/JavaThread.cpp VMCore/JavaThread.h VMCore/Jni.cpp
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Sun Feb 7 05:41:57 PST 2010
Author: geoffray
Date: Sun Feb 7 07:41:57 2010
New Revision: 95521
URL: http://llvm.org/viewvc/llvm-project?rev=95521&view=rev
Log:
Correctly handle JNI exceptions: we have been living with JNI exceptions
going back to Java for so long, I wonder how we were able to run all these
applications :).
Modified:
vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp
vmkit/trunk/lib/J3/LLVMRuntime/runtime-default.ll
vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp
vmkit/trunk/lib/J3/VMCore/JavaThread.cpp
vmkit/trunk/lib/J3/VMCore/JavaThread.h
vmkit/trunk/lib/J3/VMCore/Jni.cpp
Modified: vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp?rev=95521&r1=95520&r2=95521&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp Sun Feb 7 07:41:57 2010
@@ -285,13 +285,12 @@
currentExceptionBlock = endExceptionBlock = 0;
currentBlock = createBasicBlock("start");
- BasicBlock* executeBlock = createBasicBlock("execute");
endBlock = createBasicBlock("end block");
- Constant* sizeB = ConstantInt::get(Type::getInt32Ty(getGlobalContext()), sizeof(jmp_buf));
- Value* oldJB = new AllocaInst(module->ptrType, "", currentBlock);
- Value* newJB = new AllocaInst(Type::getInt8Ty(getGlobalContext()), sizeB, "", currentBlock);
-
+ if (returnType != Type::getVoidTy(getGlobalContext())) {
+ endNode = PHINode::Create(returnType, "", endBlock);
+ }
+
// Allocate currentLocalIndexNumber pointer
Value* temp = new AllocaInst(Type::getInt32Ty(getGlobalContext()), "",
currentBlock);
@@ -308,22 +307,6 @@
if (isSynchro(compilingMethod->access))
beginSynchronize();
- Value* test = CallInst::Create(module->setjmpLLVM, newJB, "",
- currentBlock);
-
- test = new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, test,
- module->constantZero, "");
- BranchInst::Create(executeBlock, endBlock, test, currentBlock);
-
- if (returnType != Type::getVoidTy(getGlobalContext())) {
- endNode = PHINode::Create(returnType, "", endBlock);
- endNode->addIncoming(Constant::getNullValue(returnType),
- currentBlock);
- }
-
- currentBlock = executeBlock;
-
-
uint32 nargs = func->arg_size() + 1 + (stat ? 1 : 0);
std::vector<Value*> nativeArgs;
@@ -363,8 +346,8 @@
const Type* Ty = PointerType::getUnqual(module->JavaObjectType);
PHINode* node = PHINode::Create(Ty, "", BB);
- test = new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, i,
- module->JavaObjectNullConstant, "");
+ Value* test = new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, i,
+ module->JavaObjectNullConstant, "");
node->addIncoming(Constant::getNullValue(Ty), currentBlock);
BranchInst::Create(BB, NotZero, test, currentBlock);
@@ -446,9 +429,9 @@
nativeFunc = node;
}
- Value* Args4[5] = { temp, oldCLIN, newJB, oldJB, Frame };
+ Value* Args4[3] = { temp, oldCLIN, Frame };
- CallInst::Create(module->StartJNIFunction, Args4, Args4 + 5, "",
+ CallInst::Create(module->StartJNIFunction, Args4, Args4 + 3, "",
currentBlock);
@@ -490,9 +473,9 @@
currentBlock = endBlock;
- Value* Args2[2] = { oldCLIN, oldJB };
+ Value* Args2[1] = { oldCLIN };
- CallInst::Create(module->EndJNIFunction, Args2, Args2 + 2, "", currentBlock);
+ CallInst::Create(module->EndJNIFunction, Args2, Args2 + 1, "", currentBlock);
// Synchronize after leaving native.
if (isSynchro(compilingMethod->access))
Modified: vmkit/trunk/lib/J3/LLVMRuntime/runtime-default.ll
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/LLVMRuntime/runtime-default.ll?rev=95521&r1=95520&r2=95521&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/LLVMRuntime/runtime-default.ll (original)
+++ vmkit/trunk/lib/J3/LLVMRuntime/runtime-default.ll Sun Feb 7 07:41:57 2010
@@ -211,8 +211,8 @@
declare void @j3ThrowException(%JavaObject*)
declare void @j3ThrowExceptionFromJIT()
-declare void @j3EndJNI(i32**, i8**)
-declare void @j3StartJNI(i32*, i32**, i8*, i8**, i8*)
+declare void @j3EndJNI(i32**)
+declare void @j3StartJNI(i32*, i32**, i8*)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Modified: vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp?rev=95521&r1=95520&r2=95521&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp Sun Feb 7 07:41:57 2010
@@ -327,15 +327,12 @@
}
// Does not call Java code. Can not yield a GC.
-extern "C" void j3EndJNI(uint32** oldLRN, void** oldBuffer) {
+extern "C" void j3EndJNI(uint32** oldLRN) {
JavaThread* th = JavaThread::get();
// We're going back to Java
th->endJNI();
- // Update the buffer.
- th->currentSjljBuffer = *oldBuffer;
-
// Update the number of references.
th->currentAddedReferences = *oldLRN;
@@ -344,21 +341,16 @@
extern "C" void* j3StartJNI(uint32* localReferencesNumber,
uint32** oldLocalReferencesNumber,
- void* newBuffer, void** oldBuffer,
mvm::KnownFrame* Frame)
__attribute__((noinline));
// Never throws. Does not call Java code. Can not yied a GC.
extern "C" void* j3StartJNI(uint32* localReferencesNumber,
- uint32** oldLocalReferencesNumber,
- void* newBuffer, void** oldBuffer,
- mvm::KnownFrame* Frame) {
+ uint32** oldLocalReferencesNumber,
+ mvm::KnownFrame* Frame) {
JavaThread* th = JavaThread::get();
- *oldBuffer = th->currentSjljBuffer;
- th->currentSjljBuffer = newBuffer;
-
*oldLocalReferencesNumber = th->currentAddedReferences;
th->currentAddedReferences = localReferencesNumber;
th->startKnownFrame(*Frame);
Modified: vmkit/trunk/lib/J3/VMCore/JavaThread.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaThread.cpp?rev=95521&r1=95520&r2=95521&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaThread.cpp (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaThread.cpp Sun Feb 7 07:41:57 2010
@@ -38,7 +38,6 @@
jniEnv = isolate->jniEnv;
localJNIRefs = new JNILocalReferences();
currentAddedReferences = 0;
- currentSjljBuffer = 0;
#ifdef SERVICE
eipIndex = 0;
Modified: vmkit/trunk/lib/J3/VMCore/JavaThread.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaThread.h?rev=95521&r1=95520&r2=95521&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaThread.h (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaThread.h Sun Feb 7 07:41:57 2010
@@ -10,8 +10,6 @@
#ifndef JNJVM_JAVA_THREAD_H
#define JNJVM_JAVA_THREAD_H
-#include <csetjmp>
-
#include "mvm/Object.h"
#include "mvm/Threads/Cond.h"
#include "mvm/Threads/Locks.h"
@@ -118,12 +116,6 @@
/// state - The current state of this thread: Running, Waiting or Interrupted.
uint32 state;
- /// currentSjljBuffers - Current buffer pushed when entering a non-JVM native
- /// function and popped when leaving the function. The buffer is used when
- /// the native function throws an exception through a JNI throwException call.
- ///
- void* currentSjljBuffer;
-
/// currentAddedReferences - Current number of added local references.
///
uint32_t* currentAddedReferences;
@@ -196,15 +188,8 @@
/// throwFromJNI - Throw an exception after executing JNI code.
///
void throwFromJNI(void* SP) {
- assert(currentSjljBuffer);
endKnownFrame();
enterUncooperativeCode(SP);
- internalPendingException = 0;
-#if defined(__MACH__)
- longjmp((int*)currentSjljBuffer, 1);
-#else
- longjmp((__jmp_buf_tag*)currentSjljBuffer, 1);
-#endif
}
/// throwFromNative - Throw an exception after executing Native code.
Modified: vmkit/trunk/lib/J3/VMCore/Jni.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/Jni.cpp?rev=95521&r1=95520&r2=95521&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/Jni.cpp (original)
+++ vmkit/trunk/lib/J3/VMCore/Jni.cpp Sun Feb 7 07:41:57 2010
@@ -171,8 +171,6 @@
init->invokeIntSpecial(vm, realCl, res, &str);
th->pendingException = res;
- th->throwFromJNI(SP);
-
RETURN_FROM_JNI(1);
END_JNI_EXCEPTION
@@ -187,6 +185,7 @@
JavaObject* obj = JavaThread::get()->pendingException;
llvm_gcroot(obj, 0);
+ if (obj == NULL) RETURN_FROM_JNI(NULL);
jthrowable res = (jthrowable)th->pushJNIRef(obj);
RETURN_FROM_JNI(res);
More information about the vmkit-commits
mailing list