* Removed all Id tags.
[cacao.git] / src / vm / jit / i386 / patcher.c
index b92d8e3b6e665a0c1bc9dd07a3b99cf8c02c646b..42f138e1d63aab9d4d4e49c11b7bd3f219a872cd 100644 (file)
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: patcher.c 7464 2007-03-06 00:26:31Z edwin $
-
 */
 
 
 #include "config.h"
+
+#include <stdint.h>
+
 #include "vm/types.h"
 
 #include "vm/jit/i386/codegen.h"
 
 *******************************************************************************/
 
-java_objectheader *patcher_wrapper(u1 *sp, u1 *pv, u1 *ra)
+java_object_t *patcher_wrapper(u1 *sp, u1 *pv, u1 *ra)
 {
        stackframeinfo     sfi;
        u1                *xpc;
-       java_objectheader *o;
+       java_object_t     *o;
        functionptr        f;
        bool               result;
-       java_objectheader *e;
+       java_handle_t     *e;
 
        /* define the patcher function */
 
@@ -77,7 +78,7 @@ java_objectheader *patcher_wrapper(u1 *sp, u1 *pv, u1 *ra)
        /* get stuff from the stack */
 
        xpc = (u1 *)                *((ptrint *) (sp + 6 * 4));
-       o   = (java_objectheader *) *((ptrint *) (sp + 4 * 4));
+       o   = (java_object_t *)     *((ptrint *) (sp + 4 * 4));
        f   = (functionptr)         *((ptrint *) (sp + 0 * 4));
 
        /* calculate and set the new return address */
@@ -166,12 +167,12 @@ bool patcher_get_putstatic(u1 *sp)
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (opt_showdisassemble)
+       if (opt_shownops)
                ra = ra + 5;
 
        /* patch the field value's address */
 
-       *((ptrint *) (ra + 1)) = (ptrint) &(fi->value);
+       *((intptr_t *) (ra + 1)) = (intptr_t) fi->value;
 
        return true;
 }
@@ -211,7 +212,7 @@ bool patcher_getfield(u1 *sp)
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (opt_showdisassemble)
+       if (opt_shownops)
                ra = ra + 5;
 
        /* patch the field's offset */
@@ -261,7 +262,7 @@ bool patcher_putfield(u1 *sp)
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (opt_showdisassemble)
+       if (opt_shownops)
                ra = ra + 5;
 
        /* patch the field's offset */
@@ -318,7 +319,7 @@ bool patcher_putfieldconst(u1 *sp)
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (opt_showdisassemble)
+       if (opt_shownops)
                ra = ra + 5;
 
        /* patch the field's offset */
@@ -376,7 +377,7 @@ bool patcher_aconst(u1 *sp)
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (opt_showdisassemble)
+       if (opt_shownops)
                ra = ra + 5;
 
        /* patch the classinfo pointer */
@@ -427,18 +428,13 @@ bool patcher_builtin_multianewarray(u1 *sp)
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (opt_showdisassemble)
+       if (opt_shownops)
                ra = ra + 5;
 
        /* patch the classinfo pointer */
 
        *((ptrint *) (ra + 7 + 4)) = (ptrint) c;
 
-       /* patch new function address */
-
-       *((ptrint *) (ra + 7 + 8 + 2 + 3 + 4 + 1)) =
-               (ptrint) BUILTIN_multianewarray;
-
        return true;
 }
 
@@ -479,7 +475,7 @@ bool patcher_builtin_arraycheckcast(u1 *sp)
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (opt_showdisassemble)
+       if (opt_shownops)
                ra = ra + 5;
 
        /* patch the classinfo pointer */
@@ -529,7 +525,7 @@ bool patcher_invokestatic_special(u1 *sp)
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (opt_showdisassemble)
+       if (opt_shownops)
                ra = ra + 5;
 
        /* patch stubroutine */
@@ -576,7 +572,7 @@ bool patcher_invokevirtual(u1 *sp)
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (opt_showdisassemble)
+       if (opt_shownops)
                ra = ra + 5;
 
        /* patch vftbl index */
@@ -625,7 +621,7 @@ bool patcher_invokeinterface(u1 *sp)
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (opt_showdisassemble)
+       if (opt_shownops)
                ra = ra + 5;
 
        /* patch interfacetable index */
@@ -676,7 +672,7 @@ bool patcher_checkcast_instanceof_flags(u1 *sp)
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (opt_showdisassemble)
+       if (opt_shownops)
                ra = ra + 5;
 
        /* patch class flags */
@@ -687,7 +683,61 @@ bool patcher_checkcast_instanceof_flags(u1 *sp)
 }
 
 
-/* patcher_checkcast_instanceof_interface **************************************
+/* patcher_checkcast_interface *************************************************
+
+   Machine code:
+
+   <patched call position>
+   8b 91 00 00 00 00          mov    0x00000000(%ecx),%edx
+   81 ea 00 00 00 00          sub    $0x00000000,%edx
+   85 d2                      test   %edx,%edx
+   0f 8f 06 00 00 00          jg     0x00000000
+   8b 35 03 00 00 00          mov    0x3,%esi
+   8b 91 00 00 00 00          mov    0x00000000(%ecx),%edx
+
+*******************************************************************************/
+
+bool patcher_checkcast_interface(u1 *sp)
+{
+       u1                *ra;
+       u8                 mcode;
+       constant_classref *cr;
+       classinfo         *c;
+
+       /* get stuff from the stack */
+
+       ra    = (u1 *)                *((ptrint *) (sp + 6 * 4));
+       mcode =                       *((u8 *)     (sp + 2 * 4));
+       cr    = (constant_classref *) *((ptrint *) (sp + 1 * 4));
+
+       /* get the fieldinfo */
+
+       if (!(c = resolve_classref_eager(cr)))
+               return false;
+
+       /* patch back original code */
+
+       *((u4 *) (ra + 0)) = (u4) mcode;
+       *((u1 *) (ra + 4)) = (u1) (mcode >> 32);
+
+       /* if we show disassembly, we have to skip the nop's */
+
+       if (opt_shownops)
+               ra = ra + 5;
+
+       /* patch super class index */
+
+       *((s4 *) (ra + 6 + 2)) = (s4) c->index;
+
+       *((s4 *) (ra + 6 + 6 + 2 + 6 + 6 + 2)) =
+               (s4) (OFFSET(vftbl_t, interfacetable[0]) -
+                         c->index * sizeof(methodptr*));
+
+       return true;
+}
+
+
+/* patcher_instanceof_interface ************************************************
 
    Machine code:
 
@@ -695,12 +745,12 @@ bool patcher_checkcast_instanceof_flags(u1 *sp)
    8b 91 00 00 00 00          mov    0x00000000(%ecx),%edx
    81 ea 00 00 00 00          sub    $0x00000000,%edx
    85 d2                      test   %edx,%edx
-   0f 8e 00 00 00 00          jle    0x00000000
+   0f 8e 13 00 00 00          jle    0x00000000
    8b 91 00 00 00 00          mov    0x00000000(%ecx),%edx
 
 *******************************************************************************/
 
-bool patcher_checkcast_instanceof_interface(u1 *sp)
+bool patcher_instanceof_interface(u1 *sp)
 {
        u1                *ra;
        u8                 mcode;
@@ -725,7 +775,7 @@ bool patcher_checkcast_instanceof_interface(u1 *sp)
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (opt_showdisassemble)
+       if (opt_shownops)
                ra = ra + 5;
 
        /* patch super class index */
@@ -778,7 +828,7 @@ bool patcher_checkcast_class(u1 *sp)
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (opt_showdisassemble)
+       if (opt_shownops)
                ra = ra + 5;
 
        /* patch super class' vftbl */
@@ -827,7 +877,7 @@ bool patcher_instanceof_class(u1 *sp)
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (opt_showdisassemble)
+       if (opt_shownops)
                ra = ra + 5;
 
        /* patch super class' vftbl */
@@ -948,7 +998,7 @@ bool patcher_resolve_native(u1 *sp)
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (opt_showdisassemble)
+       if (opt_shownops)
                ra = ra + 5;
 
        /* patch native function pointer */