[vmkit-commits] [vmkit] r78063 - in /vmkit/trunk: include/jnjvm/JnjvmModule.h include/jnjvm/JnjvmModuleProvider.h lib/JnJVM/Compiler/JITInfo.cpp lib/JnJVM/Compiler/JavaJITCompiler.cpp lib/JnJVM/Compiler/JnjvmModule.cpp lib/JnJVM/Compiler/JnjvmModuleProvider.cpp lib/JnJVM/Compiler/LowerConstantCalls.cpp

Nicolas Geoffray nicolas.geoffray at lip6.fr
Tue Aug 4 08:22:28 PDT 2009


Author: geoffray
Date: Tue Aug  4 10:22:20 2009
New Revision: 78063

URL: http://llvm.org/viewvc/llvm-project?rev=78063&view=rev
Log:
Use maps instead of annotations to find JavaMethod out of a
llvm::Function.


Modified:
    vmkit/trunk/include/jnjvm/JnjvmModule.h
    vmkit/trunk/include/jnjvm/JnjvmModuleProvider.h
    vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp
    vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp
    vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp
    vmkit/trunk/lib/JnJVM/Compiler/JnjvmModuleProvider.cpp
    vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp

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

==============================================================================
--- vmkit/trunk/include/jnjvm/JnjvmModule.h (original)
+++ vmkit/trunk/include/jnjvm/JnjvmModule.h Tue Aug  4 10:22:20 2009
@@ -16,8 +16,6 @@
 #include "mvm/Allocator.h"
 #include "mvm/JIT.h"
 
-#include "llvm/Support/Annotation.h"
-
 #include "JavaCompiler.h"
 
 namespace llvm {
@@ -102,7 +100,7 @@
   }
 };
 
-class LLVMMethodInfo : public mvm::JITInfo, private llvm::Annotation {
+class LLVMMethodInfo : public mvm::JITInfo {
 private:
   JavaMethod* methodDef;
 
@@ -110,15 +108,16 @@
   llvm::Constant* offsetConstant;
   const llvm::FunctionType* functionType;
   
+  
 public:
   llvm::Function* getMethod();
   llvm::Constant* getOffset();
   const llvm::FunctionType* getFunctionType();
     
-  LLVMMethodInfo(JavaMethod* M); 
+  LLVMMethodInfo(JavaMethod* M) :  methodDef(M), methodFunction(0),
+    offsetConstant(0), functionType(0) {}
+ 
 
-  static JavaMethod* get(const llvm::Function* F);
-  
   virtual void clear() {
     methodFunction = 0;
     offsetConstant = 0;
@@ -126,6 +125,7 @@
   }
 };
 
+
 class LLVMFieldInfo : public mvm::JITInfo {
 private:
   JavaField* fieldDef;
@@ -361,6 +361,7 @@
 
 class JavaLLVMCompiler : public JavaCompiler {
   friend class LLVMClassInfo;
+  friend class LLVMMethodInfo;
 
 
 protected:
@@ -379,10 +380,11 @@
   
   virtual void makeVT(Class* cl) = 0;
   
-  
+  std::map<llvm::Function*, JavaMethod*> functions;  
+  typedef std::map<llvm::Function*, JavaMethod*>::iterator function_iterator;
   
 public:
-  
+
   JavaLLVMCompiler(const std::string &ModuleID);
   
   virtual bool isStaticCompiling() = 0;
@@ -416,6 +418,9 @@
   
   virtual ~JavaLLVMCompiler();
 
+
+  JavaMethod* getJavaMethod(llvm::Function*);
+
   void resolveVirtualClass(Class* cl);
   void resolveStaticClass(Class* cl);
   static llvm::Function* getMethod(JavaMethod* meth);
@@ -477,9 +482,25 @@
 
 };
 
+struct CallbackInfo {
+  Class* cl;
+  uint16 index;
+  bool stat;
+
+  CallbackInfo(Class* c, uint32 i, bool s) :
+    cl(c), index(i), stat(s) {}
+
+};
+
+
 class JavaJITCompiler : public JavaLLVMCompiler {
 public:
 
+  std::map<llvm::Function*, CallbackInfo> callbacks;
+
+  typedef std::map<llvm::Function*, CallbackInfo>::iterator callback_iterator;
+
+
   bool EmitFunctionName;
 
   JavaJITCompiler(const std::string &ModuleID);

Modified: vmkit/trunk/include/jnjvm/JnjvmModuleProvider.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/jnjvm/JnjvmModuleProvider.h?rev=78063&r1=78062&r2=78063&view=diff

==============================================================================
--- vmkit/trunk/include/jnjvm/JnjvmModuleProvider.h (original)
+++ vmkit/trunk/include/jnjvm/JnjvmModuleProvider.h Tue Aug  4 10:22:20 2009
@@ -14,10 +14,14 @@
 
 namespace jnjvm {
 
+class JavaJITCompiler;
+
 class JnjvmModuleProvider : public llvm::ModuleProvider {
 public:
-   
-  JnjvmModuleProvider(llvm::Module* M);
+ 
+  JavaJITCompiler* Comp;
+
+  JnjvmModuleProvider(llvm::Module* M, JavaJITCompiler* C);
   ~JnjvmModuleProvider();
 
   bool materializeFunction(llvm::Function *F, std::string *ErrInfo = 0);

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp Tue Aug  4 10:22:20 2009
@@ -165,7 +165,7 @@
                                         "", Mod->getLLVMModule());
 
     }
-    methodFunction->addAnnotation(this);
+    Mod->functions.insert(std::make_pair(methodFunction, methodDef));
   }
   return methodFunction;
 }
@@ -599,20 +599,6 @@
   return LLVMAssessorInfo::AssessorInfo[type->getKey()->elements[0]];
 }
 
-static AnnotationID JavaMethod_ID(
-  AnnotationManager::getID("Java::JavaMethod"));
-
-
-LLVMMethodInfo::LLVMMethodInfo(JavaMethod* M) : 
-  llvm::Annotation(JavaMethod_ID), methodDef(M), methodFunction(0),
-  offsetConstant(0), functionType(0) {}
-
-JavaMethod* LLVMMethodInfo::get(const llvm::Function* F) {
-  LLVMMethodInfo *MI = (LLVMMethodInfo*)F->getAnnotation(JavaMethod_ID);
-  if (MI) return MI->methodDef;
-  return 0;
-}
-
 LLVMSignatureInfo* JavaLLVMCompiler::getSignatureInfo(Signdef* sign) {
   return sign->getInfo<LLVMSignatureInfo>();
 }

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp Tue Aug  4 10:22:20 2009
@@ -144,7 +144,7 @@
 #else
   EmitFunctionName = false;
 #endif
-  TheModuleProvider = new JnjvmModuleProvider(TheModule);
+  TheModuleProvider = new JnjvmModuleProvider(TheModule, this);
   addJavaPasses();
 }
 

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp Tue Aug  4 10:22:20 2009
@@ -348,6 +348,13 @@
   return func;
 }
 
+JavaMethod* JavaLLVMCompiler::getJavaMethod(llvm::Function* F) {
+  function_iterator E = functions.end();
+  function_iterator I = functions.find(F);
+  if (I == E) return 0;
+  return I->second;
+}
+
 JavaLLVMCompiler::~JavaLLVMCompiler() {
   delete JavaFunctionPasses;
   delete JavaNativeFunctionPasses;
@@ -360,7 +367,7 @@
 }
 
 namespace jnjvm {
-  llvm::FunctionPass* createLowerConstantCallsPass();
+  llvm::FunctionPass* createLowerConstantCallsPass(JnjvmModule* M);
 }
 
 void JavaLLVMCompiler::addJavaPasses() {
@@ -368,7 +375,7 @@
   JavaNativeFunctionPasses->add(new TargetData(TheModule));
   // Lower constant calls to lower things like getClass used
   // on synchronized methods.
-  JavaNativeFunctionPasses->add(createLowerConstantCallsPass());
+  JavaNativeFunctionPasses->add(createLowerConstantCallsPass(getIntrinsics()));
   
   JavaFunctionPasses = new FunctionPassManager(TheModuleProvider);
   JavaFunctionPasses->add(new TargetData(TheModule));
@@ -376,5 +383,5 @@
     JavaFunctionPasses->add(mvm::createLoopSafePointsPass());
 
   JavaFunctionPasses->add(mvm::createEscapeAnalysisPass());
-  JavaFunctionPasses->add(createLowerConstantCallsPass());
+  JavaFunctionPasses->add(createLowerConstantCallsPass(getIntrinsics()));
 }

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JnjvmModuleProvider.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JnjvmModuleProvider.cpp Tue Aug  4 10:22:20 2009
@@ -27,25 +27,10 @@
 using namespace jnjvm;
 
 
-static AnnotationID JavaCallback_ID(
-  AnnotationManager::getID("Java::Callback"));
-
-class CallbackInfo: public Annotation {
-public:
-  Class* cl;
-  uint16 index;
-  bool stat;
-
-  CallbackInfo(Class* c, uint32 i, bool s) : Annotation(JavaCallback_ID), 
-    cl(c), index(i), stat(s) {}
-};
-
-static JavaMethod* staticLookup(Function* F) {
-  CallbackInfo* CI = (CallbackInfo*)F->getAnnotation(JavaCallback_ID);
-  assert(CI && "No callback where there should be one");
-  Class* caller = CI->cl;
-  uint16 index = CI->index; 
-  bool isStatic = CI->stat;
+static JavaMethod* staticLookup(CallbackInfo& F) {
+  Class* caller = F.cl;
+  uint16 index = F.index; 
+  bool isStatic = F.stat;
   JavaConstantPool* ctpInfo = caller->getConstantPool();
 
   CommonClass* cl = 0;
@@ -67,7 +52,7 @@
 Function* JavaJITCompiler::addCallback(Class* cl, uint16 index,
                                        Signdef* sign, bool stat) {
   
-  Function* func = 0;
+  Function* F = 0;
   LLVMSignatureInfo* LSI = getSignatureInfo(sign);
   
   const UTF8* name = cl->name;
@@ -75,18 +60,18 @@
   for (sint32 i = 0; i < name->size; ++i)
     key[i] = name->elements[i];
   sprintf(key + name->size, "%d", index);
-  Function* F = TheModule->getFunction(key);
+  F = TheModule->getFunction(key);
   if (F) return F;
   
   const FunctionType* type = stat ? LSI->getStaticType() : 
                                     LSI->getVirtualType();
   
-  func = Function::Create(type, GlobalValue::GhostLinkage, key, TheModule);
+  F = Function::Create(type, GlobalValue::GhostLinkage, key, TheModule);
   
-  CallbackInfo* A = new CallbackInfo(cl, index, stat);
-  func->addAnnotation(A);
+  CallbackInfo A(cl, index, stat);
+  callbacks.insert(std::make_pair(F, A));
   
-  return func;
+  return F;
 }
 
 
@@ -99,11 +84,13 @@
   if (mvm::MvmModule::executionEngine->getPointerToGlobalIfAvailable(F))
     return false;
 
-  JavaMethod* meth = LLVMMethodInfo::get(F);
+  JavaMethod* meth = Comp->getJavaMethod(F);
   
   if (!meth) {
     // It's a callback
-    meth = staticLookup(F);
+    JavaJITCompiler::callback_iterator I = Comp->callbacks.find(F);
+    assert(I != Comp->callbacks.end() && "No callbacks found");
+    meth = staticLookup(I->second);
   }
   
   void* val = meth->compiledPtr();
@@ -130,7 +117,9 @@
   return false;
 }
 
-JnjvmModuleProvider::JnjvmModuleProvider(llvm::Module* m) {
+JnjvmModuleProvider::JnjvmModuleProvider(llvm::Module* m,
+                                         JavaJITCompiler* C) {
+  Comp = C;
   TheModule = m;
   JnjvmModule::protectEngine.lock();
   JnjvmModule::executionEngine->addModuleProvider(this);

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp Tue Aug  4 10:22:20 2009
@@ -26,14 +26,19 @@
   class VISIBILITY_HIDDEN LowerConstantCalls : public FunctionPass {
   public:
     static char ID;
-    LowerConstantCalls() : FunctionPass((intptr_t)&ID) { }
+    JnjvmModule* module;
+    LowerConstantCalls(JnjvmModule* M) : FunctionPass((intptr_t)&ID),
+      module(M) { }
 
     virtual bool runOnFunction(Function &F);
   private:
   };
   char LowerConstantCalls::ID = 0;
+
+#if 0
   static RegisterPass<LowerConstantCalls> X("LowerConstantCalls",
                                             "Lower Constant calls");
+#endif
 
 
 #ifdef ISOLATE
@@ -117,10 +122,6 @@
 #endif
 
 bool LowerConstantCalls::runOnFunction(Function& F) {
-  JavaMethod* meth = LLVMMethodInfo::get(&F);
-  JavaLLVMCompiler* TheCompiler = 
-    (JavaLLVMCompiler*)meth->classDef->classLoader->getCompiler();
-  JnjvmModule* module = TheCompiler->getIntrinsics();
   LLVMContext* Context = &F.getContext();
   bool Changed = false;
   for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; BI++) { 
@@ -132,12 +133,16 @@
       if (ICmpInst* Cmp = dyn_cast<ICmpInst>(I)) {
         if (Cmp->getOperand(1) == module->JavaObjectNullConstant) {
           Value* Arg = Cmp->getOperand(0);
+      
+#if 0
+          // Re-enable this once we can get access of the JavaMethod again.
           if (isVirtual(meth->access) && Arg == F.arg_begin()) {
             Changed = true;
             Cmp->replaceAllUsesWith(ConstantInt::getFalse(*Context));
             Cmp->eraseFromParent();
             break;
           }
+#endif
           
           CallSite Ca = CallSite::get(Arg);
           Instruction* CI = Ca.getInstruction();
@@ -735,8 +740,8 @@
 }
 
 
-FunctionPass* createLowerConstantCallsPass() {
-  return new LowerConstantCalls();
+FunctionPass* createLowerConstantCallsPass(JnjvmModule* M) {
+  return new LowerConstantCalls(M);
 }
 
 }





More information about the vmkit-commits mailing list