* src/vm/jit/exceptiontable.c: New file.
[cacao.git] / src / vm / vm.c
index 70132fdd78be06afe61a7395d8ee096d2dc64361..2a9b9cbc8bf0d20f56e34c34007065eff2436624 100644 (file)
@@ -22,8 +22,6 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: vm.c 8213 2007-07-18 20:08:26Z michi $
-
 */
 
 
 #include <stdint.h>
 #include <stdlib.h>
 
-#if defined(WITH_JRE_LAYOUT)
-# include <libgen.h>
-# include <unistd.h>
-#endif
-
 #include "vm/types.h"
 
 #include "arch.h"
@@ -50,6 +43,8 @@
 #include "mm/memory.h"
 
 #include "native/jni.h"
+#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_Class.h"
 
-#include "native/include/java_lang_Byte.h"
-#include "native/include/java_lang_Character.h"
-#include "native/include/java_lang_Short.h"
-#include "native/include/java_lang_Integer.h"
-#include "native/include/java_lang_Boolean.h"
-#include "native/include/java_lang_Long.h"
-#include "native/include/java_lang_Float.h"
-#include "native/include/java_lang_Double.h"
-
 #include "native/vm/nativevm.h"
 
 #include "threads/threads-common.h"
 
 #include "toolbox/logging.h"
 
+#include "vm/array.h"
 #include "vm/builtin.h"
 #include "vm/exceptions.h"
 #include "vm/finalizer.h"
 #include "vm/global.h"
 #include "vm/initialize.h"
+#include "vm/package.h"
+#include "vm/primitive.h"
 #include "vm/properties.h"
 #include "vm/signallocal.h"
 #include "vm/stringlocal.h"
 #include "vm/vm.h"
 
+#include "vm/jit/argument.h"
+#include "vm/jit/asmpart.h"
+
+#if defined(ENABLE_DISASSEMBLER)
+# include "vm/jit/disass.h"
+#endif
+
 #include "vm/jit/jit.h"
 #include "vm/jit/md.h"
-#include "vm/jit/asmpart.h"
 
 #if defined(ENABLE_PROFILING)
 # include "vm/jit/optimizing/profile.h"
@@ -99,7 +94,6 @@
 
 #include "vmcore/classcache.h"
 #include "vmcore/options.h"
-#include "vmcore/primitive.h"
 #include "vmcore/statistics.h"
 #include "vmcore/suck.h"
 
@@ -125,22 +119,9 @@ s4 vms = 0;                             /* number of VMs created              */
 bool vm_initializing = false;
 bool vm_exiting = false;
 
-char      *cacao_prefix = NULL;
-char      *cacao_libjvm = NULL;
-char      *classpath_libdir = 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;
-char *specificsignature = NULL;
-
-bool startit = true;
-
 #if defined(ENABLE_INTRP)
 u1 *intrp_main_stack = NULL;
 #endif
@@ -150,7 +131,7 @@ u1 *intrp_main_stack = NULL;
 
 #define HEAP_MAXSIZE      128 * 1024 * 1024 /* default 128MB                  */
 #define HEAP_STARTSIZE      2 * 1024 * 1024 /* default 2MB                    */
-#define STACK_SIZE                64 * 1024 /* default 64kB                   */
+#define STACK_SIZE               128 * 1024 /* default 64kB                   */
 
 
 /* define command line options ************************************************/
@@ -231,7 +212,6 @@ enum {
        OPT_VERBOSETC,
 #endif
 #endif /* defined(ENABLE_VERIFIER) */
-       OPT_EAGER,
 
        /* optimization options */
 
@@ -314,7 +294,6 @@ opt_struct opts[] = {
        { "?",                 false, OPT_HELP },
        { "X",                 false, OPT_X },
        { "XX:",               true,  OPT_XX },
-       { "XX",                false, OPT_XX },
 
        { "ea:",               true,  OPT_EA },
        { "da:",               true,  OPT_DA },
@@ -329,6 +308,7 @@ opt_struct opts[] = {
        { "noasyncgc",         false, OPT_IGNORE },
 #if defined(ENABLE_VERIFIER)
        { "noverify",          false, OPT_NOVERIFY },
+       { "Xverify:none",      false, OPT_NOVERIFY },
 #endif
        { "v",                 false, OPT_VERBOSE1 },
        { "verbose:",          true,  OPT_VERBOSE },
@@ -346,7 +326,6 @@ opt_struct opts[] = {
        { "log",               true,  OPT_LOG },
        { "c",                 true,  OPT_CHECK },
        { "l",                 false, OPT_LOAD },
-       { "eager",             false, OPT_EAGER },
 
 #if !defined(NDEBUG)
        { "all",               false, OPT_ALL },
@@ -533,12 +512,12 @@ static void Xusage(void)
 }   
 
 
+#if 0
 static void XXusage(void)
 {
        puts("    -v                       write state-information");
 #if !defined(NDEBUG)
-       puts("    -verbose[:jit|threads]");
-       puts("                             enable specific verbose output");
+       puts("    -verbose:jit             enable specific verbose output");
        puts("    -debug-color             colored output for ANSI terms");
 #endif
 #ifdef TYPECHECK_VERBOSE
@@ -561,7 +540,6 @@ static void XXusage(void)
        puts("    -oloop                   optimize array accesses in loops");
 #endif
        puts("    -l                       don't start the class after loading");
-       puts("    -eager                   perform eager class loading and linking");
 #if !defined(NDEBUG)
        puts("    -all                     compile all methods, no execution");
        puts("    -m                       compile only a specific method");
@@ -576,8 +554,6 @@ static void XXusage(void)
 #if defined(ENABLE_DISASSEMBLER)
        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");
 
@@ -612,6 +588,7 @@ static void XXusage(void)
 
        exit(1);
 }
+#endif
 
 
 /* version *********************************************************************
@@ -638,8 +615,34 @@ static void version(bool opt_exit)
        puts("This program is distributed in the hope that it will be useful, but");
        puts("WITHOUT ANY WARRANTY; without even the implied warranty of");
        puts("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU");
-       puts("General Public License for more details.\n");
+       puts("General Public License for more details.");
+
+       /* exit normally, if requested */
+
+       if (opt_exit)
+               exit(0);
+}
+
+
+/* fullversion *****************************************************************
+
+   Prints a Sun compatible version information (required e.g. by
+   jpackage, www.jpackage.org).
+
+*******************************************************************************/
+
+static void fullversion(void)
+{
+       puts("java full version \"cacao-"JAVA_VERSION"\"");
+
+       /* exit normally */
+
+       exit(0);
+}
+
 
+static void vm_printconfig(void)
+{
        puts("Configure/Build options:\n");
        puts("  ./configure: "VERSION_CONFIGURE_ARGS"");
 #if defined(__VERSION__)
@@ -653,43 +656,35 @@ static void version(bool opt_exit)
        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"");
+
+#if defined(WITH_JRE_LAYOUT)
+       /* When we're building with JRE-layout, the default paths are the
+          same as the runtime paths. */
 #else
-       puts("  java.boot.class.path           : "CLASSPATH_CLASSES"");
+# if defined(WITH_CLASSPATH_GNU)
+       puts("  gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR);
+       puts("  java.boot.class.path           : "CACAO_VM_ZIP":"CLASSPATH_CLASSES"");
+# elif defined(WITH_CLASSPATH_SUN)
+       puts("  sun.boot.library.path          : "CLASSPATH_LIBDIR);
+       puts("  java.boot.class.path           : "CLASSPATH_CLASSES);
+# endif
 #endif
-       puts("  gnu.classpath.boot.library.path: "CLASSPATH_LIBDIR"/classpath\n");
+
+       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);
-       printf("  libjvm.so                      : %s\n", cacao_libjvm);
-       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 */
-
-       if (opt_exit)
-               exit(0);
-}
-
-
-/* fullversion *****************************************************************
-
-   Prints a Sun compatible version information (required e.g. by
-   jpackage, www.jpackage.org).
-
-*******************************************************************************/
-
-static void fullversion(void)
-{
-       puts("java full version \"cacao-"JAVA_VERSION"\"");
 
-       /* exit normally */
+#if defined(WITH_CLASSPATH_GNU)
+       printf("  gnu.classpath.boot.library.path: %s\n", properties_get("gnu.classpath.boot.library.path"));
+#elif defined(WITH_CLASSPATH_SUN)
+       printf("  sun.boot.library.path          : %s\n", properties_get("sun.boot.library.path"));
+#endif
 
-       exit(0);
+       printf("  java.boot.class.path           : %s\n", properties_get("java.boot.class.path"));
+       printf("  java.class.path                : %s\n", properties_get("java.class.path"));
 }
 
 
@@ -748,13 +743,6 @@ bool vm_createjvm(JavaVM **p_vm, void **p_env, void *vm_args)
        if (!vm_create(_vm_args))
                goto error;
 
-#if defined(ENABLE_JNI)
-       /* 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;
@@ -780,10 +768,12 @@ bool vm_createjvm(JavaVM **p_vm, void **p_env, void *vm_args)
 
 bool vm_create(JavaVMInitArgs *vm_args)
 {
-       char *cp;
-       s4    len;
-       s4    opt;
-       s4    i, j;
+       int   len;
+       char *p;
+       char *boot_class_path;
+       char *class_path;
+       int   opt;
+       int   i, j;
        bool  opt_version;
        bool  opt_exit;
 
@@ -798,174 +788,62 @@ bool vm_create(JavaVMInitArgs *vm_args)
        vmlog_cacao_init(vm_args);
 #endif
 
-       /* check the JNI version requested */
+#if defined(ENABLE_JNI)
+       /* Check the JNI version requested. */
 
-       switch (vm_args->version) {
-       case JNI_VERSION_1_1:
-               break;
-       case JNI_VERSION_1_2:
-       case JNI_VERSION_1_4:
-               break;
-       default:
+       if (!jni_version_check(vm_args->version))
                return false;
-       }
+#endif
 
-       /* we only support 1 JVM instance */
+       /* We only support 1 JVM instance. */
 
        if (vms > 0)
                return false;
 
+       /* Install the exit handler. */
+
        if (atexit(vm_exit_handler))
                vm_abort("atexit failed: %s\n", strerror(errno));
 
-       if (opt_verbose)
-               log_text("CACAO started -------------------------------------------------------");
-
-       /* 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. */
-
-       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 */
-
-       _Jv_jvm->starttime = builtin_currenttimemillis();
-
-       /* get stuff from the environment *****************************************/
-
-#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";
-
-# if defined(WITH_CLASSPATH_GNU)
-       classpath_libdir = CLASSPATH_LIBDIR"/classpath";
-# else
-       classpath_libdir = CLASSPATH_LIBDIR;
-# endif
-#endif
-
-       /* set the bootclasspath */
-
-       cp = getenv("BOOTCLASSPATH");
-
-       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");
-
-               _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(":") +
-# endif
-                       strlen(CLASSPATH_CLASSES) +
-                       strlen("0");
-
-               _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 some options. */
 
-       /* set the classpath */
+       opt_version       = false;
+       opt_exit          = false;
 
-       cp = getenv("CLASSPATH");
+       opt_noieee        = false;
 
-       if (cp != NULL) {
-               _Jv_classpath = MNEW(char, strlen(cp) + strlen("0"));
-               strcat(_Jv_classpath, cp);
-       }
-       else {
-               _Jv_classpath = MNEW(char, strlen(".") + strlen("0"));
-               strcpy(_Jv_classpath, ".");
-       }
+       opt_heapmaxsize   = HEAP_MAXSIZE;
+       opt_heapstartsize = HEAP_STARTSIZE;
+       opt_stacksize     = STACK_SIZE;
 
-       /* get and set java.library.path */
+       /* Initialize the properties list before command-line handling.
+          Otherwise -XX:+PrintConfig crashes. */
 
-       _Jv_java_library_path = getenv("LD_LIBRARY_PATH");
+       properties_init();
 
-       if (_Jv_java_library_path == NULL)
-               _Jv_java_library_path = "";
+       /* First of all, parse the -XX options. */
 
-       /* interpret the options **************************************************/
+       options_xx(vm_args);
 
-       opt_version       = false;
-       opt_exit          = false;
+       /* 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. */
 
-       opt_noieee        = false;
+       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));
 
-       opt_heapmaxsize   = HEAP_MAXSIZE;
-       opt_heapstartsize = HEAP_STARTSIZE;
-       opt_stacksize     = STACK_SIZE;
+       /* set the VM starttime */
 
+       _Jv_jvm->starttime = builtin_currenttimemillis();
 
 #if defined(ENABLE_JVMTI)
        /* initialize JVMTI related  **********************************************/
        jvmti = false;
 #endif
 
-       /* initialize and fill properties before command-line handling */
+       /* Fill the properties before command-line handling. */
 
-       if (!properties_init())
-               vm_abort("properties_init failed");
+       properties_set();
 
        /* iterate over all passed options */
 
@@ -997,11 +875,20 @@ bool vm_create(JavaVMInitArgs *vm_args)
                        break;
 
                case OPT_CLASSPATH:
-                       /* forget old classpath and set the argument as new classpath */
-                       MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
+                       /* Forget old classpath and set the argument as new
+                          classpath. */
+
+                       class_path = 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);
+#endif
 
-                       _Jv_classpath = MNEW(char, strlen(opt_arg) + strlen("0"));
-                       strcpy(_Jv_classpath, opt_arg);
+                       MFREE(class_path, char, strlen(class_path));
                        break;
 
                case OPT_D:
@@ -1024,58 +911,79 @@ bool vm_create(JavaVMInitArgs *vm_args)
                        /* Forget default bootclasspath and set the argument as
                           new boot classpath. */
 
-                       MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
+                       boot_class_path = 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);
 
-                       _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
-                       strcpy(_Jv_bootclasspath, opt_arg);
+                       MFREE(boot_class_path, char, strlen(boot_class_path));
                        break;
 
                case OPT_BOOTCLASSPATH_A:
-                       /* append to end of bootclasspath */
+                       /* Append to bootclasspath. */
 
-                       len = strlen(_Jv_bootclasspath);
+                       boot_class_path = properties_get("sun.boot.class.path");
 
-                       _Jv_bootclasspath = MREALLOC(_Jv_bootclasspath,
-                                                                                char,
-                                                                                len + strlen("0"),
-                                                                                len + strlen(":") +
-                                                                                strlen(opt_arg) + strlen("0"));
+                       len = strlen(boot_class_path);
 
-                       strcat(_Jv_bootclasspath, ":");
-                       strcat(_Jv_bootclasspath, opt_arg);
+                       p = MREALLOC(boot_class_path,
+                                                char,
+                                                len + strlen("0"),
+                                                len + strlen(":") +
+                                                strlen(opt_arg) + strlen("0"));
+
+                       strcat(p, ":");
+                       strcat(p, opt_arg);
+
+                       properties_add("sun.boot.class.path", p);
+                       properties_add("java.boot.class.path", p);
                        break;
 
                case OPT_BOOTCLASSPATH_P:
-                       /* prepend in front of bootclasspath */
+                       /* Prepend to bootclasspath. */
+
+                       boot_class_path = properties_get("sun.boot.class.path");
+
+                       len = strlen(boot_class_path);
 
-                       cp = _Jv_bootclasspath;
-                       len = strlen(cp);
+                       p = MNEW(char, strlen(opt_arg) + strlen(":") + len + strlen("0"));
 
-                       _Jv_bootclasspath = MNEW(char, strlen(opt_arg) + strlen(":") +
-                                                                        len + strlen("0"));
+                       strcpy(p, opt_arg);
+                       strcat(p, ":");
+                       strcat(p, boot_class_path);
 
-                       strcpy(_Jv_bootclasspath, opt_arg);
-                       strcat(_Jv_bootclasspath, ":");
-                       strcat(_Jv_bootclasspath, cp);
+                       properties_add("sun.boot.class.path", p);
+                       properties_add("java.boot.class.path", p);
 
-                       MFREE(cp, char, len);
+                       MFREE(boot_class_path, char, len);
                        break;
 
                case OPT_BOOTCLASSPATH_C:
-                       /* use as Java core library, but prepend VM interface classes */
+                       /* Use as Java core library, but prepend VM interface
+                          classes. */
 
-                       MFREE(_Jv_bootclasspath, char, strlen(_Jv_bootclasspath));
+                       boot_class_path = properties_get("sun.boot.class.path");
 
-                       len = strlen(CACAO_VM_ZIP) +
+                       len =
+                               strlen(CACAO_VM_ZIP) +
                                strlen(":") +
                                strlen(opt_arg) +
                                strlen("0");
 
-                       _Jv_bootclasspath = MNEW(char, len);
+                       p = MNEW(char, len);
+
+                       strcpy(p, CACAO_VM_ZIP);
+                       strcat(p, ":");
+                       strcat(p, opt_arg);
 
-                       strcpy(_Jv_bootclasspath, CACAO_VM_ZIP);
-                       strcat(_Jv_bootclasspath, ":");
-                       strcat(_Jv_bootclasspath, opt_arg);
+                       properties_add("sun.boot.class.path", p);
+                       properties_add("java.boot.class.path", p);
+
+                       MFREE(boot_class_path, char, strlen(boot_class_path));
                        break;
 
 #if defined(ENABLE_JVMTI)
@@ -1158,13 +1066,9 @@ bool vm_create(JavaVMInitArgs *vm_args)
                        else if (strcmp("jit", opt_arg) == 0) {
                                opt_verbose = true;
                                loadverbose = true;
-                               linkverbose = true;
                                initverbose = true;
                                compileverbose = true;
                        }
-                       else if (strcmp("threads", opt_arg) == 0) {
-                               opt_verbosethreads = true;
-                       }
 #endif
                        else {
                                printf("Unknown -verbose option: %s\n", opt_arg);
@@ -1240,10 +1144,6 @@ bool vm_create(JavaVMInitArgs *vm_args)
                        makeinitializations = false;
                        break;
 
-               case OPT_EAGER:
-                       opt_eager = true;
-                       break;
-
 #if !defined(NDEBUG)
                case OPT_ALL:
                        compileall = true;
@@ -1291,14 +1191,6 @@ bool vm_create(JavaVMInitArgs *vm_args)
                                case 'o':
                                        opt_shownops = true;
                                        break;
-
-                               case 'e':
-                                       opt_showexceptionstubs = true;
-                                       break;
-
-                               case 'n':
-                                       opt_shownativestub = true;
-                                       break;
 #endif
 
                                case 'd':
@@ -1364,7 +1256,7 @@ bool vm_create(JavaVMInitArgs *vm_args)
                        break;
 
                case OPT_XX:
-                       options_xx(opt_arg);
+                       /* Already parsed. */
                        break;
 
                case OPT_EA:
@@ -1483,13 +1375,17 @@ bool vm_create(JavaVMInitArgs *vm_args)
                if (opt_jar == true) {
                        /* free old classpath */
 
-                       MFREE(_Jv_classpath, char, strlen(_Jv_classpath));
+/*                     MFREE(_Jv_classpath, char, strlen(_Jv_classpath)); */
 
                        /* put jarfile into classpath */
 
-                       _Jv_classpath = MNEW(char, strlen(mainstring) + strlen("0"));
+                       p = MNEW(char, strlen(mainstring) + strlen("0"));
 
-                       strcpy(_Jv_classpath, mainstring);
+                       strcpy(p, mainstring);
+
+#if defined(ENABLE_JAVASE)
+                       properties_add("java.class.path", p);
+#endif
                }
                else {
                        /* replace .'s with /'s in classname */
@@ -1568,17 +1464,8 @@ bool vm_create(JavaVMInitArgs *vm_args)
 
        /* AFTER: utf8_init */
 
-       suck_add(_Jv_bootclasspath);
-
-       /* 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).
-
-          AFTER: suck_add_from_property, since it may change the
-          _Jv_bootclasspath pointer. */
-
-       if (!properties_postinit())
-               vm_abort("vm_create: properties_postinit failed");
+       boot_class_path = properties_get("sun.boot.class.path");
+       suck_add(boot_class_path);
 
        /* initialize the classcache hashtable stuff: lock, hashtable
           (must be done _after_ threads_preinit) */
@@ -1619,23 +1506,27 @@ bool vm_create(JavaVMInitArgs *vm_args)
        intrp_md_init();
 #endif
 
-       /* initialize the loader subsystems (must be done _after_
-       classcache_init) */
+       /* BEFORE: loader_preinit */
 
-       if (!loader_init())
-               vm_abort("vm_create: loader_init failed");
+       package_init();
 
-       /* Link some important VM classes. */
-       /* AFTER: utf8_init */
+       /* AFTER: utf8_init, classcache_init */
 
-       if (!linker_init())
-               vm_abort("vm_create: linker_init failed");
+       loader_preinit();
+       linker_preinit();
 
-       if (!primitive_init())
-               vm_abort("vm_create: primitive_init failed");
+       /* AFTER: loader_preinit, linker_preinit */
 
-       if (!exceptions_init())
-               vm_abort("vm_create: exceptions_init failed");
+       primitive_init();
+
+       loader_init();
+       linker_init();
+
+       /* AFTER: loader_init, linker_init */
+
+       primitive_postinit();
+
+       exceptions_init();
 
        if (!builtin_init())
                vm_abort("vm_create: builtin_init failed");
@@ -1661,6 +1552,14 @@ bool vm_create(JavaVMInitArgs *vm_args)
                vm_abort("vm_create: jni_init failed");
 #endif
 
+#if defined(ENABLE_JNI) || defined(ENABLE_HANDLES)
+       /* Initialize the local reference table for the main thread. */
+       /* BEFORE: threads_init */
+
+       if (!localref_table_init())
+               vm_abort("vm_create: localref_table_init failed");
+#endif
+
 #if defined(ENABLE_THREADS)
        if (!threads_init())
                vm_abort("vm_create: threads_init failed");
@@ -1723,6 +1622,10 @@ bool vm_create(JavaVMInitArgs *vm_args)
 #endif
 
 #if defined(ENABLE_JVMTI)
+# if defined(ENABLE_GC_CACAO)
+       /* XXX this will not work with the new indirection cells for classloaders!!! */
+       assert(0);
+# endif
        if (jvmti) {
                /* add agent library to native library hashtable */
                native_hashtable_library_add(utf_new_char(libname), class_java_lang_Object->classloader, handle);
@@ -1737,6 +1640,14 @@ bool vm_create(JavaVMInitArgs *vm_args)
 
        vm_initializing = false;
 
+#if !defined(NDEBUG)
+       /* Print the VM configuration after all stuff is set and the VM is
+          initialized. */
+
+       if (opt_PrintConfig)
+               vm_printconfig();
+#endif
+
        /* everything's ok */
 
        return true;
@@ -1751,16 +1662,16 @@ bool vm_create(JavaVMInitArgs *vm_args)
 
 void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
 {
-       utf               *mainutf;
-       classinfo         *mainclass;
-       java_objectheader *e;
-       methodinfo        *m;
-       java_objectarray  *oa; 
-       s4                 oalength;
-       utf               *u;
-       java_objectheader *s;
-       s4                 status;
-       s4                 i;
+       utf                       *mainutf;
+       classinfo                 *mainclass;
+       java_handle_t             *e;
+       methodinfo                *m;
+       java_handle_objectarray_t *oa; 
+       s4                         oalength;
+       utf                       *u;
+       java_handle_t             *s;
+       s4                         status;
+       s4                         i;
 
 #if !defined(NDEBUG)
        if (compileall) {
@@ -1852,7 +1763,7 @@ void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
                u = utf_new_char(vm_args->options[opt_index + i].optionString);
                s = javastring_new(u);
 
-               oa->data[i] = s;
+               array_objectarray_element_set(oa, i, s);
        }
 
 #ifdef TYPEINFO_DEBUG_TEST
@@ -2088,6 +1999,55 @@ void vm_abort(const char *text, ...)
 }
 
 
+/* vm_abort_disassemble ********************************************************
+
+   Prints an error message, disassemble the given code range (if
+   enabled) and aborts the VM.
+
+   IN:
+       pc.......PC to disassemble
+          count....number of instructions to disassemble
+
+*******************************************************************************/
+
+void vm_abort_disassemble(void *pc, int count, const char *text, ...)
+{
+       va_list ap;
+#if defined(ENABLE_DISASSEMBLER)
+       int     i;
+#endif
+
+       /* Print debug message. */
+
+       log_start();
+
+       va_start(ap, text);
+       log_vprint(text, ap);
+       va_end(ap);
+
+       log_finish();
+
+       /* Print the PC. */
+
+#if SIZEOF_VOID_P == 8
+       log_println("PC=0x%016lx", pc);
+#else
+       log_println("PC=0x%08x", pc);
+#endif
+
+#if defined(ENABLE_DISASSEMBLER)
+       log_println("machine instructions at PC:");
+
+       /* Disassemble the given number of instructions. */
+
+       for (i = 0; i < count; i++)
+               pc = disassinstr(pc);
+#endif
+
+       vm_abort("Aborting...");
+}
+
+
 /* vm_get_mainclass_from_jar ***************************************************
 
    Gets the name of the main class from a JAR's manifest file.
@@ -2096,10 +2056,10 @@ void vm_abort(const char *text, ...)
 
 static char *vm_get_mainclass_from_jar(char *mainstring)
 {
-       classinfo         *c;
-       java_objectheader *o;
-       methodinfo        *m;
-       java_objectheader *s;
+       classinfo     *c;
+       java_handle_t *o;
+       methodinfo    *m;
+       java_handle_t *s;
 
        c = load_class_from_sysloader(utf_new_char("java/util/jar/JarFile"));
 
@@ -2160,7 +2120,9 @@ static char *vm_get_mainclass_from_jar(char *mainstring)
 
        /* get Main Attributes */
 
-       m = class_resolveclassmethod(o->vftbl->class,
+       LLNI_class_get(o, c);
+
+       m = class_resolveclassmethod(c,
                                                                 utf_new_char("getMainAttributes"), 
                                                                 utf_new_char("()Ljava/util/jar/Attributes;"),
                                                                 class_java_lang_Object,
@@ -2181,7 +2143,9 @@ static char *vm_get_mainclass_from_jar(char *mainstring)
 
        /* get property Main-Class */
 
-       m = class_resolveclassmethod(o->vftbl->class,
+       LLNI_class_get(o, c);
+
+       m = class_resolveclassmethod(c,
                                                                 utf_new_char("getValue"), 
                                                                 utf_new_char("(Ljava/lang/String;)Ljava/lang/String;"),
                                                                 class_java_lang_Object,
@@ -2328,1909 +2292,272 @@ static void vm_compile_method(void)
 #endif /* !defined(NDEBUG) */
 
 
-/* vm_array_store_int **********************************************************
+/* vm_call_array ***************************************************************
+
+   Calls a Java method with a variable number of arguments, passed via
+   an argument array.
 
-   Helper function to store an integer into the argument array, taking
-   care of architecture specific issues.
+   ATTENTION: This function has to be used outside the nativeworld.
 
 *******************************************************************************/
 
-static void vm_array_store_int(uint64_t *array, paramdesc *pd, int32_t value)
+#define VM_CALL_ARRAY(name, type)                                 \
+static type vm_call##name##_array(methodinfo *m, uint64_t *array) \
+{                                                                 \
+       methoddesc *md;                                               \
+       void       *pv;                                               \
+       type        value;                                            \
+                                                                  \
+       assert(m->code != NULL);                                      \
+                                                                  \
+       md = m->parseddesc;                                           \
+       pv = m->code->entrypoint;                                     \
+                                                                  \
+       STATISTICS(count_calls_native_to_java++);                     \
+                                                                  \
+       value = asm_vm_call_method##name(pv, array, md->memuse);      \
+                                                                  \
+       return value;                                                 \
+}
+
+static java_handle_t *vm_call_array(methodinfo *m, uint64_t *array)
 {
-       int32_t index;
+       methoddesc    *md;
+       void          *pv;
+       java_object_t *o;
 
-       if (!pd->inmemory) {
-               index        = pd->index;
-               array[index] = (int64_t) value;
-       }
-       else {
-               index        = ARG_CNT + pd->index;
-#if SIZEOF_VOID_P == 8
-               array[index] = (int64_t) value;
-#else
-# if WORDS_BIGENDIAN == 1
-               array[index] = ((int64_t) value) << 32;
-# else
-               array[index] = (int64_t) value;
-# endif
-#endif
-       }
-}
+       assert(m->code != NULL);
 
+       md = m->parseddesc;
+       pv = m->code->entrypoint;
 
-/* vm_array_store_lng **********************************************************
+       STATISTICS(count_calls_native_to_java++);
 
-   Helper function to store a long into the argument array, taking
-   care of architecture specific issues.
+       o = asm_vm_call_method(pv, array, md->memuse);
 
-*******************************************************************************/
+       if (md->returntype.type == TYPE_VOID)
+               o = NULL;
 
-static void vm_array_store_lng(uint64_t *array, paramdesc *pd, int64_t value)
-{
-       int32_t index;
+       return LLNI_WRAP(o);
+}
 
-#if SIZEOF_VOID_P == 8
-       if (!pd->inmemory)
-               index = pd->index;
-       else
-               index = ARG_CNT + pd->index;
+VM_CALL_ARRAY(_int,    int32_t)
+VM_CALL_ARRAY(_long,   int64_t)
+VM_CALL_ARRAY(_float,  float)
+VM_CALL_ARRAY(_double, double)
 
-       array[index] = value;
-#else
-       if (!pd->inmemory) {
-               /* move low and high 32-bits into it's own argument slot */
 
-               index        = GET_LOW_REG(pd->index);
-               array[index] = value & 0x00000000ffffffff;
+/* vm_call_method **************************************************************
 
-               index        = GET_HIGH_REG(pd->index);
-               array[index] = value >> 32;
-       }
-       else {
-               index        = ARG_CNT + pd->index;
-               array[index] = value;
-       }
-#endif
-}
-
-
-/* vm_array_store_flt **********************************************************
-
-   Helper function to store a float into the argument array, taking
-   care of architecture specific issues.
-
-*******************************************************************************/
-
-static void vm_array_store_flt(uint64_t *array, paramdesc *pd, uint64_t value)
-{
-       int32_t index;
-
-       if (!pd->inmemory) {
-#if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
-               index        = pd->index;
-#else
-               index        = INT_ARG_CNT + pd->index;
-#endif
-#if WORDS_BIGENDIAN == 1 && !defined(__POWERPC64__)
-               array[index] = value >> 32;
-#else
-               array[index] = value;
-#endif
-       }
-       else {
-               index        = ARG_CNT + pd->index;
-#if defined(__SPARC_64__)
-               array[index] = value >> 32;
-#else
-               array[index] = value;
-#endif
-       }
-}
-
-
-/* vm_array_store_dbl **********************************************************
-
-   Helper function to store a double into the argument array, taking
-   care of architecture specific issues.
-
-*******************************************************************************/
-
-static void vm_array_store_dbl(uint64_t *array, paramdesc *pd, uint64_t value)
-{
-       int32_t index;
-
-       if (!pd->inmemory) {
-#if SIZEOF_VOID_P != 8 && defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
-               index        = GET_LOW_REG(pd->index);
-               array[index] = value & 0x00000000ffffffff;
-
-               index        = GET_HIGH_REG(pd->index);
-               array[index] = value >> 32;
-#else
-               index        = INT_ARG_CNT + pd->index;
-               array[index] = value;
-#endif
-       }
-       else {
-               index        = ARG_CNT + pd->index;
-               array[index] = value;
-       }
-}
-
-
-/* vm_array_store_adr **********************************************************
-
-   Helper function to store an address into the argument array, taking
-   care of architecture specific issues.
-
-*******************************************************************************/
-
-static void vm_array_store_adr(uint64_t *array, paramdesc *pd, void *value)
-{
-       int32_t index;
-
-       if (!pd->inmemory) {
-#if defined(HAS_ADDRESS_REGISTER_FILE)
-               /* When the architecture has address registers, place them
-                  after integer and float registers. */
-
-               index        = INT_ARG_CNT + FLT_ARG_CNT + pd->index;
-#else
-               index        = pd->index;
-#endif
-               array[index] = (uint64_t) (intptr_t) value;
-       }
-       else {
-               index        = ARG_CNT + pd->index;
-#if SIZEOF_VOID_P == 8
-               array[index] = (uint64_t) (intptr_t) value;
-#else
-# if WORDS_BIGENDIAN == 1 && !defined(__POWERPC64__)
-               array[index] = ((uint64_t) (intptr_t) value) << 32;
-# else
-               array[index] = (uint64_t) (intptr_t) value;
-# endif
-#endif
-       }
-}
-
-
-/* vm_vmargs_from_valist *******************************************************
-
-   XXX
-
-*******************************************************************************/
-
-#if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
-static void vm_vmargs_from_valist(methodinfo *m, java_objectheader *o,
-                                                                 vm_arg *vmargs, va_list ap)
-{
-       typedesc *paramtypes;
-       s4        i;
-
-       paramtypes = m->parseddesc->paramtypes;
-
-       /* if method is non-static fill first block and skip `this' pointer */
-
-       i = 0;
-
-       if (o != NULL) {
-               /* the `this' pointer */
-               vmargs[0].type   = TYPE_ADR;
-               vmargs[0].data.l = (u8) (ptrint) o;
-
-               paramtypes++;
-               i++;
-       } 
-
-       for (; i < m->parseddesc->paramcount; i++, paramtypes++) {
-               switch (paramtypes->type) {
-               case TYPE_INT:
-                       vmargs[i].type   = TYPE_INT;
-                       vmargs[i].data.l = (s8) va_arg(ap, s4);
-                       break;
-
-               case TYPE_LNG:
-                       vmargs[i].type   = TYPE_LNG;
-                       vmargs[i].data.l = (s8) va_arg(ap, s8);
-                       break;
-
-               case TYPE_FLT:
-                       vmargs[i].type   = TYPE_FLT;
-#if defined(__ALPHA__)
-                       /* this keeps the assembler function much simpler */
-
-                       vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
-#else
-                       vmargs[i].data.f = (jfloat) va_arg(ap, jdouble);
-#endif
-                       break;
-
-               case TYPE_DBL:
-                       vmargs[i].type   = TYPE_DBL;
-                       vmargs[i].data.d = (jdouble) va_arg(ap, jdouble);
-                       break;
-
-               case TYPE_ADR: 
-                       vmargs[i].type   = TYPE_ADR;
-                       vmargs[i].data.l = (u8) (ptrint) va_arg(ap, void*);
-                       break;
-               }
-       }
-}
-#else
-uint64_t *vm_array_from_valist(methodinfo *m, java_objectheader *o, va_list ap)
-{
-       methoddesc *md;
-       paramdesc  *pd;
-       typedesc   *td;
-       uint64_t   *array;
-       int32_t     i;
-       imm_union   value;
-
-       /* get the descriptors */
-
-       md = m->parseddesc;
-       pd = md->params;
-       td = md->paramtypes;
-
-       /* allocate argument array */
-
-       array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + md->memuse);
-
-       /* if method is non-static fill first block and skip `this' pointer */
-
-       i = 0;
-
-       if (o != NULL) {
-               /* the `this' pointer */
-               vm_array_store_adr(array, pd, o);
-
-               pd++;
-               td++;
-               i++;
-       } 
-
-       for (; i < md->paramcount; i++, pd++, td++) {
-               switch (td->type) {
-               case TYPE_INT:
-                       value.i = va_arg(ap, int32_t);
-                       vm_array_store_int(array, pd, value.i);
-                       break;
-
-               case TYPE_LNG:
-                       value.l = va_arg(ap, int64_t);
-                       vm_array_store_lng(array, pd, value.l);
-                       break;
-
-               case TYPE_FLT:
-#if defined(__ALPHA__) || defined(__POWERPC64__)
-                       /* this keeps the assembler function much simpler */
-
-                       value.d = (double) va_arg(ap, double);
-#else
-                       value.f = (float) va_arg(ap, double);
-#endif
-                       vm_array_store_flt(array, pd, value.l);
-                       break;
-
-               case TYPE_DBL:
-                       value.d = va_arg(ap, double);
-                       vm_array_store_dbl(array, pd, value.l);
-                       break;
-
-               case TYPE_ADR: 
-                       value.a = va_arg(ap, void*);
-                       vm_array_store_adr(array, pd, value.a);
-                       break;
-               }
-       }
-
-       return array;
-}
-#endif
-
-
-/* vm_vmargs_from_jvalue *******************************************************
-
-   XXX
-
-*******************************************************************************/
-
-#if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
-static void vm_vmargs_from_jvalue(methodinfo *m, java_objectheader *o,
-                                                                 vm_arg *vmargs, const jvalue *args)
-{
-       typedesc *paramtypes;
-       s4        i;
-       s4        j;
-
-       paramtypes = m->parseddesc->paramtypes;
-
-       /* if method is non-static fill first block and skip `this' pointer */
-
-       i = 0;
-
-       if (o != NULL) {
-               /* the `this' pointer */
-               vmargs[0].type   = TYPE_ADR;
-               vmargs[0].data.l = (u8) (ptrint) o;
-
-               paramtypes++;
-               i++;
-       } 
-
-       for (j = 0; i < m->parseddesc->paramcount; i++, j++, paramtypes++) {
-               switch (paramtypes->decltype) {
-               case TYPE_INT:
-                       vmargs[i].type   = TYPE_INT;
-                       vmargs[i].data.l = (s8) args[j].i;
-                       break;
-
-               case TYPE_LNG:
-                       vmargs[i].type   = TYPE_LNG;
-                       vmargs[i].data.l = (s8) args[j].j;
-                       break;
-
-               case TYPE_FLT:
-                       vmargs[i].type = TYPE_FLT;
-#if defined(__ALPHA__)
-                       /* this keeps the assembler function much simpler */
-
-                       vmargs[i].data.d = (jdouble) args[j].f;
-#else
-                       vmargs[i].data.f = args[j].f;
-#endif
-                       break;
-
-               case TYPE_DBL:
-                       vmargs[i].type   = TYPE_DBL;
-                       vmargs[i].data.d = args[j].d;
-                       break;
-
-               case TYPE_ADR: 
-                       vmargs[i].type   = TYPE_ADR;
-                       vmargs[i].data.l = (u8) (ptrint) args[j].l;
-                       break;
-               }
-       }
-}
-#else
-static uint64_t *vm_array_from_jvalue(methodinfo *m, java_objectheader *o,
-                                                                         const jvalue *args)
-{
-       methoddesc *md;
-       paramdesc  *pd;
-       typedesc   *td;
-       uint64_t   *array;
-       int32_t     i;
-       int32_t     j;
-
-       /* get the descriptors */
-
-       md = m->parseddesc;
-       pd = md->params;
-       td = md->paramtypes;
-
-       /* allocate argument array */
-
-#if defined(HAS_ADDRESS_REGISTER_FILE)
-       array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + ADR_ARG_CNT + md->memuse);
-#else
-       array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + md->memuse);
-#endif
-
-       /* if method is non-static fill first block and skip `this' pointer */
-
-       i = 0;
-
-       if (o != NULL) {
-               /* the `this' pointer */
-               vm_array_store_adr(array, pd, o);
-
-               pd++;
-               td++;
-               i++;
-       } 
-
-       for (j = 0; i < md->paramcount; i++, j++, pd++, td++) {
-               switch (td->decltype) {
-               case TYPE_INT:
-                       vm_array_store_int(array, pd, args[j].i);
-                       break;
-
-               case TYPE_LNG:
-                       vm_array_store_lng(array, pd, args[j].j);
-                       break;
-
-               case TYPE_FLT:
-                       vm_array_store_flt(array, pd, args[j].j);
-                       break;
-
-               case TYPE_DBL:
-                       vm_array_store_dbl(array, pd, args[j].j);
-                       break;
-
-               case TYPE_ADR: 
-                       vm_array_store_adr(array, pd, args[j].l);
-                       break;
-               }
-       }
-
-       return array;
-}
-#endif
-
-/* vm_vmargs_from_objectarray **************************************************
-
-   XXX
-
-*******************************************************************************/
-
-#if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
-bool vm_vmargs_from_objectarray(methodinfo *m, java_objectheader *o,
-                                                               vm_arg *vmargs, java_objectarray *params)
-{
-       java_objectheader *param;
-       typedesc          *paramtypes;
-       classinfo         *c;
-       int32_t            i;
-       int32_t            j;
-       int64_t            value;
-
-       paramtypes = m->parseddesc->paramtypes;
-
-       /* if method is non-static fill first block and skip `this' pointer */
-
-       i = 0;
-
-       if (o != NULL) {
-               /* this pointer */
-               vmargs[0].type   = TYPE_ADR;
-               vmargs[0].data.l = (uint64_t) (intptr_t) o;
-
-               paramtypes++;
-               i++;
-       }
-
-       for (j = 0; i < m->parseddesc->paramcount; i++, j++, paramtypes++) {
-               switch (paramtypes->type) {
-               /* primitive types */
-               case TYPE_INT:
-               case TYPE_LNG:
-               case TYPE_FLT:
-               case TYPE_DBL:
-                       param = params->data[j];
-
-                       if (param == NULL)
-                               goto illegal_arg;
-
-                       /* internally used data type */
-                       vmargs[i].type = paramtypes->type;
-
-                       /* convert the value according to its declared type */
-
-                       c = param->vftbl->class;
-
-                       switch (paramtypes->decltype) {
-                       case PRIMITIVETYPE_BOOLEAN:
-                               if (c == class_java_lang_Boolean)
-                                       value = (int64_t) ((java_lang_Boolean *) param)->value;
-                               else
-                                       goto illegal_arg;
-
-                               vmargs[i].data.l = value;
-                               break;
-
-                       case PRIMITIVETYPE_BYTE:
-                               if (c == class_java_lang_Byte)
-                                       value = (int64_t) ((java_lang_Byte *) param)->value;
-                               else
-                                       goto illegal_arg;
-
-                               vmargs[i].data.l = value;
-                               break;
-
-                       case PRIMITIVETYPE_CHAR:
-                               if (c == class_java_lang_Character)
-                                       value = (int64_t) ((java_lang_Character *) param)->value;
-                               else
-                                       goto illegal_arg;
-
-                               vmargs[i].data.l = value;
-                               break;
-
-                       case PRIMITIVETYPE_SHORT:
-                               if (c == class_java_lang_Short)
-                                       value = (int64_t) ((java_lang_Short *) param)->value;
-                               else if (c == class_java_lang_Byte)
-                                       value = (int64_t) ((java_lang_Byte *) param)->value;
-                               else
-                                       goto illegal_arg;
-
-                               vmargs[i].data.l = value;
-                               break;
-
-                       case PRIMITIVETYPE_INT:
-                               if (c == class_java_lang_Integer)
-                                       value = (int64_t) ((java_lang_Integer *) param)->value;
-                               else if (c == class_java_lang_Short)
-                                       value = (int64_t) ((java_lang_Short *) param)->value;
-                               else if (c == class_java_lang_Byte)
-                                       value = (int64_t) ((java_lang_Byte *) param)->value;
-                               else
-                                       goto illegal_arg;
-
-                               vmargs[i].data.l = value;
-                               break;
-
-                       case PRIMITIVETYPE_LONG:
-                               if (c == class_java_lang_Long)
-                                       value = (int64_t) ((java_lang_Long *) param)->value;
-                               else if (c == class_java_lang_Integer)
-                                       value = (int64_t) ((java_lang_Integer *) param)->value;
-                               else if (c == class_java_lang_Short)
-                                       value = (int64_t) ((java_lang_Short *) param)->value;
-                               else if (c == class_java_lang_Byte)
-                                       value = (int64_t) ((java_lang_Byte *) param)->value;
-                               else
-                                       goto illegal_arg;
-
-                               vmargs[i].data.l = value;
-                               break;
-
-                       case PRIMITIVETYPE_FLOAT:
-                               if (c == class_java_lang_Float)
-                                       vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
-                               else
-                                       goto illegal_arg;
-                               break;
-
-                       case PRIMITIVETYPE_DOUBLE:
-                               if (c == class_java_lang_Double)
-                                       vmargs[i].data.d = (jdouble) ((java_lang_Double *) param)->value;
-                               else if (c == class_java_lang_Float)
-                                       vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
-                               else
-                                       goto illegal_arg;
-                               break;
-
-                       default:
-                               goto illegal_arg;
-                       }
-                       break;
-               
-               case TYPE_ADR:
-                       if (!resolve_class_from_typedesc(paramtypes, true, true, &c))
-                               return false;
-
-                       if (params->data[j] != 0) {
-                               if (paramtypes->arraydim > 0) {
-                                       if (!builtin_arrayinstanceof(params->data[j], c))
-                                               goto illegal_arg;
-
-                               } else {
-                                       if (!builtin_instanceof(params->data[j], c))
-                                               goto illegal_arg;
-                               }
-                       }
-
-                       vmargs[i].type   = TYPE_ADR;
-                       vmargs[i].data.l = (u8) (ptrint) params->data[j];
-                       break;
-
-               default:
-                       goto illegal_arg;
-               }
-       }
-
-/*     if (rettype) */
-/*             *rettype = descr->returntype.decltype; */
-
-       return true;
-
-illegal_arg:
-       exceptions_throw_illegalargumentexception();
-       return false;
-}
-#else
-uint64_t *vm_array_from_objectarray(methodinfo *m, java_objectheader *o,
-                                                                       java_objectarray *params)
-{
-       methoddesc        *md;
-       paramdesc         *pd;
-       typedesc          *td;
-       uint64_t          *array;
-       java_objectheader *param;
-       classinfo         *c;
-       int32_t            i;
-       int32_t            j;
-       imm_union          value;
-
-       /* get the descriptors */
-
-       md = m->parseddesc;
-       pd = md->params;
-       td = md->paramtypes;
-
-       /* allocate argument array */
-
-       array = DMNEW(uint64_t, INT_ARG_CNT + FLT_ARG_CNT + md->memuse);
-
-       /* if method is non-static fill first block and skip `this' pointer */
-
-       i = 0;
-
-       if (o != NULL) {
-               /* this pointer */
-               vm_array_store_adr(array, pd, o);
-
-               pd++;
-               td++;
-               i++;
-       }
-
-       for (j = 0; i < md->paramcount; i++, j++, pd++, td++) {
-               param = params->data[j];
-
-               switch (td->type) {
-               case TYPE_INT:
-                       if (param == NULL)
-                               goto illegal_arg;
-
-                       /* convert the value according to its declared type */
-
-                       c = param->vftbl->class;
-
-                       switch (td->decltype) {
-                       case PRIMITIVETYPE_BOOLEAN:
-                               if (c == class_java_lang_Boolean)
-                                       value.i = ((java_lang_Boolean *) param)->value;
-                               else
-                                       goto illegal_arg;
-                               break;
-
-                       case PRIMITIVETYPE_BYTE:
-                               if (c == class_java_lang_Byte)
-                                       value.i = ((java_lang_Byte *) param)->value;
-                               else
-                                       goto illegal_arg;
-                               break;
-
-                       case PRIMITIVETYPE_CHAR:
-                               if (c == class_java_lang_Character)
-                                       value.i = ((java_lang_Character *) param)->value;
-                               else
-                                       goto illegal_arg;
-                               break;
-
-                       case PRIMITIVETYPE_SHORT:
-                               if (c == class_java_lang_Short)
-                                       value.i = ((java_lang_Short *) param)->value;
-                               else if (c == class_java_lang_Byte)
-                                       value.i = ((java_lang_Byte *) param)->value;
-                               else
-                                       goto illegal_arg;
-                               break;
-
-                       case PRIMITIVETYPE_INT:
-                               if (c == class_java_lang_Integer)
-                                       value.i = ((java_lang_Integer *) param)->value;
-                               else if (c == class_java_lang_Short)
-                                       value.i = ((java_lang_Short *) param)->value;
-                               else if (c == class_java_lang_Byte)
-                                       value.i = ((java_lang_Byte *) param)->value;
-                               else
-                                       goto illegal_arg;
-                               break;
-
-                       default:
-                               goto illegal_arg;
-                       }
-
-                       vm_array_store_int(array, pd, value.i);
-                       break;
-
-               case TYPE_LNG:
-                       if (param == NULL)
-                               goto illegal_arg;
-
-                       /* convert the value according to its declared type */
-
-                       c = param->vftbl->class;
-
-                       switch (td->decltype) {
-                       case PRIMITIVETYPE_LONG:
-                               if (c == class_java_lang_Long)
-                                       value.l = ((java_lang_Long *) param)->value;
-                               else if (c == class_java_lang_Integer)
-                                       value.l = (int64_t) ((java_lang_Integer *) param)->value;
-                               else if (c == class_java_lang_Short)
-                                       value.l = (int64_t) ((java_lang_Short *) param)->value;
-                               else if (c == class_java_lang_Byte)
-                                       value.l = (int64_t) ((java_lang_Byte *) param)->value;
-                               else
-                                       goto illegal_arg;
-                               break;
-
-                       default:
-                               goto illegal_arg;
-                       }
-
-                       vm_array_store_lng(array, pd, value.l);
-                       break;
-
-               case TYPE_FLT:
-                       if (param == NULL)
-                               goto illegal_arg;
-
-                       /* convert the value according to its declared type */
-
-                       c = param->vftbl->class;
-
-                       switch (td->decltype) {
-                       case PRIMITIVETYPE_FLOAT:
-                               if (c == class_java_lang_Float)
-                                       value.f = ((java_lang_Float *) param)->value;
-                               else
-                                       goto illegal_arg;
-                               break;
-
-                       default:
-                               goto illegal_arg;
-                       }
-
-                       vm_array_store_flt(array, pd, value.l);
-                       break;
-
-               case TYPE_DBL:
-                       if (param == NULL)
-                               goto illegal_arg;
-
-                       /* convert the value according to its declared type */
-
-                       c = param->vftbl->class;
-
-                       switch (td->decltype) {
-                       case PRIMITIVETYPE_DOUBLE:
-                               if (c == class_java_lang_Double)
-                                       value.d = ((java_lang_Double *) param)->value;
-                               else if (c == class_java_lang_Float)
-                                       value.f = ((java_lang_Float *) param)->value;
-                               else
-                                       goto illegal_arg;
-                               break;
-
-                       default:
-                               goto illegal_arg;
-                       }
-
-                       vm_array_store_dbl(array, pd, value.l);
-                       break;
-               
-               case TYPE_ADR:
-                       if (!resolve_class_from_typedesc(td, true, true, &c))
-                               return false;
-
-                       if (param != NULL) {
-                               if (td->arraydim > 0) {
-                                       if (!builtin_arrayinstanceof(param, c))
-                                               goto illegal_arg;
-                               }
-                               else {
-                                       if (!builtin_instanceof(param, c))
-                                               goto illegal_arg;
-                               }
-                       }
-
-                       vm_array_store_adr(array, pd, param);
-                       break;
-
-               default:
-                       goto illegal_arg;
-               }
-       }
-
-       return array;
-
-illegal_arg:
-       exceptions_throw_illegalargumentexception();
-       return NULL;
-}
-#endif
-
-
-/* vm_call_method **************************************************************
-
-   Calls a Java method with a variable number of arguments and returns
-   an address.
-
-*******************************************************************************/
-
-java_objectheader *vm_call_method(methodinfo *m, java_objectheader *o, ...)
-{
-       va_list            ap;
-       java_objectheader *ro;
-
-       va_start(ap, o);
-       ro = vm_call_method_valist(m, o, ap);
-       va_end(ap);
-
-       return ro;
-}
-
-
-/* vm_call_method_valist *******************************************************
-
-   Calls a Java method with a variable number of arguments, passed via
-   a va_list, and returns an address.
-
-*******************************************************************************/
-
-java_objectheader *vm_call_method_valist(methodinfo *m, java_objectheader *o,
-                                                                                va_list ap)
-{
-#if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
-       s4                 vmargscount;
-       vm_arg            *vmargs;
-       java_objectheader *ro;
-       s4                 dumpsize;
-
-       /* mark start of dump memory area */
-
-       dumpsize = dump_size();
-
-       /* get number of Java method arguments */
-
-       vmargscount = m->parseddesc->paramcount;
-
-       /* allocate vm_arg array */
-
-       vmargs = DMNEW(vm_arg, vmargscount);
-
-       /* fill the vm_arg array from a va_list */
-
-       vm_vmargs_from_valist(m, o, vmargs, ap);
-
-       /* call the Java method */
-
-       ro = vm_call_method_vmarg(m, vmargscount, vmargs);
-
-       /* release dump area */
-
-       dump_release(dumpsize);
-
-       return ro;
-#else
-       java_objectheader *ro;
-       int32_t            dumpsize;
-       uint64_t          *array;
-
-       /* mark start of dump memory area */
-
-       dumpsize = dump_size();
-
-       /* fill the argument array from a va_list */
-
-       array = vm_array_from_valist(m, o, ap);
-
-       /* call the Java method */
-
-       ro = vm_call_array(m, array);
-
-       /* release dump area */
-
-       dump_release(dumpsize);
-
-       return ro;
-#endif
-}
-
-
-/* vm_call_method_jvalue *******************************************************
-
-   Calls a Java method with a variable number of arguments, passed via
-   a jvalue array, and returns an address.
-
-*******************************************************************************/
-
-java_objectheader *vm_call_method_jvalue(methodinfo *m, java_objectheader *o,
-                                                                                const jvalue *args)
-{
-#if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
-       s4                 vmargscount;
-       vm_arg            *vmargs;
-       java_objectheader *ro;
-       s4                 dumpsize;
-
-       /* mark start of dump memory area */
-
-       dumpsize = dump_size();
-
-       /* get number of Java method arguments */
-
-       vmargscount = m->parseddesc->paramcount;
-
-       /* allocate vm_arg array */
-
-       vmargs = DMNEW(vm_arg, vmargscount);
-
-       /* fill the vm_arg array from a va_list */
-
-       vm_vmargs_from_jvalue(m, o, vmargs, args);
-
-       /* call the Java method */
-
-       ro = vm_call_method_vmarg(m, vmargscount, vmargs);
-
-       /* release dump area */
-
-       dump_release(dumpsize);
-
-       return ro;
-#else
-       java_objectheader *ro;
-       int32_t            dumpsize;
-       uint64_t          *array;
-
-       /* mark start of dump memory area */
-
-       dumpsize = dump_size();
-
-       /* fill the argument array from a va_list */
-
-       array = vm_array_from_jvalue(m, o, args);
-
-       /* call the Java method */
-
-       ro = vm_call_array(m, array);
-
-       /* release dump area */
-
-       dump_release(dumpsize);
-
-       return ro;
-#endif
-}
-
-
-/* vm_call_array ***************************************************************
-
-   Calls a Java method with a variable number of arguments, passed via
-   an argument array, and returns an address.
-
-*******************************************************************************/
-
-#if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
-java_objectheader *vm_call_method_vmarg(methodinfo *m, s4 vmargscount,
-                                                                               vm_arg *vmargs)
-{
-       java_objectheader *o;
-
-       STATISTICS(count_calls_native_to_java++);
-
-#if defined(ENABLE_JIT)
-# if defined(ENABLE_INTRP)
-       if (opt_intrp)
-               o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
-       else
-# endif
-               o = asm_vm_call_method(m, vmargscount, vmargs);
-#else
-       o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
-#endif
-
-       return o;
-}
-#else
-java_objectheader *vm_call_array(methodinfo *m, uint64_t *array)
-{
-       methoddesc        *md;
-       java_objectheader *o;
-
-       md = m->parseddesc;
-
-       /* compile the method if not already done */
-
-       if (m->code == NULL)
-               if (!jit_compile(m))
-                       return NULL;
-
-       STATISTICS(count_calls_native_to_java++);
-
-#if defined(ENABLE_JIT)
-# if defined(ENABLE_INTRP)
-       if (opt_intrp)
-               o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
-       else
-# endif
-               o = asm_vm_call_method(m->code->entrypoint, array, md->memuse);
-#else
-       o = intrp_asm_vm_call_method(m, vmargscount, vmargs);
-#endif
-
-       return o;
-}
-#endif
-
-
-/* vm_call_int_array ***********************************************************
-
-   Calls a Java method with a variable number of arguments, passed via
-   an argument array, and returns an integer (int32_t).
-
-*******************************************************************************/
-
-#if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
-s4 vm_call_method_int_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
-{
-       s4 i;
-
-       STATISTICS(count_calls_native_to_java++);
-
-#if defined(ENABLE_JIT)
-# if defined(ENABLE_INTRP)
-       if (opt_intrp)
-               i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
-       else
-# endif
-               i = asm_vm_call_method_int(m, vmargscount, vmargs);
-#else
-       i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
-#endif
-
-       return i;
-}
-#else
-int32_t vm_call_int_array(methodinfo *m, uint64_t *array)
-{
-       methoddesc *md;
-       int32_t     i;
-
-       md = m->parseddesc;
-
-       /* compile the method if not already done */
-
-       if (m->code == NULL)
-               if (!jit_compile(m))
-                       return 0;
-
-       STATISTICS(count_calls_native_to_java++);
-
-#if defined(ENABLE_JIT)
-# if defined(ENABLE_INTRP)
-       if (opt_intrp)
-               i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
-       else
-# endif
-               i = asm_vm_call_method_int(m->code->entrypoint, array, md->memuse);
-#else
-       i = intrp_asm_vm_call_method_int(m, vmargscount, vmargs);
-#endif
-
-       return i;
-}
-#endif
-
-
-/* vm_call_method_int **********************************************************
-
-   Calls a Java method with a variable number of arguments and returns
-   an integer (s4).
-
-*******************************************************************************/
-
-s4 vm_call_method_int(methodinfo *m, java_objectheader *o, ...)
-{
-       va_list ap;
-       s4      i;
-
-       va_start(ap, o);
-       i = vm_call_method_int_valist(m, o, ap);
-       va_end(ap);
-
-       return i;
-}
-
-
-/* vm_call_method_int_valist ***************************************************
-
-   Calls a Java method with a variable number of arguments, passed via
-   a va_list, and returns an integer (int32_t).
-
-*******************************************************************************/
-
-#if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
-s4 vm_call_method_int_valist(methodinfo *m, java_objectheader *o, va_list ap)
-{
-       s4      vmargscount;
-       vm_arg *vmargs;
-       s4      i;
-       s4      dumpsize;
-
-       /* mark start of dump memory area */
-
-       dumpsize = dump_size();
-
-       /* get number of Java method arguments */
-
-       vmargscount = m->parseddesc->paramcount;
-
-       /* allocate vm_arg array */
-
-       vmargs = DMNEW(vm_arg, vmargscount);
-
-       /* fill the vm_arg array from a va_list */
-
-       vm_vmargs_from_valist(m, o, vmargs, ap);
-
-       /* call the Java method */
-
-       i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
-
-       /* release dump area */
-
-       dump_release(dumpsize);
-
-       return i;
-}
-#else
-int32_t vm_call_method_int_valist(methodinfo *m, java_objectheader *o, va_list ap)
-{
-       int32_t   dumpsize;
-       uint64_t *array;
-       int32_t   i;
-
-       /* mark start of dump memory area */
-
-       dumpsize = dump_size();
-
-       /* fill the argument array from a va_list */
-
-       array = vm_array_from_valist(m, o, ap);
-
-       /* call the Java method */
-
-       i = vm_call_int_array(m, array);
-
-       /* release dump area */
-
-       dump_release(dumpsize);
-
-       return i;
-}
-#endif
-
-
-/* vm_call_method_int_jvalue ***************************************************
-
-   Calls a Java method with a variable number of arguments, passed via
-   a jvalue array, and returns an integer (s4).
-
-*******************************************************************************/
-
-#if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
-s4 vm_call_method_int_jvalue(methodinfo *m, java_objectheader *o,
-                                                        const jvalue *args)
-{
-       s4      vmargscount;
-       vm_arg *vmargs;
-       s4      i;
-       s4      dumpsize;
-
-       /* mark start of dump memory area */
-
-       dumpsize = dump_size();
-
-       /* get number of Java method arguments */
-
-       vmargscount = m->parseddesc->paramcount;
-
-       /* allocate vm_arg array */
-
-       vmargs = DMNEW(vm_arg, vmargscount);
-
-       /* fill the vm_arg array from a va_list */
-
-       vm_vmargs_from_jvalue(m, o, vmargs, args);
-
-       /* call the Java method */
-
-       i = vm_call_method_int_vmarg(m, vmargscount, vmargs);
-
-       /* release dump area */
-
-       dump_release(dumpsize);
-
-       return i;
-}
-#else
-int32_t vm_call_method_int_jvalue(methodinfo *m, java_objectheader *o,
-                                                                 const jvalue *args)
-{
-       int32_t   dumpsize;
-       uint64_t *array;
-       int32_t   i;
-
-       /* mark start of dump memory area */
-
-       dumpsize = dump_size();
-
-       /* fill the argument array from a va_list */
-
-       array = vm_array_from_jvalue(m, o, args);
-
-       /* call the Java method */
-
-       i = vm_call_int_array(m, array);
-
-       /* release dump area */
-
-       dump_release(dumpsize);
-
-       return i;
-}
-#endif
-
-
-/* vm_call_long_array **********************************************************
-
-   Calls a Java method with a variable number of arguments, passed via
-   an argument array, and returns a long (int64_t).
-
-*******************************************************************************/
-
-#if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
-s8 vm_call_method_long_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
-{
-       s8 l;
-
-       STATISTICS(count_calls_native_to_java++);
-
-#if defined(ENABLE_JIT)
-# if defined(ENABLE_INTRP)
-       if (opt_intrp)
-               l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
-       else
-# endif
-               l = asm_vm_call_method_long(m, vmargscount, vmargs);
-#else
-       l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
-#endif
-
-       return l;
-}
-#else
-int64_t vm_call_long_array(methodinfo *m, uint64_t *array)
-{
-       methoddesc *md;
-       int64_t     l;
-
-       md = m->parseddesc;
-
-       /* compile the method if not already done */
-
-       if (m->code == NULL)
-               if (!jit_compile(m))
-                       return 0;
-
-       STATISTICS(count_calls_native_to_java++);
-
-#if defined(ENABLE_JIT)
-# if defined(ENABLE_INTRP)
-       if (opt_intrp)
-               l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
-       else
-# endif
-               l = asm_vm_call_method_long(m->code->entrypoint, array, md->memuse);
-#else
-       l = intrp_asm_vm_call_method_long(m, vmargscount, vmargs);
-#endif
-
-       return l;
-}
-#endif
-
-
-/* vm_call_method_long *********************************************************
-
-   Calls a Java method with a variable number of arguments and returns
-   a long (s8).
-
-*******************************************************************************/
-
-s8 vm_call_method_long(methodinfo *m, java_objectheader *o, ...)
-{
-       va_list ap;
-       s8      l;
-
-       va_start(ap, o);
-       l = vm_call_method_long_valist(m, o, ap);
-       va_end(ap);
-
-       return l;
-}
-
-
-/* vm_call_method_long_valist **************************************************
-
-   Calls a Java method with a variable number of arguments, passed via
-   a va_list, and returns a long (s8).
-
-*******************************************************************************/
-
-#if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
-s8 vm_call_method_long_valist(methodinfo *m, java_objectheader *o, va_list ap)
-{
-       s4      vmargscount;
-       vm_arg *vmargs;
-       s8      l;
-       s4      dumpsize;
-
-       /* mark start of dump memory area */
-
-       dumpsize = dump_size();
-
-       /* get number of Java method arguments */
-
-       vmargscount = m->parseddesc->paramcount;
-
-       /* allocate vm_arg array */
-
-       vmargs = DMNEW(vm_arg, vmargscount);
-
-       /* fill the vm_arg array from a va_list */
-
-       vm_vmargs_from_valist(m, o, vmargs, ap);
-
-       /* call the Java method */
-
-       l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
-
-       /* release dump area */
-
-       dump_release(dumpsize);
-
-       return l;
-}
-#else
-int64_t vm_call_method_long_valist(methodinfo *m, java_objectheader *o, va_list ap)
-{
-       int32_t   dumpsize;
-       uint64_t *array;
-       int64_t   l;
-
-       /* mark start of dump memory area */
-
-       dumpsize = dump_size();
-
-       /* fill the argument array from a va_list */
-
-       array = vm_array_from_valist(m, o, ap);
-
-       /* call the Java method */
-
-       l = vm_call_long_array(m, array);
-
-       /* release dump area */
-
-       dump_release(dumpsize);
-
-       return l;
-}
-#endif
-
-
-/* vm_call_method_long_jvalue **************************************************
-
-   Calls a Java method with a variable number of arguments, passed via
-   a jvalue array, and returns a long (s8).
-
-*******************************************************************************/
-
-#if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
-s8 vm_call_method_long_jvalue(methodinfo *m, java_objectheader *o,
-                                                         const jvalue *args)
-{
-       s4      vmargscount;
-       vm_arg *vmargs;
-       s8      l;
-       s4      dumpsize;
-
-       /* mark start of dump memory area */
-
-       dumpsize = dump_size();
-
-       /* get number of Java method arguments */
-
-       vmargscount = m->parseddesc->paramcount;
-
-       /* allocate vm_arg array */
-
-       vmargs = DMNEW(vm_arg, vmargscount);
-
-       /* fill the vm_arg array from a va_list */
-
-       vm_vmargs_from_jvalue(m, o, vmargs, args);
-
-       /* call the Java method */
-
-       l = vm_call_method_long_vmarg(m, vmargscount, vmargs);
-
-       /* release dump area */
-
-       dump_release(dumpsize);
-
-       return l;
-}
-#else
-int64_t vm_call_method_long_jvalue(methodinfo *m, java_objectheader *o,
-                                                                  const jvalue *args)
-{
-       int32_t   dumpsize;
-       uint64_t *array;
-       int64_t   l;
-
-       /* mark start of dump memory area */
-
-       dumpsize = dump_size();
-
-       /* fill the argument array from a va_list */
-
-       array = vm_array_from_jvalue(m, o, args);
-
-       /* call the Java method */
-
-       l = vm_call_long_array(m, array);
-
-       /* release dump area */
-
-       dump_release(dumpsize);
-
-       return l;
-}
-#endif
-
-
-/* vm_call_float_array *********************************************************
-
-   Calls a Java method with a variable number of arguments and returns
-   an float.
+   Calls a Java method with a variable number of arguments.
 
 *******************************************************************************/
 
-#if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
-float vm_call_method_float_vmarg(methodinfo *m, s4 vmargscount, vm_arg *vmargs)
-{
-       float f;
-
-       vm_abort("IMPLEMENT ME!");
-
-       STATISTICS(count_calls_native_to_java++);
-
-#if defined(ENABLE_JIT)
-# if defined(ENABLE_INTRP)
-       if (opt_intrp)
-               f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
-       else
-# endif
-               f = asm_vm_call_method_float(m, vmargscount, vmargs);
-#else
-       f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
-#endif
-
-       return f;
-}
-#else
-float vm_call_float_array(methodinfo *m, uint64_t *array)
-{
-       methoddesc *md;
-       float       f;
-
-       md = m->parseddesc;
-
-       /* compile the method if not already done */
-
-       if (m->code == NULL)
-               if (!jit_compile(m))
-                       return 0;
-
-       STATISTICS(count_calls_native_to_java++);
-
-#if defined(ENABLE_JIT)
-# if defined(ENABLE_INTRP)
-       if (opt_intrp)
-               f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
-       else
-# endif
-               f = asm_vm_call_method_float(m->code->entrypoint, array, md->memuse);
-#else
-       f = intrp_asm_vm_call_method_float(m, vmargscount, vmargs);
-#endif
-
-       return f;
+#define VM_CALL_METHOD(name, type)                                  \
+type vm_call_method##name(methodinfo *m, java_handle_t *o, ...)     \
+{                                                                   \
+       va_list ap;                                                     \
+       type    value;                                                  \
+                                                                    \
+       va_start(ap, o);                                                \
+       value = vm_call_method##name##_valist(m, o, ap);                \
+       va_end(ap);                                                     \
+                                                                    \
+       return value;                                                   \
 }
-#endif
-
-/* vm_call_method_float ********************************************************
-
-   Calls a Java method with a variable number of arguments and returns
-   an float.
-
-*******************************************************************************/
-
-float vm_call_method_float(methodinfo *m, java_objectheader *o, ...)
-{
-       va_list ap;
-       float   f;
-
-       va_start(ap, o);
-       f = vm_call_method_float_valist(m, o, ap);
-       va_end(ap);
 
-       return f;
-}
+VM_CALL_METHOD(,        java_handle_t *)
+VM_CALL_METHOD(_int,    int32_t)
+VM_CALL_METHOD(_long,   int64_t)
+VM_CALL_METHOD(_float,  float)
+VM_CALL_METHOD(_double, double)
 
 
-/* vm_call_method_float_valist *************************************************
+/* vm_call_method_valist *******************************************************
 
    Calls a Java method with a variable number of arguments, passed via
-   a va_list, and returns a float.
+   a va_list.
 
 *******************************************************************************/
 
-#if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
-float vm_call_method_float_valist(methodinfo *m, java_objectheader *o,
-                                                                 va_list ap)
-{
-       s4      vmargscount;
-       vm_arg *vmargs;
-       float   f;
-       s4      dumpsize;
-
-       /* mark start of dump memory area */
-
-       dumpsize = dump_size();
-
-       /* get number of Java method arguments */
-
-       vmargscount = m->parseddesc->paramcount;
-
-       /* allocate vm_arg array */
-
-       vmargs = DMNEW(vm_arg, vmargscount);
-
-       /* fill the vm_arg array from a va_list */
-
-       vm_vmargs_from_valist(m, o, vmargs, ap);
-
-       /* call the Java method */
-
-       f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
-
-       /* release dump area */
-
-       dump_release(dumpsize);
-
-       return f;
+#define VM_CALL_METHOD_VALIST(name, type)                               \
+type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o,     \
+                                                                  va_list ap)                          \
+{                                                                       \
+       int32_t   dumpsize;                                                 \
+       uint64_t *array;                                                    \
+       type      value;                                                    \
+                                                                        \
+       if (m->code == NULL)                                                \
+               if (!jit_compile(m))                                            \
+                       return 0;                                                   \
+                                                                        \
+       THREAD_NATIVEWORLD_EXIT;                                            \
+                                                                        \
+       dumpsize = dump_size();                                             \
+       array = argument_vmarray_from_valist(m, o, ap);                     \
+       value = vm_call##name##_array(m, array);                            \
+       dump_release(dumpsize);                                             \
+                                                                        \
+       THREAD_NATIVEWORLD_ENTER;                                           \
+                                                                        \
+       return value;                                                       \
 }
-#else
-float vm_call_method_float_valist(methodinfo *m, java_objectheader *o, va_list ap)
-{
-       int32_t   dumpsize;
-       uint64_t *array;
-       float     f;
-
-       /* mark start of dump memory area */
-
-       dumpsize = dump_size();
-
-       /* fill the argument array from a va_list */
-
-       array = vm_array_from_valist(m, o, ap);
-
-       /* call the Java method */
-
-       f = vm_call_float_array(m, array);
-
-       /* release dump area */
 
-       dump_release(dumpsize);
+VM_CALL_METHOD_VALIST(,        java_handle_t *)
+VM_CALL_METHOD_VALIST(_int,    int32_t)
+VM_CALL_METHOD_VALIST(_long,   int64_t)
+VM_CALL_METHOD_VALIST(_float,  float)
+VM_CALL_METHOD_VALIST(_double, double)
 
-       return f;
-}
-#endif
 
-/* vm_call_method_float_jvalue *************************************************
+/* vm_call_method_jvalue *******************************************************
 
    Calls a Java method with a variable number of arguments, passed via
-   a jvalue array, and returns a float.
+   a jvalue array.
 
 *******************************************************************************/
 
-#if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
-float vm_call_method_float_jvalue(methodinfo *m, java_objectheader *o,
-                                                                 const jvalue *args)
-{
-       s4      vmargscount;
-       vm_arg *vmargs;
-       float   f;
-       s4      dumpsize;
-
-       /* mark start of dump memory area */
-
-       dumpsize = dump_size();
-
-       /* get number of Java method arguments */
-
-       vmargscount = m->parseddesc->paramcount;
-
-       /* allocate vm_arg array */
-
-       vmargs = DMNEW(vm_arg, vmargscount);
-
-       /* fill the vm_arg array from a va_list */
-
-       vm_vmargs_from_jvalue(m, o, vmargs, args);
-
-       /* call the Java method */
-
-       f = vm_call_method_float_vmarg(m, vmargscount, vmargs);
-
-       /* release dump area */
-
-       dump_release(dumpsize);
-
-       return f;
+#define VM_CALL_METHOD_JVALUE(name, type)                               \
+type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o,     \
+                                                          const jvalue *args)                  \
+{                                                                       \
+       int32_t   dumpsize;                                                 \
+       uint64_t *array;                                                    \
+       type      value;                                                    \
+                                                                        \
+       if (m->code == NULL)                                                \
+               if (!jit_compile(m))                                            \
+                       return 0;                                                   \
+                                                                        \
+       THREAD_NATIVEWORLD_EXIT;                                            \
+                                                                        \
+       dumpsize = dump_size();                                             \
+       array = argument_vmarray_from_jvalue(m, o, args);                   \
+       value = vm_call##name##_array(m, array);                            \
+       dump_release(dumpsize);                                             \
+                                                                        \
+       THREAD_NATIVEWORLD_ENTER;                                           \
+                                                                        \
+       return value;                                                       \
 }
-#else
-float vm_call_method_float_jvalue(methodinfo *m, java_objectheader *o, const jvalue *args)
-{
-       int32_t   dumpsize;
-       uint64_t *array;
-       float     f;
-
-       /* mark start of dump memory area */
-
-       dumpsize = dump_size();
-
-       /* fill the argument array from a va_list */
-
-       array = vm_array_from_jvalue(m, o, args);
-
-       /* call the Java method */
 
-       f = vm_call_float_array(m, array);
+VM_CALL_METHOD_JVALUE(,        java_handle_t *)
+VM_CALL_METHOD_JVALUE(_int,    int32_t)
+VM_CALL_METHOD_JVALUE(_long,   int64_t)
+VM_CALL_METHOD_JVALUE(_float,  float)
+VM_CALL_METHOD_JVALUE(_double, double)
 
-       /* release dump area */
-
-       dump_release(dumpsize);
-
-       return f;
-}
-#endif
 
+/* vm_call_method_objectarray **************************************************
 
-/* vm_call_double_array ********************************************************
-
-   Calls a Java method with a variable number of arguments and returns
-   a double.
+   Calls a Java method with a variable number if arguments, passed via
+   an objectarray of boxed values. Returns a boxed value.
 
 *******************************************************************************/
 
-#if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
-double vm_call_method_double_vmarg(methodinfo *m, s4 vmargscount,
-                                                                  vm_arg *vmargs)
-{
-       double d;
-
-       vm_abort("IMPLEMENT ME!");
-
-       STATISTICS(count_calls_native_to_java++);
-
-#if defined(ENABLE_JIT)
-# if defined(ENABLE_INTRP)
-       if (opt_intrp)
-               d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
-       else
-# endif
-               d = asm_vm_call_method_double(m, vmargscount, vmargs);
-#else
-       d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
-#endif
-
-       return d;
-}
-#else
-double vm_call_double_array(methodinfo *m, uint64_t *array)
+java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
+                                                                                 java_handle_objectarray_t *params)
 {
-       methoddesc *md;
-       double      d;
-
-       md = m->parseddesc;
+       int32_t        dumpsize;
+       uint64_t      *array;
+       java_handle_t *xptr;
+       java_handle_t *ro;
+       imm_union      value;
 
-       /* compile the method if not already done */
+       /* compile methods which are not yet compiled */
 
        if (m->code == NULL)
                if (!jit_compile(m))
-                       return 0;
-
-       STATISTICS(count_calls_native_to_java++);
-
-#if defined(ENABLE_JIT)
-# if defined(ENABLE_INTRP)
-       if (opt_intrp)
-               d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
-       else
-# endif
-               d = asm_vm_call_method_double(m->code->entrypoint, array, md->memuse);
-#else
-       d = intrp_asm_vm_call_method_double(m, vmargscount, vmargs);
-#endif
-
-       return d;
-}
-#endif
-
-
-/* vm_call_method_double *******************************************************
-
-   Calls a Java method with a variable number of arguments and returns
-   a double.
-
-*******************************************************************************/
-
-double vm_call_method_double(methodinfo *m, java_objectheader *o, ...)
-{
-       va_list ap;
-       double  d;
-
-       va_start(ap, o);
-       d = vm_call_method_double_valist(m, o, ap);
-       va_end(ap);
-
-       return d;
-}
-
-
-/* vm_call_method_double_valist ************************************************
-
-   Calls a Java method with a variable number of arguments, passed via
-   a va_list, and returns a double.
+                       return NULL;
 
-*******************************************************************************/
+       /* leave the nativeworld */
 
-#if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
-double vm_call_method_double_valist(methodinfo *m, java_objectheader *o,
-                                                                       va_list ap)
-{
-       s4      vmargscount;
-       vm_arg *vmargs;
-       double  d;
-       s4      dumpsize;
+       THREAD_NATIVEWORLD_EXIT;
 
        /* mark start of dump memory area */
 
        dumpsize = dump_size();
 
-       /* get number of Java method arguments */
+       /* Fill the argument array from a object-array. */
 
-       vmargscount = m->parseddesc->paramcount;
+       array = argument_vmarray_from_objectarray(m, o, params);
 
-       /* allocate vm_arg array */
+       if (array == NULL) {
+               /* release dump area */
 
-       vmargs = DMNEW(vm_arg, vmargscount);
+               dump_release(dumpsize);
 
-       /* fill the vm_arg array from a va_list */
+               /* enter the nativeworld again */
 
-       vm_vmargs_from_valist(m, o, vmargs, ap);
+               THREAD_NATIVEWORLD_ENTER;
 
-       /* call the Java method */
+               exceptions_throw_illegalargumentexception();
 
-       d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
-
-       /* release dump area */
-
-       dump_release(dumpsize);
+               return NULL;
+       }
 
-       return d;
-}
-#else
-double vm_call_method_double_valist(methodinfo *m, java_objectheader *o, va_list ap)
-{
-       int32_t   dumpsize;
-       uint64_t *array;
-       double    d;
+       switch (m->parseddesc->returntype.decltype) {
+       case PRIMITIVETYPE_VOID:
+               value.a = vm_call_array(m, array);
+               break;
 
-       /* mark start of dump memory area */
+       case PRIMITIVETYPE_BOOLEAN:
+       case PRIMITIVETYPE_BYTE:
+       case PRIMITIVETYPE_CHAR:
+       case PRIMITIVETYPE_SHORT:
+       case PRIMITIVETYPE_INT:
+               value.i = vm_call_int_array(m, array);
+               break;
 
-       dumpsize = dump_size();
+       case PRIMITIVETYPE_LONG:
+               value.l = vm_call_long_array(m, array);
+               break;
 
-       /* fill the argument array from a va_list */
+       case PRIMITIVETYPE_FLOAT:
+               value.f = vm_call_float_array(m, array);
+               break;
 
-       array = vm_array_from_valist(m, o, ap);
+       case PRIMITIVETYPE_DOUBLE:
+               value.d = vm_call_double_array(m, array);
+               break;
 
-       /* call the Java method */
+       case TYPE_ADR:
+               ro = vm_call_array(m, array);
+               break;
 
-       d = vm_call_double_array(m, array);
+       default:
+               vm_abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.decltype);
+       }
 
        /* release dump area */
 
        dump_release(dumpsize);
 
-       return d;
-}
-#endif
-
-
-/* vm_call_method_double_jvalue ************************************************
-
-   Calls a Java method with a variable number of arguments, passed via
-   a jvalue array, and returns a double.
-
-*******************************************************************************/
-
-#if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
-double vm_call_method_double_jvalue(methodinfo *m, java_objectheader *o,
-                                                                       const jvalue *args)
-{
-       s4      vmargscount;
-       vm_arg *vmargs;
-       double  d;
-       s4      dumpsize;
-
-       /* mark start of dump memory area */
-
-       dumpsize = dump_size();
-
-       /* get number of Java method arguments */
+       /* enter the nativeworld again */
 
-       vmargscount = m->parseddesc->paramcount;
+       THREAD_NATIVEWORLD_ENTER;
 
-       /* allocate vm_arg array */
+       /* box the return value if necesarry */
 
-       vmargs = DMNEW(vm_arg, vmargscount);
+       if (m->parseddesc->returntype.decltype != TYPE_ADR)
+               ro = primitive_box(m->parseddesc->returntype.decltype, value);
 
-       /* fill the vm_arg array from a va_list */
+       /* check for an exception */
 
-       vm_vmargs_from_jvalue(m, o, vmargs, args);
+       xptr = exceptions_get_exception();
 
-       /* call the Java method */
+       if (xptr != NULL) {
+               /* clear exception pointer, we are calling JIT code again */
 
-       d = vm_call_method_double_vmarg(m, vmargscount, vmargs);
-
-       /* release dump area */
+               exceptions_clear_exception();
 
-       dump_release(dumpsize);
+               exceptions_throw_invocationtargetexception(xptr);
+       }
 
-       return d;
+       return ro;
 }
-#else
-double vm_call_method_double_jvalue(methodinfo *m, java_objectheader *o, const jvalue *args)
-{
-       int32_t   dumpsize;
-       uint64_t *array;
-       double    d;
-
-       /* mark start of dump memory area */
-
-       dumpsize = dump_size();
-
-       /* fill the argument array from a va_list */
-
-       array = vm_array_from_jvalue(m, o, args);
 
-       /* call the Java method */
-
-       d = vm_call_double_array(m, array);
-
-       /* release dump area */
-
-       dump_release(dumpsize);
-
-       return d;
-}
-#endif
 
 /*
  * These are local overrides for various environment variables in Emacs.
@@ -4243,4 +2570,5 @@ double vm_call_method_double_jvalue(methodinfo *m, java_objectheader *o, const j
  * c-basic-offset: 4
  * tab-width: 4
  * End:
+ * vim:noexpandtab:sw=4:ts=4:
  */