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

Nicolas Geoffray nicolas.geoffray at lip6.fr
Wed Dec 31 02:45:03 PST 2008


Author: geoffray
Date: Wed Dec 31 04:45:01 2008
New Revision: 61520

URL: http://llvm.org/viewvc/llvm-project?rev=61520&view=rev
Log:
Fix names of Java and JNI functions when static compiling.


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

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Wed Dec 31 04:45:01 2008
@@ -1210,3 +1210,20 @@
   ptr[0] = 0;
 
 }
+
+bool UserClass::isNativeOverloaded(JavaMethod* meth) {
+  
+  for (uint32 i = 0; i < nbVirtualMethods; ++i) {
+    JavaMethod& cur = virtualMethods[i];
+    if (&cur != meth && cur.name->equals(meth->name))
+      return true;
+  }
+  
+  for (uint32 i = 0; i < nbStaticMethods; ++i) {
+    JavaMethod& cur = staticMethods[i];
+    if (&cur != meth && cur.name->equals(meth->name))
+      return true;
+  }
+
+  return false;
+}

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Wed Dec 31 04:45:01 2008
@@ -874,6 +874,7 @@
   }
 #endif
 
+  bool isNativeOverloaded(JavaMethod* meth);
    
 };
 

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaJIT.cpp Wed Dec 31 04:45:01 2008
@@ -185,8 +185,19 @@
   const FunctionType *funcType = llvmFunction->getFunctionType();
   
   bool jnjvm = false;
-  natPtr = natPtr ? natPtr :
-    compilingClass->classLoader->nativeLookup(compilingMethod, jnjvm);
+  
+  const UTF8* jniConsClName = compilingClass->name;
+  const UTF8* jniConsName = compilingMethod->name;
+  const UTF8* jniConsType = compilingMethod->type;
+  sint32 clen = jniConsClName->size;
+  sint32 mnlen = jniConsName->size;
+  sint32 mtlen = jniConsType->size;
+
+  char* functionName = (char*)alloca(3 + JNI_NAME_PRE_LEN + 
+                            ((mnlen + clen + mtlen) << 1));
+  if (!natPtr)
+    natPtr = compilingClass->classLoader->nativeLookup(compilingMethod, jnjvm,
+                                                       functionName);
   
   if (!natPtr && !module->isStaticCompiling()) {
     fprintf(stderr, "Native function %s not found. Probably "

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Wed Dec 31 04:45:01 2008
@@ -883,17 +883,9 @@
   return (intptr_t)dlsym(handle, name);
 }
 
-intptr_t JnjvmClassLoader::nativeLookup(JavaMethod* meth, bool& jnjvm) {
+intptr_t JnjvmClassLoader::nativeLookup(JavaMethod* meth, bool& jnjvm,
+                                        char* buf) {
 
-  const UTF8* jniConsClName = meth->classDef->name;
-  const UTF8* jniConsName = meth->name;
-  const UTF8* jniConsType = meth->type;
-  sint32 clen = jniConsClName->size;
-  sint32 mnlen = jniConsName->size;
-  sint32 mtlen = jniConsType->size;
-
-  char* buf = (char*)alloca(3 + JNI_NAME_PRE_LEN + 
-                            ((mnlen + clen + mtlen) << 1));
   meth->jniConsFromMeth(buf);
   intptr_t res = loadInLib(buf, jnjvm);
   if (!res) {

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h Wed Dec 31 04:45:01 2008
@@ -265,7 +265,7 @@
   /// method. Also set in the jnjvm parameter is the function is defined in
   /// JnJVM.
   ///
-  intptr_t nativeLookup(JavaMethod* meth, bool& jnjvm);
+  intptr_t nativeLookup(JavaMethod* meth, bool& jnjvm, char* buf);
 };
 
 /// JnjvmBootstrapLoader - This class is for the bootstrap class loader, which

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp Wed Dec 31 04:45:01 2008
@@ -327,12 +327,25 @@
       
       LLVMSignatureInfo* LSI = getSignatureInfo(meth->getSignature());
       const llvm::Type* valPtrType = LSI->getNativeType();
+      
+      const UTF8* jniConsClName = meth->classDef->name;
+      const UTF8* jniConsName = meth->name;
+      const UTF8* jniConsType = meth->type;
+      sint32 clen = jniConsClName->size;
+      sint32 mnlen = jniConsName->size;
+      sint32 mtlen = jniConsType->size;
+
+      char* buf = (char*)alloca(3 + JNI_NAME_PRE_LEN + 1 +
+                                ((mnlen + clen + mtlen) << 1));
     
-      assert((ptr || isStaticCompiling()) && "No native function given");
+      if (meth->classDef->isNativeOverloaded(meth))
+        meth->jniConsFromMethOverloaded(buf);
+      else
+        meth->jniConsFromMeth(buf);
 
-      varGV = new GlobalVariable(valPtrType, false,
+      varGV = new GlobalVariable(valPtrType, true,
                                  GlobalValue::ExternalLinkage,
-                                 0, "", this);
+                                 0, buf, this);
     
       nativeFunctions.insert(std::make_pair(meth, varGV));
       return varGV;
@@ -1329,6 +1342,7 @@
     JnjvmClassLoader* JCL = methodDef->classDef->classLoader;
     JnjvmModule* Mod = JCL->getModule();
     if (Mod->isStaticCompiling()) {
+
       const UTF8* jniConsClName = methodDef->classDef->name;
       const UTF8* jniConsName = methodDef->name;
       const UTF8* jniConsType = methodDef->type;
@@ -1336,9 +1350,21 @@
       sint32 mnlen = jniConsName->size;
       sint32 mtlen = jniConsType->size;
 
-      char* buf = (char*)alloca(3 + JNI_NAME_PRE_LEN +
+      char* buf = (char*)alloca(3 + JNI_NAME_PRE_LEN + 1 +
                                 ((mnlen + clen + mtlen) << 1));
-      methodDef->jniConsFromMethOverloaded(buf);
+      
+      if (isNative(methodDef->access)) {
+        bool jnjvm = false;
+        JCL->nativeLookup(methodDef, jnjvm, buf);
+        if (!jnjvm) {
+          methodDef->jniConsFromMethOverloaded(buf + 1);
+          memcpy(buf, "JnJVM", 5);
+        }
+      } else {
+        methodDef->jniConsFromMethOverloaded(buf + 1);
+        memcpy(buf, "JnJVM", 5);
+      }
+
       methodFunction = Function::Create(getFunctionType(), 
                                         GlobalValue::GhostLinkage, buf, Mod);
 





More information about the vmkit-commits mailing list