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