Merged changes from trunk.
[cacao.git] / src / vm / jit / mips / patcher.c
index 0f5660d190071b03e2cc6d1ba02c9ad9334d7f42..4d3634504c7837115f386fce70192839635b8c17 100644 (file)
@@ -1,9 +1,9 @@
 /* src/vm/jit/mips/patcher.c - MIPS code patching functions
 
-   Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
-   R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
-   C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
-   Institut f. Computersprachen - TU Wien
+   Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+   C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+   E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+   J. Wenninger, Institut f. Computersprachen - TU Wien
 
    This file is part of CACAO.
 
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA.
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
 
-   Contact: cacao@complang.tuwien.ac.at
+   Contact: cacao@cacaojvm.org
 
    Authors: Christian Thalinger
 
    Changes:
 
-   $Id: patcher.c 2708 2005-06-15 13:44:10Z twisti $
+   $Id: patcher.c 5319 2006-09-05 12:54:10Z twisti $
 
 */
 
 
 #include "config.h"
-#include "vm/jit/mips/types.h"
+
+#include <assert.h>
+
+#include "vm/types.h"
 
 #include "mm/memory.h"
 #include "native/native.h"
 #include "vm/builtin.h"
+#include "vm/class.h"
+#include "vm/exceptions.h"
 #include "vm/field.h"
 #include "vm/initialize.h"
 #include "vm/options.h"
+#include "vm/resolve.h"
 #include "vm/references.h"
 #include "vm/jit/asmpart.h"
-#include "vm/jit/helper.h"
 #include "vm/jit/patcher.h"
 
 
-/* patcher_get_putstatic *******************************************************
+/* patcher_wrapper *************************************************************
 
-   Machine code:
+   Wrapper for all patchers.  It also creates the stackframe info
+   structure.
 
-   <patched call position>
-   dfc1ffb8    ld       at,-72(s8)
-   fc250000    sd       a1,0(at)
+   If the return value of the patcher function is false, it gets the
+   exception object, clears the exception pointer and returns the
+   exception.
 
 *******************************************************************************/
 
-bool patcher_get_putstatic(u1 *sp)
+java_objectheader *patcher_wrapper(u1 *sp, u1 *pv, u1 *ra)
 {
-       u1                *ra;
+       stackframeinfo     sfi;
+       u1                *xpc;
        java_objectheader *o;
-       u8                 mcode;
-       unresolved_field  *uf;
-       u1                *pv;
-       fieldinfo         *fi;
-       s2                 offset;
+       functionptr        f;
+       bool               result;
+       java_objectheader *e;
 
-       /* get stuff from the stack */
+       /* define the patcher function */
 
-       ra    = (u1 *)                *((ptrint *) (sp + 3 * 8));
-       o     = (java_objectheader *) *((ptrint *) (sp + 2 * 8));
-       mcode =                       *((u8 *)     (sp + 1 * 8));
-       uf    = (unresolved_field *)  *((ptrint *) (sp + 0 * 8));
-       pv    = (u1 *)                *((ptrint *) (sp - 2 * 8));
+       bool (*patcher_function)(u1 *);
 
-       /* calculate and set the new return address */
+       assert(pv != NULL);
 
-       ra = ra - 2 * 4;
-       *((ptrint *) (sp + 3 * 8)) = (ptrint) ra;
+       /* get stuff from the stack */
 
-       PATCHER_MONITORENTER;
+       xpc = (u1 *)                *((ptrint *) (sp + 5 * 8));
+       o   = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
+       f   = (functionptr)         *((ptrint *) (sp + 0 * 8));
 
-       /* get the fieldinfo */
+       /* store PV into the patcher function position */
 
-       if (!(fi = helper_resolve_fieldinfo(uf))) {
-               PATCHER_MONITOREXIT;
+       *((ptrint *) (sp + 0 * 8)) = (ptrint) pv;
 
-               return false;
-       }
+       /* cast the passed function to a patcher function */
 
-       /* check if the field's class is initialized */
+       patcher_function = (bool (*)(u1 *)) (ptrint) f;
 
-       if (!fi->class->initialized)
-               if (!initialize_class(fi->class))
-                       return false;
+       /* enter a monitor on the patching position */
 
-       /* patch back original code */
+       PATCHER_MONITORENTER;
 
-       *((u4 *) (ra + 0 * 4)) = mcode;
-       *((u4 *) (ra + 1 * 4)) = mcode >> 32;
+       /* create the stackframeinfo */
 
-       /* if we show disassembly, we have to skip the nop's */
+       stacktrace_create_extern_stackframeinfo(&sfi, pv, sp + 6 * 8, ra, xpc);
 
-       if (showdisassemble)
-               ra = ra + 2 * 4;
+       /* call the proper patcher function */
 
-       /* get the offset from machine instruction */
+       result = (patcher_function)(sp);
 
-       offset = (s2) (*((u4 *) ra) & 0x0000ffff);
+       /* remove the stackframeinfo */
 
-       /* patch the field value's address */
+       stacktrace_remove_stackframeinfo(&sfi);
 
-       *((ptrint *) (pv + offset)) = (ptrint) &(fi->value);
+       /* check for return value and exit accordingly */
 
-       /* synchronize instruction cache */
+       if (result == false) {
+               e = exceptions_get_and_clear_exception();
 
-       docacheflush(ra, 2 * 4);
+               PATCHER_MONITOREXIT;
+
+               return e;
+       }
 
        PATCHER_MARK_PATCHED_MONITOREXIT;
 
-       return true;
+       return NULL;
 }
 
 
-/* patcher_get_putfield ********************************************************
+/* patcher_get_putstatic *******************************************************
 
    Machine code:
 
    <patched call position>
-   8ee90020    lw       a5,32(s7)
+   dfc1ffb8    ld       at,-72(s8)
+   fc250000    sd       a1,0(at)
 
 *******************************************************************************/
 
-bool patcher_get_putfield(u1 *sp)
+bool patcher_get_putstatic(u1 *sp)
 {
-       u1                *ra;
-       java_objectheader *o;
-       u8                 mcode;
-       unresolved_field  *uf;
-       fieldinfo         *fi;
-
-       ra    = (u1 *)                *((ptrint *) (sp + 3 * 8));
-       o     = (java_objectheader *) *((ptrint *) (sp + 2 * 8));
-       mcode =                       *((u8 *)     (sp + 1 * 8));
-       uf    = (unresolved_field *)  *((ptrint *) (sp + 0 * 8));
+       u1               *ra;
+       u4                mcode[2];
+       unresolved_field *uf;
+       s4                disp;
+       u1               *pv;
+       fieldinfo        *fi;
 
-       /* calculate and set the new return address */
-
-       ra = ra - 2 * 4;
-       *((ptrint *) (sp + 3 * 8)) = (ptrint) ra;
+       /* get stuff from the stack */
 
-       PATCHER_MONITORENTER;
+       ra       = (u1 *)               *((ptrint *) (sp + 5 * 8));
+       mcode[0] =                      *((u4 *)     (sp + 3 * 8));
+       mcode[1] =                      *((u4 *)     (sp + 3 * 8 + 4));
+       uf       = (unresolved_field *) *((ptrint *) (sp + 2 * 8));
+       disp     =                      *((s4 *)     (sp + 1 * 8));
+       pv       = (u1 *)               *((ptrint *) (sp + 0 * 8));
 
        /* get the fieldinfo */
 
-       if (!(fi = helper_resolve_fieldinfo(uf))) {
-               PATCHER_MONITOREXIT;
-
+       if (!(fi = resolve_field_eager(uf)))
                return false;
-       }
 
-       /* patch back original code */
+       /* check if the field's class is initialized */
 
-       *((u4 *) (ra + 0 * 4)) = mcode;
-       *((u4 *) (ra + 1 * 4)) = mcode >> 32;
+       if (!(fi->class->state & CLASS_INITIALIZED))
+               if (!initialize_class(fi->class))
+                       return false;
 
-       /* if we show disassembly, we have to skip the nop's */
+       /* patch back original code */
 
-       if (showdisassemble)
-               ra = ra + 2 * 4;
+       *((u4 *) (ra + 0 * 4)) = mcode[0];
+       *((u4 *) (ra + 1 * 4)) = mcode[1];
 
-       /* patch the field's offset */
+       /* synchronize instruction cache */
 
-       *((u4 *) ra) |= (s2) (fi->offset & 0x0000ffff);
+       md_icacheflush(ra, 2 * 4);
 
-       /* synchronize instruction cache */
+       /* patch the field value's address */
 
-       docacheflush(ra, 2 * 4);
+       *((ptrint *) (pv + disp)) = (ptrint) &(fi->value);
 
-       PATCHER_MARK_PATCHED_MONITOREXIT;
+       /* synchronize data cache */
+
+       md_dcacheflush(pv + disp, SIZEOF_VOID_P);
 
        return true;
 }
 
 
-/* patcher_builtin_new *********************************************************
+/* patcher_get_putfield ********************************************************
 
    Machine code:
 
-   dfc4ff98    ld       a0,-104(s8)
-   <patched call postition>
-   dfd9ff90    ld       t9,-112(s8)
-   0320f809    jalr     t9
-   00000000    nop
+   <patched call position>
+   8ee90020    lw       a5,32(s7)
 
 *******************************************************************************/
 
-bool patcher_builtin_new(u1 *sp)
+bool patcher_get_putfield(u1 *sp)
 {
-       u1                *ra;
-       java_objectheader *o;
-       u8                 mcode;
-       constant_classref *cr;
-       u1                *pv;
-       classinfo         *c;
-       s2                 offset;
-
-       /* 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));
-       pv    = (u1 *)                *((ptrint *) (sp - 2 * 8));
+       u1               *ra;
+       u4                mcode[2];
+       unresolved_field *uf;
+       fieldinfo        *fi;
 
-       /* calculate and set the new return address */
+       ra       = (u1 *)               *((ptrint *) (sp + 5 * 8));
+       mcode[0] =                      *((u4 *)     (sp + 3 * 8));
+       mcode[1] =                      *((u4 *)     (sp + 3 * 8 + 4));
+       uf       = (unresolved_field *) *((ptrint *) (sp + 2 * 8));
 
-       ra = ra - (4 + 2 * 4);
-       *((ptrint *) (sp + 3 * 8)) = (ptrint) ra;
-
-       PATCHER_MONITORENTER;
-
-       /* get the classinfo */
-
-       if (!(c = helper_resolve_classinfo(cr))) {
-               PATCHER_MONITOREXIT;
+       /* get the fieldinfo */
 
+       if (!(fi = resolve_field_eager(uf)))
                return false;
-       }
 
        /* patch back original code */
 
-       *((u4 *) (ra + 1 * 4)) = mcode;
-       *((u4 *) (ra + 2 * 4)) = mcode >> 32;
-
-       /* get the offset from machine instruction */
-
-       offset = (s2) (*((u4 *) ra) & 0x0000ffff);
-
-       /* patch the classinfo pointer */
-
-       *((ptrint *) (pv + offset)) = (ptrint) c;
+       *((u4 *) (ra + 0 * 4)) = mcode[0];
+       *((u4 *) (ra + 1 * 4)) = mcode[1];
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 2 * 4;
 
-       /* get the offset from machine instruction */
-
-       offset = (s2) (*((u4 *) (ra + 4)) & 0x0000ffff);
-
-       /* patch new function address */
+       /* patch the field's offset */
 
-       *((ptrint *) (pv + offset)) = (ptrint) BUILTIN_new;
+#if SIZEOF_VOID_P == 4
+       if (fi->type == TYPE_LNG) {
+# if WORDS_BIGENDIAN == 1
+               /* ATTENTION: order of these instructions depend on M_LLD_INTERN */
+               *((u4 *) (ra + 0 * 4)) |= (s2) ((fi->offset + 0) & 0x0000ffff);
+               *((u4 *) (ra + 1 * 4)) |= (s2) ((fi->offset + 4) & 0x0000ffff);
+# else
+               /* ATTENTION: order of these instructions depend on M_LLD_INTERN */
+               *((u4 *) (ra + 0 * 4)) |= (s2) ((fi->offset + 4) & 0x0000ffff);
+               *((u4 *) (ra + 1 * 4)) |= (s2) ((fi->offset + 0) & 0x0000ffff);
+# endif
+       } else
+#endif
+               *((u4 *) ra) |= (s2) (fi->offset & 0x0000ffff);
 
        /* synchronize instruction cache */
 
-       docacheflush(ra + 4, 2 * 4);
-
-       PATCHER_MARK_PATCHED_MONITOREXIT;
+       if (opt_showdisassemble) {
+#if SIZEOF_VOID_P == 4
+               if (fi->type == TYPE_LNG)
+                       md_icacheflush(ra - 2 * 4, 4 * 4);
+               else
+#endif
+                       md_icacheflush(ra - 2 * 4, 3 * 4);
+       }
+       else {
+               md_icacheflush(ra, 2 * 4);
+       }
 
        return true;
 }
 
 
-/* patcher_builtin_newarray ****************************************************
+/* patcher_aconst **************************************************************
 
    Machine code:
 
-   dfc5ffa0    ld       a1,-96(s8)
-   <patched call position>
-   dfd9ff98    ld       t9,-104(s8)
-   0320f809    jalr     t9
-   00000000    nop
+   <patched call postition>
+   dfc4ff98    ld       a0,-104(s8)
 
 *******************************************************************************/
 
-bool patcher_builtin_newarray(u1 *sp)
+bool patcher_aconst(u1 *sp)
 {
        u1                *ra;
-       java_objectheader *o;
-       u8                 mcode;
+       u4                 mcode[2];
        constant_classref *cr;
+       s4                 disp;
        u1                *pv;
        classinfo         *c;
-       s2                 offset;
 
        /* 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));
-       pv    = (u1 *)                *((ptrint *) (sp - 2 * 8));
-
-       /* calculate and set the new return address */
-
-       ra = ra - (4 + 2 * 4);
-       *((ptrint *) (sp + 3 * 8)) = (ptrint) ra;
-
-       PATCHER_MONITORENTER;
+       ra       = (u1 *)                *((ptrint *) (sp + 5 * 8));
+       mcode[0] =                       *((u4 *)     (sp + 3 * 8));
+       mcode[1] =                       *((u4 *)     (sp + 3 * 8 + 4));
+       cr       = (constant_classref *) *((ptrint *) (sp + 2 * 8));
+       disp     =                       *((s4 *)     (sp + 1 * 8));
+       pv       = (u1 *)                *((ptrint *) (sp + 0 * 8));
 
        /* get the classinfo */
 
-       if (!(c = helper_resolve_classinfo(cr))) {
-               PATCHER_MONITOREXIT;
-
+       if (!(c = resolve_classref_eager(cr)))
                return false;
-       }
 
        /* patch back original code */
 
-       *((u4 *) (ra + 1 * 4)) = mcode;
-       *((u4 *) (ra + 2 * 4)) = mcode >> 32;
-
-       /* get the offset from machine instruction */
-
-       offset = (s2) (*((u4 *) ra) & 0x0000ffff);
-
-       /* patch the class' vftbl pointer */
-
-       *((ptrint *) (pv + offset)) = (ptrint) c->vftbl;
-
-       /* if we show disassembly, we have to skip the nop */
+       *((u4 *) (ra + 0 * 4)) = mcode[0];
+       *((u4 *) (ra + 1 * 4)) = mcode[1];
 
-       if (showdisassemble)
-               ra = ra + 2 * 4;
-
-       /* get the offset from machine instruction */
+       /* synchronize instruction cache */
 
-       offset = (s2) (*((u4 *) (ra + 4)) & 0x0000ffff);
+       md_icacheflush(ra, 2 * 4);
 
-       /* patch new function address */
+       /* patch the classinfo pointer */
 
-       *((ptrint *) (pv + offset)) = (ptrint) BUILTIN_newarray;
+       *((ptrint *) (pv + disp)) = (ptrint) c;
 
-       /* synchronize instruction cache */
+       /* synchronize data cache */
 
-       docacheflush(ra + 4, 2 * 4);
-
-       PATCHER_MARK_PATCHED_MONITOREXIT;
+       md_dcacheflush(pv + disp, SIZEOF_VOID_P);
 
        return true;
 }
@@ -353,7 +314,6 @@ bool patcher_builtin_newarray(u1 *sp)
    Machine code:
 
    <patched call position>
-   24040002    addiu    a0,zero,2
    dfc5ff90    ld       a1,-112(s8)
    03a03025    move     a2,sp
    dfd9ff88    ld       t9,-120(s8)
@@ -365,59 +325,42 @@ bool patcher_builtin_newarray(u1 *sp)
 bool patcher_builtin_multianewarray(u1 *sp)
 {
        u1                *ra;
-       java_objectheader *o;
-       u8                 mcode;
+       u4                 mcode[2];
        constant_classref *cr;
+       s4                 disp;
        u1                *pv;
        classinfo         *c;
-       s2                 offset;
 
        /* 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));
-       pv    = (u1 *)                *((ptrint *) (sp - 2 * 8));
-
-       /* calculate and set the new return address */
-
-       ra = ra - 2 * 4;
-       *((ptrint *) (sp + 3 * 8)) = (ptrint) ra;
-
-       PATCHER_MONITORENTER;
+       ra       = (u1 *)                *((ptrint *) (sp + 5 * 8));
+       mcode[0] =                       *((u4 *)     (sp + 3 * 8));
+       mcode[1] =                       *((u4 *)     (sp + 3 * 8 + 4));
+       cr       = (constant_classref *) *((ptrint *) (sp + 2 * 8));
+       disp     =                       *((s4 *)     (sp + 1 * 8));
+       pv       = (u1 *)                *((ptrint *) (sp + 0 * 8));
 
        /* get the classinfo */
 
-       if (!(c = helper_resolve_classinfo(cr))) {
-               PATCHER_MONITOREXIT;
-
+       if (!(c = resolve_classref_eager(cr)))
                return false;
-       }
 
        /* patch back original code */
 
-       *((u4 *) (ra + 0 * 4)) = mcode;
-       *((u4 *) (ra + 1 * 4)) = mcode >> 32;
+       *((u4 *) (ra + 0 * 4)) = mcode[0];
+       *((u4 *) (ra + 1 * 4)) = mcode[1];
 
-       /* if we show disassembly, we have to skip the nop's */
-
-       if (showdisassemble)
-               ra = ra + 2 * 4;
-
-       /* get the offset from machine instruction */
-
-       offset = (s2) (*((u4 *) (ra + 4)) & 0x0000ffff);
+       /* synchronize instruction cache */
 
-       /* patch the class' vftbl pointer */
+       md_icacheflush(ra, 2 * 4);
 
-       *((ptrint *) (pv + offset)) = (ptrint) c->vftbl;
+       /* patch the classinfo pointer */
 
-       /* synchronize instruction cache */
+       *((ptrint *) (pv + disp)) = (ptrint) c;
 
-       docacheflush(ra, 2 * 4);
+       /* synchronize data cache */
 
-       PATCHER_MARK_PATCHED_MONITOREXIT;
+       md_dcacheflush(pv + disp, SIZEOF_VOID_P);
 
        return true;
 }
@@ -427,8 +370,8 @@ bool patcher_builtin_multianewarray(u1 *sp)
 
    Machine code:
 
-   dfc5ffc0    ld       a1,-64(s8)
    <patched call position>
+   dfc5ffc0    ld       a1,-64(s8)
    dfd9ffb8    ld       t9,-72(s8)
    0320f809    jalr     t9
    00000000    nop
@@ -438,148 +381,42 @@ bool patcher_builtin_multianewarray(u1 *sp)
 bool patcher_builtin_arraycheckcast(u1 *sp)
 {
        u1                *ra;
-       java_objectheader *o;
-       u8                 mcode;
+       u4                 mcode[2];
        constant_classref *cr;
+       s4                 disp;
        u1                *pv;
        classinfo         *c;
-       s2                 offset;
 
        /* 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));
-       pv    = (u1 *)                *((ptrint *) (sp - 2 * 8));
-
-       /* calculate and set the new return address */
-
-       ra = ra - 3 * 4;
-       *((ptrint *) (sp + 3 * 8)) = (ptrint) ra;
-
-       PATCHER_MONITORENTER;
+       ra       = (u1 *)                *((ptrint *) (sp + 5 * 8));
+       mcode[0] =                       *((u4 *)     (sp + 3 * 8));
+       mcode[1] =                       *((u4 *)     (sp + 3 * 8 + 4));
+       cr       = (constant_classref *) *((ptrint *) (sp + 2 * 8));
+       disp     =                       *((s4 *)     (sp + 1 * 8));
+       pv       = (u1 *)                *((ptrint *) (sp + 0 * 8));
 
        /* get the classinfo */
 
-       if (!(c = helper_resolve_classinfo(cr))) {
-               PATCHER_MONITOREXIT;
-
+       if (!(c = resolve_classref_eager(cr)))
                return false;
-       }
 
        /* patch back original code */
 
-       *((u4 *) (ra + 1 * 4)) = mcode;
-       *((u4 *) (ra + 2 * 4)) = mcode >> 32;
-
-       /* get the offset from machine instruction */
-
-       offset = (s2) (*((u4 *) ra) & 0x0000ffff);
-
-       /* patch the class' vftbl pointer */
-
-       *((ptrint *) (pv + offset)) = (ptrint) c->vftbl;
-
-       /* if we show disassembly, we have to skip the nop */
-
-       if (showdisassemble)
-               ra = ra + 2 * 4;
-
-       /* get the offset from machine instruction */
-
-       offset = (s2) (*((u4 *) (ra + 1 * 4)) & 0x0000ffff);
-
-       /* patch new function address */
-
-       *((ptrint *) (pv + offset)) = (ptrint) BUILTIN_arraycheckcast;
+       *((u4 *) (ra + 0 * 4)) = mcode[0];
+       *((u4 *) (ra + 1 * 4)) = mcode[1];
 
        /* synchronize instruction cache */
 
-       docacheflush(ra + 4, 2 * 4);
-
-       PATCHER_MARK_PATCHED_MONITOREXIT;
-
-       return true;
-}
-
-
-/* patcher_builtin_arrayinstanceof *********************************************
-
-   Machine code:
-
-   dfc5fe98    ld       a1,-360(s8)
-   <patched call position>
-   dfd9fe90    ld       t9,-368(s8)
-   0320f809    jalr     t9
-   00000000    nop
-
-*******************************************************************************/
-
-bool patcher_builtin_arrayinstanceof(u1 *sp)
-{
-       u1                *ra;
-       java_objectheader *o;
-       u8                 mcode;
-       constant_classref *cr;
-       u1                *pv;
-       classinfo         *c;
-       s4                 offset;
-
-       /* 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));
-       pv    = (u1 *)                *((ptrint *) (sp - 2 * 8));
-
-       /* calculate and set the new return address */
-
-       ra = ra - 3 * 4;
-       *((ptrint *) (sp + 3 * 8)) = (ptrint) ra;
-
-       PATCHER_MONITORENTER;
+       md_icacheflush(ra, 2 * 4);
 
-       /* get the classinfo */
-
-       if (!(c = helper_resolve_classinfo(cr))) {
-               PATCHER_MONITOREXIT;
-
-               return false;
-       }
-
-       /* patch back original code */
-
-       *((u4 *) (ra + 1 * 4)) = mcode;
-       *((u4 *) (ra + 2 * 4)) = mcode >> 32;
-
-       /* get the offset from machine instruction */
-
-       offset = (s2) (*((u4 *) ra) & 0x0000ffff);
-
-       /* patch the class' vftbl pointer */
-       
-       *((ptrint *) (pv + offset)) = (ptrint) c->vftbl;
-
-       /* if we show disassembly, we have to skip the nop's */
-
-       if (showdisassemble)
-               ra = ra + 2 * 4;
-
-       /* get the offset from machine instruction */
-
-       offset = (s2) (*((u4 *) (ra + 1 * 4)) & 0x0000ffff);
-
-       /* patch new function address */
-
-       *((ptrint *) (pv + offset)) = (ptrint) BUILTIN_arrayinstanceof;
+       /* patch the classinfo pointer */
 
-       /* synchronize instruction cache */
+       *((ptrint *) (pv + disp)) = (ptrint) c;
 
-       docacheflush(ra + 4, 2 * 4);
+       /* synchronize data cache */
 
-       PATCHER_MARK_PATCHED_MONITOREXIT;
+       md_dcacheflush(pv + disp, SIZEOF_VOID_P);
 
        return true;
 }
@@ -599,59 +436,42 @@ bool patcher_builtin_arrayinstanceof(u1 *sp)
 bool patcher_invokestatic_special(u1 *sp)
 {
        u1                *ra;
-       java_objectheader *o;
-       u8                 mcode;
+       u4                 mcode[2];
        unresolved_method *um;
+       s4                 disp;
        u1                *pv;
        methodinfo        *m;
-       s4                 offset;
 
        /* get stuff from the stack */
 
-       ra    = (u1 *)                *((ptrint *) (sp + 3 * 8));
-       o     = (java_objectheader *) *((ptrint *) (sp + 2 * 8));
-       mcode =                       *((u8 *)     (sp + 1 * 8));
-       um    = (unresolved_method *) *((ptrint *) (sp + 0 * 8));
-       pv    = (u1 *)                *((ptrint *) (sp - 2 * 8));
-
-       /* calculate and set the new return address */
-
-       ra = ra - 2 * 4;
-       *((ptrint *) (sp + 3 * 8)) = (ptrint) ra;
-
-       PATCHER_MONITORENTER;
+       ra       = (u1 *)                *((ptrint *) (sp + 5 * 8));
+       mcode[0] =                       *((u4 *)     (sp + 3 * 8));
+       mcode[1] =                       *((u4 *)     (sp + 3 * 8 + 4));
+       um       = (unresolved_method *) *((ptrint *) (sp + 2 * 8));
+       disp     =                       *((s4 *)     (sp + 1 * 8));
+       pv       = (u1 *)                *((ptrint *) (sp + 0 * 8));
 
        /* get the fieldinfo */
 
-       if (!(m = helper_resolve_methodinfo(um))) {
-               PATCHER_MONITOREXIT;
-
+       if (!(m = resolve_method_eager(um)))
                return false;
-       }
 
        /* patch back original code */
 
-       *((u4 *) (ra + 0 * 4)) = mcode;
-       *((u4 *) (ra + 1 * 4)) = mcode >> 32;
+       *((u4 *) (ra + 0 * 4)) = mcode[0];
+       *((u4 *) (ra + 1 * 4)) = mcode[1];
 
-       /* if we show disassembly, we have to skip the nop's */
-
-       if (showdisassemble)
-               ra = ra + 2 * 4;
-
-       /* get the offset from machine instruction */
+       /* synchronize instruction cache */
 
-       offset = (s2) (*((u4 *) ra) & 0x0000ffff);
+       md_icacheflush(ra, 2 * 4);
 
        /* patch stubroutine */
 
-       *((ptrint *) (pv + offset)) = (ptrint) m->stubroutine;
-
-       /* synchronize instruction cache */
+       *((ptrint *) (pv + disp)) = (ptrint) m->stubroutine;
 
-       docacheflush(ra, 2 * 4);
+       /* synchronize data cache */
 
-       PATCHER_MARK_PATCHED_MONITOREXIT;
+       md_dcacheflush(pv + disp, SIZEOF_VOID_P);
 
        return true;
 }
@@ -672,41 +492,30 @@ bool patcher_invokestatic_special(u1 *sp)
 bool patcher_invokevirtual(u1 *sp)
 {
        u1                *ra;
-       java_objectheader *o;
-       u8                 mcode;
+       u4                 mcode[2];
        unresolved_method *um;
        methodinfo        *m;
 
        /* get stuff from the stack */
 
-       ra    = (u1 *)                *((ptrint *) (sp + 3 * 8));
-       o     = (java_objectheader *) *((ptrint *) (sp + 2 * 8));
-       mcode =                       *((u8 *)     (sp + 1 * 8));
-       um    = (unresolved_method *) *((ptrint *) (sp + 0 * 8));
-
-       /* calculate and set the new return address */
-
-       ra = ra - 2 * 4;
-       *((ptrint *) (sp + 3 * 8)) = (ptrint) ra;
-
-       PATCHER_MONITORENTER;
+       ra       = (u1 *)                *((ptrint *) (sp + 5 * 8));
+       mcode[0] =                       *((u4 *)     (sp + 3 * 8));
+       mcode[1] =                       *((u4 *)     (sp + 3 * 8 + 4));
+       um       = (unresolved_method *) *((ptrint *) (sp + 2 * 8));
 
        /* get the fieldinfo */
 
-       if (!(m = helper_resolve_methodinfo(um))) {
-               PATCHER_MONITOREXIT;
-
+       if (!(m = resolve_method_eager(um)))
                return false;
-       }
 
        /* patch back original code */
 
-       *((u4 *) (ra + 0 * 4)) = mcode;
-       *((u4 *) (ra + 1 * 4)) = mcode >> 32;
+       *((u4 *) (ra + 0 * 4)) = mcode[0];
+       *((u4 *) (ra + 1 * 4)) = mcode[1];
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 2 * 4;
 
        /* patch vftbl index */
@@ -716,9 +525,10 @@ bool patcher_invokevirtual(u1 *sp)
 
        /* synchronize instruction cache */
 
-       docacheflush(ra, 2 * 4);
-
-       PATCHER_MARK_PATCHED_MONITOREXIT;
+       if (opt_showdisassemble)
+               md_icacheflush(ra - 2 * 4, 4 * 4);
+       else
+               md_icacheflush(ra, 2 * 4);
 
        return true;
 }
@@ -740,41 +550,30 @@ bool patcher_invokevirtual(u1 *sp)
 bool patcher_invokeinterface(u1 *sp)
 {
        u1                *ra;
-       java_objectheader *o;
-       u8                 mcode;
+       u4                 mcode[2];
        unresolved_method *um;
        methodinfo        *m;
 
        /* get stuff from the stack */
 
-       ra    = (u1 *)                *((ptrint *) (sp + 3 * 8));
-       o     = (java_objectheader *) *((ptrint *) (sp + 2 * 8));
-       mcode =                       *((u8 *)     (sp + 1 * 8));
-       um    = (unresolved_method *) *((ptrint *) (sp + 0 * 8));
-
-       /* calculate and set the new return address */
-
-       ra = ra - 2 * 4;
-       *((ptrint *) (sp + 3 * 8)) = (ptrint) ra;
-
-       PATCHER_MONITORENTER;
+       ra       = (u1 *)                *((ptrint *) (sp + 5 * 8));
+       mcode[0] =                       *((u4 *)     (sp + 3 * 8));
+       mcode[1] =                       *((u4 *)     (sp + 3 * 8 + 4));
+       um       = (unresolved_method *) *((ptrint *) (sp + 2 * 8));
 
        /* get the fieldinfo */
 
-       if (!(m = helper_resolve_methodinfo(um))) {
-               PATCHER_MONITOREXIT;
-
+       if (!(m = resolve_method_eager(um)))
                return false;
-       }
 
        /* patch back original code */
 
-       *((u4 *) (ra + 0 * 4)) = mcode;
-       *((u4 *) (ra + 1 * 4)) = mcode >> 32;
+       *((u4 *) (ra + 0 * 4)) = mcode[0];
+       *((u4 *) (ra + 1 * 4)) = mcode[1];
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 2 * 4;
 
        /* patch interfacetable index */
@@ -789,9 +588,10 @@ bool patcher_invokeinterface(u1 *sp)
 
        /* synchronize instruction cache */
 
-       docacheflush(ra, 2 * 4);
-
-       PATCHER_MARK_PATCHED_MONITOREXIT;
+       if (opt_showdisassemble)
+               md_icacheflush(ra - 2 * 4, 5 * 4);
+       else
+               md_icacheflush(ra, 3 * 4);
 
        return true;
 }
@@ -812,59 +612,42 @@ bool patcher_invokeinterface(u1 *sp)
 bool patcher_checkcast_instanceof_flags(u1 *sp)
 {
        u1                *ra;
-       java_objectheader *o;
-       u8                 mcode;
+       u4                 mcode[2];
        constant_classref *cr;
+       s4                 disp;
        u1                *pv;
        classinfo         *c;
-       s2                 offset;
 
        /* 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));
-       pv    = (u1 *)                *((ptrint *) (sp - 2 * 8));
-
-       /* calculate and set the new return address */
-
-       ra = ra - 2 * 4;
-       *((ptrint *) (sp + 3 * 8)) = (ptrint) ra;
-
-       PATCHER_MONITORENTER;
+       ra       = (u1 *)                *((ptrint *) (sp + 5 * 8));
+       mcode[0] =                       *((u4 *)     (sp + 3 * 8));
+       mcode[1] =                       *((u4 *)     (sp + 3 * 8 + 4));
+       cr       = (constant_classref *) *((ptrint *) (sp + 2 * 8));
+       disp     =                       *((s4 *)     (sp + 1 * 8));
+       pv       = (u1 *)                *((ptrint *) (sp + 0 * 8));
 
        /* get the fieldinfo */
 
-       if (!(c = helper_resolve_classinfo(cr))) {
-               PATCHER_MONITOREXIT;
-
+       if (!(c = resolve_classref_eager(cr)))
                return false;
-       }
 
        /* patch back original code */
 
-       *((u4 *) (ra + 0 * 4)) = mcode;
-       *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-
-       /* if we show disassembly, we have to skip the nop's */
+       *((u4 *) (ra + 0 * 4)) = mcode[0];
+       *((u4 *) (ra + 1 * 4)) = mcode[1];
 
-       if (showdisassemble)
-               ra = ra + 2 * 4;
-
-       /* get the offset from machine instruction */
+       /* synchronize instruction cache */
 
-       offset = (s2) (*((u4 *) ra) & 0x0000ffff);
+       md_icacheflush(ra, 2 * 4);
 
        /* patch class flags */
 
-       *((s4 *) (pv + offset)) = (s4) c->flags;
+       *((s4 *) (pv + disp)) = (s4) c->flags;
 
-       /* synchronize instruction cache */
-
-       docacheflush(ra, 2 * 4);
+       /* synchronize data cache */
 
-       PATCHER_MARK_PATCHED_MONITOREXIT;
+       md_dcacheflush(pv + disp, sizeof(s4));
 
        return true;
 }
@@ -887,41 +670,30 @@ bool patcher_checkcast_instanceof_flags(u1 *sp)
 bool patcher_checkcast_instanceof_interface(u1 *sp)
 {
        u1                *ra;
-       java_objectheader *o;
-       u8                 mcode;
+       u4                 mcode[2];
        constant_classref *cr;
        classinfo         *c;
 
        /* 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));
-
-       /* calculate and set the new return address */
-
-       ra = ra - 2 * 4;
-       *((ptrint *) (sp + 3 * 8)) = (ptrint) ra;
-
-       PATCHER_MONITORENTER;
+       ra       = (u1 *)                *((ptrint *) (sp + 5 * 8));
+       mcode[0] =                       *((u4 *)     (sp + 3 * 8));
+       mcode[1] =                       *((u4 *)     (sp + 3 * 8 + 4));
+       cr       = (constant_classref *) *((ptrint *) (sp + 2 * 8));
 
        /* get the fieldinfo */
 
-       if (!(c = helper_resolve_classinfo(cr))) {
-               PATCHER_MONITOREXIT;
-
+       if (!(c = resolve_classref_eager(cr)))
                return false;
-       }
 
        /* patch back original code */
 
-       *((u4 *) (ra + 0 * 4)) = mcode;
-       *((u4 *) (ra + 1 * 4)) = mcode >> 32;
+       *((u4 *) (ra + 0 * 4)) = mcode[0];
+       *((u4 *) (ra + 1 * 4)) = mcode[1];
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 2 * 4;
 
        /* patch super class index */
@@ -933,9 +705,10 @@ bool patcher_checkcast_instanceof_interface(u1 *sp)
 
        /* synchronize instruction cache */
 
-       docacheflush(ra, 6 * 4);
-
-       PATCHER_MARK_PATCHED_MONITOREXIT;
+       if (opt_showdisassemble)
+               md_icacheflush(ra - 2 * 4, 8 * 4);
+       else
+               md_icacheflush(ra, 6 * 4);
 
        return true;
 }
@@ -954,59 +727,42 @@ bool patcher_checkcast_instanceof_interface(u1 *sp)
 bool patcher_checkcast_instanceof_class(u1 *sp)
 {
        u1                *ra;
-       java_objectheader *o;
-       u8                 mcode;
+       u4                 mcode[2];
        constant_classref *cr;
+       s4                 disp;
        u1                *pv;
        classinfo         *c;
-       s2                 offset;
 
        /* 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));
-       pv    = (u1 *)                *((ptrint *) (sp - 2 * 8));
-
-       /* calculate and set the new return address */
-
-       ra = ra - 2 * 4;
-       *((ptrint *) (sp + 3 * 8)) = (ptrint) ra;
-
-       PATCHER_MONITORENTER;
+       ra       = (u1 *)                *((ptrint *) (sp + 5 * 8));
+       mcode[0] =                       *((u4 *)     (sp + 3 * 8));
+       mcode[1] =                       *((u4 *)     (sp + 3 * 8 + 4));
+       cr       = (constant_classref *) *((ptrint *) (sp + 2 * 8));
+       disp     =                       *((s4 *)     (sp + 1 * 8));
+       pv       = (u1 *)                *((ptrint *) (sp + 0 * 8));
 
        /* get the fieldinfo */
 
-       if (!(c = helper_resolve_classinfo(cr))) {
-               PATCHER_MONITOREXIT;
-
+       if (!(c = resolve_classref_eager(cr)))
                return false;
-       }
 
        /* patch back original code */
 
-       *((u4 *) (ra + 0 * 4)) = mcode;
-       *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-
-       /* if we show disassembly, we have to skip the nop's */
-
-       if (showdisassemble)
-               ra = ra + 2 * 4;
+       *((u4 *) (ra + 0 * 4)) = mcode[0];
+       *((u4 *) (ra + 1 * 4)) = mcode[1];
 
-       /* get the offset from machine instruction */
+       /* synchronize instruction cache */
 
-       offset = (s2) (*((u4 *) (ra + 1 * 4)) & 0x0000ffff);
+       md_icacheflush(ra, 2 * 4);
 
        /* patch super class' vftbl */
 
-       *((ptrint *) (pv + offset)) = (ptrint) c->vftbl;
+       *((ptrint *) (pv + disp)) = (ptrint) c->vftbl;
 
-       /* synchronize instruction cache */
+       /* synchronize data cache */
 
-       docacheflush(ra, 2 * 4);
-
-       PATCHER_MARK_PATCHED_MONITOREXIT;
+       md_dcacheflush(pv + disp, SIZEOF_VOID_P);
 
        return true;
 }
@@ -1014,54 +770,82 @@ bool patcher_checkcast_instanceof_class(u1 *sp)
 
 /* patcher_clinit **************************************************************
 
-   XXX
+   No special machine code.
 
 *******************************************************************************/
 
 bool patcher_clinit(u1 *sp)
 {
-       u1                *ra;
-       java_objectheader *o;
-       u8                 mcode;
-       classinfo         *c;
+       u1        *ra;
+       u4         mcode[2];
+       classinfo *c;
 
        /* get stuff from the stack */
 
-       ra    = (u1 *)                *((ptrint *) (sp + 3 * 8));
-       o     = (java_objectheader *) *((ptrint *) (sp + 2 * 8));
-       mcode =                       *((u8 *)     (sp + 1 * 8));
-       c     = (classinfo *)         *((ptrint *) (sp + 0 * 8));
+       ra       = (u1 *)        *((ptrint *) (sp + 5 * 8));
+       mcode[0] =               *((u4 *)     (sp + 3 * 8));
+       mcode[1] =               *((u4 *)     (sp + 3 * 8 + 4));
+       c        = (classinfo *) *((ptrint *) (sp + 2 * 8));
 
-       /* calculate and set the new return address */
+       /* check if the class is initialized */
 
-       ra = ra - 2 * 4;
-       *((ptrint *) (sp + 3 * 8)) = (ptrint) ra;
+       if (!(c->state & CLASS_INITIALIZED))
+               if (!initialize_class(c))
+                       return false;
 
-       PATCHER_MONITORENTER;
+       /* patch back original code */
 
-       /* check if the class is initialized */
+       *((u4 *) (ra + 0 * 4)) = mcode[0];
+       *((u4 *) (ra + 1 * 4)) = mcode[1];
 
-       if (!c->initialized) {
-               if (!initialize_class(c)) {
-                       PATCHER_MONITOREXIT;
+       /* synchronize instruction cache */
 
-                       return false;
-               }
-       }
+       md_icacheflush(ra, 2 * 4);
+
+       return true;
+}
+
+
+/* patcher_athrow_areturn ******************************************************
+
+   Machine code:
+
+   <patched call position>
+
+*******************************************************************************/
+
+#ifdef ENABLE_VERIFIER
+bool patcher_athrow_areturn(u1 *sp)
+{
+       u1               *ra;
+       u4                mcode[2];
+       unresolved_class *uc;
+       classinfo        *c;
+
+       /* get stuff from the stack */
+
+       ra       = (u1 *)               *((ptrint *) (sp + 5 * 8));
+       mcode[0] =                      *((u4 *)     (sp + 3 * 8));
+       mcode[1] =                      *((u4 *)     (sp + 3 * 8 + 4));
+       uc       = (unresolved_class *) *((ptrint *) (sp + 2 * 8));
+
+       /* resolve the class */
+
+       if (!resolve_class(uc, resolveEager, false, &c))
+               return false;
 
        /* patch back original code */
 
-       *((u4 *) (ra + 0)) = mcode;
-       *((u4 *) (ra + 4)) = mcode >> 32;
+       *((u4 *) (ra + 0 * 4)) = mcode[0];
+       *((u4 *) (ra + 1 * 4)) = mcode[1];
 
        /* synchronize instruction cache */
 
-       docacheflush(ra, 2 * 4);
-
-       PATCHER_MARK_PATCHED_MONITOREXIT;
+       md_icacheflush(ra, 2 * 4);
 
        return true;
 }
+#endif /* ENABLE_VERIFIER */
 
 
 /* patcher_resolve_native ******************************************************
@@ -1070,65 +854,50 @@ bool patcher_clinit(u1 *sp)
 
 *******************************************************************************/
 
+#if !defined(WITH_STATIC_CLASSPATH)
 bool patcher_resolve_native(u1 *sp)
 {
-       u1                *ra;
-       java_objectheader *o;
-       u8                 mcode;
-       methodinfo        *m;
-       u1                *pv;
-       functionptr        f;
-       s2                 offset;
+       u1          *ra;
+       u4           mcode[2];
+       methodinfo  *m;
+       s4           disp;
+       u1          *pv;
+       functionptr  f;
 
        /* get stuff from the stack */
 
-       ra    = (u1 *)                *((ptrint *) (sp + 3 * 8));
-       o     = (java_objectheader *) *((ptrint *) (sp + 2 * 8));
-       mcode =                       *((u8 *)     (sp + 1 * 8));
-       m     = (methodinfo *)        *((ptrint *) (sp + 0 * 8));
-       pv    = (u1 *)                *((ptrint *) (sp - 2 * 8));
-
-       /* calculate and set the new return address */
-
-       ra = ra - 2 * 4;
-       *((ptrint *) (sp + 3 * 8)) = (ptrint) ra;
-
-       PATCHER_MONITORENTER;
+       ra       = (u1 *)         *((ptrint *) (sp + 5 * 8));
+       mcode[0] =                *((u4 *)     (sp + 3 * 8));
+       mcode[1] =                *((u4 *)     (sp + 3 * 8 + 4));
+       m        = (methodinfo *) *((ptrint *) (sp + 2 * 8));
+       disp     =                *((s4 *)     (sp + 1 * 8));
+       pv       = (u1 *)         *((ptrint *) (sp + 0 * 8));
 
        /* resolve native function */
 
-       if (!(f = native_resolve_function(m))) {
-               PATCHER_MONITOREXIT;
-
+       if (!(f = native_resolve_function(m)))
                return false;
-       }
 
        /* patch back original code */
 
-       *((u4 *) (ra + 0 * 4)) = mcode;
-       *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-
-       /* if we show disassembly, we have to skip the nop's */
-
-       if (showdisassemble)
-               ra = ra + 2 * 4;
+       *((u4 *) (ra + 0 * 4)) = mcode[0];
+       *((u4 *) (ra + 1 * 4)) = mcode[1];
 
-       /* get the offset from machine instruction */
+       /* synchronize instruction cache */
 
-       offset = (s2) (*((u4 *) ra) & 0x0000ffff);
+       md_icacheflush(ra, 2 * 4);
 
        /* patch native function pointer */
 
-       *((ptrint *) (pv + offset)) = (ptrint) f;
+       *((ptrint *) (pv + disp)) = (ptrint) f;
 
-       /* synchronize instruction cache */
+       /* synchronize data cache */
 
-       docacheflush(ra, 2 * 4);
-
-       PATCHER_MARK_PATCHED_MONITOREXIT;
+       md_dcacheflush(pv + disp, SIZEOF_VOID_P);
 
        return true;
 }
+#endif /* !defined(WITH_STATIC_CLASSPATH) */
 
 
 /*