* src/vm/properties.c: Moved to .cpp.
[cacao.git] / src / vm / vm.cpp
index 7a8c2222513522fc1e5562266430d4d0f13849aa..9e1bb905c86441036433e5d68213acf7f2cbde22 100644 (file)
@@ -41,6 +41,7 @@
 #include "vm/jit/abi-asm.h"
 
 #include "mm/codememory.h"
+#include "mm/dumpmemory.hpp"
 #include "mm/gc.hpp"
 #include "mm/memory.h"
 
@@ -63,7 +64,7 @@
 #include "vm/assertion.h"
 #endif
 
-#include "vm/builtin.h"
+#include "vm/jit/builtin.hpp"
 #include "vm/classcache.h"
 #include "vm/exceptions.hpp"
 #include "vm/finalizer.h"
@@ -72,9 +73,8 @@
 #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/properties.hpp"
 #include "vm/signallocal.h"
 #include "vm/statistics.h"
 #include "vm/string.hpp"
@@ -89,7 +89,7 @@
 # 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)
@@ -606,53 +606,6 @@ static void fullversion(void)
 }
 
 
-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);
@@ -788,12 +741,7 @@ VM::VM(JavaVMInitArgs* vm_args)
        opt_heapstartsize = HEAP_STARTSIZE;
        opt_stacksize     = STACK_SIZE;
 
-       /* Initialize the properties list before command-line handling.
-          Otherwise -XX:+PrintConfig crashes. */
-
-       properties_init();
-
-       /* First of all, parse the -XX options. */
+       // First of all, parse the -XX options.
 
 #if defined(ENABLE_VMLOG)
        vmlog_cacao_init_options();
@@ -801,6 +749,11 @@ VM::VM(JavaVMInitArgs* vm_args)
 
        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
@@ -822,10 +775,6 @@ VM::VM(JavaVMInitArgs* vm_args)
        jvmti = false;
 #endif
 
-       /* Fill the properties before command-line handling. */
-
-       properties_set();
-
        /* iterate over all passed options */
 
        while ((opt = options_get(opts, vm_args)) != OPT_DONE) {
@@ -860,14 +809,14 @@ VM::VM(JavaVMInitArgs* vm_args)
                           classpath. */
 
                        // FIXME Make class_path const char*.
-                       class_path = (char*) properties_get("java.class.path");
+                       class_path = (char*) _properties.get("java.class.path");
 
                        p = MNEW(char, strlen(opt_arg) + strlen("0"));
 
                        strcpy(p, opt_arg);
 
 #if defined(ENABLE_JAVASE)
-                       properties_add("java.class.path", p);
+                       _properties.put("java.class.path", p);
 #endif
 
                        MFREE(class_path, char, strlen(class_path));
@@ -877,14 +826,14 @@ VM::VM(JavaVMInitArgs* vm_args)
                        for (unsigned int i = 0; i < strlen(opt_arg); i++) {
                                if (opt_arg[i] == '=') {
                                        opt_arg[i] = '\0';
-                                       properties_add(opt_arg, opt_arg + i + 1);
+                                       _properties.put(opt_arg, opt_arg + i + 1);
                                        goto opt_d_done;
                                }
                        }
 
                        /* if no '=' is given, just create an empty property */
 
-                       properties_add(opt_arg, "");
+                       _properties.put(opt_arg, "");
 
                opt_d_done:
                        break;
@@ -894,14 +843,14 @@ VM::VM(JavaVMInitArgs* vm_args)
                           new boot classpath. */
 
                        // FIXME Make boot_class_path const char*.
-                       boot_class_path = (char*) properties_get("sun.boot.class.path");
+                       boot_class_path = (char*) _properties.get("sun.boot.class.path");
 
                        p = MNEW(char, strlen(opt_arg) + strlen("0"));
 
                        strcpy(p, opt_arg);
 
-                       properties_add("sun.boot.class.path", p);
-                       properties_add("java.boot.class.path", p);
+                       _properties.put("sun.boot.class.path", p);
+                       _properties.put("java.boot.class.path", p);
 
                        MFREE(boot_class_path, char, strlen(boot_class_path));
                        break;
@@ -910,7 +859,7 @@ VM::VM(JavaVMInitArgs* vm_args)
                        /* Append to bootclasspath. */
 
                        // FIXME Make boot_class_path const char*.
-                       boot_class_path = (char*) properties_get("sun.boot.class.path");
+                       boot_class_path = (char*) _properties.get("sun.boot.class.path");
 
                        len = strlen(boot_class_path);
 
@@ -924,15 +873,15 @@ VM::VM(JavaVMInitArgs* vm_args)
                        strcat(p, ":");
                        strcat(p, opt_arg);
 
-                       properties_add("sun.boot.class.path", p);
-                       properties_add("java.boot.class.path", p);
+                       _properties.put("sun.boot.class.path", p);
+                       _properties.put("java.boot.class.path", p);
                        break;
 
                case OPT_BOOTCLASSPATH_P:
                        /* Prepend to bootclasspath. */
 
                        // FIXME Make boot_class_path const char*.
-                       boot_class_path = (char*) properties_get("sun.boot.class.path");
+                       boot_class_path = (char*) _properties.get("sun.boot.class.path");
 
                        len = strlen(boot_class_path);
 
@@ -942,8 +891,8 @@ VM::VM(JavaVMInitArgs* vm_args)
                        strcat(p, ":");
                        strcat(p, boot_class_path);
 
-                       properties_add("sun.boot.class.path", p);
-                       properties_add("java.boot.class.path", p);
+                       _properties.put("sun.boot.class.path", p);
+                       _properties.put("java.boot.class.path", p);
 
                        MFREE(boot_class_path, char, len);
                        break;
@@ -953,7 +902,7 @@ VM::VM(JavaVMInitArgs* vm_args)
                           classes. */
 
                        // FIXME Make boot_class_path const char*.
-                       boot_class_path = (char*) properties_get("sun.boot.class.path");
+                       boot_class_path = (char*) _properties.get("sun.boot.class.path");
 
                        len =
                                strlen(CACAO_VM_ZIP) +
@@ -967,8 +916,8 @@ VM::VM(JavaVMInitArgs* vm_args)
                        strcat(p, ":");
                        strcat(p, opt_arg);
 
-                       properties_add("sun.boot.class.path", p);
-                       properties_add("java.boot.class.path", p);
+                       _properties.put("sun.boot.class.path", p);
+                       _properties.put("java.boot.class.path", p);
 
                        MFREE(boot_class_path, char, strlen(boot_class_path));
                        break;
@@ -1366,6 +1315,11 @@ VM::VM(JavaVMInitArgs* vm_args)
                }
        }
 
+       // 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);
@@ -1434,7 +1388,7 @@ VM::VM(JavaVMInitArgs* vm_args)
        /* AFTER: utf8_init */
 
        // FIXME Make boot_class_path const char*.
-       boot_class_path = (char*) properties_get("sun.boot.class.path");
+       boot_class_path = (char*) _properties.get("sun.boot.class.path");
        suck_add(boot_class_path);
 
        /* initialize the classcache hashtable stuff: lock, hashtable
@@ -1464,25 +1418,19 @@ VM::VM(JavaVMInitArgs* vm_args)
        pythonpass_init();
 #endif
 
-       /* BEFORE: loader_preinit */
-
-       Package::initialize();
-
        /* AFTER: utf8_init, classcache_init */
 
        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)
@@ -1603,11 +1551,75 @@ VM::VM(JavaVMInitArgs* vm_args)
        _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()
+{
+       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("");
 }
 
 
@@ -1660,7 +1672,7 @@ void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
                        strcpy(p, mainname);
 
 #if defined(ENABLE_JAVASE)
-                       properties_add("java.class.path", p);
+                       VM::get_current()->get_properties().put("java.class.path", p);
 #endif
                }
                else {
@@ -2016,6 +2028,9 @@ void VM::abort(const char* text, ...)
 
        log_finish();
 
+       // Print a backtrace.
+       os::print_backtrace();
+
        // Now abort the VM.
        os::abort();
 }
@@ -2044,6 +2059,9 @@ void VM::abort_errnum(int errnum, const char* text, ...)
 
        log_finish();
 
+       // Print a backtrace.
+       os::print_backtrace();
+
        // Now abort the VM.
        os::abort();
 }
@@ -2453,19 +2471,18 @@ type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o,     \
 {                                                                       \
        uint64_t *array;                                                    \
        type      value;                                                    \
-       int32_t   dumpmarker;                                               \
                                                                         \
        if (m->code == NULL)                                                \
                if (!jit_compile(m))                                            \
                        return 0;                                                   \
                                                                         \
        THREAD_NATIVEWORLD_EXIT;                                            \
-       DMARKER;                                                            \
+                                                                                                                                               \
+       DumpMemoryArea dma;                                                                                                     \
                                                                         \
        array = argument_vmarray_from_valist(m, o, ap);                     \
        value = vm_call##name##_array(m, array);                            \
                                                                         \
-       DRELEASE;                                                           \
        THREAD_NATIVEWORLD_ENTER;                                           \
                                                                         \
        return value;                                                       \
@@ -2491,19 +2508,18 @@ type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o,     \
 {                                                                       \
        uint64_t *array;                                                    \
        type      value;                                                    \
-       int32_t   dumpmarker;                                               \
                                                                         \
        if (m->code == NULL)                                                \
                if (!jit_compile(m))                                            \
                        return 0;                                                   \
                                                                         \
        THREAD_NATIVEWORLD_EXIT;                                            \
-       DMARKER;                                                            \
+                                                                                                                                               \
+       DumpMemoryArea dma;                                                                                                     \
                                                                         \
        array = argument_vmarray_from_jvalue(m, o, args);                   \
        value = vm_call##name##_array(m, array);                            \
                                                                         \
-       DRELEASE;                                                           \
        THREAD_NATIVEWORLD_ENTER;                                           \
                                                                         \
        return value;                                                       \
@@ -2530,7 +2546,6 @@ java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
        java_handle_t *xptr;
        java_handle_t *ro;
        imm_union      value;
-       int32_t        dumpmarker;
 
        /* Prevent compiler warnings. */
 
@@ -2546,19 +2561,14 @@ java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
 
        THREAD_NATIVEWORLD_EXIT;
 
-       /* mark start of dump memory area */
-
-       DMARKER;
+       // Create new dump memory area.
+       DumpMemoryArea dma;
 
        /* Fill the argument array from a object-array. */
 
        array = argument_vmarray_from_objectarray(m, o, params);
 
        if (array == NULL) {
-               /* release dump area */
-
-               DRELEASE;
-
                /* enter the nativeworld again */
 
                THREAD_NATIVEWORLD_ENTER;
@@ -2601,10 +2611,6 @@ java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
                VM::get_current()->abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.primitivetype);
        }
 
-       /* release dump area */
-
-       DRELEASE;
-
        /* enter the nativeworld again */
 
        THREAD_NATIVEWORLD_ENTER;