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