* src/vm/options.h, src/vm/method.c, src/vm/jit/inline/inline.c,
[cacao.git] / src / vm / vm.c
index 875e8d060831dbf4e72cb7d24a42bf932ee029e8..c280c59a8e116443b7a55154f0430c6e25b353de 100644 (file)
@@ -1,6 +1,6 @@
 /* src/vm/vm.c - VM startup and shutdown functions
 
-   Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+   Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
    J. Wenninger, Institut f. Computersprachen - TU Wien
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   Contact: cacao@cacaojvm.org
-
-   Authors: Christian Thalinger
-
-   Changes: Martin Platter
-
    $Id: vm.c 4357 2006-01-22 23:33:38Z twisti $
 
 */
 #include <errno.h>
 #include <stdlib.h>
 
+#if defined(WITH_JRE_LAYOUT)
+# include <libgen.h>
+# include <unistd.h>
+#endif
+
 #include "vm/types.h"
 
-#include "mm/boehm.h"
+#include "mm/gc-common.h"
 #include "mm/memory.h"
 #include "native/jni.h"
 #include "native/native.h"
@@ -57,6 +56,7 @@
 #include "vm/initialize.h"
 #include "vm/options.h"
 #include "vm/properties.h"
+#include "vm/rt-timing.h"
 #include "vm/signallocal.h"
 #include "vm/stringlocal.h"
 #include "vm/suck.h"
 #include "vm/jit/jit.h"
 #include "vm/jit/asmpart.h"
 
-#include "vm/jit/recompile.h"
+#if defined(ENABLE_PROFILING)
+# include "vm/jit/optimizing/profile.h"
+#endif
 
-#include "vm/jit/profile/profile.h"
-#include "vm/rt-timing.h"
+#include "vm/jit/optimizing/recompile.h"
 
 #if defined(ENABLE_JVMTI)
-#include "native/jvmti/cacaodbg.h"
+# include "native/jvmti/cacaodbg.h"
 #endif
 
 
@@ -87,11 +88,15 @@ s4 vms = 0;                             /* number of VMs created              */
 bool vm_initializing = false;
 bool vm_exiting = false;
 
-#if defined(ENABLE_INTRP)
-u1 *intrp_main_stack = NULL;
-#endif
+char      *cacao_prefix = NULL;
+char      *cacao_libjvm = NULL;
+char      *classpath_libdir = NULL;
 
-char *mainstring = NULL;
+char      *_Jv_bootclasspath;           /* contains the boot classpath        */
+char      *_Jv_classpath;               /* contains the classpath             */
+char      *_Jv_java_library_path;
+
+char      *mainstring = NULL;
 classinfo *mainclass = NULL;
 
 char *specificmethodname = NULL;
@@ -99,6 +104,10 @@ char *specificsignature = NULL;
 
 bool startit = true;
 
+#if defined(ENABLE_INTRP)
+u1 *intrp_main_stack = NULL;
+#endif
+
 
 /* define heap sizes **********************************************************/
 
@@ -130,6 +139,7 @@ enum {
 
        OPT_HELP,
        OPT_X,
+       OPT_XX,
 
        OPT_ESA,
        OPT_DSA,
@@ -143,10 +153,12 @@ enum {
        OPT_BOOTCLASSPATH_A,
        OPT_BOOTCLASSPATH_P,
 
-       OPT_GLIBJ,
+       OPT_BOOTCLASSPATH_C,
 
+#if defined(ENABLE_PROFILING)
        OPT_PROF,
        OPT_PROF_OPTION,
+#endif
 
        OPT_MS,
        OPT_MX,
@@ -198,7 +210,18 @@ enum {
 
 #if defined(ENABLE_INLINING)
        OPT_INLINING,
-#endif
+#if !defined(NDEBUG)
+       OPT_INLINE_LOG,
+#endif
+#if defined(ENABLE_INLINING_DEBUG)
+       OPT_INLINE_DEBUG_ALL,
+       OPT_INLINE_DEBUG_END,
+       OPT_INLINE_DEBUG_MIN,
+       OPT_INLINE_DEBUG_MAX,
+       OPT_INLINE_REPLACE_VERBOSE,
+       OPT_INLINE_REPLACE_VERBOSE2,
+#endif /* defined(ENABLE_INLINING_DEBUG) */
+#endif /* defined(ENABLE_INLINING) */
 
 #if defined(ENABLE_INTRP)
        /* interpreter options */
@@ -247,6 +270,7 @@ opt_struct opts[] = {
        { "help",              false, OPT_HELP },
        { "?",                 false, OPT_HELP },
        { "X",                 false, OPT_X },
+       { "XX",                false, OPT_XX },
 
        { "esa",                     false, OPT_ESA },
        { "enablesystemassertions",  false, OPT_ESA },
@@ -314,7 +338,7 @@ opt_struct opts[] = {
        { "Xbootclasspath:",   true,  OPT_BOOTCLASSPATH },
        { "Xbootclasspath/a:", true,  OPT_BOOTCLASSPATH_A },
        { "Xbootclasspath/p:", true,  OPT_BOOTCLASSPATH_P },
-       { "Xglibj:",           true,  OPT_GLIBJ },
+       { "Xbootclasspath/c:", true,  OPT_BOOTCLASSPATH_C },
 
 #ifdef ENABLE_JVMTI
        { "Xdebug",            false, OPT_DEBUG },
@@ -328,14 +352,30 @@ opt_struct opts[] = {
        { "mx",                true,  OPT_MX },
        { "Xss",               true,  OPT_SS },
        { "ss",                true,  OPT_SS },
+
+#if defined(ENABLE_PROFILING)
        { "Xprof:",            true,  OPT_PROF_OPTION },
        { "Xprof",             false, OPT_PROF },
+#endif
 
-       /* keep these at the end of the list */
+       /* inlining options */
 
 #if defined(ENABLE_INLINING)
-       { "i",                 true,  OPT_INLINING },
+#if defined(ENABLE_INLINING_DEBUG)
+       { "ia",                false, OPT_INLINE_DEBUG_ALL },
+       { "ii",                true,  OPT_INLINE_DEBUG_MIN },
+       { "im",                true,  OPT_INLINE_DEBUG_MAX },
+       { "ie",                true,  OPT_INLINE_DEBUG_END },
+       { "ir",                false, OPT_INLINE_REPLACE_VERBOSE },
+       { "iR",                false, OPT_INLINE_REPLACE_VERBOSE2 },
+#endif /* defined(ENABLE_INLINING_DEBUG) */
+#if !defined(NDEBUG)
+       { "il",                false, OPT_INLINE_LOG },
 #endif
+       { "i",                 false, OPT_INLINING },
+#endif /* defined(ENABLE_INLINING) */
+
+       /* keep these at the end of the list */
 
 #if !defined(NDEBUG)
        { "m",                 true,  OPT_METHOD },
@@ -361,7 +401,7 @@ void usage(void)
        puts("   or  cacao [-options] -jar jarfile [arguments]");
        puts("               (to run a standalone jar file)\n");
 
-       puts("Java options:");
+       puts("where options include:");
        puts("    -d32                     use 32-bit data model if available");
        puts("    -d64                     use 64-bit data model if available");
        puts("    -client                  compatibility (currently ignored)");
@@ -378,11 +418,11 @@ void usage(void)
        puts("    -showversion             print product version and continue");
        puts("    -help, -?                print this help message");
        puts("    -X                       print help on non-standard Java options");
+       puts("    -XX                      print help on CACAO options");
        puts("    -esa | -enablesystemassertions");
        puts("                             enable system assertions");
        puts("    -dsa | -disablesystemassertions");
        puts("                             disable system assertions");
-       puts("");
 
 #ifdef ENABLE_JVMTI
        puts("    -agentlib:<agent-lib-name>=<options>  library to load containg JVMTI agent");
@@ -390,7 +430,53 @@ void usage(void)
        puts("    -agentpath:<path-to-agent>=<options>  path to library containg JVMTI agent");
 #endif
 
-       puts("CACAO options:");
+       /* exit with error code */
+
+       exit(1);
+}   
+
+
+static void Xusage(void)
+{
+#if defined(ENABLE_JIT)
+       puts("    -Xjit                    JIT mode execution (default)");
+#endif
+#if defined(ENABLE_INTRP)
+       puts("    -Xint                    interpreter mode execution");
+#endif
+       puts("    -Xbootclasspath:<zip/jar files and directories separated by :>");
+    puts("                             value is set as bootstrap class path");
+       puts("    -Xbootclasspath/a:<zip/jar files and directories separated by :>");
+       puts("                             value is appended to the bootstrap class path");
+       puts("    -Xbootclasspath/p:<zip/jar files and directories separated by :>");
+       puts("                             value is prepended to the bootstrap class path");
+       puts("    -Xbootclasspath/c:<zip/jar files and directories separated by :>");
+       puts("                             value is used as Java core library, but the");
+       puts("                             hardcoded VM interface classes are prepended");
+       printf("    -Xms<size>               set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
+       printf("    -Xmx<size>               set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
+       printf("    -Xss<size>               set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
+
+#if defined(ENABLE_PROFILING)
+       puts("    -Xprof[:bb]              collect and print profiling data");
+#endif
+
+#if defined(ENABLE_JVMTI)
+    /* -Xdebug option depend on gnu classpath JDWP options. options: 
+        transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
+       puts("    -Xdebug                  enable remote debugging\n");
+       puts("    -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
+       puts("                             enable remote debugging\n");
+#endif 
+
+       /* exit with error code */
+
+       exit(1);
+}   
+
+
+static void XXusage(void)
+{
        puts("    -v                       write state-information");
        puts("    -verbose[:call|exception|jit]");
        puts("                             enable specific verbose output");
@@ -423,24 +509,34 @@ void usage(void)
        puts("    -sig                     specify signature for a specific method");
 #endif
 
-       puts("    -s(how)...               show...");
-       puts("           c(onstants)       the constant pool");
-       puts("           m(ethods)         class fields and methods");
-       puts("           u(tf)             the utf - hash");
-       puts("           i(ntermediate)    intermediate representation");
+       puts("    -s...                    show...");
+       puts("      (c)onstants            the constant pool");
+       puts("      (m)ethods              class fields and methods");
+       puts("      (u)tf                  the utf - hash");
+       puts("      (i)ntermediate         intermediate representation");
 #if defined(ENABLE_DISASSEMBLER)
-       puts("           a(ssembler)       disassembled listing");
-       puts("           e(xceptionstubs)  disassembled exception stubs (only with -sa)");
-       puts("           n(ative)          disassembled native stubs");
+       puts("      (a)ssembler            disassembled listing");
+       puts("      n(o)ps                 show NOPs in disassembler output");
+       puts("      (e)xceptionstubs       disassembled exception stubs (only with -sa)");
+       puts("      (n)ative               disassembled native stubs");
 #endif
-       puts("           d(atasegment)     data segment listing");
+       puts("           (d)atasegment     data segment listing");
+
 #if defined(ENABLE_INLINING)
-       puts("    -i     n(line)           activate inlining");
-       puts("           v(irtual)         inline virtual methods (uses/turns rt option on)");
-       puts("           e(exception)      inline methods with exceptions");
-       puts("           p(aramopt)        optimize argument renaming");
-       puts("           o(utsiders)       inline methods of foreign classes");
+       puts("    -i                       activate inlining");
+#if !defined(NDEBUG)
+       puts("    -il                      log inlining");
+#endif
+#if defined(ENABLE_INLINING_DEBUG)
+       puts("    -ia                      use inlining for all methods");
+       puts("    -ii <size>               set minimum size for inlined result");
+       puts("    -im <size>               set maximum size for inlined result");
+       puts("    -ie <number>             stop inlining after the given number of roots");
+       puts("    -ir                      log on-stack replacement");
+       puts("    -iR                      log on-stack replacement, more verbose");
+#endif /* defined(ENABLE_INLINING_DEBUG) */
 #endif /* defined(ENABLE_INLINING) */
+
 #if defined(ENABLE_IFCONV)
        puts("    -ifconv                  use if-conversion");
 #endif
@@ -454,42 +550,7 @@ void usage(void)
        /* exit with error code */
 
        exit(1);
-}   
-
-
-static void Xusage(void)
-{
-#if defined(ENABLE_JIT)
-       puts("    -Xjit                    JIT mode execution (default)");
-#endif
-#if defined(ENABLE_INTRP)
-       puts("    -Xint                    interpreter mode execution");
-#endif
-       puts("    -Xbootclasspath:<zip/jar files and directories separated by :>");
-    puts("                             value is set as bootstrap class path");
-       puts("    -Xbootclasspath/a:<zip/jar files and directories separated by :>");
-       puts("                             value is appended to the bootstrap class path");
-       puts("    -Xbootclasspath/p:<zip/jar files and directories separated by :>");
-       puts("                             value is prepended to the bootstrap class path");
-       puts("    -Xglibj:<zip/jar files and directories separated by :>");
-       puts("                             value is used as Java core library, but the");
-       puts("                             hardcoded VM interface classes are prepended");
-       printf("    -Xms<size>               set the initial size of the heap (default: %dMB)\n", HEAP_STARTSIZE / 1024 / 1024);
-       printf("    -Xmx<size>               set the maximum size of the heap (default: %dMB)\n", HEAP_MAXSIZE / 1024 / 1024);
-       printf("    -Xss<size>               set the thread stack size (default: %dkB)\n", STACK_SIZE / 1024);
-       puts("    -Xprof[:bb]              collect and print profiling data");
-#if defined(ENABLE_JVMTI)
-    /* -Xdebug option depend on gnu classpath JDWP options. options: 
-        transport=dt_socket,address=<hostname:port>,server=(y|n),suspend(y|n) */
-       puts("    -Xdebug                  enable remote debugging\n");
-       puts("    -Xrunjdwp transport=[dt_socket|...],address=<hostname:port>,server=[y|n],suspend=[y|n]\n");
-       puts("                             enable remote debugging\n");
-#endif 
-
-       /* exit with error code */
-
-       exit(1);
-}   
+}
 
 
 /* version *********************************************************************
@@ -528,17 +589,23 @@ static void version(bool opt_exit)
        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);
-       puts("  java.boot.class.path: "CACAO_VM_ZIP":"CLASSPATH_GLIBJ_ZIP"");
-       puts("  java.library.path   : "CLASSPATH_LIBRARY_PATH"\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(WITH_CLASSPATH_GNU)
+       puts("  java.boot.class.path           : "CACAO_VM_ZIP":"CLASSPATH_CLASSES"");
+#else
+       puts("  java.boot.class.path           : "CLASSPATH_CLASSES"");
+#endif
+       puts("  gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR"/classpath\n");
 
        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);
-       printf("  java.boot.class.path: %s\n", bootclasspath);
+       printf("  maximum heap size              : %d\n", opt_heapmaxsize);
+       printf("  initial heap size              : %d\n", opt_heapstartsize);
+       printf("  stack size                     : %d\n", opt_stacksize);
+       printf("  java.boot.class.path           : %s\n", _Jv_bootclasspath);
+       printf("  gnu.classpath.boot.library.path: %s\n", classpath_libdir);
+       printf("  java.class.path                : %s\n", _Jv_classpath);
 
        /* exit normally, if requested */
 
@@ -573,9 +640,79 @@ static void  vm_compile_method(void);
 #endif
 
 
+/* vm_createjvm ****************************************************************
+
+   Implementation for JNI_CreateJavaVM.
+
+*******************************************************************************/
+
+bool vm_createjvm(JavaVM **p_vm, void **p_env, void *vm_args)
+{
+       JavaVMInitArgs *_vm_args;
+       _Jv_JNIEnv     *env;
+       _Jv_JavaVM     *vm;
+
+       /* get the arguments for the new JVM */
+
+       _vm_args = (JavaVMInitArgs *) vm_args;
+
+       /* get the VM and Env tables (must be set before vm_create) */
+
+       env = NEW(_Jv_JNIEnv);
+
+#if defined(ENABLE_JAVASE)
+       env->env = &_Jv_JNINativeInterface;
+#endif
+
+       /* XXX Set the global variable.  Maybe we should do that differently. */
+
+       _Jv_env = env;
+
+       /* create and fill a JavaVM structure */
+
+       vm = NEW(_Jv_JavaVM);
+
+#if defined(ENABLE_JAVASE)
+       vm->functions = &_Jv_JNIInvokeInterface;
+#endif
+
+       /* XXX Set the global variable.  Maybe we should do that differently. */
+       /* XXX JVMTI Agents needs a JavaVM  */
+
+       _Jv_jvm = vm;
+
+       /* actually create the JVM */
+
+       if (!vm_create(_vm_args))
+               goto error;
+
+#if defined(ENABLE_JAVASE)
+       /* setup the local ref table (must be created after vm_create) */
+
+       if (!jni_init_localref_table())
+               goto error;
+#endif
+
+       /* now return the values */
+
+       *p_vm  = (JavaVM *) vm;
+       *p_env = (void *) env;
+
+       return true;
+
+ error:
+       /* release allocated memory */
+
+       FREE(env, _Jv_JNIEnv);
+       FREE(vm, _Jv_JavaVM);
+
+       return false;
+}
+
+
 /* vm_create *******************************************************************
 
-   Creates a JVM.  Called by JNI_CreateJavaVM.
+   Creates a JVM.  Called by vm_createjvm.
 
 *******************************************************************************/
 
@@ -584,7 +721,7 @@ bool vm_create(JavaVMInitArgs *vm_args)
        char *cp;
        s4    len;
        s4    opt;
-       s4    i, j, k;
+       s4    i, j;
        bool  opt_version;
        bool  opt_exit;
 
@@ -624,43 +761,111 @@ bool vm_create(JavaVMInitArgs *vm_args)
 
        /* get stuff from the environment *****************************************/
 
-#if defined(DISABLE_GC)
-       nogc_init(HEAP_MAXSIZE, HEAP_STARTSIZE);
+#if defined(WITH_JRE_LAYOUT)
+       /* SUN also uses a buffer of 4096-bytes (strace is your friend). */
+
+       cacao_prefix = MNEW(char, 4096);
+
+       if (readlink("/proc/self/exe", cacao_prefix, 4095) == -1)
+               vm_abort("readlink failed: %s\n", strerror(errno));
+
+       /* get the path of the current executable */
+
+       cacao_prefix = dirname(cacao_prefix);
+
+       if ((strlen(cacao_prefix) + strlen("/..") + strlen("0")) > 4096)
+               vm_abort("libjvm name to long for buffer\n");
+
+       /* concatenate the library name */
+
+       strcat(cacao_prefix, "/..");
+
+       /* now set path to libjvm.so */
+
+       len = strlen(cacao_prefix) + strlen("/lib/libjvm") + strlen("0");
+
+       cacao_libjvm = MNEW(char, len);
+       strcpy(cacao_libjvm, cacao_prefix);
+       strcat(cacao_libjvm, "/lib/libjvm");
+
+       /* and finally set the path to GNU Classpath libraries */
+
+       len = strlen(cacao_prefix) + strlen("/lib/classpath") + strlen("0");
+
+       classpath_libdir = MNEW(char, len);
+       strcpy(classpath_libdir, cacao_prefix);
+       strcat(classpath_libdir, "/lib/classpath");
+#else
+       cacao_prefix     = CACAO_PREFIX;
+       cacao_libjvm     = CACAO_LIBDIR"/libjvm";
+       classpath_libdir = CLASSPATH_LIBDIR"/classpath";
 #endif
 
        /* set the bootclasspath */
 
        cp = getenv("BOOTCLASSPATH");
 
-       if (cp) {
-               bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
-               strcpy(bootclasspath, cp);
+       if (cp != NULL) {
+               _Jv_bootclasspath = MNEW(char, strlen(cp) + strlen("0"));
+               strcpy(_Jv_bootclasspath, cp);
+       }
+       else {
+#if defined(WITH_JRE_LAYOUT)
+               len =
+# if defined(WITH_CLASSPATH_GNU)
+                       strlen(cacao_prefix) +
+                       strlen("/share/cacao/vm.zip") +
+                       strlen(":") +
+# endif
+                       strlen(cacao_prefix) +
+                       strlen("/share/classpath/glibj.zip") +
+                       strlen("0");
 
-       } else {
-               len = strlen(CACAO_VM_ZIP) +
+               _Jv_bootclasspath = MNEW(char, len);
+# if defined(WITH_CLASSPATH_GNU)
+               strcat(_Jv_bootclasspath, cacao_prefix);
+               strcat(_Jv_bootclasspath, "/share/cacao/vm.zip");
+               strcat(_Jv_bootclasspath, ":");
+# endif
+               strcat(_Jv_bootclasspath, cacao_prefix);
+               strcat(_Jv_bootclasspath, "/share/classpath/glibj.zip");
+#else
+               len =
+# if defined(WITH_CLASSPATH_GNU)
+                       strlen(CACAO_VM_ZIP) +
                        strlen(":") +
-                       strlen(CLASSPATH_GLIBJ_ZIP) +
+# endif
+                       strlen(CLASSPATH_CLASSES) +
                        strlen("0");
 
-               bootclasspath = MNEW(char, len);
-               strcat(bootclasspath, CACAO_VM_ZIP);
-               strcat(bootclasspath, ":");
-               strcat(bootclasspath, CLASSPATH_GLIBJ_ZIP);
+               _Jv_bootclasspath = MNEW(char, len);
+# if defined(WITH_CLASSPATH_GNU)
+               strcat(_Jv_bootclasspath, CACAO_VM_ZIP);
+               strcat(_Jv_bootclasspath, ":");
+# endif
+               strcat(_Jv_bootclasspath, CLASSPATH_CLASSES);
+#endif
        }
 
        /* set the classpath */
 
        cp = getenv("CLASSPATH");
 
-       if (cp) {
-               classpath = MNEW(char, strlen(cp) + strlen("0"));
-               strcat(classpath, cp);
+       if (cp != NULL) {
+               _Jv_classpath = MNEW(char, strlen(cp) + strlen("0"));
+               strcat(_Jv_classpath, cp);
        }
        else {
-               classpath = MNEW(char, strlen(".") + strlen("0"));
-               strcpy(classpath, ".");
+               _Jv_classpath = MNEW(char, strlen(".") + strlen("0"));
+               strcpy(_Jv_classpath, ".");
        }
 
+       /* get and set java.library.path */
+
+       _Jv_java_library_path = getenv("LD_LIBRARY_PATH");
+
+       if (_Jv_java_library_path == NULL)
+               _Jv_java_library_path = "";
 
        /* interpret the options **************************************************/
 
@@ -680,15 +885,10 @@ bool vm_create(JavaVMInitArgs *vm_args)
        jvmti = false;
 #endif
 
-       /* initialize properties before commandline handling */
+       /* initialize and fill properties before command-line handling */
 
        if (!properties_init())
-               throw_cacao_exception_exit(string_java_lang_InternalError,
-                                                                  "Unable to init properties");
-
-       /* add some default properties */
-
-       properties_add("java.endorsed.dirs", ""CACAO_PREFIX"/jre/lib/endorsed");
+               vm_abort("properties_init failed");
 
        /* iterate over all passed options */
 
@@ -721,17 +921,17 @@ bool vm_create(JavaVMInitArgs *vm_args)
 
                case OPT_CLASSPATH:
                        /* forget old classpath and set the argument as new classpath */
-                       MFREE(classpath, char, strlen(classpath));
+                       MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
 
-                       classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
-                       strcpy(classpath, opt_arg);
+                       _Jv_classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
+                       strcpy(_Jv_classpath, opt_arg);
                        break;
 
                case OPT_D:
-                       for (j = 0; j < strlen(opt_arg); j++) {
-                               if (opt_arg[j] == '=') {
-                                       opt_arg[j] = '\0';
-                                       properties_add(opt_arg, opt_arg + j + 1);
+                       for (i = 0; i < strlen(opt_arg); i++) {
+                               if (opt_arg[i] == '=') {
+                                       opt_arg[i] = '\0';
+                                       properties_add(opt_arg, opt_arg + i + 1);
                                        goto opt_d_done;
                                }
                        }
@@ -747,58 +947,58 @@ bool vm_create(JavaVMInitArgs *vm_args)
                        /* Forget default bootclasspath and set the argument as
                           new boot classpath. */
 
-                       MFREE(bootclasspath, char, strlen(bootclasspath));
+                       MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
 
-                       bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
-                       strcpy(bootclasspath, opt_arg);
+                       _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
+                       strcpy(_Jv_bootclasspath, opt_arg);
                        break;
 
                case OPT_BOOTCLASSPATH_A:
                        /* append to end of bootclasspath */
 
-                       len = strlen(bootclasspath);
+                       len = strlen(_Jv_bootclasspath);
 
-                       bootclasspath = MREALLOC(bootclasspath,
-                                                                        char,
-                                                                        len,
-                                                                        len + strlen(":") +
-                                                                        strlen(opt_arg) + strlen("0"));
+                       _Jv_bootclasspath = MREALLOC(_Jv_bootclasspath,
+                                                                                char,
+                                                                                len + strlen("0"),
+                                                                                len + strlen(":") +
+                                                                                strlen(opt_arg) + strlen("0"));
 
-                       strcat(bootclasspath, ":");
-                       strcat(bootclasspath, opt_arg);
+                       strcat(_Jv_bootclasspath, ":");
+                       strcat(_Jv_bootclasspath, opt_arg);
                        break;
 
                case OPT_BOOTCLASSPATH_P:
                        /* prepend in front of bootclasspath */
 
-                       cp = bootclasspath;
+                       cp = _Jv_bootclasspath;
                        len = strlen(cp);
 
-                       bootclasspath = MNEW(char, strlen(opt_arg) + strlen(":") +
-                                                                len + strlen("0"));
+                       _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen(":") +
+                                                                        len + strlen("0"));
 
-                       strcpy(bootclasspath, opt_arg);
-                       strcat(bootclasspath, ":");
-                       strcat(bootclasspath, cp);
+                       strcpy(_Jv_bootclasspath, opt_arg);
+                       strcat(_Jv_bootclasspath, ":");
+                       strcat(_Jv_bootclasspath, cp);
 
                        MFREE(cp, char, len);
                        break;
 
-               case OPT_GLIBJ:
+               case OPT_BOOTCLASSPATH_C:
                        /* use as Java core library, but prepend VM interface classes */
 
-                       MFREE(bootclasspath, char, strlen(bootclasspath));
+                       MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
 
                        len = strlen(CACAO_VM_ZIP) +
                                strlen(":") +
                                strlen(opt_arg) +
                                strlen("0");
 
-                       bootclasspath = MNEW(char, len);
+                       _Jv_bootclasspath = MNEW(char, len);
 
-                       strcpy(bootclasspath, CACAO_VM_ZIP);
-                       strcat(bootclasspath, ":");
-                       strcat(bootclasspath, opt_arg);
+                       strcpy(_Jv_bootclasspath, CACAO_VM_ZIP);
+                       strcat(_Jv_bootclasspath, ":");
+                       strcat(_Jv_bootclasspath, opt_arg);
                        break;
 
 #if defined(ENABLE_JVMTI)
@@ -943,8 +1143,8 @@ bool vm_create(JavaVMInitArgs *vm_args)
                        break;
                        
                case OPT_CHECK:
-                       for (j = 0; j < strlen(opt_arg); j++) {
-                               switch (opt_arg[j]) {
+                       for (i = 0; i < strlen(opt_arg); i++) {
+                               switch (opt_arg[i]) {
                                case 'b':
                                        checkbounds = false;
                                        break;
@@ -985,8 +1185,8 @@ bool vm_create(JavaVMInitArgs *vm_args)
 #endif
 
                case OPT_SHOW:       /* Display options */
-                       for (j = 0; j < strlen(opt_arg); j++) {         
-                               switch (opt_arg[j]) {
+                       for (i = 0; i < strlen(opt_arg); i++) {         
+                               switch (opt_arg[i]) {
                                case 'c':
                                        showconstantpool = true;
                                        break;
@@ -1010,6 +1210,10 @@ bool vm_create(JavaVMInitArgs *vm_args)
                                        compileverbose = true;
                                        break;
 
+                               case 'o':
+                                       opt_shownops = true;
+                                       break;
+
                                case 'e':
                                        opt_showexceptionstubs = true;
                                        break;
@@ -1036,30 +1240,34 @@ bool vm_create(JavaVMInitArgs *vm_args)
 #endif
 
 #if defined(ENABLE_INLINING)
+#if defined(ENABLE_INLINING_DEBUG)
+               case OPT_INLINE_DEBUG_ALL:
+                       opt_inline_debug_all = true;
+                       break;
+               case OPT_INLINE_DEBUG_END:
+                       opt_inline_debug_end_counter = atoi(opt_arg);
+                       break;
+               case OPT_INLINE_DEBUG_MIN:
+                       opt_inline_debug_min_size = atoi(opt_arg);
+                       break;
+               case OPT_INLINE_DEBUG_MAX:
+                       opt_inline_debug_max_size = atoi(opt_arg);
+                       break;
+               case OPT_INLINE_REPLACE_VERBOSE:
+                       opt_replace_verbose = 1;
+                       break;
+               case OPT_INLINE_REPLACE_VERBOSE2:
+                       opt_replace_verbose = 2;
+                       break;
+#endif /* defined(ENABLE_INLINING_DEBUG) */
+#if !defined(NDEBUG)
+               case OPT_INLINE_LOG:
+                       opt_inline_debug_log = true;
+                       break;
+#endif /* !defined(NDEBUG) */
+
                case OPT_INLINING:
-                       for (j = 0; j < strlen(opt_arg); j++) {         
-                               switch (opt_arg[j]) {
-                               case 'n':
-                                       /* define in options.h; Used in main.c, jit.c
-                                          & inline.c inlining is currently
-                                          deactivated */
-                                       break;
-                               case 'v':
-                                       inlinevirtuals = true;
-                                       break;
-                               case 'e':
-                                       inlineexceptions = true;
-                                       break;
-                               case 'p':
-                                       inlineparamopt = true;
-                                       break;
-                               case 'o':
-                                       inlineoutsiders = true;
-                                       break;
-                               default:
-                                       usage();
-                               }
-                       }
+                       opt_inlining = true;
                        break;
 #endif /* defined(ENABLE_INLINING) */
 
@@ -1083,6 +1291,10 @@ bool vm_create(JavaVMInitArgs *vm_args)
                        Xusage();
                        break;
 
+               case OPT_XX:
+                       XXusage();
+                       break;
+
                case OPT_ESA:
                        _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = true;
                        break;
@@ -1091,25 +1303,26 @@ bool vm_create(JavaVMInitArgs *vm_args)
                        _Jv_jvm->Java_java_lang_VMClassLoader_defaultAssertionStatus = false;
                        break;
 
+#if defined(ENABLE_PROFILING)
                case OPT_PROF_OPTION:
                        /* use <= to get the last \0 too */
 
-                       for (j = 0, k = 0; j <= strlen(opt_arg); j++) {
-                               if (opt_arg[j] == ',')
-                                       opt_arg[j] = '\0';
+                       for (i = 0, j = 0; i <= strlen(opt_arg); i++) {
+                               if (opt_arg[i] == ',')
+                                       opt_arg[i] = '\0';
 
-                               if (opt_arg[j] == '\0') {
-                                       if (strcmp("bb", opt_arg + k) == 0)
+                               if (opt_arg[i] == '\0') {
+                                       if (strcmp("bb", opt_arg + j) == 0)
                                                opt_prof_bb = true;
 
                                        else {
-                                               printf("Unknown option: -Xprof:%s\n", opt_arg + k);
+                                               printf("Unknown option: -Xprof:%s\n", opt_arg + j);
                                                usage();
                                        }
 
                                        /* set k to next char */
 
-                                       k = j + 1;
+                                       j = i + 1;
                                }
                        }
                        /* fall through */
@@ -1117,6 +1330,7 @@ bool vm_create(JavaVMInitArgs *vm_args)
                case OPT_PROF:
                        opt_prof = true;
                        break;
+#endif
 
                case OPT_JIT:
 #if defined(ENABLE_JIT)
@@ -1165,14 +1379,6 @@ bool vm_create(JavaVMInitArgs *vm_args)
                }
        }
 
-
-       /* Now we have all options handled and we can print the version
-          information. */
-
-       if (opt_version)
-               version(opt_exit);
-
-
        /* get the main class *****************************************************/
 
        if (opt_index < vm_args->nOptions) {
@@ -1183,13 +1389,13 @@ bool vm_create(JavaVMInitArgs *vm_args)
                if (opt_jar == true) {
                        /* free old classpath */
 
-                       MFREE(classpath, char, strlen(classpath));
+                       MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
 
                        /* put jarfile into classpath */
 
-                       classpath = MNEW(char, strlen(mainstring) + strlen("0"));
+                       _Jv_classpath = MNEW(char, strlen(mainstring) + strlen("0"));
 
-                       strcpy(classpath, mainstring);
+                       strcpy(_Jv_classpath, mainstring);
                }
                else {
                        /* replace .'s with /'s in classname */
@@ -1210,14 +1416,32 @@ bool vm_create(JavaVMInitArgs *vm_args)
 
                jvmti_set_phase(JVMTI_PHASE_PRIMORDIAL);
        }
-
 #endif
 
+       /* Now re-set some of the properties that may have changed. This
+          must be done after _all_ environment variables have been
+          processes (e.g. -jar handling). */
+
+       if (!properties_postinit())
+               vm_abort("properties_postinit failed");
+
+       /* Now we have all options handled and we can print the version
+          information. */
+
+       if (opt_version)
+               version(opt_exit);
 
        /* initialize this JVM ****************************************************/
 
        vm_initializing = true;
 
+#if defined(ENABLE_THREADS)
+       /* pre-initialize some core thread stuff, like the stopworldlock,
+          thus this has to happen _before_ gc_init()!!! */
+
+       threads_preinit();
+#endif
+
        /* initialize the garbage collector */
 
        gc_init(opt_heapmaxsize, opt_heapstartsize);
@@ -1231,10 +1455,6 @@ bool vm_create(JavaVMInitArgs *vm_args)
        }
 #endif
 
-#if defined(ENABLE_THREADS)
-       threads_preinit();
-#endif
-
        /* initialize the string hashtable stuff: lock (must be done
           _after_ threads_preinit) */
 
@@ -1260,7 +1480,7 @@ bool vm_create(JavaVMInitArgs *vm_args)
                throw_main_exception_exit();
 
        suck_add_from_property("java.endorsed.dirs");
-       suck_add(bootclasspath);
+       suck_add(_Jv_bootclasspath);
 
        /* initialize the memory subsystem (must be done _after_
           threads_preinit) */
@@ -1303,10 +1523,10 @@ bool vm_create(JavaVMInitArgs *vm_args)
        classcache_init) */
 
        if (!loader_init())
-               throw_main_exception_exit();
+               vm_abort("loader_init failed");
 
        if (!linker_init())
-               throw_main_exception_exit();
+               vm_abort("linker_init failed");
 
        if (!native_init())
                throw_main_exception_exit();
@@ -1317,26 +1537,20 @@ bool vm_create(JavaVMInitArgs *vm_args)
        if (!builtin_init())
                throw_main_exception_exit();
 
+#if defined(ENABLE_JAVASE)
        /* Initialize the JNI subsystem (must be done _before_
           threads_init, as threads_init can call JNI methods
           (e.g. NewGlobalRef). */
 
        if (!jni_init())
                throw_main_exception_exit();
+#endif
 
 #if defined(ENABLE_THREADS)
        if (!threads_init())
                throw_main_exception_exit();
 #endif
 
-       /* That's important, otherwise we get into trouble, if the Runtime
-          static initializer is called before (circular dependency. This
-          is with classpath 0.09. Another important thing is, that this
-          has to happen after initThreads!!! */
-
-       if (!initialize_class(class_java_lang_System))
-               throw_main_exception_exit();
-
 #if defined(ENABLE_PROFILING)
        /* initialize profiling */
 
@@ -1364,9 +1578,9 @@ bool vm_create(JavaVMInitArgs *vm_args)
 # if defined(ENABLE_PROFILING)
        /* start the profile sampling thread */
 
-       if (opt_prof)
-               if (!profile_start_thread())
-                       throw_main_exception_exit();
+/*     if (opt_prof) */
+/*             if (!profile_start_thread()) */
+/*                     throw_main_exception_exit(); */
 # endif
 #endif
 
@@ -1438,19 +1652,18 @@ void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
 
        mainutf = utf_new_char(mainstring);
 
+#if defined(ENABLE_JAVAME_CLDC1_1)
+       if (!(mainclass = load_class_bootstrap(mainutf)))
+               throw_main_exception_exit();
+#else
        if (!(mainclass = load_class_from_sysloader(mainutf)))
                throw_main_exception_exit();
+#endif
 
-       /* error loading class, clear exceptionptr for new exception */
-
-       if (*exceptionptr || !mainclass) {
-               /*                      *exceptionptr = NULL; */
+       /* error loading class */
 
-               /*                      *exceptionptr = */
-               /*                              new_exception_message(string_java_lang_NoClassDefFoundError, */
-               /*                                                                        mainstring); */
+       if ((*exceptionptr != NULL) || (mainclass == NULL))
                throw_main_exception_exit();
-       }
 
        if (!link_class(mainclass))
                throw_main_exception_exit();
@@ -1500,9 +1713,15 @@ void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
        jvmti_set_phase(JVMTI_PHASE_LIVE);
 #endif
 
-       /* increase total started thread count */
+       /* set ThreadMXBean variables */
+
+       _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount++;
+       _Jv_jvm->java_lang_management_ThreadMXBean_TotalStartedThreadCount++;
 
-       _Jv_jvm->total_started_thread_count++;
+       if (_Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount >
+               _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount)
+               _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
+                       _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
 
        /* start the main thread */