abort, abort_errnum, and abort_errno.
* src/vm/vm.cpp: Likewise.
* src/mm/gc-boehm.cpp,
src/native/jni.cpp,
src/native/jni.hpp,
src/native/vm/gnuclasspath/gnu_java_lang_management_VMRuntimeMXBeanImpl.cpp,
src/threads/posix/condition-posix.hpp,
src/threads/posix/mutex-posix.hpp,
src/vm/exceptions.cpp,
src/vm/os.cpp,
src/vm/primitive.cpp,
src/vm/string.cpp: Use VM::get_current() instead of using vm directly,
use new abort functions.
if (in_gc_out_of_memory) {
/* this is all we can do... */
- vm_abort("gc_out_of_memory: out of memory");
+ VM::get_current()->abort("gc_out_of_memory: out of memory");
}
in_gc_out_of_memory = true;
* Emacs will automagically detect them.
* ---------------------------------------------------------------------
* Local variables:
- * mode: c
+ * mode: c++
* indent-tabs-mode: t
* c-basic-offset: 4
* tab-width: 4
{
STATISTICS(jniinvokation());
- *javavm = vm->get_javavm();
+ *javavm = VM::get_current()->get_javavm();
return 0;
}
TRACEJNICALLS(("_Jv_JNI_DestroyJavaVM(javavm=%p)", javavm));
- if (vm->is_created() == false)
+ if (VM::get_current()->is_created() == false)
return JNI_ERR;
status = vm_destroy(javavm);
result = thread_current_is_attached();
if (result == true) {
- *p_env = vm->get_jnienv();
+ *p_env = VM::get_current()->get_jnienv();
return JNI_OK;
}
return JNI_ERR;
#endif
- *p_env = vm->get_jnienv();
+ *p_env = VM::get_current()->get_jnienv();
return JNI_OK;
}
TRACEJNICALLS(("jni_AttachCurrentThread(javavm=%p, p_env=%p, thr_args=%p)", javavm, p_env, thr_args));
- if (vm->is_created() == false)
+ if (VM::get_current()->is_created() == false)
return JNI_ERR;
result = jni_attach_current_thread(p_env, thr_args, false);
{
TRACEJNICALLS(("jni_GetEnv(javavm=%p, env=%p, version=%d)", javavm, env, version));
- if (vm->is_created() == false) {
+ if (VM::get_current()->is_created() == false) {
*env = NULL;
return JNI_EDETACHED;
}
/* Check the JNI version. */
if (jni_version_check(version) == true) {
- *env = vm->get_jnienv();
+ *env = VM::get_current()->get_jnienv();
return JNI_OK;
}
TRACEJNICALLS(("jni_AttachCurrentThreadAsDaemon(javavm=%p, penv=%p, args=%p)", javavm, penv, args));
- if (vm->is_created() == false)
+ if (VM::get_current()->is_created() == false)
return JNI_ERR;
result = jni_attach_current_thread(penv, args, true);
// We currently only support 1 VM running.
- vmBuf[0] = vm->get_javavm();
+ vmBuf[0] = VM::get_current()->get_javavm();
*nVMs = 1;
return JNI_OK;
#ifndef _JNI_HPP
#define _JNI_HPP
+#include <stdbool.h>
#include <stdint.h>
#include "vm/global.h"
*/
JNIEXPORT int64_t JNICALL Java_gnu_java_lang_management_VMRuntimeMXBeanImpl_getStartTime(JNIEnv *env, jclass clazz)
{
- return vm->get_starttime();
+ return VM::get_current()->get_starttime();
}
} // extern "C"
result = pthread_cond_init(&_cond, NULL);
- if (result != 0)
- vm_abort_errnum(result, "Condition::Condition(): pthread_cond_init failed");
+ if (result != 0) {
+ VM::get_current()->abort_errnum(result, "Condition::Condition(): pthread_cond_init failed");
+ }
}
result = pthread_cond_destroy(&_cond);
- if (result != 0)
- vm_abort_errnum(result, "Condition::~Condition(): pthread_cond_destroy failed");
+ if (result != 0) {
+ VM::get_current()->abort_errnum(result, "Condition::~Condition(): pthread_cond_destroy failed");
+ }
}
result = pthread_cond_broadcast(&_cond);
- if (result != 0)
- vm_abort_errnum(result, "Condition::broadcast(): pthread_cond_broadcast failed");
+ if (result != 0) {
+ VM::get_current()->abort_errnum(result, "Condition::broadcast(): pthread_cond_broadcast failed");
+ }
}
result = pthread_cond_signal(&_cond);
- if (result != 0)
- vm_abort_errnum(result, "Condition::signal(): pthread_cond_signal failed");
+ if (result != 0) {
+ VM::get_current()->abort_errnum(result, "Condition::signal(): pthread_cond_signal failed");
+ }
}
result = pthread_cond_wait(&_cond, &(mutex->_mutex));
- if (result != 0)
- vm_abort_errnum(result, "Condition::wait(): pthread_cond_wait failed");
+ if (result != 0) {
+ VM::get_current()->abort_errnum(result, "Condition::wait(): pthread_cond_wait failed");
+ }
}
#else
int result = pthread_mutexattr_init(&_attr);
if (result != 0) {
- vm_abort_errnum(result, "Mutex::Mutex(): pthread_mutexattr_init failed");
+ VM::get_current()->abort_errnum(result, "Mutex::Mutex(): pthread_mutexattr_init failed");
}
result = pthread_mutexattr_settype(&_attr, PTHREAD_MUTEX_RECURSIVE);
if (result != 0) {
- vm_abort_errnum(result, "Mutex::Mutex(): pthread_mutexattr_settype failed");
+ VM::get_current()->abort_errnum(result, "Mutex::Mutex(): pthread_mutexattr_settype failed");
}
result = pthread_mutex_init(&_mutex, &_attr);
if (result != 0) {
- vm_abort_errnum(result, "Mutex::Mutex(): pthread_mutex_init failed");
+ VM::get_current()->abort_errnum(result, "Mutex::Mutex(): pthread_mutex_init failed");
}
}
int result = pthread_mutexattr_destroy(&_attr);
if (result != 0) {
- vm_abort_errnum(result, "Mutex::~Mutex(): pthread_mutexattr_destroy failed");
+ VM::get_current()->abort_errnum(result, "Mutex::~Mutex(): pthread_mutexattr_destroy failed");
}
result = pthread_mutex_destroy(&_mutex);
if (result != 0) {
- vm_abort_errnum(result, "Mutex::~Mutex(): pthread_mutex_destroy failed");
+ VM::get_current()->abort_errnum(result, "Mutex::~Mutex(): pthread_mutex_destroy failed");
}
}
int result = pthread_mutex_lock(&_mutex);
if (result != 0) {
- vm_abort_errnum(result, "Mutex::lock(): pthread_mutex_lock failed");
+ VM::get_current()->abort_errnum(result, "Mutex::lock(): pthread_mutex_lock failed");
}
}
int result = pthread_mutex_unlock(&_mutex);
if (result != 0) {
- vm_abort_errnum(result, "Mutex::unlock: pthread_mutex_unlock failed");
+ VM::get_current()->abort_errnum(result, "Mutex::unlock: pthread_mutex_unlock failed");
}
}
log_finish();
- vm_abort("Aborting...");
+ VM::get_current()->abort("Aborting...");
}
java_handle_t *s;
java_handle_t *o;
- if (vm->is_initializing()) {
+ if (VM::get_current()->is_initializing()) {
/* This can happen when global class variables are used which
are not initialized yet. */
classinfo *c;
java_handle_t *o;
- if (vm->is_initializing())
+ if (VM::get_current()->is_initializing())
exceptions_abort(classname, NULL);
c = load_class_bootstrap(classname);
java_handle_t *o;
classinfo *c;
- if (vm->is_initializing())
+ if (VM::get_current()->is_initializing())
exceptions_abort(classname, NULL);
c = load_class_bootstrap(classname);
classinfo *c;
java_handle_t *o;
- if (vm->is_initializing())
+ if (VM::get_current()->is_initializing())
exceptions_abort(classname, message);
c = load_class_bootstrap(classname);
classinfo *c;
methodinfo *m;
- if (vm->is_initializing())
+ if (VM::get_current()->is_initializing())
exceptions_abort(classname, NULL);
java_lang_Throwable jlt(cause);
java_handle_t *o;
methodinfo *m;
- if (vm->is_initializing())
+ if (VM::get_current()->is_initializing())
exceptions_abort(classname, NULL);
c = load_class_bootstrap(classname);
static void exceptions_throw_utf_cause(utf *classname, java_handle_t *cause)
{
- if (vm->is_initializing())
+ if (VM::get_current()->is_initializing())
exceptions_abort(classname, NULL);
java_lang_Throwable jltcause(cause);
false);
if (m == NULL)
- vm_abort("exceptions_print_stacktrace: printStackTrace()V not found");
+ VM::get_current()->abort("exceptions_print_stacktrace: printStackTrace()V not found");
/* Print message. */
fd = open("/dev/zero", O_RDONLY, 0);
if (fd == -1)
- vm_abort("os::mmap_anonymous: open failed: %s", os::strerror(errno));
+ VM::get_current()->abort_errno("os::mmap_anonymous: open failed");
p = mmap(addr, len, prot, flags, fd, 0);
#endif
#else
if (p == (void *) -1)
#endif
- vm_abort("os::mmap_anonymous: mmap failed: %s", os::strerror(errno));
+ VM::get_current()->abort_errno("os::mmap_anonymous: mmap failed");
return p;
}
break;
default:
o = NULL;
- vm_abort("primitive_box: invalid primitive type %d", type);
+ VM::get_current()->abort("primitive_box: invalid primitive type %d", type);
}
return o;
value.a = h;
break;
default:
- vm_abort("Primitive::unbox: invalid primitive type %d", type);
+ VM::get_current()->abort("Primitive::unbox: invalid primitive type %d", type);
}
return value;
if (js.is_null() || (js.get_value() == NULL)) {
/* error in hashtable found */
-
- vm_abort("stringtable_update: invalid literalstring in hashtable");
+ VM::get_current()->abort("stringtable_update: invalid literalstring in hashtable");
}
a = LLNI_UNWRAP(js.get_value());
/**
- * This is _the_ instance of the VM.
+ * This is _the_ VM instance.
*/
-VM* vm;
+VM* VM::_vm = NULL;
/* global variables ***********************************************************/
// Instantiate a new VM.
try {
- vm = new VM(_vm_args);
+ _vm = new VM(_vm_args);
}
catch (std::exception e) {
// FIXME How can we delete the resources allocated?
// FREE(env, _Jv_JNIEnv);
// FREE(vm, _Jv_JavaVM);
- vm = NULL;
+ _vm = NULL;
return false;
}
// Return the values.
- *p_vm = vm->get_javavm();
- *p_env = vm->get_jnienv();
+ *p_vm = _vm->get_javavm();
+ *p_env = _vm->get_jnienv();
return true;
}
// Make ourself globally visible.
// XXX Is this a good idea?
- vm = this;
+ _vm = this;
/* create and fill a JavaVM structure */
/* Install the exit handler. */
if (atexit(vm_exit_handler))
- vm_abort("atexit failed: %s\n", strerror(errno));
+ VM::get_current()->abort("atexit failed: %s\n", strerror(errno));
/* Set some options. */
/* install architecture dependent signal handlers */
if (!signal_init())
- vm_abort("vm_create: signal_init failed");
+ VM::get_current()->abort("vm_create: signal_init failed");
#if defined(ENABLE_INTRP)
/* Allocate main thread stack on the Java heap. */
/* AFTER: threads_preinit */
if (!string_init())
- vm_abort("vm_create: string_init failed");
+ VM::get_current()->abort("vm_create: string_init failed");
/* AFTER: threads_preinit */
/* AFTER: thread_preinit */
if (!suck_init())
- vm_abort("vm_create: suck_init failed");
+ VM::get_current()->abort("vm_create: suck_init failed");
suck_add_from_property("java.endorsed.dirs");
(must be done _after_ threads_preinit) */
if (!classcache_init())
- vm_abort("vm_create: classcache_init failed");
+ VM::get_current()->abort("vm_create: classcache_init failed");
/* Initialize the code memory management. */
/* AFTER: threads_preinit */
threads_preinit) */
if (!finalizer_init())
- vm_abort("vm_create: finalizer_init failed");
+ VM::get_current()->abort("vm_create: finalizer_init failed");
/* Initialize the JIT compiler. */
#endif
if (!builtin_init())
- vm_abort("vm_create: builtin_init failed");
+ VM::get_current()->abort("vm_create: builtin_init failed");
/* Initialize the native subsystem. */
/* BEFORE: threads_init */
if (!native_init())
- vm_abort("vm_create: native_init failed");
+ VM::get_current()->abort("vm_create: native_init failed");
/* Register the native methods implemented in the VM. */
/* BEFORE: threads_init */
(e.g. NewGlobalRef). */
if (!jni_init())
- vm_abort("vm_create: jni_init failed");
+ VM::get_current()->abort("vm_create: jni_init failed");
#endif
#if defined(ENABLE_JNI) || defined(ENABLE_HANDLES)
/* BEFORE: threads_init */
if (!localref_table_init())
- vm_abort("vm_create: localref_table_init failed");
+ VM::get_current()->abort("vm_create: localref_table_init failed");
#endif
/* Iinitialize some important system classes. */
/* initialize profiling */
if (!profile_init())
- vm_abort("vm_create: profile_init failed");
+ VM::get_current()->abort("vm_create: profile_init failed");
#endif
#if defined(ENABLE_THREADS)
/* initialize recompilation */
if (!recompile_init())
- vm_abort("vm_create: recompile_init failed");
+ VM::get_current()->abort("vm_create: recompile_init failed");
/* start the signal handler thread */
if (threads_pthreads_implementation_nptl)
#endif
if (!signal_start_thread())
- vm_abort("vm_create: signal_start_thread failed");
+ VM::get_current()->abort("vm_create: signal_start_thread failed");
/* finally, start the finalizer thread */
if (!finalizer_start_thread())
- vm_abort("vm_create: finalizer_start_thread failed");
+ VM::get_current()->abort("vm_create: finalizer_start_thread failed");
# if !defined(NDEBUG)
/* start the memory profiling thread */
if (opt_ProfileMemoryUsage || opt_ProfileGCMemoryUsage)
if (!memory_start_thread())
- vm_abort("vm_create: memory_start_thread failed");
+ VM::get_current()->abort("vm_create: memory_start_thread failed");
# endif
/* start the recompilation thread (must be done before the
profiling thread) */
if (!recompile_start_thread())
- vm_abort("vm_create: recompile_start_thread failed");
+ VM::get_current()->abort("vm_create: recompile_start_thread failed");
# if defined(ENABLE_PROFILING)
/* start the profile sampling thread */
/* if (opt_prof) */
/* if (!profile_start_thread()) */
-/* vm_abort("vm_create: profile_start_thread failed"); */
+/* VM::get_current()->abort("vm_create: profile_start_thread failed"); */
# endif
#endif
the application's main method exits. */
if (!thread_detach_current_thread())
- vm_abort("vm_run: Could not detach main thread.");
+ VM::get_current()->abort("vm_run: Could not detach main thread.");
#endif
/* Destroy the JavaVM. */
}
-/* vm_abort ********************************************************************
-
- Prints an error message and aborts the VM.
-
- IN:
- text ... error message to print
-
-*******************************************************************************/
-
-void vm_abort(const char *text, ...)
+/**
+ * Prints an error message and aborts the VM.
+ *
+ * @param text Error message to print.
+ */
+void VM::abort(const char* text, ...)
{
va_list ap;
- /* Print the log message. */
-
+ // Print the log message.
log_start();
va_start(ap, text);
log_finish();
- /* Now abort the VM. */
-
+ // Now abort the VM.
os::abort();
}
-/* vm_abort_errnum *************************************************************
-
- Prints an error message, appends ":" plus the strerror-message of
- errnum and aborts the VM.
-
- IN:
- errnum ... error number
- text ..... error message to print
-
-*******************************************************************************/
-
-void vm_abort_errnum(int errnum, const char *text, ...)
+/**
+ * Prints an error message, appends ":" plus the strerror-message of
+ * errnum and aborts the VM.
+ *
+ * @param errnum Error number.
+ * @param text Error message to print.
+ */
+void VM::abort_errnum(int errnum, const char* text, ...)
{
va_list ap;
- /* Print the log message. */
-
+ // Print the log message.
log_start();
va_start(ap, text);
log_vprint(text, ap);
va_end(ap);
- /* Print the strerror-message of errnum. */
-
+ // Print the strerror-message of errnum.
log_print(": %s", os::strerror(errnum));
log_finish();
- /* Now abort the VM. */
-
+ // Now abort the VM.
os::abort();
}
-/* vm_abort_errno **************************************************************
-
- Equal to vm_abort_errnum, but uses errno to get the error number.
-
- IN:
- text ... error message to print
-
-*******************************************************************************/
-
-void vm_abort_errno(const char *text, ...)
+/**
+ * Equal to VM::abort_errnum, but uses errno to get the error number.
+ *
+ * @param text Error message to print.
+ */
+void VM::abort_errno(const char* text, ...)
{
va_list ap;
va_start(ap, text);
- vm_abort_errnum(errno, text, ap);
+ abort_errnum(errno, text, ap);
va_end(ap);
}
pc = disassinstr((u1*) pc);
#endif
- vm_abort("Aborting...");
+ VM::get_current()->abort("Aborting...");
}
}
if (m == NULL)
- vm_abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
+ VM::get_current()->abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
opt_method, opt_signature ? opt_signature : "");
jit_compile(m);
break;
default:
- vm_abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.primitivetype);
+ VM::get_current()->abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.primitivetype);
}
/* release dump area */
extern "C" {
-JavaVM* VM_get_javavm() { return vm->get_javavm(); }
-JNIEnv* VM_get_jnienv() { return vm->get_jnienv(); }
-bool VM_is_initializing() { return vm->is_initializing(); }
-bool VM_is_created() { return vm->is_created(); }
-int64_t VM_get_starttime() { return vm->get_starttime(); }
+JavaVM* VM_get_javavm() { return VM::get_current()->get_javavm(); }
+JNIEnv* VM_get_jnienv() { return VM::get_current()->get_jnienv(); }
+bool VM_is_initializing() { return VM::get_current()->is_initializing(); }
+bool VM_is_created() { return VM::get_current()->is_created(); }
+int64_t VM_get_starttime() { return VM::get_current()->get_starttime(); }
+
+void vm_abort(const char* text, ...)
+{
+ va_list ap;
+
+ va_start(ap, text);
+ VM::get_current()->abort(text, ap);
+ va_end(ap);
+}
+
+void vm_abort_errnum(int errnum, const char* text, ...)
+{
+ va_list ap;
+
+ va_start(ap, text);
+ VM::get_current()->abort_errnum(errnum, text, ap);
+ va_end(ap);
+}
+
+void vm_abort_errno(const char* text, ...)
+{
+ va_list ap;
+
+ va_start(ap, text);
+ VM::get_current()->abort_errno(text, ap);
+ va_end(ap);
+}
}
#include <stdarg.h>
#include <stdint.h>
-#include "vm/types.h"
-
+// We need the JNI types for the VM class.
#include "native/jni.hpp"
-#include "vm/global.h"
-
-#include "vm/class.h"
-#include "vm/method.h"
-
#ifdef __cplusplus
/**
*/
class VM {
private:
+ // This is _the_ VM instance.
+ static VM* _vm;
+
// JNI variables.
JavaVM* _javavm;
JNIEnv* _jnienv;
// Static methods.
static bool create(JavaVM** p_vm, void** p_env, void* vm_args);
+ static VM* get_current() { return _vm; }
// Getters for private members.
JavaVM* get_javavm() { return _javavm; }
bool is_created() { return _created; }
bool is_exiting() { return _exiting; }
int64_t get_starttime() { return _starttime; }
-};
-
-/**
- * This is _the_ instance of the VM.
- */
-extern VM* vm;
+ // Instance functions.
+ void abort(const char* text, ...);
+ void abort_errnum(int errnum, const char* text, ...);
+ void abort_errno(const char* text, ...);
+};
#else
#endif
+
+// Includes.
+#include "vm/global.h"
+#include "vm/method.h"
+
+
/* These C methods are the exported interface. ********************************/
#ifdef __cplusplus
/* export global variables ****************************************************/
#if defined(ENABLE_INTRP)
-extern u1 *intrp_main_stack;
+extern uint8_t* intrp_main_stack;
#endif
bool vm_create(JavaVMInitArgs *vm_args);
void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args);
-s4 vm_destroy(JavaVM *vm);
-void vm_exit(s4 status);
-void vm_shutdown(s4 status);
+int32_t vm_destroy(JavaVM *vm);
+void vm_exit(int32_t status);
+void vm_shutdown(int32_t status);
void vm_exit_handler(void);
-void vm_abort(const char *text, ...);
-void vm_abort_errnum(int errnum, const char *text, ...);
-void vm_abort_errno(const char *text, ...);
void vm_abort_disassemble(void *pc, int count, const char *text, ...);
/* Java method calling functions */
java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o, java_handle_objectarray_t *params);
+
+// Legacy C interface.
+void vm_abort(const char* text, ...);
+void vm_abort_errnum(int errnum, const char* text, ...);
+void vm_abort_errno(const char* text, ...);
+
#ifdef __cplusplus
}
#endif