src/native/vm/nativevm.c
author Christian Thalinger <twisti@complang.tuwien.ac.at>
Tue, 08 Jul 2008 16:36:33 +0200
branchcacao-1.0.x
changeset 8416 05da71d55c67
parent 8181 1c0d84d8f0dc
child 8459 3dc10fb941c7
permissions -rw-r--r--
* ChangeLog: Updated.
     1 /* src/native/vm/nativevm.c - register the native functions
     2 
     3    Copyright (C) 2007, 2008
     4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
     5 
     6    This file is part of CACAO.
     7 
     8    This program is free software; you can redistribute it and/or
     9    modify it under the terms of the GNU General Public License as
    10    published by the Free Software Foundation; either version 2, or (at
    11    your option) any later version.
    12 
    13    This program is distributed in the hope that it will be useful, but
    14    WITHOUT ANY WARRANTY; without even the implied warranty of
    15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    16    General Public License for more details.
    17 
    18    You should have received a copy of the GNU General Public License
    19    along with this program; if not, write to the Free Software
    20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    21    02110-1301, USA.
    22 
    23 */
    24 
    25 
    26 #include "config.h"
    27 
    28 #include <stdint.h>
    29 
    30 #include "native/vm/nativevm.h"
    31 
    32 #include "vm/initialize.h"
    33 
    34 #include "vmcore/class.h"
    35 #include "vmcore/method.h"
    36 #include "vmcore/options.h"
    37 #include "vmcore/system.h"
    38 
    39 #if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
    40 # include "mm/memory.h"
    41 
    42 # include "native/native.h"
    43 
    44 # include "native/vm/openjdk/hpi.h"
    45 
    46 # include "vm/properties.h"
    47 # include "vm/vm.h"
    48 
    49 # include "vmcore/utf8.h"
    50 #endif
    51 
    52 
    53 /* nativevm_preinit ************************************************************
    54 
    55    Pre-initialize the implementation specific native stuff.
    56 
    57 *******************************************************************************/
    58 
    59 void nativevm_preinit(void)
    60 {
    61 	/* Register native methods of all classes implemented. */
    62 
    63 #if defined(ENABLE_JAVASE)
    64 # if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
    65 
    66 	TRACESUBSYSTEMINITIALIZATION("nativevm_preinit");
    67 
    68 	_Jv_gnu_classpath_VMStackWalker_init();
    69 	_Jv_gnu_classpath_VMSystemProperties_init();
    70 	_Jv_gnu_java_lang_VMCPStringBuilder_init();
    71 	_Jv_gnu_java_lang_management_VMClassLoadingMXBeanImpl_init();
    72 	_Jv_gnu_java_lang_management_VMMemoryMXBeanImpl_init();
    73 	_Jv_gnu_java_lang_management_VMRuntimeMXBeanImpl_init();
    74 	_Jv_gnu_java_lang_management_VMThreadMXBeanImpl_init();
    75 	_Jv_java_lang_VMClass_init();
    76 	_Jv_java_lang_VMClassLoader_init();
    77 	_Jv_java_lang_VMObject_init();
    78 	_Jv_java_lang_VMRuntime_init();
    79 	_Jv_java_lang_VMSystem_init();
    80 	_Jv_java_lang_VMString_init();
    81 	_Jv_java_lang_VMThread_init();
    82 	_Jv_java_lang_VMThrowable_init();
    83 	_Jv_java_lang_management_VMManagementFactory_init();
    84 	_Jv_java_lang_reflect_VMConstructor_init();
    85 	_Jv_java_lang_reflect_VMField_init();
    86 	_Jv_java_lang_reflect_VMMethod_init();
    87 	_Jv_java_lang_reflect_VMProxy_init();
    88 	_Jv_java_security_VMAccessController_init();
    89 	_Jv_java_util_concurrent_atomic_AtomicLong_init();
    90 	_Jv_sun_misc_Unsafe_init();
    91 
    92 #if defined(ENABLE_ANNOTATIONS)
    93 	_Jv_sun_reflect_ConstantPool_init();
    94 #endif
    95 
    96 # elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
    97 
    98 	char* boot_library_path;
    99 	int   len;
   100 	char* p;
   101 	utf*  u;
   102 	void* handle;
   103 
   104 	TRACESUBSYSTEMINITIALIZATION("nativevm_preinit");
   105 
   106 	/* Load libjava.so */
   107 
   108 	boot_library_path = properties_get("sun.boot.library.path");
   109 
   110 	len =
   111 		system_strlen(boot_library_path) +
   112 		system_strlen("/libjava.so") +
   113 		system_strlen("0");
   114 
   115 	p = MNEW(char, len);
   116 
   117 	system_strcpy(p, boot_library_path);
   118 	system_strcat(p, "/libjava.so");
   119 
   120 	u = utf_new_char(p);
   121 
   122 	handle = native_library_open(u);
   123 
   124 	if (handle == NULL)
   125 		vm_abort("nativevm_init: failed to open libjava.so at: %s", p);
   126 
   127 	MFREE(p, char, len);
   128 
   129 	native_library_add(u, NULL, handle);
   130 
   131 	/* Initialize the HPI. */
   132 
   133 	hpi_initialize();
   134 
   135 	_Jv_sun_misc_Unsafe_init();
   136 
   137 # else
   138 #  error unknown classpath configuration
   139 # endif
   140 
   141 #elif defined(ENABLE_JAVAME_CLDC1_1)
   142 
   143 	TRACESUBSYSTEMINITIALIZATION("nativevm_preinit");
   144 
   145 	_Jv_com_sun_cldc_io_ResourceInputStream_init();
   146 	_Jv_com_sun_cldc_io_j2me_socket_Protocol_init();
   147 	_Jv_com_sun_cldchi_io_ConsoleOutputStream_init();
   148 	_Jv_com_sun_cldchi_jvm_JVM_init();
   149 	_Jv_java_lang_Class_init();
   150 	_Jv_java_lang_Double_init();
   151 	_Jv_java_lang_Float_init();
   152 	_Jv_java_lang_Math_init();
   153 	_Jv_java_lang_Object_init();
   154 	_Jv_java_lang_Runtime_init();
   155 	_Jv_java_lang_String_init();
   156 	_Jv_java_lang_System_init();
   157 	_Jv_java_lang_Thread_init();
   158 	_Jv_java_lang_Throwable_init();
   159 
   160 #else
   161 # error unknown Java configuration
   162 #endif
   163 }
   164 
   165 
   166 /* nativevm_init ***************************************************************
   167 
   168    Initialize the implementation specific native stuff.
   169 
   170 *******************************************************************************/
   171 
   172 void nativevm_init(void)
   173 {
   174 #if defined(ENABLE_JAVASE)
   175 
   176 # if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
   177 
   178 	TRACESUBSYSTEMINITIALIZATION("nativevm_init");
   179 
   180 	/* nothing to do */
   181 
   182 # elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
   183 
   184 	methodinfo *m;
   185 
   186 	TRACESUBSYSTEMINITIALIZATION("nativevm_init");
   187 
   188 	m = class_resolveclassmethod(class_java_lang_System,
   189 								 utf_new_char("initializeSystemClass"),
   190 								 utf_void__void,
   191 								 class_java_lang_Object,
   192 								 false);
   193 
   194 	if (m == NULL)
   195 		vm_abort("nativevm_init: Error resolving java.lang.System.initializeSystemClass()");
   196 
   197 	(void) vm_call_method(m, NULL);
   198 
   199 # else
   200 #  error unknown classpath configuration
   201 # endif
   202 
   203 #elif defined(ENABLE_JAVAME_CLDC1_1)
   204 
   205 	TRACESUBSYSTEMINITIALIZATION("nativevm_init");
   206 
   207 	/* nothing to do */
   208 
   209 #else
   210 # error unknown Java configuration
   211 #endif
   212 }
   213 
   214 
   215 /*
   216  * These are local overrides for various environment variables in Emacs.
   217  * Please do not remove this and leave it at the end of the file, where
   218  * Emacs will automagically detect them.
   219  * ---------------------------------------------------------------------
   220  * Local variables:
   221  * mode: c
   222  * indent-tabs-mode: t
   223  * c-basic-offset: 4
   224  * tab-width: 4
   225  * End:
   226  */