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