* src/native/native.cpp: Moved to C++, use STL container.
authorChristian Thalinger <twisti@complang.tuwien.ac.at>
Wed, 10 Sep 2008 10:00:45 +0000 (12:00 +0200)
committerChristian Thalinger <twisti@complang.tuwien.ac.at>
Wed, 10 Sep 2008 10:00:45 +0000 (12:00 +0200)
* src/native/native.hpp: Likewise.
* src/native/jni.cpp,
src/native/vm/cldc1.1/com_sun_cldc_io_ResourceInputStream.cpp,
src/native/vm/cldc1.1/com_sun_cldc_io_j2me_socket_Protocol.cpp,
src/native/vm/cldc1.1/com_sun_cldchi_io_ConsoleOutputStream.cpp,
src/native/vm/cldc1.1/com_sun_cldchi_jvm_JVM.cpp,
src/native/vm/cldc1.1/java_lang_Class.cpp,
src/native/vm/cldc1.1/java_lang_Double.cpp,
src/native/vm/cldc1.1/java_lang_Float.cpp,
src/native/vm/cldc1.1/java_lang_Math.cpp,
src/native/vm/cldc1.1/java_lang_Object.cpp,
src/native/vm/cldc1.1/java_lang_Runtime.cpp,
src/native/vm/cldc1.1/java_lang_String.cpp,
src/native/vm/cldc1.1/java_lang_System.cpp,
src/native/vm/cldc1.1/java_lang_Thread.cpp,
src/native/vm/cldc1.1/java_lang_Throwable.cpp,
src/native/vm/gnuclasspath/gnu_classpath_VMStackWalker.cpp,
src/native/vm/gnuclasspath/gnu_classpath_VMSystemProperties.cpp,
src/native/vm/gnuclasspath/gnu_java_lang_VMCPStringBuilder.cpp,
src/native/vm/gnuclasspath/gnu_java_lang_management_VMClassLoadingMXBeanImpl.cpp,
src/native/vm/gnuclasspath/gnu_java_lang_management_VMMemoryMXBeanImpl.cpp,
src/native/vm/gnuclasspath/gnu_java_lang_management_VMRuntimeMXBeanImpl.cpp,
src/native/vm/gnuclasspath/gnu_java_lang_management_VMThreadMXBeanImpl.cpp,
src/native/vm/gnuclasspath/java_lang_VMClass.cpp,
src/native/vm/gnuclasspath/java_lang_VMClassLoader.cpp,
src/native/vm/gnuclasspath/java_lang_VMObject.cpp,
src/native/vm/gnuclasspath/java_lang_VMRuntime.cpp,
src/native/vm/gnuclasspath/java_lang_VMString.cpp,
src/native/vm/gnuclasspath/java_lang_VMSystem.cpp,
src/native/vm/gnuclasspath/java_lang_VMThread.cpp,
src/native/vm/gnuclasspath/java_lang_VMThrowable.cpp,
src/native/vm/gnuclasspath/java_lang_management_VMManagementFactory.cpp,
src/native/vm/gnuclasspath/java_lang_reflect_VMConstructor.cpp,
src/native/vm/gnuclasspath/java_lang_reflect_VMField.cpp,
src/native/vm/gnuclasspath/java_lang_reflect_VMMethod.cpp,
src/native/vm/gnuclasspath/java_security_VMAccessController.cpp,
src/native/vm/gnuclasspath/java_util_concurrent_atomic_AtomicLong.cpp,
src/native/vm/gnuclasspath/sun_reflect_ConstantPool.cpp,
src/native/vm/nativevm.cpp,
src/native/vm/openjdk/hpi.cpp,
src/native/vm/openjdk/jvm.cpp,
src/native/vm/sun_misc_Unsafe.cpp,
src/vm/jit/jit.cpp,
src/vm/jit/patcher-common.cpp,
src/vm/vm.cpp,
src/vm/vm.hpp: Related changes.

47 files changed:
src/native/jni.cpp
src/native/native.cpp
src/native/native.hpp
src/native/vm/cldc1.1/com_sun_cldc_io_ResourceInputStream.cpp
src/native/vm/cldc1.1/com_sun_cldc_io_j2me_socket_Protocol.cpp
src/native/vm/cldc1.1/com_sun_cldchi_io_ConsoleOutputStream.cpp
src/native/vm/cldc1.1/com_sun_cldchi_jvm_JVM.cpp
src/native/vm/cldc1.1/java_lang_Class.cpp
src/native/vm/cldc1.1/java_lang_Double.cpp
src/native/vm/cldc1.1/java_lang_Float.cpp
src/native/vm/cldc1.1/java_lang_Math.cpp
src/native/vm/cldc1.1/java_lang_Object.cpp
src/native/vm/cldc1.1/java_lang_Runtime.cpp
src/native/vm/cldc1.1/java_lang_String.cpp
src/native/vm/cldc1.1/java_lang_System.cpp
src/native/vm/cldc1.1/java_lang_Thread.cpp
src/native/vm/cldc1.1/java_lang_Throwable.cpp
src/native/vm/gnuclasspath/gnu_classpath_VMStackWalker.cpp
src/native/vm/gnuclasspath/gnu_classpath_VMSystemProperties.cpp
src/native/vm/gnuclasspath/gnu_java_lang_VMCPStringBuilder.cpp
src/native/vm/gnuclasspath/gnu_java_lang_management_VMClassLoadingMXBeanImpl.cpp
src/native/vm/gnuclasspath/gnu_java_lang_management_VMMemoryMXBeanImpl.cpp
src/native/vm/gnuclasspath/gnu_java_lang_management_VMRuntimeMXBeanImpl.cpp
src/native/vm/gnuclasspath/gnu_java_lang_management_VMThreadMXBeanImpl.cpp
src/native/vm/gnuclasspath/java_lang_VMClass.cpp
src/native/vm/gnuclasspath/java_lang_VMClassLoader.cpp
src/native/vm/gnuclasspath/java_lang_VMObject.cpp
src/native/vm/gnuclasspath/java_lang_VMRuntime.cpp
src/native/vm/gnuclasspath/java_lang_VMString.cpp
src/native/vm/gnuclasspath/java_lang_VMSystem.cpp
src/native/vm/gnuclasspath/java_lang_VMThread.cpp
src/native/vm/gnuclasspath/java_lang_VMThrowable.cpp
src/native/vm/gnuclasspath/java_lang_management_VMManagementFactory.cpp
src/native/vm/gnuclasspath/java_lang_reflect_VMConstructor.cpp
src/native/vm/gnuclasspath/java_lang_reflect_VMField.cpp
src/native/vm/gnuclasspath/java_lang_reflect_VMMethod.cpp
src/native/vm/gnuclasspath/java_security_VMAccessController.cpp
src/native/vm/gnuclasspath/java_util_concurrent_atomic_AtomicLong.cpp
src/native/vm/gnuclasspath/sun_reflect_ConstantPool.cpp
src/native/vm/nativevm.cpp
src/native/vm/openjdk/hpi.cpp
src/native/vm/openjdk/jvm.cpp
src/native/vm/sun_misc_Unsafe.cpp
src/vm/jit/jit.cpp
src/vm/jit/patcher-common.cpp
src/vm/vm.cpp
src/vm/vm.hpp

index a9761747888e20aabc350fd727a3310d78dbdc5e..c88888fed4680812a67dae23e7244ad3feb07705 100644 (file)
@@ -2972,20 +2972,18 @@ JNI_SET_ARRAY_REGION(Double,  jdouble,  double,  double)
 
 *******************************************************************************/
 
-jint _Jv_JNI_RegisterNatives(JNIEnv *env, jclass clazz,
-                                                        const JNINativeMethod *methods, jint nMethods)
+jint jni_RegisterNatives(JNIEnv* env, jclass clazz, const JNINativeMethod* methods, jint nMethods)
 {
-       classinfo *c;
-
-       STATISTICS(jniinvokation());
+       TRACEJNICALLS(("jni_RegisterNatives(env=%p, clazz=%p, methods=%p, nMethods=%d)", env, clazz, methods, nMethods));
 
-       c = LLNI_classinfo_unwrap(clazz);
+       classinfo* c = LLNI_classinfo_unwrap(clazz);
 
        /* XXX: if implemented this needs a call to jvmti_NativeMethodBind
        if (jvmti) jvmti_NativeMethodBind(method, address,  new_address_ptr);
        */
 
-       native_method_register(c->name, methods, nMethods);
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(c->name, methods, nMethods);
 
     return 0;
 }
@@ -4074,7 +4072,7 @@ struct JNINativeInterface_ _Jv_JNINativeInterface = {
        _Jv_JNI_SetFloatArrayRegion,
        _Jv_JNI_SetDoubleArrayRegion,
 
-       _Jv_JNI_RegisterNatives,
+       jni_RegisterNatives,
        _Jv_JNI_UnregisterNatives,
 
        _Jv_JNI_MonitorEnter,
index 794fffbe2edcdf9ef1e4d9bf1b595e4a5d3cbc01..89a530ca7e5ff7215748e24f5b10cfd110999118 100644 (file)
@@ -30,7 +30,9 @@
 
 #include <stdint.h>
 
-#include "vm/types.h"
+#include <algorithm>
+#include <functional>
+#include <map>
 
 #include "mm/memory.h"
 
@@ -39,8 +41,6 @@
 
 #include "threads/mutex.hpp"
 
-#include "toolbox/avl.h"
-#include "toolbox/hashtable.h"
 #include "toolbox/logging.h"
 
 #include "vm/jit/builtin.hpp"
 #endif
 
 
-/* global variables ***********************************************************/
-
-static avl_tree_t *tree_native_methods;
-
-#if defined(ENABLE_DL)
-static hashtable *hashtable_library;
-#endif
-
-
-/* prototypes *****************************************************************/
-
-static s4 native_tree_native_methods_comparator(const void *treenode, const void *node);
-
-
-/* native_init *****************************************************************
-
-   Initializes the native subsystem.
-
-*******************************************************************************/
-
-bool native_init(void)
-{
-       TRACESUBSYSTEMINITIALIZATION("native_init");
-
-#if defined(ENABLE_DL)
-       /* initialize library hashtable, 10 entries should be enough */
-
-       hashtable_library = NEW(hashtable);
-
-       hashtable_create(hashtable_library, 10);
-#endif
-
-       /* initialize the native methods table */
-
-       tree_native_methods = avl_create(&native_tree_native_methods_comparator);
-
-       /* everything's ok */
-
-       return true;
-}
-
-
-/* native_tree_native_methods_comparator ***************************************
-
-   Comparison function for AVL tree of native methods.
-
-   IN:
-       treenode....node in the tree
-          node........node to compare with tree-node
-
-   RETURN VALUE:
-       -1, 0, +1
-
-*******************************************************************************/
-
-static s4 native_tree_native_methods_comparator(const void *treenode, const void *node)
-{
-       const native_methods_node_t *treenmn;
-       const native_methods_node_t *nmn;
-
-       treenmn = (native_methods_node_t*) treenode;
-       nmn     = (native_methods_node_t*) node;
-
-       /* these are for walking the tree */
-
-       if (treenmn->classname < nmn->classname)
-               return -1;
-       else if (treenmn->classname > nmn->classname)
-               return 1;
-
-       if (treenmn->name < nmn->name)
-               return -1;
-       else if (treenmn->name > nmn->name)
-               return 1;
-
-       if (treenmn->descriptor < nmn->descriptor)
-               return -1;
-       else if (treenmn->descriptor > nmn->descriptor)
-               return 1;
-
-       /* all pointers are equal, we have found the entry */
-
-       return 0;
-}
-
-
 /* native_make_overloaded_function *********************************************
 
    XXX
@@ -398,109 +312,68 @@ static utf *native_method_symbol(utf *classname, utf *methodname)
 }
 
 
-/* native_method_register ******************************************************
-
-   Register a native method in the native method table.
-
-*******************************************************************************/
-
-void native_method_register(utf *classname, const JNINativeMethod *methods,
-                                                       int32_t count)
+bool operator< (const NativeMethod& first, const NativeMethod& second)
 {
-       native_methods_node_t *nmn;
-       utf                   *name;
-       utf                   *descriptor;
-       int32_t                i;
+       if (first._classname < second._classname)
+               return true;
+       else if (first._classname > second._classname)
+               return false;
+               
+       if (first._name < second._name)
+               return true;
+       else if (first._name > second._name)
+               return false;
+
+       if (first._descriptor < second._descriptor)
+               return true;
+       else if (first._descriptor > second._descriptor)
+               return false;
+
+       // All pointers are equal, we have found the entry.
+       return false;
+}
 
-       /* insert all methods passed */
 
-       for (i = 0; i < count; i++) {
+/**
+ * Register native methods with the VM.  This is done by inserting
+ * them into the native method table.
+ *
+ * @param classname
+ * @param methods   Native methods array.
+ * @param count     Number of methods in the array.
+ */
+void NativeMethods::register_methods(utf* classname, const JNINativeMethod* methods, size_t count)
+{
+       // Insert all methods passed */
+       for (size_t i = 0; i < count; i++) {
                if (opt_verbosejni) {
                        printf("[Registering JNI native method ");
                        utf_display_printable_ascii_classname(classname);
                        printf(".%s]\n", methods[i].name);
                }
 
-               /* generate the utf8 names */
-
-               name       = utf_new_char(methods[i].name);
-               descriptor = utf_new_char(methods[i].signature);
-
-               /* allocate a new tree node */
+               // Generate the UTF8 names.
+               utf* name      = utf_new_char(methods[i].name);
+               utf* signature = utf_new_char(methods[i].signature);
 
-               nmn = NEW(native_methods_node_t);
+               NativeMethod nm(classname, name, signature, methods[i].fnPtr);
 
-               nmn->classname  = classname;
-               nmn->name       = name;
-               nmn->descriptor = descriptor;
-               nmn->function   = (functionptr) (ptrint) methods[i].fnPtr;
-
-               /* insert the method into the tree */
-
-               avl_insert(tree_native_methods, nmn);
+               // Insert the method into the table.
+               _methods.insert(nm);
        }
 }
 
 
-/* native_method_find **********************************************************
-
-   Find a native method in the native method table.
-
-*******************************************************************************/
-
-static functionptr native_method_find(methodinfo *m)
-{
-       native_methods_node_t  tmpnmn;
-       native_methods_node_t *nmn;
-
-       /* fill the temporary structure used for searching the tree */
-
-       tmpnmn.classname  = m->clazz->name;
-       tmpnmn.name       = m->name;
-       tmpnmn.descriptor = m->descriptor;
-
-       /* find the entry in the AVL-tree */
-
-       nmn = (native_methods_node_t*) avl_find(tree_native_methods, &tmpnmn);
-
-       if (nmn == NULL)
-               return NULL;
-
-       return nmn->function;
-}
-
-
-/* native_method_resolve *******************************************************
-
-   Resolves a native method, maybe from a dynamic library.
-
-   IN:
-       m ... methodinfo of the native Java method to resolve
-
-   RESULT:
-       pointer to the resolved method (symbol)
-
-*******************************************************************************/
-
-functionptr native_method_resolve(methodinfo *m)
+/**
+ * Resolves a native method, maybe from a dynamic library.
+ *
+ * @param m Method structure of the native Java method to resolve.
+ *
+ * @return Pointer to the resolved method (symbol).
+ */
+void* NativeMethods::resolve_method(methodinfo* m)
 {
-       utf                            *name;
-       utf                            *newname;
-       functionptr                     f;
-#if defined(ENABLE_DL)
-       classloader_t                  *cl;
-       hashtable_library_loader_entry *le;
-       hashtable_library_name_entry   *ne;
-       u4                              key;    /* hashkey                        */
-       u4                              slot;   /* slot in hashtable              */
-#endif
-#if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
-       methodinfo                     *method_findNative;
-       java_handle_t                  *s;
-#endif
-
-       /* verbose output */
-
+       // Verbose output.
        if (opt_verbosejni) {
                printf("[Dynamic-linking native method ");
                utf_display_printable_ascii_classname(m->clazz->name);
@@ -511,54 +384,33 @@ functionptr native_method_resolve(methodinfo *m)
 
        /* generate method symbol string */
 
-       name = native_method_symbol(m->clazz->name, m->name);
+       utf* name = native_method_symbol(m->clazz->name, m->name);
 
        /* generate overloaded function (having the types in it's name)           */
 
-       newname = native_make_overloaded_function(name, m->descriptor);
+       utf* newname = native_make_overloaded_function(name, m->descriptor);
 
-       /* check the library hash entries of the classloader of the
-          methods's class  */
-
-       f = NULL;
+       // Try to find the symbol.
+       void* symbol = NULL;
 
 #if defined(ENABLE_DL)
-       /* Get the classloader. */
-
-       cl = class_get_classloader(m->clazz);
-
-       /* normally addresses are aligned to 4, 8 or 16 bytes */
-
-       key  = ((u4) (ptrint) cl) >> 4;                       /* align to 16-byte */
-       slot = key & (hashtable_library->size - 1);
-       le   = (hashtable_library_loader_entry*) hashtable_library->ptr[slot];
-
-       /* iterate through loaders in this hash slot */
+       // Get the classloader.
+       classloader_t* classloader = class_get_classloader(m->clazz);
 
-       while ((le != NULL) && (f == NULL)) {
-               /* iterate through names in this loader */
+       // Resolve the native method name from the native libraries.
+       NativeLibraries& libraries = VM::get_current()->get_nativelibraries();
+       symbol = libraries.resolve_symbol(name, classloader);
 
-               ne = le->namelink;
-                       
-               while ((ne != NULL) && (f == NULL)) {
-                       f = (functionptr) (ptrint) os::dlsym(ne->handle, name->text);
-
-                       if (f == NULL)
-                               f = (functionptr) (ptrint) os::dlsym(ne->handle, newname->text);
-
-                       ne = ne->hashlink;
-               }
-
-               le = le->hashlink;
-       }
+       if (symbol == NULL)
+               symbol = libraries.resolve_symbol(newname, classloader);
 
 # if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
-       if (f == NULL) {
+       if (symbol == NULL) {
                /* We can resolve the function directly from
                   java.lang.ClassLoader as it's a static function. */
                /* XXX should be done in native_init */
 
-               method_findNative =
+               methodinfo* method_findNative =
                        class_resolveclassmethod(class_java_lang_ClassLoader,
                                                                         utf_findNative,
                                                                         utf_java_lang_ClassLoader_java_lang_String__J,
@@ -568,36 +420,29 @@ functionptr native_method_resolve(methodinfo *m)
                if (method_findNative == NULL)
                        return NULL;
 
-               /* try the normal name */
+               // Try the normal name.
+               java_handle_t* s = javastring_new(name);
+               symbol = (void*) vm_call_method_long(method_findNative, NULL, classloader, s);
 
-               s = javastring_new(name);
-
-               f = (functionptr) (intptr_t) vm_call_method_long(method_findNative,
-                                                                                                                NULL, cl, s);
-
-               /* if not found, try the mangled name */
-
-               if (f == NULL) {
+               // If not found, try the mangled name.
+               if (symbol == NULL) {
                        s = javastring_new(newname);
-
-                       f = (functionptr) (intptr_t) vm_call_method_long(method_findNative,
-                                                                                                                        NULL, cl, s);
+                       symbol = (void*) vm_call_method_long(method_findNative, NULL, classloader, s);
                }
        }
 # endif
 
-       if (f != NULL)
+       if (symbol != NULL)
                if (opt_verbosejni)
                        printf("JNI ]\n");
 #endif
 
-       /* If not found, try to find the native function symbol in the
-          main program. */
+       // If not found already, try to find the native method symbol in
+       // the native methods registered with the VM.
+       if (symbol == NULL) {
+               symbol = find_registered_method(m);
 
-       if (f == NULL) {
-               f = native_method_find(m);
-
-               if (f != NULL)
+               if (symbol != NULL)
                        if (opt_verbosejni)
                                printf("internal ]\n");
        }
@@ -607,54 +452,66 @@ functionptr native_method_resolve(methodinfo *m)
        if (jvmti) jvmti_NativeMethodBind(m, f, &f);
 #endif
 
-       /* no symbol found? throw exception */
-
-       if (f == NULL) {
+       // Symbol not found?  Throw an exception.
+       if (symbol == NULL) {
                if (opt_verbosejni)
                        printf("failed ]\n");
 
                exceptions_throw_unsatisfiedlinkerror(m->name);
        }
 
-       return f;
+       return symbol;
 }
 
 
-/* native_library_open *********************************************************
-
-   Open a native library with the given utf8 name.
+/**
+ * Try to find the given method in the native methods registered with
+ * the VM.
+ *
+ * @param m Method structure.
+ *
+ * @return Pointer to function if found, NULL otherwise.
+ */
+void* NativeMethods::find_registered_method(methodinfo* m)
+{
+       NativeMethod nm(m);
+       std::set<NativeMethod>::iterator it = _methods.find(nm);
 
-   IN:
-       filename ... filename of the library to open
+       if (it == _methods.end())
+               return NULL;
 
-   RETURN:
-       handle of the opened library
+       return (*it).get_function();
+}
 
-*******************************************************************************/
 
+/**
+ * Open this native library.
+ *
+ * @return File handle on success, NULL otherwise.
+ */
 #if defined(ENABLE_DL)
-void* native_library_open(utf *filename)
+void* NativeLibrary::open()
 {
-       void* handle;
-
        if (opt_verbosejni) {
                printf("[Loading native library ");
-               utf_display_printable_ascii(filename);
+               utf_display_printable_ascii(_filename);
                printf(" ... ");
        }
 
-       /* try to open the library */
+       // Sanity check.
+       assert(_filename != NULL);
 
-       handle = os::dlopen(filename->text, RTLD_LAZY);
+       // Try to open the library.
+       _handle = os::dlopen(_filename->text, RTLD_LAZY);
 
-       if (handle == NULL) {
+       if (_handle == NULL) {
                if (opt_verbosejni)
                        printf("failed ]\n");
 
                if (opt_verbose) {
                        log_start();
-                       log_print("native_library_open: os::dlopen failed: ");
-                       log_print(dlerror());
+                       log_print("NativeLibrary::open: os::dlopen failed: ");
+                       log_print(os::dlerror());
                        log_finish();
                }
 
@@ -664,258 +521,209 @@ void* native_library_open(utf *filename)
        if (opt_verbosejni)
                printf("OK ]\n");
 
-       return handle;
+       return _handle;
 }
 #endif
 
 
-/* native_library_close ********************************************************
-
-   Close the native library of the given handle.
-
-   IN:
-       handle ... handle of the open library
-
-*******************************************************************************/
-
+/**
+ * Close this native library.
+ */
 #if defined(ENABLE_DL)
-void native_library_close(void* handle)
+void NativeLibrary::close()
 {
-       int result;
-
        if (opt_verbosejni) {
                printf("[Unloading native library ");
 /*             utf_display_printable_ascii(filename); */
                printf(" ... ");
        }
 
-       /* Close the library. */
+       // Sanity check.
+       assert(_handle != NULL);
 
-       result = os::dlclose(handle);
+       // Close the library.
+       int result = os::dlclose(_handle);
 
        if (result != 0) {
+               if (opt_verbosejni)
+                       printf("failed ]\n");
+
                if (opt_verbose) {
                        log_start();
-                       log_print("native_library_close: os::dlclose failed: ");
-                       log_print(dlerror());
+                       log_print("NativeLibrary::close: os::dlclose failed: ");
+                       log_print(os::dlerror());
                        log_finish();
                }
        }
+
+       if (opt_verbosejni)
+               printf("OK ]\n");
 }
 #endif
 
 
-/* native_library_add **********************************************************
-
-   Adds an entry to the native library hashtable.
-
-*******************************************************************************/
-
-#if defined(ENABLE_DL)
-void native_library_add(utf *filename, classloader_t *loader, void* handle)
+/**
+ * Load this native library and initialize it, if possible.
+ *
+ * @param env JNI environment.
+ *
+ * @return true if library loaded successfully, false otherwise.
+ */
+bool NativeLibrary::load(JNIEnv* env)
 {
-       hashtable_library_loader_entry *le;
-       hashtable_library_name_entry   *ne; /* library name                       */
-       u4   key;                           /* hashkey                            */
-       u4   slot;                          /* slot in hashtable                  */
-
-       hashtable_library->mutex->lock();
-
-       /* normally addresses are aligned to 4, 8 or 16 bytes */
-
-       key  = ((u4) (ptrint) loader) >> 4;        /* align to 16-byte boundaries */
-       slot = key & (hashtable_library->size - 1);
-       le   = (hashtable_library_loader_entry*) hashtable_library->ptr[slot];
-
-       /* search external hash chain for the entry */
-
-       while (le) {
-               if (le->loader == loader)
-                       break;
-
-               le = le->hashlink;                  /* next element in external chain */
+#if defined(ENABLE_DL)
+       if (_filename == NULL) {
+               exceptions_throw_nullpointerexception();
+               return false;
        }
 
-       /* no loader found? create a new entry */
-
-       if (le == NULL) {
-               le = NEW(hashtable_library_loader_entry);
-
-               le->loader   = loader;
-               le->namelink = NULL;
+       // Is the library already loaded?
+       if (is_loaded())
+               return true;
 
-               /* insert entry into hashtable */
+       // Open the library.
+       open();
 
-               le->hashlink =
-                       (hashtable_library_loader_entry *) hashtable_library->ptr[slot];
-               hashtable_library->ptr[slot] = le;
+       if (_handle == NULL)
+               return false;
 
-               /* update number of hashtable-entries */
+# if defined(ENABLE_JNI)
+       // Resolve JNI_OnLoad function.
+       void* onload = os::dlsym(_handle, "JNI_OnLoad");
 
-               hashtable_library->entries++;
-       }
+       if (onload != NULL) {
+               JNIEXPORT jint (JNICALL *JNI_OnLoad) (JavaVM*, void*);
+               JavaVM *vm;
 
+               JNI_OnLoad = (JNIEXPORT jint (JNICALL *)(JavaVM*, void*)) (uintptr_t) onload;
 
-       /* search for library name */
+               env->GetJavaVM(&vm);
 
-       ne = le->namelink;
+               jint version = JNI_OnLoad(vm, NULL);
 
-       while (ne) {
-               if (ne->name == filename) {
-                       hashtable_library->mutex->unlock();
-                       return;
+               // If the version is not 1.2 and not 1.4 the library cannot be
+               // loaded.
+               if ((version != JNI_VERSION_1_2) && (version != JNI_VERSION_1_4)) {
+                       os::dlclose(_handle);
+                       return false;
                }
-
-               ne = ne->hashlink;                  /* next element in external chain */
        }
+# endif
 
-       /* not found? add the library name to the classloader */
-
-       ne = NEW(hashtable_library_name_entry);
+       // Insert the library name into the native library table.
+       NativeLibraries& nativelibraries = VM::get_current()->get_nativelibraries();
+       nativelibraries.add(*this);
 
-       ne->name   = filename;
-       ne->handle = handle;
+       return true;
+#else
+       os::abort("NativeLibrary::load: Not available in this configuration.");
 
-       /* insert entry into external chain */
+       // Keep the compiler happy.
+       return false;
+#endif
+}
 
-       ne->hashlink = le->namelink;
-       le->namelink = ne;
 
-       hashtable_library->mutex->unlock();
+/**
+ * Checks if this native library is loaded.
+ *
+ * @return true if loaded, false otherwise.
+ */
+#if defined(ENABLE_DL)
+bool NativeLibrary::is_loaded()
+{
+       NativeLibraries& libraries = VM::get_current()->get_nativelibraries();
+       return libraries.is_loaded(*this);
 }
 #endif
 
 
-/* native_library_find *********************************************************
-
-   Find an entry in the native library hashtable.
+/**
+ * Resolve the given symbol in this native library.
+ *
+ * @param symbolname Symbol name.
+ *
+ * @return Pointer to symbol if found, NULL otherwise.
+ */
+void* NativeLibrary::resolve_symbol(utf* symbolname) const
+{
+       return os::dlsym(_handle, symbolname->text);
+}
 
-*******************************************************************************/
 
+/**
+ * Add the given native library to the native libraries table.
+ *
+ * @param library Native library to insert.
+ */
 #if defined(ENABLE_DL)
-hashtable_library_name_entry *native_library_find(utf *filename,
-                                                                                                 classloader_t *loader)
+void NativeLibraries::add(NativeLibrary& library)
 {
-       hashtable_library_loader_entry *le;
-       hashtable_library_name_entry   *ne; /* library name                       */
-       u4   key;                           /* hashkey                            */
-       u4   slot;                          /* slot in hashtable                  */
+       // Make the container thread-safe.
+       _mutex.lock();
 
-       /* normally addresses are aligned to 4, 8 or 16 bytes */
+       // XXX Check for double entries.
+       // Insert the native library.
+       _libraries.insert(std::make_pair(library.get_classloader(), library));
 
-       key  = ((u4) (ptrint) loader) >> 4;        /* align to 16-byte boundaries */
-       slot = key & (hashtable_library->size - 1);
-       le   = (hashtable_library_loader_entry*) hashtable_library->ptr[slot];
-
-       /* search external hash chain for the entry */
-
-       while (le) {
-               if (le->loader == loader)
-                       break;
-
-               le = le->hashlink;                  /* next element in external chain */
-       }
-
-       /* no loader found? return NULL */
-
-       if (le == NULL)
-               return NULL;
-
-       /* search for library name */
-
-       ne = le->namelink;
-
-       while (ne) {
-               if (ne->name == filename)
-                       return ne;
-
-               ne = ne->hashlink;                  /* next element in external chain */
-       }
-
-       /* return entry, if no entry was found, ne is NULL */
-
-       return ne;
+       _mutex.unlock();
 }
 #endif
 
 
-/* native_library_load *********************************************************
-
-   Load a native library and initialize it, if possible.
-
-   IN:
-       name ... name of the library
-          cl ..... classloader which loads this library
-
-   RETURN:
-       1 ... library loaded successfully
-       0 ... error
-
-*******************************************************************************/
-
-int native_library_load(JNIEnv *env, utf *name, classloader_t *cl)
+/**
+ * Checks if the given native library is loaded.
+ *
+ * @param library Native library.
+ *
+ * @return true if loaded, false otherwise.
+ */
+bool NativeLibraries::is_loaded(NativeLibrary& library)
 {
-#if defined(ENABLE_DL)
-       void*   handle;
-# if defined(ENABLE_JNI)
-       void*   onload;
-       int32_t version;
-# endif
-
-       if (name == NULL) {
-               exceptions_throw_nullpointerexception();
-               return 0;
-       }
-
-       /* Is the library already loaded? */
-
-       if (native_library_find(name, cl) != NULL)
-               return 1;
-
-       /* Open the library. */
-
-       handle = native_library_open(name);
-
-       if (handle == NULL)
-               return 0;
+       std::pair<MAP::const_iterator, MAP::const_iterator> its = _libraries.equal_range(library.get_classloader());
 
-# if defined(ENABLE_JNI)
-       /* Resolve JNI_OnLoad function. */
+       // No entry for the classloader was found (the range has length
+       // zero).
+       if (its.first == its.second)
+               return false;
+       
+       MAP::const_iterator it = find_if(its.first, its.second, std::bind2nd(comparator(), library.get_filename()));
 
-       onload = os::dlsym(handle, "JNI_OnLoad");
+       // No matching entry in the range found.
+       if (it == its.second)
+               return false;
 
-       if (onload != NULL) {
-               JNIEXPORT int32_t (JNICALL *JNI_OnLoad) (JavaVM *, void *);
-               JavaVM *vm;
+       return true;
+}
 
-               JNI_OnLoad = (JNIEXPORT int32_t (JNICALL *)(JavaVM *, void *)) (ptrint) onload;
 
-               env->GetJavaVM(&vm);
+/**
+ * Try to find a symbol with the given name in all loaded native
+ * libraries defined by classloader.
+ *
+ * @param symbolname  Name of the symbol to find.
+ * @param classloader Defining classloader.
+ *
+ * @return Pointer to symbol if found, NULL otherwise.
+ */
+void* NativeLibraries::resolve_symbol(utf* symbolname, classloader_t* classloader)
+{
+       std::pair<MAP::const_iterator, MAP::const_iterator> its = _libraries.equal_range(classloader);
 
-               version = JNI_OnLoad(vm, NULL);
+       // No entry for the classloader was found (the range has length
+       // zero).
+       if (its.first == its.second)
+               return NULL;
 
-               /* If the version is not 1.2 and not 1.4 the library cannot be
-                  loaded. */
+       for (MAP::const_iterator it = its.first; it != its.second; it++) {
+               const NativeLibrary& library = (*it).second;
+               void* symbol = library.resolve_symbol(symbolname);
 
-               if ((version != JNI_VERSION_1_2) && (version != JNI_VERSION_1_4)) {
-                       os::dlclose(handle);
-                       return 0;
-               }
+               if (symbol != NULL)
+                       return symbol;
        }
-# endif
 
-       /* Insert the library name into the library hash. */
-
-       native_library_add(name, cl, handle);
-
-       return 1;
-#else
-       vm_abort("native_library_load: not available");
-
-       /* Keep compiler happy. */
-
-       return 0;
-#endif
+       return NULL;
 }
 
 
index 19b9f69250b2bdc304b256ffb6c926dd677f8f55..c0b4cdaa4837025d1e0b52ce49bca942a7e046c2 100644 (file)
@@ -2,6 +2,7 @@
 
    Copyright (C) 1996-2005, 2006, 2007, 2008
    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+   Copyright (C) 2008 Theobroma Systems Ltd.
 
    This file is part of CACAO.
 
 
 #include <stdint.h>
 
+#ifdef __cplusplus
+#include <map>
+#include <set>
+#endif
+
 #include "native/jni.hpp"
 
 #include "vm/class.h"
 #endif
 
 
-/* native_methods_node_t ******************************************************/
+#ifdef __cplusplus
+
+#if defined(ENABLE_DL)
+/**
+ * Represents a native library.
+ */
+class NativeLibrary {
+private:
+       utf*           _filename;    ///< Name of the native library.
+       classloader_t* _classloader; ///< Defining classloader.
+       void*          _handle;      ///< Filesystem handle.
+
+public:
+       NativeLibrary(utf* filename, classloader_t* classloader = 0, void* handle = 0) : _filename(filename), _classloader(classloader), _handle(handle) {}
+       NativeLibrary(void* handle) : _filename(0), _classloader(0), _handle(handle) {}
+
+       inline classloader_t* get_classloader() const { return _classloader; }
+       inline utf*           get_filename   () const { return _filename; }
+       inline void*          get_handle     () const { return _handle; }
+
+       void* open();
+       void  close();
+       bool  load(JNIEnv* env);
+       bool  is_loaded();
+       void* resolve_symbol(utf* symbolname) const;
+};
 
-typedef struct native_methods_node_t native_methods_node_t;
 
-struct native_methods_node_t {
-       utf         *classname;             /* class name                         */
-       utf         *name;                  /* method name                        */
-       utf         *descriptor;            /* descriptor name                    */
-       functionptr  function;              /* pointer to the implementation      */
+/**
+ * Table containing all loaded native libraries.
+ */
+class NativeLibraries {
+private:
+       Mutex _mutex; ///< Mutex to make the container thread-safe.
+       typedef std::multimap<classloader_t*, NativeLibrary> MAP;
+       MAP _libraries;
+
+private:
+       // Comparator class.
+       class comparator : public std::binary_function<std::pair<classloader_t*, NativeLibrary>, utf*, bool> {
+       public:
+               bool operator() (std::pair<classloader_t*, NativeLibrary> args, const utf* filename) const
+               {
+                       return (args.second.get_filename() == filename);
+               }
+       };
+
+public:
+       void  add(NativeLibrary& library);
+       bool  is_loaded(NativeLibrary& library);
+       void* resolve_symbol(utf* symbolname, classloader_t* classloader);
 };
+#endif
 
 
-/* hashtable_library_loader_entry *********************************************/
+/**
+ * Represents a native method.
+ */
+class NativeMethod {
+private:
+       utf*  _classname;  ///< Class name.
+       utf*  _name;       ///< Method name.
+       utf*  _descriptor; ///< Method signature.
+       void* _function;   ///< Pointer to the native function.
 
-#if defined(ENABLE_DL)
-typedef struct hashtable_library_loader_entry hashtable_library_loader_entry;
-typedef struct hashtable_library_name_entry   hashtable_library_name_entry;
+       friend bool operator< (const NativeMethod& first, const NativeMethod& second);
 
-struct hashtable_library_loader_entry {
-       classloader_t                  *loader;  /* class loader                  */
-       hashtable_library_name_entry   *namelink;/* libs loaded by this loader    */
-       hashtable_library_loader_entry *hashlink;/* link for external chaining    */
-};
-#endif
+public:
+       NativeMethod(utf* classname, utf* name, utf* signature, void* function) : _classname(classname), _name(name), _descriptor(signature), _function(function) {}
+       NativeMethod(methodinfo* m) : _classname(m->clazz->name), _name(m->name), _descriptor(m->descriptor), _function(0) {}
 
+       inline void* get_function() const { return _function; }
+};
 
-/* hashtable_library_name_entry ***********************************************/
 
-#if defined(ENABLE_DL)
-struct hashtable_library_name_entry {
-       utf                          *name;      /* library name                  */
-       void*                         handle;    /* libtool library handle        */
-       hashtable_library_name_entry *hashlink;  /* link for external chaining    */
+/**
+ * Table containing all native methods registered with the VM.
+ */
+class NativeMethods {
+private:
+       Mutex _mutex;
+       std::set<NativeMethod> _methods;
+
+private:
+       // Comparator class.
+       class comparator : public std::binary_function<std::pair<classloader_t*, NativeLibrary>, utf*, bool> {
+       public:
+               bool operator() (std::pair<classloader_t*, NativeLibrary> args, const utf* filename) const
+               {
+                       return (args.second.get_filename() == filename);
+               }
+       };
+       
+public:
+       void  register_methods(utf* classname, const JNINativeMethod* methods, size_t count);
+       void* resolve_method(methodinfo* m);
+       void* find_registered_method(methodinfo* m);
 };
-#endif
 
+#endif
 
 /* function prototypes ********************************************************/
 
@@ -95,19 +165,6 @@ struct hashtable_library_name_entry {
 extern "C" {
 #endif
 
-bool native_init(void);
-
-void        native_method_register(utf *classname, const JNINativeMethod *methods, int32_t count);
-functionptr native_method_resolve(methodinfo *m);
-
-#if defined(ENABLE_DL)
-void*       native_library_open(utf *filename);
-void        native_library_close(void* handle);
-void        native_library_add(utf *filename, classloader_t *loader, void *handle);
-hashtable_library_name_entry *native_library_find(utf *filename, classloader_t *loader);
-int         native_library_load(JNIEnv *env, utf *name, classloader_t *cl);
-#endif
-
 java_handle_t *native_new_and_init(classinfo *c);
 java_handle_t *native_new_and_init_string(classinfo *c, java_handle_t *s);
 
index 7722a28021c49623c6d4acb0b37c63b3c978913f..3d53b2cbf52e5d11e6f9f20984500dcf315e50f5 100644 (file)
@@ -377,11 +377,10 @@ static JNINativeMethod methods[] = {
  
 void _Jv_com_sun_cldc_io_ResourceInputStream_init(void)
 {
-       utf *u;
+       utf* u = utf_new_char("com/sun/cldc/io/ResourceInputStream");
  
-       u = utf_new_char("com/sun/cldc/io/ResourceInputStream");
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
index 80124b3b27e3c137e06ee0b0eeecd6929cda72cb..9ad7f7c206d258eb6d074778a4b3ea8c0de0998a 100644 (file)
@@ -240,11 +240,10 @@ static JNINativeMethod methods[] = {
  
 void _Jv_com_sun_cldc_io_j2me_socket_Protocol_init(void)
 {
-       utf *u;
+       utf* u = utf_new_char("com/sun/cldc/io/j2me/socket/Protocol");
  
-       u = utf_new_char("com/sun/cldc/io/j2me/socket/Protocol");
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
index 0b00e0d9898e82f01460da1a9cc727fb66a0178b..96aeb015888364b25596d2f66fffe3cc7ff71b08 100644 (file)
@@ -37,6 +37,8 @@
 # include "native/include/com_sun_cldchi_io_ConsoleOutputStream.h"
 #endif
 
+#include "vm/vm.hpp"
+
 
 // Native functions are exported as C functions.
 extern "C" {
@@ -69,11 +71,10 @@ static JNINativeMethod methods[] = {
  
 void _Jv_com_sun_cldchi_io_ConsoleOutputStream_init(void)
 {
-       utf *u;
-       u = utf_new_char("com/sun/cldchi/io/ConsoleOutputStream");
+       utf* u = utf_new_char("com/sun/cldchi/io/ConsoleOutputStream");
  
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
index 229b929112e596801bb2e76b57d1e07b99ee7e18..69acdddbf8c80dd2c68c4e58558039a71e15d2fe 100644 (file)
@@ -36,6 +36,7 @@
 
 #include "vm/exceptions.hpp"
 #include "vm/string.hpp"
+#include "vm/vm.hpp"
 
 
 // Native functions are exported as C functions.
@@ -53,15 +54,14 @@ JNIEXPORT void JNICALL Java_com_sun_cldchi_jvm_JVM_loadLibrary(JNIEnv *env, jcla
                return;
        }
 
-       /* REMOVEME When we use Java-strings internally. */
+       // REMOVEME When we use Java-strings internally.
+       utf* name = javastring_toutf((java_handle_t*) libName, false);
 
-       utf* name = javastring_toutf((java_handle_t *) libName, false);
+       NativeLibrary nl(name);
+       bool result = nl.load(env);
 
-       int result = native_library_load(env, name, NULL);
-
-       /* Check for error and throw an exception in case. */
-
-       if (result == 0) {
+       // Check for error and throw an exception in case.
+       if (result == false) {
                exceptions_throw_unsatisfiedlinkerror(name);
        }
 }
@@ -84,11 +84,10 @@ static JNINativeMethod methods[] = {
  
 void _Jv_com_sun_cldchi_jvm_JVM_init(void)
 {
-       utf *u;
-       u = utf_new_char("com/sun/cldchi/jvm/JVM");
+       utf* u = utf_new_char("com/sun/cldchi/jvm/JVM");
  
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
index 57b5ddaace8508f0a4972b7ef4c2c931534e36f7..a5d928dd78679e21e069443a72633cfc332b1095 100644 (file)
@@ -223,11 +223,10 @@ static JNINativeMethod methods[] = {
 
 void _Jv_java_lang_Class_init(void)
 {
-       utf *u;
+       utf* u = utf_new_char("java/lang/Class");
  
-       u = utf_new_char("java/lang/Class");
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
index de0ee083dbd5667720684ade7e6662d5f3f05c23..6f5f701b3ffe3ba4d10c0ac65d72620635118ee9 100644 (file)
@@ -34,6 +34,8 @@
 # include "native/include/java_lang_Double.h"
 #endif
 
+#include "vm/vm.hpp"
+
 #include "vm/jit/builtin.hpp"
 
 
@@ -107,11 +109,10 @@ static JNINativeMethod methods[] = {
 
 void _Jv_java_lang_Double_init(void)
 {
-       utf *u;
-       u = utf_new_char("java/lang/Double");
+       utf* u = utf_new_char("java/lang/Double");
  
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
index 6a4face1d70703ebcd53d06294428c89b701231b..9d521e2a18c5f23225074b5d29806e498bfe89a3 100644 (file)
@@ -34,6 +34,8 @@
 # include "native/include/java_lang_Float.h"
 #endif
 
+#include "vm/vm.hpp"
+
 #include "vm/jit/builtin.hpp"
 
 
@@ -79,11 +81,10 @@ static JNINativeMethod methods[] = {
 
 void _Jv_java_lang_Float_init(void)
 {
-       utf *u;
-       u = utf_new_char("java/lang/Float");
+       utf* u = utf_new_char("java/lang/Float");
  
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
index b728f783cd4e5f68f308578b506088d9327fb66b..50f2c93360a9f192d921c3e617d85b3d452ec07a 100644 (file)
@@ -36,6 +36,8 @@
 # include "native/include/java_lang_Math.h"
 #endif
 
+#include "vm/vm.hpp"
+
 
 // Native functions are exported as C functions.
 extern "C" {
@@ -128,11 +130,10 @@ static JNINativeMethod methods[] = {
 
 void _Jv_java_lang_Math_init(void)
 {
-       utf *u;
-       u = utf_new_char("java/lang/Math");
+       utf* u = utf_new_char("java/lang/Math");
  
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
index 839dca7444977e009529bdf1cd8e4a8a97553487..ac38a3751ed2a2cf2f4a2b5c34f97c354fb8f352 100644 (file)
@@ -147,11 +147,10 @@ static JNINativeMethod methods[] = {
  
 void _Jv_java_lang_Object_init(void)
 {
-       utf *u;
+       utf* u = utf_new_char("java/lang/Object");
  
-       u = utf_new_char("java/lang/Object");
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
index c7751160563ff7c9fc796b915143bf7b7dd6f3c1..a837bf2865c2c91e8e1c267388419c05755ad2a0 100644 (file)
@@ -107,11 +107,10 @@ static JNINativeMethod methods[] = {
  
 void _Jv_java_lang_Runtime_init(void)
 {
-       utf *u;
-       u = utf_new_char("java/lang/Runtime");
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+       utf* u = utf_new_char("java/lang/Runtime");
+
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
index c9e49c89a40c0ab345c4508bdaeb29e3a96d6e74..b86e539d45c22aa35cd12947f3c0ab84984a0633 100644 (file)
@@ -200,11 +200,10 @@ static JNINativeMethod methods[] = {
  
 void _Jv_java_lang_String_init(void)
 {
-       utf *u;
+       utf* u = utf_new_char("java/lang/String");
  
-       u = utf_new_char("java/lang/String");
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
index 47f3e63b0fbeeb017a2388976efcb72daf10828a..ccc1c0eccc57c92e9d751b0db67fa881eff5e5a0 100644 (file)
@@ -112,11 +112,10 @@ static JNINativeMethod methods[] = {
  
 void _Jv_java_lang_System_init(void)
 {
-       utf *u;
+       utf* u = utf_new_char("java/lang/System");
  
-       u = utf_new_char("java/lang/System");
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
index d7e6750e890f251146e88f2a29fcf7b37cafbf6d..99a7393a06f78562a9a4d75d263a9600a63560f7 100644 (file)
@@ -201,11 +201,10 @@ static JNINativeMethod methods[] = {
  
 void _Jv_java_lang_Thread_init(void)
 {
-       utf *u;
+       utf* u = utf_new_char("java/lang/Thread");
  
-       u = utf_new_char("java/lang/Thread");
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
index 8385cf9b41e7c8a95521c1a931a18cc9ad68c8ca..f5d566ea574bf47e299a24065d99c7d2629b33aa 100644 (file)
@@ -94,11 +94,10 @@ static JNINativeMethod methods[] = {
  
 void _Jv_java_lang_Throwable_init(void)
 {
-       utf *u;
+       utf* u = utf_new_char("java/lang/Throwable");
  
-       u = utf_new_char("java/lang/Throwable");
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
index ac09c220cd3fd211b51f3836ff0ad56d1d44c3cf..3834360261ad7325c172ead60d39634baa29705a 100644 (file)
@@ -126,11 +126,10 @@ static JNINativeMethod methods[] = {
 
 void _Jv_gnu_classpath_VMStackWalker_init(void)
 {
-       utf *u;
+       utf* u = utf_new_char("gnu/classpath/VMStackWalker");
 
-       u = utf_new_char("gnu/classpath/VMStackWalker");
-
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
index 25b7d7967ca567c50c703e4122ee67ae551df8d8..0789c0eda8d96a7a61fb1c31e31e32ab9a86c337 100644 (file)
@@ -136,11 +136,10 @@ static JNINativeMethod methods[] = {
 
 void _Jv_gnu_classpath_VMSystemProperties_init(void)
 {
-       utf *u;
+       utf* u = utf_new_char("gnu/classpath/VMSystemProperties");
 
-       u = utf_new_char("gnu/classpath/VMSystemProperties");
-
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
index d414ee26953a1db00598e1305b0dd48f927da4b2..c0b34194224d2ec9d1ca69d1f0cc0a39e054b6fc 100644 (file)
@@ -103,11 +103,10 @@ static JNINativeMethod methods[] = {
 
 void _Jv_gnu_java_lang_VMCPStringBuilder_init(void)
 {
-       utf *u;
+       utf* u = utf_new_char("gnu/java/lang/VMCPStringBuilder");
 
-       u = utf_new_char("gnu/java/lang/VMCPStringBuilder");
-
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
index 80fd5654c8102c8599800b92ba70722d59101edd..069b7dffe4c0882dbc3f562f0cf4afdb58171788 100644 (file)
@@ -121,11 +121,10 @@ static JNINativeMethod methods[] = {
 
 void _Jv_gnu_java_lang_management_VMClassLoadingMXBeanImpl_init(void)
 {
-       utf *u;
+       utf* u = utf_new_char("gnu/java/lang/management/VMClassLoadingMXBeanImpl");
 
-       u = utf_new_char("gnu/java/lang/management/VMClassLoadingMXBeanImpl");
-
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
index 221b0fd1249df371a5d0d568f7cace8555f7f1bc..6ad098df7966b09fb737457aed0aef86a9f787e8 100644 (file)
@@ -175,11 +175,10 @@ static JNINativeMethod methods[] = {
 
 void _Jv_gnu_java_lang_management_VMMemoryMXBeanImpl_init(void)
 {
-       utf *u;
+       utf* u = utf_new_char("gnu/java/lang/management/VMMemoryMXBeanImpl");
 
-       u = utf_new_char("gnu/java/lang/management/VMMemoryMXBeanImpl");
-
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
index b469172b459889ef1dfd2b6e8d6c208e49648037..c17382a54fc729faca297936393680a2bd4f5e11 100644 (file)
@@ -86,11 +86,10 @@ static JNINativeMethod methods[] = {
 
 void _Jv_gnu_java_lang_management_VMRuntimeMXBeanImpl_init(void)
 {
-       utf *u;
+       utf* u = utf_new_char("gnu/java/lang/management/VMRuntimeMXBeanImpl");
 
-       u = utf_new_char("gnu/java/lang/management/VMRuntimeMXBeanImpl");
-
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
index 19ce5197ab5c3f523b977798c00f6e6cae6de981..0ad83bcde2b47390b6d148c00a0008c671e1d7b2 100644 (file)
@@ -191,11 +191,10 @@ static JNINativeMethod methods[] = {
 
 void _Jv_gnu_java_lang_management_VMThreadMXBeanImpl_init(void)
 {
-       utf *u;
+       utf* u = utf_new_char("gnu/java/lang/management/VMThreadMXBeanImpl");
 
-       u = utf_new_char("gnu/java/lang/management/VMThreadMXBeanImpl");
-
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
index 998b8c41b17a27ca6a97d3243b8dfccff35fcff9..5e2136aa53ab47da8d4ffc0ab6459128f3f34556 100644 (file)
@@ -617,11 +617,10 @@ static JNINativeMethod methods[] = {
 
 void _Jv_java_lang_VMClass_init(void)
 {
-       utf *u;
+       utf* u = utf_new_char("java/lang/VMClass");
 
-       u = utf_new_char("java/lang/VMClass");
-
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
index 60a0083d9d06995b1f49a1ce17e9ee28d8db30e0..926d825f8c16e117562e5d4b38ab60fbb6e3bed0 100644 (file)
@@ -599,11 +599,10 @@ static JNINativeMethod methods[] = {
 
 void _Jv_java_lang_VMClassLoader_init(void)
 {
-       utf *u;
+       utf* u = utf_new_char("java/lang/VMClassLoader");
 
-       u = utf_new_char("java/lang/VMClassLoader");
-
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
index c80de0ecf98de5c73a83eb60a410c683700da6ac..769d1a071f9390dd00bc4aec1c55734bc54db02d 100644 (file)
@@ -146,11 +146,10 @@ static JNINativeMethod methods[] = {
 
 void _Jv_java_lang_VMObject_init(void)
 {
-       utf *u;
+       utf* u = utf_new_char("java/lang/VMObject");
 
-       u = utf_new_char("java/lang/VMObject");
-
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
index c26433d7fa3cb512eb0db41b121b2641f3d34330..93b8833f1335bd0aa0ec2609993f643b27353790 100644 (file)
@@ -203,10 +203,7 @@ JNIEXPORT jint JNICALL Java_java_lang_VMRuntime_availableProcessors(JNIEnv *env,
  */
 JNIEXPORT jint JNICALL Java_java_lang_VMRuntime_nativeLoad(JNIEnv *env, jclass clazz, jstring libname, jobject loader)
 {
-       classloader_t *cl;
-       utf           *name;
-
-       cl = loader_hashtable_classloader_add((java_handle_t *) loader);
+       classloader_t* cl = loader_hashtable_classloader_add((java_handle_t *) loader);
 
        /* REMOVEME When we use Java-strings internally. */
 
@@ -215,9 +212,10 @@ JNIEXPORT jint JNICALL Java_java_lang_VMRuntime_nativeLoad(JNIEnv *env, jclass c
                return 0;
        }
 
-       name = javastring_toutf((java_handle_t *) libname, false);
+       utf* name = javastring_toutf((java_handle_t *) libname, false);
 
-       return native_library_load(env, name, cl);
+       NativeLibrary library(name, cl);
+       return library.load(env);
 }
 
 
@@ -295,11 +293,10 @@ static JNINativeMethod methods[] = {
 
 void _Jv_java_lang_VMRuntime_init(void)
 {
-       utf *u;
-
-       u = utf_new_char("java/lang/VMRuntime");
+       utf* u = utf_new_char("java/lang/VMRuntime");
 
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
index 7660a38e3ea344462c9ef9ee21f7af64e8475abf..9579db252c8271851742b547540a6170ccf5cd2c 100644 (file)
@@ -36,6 +36,7 @@
 #endif
 
 #include "vm/string.hpp"
+#include "vm/vm.hpp"
 
 
 // Native functions are exported as C functions.
@@ -72,11 +73,10 @@ static JNINativeMethod methods[] = {
 
 void _Jv_java_lang_VMString_init(void)
 {
-       utf *u;
+       utf* u = utf_new_char("java/lang/VMString");
 
-       u = utf_new_char("java/lang/VMString");
-
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
index 640dfd60e9418c2538a3ad213c81deeefc9e68de..e5b3e95303fc5b2fc78ab54a5d7225fdf0adf8a7 100644 (file)
@@ -88,11 +88,10 @@ static JNINativeMethod methods[] = {
 
 void _Jv_java_lang_VMSystem_init(void)
 {
-       utf *u;
+       utf* u = utf_new_char("java/lang/VMSystem");
 
-       u = utf_new_char("java/lang/VMSystem");
-
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
index 76aaaf81d766d4a81a9d749a4ca572b741bb92c7..da3eccb25488ba8f6f45dc8d81798a7ac3184940 100644 (file)
@@ -348,11 +348,10 @@ static JNINativeMethod methods[] = {
 
 void _Jv_java_lang_VMThread_init(void)
 {
-       utf *u;
+       utf* u = utf_new_char("java/lang/VMThread");
 
-       u = utf_new_char("java/lang/VMThread");
-
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
index 36dfaa3156542a37ba575aec5e633bfd2d8b0a77..d62fe2926d48200e96df73bfec11f287184ebfc6 100644 (file)
@@ -182,11 +182,10 @@ static JNINativeMethod methods[] = {
 
 void _Jv_java_lang_VMThrowable_init(void)
 {
-       utf *u;
+       utf* u = utf_new_char("java/lang/VMThrowable");
 
-       u = utf_new_char("java/lang/VMThrowable");
-
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
index 9d91b0c3db04f7ef2613082a7ff7a65211f581f8..10f450dd13daffeca9c4bed8dab1571ebbb335e0 100644 (file)
 
 #include "toolbox/logging.h"
 
-#include "vm/jit/builtin.hpp"
 #include "vm/globals.hpp"
+#include "vm/vm.hpp"
+
+#include "vm/jit/builtin.hpp"
 
 
 // Native functions are exported as C functions.
@@ -115,11 +117,10 @@ static JNINativeMethod methods[] = {
 
 void _Jv_java_lang_management_VMManagementFactory_init(void)
 {
-       utf *u;
-
-       u = utf_new_char("java/lang/management/VMManagementFactory");
+       utf* u = utf_new_char("java/lang/management/VMManagementFactory");
 
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
index 42664496f019d7d4e3d140d674d29bd669b3bc85..3a302b3fd4cad2ad6b05768792be4bdf2df38a25 100644 (file)
@@ -206,11 +206,10 @@ static JNINativeMethod methods[] = {
 
 void _Jv_java_lang_reflect_VMConstructor_init(void)
 {
-       utf *u;
+       utf* u = utf_new_char("java/lang/reflect/VMConstructor");
 
-       u = utf_new_char("java/lang/reflect/VMConstructor");
-
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
index fe8fbb77e19cb9f6e20107a976ea831a6ed0d16d..0d49fa0a3ea24b3e08e5c6bacdfdacf03189dc90 100644 (file)
@@ -1113,11 +1113,10 @@ static const JNINativeMethod methods[] = {
 
 void _Jv_java_lang_reflect_VMField_init(void)
 {
-       utf *u;
+       utf* u = utf_new_char("java/lang/reflect/VMField");
 
-       u = utf_new_char("java/lang/reflect/VMField");
-
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
index e89f28af4d3cf47c72f59474d19b88561d6f3fb9..c569915f28f61579d3912c69b574a68ee8a6dd13 100644 (file)
@@ -287,11 +287,10 @@ static JNINativeMethod methods[] = {
 
 void _Jv_java_lang_reflect_VMMethod_init(void)
 {
-       utf *u;
+       utf* u = utf_new_char("java/lang/reflect/VMMethod");
 
-       u = utf_new_char("java/lang/reflect/VMMethod");
-
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
index 0e6c17ff61ea4a19df960428684178c906c1e9b4..89977192987bbf42d61083a7dd87af3d40db4e58 100644 (file)
@@ -71,11 +71,10 @@ static JNINativeMethod methods[] = {
 
 void _Jv_java_security_VMAccessController_init(void)
 {
-       utf *u;
+       utf* u = utf_new_char("java/security/VMAccessController");
 
-       u = utf_new_char("java/security/VMAccessController");
-
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
index a17a853653f0c675be465baf6f7778946f9e5e22..8ee6b74ca3831c41563f018e656c8733281eb1a1 100644 (file)
@@ -35,6 +35,7 @@
 #endif
 
 #include "vm/utf8.h"
+#include "vm/vm.hpp"
 
 
 // Native functions are exported as C functions.
@@ -69,11 +70,10 @@ static JNINativeMethod methods[] = {
 
 void _Jv_java_util_concurrent_atomic_AtomicLong_init(void)
 {
-       utf *u;
+       utf* u = utf_new_char("java/util/concurrent/atomic/AtomicLong");
 
-       u = utf_new_char("java/util/concurrent/atomic/AtomicLong");
-
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
index 13c274b1ade06a0a765b38411fe077ebb992fa25..418fb50f92687c38540ae3af5f540dd6159e1d7a 100644 (file)
@@ -418,7 +418,10 @@ static JNINativeMethod methods[] = {
 
 void _Jv_sun_reflect_ConstantPool_init(void)
 {
-       native_method_register(utf_new_char("sun/reflect/ConstantPool"), methods, NATIVE_METHODS_COUNT);
+       utf* u = utf_new_char("sun/reflect/ConstantPool");
+
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
index 54db83e314f44d17556e9b689a1affd0ff1d5d1b..43973647335608e4c80f7f61d4e416099e40f1bc 100644 (file)
@@ -111,14 +111,16 @@ void nativevm_preinit(void)
 
        utf* u = utf_new_char(p);
 
-       void* handle = native_library_open(u);
+       NativeLibrary nl(u);
+       void* handle = nl.open();
 
        if (handle == NULL)
-               vm_abort("nativevm_init: failed to open libjava.so at: %s", p);
+               os::abort("nativevm_init: failed to open libjava.so at: %s", p);
 
        MFREE(p, char, len);
 
-       native_library_add(u, NULL, handle);
+       NativeLibraries& nls = vm->get_nativelibraries();
+       nls.add(nl);
 
        // Initialize the HPI.
        HPI& hpi = vm->get_hpi();
index 0c283c9567a44b6a922cd9f340b0e258d0893f1a..ad6eec544c960f81079d65585f4c44d0bd157fab 100644 (file)
@@ -68,7 +68,8 @@ void HPI::initialize() // REMOVEME
        TRACESUBSYSTEMINITIALIZATION("hpi_init");
 
        // Load libhpi.so
-       Properties& properties = VM::get_current()->get_properties();
+       VM* vm = VM::get_current();
+       Properties& properties = vm->get_properties();
        const char* boot_library_path = properties.get("sun.boot.library.path");
 
        size_t len =
@@ -88,7 +89,8 @@ void HPI::initialize() // REMOVEME
 
        MFREE(p, char, len);
 
-       void* handle = native_library_open(u);
+       NativeLibrary nl(u);
+       void* handle = nl.open();
 
        if (handle == NULL)
                if (opt_TraceHPI)
@@ -108,7 +110,8 @@ void HPI::initialize() // REMOVEME
                        vm_abort("hpi_init: HPI DLL_Initialize failed");
     }
 
-       native_library_add(u, NULL, handle);
+       NativeLibraries& nls = vm->get_nativelibraries();
+       nls.add(nl);
 
     if (opt_TraceHPI)
                log_println("HPI::initialize: HPI loaded successfully");
index e258f36b526d3955ea10ca84351f2ea2c768ee60..d23997e8144bc1e0c7a96ffa9635b3471d901fa3 100644 (file)
@@ -2897,17 +2897,15 @@ struct protoent *JVM_GetProtoByName(char* name)
 
 /* JVM_LoadLibrary */
 
-void *JVM_LoadLibrary(const char *name)
+void* JVM_LoadLibrary(const char* name)
 {
-       utf*  u;
-       void* handle;
-
        TRACEJVMCALLSENTER(("JVM_LoadLibrary(name=%s)", name));
 
-       u = utf_new_char(name);
-
-       handle = native_library_open(u);
+       utf* u = utf_new_char(name);
 
+       NativeLibrary nl(u);
+       void* handle = nl.open();
+       
        TRACEJVMCALLSEXIT(("->%p", handle));
 
        return handle;
@@ -2920,7 +2918,8 @@ void JVM_UnloadLibrary(void* handle)
 {
        TRACEJVMCALLS(("JVM_UnloadLibrary(handle=%p)", handle));
 
-       native_library_close(handle);
+       NativeLibrary nl(handle);
+       nl.close();
 }
 
 
index 95fcef7bbc8a67b697cc980d0d81af07b7d52274..6c7dc69772954680e1aafd6c0db399803e88c37f 100644 (file)
@@ -1155,11 +1155,10 @@ static JNINativeMethod methods[] = {
 
 void _Jv_sun_misc_Unsafe_init(void)
 {
-       utf *u;
+       utf* u = utf_new_char("sun/misc/Unsafe");
 
-       u = utf_new_char("sun/misc/Unsafe");
-
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }
 
 
index 6852a963303b3bc177b118407ca0da0584d8aa50..3921fbab1328ff393b175f742a103b9d0a31287c 100644 (file)
@@ -569,17 +569,15 @@ static u1 *jit_compile_intern(jitdata *jd)
        show_filters_apply(jd->m);
 #endif
 
-       /* Handle native methods and create a native stub. */
-
+       // Handle native methods and create a native stub.
        if (m->flags & ACC_NATIVE) {
-               functionptr f;
-
-               f = native_method_resolve(m);
+               NativeMethods& nm = VM::get_current()->get_nativemethods();
+               void* f = nm.resolve_method(m);
 
                if (f == NULL)
                        return NULL;
 
-               code = NativeStub::generate(m, f);
+               code = NativeStub::generate(m, (functionptr) f);
 
                /* Native methods are never recompiled. */
                
index 737631c9acb8370550fde1c4b1e6a590fad49c39..1b874b053c2387dbe3fe79fefbd09448cb2f1f2c 100644 (file)
@@ -474,7 +474,6 @@ bool patcher_resolve_native_function(patchref_t *pr)
 {
        methodinfo  *m;
        uint8_t     *datap;
-       functionptr  f;
 
        /* get stuff from the patcher reference */
 
@@ -483,12 +482,15 @@ bool patcher_resolve_native_function(patchref_t *pr)
 
        /* resolve native function */
 
-       if (!(f = native_method_resolve(m)))
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       void* f = nm.resolve_method(m);
+
+       if (f == NULL)
                return false;
 
        /* patch native function pointer */
 
-       *((intptr_t *) datap) = (intptr_t) f;
+       *((intptr_t*) datap) = (intptr_t) f;
 
        /* synchronize data cache */
 
index 30e8d3bfcc6f7a3bf7986a4f9c74d2d49041ca67..213cb2f6c73303da7a65d4255010f46602143bfe 100644 (file)
@@ -1435,12 +1435,6 @@ VM::VM(JavaVMInitArgs* vm_args)
        if (!builtin_init())
                os::abort("vm_create: builtin_init failed");
 
-       /* Initialize the native subsystem. */
-       /* BEFORE: threads_init */
-
-       if (!native_init())
-               os::abort("vm_create: native_init failed");
-
        /* Register the native methods implemented in the VM. */
        /* BEFORE: threads_init */
 
index e09f3a518fed381a4d44028bf2f8d5dafbd8c05c..6e3d54d37c09e765d89ec7ba476d451dce388b3a 100644 (file)
@@ -33,6 +33,7 @@
 
 // We need the JNI types for the VM class.
 #include "native/jni.hpp"
+#include "native/native.hpp"
 
 #if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
 # include "native/vm/openjdk/hpi.hpp"
@@ -65,14 +66,16 @@ private:
        int64_t _starttime;
 
        // Subsystems.
-       Properties _properties; ///< Commandline properties.
+       Properties      _properties;      ///< Commandline properties.
 #if defined(ENABLE_THREADS)
-       Recompiler _recompiler; ///< JIT recompilation framework.
+       Recompiler      _recompiler;      ///< JIT recompilation framework.
 #endif
 #if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
-       HPI        _hpi;
-       Management _management;
+       HPI             _hpi;             ///< Host Porting Interface.
+       Management      _management;      ///< Java management interface.
 #endif
+       NativeLibraries _nativelibraries; ///< Native library table.
+       NativeMethods   _nativemethods;   ///< Native methods table.
 
 public:
        // Constructor, Destructor.
@@ -94,12 +97,14 @@ public:
        bool    is_exiting()      { return _exiting; }
        int64_t get_starttime()   { return _starttime; }
 
-       Properties& get_properties() { return _properties; }
-       Recompiler& get_recompiler() { return _recompiler; } // REMOVEME
+       Properties&      get_properties     () { return _properties; }
+       Recompiler&      get_recompiler     () { return _recompiler; } // REMOVEME
 #if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
-       HPI&        get_hpi       () { return _hpi; }
-       Management& get_management() { return _management; }
+       HPI&             get_hpi            () { return _hpi; }
+       Management&      get_management     () { return _management; }
 #endif
+       NativeLibraries& get_nativelibraries() { return _nativelibraries; }
+       NativeMethods&   get_nativemethods  () { return _nativemethods; }
 };
 
 #else