[vmkit-commits] [vmkit] r65444 - in /vmkit/trunk/lib/JnJVM/VMCore: ExceptionsCheck.inc JavaJIT.cpp JavaJITOpcodes.cpp

Nicolas Geoffray nicolas.geoffray at lip6.fr
Wed Feb 25 03:17:53 PST 2009


Author: geoffray
Date: Wed Feb 25 05:17:51 2009
New Revision: 65444

URL: http://llvm.org/viewvc/llvm-project?rev=65444&view=rev
Log:
Disable exceptions if the module says so.


Modified:
    vmkit/trunk/lib/JnJVM/VMCore/ExceptionsCheck.inc
    vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp

Modified: vmkit/trunk/lib/JnJVM/VMCore/ExceptionsCheck.inc
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/ExceptionsCheck.inc?rev=65444&r1=65443&r2=65444&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/ExceptionsCheck.inc (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/ExceptionsCheck.inc Wed Feb 25 05:17:51 2009
@@ -4,33 +4,36 @@
   
   Instruction* res = CallInst::Create(F, args.begin(), args.end(), Name,
                                       InsertAtEnd);
-  Value* threadId = getCurrentThread();
-  Value* geps[2] = { module->constantZero,
-                     module->OffsetJavaExceptionInThreadConstant };
+  
+  if (module->hasExceptionsEnabled()) {
+    Value* threadId = getCurrentThread();
+    Value* geps[2] = { module->constantZero,
+                       module->OffsetJavaExceptionInThreadConstant };
 
-  Value* javaExceptionPtr = GetElementPtrInst::Create(threadId, geps,
-                                                      geps + 2, "",
-                                                      currentBlock);
+    Value* javaExceptionPtr = GetElementPtrInst::Create(threadId, geps,
+                                                        geps + 2, "",
+                                                        currentBlock);
     
-  // Get the Java exception.
-  Value* obj = new LoadInst(javaExceptionPtr, "", currentBlock);
+    // Get the Java exception.
+    Value* obj = new LoadInst(javaExceptionPtr, "", currentBlock);
     
-  BasicBlock* ifNormal = createBasicBlock("no exception block");
+    BasicBlock* ifNormal = createBasicBlock("no exception block");
   
-  Constant* zero = module->JavaObjectNullConstant;
-  Value* test = new ICmpInst(ICmpInst::ICMP_NE, obj, zero, "",
-                             currentBlock);
+    Constant* zero = module->JavaObjectNullConstant;
+    Value* test = new ICmpInst(ICmpInst::ICMP_NE, obj, zero, "",
+                               currentBlock);
 
-  BranchInst::Create(currentExceptionBlock, ifNormal, test, currentBlock);
+    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);
-  }
+    if (!currentExceptionBlock->empty()) {
+      Instruction* insn = currentExceptionBlock->begin();
+      PHINode* node = dyn_cast<PHINode>(insn);
+      if (node) node->addIncoming(obj, currentBlock);
+    }
   
-  currentBlock = ifNormal; 
+    currentBlock = ifNormal; 
+  }
 
   return res;
 }
@@ -39,32 +42,35 @@
                        BasicBlock *InsertAtEnd) {
 
   Instruction* res = CallInst::Create(F, arg1, Name, InsertAtEnd);
-  Value* threadId = getCurrentThread();
-  Value* geps[2] = { module->constantZero,
-                     module->OffsetJavaExceptionInThreadConstant };
+  
+  if (module->hasExceptionsEnabled()) {
+    Value* threadId = getCurrentThread();
+    Value* geps[2] = { module->constantZero,
+                       module->OffsetJavaExceptionInThreadConstant };
 
-  Value* javaExceptionPtr = GetElementPtrInst::Create(threadId, geps,
-                                                      geps + 2, "",
-                                                      currentBlock);
+    Value* javaExceptionPtr = GetElementPtrInst::Create(threadId, geps,
+                                                        geps + 2, "",
+                                                        currentBlock);
     
-  // Get the Java exception.
-  Value* obj = new LoadInst(javaExceptionPtr, "", currentBlock);
+    // Get the Java exception.
+    Value* obj = new LoadInst(javaExceptionPtr, "", currentBlock);
     
-  BasicBlock* ifNormal = createBasicBlock("no exception block");
+    BasicBlock* ifNormal = createBasicBlock("no exception block");
   
-  Constant* zero = module->JavaObjectNullConstant;
-  Value* test = new ICmpInst(ICmpInst::ICMP_NE, obj, zero, "",
-                             currentBlock);
+    Constant* zero = module->JavaObjectNullConstant;
+    Value* test = new ICmpInst(ICmpInst::ICMP_NE, obj, zero, "",
+                               currentBlock);
 
-  BranchInst::Create(currentExceptionBlock, ifNormal, test, currentBlock);
+    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);
-  }
+    if (!currentExceptionBlock->empty()) {
+      Instruction* insn = currentExceptionBlock->begin();
+      PHINode* node = dyn_cast<PHINode>(insn);
+      if (node) node->addIncoming(obj, currentBlock);
+    }
   
-  currentBlock = ifNormal;
+    currentBlock = ifNormal;
+  }
 
   return res;
 }
@@ -76,32 +82,34 @@
   
   Instruction* res = CallInst::Create(F, args, args + 2, Name, InsertAtEnd);
   
-  Value* threadId = getCurrentThread();
-  Value* geps[2] = { module->constantZero,
-                     module->OffsetJavaExceptionInThreadConstant };
+  if (module->hasExceptionsEnabled()) {
+    Value* threadId = getCurrentThread();
+    Value* geps[2] = { module->constantZero,
+                       module->OffsetJavaExceptionInThreadConstant };
 
-  Value* javaExceptionPtr = GetElementPtrInst::Create(threadId, geps,
-                                                      geps + 2, "",
-                                                      currentBlock);
+    Value* javaExceptionPtr = GetElementPtrInst::Create(threadId, geps,
+                                                        geps + 2, "",
+                                                        currentBlock);
     
-  // Get the Java exception.
-  Value* obj = new LoadInst(javaExceptionPtr, "", currentBlock);
+    // Get the Java exception.
+    Value* obj = new LoadInst(javaExceptionPtr, "", currentBlock);
     
-  BasicBlock* ifNormal = createBasicBlock("no exception block");
+    BasicBlock* ifNormal = createBasicBlock("no exception block");
   
-  Constant* zero = module->JavaObjectNullConstant;
-  Value* test = new ICmpInst(ICmpInst::ICMP_NE, obj, zero, "",
-                             currentBlock);
+    Constant* zero = module->JavaObjectNullConstant;
+    Value* test = new ICmpInst(ICmpInst::ICMP_NE, obj, zero, "",
+                               currentBlock);
 
-  BranchInst::Create(currentExceptionBlock, ifNormal, test, currentBlock);
+    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);
-  }
+    if (!currentExceptionBlock->empty()) {
+      Instruction* insn = currentExceptionBlock->begin();
+      PHINode* node = dyn_cast<PHINode>(insn);
+      if (node) node->addIncoming(obj, currentBlock);
+    }
 
-  currentBlock = ifNormal;
+    currentBlock = ifNormal;
+  }
 
   return res;
 }
@@ -109,32 +117,35 @@
 Instruction* JavaJIT::invoke(Value *F, const char* Name,
                        BasicBlock *InsertAtEnd) {
   Instruction* res = llvm::CallInst::Create(F, Name, InsertAtEnd);
-  Value* threadId = getCurrentThread();
-  Value* geps[2] = { module->constantZero,
-                     module->OffsetJavaExceptionInThreadConstant };
+  
+  if (module->hasExceptionsEnabled()) {
+    Value* threadId = getCurrentThread();
+    Value* geps[2] = { module->constantZero,
+                       module->OffsetJavaExceptionInThreadConstant };
 
-  Value* javaExceptionPtr = GetElementPtrInst::Create(threadId, geps,
-                                                      geps + 2, "",
-                                                      currentBlock);
+    Value* javaExceptionPtr = GetElementPtrInst::Create(threadId, geps,
+                                                        geps + 2, "",
+                                                        currentBlock);
     
-  // Get the Java exception.
-  Value* obj = new LoadInst(javaExceptionPtr, "", currentBlock);
+    // Get the Java exception.
+    Value* obj = new LoadInst(javaExceptionPtr, "", currentBlock);
     
-  BasicBlock* ifNormal = createBasicBlock("no exception block");
+    BasicBlock* ifNormal = createBasicBlock("no exception block");
   
-  Constant* zero = module->JavaObjectNullConstant;
-  Value* test = new ICmpInst(ICmpInst::ICMP_NE, obj, zero, "",
-                             currentBlock);
+    Constant* zero = module->JavaObjectNullConstant;
+    Value* test = new ICmpInst(ICmpInst::ICMP_NE, obj, zero, "",
+                               currentBlock);
 
-  BranchInst::Create(currentExceptionBlock, ifNormal, test, currentBlock);
+    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);
-  }
+    if (!currentExceptionBlock->empty()) {
+      Instruction* insn = currentExceptionBlock->begin();
+      PHINode* node = dyn_cast<PHINode>(insn);
+      if (node) node->addIncoming(obj, currentBlock);
+    }
 
-  currentBlock = ifNormal;
+    currentBlock = ifNormal;
+  }
 
   return res;
 }

Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp?rev=65444&r1=65443&r2=65444&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp Wed Feb 25 05:17:51 2009
@@ -882,7 +882,7 @@
               compilingMethod->printString());
   
 #ifndef DWARF_EXCEPTIONS
-  if (codeLen < 5 && !callsStackWalker)
+  if (codeLen < 5 && !callsStackWalker && !module->isStaticCompiling())
     compilingMethod->canBeInlined = true;
 #endif
 
@@ -970,18 +970,20 @@
 
 void JavaJIT::JITVerifyNull(Value* obj) {
 
-  Constant* zero = module->JavaObjectNullConstant;
-  Value* test = new ICmpInst(ICmpInst::ICMP_EQ, obj, zero, "",
-                             currentBlock);
+  if (module->hasExceptionsEnabled()) {
+    Constant* zero = module->JavaObjectNullConstant;
+    Value* test = new ICmpInst(ICmpInst::ICMP_EQ, obj, zero, "",
+                               currentBlock);
 
-  BasicBlock* exit = createBasicBlock("verifyNullExit");
-  BasicBlock* cont = createBasicBlock("verifyNullCont");
+    BasicBlock* exit = createBasicBlock("verifyNullExit");
+    BasicBlock* cont = createBasicBlock("verifyNullCont");
 
-  BranchInst::Create(exit, cont, test, currentBlock);
-  currentBlock = exit;
-  throwException(module->NullPointerExceptionFunction, 0, 0);
-  currentBlock = cont;
-  
+    BranchInst::Create(exit, cont, test, currentBlock);
+    currentBlock = exit;
+    throwException(module->NullPointerExceptionFunction, 0, 0);
+    currentBlock = cont;
+  }
+ 
 }
 
 Value* JavaJIT::verifyAndComputePtr(Value* obj, Value* index,
@@ -992,7 +994,7 @@
     index = new SExtInst(index, Type::Int32Ty, "", currentBlock);
   }
   
-  if (true) {
+  if (module->hasExceptionsEnabled()) {
     Value* size = arraySize(obj);
     
     Value* cmp = new ICmpInst(ICmpInst::ICMP_ULT, index, size, "",

Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp?rev=65444&r1=65443&r2=65444&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp Wed Feb 25 05:17:51 2009
@@ -1896,28 +1896,30 @@
         }
         Value* arg1 = popAsInt();
 
-        Value* cmp = new ICmpInst(ICmpInst::ICMP_SLT, arg1,
-                                  module->constantZero, "", currentBlock);
-
-        BasicBlock* BB1 = createBasicBlock("");
-        BasicBlock* BB2 = createBasicBlock("");
-
-        BranchInst::Create(BB1, BB2, cmp, currentBlock);
-        currentBlock = BB1;
-        throwException(module->NegativeArraySizeExceptionFunction, arg1);
-        currentBlock = BB2;
-        
-        cmp = new ICmpInst(ICmpInst::ICMP_SGT, arg1,
-                           module->MaxArraySizeConstant,
-                           "", currentBlock);
-
-        BB1 = createBasicBlock("");
-        BB2 = createBasicBlock("");
-
-        BranchInst::Create(BB1, BB2, cmp, currentBlock);
-        currentBlock = BB1;
-        throwException(module->OutOfMemoryErrorFunction, arg1);
-        currentBlock = BB2;
+        if (module->hasExceptionsEnabled()) {
+          Value* cmp = new ICmpInst(ICmpInst::ICMP_SLT, arg1,
+                                    module->constantZero, "", currentBlock);
+
+          BasicBlock* BB1 = createBasicBlock("");
+          BasicBlock* BB2 = createBasicBlock("");
+
+          BranchInst::Create(BB1, BB2, cmp, currentBlock);
+          currentBlock = BB1;
+          throwException(module->NegativeArraySizeExceptionFunction, arg1);
+          currentBlock = BB2;
+        
+          cmp = new ICmpInst(ICmpInst::ICMP_SGT, arg1,
+                             module->MaxArraySizeConstant,
+                             "", currentBlock);
+
+          BB1 = createBasicBlock("");
+          BB2 = createBasicBlock("");
+
+          BranchInst::Create(BB1, BB2, cmp, currentBlock);
+          currentBlock = BB1;
+          throwException(module->OutOfMemoryErrorFunction, arg1);
+          currentBlock = BB2;
+        }
         
         Value* mult = BinaryOperator::CreateMul(arg1, sizeElement, "",
                                                 currentBlock);
@@ -1973,6 +1975,11 @@
       }
 
       case CHECKCAST :
+        if (!module->hasExceptionsEnabled()) {
+          i += 2;
+          break;
+        }
+
       case INSTANCEOF : {
         
         bool checkcast = (bytecodes[i] == CHECKCAST);





More information about the vmkit-commits mailing list