Merged revisions 8245-8298 via svnmerge from
[cacao.git] / src / native / vm / nativevm.c
1 /* src/native/vm/nativevm.c - register the native functions
2
3    Copyright (C) 2007 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25    $Id: native.c 7906 2007-05-14 17:25:33Z twisti $
26
27 */
28
29
30 #include "config.h"
31 #include "vm/types.h"
32
33 #include "native/vm/nativevm.h"
34
35 #include "vmcore/method.h"
36
37 #if defined(WITH_CLASSPATH_SUN)
38 # include "native/native.h"
39
40 # include "vm/vm.h"
41
42 # include "vmcore/class.h"
43 # include "vmcore/utf8.h"
44 #endif
45
46
47 /* nativevm_preinit ************************************************************
48
49    Pre-initialize the implementation specific native stuff.
50
51 *******************************************************************************/
52
53 bool nativevm_preinit(void)
54 {
55         /* register native methods of all classes implemented */
56
57 #if defined(ENABLE_JAVASE)
58
59 # if defined(WITH_CLASSPATH_GNU)
60
61         _Jv_gnu_classpath_VMStackWalker_init();
62         _Jv_gnu_classpath_VMSystemProperties_init();
63         _Jv_gnu_java_lang_management_VMClassLoadingMXBeanImpl_init();
64         _Jv_gnu_java_lang_management_VMMemoryMXBeanImpl_init();
65         _Jv_gnu_java_lang_management_VMRuntimeMXBeanImpl_init();
66         _Jv_gnu_java_lang_management_VMThreadMXBeanImpl_init();
67         _Jv_java_lang_VMClass_init();
68         _Jv_java_lang_VMClassLoader_init();
69         _Jv_java_lang_VMObject_init();
70         _Jv_java_lang_VMRuntime_init();
71         _Jv_java_lang_VMSystem_init();
72         _Jv_java_lang_VMString_init();
73         _Jv_java_lang_VMThread_init();
74         _Jv_java_lang_VMThrowable_init();
75         _Jv_java_lang_management_VMManagementFactory_init();
76         _Jv_java_lang_reflect_Constructor_init();
77         _Jv_java_lang_reflect_Field_init();
78         _Jv_java_lang_reflect_Method_init();
79         _Jv_java_lang_reflect_VMProxy_init();
80         _Jv_java_security_VMAccessController_init();
81         _Jv_java_util_concurrent_atomic_AtomicLong_init();
82         _Jv_sun_misc_Unsafe_init();
83
84 #if defined(ENABLE_ANNOTATIONS)
85         _Jv_sun_reflect_ConstantPool_init();
86 #endif
87
88 # elif defined(WITH_CLASSPATH_SUN)
89
90         utf         *u;
91         lt_dlhandle  handle;
92
93         u = utf_new_char(CLASSPATH_LIBDIR"/libjava.so");
94
95         handle = native_library_open(u);
96         native_library_add(u, NULL, handle);
97
98         _Jv_sun_misc_Unsafe_init();
99
100 # else
101
102 #  error unknown classpath configuration
103
104 # endif
105
106 #elif defined(ENABLE_JAVAME_CLDC1_1)
107
108         _Jv_com_sun_cldc_io_ResourceInputStream_init();
109         _Jv_com_sun_cldc_io_j2me_socket_Protocol_init();
110         _Jv_com_sun_cldchi_io_ConsoleOutputStream_init();
111         _Jv_com_sun_cldchi_jvm_JVM_init();
112         _Jv_java_lang_Class_init();
113         _Jv_java_lang_Double_init();
114         _Jv_java_lang_Float_init();
115         _Jv_java_lang_Math_init();
116         _Jv_java_lang_Object_init();
117         _Jv_java_lang_Runtime_init();
118         _Jv_java_lang_String_init();
119         _Jv_java_lang_System_init();
120         _Jv_java_lang_Thread_init();
121         _Jv_java_lang_Throwable_init();
122
123 #else
124
125 # error unknown Java configuration
126
127 #endif
128
129         /* everything's ok */
130
131         return true;
132 }
133
134
135 /* nativevm_init ***************************************************************
136
137    Initialize the implementation specific native stuff.
138
139 *******************************************************************************/
140
141 bool nativevm_init(void)
142 {
143 #if defined(ENABLE_JAVASE)
144
145 # if defined(WITH_CLASSPATH_GNU)
146
147         /* nothing to do */
148
149 # elif defined(WITH_CLASSPATH_SUN)
150
151         methodinfo *m;
152
153         m = class_resolveclassmethod(class_java_lang_System,
154                                                                  utf_new_char("initializeSystemClass"),
155                                                                  utf_void__void,
156                                                                  class_java_lang_Object,
157                                                                  false);
158
159         if (m == NULL)
160                 return false;
161
162         (void) vm_call_method(m, NULL);
163
164 # else
165
166 #  error unknown classpath configuration
167
168 # endif
169
170 #elif defined(ENABLE_JAVAME_CLDC1_1)
171
172         /* nothing to do */
173
174 #else
175
176 # error unknown Java configuration
177
178 #endif
179
180         /* everything's ok */
181
182         return true;
183 }
184
185
186 /*
187  * These are local overrides for various environment variables in Emacs.
188  * Please do not remove this and leave it at the end of the file, where
189  * Emacs will automagically detect them.
190  * ---------------------------------------------------------------------
191  * Local variables:
192  * mode: c
193  * indent-tabs-mode: t
194  * c-basic-offset: 4
195  * tab-width: 4
196  * End:
197  */