* src/vm/vm.hpp (VM): Added member_vm, added functions get_current,
authorChristian Thalinger <twisti@complang.tuwien.ac.at>
Thu, 14 Aug 2008 15:26:54 +0000 (17:26 +0200)
committerChristian Thalinger <twisti@complang.tuwien.ac.at>
Thu, 14 Aug 2008 15:26:54 +0000 (17:26 +0200)
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.

12 files changed:
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
src/vm/vm.cpp
src/vm/vm.hpp

index 2b4f64a725ffd397623c37a2efda2927025ace6a..f76473ee0a02f9adbb622576fdb1cfdd092b35ea 100644 (file)
@@ -240,7 +240,7 @@ void *gc_out_of_memory(size_t bytes_requested)
 
        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;
@@ -265,7 +265,7 @@ void *gc_out_of_memory(size_t bytes_requested)
  * Emacs will automagically detect them.
  * ---------------------------------------------------------------------
  * Local variables:
- * mode: c
+ * mode: c++
  * indent-tabs-mode: t
  * c-basic-offset: 4
  * tab-width: 4
index e0f5445d21b0e5dccdbc76ef24365e8ec0662485..76dbd1cfbe982e5965a260c5e97882feee155785 100644 (file)
@@ -3081,7 +3081,7 @@ jint _Jv_JNI_GetJavaVM(JNIEnv *env, JavaVM **javavm)
 {
        STATISTICS(jniinvokation());
 
-    *javavm = vm->get_javavm();
+    *javavm = VM::get_current()->get_javavm();
 
        return 0;
 }
@@ -3621,7 +3621,7 @@ jint _Jv_JNI_DestroyJavaVM(JavaVM *javavm)
 
        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);
@@ -3656,7 +3656,7 @@ static int jni_attach_current_thread(void **p_env, void *thr_args, bool isdaemon
        result = thread_current_is_attached();
 
        if (result == true) {
-               *p_env = vm->get_jnienv();
+               *p_env = VM::get_current()->get_jnienv();
                return JNI_OK;
        }
 
@@ -3675,7 +3675,7 @@ static int jni_attach_current_thread(void **p_env, void *thr_args, bool isdaemon
                return JNI_ERR;
 #endif
 
-       *p_env = vm->get_jnienv();
+       *p_env = VM::get_current()->get_jnienv();
 
        return JNI_OK;
 }
@@ -3687,7 +3687,7 @@ jint jni_AttachCurrentThread(JavaVM *javavm, void **p_env, void *thr_args)
 
        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);
@@ -3756,7 +3756,7 @@ jint jni_GetEnv(JavaVM *javavm, void **env, jint version)
 {
        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;
        }
@@ -3772,7 +3772,7 @@ jint jni_GetEnv(JavaVM *javavm, void **env, jint version)
        /* Check the JNI version. */
 
        if (jni_version_check(version) == true) {
-               *env = vm->get_jnienv();
+               *env = VM::get_current()->get_jnienv();
                return JNI_OK;
        }
 
@@ -3812,7 +3812,7 @@ jint jni_AttachCurrentThreadAsDaemon(JavaVM *javavm, void **penv, void *args)
 
        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);
@@ -4167,7 +4167,7 @@ jint JNI_GetCreatedJavaVMs(JavaVM **vmBuf, jsize bufLen, jsize *nVMs)
 
        // We currently only support 1 VM running.
 
-       vmBuf[0] = vm->get_javavm();
+       vmBuf[0] = VM::get_current()->get_javavm();
        *nVMs    = 1;
 
     return JNI_OK;
index 90dc82ca696d30362d3024172c00af5c5c381280..616cafd3a203c3e5fdd056ac8037ad8d8d0cb6ba 100644 (file)
@@ -63,6 +63,7 @@
 #ifndef _JNI_HPP
 #define _JNI_HPP
 
+#include <stdbool.h>
 #include <stdint.h>
 
 #include "vm/global.h"
index e9895020b992c8f1fc5d07d197fbc50ed5f7fcf2..347934be704d5017af22c80329f1af0ca017f755 100644 (file)
@@ -64,7 +64,7 @@ JNIEXPORT java_handle_objectarray_t* JNICALL Java_gnu_java_lang_management_VMRun
  */
 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"
index 4c8afc060baf4dcef9d333abf0f85a38cafdf241..1307195cc90dca1676b8439803057807f1b57a39 100644 (file)
@@ -63,8 +63,9 @@ inline Condition::Condition()
 
        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");
+       }
 }
 
 
@@ -77,8 +78,9 @@ inline Condition::~Condition()
 
        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");
+       }
 }
 
 
@@ -92,8 +94,9 @@ inline void Condition::broadcast()
 
        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");
+       }
 }
 
 
@@ -107,8 +110,9 @@ inline void Condition::signal()
 
        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");
+       }
 }
 
 
@@ -132,8 +136,9 @@ inline void Condition::wait(Mutex* mutex)
 
        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
index db7b2d52840cd0246d8f38a1e79d616706b61cd9..2cba5e53663fc6cd8274b6e5e3a416e1af775c77 100644 (file)
@@ -72,19 +72,19 @@ inline Mutex::Mutex()
        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");
        }
 }
 
@@ -97,13 +97,13 @@ inline Mutex::~Mutex()
        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");
        }
 }
 
@@ -122,7 +122,7 @@ inline void Mutex::lock()
        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");
        }
 }
 
@@ -136,7 +136,7 @@ inline void Mutex::unlock()
        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");
        }
 }
 
index c70c7980331828983de36196329bbf0b1dea3273..c547f5486c818efd083cdb9f3b642906cbb68ce7 100644 (file)
@@ -241,7 +241,7 @@ static void exceptions_abort(utf *classname, utf *message)
 
        log_finish();
 
-       vm_abort("Aborting...");
+       VM::get_current()->abort("Aborting...");
 }
 
 
@@ -266,7 +266,7 @@ static java_handle_t *exceptions_new_class_utf(classinfo *c, utf *message)
        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. */
 
@@ -304,7 +304,7 @@ static java_handle_t *exceptions_new_utf(utf *classname)
        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);
@@ -342,7 +342,7 @@ static java_handle_t *exceptions_new_utf_javastring(utf *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);
@@ -379,7 +379,7 @@ static java_handle_t *exceptions_new_utf_utf(utf *classname, utf *message)
        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);
@@ -454,7 +454,7 @@ static void exceptions_throw_utf_throwable(utf *classname,
        classinfo           *c;
        methodinfo          *m;
 
-       if (vm->is_initializing())
+       if (VM::get_current()->is_initializing())
                exceptions_abort(classname, NULL);
 
        java_lang_Throwable jlt(cause);
@@ -506,7 +506,7 @@ static void exceptions_throw_utf_exception(utf *classname,
        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);
@@ -551,7 +551,7 @@ static void exceptions_throw_utf_exception(utf *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);
@@ -2011,7 +2011,7 @@ void exceptions_print_stacktrace(void)
                                                                         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. */
 
index 0c920a86798c185cee2a7b6bfd72a8fbb707eb2f..6eaf41f860c8a6bbf8b74a393c2bd4bea93aefc0 100644 (file)
@@ -84,7 +84,7 @@ void* os::mmap_anonymous(void *addr, size_t len, int prot, int flags)
        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
@@ -94,7 +94,7 @@ void* os::mmap_anonymous(void *addr, size_t len, int prot, int flags)
 #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;
 }
index e20334cc00efa591e414675fdad59f68b428fd9e..ae64eb8272895e923184baec8370ee610a2b2940 100644 (file)
@@ -226,7 +226,7 @@ java_handle_t* Primitive::box(int type, imm_union value)
                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;
@@ -287,7 +287,7 @@ imm_union Primitive::unbox(java_handle_t *h)
                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;
index a6b7c08c3c1024cfd2735adf4d1785415e63e8f0..3267c9285ad98acbe007e9ca9abba9910d148971 100644 (file)
@@ -107,8 +107,7 @@ void stringtable_update(void)
                                
                                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());
index d7966f300f9b358dc5137c713a8db7d814f422e5..7a8c2222513522fc1e5562266430d4d0f13849aa 100644 (file)
 
 
 /**
- * This is _the_ instance of the VM.
+ * This is _the_ VM instance.
  */
-VM* vm;
+VM* VM::_vm = NULL;
 
 
 /* global variables ***********************************************************/
@@ -681,7 +681,7 @@ bool VM::create(JavaVM** p_vm, void** p_env, void* vm_args)
 
        // 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?
@@ -689,15 +689,15 @@ bool VM::create(JavaVM** p_vm, void** p_env, void* vm_args)
 //             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;
 }
@@ -724,7 +724,7 @@ VM::VM(JavaVMInitArgs* vm_args)
 
        // Make ourself globally visible.
        // XXX Is this a good idea?
-       vm = this;
+       _vm = this;
 
        /* create and fill a JavaVM structure */
 
@@ -775,7 +775,7 @@ VM::VM(JavaVMInitArgs* vm_args)
        /* 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. */
 
@@ -1396,7 +1396,7 @@ VM::VM(JavaVMInitArgs* vm_args)
        /* 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. */
@@ -1410,7 +1410,7 @@ VM::VM(JavaVMInitArgs* vm_args)
        /* 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 */
 
@@ -1419,7 +1419,7 @@ VM::VM(JavaVMInitArgs* vm_args)
        /* 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");
 
@@ -1441,7 +1441,7 @@ VM::VM(JavaVMInitArgs* vm_args)
           (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 */
@@ -1452,7 +1452,7 @@ VM::VM(JavaVMInitArgs* vm_args)
           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. */
 
@@ -1490,13 +1490,13 @@ VM::VM(JavaVMInitArgs* vm_args)
 #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 */
@@ -1509,7 +1509,7 @@ VM::VM(JavaVMInitArgs* vm_args)
           (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)
@@ -1517,7 +1517,7 @@ VM::VM(JavaVMInitArgs* vm_args)
        /* 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. */
@@ -1538,14 +1538,14 @@ VM::VM(JavaVMInitArgs* vm_args)
        /* 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 */
 
@@ -1554,33 +1554,33 @@ VM::VM(JavaVMInitArgs* vm_args)
        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
 
@@ -1800,7 +1800,7 @@ void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
           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. */
@@ -1998,21 +1998,16 @@ void vm_exit_handler(void)
 }
 
 
-/* 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);
@@ -2021,62 +2016,50 @@ void vm_abort(const char *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);
 }
 
@@ -2127,7 +2110,7 @@ void vm_abort_disassemble(void *pc, int count, const char *text, ...)
                pc = disassinstr((u1*) pc);
 #endif
 
-       vm_abort("Aborting...");
+       VM::get_current()->abort("Aborting...");
 }
 
 
@@ -2368,7 +2351,7 @@ static void vm_compile_method(char* mainname)
        }
 
        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);
@@ -2615,7 +2598,7 @@ java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
                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 */
@@ -2651,11 +2634,38 @@ java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
 
 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);
+}
 
 }
 
index 751de80a295a7e54c3f7c30a3b17d824ea225119..4375150f20ffebcb213a3da2b96b2e3a43598193 100644 (file)
 #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
 
 /**
@@ -47,6 +41,9 @@
  */
 class VM {
 private:
+       // This is _the_ VM instance.
+       static VM* _vm;
+
        // JNI variables.
        JavaVM* _javavm;
        JNIEnv* _jnienv;
@@ -64,6 +61,7 @@ public:
 
        // 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; }
@@ -72,13 +70,12 @@ public:
        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
 
@@ -90,6 +87,12 @@ int64_t VM_get_starttime();
 
 #endif
 
+
+// Includes.
+#include "vm/global.h"
+#include "vm/method.h"
+
+
 /* These C methods are the exported interface. ********************************/
 
 #ifdef __cplusplus
@@ -106,7 +109,7 @@ bool VM_create(JavaVM** p_vm, void** p_env, void* vm_args);
 /* export global variables ****************************************************/
 
 #if defined(ENABLE_INTRP)
-extern u1 *intrp_main_stack;
+extern uint8_t* intrp_main_stack;
 #endif
 
 
@@ -120,15 +123,12 @@ void usage(void);
 
 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 */
@@ -157,6 +157,12 @@ double  vm_call_method_double_jvalue(methodinfo *m, java_handle_t *o, const jval
 
 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