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

Nicolas Geoffray nicolas.geoffray at lip6.fr
Sat Nov 8 08:52:30 PST 2008


Author: geoffray
Date: Sat Nov  8 10:52:25 2008
New Revision: 58915

URL: http://llvm.org/viewvc/llvm-project?rev=58915&view=rev
Log:
Make JNI name creation of methods instance functions of JavaMethod.
Use this name for static compilation.


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=58915&r1=58914&r2=58915&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Sat Nov  8 10:52:25 2008
@@ -801,6 +801,13 @@
   /// printString - Output a string representation of the method.
   ///
   const char* printString() const;
+  
+  /// jniConsFromMeth - Construct the JNI name of this method.
+  ///
+  void jniConsFromMeth(char* buf) const;
+  void jniConsFromMeth2(char* buf) const;
+  void jniConsFromMeth3(char* buf) const;
+  
 
 //===----------------------------------------------------------------------===//
 //
@@ -996,6 +1003,9 @@
     return static_cast<Ty*>(JInfo);
   }
 
+  #define JNI_NAME_PRE "Java_"
+  #define JNI_NAME_PRE_LEN 5
+
 };
 
 

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmModule.cpp Sat Nov  8 10:52:25 2008
@@ -557,10 +557,28 @@
 Function* LLVMMethodInfo::getMethod() {
   if (!methodFunction) {
     JnjvmClassLoader* JCL = methodDef->classDef->classLoader;
-    methodFunction = Function::Create(getFunctionType(), 
-                                      GlobalValue::GhostLinkage,
-                                      methodDef->printString(),
-                                      JCL->TheModule);
+    JnjvmModule* Mod = JCL->getModule();
+    if (Mod->isStaticCompiling()) {
+      const UTF8* jniConsClName = methodDef->classDef->name;
+      const UTF8* jniConsName = methodDef->name;
+      const UTF8* jniConsType = methodDef->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));
+      methodDef->jniConsFromMeth3(buf);
+      methodFunction = Function::Create(getFunctionType(), 
+                                        GlobalValue::GhostLinkage, buf, Mod);
+
+    } else {
+
+      methodFunction = Function::Create(getFunctionType(), 
+                                        GlobalValue::GhostLinkage,
+                                        "", Mod);
+
+    }
     JCL->TheModuleProvider->addFunction(methodFunction, methodDef);
   }
   return methodFunction;

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/NativeUtil.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/NativeUtil.cpp Sat Nov  8 10:52:25 2008
@@ -7,9 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include <dlfcn.h>
-#include <stdlib.h>
-#include <string.h>
 
 #include "ClasspathReflect.h"
 #include "JavaArray.h"
@@ -24,25 +21,25 @@
 #include "NativeUtil.h"
 #include "Reader.h"
 
+#include <cstdlib>
+#include <cstring>
+
 using namespace jnjvm;
 
 Jnjvm* NativeUtil::myVM(JNIEnv* env) {
   return JavaThread::get()->isolate;
 }
 
-#define PRE "Java_"
-#define PRE_LEN 5
-
-static char* jniConsFromMeth(CommonClass* cl, JavaMethod* meth, char* buf) {
-  const UTF8* jniConsClName = cl->name;
-  const UTF8* jniConsName = meth->name;
+void JavaMethod::jniConsFromMeth(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[PRE_LEN]);
+  char* ptr = &(buf[JNI_NAME_PRE_LEN]);
   
-  memcpy(buf, PRE, PRE_LEN);
+  memcpy(buf, JNI_NAME_PRE, JNI_NAME_PRE_LEN);
   
   for (sint32 i =0; i < clen; ++i) {
     cur = jniConsClName->elements[i];
@@ -63,20 +60,19 @@
   
   ptr[0] = 0;
 
-  return buf;
 
 }
 
-static char* jniConsFromMeth2(CommonClass* cl, JavaMethod* meth, char* buf) {
-  const UTF8* jniConsClName = cl->name;
-  const UTF8* jniConsName = meth->name;
+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[PRE_LEN]);
+  char* ptr = &(buf[JNI_NAME_PRE_LEN]);
   
-  memcpy(buf, PRE, PRE_LEN);
+  memcpy(buf, JNI_NAME_PRE, JNI_NAME_PRE_LEN);
   
   for (sint32 i =0; i < clen; ++i) {
     cur = jniConsClName->elements[i];
@@ -102,21 +98,20 @@
   
   ptr[0] = 0;
 
-  return buf;
 
 }
 
-static char* jniConsFromMeth3(CommonClass* cl, JavaMethod* meth, char* buf) {
-  const UTF8* jniConsClName = cl->name;
-  const UTF8* jniConsName = meth->name;
-  const UTF8* jniConsType = meth->type;
+void JavaMethod::jniConsFromMeth3(char* buf) const {
+  const UTF8* jniConsClName = classDef->name;
+  const UTF8* jniConsName = name;
+  const UTF8* jniConsType = type;
   sint32 clen = jniConsClName->size;
   sint32 mnlen = jniConsName->size;
 
   uint32 cur = 0;
-  char* ptr = &(buf[PRE_LEN]);
+  char* ptr = &(buf[JNI_NAME_PRE_LEN]);
   
-  memcpy(buf, PRE, PRE_LEN);
+  memcpy(buf, JNI_NAME_PRE, JNI_NAME_PRE_LEN);
   
   for (sint32 i =0; i < clen; ++i) {
     cur = jniConsClName->elements[i];
@@ -167,7 +162,6 @@
 
   ptr[0] = 0;
 
-  return buf;
 
 }
 
@@ -179,23 +173,22 @@
   sint32 mnlen = jniConsName->size;
   sint32 mtlen = jniConsType->size;
 
-  char* buf = (char*)alloca(3 + PRE_LEN + mnlen + clen + (mtlen << 1));
-  jniConsFromMeth(cl, meth, buf);
+  char* buf = (char*)alloca(3 + JNI_NAME_PRE_LEN + mnlen + clen + (mtlen << 1));
+  meth->jniConsFromMeth(buf);
   void* res = cl->classLoader->loadLib(buf, jnjvm);
   if (!res) {
-    buf = jniConsFromMeth2(cl, meth, buf);
+    meth->jniConsFromMeth2(buf);
     res = cl->classLoader->loadLib(buf, jnjvm);
     if (!res) {
-      buf = jniConsFromMeth3(cl, meth, buf);
+      meth->jniConsFromMeth3(buf);
       res = cl->classLoader->loadLib(buf, jnjvm);
     }
   }
   return res;
 }
 
-#undef PRE_LEN
-
-UserCommonClass* NativeUtil::resolvedImplClass(Jnjvm* vm, jclass clazz, bool doClinit) {
+UserCommonClass* NativeUtil::resolvedImplClass(Jnjvm* vm, jclass clazz,
+                                               bool doClinit) {
   UserCommonClass* cl = ((JavaObjectClass*)clazz)->getClass();
   cl->resolveClass();
   if (doClinit) cl->initialiseClass(vm);





More information about the vmkit-commits mailing list