Merged with cldc-branch
[cacao.git] / src / native / vm / nativevm.c
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 #if defined(WITH_CLASSPATH_SUN)
31 # include <string.h>
32 #endif
33
34 #include "native/vm/nativevm.h"
35
36 #include "vmcore/method.h"
37 #include "vmcore/options.h"
38
39 #if defined(WITH_CLASSPATH_SUN)
40 # include "mm/memory.h"
41
42 # include "native/native.h"
43
44 # include "vm/properties.h"
45 # include "vm/vm.h"
46
47 # include "vmcore/class.h"
48 # include "vmcore/utf8.h"
49 #endif
50
51
52 /* nativevm_preinit ************************************************************
53
54    Pre-initialize the implementation specific native stuff.
55
56 *******************************************************************************/
57
58 bool nativevm_preinit(void)
59 {
60         /* register native methods of all classes implemented */
61
62 #if defined(ENABLE_JAVASE)
63
64 # if defined(WITH_CLASSPATH_GNU)
65
66         TRACESUBSYSTEMINITIALIZATION("nativevm_preinit");
67
68         _Jv_gnu_classpath_VMStackWalker_init();
69         _Jv_gnu_classpath_VMSystemProperties_init();
70         _Jv_gnu_java_lang_management_VMClassLoadingMXBeanImpl_init();
71         _Jv_gnu_java_lang_management_VMMemoryMXBeanImpl_init();
72         _Jv_gnu_java_lang_management_VMRuntimeMXBeanImpl_init();
73         _Jv_gnu_java_lang_management_VMThreadMXBeanImpl_init();
74         _Jv_java_lang_VMClass_init();
75         _Jv_java_lang_VMClassLoader_init();
76         _Jv_java_lang_VMObject_init();
77         _Jv_java_lang_VMRuntime_init();
78         _Jv_java_lang_VMSystem_init();
79         _Jv_java_lang_VMString_init();
80         _Jv_java_lang_VMThread_init();
81         _Jv_java_lang_VMThrowable_init();
82         _Jv_java_lang_management_VMManagementFactory_init();
83         _Jv_java_lang_reflect_Constructor_init();
84         _Jv_java_lang_reflect_Field_init();
85         _Jv_java_lang_reflect_Method_init();
86         _Jv_java_lang_reflect_VMProxy_init();
87         _Jv_java_security_VMAccessController_init();
88         _Jv_java_util_concurrent_atomic_AtomicLong_init();
89         _Jv_sun_misc_Unsafe_init();
90
91 #if defined(ENABLE_ANNOTATIONS)
92         _Jv_sun_reflect_ConstantPool_init();
93 #endif
94
95 # elif defined(WITH_CLASSPATH_SUN)
96
97         char        *boot_library_path;
98         int          len;
99         char        *p;
100         utf         *u;
101         lt_dlhandle  handle;
102
103         TRACESUBSYSTEMINITIALIZATION("nativevm_preinit");
104
105         boot_library_path = properties_get("sun.boot.library.path");
106
107         len =
108                 strlen(boot_library_path) +
109                 strlen("/libjava.so") +
110                 strlen("0");
111
112         p = MNEW(char, len);
113
114         strcpy(p, boot_library_path);
115         strcat(p, "/libjava.so");
116
117         u = utf_new_char(p);
118
119         MFREE(p, char, len);
120
121         handle = native_library_open(u);
122         native_library_add(u, NULL, handle);
123
124         _Jv_sun_misc_Unsafe_init();
125
126 # else
127
128 #  error unknown classpath configuration
129
130 # endif
131
132 #elif defined(ENABLE_JAVAME_CLDC1_1)
133
134         TRACESUBSYSTEMINITIALIZATION("nativevm_preinit");
135
136         _Jv_com_sun_cldc_io_ResourceInputStream_init();
137         _Jv_com_sun_cldc_io_j2me_socket_Protocol_init();
138         _Jv_com_sun_cldchi_io_ConsoleOutputStream_init();
139         _Jv_com_sun_cldchi_jvm_JVM_init();
140         _Jv_java_lang_Class_init();
141         _Jv_java_lang_Double_init();
142         _Jv_java_lang_Float_init();
143         _Jv_java_lang_Math_init();
144         _Jv_java_lang_Object_init();
145         _Jv_java_lang_Runtime_init();
146         _Jv_java_lang_String_init();
147         _Jv_java_lang_System_init();
148         _Jv_java_lang_Thread_init();
149         _Jv_java_lang_Throwable_init();
150
151 #else
152
153 # error unknown Java configuration
154
155 #endif
156
157         /* everything's ok */
158
159         return true;
160 }
161
162
163 /* nativevm_init ***************************************************************
164
165    Initialize the implementation specific native stuff.
166
167 *******************************************************************************/
168
169 bool nativevm_init(void)
170 {
171 #if defined(ENABLE_JAVASE)
172
173 # if defined(WITH_CLASSPATH_GNU)
174
175         TRACESUBSYSTEMINITIALIZATION("nativevm_init");
176
177         /* nothing to do */
178
179 # elif defined(WITH_CLASSPATH_SUN)
180
181         methodinfo *m;
182
183         TRACESUBSYSTEMINITIALIZATION("nativevm_init");
184
185         m = class_resolveclassmethod(class_java_lang_System,
186                                                                  utf_new_char("initializeSystemClass"),
187                                                                  utf_void__void,
188                                                                  class_java_lang_Object,
189                                                                  false);
190
191         if (m == NULL)
192                 return false;
193
194         (void) vm_call_method(m, NULL);
195
196 # else
197
198 #  error unknown classpath configuration
199
200 # endif
201
202 #elif defined(ENABLE_JAVAME_CLDC1_1)
203
204         TRACESUBSYSTEMINITIALIZATION("nativevm_init");
205
206         /* nothing to do */
207
208 #else
209
210 # error unknown Java configuration
211
212 #endif
213
214         /* everything's ok */
215
216         return true;
217 }
218
219
220 /*
221  * These are local overrides for various environment variables in Emacs.
222  * Please do not remove this and leave it at the end of the file, where
223  * Emacs will automagically detect them.
224  * ---------------------------------------------------------------------
225  * Local variables:
226  * mode: c
227  * indent-tabs-mode: t
228  * c-basic-offset: 4
229  * tab-width: 4
230  * End:
231  */