[vmkit-commits] [vmkit] r58192 - in /vmkit/trunk/lib/JnJVM: Classpath/ClasspathVMRuntime.cpp VMCore/JavaInitialise.cpp VMCore/Jnjvm.cpp VMCore/Jnjvm.h VMCore/JnjvmClassLoader.cpp VMCore/JnjvmClassLoader.h VMCore/NativeUtil.cpp

Nicolas Geoffray nicolas.geoffray at lip6.fr
Sun Oct 26 11:17:41 PDT 2008


Author: geoffray
Date: Sun Oct 26 13:17:39 2008
New Revision: 58192

URL: http://llvm.org/viewvc/llvm-project?rev=58192&view=rev
Log:
Code cleanup. 
Class loader reference the native libraries they loaded, not the virtual machine.



Modified:
    vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMRuntime.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp
    vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp
    vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h
    vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h
    vmkit/trunk/lib/JnJVM/VMCore/NativeUtil.cpp

Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMRuntime.cpp?rev=58192&r1=58191&r2=58192&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMRuntime.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMRuntime.cpp Sun Oct 26 13:17:39 2008
@@ -73,12 +73,14 @@
 jobject _loader) {
   JavaString* str = (JavaString*)_str;
   Jnjvm* vm = JavaThread::get()->isolate;
-  
+  JnjvmClassLoader* loader = 
+    JnjvmClassLoader::getJnjvmLoaderFromJavaObject((JavaObject*)_loader, vm);
+
   char* buf = str->strToAsciiz();
   
   void* res = dlopen(buf, RTLD_LAZY | RTLD_LOCAL);
   if (res != 0) {
-    vm->nativeLibs.push_back(res);
+    loader->nativeLibs.push_back(res);
     onLoad_t onLoad = (onLoad_t)(intptr_t)dlsym(res, "JNI_OnLoad");
     if (onLoad) onLoad(&vm->javavmEnv, 0);
     return 1;

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp Sun Oct 26 13:17:39 2008
@@ -7,26 +7,12 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "mvm/Allocator.h"
 #include "mvm/VirtualMachine.h"
-#include "mvm/Threads/Locks.h"
-#include "mvm/Threads/Thread.h"
 
 #include "JavaArray.h"
-#include "JavaCache.h"
-#include "JavaClass.h"
-#include "JavaConstantPool.h"
-#include "JavaJIT.h"
 #include "JavaObject.h"
-#include "JavaString.h"
 #include "JavaThread.h"
-#include "JavaTypes.h"
-#include "JavaUpcalls.h"
 #include "Jnjvm.h"
-#include "JnjvmModuleProvider.h"
-#include "NativeUtil.h"
-#include "LockedMap.h"
-#include "Zip.h"
 
 #ifdef SERVICE_VM
 #include "ServiceDomain.h"
@@ -75,35 +61,31 @@
 #undef INIT
 }
 
-void Jnjvm::initialiseStatics() {
-
 #ifdef ISOLATE_SHARING
+void mvm::VirtualMachine::initialiseJVM() {
+  initialiseVT();
   if (!JnjvmSharedLoader::sharedLoader) {
     JnjvmSharedLoader::sharedLoader = JnjvmSharedLoader::createSharedLoader();
   }
-#endif
- 
-  bootstrapLoader = gc_new(JnjvmBootstrapLoader)(0);
 }
 
+mvm::VirtualMachine* mvm::VirtualMachine::createJVM() {
+  JnjvmBootstraLoader* bootstrapLoader = gc_new(JnjvmBootstrapLoader)(0);
+  Jnjvm* vm = gc_new(Jnjvm)(bootstrapLoader);
+  return vm;
+}
+#else
+  
 void mvm::VirtualMachine::initialiseJVM() {
-#ifndef ISOLATE_SHARING
+  initialiseVT();
   if (!JnjvmClassLoader::bootstrapLoader) {
-    initialiseVT();
-    Jnjvm::initialiseStatics();
-    JnjvmClassLoader::bootstrapLoader = Jnjvm::bootstrapLoader;
+    JnjvmClassLoader::bootstrapLoader = gc_new(JnjvmBootstrapLoader)(0);
   }
-#else
-  initialiseVT(); 
-#endif
 }
 
 mvm::VirtualMachine* mvm::VirtualMachine::createJVM() {
-#ifdef SERVICE_VM
-  ServiceDomain* vm = ServiceDomain::allocateService();
-  vm->startExecution();
-#else
-  Jnjvm* vm = gc_new(Jnjvm)(0);
-#endif
+  Jnjvm* vm = gc_new(Jnjvm)(JnjvmClassLoader::bootstrapLoader);
   return vm;
 }
+
+#endif

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Sun Oct 26 13:17:39 2008
@@ -45,9 +45,6 @@
 const unsigned int Jnjvm::Magic = 0xcafebabe;
 
 #ifndef ISOLATE
-/// If we're not in a multi-vm environment, this can be made static.
-std::vector<void*> Jnjvm::nativeLibs;
-JnjvmBootstrapLoader* Jnjvm::bootstrapLoader;
 std::map<const char, UserClassPrimitive*> Jnjvm::primitiveMap;
 #endif
 
@@ -789,7 +786,7 @@
   }
 }
 
-Jnjvm::Jnjvm(uint32 memLimit) {
+Jnjvm::Jnjvm(JnjvmBootstrapLoader* loader) {
 
   classpath = getenv("CLASSPATH");
   if (!classpath) classpath = ".";
@@ -799,10 +796,7 @@
   javavmEnv = &JNI_JavaVMTable;
   
 
-#ifdef ISOLATE_SHARING
-  initialiseStatics();
-#endif
-  
+  bootstrapLoader = loader;
   upcalls = bootstrapLoader->upcalls;
 
 #ifdef ISOLATE_SHARING

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h Sun Oct 26 13:17:39 2008
@@ -21,7 +21,6 @@
 #include "mvm/Threads/Cond.h"
 #include "mvm/Threads/Locks.h"
 
-#include "JavaTypes.h"
 #include "JnjvmConfig.h"
 #include "LockedMap.h"
 
@@ -177,7 +176,7 @@
   /// bootstraLoader - Bootstrap loader for base classes of this virtual
   /// machine.
   ///
-  ISOLATE_STATIC JnjvmBootstrapLoader* bootstrapLoader;
+  JnjvmBootstrapLoader* bootstrapLoader;
 
   /// upcalls - Upcalls to call Java methods and access Java fields.
   ///
@@ -200,10 +199,6 @@
   ///
   std::vector< std::pair<char*, char*> > postProperties;
 
-  /// nativeLibs - Native libraries (e.g. '.so') loaded by this JVM.
-  ///
-  ISOLATE_STATIC std::vector<void*> nativeLibs;
-
   /// classpath - The CLASSPATH value, or the paths given in command line.
   ///
   const char* classpath;
@@ -293,18 +288,13 @@
     classpath = cp;
   }
   
-  /// initialiseStatics - Initializes the isolate. The function initialize
-  /// static variables in a single environment.
-  ///
-  ISOLATE_STATIC void initialiseStatics();
-  
   ISOLATE_STATIC UserClassPrimitive* getPrimitiveClass(char id) {
     return primitiveMap[id];
   }
 
   /// Jnjvm - Allocates a new JVM.
   ///
-  Jnjvm(uint32 memLimit);
+  Jnjvm(JnjvmBootstrapLoader* loader);
   
   /// runApplication - Runs the application with the given command line.
   /// User-visible function, inherited by the VirtualMachine class.

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Sun Oct 26 13:17:39 2008
@@ -7,10 +7,18 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include <dlfcn.h>
 #include <limits.h>
 #include <unistd.h>
 #include <sys/stat.h>
 
+
+#if defined(__MACH__)
+#define SELF_HANDLE RTLD_DEFAULT
+#else
+#define SELF_HANDLE 0
+#endif
+
 #include "debug.h"
 
 #include "mvm/Allocator.h"
@@ -31,8 +39,6 @@
 
 #ifndef ISOLATE_SHARING
 JnjvmBootstrapLoader* JnjvmClassLoader::bootstrapLoader = 0;
-UserClass* JnjvmBootstrapLoader::SuperArray = 0;
-UserClass** JnjvmBootstrapLoader::InterfacesArray;
 #endif
 
 
@@ -654,3 +660,22 @@
 
   return readerConstructUTF8(buf, n);
 }
+
+void* JnjvmClassLoader::loadLib(const char* buf, bool& jnjvm) {
+  void* res = dlsym(SELF_HANDLE, buf);
+  
+  if (!res) {
+    for (std::vector<void*>::iterator i = nativeLibs.begin(),
+              e = nativeLibs.end(); i!= e; ++i) {
+      res = dlsym((*i), buf);
+      if (res) break;
+    }
+  } else {
+    jnjvm = true;
+  }
+  
+  if (!res && this != bootstrapLoader)
+    res = bootstrapLoader->loadLib(buf, jnjvm);
+
+  return res;
+}

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h Sun Oct 26 13:17:39 2008
@@ -222,6 +222,12 @@
 
   /// Strings hashed by this classloader.
   std::vector<JavaString*, gc_allocator<JavaString*> > strings;
+  
+  /// nativeLibs - Native libraries (e.g. '.so') loaded by this class loader.
+  ///
+  std::vector<void*> nativeLibs;
+
+  void* loadLib(const char* buf, bool& jnjvm);
 };
 
 /// JnjvmBootstrapLoader - This class is for the bootstrap class loader, which
@@ -288,10 +294,13 @@
   /// Java code.
   ///
   Classpath* upcalls;
+  
+  /// InterfacesArray - The interfaces that array classes implement.
+  ///
+  UserClass** InterfacesArray;
 
-  ISOLATE_STATIC UserClass** InterfacesArray;
-  ISOLATE_STATIC UserClass* SuperArray;
-
+  /// SuperArray - The super of array classes.
+  UserClass* SuperArray;
 
   /// Lists of UTF8s used internaly in VMKit.
   const UTF8* NoClassDefFoundError;

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/NativeUtil.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/NativeUtil.cpp Sun Oct 26 13:17:39 2008
@@ -30,12 +30,6 @@
   return JavaThread::get()->isolate;
 }
 
-#if defined(__MACH__)
-#define SELF_HANDLE RTLD_DEFAULT
-#else
-#define SELF_HANDLE 0
-#endif
-
 #define PRE "Java_"
 #define PRE_LEN 5
 
@@ -177,25 +171,6 @@
 
 }
 
-static void* loadName(char* buf, bool& jnjvm) {
-  void* res = dlsym(SELF_HANDLE, buf);
-  if (!res) {
-#ifndef SERVICE_VM
-    Jnjvm* vm = JavaThread::get()->isolate;
-#else
-    Jnjvm* vm = Jnjvm::bootstrapVM;
-#endif
-    for (std::vector<void*>::iterator i = vm->nativeLibs.begin(), 
-              e = vm->nativeLibs.end(); i!= e; ++i) {
-      res = dlsym((*i), buf);
-      if (res) break;
-    }
-  } else {
-    jnjvm = true;
-  }
-  return res;
-}
-
 void* NativeUtil::nativeLookup(CommonClass* cl, JavaMethod* meth, bool& jnjvm) {
   const UTF8* jniConsClName = cl->name;
   const UTF8* jniConsName = meth->name;
@@ -206,13 +181,13 @@
 
   char* buf = (char*)alloca(3 + PRE_LEN + mnlen + clen + (mtlen << 1));
   jniConsFromMeth(cl, meth, buf);
-  void* res = loadName(buf, jnjvm);
+  void* res = cl->classLoader->loadLib(buf, jnjvm);
   if (!res) {
     buf = jniConsFromMeth2(cl, meth, buf);
-    res = loadName(buf, jnjvm);
+    res = cl->classLoader->loadLib(buf, jnjvm);
     if (!res) {
       buf = jniConsFromMeth3(cl, meth, buf);
-      res = loadName(buf, jnjvm);
+      res = cl->classLoader->loadLib(buf, jnjvm);
       if (!res) {
         printf("Native function %s not found. Probably "
                "not implemented by JnJVM?\n", meth->printString());





More information about the vmkit-commits mailing list