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