[vmkit-commits] [vmkit] r58327 - in /vmkit/trunk/lib/JnJVM/VMCore: JavaJIT.cpp JnjvmModule.cpp JnjvmModule.h

Nicolas Geoffray nicolas.geoffray at lip6.fr
Tue Oct 28 05:07:40 PDT 2008


Author: geoffray
Date: Tue Oct 28 07:07:40 2008
New Revision: 58327

URL: http://llvm.org/viewvc/llvm-project?rev=58327&view=rev
Log:
Provide a global variable wrapper for native functions, so that we do
not use IntToPtr instructions.



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

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp Tue Oct 28 07:07:40 2008
@@ -181,11 +181,19 @@
   natPtr = natPtr ? natPtr :
               NativeUtil::nativeLookup(compilingClass, compilingMethod, jnjvm);
   
+  if (!natPtr && !module->isStaticCompiling()) {
+    fprintf(stderr, "Native function %s not found. Probably "
+               "not implemented by JnJVM?\n", compilingMethod->printString());
+    JavaJIT::printBacktrace();
+    JavaThread::get()->isolate->unknownError("can not find native method %s",
+                                             compilingMethod->printString());
+  }
   
   
   Function* func = llvmFunction;
   if (jnjvm) {
-    module->executionEngine->addGlobalMapping(func, natPtr);
+    if (!module->isStaticCompiling())
+      module->executionEngine->addGlobalMapping(func, natPtr);
     return llvmFunction;
   }
   
@@ -282,15 +290,10 @@
     nativeArgs.push_back(i);
   }
   
-  
-  LLVMSignatureInfo* LSI = 
-    module->getSignatureInfo(compilingMethod->getSignature());
-  const llvm::Type* valPtrType = LSI->getNativePtrType();
-  Value* valPtr = 
-    ConstantExpr::getIntToPtr(ConstantInt::get(Type::Int64Ty, (uint64)natPtr),
-                              valPtrType);
+  Value* nativeFunc = module->getNativeFunction(compilingMethod, natPtr);
+  nativeFunc = new LoadInst(nativeFunc, "", currentBlock);
 
-  Value* result = llvm::CallInst::Create(valPtr, nativeArgs.begin(),
+  Value* result = llvm::CallInst::Create(nativeFunc, nativeArgs.begin(),
                                          nativeArgs.end(), "", currentBlock);
 
   if (returnType != Type::VoidTy)

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp Tue Oct 28 07:07:40 2008
@@ -147,7 +147,8 @@
   java_class_iterator I = javaClasses.find(cl);
   if (I == End) {
     
-    JavaObject* obj = cl->getClassDelegatee(JavaThread::get()->isolate);
+    JavaObject* obj = isStaticCompiling() ? 0 : 
+      cl->getClassDelegatee(JavaThread::get()->isolate);
     Constant* cons = 
       ConstantExpr::getIntToPtr(ConstantInt::get(Type::Int64Ty, uint64(obj)),
                                 JnjvmModule::JavaObjectType);
@@ -210,6 +211,31 @@
   return varGV;
 }
 
+Value* JnjvmModule::getNativeFunction(JavaMethod* meth, void* ptr) {
+  llvm::GlobalVariable* varGV = 0;
+  native_function_iterator End = nativeFunctions.end();
+  native_function_iterator I = nativeFunctions.find(meth);
+  if (I == End) {
+    
+      
+    LLVMSignatureInfo* LSI = getSignatureInfo(meth->getSignature());
+    const llvm::Type* valPtrType = LSI->getNativePtrType();
+
+    Constant* cons = 
+      ConstantExpr::getIntToPtr(ConstantInt::get(Type::Int64Ty, uint64_t(ptr)),
+                                valPtrType);
+
+    varGV = new GlobalVariable(valPtrType, !staticCompilation,
+                               GlobalValue::ExternalLinkage,
+                               cons, "", this);
+    
+    nativeFunctions.insert(std::make_pair(meth, varGV));
+  } else {
+    varGV = I->second;
+  }
+  return varGV;
+}
+
 #ifndef WITHOUT_VTABLE
 VirtualTable* JnjvmModule::allocateVT(Class* cl,
                                       uint32 index) {

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.h Tue Oct 28 07:07:40 2008
@@ -185,6 +185,7 @@
   std::map<const JavaConstantPool*, llvm::GlobalVariable*> constantPools;
   std::map<const JavaString*, llvm::GlobalVariable*> strings;
   std::map<const Enveloppe*, llvm::GlobalVariable*> enveloppes;
+  std::map<const JavaMethod*, llvm::GlobalVariable*> nativeFunctions;
 
   typedef std::map<const CommonClass*, llvm::GlobalVariable*>::iterator
     native_class_iterator;  
@@ -207,6 +208,9 @@
   typedef std::map<const Enveloppe*, llvm::GlobalVariable*>::iterator
     enveloppe_iterator;
   
+  typedef std::map<const JavaMethod*, llvm::GlobalVariable*>::iterator
+    native_function_iterator;
+  
   
   bool staticCompilation;
 
@@ -381,6 +385,7 @@
   llvm::Value* getEnveloppe(Enveloppe* enveloppe);
   llvm::Value* getString(JavaString* str);
   llvm::Value* getConstantPool(JavaConstantPool* ctp);
+  llvm::Value* getNativeFunction(JavaMethod* meth, void* natPtr);
 
 private:
   static llvm::Module* initialModule;





More information about the vmkit-commits mailing list