Line data Source code
1 : /* src/native/vm/nativevm.cpp - Register native VM interface functions.
2 :
3 : Copyright (C) 1996-2013
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 "native/vm/nativevm.hpp"
29 :
30 : #include "toolbox/logging.hpp"
31 :
32 : #include "vm/class.hpp"
33 : #include "vm/exceptions.hpp"
34 : #include "vm/initialize.hpp"
35 : #include "vm/options.hpp"
36 : #include "vm/os.hpp"
37 : #include "vm/jit/builtin.hpp"
38 :
39 : #if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
40 : # include "native/native.hpp"
41 :
42 : #ifndef WITH_JAVA_RUNTIME_LIBRARY_OPENJDK_7
43 : # include "native/vm/openjdk/hpi.hpp"
44 : #endif
45 :
46 : # include "toolbox/buffer.hpp"
47 :
48 : # include "vm/globals.hpp"
49 : # include "vm/properties.hpp"
50 : # include "vm/utf8.hpp"
51 : # include "vm/vm.hpp"
52 : #endif
53 :
54 :
55 : /* nativevm_preinit ************************************************************
56 :
57 : Pre-initialize the implementation specific native stuff.
58 :
59 : *******************************************************************************/
60 :
61 163 : void nativevm_preinit(void)
62 : {
63 163 : TRACESUBSYSTEMINITIALIZATION("nativevm_preinit");
64 :
65 : /* Register native methods of all classes implemented. */
66 :
67 : #if defined(ENABLE_JAVASE)
68 : # if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
69 :
70 163 : _Jv_gnu_classpath_VMStackWalker_init();
71 163 : _Jv_gnu_classpath_VMSystemProperties_init();
72 163 : _Jv_gnu_java_lang_VMCPStringBuilder_init();
73 163 : _Jv_gnu_java_lang_management_VMClassLoadingMXBeanImpl_init();
74 163 : _Jv_gnu_java_lang_management_VMMemoryMXBeanImpl_init();
75 163 : _Jv_gnu_java_lang_management_VMRuntimeMXBeanImpl_init();
76 163 : _Jv_gnu_java_lang_management_VMThreadMXBeanImpl_init();
77 163 : _Jv_java_lang_VMClass_init();
78 163 : _Jv_java_lang_VMClassLoader_init();
79 163 : _Jv_java_lang_VMObject_init();
80 163 : _Jv_java_lang_VMRuntime_init();
81 163 : _Jv_java_lang_VMSystem_init();
82 163 : _Jv_java_lang_VMString_init();
83 163 : _Jv_java_lang_VMThread_init();
84 163 : _Jv_java_lang_VMThrowable_init();
85 163 : _Jv_java_lang_management_VMManagementFactory_init();
86 163 : _Jv_java_lang_reflect_VMConstructor_init();
87 163 : _Jv_java_lang_reflect_VMField_init();
88 163 : _Jv_java_lang_reflect_VMMethod_init();
89 : //_Jv_java_lang_reflect_VMProxy_init();
90 163 : _Jv_java_security_VMAccessController_init();
91 163 : _Jv_java_util_concurrent_atomic_AtomicLong_init();
92 163 : _Jv_sun_misc_Unsafe_init();
93 :
94 : #if defined(ENABLE_ANNOTATIONS)
95 163 : _Jv_sun_reflect_ConstantPool_init();
96 : #endif
97 :
98 : # elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
99 :
100 : // Load libjava.so
101 : VM* vm = VM::get_current();
102 : Properties& properties = vm->get_properties();
103 : const char* boot_library_path = properties.get("sun.boot.library.path");
104 :
105 : // Use Buffer to assemble library path.
106 : Buffer<> buf;
107 :
108 : buf.write(boot_library_path);
109 : buf.write("/libjava.so");
110 :
111 : Utf8String u = buf.utf8_str();
112 :
113 : NativeLibrary nl(u);
114 : void* handle = nl.open();
115 :
116 : if (handle == NULL)
117 : os::abort("nativevm_init: failed to open libjava.so at: %s", buf.c_str());
118 :
119 : NativeLibraries& nls = vm->get_nativelibraries();
120 : nls.add(nl);
121 :
122 : #ifndef WITH_JAVA_RUNTIME_LIBRARY_OPENJDK_7
123 : // Initialize the HPI.
124 : HPI& hpi = vm->get_hpi();
125 : hpi.initialize();
126 : #endif
127 :
128 : _Jv_sun_misc_Perf_init();
129 : _Jv_sun_misc_Unsafe_init();
130 :
131 : # if !defined(NDEBUG)
132 : // Sanity check current time in milliseconds, because negative values
133 : // might confuse OpenJDKs sanity checks.
134 : if (opt_PrintWarnings && (builtin_currenttimemillis() < 0))
135 : log_println("nativevm_preinit: Current time in milliseconds is negative, please check your time!");
136 : # endif
137 :
138 : # else
139 : # error unknown classpath configuration
140 : # endif
141 :
142 : #elif defined(ENABLE_JAVAME_CLDC1_1)
143 :
144 : _Jv_com_sun_cldc_io_ResourceInputStream_init();
145 : _Jv_com_sun_cldc_io_j2me_socket_Protocol_init();
146 : _Jv_com_sun_cldchi_io_ConsoleOutputStream_init();
147 : _Jv_com_sun_cldchi_jvm_JVM_init();
148 : _Jv_java_lang_Class_init();
149 : _Jv_java_lang_Double_init();
150 : _Jv_java_lang_Float_init();
151 : _Jv_java_lang_Math_init();
152 : _Jv_java_lang_Object_init();
153 : _Jv_java_lang_Runtime_init();
154 : _Jv_java_lang_String_init();
155 : _Jv_java_lang_System_init();
156 : _Jv_java_lang_Thread_init();
157 : _Jv_java_lang_Throwable_init();
158 :
159 : #else
160 : # error unknown Java configuration
161 : #endif
162 163 : }
163 :
164 :
165 : /* nativevm_init ***************************************************************
166 :
167 : Initialize the implementation specific native stuff.
168 :
169 : *******************************************************************************/
170 :
171 163 : bool nativevm_init(void)
172 : {
173 163 : TRACESUBSYSTEMINITIALIZATION("nativevm_init");
174 :
175 : #if defined(ENABLE_JAVASE)
176 :
177 : # if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
178 :
179 : // Nothing to do.
180 :
181 : # elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
182 :
183 : methodinfo* m = class_resolveclassmethod(class_java_lang_System,
184 : Utf8String::from_utf8("initializeSystemClass"),
185 : utf8::void__void,
186 : class_java_lang_Object,
187 : false);
188 :
189 : if (m == NULL)
190 : return false;
191 :
192 : (void) vm_call_method(m, NULL);
193 :
194 : if (exceptions_get_exception() != NULL)
195 : return false;
196 :
197 : # else
198 : # error unknown classpath configuration
199 : # endif
200 :
201 : #elif defined(ENABLE_JAVAME_CLDC1_1)
202 :
203 : // Nothing to do.
204 :
205 : #else
206 : # error unknown Java configuration
207 : #endif
208 :
209 163 : return true;
210 : }
211 :
212 :
213 : /*
214 : * These are local overrides for various environment variables in Emacs.
215 : * Please do not remove this and leave it at the end of the file, where
216 : * Emacs will automagically detect them.
217 : * ---------------------------------------------------------------------
218 : * Local variables:
219 : * mode: c++
220 : * indent-tabs-mode: t
221 : * c-basic-offset: 4
222 : * tab-width: 4
223 : * End:
224 : * vim:noexpandtab:sw=4:ts=4:
225 : */
|