[vmkit-commits] [vmkit] r63516 - in /vmkit/trunk/lib/JnJVM/VMCore: JavaJIT.cpp JavaJIT.h JavaJITOpcodes.cpp

Nicolas Geoffray nicolas.geoffray at lip6.fr
Mon Feb 2 06:49:22 PST 2009


Author: geoffray
Date: Mon Feb  2 08:49:22 2009
New Revision: 63516

URL: http://llvm.org/viewvc/llvm-project?rev=63516&view=rev
Log:
Factorize code, no functionality changes.


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

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp Mon Feb  2 08:49:22 2009
@@ -184,6 +184,20 @@
 #endif
 }
 
+llvm::Value* JavaJIT::getCurrentThread() {
+  Value* FrameAddr = CallInst::Create(module->llvm_frameaddress,
+                                     	module->constantZero, "", currentBlock);
+  Value* threadId = new PtrToIntInst(FrameAddr, module->pointerSizeType, "",
+                              			 currentBlock);
+  threadId = BinaryOperator::CreateAnd(threadId, module->constantThreadIDMask,
+                                       "", currentBlock);
+  threadId = new IntToPtrInst(threadId, module->JavaThreadType, "",
+                              currentBlock);
+
+  return threadId;
+}
+
+
 llvm::Function* JavaJIT::nativeCompile(intptr_t natPtr) {
   
   PRINT_DEBUG(JNJVM_COMPILE, 1, COLOR_NORMAL, "native compile %s\n",
@@ -250,15 +264,8 @@
   uint32 nargs = func->arg_size() + 1 + (stat ? 1 : 0); 
   std::vector<Value*> nativeArgs;
   
-  Value* FrameAddr = CallInst::Create(module->llvm_frameaddress,
-                                     	module->constantZero, "", currentBlock);
-  Value* threadId = new PtrToIntInst(FrameAddr, module->pointerSizeType, "",
-                              			 currentBlock);
-  threadId = BinaryOperator::CreateAnd(threadId, module->constantThreadIDMask,
-                                       "", currentBlock);
-  threadId = new IntToPtrInst(threadId, module->JavaThreadType, "",
-                              currentBlock);
-
+  
+  Value* threadId = getCurrentThread();
 
   Value* geps[2] = { module->constantZero, module->constantEight };
 
@@ -316,6 +323,9 @@
     currentBlock = endBlock;
     nativeFunc = node;
   }
+  
+  Value* FrameAddr = CallInst::Create(module->llvm_frameaddress,
+                                     	module->constantZero, "", currentBlock);
 
   // When calling a native method, it may do whatever it wants with the
   // frame pointer. Therefore make sure it's on the stack. x86_64 has
@@ -362,12 +372,9 @@
   Value* lockMask = BinaryOperator::CreateAnd(lock, 
                                               module->constantThreadFreeMask,
                                               "", currentBlock);
-  Value* threadId = CallInst::Create(module->llvm_frameaddress,
-                                     module->constantZero, "", currentBlock);
+  Value* threadId = getCurrentThread();
   threadId = new PtrToIntInst(threadId, module->pointerSizeType, "",
                               currentBlock);
-  threadId = BinaryOperator::CreateAnd(threadId, module->constantThreadIDMask,
-                                       "", currentBlock);
   
   Value* cmp = new ICmpInst(ICmpInst::ICMP_EQ, lockMask, threadId, "",
                             currentBlock);
@@ -404,13 +411,9 @@
   lock = new PtrToIntInst(lock, module->pointerSizeType, "", currentBlock);
   Value* lockMask = BinaryOperator::CreateAnd(lock, module->constantLockedMask,
                                               "", currentBlock);
-  Value* threadId = CallInst::Create(module->llvm_frameaddress,
-                                     module->constantZero, "", currentBlock);
+  Value* threadId = getCurrentThread();
   threadId = new PtrToIntInst(threadId, module->pointerSizeType, "",
                               currentBlock);
-  threadId = BinaryOperator::CreateAnd(threadId, module->constantThreadIDMask,
-                                       "", currentBlock);
-  
   Value* cmp = new ICmpInst(ICmpInst::ICMP_EQ, lockMask, threadId, "",
                             currentBlock);
   
@@ -710,14 +713,7 @@
   Value* NewIsolate = 0;
   Value* IsolatePtr = 0;
   if (loader != loader->bootstrapLoader && isPublic(compilingMethod->access)) {
-    threadId = CallInst::Create(module->llvm_frameaddress, module->constantZero,
-                                "", currentBlock);
-    threadId = new PtrToIntInst(threadId, module->pointerSizeType, "",
-                                currentBlock);
-    threadId = BinaryOperator::CreateAnd(threadId, module->constantThreadIDMask,
-                                       "", currentBlock);
-  
-    threadId = new IntToPtrInst(threadId, module->ptrPtrType, "", currentBlock);
+    threadId = getCurrentThread();
      
     IsolateIDPtr = GetElementPtrInst::Create(threadId, module->constantThree,
                                              "", currentBlock);
@@ -1157,18 +1153,7 @@
     // catch the exception but resume unwinding.
     JnjvmClassLoader* loader = compilingClass->classLoader;;
     if (loader != loader->bootstrapLoader) {
-      Value* threadId = CallInst::Create(module->llvm_frameaddress,
-                                         module->constantZero,
-                                         "", currentBlock);
-      threadId = new PtrToIntInst(threadId, module->pointerSizeType, "",
-                                  currentBlock);
-      threadId = BinaryOperator::CreateAnd(threadId,
-                                           module->constantThreadIDMask,
-                                           "", currentBlock);
-  
-      threadId = new IntToPtrInst(threadId, module->ptrPtrType, "",
-                                  currentBlock);
-     
+      Value* threadId = getCurrentThread();
       Value* Isolate = GetElementPtrInst::Create(threadId,
                                                  module->constantFour, "",
                                                  currentBlock);
@@ -1246,17 +1231,9 @@
     Value* OldIsolate = 0;
     Value* NewIsolate = 0;
     Value* IsolatePtr = 0;
+    currentBlock = cur->javaHandler;
     if (loader != loader->bootstrapLoader) {
-      threadId = CallInst::Create(module->llvm_frameaddress, 
-                                  module->constantZero, "", cur->javaHandler);
-      threadId = new PtrToIntInst(threadId, module->pointerSizeType, "",
-                                  cur->javaHandler);
-      threadId = BinaryOperator::CreateAnd(threadId, 
-                                           module->constantThreadIDMask, "",
-                                           cur->javaHandler);
-  
-      threadId = new IntToPtrInst(threadId, module->ptrPtrType, "",
-                                  cur->javaHandler);
+      threadId = getCurrentThread();
      
       IsolateIDPtr = GetElementPtrInst::Create(threadId, module->constantThree,
                                                "", cur->javaHandler);
@@ -1886,16 +1863,12 @@
   Cl = new BitCastInst(Cl, module->JavaCommonClassType, "", currentBlock);
   new StoreInst(Cl, GEP, currentBlock);
   
-  Value* gep2[2] = { module->constantZero, module->JavaObjectLockOffsetConstant };
+  Value* gep2[2] = { module->constantZero,
+                     module->JavaObjectLockOffsetConstant };
   Value* lockPtr = GetElementPtrInst::Create(val, gep2, gep2 + 2, "",
                                              currentBlock);
-  Value* threadId = CallInst::Create(module->llvm_frameaddress,
-                                     module->constantZero, "", currentBlock);
-  threadId = new PtrToIntInst(threadId, module->pointerSizeType, "",
-                              currentBlock);
-  threadId = BinaryOperator::CreateAnd(threadId, module->constantThreadIDMask,
-                                       "", currentBlock);
-  threadId = new IntToPtrInst(threadId, module->ptrType, "", currentBlock);
+  Value* threadId = getCurrentThread();
+  threadId = new BitCastInst(threadId, module->ptrType, "", currentBlock);
   new StoreInst(threadId, lockPtr, currentBlock);
 
   push(val, false);

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.h Mon Feb  2 08:49:22 2009
@@ -116,8 +116,9 @@
   llvm::Value* getConstantPoolAt(uint32 index, llvm::Function* resolver,
                                  const llvm::Type* returnType,
                                  llvm::Value* addArg, bool doThrow = true);
- 
-  
+
+  /// getCurrentThread - Emit code to get the current thread.
+  llvm::Value* getCurrentThread();
 
 //===--------------------------- Inline support ---------------------------===//
 

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaJITOpcodes.cpp Mon Feb  2 08:49:22 2009
@@ -1948,16 +1948,9 @@
                            module->JavaObjectLockOffsetConstant };
         Value* lockPtr = GetElementPtrInst::Create(res, gep1, gep1 + 2,
                                                    "", currentBlock);
-        Value* threadId = CallInst::Create(module->llvm_frameaddress,
-                                           module->constantZero, "",
-                                           currentBlock);
-        threadId = new PtrToIntInst(threadId, module->pointerSizeType, "",
-                                    currentBlock);
-        threadId = BinaryOperator::CreateAnd(threadId,
-                                             module->constantThreadIDMask,
-                                             "", currentBlock);
-        threadId = new IntToPtrInst(threadId, module->ptrType, "",
-                                    currentBlock);
+        Value* threadId = getCurrentThread();
+        
+        threadId = new BitCastInst(threadId, module->ptrType, "", currentBlock);
 
         new StoreInst(threadId, lockPtr, currentBlock);
 





More information about the vmkit-commits mailing list