[vmkit-commits] [vmkit] r97325 - in /vmkit/trunk: include/j3/JavaAOTCompiler.h include/j3/JavaCompiler.h include/j3/JavaLLVMCompiler.h include/j3/LLVMInfo.h lib/J3/Compiler/JavaJITCompiler.cpp lib/J3/Compiler/LLVMInfo.cpp lib/J3/Compiler/LLVMMaterializer.cpp lib/Mvm/Compiler/JIT.cpp

Nicolas Geoffray nicolas.geoffray at lip6.fr
Sat Feb 27 06:22:35 PST 2010


Author: geoffray
Date: Sat Feb 27 08:22:35 2010
New Revision: 97325

URL: http://llvm.org/viewvc/llvm-project?rev=97325&view=rev
Log:
Remove static methods and put all local to a compiler.


Modified:
    vmkit/trunk/include/j3/JavaAOTCompiler.h
    vmkit/trunk/include/j3/JavaCompiler.h
    vmkit/trunk/include/j3/JavaLLVMCompiler.h
    vmkit/trunk/include/j3/LLVMInfo.h
    vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp
    vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp
    vmkit/trunk/lib/J3/Compiler/LLVMMaterializer.cpp
    vmkit/trunk/lib/Mvm/Compiler/JIT.cpp

Modified: vmkit/trunk/include/j3/JavaAOTCompiler.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/JavaAOTCompiler.h?rev=97325&r1=97324&r2=97325&view=diff
==============================================================================
--- vmkit/trunk/include/j3/JavaAOTCompiler.h (original)
+++ vmkit/trunk/include/j3/JavaAOTCompiler.h Sat Feb 27 08:22:35 2010
@@ -174,7 +174,7 @@
   
   void CreateStaticInitializer();
   
-  static void setNoInline(Class* cl);
+  void setNoInline(Class* cl);
   
   void printStats();
   

Modified: vmkit/trunk/include/j3/JavaCompiler.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/JavaCompiler.h?rev=97325&r1=97324&r2=97325&view=diff
==============================================================================
--- vmkit/trunk/include/j3/JavaCompiler.h (original)
+++ vmkit/trunk/include/j3/JavaCompiler.h Sat Feb 27 08:22:35 2010
@@ -16,6 +16,7 @@
 #include <dlfcn.h>
 
 #include "mvm/GC/GC.h"
+#include "mvm/Allocator.h"
 
 namespace mvm {
   class UTF8;
@@ -27,11 +28,14 @@
 class CommonClass;
 class JavaMethod;
 class JavaVirtualTable;
+class JnjvmClassLoader;
 class Signdef;
 
 class JavaCompiler {
 public:
   
+  mvm::BumpPtrAllocator allocator;
+
   virtual JavaCompiler* Create(const std::string&) {
     return this;
   }

Modified: vmkit/trunk/include/j3/JavaLLVMCompiler.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/JavaLLVMCompiler.h?rev=97325&r1=97324&r2=97325&view=diff
==============================================================================
--- vmkit/trunk/include/j3/JavaLLVMCompiler.h (original)
+++ vmkit/trunk/include/j3/JavaLLVMCompiler.h Sat Feb 27 08:22:35 2010
@@ -56,8 +56,20 @@
   virtual void makeVT(Class* cl) = 0;
   virtual void makeIMT(Class* cl) = 0;
   
-  std::map<llvm::Function*, JavaMethod*> functions;  
+  std::map<llvm::Function*, JavaMethod*> functions;
   typedef std::map<llvm::Function*, JavaMethod*>::iterator function_iterator;
+  
+  std::map<JavaMethod*, LLVMMethodInfo*> method_infos;
+  typedef std::map<JavaMethod*, LLVMMethodInfo*>::iterator method_info_iterator;
+  
+  std::map<JavaField*, LLVMFieldInfo*> field_infos;
+  typedef std::map<JavaField*, LLVMFieldInfo*>::iterator field_info_iterator;
+  
+  std::map<Signdef*, LLVMSignatureInfo*> signature_infos;
+  typedef std::map<Signdef*, LLVMSignatureInfo*>::iterator signature_info_iterator;
+  
+  std::map<Class*, LLVMClassInfo*> class_infos;
+  typedef std::map<Class*, LLVMClassInfo*>::iterator class_info_iterator;
 
   std::map<llvm::MDNode*, JavaMethod*> DbgInfos;
   typedef std::map<llvm::MDNode*, JavaMethod*>::iterator dbg_iterator;
@@ -109,16 +121,63 @@
 
   void resolveVirtualClass(Class* cl);
   void resolveStaticClass(Class* cl);
-  static llvm::Function* getMethod(JavaMethod* meth);
+  llvm::Function* getMethod(JavaMethod* meth);
 
   void initialiseAssessorInfo();
   std::map<const char, LLVMAssessorInfo> AssessorInfo;
   LLVMAssessorInfo& getTypedefInfo(const Typedef* type);
 
-  static LLVMSignatureInfo* getSignatureInfo(Signdef* sign);
-  static LLVMClassInfo* getClassInfo(Class* cl);
-  static LLVMFieldInfo* getFieldInfo(JavaField* field);
-  static LLVMMethodInfo* getMethodInfo(JavaMethod* method);
+  LLVMSignatureInfo* getSignatureInfo(Signdef* sign) {
+    signature_info_iterator E = signature_infos.end();
+    signature_info_iterator I = signature_infos.find(sign);
+    if (I == E) {
+      LLVMSignatureInfo* signInfo =
+        new(allocator, "LLVMSignatureInfo") LLVMSignatureInfo(sign, this);
+      signature_infos.insert(std::make_pair(sign, signInfo));
+      return signInfo;
+    } else {
+      return I->second;
+    }
+  }
+  
+  LLVMFieldInfo* getFieldInfo(JavaField* field) {
+    field_info_iterator E = field_infos.end();
+    field_info_iterator I = field_infos.find(field);
+    if (I == E) {
+      LLVMFieldInfo* fieldInfo =
+        new(allocator, "LLVMFieldInfo") LLVMFieldInfo(field, this);
+      field_infos.insert(std::make_pair(field, fieldInfo));
+      return fieldInfo;
+    } else {
+      return I->second;
+    }
+  }
+  
+  LLVMClassInfo* getClassInfo(Class* klass) {
+    class_info_iterator E = class_infos.end();
+    class_info_iterator I = class_infos.find(klass);
+    if (I == E) {
+      LLVMClassInfo* classInfo =
+        new(allocator, "LLVMClassInfo") LLVMClassInfo(klass, this);
+      class_infos.insert(std::make_pair(klass, classInfo));
+      return classInfo;
+    } else {
+      return I->second;
+    }
+  }
+  
+  LLVMMethodInfo* getMethodInfo(JavaMethod* method) {
+    method_info_iterator E = method_infos.end();
+    method_info_iterator I = method_infos.find(method);
+    if (I == E) {
+      LLVMMethodInfo* methodInfo =
+        new(allocator, "LLVMMethodInfo") LLVMMethodInfo(method, this);
+      method_infos.insert(std::make_pair(method, methodInfo));
+      return methodInfo;
+    } else {
+      return I->second;
+    }
+  }
   
   virtual llvm::Constant* getFinalObject(JavaObject* obj, CommonClass* cl) = 0;
   virtual JavaObject* getFinalObject(llvm::Value* C) = 0;

Modified: vmkit/trunk/include/j3/LLVMInfo.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/j3/LLVMInfo.h?rev=97325&r1=97324&r2=97325&view=diff
==============================================================================
--- vmkit/trunk/include/j3/LLVMInfo.h (original)
+++ vmkit/trunk/include/j3/LLVMInfo.h Sat Feb 27 08:22:35 2010
@@ -25,6 +25,7 @@
 
 class Class;
 class JavaField;
+class JavaLLVMCompiler;
 class JavaMethod;
 class Signdef;
 
@@ -40,24 +41,28 @@
   friend class JavaJITCompiler;
   friend class JavaLLVMCompiler;
 private:
+  /// Compiler - The compiler for this class info.
+  JavaLLVMCompiler* Compiler;
+  
   Class* classDef;
+  
   /// virtualSizeLLVM - The LLVM constant size of instances of this class.
-  ///
   llvm::Constant* virtualSizeConstant;
+
   /// virtualType - The LLVM type of instance of this class.
-  ///
   const llvm::Type * virtualType;
 
   /// staticType - The LLVM type of the static instance of this class.
-  ///
   const llvm::Type * staticType;
+
 public:
   
   llvm::Value* getVirtualSize();
   const llvm::Type* getVirtualType();
   const llvm::Type* getStaticType();
   
-  LLVMClassInfo(Class* cl) :
+  LLVMClassInfo(Class* cl, JavaLLVMCompiler* comp) :
+    Compiler(comp),
     classDef(cl),
     virtualSizeConstant(0),
     virtualType(0),
@@ -72,6 +77,9 @@
 
 class LLVMMethodInfo : public mvm::JITInfo {
 private:
+  /// Compiler - The compiler for this method info.
+  JavaLLVMCompiler* Compiler;
+
   JavaMethod* methodDef;
 
   llvm::Function* methodFunction;
@@ -79,14 +87,14 @@
   const llvm::FunctionType* functionType;
   llvm::MDNode* DbgSubprogram;
   
-  
 public:
   llvm::Function* getMethod();
   llvm::Constant* getOffset();
   const llvm::FunctionType* getFunctionType();
     
-  LLVMMethodInfo(JavaMethod* M) :  methodDef(M), methodFunction(0),
-    offsetConstant(0), functionType(0), DbgSubprogram(0) {}
+  LLVMMethodInfo(JavaMethod* M, JavaLLVMCompiler* comp) :  Compiler(comp),
+    methodDef(M), methodFunction(0), offsetConstant(0), functionType(0),
+    DbgSubprogram(0) {}
  
   void setDbgSubprogram(llvm::MDNode* node) { DbgSubprogram = node; }
   llvm::MDNode* getDbgSubprogram() { return DbgSubprogram; }
@@ -102,6 +110,9 @@
 
 class LLVMFieldInfo : public mvm::JITInfo {
 private:
+  /// Compiler - The compiler for this field info.
+  JavaLLVMCompiler* Compiler;
+  
   JavaField* fieldDef;
   
   llvm::Constant* offsetConstant;
@@ -109,7 +120,8 @@
 public:
   llvm::Constant* getOffset();
 
-  LLVMFieldInfo(JavaField* F) : 
+  LLVMFieldInfo(JavaField* F, JavaLLVMCompiler* comp) :
+    Compiler(comp),
     fieldDef(F), 
     offsetConstant(0) {}
 
@@ -120,6 +132,9 @@
 
 class LLVMSignatureInfo : public mvm::JITInfo {
 private:
+  /// Compiler - The compiler for this signature info.
+  JavaLLVMCompiler* Compiler;
+  
   const llvm::FunctionType* staticType;
   const llvm::FunctionType* virtualType;
   const llvm::FunctionType* nativeType;
@@ -168,7 +183,8 @@
   llvm::Function* getSpecialStub();
   llvm::Function* getVirtualStub();
   
-  LLVMSignatureInfo(Signdef* sign) : 
+  LLVMSignatureInfo(Signdef* sign, JavaLLVMCompiler* comp) :
+    Compiler(comp),
     staticType(0),
     virtualType(0),
     nativeType(0),

Modified: vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp?rev=97325&r1=97324&r2=97325&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaJITCompiler.cpp Sat Feb 27 08:22:35 2010
@@ -72,12 +72,12 @@
 
 class JavaJITListener : public llvm::JITEventListener {
   JavaMethod* currentCompiledMethod;
+  llvm::Function* currentCompiledFunction;
 public:
   virtual void NotifyFunctionEmitted(const Function &F,
                                      void *Code, size_t Size,
                                      const EmittedFunctionDetails &Details) {
-    if (currentCompiledMethod &&
-        JavaLLVMCompiler::getMethod(currentCompiledMethod) == &F) {
+    if (currentCompiledMethod && currentCompiledFunction == &F) {
       Jnjvm* vm = JavaThread::get()->getJVM();
       mvm::BumpPtrAllocator& Alloc = 
         currentCompiledMethod->classDef->classLoader->allocator;
@@ -115,12 +115,19 @@
     }
   }
 
-  void setCurrentCompiledMethod(JavaMethod* meth) {
+  void setCurrentCompiledMethod(JavaMethod* meth, llvm::Function* func) {
     currentCompiledMethod = meth;
+    currentCompiledFunction = func;
+  }
+  
+  void clearCurrentCompiledMethod() {
+    currentCompiledMethod = NULL;
+    currentCompiledFunction = NULL;
   }
 
   JavaJITListener() {
-    currentCompiledMethod = 0;
+    currentCompiledMethod = NULL;
+    currentCompiledFunction = NULL;
   }
 };
 
@@ -395,9 +402,9 @@
 void* JavaJITCompiler::materializeFunction(JavaMethod* meth) {
   mvm::MvmModule::protectIR();
   Function* func = parseFunction(meth);
-  JITListener->setCurrentCompiledMethod(meth);
+  JITListener->setCurrentCompiledMethod(meth, func);
   void* res = mvm::MvmModule::executionEngine->getPointerToGlobal(func);
-  JITListener->setCurrentCompiledMethod(0);
+  JITListener->clearCurrentCompiledMethod();
   func->deleteBody();
   mvm::MvmModule::unprotectIR();
 

Modified: vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp?rev=97325&r1=97324&r2=97325&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp Sat Feb 27 08:22:35 2010
@@ -47,7 +47,7 @@
     LLVMContext& context = Mod->getLLVMModule()->getContext();
 
     if (classDef->super) {
-      LLVMClassInfo* CLI = JavaLLVMCompiler::getClassInfo(classDef->super);
+      LLVMClassInfo* CLI = Compiler->getClassInfo(classDef->super);
       const llvm::Type* Ty = CLI->getVirtualType()->getContainedType(0);
       fields.push_back(Ty);
     
@@ -136,9 +136,7 @@
 Function* LLVMMethodInfo::getMethod() {
   if (!methodFunction) {
     JnjvmClassLoader* JCL = methodDef->classDef->classLoader;
-    JavaLLVMCompiler* Mod = (JavaLLVMCompiler*)JCL->getCompiler();
-    if (Mod->emitFunctionName()) {
-
+    if (Compiler->emitFunctionName()) {
       const UTF8* jniConsClName = methodDef->classDef->name;
       const UTF8* jniConsName = methodDef->name;
       const UTF8* jniConsType = methodDef->type;
@@ -160,11 +158,11 @@
         memcpy(buf, "JnJVM", 5);
       }
 
-      methodFunction = Mod->getLLVMModule()->getFunction(buf);
+      methodFunction = Compiler->getLLVMModule()->getFunction(buf);
       if (!methodFunction) {
         methodFunction = Function::Create(getFunctionType(), 
                                           GlobalValue::ExternalWeakLinkage, buf,
-                                          Mod->getLLVMModule());
+                                          Compiler->getLLVMModule());
       } else {
         assert(methodFunction->getFunctionType() == getFunctionType() &&
                "Type mismatch");
@@ -177,15 +175,24 @@
 
       methodFunction = Function::Create(getFunctionType(), 
                                         GlobalValue::ExternalWeakLinkage,
-                                        "", Mod->getLLVMModule());
+                                        "", Compiler->getLLVMModule());
 
     }
     
-    if (Mod->useCooperativeGC()) {
+    if (Compiler->useCooperativeGC()) {
       methodFunction->setGC("vmkit");
     }
     
-    Mod->functions.insert(std::make_pair(methodFunction, methodDef));
+    Compiler->functions.insert(std::make_pair(methodFunction, methodDef));
+    if (Compiler != JCL->getCompiler()) {
+      if (mvm::MvmModule::executionEngine &&
+          !mvm::MvmModule::executionEngine->isCompilingLazily()) {
+        assert(methodDef->code && "getting a not compiled method from another "
+                                 "module");
+        mvm::MvmModule::executionEngine->updateGlobalMapping(methodFunction,
+                                                             methodDef->code);
+      }
+    }
   }
   return methodFunction;
 }
@@ -193,7 +200,7 @@
 const FunctionType* LLVMMethodInfo::getFunctionType() {
   if (!functionType) {
     Signdef* sign = methodDef->getSignature();
-    LLVMSignatureInfo* LSI = JavaLLVMCompiler::getSignatureInfo(sign);
+    LLVMSignatureInfo* LSI = Compiler->getSignatureInfo(sign);
     assert(LSI);
     if (isStatic(methodDef->access)) {
       functionType = LSI->getStaticType();
@@ -823,19 +830,3 @@
 LLVMAssessorInfo& JavaLLVMCompiler::getTypedefInfo(const Typedef* type) {
   return AssessorInfo[type->getKey()->elements[0]];
 }
-
-LLVMSignatureInfo* JavaLLVMCompiler::getSignatureInfo(Signdef* sign) {
-  return sign->getInfo<LLVMSignatureInfo>();
-}
-  
-LLVMClassInfo* JavaLLVMCompiler::getClassInfo(Class* cl) {
-  return cl->getInfo<LLVMClassInfo>();
-}
-
-LLVMFieldInfo* JavaLLVMCompiler::getFieldInfo(JavaField* field) {
-  return field->getInfo<LLVMFieldInfo>();
-}
-  
-LLVMMethodInfo* JavaLLVMCompiler::getMethodInfo(JavaMethod* method) {
-  return method->getInfo<LLVMMethodInfo>();
-}

Modified: vmkit/trunk/lib/J3/Compiler/LLVMMaterializer.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/LLVMMaterializer.cpp?rev=97325&r1=97324&r2=97325&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/LLVMMaterializer.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/LLVMMaterializer.cpp Sat Feb 27 08:22:35 2010
@@ -144,7 +144,7 @@
   void* val = meth->compiledPtr();
 
   if (isVirtual(meth->access)) {
-    LLVMMethodInfo* LMI = JavaLLVMCompiler::getMethodInfo(meth);
+    LLVMMethodInfo* LMI = Comp->getMethodInfo(meth);
     uint64_t offset = dyn_cast<ConstantInt>(LMI->getOffset())->getZExtValue();
     assert(meth->classDef->isResolved() && "Class not resolved");
 #if !defined(ISOLATE_SHARING) && !defined(SERVICE)

Modified: vmkit/trunk/lib/Mvm/Compiler/JIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Compiler/JIT.cpp?rev=97325&r1=97324&r2=97325&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/Compiler/JIT.cpp (original)
+++ vmkit/trunk/lib/Mvm/Compiler/JIT.cpp Sat Feb 27 08:22:35 2010
@@ -496,14 +496,11 @@
 //     -instcombine -gvn -sccp -simplifycfg -instcombine -condprop -dse -adce 
 //     -simplifycfg
 //
-void MvmModule::AddStandardCompilePasses() {
-  // TODO: enable this when
-  // - each module will have its declaration of external functions
-  // 
-  //PM->add(llvm::createVerifierPass());        // Verify that input is correct
- 
+void MvmModule::AddStandardCompilePasses() { 
   FunctionPassManager* PM = globalFunctionPasses;
   PM->add(new TargetData(*MvmModule::TheTargetData));
+  
+  addPass(PM, createVerifierPass());        // Verify that input is correct
 
 #ifdef WITH_MMTK
   addPass(PM, createCFGSimplificationPass()); // Clean up disgusting code





More information about the vmkit-commits mailing list