[llvm-commits] [vmkit] r50856 - in /vmkit/trunk/lib/JnJVM/VMCore: JavaJIT.h JavaJITInitialise.cpp JavaJITOpcodes.cpp JavaRuntimeJIT.cpp

Nicolas Geoffray nicolas.geoffray at lip6.fr
Thu May 8 09:07:14 PDT 2008


Author: geoffray
Date: Thu May  8 11:07:14 2008
New Revision: 50856

URL: http://llvm.org/viewvc/llvm-project?rev=50856&view=rev
Log:
Inline ANEWARRAY opcode.


Modified:
    vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.h
    vmkit/trunk/lib/JnJVM/VMCore/JavaJITInitialise.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.h Thu May  8 11:07:14 2008
@@ -122,6 +122,8 @@
   static llvm::Function* nullPointerExceptionLLVM;
   static llvm::Function* indexOutOfBoundsExceptionLLVM;
   static llvm::Function* classCastExceptionLLVM;
+  static llvm::Function* outOfMemoryErrorLLVM;
+  static llvm::Function* negativeArraySizeExceptionLLVM;
   std::vector<llvm::BasicBlock*> jsrs;
   // exception local
   llvm::Value* supplLocal;
@@ -273,6 +275,8 @@
   static llvm::Function* arrayLengthLLVM;
   static llvm::Function* getVTLLVM;
   static llvm::Function* getClassLLVM;
+  static llvm::Function* getCollectorLLVM;
+  static llvm::Function* javaObjectAllocateLLVM;
   
 
   static Class* getCallingClass();
@@ -288,6 +292,11 @@
 
   static llvm::Constant*    constantJavaObjectNull;
   static llvm::Constant*    constantUTF8Null;
+  static llvm::Constant*    constantMaxArraySize;
+  static llvm::Constant*    constantJavaObjectSize;
+
+  static llvm::GlobalVariable* ArrayObjectVT;
+  static llvm::GlobalVariable* JavaObjectVT;
 };
 
 enum Opcode {

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaJITInitialise.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaJITInitialise.cpp Thu May  8 11:07:14 2008
@@ -69,10 +69,10 @@
   mvm::jit::protectTypes();//->lock();
   // Create JavaObject::llvmType
   const llvm::Type* Pty = mvm::jit::ptrType;
+  const llvm::Type* VTType = PointerType::getUnqual(PointerType::getUnqual(Type::Int32Ty));
   
   std::vector<const llvm::Type*> objectFields;
-  objectFields.push_back(
-      PointerType::getUnqual(PointerType::getUnqual(Type::Int32Ty))); // VT
+  objectFields.push_back(VTType); // VT
   objectFields.push_back(Pty); // Class
   objectFields.push_back(Pty); // Lock
   JavaObject::llvmType = 
@@ -477,6 +477,35 @@
                      "indexOutOfBoundsException",
                      module);
   }
+  {
+  std::vector<const Type*> args;
+  args.push_back(Type::Int32Ty);
+  const FunctionType* type = FunctionType::get(Type::VoidTy, args, false);
+
+
+  negativeArraySizeExceptionLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
+                     "negativeArraySizeException",
+                     module);
+  
+  outOfMemoryErrorLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
+                     "outOfMemoryError",
+                     module);
+  }
+  
+  {
+  std::vector<const Type*> args;
+  args.push_back(Type::Int32Ty);
+  args.push_back(VTType);
+#ifdef MULTIPLE_GC
+  args.push_back(mvm::jit::ptrType);
+#endif
+  const FunctionType* type = FunctionType::get(JavaObject::llvmType, args, false);
+
+
+  javaObjectAllocateLLVM = Function::Create(type, GlobalValue::ExternalLinkage,
+                     "gcmalloc",
+                     module);
+  }
   
   // Create proceedPendingExceptionLLVM
   {
@@ -731,11 +760,40 @@
   mvm::jit::protectConstants();//->lock();
   constantUTF8Null = Constant::getNullValue(UTF8::llvmType); 
   constantJavaObjectNull = Constant::getNullValue(JavaObject::llvmType);
+  constantMaxArraySize = ConstantInt::get(Type::Int32Ty,
+                                          JavaArray::MaxArraySize);
+  constantJavaObjectSize = ConstantInt::get(Type::Int32Ty, sizeof(JavaObject));
+  
+  
+  Constant* cons = 
+    ConstantExpr::getIntToPtr(ConstantInt::get(Type::Int64Ty,
+                              uint64_t (JavaObject::VT)), VTType);
+      
+  JavaObjectVT = new GlobalVariable(VTType, true,
+                                    GlobalValue::ExternalLinkage,
+                                    cons, "",
+                                    module);
+  
+  cons = 
+    ConstantExpr::getIntToPtr(ConstantInt::get(Type::Int64Ty,
+                              uint64_t (ArrayObject::VT)), VTType);
+  
+  ArrayObjectVT = new GlobalVariable(VTType, true,
+                                    GlobalValue::ExternalLinkage,
+                                    cons, "",
+                                    module);
+  
+      
+  
   mvm::jit::unprotectConstants();//->unlock();
 }
 
 llvm::Constant*    JavaJIT::constantJavaObjectNull;
 llvm::Constant*    JavaJIT::constantUTF8Null;
+llvm::Constant*    JavaJIT::constantMaxArraySize;
+llvm::Constant*    JavaJIT::constantJavaObjectSize;
+llvm::GlobalVariable*    JavaJIT::JavaObjectVT;
+llvm::GlobalVariable*    JavaJIT::ArrayObjectVT;
 
 
 namespace mvm {

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp Thu May  8 11:07:14 2008
@@ -1793,15 +1793,90 @@
         
         llvm::Value* valCl = new LoadInst(dcl->llvmVar(vm->module), "", currentBlock);
         llvm::Value* arg1 = popAsInt();
-#ifdef MULTIPLE_VM
+
+        Value* cmp = new ICmpInst(ICmpInst::ICMP_SLT, arg1, mvm::jit::constantZero, "", currentBlock);
+
+        BasicBlock* BB1 = createBasicBlock("");
+        BasicBlock* BB2 = createBasicBlock("");
+
+        BranchInst::Create(BB1, BB2, cmp, currentBlock);
+        currentBlock = BB1;
+        std::vector<Value*> exArgs;
+        exArgs.push_back(arg1);
+        if (currentExceptionBlock != endExceptionBlock) {
+          InvokeInst::Create(negativeArraySizeExceptionLLVM, unifiedUnreachable, currentExceptionBlock, exArgs.begin(), exArgs.end(), "", currentBlock);
+        } else {
+          CallInst::Create(negativeArraySizeExceptionLLVM, exArgs.begin(), exArgs.end(), "", currentBlock);
+          new UnreachableInst(currentBlock);
+        }
+        currentBlock = BB2;
+        
+        cmp = new ICmpInst(ICmpInst::ICMP_SGT, arg1, constantMaxArraySize, "", currentBlock);
+
+        BB1 = createBasicBlock("");
+        BB2 = createBasicBlock("");
+
+        BranchInst::Create(BB1, BB2, cmp, currentBlock);
+        currentBlock = BB1;
+        if (currentExceptionBlock != endExceptionBlock) {
+          InvokeInst::Create(outOfMemoryErrorLLVM, unifiedUnreachable, currentExceptionBlock, exArgs.begin(), exArgs.end(), "", currentBlock);
+        } else {
+          CallInst::Create(outOfMemoryErrorLLVM, exArgs.begin(), exArgs.end(), "", currentBlock);
+          new UnreachableInst(currentBlock);
+        }
+        currentBlock = BB2;
+        
+        Value* mult = BinaryOperator::createMul(arg1, mvm::jit::constantPtrSize, "", currentBlock);
+        Value* size = BinaryOperator::createAdd(constantJavaObjectSize, mult, "", currentBlock);
         std::vector<Value*> args;
-        args.push_back(arg1);
-        args.push_back(valCl);
-        args.push_back(isolateLocal);
-        push(invoke(ObjectAconsLLVM, args, "", currentBlock), AssessorDesc::dRef);
-#else
-        push(invoke(ObjectAconsLLVM, arg1, valCl, "", currentBlock), AssessorDesc::dRef);
+        args.push_back(size);
+        args.push_back(new LoadInst(ArrayObjectVT, "", currentBlock));
+#ifdef MULTIPLE_GC
+        args.push_back(CallInst::Create(getCollector, isolateLocal, "", currentBlock));
 #endif
+        Value* res = invoke(javaObjectAllocateLLVM, args, "", currentBlock);
+        Value* cast = new BitCastInst(res, ArrayObject::llvmType, "", currentBlock);
+
+        // Set the size
+        std::vector<Value*> gep4;
+        gep4.push_back(mvm::jit::constantZero);
+        gep4.push_back(JavaArray::sizeOffset());
+        new StoreInst(arg1, GetElementPtrInst::Create(cast, gep4.begin(), gep4.end(), "", currentBlock), currentBlock);
+        
+        /*
+        // Memset 0 to everyone
+        std::vector<Value*> gep5;
+        gep5.push_back(mvm::jit::constantZero);
+        gep5.push_back(JavaArray::elementsOffset());
+        Value* elements = GetElementPtrInst::Create(cast, gep5.begin(), gep5.end(), "", currentBlock);
+        
+        std::vector<Value*> argsM;
+        argsM.push_back(new BitCastInst(elements, mvm::jit::ptrType, "", currentBlock));
+        argsM.push_back(mvm::jit::constantInt8Zero);
+        argsM.push_back(mult);
+        argsM.push_back(mvm::jit::constantFour);
+        CallInst::Create(mvm::jit::llvm_memset_i32, argsM.begin(), argsM.end(), "", currentBlock);
+        */
+        // Set the class
+        std::vector<Value*> gep;
+        gep.push_back(mvm::jit::constantZero);
+        gep.push_back(JavaObject::classOffset());
+        new StoreInst(valCl, GetElementPtrInst::Create(res, gep.begin(), gep.end(), "", currentBlock), currentBlock);
+        /* 
+        // Set the lock to zero
+        std::vector<Value*> gep2;
+        gep2.push_back(mvm::jit::constantZero);
+        gep2.push_back(JavaObject::lockOffset());
+        new StoreInst(mvm::jit::constantPtrNull, GetElementPtrInst::Create(res, gep2.begin(), gep2.end(), "", currentBlock), currentBlock);
+        
+        // Set the real VT
+        std::vector<Value*> gep3;
+        gep3.push_back(mvm::jit::constantZero);
+        gep3.push_back(mvm::jit::constantZero);
+        new StoreInst(new LoadInst(ArrayObjectVT, "", currentBlock), GetElementPtrInst::Create(res, gep3.begin(), gep3.end(), "", currentBlock), currentBlock);
+        */ 
+        push(res, AssessorDesc::dRef);
+
         break;
       }
 

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaRuntimeJIT.cpp Thu May  8 11:07:14 2008
@@ -38,6 +38,9 @@
 llvm::Function* JavaJIT::nullPointerExceptionLLVM = 0;
 llvm::Function* JavaJIT::classCastExceptionLLVM = 0;
 llvm::Function* JavaJIT::indexOutOfBoundsExceptionLLVM = 0;
+llvm::Function* JavaJIT::negativeArraySizeExceptionLLVM = 0;
+llvm::Function* JavaJIT::outOfMemoryErrorLLVM = 0;
+llvm::Function* JavaJIT::javaObjectAllocateLLVM = 0;
 llvm::Function* JavaJIT::javaObjectTracerLLVM = 0;
 llvm::Function* JavaJIT::virtualLookupLLVM = 0;
 llvm::Function* JavaJIT::fieldLookupLLVM = 0;
@@ -211,6 +214,14 @@
   JavaThread::get()->isolate->nullPointerException("null");
 }
 
+extern "C" void negativeArraySizeException(sint32 val) {
+  JavaThread::get()->isolate->negativeArraySizeException(val);
+}
+
+extern "C" void outOfMemoryError(sint32 val) {
+  JavaThread::get()->isolate->outOfMemoryError(val);
+}
+
 extern "C" void classCastException(JavaObject* obj, CommonClass* cl) {
   JavaThread::get()->isolate->classCastException("");
 }





More information about the llvm-commits mailing list