Merged with tip.
[cacao.git] / src / native / vm / nativevm.c
index fdf4aa0635270d44d4ca1d0673560c8056d644b5..defffab17908eda060fc92871961545796a169b0 100644 (file)
@@ -1,9 +1,7 @@
 /* src/native/vm/nativevm.c - register the native functions
 
-   Copyright (C) 2007 R. Grafl, A. Krall, C. Kruegel,
-   C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
-   E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
-   J. Wenninger, Institut f. Computersprachen - TU Wien
+   Copyright (C) 2007, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
 
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: native.c 7906 2007-05-14 17:25:33Z twisti $
-
 */
 
 
 #include "config.h"
-#include "vm/types.h"
+
+#include <stdint.h>
 
 #include "native/vm/nativevm.h"
 
+#include "vm/initialize.h"
+
+#include "vmcore/class.h"
 #include "vmcore/method.h"
+#include "vmcore/options.h"
+#include "vmcore/system.h"
+
+#if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
+# include "mm/memory.h"
 
-#if defined(WITH_CLASSPATH_SUN)
 # include "native/native.h"
 
+# include "native/vm/openjdk/hpi.h"
+
+# include "vm/properties.h"
 # include "vm/vm.h"
 
-# include "vmcore/class.h"
 # include "vmcore/utf8.h"
 #endif
 
 
 *******************************************************************************/
 
-bool nativevm_preinit(void)
+void nativevm_preinit(void)
 {
-       /* register native methods of all classes implemented */
+       /* Register native methods of all classes implemented. */
 
 #if defined(ENABLE_JAVASE)
+# if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
 
-# if defined(WITH_CLASSPATH_GNU)
+       TRACESUBSYSTEMINITIALIZATION("nativevm_preinit");
 
        _Jv_gnu_classpath_VMStackWalker_init();
        _Jv_gnu_classpath_VMSystemProperties_init();
+       _Jv_gnu_java_lang_VMCPStringBuilder_init();
        _Jv_gnu_java_lang_management_VMClassLoadingMXBeanImpl_init();
        _Jv_gnu_java_lang_management_VMMemoryMXBeanImpl_init();
        _Jv_gnu_java_lang_management_VMRuntimeMXBeanImpl_init();
@@ -73,34 +81,67 @@ bool nativevm_preinit(void)
        _Jv_java_lang_VMThread_init();
        _Jv_java_lang_VMThrowable_init();
        _Jv_java_lang_management_VMManagementFactory_init();
-       _Jv_java_lang_reflect_Constructor_init();
-       _Jv_java_lang_reflect_Field_init();
-       _Jv_java_lang_reflect_Method_init();
+       _Jv_java_lang_reflect_VMConstructor_init();
+       _Jv_java_lang_reflect_VMField_init();
+       _Jv_java_lang_reflect_VMMethod_init();
        _Jv_java_lang_reflect_VMProxy_init();
        _Jv_java_security_VMAccessController_init();
        _Jv_java_util_concurrent_atomic_AtomicLong_init();
        _Jv_sun_misc_Unsafe_init();
 
-# elif defined(WITH_CLASSPATH_SUN)
+#if defined(ENABLE_ANNOTATIONS)
+       _Jv_sun_reflect_ConstantPool_init();
+#endif
+
+# elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
+
+       char* boot_library_path;
+       int   len;
+       char* p;
+       utf*  u;
+       void* handle;
+
+       TRACESUBSYSTEMINITIALIZATION("nativevm_preinit");
 
-       utf         *u;
-       lt_dlhandle  handle;
+       /* Load libjava.so */
 
-       u = utf_new_char(CLASSPATH_LIBDIR"/libjava.so");
+       boot_library_path = properties_get("sun.boot.library.path");
+
+       len =
+               system_strlen(boot_library_path) +
+               system_strlen("/libjava.so") +
+               system_strlen("0");
+
+       p = MNEW(char, len);
+
+       system_strcpy(p, boot_library_path);
+       system_strcat(p, "/libjava.so");
+
+       u = utf_new_char(p);
 
        handle = native_library_open(u);
+
+       if (handle == NULL)
+               vm_abort("nativevm_init: failed to open libjava.so at: %s", p);
+
+       MFREE(p, char, len);
+
        native_library_add(u, NULL, handle);
 
+       /* Initialize the HPI. */
+
+       hpi_initialize();
+
        _Jv_sun_misc_Unsafe_init();
 
 # else
-
 #  error unknown classpath configuration
-
 # endif
 
 #elif defined(ENABLE_JAVAME_CLDC1_1)
 
+       TRACESUBSYSTEMINITIALIZATION("nativevm_preinit");
+
        _Jv_com_sun_cldc_io_ResourceInputStream_init();
        _Jv_com_sun_cldc_io_j2me_socket_Protocol_init();
        _Jv_com_sun_cldchi_io_ConsoleOutputStream_init();
@@ -117,14 +158,8 @@ bool nativevm_preinit(void)
        _Jv_java_lang_Throwable_init();
 
 #else
-
 # error unknown Java configuration
-
 #endif
-
-       /* everything's ok */
-
-       return true;
 }
 
 
@@ -134,18 +169,22 @@ bool nativevm_preinit(void)
 
 *******************************************************************************/
 
-bool nativevm_init(void)
+void nativevm_init(void)
 {
 #if defined(ENABLE_JAVASE)
 
-# if defined(WITH_CLASSPATH_GNU)
+# if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
+
+       TRACESUBSYSTEMINITIALIZATION("nativevm_init");
 
        /* nothing to do */
 
-# elif defined(WITH_CLASSPATH_SUN)
+# elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
 
        methodinfo *m;
 
+       TRACESUBSYSTEMINITIALIZATION("nativevm_init");
+
        m = class_resolveclassmethod(class_java_lang_System,
                                                                 utf_new_char("initializeSystemClass"),
                                                                 utf_void__void,
@@ -153,29 +192,23 @@ bool nativevm_init(void)
                                                                 false);
 
        if (m == NULL)
-               return false;
+               vm_abort("nativevm_init: Error resolving java.lang.System.initializeSystemClass()");
 
        (void) vm_call_method(m, NULL);
 
 # else
-
 #  error unknown classpath configuration
-
 # endif
 
 #elif defined(ENABLE_JAVAME_CLDC1_1)
 
+       TRACESUBSYSTEMINITIALIZATION("nativevm_init");
+
        /* nothing to do */
 
 #else
-
 # error unknown Java configuration
-
 #endif
-
-       /* everything's ok */
-
-       return true;
 }