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