Line data Source code
1 : /* src/vm/vm.hpp - basic JVM functions
2 :
3 : Copyright (C) 1996-2012
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 : #include "vm/global.hpp"
31 :
32 : #include <stdarg.h>
33 : #include <stdint.h>
34 :
35 : // We need the JNI types for the VM class.
36 : #include "native/jni.hpp"
37 : #include "native/native.hpp"
38 :
39 : #if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
40 : #ifndef WITH_JAVA_RUNTIME_LIBRARY_OPENJDK_7
41 : # include "native/vm/openjdk/hpi.hpp"
42 : #endif
43 : # include "native/vm/openjdk/management.hpp"
44 : #endif
45 :
46 : #include "vm/properties.hpp"
47 : #include "vm/suck.hpp"
48 :
49 : #include "vm/jit/optimizing/recompiler.hpp"
50 :
51 : struct methodinfo;
52 :
53 : /**
54 : * Represent an instance of a VM.
55 : */
56 : class VM {
57 : private:
58 : // This is _the_ VM instance.
59 : static VM* _vm;
60 :
61 : // JNI variables.
62 : JavaVM* _javavm;
63 : JNIEnv* _jnienv;
64 :
65 : // VM variables.
66 : bool _initializing;
67 : bool _created;
68 : bool _exiting;
69 : int64_t _starttime;
70 : int64_t _inittime;
71 :
72 : // Subsystems.
73 : Properties _properties; ///< Commandline properties.
74 : #if defined(ENABLE_THREADS)
75 : Recompiler _recompiler; ///< JIT recompilation framework.
76 : #endif
77 : #if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
78 : #ifndef WITH_JAVA_RUNTIME_LIBRARY_OPENJDK_7
79 : HPI _hpi; ///< Host Porting Interface.
80 : #else
81 : Mutex _jniMutex; ///< XXX should be part of the not existing class wrapper for src/native/vm/openjdk/jvm.cpp
82 : #endif
83 : Management _management; ///< Java management interface.
84 : #endif
85 : NativeLibraries _nativelibraries; ///< Native library table.
86 : NativeMethods _nativemethods; ///< Native methods table.
87 : #if defined(ENABLE_JVMTI)
88 : NativeAgents _nativeagents; ///< Native agents table.
89 : #endif
90 : SuckClasspath _suckclasspath; ///< Classpath entries list.
91 :
92 : public:
93 : // Constructor, Destructor.
94 : VM(JavaVMInitArgs*);
95 : ~VM();
96 :
97 : // Static methods.
98 : static bool create(JavaVM** p_vm, void** p_env, void* vm_args);
99 83211 : static VM* get_current() { return _vm; }
100 :
101 : static void print_build_time_config();
102 : void print_run_time_config();
103 :
104 : // Getters for private members.
105 586 : JavaVM* get_javavm() { return _javavm; }
106 11361 : JNIEnv* get_jnienv() { return _jnienv; }
107 22086 : bool is_initializing() { return _initializing; }
108 423 : bool is_created() { return _created; }
109 : bool is_exiting() { return _exiting; }
110 0 : int64_t get_starttime() { return _starttime; }
111 : int64_t get_inittime() { return _inittime; }
112 :
113 304 : Properties& get_properties () { return _properties; }
114 :
115 : #if defined(ENABLE_THREADS)
116 163 : Recompiler& get_recompiler () { return _recompiler; } // REMOVEME
117 : #endif
118 :
119 : #if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
120 : #ifndef WITH_JAVA_RUNTIME_LIBRARY_OPENJDK_7
121 : HPI& get_hpi () { return _hpi; }
122 : #else
123 : Mutex& get_jniMutex () { return _jniMutex; }
124 : #endif
125 : Management& get_management () { return _management; }
126 : #endif
127 2780 : NativeLibraries& get_nativelibraries() { return _nativelibraries; }
128 9744 : NativeMethods& get_nativemethods () { return _nativemethods; }
129 36090 : SuckClasspath& get_suckclasspath () { return _suckclasspath; }
130 :
131 : private:
132 : // Internal helper methods.
133 : bool start_runtime_agents();
134 : };
135 :
136 : /* These C methods are the exported interface. ********************************/
137 :
138 : extern "C" bool VM_create(JavaVM** p_vm, void** p_env, void* vm_args);
139 :
140 :
141 : /* export global variables ****************************************************/
142 :
143 : #if defined(ENABLE_INTRP)
144 : extern uint8_t* intrp_main_stack;
145 : #endif
146 :
147 :
148 : /* function prototypes ********************************************************/
149 :
150 : extern "C" {
151 :
152 : void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args);
153 : int32_t vm_destroy(JavaVM *vm);
154 : void vm_exit(int32_t status);
155 : void vm_shutdown(int32_t status);
156 :
157 : void vm_exit_handler(void);
158 :
159 : void vm_abort_disassemble(void *pc, int count, const char *text, ...);
160 :
161 : /* Java method calling functions */
162 :
163 : java_handle_t *vm_call_method(methodinfo *m, java_handle_t *o, ...);
164 : java_handle_t *vm_call_method_valist(methodinfo *m, java_handle_t *o,
165 : va_list ap);
166 : java_handle_t *vm_call_method_jvalue(methodinfo *m, java_handle_t *o,
167 : const jvalue *args);
168 :
169 : int32_t vm_call_method_int(methodinfo *m, java_handle_t *o, ...);
170 : int32_t vm_call_method_int_valist(methodinfo *m, java_handle_t *o, va_list ap);
171 : int32_t vm_call_method_int_jvalue(methodinfo *m, java_handle_t *o, const jvalue *args);
172 :
173 : int64_t vm_call_method_long(methodinfo *m, java_handle_t *o, ...);
174 : int64_t vm_call_method_long_valist(methodinfo *m, java_handle_t *o, va_list ap);
175 : int64_t vm_call_method_long_jvalue(methodinfo *m, java_handle_t *o, const jvalue *args);
176 :
177 : float vm_call_method_float(methodinfo *m, java_handle_t *o, ...);
178 : float vm_call_method_float_valist(methodinfo *m, java_handle_t *o, va_list ap);
179 : float vm_call_method_float_jvalue(methodinfo *m, java_handle_t *o, const jvalue *args);
180 :
181 : double vm_call_method_double(methodinfo *m, java_handle_t *o, ...);
182 : double vm_call_method_double_valist(methodinfo *m, java_handle_t *o, va_list ap);
183 : double vm_call_method_double_jvalue(methodinfo *m, java_handle_t *o, const jvalue *args);
184 :
185 : java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o, java_handle_objectarray_t *params);
186 :
187 :
188 : // Legacy C interface.
189 : void vm_abort(const char* text, ...);
190 :
191 : } // extern "C"
192 :
193 : #endif // _VM_HPP
194 :
195 :
196 : /*
197 : * These are local overrides for various environment variables in Emacs.
198 : * Please do not remove this and leave it at the end of the file, where
199 : * Emacs will automagically detect them.
200 : * ---------------------------------------------------------------------
201 : * Local variables:
202 : * mode: c++
203 : * indent-tabs-mode: t
204 : * c-basic-offset: 4
205 : * tab-width: 4
206 : * End:
207 : * vim:noexpandtab:sw=4:ts=4:
208 : */
|