Merge from subtype.
[cacao.git] / src / vm / vm.hpp
1 /* src/vm/vm.hpp - basic JVM functions
2
3    Copyright (C) 1996-2005, 2006, 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 #ifndef _VM_HPP
27 #define _VM_HPP
28
29 #include "config.h"
30
31 #include <stdarg.h>
32 #include <stdint.h>
33
34 // We need the JNI types for the VM class.
35 #include "native/jni.hpp"
36 #include "native/native.hpp"
37
38 #if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
39 # include "native/vm/openjdk/hpi.hpp"
40 # include "native/vm/openjdk/management.hpp"
41 #endif
42
43 #include "vm/properties.hpp"
44
45 #include "vm/jit/optimizing/recompiler.hpp"
46
47
48 #ifdef __cplusplus
49
50 /**
51  * Represent an instance of a VM.
52  */
53 class VM {
54 private:
55         // This is _the_ VM instance.
56         static VM* _vm;
57
58         // JNI variables.
59         JavaVM* _javavm;
60         JNIEnv* _jnienv;
61
62         // VM variables.
63         bool    _initializing;
64         bool    _created;
65         bool    _exiting;
66         int64_t _starttime;
67
68         // Subsystems.
69         Properties      _properties;      ///< Commandline properties.
70 #if defined(ENABLE_THREADS)
71         Recompiler      _recompiler;      ///< JIT recompilation framework.
72 #endif
73 #if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
74         HPI             _hpi;             ///< Host Porting Interface.
75         Management      _management;      ///< Java management interface.
76 #endif
77         NativeLibraries _nativelibraries; ///< Native library table.
78         NativeMethods   _nativemethods;   ///< Native methods table.
79
80 public:
81         // Constructor, Destructor.
82         VM(JavaVMInitArgs*);
83         ~VM();
84
85         // Static methods.
86         static bool create(JavaVM** p_vm, void** p_env, void* vm_args);
87         static VM*  get_current() { return _vm; }
88
89         static void print_build_time_config();
90         void        print_run_time_config();
91
92         // Getters for private members.
93         JavaVM* get_javavm()      { return _javavm; }
94         JNIEnv* get_jnienv()      { return _jnienv; }
95         bool    is_initializing() { return _initializing; }
96         bool    is_created()      { return _created; }
97         bool    is_exiting()      { return _exiting; }
98         int64_t get_starttime()   { return _starttime; }
99
100         Properties&      get_properties     () { return _properties; }
101         Recompiler&      get_recompiler     () { return _recompiler; } // REMOVEME
102 #if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
103         HPI&             get_hpi            () { return _hpi; }
104         Management&      get_management     () { return _management; }
105 #endif
106         NativeLibraries& get_nativelibraries() { return _nativelibraries; }
107         NativeMethods&   get_nativemethods  () { return _nativemethods; }
108 };
109
110 #else
111
112 JavaVM* VM_get_javavm();
113 JNIEnv* VM_get_jnienv();
114 bool    VM_is_initializing();
115 bool    VM_is_created();
116 int64_t VM_get_starttime();
117
118 #endif
119
120
121 // Includes.
122 #include "vm/global.h"
123 #include "vm/method.hpp"
124
125
126 /* These C methods are the exported interface. ********************************/
127
128 #ifdef __cplusplus
129 extern "C" {
130 #endif
131
132 bool VM_create(JavaVM** p_vm, void** p_env, void* vm_args);
133
134 #ifdef __cplusplus
135 }
136 #endif
137
138
139 /* export global variables ****************************************************/
140
141 #if defined(ENABLE_INTRP)
142 extern uint8_t* intrp_main_stack;
143 #endif
144
145
146 /* function prototypes ********************************************************/
147
148 #ifdef __cplusplus
149 extern "C" {
150 #endif
151
152 void usage(void);
153
154 bool vm_create(JavaVMInitArgs *vm_args);
155 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args);
156 int32_t   vm_destroy(JavaVM *vm);
157 void vm_exit(int32_t status);
158 void vm_shutdown(int32_t status);
159
160 void vm_exit_handler(void);
161
162 void vm_abort_disassemble(void *pc, int count, const char *text, ...);
163
164 /* Java method calling functions */
165
166 java_handle_t *vm_call_method(methodinfo *m, java_handle_t *o, ...);
167 java_handle_t *vm_call_method_valist(methodinfo *m, java_handle_t *o,
168                                                                                  va_list ap);
169 java_handle_t *vm_call_method_jvalue(methodinfo *m, java_handle_t *o,
170                                                                                  const jvalue *args);
171
172 int32_t vm_call_method_int(methodinfo *m, java_handle_t *o, ...);
173 int32_t vm_call_method_int_valist(methodinfo *m, java_handle_t *o, va_list ap);
174 int32_t vm_call_method_int_jvalue(methodinfo *m, java_handle_t *o, const jvalue *args);
175
176 int64_t vm_call_method_long(methodinfo *m, java_handle_t *o, ...);
177 int64_t vm_call_method_long_valist(methodinfo *m, java_handle_t *o, va_list ap);
178 int64_t vm_call_method_long_jvalue(methodinfo *m, java_handle_t *o, const jvalue *args);
179
180 float   vm_call_method_float(methodinfo *m, java_handle_t *o, ...);
181 float   vm_call_method_float_valist(methodinfo *m, java_handle_t *o, va_list ap);
182 float   vm_call_method_float_jvalue(methodinfo *m, java_handle_t *o, const jvalue *args);
183
184 double  vm_call_method_double(methodinfo *m, java_handle_t *o, ...);
185 double  vm_call_method_double_valist(methodinfo *m, java_handle_t *o, va_list ap);
186 double  vm_call_method_double_jvalue(methodinfo *m, java_handle_t *o, const jvalue *args);
187
188 java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o, java_handle_objectarray_t *params);
189
190
191 // Legacy C interface.
192 void vm_abort(const char* text, ...);
193 void vm_abort_errnum(int errnum, const char* text, ...);
194 void vm_abort_errno(const char* text, ...);
195
196 #ifdef __cplusplus
197 }
198 #endif
199
200 #endif // _VM_HPP
201
202
203 /*
204  * These are local overrides for various environment variables in Emacs.
205  * Please do not remove this and leave it at the end of the file, where
206  * Emacs will automagically detect them.
207  * ---------------------------------------------------------------------
208  * Local variables:
209  * mode: c++
210  * indent-tabs-mode: t
211  * c-basic-offset: 4
212  * tab-width: 4
213  * End:
214  * vim:noexpandtab:sw=4:ts=4:
215  */