* src/vm/jit/powerpc/patcher.c (patcher_invokevirtual): Use disp
[cacao.git] / src / vm / jit / powerpc / patcher.c
index dc05571a2aa1075507a36da593b77050ad6dc8a1..5b8492087593828d8ffb799a663f37234f159876 100644 (file)
@@ -1,9 +1,9 @@
 /* src/vm/jit/powerpc/patcher.c - PowerPC 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 3461 2005-10-20 09:53:00Z edwin $
+   $Id: patcher.c 4708 2006-03-30 10:10:07Z twisti $
 
 */
 
 #include "mm/memory.h"
 #include "native/native.h"
 #include "vm/builtin.h"
+#include "vm/class.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"
 
 
@@ -77,11 +78,6 @@ bool patcher_get_putstatic(u1 *sp)
        disp  =                       *((s4 *)     (sp + 1 * 4));
        pv    = (u1 *)                *((ptrint *) (sp + 0 * 4));
 
-       /* calculate and set the new return address */
-
-       ra = ra - 4;
-       *((ptrint *) (sp + 5 * 4)) = (ptrint) ra;
-
        PATCHER_MONITORENTER;
 
        /* get the fieldinfo */
@@ -94,7 +90,7 @@ bool patcher_get_putstatic(u1 *sp)
 
        /* check if the field's class is initialized */
 
-       if (!fi->class->initialized) {
+       if (!(fi->class->state & CLASS_INITIALIZED)) {
                if (!initialize_class(fi->class)) {
                        PATCHER_MONITOREXIT;
 
@@ -108,12 +104,16 @@ bool patcher_get_putstatic(u1 *sp)
 
        /* synchronize instruction cache */
 
-       asm_cacheflush(ra, 4);
+       md_icacheflush(ra, 4);
 
        /* patch the field value's address */
 
        *((ptrint *) (pv + disp)) = (ptrint) &(fi->value);
 
+       /* synchronize data cache */
+
+       md_dcacheflush(pv + disp, SIZEOF_VOID_P);
+
        PATCHER_MARK_PATCHED_MONITOREXIT;
 
        return true;
@@ -144,11 +144,6 @@ bool patcher_get_putfield(u1 *sp)
        uf    = (unresolved_field *)  *((ptrint *) (sp + 2 * 4));
        pv    = (u1 *)                *((ptrint *) (sp + 1 * 4));
 
-       /* calculate and set the new return address */
-
-       ra = ra - 4;
-       *((ptrint *) (sp + 5 * 4)) = (ptrint) ra;
-
        PATCHER_MONITORENTER;
 
        /* get the fieldinfo */
@@ -171,18 +166,34 @@ bool patcher_get_putfield(u1 *sp)
        /* patch the field's offset */
 
        if (fi->type == TYPE_LNG) {
-               /* if the field has type long, we have to patch two instructions */
+               s2 disp;
+
+               /* If the field has type long, we have to patch two
+                  instructions.  But we have to check which instruction is
+                  first.  We do that with the offset of the first
+                  instruction. */
+
+               disp = *((u4 *) (ra + 0));
 
-               *((u4 *) ra) |= (s2) ((fi->offset + 4) & 0x0000ffff);
-               *((u4 *) (ra + 4)) |= (s2) (fi->offset & 0x0000ffff);
+#if WORDS_BIGENDIAN == 1
+               if (disp == 4) {
+                       *((u4 *) (ra + 0)) |= (s2) ((fi->offset + 4) & 0x0000ffff);
+                       *((u4 *) (ra + 4)) |= (s2) ((fi->offset + 0) & 0x0000ffff);
 
+               } else {
+                       *((u4 *) (ra + 0)) |= (s2) ((fi->offset + 0) & 0x0000ffff);
+                       *((u4 *) (ra + 4)) |= (s2) ((fi->offset + 4) & 0x0000ffff);
+               }
+#else
+#error Fix me for LE
+#endif
        } else {
                *((u4 *) ra) |= (s2) (fi->offset & 0x0000ffff);
        }
 
        /* synchronize instruction cache */
 
-       asm_cacheflush(ra, 8);
+       md_icacheflush(ra, 8);
 
        PATCHER_MARK_PATCHED_MONITOREXIT;
 
@@ -190,23 +201,19 @@ bool patcher_get_putfield(u1 *sp)
 }
 
 
-/* patcher_builtin_new *********************************************************
+/* patcher_aconst **************************************************************
 
    Machine code:
 
-   806dffc4    lwz   r3,-60(r13)
    <patched call postition>
+   806dffc4    lwz   r3,-60(r13)
    81adffc0    lwz   r13,-64(r13)
    7da903a6    mtctr r13
    4e800421    bctrl
 
-   NOTICE: Only the displacement for the function address is passed,
-   but the address of the classinfo pointer is one below (above, in
-   addresses speaking). This is for sure.
-
 *******************************************************************************/
 
-bool patcher_builtin_new(u1 *sp)
+bool patcher_aconst(u1 *sp)
 {
        u1                *ra;
        java_objectheader *o;
@@ -225,83 +232,6 @@ bool patcher_builtin_new(u1 *sp)
        disp  =                       *((s4 *)     (sp + 1 * 4));
        pv    = (u1 *)                *((ptrint *) (sp + 0 * 4));
 
-       /* calculate and set the new return address */
-
-       ra = ra - (2 * 4);
-       *((ptrint *) (sp + 5 * 4)) = (ptrint) ra;
-
-       PATCHER_MONITORENTER;
-
-       /* get the classinfo */
-
-       if (!(c = resolve_classref_eager_nonabstract(cr))) {
-               PATCHER_MONITOREXIT;
-
-               return false;
-       }
-
-       /* patch back original code */
-
-       *((u4 *) (ra + 4)) = mcode;
-
-       /* synchronize instruction cache */
-
-       asm_cacheflush(ra + 4, 4);
-
-       /* patch the classinfo pointer */
-
-       *((ptrint *) (pv + (disp + SIZEOF_VOID_P))) = (ptrint) c;
-
-       /* patch new function address */
-
-       *((ptrint *) (pv + disp)) = (ptrint) BUILTIN_new;
-
-       PATCHER_MARK_PATCHED_MONITOREXIT;
-
-       return true;
-}
-
-
-/* patcher_builtin_newarray ****************************************************
-
-   Machine code:
-
-   808dffc8    lwz   r4,-56(r13)
-   <patched call position>
-   81adffc4    lwz   r13,-60(r13)
-   7da903a6    mtctr r13
-   4e800421    bctrl
-
-   NOTICE: Only the displacement for the function address is passed,
-   but the address of the vftbl pointer is one below (above, in
-   addresses speaking). This is for sure.
-
-*******************************************************************************/
-
-bool patcher_builtin_newarray(u1 *sp)
-{
-       u1                *ra;
-       java_objectheader *o;
-       u4                 mcode;
-       constant_classref *cr;
-       u1                *pv;
-       s4                 disp;
-       classinfo         *c;
-
-       /* get stuff from the stack */
-
-       ra    = (u1 *)                *((ptrint *) (sp + 5 * 4));
-       o     = (java_objectheader *) *((ptrint *) (sp + 4 * 4));
-       mcode =                       *((u4 *)     (sp + 3 * 4));
-       cr    = (constant_classref *) *((ptrint *) (sp + 2 * 4));
-       disp  =                       *((s4 *)     (sp + 1 * 4));
-       pv    = (u1 *)                *((ptrint *) (sp + 0 * 4));
-
-       /* calculate and set the new return address */
-
-       ra = ra - 2 * 4;
-       *((ptrint *) (sp + 5 * 4)) = (ptrint) ra;
-
        PATCHER_MONITORENTER;
 
        /* get the classinfo */
@@ -314,19 +244,19 @@ bool patcher_builtin_newarray(u1 *sp)
 
        /* patch back original code */
 
-       *((u4 *) (ra + 4)) = mcode;
+       *((u4 *) ra) = mcode;
 
        /* synchronize instruction cache */
 
-       asm_cacheflush(ra + 4, 4);
+       md_icacheflush(ra, 4);
 
-       /* patch the class' vftbl pointer */
+       /* patch the classinfo pointer */
 
-       *((ptrint *) (pv + (disp + SIZEOF_VOID_P))) = (ptrint) c->vftbl;
+       *((ptrint *) (pv + disp)) = (ptrint) c;
 
-       /* patch new function address */
+       /* synchronize data cache */
 
-       *((ptrint *) (pv + disp)) = (ptrint) BUILTIN_newarray;
+       md_dcacheflush(pv + disp, SIZEOF_VOID_P);
 
        PATCHER_MARK_PATCHED_MONITOREXIT;
 
@@ -366,11 +296,6 @@ bool patcher_builtin_multianewarray(u1 *sp)
        disp  =                       *((s4 *)     (sp + 1 * 4));
        pv    = (u1 *)                *((ptrint *) (sp + 0 * 4));
 
-       /* calculate and set the new return address */
-
-       ra = ra - 4;
-       *((ptrint *) (sp + 5 * 4)) = (ptrint) ra;
-
        PATCHER_MONITORENTER;
 
        /* get the classinfo */
@@ -387,11 +312,15 @@ bool patcher_builtin_multianewarray(u1 *sp)
 
        /* synchronize instruction cache */
 
-       asm_cacheflush(ra, 4);
+       md_icacheflush(ra, 4);
 
-       /* patch the class' vftbl pointer */
+       /* patch the classinfo pointer */
 
-       *((ptrint *) (pv + disp)) = (ptrint) c->vftbl;
+       *((ptrint *) (pv + disp)) = (ptrint) c;
+
+       /* synchronize data cache */
+
+       md_dcacheflush(pv + disp, SIZEOF_VOID_P);
 
        PATCHER_MARK_PATCHED_MONITOREXIT;
 
@@ -409,10 +338,6 @@ bool patcher_builtin_multianewarray(u1 *sp)
    7da903a6    mtctr r13
    4e800421    bctrl
 
-   NOTICE: Only the displacement of the vftbl pointer address is
-   passed, but the address of the function pointer is one above
-   (below, in addresses speaking). This is for sure.
-
 *******************************************************************************/
 
 bool patcher_builtin_arraycheckcast(u1 *sp)
@@ -434,11 +359,6 @@ bool patcher_builtin_arraycheckcast(u1 *sp)
        disp  =                       *((s4 *)     (sp + 1 * 4));
        pv    = (u1 *)                *((ptrint *) (sp + 0 * 4));
 
-       /* calculate and set the new return address */
-
-       ra = ra - 1 * 4;
-       *((ptrint *) (sp + 5 * 4)) = (ptrint) ra;
-
        PATCHER_MONITORENTER;
 
        /* get the classinfo */
@@ -455,88 +375,15 @@ bool patcher_builtin_arraycheckcast(u1 *sp)
 
        /* synchronize instruction cache */
 
-       asm_cacheflush(ra, 4);
-
-       /* patch the class' vftbl pointer */
-
-       *((ptrint *) (pv + disp)) = (ptrint) c->vftbl;
-
-       /* patch new function address */
-
-       *((ptrint *) (pv + (disp - SIZEOF_VOID_P))) =
-               (ptrint) BUILTIN_arraycheckcast;
-
-       PATCHER_MARK_PATCHED_MONITOREXIT;
-
-       return true;
-}
-
-
-/* patcher_builtin_arrayinstanceof *********************************************
-
-   Machine code:
-
-   808dff50    lwz   r4,-176(r13)
-   <patched call position>
-   81adff4c    lwz   r13,-180(r13)
-   7da903a6    mtctr r13
-   4e800421    bctrl
-
-   NOTICE: Only the displacement for the function address is passed,
-   but the address of the vftbl pointer is one below (above, in
-   addresses speaking). This is for sure.
-
-*******************************************************************************/
-
-bool patcher_builtin_arrayinstanceof(u1 *sp)
-{
-       u1                *ra;
-       java_objectheader *o;
-       u4                 mcode;
-       constant_classref *cr;
-       s4                 disp;
-       u1                *pv;
-       classinfo         *c;
-
-       /* get stuff from the stack */
-
-       ra    = (u1 *)                *((ptrint *) (sp + 5 * 4));
-       o     = (java_objectheader *) *((ptrint *) (sp + 4 * 4));
-       mcode =                       *((u4 *)     (sp + 3 * 4));
-       cr    = (constant_classref *) *((ptrint *) (sp + 2 * 4));
-       disp  =                       *((s4 *)     (sp + 1 * 4));
-       pv    = (u1 *)                *((ptrint *) (sp + 0 * 4));
-
-       /* calculate and set the new return address */
-
-       ra = ra - 2 * 4;
-       *((ptrint *) (sp + 5 * 4)) = (ptrint) ra;
+       md_icacheflush(ra, 4);
 
-       PATCHER_MONITORENTER;
-
-       /* get the classinfo */
-
-       if (!(c = resolve_classref_eager(cr))) {
-               PATCHER_MONITOREXIT;
-
-               return false;
-       }
-
-       /* patch back original code */
-
-       *((u4 *) (ra + 4)) = mcode;
-
-       /* synchronize instruction cache */
-
-       asm_cacheflush(ra + 4, 4);
+       /* patch the classinfo pointer */
 
-       /* patch the class' vftbl pointer */
-       
-       *((ptrint *) (pv + (disp + SIZEOF_VOID_P))) = (ptrint) c->vftbl;
+       *((ptrint *) (pv + disp)) = (ptrint) c;
 
-       /* patch new function address */
+       /* synchronize data cache */
 
-       *((ptrint *) (pv + disp)) = (ptrint) BUILTIN_arrayinstanceof;
+       md_dcacheflush(pv + disp, SIZEOF_VOID_P);
 
        PATCHER_MARK_PATCHED_MONITOREXIT;
 
@@ -574,11 +421,6 @@ bool patcher_invokestatic_special(u1 *sp)
        disp  =                       *((s4 *)     (sp + 1 * 4));
        pv    = (u1 *)                *((ptrint *) (sp + 0 * 4));
 
-       /* calculate and set the new return address */
-
-       ra = ra - 4;
-       *((ptrint *) (sp + 5 * 4)) = (ptrint) ra;
-
        PATCHER_MONITORENTER;
 
        /* get the fieldinfo */
@@ -595,12 +437,16 @@ bool patcher_invokestatic_special(u1 *sp)
 
        /* synchronize instruction cache */
 
-       asm_cacheflush(ra, 4);
+       md_icacheflush(ra, 4);
 
        /* patch stubroutine */
 
        *((ptrint *) (pv + disp)) = (ptrint) m->stubroutine;
 
+       /* synchronize data cache */
+
+       md_dcacheflush(pv + disp, SIZEOF_VOID_P);
+
        PATCHER_MARK_PATCHED_MONITOREXIT;
 
        return true;
@@ -626,6 +472,7 @@ bool patcher_invokevirtual(u1 *sp)
        u4                 mcode;
        unresolved_method *um;
        methodinfo        *m;
+       s4                 disp;
 
        /* get stuff from the stack */
 
@@ -634,11 +481,6 @@ bool patcher_invokevirtual(u1 *sp)
        mcode =                       *((u4 *)     (sp + 3 * 4));
        um    = (unresolved_method *) *((ptrint *) (sp + 2 * 4));
 
-       /* calculate and set the new return address */
-
-       ra = ra - 4;
-       *((ptrint *) (sp + 5 * 4)) = (ptrint) ra;
-
        PATCHER_MONITORENTER;
 
        /* get the fieldinfo */
@@ -660,12 +502,13 @@ bool patcher_invokevirtual(u1 *sp)
 
        /* patch vftbl index */
 
-       *((s4 *) (ra + 4)) |= (s4) ((OFFSET(vftbl_t, table[0]) +
-                                                                sizeof(methodptr) * m->vftblindex) & 0x0000ffff);
+       disp = (OFFSET(vftbl_t, table[0]) + sizeof(methodptr) * m->vftblindex);
+
+       *((s4 *) (ra + 4)) |= (disp & 0x0000ffff);
 
        /* synchronize instruction cache */
 
-       asm_cacheflush(ra, 2 * 4);
+       md_icacheflush(ra, 2 * 4);
 
        PATCHER_MARK_PATCHED_MONITOREXIT;
 
@@ -693,6 +536,7 @@ bool patcher_invokeinterface(u1 *sp)
        u4                 mcode;
        unresolved_method *um;
        methodinfo        *m;
+       s4                 disp;
 
        /* get stuff from the stack */
 
@@ -701,11 +545,6 @@ bool patcher_invokeinterface(u1 *sp)
        mcode =                       *((u4 *)     (sp + 3 * 4));
        um    = (unresolved_method *) *((ptrint *) (sp + 2 * 4));
 
-       /* calculate and set the new return address */
-
-       ra = ra - 4;
-       *((ptrint *) (sp + 5 * 4)) = (ptrint) ra;
-
        PATCHER_MONITORENTER;
 
        /* get the fieldinfo */
@@ -727,17 +566,19 @@ bool patcher_invokeinterface(u1 *sp)
 
        /* patch interfacetable index */
 
-       *((s4 *) (ra + 1 * 4)) |= (s4) ((OFFSET(vftbl_t, interfacetable[0]) -
-                                                                sizeof(methodptr*) * m->class->index) & 0x0000ffff);
+       disp = (OFFSET(vftbl_t, interfacetable[0]) - sizeof(methodptr*) * m->class->index);
+
+       *((s4 *) (ra + 1 * 4)) |= (disp & 0x0000ffff);
 
        /* patch method offset */
 
-       *((s4 *) (ra + 2 * 4)) |=
-               (s4) ((sizeof(methodptr) * (m - m->class->methods)) & 0x0000ffff);
+       disp = (sizeof(methodptr) * (m - m->class->methods));
+
+       *((s4 *) (ra + 2 * 4)) |= (disp & 0x0000ffff);
 
        /* synchronize instruction cache */
 
-       asm_cacheflush(ra, 3 * 4);
+       md_icacheflush(ra, 3 * 4);
 
        PATCHER_MARK_PATCHED_MONITOREXIT;
 
@@ -773,11 +614,6 @@ bool patcher_checkcast_instanceof_flags(u1 *sp)
        disp  =                       *((s4 *)     (sp + 1 * 4));
        pv    = (u1 *)                *((ptrint *) (sp + 0 * 4));
 
-       /* calculate and set the new return address */
-
-       ra = ra - 4;
-       *((ptrint *) (sp + 5 * 4)) = (ptrint) ra;
-
        PATCHER_MONITORENTER;
 
        /* get the fieldinfo */
@@ -794,12 +630,16 @@ bool patcher_checkcast_instanceof_flags(u1 *sp)
 
        /* synchronize instruction cache */
 
-       asm_cacheflush(ra, 4);
+       md_icacheflush(ra, 4);
 
        /* patch class flags */
 
        *((s4 *) (pv + disp)) = (s4) c->flags;
 
+       /* synchronize data cache */
+
+       md_dcacheflush(pv + disp, SIZEOF_VOID_P);
+
        PATCHER_MARK_PATCHED_MONITOREXIT;
 
        return true;
@@ -826,6 +666,7 @@ bool patcher_checkcast_instanceof_interface(u1 *sp)
        u4                 mcode;
        constant_classref *cr;
        classinfo         *c;
+       s4                 disp;
 
        /* get stuff from the stack */
 
@@ -834,11 +675,6 @@ bool patcher_checkcast_instanceof_interface(u1 *sp)
        mcode =                       *((u4 *)     (sp + 3 * 4));
        cr    = (constant_classref *) *((ptrint *) (sp + 2 * 4));
 
-       /* calculate and set the new return address */
-
-       ra = ra - 4;
-       *((ptrint *) (sp + 5 * 4)) = (ptrint) ra;
-
        PATCHER_MONITORENTER;
 
        /* get the fieldinfo */
@@ -860,14 +696,17 @@ bool patcher_checkcast_instanceof_interface(u1 *sp)
 
        /* patch super class index */
 
-       *((s4 *) (ra + 2 * 4)) |= (s4) (-(c->index) & 0x0000ffff);
+       disp = -(c->index);
 
-       *((s4 *) (ra + 4 * 4)) |= (s4) ((OFFSET(vftbl_t, interfacetable[0]) -
-                                                                        c->index * sizeof(methodptr*)) & 0x0000ffff);
+       *((s4 *) (ra + 2 * 4)) |= (disp & 0x0000ffff);
+
+       disp = (OFFSET(vftbl_t, interfacetable[0]) - c->index * sizeof(methodptr*);
+
+       *((s4 *) (ra + 4 * 4)) |= (disp & 0x0000ffff);
 
        /* synchronize instruction cache */
 
-       asm_cacheflush(ra, 5 * 4);
+       md_icacheflush(ra, 5 * 4);
 
        PATCHER_MARK_PATCHED_MONITOREXIT;
 
@@ -905,11 +744,6 @@ bool patcher_checkcast_class(u1 *sp)
        disp  =                       *((s4 *)     (sp + 1 * 4));
        pv    = (u1 *)                *((ptrint *) (sp + 0 * 4));
 
-       /* calculate and set the new return address */
-
-       ra = ra - 4;
-       *((ptrint *) (sp + 5 * 4)) = (ptrint) ra;
-
        PATCHER_MONITORENTER;
 
        /* get the fieldinfo */
@@ -926,12 +760,16 @@ bool patcher_checkcast_class(u1 *sp)
 
        /* synchronize instruction cache */
 
-       asm_cacheflush(ra, 4);
+       md_icacheflush(ra, 4);
 
        /* patch super class' vftbl */
 
        *((ptrint *) (pv + disp)) = (ptrint) c->vftbl;
 
+       /* synchronize data cache */
+
+       md_dcacheflush(pv + disp, SIZEOF_VOID_P);
+
        PATCHER_MARK_PATCHED_MONITOREXIT;
 
        return true;
@@ -967,11 +805,6 @@ bool patcher_instanceof_class(u1 *sp)
        disp  =                       *((s4 *)     (sp + 1 * 4));
        pv    = (u1 *)                *((ptrint *) (sp + 0 * 4));
 
-       /* calculate and set the new return address */
-
-       ra = ra - 4;
-       *((ptrint *) (sp + 5 * 4)) = (ptrint) ra;
-
        PATCHER_MONITORENTER;
 
        /* get the fieldinfo */
@@ -988,12 +821,16 @@ bool patcher_instanceof_class(u1 *sp)
 
        /* synchronize instruction cache */
 
-       asm_cacheflush(ra, 4);
+       md_icacheflush(ra, 4);
 
        /* patch super class' vftbl */
 
        *((ptrint *) (pv + disp)) = (ptrint) c->vftbl;
 
+       /* synchronize data cache */
+
+       md_dcacheflush(pv + disp, SIZEOF_VOID_P);
+
        PATCHER_MARK_PATCHED_MONITOREXIT;
 
        return true;
@@ -1020,16 +857,11 @@ bool patcher_clinit(u1 *sp)
        mcode =                       *((u4 *)     (sp + 3 * 4));
        c     = (classinfo *)         *((ptrint *) (sp + 2 * 4));
 
-       /* calculate and set the new return address */
-
-       ra = ra - 4;
-       *((ptrint *) (sp + 5 * 4)) = (ptrint) ra;
-
        PATCHER_MONITORENTER;
 
        /* check if the class is initialized */
 
-       if (!c->initialized) {
+       if (!(c->state & CLASS_INITIALIZED)) {
                if (!initialize_class(c)) {
                        PATCHER_MONITOREXIT;
 
@@ -1043,7 +875,7 @@ bool patcher_clinit(u1 *sp)
 
        /* synchronize instruction cache */
 
-       asm_cacheflush(ra, 4);
+       md_icacheflush(ra, 4);
 
        PATCHER_MARK_PATCHED_MONITOREXIT;
 
@@ -1051,13 +883,62 @@ bool patcher_clinit(u1 *sp)
 }
 
 
+/* patcher_athrow_areturn ******************************************************
+
+   Machine code:
+
+   <patched call position>
+
+*******************************************************************************/
+
+#ifdef ENABLE_VERIFIER
+bool patcher_athrow_areturn(u1 *sp)
+{
+       u1                *ra;
+       java_objectheader *o;
+       u4                 mcode;
+       unresolved_class  *uc;
+       classinfo         *c;
+
+       /* get stuff from the stack */
+
+       ra    = (u1 *)                *((ptrint *) (sp + 5 * 4));
+       o     = (java_objectheader *) *((ptrint *) (sp + 4 * 4));
+       mcode =                       *((u4 *)     (sp + 3 * 4));
+       uc    = (unresolved_class *)  *((ptrint *) (sp + 2 * 4));
+
+       PATCHER_MONITORENTER;
+
+       /* resolve the class */
+
+       if (!resolve_class(uc, resolveEager, false, &c)) {
+               PATCHER_MONITOREXIT;
+
+               return false;
+       }
+
+       /* patch back original code */
+
+       *((u4 *) ra) = mcode;
+
+       /* synchronize instruction cache */
+
+       md_icacheflush(ra, 4);
+
+       PATCHER_MARK_PATCHED_MONITOREXIT;
+
+       return true;
+}
+#endif /* ENABLE_VERIFIER */
+
+
 /* patcher_resolve_native ******************************************************
 
    XXX
 
 *******************************************************************************/
 
-#if !defined(ENABLE_STATICVM)
+#if !defined(WITH_STATIC_CLASSPATH)
 bool patcher_resolve_native(u1 *sp)
 {
        u1                *ra;
@@ -1079,7 +960,7 @@ bool patcher_resolve_native(u1 *sp)
 
        /* calculate and set the new return address */
 
-       ra = ra - 4;
+       ra = ra - 1 * 4;
        *((ptrint *) (sp + 5 * 4)) = (ptrint) ra;
 
        PATCHER_MONITORENTER;
@@ -1098,17 +979,21 @@ bool patcher_resolve_native(u1 *sp)
 
        /* synchronize instruction cache */
 
-       asm_cacheflush(ra, 4);
+       md_icacheflush(ra, 4);
 
        /* patch native function pointer */
 
        *((ptrint *) (pv + disp)) = (ptrint) f;
 
+       /* synchronize data cache */
+
+       md_dcacheflush(pv + disp, SIZEOF_VOID_P);
+
        PATCHER_MARK_PATCHED_MONITOREXIT;
 
        return true;
 }
-#endif /* !defined(ENABLE_STATICVM) */
+#endif /* !defined(WITH_STATIC_CLASSPATH) */
 
 
 /*