[vmkit-commits] [vmkit] r60949 - in /vmkit/trunk/lib/JnJVM/VMCore: JavaClass.h JnjvmModule.cpp NativeUtil.cpp

Nicolas Geoffray nicolas.geoffray at lip6.fr
Fri Dec 12 01:13:30 PST 2008


Author: geoffray
Date: Fri Dec 12 03:13:29 2008
New Revision: 60949

URL: http://llvm.org/viewvc/llvm-project?rev=60949&view=rev
Log:
Correct implementation of name mangling in JNI.


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

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Fri Dec 12 03:13:29 2008
@@ -1002,8 +1002,7 @@
   /// jniConsFromMeth - Construct the JNI name of this method.
   ///
   void jniConsFromMeth(char* buf) const;
-  void jniConsFromMeth2(char* buf) const;
-  void jniConsFromMeth3(char* buf) const;
+  void jniConsFromMethOverloaded(char* buf) const;
   
 
 //===----------------------------------------------------------------------===//

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp Fri Dec 12 03:13:29 2008
@@ -681,9 +681,9 @@
       sint32 mnlen = jniConsName->size;
       sint32 mtlen = jniConsType->size;
 
-      char* buf = 
-        (char*)alloca(3 + JNI_NAME_PRE_LEN + mnlen + clen + (mtlen << 1));
-      methodDef->jniConsFromMeth3(buf);
+      char* buf = (char*)alloca(3 + JNI_NAME_PRE_LEN +
+                                ((mnlen + clen + mtlen) << 1));
+      methodDef->jniConsFromMethOverloaded(buf);
       methodFunction = Function::Create(getFunctionType(), 
                                         GlobalValue::GhostLinkage, buf, Mod);
 

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/NativeUtil.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/NativeUtil.cpp Fri Dec 12 03:13:29 2008
@@ -44,39 +44,11 @@
   for (sint32 i =0; i < clen; ++i) {
     cur = jniConsClName->elements[i];
     if (cur == '/') ptr[0] = '_';
-    else ptr[0] = (uint8)cur;
-    ++ptr;
-  }
-  
-  ptr[0] = '_';
-  ++ptr;
-  
-  for (sint32 i =0; i < mnlen; ++i) {
-    cur = jniConsName->elements[i];
-    if (cur == '/') ptr[0] = '_';
-    else ptr[0] = (uint8)cur;
-    ++ptr;
-  }
-  
-  ptr[0] = 0;
-
-
-}
-
-void JavaMethod::jniConsFromMeth2(char* buf) const {
-  const UTF8* jniConsClName = classDef->name;
-  const UTF8* jniConsName = name;
-  sint32 clen = jniConsClName->size;
-  sint32 mnlen = jniConsName->size;
-
-  uint32 cur = 0;
-  char* ptr = &(buf[JNI_NAME_PRE_LEN]);
-  
-  memcpy(buf, JNI_NAME_PRE, JNI_NAME_PRE_LEN);
-  
-  for (sint32 i =0; i < clen; ++i) {
-    cur = jniConsClName->elements[i];
-    if (cur == '/') ptr[0] = '_';
+    else if (cur == '_') {
+      ptr[0] = '_';
+      ptr[1] = '1';
+      ++ptr;
+    }
     else ptr[0] = (uint8)cur;
     ++ptr;
   }
@@ -101,7 +73,7 @@
 
 }
 
-void JavaMethod::jniConsFromMeth3(char* buf) const {
+void JavaMethod::jniConsFromMethOverloaded(char* buf) const {
   const UTF8* jniConsClName = classDef->name;
   const UTF8* jniConsName = name;
   const UTF8* jniConsType = type;
@@ -116,6 +88,11 @@
   for (sint32 i =0; i < clen; ++i) {
     cur = jniConsClName->elements[i];
     if (cur == '/') ptr[0] = '_';
+    else if (cur == '_') {
+      ptr[0] = '_';
+      ptr[1] = '1';
+      ++ptr;
+    }
     else ptr[0] = (uint8)cur;
     ++ptr;
   }
@@ -126,6 +103,11 @@
   for (sint32 i =0; i < mnlen; ++i) {
     cur = jniConsName->elements[i];
     if (cur == '/') ptr[0] = '_';
+    else if (cur == '_') {
+      ptr[0] = '_';
+      ptr[1] = '1';
+      ++ptr;
+    }
     else ptr[0] = (uint8)cur;
     ++ptr;
   }
@@ -165,7 +147,8 @@
 
 }
 
-intptr_t NativeUtil::nativeLookup(CommonClass* cl, JavaMethod* meth, bool& jnjvm) {
+intptr_t NativeUtil::nativeLookup(CommonClass* cl, JavaMethod* meth,
+                                  bool& jnjvm) {
   const UTF8* jniConsClName = cl->name;
   const UTF8* jniConsName = meth->name;
   const UTF8* jniConsType = meth->type;
@@ -173,16 +156,13 @@
   sint32 mnlen = jniConsName->size;
   sint32 mtlen = jniConsType->size;
 
-  char* buf = (char*)alloca(3 + JNI_NAME_PRE_LEN + mnlen + clen + (mtlen << 1));
+  char* buf = (char*)alloca(3 + JNI_NAME_PRE_LEN + 
+                            ((mnlen + clen + mtlen) << 1));
   meth->jniConsFromMeth(buf);
   intptr_t res = cl->classLoader->loadInLib(buf, jnjvm);
   if (!res) {
-    meth->jniConsFromMeth2(buf);
+    meth->jniConsFromMethOverloaded(buf);
     res = cl->classLoader->loadInLib(buf, jnjvm);
-    if (!res) {
-      meth->jniConsFromMeth3(buf);
-      res = cl->classLoader->loadInLib(buf, jnjvm);
-    }
   }
   return res;
 }





More information about the vmkit-commits mailing list