[vmkit-commits] [vmkit] r137038 - in /vmkit/trunk: include/j3/JavaLLVMCompiler.h lib/J3/Compiler/JavaJITCompiler.cpp lib/J3/Compiler/LLVMInfo.cpp lib/J3/VMCore/JavaTypes.cpp lib/J3/VMCore/JavaTypes.h lib/Mvm/CommonThread/ObjectLocks.cpp

Nicolas Geoffray nicolas.geoffray at lip6.fr
Sun Aug 7 08:37:46 PDT 2011


Author: geoffray
Date: Sun Aug  7 10:37:46 2011
New Revision: 137038

URL: http://llvm.org/viewvc/llvm-project?rev=137038&view=rev
Log:
Avoid duplicated stubs by caching on the llvm::FunctionType.


Modified:
    vmkit/trunk/include/j3/JavaLLVMCompiler.h
    vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp
    vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp
    vmkit/trunk/lib/J3/VMCore/JavaTypes.cpp
    vmkit/trunk/lib/J3/VMCore/JavaTypes.h
    vmkit/trunk/lib/Mvm/CommonThread/ObjectLocks.cpp

Modified: vmkit/trunk/include/j3/JavaLLVMCompiler.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/JavaLLVMCompiler.h?rev=137038&r1=137037&r2=137038&view=diff
==============================================================================
--- vmkit/trunk/include/j3/JavaLLVMCompiler.h (original)
+++ vmkit/trunk/include/j3/JavaLLVMCompiler.h Sun Aug  7 10:37:46 2011
@@ -14,6 +14,7 @@
 #include "j3/J3Intrinsics.h"
 #include "j3/LLVMInfo.h"
 
+#include "llvm/ADT/DenseMap.h"
 #include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 
@@ -43,6 +44,7 @@
 class JavaLLVMCompiler : public JavaCompiler {
   friend class LLVMClassInfo;
   friend class LLVMMethodInfo;
+  friend class LLVMSignatureInfo;
 
 protected:
   llvm::Module* TheModule;
@@ -75,6 +77,14 @@
   std::map<llvm::MDNode*, JavaMethod*> DbgInfos;
   typedef std::map<llvm::MDNode*, JavaMethod*>::iterator dbg_iterator;
 
+  llvm::DenseMap<llvm::FunctionType*, llvm::Function*> virtualStubs;
+  llvm::DenseMap<llvm::FunctionType*, llvm::Function*> specialStubs;
+  llvm::DenseMap<llvm::FunctionType*, llvm::Function*> staticStubs;
+  llvm::DenseMap<llvm::FunctionType*, llvm::Function*> virtualBufs;
+  llvm::DenseMap<llvm::FunctionType*, llvm::Function*> staticBufs;
+  llvm::DenseMap<llvm::FunctionType*, llvm::Function*> virtualAPs;
+  llvm::DenseMap<llvm::FunctionType*, llvm::Function*> staticAPs;
+
 public:
   JavaLLVMCompiler(const std::string &ModuleID);
   

Modified: vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp?rev=137038&r1=137037&r2=137038&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp Sun Aug  7 10:37:46 2011
@@ -313,9 +313,10 @@
   
     Jnjvm* vm = JavaThread::get()->getJVM();
     mvm::MvmModule::addToVM(vm, &GFI, (JIT*)executionEngine, allocator, meth);
-  }
+
     // Now that it's compiled, we don't need the IR anymore
-  func->deleteBody();
+    func->deleteBody();
+  }
   mvm::MvmModule::unprotectIR();
   return res;
 }
@@ -323,14 +324,18 @@
 void* JavaJITCompiler::GenerateStub(llvm::Function* F) {
   mvm::MvmModule::protectIR();
   void* res = executionEngine->getPointerToGlobal(F);
+ 
+  // If the stub was already generated through an equivalent signature,
+  // The body has been deleted, so the function just becomes a declaration.
+  if (!F->isDeclaration()) {
+    llvm::GCFunctionInfo& GFI = GCInfo->getFunctionInfo(*F);
   
-  llvm::GCFunctionInfo& GFI = GCInfo->getFunctionInfo(*F);
-  
-  Jnjvm* vm = JavaThread::get()->getJVM();
-  mvm::MvmModule::addToVM(vm, &GFI, (JIT*)executionEngine, allocator, NULL);
+    Jnjvm* vm = JavaThread::get()->getJVM();
+    mvm::MvmModule::addToVM(vm, &GFI, (JIT*)executionEngine, allocator, NULL);
   
-  // Now that it's compiled, we don't need the IR anymore
-  F->deleteBody();
+    // Now that it's compiled, we don't need the IR anymore
+    F->deleteBody();
+  }
   mvm::MvmModule::unprotectIR();
   return res;
 }

Modified: vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp?rev=137038&r1=137037&r2=137038&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp Sun Aug  7 10:37:46 2011
@@ -311,21 +311,26 @@
   LLVMContext& context = Compiler->getLLVMModule()->getContext();
   J3Intrinsics& Intrinsics = *Compiler->getIntrinsics();
   Function* res = 0;
+  FunctionType* FTy = virt ? getVirtualBufType() : getStaticBufType();
+  if (virt) {
+    res = Compiler->virtualBufs[FTy];
+  } else {
+    res = Compiler->staticBufs[FTy];
+  }
+  if (res != NULL) {
+    return res;
+  }
   if (Compiler->isStaticCompiling()) {
     mvm::ThreadAllocator allocator;
     const char* type = virt ? "virtual_buf" : "static_buf";
     char* buf = (char*)allocator.Allocate(
         (signature->keyName->size << 1) + 1 + 11);
     signature->nativeName(buf, type);
-    res = Function::Create(virt ? getVirtualBufType() : getStaticBufType(),
-                           GlobalValue::ExternalLinkage, buf,
-                           Compiler->getLLVMModule());
-  
-
+    res = Function::Create(
+        FTy, GlobalValue::ExternalLinkage, buf, Compiler->getLLVMModule());
   } else {
-    res = Function::Create(virt ? getVirtualBufType() : getStaticBufType(),
-                           GlobalValue::ExternalLinkage, "",
-                           Compiler->getLLVMModule());
+    res = Function::Create(
+        FTy, GlobalValue::ExternalLinkage, "", Compiler->getLLVMModule());
   }
 
   BasicBlock* currentBlock = BasicBlock::Create(context, "enter", res);
@@ -390,6 +395,12 @@
   
   res->setGC("vmkit");
 
+  if (virt) {
+    Compiler->virtualBufs[FTy] = res;
+  } else {
+    Compiler->staticBufs[FTy] = res;
+  }
+
   return res;
 }
 
@@ -399,21 +410,26 @@
   
   J3Intrinsics& Intrinsics = *Compiler->getIntrinsics();
   Function* res = NULL;
+  FunctionType* FTy = virt ? getVirtualBufType() : getStaticBufType();
+  if (virt) {
+    res = Compiler->virtualAPs[FTy];
+  } else {
+    res = Compiler->staticAPs[FTy];
+  }
+  if (res != NULL) {
+    return res;
+  }
   if (Compiler->isStaticCompiling()) {
     mvm::ThreadAllocator allocator;
     const char* type = virt ? "virtual_ap" : "static_ap";
     char* buf = (char*)allocator.Allocate(
         (signature->keyName->size << 1) + 1 + 11);
     signature->nativeName(buf, type);
-    res = Function::Create(virt ? getVirtualBufType() : getStaticBufType(),
-                           GlobalValue::ExternalLinkage, buf,
-                           Compiler->getLLVMModule());
-  
-
+    res = Function::Create(
+        FTy, GlobalValue::ExternalLinkage, buf, Compiler->getLLVMModule());
   } else {
-    res = Function::Create(virt ? getVirtualBufType() : getStaticBufType(),
-                           GlobalValue::ExternalLinkage, "",
-                           Compiler->getLLVMModule());
+    res = Function::Create(
+        FTy, GlobalValue::ExternalLinkage, "", Compiler->getLLVMModule());
   }
   LLVMContext& context = Compiler->getLLVMModule()->getContext();
   
@@ -467,6 +483,11 @@
   
   res->setGC("vmkit");
   
+  if (virt) {
+    Compiler->virtualAPs[FTy] = res;
+  } else {
+    Compiler->staticAPs[FTy] = res;
+  }
   return res;
 }
 
@@ -478,21 +499,30 @@
   
   J3Intrinsics& Intrinsics = *Compiler->getIntrinsics();
   Function* stub = NULL;
+  FunctionType* FTy = (virt || special)? getVirtualType() : getStaticType();
+  if (virt) {
+    stub = Compiler->virtualStubs[FTy];
+  } else if (special) {
+    stub = Compiler->specialStubs[FTy];
+  } else {
+    stub = Compiler->staticStubs[FTy];
+  }
+  if (stub != NULL) {
+    return stub;
+  }
   if (Compiler->isStaticCompiling()) {
     mvm::ThreadAllocator allocator;
     const char* type = virt ? "virtual_stub" : special ? "special_stub" : "static_stub";
     char* buf = (char*)allocator.Allocate(
         (signature->keyName->size << 1) + 1 + 11);
     signature->nativeName(buf, type);
-    stub = Function::Create((virt || special)? getVirtualType() : getStaticType(),
-                            GlobalValue::ExternalLinkage, buf,
-                            Compiler->getLLVMModule());
+    stub = Function::Create(
+        FTy, GlobalValue::ExternalLinkage, buf, Compiler->getLLVMModule());
   
 
   } else {
-    stub = Function::Create((virt || special)? getVirtualType() : getStaticType(),
-                            GlobalValue::ExternalLinkage, "",
-                            Compiler->getLLVMModule());
+    stub = Function::Create(
+        FTy, GlobalValue::ExternalLinkage, "", Compiler->getLLVMModule());
   }
   LLVMContext& context = Compiler->getLLVMModule()->getContext();
   
@@ -568,7 +598,14 @@
   }
   
   stub->setGC("vmkit");
-  
+ 
+  if (virt) {
+    Compiler->virtualStubs[FTy] = stub;
+  } else if (special) {
+    Compiler->specialStubs[FTy] = stub;
+  } else {
+    Compiler->staticStubs[FTy] = stub;
+  }
   return stub;
 }
 

Modified: vmkit/trunk/lib/J3/VMCore/JavaTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaTypes.cpp?rev=137038&r1=137037&r2=137038&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaTypes.cpp (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaTypes.cpp Sun Aug  7 10:37:46 2011
@@ -170,37 +170,18 @@
 }
 
 void Signdef::nativeName(char* ptr, const char* ext) const {
-  sint32 i = 0;
-  while (i < keyName->size) {
-    char c = keyName->elements[i++];
-    if (c == I_PARG) {
-      ptr[0] = '_';
-      ptr[1] = '_';
-      ptr += 2;
-    } else if (c == '/') {
-      ptr[0] = '_';
-      ++ptr;
-    } else if (c == '_') {
-      ptr[0] = '_';
-      ptr[1] = '1';
-      ptr += 2;
-    } else if (c == I_END_REF) {
-      ptr[0] = '_';
-      ptr[1] = '2';
-      ptr += 2;
-    } else if (c == I_TAB) {
-      ptr[0] = '_';
-      ptr[1] = '3';
-      ptr += 2;
-    } else if (c == I_PARD) {
-      ptr[0] = '_';
-      ptr[1] = '_';
-      ptr += 2;
-    } else {
-      ptr[0] = c;
-      ++ptr;
-    }
+  ptr[0] = '_';
+  ptr[1] = '_';
+  ptr += 2;
+  for (uint32_t i = 0; i < nbArguments; i++) {
+    ptr[0] = arguments[i + 1]->getId();
+    ++ptr;
   }
+  ptr[0] = '_';
+  ptr[1] = '_';
+  ptr += 2;
+  ptr[0] = arguments[0]->getId();
+  ++ptr;
 
   assert(ext && "I need an extension");
   memcpy(ptr, ext, strlen(ext) + 1);

Modified: vmkit/trunk/lib/J3/VMCore/JavaTypes.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaTypes.h?rev=137038&r1=137037&r2=137038&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaTypes.h (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaTypes.h Sun Aug  7 10:37:46 2011
@@ -141,6 +141,8 @@
   const UTF8* getKey() const {
     return keyName;
   }
+
+  virtual char getId() const = 0;
   
   virtual ~Typedef() {}
 };
@@ -152,6 +154,10 @@
   char charId;
   
 public:
+
+  virtual char getId() const {
+    return charId;
+  }
   
   virtual bool trace() const {
     return false;
@@ -231,6 +237,10 @@
   ArrayTypedef(const UTF8* name) {
     keyName = name;
   }
+
+  virtual char getId() const {
+    return I_REF;
+  }
 };
 
 class ObjectTypedef : public Typedef {
@@ -254,6 +264,9 @@
     return pseudoAssocClassName;
   }
 
+  virtual char getId() const {
+    return I_REF;
+  }
 };
 
 

Modified: vmkit/trunk/lib/Mvm/CommonThread/ObjectLocks.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommonThread/ObjectLocks.cpp?rev=137038&r1=137037&r2=137038&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/CommonThread/ObjectLocks.cpp (original)
+++ vmkit/trunk/lib/Mvm/CommonThread/ObjectLocks.cpp Sun Aug  7 10:37:46 2011
@@ -86,10 +86,10 @@
 void printDebugMessage(gc* object, LockSystem& table) {
   llvm_gcroot(object, 0);
   fprintf(stderr,
-      "WARNING: [%p] has been waiting really long for %p (header = %lx)\n",
+      "WARNING: [%p] has been waiting really long for %p (header = %p)\n",
       (void*)mvm::Thread::get(),
       (void*)object,
-      object->header);
+      (void*)object->header);
   FatLock* obj = table.getFatLockFromID(object->header);
   if (obj != NULL) {
     fprintf(stderr,





More information about the vmkit-commits mailing list