* Use new, more general, stacktrace system
authortwisti <none@none>
Sat, 9 Jul 2005 14:04:34 +0000 (14:04 +0000)
committertwisti <none@none>
Sat, 9 Jul 2005 14:04:34 +0000 (14:04 +0000)
* Implemented remaining asmpart functions inline
* Added opt_ prefix to some options

src/vm/jit/x86_64/asmpart.S
src/vm/jit/x86_64/codegen.c
src/vm/jit/x86_64/codegen.h
src/vm/jit/x86_64/md-asm.h
src/vm/jit/x86_64/md.c
src/vm/jit/x86_64/patcher.c

index c994782258013a447ab0fe8cd98a3da9af07d7f0..1d0048641bdd8fc632247fb9f0f999d8bafb5f74 100644 (file)
@@ -28,7 +28,7 @@
             Reinhard Grafl
             Christian Thalinger
 
-   $Id: asmpart.S 2733 2005-06-17 12:18:29Z twisti $
+   $Id: asmpart.S 2956 2005-07-09 14:04:34Z twisti $
 
 */
 
@@ -64,7 +64,6 @@
        .globl asm_wrapper_patcher
 
        .globl asm_builtin_arraycheckcast
-       .globl asm_builtin_aastore
 
        .globl asm_builtin_f2i
        .globl asm_builtin_f2l
        .globl asm_criticalsections
        .globl asm_getclassvalues_atomic
 
-       .globl asm_prepare_native_stackinfo
-       .globl asm_remove_native_stackinfo
-       .globl asm_throw_and_handle_exception
-       .globl asm_throw_and_handle_hardware_arithmetic_exception               
-
 
 /********************* function asm_calljavafunction ***************************
 *                                                                              *
@@ -735,53 +729,54 @@ noflt:
 *******************************************************************************/
 
 asm_wrapper_patcher:
-       sub     $(17*8),%rsp                /* stack frame (16-byte aligned)      */
+       sub     $(19*8+sizestackframeinfo),sp /* stack frame (16-byte aligned)    */
 
        SAVE_ARGUMENT_REGISTERS(0)
        SAVE_TEMPORARY_REGISTERS(14)
 
-       mov     itmp1,15*8(%rsp)            /* save itmp1 and itmp2               */
-       mov     itmp2,16*8(%rsp)            /* can be used by some instructions   */
+       mov     itmp1,15*8(sp)              /* save itmp1 and itmp2               */
+       mov     itmp2,16*8(sp)              /* can be used by some instructions   */
+
+       mov     sp,a0                       /* create stackframe info             */
+       add     $(19*8),a0
+       xor     a1,a1                       /* if pv is NULL, use findmethod      */
+       mov     sp,a2
+       add     $((5+19)*8+sizestackframeinfo),a2
+       mov     ((4+19)*8+sizestackframeinfo)(sp),a3
+       call    stacktrace_create_inline_stackframeinfo
 
-       mov     %rsp,a0                     /* pass stack pointer                 */
-       add     $(18*8),a0                  /* skip patcher function pointer      */
-       mov     17*8(%rsp),itmp3            /* get function pointer               */
+       mov     sp,a0                       /* pass stack pointer                 */
+       add     $((1+19)*8+sizestackframeinfo),a0   /* skip function pointer      */
+       mov     (19*8+sizestackframeinfo)(sp),itmp3 /* get function pointer       */
        call    *itmp3                      /* call the patcher function          */
-       mov     v0,itmp3                    /* save return value                  */
+       mov     v0,17*8(sp)                 /* save return value                  */
+
+       mov     sp,a0                       /* remove stackframe info             */
+       add     $(19*8),a0
+       call    stacktrace_remove_stackframeinfo
 
        RESTORE_ARGUMENT_REGISTERS(0)
        RESTORE_TEMPORARY_REGISTERS(14)
 
-       mov     15*8(%rsp),itmp1            /* restore itmp1 and itmp2            */
-       mov     16*8(%rsp),itmp2            /* can be used by some instructions   */
+       mov     15*8(sp),itmp1              /* restore itmp1 and itmp2            */
+       mov     16*8(sp),itmp2              /* can be used by some instructions   */
+       mov     17*8(sp),itmp3              /* restore return value               */
 
-       add     $((4+17)*8),%rsp            /* remove stack frame, keep ra        */
+       add     $((4+19)*8+sizestackframeinfo),sp /* remove stack frame, keep ra  */
 
        test    itmp3,itmp3                 /* exception thrown?                  */
        jz      L_asm_wrapper_patcher_exception
        ret                                 /* call new patched code              */
 
 L_asm_wrapper_patcher_exception:
-       /*stack bottom is xpc and it is directly below the last java stackframe*/
-       push $0
-       push $0
-       push $0 /*padding*/
-       call asm_prepare_native_stackinfo /* be aware of the stack effect and calling convention explained above*/
-
 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
        call    builtin_asm_get_exceptionptrptr
-       mov     v0,itmp2
+       mov     v0,itmp2                    /* v0 == xptr                         */
 #else
        lea     _exceptionptr,itmp2
 #endif
-       mov     (itmp2),a0                  /* get the exception pointer          */
+       mov     (itmp2),xptr                /* get the exception pointer          */
        movl    $0,(itmp2)                  /* clear exception pointer            */
-       call    helper_fillin_stacktrace
-
-       mov     v0,xptr
-
-       call    asm_remove_native_stackinfo /* be aware of the stack effect and calling convention explained above*/
-       add     $8,%rsp
 
        pop     xpc                         /* get and remove return address      */
        jmp     asm_handle_exception
@@ -849,100 +844,6 @@ asm_builtin_d2l:
        ret
 
 
-/* asm_builtin_arraycheckcast **************************************************
-
-   Does the cast check and eventually throws an exception.
-
-*******************************************************************************/
-
-asm_builtin_arraycheckcast:
-       sub     $24,%rsp                    /* keep stack 16-byte aligned         */
-       mov     %rdi,(%rsp)                 /* save object pointer                */
-       call    builtin_arraycheckcast
-       test    %rax,%rax                   /* if (false) throw exception         */
-       je      nb_carray_throw
-       mov     (%rsp),%rax                 /* return object pointer              */
-       add     $24,%rsp                    /* free stack space                   */
-       ret
-
-nb_carray_throw:
-       /*call    new_classcastexception*/
-       add     $24,%rsp
-       pop     xpc                        /* delete return address              */
-       sub     $3,xpc                     /* faulting address is ra - 3         */
-        mov     string_java_lang_ClassCastException,xptr
-       jmp     asm_throw_and_handle_exception
-
-               
-/* asm_builtin_aastore *********************************************************
-
-   Checks if the object can be stored in the given array and stores the
-   address if it's possible. This function can also throw some exceptions.
-
-*******************************************************************************/
-
-asm_builtin_aastore:
-       sub     $(3*8),%rsp             /* allocate stack space                   */
-       test    %rdi,%rdi               /* if null pointer throw exception        */
-       je      nb_aastore_null
-
-       movl    offarraysize(%rdi),%eax /* load size                              */
-       cmpl    %eax,%esi               /* do bound check                         */
-       jae     nb_aastore_bound        /* if out of bounds throw exception       */
-
-       shl     $3,%rsi                 /* index * 8                              */
-       mov     %rdi,%r10
-       add     %rsi,%r10               /* add index * 8 to arrayref              */
-
-       mov     %r10,(%rsp)             /* save store position                    */
-       mov     %rdx,8(%rsp)            /* save object                            */
-
-       mov     %rdx,%rsi               /* object is second argument              */
-       call    builtin_canstore        /* builtin_canstore(arrayref,object)      */
-       test    %rax,%rax               /* if (false) throw exception             */
-       je      nb_aastore_throw
-
-       mov     (%rsp),%r10             /* restore store position                 */
-       mov     8(%rsp),%rdx            /* restore object                         */
-       mov     %rdx,offobjarrdata(%r10)/* store objectptr in array               */
-       add     $(3*8),%rsp             /* free stack space                       */
-       ret
-
-nb_aastore_null:
-       add     $24,%rsp
-       pop     xpc                    /* delete return address from stack       */
-       sub     $3,xpc                 /* faulting address is return adress - 3  */
-        mov     string_java_lang_NullPointerException,xptr
-       jmp    asm_throw_and_handle_exception
-
-nb_aastore_bound:
-       add     $24,%rsp
-       push    $0 /*directly below return address*/
-       push    $0 /*internal*/
-       push    $0 /*padding*/
-       mov     %rsi,itmp1
-       
-       call    asm_prepare_native_stackinfo
-
-       mov     itmp1,%rdi               /* move index into a0                     */
-       call    new_arrayindexoutofboundsexception
-
-       call    asm_remove_native_stackinfo
-
-       pop     xpc                    /* just remove one quadword                  */
-       pop     xpc                    /* delete return address                  */
-       sub     $3,xpc                 /* faulting address is return adress - 3  */
-       jmp     asm_handle_exception
-               
-nb_aastore_throw:
-       /*call    new_arraystoreexception*/
-       add     $24,%rsp
-       pop     xpc                    /* delete return address                  */
-       sub     $3,xpc                 /* faulting address is return adress - 3  */
-        mov     string_java_lang_ArrayStoreException,xptr
-       jmp     asm_throw_and_handle_exception
-
-               
 /******************* function asm_initialize_thread_stack **********************
 *                                                                              *
 * initialized a thread stack                                                   *
@@ -1039,127 +940,6 @@ asm_switchstackandcall:
         ret
 
 
-
-
-/************************ function asm_prepare_native_stackinfo ****************************
-*                                                                                          *
-*    creates a stackfame for the begin of a native function (either builtin or not )       *
-*    expected stack at begin of function                                                   *
-*                                        ....                                              *
-*                   address of the jit call which invokes the native                       *
-*                   begin address of stack frame of the java method                        *
-*                   method pointer or 0 (for built ins)                                    *
-*                   padding for stackframesize 16*n+8                                      *
-*                   return address                                                         *
-*                                                                                          *
-*    at end of function:                                                                   *
-*                                          ...                                             *
-*                   address of the jit call which invokes the native                       *
-*                   begin address of stack frame of the java method                        *
-*                   method pointer or 0 (for built ins)                                    *
-*                   address of thread specific top of native list                          *
-*                   old value of thread specific head                                      *
-*                   padding for stackframesize 16*n+8)                                     *
-*                   return address                                                         *
-*                                                                                          *
-*                                        ....                                              *
-* This thing is less efficient than the original #define (callerside)                      *
-* destroyes REG_ITMP2, keeps REG_ITMP1                                                     *
-********************************************************************************************/
-
-
-asm_prepare_native_stackinfo:
-        sub $16,%rsp  /*space for the 2 new pointers*/
-        mov 16(%rsp),itmp2
-        mov itmp2,(%rsp)
-        push itmp1
-        call builtin_asm_get_stackframeinfo
-
-        mov itmp1, 32(%rsp)
-        mov (itmp1),itmp2
-        mov itmp2,24(%rsp)
-        mov %rsp,itmp2
-        add $24,itmp2
-        mov itmp2,(itmp1)
-        pop itmp1
-        ret
-
-               
-
-/************************ function asm_remove _native_stackinfo *******************************************
-*                                                                                                         *
-*    removes a stackfame for the begin of a native function (either builtin or not)                       *
-*    expected stack at begin of function                                                                  *
-*                   address of the jit call which invokes the native                                      *
-*                   begin address of stack frame of the java method                                       *
-*                   method pointer or 0 (for built ins)                                                   *
-*                   address thread specific top of native list                                            *
-*                   old value of thread specific head                                                     *
-*                   padding                                                                               *
-*                   return address                                                                        *
-*                                                                                                         *
-*    at end of function:                                                                                  *
-*                             ....                                                                        *
-*                   return adresss of the jit call which invokes the native                               *
-*                   padding                                                                               *
-*                   return address                                                                        *
-*                                                                                                         *
-*                                                                                                         *
-*                                                                                                         *
-* This thing is less efficient than the original #define (callerside), uses ITMP2,uses ITMP3,keeps ITMP1  *
-***********************************************************************************************************/
-
-asm_remove_native_stackinfo:
-        mov 16(%rsp),itmp2
-        mov 24(%rsp),itmp3
-        mov itmp2,(itmp3)
-        pop itmp3
-        add $32,%rsp
-        push itmp3
-        ret
-
-
-
-asm_throw_and_handle_exception:
-        push xpc /* the pushed XPC is directly below the java frame*/
-        push $0 
-        push $0
-        push $0 /*padding*/
-        call asm_prepare_native_stackinfo /* be aware of the stack effect and calling convention explained above*/
-        mov itmp1,%rdi
-
-        call new_exception
-
-        call asm_remove_native_stackinfo /* be aware of the stack effect and calling convention explained above*/
-
-        pop xpc
-       pop xpc
-
-        jmp asm_handle_exception
-        ret /*should never be reached */
-
-
-asm_throw_and_handle_hardware_arithmetic_exception:
-
-        push xpc
-        push $0 /* the pushed XPC is directly below the java frame*/
-        push $0
-       push $0 /*padding*/
-        call asm_prepare_native_stackinfo /* be aware of the stack effect and calling convention explained above*/
-
-        mov string_java_lang_ArithmeticException_message,%rsi
-        mov string_java_lang_ArithmeticException,%rdi
-
-        call new_exception_message
-
-        call asm_remove_native_stackinfo /* be aware of the stack effect and calling convention explained above*/
-       pop xpc
-        pop xpc
-
-        jmp asm_handle_exception
-        ret /*should never be reached */
-
-
 asm_getclassvalues_atomic:
 _crit_restart2:
 _crit_begin2:
index 8c3f30287ae8b2148aff9633862522187fd776d3..a97cc3598aa43b498924df3b7280f05736385389 100644 (file)
@@ -29,7 +29,7 @@
 
    Changes: Christian Ullrich
 
-   $Id: codegen.c 2875 2005-06-30 09:16:21Z twisti $
+   $Id: codegen.c 2956 2005-07-09 14:04:34Z twisti $
 
 */
 
@@ -1220,24 +1220,24 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        }
                        gen_div_check(src);
 
-                       x86_64_alul_imm_reg(cd, X86_64_CMP, 0x80000000, RAX);    /* check as described in jvm spec */
+                       x86_64_alul_imm_reg(cd, X86_64_CMP, 0x80000000, RAX); /* check as described in jvm spec */
                        x86_64_jcc(cd, X86_64_CC_NE, 4 + 6);
-                       x86_64_alul_imm_reg(cd, X86_64_CMP, -1, REG_ITMP3);      /* 4 bytes */
-                       x86_64_jcc(cd, X86_64_CC_E, 3 + 1 + 3);                  /* 6 bytes */
+                       x86_64_alul_imm_reg(cd, X86_64_CMP, -1, REG_ITMP3);    /* 4 bytes */
+                       x86_64_jcc(cd, X86_64_CC_E, 3 + 1 + 3);                /* 6 bytes */
 
-                       x86_64_mov_reg_reg(cd, RDX, REG_ITMP2);    /* save %rdx, cause it's an argument register */
+                       x86_64_mov_reg_reg(cd, RDX, REG_ITMP2); /* save %rdx, cause it's an argument register */
                        x86_64_cltd(cd);
                        x86_64_idivl_reg(cd, REG_ITMP3);
 
                        if (iptr->dst->flags & INMEMORY) {
                                x86_64_mov_reg_membase(cd, RAX, REG_SP, iptr->dst->regoff * 8);
-                               x86_64_mov_reg_reg(cd, REG_ITMP2, RDX);    /* restore %rdx */
+                               x86_64_mov_reg_reg(cd, REG_ITMP2, RDX);       /* restore %rdx */
 
                        } else {
                                M_INTMOVE(RAX, iptr->dst->regoff);
 
                                if (iptr->dst->regoff != RDX) {
-                                       x86_64_mov_reg_reg(cd, REG_ITMP2, RDX);    /* restore %rdx */
+                                       x86_64_mov_reg_reg(cd, REG_ITMP2, RDX);   /* restore %rdx */
                                }
                        }
                        break;
@@ -1259,28 +1259,28 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        }
                        gen_div_check(src);
 
-                       x86_64_mov_reg_reg(cd, RDX, REG_ITMP2);    /* save %rdx, cause it's an argument register */
+                       x86_64_mov_reg_reg(cd, RDX, REG_ITMP2); /* save %rdx, cause it's an argument register */
 
-                       x86_64_alul_imm_reg(cd, X86_64_CMP, 0x80000000, RAX);    /* check as described in jvm spec */
+                       x86_64_alul_imm_reg(cd, X86_64_CMP, 0x80000000, RAX); /* check as described in jvm spec */
                        x86_64_jcc(cd, X86_64_CC_NE, 2 + 4 + 6);
 
 
-                       x86_64_alul_reg_reg(cd, X86_64_XOR, RDX, RDX);           /* 2 bytes */
-                       x86_64_alul_imm_reg(cd, X86_64_CMP, -1, REG_ITMP3);      /* 4 bytes */
-                       x86_64_jcc(cd, X86_64_CC_E, 1 + 3);                      /* 6 bytes */
+                       x86_64_alul_reg_reg(cd, X86_64_XOR, RDX, RDX);         /* 2 bytes */
+                       x86_64_alul_imm_reg(cd, X86_64_CMP, -1, REG_ITMP3);    /* 4 bytes */
+                       x86_64_jcc(cd, X86_64_CC_E, 1 + 3);                    /* 6 bytes */
 
                        x86_64_cltd(cd);
                        x86_64_idivl_reg(cd, REG_ITMP3);
 
                        if (iptr->dst->flags & INMEMORY) {
                                x86_64_mov_reg_membase(cd, RDX, REG_SP, iptr->dst->regoff * 8);
-                               x86_64_mov_reg_reg(cd, REG_ITMP2, RDX);    /* restore %rdx */
+                               x86_64_mov_reg_reg(cd, REG_ITMP2, RDX);       /* restore %rdx */
 
                        } else {
                                M_INTMOVE(RDX, iptr->dst->regoff);
 
                                if (iptr->dst->regoff != RDX) {
-                                       x86_64_mov_reg_reg(cd, REG_ITMP2, RDX);    /* restore %rdx */
+                                       x86_64_mov_reg_reg(cd, REG_ITMP2, RDX);   /* restore %rdx */
                                }
                        }
                        break;
@@ -2055,18 +2055,6 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        break;
 
 
-               case ICMD_AASTORE:    /* ..., arrayref, index, value  ==> ...         */
-
-                       var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
-                       var_to_reg_int(s2, src->prev, REG_ITMP2);
-                       if (iptr->op1 == 0) {
-                               gen_nullptr_check(s1);
-                               gen_bound_check;
-                       }
-                       var_to_reg_int(s3, src, REG_ITMP3);
-                       x86_64_mov_reg_memindex(cd, s3, OFFSET(java_objectarray, data[0]), s1, s2, 3);
-                       break;
-
                case ICMD_LASTORE:    /* ..., arrayref, index, value  ==> ...         */
 
                        var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
@@ -2151,6 +2139,32 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        x86_64_movb_reg_memindex(cd, s3, OFFSET(java_bytearray, data[0]), s1, s2, 0);
                        break;
 
+               case ICMD_AASTORE:    /* ..., arrayref, index, value  ==> ...         */
+
+                       var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
+                       var_to_reg_int(s2, src->prev, REG_ITMP2);
+/*                     if (iptr->op1 == 0) { */
+                               gen_nullptr_check(s1);
+                               gen_bound_check;
+/*                     } */
+                       var_to_reg_int(s3, src, REG_ITMP3);
+
+                       M_MOV(s1, rd->argintregs[0]);
+                       M_MOV(s3, rd->argintregs[1]);
+                       bte = iptr->val.a;
+                       x86_64_mov_imm_reg(cd, (ptrint) bte->fp, REG_ITMP1);
+                       x86_64_call_reg(cd, REG_ITMP1);
+                       M_TEST(REG_RESULT);
+                       M_BEQ(0);
+                       codegen_addxstorerefs(cd, cd->mcodeptr);
+
+                       var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
+                       var_to_reg_int(s2, src->prev, REG_ITMP2);
+                       var_to_reg_int(s3, src, REG_ITMP3);
+                       x86_64_mov_reg_memindex(cd, s3, OFFSET(java_objectarray, data[0]), s1, s2, 3);
+                       break;
+
+
                case ICMD_IASTORECONST: /* ..., arrayref, index  ==> ...              */
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
@@ -2233,7 +2247,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                                                        PATCHER_get_putstatic,
                                                                        (unresolved_field *) iptr->target);
 
-                               if (showdisassemble) {
+                               if (opt_showdisassemble) {
                                        M_NOP; M_NOP; M_NOP; M_NOP; M_NOP;
                                }
 
@@ -2246,7 +2260,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                        codegen_addpatchref(cd, cd->mcodeptr,
                                                                                PATCHER_clinit, fi->class);
 
-                                       if (showdisassemble) {
+                                       if (opt_showdisassemble) {
                                                M_NOP; M_NOP; M_NOP; M_NOP; M_NOP;
                                        }
                                }
@@ -2291,7 +2305,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                                                        PATCHER_get_putstatic,
                                                                        (unresolved_field *) iptr->target);
 
-                               if (showdisassemble) {
+                               if (opt_showdisassemble) {
                                        M_NOP; M_NOP; M_NOP; M_NOP; M_NOP;
                                }
 
@@ -2304,7 +2318,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                        codegen_addpatchref(cd, cd->mcodeptr,
                                                                                PATCHER_clinit, fi->class);
 
-                                       if (showdisassemble) {
+                                       if (opt_showdisassemble) {
                                                M_NOP; M_NOP; M_NOP; M_NOP; M_NOP;
                                        }
                                }
@@ -2347,7 +2361,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                                                        PATCHER_get_putstatic,
                                                                        (unresolved_field *) iptr[1].target);
 
-                               if (showdisassemble) {
+                               if (opt_showdisassemble) {
                                        M_NOP; M_NOP; M_NOP; M_NOP; M_NOP;
                                }
 
@@ -2360,7 +2374,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                        codegen_addpatchref(cd, cd->mcodeptr,
                                                                                PATCHER_clinit, fi->class);
 
-                                       if (showdisassemble) {
+                                       if (opt_showdisassemble) {
                                                M_NOP; M_NOP; M_NOP; M_NOP; M_NOP;
                                        }
                                }
@@ -2401,7 +2415,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                                                        PATCHER_get_putfield,
                                                                        (unresolved_field *) iptr->target);
 
-                               if (showdisassemble) {
+                               if (opt_showdisassemble) {
                                        M_NOP; M_NOP; M_NOP; M_NOP; M_NOP;
                                }
 
@@ -2452,7 +2466,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                                                        PATCHER_get_putfield,
                                                                        (unresolved_field *) iptr->target);
 
-                               if (showdisassemble) {
+                               if (opt_showdisassemble) {
                                        M_NOP; M_NOP; M_NOP; M_NOP; M_NOP;
                                }
 
@@ -2492,7 +2506,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                                                        PATCHER_putfieldconst,
                                                                        (unresolved_field *) iptr[1].target);
 
-                               if (showdisassemble) {
+                               if (opt_showdisassemble) {
                                        M_NOP; M_NOP; M_NOP; M_NOP; M_NOP;
                                }
 
@@ -3081,7 +3095,7 @@ gen_method:
                                        codegen_addpatchref(cd, cd->mcodeptr,
                                                                                bte->fp, iptr->target);
 
-                                       if (showdisassemble) {
+                                       if (opt_showdisassemble) {
                                                M_NOP; M_NOP; M_NOP; M_NOP; M_NOP;
                                        }
 
@@ -3117,7 +3131,7 @@ gen_method:
                                        codegen_addpatchref(cd, cd->mcodeptr,
                                                                                PATCHER_invokestatic_special, um);
 
-                                       if (showdisassemble) {
+                                       if (opt_showdisassemble) {
                                                M_NOP; M_NOP; M_NOP; M_NOP; M_NOP;
                                        }
 
@@ -3142,7 +3156,7 @@ gen_method:
                                        codegen_addpatchref(cd, cd->mcodeptr,
                                                                                PATCHER_invokevirtual, um);
 
-                                       if (showdisassemble) {
+                                       if (opt_showdisassemble) {
                                                M_NOP; M_NOP; M_NOP; M_NOP; M_NOP;
                                        }
 
@@ -3171,7 +3185,7 @@ gen_method:
                                        codegen_addpatchref(cd, cd->mcodeptr,
                                                                                PATCHER_invokeinterface, um);
 
-                                       if (showdisassemble) {
+                                       if (opt_showdisassemble) {
                                                M_NOP; M_NOP; M_NOP; M_NOP; M_NOP;
                                        }
 
@@ -3262,7 +3276,7 @@ gen_method:
                                3 /* test */ + 6 /* jcc */;
 
                        if (!super)
-                               s2 += (showdisassemble ? 5 : 0);
+                               s2 += (opt_showdisassemble ? 5 : 0);
 
                        /* calculate class checkcast code size */
 
@@ -3289,19 +3303,19 @@ gen_method:
                        s3 += 3 /* cmp */ + 6 /* jcc */;
 
                        if (!super)
-                               s3 += (showdisassemble ? 5 : 0);
+                               s3 += (opt_showdisassemble ? 5 : 0);
 
                        /* if class is not resolved, check which code to call */
 
                        if (!super) {
                                x86_64_test_reg_reg(cd, s1, s1);
-                               x86_64_jcc(cd, X86_64_CC_Z, 6 + (showdisassemble ? 5 : 0) + 7 + 6 + s2 + 5 + s3);
+                               x86_64_jcc(cd, X86_64_CC_Z, 6 + (opt_showdisassemble ? 5 : 0) + 7 + 6 + s2 + 5 + s3);
 
                                codegen_addpatchref(cd, cd->mcodeptr,
                                                                        PATCHER_checkcast_instanceof_flags,
                                                                        (constant_classref *) iptr->target);
 
-                               if (showdisassemble) {
+                               if (opt_showdisassemble) {
                                        M_NOP; M_NOP; M_NOP; M_NOP; M_NOP;
                                }
 
@@ -3327,7 +3341,7 @@ gen_method:
                                                                                PATCHER_checkcast_instanceof_interface,
                                                                                (constant_classref *) iptr->target);
 
-                                       if (showdisassemble) {
+                                       if (opt_showdisassemble) {
                                                M_NOP; M_NOP; M_NOP; M_NOP; M_NOP;
                                        }
                                }
@@ -3368,7 +3382,7 @@ gen_method:
                                                                                PATCHER_checkcast_class,
                                                                                (constant_classref *) iptr->target);
 
-                                       if (showdisassemble) {
+                                       if (opt_showdisassemble) {
                                                M_NOP; M_NOP; M_NOP; M_NOP; M_NOP;
                                        }
                                }
@@ -3412,14 +3426,43 @@ gen_method:
                        d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        M_INTMOVE(s1, d);
                        store_reg_to_var_int(iptr->dst, d);
-/*                     if (iptr->dst->flags & INMEMORY) { */
-/*                             x86_64_mov_reg_membase(cd, s1, REG_SP, iptr->dst->regoff * 8); */
-/*                     } else { */
-/*                             M_INTMOVE(s1, iptr->dst->regoff); */
-/*                     } */
                        }
                        break;
 
+               case ICMD_ARRAYCHECKCAST: /* ..., objectref ==> ..., objectref        */
+                                         /* op1: 1... resolved, 0... not resolved    */
+
+                       var_to_reg_int(s1, src, REG_ITMP1);
+                       M_INTMOVE(s1, rd->argintregs[0]);
+
+                       bte = iptr->val.a;
+
+                       if (!iptr->op1) {
+                               codegen_addpatchref(cd, cd->mcodeptr, bte->fp, iptr->target);
+
+                               if (opt_showdisassemble) {
+                                       M_NOP; M_NOP; M_NOP; M_NOP; M_NOP;
+                               }
+
+                               a = 0;
+
+                       } else {
+                               a = (ptrint) bte->fp;
+                       }
+
+                       x86_64_mov_imm_reg(cd, (ptrint) iptr->target, rd->argintregs[1]);
+                       x86_64_mov_imm_reg(cd, (ptrint) a, REG_ITMP1);
+                       x86_64_call_reg(cd, REG_ITMP1);
+                       M_TEST(REG_RESULT);
+                       M_BEQ(0);
+                       codegen_addxcastrefs(cd, cd->mcodeptr);
+
+                       var_to_reg_int(s1, src, REG_ITMP1);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP1);
+                       M_INTMOVE(s1, d);
+                       store_reg_to_var_int(iptr->dst, d);
+                       break;
+
                case ICMD_INSTANCEOF: /* ..., objectref ==> ..., intresult            */
 
                                      /* op1:   0 == array, 1 == class                */
@@ -3474,7 +3517,7 @@ gen_method:
                                3 /* test */ + 4 /* setcc */;
 
                        if (!super)
-                               s2 += (showdisassemble ? 5 : 0);
+                               s2 += (opt_showdisassemble ? 5 : 0);
 
                        /* calculate class instanceof code size */
                        
@@ -3490,7 +3533,7 @@ gen_method:
                        s3 += 3 /* sub */ + 3 /* xor */ + 3 /* cmp */ + 4 /* setcc */;
 
                        if (!super)
-                               s3 += (showdisassemble ? 5 : 0);
+                               s3 += (opt_showdisassemble ? 5 : 0);
 
                        x86_64_alu_reg_reg(cd, X86_64_XOR, d, d);
 
@@ -3498,14 +3541,14 @@ gen_method:
 
                        if (!super) {
                                x86_64_test_reg_reg(cd, s1, s1);
-                               x86_64_jcc(cd, X86_64_CC_Z, (6 + (showdisassemble ? 5 : 0) +
+                               x86_64_jcc(cd, X86_64_CC_Z, (6 + (opt_showdisassemble ? 5 : 0) +
                                                                                         7 + 6 + s2 + 5 + s3));
 
                                codegen_addpatchref(cd, cd->mcodeptr,
                                                                        PATCHER_checkcast_instanceof_flags,
                                                                        (constant_classref *) iptr->target);
 
-                               if (showdisassemble) {
+                               if (opt_showdisassemble) {
                                        M_NOP; M_NOP; M_NOP; M_NOP; M_NOP;
                                }
 
@@ -3530,7 +3573,7 @@ gen_method:
                                                                                PATCHER_checkcast_instanceof_interface,
                                                                                (constant_classref *) iptr->target);
 
-                                       if (showdisassemble) {
+                                       if (opt_showdisassemble) {
                                                M_NOP; M_NOP; M_NOP; M_NOP; M_NOP;
                                        }
                                }
@@ -3572,7 +3615,7 @@ gen_method:
                                                                                PATCHER_instanceof_class,
                                                                                (constant_classref *) iptr->target);
 
-                                       if (showdisassemble) {
+                                       if (opt_showdisassemble) {
                                                M_NOP; M_NOP; M_NOP; M_NOP; M_NOP;
                                        }
                                }
@@ -3648,7 +3691,7 @@ gen_method:
                                                                        (functionptr) (ptrint) iptr->target,
                                                                        iptr->val.a);
 
-                               if (showdisassemble) {
+                               if (opt_showdisassemble) {
                                        M_NOP; M_NOP; M_NOP; M_NOP; M_NOP;
                                }
 
@@ -3739,12 +3782,82 @@ gen_method:
 
                /* move index register into REG_ITMP1 */
 
-               M_MOV(bref->reg, REG_ITMP1);                             /* 3 bytes  */
+               M_MOV(bref->reg, REG_ITMP1);                              /* 3 bytes  */
+
+               x86_64_mov_imm_reg(cd, 0, REG_ITMP2_XPC);                 /* 10 bytes */
+               dseg_adddata(cd, cd->mcodeptr);
+               M_AADD_IMM32(bref->branchpos - 6, REG_ITMP2_XPC);         /* 7 bytes  */
+
+               if (xcodeptr != NULL) {
+                       x86_64_jmp_imm(cd, xcodeptr - cd->mcodeptr - 5);
+
+               } else {
+                       xcodeptr = cd->mcodeptr;
+
+                       M_ASUB_IMM(2 * 8 + sizeof(stackframeinfo), REG_SP);
+                       M_IST(REG_ITMP1, REG_SP, 0 * 8);
+                       M_AST(REG_ITMP2_XPC, REG_SP, 1 * 8);
+
+                       /* create stackframe info */
+
+                       M_MOV(REG_SP, rd->argintregs[0]);
+                       M_AADD_IMM(2 * 8, rd->argintregs[0]);
+
+                       x86_64_lea_membase_reg(cd, RIP, -(((ptrint) cd->mcodeptr + 7) - (ptrint) cd->mcodebase), rd->argintregs[1]);
+
+                       M_MOV(REG_SP, rd->argintregs[2]);
+                       M_AADD_IMM(2 * 8 + sizeof(stackframeinfo), rd->argintregs[2]);
+                       M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
+                       x86_64_mov_imm_reg(cd, (ptrint) stacktrace_create_inline_stackframeinfo,
+                                                          REG_ITMP3);
+                       x86_64_call_reg(cd, REG_ITMP3);
+
+                       /* create exception */
+
+                       M_ILD(rd->argintregs[0], REG_SP, 0 * 8);
+                       x86_64_mov_imm_reg(cd, (ptrint) new_arrayindexoutofboundsexception,
+                                                          REG_ITMP3);
+                       x86_64_call_reg(cd, REG_ITMP3);
+                       M_AST(REG_RESULT, REG_SP, 0 * 8);
+
+                       /* removed stackframe info */
+
+                       M_MOV(REG_SP, rd->argintregs[0]);
+                       M_AADD_IMM(2 * 8, rd->argintregs[0]);
+                       x86_64_mov_imm_reg(cd, (ptrint) stacktrace_remove_stackframeinfo,
+                                                          REG_ITMP3);
+                       x86_64_call_reg(cd, REG_ITMP3);
+
+                       M_ALD(REG_ITMP1_XPTR, REG_SP, 0 * 8);
+                       M_ALD(REG_ITMP2_XPC, REG_SP, 1 * 8);
+                       M_AADD_IMM(2 * 8 + sizeof(stackframeinfo), REG_SP);
+
+                       x86_64_mov_imm_reg(cd, (ptrint) asm_handle_exception, REG_ITMP3);
+                       x86_64_jmp_reg(cd, REG_ITMP3);
+               }
+       }
+
+       /* generate ArrayStoreException stubs */
+
+       xcodeptr = NULL;
+       
+       for (bref = cd->xstorerefs; bref != NULL; bref = bref->next) {
+               if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) {
+                       gen_resolvebranch(cd->mcodebase + bref->branchpos, 
+                                                         bref->branchpos,
+                                                         xcodeptr - cd->mcodebase - (10 + 7));
+                       continue;
+               }
+
+               gen_resolvebranch(cd->mcodebase + bref->branchpos, 
+                                 bref->branchpos,
+                                                 cd->mcodeptr - cd->mcodebase);
+
+               MCODECHECK(512);
 
                x86_64_mov_imm_reg(cd, 0, REG_ITMP2_XPC);                 /* 10 bytes */
                dseg_adddata(cd, cd->mcodeptr);
-               x86_64_mov_imm_reg(cd, bref->branchpos - 6, REG_ITMP3);   /* 10 bytes */
-               M_AADD(REG_ITMP3, REG_ITMP2_XPC);                         /* 3 bytes  */
+               M_AADD_IMM32(bref->branchpos - 6, REG_ITMP2_XPC);         /* 7 bytes  */
 
                if (xcodeptr != NULL) {
                        x86_64_jmp_imm(cd, xcodeptr - cd->mcodeptr - 5);
@@ -3752,27 +3865,41 @@ gen_method:
                } else {
                        xcodeptr = cd->mcodeptr;
 
+                       M_ASUB_IMM(2 * 8 + sizeof(stackframeinfo), REG_SP);
+                       M_AST(REG_ITMP2_XPC, REG_SP, 1 * 8);
 
-                       /*create stackinfo -- begin*/
-                       x86_64_alu_imm_reg(cd, X86_64_SUB, 4 * 8, REG_SP);
-                       x86_64_mov_reg_membase(cd, REG_ITMP2_XPC, REG_SP, 3 * 8);
-                       x86_64_mov_imm_membase(cd,0,REG_SP,2*8);
-                       x86_64_mov_imm_membase(cd,0,REG_SP,1*8);
-                       x86_64_mov_imm_reg(cd,(ptrint)asm_prepare_native_stackinfo,REG_ITMP3);
-                       x86_64_call_reg(cd,REG_ITMP3);
-                       /*create stackinfo -- end*/
+                       /* create stackframe info */
 
-                       x86_64_mov_reg_reg(cd, REG_ITMP1, rd->argintregs[0]);
-                       x86_64_mov_imm_reg(cd, (ptrint) new_arrayindexoutofboundsexception, REG_ITMP3);
+                       M_MOV(REG_SP, rd->argintregs[0]);
+                       M_AADD_IMM(2 * 8, rd->argintregs[0]);
+
+                       x86_64_lea_membase_reg(cd, RIP, -(((ptrint) cd->mcodeptr + 7) - (ptrint) cd->mcodebase), rd->argintregs[1]);
+
+                       M_MOV(REG_SP, rd->argintregs[2]);
+                       M_AADD_IMM(2 * 8 + sizeof(stackframeinfo), rd->argintregs[2]);
+                       M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
+                       x86_64_mov_imm_reg(cd, (ptrint) stacktrace_create_inline_stackframeinfo,
+                                                          REG_ITMP3);
                        x86_64_call_reg(cd, REG_ITMP3);
 
-                       /*remove stackinfo -- begin*/
-                       x86_64_mov_imm_reg(cd,(ptrint)asm_remove_native_stackinfo,REG_ITMP3);
-                       x86_64_call_reg(cd,REG_ITMP3);
-                       /*remove stackinfo -- end*/
+                       /* create exception */
 
-                       x86_64_mov_membase_reg(cd, REG_SP, 1 * 8, REG_ITMP2_XPC);
-                       x86_64_alu_imm_reg(cd, X86_64_ADD, 2 * 8, REG_SP);
+                       x86_64_mov_imm_reg(cd, (ptrint) new_arraystoreexception,
+                                                          REG_ITMP3);
+                       x86_64_call_reg(cd, REG_ITMP3);
+                       M_AST(REG_RESULT, REG_SP, 0 * 8);
+
+                       /* removed stackframe info */
+
+                       M_MOV(REG_SP, rd->argintregs[0]);
+                       M_AADD_IMM(2 * 8, rd->argintregs[0]);
+                       x86_64_mov_imm_reg(cd, (ptrint) stacktrace_remove_stackframeinfo,
+                                                          REG_ITMP3);
+                       x86_64_call_reg(cd, REG_ITMP3);
+
+                       M_ALD(REG_ITMP1_XPTR, REG_SP, 0 * 8);
+                       M_ALD(REG_ITMP2_XPC, REG_SP, 1 * 8);
+                       M_AADD_IMM(2 * 8 + sizeof(stackframeinfo), REG_SP);
 
                        x86_64_mov_imm_reg(cd, (ptrint) asm_handle_exception, REG_ITMP3);
                        x86_64_jmp_reg(cd, REG_ITMP3);
@@ -3787,7 +3914,7 @@ gen_method:
                if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) {
                        gen_resolvebranch(cd->mcodebase + bref->branchpos, 
                                                          bref->branchpos,
-                                                         xcodeptr - cd->mcodebase - (10 + 10 + 3));
+                                                         xcodeptr - cd->mcodebase - (10 + 7));
                        continue;
                }
 
@@ -3799,8 +3926,7 @@ gen_method:
 
                x86_64_mov_imm_reg(cd, 0, REG_ITMP2_XPC);                 /* 10 bytes */
                dseg_adddata(cd, cd->mcodeptr);
-               x86_64_mov_imm_reg(cd, bref->branchpos - 6, REG_ITMP3);   /* 10 bytes */
-               x86_64_alu_reg_reg(cd, X86_64_ADD, REG_ITMP3, REG_ITMP2_XPC); /* 3 bytes  */
+               M_AADD_IMM32(bref->branchpos - 6, REG_ITMP2_XPC);         /* 7 bytes  */
 
                if (xcodeptr != NULL) {
                        x86_64_jmp_imm(cd, xcodeptr - cd->mcodeptr - 5);
@@ -3808,33 +3934,48 @@ gen_method:
                } else {
                        xcodeptr = cd->mcodeptr;
 
+                       M_ASUB_IMM(2 * 8 + sizeof(stackframeinfo), REG_SP);
+                       M_AST(REG_ITMP2_XPC, REG_SP, 1 * 8);
+
+                       /* create stackframe info */
+
+                       M_MOV(REG_SP, rd->argintregs[0]);
+                       M_AADD_IMM(2 * 8, rd->argintregs[0]);
 
-                       /*create stackinfo -- begin*/
-                       x86_64_alu_imm_reg(cd, X86_64_SUB, 4 * 8, REG_SP);
-                       x86_64_mov_reg_membase(cd, REG_ITMP2_XPC, REG_SP, 3 * 8);
-                       x86_64_mov_imm_membase(cd,0,REG_SP,2*8);
-                       x86_64_mov_imm_membase(cd,0,REG_SP,1*8);
-                       x86_64_mov_imm_reg(cd,(ptrint)asm_prepare_native_stackinfo,REG_ITMP3);
-                       x86_64_call_reg(cd,REG_ITMP3);
-                       /*create stackinfo -- end*/
+                       x86_64_lea_membase_reg(cd, RIP, -(((ptrint) cd->mcodeptr + 7) - (ptrint) cd->mcodebase), rd->argintregs[1]);
 
-                       x86_64_mov_imm_reg(cd, (u8) new_negativearraysizeexception, REG_ITMP3);
+                       M_MOV(REG_SP, rd->argintregs[2]);
+                       M_AADD_IMM(2 * 8 + sizeof(stackframeinfo), rd->argintregs[2]);
+                       M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
+                       x86_64_mov_imm_reg(cd, (ptrint) stacktrace_create_inline_stackframeinfo,
+                                                          REG_ITMP3);
                        x86_64_call_reg(cd, REG_ITMP3);
 
-                       /*remove stackinfo -- begin*/
-                       x86_64_mov_imm_reg(cd,(ptrint)asm_remove_native_stackinfo,REG_ITMP3);
-                       x86_64_call_reg(cd,REG_ITMP3);
-                       /*remove stackinfo -- end*/
+                       /* create exception */
+
+                       x86_64_mov_imm_reg(cd, (ptrint) new_negativearraysizeexception,
+                                                          REG_ITMP3);
+                       x86_64_call_reg(cd, REG_ITMP3);
+                       M_AST(REG_RESULT, REG_SP, 0 * 8);
+
+                       /* removed stackframe info */
+
+                       M_MOV(REG_SP, rd->argintregs[0]);
+                       M_AADD_IMM(2 * 8, rd->argintregs[0]);
+                       x86_64_mov_imm_reg(cd, (ptrint) stacktrace_remove_stackframeinfo,
+                                                          REG_ITMP3);
+                       x86_64_call_reg(cd, REG_ITMP3);
 
-                       x86_64_mov_membase_reg(cd, REG_SP, 1 * 8, REG_ITMP2_XPC);
-                       x86_64_alu_imm_reg(cd, X86_64_ADD, 2 * 8, REG_SP);
+                       M_ALD(REG_ITMP1_XPTR, REG_SP, 0 * 8);
+                       M_ALD(REG_ITMP2_XPC, REG_SP, 1 * 8);
+                       M_AADD_IMM(2 * 8 + sizeof(stackframeinfo), REG_SP);
 
-                       x86_64_mov_imm_reg(cd, (u8) asm_handle_exception, REG_ITMP3);
+                       x86_64_mov_imm_reg(cd, (ptrint) asm_handle_exception, REG_ITMP3);
                        x86_64_jmp_reg(cd, REG_ITMP3);
                }
        }
 
-       /* generate cast check stubs */
+       /* generate ClassCastException stubs */
 
        xcodeptr = NULL;
        
@@ -3842,7 +3983,7 @@ gen_method:
                if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) {
                        gen_resolvebranch(cd->mcodebase + bref->branchpos, 
                                                          bref->branchpos,
-                                                         xcodeptr - cd->mcodebase - (10 + 10 + 3));
+                                                         xcodeptr - cd->mcodebase - (10 + 7));
                        continue;
                }
 
@@ -3854,8 +3995,7 @@ gen_method:
 
                x86_64_mov_imm_reg(cd, 0, REG_ITMP2_XPC);                 /* 10 bytes */
                dseg_adddata(cd, cd->mcodeptr);
-               x86_64_mov_imm_reg(cd, bref->branchpos - 6, REG_ITMP3);   /* 10 bytes */
-               x86_64_alu_reg_reg(cd, X86_64_ADD, REG_ITMP3, REG_ITMP2_XPC); /* 3 bytes  */
+               M_AADD_IMM32(bref->branchpos - 6, REG_ITMP2_XPC);         /* 7 bytes  */
 
                if (xcodeptr != NULL) {
                        x86_64_jmp_imm(cd, xcodeptr - cd->mcodeptr - 5);
@@ -3863,33 +4003,47 @@ gen_method:
                } else {
                        xcodeptr = cd->mcodeptr;
 
-                       /*create stackinfo -- begin*/
-                       x86_64_alu_imm_reg(cd, X86_64_SUB, 4 * 8, REG_SP);
-                       x86_64_mov_reg_membase(cd, REG_ITMP2_XPC, REG_SP, 3 * 8);
-                       x86_64_mov_imm_membase(cd,0,REG_SP,2*8);
-                       x86_64_mov_imm_membase(cd,0,REG_SP,1*8);
-                       x86_64_mov_imm_reg(cd,(ptrint)asm_prepare_native_stackinfo,REG_ITMP3);
-                       x86_64_call_reg(cd,REG_ITMP3);
-                       /*create stackinfo -- end*/
+                       M_ASUB_IMM(2 * 8 + sizeof(stackframeinfo), REG_SP);
+                       M_AST(REG_ITMP2_XPC, REG_SP, 1 * 8);
+
+                       /* create stackframe info */
+
+                       M_MOV(REG_SP, rd->argintregs[0]);
+                       M_AADD_IMM(2 * 8, rd->argintregs[0]);
+
+                       x86_64_lea_membase_reg(cd, RIP, -(((ptrint) cd->mcodeptr + 7) - (ptrint) cd->mcodebase), rd->argintregs[1]);
+
+                       M_MOV(REG_SP, rd->argintregs[2]);
+                       M_AADD_IMM(2 * 8 + sizeof(stackframeinfo), rd->argintregs[2]);
+                       M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
+                       x86_64_mov_imm_reg(cd, (ptrint) stacktrace_create_inline_stackframeinfo,
+                                                          REG_ITMP3);
+                       x86_64_call_reg(cd, REG_ITMP3);
 
+                       /* create exception */
 
-                       x86_64_mov_imm_reg(cd, (u8) new_classcastexception, REG_ITMP3);
+                       x86_64_mov_imm_reg(cd, (ptrint) new_classcastexception, REG_ITMP3);
                        x86_64_call_reg(cd, REG_ITMP3);
+                       M_AST(REG_RESULT, REG_SP, 0 * 8);
 
-                       /*remove stackinfo -- begin*/
-                       x86_64_mov_imm_reg(cd,(ptrint)asm_remove_native_stackinfo,REG_ITMP3);
-                       x86_64_call_reg(cd,REG_ITMP3);
-                       /*remove stackinfo -- end*/
+                       /* removed stackframe info */
 
-                       x86_64_mov_membase_reg(cd, REG_SP, 1 * 8, REG_ITMP2_XPC);
-                       x86_64_alu_imm_reg(cd, X86_64_ADD, 2 * 8, REG_SP);
+                       M_MOV(REG_SP, rd->argintregs[0]);
+                       M_AADD_IMM(2 * 8, rd->argintregs[0]);
+                       x86_64_mov_imm_reg(cd, (ptrint) stacktrace_remove_stackframeinfo,
+                                                          REG_ITMP3);
+                       x86_64_call_reg(cd, REG_ITMP3);
+
+                       M_ALD(REG_ITMP1_XPTR, REG_SP, 0 * 8);
+                       M_ALD(REG_ITMP2_XPC, REG_SP, 1 * 8);
+                       M_AADD_IMM(2 * 8 + sizeof(stackframeinfo), REG_SP);
 
-                       x86_64_mov_imm_reg(cd, (u8) asm_handle_exception, REG_ITMP3);
+                       x86_64_mov_imm_reg(cd, (ptrint) asm_handle_exception, REG_ITMP3);
                        x86_64_jmp_reg(cd, REG_ITMP3);
                }
        }
 
-       /* generate divide by zero check stubs */
+       /* generate ArithmeticException stubs */
 
        xcodeptr = NULL;
        
@@ -3897,7 +4051,7 @@ gen_method:
                if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) {
                        gen_resolvebranch(cd->mcodebase + bref->branchpos, 
                                                          bref->branchpos,
-                                                         xcodeptr - cd->mcodebase - (10 + 10 + 3));
+                                                         xcodeptr - cd->mcodebase - (10 + 7));
                        continue;
                }
 
@@ -3909,8 +4063,7 @@ gen_method:
 
                x86_64_mov_imm_reg(cd, 0, REG_ITMP2_XPC);                 /* 10 bytes */
                dseg_adddata(cd, cd->mcodeptr);
-               x86_64_mov_imm_reg(cd, bref->branchpos - 6, REG_ITMP3);   /* 10 bytes */
-               x86_64_alu_reg_reg(cd, X86_64_ADD, REG_ITMP3, REG_ITMP2_XPC); /* 3 bytes  */
+               M_AADD_IMM32(bref->branchpos - 6, REG_ITMP2_XPC);         /* 7 bytes  */
 
                if (xcodeptr != NULL) {
                        x86_64_jmp_imm(cd, xcodeptr - cd->mcodeptr - 5);
@@ -3918,40 +4071,55 @@ gen_method:
                } else {
                        xcodeptr = cd->mcodeptr;
 
-                       /*create stackinfo -- begin*/
-                       x86_64_alu_imm_reg(cd, X86_64_SUB, 4 * 8, REG_SP);
-                       x86_64_mov_reg_membase(cd, REG_ITMP2_XPC, REG_SP, 3 * 8);
-                       x86_64_mov_imm_membase(cd,0,REG_SP,2*8);
-                       x86_64_mov_imm_membase(cd,0,REG_SP,1*8);
-                       x86_64_mov_imm_reg(cd,(ptrint)asm_prepare_native_stackinfo,REG_ITMP3);
-                       x86_64_call_reg(cd,REG_ITMP3);
-                       /*create stackinfo -- end*/
+                       M_ASUB_IMM(2 * 8 + sizeof(stackframeinfo), REG_SP);
+                       M_AST(REG_ITMP2_XPC, REG_SP, 1 * 8);
+
+                       /* create stackframe info */
+
+                       M_MOV(REG_SP, rd->argintregs[0]);
+                       M_AADD_IMM(2 * 8, rd->argintregs[0]);
+
+                       x86_64_lea_membase_reg(cd, RIP, -(((ptrint) cd->mcodeptr + 7) - (ptrint) cd->mcodebase), rd->argintregs[1]);
 
-                       x86_64_mov_imm_reg(cd, (u8) new_arithmeticexception, REG_ITMP3);
+                       M_MOV(REG_SP, rd->argintregs[2]);
+                       M_AADD_IMM(2 * 8 + sizeof(stackframeinfo), rd->argintregs[2]);
+                       M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
+                       x86_64_mov_imm_reg(cd, (ptrint) stacktrace_create_inline_stackframeinfo,
+                                                          REG_ITMP3);
                        x86_64_call_reg(cd, REG_ITMP3);
 
-                       /*remove stackinfo -- begin*/
-                       x86_64_mov_imm_reg(cd,(ptrint)asm_remove_native_stackinfo,REG_ITMP3);
-                       x86_64_call_reg(cd,REG_ITMP3);
-                       /*remove stackinfo -- end*/
+                       /* create exception */
 
-                       x86_64_mov_membase_reg(cd, REG_SP, 1 * 8, REG_ITMP2_XPC);
-                       x86_64_alu_imm_reg(cd, X86_64_ADD, 2 * 8, REG_SP);
+                       x86_64_mov_imm_reg(cd, (ptrint) new_arithmeticexception, REG_ITMP3);
+                       x86_64_call_reg(cd, REG_ITMP3);
+                       M_AST(REG_RESULT, REG_SP, 0 * 8);
+
+                       /* removed stackframe info */
+
+                       M_MOV(REG_SP, rd->argintregs[0]);
+                       M_AADD_IMM(2 * 8, rd->argintregs[0]);
+                       x86_64_mov_imm_reg(cd, (ptrint) stacktrace_remove_stackframeinfo,
+                                                          REG_ITMP3);
+                       x86_64_call_reg(cd, REG_ITMP3);
+
+                       M_ALD(REG_ITMP1_XPTR, REG_SP, 0 * 8);
+                       M_ALD(REG_ITMP2_XPC, REG_SP, 1 * 8);
+                       M_AADD_IMM(2 * 8 + sizeof(stackframeinfo), REG_SP);
 
-                       x86_64_mov_imm_reg(cd, (u8) asm_handle_exception, REG_ITMP3);
+                       x86_64_mov_imm_reg(cd, (ptrint) asm_handle_exception, REG_ITMP3);
                        x86_64_jmp_reg(cd, REG_ITMP3);
                }
        }
 
-       /* generate exception check stubs */
+       /* generate NullpointerException stubs */
 
        xcodeptr = NULL;
        
-       for (bref = cd->xexceptionrefs; bref != NULL; bref = bref->next) {
+       for (bref = cd->xnullrefs; bref != NULL; bref = bref->next) {
                if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) {
                        gen_resolvebranch(cd->mcodebase + bref->branchpos, 
                                                          bref->branchpos,
-                                                         xcodeptr - cd->mcodebase - (10 + 10 + 3));
+                                                         xcodeptr - cd->mcodebase - (10 + 7));
                        continue;
                }
 
@@ -3963,8 +4131,7 @@ gen_method:
 
                x86_64_mov_imm_reg(cd, 0, REG_ITMP2_XPC);                 /* 10 bytes */
                dseg_adddata(cd, cd->mcodeptr);
-               x86_64_mov_imm_reg(cd, bref->branchpos - 6, REG_ITMP1);   /* 10 bytes */
-               x86_64_alu_reg_reg(cd, X86_64_ADD, REG_ITMP1, REG_ITMP2_XPC); /* 3 bytes  */
+               M_AADD_IMM32(bref->branchpos - 6, REG_ITMP2_XPC);         /* 7 bytes  */
 
                if (xcodeptr != NULL) {
                        x86_64_jmp_imm(cd, xcodeptr - cd->mcodeptr - 5);
@@ -3972,53 +4139,56 @@ gen_method:
                } else {
                        xcodeptr = cd->mcodeptr;
 
-                       x86_64_alu_imm_reg(cd, X86_64_SUB, 4*8, REG_SP);
-                       x86_64_mov_reg_membase(cd, REG_ITMP2_XPC, REG_SP, 3*8);
-                       x86_64_mov_imm_membase(cd, 0, REG_SP, 2*8);
-                       x86_64_mov_imm_membase(cd, 0, REG_SP, 1*8);
-                       x86_64_mov_imm_membase(cd, 0, REG_SP, 0*8);
-                       x86_64_mov_imm_reg(cd,(u8) asm_prepare_native_stackinfo,REG_ITMP1);
-                       x86_64_call_reg(cd,REG_ITMP1);
-                       
+                       M_ASUB_IMM(2 * 8 + sizeof(stackframeinfo), REG_SP);
+                       M_AST(REG_ITMP2_XPC, REG_SP, 1 * 8);
 
-#if defined(USE_THREADS) && defined(NATIVE_THREADS)
-                       x86_64_mov_imm_reg(cd, (u8) &builtin_get_exceptionptrptr, REG_ITMP1);
-                       x86_64_call_reg(cd, REG_ITMP1);
-                       x86_64_mov_membase_reg(cd, REG_RESULT, 0, REG_ITMP3);
-                       x86_64_mov_imm_membase(cd, 0, REG_RESULT, 0);
-                       x86_64_mov_reg_reg(cd, REG_ITMP3, REG_ITMP1_XPTR);
-#else
-                       x86_64_mov_imm_reg(cd, (u8) &_exceptionptr, REG_ITMP3);
-                       x86_64_mov_membase_reg(cd, REG_ITMP3, 0, REG_ITMP1_XPTR);
-                       x86_64_mov_imm_membase(cd, 0, REG_ITMP3, 0);
-#endif
-                       x86_64_mov_reg_reg(cd,REG_ITMP1_XPTR,RDI);
-                       x86_64_mov_imm_reg(cd,(u8) helper_fillin_stacktrace_always,REG_ITMP1);
-                       x86_64_call_reg(cd,REG_ITMP1);
-                       x86_64_mov_reg_reg(cd,REG_RESULT,REG_ITMP1_XPTR);
+                       /* create stackframe info */
 
-                       x86_64_mov_imm_reg(cd,(u8) asm_remove_native_stackinfo,REG_ITMP2);
-                       x86_64_call_reg(cd,REG_ITMP2);
-                       
-                       x86_64_alu_imm_reg(cd, X86_64_ADD, 8, REG_SP);
-                       x86_64_mov_membase_reg(cd, REG_SP, 0, REG_ITMP2_XPC);
-                       x86_64_alu_imm_reg(cd, X86_64_ADD, 8, REG_SP);
+                       M_MOV(REG_SP, rd->argintregs[0]);
+                       M_AADD_IMM(2 * 8, rd->argintregs[0]);
+
+                       x86_64_lea_membase_reg(cd, RIP, -(((ptrint) cd->mcodeptr + 7) - (ptrint) cd->mcodebase), rd->argintregs[1]);
+
+                       M_MOV(REG_SP, rd->argintregs[2]);
+                       M_AADD_IMM(2 * 8 + sizeof(stackframeinfo), rd->argintregs[2]);
+                       M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
+                       x86_64_mov_imm_reg(cd, (ptrint) stacktrace_create_inline_stackframeinfo,
+                                                          REG_ITMP3);
+                       x86_64_call_reg(cd, REG_ITMP3);
+
+                       /* create exception */
+
+                       x86_64_mov_imm_reg(cd, (ptrint) new_nullpointerexception,
+                                                          REG_ITMP3);
+                       x86_64_call_reg(cd, REG_ITMP3);
+                       M_AST(REG_RESULT, REG_SP, 0 * 8);
 
+                       /* removed stackframe info */
 
-                       x86_64_mov_imm_reg(cd, (u8) asm_handle_exception, REG_ITMP3);
+                       M_MOV(REG_SP, rd->argintregs[0]);
+                       M_AADD_IMM(2 * 8, rd->argintregs[0]);
+                       x86_64_mov_imm_reg(cd, (ptrint) stacktrace_remove_stackframeinfo,
+                                                          REG_ITMP3);
+                       x86_64_call_reg(cd, REG_ITMP3);
+
+                       M_ALD(REG_ITMP1_XPTR, REG_SP, 0 * 8);
+                       M_ALD(REG_ITMP2_XPC, REG_SP, 1 * 8);
+                       M_AADD_IMM(2 * 8 + sizeof(stackframeinfo), REG_SP);
+
+                       x86_64_mov_imm_reg(cd, (ptrint) asm_handle_exception, REG_ITMP3);
                        x86_64_jmp_reg(cd, REG_ITMP3);
                }
        }
 
-       /* generate NullpointerException stubs */
+       /* generate ICMD_CHECKEXCEPTION stubs */
 
        xcodeptr = NULL;
        
-       for (bref = cd->xnullrefs; bref != NULL; bref = bref->next) {
+       for (bref = cd->xexceptionrefs; bref != NULL; bref = bref->next) {
                if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) {
                        gen_resolvebranch(cd->mcodebase + bref->branchpos, 
                                                          bref->branchpos,
-                                                         xcodeptr - cd->mcodebase - (10 + 10 + 3));
+                                                         xcodeptr - cd->mcodebase - (10 + 7));
                        continue;
                }
 
@@ -4030,8 +4200,7 @@ gen_method:
 
                x86_64_mov_imm_reg(cd, 0, REG_ITMP2_XPC);                 /* 10 bytes */
                dseg_adddata(cd, cd->mcodeptr);
-               x86_64_mov_imm_reg(cd, bref->branchpos - 6, REG_ITMP1);   /* 10 bytes */
-               M_AADD(REG_ITMP1, REG_ITMP2_XPC);                         /* 3 bytes  */
+               M_AADD_IMM32(bref->branchpos - 6, REG_ITMP2_XPC);         /* 7 bytes  */
 
                if (xcodeptr != NULL) {
                        x86_64_jmp_imm(cd, xcodeptr - cd->mcodeptr - 5);
@@ -4039,26 +4208,57 @@ gen_method:
                } else {
                        xcodeptr = cd->mcodeptr;
 
-                       /*create stackinfo -- begin*/
-                       x86_64_alu_imm_reg(cd, X86_64_SUB, 4 * 8, REG_SP);
-                       x86_64_mov_reg_membase(cd, REG_ITMP2_XPC, REG_SP, 3 * 8);
-                       x86_64_mov_imm_membase(cd,0,REG_SP,2*8);
-                       x86_64_mov_imm_membase(cd,0,REG_SP,1*8);
-                       x86_64_mov_imm_reg(cd,(ptrint)asm_prepare_native_stackinfo,REG_ITMP3);
-                       x86_64_call_reg(cd,REG_ITMP3);
-                       /*create stackinfo -- end*/
+                       M_ASUB_IMM(2 * 8 + sizeof(stackframeinfo), REG_SP);
+                       M_AST(REG_ITMP2_XPC, REG_SP, 1 * 8);
+
+                       /* create stackframe info */
+
+                       M_MOV(REG_SP, rd->argintregs[0]);
+                       M_AADD_IMM(2 * 8, rd->argintregs[0]);
 
+                       x86_64_lea_membase_reg(cd, RIP, -(((ptrint) cd->mcodeptr + 7) - (ptrint) cd->mcodebase), rd->argintregs[1]);
 
-                       x86_64_mov_imm_reg(cd, (ptrint) new_nullpointerexception, REG_ITMP3);
+                       M_MOV(REG_SP, rd->argintregs[2]);
+                       M_AADD_IMM(2 * 8 + sizeof(stackframeinfo), rd->argintregs[2]);
+                       M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
+                       x86_64_mov_imm_reg(cd, (ptrint) stacktrace_create_inline_stackframeinfo,
+                                                          REG_ITMP3);
                        x86_64_call_reg(cd, REG_ITMP3);
 
-                       /*remove stackinfo -- begin*/
-                       x86_64_mov_imm_reg(cd,(ptrint)asm_remove_native_stackinfo,REG_ITMP3);
-                       x86_64_call_reg(cd,REG_ITMP3);
-                       /*remove stackinfo -- end*/
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+                       x86_64_mov_imm_reg(cd, (ptrint) &builtin_get_exceptionptrptr,
+                                                          REG_ITMP1);
+                       x86_64_call_reg(cd, REG_ITMP1);
 
-                       x86_64_mov_membase_reg(cd, REG_SP, 1 * 8, REG_ITMP2_XPC);
-                       x86_64_alu_imm_reg(cd, X86_64_ADD, 2 * 8, REG_SP);
+                       M_ALD(REG_ITMP3, REG_RESULT, 0);
+                       x86_64_mov_imm_membase(cd, 0, REG_RESULT, 0);
+                       M_MOV(REG_ITMP3, REG_ITMP1_XPTR);
+#else
+                       x86_64_mov_imm_reg(cd, (ptrint) &_exceptionptr, REG_ITMP3);
+                       M_ALD(REG_ITMP1_XPTR, REG_ITMP3, 0);
+                       x86_64_mov_imm_membase(cd, 0, REG_ITMP3, 0);
+#endif
+
+                       M_AST(REG_ITMP1_XPTR, REG_SP, 0 * 8);
+
+                       /* call fillInStackTrace */
+
+                       M_MOV(REG_ITMP1_XPTR, rd->argintregs[0]);
+                       x86_64_mov_imm_reg(cd, (ptrint) stacktrace_call_fillInStackTrace,
+                                                          REG_ITMP3);
+                       x86_64_call_reg(cd, REG_ITMP3);
+
+                       /* removed stackframe info */
+
+                       M_MOV(REG_SP, rd->argintregs[0]);
+                       M_AADD_IMM(2 * 8, rd->argintregs[0]);
+                       x86_64_mov_imm_reg(cd, (ptrint) stacktrace_remove_stackframeinfo,
+                                                          REG_ITMP3);
+                       x86_64_call_reg(cd, REG_ITMP3);
+
+                       M_ALD(REG_ITMP1_XPTR, REG_SP, 0 * 8);
+                       M_ALD(REG_ITMP2_XPC, REG_SP, 1 * 8);
+                       M_AADD_IMM(2 * 8 + sizeof(stackframeinfo), REG_SP);
 
                        x86_64_mov_imm_reg(cd, (ptrint) asm_handle_exception, REG_ITMP3);
                        x86_64_jmp_reg(cd, REG_ITMP3);
@@ -4190,7 +4390,10 @@ functionptr createnativestub(functionptr f, methodinfo *m, codegendata *cd,
 
        /* calculate stack frame size */
 
-       stackframesize = 4 + INT_ARG_CNT + FLT_ARG_CNT + nmd->memuse;
+       stackframesize =
+               sizeof(stackframeinfo) / SIZEOF_VOID_P +
+               INT_ARG_CNT + FLT_ARG_CNT +
+               nmd->memuse;
 
        if (!(stackframesize & 0x1))                /* keep stack 16-byte aligned */
                stackframesize++;
@@ -4223,7 +4426,7 @@ functionptr createnativestub(functionptr f, methodinfo *m, codegendata *cd,
        if ((m->flags & ACC_STATIC) && !m->class->initialized) {
                codegen_addpatchref(cd, cd->mcodeptr, PATCHER_clinit, m->class);
 
-               if (showdisassemble) {
+               if (opt_showdisassemble) {
                        M_NOP; M_NOP; M_NOP; M_NOP; M_NOP;
                }
        }
@@ -4283,19 +4486,16 @@ functionptr createnativestub(functionptr f, methodinfo *m, codegendata *cd,
 
        /* create dynamic stack info */
 
-       x86_64_mov_imm_membase(cd, 0, REG_SP, (stackframesize - 1) * 8);
-       x86_64_mov_imm_reg(cd, (ptrint) m, REG_ITMP1);
-       M_AST(REG_ITMP1, REG_SP, (stackframesize - 2) * 8);
-       x86_64_mov_imm_reg(cd, (ptrint) builtin_asm_get_stackframeinfo, REG_ITMP1);
+       M_MOV(REG_SP, rd->argintregs[0]);
+       M_AADD_IMM(stackframesize * 8 - sizeof(stackframeinfo), rd->argintregs[0]);
+       x86_64_lea_membase_reg(cd, RIP, -(((ptrint) cd->mcodeptr + 7) - (ptrint) cd->mcodebase), rd->argintregs[1]);
+       M_MOV(REG_SP, rd->argintregs[2]);
+       M_AADD_IMM(stackframesize * 8 + SIZEOF_VOID_P, rd->argintregs[2]);
+       M_ALD(rd->argintregs[3], REG_SP, stackframesize * 8);
+       x86_64_mov_imm_reg(cd, (ptrint) stacktrace_create_native_stackframeinfo,
+                                          REG_ITMP1);
        x86_64_call_reg(cd, REG_ITMP1);
-
-       M_AST(REG_RESULT, REG_SP, (stackframesize - 3) * 8);
-       M_ALD(REG_ITMP2, REG_RESULT, 0);
-       M_AST(REG_ITMP2, REG_SP, (stackframesize - 4) * 8);
-       M_MOV(REG_SP, REG_ITMP2);
-       M_AADD_IMM((stackframesize - 4) * 8, REG_ITMP2);
-       M_AST(REG_ITMP2, REG_RESULT, 0);
-
+       
        STATS({
                x86_64_mov_imm_reg(cd, (ptrint) nativeinvokation, REG_ITMP1);
                x86_64_call_reg(cd, REG_ITMP1);
@@ -4365,7 +4565,7 @@ functionptr createnativestub(functionptr f, methodinfo *m, codegendata *cd,
        if (f == NULL) {
                codegen_addpatchref(cd, cd->mcodeptr, PATCHER_resolve_native, m);
 
-               if (showdisassemble) {
+               if (opt_showdisassemble) {
                        M_NOP; M_NOP; M_NOP; M_NOP; M_NOP;
                }
        }
@@ -4375,11 +4575,23 @@ functionptr createnativestub(functionptr f, methodinfo *m, codegendata *cd,
        x86_64_call_reg(cd, REG_ITMP1);
 
 
-       /* remove dynamic stack info */
+       /* remove native stackframe info */
 
-       M_LLD(REG_ITMP2, REG_SP, (stackframesize - 4) * 8);
-       M_LLD(REG_ITMP3, REG_SP, (stackframesize - 3) * 8);
-       M_LST(REG_ITMP2, REG_ITMP3, 0);
+       if (IS_INT_LNG_TYPE(md->returntype.type))
+               M_LST(REG_RESULT, REG_SP, 0 * 8);
+       else
+               M_DST(REG_FRESULT, REG_SP, 0 * 8);
+
+       M_MOV(REG_SP, rd->argintregs[0]);
+       M_AADD_IMM(stackframesize * 8 - sizeof(stackframeinfo), rd->argintregs[0]);
+       x86_64_mov_imm_reg(cd, (ptrint) stacktrace_remove_stackframeinfo,
+                                          REG_ITMP1);
+       x86_64_call_reg(cd, REG_ITMP1);
+
+       if (IS_INT_LNG_TYPE(md->returntype.type))
+               M_LLD(REG_RESULT, REG_SP, 0 * 8);
+       else
+               M_DLD(REG_FRESULT, REG_SP, 0 * 8);
 
 
        /* generate call trace */
index 2bcbaf2f345552779f8e376cbe9838c9b8d1fcb8..6642807aeb1e19e8e68c8638fe83d71131f1d6b5 100644 (file)
@@ -28,7 +28,7 @@
             Christian Thalinger
 
 
-   $Id: codegen.h 2876 2005-06-30 09:18:02Z twisti $
+   $Id: codegen.h 2956 2005-07-09 14:04:34Z twisti $
 
 */
 
@@ -437,6 +437,13 @@ typedef enum {
 #define M_AADD_IMM(a,b)         M_LADD_IMM(a,b)
 #define M_ASUB_IMM(a,b)         M_LSUB_IMM(a,b)
 
+#define M_LADD_IMM32(a,b)       x86_64_alu_imm32_reg(cd, X86_64_ADD, (a), (b))
+#define M_AADD_IMM32(a,b)       M_LADD_IMM32(a,b)
+
+#define M_TEST(a)               x86_64_test_reg_reg(cd, (a), (a))
+
+#define M_BEQ(disp)             x86_64_jcc(cd, X86_64_CC_E, (disp))
+
 #define M_RET                   x86_64_ret(cd)
 
 #define M_NOP                   x86_64_nop(cd)
index b1190bd4ed0ed121344b2aaf36d086de29de5704..0ba8963061406aa8f95192025f9da02c9fb29a5e 100644 (file)
@@ -28,7 +28,7 @@
 
    Changes:
 
-   $Id: md-asm.h 2588 2005-06-08 10:58:04Z twisti $
+   $Id: md-asm.h 2956 2005-07-09 14:04:34Z twisti $
 
 */
 
@@ -58,6 +58,8 @@
 #define fa6      %xmm6
 #define fa7      %xmm7
 
+#define sp       %rsp
+
 #define itmp1    %rax
 #define itmp2    %r10
 #define itmp3    %r11
index a1ee444741c186bdf0e792d79def0b2b3343a0c1..d07fcb74e01ea323e559f32ca94de43670aaafcc 100644 (file)
@@ -28,7 +28,7 @@
 
    Changes:
 
-   $Id: md.c 2914 2005-07-05 13:39:44Z twisti $
+   $Id: md.c 2956 2005-07-09 14:04:34Z twisti $
 
 */
 
@@ -41,6 +41,7 @@
 #include "config.h"
 #include "vm/jit/x86_64/md-abi.h"
 
+#include "vm/exceptions.h"
 #include "vm/options.h"
 #include "vm/stringlocal.h"
 #include "vm/jit/asmpart.h"
@@ -66,15 +67,40 @@ void md_init(void)
 
 void signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
 {
-       ucontext_t *_uc;
-       mcontext_t *_mc;
+       ucontext_t     *_uc;
+       mcontext_t     *_mc;
+       stackframeinfo *sfi;
+       u1             *pv;
+       u1             *sp;
+       functionptr     ra;
 
        _uc = (ucontext_t *) _p;
        _mc = &_uc->uc_mcontext;
 
-       _mc->gregs[REG_RAX] = (ptrint) string_java_lang_NullPointerException;
-       _mc->gregs[REG_R10] = _mc->gregs[REG_RIP];           /* REG_ITMP2_XPC     */
-       _mc->gregs[REG_RIP] = (ptrint) asm_throw_and_handle_exception;
+       /* allocate stackframeinfo on heap */
+
+       sfi = NEW(stackframeinfo);
+
+       /* create exception */
+
+       /* ATTENTION: don't use CACAO internal REG_* defines as they are          */
+       /* different to the ones in <ucontext.h>                                  */
+
+       sp = (u1 *) _mc->gregs[REG_RSP];
+       ra = (functionptr) _mc->gregs[REG_RIP];
+
+       pv = (u1 *) codegen_findmethod(ra);
+
+       stacktrace_create_inline_stackframeinfo(sfi, pv, sp, ra);
+
+       _mc->gregs[REG_RAX] = (ptrint) new_nullpointerexception();
+
+       stacktrace_remove_stackframeinfo(sfi);
+
+       FREE(sfi, stackframeinfo);
+
+       _mc->gregs[REG_R10] = _mc->gregs[REG_RIP];               /* REG_ITMP2_XPC */
+       _mc->gregs[REG_RIP] = (ptrint) asm_handle_exception;
 }
 
 
@@ -86,15 +112,40 @@ void signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
 
 void signal_handler_sigfpe(int sig, siginfo_t *siginfo, void *_p)
 {
-       ucontext_t *_uc;
-       mcontext_t *_mc;
+       ucontext_t     *_uc;
+       mcontext_t     *_mc;
+       stackframeinfo *sfi;
+       u1             *pv;
+       u1             *sp;
+       functionptr     ra;
 
        _uc = (ucontext_t *) _p;
        _mc = &_uc->uc_mcontext;
 
-       _mc->gregs[REG_R10] = _mc->gregs[REG_RIP];           /* REG_ITMP2_XPC     */
-       _mc->gregs[REG_RIP] =
-               (ptrint) asm_throw_and_handle_hardware_arithmetic_exception;
+       /* allocate stackframeinfo on heap */
+
+       sfi = NEW(stackframeinfo);
+
+       /* create exception */
+
+       /* ATTENTION: don't use CACAO internal REG_* defines as they are          */
+       /* different to the ones in <ucontext.h>                                  */
+
+       sp = (u1 *) _mc->gregs[REG_RSP];
+       ra = (functionptr) _mc->gregs[REG_RIP];
+
+       pv = (u1 *) codegen_findmethod(ra);
+
+       stacktrace_create_inline_stackframeinfo(sfi, pv, sp, ra);
+
+       _mc->gregs[REG_RAX] = (ptrint) new_arithmeticexception();
+
+       stacktrace_remove_stackframeinfo(sfi);
+
+       FREE(sfi, stackframeinfo);
+
+       _mc->gregs[REG_R10] = _mc->gregs[REG_RIP];               /* REG_ITMP2_XPC */
+       _mc->gregs[REG_RIP] = (ptrint) asm_handle_exception;
 }
 
 
index a0415d8504058ac177bca7365780f8b83fad9d6b..64ddb28fee7ae9f4a888ea0f931243f0ee86fc1d 100644 (file)
@@ -28,7 +28,7 @@
 
    Changes:
 
-   $Id: patcher.c 2779 2005-06-22 10:28:54Z twisti $
+   $Id: patcher.c 2956 2005-07-09 14:04:34Z twisti $
 
 */
 
 #include "vm/jit/patcher.h"
 
 
-bool helper_initialize_class(void* beginOfJavaStack,classinfo *c,u1 *ra)
-{
-       if (!c->initialized) {
-               native_stackframeinfo sfi;
-               bool init;
-
-               /* more or less the same as the above sfi setup is done in the assembler code by the prepare/remove functions*/
-               sfi.returnToFromNative = (functionptr) (ptrint) ra;
-               sfi.beginOfJavaStackframe = beginOfJavaStack;
-               sfi.method = NULL; /*internal*/
-               sfi.addressOfThreadspecificHead = builtin_asm_get_stackframeinfo();
-               sfi.oldThreadspecificHeadValue = *(sfi.addressOfThreadspecificHead);
-               *(sfi.addressOfThreadspecificHead) = &sfi;
-
-               /*printf("calling static initializer (helper_initialize_class), returnaddress=%p for class %s\n",ra,c->name->text);*/
-
-               init=initialize_class(c);
-
-               *(sfi.addressOfThreadspecificHead) = sfi.oldThreadspecificHeadValue;
-
-               return init;
-       }
-
-       return true;
-}
-
-
-
 /* patcher_get_putstatic *******************************************************
 
    Machine code:
@@ -93,7 +65,6 @@ bool patcher_get_putstatic(u1 *sp)
        unresolved_field  *uf;
        fieldinfo         *fi;
        s4                 offset;
-       void              *beginJavaStack;
 
        /* get stuff from the stack */
 
@@ -102,8 +73,6 @@ bool patcher_get_putstatic(u1 *sp)
        mcode =                       *((u8 *)     (sp + 1 * 8));
        uf    = (unresolved_field *)  *((ptrint *) (sp + 0 * 8));
 
-       beginJavaStack=              (void*)(sp + 3 * 8);
-
        /* calculate and set the new return address */
 
        ra = ra - 5;
@@ -121,7 +90,7 @@ bool patcher_get_putstatic(u1 *sp)
 
        /* check if the field's class is initialized */
 
-       if (!helper_initialize_class(beginJavaStack, fi->class, ra + 5)) {
+       if (!initialize_class(fi->class)) {
                PATCHER_MONITOREXIT;
 
                return false;
@@ -133,7 +102,7 @@ bool patcher_get_putstatic(u1 *sp)
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 5;
 
        /* get RIP offset from machine instruction */
@@ -197,7 +166,7 @@ bool patcher_get_putfield(u1 *sp)
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 5;
 
        /* patch the field's offset: we check for the field type, because the     */
@@ -275,7 +244,7 @@ bool patcher_putfieldconst(u1 *sp)
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 5;
 
        /* patch the field's offset */
@@ -325,14 +294,13 @@ bool patcher_builtin_new(u1 *sp)
        u8                 mcode;
        constant_classref *cr;
        classinfo         *c;
-       void              *beginJavaStack;
+
        /* get stuff from the stack */
 
        ra    = (u1 *)                *((ptrint *) (sp + 3 * 8));
        o     = (java_objectheader *) *((ptrint *) (sp + 2 * 8));
        mcode =                       *((u8 *)     (sp + 1 * 8));
        cr    = (constant_classref *) *((ptrint *) (sp + 0 * 8));
-       beginJavaStack =              (void*) (sp+3*8);
 
        /* calculate and set the new return address */
 
@@ -349,7 +317,7 @@ bool patcher_builtin_new(u1 *sp)
                return false;
        }
 
-       if (!helper_initialize_class(beginJavaStack, c, ra + 5)) {
+       if (!initialize_class(c)) {
                PATCHER_MONITOREXIT;
 
                return false;
@@ -365,7 +333,7 @@ bool patcher_builtin_new(u1 *sp)
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 5;
 
        /* patch new function address */
@@ -429,7 +397,7 @@ bool patcher_builtin_newarray(u1 *sp)
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 5;
 
        /* patch new function address */
@@ -491,7 +459,7 @@ bool patcher_builtin_multianewarray(u1 *sp)
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 5;
 
        /* patch the class' vftbl pointer */
@@ -512,8 +480,8 @@ bool patcher_builtin_multianewarray(u1 *sp)
 
    Machine code:
 
-   48 be b8 3f b2 00 00 00 00 00    mov    $0xb23fb8,%rsi
    <patched call position>
+   48 be b8 3f b2 00 00 00 00 00    mov    $0xb23fb8,%rsi
    48 b8 00 00 00 00 00 00 00 00    mov    $0x0,%rax
    48 ff d0                         callq  *%rax
 
@@ -536,7 +504,7 @@ bool patcher_builtin_arraycheckcast(u1 *sp)
 
        /* calculate and set the new return address */
 
-       ra = ra - (10 + 5);
+       ra = ra - 5;
        *((ptrint *) (sp + 3 * 8)) = (ptrint) ra;
 
        PATCHER_MONITORENTER;
@@ -551,17 +519,17 @@ bool patcher_builtin_arraycheckcast(u1 *sp)
 
        /* patch back original code */
 
-       *((u8 *) (ra + 10)) = mcode;
-
-       /* patch the class' vftbl pointer */
-
-       *((ptrint *) (ra + 2)) = (ptrint) c->vftbl;
+       *((u8 *) ra) = mcode;
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 5;
 
+       /* patch the class' vftbl pointer */
+
+       *((ptrint *) (ra + 2)) = (ptrint) c->vftbl;
+
        /* patch new function address */
 
        *((ptrint *) (ra + 10 + 2)) = (ptrint) BUILTIN_arraycheckcast;
@@ -623,7 +591,7 @@ bool patcher_builtin_arrayinstanceof(u1 *sp)
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 5;
 
        /* patch new function address */
@@ -681,7 +649,7 @@ bool patcher_invokestatic_special(u1 *sp)
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 5;
 
        /* patch stubroutine */
@@ -741,7 +709,7 @@ bool patcher_invokevirtual(u1 *sp)
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 5;
 
        /* patch vftbl index */
@@ -803,7 +771,7 @@ bool patcher_invokeinterface(u1 *sp)
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 5;
 
        /* patch interfacetable index */
@@ -869,7 +837,7 @@ bool patcher_checkcast_instanceof_flags(u1 *sp)
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 5;
 
        /* patch class flags */
@@ -931,7 +899,7 @@ bool patcher_checkcast_instanceof_interface(u1 *sp)
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 5;
 
        /* patch super class index */
@@ -997,7 +965,7 @@ bool patcher_checkcast_class(u1 *sp)
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 5;
 
        /* patch super class' vftbl */
@@ -1056,7 +1024,7 @@ bool patcher_instanceof_class(u1 *sp)
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 5;
 
        /* patch super class' vftbl */
@@ -1087,7 +1055,6 @@ bool patcher_clinit(u1 *sp)
        java_objectheader *o;
        u8                 mcode;
        classinfo         *c;
-       void              *beginJavaStack;
 
        /* get stuff from the stack */
 
@@ -1096,8 +1063,6 @@ bool patcher_clinit(u1 *sp)
        mcode =                       *((u8 *)     (sp + 1 * 8));
        c     = (classinfo *)         *((ptrint *) (sp + 0 * 8));
 
-       beginJavaStack =      (void*) (sp + 3 * 8);
-
        /* calculate and set the new return address */
 
        ra = ra - 5;
@@ -1107,7 +1072,7 @@ bool patcher_clinit(u1 *sp)
 
        /* check if the class is initialized */
 
-       if (!helper_initialize_class(beginJavaStack, c, ra + 5)) {
+       if (!initialize_class(c)) {
                PATCHER_MONITOREXIT;
 
                return false;
@@ -1133,6 +1098,7 @@ bool patcher_clinit(u1 *sp)
 
 *******************************************************************************/
 
+#if !defined(ENABLE_STATICVM)
 bool patcher_resolve_native(u1 *sp)
 {
        u1                *ra;
@@ -1140,7 +1106,6 @@ bool patcher_resolve_native(u1 *sp)
        u8                 mcode;
        methodinfo        *m;
        functionptr        f;
-       void              *beginJavaStack;
 
        /* get stuff from the stack */
 
@@ -1149,8 +1114,6 @@ bool patcher_resolve_native(u1 *sp)
        mcode =                       *((u8 *)     (sp + 1 * 8));
        m     = (methodinfo *)        *((ptrint *) (sp + 0 * 8));
 
-       beginJavaStack =      (void*) (sp + 3 * 8);
-
        /* calculate and set the new return address */
 
        ra = ra - 5;
@@ -1172,7 +1135,7 @@ bool patcher_resolve_native(u1 *sp)
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 5;
 
        /* patch native function pointer */
@@ -1183,6 +1146,7 @@ bool patcher_resolve_native(u1 *sp)
 
        return true;
 }
+#endif /* !defined(ENABLE_STATICVM) */
 
 
 /*