CACAO
nativevm.cpp
Go to the documentation of this file.
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 void nativevm_preinit(void)
62 {
63  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 
89  //_Jv_java_lang_reflect_VMProxy_init();
93 
94 #if defined(ENABLE_ANNOTATIONS)
96 #endif
97 
98 #if defined(ENABLE_COMPILER2)
100 #endif
101 
102 # elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
103 
104  // Load libjava.so
105  VM* vm = VM::get_current();
106  Properties& properties = vm->get_properties();
107  const char* boot_library_path = properties.get("sun.boot.library.path");
108 
109  // Use Buffer to assemble library path.
110  Buffer<> buf;
111 
112  buf.write(boot_library_path);
113  buf.write("/libjava.so");
114 
115  Utf8String u = buf.utf8_str();
116 
117  NativeLibrary nl(u);
118  void* handle = nl.open();
119 
120  if (handle == NULL)
121  os::abort("nativevm_init: failed to open libjava.so at: %s", buf.c_str());
122 
124  nls.add(nl);
125 
126 #ifndef WITH_JAVA_RUNTIME_LIBRARY_OPENJDK_7
127  // Initialize the HPI.
128  HPI& hpi = vm->get_hpi();
129  hpi.initialize();
130 #endif
131 
134 
135 # if !defined(NDEBUG)
136  // Sanity check current time in milliseconds, because negative values
137  // might confuse OpenJDKs sanity checks.
139  log_println("nativevm_preinit: Current time in milliseconds is negative, please check your time!");
140 # endif
141 
142 # else
143 # error unknown classpath configuration
144 # endif
145 
146 #elif defined(ENABLE_JAVAME_CLDC1_1)
147 
162 
163 #else
164 # error unknown Java configuration
165 #endif
166 }
167 
168 
169 /* nativevm_init ***************************************************************
170 
171  Initialize the implementation specific native stuff.
172 
173 *******************************************************************************/
174 
175 bool nativevm_init(void)
176 {
177  TRACESUBSYSTEMINITIALIZATION("nativevm_init");
178 
179 #if defined(ENABLE_JAVASE)
180 
181 # if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
182 
183  // Nothing to do.
184 
185 # elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
186 
188  Utf8String::from_utf8("initializeSystemClass"),
189  utf8::void__void,
191  false);
192 
193  if (m == NULL)
194  return false;
195 
196  (void) vm_call_method(m, NULL);
197 
198  if (exceptions_get_exception() != NULL)
199  return false;
200 
201 # else
202 # error unknown classpath configuration
203 # endif
204 
205 #elif defined(ENABLE_JAVAME_CLDC1_1)
206 
207  // Nothing to do.
208 
209 #else
210 # error unknown Java configuration
211 #endif
212 
213  return true;
214 }
215 
216 
217 /*
218  * These are local overrides for various environment variables in Emacs.
219  * Please do not remove this and leave it at the end of the file, where
220  * Emacs will automagically detect them.
221  * ---------------------------------------------------------------------
222  * Local variables:
223  * mode: c++
224  * indent-tabs-mode: t
225  * c-basic-offset: 4
226  * tab-width: 4
227  * End:
228  * vim:noexpandtab:sw=4:ts=4:
229  */
void _Jv_java_lang_VMSystem_init(void)
Utf8String utf8_str()
get utf-8 string contents of buffer as utf8-string
Definition: buffer.hpp:506
void _Jv_java_util_concurrent_atomic_AtomicLong_init(void)
void _Jv_java_lang_reflect_VMMethod_init(void)
methodinfo * class_resolveclassmethod(classinfo *c, Utf8String name, Utf8String desc, classinfo *referer, bool throwexception)
Definition: class.cpp:1211
void * open()
Open this native library.
Definition: native.cpp:398
void _Jv_java_lang_Math_init(void)
void _Jv_java_lang_management_VMManagementFactory_init(void)
void nativevm_preinit(void)
Definition: nativevm.cpp:61
void _Jv_java_lang_VMRuntime_init(void)
void _Jv_gnu_java_lang_VMCPStringBuilder_init(void)
void _Jv_gnu_classpath_VMStackWalker_init(void)
const char * c_str()
get contents of buffer as zero-terminated c-style-string This strings lifetime is tied to it&#39;s buffer...
Definition: buffer.hpp:489
typedef void(JNICALL *jvmtiEventSingleStep)(jvmtiEnv *jvmti_env
void _Jv_gnu_java_lang_management_VMThreadMXBeanImpl_init(void)
void _Jv_java_lang_reflect_VMField_init(void)
void _Jv_com_sun_cldchi_io_ConsoleOutputStream_init(void)
void _Jv_java_lang_Object_init(void)
java_handle_t * vm_call_method(methodinfo *m, java_handle_t *o,...)
void _Jv_java_security_VMAccessController_init(void)
void _Jv_com_sun_cldc_io_j2me_socket_Protocol_init(void)
Commandline properties.
Definition: properties.hpp:45
void _Jv_com_sun_cldchi_jvm_JVM_init(void)
classinfo * class_java_lang_Object
Definition: globals.cpp:28
void log_println(const char *text,...)
Definition: logging.cpp:193
#define TRACESUBSYSTEMINITIALIZATION(text)
Definition: options.hpp:258
void initialize()
Definition: hpi.cpp:67
Host Porting Interface (HPI).
Definition: hpi.hpp:53
NativeLibraries & get_nativelibraries()
Definition: vm.hpp:127
void _Jv_java_lang_VMClass_init(void)
void _Jv_sun_misc_Perf_init(void)
bool nativevm_init(void)
Definition: nativevm.cpp:175
void _Jv_gnu_java_lang_management_VMMemoryMXBeanImpl_init(void)
void _Jv_com_sun_cldc_io_ResourceInputStream_init(void)
void _Jv_java_lang_Float_init(void)
void _Jv_java_lang_System_init(void)
void _Jv_gnu_java_lang_management_VMRuntimeMXBeanImpl_init(void)
void _Jv_org_cacaojvm_compiler2_test_Compiler2Test_init(void)
Properties & get_properties()
Definition: vm.hpp:113
static Utf8String from_utf8(const char *, size_t)
Definition: utf8.cpp:335
classinfo * class_java_lang_System
Definition: globals.cpp:40
Represents a native library.
Definition: native.hpp:60
static void abort()
Definition: os.hpp:196
void add(NativeLibrary &library)
Add the given native library to the native libraries table.
Definition: native.cpp:557
void _Jv_java_lang_Double_init(void)
void _Jv_java_lang_VMObject_init(void)
void _Jv_java_lang_VMThrowable_init(void)
void _Jv_gnu_classpath_VMSystemProperties_init(void)
void _Jv_java_lang_String_init(void)
void _Jv_sun_misc_Unsafe_init()
int opt_PrintWarnings
Definition: options.cpp:198
void _Jv_java_lang_Throwable_init(void)
void _Jv_java_lang_Class_init(void)
Buffer & write(char)
Definition: buffer.hpp:280
void _Jv_java_lang_Thread_init(void)
Table containing all loaded native libraries.
Definition: native.hpp:85
java_handle_t * exceptions_get_exception(void)
Definition: exceptions.cpp:76
s8 builtin_currenttimemillis(void)
Definition: builtin.cpp:2063
void _Jv_java_lang_VMString_init(void)
void _Jv_java_lang_VMThread_init(void)
void _Jv_java_lang_Runtime_init(void)
Nl nl
Definition: OStream.cpp:56
void _Jv_sun_reflect_ConstantPool_init(void)
const char * get(const char *key)
Get a property entry from the internal property map.
Definition: properties.cpp:590
Represent an instance of a VM.
Definition: vm.hpp:56
void _Jv_gnu_java_lang_management_VMClassLoadingMXBeanImpl_init(void)
void _Jv_java_lang_reflect_VMConstructor_init(void)
void _Jv_java_lang_VMClassLoader_init(void)
static VM * get_current()
Definition: vm.hpp:99