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