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

Nicolas Geoffray nicolas.geoffray at lip6.fr
Thu Nov 13 14:53:02 PST 2008


Author: geoffray
Date: Thu Nov 13 16:53:02 2008
New Revision: 59271

URL: http://llvm.org/viewvc/llvm-project?rev=59271&view=rev
Log:
Get rid of maps and use LLVM to lookup callback functions.


Modified:
    vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.cpp
    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=59271&r1=59270&r2=59271&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaConstantPool.cpp Thu Nov 13 16:53:02 2008
@@ -369,7 +369,7 @@
     // lookup the method
     meth = cl->lookupMethodDontThrow(utf8, sign->keyName, isStatic(access),
                                      false, 0);
-  } 
+  }
 }
 
 uint32 JavaConstantPool::getClassIndexFromMethod(uint32 index) {
@@ -419,12 +419,19 @@
       return F;
     }
   }
-  
-  // Return the callback.
+ 
+  // If it's static we're not using ctpRes for anything. We can store
+  // the callback. If it's special, the ctpRes contains the offset in
+  // the virtual table, so we can't put the callback and must rely on
+  // the module provider to hash callbacks.
+  if (isStatic(access) && ctpRes[index]) return ctpRes[index];
+
   void* val =
     classDef->classLoader->TheModuleProvider->addCallback(classDef, index, sign,
                                                           isStatic(access));
         
+  if (isStatic(access)) ctpRes[index] = val;
+  
   return val;
 }
 

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmModuleProvider.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmModuleProvider.cpp Thu Nov 13 16:53:02 2008
@@ -40,7 +40,7 @@
     cl(c), index(i) {}
 };
 
-JavaMethod* JnjvmModuleProvider::staticLookup(Class* caller, uint32 index) { 
+JavaMethod* JnjvmModuleProvider::staticLookup(Class* caller, uint32 index) {
   JavaConstantPool* ctpInfo = caller->getConstantPool();
   
 
@@ -108,6 +108,7 @@
 
   return false;
 }
+
 void* JnjvmModuleProvider::materializeFunction(JavaMethod* meth) {
   Function* func = parseFunction(meth);
   
@@ -140,31 +141,28 @@
 llvm::Function* JnjvmModuleProvider::addCallback(Class* cl, uint32 index,
                                                  Signdef* sign, bool stat) {
   
-  void* key = &(cl->getConstantPool()->ctpRes[index]);
-   
-  reverse_callback_iterator CI = reverseCallbacks.find(key);
-  if (CI != reverseCallbacks.end()) {
-    return CI->second;
-  }
-  
-  const llvm::FunctionType* type = 0;
   JnjvmModule* M = cl->classLoader->getModule();
+  Function* func = 0;
   LLVMSignatureInfo* LSI = M->getSignatureInfo(sign);
+  if (!stat) {
+    char* name = cl->printString();
+    char* key = (char*)alloca(strlen(name) + 2);
+    sprintf(key, "%s%d", name, index);
+    Function* F = TheModule->getFunction(key);
+    if (F) return F;
   
-  if (stat) {
-    type = LSI->getStaticType();
+    const FunctionType* type = LSI->getVirtualType();
+  
+    func = Function::Create(type, GlobalValue::GhostLinkage, key, TheModule);
   } else {
-    type = LSI->getVirtualType();
+    const llvm::FunctionType* type = LSI->getStaticType();
+    func = Function::Create(type, GlobalValue::GhostLinkage, "staticCallback",
+                            TheModule);
   }
   
-  Function* func = llvm::Function::Create(type, 
-                                          llvm::GlobalValue::GhostLinkage,
-                                          "callback",
-                                          TheModule);
   CallbackInfo* A = new CallbackInfo(cl, index);
   func->addAnnotation(A);
-  reverseCallbacks.insert(std::make_pair(key, func));
-
+  
   return func;
 }
 

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmModuleProvider.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmModuleProvider.h Thu Nov 13 16:53:02 2008
@@ -26,11 +26,6 @@
 private:
   JavaMethod* staticLookup(Class* caller, uint32 index);
   
-  std::map<void*, llvm::Function* > reverseCallbacks;
-  
-  typedef std::map<void*, llvm::Function* >::iterator
-    reverse_callback_iterator;  
-
   llvm::FunctionPassManager* perFunctionPasses;
   llvm::FunctionPassManager* perNativeFunctionPasses;
 





More information about the vmkit-commits mailing list