[vmkit-commits] [vmkit] r142979 - in /vmkit/trunk: include/mvm/JIT.h lib/J3/ClassLib/GNUClasspath/ClasspathVMClass.inc lib/J3/ClassLib/GNUClasspath/ClasspathVMSystem.inc lib/J3/Compiler/JavaJIT.cpp lib/J3/Compiler/JavaJIT.h lib/J3/Compiler/JavaJITCompiler.cpp lib/J3/Compiler/JavaJITOpcodes.cpp lib/J3/LLVMRuntime/runtime-default.ll lib/J3/VMCore/JavaRuntimeJIT.cpp lib/J3/VMCore/JavaThread.h lib/Mvm/Compiler/JIT.cpp lib/Mvm/Compiler/LLVMRuntime.ll lib/Mvm/Runtime/Object.cpp

Nicolas Geoffray nicolas.geoffray at lip6.fr
Tue Oct 25 15:22:54 PDT 2011


Author: geoffray
Date: Tue Oct 25 17:22:54 2011
New Revision: 142979

URL: http://llvm.org/viewvc/llvm-project?rev=142979&view=rev
Log:
New exception model: use setjm[/longjmp in Java code and remove exception check after each call. Now only if you do try/cat you pay the price of exceptions.


Modified:
    vmkit/trunk/include/mvm/JIT.h
    vmkit/trunk/lib/J3/ClassLib/GNUClasspath/ClasspathVMClass.inc
    vmkit/trunk/lib/J3/ClassLib/GNUClasspath/ClasspathVMSystem.inc
    vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp
    vmkit/trunk/lib/J3/Compiler/JavaJIT.h
    vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp
    vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp
    vmkit/trunk/lib/J3/LLVMRuntime/runtime-default.ll
    vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp
    vmkit/trunk/lib/J3/VMCore/JavaThread.h
    vmkit/trunk/lib/Mvm/Compiler/JIT.cpp
    vmkit/trunk/lib/Mvm/Compiler/LLVMRuntime.ll
    vmkit/trunk/lib/Mvm/Runtime/Object.cpp

Modified: vmkit/trunk/include/mvm/JIT.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/JIT.h?rev=142979&r1=142978&r2=142979&view=diff
==============================================================================
--- vmkit/trunk/include/mvm/JIT.h (original)
+++ vmkit/trunk/include/mvm/JIT.h Tue Oct 25 17:22:54 2011
@@ -112,6 +112,10 @@
   llvm::Function* FieldWriteBarrierFunction;
   llvm::Function* NonHeapWriteBarrierFunction;
 
+  llvm::Function* SetjmpFunction;
+  llvm::Function* RegisterSetjmpFunction;
+  llvm::Function* UnregisterSetjmpFunction;
+
   llvm::Constant* constantInt8Zero;
   llvm::Constant* constantZero;
   llvm::Constant* constantOne;

Modified: vmkit/trunk/lib/J3/ClassLib/GNUClasspath/ClasspathVMClass.inc
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/ClassLib/GNUClasspath/ClasspathVMClass.inc?rev=142979&r1=142978&r2=142979&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/ClassLib/GNUClasspath/ClasspathVMClass.inc (original)
+++ vmkit/trunk/lib/J3/ClassLib/GNUClasspath/ClasspathVMClass.inc Tue Oct 25 17:22:54 2011
@@ -593,7 +593,7 @@
   llvm_gcroot(throwable, 0);
 
   assert(throwable && "Using internal VM throw exception without exception");
-  JavaThread::get()->pendingException = (JavaObject*)throwable;
+  JavaThread::get()->throwException(throwable);
 }
 
 JNIEXPORT ArrayObject* Java_java_lang_VMClass_getDeclaredAnnotations(

Modified: vmkit/trunk/lib/J3/ClassLib/GNUClasspath/ClasspathVMSystem.inc
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/ClassLib/GNUClasspath/ClasspathVMSystem.inc?rev=142979&r1=142978&r2=142979&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/ClassLib/GNUClasspath/ClasspathVMSystem.inc (original)
+++ vmkit/trunk/lib/J3/ClassLib/GNUClasspath/ClasspathVMSystem.inc Tue Oct 25 17:22:54 2011
@@ -42,15 +42,15 @@
   Jnjvm *vm = th->getJVM();
 
   if (src == NULL || dst == NULL) {
-    th->pendingException = vm->CreateNullPointerException();
-    return;
+    th->throwException(vm->CreateNullPointerException());
+    UNREACHABLE();
   }
   
   if (!(JavaObject::getClass(src)->isArray() &&
         JavaObject::getClass(dst)->isArray())) {
-    th->pendingException = vm->CreateArrayStoreException(
-      (JavaVirtualTable*)dst->getVirtualTable());
-    return;
+    th->throwException(vm->CreateArrayStoreException(
+      (JavaVirtualTable*)dst->getVirtualTable()));
+    UNREACHABLE();
   }
   
   UserClassArray* ts = (UserClassArray*)JavaObject::getClass(src);
@@ -62,33 +62,32 @@
   sint32 dstSize = JavaArray::getSize(dst);
 
   if (len > srcSize) {
-    th->pendingException = vm->CreateIndexOutOfBoundsException(len);
+    th->throwException(vm->CreateIndexOutOfBoundsException(len));
   } else if (len > dstSize) {
-    th->pendingException = vm->CreateIndexOutOfBoundsException(len);
+    th->throwException(vm->CreateIndexOutOfBoundsException(len));
   } else if (len + sstart > srcSize) {
-    th->pendingException = vm->CreateIndexOutOfBoundsException(len + sstart);
+    th->throwException(vm->CreateIndexOutOfBoundsException(len + sstart));
   } else if (len + dstart > dstSize) {
-    th->pendingException = vm->CreateIndexOutOfBoundsException(len + dstart);
+    th->throwException(vm->CreateIndexOutOfBoundsException(len + dstart));
   } else if (dstart < 0) {
-    th->pendingException = vm->CreateIndexOutOfBoundsException(dstart);
+    th->throwException(vm->CreateIndexOutOfBoundsException(dstart));
   } else if (sstart < 0) {
-    th->pendingException = vm->CreateIndexOutOfBoundsException(sstart);
+    th->throwException(vm->CreateIndexOutOfBoundsException(sstart));
   } else if (len < 0) {
-    th->pendingException = vm->CreateIndexOutOfBoundsException(len);
+    th->throwException(vm->CreateIndexOutOfBoundsException(len));
   } else if ((dstType->isPrimitive() || srcType->isPrimitive()) &&
              srcType != dstType) {
-    th->pendingException = vm->CreateArrayStoreException(
-      (JavaVirtualTable*)dst->getVirtualTable());
+    th->throwException(vm->CreateArrayStoreException(
+      (JavaVirtualTable*)dst->getVirtualTable()));
   }
-  if (th->pendingException != NULL) return;
   
   if (!(dstType->isPrimitive())) {
     for (int i = 0; i < len; i++) {
       cur = ArrayObject::getElement((ArrayObject*)src, i + sstart);
       if (cur) {
         if (!(JavaObject::getClass(cur)->isAssignableFrom(dstType))) {
-          th->pendingException = vm->CreateArrayStoreException(
-              (JavaVirtualTable*)dst->getVirtualTable());
+          th->throwException(vm->CreateArrayStoreException(
+              (JavaVirtualTable*)dst->getVirtualTable()));
           break;
         } else {
           ArrayObject::setElement((ArrayObject*)dst, cur, i + dstart);

Modified: vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp?rev=142979&r1=142978&r2=142979&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp Tue Oct 25 17:22:54 2011
@@ -599,6 +599,21 @@
   // Synchronize after leaving native.
   if (isSynchro(compilingMethod->access))
     endSynchronize();
+
+  BasicBlock* ifNormal = createBasicBlock("");
+  BasicBlock* ifException = createBasicBlock("");
+  Value* javaExceptionPtr = getJavaExceptionPtr(getJavaThreadPtr(getMutatorThreadPtr()));
+  Value* obj = new LoadInst(javaExceptionPtr, "", currentBlock);
+  Value* test = new ICmpInst(*currentBlock, ICmpInst::ICMP_NE, obj, intrinsics->JavaObjectNullConstant, "");
+  BranchInst::Create(ifException, ifNormal, test, currentBlock);
+
+  currentBlock = ifException;
+  // Clear exception.
+  new StoreInst(intrinsics->JavaObjectNullConstant, javaExceptionPtr,
+                currentBlock);
+  CallInst::Create(intrinsics->ThrowExceptionFunction, obj, "", currentBlock);
+  new UnreachableInst(*llvmContext, currentBlock);
+  currentBlock = ifNormal;
   
   if (returnType != Type::getVoidTy(*llvmContext))
     ReturnInst::Create(*llvmContext, endNode, currentBlock);
@@ -1071,6 +1086,10 @@
 #endif
 
   nbHandlers = readExceptionTable(reader, codeLen);
+  if (nbHandlers != 0) {
+    jmpBuffer = new AllocaInst(ArrayType::get(Type::getInt8Ty(*llvmContext), sizeof(mvm::ExceptionBuffer)), "", currentBlock);
+    jmpBuffer = new BitCastInst(jmpBuffer, intrinsics->ptrType, "", currentBlock);
+  }
   
   reader.cursor = start;
   exploreOpcodes(reader, codeLen);
@@ -1120,7 +1139,7 @@
     BranchInst::Create(stackOverflow, noStackOverflow, stackCheck,
                        currentBlock);
     currentBlock = stackOverflow;
-    throwException(intrinsics->StackOverflowErrorFunction, 0, 0);
+    throwRuntimeException(intrinsics->StackOverflowErrorFunction, 0, 0);
     currentBlock = noStackOverflow;
   }
 
@@ -1163,12 +1182,31 @@
     CallInst::Create(intrinsics->PrintMethodEndFunction, arg, "", currentBlock);
     }
 #endif
+
+  finishExceptions();
   
   PI = pred_begin(currentBlock);
   PE = pred_end(currentBlock);
   if (PI == PE) {
     currentBlock->eraseFromParent();
   } else {
+    if (nbHandlers != 0) {
+      BasicBlock* ifNormal = createBasicBlock("");
+      BasicBlock* ifException = createBasicBlock("");
+      Value* javaExceptionPtr = getJavaExceptionPtr(getJavaThreadPtr(getMutatorThreadPtr()));
+      Value* obj = new LoadInst(javaExceptionPtr, "", currentBlock);
+      Value* test = new ICmpInst(*currentBlock, ICmpInst::ICMP_NE, obj, intrinsics->JavaObjectNullConstant, "");
+      BranchInst::Create(ifException, ifNormal, test, currentBlock);
+
+      currentBlock = ifException;
+      // Clear exception.
+      new StoreInst(intrinsics->JavaObjectNullConstant, javaExceptionPtr,
+                    currentBlock);
+      CallInst::Create(intrinsics->ThrowExceptionFunction, obj, "", currentBlock);
+      new UnreachableInst(*llvmContext, currentBlock);
+      currentBlock = ifNormal;
+    }
+
     if (returnType != Type::getVoidTy(*llvmContext)) {
       if (returnValue != NULL) {
         Value* obj = new LoadInst(
@@ -1182,9 +1220,6 @@
     }
   }
 
-  currentBlock = endExceptionBlock;
-
-  finishExceptions();
    
   removeUnusedLocals(intLocals);
   removeUnusedLocals(doubleLocals);
@@ -1306,7 +1341,7 @@
 
     BranchInst::Create(exit, cont, test, currentBlock);
     currentBlock = exit;
-    throwException(intrinsics->NullPointerExceptionFunction, 0, 0);
+    throwRuntimeException(intrinsics->NullPointerExceptionFunction, 0, 0);
     currentBlock = cont;
   } 
 }
@@ -1334,7 +1369,7 @@
     
     currentBlock = ifFalse;
     Value* args[2] = { obj, index };
-    throwException(intrinsics->IndexOutOfBoundsExceptionFunction, args, 2);
+    throwRuntimeException(intrinsics->IndexOutOfBoundsExceptionFunction, args, 2);
     currentBlock = ifTrue;
   }
   
@@ -2346,7 +2381,7 @@
   // Block bb7 (label_bb7)
   currentBlock = label_bb7;
   Value* VTArgs[1] = { Constant::getNullValue(intrinsics->VTType) };
-  throwException(intrinsics->ArrayStoreExceptionFunction, VTArgs, 1);
+  throwRuntimeException(intrinsics->ArrayStoreExceptionFunction, VTArgs, 1);
    
 
   
@@ -2492,51 +2527,39 @@
                        const char* Name,
                        BasicBlock *InsertAtEnd) {
   assert(!inlining);
-  
-  Instruction* res = CallInst::Create(F, args, Name, InsertAtEnd);
+ 
+  BasicBlock* ifException = NULL;
+  if (jmpBuffer != NULL) {
+    BasicBlock* doCall = createBasicBlock("");
+    ifException = createBasicBlock("");
+    Instruction* check = CallInst::Create(intrinsics->SetjmpFunction, jmpBuffer, "", currentBlock);
+    check = new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, check, intrinsics->constantZero, "");
+    BranchInst::Create(doCall, ifException, check, currentBlock);
+    currentBlock = doCall;
+    CallInst::Create(intrinsics->RegisterSetjmpFunction, jmpBuffer, "", currentBlock);
+  }
+
+  Instruction* res = CallInst::Create(F, args, Name,  currentBlock);
   DebugLoc DL = CreateLocation();
   res->setDebugLoc(DL);
   
-  if (TheCompiler->hasExceptionsEnabled()) {
-    Value* javaExceptionPtr = getJavaExceptionPtr(getJavaThreadPtr(getMutatorThreadPtr()));
-    
-    // Get the Java exception.
-    Value* obj = 0;
-    
+  if (jmpBuffer != NULL) {
+    CallInst::Create(intrinsics->UnregisterSetjmpFunction, jmpBuffer, "", currentBlock);
     BasicBlock* ifNormal = createBasicBlock("no exception block");
-  
-    Value* test = 0;
-    Constant* zero = intrinsics->JavaObjectNullConstant;
-
-    // If F is a runtime intrinsic that does not access memory, use a hack
-    // that will prevent LLVM from moving the exception check: runtime
-    // intrinsics return the exception if an exception was raised.
-    if (F == intrinsics->InitialisationCheckFunction || 
-        F == intrinsics->GetConstantPoolAtFunction ||
-        F == intrinsics->GetArrayClassFunction ||
-        F == intrinsics->GetClassDelegateeFunction) {
-      // Make the load volatile to force the instruction after the call.
-      // Otherwise, LLVM will merge the load with a previous load because
-      // the function is readnone.
-      obj = new LoadInst(javaExceptionPtr, "", false, currentBlock);
-      test = new BitCastInst(res, intrinsics->JavaObjectType, "", currentBlock);
-      test = new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, test, obj, "");
-      Value* T = new ICmpInst(*currentBlock, ICmpInst::ICMP_NE, obj, zero, "");
-      test = BinaryOperator::CreateAnd(test, T, "", currentBlock);
-    } else {
-      obj = new LoadInst(javaExceptionPtr, "", currentBlock);
-      test = new ICmpInst(*currentBlock, ICmpInst::ICMP_NE, obj, zero, "");
-    }
+    BranchInst::Create(ifNormal, currentBlock);
 
-    BranchInst::Create(currentExceptionBlock, ifNormal, test, currentBlock);
-
-    
+    currentBlock = ifException;
+    CallInst::Create(intrinsics->UnregisterSetjmpFunction, jmpBuffer, "", currentBlock);
+ 
     if (!currentExceptionBlock->empty()) {
+      // Get the Java exception.
+      Value* javaExceptionPtr = getJavaExceptionPtr(getJavaThreadPtr(getMutatorThreadPtr())); 
+      Value* obj = new LoadInst(javaExceptionPtr, "", currentBlock);
       Instruction* insn = currentExceptionBlock->begin();
       PHINode* node = dyn_cast<PHINode>(insn);
       if (node) node->addIncoming(obj, currentBlock);
-    }
-  
+    } 
+    BranchInst::Create(currentExceptionBlock, currentBlock);
     currentBlock = ifNormal; 
   }
 
@@ -2564,62 +2587,32 @@
   return invoke(F, args, Name, InsertAtEnd);
 }
 
-void JavaJIT::throwException(llvm::Function* F, Value* arg1) {
-  Instruction* obj = CallInst::Create(F, arg1, "", currentBlock);
-  DebugLoc DL = CreateLocation();
-  obj->setDebugLoc(DL);
+void JavaJIT::throwException(Value* obj, bool checkNull) {
+  if (checkNull) JITVerifyNull(obj);
+  if (nbHandlers == 0) {
+    CallInst::Create(intrinsics->ThrowExceptionFunction, obj, "", currentBlock);
+    new UnreachableInst(*llvmContext, currentBlock);
+  } else {
+    Value* javaExceptionPtr = getJavaExceptionPtr(getJavaThreadPtr(getMutatorThreadPtr()));
+    new StoreInst(obj, javaExceptionPtr, currentBlock);
 
-  if (currentExceptionBlock != endExceptionBlock) {
     Instruction* insn = currentExceptionBlock->begin();
     PHINode* node = dyn_cast<PHINode>(insn);
     if (node) node->addIncoming(obj, currentBlock);
     BranchInst::Create(currentExceptionBlock, currentBlock);
-  } else {
-    if (endNode) {
-      endNode->addIncoming(Constant::getNullValue(endNode->getType()),
-                           currentBlock);
-    }
-    BranchInst::Create(endBlock, currentBlock);
   }
 }
 
-void JavaJIT::throwException(Value* obj) {
-  JITVerifyNull(obj);
-	Value* javaExceptionPtr = getJavaExceptionPtr(getJavaThreadPtr(getMutatorThreadPtr()));
-
-  new StoreInst(obj, javaExceptionPtr, currentBlock);
-  if (currentExceptionBlock != endExceptionBlock) {
-    Instruction* insn = currentExceptionBlock->begin();
-    PHINode* node = dyn_cast<PHINode>(insn);
-    if (node) node->addIncoming(obj, currentBlock);
-    BranchInst::Create(currentExceptionBlock, currentBlock);
-  } else {
-    if (endNode) {
-      endNode->addIncoming(Constant::getNullValue(endNode->getType()),
-                           currentBlock);
-    }
-    BranchInst::Create(endBlock, currentBlock);
-  }
+void JavaJIT::throwRuntimeException(llvm::Function* F, Value* arg1) {
+  Value* args[1] = { arg1 };
+  throwRuntimeException(F, args, 1);
 }
 
-void JavaJIT::throwException(llvm::Function* F, Value** args,
-                             uint32 nbArgs) {
+void JavaJIT::throwRuntimeException(llvm::Function* F, Value** args, uint32 nbArgs) {
   Instruction* obj = CallInst::Create(F, ArrayRef<Value*>(args, nbArgs), "", currentBlock);
   DebugLoc DL = CreateLocation();
   obj->setDebugLoc(DL);
-
-  if (currentExceptionBlock != endExceptionBlock) {
-    Instruction* insn = currentExceptionBlock->begin();
-    PHINode* node = dyn_cast<PHINode>(insn);
-    if (node) node->addIncoming(obj, currentBlock);
-    BranchInst::Create(currentExceptionBlock, currentBlock);
-  } else {
-    if (endNode) {
-      endNode->addIncoming(Constant::getNullValue(endNode->getType()),
-                           currentBlock);
-    }
-    BranchInst::Create(endBlock, currentBlock);
-  }
+  throwException(obj, false);
 }
 
 /// Handler - This class represents an exception handler. It is only needed
@@ -2803,7 +2796,7 @@
     // First thing in the handler: clear the exception.
     Value* javaExceptionPtr = getJavaExceptionPtr(getJavaThreadPtr(getMutatorThreadPtr()));
     
-    // Clear exceptions.
+    // Clear exception.
     new StoreInst(intrinsics->JavaObjectNullConstant, javaExceptionPtr,
                   currentBlock);
   }

Modified: vmkit/trunk/lib/J3/Compiler/JavaJIT.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJIT.h?rev=142979&r1=142978&r2=142979&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaJIT.h (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaJIT.h Tue Oct 25 17:22:54 2011
@@ -95,6 +95,7 @@
     isCustomizable = false;
     overridesThis = false;
     nbHandlers = 0;
+    jmpBuffer = NULL;
   }
 
   /// javaCompile - Compile the Java method.
@@ -153,6 +154,8 @@
 
   /// endNode - The result of the method.
   llvm::PHINode* endNode;
+
+  llvm::Value* jmpBuffer;
   
   /// arraySize - Get the size of the array.
   llvm::Value* arraySize(llvm::Value* obj) {
@@ -390,10 +393,10 @@
   llvm::BasicBlock* unifiedUnreachable;
 
   /// throwException - Emit code to throw an exception.
-  void throwException(llvm::Function* F, llvm::Value** args,
+  void throwRuntimeException(llvm::Function* F, llvm::Value** args,
                       uint32 nbArgs);
-  void throwException(llvm::Function* F, llvm::Value* arg1);
-  void throwException(llvm::Value* obj);
+  void throwRuntimeException(llvm::Function* F, llvm::Value* arg1);
+  void throwException(llvm::Value* obj, bool checkNull = true);
 
   /// finishExceptions - Emit code to unwind the current function if an
   /// exception is thrown.

Modified: vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp?rev=142979&r1=142978&r2=142979&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp Tue Oct 25 17:22:54 2011
@@ -323,7 +323,7 @@
   mvm::MvmModule::protectIR();
   Function* func = parseFunction(meth, customizeFor);
   void* res = executionEngine->getPointerToGlobal(func);
- 
+
   if (!func->isDeclaration()) {
     llvm::GCFunctionInfo& GFI = GCInfo->getFunctionInfo(*func);
   

Modified: vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp?rev=142979&r1=142978&r2=142979&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp Tue Oct 25 17:22:54 2011
@@ -712,7 +712,7 @@
           BranchInst::Create(endBlock, exceptionBlock, res, currentBlock);
           
           currentBlock = exceptionBlock;
-          throwException(intrinsics->ArrayStoreExceptionFunction, VTArgs, 2);
+          throwRuntimeException(intrinsics->ArrayStoreExceptionFunction, VTArgs, 2);
 
           currentBlock = endBlock;
         }
@@ -1004,7 +1004,7 @@
 
           BranchInst::Create(ifTrue, ifFalse, cmp, currentBlock);
           currentBlock = ifTrue;
-          throwException(intrinsics->ArithmeticExceptionFunction, 0, 0);
+          throwRuntimeException(intrinsics->ArithmeticExceptionFunction, 0, 0);
           currentBlock = ifFalse;  
         }
         Value* cmp = new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, val2,
@@ -1042,7 +1042,7 @@
 
           BranchInst::Create(ifTrue, ifFalse, cmp, currentBlock);
           currentBlock = ifTrue;
-          throwException(intrinsics->ArithmeticExceptionFunction, 0, 0);
+          throwRuntimeException(intrinsics->ArithmeticExceptionFunction, 0, 0);
           currentBlock = ifFalse;
         }
         push(BinaryOperator::CreateSDiv(val1, val2, "", currentBlock),
@@ -1081,7 +1081,7 @@
 
           BranchInst::Create(ifTrue, ifFalse, cmp, currentBlock);
           currentBlock = ifTrue;
-          throwException(intrinsics->ArithmeticExceptionFunction, 0, 0);
+          throwRuntimeException(intrinsics->ArithmeticExceptionFunction, 0, 0);
           currentBlock = ifFalse;
         }
         Value* cmp = new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, val2,
@@ -1114,7 +1114,7 @@
 
           BranchInst::Create(ifTrue, ifFalse, cmp, currentBlock);
           currentBlock = ifTrue;
-          throwException(intrinsics->ArithmeticExceptionFunction, 0, 0);
+          throwRuntimeException(intrinsics->ArithmeticExceptionFunction, 0, 0);
           currentBlock = ifFalse;
         }
         push(BinaryOperator::CreateSRem(val1, val2, "", currentBlock),
@@ -2131,7 +2131,7 @@
 
           BranchInst::Create(BB1, BB2, cmp, currentBlock);
           currentBlock = BB1;
-          throwException(intrinsics->NegativeArraySizeExceptionFunction, arg1);
+          throwRuntimeException(intrinsics->NegativeArraySizeExceptionFunction, arg1);
           currentBlock = BB2;
         
           cmp = new ICmpInst(*currentBlock, ICmpInst::ICMP_SGT, arg1,
@@ -2142,7 +2142,7 @@
 
           BranchInst::Create(BB1, BB2, cmp, currentBlock);
           currentBlock = BB1;
-          throwException(intrinsics->OutOfMemoryErrorFunction, arg1);
+          throwRuntimeException(intrinsics->OutOfMemoryErrorFunction, arg1);
           currentBlock = BB2;
         }
         
@@ -2219,7 +2219,7 @@
 
           BranchInst::Create(endCheckcast, ifFalse, cmp, currentBlock);
           currentBlock = exceptionCheckcast;
-          throwException(intrinsics->ClassCastExceptionFunction, args, 2);
+          throwRuntimeException(intrinsics->ClassCastExceptionFunction, args, 2);
           currentBlock = ifFalse;
         } else {
           BasicBlock* ifFalse = createBasicBlock("false type compare");

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=142979&r1=142978&r2=142979&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/LLVMRuntime/runtime-default.ll (original)
+++ vmkit/trunk/lib/J3/LLVMRuntime/runtime-default.ll Tue Oct 25 17:22:54 2011
@@ -166,7 +166,7 @@
 ;;; forceInitialisationCheck - Force to check initialization. The difference
 ;;; between this function and the initialisationCheck function is that the
 ;;; latter is readnone and can thus be removed. This function is removed
-;;; by Jnjvm after the GVN pass, therefore it does not have an actual
+;;; by J3 after the GVN pass, therefore it does not have an actual
 ;;; implementation.
 declare void @forceInitialisationCheck(%JavaClass*)
 
@@ -177,10 +177,10 @@
 declare void @forceLoadedCheck(%JavaCommonClass*)
 
 ;;; getConstantPoolAt - Get the value in the constant pool of this class.
-;;; This function is removed by Jnjvm after the GVn pass, therefore it does
+;;; This function is removed by J3's LLVM pass, therefore it does
 ;;; not have an actual implementation.
 declare i8* @getConstantPoolAt(i8* (%JavaClass*, i32, ...)*, i8**,
-                               %JavaClass*, i32, ...) readnone
+                               %JavaClass*, i32, ...)
 
 ;;; j3VirtualTableLookup - Look up the offset in a virtual table of a
 ;;; specific function.

Modified: vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp?rev=142979&r1=142978&r2=142979&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp Tue Oct 25 17:22:54 2011
@@ -29,8 +29,6 @@
 
   void* res = 0;
 
-  BEGIN_NATIVE_EXCEPTION(1)
-  
   UserConstantPool* ctpInfo = caller->getConstantPool();
   if (ctpInfo->ctpRes[index]) {
     res = ctpInfo->ctpRes[index];
@@ -45,15 +43,6 @@
     
     ctpInfo->ctpRes[index] = (void*)res;
   }
-  
-    
-  END_NATIVE_EXCEPTION
-
-  // Since the function is marked readnone, LLVM may move it after the
-  // exception check. Therefore, we trick LLVM to check the return value of the
-  // function.
-  JavaObject* obj = JavaThread::get()->pendingException;
-  if (obj) return (JavaMethod*)obj;
   return res;
 }
 
@@ -61,8 +50,6 @@
 extern "C" void* j3VirtualFieldLookup(UserClass* caller, uint32 index) {
   
   void* res = 0;
-  
-  BEGIN_NATIVE_EXCEPTION(1)
 
   UserConstantPool* ctpInfo = caller->getConstantPool();
   if (ctpInfo->ctpRes[index]) {
@@ -83,13 +70,6 @@
     res = (void*)field->ptrOffset;
   }
 
-  END_NATIVE_EXCEPTION
-
-  // Since the function is marked readnone, LLVM may move it after the
-  // exception check. Therefore, we trick LLVM to check the return value of the
-  // function.
-  JavaObject* obj = JavaThread::get()->pendingException;
-  if (obj) return (void*)obj;
   return res;
 }
 
@@ -98,8 +78,6 @@
   
   void* res = 0;
   
-  BEGIN_NATIVE_EXCEPTION(1)
-  
   UserConstantPool* ctpInfo = caller->getConstantPool();
   
   if (ctpInfo->ctpRes[index]) {
@@ -128,13 +106,6 @@
     res = ptr;
   }
 
-  END_NATIVE_EXCEPTION
-
-  // Since the function is marked readnone, LLVM may move it after the
-  // exception check. Therefore, we trick LLVM to check the return value of the
-  // function.
-  JavaObject* obj = JavaThread::get()->pendingException;
-  if (obj) return (void*)obj;
   return res;
 }
 
@@ -144,8 +115,6 @@
   llvm_gcroot(obj, 0);
   uint32 res = 0;
   
-  BEGIN_NATIVE_EXCEPTION(1)
-    
   UserCommonClass* cl = 0;
   const UTF8* utf8 = 0;
   Signdef* sign = 0;
@@ -173,8 +142,6 @@
 
   res = dmeth->offset;
 
-  END_NATIVE_EXCEPTION
-
   return res;
 }
 
@@ -183,8 +150,6 @@
   
   void* res = 0;
   
-  BEGIN_NATIVE_EXCEPTION(1)
-   
   UserConstantPool* ctpInfo = caller->getConstantPool();
   UserCommonClass* cl = ctpInfo->loadClass(index);
   // We can not initialize here, because bytecodes such as CHECKCAST
@@ -202,50 +167,20 @@
       cl->classLoader->constructArray(arrayName)->virtualVT;
   }
 
-  END_NATIVE_EXCEPTION
-  
-  // Since the function is marked readnone, LLVM may move it after the
-  // exception check. Therefore, we trick LLVM to check the return value of the
-  // function.
-  JavaObject* obj = JavaThread::get()->pendingException;
-  if (obj) return (void*)obj;
   return res;
 }
 
 // Calls Java code.
 // Throws if initializing the class throws an exception.
 extern "C" UserCommonClass* j3RuntimeInitialiseClass(UserClass* cl) {
-  BEGIN_NATIVE_EXCEPTION(1)
- 
   cl->resolveClass();
   cl->initialiseClass(JavaThread::get()->getJVM());
-  
-  END_NATIVE_EXCEPTION
-
-  // Since the function is marked readnone, LLVM may move it after the
-  // exception check. Therefore, we trick LLVM to check the return value of the
-  // function.
-  JavaObject* obj = JavaThread::get()->pendingException;
-  if (obj) return (UserCommonClass*)obj;
   return cl;
 }
 
 // Calls Java code.
 extern "C" JavaObject* j3RuntimeDelegatee(UserCommonClass* cl) {
-  JavaObject* res = 0;
-  llvm_gcroot(res, 0);
-
-  BEGIN_NATIVE_EXCEPTION(1)
-  Jnjvm* vm = JavaThread::get()->getJVM();
-  res = cl->getClassDelegatee(vm);
-  END_NATIVE_EXCEPTION
-  
-  // Since the function is marked readnone, LLVM may move it after the
-  // exception check. Therefore, we trick LLVM to check the return value of the
-  // function.
-  JavaObject* obj = JavaThread::get()->pendingException;
-  if (obj) return obj;
-  return res;
+  return cl->getClassDelegatee(JavaThread::get()->getJVM());
 }
 
 // Throws if one of the dimension is negative.
@@ -287,8 +222,6 @@
   JavaObject* res = 0;
   llvm_gcroot(res, 0);
 
-  BEGIN_NATIVE_EXCEPTION(1)
-
   va_list ap;
   va_start(ap, len);
   mvm::ThreadAllocator allocator;
@@ -299,8 +232,6 @@
   Jnjvm* vm = JavaThread::get()->getJVM();
   res = multiCallNewIntern(cl, len, dims, vm);
 
-  END_NATIVE_EXCEPTION
-
   return res;
 }
 
@@ -310,7 +241,6 @@
                                              JavaVirtualTable** VT) {
   JavaVirtualTable* res = 0;
   assert(VT && "Incorrect call to j3GetArrayClass");
-  BEGIN_NATIVE_EXCEPTION(1)
   
   UserConstantPool* ctpInfo = caller->getConstantPool();
   UserCommonClass* cl = ctpInfo->loadClass(index);
@@ -322,13 +252,6 @@
   res = JCL->constructArray(arrayName)->virtualVT;
   *VT = res;
 
-  END_NATIVE_EXCEPTION
-
-  // Since the function is marked readnone, LLVM may move it after the
-  // exception check. Therefore, we trick LLVM to check the return value of the
-  // function.
-  JavaObject* obj = JavaThread::get()->pendingException;
-  if (obj) return (JavaVirtualTable*)obj;
   return res;
 }
 
@@ -377,144 +300,47 @@
   JavaObject::release(obj);
 }
 
-// Does not call any Java code. Can not yield a GC.
 extern "C" void j3ThrowException(JavaObject* obj) {
   llvm_gcroot(obj, 0);
-  return JavaThread::get()->throwException(obj);
+  JavaThread::get()->throwException(obj);
+  UNREACHABLE();
 }
 
-// Creates a Java object and then throws it.
 extern "C" JavaObject* j3NullPointerException() {
-  JavaObject *exc = 0;
-  llvm_gcroot(exc, 0);
-  JavaThread *th = JavaThread::get();
-
-  BEGIN_NATIVE_EXCEPTION(1)
-  
-  exc = th->getJVM()->CreateNullPointerException();
-
-  END_NATIVE_EXCEPTION
-
-  th->pendingException = exc;
-  return exc;
+  return JavaThread::get()->getJVM()->CreateNullPointerException();
 }
 
-// Creates a Java object and then throws it.
 extern "C" JavaObject* j3NegativeArraySizeException(sint32 val) {
-  JavaObject *exc = 0;
-  llvm_gcroot(exc, 0);
-  JavaThread *th = JavaThread::get();
-
-  BEGIN_NATIVE_EXCEPTION(1)
-  
-  exc = th->getJVM()->CreateNegativeArraySizeException();
-
-  END_NATIVE_EXCEPTION
-
-  th->pendingException = exc;
-  return exc;
+  return JavaThread::get()->getJVM()->CreateNegativeArraySizeException();
 }
 
-// Creates a Java object and then throws it.
 extern "C" JavaObject* j3OutOfMemoryError(sint32 val) {
-  JavaObject *exc = 0;
-  llvm_gcroot(exc, 0);
-  JavaThread *th = JavaThread::get();
-
-  BEGIN_NATIVE_EXCEPTION(1)
-  
-  exc = th->getJVM()->CreateOutOfMemoryError();
-
-  END_NATIVE_EXCEPTION
-
-  th->pendingException = exc;
-  return exc;
+  return JavaThread::get()->getJVM()->CreateOutOfMemoryError();
 }
 
-// Creates a Java object and then throws it.
 extern "C" JavaObject* j3StackOverflowError() {
-  JavaObject *exc = 0;
-  llvm_gcroot(exc, 0);
-  JavaThread *th = JavaThread::get();
-
-  BEGIN_NATIVE_EXCEPTION(1)
-  
-  exc = th->getJVM()->CreateStackOverflowError();
-
-  END_NATIVE_EXCEPTION
-
-  th->pendingException = exc;
-  return exc;
+  return JavaThread::get()->getJVM()->CreateStackOverflowError();
 }
 
-// Creates a Java object and then throws it.
 extern "C" JavaObject* j3ArithmeticException() {
-  JavaObject *exc = 0;
-  llvm_gcroot(exc, 0);
-  JavaThread *th = JavaThread::get();
-
-  BEGIN_NATIVE_EXCEPTION(1)
-  
-  exc = th->getJVM()->CreateArithmeticException();
-
-  END_NATIVE_EXCEPTION
-
-  th->pendingException = exc;
-  return exc;
+  return JavaThread::get()->getJVM()->CreateArithmeticException();
 }
 
-// Creates a Java object and then throws it.
 extern "C" JavaObject* j3ClassCastException(JavaObject* obj,
                                             UserCommonClass* cl) {
-  JavaObject *exc = 0;
-  llvm_gcroot(obj, 0);
-  llvm_gcroot(exc, 0);
-  
-  JavaThread *th = JavaThread::get();
-
-  BEGIN_NATIVE_EXCEPTION(1)
-  
-  exc = th->getJVM()->CreateClassCastException(obj, cl);
-
-  END_NATIVE_EXCEPTION
-
-  th->pendingException = exc;
-  return exc;
+  llvm_gcroot(obj, 0);  
+  return JavaThread::get()->getJVM()->CreateClassCastException(obj, cl);
 }
 
-// Creates a Java object and then throws it.
 extern "C" JavaObject* j3IndexOutOfBoundsException(JavaObject* obj,
                                                    sint32 index) {
-  JavaObject *exc = 0;
   llvm_gcroot(obj, 0);
-  llvm_gcroot(exc, 0);
-  
-  JavaThread *th = JavaThread::get();
-
-  BEGIN_NATIVE_EXCEPTION(1)
-  
-  exc = th->getJVM()->CreateIndexOutOfBoundsException(index);
-
-  END_NATIVE_EXCEPTION
-
-  th->pendingException = exc;
-  return exc;
+  return JavaThread::get()->getJVM()->CreateIndexOutOfBoundsException(index);
 }
 
-// Creates a Java object and then throws it.
 extern "C" JavaObject* j3ArrayStoreException(JavaVirtualTable* VT,
                                              JavaVirtualTable* VT2) {
-  JavaObject *exc = 0;
-  llvm_gcroot(exc, 0);
-  JavaThread *th = JavaThread::get();
-
-  BEGIN_NATIVE_EXCEPTION(1)
-  exc = th->getJVM()->CreateArrayStoreException(VT);
-
-  END_NATIVE_EXCEPTION
-
-  th->pendingException = exc;
-  return exc;
+  return JavaThread::get()->getJVM()->CreateArrayStoreException(VT);
 }
 
 // Create an exception then throws it.
@@ -522,30 +348,18 @@
   JavaObject *exc = 0;
   llvm_gcroot(exc, 0);
   JavaThread *th = JavaThread::get();
-  
-  BEGIN_NATIVE_EXCEPTION(1)
-
   JavaMethod* meth = th->getCallingMethodLevel(0);
   exc = th->getJVM()->CreateUnsatisfiedLinkError(meth);
-
-  END_NATIVE_EXCEPTION
-
-  th->pendingException = exc;
+  j3ThrowException(exc);
 }
 
 extern "C" void* j3StringLookup(UserClass* cl, uint32 index) {
   
   JavaString** str = 0;
-  
-  BEGIN_NATIVE_EXCEPTION(1)
-  
   UserConstantPool* ctpInfo = cl->getConstantPool();
   const UTF8* utf8 = ctpInfo->UTF8At(ctpInfo->ctpDef[index]);
   str = cl->classLoader->UTF8ToStr(utf8);
   ctpInfo->ctpRes[index] = str;
-  
-  END_NATIVE_EXCEPTION
-
   return (void*)str;
 }
 
@@ -555,8 +369,6 @@
   UserCommonClass* cl = JavaObject::getClass(obj);
   void* result = NULL;
   
-  BEGIN_NATIVE_EXCEPTION(1)
-
   // Lookup the caller of this class.
   mvm::StackWalker Walker(th);
   ++Walker; // Remove the stub.
@@ -610,16 +422,12 @@
     }
   }
 
-  END_NATIVE_EXCEPTION
-
   return result;
 }
 
 extern "C" void* j3ResolveStaticStub() {
   JavaThread *th = JavaThread::get();
   void* result = NULL;
-  
-  BEGIN_NATIVE_EXCEPTION(1)
 
   // Lookup the caller of this class.
   mvm::StackWalker Walker(th);
@@ -647,16 +455,12 @@
   // Update the entry in the constant pool.
   ctpInfo->ctpRes[ctpIndex] = result;
 
-  END_NATIVE_EXCEPTION
-
   return result;
 }
 
 extern "C" void* j3ResolveSpecialStub() {
   JavaThread *th = JavaThread::get();
   void* result = NULL;
-  
-  BEGIN_NATIVE_EXCEPTION(1)
 
   // Lookup the caller of this class.
   mvm::StackWalker Walker(th);
@@ -692,8 +496,6 @@
   // Update the entry in the constant pool.
   ctpInfo->ctpRes[ctpIndex] = result;
 
-  END_NATIVE_EXCEPTION
-
   return result;
 }
 

Modified: vmkit/trunk/lib/J3/VMCore/JavaThread.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaThread.h?rev=142979&r1=142978&r2=142979&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaThread.h (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaThread.h Tue Oct 25 17:22:54 2011
@@ -28,14 +28,8 @@
 class Jnjvm;
 
 
-#define BEGIN_NATIVE_EXCEPTION(level) \
-  JavaThread* __th = JavaThread::get(); \
-  TRY {
-
-#define END_NATIVE_EXCEPTION \
-  } CATCH { \
-    __th->throwFromNative(); \
-  } END_CATCH;
+#define BEGIN_NATIVE_EXCEPTION(level)
+#define END_NATIVE_EXCEPTION
 
 #define BEGIN_JNI_EXCEPTION \
   JavaThread* th = JavaThread::get(); \

Modified: vmkit/trunk/lib/Mvm/Compiler/JIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Compiler/JIT.cpp?rev=142979&r1=142978&r2=142979&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/Compiler/JIT.cpp (original)
+++ vmkit/trunk/lib/Mvm/Compiler/JIT.cpp Tue Oct 25 17:22:54 2011
@@ -367,6 +367,10 @@
   NonHeapWriteBarrierFunction = module->getFunction("nonHeapWriteBarrier");
   AllocateFunction = module->getFunction("gcmalloc");
 
+  SetjmpFunction = module->getFunction("_setjmp");
+  RegisterSetjmpFunction = module->getFunction("registerSetjmp");
+  UnregisterSetjmpFunction = module->getFunction("unregisterSetjmp");
+
   AllocateFunction->setGC("vmkit");
   ArrayWriteBarrierFunction->setGC("vmkit");
   FieldWriteBarrierFunction->setGC("vmkit");

Modified: vmkit/trunk/lib/Mvm/Compiler/LLVMRuntime.ll
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Compiler/LLVMRuntime.ll?rev=142979&r1=142978&r2=142979&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/Compiler/LLVMRuntime.ll (original)
+++ vmkit/trunk/lib/Mvm/Compiler/LLVMRuntime.ll Tue Oct 25 17:22:54 2011
@@ -68,3 +68,9 @@
 declare void @arrayWriteBarrier(i8*, i8**, i8*)
 declare void @fieldWriteBarrier(i8*, i8**, i8*)
 declare void @nonHeapWriteBarrier(i8**, i8*)
+
+
+
+declare i32 @_setjmp(i8*) nounwind
+declare void @registerSetjmp(i8*) nounwind
+declare void @unregisterSetjmp(i8*) nounwind

Modified: vmkit/trunk/lib/Mvm/Runtime/Object.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/Object.cpp?rev=142979&r1=142978&r2=142979&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/Runtime/Object.cpp (original)
+++ vmkit/trunk/lib/Mvm/Runtime/Object.cpp Tue Oct 25 17:22:54 2011
@@ -38,6 +38,14 @@
 extern "C" void EmptyDestructor() {
 }
 
+extern "C" void registerSetjmp(ExceptionBuffer* buffer) {
+  buffer->init();
+}
+
+extern "C" void unregisterSetjmp(ExceptionBuffer* buffer) {
+  buffer->remove();
+}
+
 void VirtualMachine::waitForExit() {   
   threadLock.lock();
   





More information about the vmkit-commits mailing list