[vmkit-commits] [vmkit] r91447 - in /vmkit/trunk/lib/JnJVM: Compiler/JavaAOTCompiler.cpp Compiler/JavaJITCompiler.cpp VMCore/JavaClass.cpp VMCore/JavaClass.h

Nicolas Geoffray nicolas.geoffray at lip6.fr
Tue Dec 15 12:19:41 PST 2009


Author: geoffray
Date: Tue Dec 15 14:19:41 2009
New Revision: 91447

URL: http://llvm.org/viewvc/llvm-project?rev=91447&view=rev
Log:
Optimize IMT by avoiding duplicates in IMT entries.


Modified:
    vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp
    vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Tue Dec 15 14:19:41 2009
@@ -1530,7 +1530,7 @@
   } else {
     Class* cl = classDef->asClass();
     assert(cl && "Not a class");
-    std::vector<JavaMethod*> contents[InterfaceMethodTable::NumIndexes];
+    std::set<JavaMethod*> contents[InterfaceMethodTable::NumIndexes];
     classDef->asClass()->fillIMT(contents);
   
 
@@ -1543,46 +1543,71 @@
     std::vector<Constant*> IElemts;
 
     for (uint32_t i = 0; i < InterfaceMethodTable::NumIndexes; ++i) {
-      std::vector<JavaMethod*>& atIndex = contents[i];
+      std::set<JavaMethod*>& atIndex = contents[i];
       uint32_t size = atIndex.size();
       if (size == 1) {
-        JavaMethod* meth = cl->lookupMethodDontThrow(atIndex[0]->name,
-                                                     atIndex[0]->type,
+        JavaMethod* Imeth = *(atIndex.begin());
+        JavaMethod* meth = cl->lookupMethodDontThrow(Imeth->name,
+                                                     Imeth->type,
                                                      false, true, 0);
         LLVMMethodInfo* LMI = getMethodInfo(meth);
         Function* func = LMI->getMethod();
         IElemts.push_back(ConstantExpr::getBitCast(func, PTy));
       } else if (size > 1) {
-        uint32_t length = 2 * size;
+        std::vector<JavaMethod*> methods;
+        bool SameMethod = true;
+        JavaMethod* OldMethod = 0;
+      
+        for (std::set<JavaMethod*>::iterator it = atIndex.begin(),
+             et = atIndex.end(); it != et; ++it) {
+          JavaMethod* Imeth = *it;
+          JavaMethod* Cmeth = cl->lookupMethodDontThrow(Imeth->name, Imeth->type,
+                                                      false, true, 0);
+       
+          if (OldMethod && OldMethod != Cmeth) SameMethod = false;
+          else OldMethod = Cmeth;
         
-        const ArrayType* ATy = 
-          dyn_cast<ArrayType>(JnjvmModule::VTType->getContainedType(0));
-        ATy = ArrayType::get(PTy, length);
-        std::vector<Constant*> InternalElemts;
-     
+          methods.push_back(Cmeth);
+        }
 
-        for (uint32_t j = 0; j < size; ++j) {
-          JavaMethod* Imeth = atIndex[j];
-          JavaMethod* Cmeth = cl->lookupMethodDontThrow(Imeth->name,
-                                                        Imeth->type,
-                                                        false, true, 0);
-          LLVMMethodInfo* LMI = getMethodInfo(Cmeth);
+        if (SameMethod) {
+          LLVMMethodInfo* LMI = getMethodInfo(methods[0]);
           Function* func = LMI->getMethod();
-          InternalElemts.push_back(
-            ConstantExpr::getBitCast(getMethodInClass(Imeth), PTy));
-          InternalElemts.push_back(ConstantExpr::getBitCast(func, PTy));
-        }
-        Constant* Array = ConstantArray::get(ATy, InternalElemts);
+          IElemts.push_back(ConstantExpr::getBitCast(func, PTy));
+        } else {
+
+          uint32_t length = 2 * size;
+        
+          const ArrayType* ATy = 
+            dyn_cast<ArrayType>(JnjvmModule::VTType->getContainedType(0));
+          ATy = ArrayType::get(PTy, length);
+          std::vector<Constant*> InternalElemts;
+     
+
+          std::set<JavaMethod*>::iterator Interf = atIndex.begin();
+          for (std::vector<JavaMethod*>::iterator it = methods.begin(),
+               et = methods.end(); it != et; ++it, ++Interf) {
+            JavaMethod* Imeth = *Interf;
+            JavaMethod* Cmeth = *it;
+
+            LLVMMethodInfo* LMI = getMethodInfo(Cmeth);
+            Function* func = LMI->getMethod();
+            InternalElemts.push_back(
+              ConstantExpr::getBitCast(getMethodInClass(Imeth), PTy));
+            InternalElemts.push_back(ConstantExpr::getBitCast(func, PTy));
+          }
+          Constant* Array = ConstantArray::get(ATy, InternalElemts);
     
-        GlobalVariable* GV = new GlobalVariable(*getLLVMModule(), ATy, false,
-                                                GlobalValue::InternalLinkage,
-                                              Array, "");
+          GlobalVariable* GV = new GlobalVariable(*getLLVMModule(), ATy, false,
+                                                  GlobalValue::InternalLinkage,
+                                                  Array, "");
      
-        Constant* CI =
-          ConstantExpr::getPtrToInt(GV, Type::getInt32Ty(getGlobalContext()));
-        CI = ConstantExpr::getAdd(CI, JavaIntrinsics.constantOne);
-        CI = ConstantExpr::getIntToPtr(CI, PTy);
-        IElemts.push_back(CI);
+          Constant* CI =
+            ConstantExpr::getPtrToInt(GV, Type::getInt32Ty(getGlobalContext()));
+          CI = ConstantExpr::getAdd(CI, JavaIntrinsics.constantOne);
+          CI = ConstantExpr::getIntToPtr(CI, PTy);
+          IElemts.push_back(CI);
+        }
       } else {
         IElemts.push_back(N);
       }

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp Tue Dec 15 14:19:41 2009
@@ -266,39 +266,67 @@
   InterfaceMethodTable* IMT = cl->virtualVT->IMT;
   if (!IMT) return;
  
-  std::vector<JavaMethod*> contents[InterfaceMethodTable::NumIndexes];
+  std::set<JavaMethod*> contents[InterfaceMethodTable::NumIndexes];
   cl->fillIMT(contents);
   
   ExecutionEngine* EE = mvm::MvmModule::executionEngine;
   
   for (uint32_t i = 0; i < InterfaceMethodTable::NumIndexes; ++i) {
-    std::vector<JavaMethod*>& atIndex = contents[i];
+    std::set<JavaMethod*>& atIndex = contents[i];
     uint32_t size = atIndex.size();
     if (size == 1) {
-      JavaMethod* meth = cl->lookupMethodDontThrow(atIndex[0]->name,
-                                                   atIndex[0]->type,
+      JavaMethod* Imeth = *(atIndex.begin());
+      JavaMethod* meth = cl->lookupMethodDontThrow(Imeth->name,
+                                                   Imeth->type,
                                                    false, true, 0);
       LLVMMethodInfo* LMI = getMethodInfo(meth);
       Function* func = LMI->getMethod();
       uintptr_t res = (uintptr_t)EE->getPointerToFunctionOrStub(func);
       IMT->contents[i] = res;
     } else if (size > 1) {
-      uint32_t length = 2 * size * sizeof(uintptr_t);
+      std::vector<JavaMethod*> methods;
+      bool SameMethod = true;
+      JavaMethod* OldMethod = 0;
       
-      uintptr_t* table = (uintptr_t*)
-        cl->classLoader->allocator.Allocate(length, "IMT");
-      
-      IMT->contents[i] = (uintptr_t)table | 1;
-
-      for (uint32_t j = 0; j < size; ++j) {
-        JavaMethod* Imeth = atIndex[j];
+      for (std::set<JavaMethod*>::iterator it = atIndex.begin(),
+           et = atIndex.end(); it != et; ++it) {
+        JavaMethod* Imeth = *it;
         JavaMethod* Cmeth = cl->lookupMethodDontThrow(Imeth->name, Imeth->type,
                                                       false, true, 0);
-        LLVMMethodInfo* LMI = getMethodInfo(Cmeth);
+       
+        if (OldMethod && OldMethod != Cmeth) SameMethod = false;
+        else OldMethod = Cmeth;
+        
+        methods.push_back(Cmeth);
+      }
+
+      if (SameMethod) {
+        LLVMMethodInfo* LMI = getMethodInfo(methods[0]);
         Function* func = LMI->getMethod();
         uintptr_t res = (uintptr_t)EE->getPointerToFunctionOrStub(func);
-        table[j << 1] = (uintptr_t)Imeth;
-        table[(j << 1) + 1] = res;
+        IMT->contents[i] = res;
+      } else {
+
+        uint32_t length = 2 * size * sizeof(uintptr_t);
+      
+        uintptr_t* table = (uintptr_t*)
+          cl->classLoader->allocator.Allocate(length, "IMT");
+      
+        IMT->contents[i] = (uintptr_t)table | 1;
+
+        int j = 0;
+        std::set<JavaMethod*>::iterator Interf = atIndex.begin();
+        for (std::vector<JavaMethod*>::iterator it = methods.begin(),
+             et = methods.end(); it != et; ++it, j += 2, ++Interf) {
+          JavaMethod* Imeth = *Interf;
+          JavaMethod* Cmeth = *it;
+          
+          LLVMMethodInfo* LMI = getMethodInfo(Cmeth);
+          Function* func = LMI->getMethod();
+          uintptr_t res = (uintptr_t)EE->getPointerToFunctionOrStub(func);
+          table[j] = (uintptr_t)Imeth;
+          table[j + 1] = res;
+        }
       }
     }
   }

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Tue Dec 15 14:19:41 2009
@@ -772,7 +772,7 @@
   }
 }
 
-void Class::fillIMT(std::vector<JavaMethod*>* meths) {
+void Class::fillIMT(std::set<JavaMethod*>* meths) {
   for (uint32 i = 0; i < nbInterfaces; ++i) {
     interfaces[i]->fillIMT(meths);
   }
@@ -783,7 +783,8 @@
     for (uint32 i = 0; i < nbVirtualMethods; ++i) {
       JavaMethod& meth = virtualMethods[i];
       uint32_t index = InterfaceMethodTable::getIndex(meth.name, meth.type);
-      meths[index].push_back(&meth);
+      if (meths[index].find(&meth) == meths[index].end())
+        meths[index].insert(&meth);
     }
   }
 }

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Tue Dec 15 14:19:41 2009
@@ -25,6 +25,7 @@
 #include "JnjvmConfig.h"
 
 #include <cassert>
+#include <set>
 
 namespace jnjvm {
 
@@ -918,7 +919,7 @@
   /// fillIMT - Fill the vector with vectors of methods with the same IMT
   /// index.
   ///
-  void fillIMT(std::vector<JavaMethod*>* meths);
+  void fillIMT(std::set<JavaMethod*>* meths);
 
 private:
 





More information about the vmkit-commits mailing list