- all patcher use the same wrapper and thus the same passing conventions
authortwisti <none@none>
Tue, 26 Apr 2005 19:49:15 +0000 (19:49 +0000)
committertwisti <none@none>
Tue, 26 Apr 2005 19:49:15 +0000 (19:49 +0000)
- skip nop's with showdisassemble

src/vm/jit/x86_64/patcher.c

index 1b599291f49ce6b6891ebe92c6be31853a79b5f4..87f303362b0f8f1bc7395b2467fad24d809df74c 100644 (file)
@@ -28,7 +28,7 @@
 
    Changes:
 
-   $Id: patcher.c 2360 2005-04-24 13:07:57Z jowenn $
+   $Id: patcher.c 2391 2005-04-26 19:49:15Z twisti $
 
 */
 
 #include "vm/builtin.h"
 #include "vm/field.h"
 #include "vm/initialize.h"
+#include "vm/options.h"
 #include "vm/references.h"
 #include "vm/jit/helper.h"
 #include "vm/exceptions.h"
 
+
 /* patcher_get_putstatic *******************************************************
 
    XXX
@@ -116,6 +118,11 @@ bool patcher_get_putstatic(u1 *sp)
 
        *((u8 *) ra) = mcode;
 
+       /* if we show disassembly, we have to skip the nop's */
+
+       if (showdisassemble)
+               ra = ra + 5;
+
        /* get RIP offset from machine instruction */
 
        ripoffset = *((u4 *) (ra + 3));
@@ -134,8 +141,6 @@ bool patcher_get_putstatic(u1 *sp)
 
 /* patcher_get_putfield ********************************************************
 
-   XXX
-
    Machine code:
 
    45 8b 8f 00 00 00 00             mov    0x0(%r15),%r9d
@@ -175,6 +180,11 @@ bool patcher_get_putfield(u1 *sp)
 
        *((u8 *) ra) = mcode;
 
+       /* if we show disassembly, we have to skip the nop's */
+
+       if (showdisassemble)
+               ra = ra + 5;
+
        /* patch the field's offset: we check for the field type, because the     */
        /* instructions have different lengths                                    */
 
@@ -201,25 +211,32 @@ bool patcher_get_putfield(u1 *sp)
 
 /* patcher_builtin_new *********************************************************
 
-   XXX
-
    Machine code:
 
+   48 bf a0 f0 92 00 00 00 00 00    mov    $0x92f0a0,%rdi
+   <patched call position>
+   48 b8 00 00 00 00 00 00 00 00    mov    $0x0,%rax
+   48 ff d0                         callq  *%rax
+
 *******************************************************************************/
 
-bool patcher_builtin_new(constant_classref *cr, u1 *sp)
+bool patcher_builtin_new(u1 *sp)
 {
        u1                *ra;
+       u8                 mcode;
+       constant_classref *cr;
        classinfo         *c;
 
        /* get stuff from the stack */
 
-       ra = (u1 *)                *((ptrint *) (sp + 0 * 8));
+       ra    = (u1 *)                *((ptrint *) (sp + 2 * 8));
+       mcode =                       *((u8 *)     (sp + 1 * 8));
+       cr    = (constant_classref *) *((ptrint *) (sp + 0 * 8));
 
        /* calculate and set the new return address */
 
-       ra = ra - (10 + 10 + 3);
-       *((ptrint *) (sp + 0 * 8)) = (ptrint) ra;
+       ra = ra - (10 + 5);
+       *((ptrint *) (sp + 2 * 8)) = (ptrint) ra;
 
        *dontfillinexceptionstacktrace=true;
 
@@ -231,10 +248,19 @@ bool patcher_builtin_new(constant_classref *cr, u1 *sp)
                return false;
        }
 
+       /* patch back original code */
+
+       *((u8 *) (ra + 10)) = mcode;
+
        /* patch the classinfo pointer */
 
        *((ptrint *) (ra + 2)) = (ptrint) c;
 
+       /* if we show disassembly, we have to skip the nop's */
+
+       if (showdisassemble)
+               ra = ra + 5;
+
        /* patch new function address */
 
        *((ptrint *) (ra + 10 + 2)) = (ptrint) BUILTIN_new;
@@ -246,41 +272,55 @@ bool patcher_builtin_new(constant_classref *cr, u1 *sp)
 
 /* patcher_builtin_newarray ****************************************************
 
-   XXX
-
    Machine code:
 
+   48 be 88 13 9b 00 00 00 00 00    mov    $0x9b1388,%rsi
+   <patched call position>
+   48 b8 00 00 00 00 00 00 00 00    mov    $0x0,%rax
+   48 ff d0                         callq  *%rax
+
 *******************************************************************************/
 
-bool patcher_builtin_newarray(u1 *sp, constant_classref *cr)
+bool patcher_builtin_newarray(u1 *sp)
 {
        u1                *ra;
+       u8                 mcode;
+       constant_classref *cr;
        classinfo         *c;
 
        /* get stuff from the stack */
 
-       ra = (u1 *) *((ptrint *) (sp + 0 * 8));
+       ra    = (u1 *)                *((ptrint *) (sp + 2 * 8));
+       mcode =                       *((u8 *)     (sp + 1 * 8));
+       cr    = (constant_classref *) *((ptrint *) (sp + 0 * 8));
 
        /* calculate and set the new return address */
 
-       ra = ra - (10 + 10 + 3);
-       *((ptrint *) (sp + 0 * 8)) = (ptrint) ra;
-
+       ra = ra - (10 + 5);
+       *((ptrint *) (sp + 2 * 8)) = (ptrint) ra;
 
        *dontfillinexceptionstacktrace=true;
 
-
        /* get the classinfo */
 
-       if (!(c = helper_resolve_classinfo(cr)))
-       {
+       if (!(c = helper_resolve_classinfo(cr))) {
                *dontfillinexceptionstacktrace=false;
                return false;
        }
+
+       /* patch back original code */
+
+       *((u8 *) (ra + 10)) = mcode;
+
        /* patch the class' vftbl pointer */
 
        *((ptrint *) (ra + 2)) = (ptrint) c->vftbl;
 
+       /* if we show disassembly, we have to skip the nop's */
+
+       if (showdisassemble)
+               ra = ra + 5;
+
        /* patch new function address */
 
        *((ptrint *) (ra + 10 + 2)) = (ptrint) BUILTIN_newarray;
@@ -292,25 +332,34 @@ bool patcher_builtin_newarray(u1 *sp, constant_classref *cr)
 
 /* patcher_builtin_multianewarray **********************************************
 
-   XXX
-
    Machine code:
 
+   <patched call position>
+   48 bf 02 00 00 00 00 00 00 00    mov    $0x2,%rdi
+   48 be 30 40 b2 00 00 00 00 00    mov    $0xb24030,%rsi
+   48 89 e2                         mov    %rsp,%rdx
+   48 b8 7c 96 4b 00 00 00 00 00    mov    $0x4b967c,%rax
+   48 ff d0                         callq  *%rax
+
 *******************************************************************************/
 
-bool patcher_builtin_multianewarray(u1 *sp, constant_classref *cr)
+bool patcher_builtin_multianewarray(u1 *sp)
 {
        u1                *ra;
+       u8                 mcode;
+       constant_classref *cr;
        classinfo         *c;
 
        /* get stuff from the stack */
 
-       ra = (u1 *) *((ptrint *) (sp + 0 * 8));
+       ra    = (u1 *)                *((ptrint *) (sp + 2 * 8));
+       mcode =                       *((u8 *)     (sp + 1 * 8));
+       cr    = (constant_classref *) *((ptrint *) (sp + 0 * 8));
 
        /* calculate and set the new return address */
 
-       ra = ra - (10 + 10 + 3 + 10 + 3);
-       *((ptrint *) (sp + 0 * 8)) = (ptrint) ra;
+       ra = ra - 5;
+       *((ptrint *) (sp + 2 * 8)) = (ptrint) ra;
 
        *dontfillinexceptionstacktrace=true;
 
@@ -320,6 +369,16 @@ bool patcher_builtin_multianewarray(u1 *sp, constant_classref *cr)
                *dontfillinexceptionstacktrace=false;
                return false;
        }
+
+       /* patch back original code */
+
+       *((u8 *) ra) = mcode;
+
+       /* if we show disassembly, we have to skip the nop's */
+
+       if (showdisassemble)
+               ra = ra + 5;
+
        /* patch the class' vftbl pointer */
 
        *((ptrint *) (ra + 10 + 2)) = (ptrint) c->vftbl;
@@ -335,36 +394,51 @@ bool patcher_builtin_multianewarray(u1 *sp, constant_classref *cr)
 
 /* patcher_builtin_checkarraycast **********************************************
 
-   XXX
-
    Machine code:
 
+   48 be b8 3f b2 00 00 00 00 00    mov    $0xb23fb8,%rsi
+   <patched call position>
+   48 b8 00 00 00 00 00 00 00 00    mov    $0x0,%rax
+   48 ff d0                         callq  *%rax
+
 *******************************************************************************/
 
-bool patcher_builtin_checkarraycast(u1 *sp, constant_classref *cr)
+bool patcher_builtin_checkarraycast(u1 *sp)
 {
        u1                *ra;
+       u8                 mcode;
+       constant_classref *cr;
        classinfo         *c;
 
        /* get stuff from the stack */
 
-       ra = (u1 *) *((ptrint *) (sp + 0 * 8));
+       ra    = (u1 *)                *((ptrint *) (sp + 2 * 8));
+       mcode =                       *((u8 *)     (sp + 1 * 8));
+       cr    = (constant_classref *) *((ptrint *) (sp + 0 * 8));
 
        /* calculate and set the new return address */
 
-       ra = ra - (10 + 10 + 3);
-       *((ptrint *) (sp + 0 * 8)) = (ptrint) ra;
+       ra = ra - (10 + 5);
+       *((ptrint *) (sp + 2 * 8)) = (ptrint) ra;
 
        *dontfillinexceptionstacktrace=true;
 
        /* get the classinfo */
 
-       if (!(c = helper_resolve_classinfo(cr)))
-       {
+       if (!(c = helper_resolve_classinfo(cr))) {
                *dontfillinexceptionstacktrace=false;
                return false;
        }
 
+       /* patch back original code */
+
+       *((u8 *) (ra + 10)) = mcode;
+
+       /* if we show disassembly, we have to skip the nop's */
+
+       if (showdisassemble)
+               ra = ra + 5;
+
        /* patch the class' vftbl pointer */
 
        *((ptrint *) (ra + 2)) = (ptrint) c->vftbl;
@@ -380,38 +454,51 @@ bool patcher_builtin_checkarraycast(u1 *sp, constant_classref *cr)
 
 /* patcher_builtin_arrayinstanceof *********************************************
 
-   XXX
-
    Machine code:
 
+   48 be 30 3c b2 00 00 00 00 00    mov    $0xb23c30,%rsi
+   <patched call position>
+   48 b8 00 00 00 00 00 00 00 00    mov    $0x0,%rax
+   48 ff d0                         callq  *%rax
+
 *******************************************************************************/
 
-bool patcher_builtin_arrayinstanceof(u1 *sp, constant_classref *cr)
+bool patcher_builtin_arrayinstanceof(u1 *sp)
 {
        u1                *ra;
+       u8                 mcode;
+       constant_classref *cr;
        classinfo         *c;
 
        /* get stuff from the stack */
 
-       ra = (u1 *) *((ptrint *) (sp + 0 * 8));
+       ra    = (u1 *)                *((ptrint *) (sp + 2 * 8));
+       mcode =                       *((u8 *)     (sp + 1 * 8));
+       cr    = (constant_classref *) *((ptrint *) (sp + 0 * 8));
 
        /* calculate and set the new return address */
 
-       ra = ra - (10 + 10 + 3);
-       *((ptrint *) (sp + 0 * 8)) = (ptrint) ra;
-
+       ra = ra - (10 + 5);
+       *((ptrint *) (sp + 2 * 8)) = (ptrint) ra;
 
        *dontfillinexceptionstacktrace=true;
 
-
        /* get the classinfo */
 
-       if (!(c = helper_resolve_classinfo(cr)))
-       {
+       if (!(c = helper_resolve_classinfo(cr))) {
                *dontfillinexceptionstacktrace=false;
                return false;
        }
 
+       /* patch back original code */
+
+       *((u8 *) (ra + 10)) = mcode;
+
+       /* if we show disassembly, we have to skip the nop's */
+
+       if (showdisassemble)
+               ra = ra + 5;
+
        /* patch the class' vftbl pointer */
 
        *((ptrint *) (ra + 2)) = (ptrint) c->vftbl;
@@ -463,6 +550,11 @@ bool patcher_invokestatic_special(u1 *sp)
 
        *((u8 *) ra) = mcode;
 
+       /* if we show disassembly, we have to skip the nop's */
+
+       if (showdisassemble)
+               ra = ra + 5;
+
        /* patch stubroutine */
 
        *((ptrint *) (ra + 2)) = (ptrint) m->stubroutine;
@@ -510,6 +602,11 @@ bool patcher_invokevirtual(u1 *sp)
 
        *((u8 *) ra) = mcode;
 
+       /* if we show disassembly, we have to skip the nop's */
+
+       if (showdisassemble)
+               ra = ra + 5;
+
        /* patch vftbl index */
 
        *((s4 *) (ra + 3 + 3)) = (s4) (OFFSET(vftbl_t, table[0]) +
@@ -558,6 +655,11 @@ bool patcher_invokeinterface(u1 *sp)
 
        *((u8 *) ra) = mcode;
 
+       /* if we show disassembly, we have to skip the nop's */
+
+       if (showdisassemble)
+               ra = ra + 5;
+
        /* patch interfacetable index */
 
        *((s4 *) (ra + 3 + 3)) = (s4) (OFFSET(vftbl_t, interfacetable[0]) -
@@ -601,15 +703,20 @@ bool patcher_checkcast_instanceof_flags(u1 *sp)
 
        /* get the fieldinfo */
 
-       if (!(c = helper_resolve_classinfo(cr)))
-       {
+       if (!(c = helper_resolve_classinfo(cr))) {
                *dontfillinexceptionstacktrace=false;
                return false;
        }
+
        /* patch back original code */
 
        *((u8 *) ra) = mcode;
 
+       /* if we show disassembly, we have to skip the nop's */
+
+       if (showdisassemble)
+               ra = ra + 5;
+
        /* patch class flags */
 
        *((s4 *) (ra + 2)) = (s4) c->flags;
@@ -643,13 +750,11 @@ bool patcher_checkcast_instanceof_interface(u1 *sp)
        ra = ra - 5;
        *((ptrint *) (sp + 2 * 8)) = (ptrint) ra;
 
-
        *dontfillinexceptionstacktrace=true;
 
        /* get the fieldinfo */
 
-       if (!(c = helper_resolve_classinfo(cr)))
-       {
+       if (!(c = helper_resolve_classinfo(cr))) {
                *dontfillinexceptionstacktrace=false;
                return false;
        }
@@ -658,6 +763,11 @@ bool patcher_checkcast_instanceof_interface(u1 *sp)
 
        *((u8 *) ra) = mcode;
 
+       /* if we show disassembly, we have to skip the nop's */
+
+       if (showdisassemble)
+               ra = ra + 5;
+
        /* patch super class index */
 
        *((s4 *) (ra + 7 + 3)) = (s4) c->index;
@@ -699,8 +809,7 @@ bool patcher_checkcast_class(u1 *sp)
 
        /* get the fieldinfo */
 
-       if (!(c = helper_resolve_classinfo(cr)))
-       {
+       if (!(c = helper_resolve_classinfo(cr))) {
                *dontfillinexceptionstacktrace=false;
                return false;
        }
@@ -709,6 +818,11 @@ bool patcher_checkcast_class(u1 *sp)
 
        *((u8 *) ra) = mcode;
 
+       /* if we show disassembly, we have to skip the nop's */
+
+       if (showdisassemble)
+               ra = ra + 5;
+
        /* patch super class' vftbl */
 
        *((ptrint *) (ra + 2)) = (ptrint) c->vftbl;
@@ -747,8 +861,7 @@ bool patcher_instanceof_class(u1 *sp)
 
        /* get the fieldinfo */
 
-       if (!(c = helper_resolve_classinfo(cr)))
-       {
+       if (!(c = helper_resolve_classinfo(cr))) {
                *dontfillinexceptionstacktrace=false;
                return false;
        }
@@ -757,6 +870,11 @@ bool patcher_instanceof_class(u1 *sp)
 
        *((u8 *) ra) = mcode;
 
+       /* if we show disassembly, we have to skip the nop's */
+
+       if (showdisassemble)
+               ra = ra + 5;
+
        /* patch super class' vftbl */
 
        *((ptrint *) (ra + 2)) = (ptrint) c->vftbl;
@@ -793,8 +911,7 @@ bool patcher_clinit(u1 *sp)
 
        /* check if the class is initialized */
 
-       if (!c->initialized)
-       {
+       if (!c->initialized) {
                bool init;
                {
                        /*struct native_stackframeinfo {