* src/vm/jit/exceptiontable.c: New file.
[cacao.git] / src / vm / vm.c
index 583801a4f5a89d4bcba85e1f3b4b1d51f9f8fd82..2a9b9cbc8bf0d20f56e34c34007065eff2436624 100644 (file)
@@ -44,6 +44,7 @@
 
 #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 "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"
@@ -122,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 ************************************************/
@@ -508,8 +517,7 @@ 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
@@ -633,7 +641,7 @@ static void fullversion(void)
 }
 
 
-void vm_printconfig(void)
+static void vm_printconfig(void)
 {
        puts("Configure/Build options:\n");
        puts("  ./configure: "VERSION_CONFIGURE_ARGS"");
@@ -735,16 +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) */
-
-       /* XXX this one will never get freed for the main thread;
-          call localref_table_destroy() if you want to do it! */
-
-       if (!localref_table_init())
-               goto error;
-#endif
-
        /* now return the values */
 
        *p_vm  = (JavaVM *) vm;
@@ -1071,9 +1069,6 @@ bool vm_create(JavaVMInitArgs *vm_args)
                                initverbose = true;
                                compileverbose = true;
                        }
-                       else if (strcmp("threads", opt_arg) == 0) {
-                               opt_verbosethreads = true;
-                       }
 #endif
                        else {
                                printf("Unknown -verbose option: %s\n", opt_arg);
@@ -1511,6 +1506,10 @@ bool vm_create(JavaVMInitArgs *vm_args)
        intrp_md_init();
 #endif
 
+       /* BEFORE: loader_preinit */
+
+       package_init();
+
        /* AFTER: utf8_init, classcache_init */
 
        loader_preinit();
@@ -1527,8 +1526,7 @@ bool vm_create(JavaVMInitArgs *vm_args)
 
        primitive_postinit();
 
-       if (!exceptions_init())
-               vm_abort("vm_create: exceptions_init failed");
+       exceptions_init();
 
        if (!builtin_init())
                vm_abort("vm_create: builtin_init failed");
@@ -1554,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");
@@ -1634,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;
@@ -1749,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);
 
-               LLNI_objectarray_element_set(oa, i, s);
+               array_objectarray_element_set(oa, i, s);
        }
 
 #ifdef TYPEINFO_DEBUG_TEST
@@ -1985,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.
@@ -2229,536 +2292,60 @@ static void vm_compile_method(void)
 #endif /* !defined(NDEBUG) */
 
 
-/* vm_array_store_int **********************************************************
-
-   Helper function to store an integer into the argument array, taking
-   care of architecture specific issues.
-
-*******************************************************************************/
-
-static void vm_array_store_int(uint64_t *array, paramdesc *pd, int32_t value)
-{
-       int32_t index;
-
-       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
-       }
-}
-
-
-/* vm_array_store_lng **********************************************************
-
-   Helper function to store a long into the argument array, taking
-   care of architecture specific issues.
-
-*******************************************************************************/
-
-static void vm_array_store_lng(uint64_t *array, paramdesc *pd, int64_t value)
-{
-       int32_t index;
-
-#if SIZEOF_VOID_P == 8
-       if (!pd->inmemory)
-               index = pd->index;
-       else
-               index = ARG_CNT + pd->index;
-
-       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;
-
-               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(__POWERPC__) && !defined(__POWERPC64__) && !defined(__S390__)
-               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
-               array[index] = ((uint64_t) (intptr_t) value) << 32;
-# else
-               array[index] = (uint64_t) (intptr_t) value;
-# endif
-#endif
-       }
-}
-
-
-/* vm_array_from_valist ********************************************************
-
-   XXX
-
-*******************************************************************************/
-
-uint64_t *vm_array_from_valist(methodinfo *m, java_handle_t *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(__POWERPC__) || defined(__POWERPC64__)
-                       /* This is required to load the correct float value in
-                          assembler code. */
-
-                       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;
-}
-
+/* vm_call_array ***************************************************************
 
-/* vm_array_from_jvalue ********************************************************
+   Calls a Java method with a variable number of arguments, passed via
+   an argument array.
 
-   XXX
+   ATTENTION: This function has to be used outside the nativeworld.
 
 *******************************************************************************/
 
-static uint64_t *vm_array_from_jvalue(methodinfo *m, java_handle_t *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;
+#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;                                                 \
 }
 
-
-/* vm_array_from_objectarray ***************************************************
-
-   XXX
-
-*******************************************************************************/
-
-uint64_t *vm_array_from_objectarray(methodinfo *m, java_handle_t *o,
-                                                                       java_handle_objectarray_t *params)
+static java_handle_t *vm_call_array(methodinfo *m, uint64_t *array)
 {
        methoddesc    *md;
-       paramdesc     *pd;
-       typedesc      *td;
-       uint64_t      *array;
-       java_handle_t *param;
-       classinfo     *c;
-       int            type;
-       int32_t        i;
-       int32_t        j;
-       imm_union      value;
+       void          *pv;
+       java_object_t *o;
 
-       /* get the descriptors */
+       assert(m->code != NULL);
 
        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 */
+       pv = m->code->entrypoint;
 
-       i = 0;
+       STATISTICS(count_calls_native_to_java++);
 
-       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++) {
-               LLNI_objectarray_element_get(params, j, param);
-
-               switch (td->type) {
-               case TYPE_INT:
-                       if (param == NULL)
-                               goto illegal_arg;
-
-                       /* convert the value according to its declared type */
-
-                       LLNI_class_get(param, c);
-                       type = primitive_type_get_by_wrapperclass(c);
-
-                       switch (td->decltype) {
-                       case PRIMITIVETYPE_BOOLEAN:
-                               switch (type) {
-                               case PRIMITIVETYPE_BOOLEAN:
-                                       /* This type is OK. */
-                                       break;
-                               default:
-                                       goto illegal_arg;
-                               }
-                               break;
+       o = asm_vm_call_method(pv, array, md->memuse);
 
-                       case PRIMITIVETYPE_BYTE:
-                               switch (type) {
-                               case PRIMITIVETYPE_BYTE:
-                                       /* This type is OK. */
-                                       break;
-                               default:
-                                       goto illegal_arg;
-                               }
-                               break;
-
-                       case PRIMITIVETYPE_CHAR:
-                               switch (type) {
-                               case PRIMITIVETYPE_CHAR:
-                                       /* This type is OK. */
-                                       break;
-                               default:
-                                       goto illegal_arg;
-                               }
-                               break;
-
-                       case PRIMITIVETYPE_SHORT:
-                               switch (type) {
-                               case PRIMITIVETYPE_BYTE:
-                               case PRIMITIVETYPE_SHORT:
-                                       /* These types are OK. */
-                                       break;
-                               default:
-                                       goto illegal_arg;
-                               }
-                               break;
-
-                       case PRIMITIVETYPE_INT:
-                               switch (type) {
-                               case PRIMITIVETYPE_BYTE:
-                               case PRIMITIVETYPE_SHORT:
-                               case PRIMITIVETYPE_INT:
-                                       /* These types are OK. */
-                                       break;
-                               default:
-                                       goto illegal_arg;
-                               }
-                               break;
-
-                       default:
-                               vm_abort("vm_array_from_objectarray: invalid type %d",
-                                                td->decltype);
-                       }
-
-                       value = primitive_unbox(param);
-                       vm_array_store_int(array, pd, value.i);
-                       break;
-
-               case TYPE_LNG:
-                       if (param == NULL)
-                               goto illegal_arg;
-
-                       LLNI_class_get(param, c);
-                       assert(td->decltype == PRIMITIVETYPE_LONG);
-
-                       switch (type) {
-                       case PRIMITIVETYPE_BYTE:
-                       case PRIMITIVETYPE_SHORT:
-                       case PRIMITIVETYPE_INT:
-                       case PRIMITIVETYPE_LONG:
-                               /* These types are OK. */
-                               break;
-                       default:
-                               goto illegal_arg;
-                       }
+       if (md->returntype.type == TYPE_VOID)
+               o = NULL;
 
-                       value = primitive_unbox(param);
-                       vm_array_store_lng(array, pd, value.l);
-                       break;
-
-               case TYPE_FLT:
-                       if (param == NULL)
-                               goto illegal_arg;
-
-                       LLNI_class_get(param, c);
-                       type = primitive_type_get_by_wrapperclass(c);
-
-                       assert(td->decltype == PRIMITIVETYPE_FLOAT);
-
-                       switch (type) {
-                       case PRIMITIVETYPE_FLOAT:
-                               /* This type is OK. */
-                               break;
-                       default:
-                               goto illegal_arg;
-                       }
-
-                       value = primitive_unbox(param);
-                       vm_array_store_flt(array, pd, value.l);
-                       break;
-
-               case TYPE_DBL:
-                       if (param == NULL)
-                               goto illegal_arg;
-
-                       LLNI_class_get(param, c);
-                       type = primitive_type_get_by_wrapperclass(c);
-
-                       assert(td->decltype == PRIMITIVETYPE_DOUBLE);
-
-                       switch (type) {
-                       case PRIMITIVETYPE_FLOAT:
-                       case PRIMITIVETYPE_DOUBLE:
-                               /* These types are OK. */
-                               break;
-                       default:
-                               goto illegal_arg;
-                       }
-
-                       value = primitive_unbox(param);
-                       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:
-                       vm_abort("vm_array_from_objectarray: invalid type %d", td->type);
-               }
-       }
-
-       return array;
-
-illegal_arg:
-       exceptions_throw_illegalargumentexception();
-       return NULL;
+       return LLNI_WRAP(o);
 }
 
+VM_CALL_ARRAY(_int,    int32_t)
+VM_CALL_ARRAY(_long,   int64_t)
+VM_CALL_ARRAY(_float,  float)
+VM_CALL_ARRAY(_double, double)
+
 
 /* vm_call_method **************************************************************
 
@@ -2801,11 +2388,19 @@ type vm_call_method##name##_valist(methodinfo *m, java_handle_t *o,     \
        uint64_t *array;                                                    \
        type      value;                                                    \
                                                                         \
+       if (m->code == NULL)                                                \
+               if (!jit_compile(m))                                            \
+                       return 0;                                                   \
+                                                                        \
+       THREAD_NATIVEWORLD_EXIT;                                            \
+                                                                        \
        dumpsize = dump_size();                                             \
-       array = vm_array_from_valist(m, o, ap);                             \
+       array = argument_vmarray_from_valist(m, o, ap);                     \
        value = vm_call##name##_array(m, array);                            \
        dump_release(dumpsize);                                             \
                                                                         \
+       THREAD_NATIVEWORLD_ENTER;                                           \
+                                                                        \
        return value;                                                       \
 }
 
@@ -2831,11 +2426,19 @@ type vm_call_method##name##_jvalue(methodinfo *m, java_handle_t *o,     \
        uint64_t *array;                                                    \
        type      value;                                                    \
                                                                         \
+       if (m->code == NULL)                                                \
+               if (!jit_compile(m))                                            \
+                       return 0;                                                   \
+                                                                        \
+       THREAD_NATIVEWORLD_EXIT;                                            \
+                                                                        \
        dumpsize = dump_size();                                             \
-       array = vm_array_from_jvalue(m, o, args);                           \
+       array = argument_vmarray_from_jvalue(m, o, args);                   \
        value = vm_call##name##_array(m, array);                            \
        dump_release(dumpsize);                                             \
                                                                         \
+       THREAD_NATIVEWORLD_ENTER;                                           \
+                                                                        \
        return value;                                                       \
 }
 
@@ -2846,40 +2449,114 @@ VM_CALL_METHOD_JVALUE(_float,  float)
 VM_CALL_METHOD_JVALUE(_double, double)
 
 
-/* vm_call_array ***************************************************************
+/* vm_call_method_objectarray **************************************************
 
-   Calls a Java method with a variable number of arguments, passed via
-   an argument array.
+   Calls a Java method with a variable number if arguments, passed via
+   an objectarray of boxed values. Returns a boxed value.
 
 *******************************************************************************/
 
-#define VM_CALL_ARRAY(name, type)                            \
-type vm_call##name##_array(methodinfo *m, uint64_t *array)   \
-{                                                            \
-       methoddesc *md;                                          \
-       void       *pv;                                          \
-       type        value;                                       \
-                                                             \
-       md = m->parseddesc;                                      \
-                                                             \
-       if (m->code == NULL)                                     \
-               if (!jit_compile(m))                                 \
-                       return 0;                                        \
-                                                             \
-       pv = m->code->entrypoint;                                \
-                                                             \
-       STATISTICS(count_calls_native_to_java++);                \
-                                                             \
-       value = asm_vm_call_method##name(pv, array, md->memuse); \
-                                                             \
-       return value;                                            \
-}
+java_handle_t *vm_call_method_objectarray(methodinfo *m, java_handle_t *o,
+                                                                                 java_handle_objectarray_t *params)
+{
+       int32_t        dumpsize;
+       uint64_t      *array;
+       java_handle_t *xptr;
+       java_handle_t *ro;
+       imm_union      value;
 
-VM_CALL_ARRAY(,        java_handle_t *)
-VM_CALL_ARRAY(_int,    int32_t)
-VM_CALL_ARRAY(_long,   int64_t)
-VM_CALL_ARRAY(_float,  float)
-VM_CALL_ARRAY(_double, double)
+       /* compile methods which are not yet compiled */
+
+       if (m->code == NULL)
+               if (!jit_compile(m))
+                       return NULL;
+
+       /* leave the nativeworld */
+
+       THREAD_NATIVEWORLD_EXIT;
+
+       /* mark start of dump memory area */
+
+       dumpsize = dump_size();
+
+       /* Fill the argument array from a object-array. */
+
+       array = argument_vmarray_from_objectarray(m, o, params);
+
+       if (array == NULL) {
+               /* release dump area */
+
+               dump_release(dumpsize);
+
+               /* enter the nativeworld again */
+
+               THREAD_NATIVEWORLD_ENTER;
+
+               exceptions_throw_illegalargumentexception();
+
+               return NULL;
+       }
+
+       switch (m->parseddesc->returntype.decltype) {
+       case PRIMITIVETYPE_VOID:
+               value.a = vm_call_array(m, array);
+               break;
+
+       case PRIMITIVETYPE_BOOLEAN:
+       case PRIMITIVETYPE_BYTE:
+       case PRIMITIVETYPE_CHAR:
+       case PRIMITIVETYPE_SHORT:
+       case PRIMITIVETYPE_INT:
+               value.i = vm_call_int_array(m, array);
+               break;
+
+       case PRIMITIVETYPE_LONG:
+               value.l = vm_call_long_array(m, array);
+               break;
+
+       case PRIMITIVETYPE_FLOAT:
+               value.f = vm_call_float_array(m, array);
+               break;
+
+       case PRIMITIVETYPE_DOUBLE:
+               value.d = vm_call_double_array(m, array);
+               break;
+
+       case TYPE_ADR:
+               ro = vm_call_array(m, array);
+               break;
+
+       default:
+               vm_abort("vm_call_method_objectarray: invalid return type %d", m->parseddesc->returntype.decltype);
+       }
+
+       /* release dump area */
+
+       dump_release(dumpsize);
+
+       /* enter the nativeworld again */
+
+       THREAD_NATIVEWORLD_ENTER;
+
+       /* box the return value if necesarry */
+
+       if (m->parseddesc->returntype.decltype != TYPE_ADR)
+               ro = primitive_box(m->parseddesc->returntype.decltype, value);
+
+       /* check for an exception */
+
+       xptr = exceptions_get_exception();
+
+       if (xptr != NULL) {
+               /* clear exception pointer, we are calling JIT code again */
+
+               exceptions_clear_exception();
+
+               exceptions_throw_invocationtargetexception(xptr);
+       }
+
+       return ro;
+}
 
 
 /*