[vmkit-commits] [vmkit] r143293 - 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/JavaJITClasspath.inc 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
Sat Oct 29 13:30:33 PDT 2011


Author: geoffray
Date: Sat Oct 29 15:30:33 2011
New Revision: 143293

URL: http://llvm.org/viewvc/llvm-project?rev=143293&view=rev
Log:
Revert exception changes, it breaks MMTk compilation.

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/JavaJITClasspath.inc
    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=143293&r1=143292&r2=143293&view=diff
==============================================================================
--- vmkit/trunk/include/mvm/JIT.h (original)
+++ vmkit/trunk/include/mvm/JIT.h Sat Oct 29 15:30:33 2011
@@ -112,10 +112,6 @@
   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=143293&r1=143292&r2=143293&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/ClassLib/GNUClasspath/ClasspathVMClass.inc (original)
+++ vmkit/trunk/lib/J3/ClassLib/GNUClasspath/ClasspathVMClass.inc Sat Oct 29 15:30:33 2011
@@ -593,7 +593,7 @@
   llvm_gcroot(throwable, 0);
 
   assert(throwable && "Using internal VM throw exception without exception");
-  JavaThread::get()->throwException(throwable);
+  JavaThread::get()->pendingException = (JavaObject*)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=143293&r1=143292&r2=143293&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/ClassLib/GNUClasspath/ClasspathVMSystem.inc (original)
+++ vmkit/trunk/lib/J3/ClassLib/GNUClasspath/ClasspathVMSystem.inc Sat Oct 29 15:30:33 2011
@@ -42,15 +42,15 @@
   Jnjvm *vm = th->getJVM();
 
   if (src == NULL || dst == NULL) {
-    th->throwException(vm->CreateNullPointerException());
-    UNREACHABLE();
+    th->pendingException = vm->CreateNullPointerException();
+    return;
   }
   
   if (!(JavaObject::getClass(src)->isArray() &&
         JavaObject::getClass(dst)->isArray())) {
-    th->throwException(vm->CreateArrayStoreException(
-      (JavaVirtualTable*)dst->getVirtualTable()));
-    UNREACHABLE();
+    th->pendingException = vm->CreateArrayStoreException(
+      (JavaVirtualTable*)dst->getVirtualTable());
+    return;
   }
   
   UserClassArray* ts = (UserClassArray*)JavaObject::getClass(src);
@@ -62,32 +62,33 @@
   sint32 dstSize = JavaArray::getSize(dst);
 
   if (len > srcSize) {
-    th->throwException(vm->CreateIndexOutOfBoundsException(len));
+    th->pendingException = vm->CreateIndexOutOfBoundsException(len);
   } else if (len > dstSize) {
-    th->throwException(vm->CreateIndexOutOfBoundsException(len));
+    th->pendingException = vm->CreateIndexOutOfBoundsException(len);
   } else if (len + sstart > srcSize) {
-    th->throwException(vm->CreateIndexOutOfBoundsException(len + sstart));
+    th->pendingException = vm->CreateIndexOutOfBoundsException(len + sstart);
   } else if (len + dstart > dstSize) {
-    th->throwException(vm->CreateIndexOutOfBoundsException(len + dstart));
+    th->pendingException = vm->CreateIndexOutOfBoundsException(len + dstart);
   } else if (dstart < 0) {
-    th->throwException(vm->CreateIndexOutOfBoundsException(dstart));
+    th->pendingException = vm->CreateIndexOutOfBoundsException(dstart);
   } else if (sstart < 0) {
-    th->throwException(vm->CreateIndexOutOfBoundsException(sstart));
+    th->pendingException = vm->CreateIndexOutOfBoundsException(sstart);
   } else if (len < 0) {
-    th->throwException(vm->CreateIndexOutOfBoundsException(len));
+    th->pendingException = vm->CreateIndexOutOfBoundsException(len);
   } else if ((dstType->isPrimitive() || srcType->isPrimitive()) &&
              srcType != dstType) {
-    th->throwException(vm->CreateArrayStoreException(
-      (JavaVirtualTable*)dst->getVirtualTable()));
+    th->pendingException = 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->throwException(vm->CreateArrayStoreException(
-              (JavaVirtualTable*)dst->getVirtualTable()));
+          th->pendingException = 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=143293&r1=143292&r2=143293&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp Sat Oct 29 15:30:33 2011
@@ -599,21 +599,6 @@
   // 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);
@@ -1086,10 +1071,6 @@
 #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);
@@ -1139,7 +1120,7 @@
     BranchInst::Create(stackOverflow, noStackOverflow, stackCheck,
                        currentBlock);
     currentBlock = stackOverflow;
-    throwRuntimeException(intrinsics->StackOverflowErrorFunction, 0, 0);
+    throwException(intrinsics->StackOverflowErrorFunction, 0, 0);
     currentBlock = noStackOverflow;
   }
 
@@ -1182,31 +1163,12 @@
     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(
@@ -1220,6 +1182,9 @@
     }
   }
 
+  currentBlock = endExceptionBlock;
+
+  finishExceptions();
    
   removeUnusedLocals(intLocals);
   removeUnusedLocals(doubleLocals);
@@ -1341,7 +1306,7 @@
 
     BranchInst::Create(exit, cont, test, currentBlock);
     currentBlock = exit;
-    throwRuntimeException(intrinsics->NullPointerExceptionFunction, 0, 0);
+    throwException(intrinsics->NullPointerExceptionFunction, 0, 0);
     currentBlock = cont;
   } 
 }
@@ -1369,7 +1334,7 @@
     
     currentBlock = ifFalse;
     Value* args[2] = { obj, index };
-    throwRuntimeException(intrinsics->IndexOutOfBoundsExceptionFunction, args, 2);
+    throwException(intrinsics->IndexOutOfBoundsExceptionFunction, args, 2);
     currentBlock = ifTrue;
   }
   
@@ -2299,39 +2264,51 @@
                        const char* Name,
                        BasicBlock *InsertAtEnd) {
   assert(!inlining);
- 
-  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);
+  
+  Instruction* res = CallInst::Create(F, args, Name, InsertAtEnd);
   DebugLoc DL = CreateLocation();
   res->setDebugLoc(DL);
   
-  if (jmpBuffer != NULL) {
-    CallInst::Create(intrinsics->UnregisterSetjmpFunction, jmpBuffer, "", currentBlock);
+  if (TheCompiler->hasExceptionsEnabled()) {
+    Value* javaExceptionPtr = getJavaExceptionPtr(getJavaThreadPtr(getMutatorThreadPtr()));
+    
+    // Get the Java exception.
+    Value* obj = 0;
+    
     BasicBlock* ifNormal = createBasicBlock("no exception block");
-    BranchInst::Create(ifNormal, currentBlock);
+  
+    Value* test = 0;
+    Constant* zero = intrinsics->JavaObjectNullConstant;
 
-    currentBlock = ifException;
-    CallInst::Create(intrinsics->UnregisterSetjmpFunction, jmpBuffer, "", currentBlock);
- 
+    // 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(currentExceptionBlock, ifNormal, test, 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; 
   }
 
@@ -2359,32 +2336,62 @@
   return invoke(F, args, Name, InsertAtEnd);
 }
 
-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);
+void JavaJIT::throwException(llvm::Function* F, Value* arg1) {
+  Instruction* obj = CallInst::Create(F, arg1, "", 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);
   }
 }
 
-void JavaJIT::throwRuntimeException(llvm::Function* F, Value* arg1) {
-  Value* args[1] = { arg1 };
-  throwRuntimeException(F, args, 1);
+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** args, uint32 nbArgs) {
+void JavaJIT::throwException(llvm::Function* F, Value** args,
+                             uint32 nbArgs) {
   Instruction* obj = CallInst::Create(F, ArrayRef<Value*>(args, nbArgs), "", currentBlock);
   DebugLoc DL = CreateLocation();
   obj->setDebugLoc(DL);
-  throwException(obj, false);
+
+  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);
+  }
 }
 
 /// Handler - This class represents an exception handler. It is only needed
@@ -2568,7 +2575,7 @@
     // First thing in the handler: clear the exception.
     Value* javaExceptionPtr = getJavaExceptionPtr(getJavaThreadPtr(getMutatorThreadPtr()));
     
-    // Clear exception.
+    // Clear exceptions.
     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=143293&r1=143292&r2=143293&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaJIT.h (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaJIT.h Sat Oct 29 15:30:33 2011
@@ -95,7 +95,6 @@
     isCustomizable = false;
     overridesThis = false;
     nbHandlers = 0;
-    jmpBuffer = NULL;
   }
 
   /// javaCompile - Compile the Java method.
@@ -154,8 +153,6 @@
 
   /// 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) {
@@ -393,10 +390,10 @@
   llvm::BasicBlock* unifiedUnreachable;
 
   /// throwException - Emit code to throw an exception.
-  void throwRuntimeException(llvm::Function* F, llvm::Value** args,
+  void throwException(llvm::Function* F, llvm::Value** args,
                       uint32 nbArgs);
-  void throwRuntimeException(llvm::Function* F, llvm::Value* arg1);
-  void throwException(llvm::Value* obj, bool checkNull = true);
+  void throwException(llvm::Function* F, llvm::Value* arg1);
+  void throwException(llvm::Value* obj);
 
   /// finishExceptions - Emit code to unwind the current function if an
   /// exception is thrown.

Modified: vmkit/trunk/lib/J3/Compiler/JavaJITClasspath.inc
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJITClasspath.inc?rev=143293&r1=143292&r2=143293&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaJITClasspath.inc (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaJITClasspath.inc Sat Oct 29 15:30:33 2011
@@ -99,7 +99,7 @@
   // Block bb7 (label_bb7)
   currentBlock = label_bb7;
   Value* VTArgs[1] = { Constant::getNullValue(intrinsics->VTType) };
-  throwRuntimeException(intrinsics->ArrayStoreExceptionFunction, VTArgs, 1);
+  throwException(intrinsics->ArrayStoreExceptionFunction, VTArgs, 1);
    
 
   

Modified: vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp?rev=143293&r1=143292&r2=143293&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp Sat Oct 29 15:30:33 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=143293&r1=143292&r2=143293&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp Sat Oct 29 15:30:33 2011
@@ -712,7 +712,7 @@
           BranchInst::Create(endBlock, exceptionBlock, res, currentBlock);
           
           currentBlock = exceptionBlock;
-          throwRuntimeException(intrinsics->ArrayStoreExceptionFunction, VTArgs, 2);
+          throwException(intrinsics->ArrayStoreExceptionFunction, VTArgs, 2);
 
           currentBlock = endBlock;
         }
@@ -1004,7 +1004,7 @@
 
           BranchInst::Create(ifTrue, ifFalse, cmp, currentBlock);
           currentBlock = ifTrue;
-          throwRuntimeException(intrinsics->ArithmeticExceptionFunction, 0, 0);
+          throwException(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;
-          throwRuntimeException(intrinsics->ArithmeticExceptionFunction, 0, 0);
+          throwException(intrinsics->ArithmeticExceptionFunction, 0, 0);
           currentBlock = ifFalse;
         }
         push(BinaryOperator::CreateSDiv(val1, val2, "", currentBlock),
@@ -1081,7 +1081,7 @@
 
           BranchInst::Create(ifTrue, ifFalse, cmp, currentBlock);
           currentBlock = ifTrue;
-          throwRuntimeException(intrinsics->ArithmeticExceptionFunction, 0, 0);
+          throwException(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;
-          throwRuntimeException(intrinsics->ArithmeticExceptionFunction, 0, 0);
+          throwException(intrinsics->ArithmeticExceptionFunction, 0, 0);
           currentBlock = ifFalse;
         }
         push(BinaryOperator::CreateSRem(val1, val2, "", currentBlock),
@@ -2131,7 +2131,7 @@
 
           BranchInst::Create(BB1, BB2, cmp, currentBlock);
           currentBlock = BB1;
-          throwRuntimeException(intrinsics->NegativeArraySizeExceptionFunction, arg1);
+          throwException(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;
-          throwRuntimeException(intrinsics->OutOfMemoryErrorFunction, arg1);
+          throwException(intrinsics->OutOfMemoryErrorFunction, arg1);
           currentBlock = BB2;
         }
         
@@ -2219,7 +2219,7 @@
 
           BranchInst::Create(endCheckcast, ifFalse, cmp, currentBlock);
           currentBlock = exceptionCheckcast;
-          throwRuntimeException(intrinsics->ClassCastExceptionFunction, args, 2);
+          throwException(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=143293&r1=143292&r2=143293&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/LLVMRuntime/runtime-default.ll (original)
+++ vmkit/trunk/lib/J3/LLVMRuntime/runtime-default.ll Sat Oct 29 15:30:33 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 J3 after the GVN pass, therefore it does not have an actual
+;;; by Jnjvm 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 J3's LLVM pass, therefore it does
+;;; This function is removed by Jnjvm after the GVn pass, therefore it does
 ;;; not have an actual implementation.
 declare i8* @getConstantPoolAt(i8* (%JavaClass*, i32, ...)*, i8**,
-                               %JavaClass*, i32, ...)
+                               %JavaClass*, i32, ...) readnone
 
 ;;; 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=143293&r1=143292&r2=143293&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp Sat Oct 29 15:30:33 2011
@@ -29,6 +29,8 @@
 
   void* res = 0;
 
+  BEGIN_NATIVE_EXCEPTION(1)
+  
   UserConstantPool* ctpInfo = caller->getConstantPool();
   if (ctpInfo->ctpRes[index]) {
     res = ctpInfo->ctpRes[index];
@@ -43,6 +45,15 @@
     
     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;
 }
 
@@ -50,6 +61,8 @@
 extern "C" void* j3VirtualFieldLookup(UserClass* caller, uint32 index) {
   
   void* res = 0;
+  
+  BEGIN_NATIVE_EXCEPTION(1)
 
   UserConstantPool* ctpInfo = caller->getConstantPool();
   if (ctpInfo->ctpRes[index]) {
@@ -70,6 +83,13 @@
     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;
 }
 
@@ -78,6 +98,8 @@
   
   void* res = 0;
   
+  BEGIN_NATIVE_EXCEPTION(1)
+  
   UserConstantPool* ctpInfo = caller->getConstantPool();
   
   if (ctpInfo->ctpRes[index]) {
@@ -106,6 +128,13 @@
     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;
 }
 
@@ -115,6 +144,8 @@
   llvm_gcroot(obj, 0);
   uint32 res = 0;
   
+  BEGIN_NATIVE_EXCEPTION(1)
+    
   UserCommonClass* cl = 0;
   const UTF8* utf8 = 0;
   Signdef* sign = 0;
@@ -142,6 +173,8 @@
 
   res = dmeth->offset;
 
+  END_NATIVE_EXCEPTION
+
   return res;
 }
 
@@ -150,6 +183,8 @@
   
   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
@@ -167,20 +202,50 @@
       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) {
-  return cl->getClassDelegatee(JavaThread::get()->getJVM());
+  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;
 }
 
 // Throws if one of the dimension is negative.
@@ -222,6 +287,8 @@
   JavaObject* res = 0;
   llvm_gcroot(res, 0);
 
+  BEGIN_NATIVE_EXCEPTION(1)
+
   va_list ap;
   va_start(ap, len);
   mvm::ThreadAllocator allocator;
@@ -232,6 +299,8 @@
   Jnjvm* vm = JavaThread::get()->getJVM();
   res = multiCallNewIntern(cl, len, dims, vm);
 
+  END_NATIVE_EXCEPTION
+
   return res;
 }
 
@@ -241,6 +310,7 @@
                                              JavaVirtualTable** VT) {
   JavaVirtualTable* res = 0;
   assert(VT && "Incorrect call to j3GetArrayClass");
+  BEGIN_NATIVE_EXCEPTION(1)
   
   UserConstantPool* ctpInfo = caller->getConstantPool();
   UserCommonClass* cl = ctpInfo->loadClass(index);
@@ -252,6 +322,13 @@
   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;
 }
 
@@ -300,47 +377,144 @@
   JavaObject::release(obj);
 }
 
+// Does not call any Java code. Can not yield a GC.
 extern "C" void j3ThrowException(JavaObject* obj) {
   llvm_gcroot(obj, 0);
-  JavaThread::get()->throwException(obj);
-  UNREACHABLE();
+  return JavaThread::get()->throwException(obj);
 }
 
+// Creates a Java object and then throws it.
 extern "C" JavaObject* j3NullPointerException() {
-  return JavaThread::get()->getJVM()->CreateNullPointerException();
+  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;
 }
 
+// Creates a Java object and then throws it.
 extern "C" JavaObject* j3NegativeArraySizeException(sint32 val) {
-  return JavaThread::get()->getJVM()->CreateNegativeArraySizeException();
+  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;
 }
 
+// Creates a Java object and then throws it.
 extern "C" JavaObject* j3OutOfMemoryError(sint32 val) {
-  return JavaThread::get()->getJVM()->CreateOutOfMemoryError();
+  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;
 }
 
+// Creates a Java object and then throws it.
 extern "C" JavaObject* j3StackOverflowError() {
-  return JavaThread::get()->getJVM()->CreateStackOverflowError();
+  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;
 }
 
+// Creates a Java object and then throws it.
 extern "C" JavaObject* j3ArithmeticException() {
-  return JavaThread::get()->getJVM()->CreateArithmeticException();
+  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;
 }
 
+// Creates a Java object and then throws it.
 extern "C" JavaObject* j3ClassCastException(JavaObject* obj,
                                             UserCommonClass* cl) {
-  llvm_gcroot(obj, 0);  
-  return JavaThread::get()->getJVM()->CreateClassCastException(obj, 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;
 }
 
+// Creates a Java object and then throws it.
 extern "C" JavaObject* j3IndexOutOfBoundsException(JavaObject* obj,
                                                    sint32 index) {
+  JavaObject *exc = 0;
   llvm_gcroot(obj, 0);
-  return JavaThread::get()->getJVM()->CreateIndexOutOfBoundsException(index);
+  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;
 }
 
+// Creates a Java object and then throws it.
 extern "C" JavaObject* j3ArrayStoreException(JavaVirtualTable* VT,
                                              JavaVirtualTable* VT2) {
-  return JavaThread::get()->getJVM()->CreateArrayStoreException(VT);
+  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;
 }
 
 // Create an exception then throws it.
@@ -348,18 +522,30 @@
   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);
-  j3ThrowException(exc);
+
+  END_NATIVE_EXCEPTION
+
+  th->pendingException = 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;
 }
 
@@ -369,6 +555,8 @@
   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.
@@ -422,12 +610,16 @@
     }
   }
 
+  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);
@@ -455,12 +647,16 @@
   // 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);
@@ -496,6 +692,8 @@
   // 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=143293&r1=143292&r2=143293&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaThread.h (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaThread.h Sat Oct 29 15:30:33 2011
@@ -28,8 +28,14 @@
 class Jnjvm;
 
 
-#define BEGIN_NATIVE_EXCEPTION(level)
-#define END_NATIVE_EXCEPTION
+#define BEGIN_NATIVE_EXCEPTION(level) \
+  JavaThread* __th = JavaThread::get(); \
+  TRY {
+
+#define END_NATIVE_EXCEPTION \
+  } CATCH { \
+    __th->throwFromNative(); \
+  } END_CATCH;
 
 #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=143293&r1=143292&r2=143293&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/Compiler/JIT.cpp (original)
+++ vmkit/trunk/lib/Mvm/Compiler/JIT.cpp Sat Oct 29 15:30:33 2011
@@ -367,10 +367,6 @@
   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=143293&r1=143292&r2=143293&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/Compiler/LLVMRuntime.ll (original)
+++ vmkit/trunk/lib/Mvm/Compiler/LLVMRuntime.ll Sat Oct 29 15:30:33 2011
@@ -68,9 +68,3 @@
 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=143293&r1=143292&r2=143293&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/Runtime/Object.cpp (original)
+++ vmkit/trunk/lib/Mvm/Runtime/Object.cpp Sat Oct 29 15:30:33 2011
@@ -38,14 +38,6 @@
 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