[vmkit-commits] [vmkit] r96132 - in /vmkit/trunk: include/j3/JnjvmModule.h lib/J3/Compiler/JavaAOTCompiler.cpp lib/J3/Compiler/JavaJIT.cpp lib/J3/Compiler/JavaJITCompiler.cpp lib/J3/VMCore/JavaClass.h

Nicolas Geoffray nicolas.geoffray at lip6.fr
Sat Feb 13 15:09:12 PST 2010


Author: geoffray
Date: Sat Feb 13 17:09:12 2010
New Revision: 96132

URL: http://llvm.org/viewvc/llvm-project?rev=96132&view=rev
Log:
New Interface for creating stubs. No functionality changes.


Modified:
    vmkit/trunk/include/j3/JnjvmModule.h
    vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp
    vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp
    vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp
    vmkit/trunk/lib/J3/VMCore/JavaClass.h

Modified: vmkit/trunk/include/j3/JnjvmModule.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/JnjvmModule.h?rev=96132&r1=96131&r2=96132&view=diff

==============================================================================
--- vmkit/trunk/include/j3/JnjvmModule.h (original)
+++ vmkit/trunk/include/j3/JnjvmModule.h Sat Feb 13 17:09:12 2010
@@ -472,6 +472,10 @@
   llvm::FunctionPassManager* JavaFunctionPasses;
   llvm::FunctionPassManager* JavaNativeFunctionPasses;
   
+  virtual bool needsCallback(JavaMethod* meth, bool* needsInit) {
+    *needsInit = true;
+    return meth == NULL;
+  }
   virtual llvm::Value* addCallback(Class* cl, uint16 index, Signdef* sign,
                                    bool stat) = 0;
   
@@ -577,6 +581,7 @@
   
   virtual llvm::Value* addCallback(Class* cl, uint16 index, Signdef* sign,
                                    bool stat);
+  virtual uintptr_t getPointerOrStub(JavaMethod& meth, int type);
 
 #ifdef WITH_LLVM_GCC
   virtual mvm::StackScanner* createStackScanner() {

Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=96132&r1=96131&r2=96132&view=diff

==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Sat Feb 13 17:09:12 2010
@@ -1829,7 +1829,7 @@
 }
 
 Value* JavaAOTCompiler::addCallback(Class* cl, uint16 index,
-                                      Signdef* sign, bool stat) {
+                                    Signdef* sign, bool stat) {
  
   JavaConstantPool* ctpInfo = cl->ctpInfo;
   Signdef* signature = 0;

Modified: vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp?rev=96132&r1=96131&r2=96132&view=diff

==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp Sat Feb 13 17:09:12 2010
@@ -1604,7 +1604,6 @@
   std::vector<Value*> args;
   FunctionType::param_iterator it  = virtualType->param_end();
   makeArgs(it, index, args, signature->nbArguments + 1);
-  Value* func = 0;
 
   if (finalCl) {
     Class* lookup = finalCl->isArray() ? finalCl->super : finalCl->asClass();
@@ -1648,22 +1647,25 @@
   args.push_back(node);
 #endif
 
-  if (!meth) {
-    // Make sure the class is loaded before materializing the method.
-    uint32 clIndex = ctpInfo->getClassIndexFromMethod(index);
-    UserCommonClass* cl = 0;
-    Value* Cl = getResolvedCommonClass(clIndex, false, &cl);
-    if (!cl) {
-      CallInst::Create(module->ForceLoadedCheckFunction, Cl, "", currentBlock);
-    }
-    func =  TheCompiler->addCallback(compilingClass, index, signature, false);
-  } else {
-    func = TheCompiler->getMethod(meth);
-  }
-
   if (meth && canBeInlined(meth)) {
     val = invokeInline(meth, args);
   } else {
+    Value* func = 0;
+    bool needsInit = false;
+    if (TheCompiler->needsCallback(meth, &needsInit)) {
+      if (needsInit) {
+        // Make sure the class is loaded before materializing the method.
+        uint32 clIndex = ctpInfo->getClassIndexFromMethod(index);
+        UserCommonClass* cl = 0;
+        Value* Cl = getResolvedCommonClass(clIndex, false, &cl);
+        if (!cl) {
+          CallInst::Create(module->ForceLoadedCheckFunction, Cl, "",currentBlock);
+        }
+      }
+      func = TheCompiler->addCallback(compilingClass, index, signature, false);
+    } else {
+      func = TheCompiler->getMethod(meth);
+    }
     val = invoke(func, args, "", currentBlock);
   }
   
@@ -1727,24 +1729,23 @@
                        currentBlock);
     }
     
-    Value* func = 0;
-    if (meth) {
-      /*if (meth == upcalls->SystemArraycopy ||
-          meth == upcalls->VMSystemArraycopy) {
-        lowerArraycopy(args);
-        return;
-      }*/
-      func = TheCompiler->getMethod(meth);
-    } else {
-      func = TheCompiler->addCallback(compilingClass, index, signature, true);
-    }
-
     if (meth && canBeInlined(meth)) {
       val = invokeInline(meth, args);
     } else {
+      Value* func = 0;
+      bool needsInit = false;
+      if (TheCompiler->needsCallback(meth, &needsInit)) {
+        func = TheCompiler->addCallback(compilingClass, index, signature, true);
+      } else {
+        /*if (meth == upcalls->SystemArraycopy ||
+            meth == upcalls->VMSystemArraycopy) {
+          lowerArraycopy(args);
+          return;
+        }*/
+        func = TheCompiler->getMethod(meth);
+      }
       val = invoke(func, args, "", currentBlock);
     }
-
   }
 
   const llvm::Type* retType = staticType->getReturnType();

Modified: vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp?rev=96132&r1=96131&r2=96132&view=diff

==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp Sat Feb 13 17:09:12 2010
@@ -253,11 +253,8 @@
 
 
   // Fill the virtual table with function pointers.
-  ExecutionEngine* EE = mvm::MvmModule::executionEngine;
   for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) {
     JavaMethod& meth = cl->virtualMethods[i];
-    LLVMMethodInfo* LMI = getMethodInfo(&meth);
-    Function* func = LMI->getMethod();
 
     // Special handling for finalize method. Don't put a finalizer
     // if there is none, or if it is empty.
@@ -265,11 +262,11 @@
       if (!cl->super) {
         meth.canBeInlined = true;
       } else {
-        VT->destructor = (uintptr_t)EE->getPointerToFunctionOrStub(func);
+        VT->destructor = getPointerOrStub(meth, JavaMethod::Virtual);
       }
     } else {
-      VT->getFunctions()[meth.offset] = 
-        (uintptr_t)EE->getPointerToFunctionOrStub(func);
+      VT->getFunctions()[meth.offset] = getPointerOrStub(meth,
+                                                         JavaMethod::Virtual);
     }
   }
 
@@ -286,8 +283,6 @@
   std::set<JavaMethod*> contents[InterfaceMethodTable::NumIndexes];
   cl->fillIMT(contents);
   
-  ExecutionEngine* EE = mvm::MvmModule::executionEngine;
-  
   for (uint32_t i = 0; i < InterfaceMethodTable::NumIndexes; ++i) {
     std::set<JavaMethod*>& atIndex = contents[i];
     uint32_t size = atIndex.size();
@@ -297,10 +292,7 @@
                                                    Imeth->type,
                                                    false, true, 0);
       if (meth) {
-        LLVMMethodInfo* LMI = getMethodInfo(meth);
-        Function* func = LMI->getMethod();
-        uintptr_t res = (uintptr_t)EE->getPointerToFunctionOrStub(func);
-        IMT->contents[i] = res;
+        IMT->contents[i] = getPointerOrStub(*meth, JavaMethod::Interface);
       } else {
         IMT->contents[i] = (uintptr_t)ThrowUnfoundInterface;
       }
@@ -323,10 +315,8 @@
 
       if (SameMethod) {
         if (methods[0]) {
-          LLVMMethodInfo* LMI = getMethodInfo(methods[0]);
-          Function* func = LMI->getMethod();
-          uintptr_t res = (uintptr_t)EE->getPointerToFunctionOrStub(func);
-          IMT->contents[i] = res;
+          IMT->contents[i] = getPointerOrStub(*(methods[0]),
+                                              JavaMethod::Interface);
         } else {
           IMT->contents[i] = (uintptr_t)ThrowUnfoundInterface;
         }
@@ -348,10 +338,7 @@
          
           table[j] = (uintptr_t)Imeth;
           if (Cmeth) {
-            LLVMMethodInfo* LMI = getMethodInfo(Cmeth);
-            Function* func = LMI->getMethod();
-            uintptr_t res = (uintptr_t)EE->getPointerToFunctionOrStub(func);
-            table[j + 1] = res;
+             table[j + 1] = getPointerOrStub(*Cmeth, JavaMethod::Interface);
           } else {
             table[j + 1] = (uintptr_t)ThrowUnfoundInterface;
           }
@@ -428,3 +415,10 @@
   return JavaCompiler::loadMethod(handle, symbol);
 }
 
+uintptr_t JavaJITCompiler::getPointerOrStub(JavaMethod& meth,
+                                            int side) {
+  ExecutionEngine* EE = mvm::MvmModule::executionEngine;
+  LLVMMethodInfo* LMI = getMethodInfo(&meth);
+  Function* func = LMI->getMethod();
+  return (uintptr_t)EE->getPointerToFunctionOrStub(func);
+}

Modified: vmkit/trunk/lib/J3/VMCore/JavaClass.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaClass.h?rev=96132&r1=96131&r2=96132&view=diff

==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaClass.h (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaClass.h Sat Feb 13 17:09:12 2010
@@ -1011,6 +1011,13 @@
 
 public:
   
+  enum Type {
+    Static,
+    Special,
+    Interface,
+    Virtual
+  };
+
   /// constructMethod - Create a new method.
   ///
   void initialise(Class* cl, const UTF8* name, const UTF8* type, uint16 access);





More information about the vmkit-commits mailing list