[vmkit-commits] [vmkit] r134154 - in /vmkit/trunk: Makefile.common.in autoconf/configure.ac configure include/mvm/Threads/Thread.h lib/J3/Compiler/ExceptionsCheck.inc lib/J3/Compiler/ExceptionsDwarf.inc lib/J3/Compiler/JavaJIT.cpp lib/J3/VMCore/JavaMetaJIT.cpp lib/J3/VMCore/JavaRuntimeJIT.cpp lib/J3/VMCore/JavaThread.h lib/Mvm/CommonThread/ctthread.cpp lib/Mvm/Compiler/JIT.cpp

Nicolas Geoffray nicolas.geoffray at lip6.fr
Thu Jun 30 07:16:56 PDT 2011


Author: geoffray
Date: Thu Jun 30 09:16:56 2011
New Revision: 134154

URL: http://llvm.org/viewvc/llvm-project?rev=134154&view=rev
Log:
Remove support for dwarf exceptions.


Removed:
    vmkit/trunk/lib/J3/Compiler/ExceptionsCheck.inc
    vmkit/trunk/lib/J3/Compiler/ExceptionsDwarf.inc
Modified:
    vmkit/trunk/Makefile.common.in
    vmkit/trunk/autoconf/configure.ac
    vmkit/trunk/configure
    vmkit/trunk/include/mvm/Threads/Thread.h
    vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp
    vmkit/trunk/lib/J3/VMCore/JavaMetaJIT.cpp
    vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp
    vmkit/trunk/lib/J3/VMCore/JavaThread.h
    vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp
    vmkit/trunk/lib/Mvm/Compiler/JIT.cpp

Modified: vmkit/trunk/Makefile.common.in
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/Makefile.common.in?rev=134154&r1=134153&r2=134154&view=diff
==============================================================================
--- vmkit/trunk/Makefile.common.in (original)
+++ vmkit/trunk/Makefile.common.in Thu Jun 30 09:16:56 2011
@@ -25,7 +25,7 @@
 # Include LLVM's Master Makefile.
 include $(LLVM_OBJ_ROOT)/Makefile.common
 
-CXX.Flags += @GC_FLAGS@ @EXCEPTION_FLAGS@ -Wno-variadic-macros -fno-omit-frame-pointer -fno-strict-aliasing -Wno-deprecated -ansi -DENABLE_THREADS -fno-rtti
+CXX.Flags += @GC_FLAGS@ -fno-exceptions -Wno-variadic-macros -fno-omit-frame-pointer -fno-strict-aliasing -Wno-deprecated -ansi -DENABLE_THREADS -fno-rtti
 
 # GNU Classpath flags
 CLASSPATH_FLAGS = @classpathinclude@

Modified: vmkit/trunk/autoconf/configure.ac
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/autoconf/configure.ac?rev=134154&r1=134153&r2=134154&view=diff
==============================================================================
--- vmkit/trunk/autoconf/configure.ac (original)
+++ vmkit/trunk/autoconf/configure.ac Thu Jun 30 09:16:56 2011
@@ -180,43 +180,6 @@
 AC_SUBST([MMTK_PLAN])
 
 dnl **************************************************************************
-dnl Exception type
-dnl **************************************************************************
-AC_ARG_WITH(exception-type,
-       [AS_HELP_STRING(--with-exception-type=something,
-           [Exception type ('check' or 'dwarf')])],
-       [[exceptiontype=$withval]],
-       [[ echo Using check as exception type.
-                exceptiontype=check
-       ]]
-)
-
-AC_ARG_WITH(runtime-exception-type,
-       [AS_HELP_STRING(--with-runtime-exception-type=something,
-           [Runtime exception type ('setjmp' or 'dwarf')])],
-       [[runtimeexceptiontype=$withval]],
-       [[ echo Using setjmp as exception type.
-                exceptiontype=setjmp
-       ]]
-)
-
-if test "x$exceptiontype" = "xdwarf";  then
-  EXCEPTION_FLAGS="-DDWARF_EXCEPTIONS -fexceptions"
-fi
-
-if test "x$runtimeexceptiontype" = "xdwarf";  then
-  EXCEPTION_FLAGS+="-DRUNTIME_DWARF_EXCEPTIONS -fexceptions"
-fi
-
-if test "x$runtimeexceptiontype" != "xdwarf"; then
-  if test "x$exceptiontype" != "xdwarf"; then
-    EXCEPTION_FLAGS="-fno-exceptions"
-  fi
-fi
-
-AC_SUBST([EXCEPTION_FLAGS])
-
-dnl **************************************************************************
 dnl GNU CLASSPATH installation prefix
 dnl **************************************************************************
 

Modified: vmkit/trunk/configure
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/configure?rev=134154&r1=134153&r2=134154&view=diff
==============================================================================
--- vmkit/trunk/configure (original)
+++ vmkit/trunk/configure Thu Jun 30 09:16:56 2011
@@ -646,7 +646,6 @@
 classpathinclude
 classpathlibs
 classpathglibj
-EXCEPTION_FLAGS
 MMTK_PLAN
 GC_FLAGS
 WITH_64
@@ -710,8 +709,6 @@
 with_llvmsrc
 with_llvmobj
 with_mmtk_plan
-with_exception_type
-with_runtime_exception_type
 with_gnu_classpath_libs
 with_gnu_classpath_glibj
 with_j3
@@ -1350,10 +1347,6 @@
   --with-llvmobj          Location of LLVM Object Code
   --with-mmtk-plan=something
                           MMTk plan type ('org.mmtk.plan.marksweep.MS')
-  --with-exception-type=something
-                          Exception type ('check' or 'dwarf')
-  --with-runtime-exception-type=something
-                          Runtime exception type ('setjmp' or 'dwarf')
   --with-gnu-classpath-libs=something
                           GNU CLASSPATH libraries (default is
                           /usr/lib/classpath)
@@ -2545,46 +2538,6 @@
 
 
 
-# Check whether --with-exception-type was given.
-if test "${with_exception_type+set}" = set; then :
-  withval=$with_exception_type; exceptiontype=$withval
-else
-   echo Using check as exception type.
-                exceptiontype=check
-
-
-fi
-
-
-
-# Check whether --with-runtime-exception-type was given.
-if test "${with_runtime_exception_type+set}" = set; then :
-  withval=$with_runtime_exception_type; runtimeexceptiontype=$withval
-else
-   echo Using setjmp as exception type.
-                exceptiontype=setjmp
-
-
-fi
-
-
-if test "x$exceptiontype" = "xdwarf";  then
-  EXCEPTION_FLAGS="-DDWARF_EXCEPTIONS -fexceptions"
-fi
-
-if test "x$runtimeexceptiontype" = "xdwarf";  then
-  EXCEPTION_FLAGS+="-DRUNTIME_DWARF_EXCEPTIONS -fexceptions"
-fi
-
-if test "x$runtimeexceptiontype" != "xdwarf"; then
-  if test "x$exceptiontype" != "xdwarf"; then
-    EXCEPTION_FLAGS="-fno-exceptions"
-  fi
-fi
-
-
-
-
 classpathversion=0.97.2;
 
 

Modified: vmkit/trunk/include/mvm/Threads/Thread.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Threads/Thread.h?rev=134154&r1=134153&r2=134154&view=diff
==============================================================================
--- vmkit/trunk/include/mvm/Threads/Thread.h (original)
+++ vmkit/trunk/include/mvm/Threads/Thread.h Thu Jun 30 09:16:56 2011
@@ -17,22 +17,15 @@
 #include "debug.h"
 #include "types.h"
 
-#ifdef RUNTIME_DWARF_EXCEPTIONS
-  #define TRY try
-  #define CATCH catch(...)
-  #define IGNORE catch(...) { mvm::Thread::get()->clearException(); }
-  #define END_CATCH
+#include <csetjmp>
+#if defined(__MACH__)
+  #define TRY { mvm::ExceptionBuffer __buffer__; if (!_setjmp(__buffer__.buffer))
 #else
-  #include <csetjmp>
-  #if defined(__MACH__)
-    #define TRY { mvm::ExceptionBuffer __buffer__; if (!_setjmp(__buffer__.buffer))
-  #else
-    #define TRY { mvm::ExceptionBuffer __buffer__; if (!setjmp(__buffer__.buffer))
-  #endif
-  #define CATCH else
-  #define IGNORE else { mvm::Thread::get()->clearException(); }}
-  #define END_CATCH }
+  #define TRY { mvm::ExceptionBuffer __buffer__; if (!setjmp(__buffer__.buffer))
 #endif
+#define CATCH else
+#define IGNORE else { mvm::Thread::get()->clearException(); }}
+#define END_CATCH }
 
 namespace mvm {
 
@@ -146,12 +139,8 @@
 class Thread : public CircularBase {
 public:
   Thread() {
-#ifdef RUNTIME_DWARF_EXCEPTIONS
-  internalPendingException = 0;
-#else
-  lastExceptionBuffer = 0;
-#endif
-  lastKnownFrame = 0;
+    lastExceptionBuffer = 0;
+    lastKnownFrame = 0;
   }
 
   /// yield - Yield the processor to another thread.
@@ -251,9 +240,6 @@
 
   /// clearException - Clear any pending exception of the current thread.
   void clearException() {
-#ifdef RUNTIME_DWARF_EXCEPTIONS
-    internalPendingException = 0;
-#endif
     internalClearException();
   }
 
@@ -325,13 +311,9 @@
   ///
   KnownFrame* lastKnownFrame;
   
-#ifdef RUNTIME_DWARF_EXCEPTIONS
-  void* internalPendingException;
-#else
   /// lastExceptionBuffer - The last exception buffer on this thread's stack.
   ///
   ExceptionBuffer* lastExceptionBuffer;
-#endif
 
   void internalThrowException();
 
@@ -341,7 +323,6 @@
   void endUnknownFrame();
 };
 
-#ifndef RUNTIME_DWARF_EXCEPTIONS
 class ExceptionBuffer {
 public:
   ExceptionBuffer() {
@@ -358,7 +339,6 @@
   ExceptionBuffer* previousBuffer;
   jmp_buf buffer;
 };
-#endif
 
 /// StackWalker - This class walks the stack of threads, returning a MethodInfo
 /// object at each iteration.

Removed: vmkit/trunk/lib/J3/Compiler/ExceptionsCheck.inc
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/ExceptionsCheck.inc?rev=134153&view=auto
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/ExceptionsCheck.inc (original)
+++ vmkit/trunk/lib/J3/Compiler/ExceptionsCheck.inc (removed)
@@ -1,542 +0,0 @@
-Instruction* JavaJIT::invoke(Value *F, std::vector<llvm::Value*>& args,
-                       const char* Name,
-                       BasicBlock *InsertAtEnd) {
-  
-  Instruction* res = CallInst::Create(F, args.begin(), args.end(), Name,
-                                      InsertAtEnd);
-  DebugLoc DL = CreateLocation();
-  res->setDebugLoc(DL);
-  
-  if (TheCompiler->hasExceptionsEnabled()) {
-    Value* javaExceptionPtr = getJavaExceptionPtr(getJavaThreadPtr(getMutatorThreadPtr()));
-    
-    // Get the Java exception.
-    Value* obj = 0;
-    
-    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, "", TheCompiler->useCooperativeGC(), 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()) {
-      Instruction* insn = currentExceptionBlock->begin();
-      PHINode* node = dyn_cast<PHINode>(insn);
-      if (node) node->addIncoming(obj, currentBlock);
-    }
-  
-    currentBlock = ifNormal; 
-  }
-
-  return res;
-}
-
-Instruction* JavaJIT::invoke(Value *F, Value* arg1, const char* Name,
-                       BasicBlock *InsertAtEnd) {
-
-  Instruction* res = CallInst::Create(F, arg1, Name, InsertAtEnd);
-  DebugLoc DL = CreateLocation();
-  res->setDebugLoc(DL);
-  
-  if (TheCompiler->hasExceptionsEnabled()) {
-    Value* javaExceptionPtr = getJavaExceptionPtr(getJavaThreadPtr(getMutatorThreadPtr()));
-    
-    // Get the Java exception.
-    Value* obj = 0;
-    
-    BasicBlock* ifNormal = createBasicBlock("no exception block");
-  
-    Value* test = 0;
-    Constant* zero = intrinsics->JavaObjectNullConstant;
-    if (F == intrinsics->InitialisationCheckFunction || 
-        F == intrinsics->GetConstantPoolAtFunction ||
-        F == intrinsics->GetArrayClassFunction ||
-        F == intrinsics->GetClassDelegateeFunction) {
-      obj = new LoadInst(javaExceptionPtr, "", TheCompiler->useCooperativeGC(), 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()) {
-      Instruction* insn = currentExceptionBlock->begin();
-      PHINode* node = dyn_cast<PHINode>(insn);
-      if (node) node->addIncoming(obj, currentBlock);
-    }
-  
-    currentBlock = ifNormal;
-  }
-
-  return res;
-}
-
-Instruction* JavaJIT::invoke(Value *F, Value* arg1, Value* arg2,
-                       const char* Name, BasicBlock *InsertAtEnd) {
-
-  Value* args[2] = { arg1, arg2 };
-  
-  Instruction* res = CallInst::Create(F, args, args + 2, Name, InsertAtEnd);
-  DebugLoc DL = CreateLocation();
-  res->setDebugLoc(DL);
-  
-  if (TheCompiler->hasExceptionsEnabled()) {
-    Value* javaExceptionPtr = getJavaExceptionPtr(getJavaThreadPtr(getMutatorThreadPtr()));
-    
-    // Get the Java exception.
-    Value* obj = 0;
-    
-    BasicBlock* ifNormal = createBasicBlock("no exception block");
-    
-    Value* test = 0;
-    Constant* zero = intrinsics->JavaObjectNullConstant;
-    if (F == intrinsics->InitialisationCheckFunction || 
-        F == intrinsics->GetConstantPoolAtFunction ||
-        F == intrinsics->GetArrayClassFunction ||
-        F == intrinsics->GetClassDelegateeFunction) {
-      obj = new LoadInst(javaExceptionPtr, "", TheCompiler->useCooperativeGC(), 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()) {
-      Instruction* insn = currentExceptionBlock->begin();
-      PHINode* node = dyn_cast<PHINode>(insn);
-      if (node) node->addIncoming(obj, currentBlock);
-    }
-
-    currentBlock = ifNormal;
-  }
-
-  return res;
-}
-
-Instruction* JavaJIT::invoke(Value *F, const char* Name,
-                       BasicBlock *InsertAtEnd) {
-  Instruction* res = llvm::CallInst::Create(F, Name, InsertAtEnd);
-  DebugLoc DL = CreateLocation();
-  res->setDebugLoc(DL);
-  
-  if (TheCompiler->hasExceptionsEnabled()) {
-    Value* javaExceptionPtr = getJavaExceptionPtr(getJavaThreadPtr(getMutatorThreadPtr()));
-    
-    // Get the Java exception.
-    Value* obj = 0;
-    
-    BasicBlock* ifNormal = createBasicBlock("no exception block");
-  
-    Value* test = 0;
-    Constant* zero = intrinsics->JavaObjectNullConstant;
-    if (F == intrinsics->InitialisationCheckFunction || 
-        F == intrinsics->GetConstantPoolAtFunction ||
-        F == intrinsics->GetArrayClassFunction ||
-        F == intrinsics->GetClassDelegateeFunction) {
-      obj = new LoadInst(javaExceptionPtr, "", TheCompiler->useCooperativeGC(), 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()) {
-      Instruction* insn = currentExceptionBlock->begin();
-      PHINode* node = dyn_cast<PHINode>(insn);
-      if (node) node->addIncoming(obj, currentBlock);
-    }
-
-    currentBlock = ifNormal;
-  }
-
-  return res;
-}
-
-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::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::throwException(llvm::Function* F, Value** args,
-                             uint32 nbArgs) {
-  Instruction* obj = CallInst::Create(F, args, 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);
-  }
-}
-
-/// Handler - This class represents an exception handler. It is only needed
-/// when parsing the .class file in the JIT, therefore it is only defined
-/// here. The readExceptionTable function is the only function that makes
-/// use of this class.
-struct Handler {
-  
-  /// startpc - The bytecode number that begins the try clause.
-  uint32 startpc;
-
-  /// endpc - The bytecode number that ends the try clause.
-  uint32 endpc;
-
-  /// handlerpc - The bytecode number where the handler code starts.
-  uint32 handlerpc;
-
-  /// catche - Index in the constant pool of the exception class.
-  uint16 catche;
-
-  /// catchClass - The class of the exception: it must always be loaded before
-  /// reading the exception table so that we do not throw an exception
-  /// when compiling.
-  UserClass* catchClass;
-
-  /// tester - The basic block that tests if the exception is handled by this
-  /// handler. If the handler is not the first of a list of handlers with the
-  /// same range, than this block is the catcher block. Otherwise, it is the
-  /// destination of the catcher block and of the handlers that do not handler
-  /// the exception.
-  llvm::BasicBlock* tester;
-
-  /// javaHandler - The Java code that handles the exception. At this point, we
-  /// know we have caught and are handling the exception. The Java exception
-  /// object is the PHI node that begins this block.
-  llvm::BasicBlock* javaHandler;
-
-};
-
-unsigned JavaJIT::readExceptionTable(Reader& reader, uint32 codeLen) {
-
-  // This function uses currentBlock to simplify things. We save the current
-  // value of currentBlock to restore it at the end of the function
-  BasicBlock* temp = currentBlock;
-  
-  sint16 nbe = reader.readU2();
-  sint16 sync = isSynchro(compilingMethod->access) ? 1 : 0;
-  nbe += sync;
- 
-  mvm::ThreadAllocator allocator;
-  // Loop over all handlers in the bytecode to initialize their values.
-  Handler* handlers =
-      (Handler*)allocator.Allocate(sizeof(Handler) * (nbe - sync));
-  for (uint16 i = 0; i < nbe - sync; ++i) {
-    Handler* ex   = &handlers[i];
-    ex->startpc   = reader.readU2();
-    ex->endpc     = reader.readU2();
-    ex->handlerpc = reader.readU2();
-
-    ex->catche = reader.readU2();
-
-#ifndef ISOLATE_SHARING
-    if (ex->catche) {
-      UserClass* cl = 
-        (UserClass*)(compilingClass->ctpInfo->isClassLoaded(ex->catche));
-      // When loading the class, we made sure that all exception classes
-      // were loaded, so cl must have a value.
-      assert(cl && "exception class has not been loaded");
-      ex->catchClass = cl;
-    } else {
-      ex->catchClass = Classpath::newThrowable;
-    }
-#endif
-    
-    ex->tester = createBasicBlock("testException");
-    
-    // PHI Node for the exception object
-    PHINode::Create(intrinsics->JavaObjectType, 0, "", ex->tester);
-    
-    // Set the unwind destination of the instructions in the range of this
-    // handler to the test block of the handler. If an instruction already has
-    // a handler and thus is not the synchronize or regular end handler block,
-    // leave it as-is.
-    for (uint16 i = ex->startpc; i < ex->endpc; ++i) {
-      if (opcodeInfos[i].exceptionBlock == endExceptionBlock) {
-        opcodeInfos[i].exceptionBlock = ex->tester;
-      }
-    }
-
-    // If the handler pc does not already have a block, create a new one.
-    if (!(opcodeInfos[ex->handlerpc].newBlock)) {
-      opcodeInfos[ex->handlerpc].newBlock = createBasicBlock("javaHandler");
-    }
-    
-    // Set the Java handler for this exception.
-    ex->javaHandler = opcodeInfos[ex->handlerpc].newBlock;
-    opcodeInfos[ex->handlerpc].handler = true;
-    
-    if (ex->javaHandler->empty()) {
-      PHINode::Create(intrinsics->JavaObjectType, 0, "", ex->javaHandler);
-    }
-
-  }
-
-  // Loop over all handlers to implement their tester.
-  for (sint16 i = 0; i < nbe - sync; ++i) {
-    Handler* cur = &handlers[i];
-    BasicBlock* bbNext = 0;
-    PHINode* javaNode = 0;
-    currentExceptionBlock = opcodeInfos[cur->handlerpc].exceptionBlock;
-
-    // Look out where we go if we're not the handler for the exception.
-    if (i + 1 != nbe - sync) {
-      Handler* next = &handlers[i + 1];
-      if (!(cur->startpc >= next->startpc && cur->endpc <= next->endpc)) {
-        // If there is no handler to go to (either one that has the same range
-        // or one that contains the range), then we jump to the end handler.
-        bbNext = endExceptionBlock;
-      } else {
-        // If there's a handler to goto, we jump to its tester block and record
-        // the exception PHI node to give our exception to the tester.
-        bbNext = next->tester;
-        javaNode = dyn_cast<PHINode>(bbNext->begin());
-        assert(javaNode);
-      }
-    } else {
-      // If there's no handler after us, we jump to the end handler.
-      bbNext = endExceptionBlock;
-    }
-
-    currentBlock = cur->tester;
-    
-    assert(cur->catchClass && 
-           "Class not loaded when reading the exception table");
-
-    Value* VTVar = TheCompiler->getVirtualTable(cur->catchClass->virtualVT);
-
-    
-#ifdef SERVICE
-    // Verifies that the current isolate is not stopped. If it is, we don't
-    // catch the exception but resume unwinding.
-    JnjvmClassLoader* loader = compilingClass->classLoader;;
-    if (loader != loader->bootstrapLoader) {
-      Value* Isolate = getVMPtr(getMutatorThread());
-     
-      Isolate = new LoadInst(Isolate, "", currentBlock);
-      Isolate = new BitCastInst(Isolate, intrinsics->ptrPtrType, "", currentBlock);
-      Value* Status = GetElementPtrInst::Create(Isolate, intrinsics->constantOne, "",
-                                                currentBlock);
-      Status = new LoadInst(Status, "", currentBlock);
-      Status = new PtrToIntInst(Status, Type::Int32Ty, "", currentBlock);
-  
-      Value* stopping = new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, Status,
-                                     intrinsics->constantOne, "");
-
-      BasicBlock* raiseBlock = createBasicBlock("raiseBlock");
-      BasicBlock* continueBlock = createBasicBlock("continueBlock");
-      BranchInst::Create(raiseBlock, continueBlock, stopping, currentBlock);
-      currentBlock = raiseBlock;
-      BranchInst::Create(endExceptionBlock, currentBlock); 
-
-      currentBlock = continueBlock;
-    }
-#endif
-    
-    // Get the Java exception.
-    Value* obj = currentBlock->begin();
-    
-    Value* objVT = CallInst::Create(intrinsics->GetVTFunction, obj, "",
-                                    currentBlock);
-
-    uint32 depth = cur->catchClass->virtualVT->depth;
-    Value* depthCl = ConstantInt::get(Type::getInt32Ty(*llvmContext), depth);
-    Value* cmp = 0;
-
-    if (depth >= JavaVirtualTable::getDisplayLength()) {
-      Value* classArgs[2] = { objVT, VTVar };
-          
-      cmp = CallInst::Create(intrinsics->IsSecondaryClassFunction,
-                             classArgs, classArgs + 2, "",
-                             currentBlock);
-
-    } else {
-     
-      Value* inDisplay = CallInst::Create(intrinsics->GetDisplayFunction,
-                                          objVT, "", currentBlock);
-            
-      Value* displayArgs[2] = { inDisplay, depthCl };
-      Value* VTInDisplay = CallInst::Create(intrinsics->GetVTInDisplayFunction,
-                                            displayArgs, displayArgs + 2, "",
-                                            currentBlock);
-             
-      cmp = new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, VTInDisplay, VTVar,
-                         "");
-    }
-   
-    // Add the Java exception in the phi node of the handler.
-    Instruction* insn = cur->javaHandler->begin();
-    PHINode* node = dyn_cast<PHINode>(insn);
-    assert(node && "malformed exceptions");
-    node->addIncoming(obj, currentBlock);
-   
-    // Add the Java exception in the phi node of the next block.
-    if (javaNode)
-      javaNode->addIncoming(obj, currentBlock);
- 
-    // If we are catching this exception, then jump to the Java Handler,
-    // otherwise jump to our next handler.
-    BranchInst::Create(cur->javaHandler, bbNext, cmp, currentBlock);
-
-    currentBlock = cur->javaHandler;
-
-    // First thing in the handler: clear the exception.
-    Value* javaExceptionPtr = getJavaExceptionPtr(getJavaThreadPtr(getMutatorThreadPtr()));
-    
-    // Clear exceptions.
-    new StoreInst(intrinsics->JavaObjectNullConstant, javaExceptionPtr,
-                  currentBlock);
-
-#if defined(SERVICE)
-
-    // Change the isolate we are currently running, now that we have catched
-    // the exception: the exception may have been thrown by another isolate.
-    Value* mutatorThreadId = 0;
-    Value* OldIsolateID = 0;
-    Value* IsolateIDPtr = 0;
-    Value* OldIsolate = 0;
-    Value* NewIsolate = 0;
-    Value* IsolatePtr = 0;
-    currentBlock = cur->javaHandler;
-    if (loader != loader->bootstrapLoader) {
-      mutatorThreadId = getGetMutatorThreadPtr();
-      IsolateIDPtr = getIsolateIDPtr(mutatorThreadId);
-      const Type* realType = PointerType::getUnqual(intrinsics->pointerSizeType);
-      IsolateIDPtr = new BitCastInst(IsolateIDPtr, realType, "",
-                                     currentBlock);
-      OldIsolateID = new LoadInst(IsolateIDPtr, "", currentBlock);
-
-      Value* MyID = ConstantInt::get(intrinsics->pointerSizeType,
-                                     loader->getIsolate()->IsolateID);
-
-      new StoreInst(MyID, IsolateIDPtr, currentBlock);
-      IsolatePtr = getVMPtr(mutatorThreadPtr);
-     
-      OldIsolate = new LoadInst(IsolatePtr, "", currentBlock);
-      NewIsolate = intrinsics->getIsolate(loader->getIsolate(), currentBlock);
-      new StoreInst(NewIsolate, IsolatePtr, currentBlock);
-
-    }
-#endif
-     
-  }
- 
-  // Restore currentBlock.
-  currentBlock = temp;
-  return nbe;
-}
-
-void JavaJIT::finishExceptions() {
-  pred_iterator PI = pred_begin(endExceptionBlock);
-  pred_iterator PE = pred_end(endExceptionBlock);
-  if (PI == PE) {
-    endExceptionBlock->eraseFromParent();
-  } else {
-    if (endNode) {
-      endNode->addIncoming(Constant::getNullValue(endNode->getType()),
-                           endExceptionBlock);
-    }
-    BranchInst::Create(endBlock, endExceptionBlock);
-  }
- 
-
-  PI = pred_begin(unifiedUnreachable);
-  PE = pred_end(unifiedUnreachable);
-  if (PI == PE) {
-    unifiedUnreachable->eraseFromParent();
-  } else {
-    new UnreachableInst(*llvmContext, unifiedUnreachable);
-  }
-  
-  for (Function::iterator BI = llvmFunction->begin(), BE = llvmFunction->end();
-       BI != BE; BI++) {
-    PI = pred_begin(BI);
-    PE = pred_end(BI);
-    if (PI == PE) {
-      Instruction* insn = BI->begin();
-      PHINode* node = dyn_cast<PHINode>(insn);
-      if (node) {
-        node->replaceAllUsesWith(Constant::getNullValue(node->getType()));
-        node->eraseFromParent();
-      }
-    }
-  }
-
-}

Removed: vmkit/trunk/lib/J3/Compiler/ExceptionsDwarf.inc
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/ExceptionsDwarf.inc?rev=134153&view=auto
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/ExceptionsDwarf.inc (original)
+++ vmkit/trunk/lib/J3/Compiler/ExceptionsDwarf.inc (removed)
@@ -1,561 +0,0 @@
-Instruction* JavaJIT::invoke(Value *F, std::vector<llvm::Value*>& args,
-                       const char* Name,
-                       BasicBlock *InsertAtEnd) {
-  
-  // means: is there a handler for me?
-  if (currentExceptionBlock != endExceptionBlock) {
-    BasicBlock* ifNormal = createBasicBlock("no exception block");
-    currentBlock = ifNormal;
-    return llvm::InvokeInst::Create(F, ifNormal, currentExceptionBlock,
-                                    args.begin(), 
-                                    args.end(), Name, InsertAtEnd);
-  } else {
-    return llvm::CallInst::Create(F, args.begin(), args.end(), Name, InsertAtEnd);
-  }
-}
-
-Instruction* JavaJIT::invoke(Value *F, Value* arg1, const char* Name,
-                       BasicBlock *InsertAtEnd) {
-
-  // means: is there a handler for me?
-  if (currentExceptionBlock != endExceptionBlock) {
-    BasicBlock* ifNormal = createBasicBlock("no exception block");
-    currentBlock = ifNormal;
-    Value* arg[1] = { arg1 };
-    return InvokeInst::Create(F, ifNormal, currentExceptionBlock,
-                              arg, arg + 1, Name, InsertAtEnd);
-  } else {
-    return CallInst::Create(F, arg1, Name, InsertAtEnd);
-  }
-}
-
-Instruction* JavaJIT::invoke(Value *F, Value* arg1, Value* arg2,
-                       const char* Name, BasicBlock *InsertAtEnd) {
-
-  Value* args[2] = { arg1, arg2 };
-  
-  // means: is there a handler for me?
-  if (currentExceptionBlock != endExceptionBlock) {
-    BasicBlock* ifNormal = createBasicBlock("no exception block");
-    currentBlock = ifNormal;
-    return InvokeInst::Create(F, ifNormal, currentExceptionBlock,
-                              args, args + 2, Name, InsertAtEnd);
-  } else {
-    return CallInst::Create(F, args, args + 2, Name, InsertAtEnd);
-  }
-}
-
-Instruction* JavaJIT::invoke(Value *F, const char* Name,
-                       BasicBlock *InsertAtEnd) {
-  // means: is there a handler for me?
-  if (currentExceptionBlock != endExceptionBlock) {
-    BasicBlock* ifNormal = createBasicBlock("no exception block");
-    currentBlock = ifNormal;
-    Value* args[1];
-    return llvm::InvokeInst::Create(F, ifNormal, currentExceptionBlock,
-                                    args, args, Name,
-                                    InsertAtEnd);
-  } else {
-    return llvm::CallInst::Create(F, Name, InsertAtEnd);
-  }
-}
-
-void JavaJIT::throwException(llvm::Function* F, Value* arg1) {
-  if (currentExceptionBlock != endExceptionBlock) {
-    Value* exArgs[1] = { arg1 };
-    InvokeInst::Create(F, unifiedUnreachable,
-                       currentExceptionBlock, exArgs, exArgs + 1,
-                       "", currentBlock);
-  } else {
-    CallInst::Create(F, arg1, "", currentBlock);
-    new UnreachableInst(currentBlock);
-  }
-}
-
-void JavaJIT::throwException(Value* obj) {
-  Function* F = module->ThrowExceptionFunction;
-  if (currentExceptionBlock != endExceptionBlock) {
-    Value* exArgs[1] = { obj };
-    InvokeInst::Create(F, unifiedUnreachable,
-                       currentExceptionBlock, exArgs, exArgs + 1,
-                       "", currentBlock);
-  } else {
-    CallInst::Create(F, obj, "", currentBlock);
-    new UnreachableInst(currentBlock);
-  }
-}
-
-void JavaJIT::throwException(llvm::Function* F, Value** args,
-                             uint32 nbArgs) {
-  if (currentExceptionBlock != endExceptionBlock) {
-    InvokeInst::Create(F, unifiedUnreachable,
-                       currentExceptionBlock, args, args + nbArgs,
-                       "", currentBlock);
-  } else {
-    CallInst::Create(F, args, args + nbArgs, "", currentBlock);
-    new UnreachableInst(currentBlock);
-  }
-}
-
-/// Handler - This class represents an exception handler. It is only needed
-/// when parsing the .class file in the JIT, therefore it is only defined
-/// here. The readExceptionTable function is the only function that makes
-/// use of this class.
-struct Handler {
-  
-  /// startpc - The bytecode number that begins the try clause.
-  uint32 startpc;
-
-  /// endpc - The bytecode number that ends the try clause.
-  uint32 endpc;
-
-  /// handlerpc - The bytecode number where the handler code starts.
-  uint32 handlerpc;
-
-  /// catche - Index in the constant pool of the exception class.
-  uint16 catche;
-
-  /// catchClass - The class of the exception: it must always be loaded before
-  /// reading the exception table so that we do not throw an exception
-  /// when compiling.
-  UserClass* catchClass;
-
-  /// catcher - The basic block that catches the exception. The catcher deals
-  /// with LLVM codegen and declares the llvm.select method. This block is the
-  /// destination of invoke instructions that are in the try clause.
-  llvm::BasicBlock* catcher;
-
-  /// tester - The basic block that tests if the exception is handled by this
-  /// handler. If the handler is not the first of a list of handlers with the
-  /// same range, than this block is the catcher block. Otherwise, it is the
-  /// destination of the catcher block and of the handlers that do not handler
-  /// the exception.
-  llvm::BasicBlock* tester;
-
-  /// javaHandler - The Java code that handles the exception. At this point, we
-  /// know we have caught and are handling the exception. The Java exception
-  /// object is the PHI node that begins this block.
-  llvm::BasicBlock* javaHandler;
-
-  /// nativeHandler - The CXX exception-related code that handles the exception.
-  /// The block clears the exception from the execution environment, calls
-  /// the CXX begin and end catch methods and jumps to the Java handler.
-  llvm::BasicBlock* nativeHandler;
-
-  /// exceptionPHI - The CXX exception object for the tester block. The
-  /// tester has incoming blocks, either from the catcher or from other
-  /// handlers that don't handle the exception. Therefore each incoming block
-  /// specifies the CXX exception object that was caught.
-  llvm::PHINode* exceptionPHI;
-};
-
-unsigned JavaJIT::readExceptionTable(Reader& reader, uint32 codeLen) {
-
-  // This function uses currentBlock to simplify things. We save the current
-  // value of currentBlock to restore it at the end of the function
-  BasicBlock* temp = currentBlock;
-  
-  sint16 nbe = reader.readU2();
-  sint16 sync = isSynchro(compilingMethod->access) ? 1 : 0;
-  nbe += sync;
- 
-  // realEndExceptionBlock is the block where handlers will resume if
-  // they don't treat the exception. realEndExceptionBlock does not
-  // have to catch the exception.
-  BasicBlock* realEndExceptionBlock = endExceptionBlock;
-
-  // endExceptionBlockCatcher is the block where every instruction will
-  // unwind.
-  BasicBlock* endExceptionBlockCatcher = endExceptionBlock;
-
-  if (sync) {
-    // synchronizeExceptionBlock is the the block which will release the lock
-    // on the object. trySynchronizeExceptionBlock is the block which will
-    // catch the exception if one is thrown.
-    BasicBlock* synchronizeExceptionBlock = 
-          createBasicBlock("synchronizeExceptionBlock");
-    BasicBlock* trySynchronizeExceptionBlock = 
-          createBasicBlock("trySynchronizeExceptionBlock");
-
-    // So synchronizeExceptionBlock becomes the block where every instructions
-    // will unwind.
-    realEndExceptionBlock = synchronizeExceptionBlock;
-    endExceptionBlockCatcher = trySynchronizeExceptionBlock;
-    Value* argsSync = 0;
-    if (isVirtual(compilingMethod->access)) {
-      argsSync = llvmFunction->arg_begin();
-    } else {
-      Value* cl = module->getJavaClass(compilingClass);
-      argsSync = cl;
-    }
-
-    // In the synchronizeExceptionBlock: release the object and go to
-    // endExceptionBlock, which will unwind the function.
-    
-    CallInst::Create(module->ReleaseObjectFunction, argsSync, "",
-                     synchronizeExceptionBlock);
-
-    BranchInst::Create(endExceptionBlock, synchronizeExceptionBlock);
-   
-
-    // In the trySynchronizeExceptionBlock: catch the exception and move
-    // to synchronizeExceptionBlock.
-
-    const PointerType* PointerTy_0 = module->ptrType;
-    Instruction* ptr_eh_ptr = CallInst::Create(module->llvmGetException,
-                                               "eh_ptr",
-                                                trySynchronizeExceptionBlock);
-    Constant* C = ConstantExpr::getCast(Instruction::BitCast,
-                                        module->personality, PointerTy_0);
-    Value* int32_eh_select_params[3] = 
-      { ptr_eh_ptr, C, module->constantPtrNull };
-    CallInst::Create(module->exceptionSelector, int32_eh_select_params,
-                     int32_eh_select_params + 3, "eh_select", 
-                     trySynchronizeExceptionBlock);
-
-    BranchInst::Create(synchronizeExceptionBlock,
-                       trySynchronizeExceptionBlock);
-
-    // Now we can set the unwind destination of all instructions to
-    // the exception catcher.
-    for (uint16 i = 0; i < codeLen; ++i) {
-      if (opcodeInfos[i].exceptionBlock == endExceptionBlock) {
-        opcodeInfos[i].exceptionBlock = trySynchronizeExceptionBlock;
-      }
-    }
-  }
-  
-  mvm::ThreadAllocator allocator;
-  // Loop over all handlers in the bytecode to initialize their values.
-  Handler* handlers = (Handler*)
-      allocator.Allocate(sizeof(Handler) * (nbe - sync));
-  for (uint16 i = 0; i < nbe - sync; ++i) {
-    Handler* ex   = &handlers[i];
-    ex->startpc   = reader.readU2();
-    ex->endpc     = reader.readU2();
-    ex->handlerpc = reader.readU2();
-
-    ex->catche = reader.readU2();
-
-#ifndef ISOLATE_SHARING
-    if (ex->catche) {
-      UserClass* cl = 
-        (UserClass*)(compilingClass->ctpInfo->isClassLoaded(ex->catche));
-      // When loading the class, we made sure that all exception classes
-      // were loaded, so cl must have a value.
-      assert(cl && "exception class has not been loaded");
-      ex->catchClass = cl;
-    } else {
-      ex->catchClass = Classpath::newThrowable;
-    }
-#endif
-    
-    ex->catcher = createBasicBlock("testException");
-    
-    // Set the unwind destination of the instructions in the range of this
-    // handler to the test block of the handler. If an instruction already has
-    // a handler and thus is not the synchronize or regular end handler block,
-    // leave it as-is.
-    for (uint16 i = ex->startpc; i < ex->endpc; ++i) {
-      if (opcodeInfos[i].exceptionBlock == endExceptionBlockCatcher) {
-        opcodeInfos[i].exceptionBlock = ex->catcher;
-      }
-    }
-
-    // If the handler pc does not already have a block, create a new one.
-    if (!(opcodeInfos[ex->handlerpc].newBlock)) {
-      opcodeInfos[ex->handlerpc].newBlock = createBasicBlock("javaHandler");
-    }
-    
-    // Set the Java handler for this exception.
-    ex->javaHandler = opcodeInfos[ex->handlerpc].newBlock;
-    opcodeInfos[ex->handlerpc].handler = true;
-
-    // Set the native handler of this exception, which will catch the exception
-    // object.
-    ex->nativeHandler = createBasicBlock("nativeHandler");
-  }
-
-  // Loop over all handlers to know which ones have the same range. Handlers
-  // with a same range all verify the exception's class, but only one catches
-  // the exception. This is the reason why we have a tester block
-  // and a catcher block: the first one tests the exception's class, and the
-  // second one catches the exception.
-  bool first = true;
-  for (sint16 i = 0; i < nbe - sync; ++i) {
-    Handler* cur = &handlers[i];
-
-    // If we are the first handler, we must have one block for catching
-    // the exception, and one block for comparing the exception. The former
-    // is catcher and the latter is tester. Handlers that live in
-    // the range of this handler will jump to tester because they
-    // have already catched the exception. The other instructions in the range
-    // of this handler will jump to catcher because the
-    // exception still has to be catched.
-    if (first) {
-      cur->tester = createBasicBlock("realTestException");
-    } else {
-      cur->tester = cur->catcher;
-    }
-   
-    // Set the exception as a phi node. This PHI has two types of incoming
-    // nodes:
-    // - Handlers within the range: they have already catched the exception
-    //   and verified its type. They are not the right handler for the
-    //   exception, so they jump to this handler
-    // - The testException block of this handler (which is unique). It has
-    //   catched the exception and is now jumping to perform the test.
-    cur->exceptionPHI = PHINode::Create(module->ptrType, "", cur->tester);
-
-    // Look if the next handler has the same range or has a different range.
-    // If it's in the same range, then no need to catch the exception.
-    // Otherwise, it's a new range and we need to catch the exception.
-    if (i + 1 != nbe - sync) {
-      Handler* next = &handlers[i + 1];
-      
-      if (cur->startpc == next->startpc && cur->endpc == next->endpc) {
-        first = false;
-      } else {
-        first = true;
-      }
-    } 
-  }
-  
-
-  // Loop over all handlers to implement their catcher and tester.
-  for (sint16 i = 0; i < nbe - sync; ++i) {
-    Handler* cur = &handlers[i];
-    BasicBlock* bbNext = 0;
-    PHINode* nodeNext = 0;
-    currentExceptionBlock = opcodeInfos[cur->handlerpc].exceptionBlock;
-
-    // Look out where we go if we're not the handler for the exception.
-    if (i + 1 != nbe - sync) {
-      Handler* next = &handlers[i + 1];
-      if (!(cur->startpc >= next->startpc && cur->endpc <= next->endpc)) {
-        // If there is no handler to go to (either one that has the same range
-        // or one that contains the range), then we jump to the end handler.
-        bbNext = realEndExceptionBlock;
-      } else {
-        // If there's a handler to goto, we jump to its tester block and record
-        // the exception PHI node to give our exception to the tester.
-        bbNext = next->tester;
-        nodeNext = next->exceptionPHI;
-      }
-    } else {
-      // If there's no handler after us, we jump to the end handler.
-      bbNext = realEndExceptionBlock;
-    }
-
-    // If the tester and the catcher is not the same, then we must implement
-    // the catcher. The catcher catches the exception, jumps to the tester
-    // and gives the exception as an incoming node the the exceptionPHI.
-    if (cur->tester != cur->catcher) {
-      const PointerType* PointerTy_0 = module->ptrType;
-      Instruction* ptr_eh_ptr = 
-        CallInst::Create(module->llvmGetException, "eh_ptr", cur->catcher);
-      Constant* C = ConstantExpr::getCast(Instruction::BitCast,
-                                          module->personality, PointerTy_0);
-      Value* int32_eh_select_params[3] = 
-        { ptr_eh_ptr, C, module->constantPtrNull };
-      llvm::CallInst::Create(module->exceptionSelector,
-                             int32_eh_select_params,
-                             int32_eh_select_params + 3, "eh_select",
-                             cur->catcher);
-      llvm::BranchInst::Create(cur->tester, cur->catcher);
-      cur->exceptionPHI->addIncoming(ptr_eh_ptr, cur->catcher);
-    } 
-    
-    currentBlock = cur->tester;
-    
-    Value* clVar = 0; 
-#ifdef ISOLATE_SHARING
-    // We're dealing with exceptions, don't catch the exception if the class can
-    // not be found.
-    if (cur->catche) clVar = getResolvedClass(cur->catche, false, false, 0);
-    else clVar = CallInst::Create(module->GetJnjvmExceptionClassFunction,
-                                  isolateLocal, "", currentBlock);
-#else
-    // We know catchClass exists because we have loaded all exceptions catched
-    // by the method when we loaded the class that defined this method.
-    clVar = module->getNativeClass(cur->catchClass);
-#endif
-    if (clVar->getType() != module->JavaCommonClassType) 
-      clVar = new BitCastInst(clVar, module->JavaCommonClassType, "",
-                              currentBlock);
-
-    
-#ifdef SERVICE
-    // Verifies that the current isolate is not stopped. If it is, we don't
-    // catch the exception but resume unwinding.
-    JnjvmClassLoader* loader = compilingClass->classLoader;;
-    if (loader != loader->bootstrapLoader) {
-      Value* Isolate = getVMPtr(getMutatorThreadPtr());
-     
-      Isolate = new LoadInst(Isolate, "", currentBlock);
-      Isolate = new BitCastInst(Isolate, module->ptrPtrType, "", currentBlock);
-      Value* Status = GetElementPtrInst::Create(Isolate, module->constantOne, "",
-                                                currentBlock);
-      Status = new LoadInst(Status, "", currentBlock);
-      Status = new PtrToIntInst(Status, Type::Int32Ty, "", currentBlock);
-  
-      Value* stopping = new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, Status,
-                                     module->constantOne, "");
-
-      BasicBlock* raiseBlock = createBasicBlock("raiseBlock");
-      BasicBlock* continueBlock = createBasicBlock("continueBlock");
-      BranchInst::Create(raiseBlock, continueBlock, stopping, currentBlock);
-      currentBlock = raiseBlock;
-      BranchInst::Create(endExceptionBlock, currentBlock); 
-
-      currentBlock = continueBlock;
-    }
-#endif
-   
-		Value* mutatorThreadId = getMutatorThreadPtr();
-		Value* javaThreadId = getJavaThreadPtr(mutatorThreadId);
-    Value* javaExceptionPtr = getGetJavaExceptionPtr(javaThreadId);
-    
-    // Get the Java exception.
-    Value* obj = new LoadInst(javaExceptionPtr, "", currentBlock);
-
-    Value* objCl = CallInst::Create(module->GetClassFunction, obj, "",
-                                    currentBlock);
-
-    Value* depthCl = ConstantInt::get(Type::Int32Ty, cur->catchClass->depth);
-    Value* depthClObj = CallInst::Create(module->GetDepthFunction, objCl, "",
-                                         currentBlock);
-    
-    // Compare the exception with the exception class we catch.
-    Value* cmp = new ICmpInst(*currentBlock, ICmpInst::ICMP_ULE, depthCl,
-                              depthClObj, "");
-
-    BasicBlock* supDepth = createBasicBlock("superior depth");
-            
-    BranchInst::Create(supDepth, bbNext, cmp, currentBlock);
-    
-    if (nodeNext)
-      nodeNext->addIncoming(cur->exceptionPHI, currentBlock);
-  
-    currentBlock = supDepth;
-    Value* inDisplay = CallInst::Create(module->GetDisplayFunction,
-                                        objCl, "", currentBlock);
-            
-    Value* displayArgs[2] = { inDisplay, depthCl };
-    Value* clInDisplay = CallInst::Create(module->GetClassInDisplayFunction,
-                                          displayArgs, displayArgs + 2, "",
-                                          currentBlock);
-             
-    cmp = new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, clInDisplay, clVar,
-                       "");
-    
-    // If we are catching this exception, then jump to the nativeHandler,
-    // otherwise jump to our next handler.
-    BranchInst::Create(cur->nativeHandler, bbNext, cmp, currentBlock); 
-
-    // Add the incoming value to the next handler, which is the exception we
-    // just catched.
-    if (nodeNext)
-      nodeNext->addIncoming(cur->exceptionPHI, currentBlock);
-    
-    currentBlock = cur->nativeHandler;
- 
-		mutatorThreadId = getMutatorThreadPtr();
-		javaThreadId = getJavaThreadPtr(mutatorThreadId);
-    javaExceptionPtr = getGetJavaExceptionPtr(javaThreadId);
-    
-    // Get the Java exception.
-    Value* exc = new LoadInst(javaExceptionPtr, "", currentBlock);
-    Value* cxxExceptionPtr = getCXXExceptionPtr(mutatorThreadId);
-
-    // Clear exceptions.
-    new StoreInst(module->constantPtrNull, cxxExceptionPtr, currentBlock);
-    new StoreInst(module->JavaObjectNullConstant, javaExceptionPtr,
-                  currentBlock);
-
-    // Call the CXX begin and end catcher.
-    CallInst::Create(module->exceptionBeginCatch, cur->exceptionPHI,
-                           "tmp8", cur->nativeHandler);
-    CallInst::Create(module->exceptionEndCatch, "", cur->nativeHandler);
-
-    // We can now jump to the Java handler!
-    BranchInst::Create(cur->javaHandler, cur->nativeHandler);
-
-    // If the Java handler is empty, create a PHI node that will contain the
-    // exception and give our own.
-    if (cur->javaHandler->empty()) {
-      PHINode* node = PHINode::Create(JnjvmModule::JavaObjectType, "",
-                                      cur->javaHandler);
-      node->addIncoming(exc, cur->nativeHandler);
-      
-    } else {
-      // If the Java handler is not empty, then the first instruction is the
-      // PHI node. Give it our own.
-      Instruction* insn = cur->javaHandler->begin();
-      PHINode* node = dyn_cast<PHINode>(insn);
-      assert(node && "malformed exceptions");
-      node->addIncoming(exc, cur->nativeHandler);
-    }
-
-
-#if defined(SERVICE)
-
-    // Change the isolate we are currently running, now that we have catched
-    // the exception: the exception may have been thrown by another isolate.
-    Value* mutatorThreadId = 0;
-    Value* OldIsolateID = 0;
-    Value* IsolateIDPtr = 0;
-    Value* OldIsolate = 0;
-    Value* NewIsolate = 0;
-    Value* IsolatePtr = 0;
-    currentBlock = cur->javaHandler;
-    if (loader != loader->bootstrapLoader) {
-      mutatorThreadId = getGetMutatorThreadPtr();
-      IsolateIDPtr = getIsolateIDPtr(mutatorThreadId);
-      const Type* realType = PointerType::getUnqual(intrinsics->pointerSizeType);
-      IsolateIDPtr = new BitCastInst(IsolateIDPtr, realType, "",
-                                     currentBlock);
-      OldIsolateID = new LoadInst(IsolateIDPtr, "", currentBlock);
-
-      Value* MyID = ConstantInt::get(intrinsics->pointerSizeType,
-                                     loader->getIsolate()->IsolateID);
-
-      new StoreInst(MyID, IsolateIDPtr, currentBlock);
-      IsolatePtr = getVMPtr(mutatorThreadPtr);
-     
-      OldIsolate = new LoadInst(IsolatePtr, "", currentBlock);
-      NewIsolate = intrinsics->getIsolate(loader->getIsolate(), currentBlock);
-      new StoreInst(NewIsolate, IsolatePtr, currentBlock);
-
-    }
-#endif
-     
-  }
- 
-  // Restore currentBlock.
-  currentBlock = temp;
-  return nbe;
-
-}
-
-void JavaJIT::finishExceptions() {
-  pred_iterator PI = pred_begin(endExceptionBlock);
-  pred_iterator PE = pred_end(endExceptionBlock);
-  if (PI == PE) {
-    endExceptionBlock->eraseFromParent();
-  } else {
-    Value* cxxExceptionPtr = getCXXExceptionPtr(getMutatorThreadPtr());
-    Value* cxxException = new LoadInst(cxxExceptionPtr, "", currentBlock);
-    llvm::CallInst::Create(module->unwindResume, cxxException, "", currentBlock);
-    new UnreachableInst(currentBlock);
-  }
-  
-  PI = pred_begin(unifiedUnreachable);
-  PE = pred_end(unifiedUnreachable);
-  if (PI == PE) {
-    unifiedUnreachable->eraseFromParent();
-  } else {
-    new UnreachableInst(unifiedUnreachable);
-  }
-
-}

Modified: vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp?rev=134154&r1=134153&r2=134154&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp Thu Jun 30 09:16:56 2011
@@ -2603,8 +2603,544 @@
   return DL;
 }
 
-#ifdef DWARF_EXCEPTIONS
-#include "ExceptionsDwarf.inc"
-#else
-#include "ExceptionsCheck.inc"
+Instruction* JavaJIT::invoke(Value *F, std::vector<llvm::Value*>& args,
+                       const char* Name,
+                       BasicBlock *InsertAtEnd) {
+  
+  Instruction* res = CallInst::Create(F, args.begin(), args.end(), Name,
+                                      InsertAtEnd);
+  DebugLoc DL = CreateLocation();
+  res->setDebugLoc(DL);
+  
+  if (TheCompiler->hasExceptionsEnabled()) {
+    Value* javaExceptionPtr = getJavaExceptionPtr(getJavaThreadPtr(getMutatorThreadPtr()));
+    
+    // Get the Java exception.
+    Value* obj = 0;
+    
+    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, "", TheCompiler->useCooperativeGC(), 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()) {
+      Instruction* insn = currentExceptionBlock->begin();
+      PHINode* node = dyn_cast<PHINode>(insn);
+      if (node) node->addIncoming(obj, currentBlock);
+    }
+  
+    currentBlock = ifNormal; 
+  }
+
+  return res;
+}
+
+Instruction* JavaJIT::invoke(Value *F, Value* arg1, const char* Name,
+                       BasicBlock *InsertAtEnd) {
+
+  Instruction* res = CallInst::Create(F, arg1, Name, InsertAtEnd);
+  DebugLoc DL = CreateLocation();
+  res->setDebugLoc(DL);
+  
+  if (TheCompiler->hasExceptionsEnabled()) {
+    Value* javaExceptionPtr = getJavaExceptionPtr(getJavaThreadPtr(getMutatorThreadPtr()));
+    
+    // Get the Java exception.
+    Value* obj = 0;
+    
+    BasicBlock* ifNormal = createBasicBlock("no exception block");
+  
+    Value* test = 0;
+    Constant* zero = intrinsics->JavaObjectNullConstant;
+    if (F == intrinsics->InitialisationCheckFunction || 
+        F == intrinsics->GetConstantPoolAtFunction ||
+        F == intrinsics->GetArrayClassFunction ||
+        F == intrinsics->GetClassDelegateeFunction) {
+      obj = new LoadInst(javaExceptionPtr, "", TheCompiler->useCooperativeGC(), 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()) {
+      Instruction* insn = currentExceptionBlock->begin();
+      PHINode* node = dyn_cast<PHINode>(insn);
+      if (node) node->addIncoming(obj, currentBlock);
+    }
+  
+    currentBlock = ifNormal;
+  }
+
+  return res;
+}
+
+Instruction* JavaJIT::invoke(Value *F, Value* arg1, Value* arg2,
+                       const char* Name, BasicBlock *InsertAtEnd) {
+
+  Value* args[2] = { arg1, arg2 };
+  
+  Instruction* res = CallInst::Create(F, args, args + 2, Name, InsertAtEnd);
+  DebugLoc DL = CreateLocation();
+  res->setDebugLoc(DL);
+  
+  if (TheCompiler->hasExceptionsEnabled()) {
+    Value* javaExceptionPtr = getJavaExceptionPtr(getJavaThreadPtr(getMutatorThreadPtr()));
+    
+    // Get the Java exception.
+    Value* obj = 0;
+    
+    BasicBlock* ifNormal = createBasicBlock("no exception block");
+    
+    Value* test = 0;
+    Constant* zero = intrinsics->JavaObjectNullConstant;
+    if (F == intrinsics->InitialisationCheckFunction || 
+        F == intrinsics->GetConstantPoolAtFunction ||
+        F == intrinsics->GetArrayClassFunction ||
+        F == intrinsics->GetClassDelegateeFunction) {
+      obj = new LoadInst(javaExceptionPtr, "", TheCompiler->useCooperativeGC(), 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()) {
+      Instruction* insn = currentExceptionBlock->begin();
+      PHINode* node = dyn_cast<PHINode>(insn);
+      if (node) node->addIncoming(obj, currentBlock);
+    }
+
+    currentBlock = ifNormal;
+  }
+
+  return res;
+}
+
+Instruction* JavaJIT::invoke(Value *F, const char* Name,
+                       BasicBlock *InsertAtEnd) {
+  Instruction* res = llvm::CallInst::Create(F, Name, InsertAtEnd);
+  DebugLoc DL = CreateLocation();
+  res->setDebugLoc(DL);
+  
+  if (TheCompiler->hasExceptionsEnabled()) {
+    Value* javaExceptionPtr = getJavaExceptionPtr(getJavaThreadPtr(getMutatorThreadPtr()));
+    
+    // Get the Java exception.
+    Value* obj = 0;
+    
+    BasicBlock* ifNormal = createBasicBlock("no exception block");
+  
+    Value* test = 0;
+    Constant* zero = intrinsics->JavaObjectNullConstant;
+    if (F == intrinsics->InitialisationCheckFunction || 
+        F == intrinsics->GetConstantPoolAtFunction ||
+        F == intrinsics->GetArrayClassFunction ||
+        F == intrinsics->GetClassDelegateeFunction) {
+      obj = new LoadInst(javaExceptionPtr, "", TheCompiler->useCooperativeGC(), 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()) {
+      Instruction* insn = currentExceptionBlock->begin();
+      PHINode* node = dyn_cast<PHINode>(insn);
+      if (node) node->addIncoming(obj, currentBlock);
+    }
+
+    currentBlock = ifNormal;
+  }
+
+  return res;
+}
+
+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::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::throwException(llvm::Function* F, Value** args,
+                             uint32 nbArgs) {
+  Instruction* obj = CallInst::Create(F, args, 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);
+  }
+}
+
+/// Handler - This class represents an exception handler. It is only needed
+/// when parsing the .class file in the JIT, therefore it is only defined
+/// here. The readExceptionTable function is the only function that makes
+/// use of this class.
+struct Handler {
+  
+  /// startpc - The bytecode number that begins the try clause.
+  uint32 startpc;
+
+  /// endpc - The bytecode number that ends the try clause.
+  uint32 endpc;
+
+  /// handlerpc - The bytecode number where the handler code starts.
+  uint32 handlerpc;
+
+  /// catche - Index in the constant pool of the exception class.
+  uint16 catche;
+
+  /// catchClass - The class of the exception: it must always be loaded before
+  /// reading the exception table so that we do not throw an exception
+  /// when compiling.
+  UserClass* catchClass;
+
+  /// tester - The basic block that tests if the exception is handled by this
+  /// handler. If the handler is not the first of a list of handlers with the
+  /// same range, than this block is the catcher block. Otherwise, it is the
+  /// destination of the catcher block and of the handlers that do not handler
+  /// the exception.
+  llvm::BasicBlock* tester;
+
+  /// javaHandler - The Java code that handles the exception. At this point, we
+  /// know we have caught and are handling the exception. The Java exception
+  /// object is the PHI node that begins this block.
+  llvm::BasicBlock* javaHandler;
+
+};
+
+unsigned JavaJIT::readExceptionTable(Reader& reader, uint32 codeLen) {
+
+  // This function uses currentBlock to simplify things. We save the current
+  // value of currentBlock to restore it at the end of the function
+  BasicBlock* temp = currentBlock;
+  
+  sint16 nbe = reader.readU2();
+  sint16 sync = isSynchro(compilingMethod->access) ? 1 : 0;
+  nbe += sync;
+ 
+  mvm::ThreadAllocator allocator;
+  // Loop over all handlers in the bytecode to initialize their values.
+  Handler* handlers =
+      (Handler*)allocator.Allocate(sizeof(Handler) * (nbe - sync));
+  for (uint16 i = 0; i < nbe - sync; ++i) {
+    Handler* ex   = &handlers[i];
+    ex->startpc   = reader.readU2();
+    ex->endpc     = reader.readU2();
+    ex->handlerpc = reader.readU2();
+
+    ex->catche = reader.readU2();
+
+#ifndef ISOLATE_SHARING
+    if (ex->catche) {
+      UserClass* cl = 
+        (UserClass*)(compilingClass->ctpInfo->isClassLoaded(ex->catche));
+      // When loading the class, we made sure that all exception classes
+      // were loaded, so cl must have a value.
+      assert(cl && "exception class has not been loaded");
+      ex->catchClass = cl;
+    } else {
+      ex->catchClass = Classpath::newThrowable;
+    }
 #endif
+    
+    ex->tester = createBasicBlock("testException");
+    
+    // PHI Node for the exception object
+    PHINode::Create(intrinsics->JavaObjectType, 0, "", ex->tester);
+    
+    // Set the unwind destination of the instructions in the range of this
+    // handler to the test block of the handler. If an instruction already has
+    // a handler and thus is not the synchronize or regular end handler block,
+    // leave it as-is.
+    for (uint16 i = ex->startpc; i < ex->endpc; ++i) {
+      if (opcodeInfos[i].exceptionBlock == endExceptionBlock) {
+        opcodeInfos[i].exceptionBlock = ex->tester;
+      }
+    }
+
+    // If the handler pc does not already have a block, create a new one.
+    if (!(opcodeInfos[ex->handlerpc].newBlock)) {
+      opcodeInfos[ex->handlerpc].newBlock = createBasicBlock("javaHandler");
+    }
+    
+    // Set the Java handler for this exception.
+    ex->javaHandler = opcodeInfos[ex->handlerpc].newBlock;
+    opcodeInfos[ex->handlerpc].handler = true;
+    
+    if (ex->javaHandler->empty()) {
+      PHINode::Create(intrinsics->JavaObjectType, 0, "", ex->javaHandler);
+    }
+
+  }
+
+  // Loop over all handlers to implement their tester.
+  for (sint16 i = 0; i < nbe - sync; ++i) {
+    Handler* cur = &handlers[i];
+    BasicBlock* bbNext = 0;
+    PHINode* javaNode = 0;
+    currentExceptionBlock = opcodeInfos[cur->handlerpc].exceptionBlock;
+
+    // Look out where we go if we're not the handler for the exception.
+    if (i + 1 != nbe - sync) {
+      Handler* next = &handlers[i + 1];
+      if (!(cur->startpc >= next->startpc && cur->endpc <= next->endpc)) {
+        // If there is no handler to go to (either one that has the same range
+        // or one that contains the range), then we jump to the end handler.
+        bbNext = endExceptionBlock;
+      } else {
+        // If there's a handler to goto, we jump to its tester block and record
+        // the exception PHI node to give our exception to the tester.
+        bbNext = next->tester;
+        javaNode = dyn_cast<PHINode>(bbNext->begin());
+        assert(javaNode);
+      }
+    } else {
+      // If there's no handler after us, we jump to the end handler.
+      bbNext = endExceptionBlock;
+    }
+
+    currentBlock = cur->tester;
+    
+    assert(cur->catchClass && 
+           "Class not loaded when reading the exception table");
+
+    Value* VTVar = TheCompiler->getVirtualTable(cur->catchClass->virtualVT);
+
+    
+#ifdef SERVICE
+    // Verifies that the current isolate is not stopped. If it is, we don't
+    // catch the exception but resume unwinding.
+    JnjvmClassLoader* loader = compilingClass->classLoader;;
+    if (loader != loader->bootstrapLoader) {
+      Value* Isolate = getVMPtr(getMutatorThread());
+     
+      Isolate = new LoadInst(Isolate, "", currentBlock);
+      Isolate = new BitCastInst(Isolate, intrinsics->ptrPtrType, "", currentBlock);
+      Value* Status = GetElementPtrInst::Create(Isolate, intrinsics->constantOne, "",
+                                                currentBlock);
+      Status = new LoadInst(Status, "", currentBlock);
+      Status = new PtrToIntInst(Status, Type::Int32Ty, "", currentBlock);
+  
+      Value* stopping = new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, Status,
+                                     intrinsics->constantOne, "");
+
+      BasicBlock* raiseBlock = createBasicBlock("raiseBlock");
+      BasicBlock* continueBlock = createBasicBlock("continueBlock");
+      BranchInst::Create(raiseBlock, continueBlock, stopping, currentBlock);
+      currentBlock = raiseBlock;
+      BranchInst::Create(endExceptionBlock, currentBlock); 
+
+      currentBlock = continueBlock;
+    }
+#endif
+    
+    // Get the Java exception.
+    Value* obj = currentBlock->begin();
+    
+    Value* objVT = CallInst::Create(intrinsics->GetVTFunction, obj, "",
+                                    currentBlock);
+
+    uint32 depth = cur->catchClass->virtualVT->depth;
+    Value* depthCl = ConstantInt::get(Type::getInt32Ty(*llvmContext), depth);
+    Value* cmp = 0;
+
+    if (depth >= JavaVirtualTable::getDisplayLength()) {
+      Value* classArgs[2] = { objVT, VTVar };
+          
+      cmp = CallInst::Create(intrinsics->IsSecondaryClassFunction,
+                             classArgs, classArgs + 2, "",
+                             currentBlock);
+
+    } else {
+     
+      Value* inDisplay = CallInst::Create(intrinsics->GetDisplayFunction,
+                                          objVT, "", currentBlock);
+            
+      Value* displayArgs[2] = { inDisplay, depthCl };
+      Value* VTInDisplay = CallInst::Create(intrinsics->GetVTInDisplayFunction,
+                                            displayArgs, displayArgs + 2, "",
+                                            currentBlock);
+             
+      cmp = new ICmpInst(*currentBlock, ICmpInst::ICMP_EQ, VTInDisplay, VTVar,
+                         "");
+    }
+   
+    // Add the Java exception in the phi node of the handler.
+    Instruction* insn = cur->javaHandler->begin();
+    PHINode* node = dyn_cast<PHINode>(insn);
+    assert(node && "malformed exceptions");
+    node->addIncoming(obj, currentBlock);
+   
+    // Add the Java exception in the phi node of the next block.
+    if (javaNode)
+      javaNode->addIncoming(obj, currentBlock);
+ 
+    // If we are catching this exception, then jump to the Java Handler,
+    // otherwise jump to our next handler.
+    BranchInst::Create(cur->javaHandler, bbNext, cmp, currentBlock);
+
+    currentBlock = cur->javaHandler;
+
+    // First thing in the handler: clear the exception.
+    Value* javaExceptionPtr = getJavaExceptionPtr(getJavaThreadPtr(getMutatorThreadPtr()));
+    
+    // Clear exceptions.
+    new StoreInst(intrinsics->JavaObjectNullConstant, javaExceptionPtr,
+                  currentBlock);
+
+#if defined(SERVICE)
+
+    // Change the isolate we are currently running, now that we have catched
+    // the exception: the exception may have been thrown by another isolate.
+    Value* mutatorThreadId = 0;
+    Value* OldIsolateID = 0;
+    Value* IsolateIDPtr = 0;
+    Value* OldIsolate = 0;
+    Value* NewIsolate = 0;
+    Value* IsolatePtr = 0;
+    currentBlock = cur->javaHandler;
+    if (loader != loader->bootstrapLoader) {
+      mutatorThreadId = getGetMutatorThreadPtr();
+      IsolateIDPtr = getIsolateIDPtr(mutatorThreadId);
+      const Type* realType = PointerType::getUnqual(intrinsics->pointerSizeType);
+      IsolateIDPtr = new BitCastInst(IsolateIDPtr, realType, "",
+                                     currentBlock);
+      OldIsolateID = new LoadInst(IsolateIDPtr, "", currentBlock);
+
+      Value* MyID = ConstantInt::get(intrinsics->pointerSizeType,
+                                     loader->getIsolate()->IsolateID);
+
+      new StoreInst(MyID, IsolateIDPtr, currentBlock);
+      IsolatePtr = getVMPtr(mutatorThreadPtr);
+     
+      OldIsolate = new LoadInst(IsolatePtr, "", currentBlock);
+      NewIsolate = intrinsics->getIsolate(loader->getIsolate(), currentBlock);
+      new StoreInst(NewIsolate, IsolatePtr, currentBlock);
+
+    }
+#endif
+     
+  }
+ 
+  // Restore currentBlock.
+  currentBlock = temp;
+  return nbe;
+}
+
+void JavaJIT::finishExceptions() {
+  pred_iterator PI = pred_begin(endExceptionBlock);
+  pred_iterator PE = pred_end(endExceptionBlock);
+  if (PI == PE) {
+    endExceptionBlock->eraseFromParent();
+  } else {
+    if (endNode) {
+      endNode->addIncoming(Constant::getNullValue(endNode->getType()),
+                           endExceptionBlock);
+    }
+    BranchInst::Create(endBlock, endExceptionBlock);
+  }
+ 
+
+  PI = pred_begin(unifiedUnreachable);
+  PE = pred_end(unifiedUnreachable);
+  if (PI == PE) {
+    unifiedUnreachable->eraseFromParent();
+  } else {
+    new UnreachableInst(*llvmContext, unifiedUnreachable);
+  }
+  
+  for (Function::iterator BI = llvmFunction->begin(), BE = llvmFunction->end();
+       BI != BE; BI++) {
+    PI = pred_begin(BI);
+    PE = pred_end(BI);
+    if (PI == PE) {
+      Instruction* insn = BI->begin();
+      PHINode* node = dyn_cast<PHINode>(insn);
+      if (node) {
+        node->replaceAllUsesWith(Constant::getNullValue(node->getType()));
+        node->eraseFromParent();
+      }
+    }
+  }
+}

Modified: vmkit/trunk/lib/J3/VMCore/JavaMetaJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaMetaJIT.cpp?rev=134154&r1=134153&r2=134154&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaMetaJIT.cpp (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaMetaJIT.cpp Thu Jun 30 09:16:56 2011
@@ -56,18 +56,9 @@
   }\
 }
   
-#if defined(DWARF_EXCEPTIONS)
-
-#define DO_TRY try {
-#define DO_CATCH } catch(...) { th->throwFromJava(); } \
-
-#else
-
 #define DO_TRY
 #define DO_CATCH if (th->pendingException) { th->throwFromJava(); }
 
-#endif
-
 //===----------------------------------------------------------------------===//
 // We do not need to have special care on the GC-pointers in the buffer
 // manipulated in these functions because the objects in the buffer are

Modified: vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp?rev=134154&r1=134153&r2=134154&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp Thu Jun 30 09:16:56 2011
@@ -399,12 +399,7 @@
 
   END_NATIVE_EXCEPTION
 
-#ifdef DWARF_EXCEPTIONS
-  th->throwException(exc);
-#else
   th->pendingException = exc;
-#endif
-
   return exc;
 }
 
@@ -420,12 +415,7 @@
 
   END_NATIVE_EXCEPTION
 
-#ifdef DWARF_EXCEPTIONS
-  th->throwException(exc);
-#else
   th->pendingException = exc;
-#endif
-
   return exc;
 }
 
@@ -441,12 +431,7 @@
 
   END_NATIVE_EXCEPTION
 
-#ifdef DWARF_EXCEPTIONS
-  th->throwException(exc);
-#else
   th->pendingException = exc;
-#endif
-
   return exc;
 }
 
@@ -462,12 +447,7 @@
 
   END_NATIVE_EXCEPTION
 
-#ifdef DWARF_EXCEPTIONS
-  th->throwException(exc);
-#else
   th->pendingException = exc;
-#endif
-
   return exc;
 }
 
@@ -483,12 +463,7 @@
 
   END_NATIVE_EXCEPTION
 
-#ifdef DWARF_EXCEPTIONS
-  th->throwException(exc);
-#else
   th->pendingException = exc;
-#endif
-
   return exc;
 }
 
@@ -507,12 +482,7 @@
 
   END_NATIVE_EXCEPTION
 
-#ifdef DWARF_EXCEPTIONS
-  th->throwException(exc);
-#else
   th->pendingException = exc;
-#endif
-
   return exc;
 }
 
@@ -531,12 +501,7 @@
 
   END_NATIVE_EXCEPTION
 
-#ifdef DWARF_EXCEPTIONS
-  th->throwException(exc);
-#else
   th->pendingException = exc;
-#endif
-  
   return exc;
 }
 
@@ -552,12 +517,7 @@
 
   END_NATIVE_EXCEPTION
 
-#ifdef DWARF_EXCEPTIONS
-  th->throwException(exc);
-#else
   th->pendingException = exc;
-#endif
-  
   return exc;
 }
 
@@ -574,12 +534,7 @@
 
   END_NATIVE_EXCEPTION
 
-#ifdef DWARF_EXCEPTIONS
-  th->throwException(exc);
-#else
   th->pendingException = exc;
-#endif
-  
 }
 
 extern "C" void* j3StringLookup(UserClass* cl, uint32 index) {

Modified: vmkit/trunk/lib/J3/VMCore/JavaThread.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaThread.h?rev=134154&r1=134153&r2=134154&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaThread.h (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaThread.h Thu Jun 30 09:16:56 2011
@@ -169,9 +169,6 @@
   /// throwFromNative - Throw an exception after executing Native code.
   ///
   void throwFromNative() {
-#ifdef DWARF_EXCEPTIONS
-    throwPendingException();
-#endif
   }
   
   /// throwFromJava - Throw an exception after executing Java code.

Modified: vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp?rev=134154&r1=134153&r2=134154&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp (original)
+++ vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp Thu Jun 30 09:16:56 2011
@@ -100,31 +100,11 @@
 #endif
 
 void Thread::internalThrowException() {
-#ifdef RUNTIME_DWARF_EXCEPTIONS
-  // Use dlsym instead of getting the functions statically with extern "C"
-  // because gcc compiles exceptions differently.
-  typedef void* (*cxa_allocate_exception_type)(unsigned);
-  typedef void  (*cxa_throw_type)(void*, void*, void*);
-  
-  static cxa_allocate_exception_type cxa_allocate_exception =
-    (cxa_allocate_exception_type)(uintptr_t)
-    dlsym(SELF_HANDLE, "__cxa_allocate_exception");
-  
-  static cxa_throw_type cxa_throw =
-    (cxa_throw_type)(uintptr_t)
-    dlsym(SELF_HANDLE, "__cxa_throw");
-  
-  void* exc = cxa_allocate_exception(0);
-  // 32 = sizeof(_Unwind_Exception) in libgcc...  
-  internalPendingException = (void*)((uintptr_t)exc - 32);
-  cxa_throw(exc, 0, 0);
-#else
 #if defined(__MACH__)
   _longjmp(lastExceptionBuffer->buffer, 1);
 #else
   longjmp(lastExceptionBuffer->buffer, 1);
 #endif
-#endif
 }
 
 void Thread::printBacktrace() {

Modified: vmkit/trunk/lib/Mvm/Compiler/JIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Compiler/JIT.cpp?rev=134154&r1=134153&r2=134154&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/Compiler/JIT.cpp (original)
+++ vmkit/trunk/lib/Mvm/Compiler/JIT.cpp Thu Jun 30 09:16:56 2011
@@ -124,11 +124,7 @@
   llvm::NoFramePointerElim = true;
   llvm::DisablePrettyStackTrace = true;
   llvm::JITEmitDebugInfo = EmitDebugInfo;
-#if DWARF_EXCEPTIONS
-  llvm::JITExceptionHandling = true;
-#else
   llvm::JITExceptionHandling = false;
-#endif
   
   // Disable branch fold for accurate line numbers.
   const char* commands[2] = { "vmkit", "-disable-branch-fold" };





More information about the vmkit-commits mailing list