#include "mm/gc.hpp"
#include "mm/memory.h"
-#include "native/jni.h"
+#include "native/jni.hpp"
#include "native/llni.h"
#include "native/localref.h"
#include "native/native.h"
-#include "native/include/java_lang_Object.h" /* required by j.l.C */
-#include "native/include/java_lang_String.h" /* required by j.l.C */
-
-#if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
-# include "native/include/java_nio_ByteBuffer.h" /* required by j.l.CL */
-# include "native/include/java_lang_ClassLoader.h" /* required by j.l.C */
-#endif
-
-#include "native/include/java_lang_Class.h"
-
#include "native/vm/nativevm.h"
#include "threads/lock-common.h"
#endif
#include "vm/builtin.h"
+#include "vm/classcache.h"
#include "vm/exceptions.hpp"
#include "vm/finalizer.h"
#include "vm/global.h"
+#include "vm/globals.hpp"
#include "vm/initialize.h"
+#include "vm/options.h"
+#include "vm/os.hpp"
#include "vm/package.hpp"
#include "vm/primitive.hpp"
#include "vm/properties.h"
#include "vm/signallocal.h"
+#include "vm/statistics.h"
#include "vm/string.hpp"
+#include "vm/suck.h"
#include "vm/vm.hpp"
#include "vm/jit/argument.h"
# include "vm/jit/disass.h"
#endif
-#include "vm/jit/jit.h"
+#include "vm/jit/jit.hpp"
#include "vm/jit/methodtree.h"
#if defined(ENABLE_PROFILING)
#include "vm/jit/trap.h"
-#include "vmcore/classcache.h"
-#include "vmcore/globals.hpp"
-#include "vmcore/options.h"
-#include "vmcore/statistics.h"
-#include "vmcore/suck.h"
-#include "vmcore/os.hpp"
-
#if defined(ENABLE_JVMTI)
# include "native/jvmti/cacaodbg.h"
#endif
/**
- * This is _the_ instance of the VM.
+ * This is _the_ VM instance.
*/
-VM* vm;
+VM* VM::_vm = NULL;
/* global variables ***********************************************************/
}
-static void vm_printconfig(void)
-{
- puts("Configure/Build options:\n");
- puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
-#if defined(__VERSION__)
- puts(" CC : "VERSION_CC" ("__VERSION__")");
-#else
- puts(" CC : "VERSION_CC"");
-#endif
- puts(" CFLAGS : "VERSION_CFLAGS"\n");
-
- puts("Default variables:\n");
- printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
- printf(" initial heap size : %d\n", HEAP_STARTSIZE);
- printf(" stack size : %d\n", STACK_SIZE);
-
-#if defined(ENABLE_JRE_LAYOUT)
- /* When we're building with JRE-layout, the default paths are the
- same as the runtime paths. */
-#else
-# if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
- puts(" gnu.classpath.boot.library.path: "JAVA_RUNTIME_LIBRARY_LIBDIR);
- puts(" java.boot.class.path : "CACAO_VM_ZIP":"JAVA_RUNTIME_LIBRARY_CLASSES"");
-# elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
- puts(" sun.boot.library.path : "JAVA_RUNTIME_LIBRARY_LIBDIR);
- puts(" java.boot.class.path : "JAVA_RUNTIME_LIBRARY_CLASSES);
-# endif
-#endif
-
- puts("");
-
- puts("Runtime variables:\n");
- printf(" maximum heap size : %d\n", opt_heapmaxsize);
- printf(" initial heap size : %d\n", opt_heapstartsize);
- printf(" stack size : %d\n", opt_stacksize);
-
-#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
- printf(" gnu.classpath.boot.library.path: %s\n", properties_get("gnu.classpath.boot.library.path"));
-#elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
- printf(" sun.boot.library.path : %s\n", properties_get("sun.boot.library.path"));
-#endif
-
- printf(" java.boot.class.path : %s\n", properties_get("java.boot.class.path"));
- printf(" java.class.path : %s\n", properties_get("java.class.path"));
-}
-
-
/* forward declarations *******************************************************/
static char *vm_get_mainclass_from_jar(char *mainstring);
// 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. */
properties_init();
- /* First of all, parse the -XX options. */
+ // First of all, parse the -XX options.
#if defined(ENABLE_VMLOG)
vmlog_cacao_init_options();
options_xx(vm_args);
+ // After -XX options are parsed, print the build-time
+ // configuration, if requested.
+ if (opt_PrintConfig)
+ print_build_time_config();
+
#if defined(ENABLE_VMLOG)
vmlog_cacao_init();
#endif
/* We need to check if the actual size of a java.lang.Class object
is smaller or equal than the assumption made in
- src/vmcore/class.h. */
+ src/vm/class.h. */
- if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
- vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
+#warning FIXME We need to check the size of java.lang.Class!!!
+// if (sizeof(java_lang_Class) > sizeof(dummy_java_lang_Class))
+// vm_abort("vm_create: java_lang_Class structure is bigger than classinfo.object (%d > %d)", sizeof(java_lang_Class), sizeof(dummy_java_lang_Class));
/* set the VM starttime */
opt_showdisassemble = true;
compileverbose = true;
break;
-
- case 'o':
- opt_shownops = true;
- break;
#endif
case 'd':
}
}
+ // Print the preliminary run-time VM configuration after options
+ // are parsed.
+ if (opt_PrintConfig)
+ print_run_time_config();
+
#if defined(ENABLE_JVMTI)
if (jvmti) {
jvmti_set_phase(JVMTI_PHASE_ONLOAD);
/* 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. */
loader_preinit();
linker_preinit();
- /* AFTER: loader_preinit, linker_preinit */
-
- primitive_init();
+ // AFTER: loader_preinit, linker_preinit
+ Primitive::initialize_table();
loader_init();
linker_init();
- /* AFTER: loader_init, linker_init */
-
- primitive_postinit();
+ // AFTER: loader_init, linker_init
+ Primitive::post_initialize_table();
method_init();
#if defined(ENABLE_JIT)
#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
_created = true;
_initializing = false;
- /* Print the VM configuration after all stuff is set and the VM is
- initialized. */
-
+ // Print the run-time VM configuration after all stuff is set and
+ // the VM is initialized.
if (opt_PrintConfig)
- vm_printconfig();
+ print_run_time_config();
+}
+
+
+/**
+ * Print build-time (default) VM configuration.
+ */
+void VM::print_build_time_config(void)
+{
+ puts("CACAO "VERSION" configure/build options:");
+ puts("");
+ puts(" ./configure: "VERSION_CONFIGURE_ARGS"");
+#if defined(__VERSION__)
+ puts(" CC : "VERSION_CC" ("__VERSION__")");
+ puts(" CXX : "VERSION_CXX" ("__VERSION__")");
+#else
+ puts(" CC : "VERSION_CC"");
+ puts(" CXX : "VERSION_CXX"");
+#endif
+ puts(" CFLAGS : "VERSION_CFLAGS"");
+ puts(" CXXFLAGS : "VERSION_CXXFLAGS"");
+
+ puts("");
+
+ puts("Build-time (default) variables:\n");
+ printf(" maximum heap size : %d\n", HEAP_MAXSIZE);
+ printf(" initial heap size : %d\n", HEAP_STARTSIZE);
+ printf(" stack size : %d\n", STACK_SIZE);
+
+#if defined(ENABLE_JRE_LAYOUT)
+ // When we're building with JRE-layout, the default paths are the
+ // same as the runtime paths.
+#else
+# if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
+ puts(" gnu.classpath.boot.library.path: "JAVA_RUNTIME_LIBRARY_LIBDIR);
+ puts(" java.boot.class.path : "CACAO_VM_ZIP":"JAVA_RUNTIME_LIBRARY_CLASSES"");
+# elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
+ puts(" sun.boot.library.path : "JAVA_RUNTIME_LIBRARY_LIBDIR);
+ puts(" java.boot.class.path : "JAVA_RUNTIME_LIBRARY_CLASSES);
+# endif
+#endif
+
+ puts("");
+}
+
+
+/**
+ * Print run-time VM configuration.
+ */
+void VM::print_run_time_config(void)
+{
+ puts("Run-time variables:\n");
+ printf(" maximum heap size : %d\n", opt_heapmaxsize);
+ printf(" initial heap size : %d\n", opt_heapstartsize);
+ printf(" stack size : %d\n", opt_stacksize);
+
+#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
+ printf(" gnu.classpath.boot.library.path: %s\n", properties_get("gnu.classpath.boot.library.path"));
+#elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
+ printf(" sun.boot.library.path : %s\n", properties_get("sun.boot.library.path"));
+#endif
+
+ printf(" java.boot.class.path : %s\n", properties_get("java.boot.class.path"));
+ printf(" java.class.path : %s\n", properties_get("java.class.path"));
+
+ puts("");
}
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. */
+ // Print a backtrace.
+ os::print_backtrace();
+ // 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. */
+ // Print a backtrace.
+ os::print_backtrace();
+ // 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);
+}
}