CACAO
vm.hpp
Go to the documentation of this file.
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
44 #endif
45 
46 #include "vm/properties.hpp"
47 #include "vm/suck.hpp"
48 
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.
64 
65  // VM variables.
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  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  JavaVM* get_javavm() { return _javavm; }
106  JNIEnv* get_jnienv() { return _jnienv; }
107  bool is_initializing() { return _initializing; }
108  bool is_created() { return _created; }
109  bool is_exiting() { return _exiting; }
110  int64_t get_starttime() { return _starttime; }
111  int64_t get_inittime() { return _inittime; }
112 
114 
115 #if defined(ENABLE_THREADS)
116  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
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 
165  va_list ap);
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 
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 
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 
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  */
java_handle_t * vm_call_method_valist(methodinfo *m, java_handle_t *o, va_list ap)
JavaVM * _javavm
Definition: vm.hpp:62
Management support.
Definition: management.hpp:37
Table containing all native methods registered with the VM.
Definition: native.hpp:132
NativeMethods & get_nativemethods()
Definition: vm.hpp:128
SuckClasspath _suckclasspath
Classpath entries list.
Definition: vm.hpp:90
~VM()
int64_t _starttime
Definition: vm.hpp:69
java_handle_t * vm_call_method_jvalue(methodinfo *m, java_handle_t *o, const jvalue *args)
void vm_exit_handler(void)
Definition: vm.cpp:1903
_Jv_JNIEnv JNIEnv
Definition: jni.hpp:112
int64_t vm_call_method_long_jvalue(methodinfo *m, java_handle_t *o, const jvalue *args)
float vm_call_method_float_jvalue(methodinfo *m, java_handle_t *o, const jvalue *args)
int64_t get_inittime()
Definition: vm.hpp:111
JNIEnv * get_jnienv()
Definition: vm.hpp:106
double vm_call_method_double_valist(methodinfo *m, java_handle_t *o, va_list ap)
Recompiler & get_recompiler()
Definition: vm.hpp:116
NativeMethods _nativemethods
Native methods table.
Definition: vm.hpp:86
_Jv_JavaVM JavaVM
Definition: jni.hpp:114
bool VM_create(JavaVM **p_vm, void **p_env, void *vm_args)
C wrapper for VM::create.
Definition: vm.cpp:626
bool is_initializing()
Definition: vm.hpp:107
NativeLibraries _nativelibraries
Native library table.
Definition: vm.hpp:85
Dummy implementation of a mutex.
Definition: mutex-none.hpp:33
int64_t vm_call_method_long(methodinfo *m, java_handle_t *o,...)
java_handle_t * vm_call_method(methodinfo *m, java_handle_t *o,...)
Recompiler _recompiler
JIT recompilation framework.
Definition: vm.hpp:75
Commandline properties.
Definition: properties.hpp:45
int vm_destroy(JavaVM *vm)
Definition: vm.cpp:1771
int32_t vm_call_method_int(methodinfo *m, java_handle_t *o,...)
void vm_shutdown()
Hook point before the VM is actually destroyed.
Definition: hook.hpp:168
void vm_abort(const char *text,...)
Definition: vm.cpp:2586
int32_t vm_call_method_int_valist(methodinfo *m, java_handle_t *o, va_list ap)
Host Porting Interface (HPI).
Definition: hpi.hpp:53
Properties _properties
Commandline properties.
Definition: vm.hpp:73
bool _created
Definition: vm.hpp:67
void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
Definition: vm.cpp:1588
NativeLibraries & get_nativelibraries()
Definition: vm.hpp:127
static void print_build_time_config()
Print build-time (default) VM configuration.
Definition: vm.cpp:1464
Thread for JIT recompilations.
Definition: recompiler.hpp:39
int64_t get_starttime()
Definition: vm.hpp:110
void vm_exit(s4 status)
Definition: vm.cpp:1807
JavaVM * get_javavm()
Definition: vm.hpp:105
Properties & get_properties()
Definition: vm.hpp:113
Classpath entries list.
Definition: suck.hpp:62
void print_run_time_config()
Print run-time VM configuration.
Definition: vm.cpp:1507
bool _exiting
Definition: vm.hpp:68
java_handle_t * vm_call_method_objectarray(methodinfo *m, java_handle_t *o, java_handle_objectarray_t *params)
Definition: vm.cpp:2483
int64_t _inittime
Definition: vm.hpp:70
JNIEnv * _jnienv
Definition: vm.hpp:63
int32_t vm_call_method_int_jvalue(methodinfo *m, java_handle_t *o, const jvalue *args)
#define pc
Definition: md-asm.hpp:56
double vm_call_method_double_jvalue(methodinfo *m, java_handle_t *o, const jvalue *args)
SuckClasspath & get_suckclasspath()
Definition: vm.hpp:129
Table containing all loaded native libraries.
Definition: native.hpp:85
bool is_exiting()
Definition: vm.hpp:109
static bool create(JavaVM **p_vm, void **p_env, void *vm_args)
Implementation for JNI_CreateJavaVM.
Definition: vm.cpp:591
float vm_call_method_float(methodinfo *m, java_handle_t *o,...)
void vm_abort_disassemble(void *pc, int count, const char *text,...)
Definition: vm.cpp:2001
bool is_created()
Definition: vm.hpp:108
bool _initializing
Definition: vm.hpp:66
static VM * _vm
This is the VM instance.
Definition: vm.hpp:59
bool start_runtime_agents()
Start runtime agents which are provided by the JRE but need to be started explicitly by the VM...
Definition: vm.cpp:1531
VM(JavaVMInitArgs *)
VM constructor.
Definition: vm.cpp:636
Represent an instance of a VM.
Definition: vm.hpp:56
int64_t vm_call_method_long_valist(methodinfo *m, java_handle_t *o, va_list ap)
float vm_call_method_float_valist(methodinfo *m, java_handle_t *o, va_list ap)
static VM * get_current()
Definition: vm.hpp:99
double vm_call_method_double(methodinfo *m, java_handle_t *o,...)