[vmkit-commits] [vmkit] r59269 - in /vmkit/trunk/lib/JnJVM/VMCore: JavaConstantPool.cpp JnjvmModule.cpp JnjvmModule.h JnjvmModuleProvider.cpp JnjvmModuleProvider.h

Nicolas Geoffray nicolas.geoffray at lip6.fr
Thu Nov 13 14:19:09 PST 2008


Author: geoffray
Date: Thu Nov 13 16:19:08 2008
New Revision: 59269

URL: http://llvm.org/viewvc/llvm-project?rev=59269&view=rev
Log:
Use llvm::annotations instead of maps to get the JavaMethod and the callback
info of llvm::Functions.


Modified:
    vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.h
    vmkit/trunk/lib/JnJVM/VMCore/JnjvmModuleProvider.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JnjvmModuleProvider.h

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.cpp Thu Nov 13 16:19:08 2008
@@ -43,7 +43,8 @@
 const uint32 JavaConstantPool::ConstantNameAndType = 12;
 
 
-static uint32 unimplemented(JavaConstantPool* ctp, Reader& reader, uint32 index) {
+static uint32 unimplemented(JavaConstantPool* ctp, Reader& reader,
+                            uint32 index) {
   JavaThread::get()->getJVM()->classFormatError(
                                     "unknown constant pool at index %d", 
                                     index);

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp Thu Nov 13 16:19:08 2008
@@ -575,7 +575,7 @@
                                         "", Mod);
 
     }
-    JCL->TheModuleProvider->addFunction(methodFunction, methodDef);
+    methodFunction->addAnnotation(this);
   }
   return methodFunction;
 }
@@ -1176,3 +1176,16 @@
   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;
+}

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.h Thu Nov 13 16:19:08 2008
@@ -82,7 +82,7 @@
     staticType(0) {}
 };
 
-class LLVMMethodInfo : public mvm::JITInfo {
+class LLVMMethodInfo : public mvm::JITInfo, private llvm::Annotation {
 private:
   JavaMethod* methodDef;
 
@@ -94,12 +94,10 @@
   llvm::Function* getMethod();
   llvm::ConstantInt* getOffset();
   const llvm::FunctionType* getFunctionType();
-  
-  LLVMMethodInfo(JavaMethod* M) : 
-    methodDef(M), 
-    methodFunction(0),
-    offsetConstant(0),
-    functionType(0) {}
+    
+  LLVMMethodInfo(JavaMethod* M); 
+
+  static JavaMethod* get(const Function* F);
 };
 
 class LLVMFieldInfo : public mvm::JITInfo {

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmModuleProvider.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmModuleProvider.cpp Thu Nov 13 16:19:08 2008
@@ -26,6 +26,20 @@
 using namespace llvm;
 using namespace jnjvm;
 
+
+static AnnotationID JavaCallback_ID(
+  AnnotationManager::getID("Java::Callback"));
+
+
+class CallbackInfo: public Annotation {
+public:
+  Class* cl;
+  uint32 index;
+
+  CallbackInfo(Class* c, uint32 i) : Annotation(JavaCallback_ID), 
+    cl(c), index(i) {}
+};
+
 JavaMethod* JnjvmModuleProvider::staticLookup(Class* caller, uint32 index) { 
   JavaConstantPool* ctpInfo = caller->getConstantPool();
   
@@ -53,24 +67,6 @@
   return meth;
 }
 
-std::pair<Class*, uint32>* JnjvmModuleProvider::lookupCallback(Function* F) {
-  callback_iterator CI = callbacks.find(F);
-  if (CI != callbacks.end()) {
-    return &(CI->second);
-  } else {
-    return 0;
-  }
-}
-
-JavaMethod* JnjvmModuleProvider::lookupFunction(Function* F) {
-  function_iterator CI = functions.find(F);
-  if (CI != functions.end()) {
-    return CI->second;
-  } else {
-    return 0;
-  }
-}
-
 bool JnjvmModuleProvider::materializeFunction(Function *F, 
                                               std::string *ErrInfo) {
   
@@ -80,13 +76,13 @@
   if (!(F->hasNotBeenReadFromBitcode())) 
     return false;
   
-  JavaMethod* meth = lookupFunction(F);
+  JavaMethod* meth = LLVMMethodInfo::get(F);
   
   if (!meth) {
     // It's a callback
-    std::pair<Class*, uint32> * p = lookupCallback(F);
-    assert(p && "No callback where there should be one");
-    meth = staticLookup(p->first, p->second); 
+    CallbackInfo* CI = (CallbackInfo*)F->getAnnotation(JavaCallback_ID);
+    assert(CI && "No callback where there should be one");
+    meth = staticLookup(CI->cl, CI->index); 
   }
   
   void* val = meth->compiledPtr();
@@ -165,18 +161,13 @@
                                           llvm::GlobalValue::GhostLinkage,
                                           "callback",
                                           TheModule);
-
-  callbacks.insert(std::make_pair(func, std::make_pair(cl, index)));
+  CallbackInfo* A = new CallbackInfo(cl, index);
+  func->addAnnotation(A);
   reverseCallbacks.insert(std::make_pair(key, func));
 
   return func;
 }
 
-void JnjvmModuleProvider::addFunction(Function* F, JavaMethod* meth) {
-  functions.insert(std::make_pair(F, meth));
-}
-
-
 namespace mvm {
   llvm::FunctionPass* createEscapeAnalysisPass(llvm::Function*);
   llvm::FunctionPass* createLowerConstantCallsPass();

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmModuleProvider.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmModuleProvider.h Thu Nov 13 16:19:08 2008
@@ -26,19 +26,8 @@
 private:
   JavaMethod* staticLookup(Class* caller, uint32 index);
   
-  std::map<llvm::Function*, JavaMethod*> functions;
-  std::map<llvm::Function*, std::pair<Class*, uint32> > callbacks;
   std::map<void*, llvm::Function* > reverseCallbacks;
   
-  std::pair<Class*, uint32>* lookupCallback(llvm::Function*);
-  JavaMethod* lookupFunction(llvm::Function*);
-
-  typedef std::map<llvm::Function*, JavaMethod*>::iterator
-    function_iterator;  
-  
-  typedef std::map<llvm::Function*, std::pair<Class*, uint32> >::iterator
-    callback_iterator;  
-  
   typedef std::map<void*, llvm::Function* >::iterator
     reverse_callback_iterator;  
 
@@ -52,7 +41,6 @@
   
   llvm::Function* addCallback(Class* cl, uint32 index, Signdef* sign,
                               bool stat);
-  void addFunction(llvm::Function* F, JavaMethod* meth);
 
   bool materializeFunction(Function *F, std::string *ErrInfo = 0);
   void* materializeFunction(JavaMethod* meth);





More information about the vmkit-commits mailing list