Merged changes from trunk.
[cacao.git] / src / vm / jit / mips / patcher.c
index a3eb90bd83676d343f2c3a3bf3b8eb4ef45688a7..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 3812 2005-11-28 18:00:47Z edwin $
+   $Id: patcher.c 5319 2006-09-05 12:54:10Z twisti $
 
 */
 
 
-#include <sys/cachectl.h>
-
 #include "config.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/jit/patcher.h"
 
 
+/* patcher_wrapper *************************************************************
+
+   Wrapper for all patchers.  It also creates the stackframe info
+   structure.
+
+   If the return value of the patcher function is false, it gets the
+   exception object, clears the exception pointer and returns the
+   exception.
+
+*******************************************************************************/
+
+java_objectheader *patcher_wrapper(u1 *sp, u1 *pv, u1 *ra)
+{
+       stackframeinfo     sfi;
+       u1                *xpc;
+       java_objectheader *o;
+       functionptr        f;
+       bool               result;
+       java_objectheader *e;
+
+       /* define the patcher function */
+
+       bool (*patcher_function)(u1 *);
+
+       assert(pv != NULL);
+
+       /* get stuff from the stack */
+
+       xpc = (u1 *)                *((ptrint *) (sp + 5 * 8));
+       o   = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
+       f   = (functionptr)         *((ptrint *) (sp + 0 * 8));
+
+       /* store PV into the patcher function position */
+
+       *((ptrint *) (sp + 0 * 8)) = (ptrint) pv;
+
+       /* cast the passed function to a patcher function */
+
+       patcher_function = (bool (*)(u1 *)) (ptrint) f;
+
+       /* enter a monitor on the patching position */
+
+       PATCHER_MONITORENTER;
+
+       /* create the stackframeinfo */
+
+       stacktrace_create_extern_stackframeinfo(&sfi, pv, sp + 6 * 8, ra, xpc);
+
+       /* call the proper patcher function */
+
+       result = (patcher_function)(sp);
+
+       /* remove the stackframeinfo */
+
+       stacktrace_remove_stackframeinfo(&sfi);
+
+       /* check for return value and exit accordingly */
+
+       if (result == false) {
+               e = exceptions_get_and_clear_exception();
+
+               PATCHER_MONITOREXIT;
+
+               return e;
+       }
+
+       PATCHER_MARK_PATCHED_MONITOREXIT;
+
+       return NULL;
+}
+
+
 /* patcher_get_putstatic *******************************************************
 
    Machine code:
 
 bool patcher_get_putstatic(u1 *sp)
 {
-       u1                *ra;
-       java_objectheader *o;
-#if SIZEOF_VOID_P == 8
-       u8                 mcode;
-#else
-       u4                 mcode[2];
-#endif
-       unresolved_field  *uf;
-       s4                 disp;
-       u1                *pv;
-       fieldinfo         *fi;
+       u1               *ra;
+       u4                mcode[2];
+       unresolved_field *uf;
+       s4                disp;
+       u1               *pv;
+       fieldinfo        *fi;
 
        /* get stuff from the stack */
 
-       ra       = (u1 *)                *((ptrint *) (sp + 5 * 8));
-       o        = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
-#if SIZEOF_VOID_P == 8
-       mcode    =                       *((u8 *)     (sp + 3 * 8));
-#else
-       mcode[0] =                       *((u4 *)     (sp + 3 * 8));
-       mcode[1] =                       *((u4 *)     (sp + 3 * 8 + 4));
-#endif
-       uf       = (unresolved_field *)  *((ptrint *) (sp + 2 * 8));
-       disp     =                       *((s4 *)     (sp + 1 * 8));
-       pv       = (u1 *)                *((ptrint *) (sp + 0 * 8));
-
-       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 = resolve_field_eager(uf))) {
-               PATCHER_MONITOREXIT;
-
+       if (!(fi = resolve_field_eager(uf)))
                return false;
-       }
 
        /* check if the field's class is initialized */
 
-       if (!fi->class->initialized) {
-               if (!initialize_class(fi->class)) {
-                       PATCHER_MONITOREXIT;
-
+       if (!(fi->class->state & CLASS_INITIALIZED))
+               if (!initialize_class(fi->class))
                        return false;
-               }
-       }
 
        /* patch back original code */
 
-#if SIZEOF_VOID_P == 8
-       *((u4 *) (ra + 0 * 4)) = mcode;
-       *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
        *((u4 *) (ra + 0 * 4)) = mcode[0];
        *((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
 
        /* synchronize instruction cache */
 
-       cacheflush(ra, 2 * 4, ICACHE);
+       md_icacheflush(ra, 2 * 4);
 
        /* patch the field value's address */
 
@@ -128,9 +179,7 @@ bool patcher_get_putstatic(u1 *sp)
 
        /* synchronize data cache */
 
-       cacheflush(pv + disp, SIZEOF_VOID_P, DCACHE);
-
-       PATCHER_MARK_PATCHED_MONITOREXIT;
+       md_dcacheflush(pv + disp, SIZEOF_VOID_P);
 
        return true;
 }
@@ -147,45 +196,25 @@ bool patcher_get_putstatic(u1 *sp)
 
 bool patcher_get_putfield(u1 *sp)
 {
-       u1                *ra;
-       java_objectheader *o;
-#if SIZEOF_VOID_P == 8
-       u8                 mcode;
-#else
-       u4                 mcode[2];
-#endif
-       unresolved_field  *uf;
-       fieldinfo         *fi;
+       u1               *ra;
+       u4                mcode[2];
+       unresolved_field *uf;
+       fieldinfo        *fi;
 
-       ra       = (u1 *)                *((ptrint *) (sp + 5 * 8));
-       o        = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
-#if SIZEOF_VOID_P == 8
-       mcode    =                       *((u8 *)     (sp + 3 * 8));
-#else
-       mcode[0] =                       *((u4 *)     (sp + 3 * 8));
-       mcode[1] =                       *((u4 *)     (sp + 3 * 8 + 4));
-#endif
-       uf       = (unresolved_field *)  *((ptrint *) (sp + 2 * 8));
-
-       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));
 
        /* get the fieldinfo */
 
-       if (!(fi = resolve_field_eager(uf))) {
-               PATCHER_MONITOREXIT;
-
+       if (!(fi = resolve_field_eager(uf)))
                return false;
-       }
 
        /* patch back original code */
 
-#if SIZEOF_VOID_P == 8
-       *((u4 *) (ra + 0 * 4)) = mcode;
-       *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
        *((u4 *) (ra + 0 * 4)) = mcode[0];
        *((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
 
        /* if we show disassembly, we have to skip the nop's */
 
@@ -213,16 +242,15 @@ bool patcher_get_putfield(u1 *sp)
 
        if (opt_showdisassemble) {
 #if SIZEOF_VOID_P == 4
-               if (fi->type == TYPE_LNG) {
-                       cacheflush(ra - 2 * 4, 4 * 4, ICACHE);
-               else
+               if (fi->type == TYPE_LNG)
+                       md_icacheflush(ra - 2 * 4, 4 * 4);
+               else
 #endif
-                       cacheflush(ra - 2 * 4, 3 * 4, ICACHE);
-       } else {
-               cacheflush(ra, 2 * 4, ICACHE);
+                       md_icacheflush(ra - 2 * 4, 3 * 4);
+       }
+       else {
+               md_icacheflush(ra, 2 * 4);
        }
-
-       PATCHER_MARK_PATCHED_MONITOREXIT;
 
        return true;
 }
@@ -240,12 +268,7 @@ bool patcher_get_putfield(u1 *sp)
 bool patcher_aconst(u1 *sp)
 {
        u1                *ra;
-       java_objectheader *o;
-#if SIZEOF_VOID_P == 8
-       u8                 mcode;
-#else
        u4                 mcode[2];
-#endif
        constant_classref *cr;
        s4                 disp;
        u1                *pv;
@@ -254,40 +277,25 @@ bool patcher_aconst(u1 *sp)
        /* get stuff from the stack */
 
        ra       = (u1 *)                *((ptrint *) (sp + 5 * 8));
-       o        = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
-#if SIZEOF_VOID_P == 8
-       mcode    =                       *((u8 *)     (sp + 3 * 8));
-#else
        mcode[0] =                       *((u4 *)     (sp + 3 * 8));
        mcode[1] =                       *((u4 *)     (sp + 3 * 8 + 4));
-#endif
        cr       = (constant_classref *) *((ptrint *) (sp + 2 * 8));
        disp     =                       *((s4 *)     (sp + 1 * 8));
        pv       = (u1 *)                *((ptrint *) (sp + 0 * 8));
 
-       PATCHER_MONITORENTER;
-
        /* get the classinfo */
 
-       if (!(c = resolve_classref_eager(cr))) {
-               PATCHER_MONITOREXIT;
-
+       if (!(c = resolve_classref_eager(cr)))
                return false;
-       }
 
        /* patch back original code */
 
-#if SIZEOF_VOID_P == 8
-       *((u4 *) (ra + 0 * 4)) = mcode;
-       *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
        *((u4 *) (ra + 0 * 4)) = mcode[0];
        *((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
 
        /* synchronize instruction cache */
 
-       cacheflush(ra, 2 * 4, ICACHE);
+       md_icacheflush(ra, 2 * 4);
 
        /* patch the classinfo pointer */
 
@@ -295,9 +303,7 @@ bool patcher_aconst(u1 *sp)
 
        /* synchronize data cache */
 
-       cacheflush(pv + disp, SIZEOF_VOID_P * 1, DCACHE);
-
-       PATCHER_MARK_PATCHED_MONITOREXIT;
+       md_dcacheflush(pv + disp, SIZEOF_VOID_P);
 
        return true;
 }
@@ -319,12 +325,7 @@ bool patcher_aconst(u1 *sp)
 bool patcher_builtin_multianewarray(u1 *sp)
 {
        u1                *ra;
-       java_objectheader *o;
-#if SIZEOF_VOID_P == 8
-       u8                 mcode;
-#else  
        u4                 mcode[2];
-#endif
        constant_classref *cr;
        s4                 disp;
        u1                *pv;
@@ -333,40 +334,25 @@ bool patcher_builtin_multianewarray(u1 *sp)
        /* get stuff from the stack */
 
        ra       = (u1 *)                *((ptrint *) (sp + 5 * 8));
-       o        = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
-#if SIZEOF_VOID_P == 8
-       mcode    =                       *((u8 *)     (sp + 3 * 8));
-#else
        mcode[0] =                       *((u4 *)     (sp + 3 * 8));
        mcode[1] =                       *((u4 *)     (sp + 3 * 8 + 4));
-#endif
        cr       = (constant_classref *) *((ptrint *) (sp + 2 * 8));
        disp     =                       *((s4 *)     (sp + 1 * 8));
        pv       = (u1 *)                *((ptrint *) (sp + 0 * 8));
 
-       PATCHER_MONITORENTER;
-
        /* get the classinfo */
 
-       if (!(c = resolve_classref_eager(cr))) {
-               PATCHER_MONITOREXIT;
-
+       if (!(c = resolve_classref_eager(cr)))
                return false;
-       }
 
        /* patch back original code */
 
-#if SIZEOF_VOID_P == 8
-       *((u4 *) (ra + 0 * 4)) = mcode;
-       *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
        *((u4 *) (ra + 0 * 4)) = mcode[0];
        *((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
 
        /* synchronize instruction cache */
 
-       cacheflush(ra, 2 * 4, ICACHE);
+       md_icacheflush(ra, 2 * 4);
 
        /* patch the classinfo pointer */
 
@@ -374,9 +360,7 @@ bool patcher_builtin_multianewarray(u1 *sp)
 
        /* synchronize data cache */
 
-       cacheflush(pv + disp, SIZEOF_VOID_P, DCACHE);
-
-       PATCHER_MARK_PATCHED_MONITOREXIT;
+       md_dcacheflush(pv + disp, SIZEOF_VOID_P);
 
        return true;
 }
@@ -397,12 +381,7 @@ bool patcher_builtin_multianewarray(u1 *sp)
 bool patcher_builtin_arraycheckcast(u1 *sp)
 {
        u1                *ra;
-       java_objectheader *o;
-#if SIZEOF_VOID_P == 8
-       u8                 mcode;
-#else
        u4                 mcode[2];
-#endif
        constant_classref *cr;
        s4                 disp;
        u1                *pv;
@@ -411,40 +390,25 @@ bool patcher_builtin_arraycheckcast(u1 *sp)
        /* get stuff from the stack */
 
        ra       = (u1 *)                *((ptrint *) (sp + 5 * 8));
-       o        = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
-#if SIZEOF_VOID_P == 8
-       mcode    =                       *((u8 *)     (sp + 3 * 8));
-#else
        mcode[0] =                       *((u4 *)     (sp + 3 * 8));
        mcode[1] =                       *((u4 *)     (sp + 3 * 8 + 4));
-#endif
        cr       = (constant_classref *) *((ptrint *) (sp + 2 * 8));
        disp     =                       *((s4 *)     (sp + 1 * 8));
        pv       = (u1 *)                *((ptrint *) (sp + 0 * 8));
 
-       PATCHER_MONITORENTER;
-
        /* get the classinfo */
 
-       if (!(c = resolve_classref_eager(cr))) {
-               PATCHER_MONITOREXIT;
-
+       if (!(c = resolve_classref_eager(cr)))
                return false;
-       }
 
        /* patch back original code */
 
-#if SIZEOF_VOID_P == 8
-       *((u4 *) (ra + 0 * 4)) = mcode;
-       *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
        *((u4 *) (ra + 0 * 4)) = mcode[0];
        *((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
 
        /* synchronize instruction cache */
 
-       cacheflush(ra, 2 * 4, ICACHE);
+       md_icacheflush(ra, 2 * 4);
 
        /* patch the classinfo pointer */
 
@@ -452,9 +416,7 @@ bool patcher_builtin_arraycheckcast(u1 *sp)
 
        /* synchronize data cache */
 
-       cacheflush(pv + disp, SIZEOF_VOID_P * 1, DCACHE);
-
-       PATCHER_MARK_PATCHED_MONITOREXIT;
+       md_dcacheflush(pv + disp, SIZEOF_VOID_P);
 
        return true;
 }
@@ -474,12 +436,7 @@ bool patcher_builtin_arraycheckcast(u1 *sp)
 bool patcher_invokestatic_special(u1 *sp)
 {
        u1                *ra;
-       java_objectheader *o;
-#if SIZEOF_VOID_P == 8
-       u8                 mcode;
-#else
        u4                 mcode[2];
-#endif
        unresolved_method *um;
        s4                 disp;
        u1                *pv;
@@ -488,40 +445,25 @@ bool patcher_invokestatic_special(u1 *sp)
        /* get stuff from the stack */
 
        ra       = (u1 *)                *((ptrint *) (sp + 5 * 8));
-       o        = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
-#if SIZEOF_VOID_P == 8
-       mcode    =                       *((u8 *)     (sp + 3 * 8));
-#else
        mcode[0] =                       *((u4 *)     (sp + 3 * 8));
        mcode[1] =                       *((u4 *)     (sp + 3 * 8 + 4));
-#endif
        um       = (unresolved_method *) *((ptrint *) (sp + 2 * 8));
        disp     =                       *((s4 *)     (sp + 1 * 8));
        pv       = (u1 *)                *((ptrint *) (sp + 0 * 8));
 
-       PATCHER_MONITORENTER;
-
        /* get the fieldinfo */
 
-       if (!(m = resolve_method_eager(um))) {
-               PATCHER_MONITOREXIT;
-
+       if (!(m = resolve_method_eager(um)))
                return false;
-       }
 
        /* patch back original code */
 
-#if SIZEOF_VOID_P == 8
-       *((u4 *) (ra + 0 * 4)) = mcode;
-       *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
        *((u4 *) (ra + 0 * 4)) = mcode[0];
        *((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
 
        /* synchronize instruction cache */
 
-       cacheflush(ra, 2 * 4, ICACHE);
+       md_icacheflush(ra, 2 * 4);
 
        /* patch stubroutine */
 
@@ -529,9 +471,7 @@ bool patcher_invokestatic_special(u1 *sp)
 
        /* synchronize data cache */
 
-       cacheflush(pv + disp, SIZEOF_VOID_P, DCACHE);
-
-       PATCHER_MARK_PATCHED_MONITOREXIT;
+       md_dcacheflush(pv + disp, SIZEOF_VOID_P);
 
        return true;
 }
@@ -552,46 +492,26 @@ bool patcher_invokestatic_special(u1 *sp)
 bool patcher_invokevirtual(u1 *sp)
 {
        u1                *ra;
-       java_objectheader *o;
-#if SIZEOF_VOID_P == 8
-       u8                 mcode;
-#else
        u4                 mcode[2];
-#endif
        unresolved_method *um;
        methodinfo        *m;
 
        /* get stuff from the stack */
 
        ra       = (u1 *)                *((ptrint *) (sp + 5 * 8));
-       o        = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
-#if SIZEOF_VOID_P == 8
-       mcode    =                       *((u8 *)     (sp + 3 * 8));
-#else
        mcode[0] =                       *((u4 *)     (sp + 3 * 8));
        mcode[1] =                       *((u4 *)     (sp + 3 * 8 + 4));
-#endif
        um       = (unresolved_method *) *((ptrint *) (sp + 2 * 8));
 
-       PATCHER_MONITORENTER;
-
        /* get the fieldinfo */
 
-       if (!(m = resolve_method_eager(um))) {
-               PATCHER_MONITOREXIT;
-
+       if (!(m = resolve_method_eager(um)))
                return false;
-       }
 
        /* patch back original code */
 
-#if SIZEOF_VOID_P == 8
-       *((u4 *) (ra + 0 * 4)) = mcode;
-       *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
        *((u4 *) (ra + 0 * 4)) = mcode[0];
        *((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
 
        /* if we show disassembly, we have to skip the nop's */
 
@@ -606,11 +526,9 @@ bool patcher_invokevirtual(u1 *sp)
        /* synchronize instruction cache */
 
        if (opt_showdisassemble)
-               cacheflush(ra - 2 * 4, 4 * 4, ICACHE);
+               md_icacheflush(ra - 2 * 4, 4 * 4);
        else
-               cacheflush(ra, 2 * 4, ICACHE);
-
-       PATCHER_MARK_PATCHED_MONITOREXIT;
+               md_icacheflush(ra, 2 * 4);
 
        return true;
 }
@@ -632,46 +550,26 @@ bool patcher_invokevirtual(u1 *sp)
 bool patcher_invokeinterface(u1 *sp)
 {
        u1                *ra;
-       java_objectheader *o;
-#if SIZEOF_VOID_P == 8
-       u8                 mcode;
-#else
        u4                 mcode[2];
-#endif
        unresolved_method *um;
        methodinfo        *m;
 
        /* get stuff from the stack */
 
        ra       = (u1 *)                *((ptrint *) (sp + 5 * 8));
-       o        = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
-#if SIZEOF_VOID_P == 8
-       mcode    =                       *((u8 *)     (sp + 3 * 8));
-#else
        mcode[0] =                       *((u4 *)     (sp + 3 * 8));
        mcode[1] =                       *((u4 *)     (sp + 3 * 8 + 4));
-#endif
        um       = (unresolved_method *) *((ptrint *) (sp + 2 * 8));
 
-       PATCHER_MONITORENTER;
-
        /* get the fieldinfo */
 
-       if (!(m = resolve_method_eager(um))) {
-               PATCHER_MONITOREXIT;
-
+       if (!(m = resolve_method_eager(um)))
                return false;
-       }
 
        /* patch back original code */
 
-#if SIZEOF_VOID_P == 8
-       *((u4 *) (ra + 0 * 4)) = mcode;
-       *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
        *((u4 *) (ra + 0 * 4)) = mcode[0];
        *((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
 
        /* if we show disassembly, we have to skip the nop's */
 
@@ -691,11 +589,9 @@ bool patcher_invokeinterface(u1 *sp)
        /* synchronize instruction cache */
 
        if (opt_showdisassemble)
-               cacheflush(ra - 2 * 4, 5 * 4, ICACHE);
+               md_icacheflush(ra - 2 * 4, 5 * 4);
        else
-               cacheflush(ra, 3 * 4, ICACHE);
-
-       PATCHER_MARK_PATCHED_MONITOREXIT;
+               md_icacheflush(ra, 3 * 4);
 
        return true;
 }
@@ -716,12 +612,7 @@ bool patcher_invokeinterface(u1 *sp)
 bool patcher_checkcast_instanceof_flags(u1 *sp)
 {
        u1                *ra;
-       java_objectheader *o;
-#if SIZEOF_VOID_P == 8
-       u8                 mcode;
-#else
        u4                 mcode[2];
-#endif
        constant_classref *cr;
        s4                 disp;
        u1                *pv;
@@ -730,40 +621,25 @@ bool patcher_checkcast_instanceof_flags(u1 *sp)
        /* get stuff from the stack */
 
        ra       = (u1 *)                *((ptrint *) (sp + 5 * 8));
-       o        = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
-#if SIZEOF_VOID_P == 8
-       mcode    =                       *((u8 *)     (sp + 3 * 8));
-#else
        mcode[0] =                       *((u4 *)     (sp + 3 * 8));
        mcode[1] =                       *((u4 *)     (sp + 3 * 8 + 4));
-#endif
        cr       = (constant_classref *) *((ptrint *) (sp + 2 * 8));
        disp     =                       *((s4 *)     (sp + 1 * 8));
        pv       = (u1 *)                *((ptrint *) (sp + 0 * 8));
 
-       PATCHER_MONITORENTER;
-
        /* get the fieldinfo */
 
-       if (!(c = resolve_classref_eager(cr))) {
-               PATCHER_MONITOREXIT;
-
+       if (!(c = resolve_classref_eager(cr)))
                return false;
-       }
 
        /* patch back original code */
 
-#if SIZEOF_VOID_P == 8
-       *((u4 *) (ra + 0 * 4)) = mcode;
-       *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
        *((u4 *) (ra + 0 * 4)) = mcode[0];
        *((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
 
        /* synchronize instruction cache */
 
-       cacheflush(ra, 2 * 4, ICACHE);
+       md_icacheflush(ra, 2 * 4);
 
        /* patch class flags */
 
@@ -771,9 +647,7 @@ bool patcher_checkcast_instanceof_flags(u1 *sp)
 
        /* synchronize data cache */
 
-       cacheflush(pv + disp, sizeof(s4), DCACHE);
-
-       PATCHER_MARK_PATCHED_MONITOREXIT;
+       md_dcacheflush(pv + disp, sizeof(s4));
 
        return true;
 }
@@ -796,46 +670,26 @@ bool patcher_checkcast_instanceof_flags(u1 *sp)
 bool patcher_checkcast_instanceof_interface(u1 *sp)
 {
        u1                *ra;
-       java_objectheader *o;
-#if SIZEOF_VOID_P == 8
-       u8                 mcode;
-#else
        u4                 mcode[2];
-#endif
        constant_classref *cr;
        classinfo         *c;
 
        /* get stuff from the stack */
 
        ra       = (u1 *)                *((ptrint *) (sp + 5 * 8));
-       o        = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
-#if SIZEOF_VOID_P == 8
-       mcode    =                       *((u8 *)     (sp + 3 * 8));
-#else
        mcode[0] =                       *((u4 *)     (sp + 3 * 8));
        mcode[1] =                       *((u4 *)     (sp + 3 * 8 + 4));
-#endif
        cr       = (constant_classref *) *((ptrint *) (sp + 2 * 8));
 
-       PATCHER_MONITORENTER;
-
        /* get the fieldinfo */
 
-       if (!(c = resolve_classref_eager(cr))) {
-               PATCHER_MONITOREXIT;
-
+       if (!(c = resolve_classref_eager(cr)))
                return false;
-       }
 
        /* patch back original code */
 
-#if SIZEOF_VOID_P == 8
-       *((u4 *) (ra + 0 * 4)) = mcode;
-       *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
        *((u4 *) (ra + 0 * 4)) = mcode[0];
        *((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
 
        /* if we show disassembly, we have to skip the nop's */
 
@@ -852,11 +706,9 @@ bool patcher_checkcast_instanceof_interface(u1 *sp)
        /* synchronize instruction cache */
 
        if (opt_showdisassemble)
-               cacheflush(ra - 2 * 4, 8 * 4, ICACHE);
+               md_icacheflush(ra - 2 * 4, 8 * 4);
        else
-               cacheflush(ra, 6 * 4, ICACHE);
-
-       PATCHER_MARK_PATCHED_MONITOREXIT;
+               md_icacheflush(ra, 6 * 4);
 
        return true;
 }
@@ -875,12 +727,7 @@ bool patcher_checkcast_instanceof_interface(u1 *sp)
 bool patcher_checkcast_instanceof_class(u1 *sp)
 {
        u1                *ra;
-       java_objectheader *o;
-#if SIZEOF_VOID_P == 8
-       u8                 mcode;
-#else
        u4                 mcode[2];
-#endif
        constant_classref *cr;
        s4                 disp;
        u1                *pv;
@@ -889,40 +736,25 @@ bool patcher_checkcast_instanceof_class(u1 *sp)
        /* get stuff from the stack */
 
        ra       = (u1 *)                *((ptrint *) (sp + 5 * 8));
-       o        = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
-#if SIZEOF_VOID_P == 8
-       mcode    =                       *((u8 *)     (sp + 3 * 8));
-#else
        mcode[0] =                       *((u4 *)     (sp + 3 * 8));
        mcode[1] =                       *((u4 *)     (sp + 3 * 8 + 4));
-#endif
        cr       = (constant_classref *) *((ptrint *) (sp + 2 * 8));
        disp     =                       *((s4 *)     (sp + 1 * 8));
        pv       = (u1 *)                *((ptrint *) (sp + 0 * 8));
 
-       PATCHER_MONITORENTER;
-
        /* get the fieldinfo */
 
-       if (!(c = resolve_classref_eager(cr))) {
-               PATCHER_MONITOREXIT;
-
+       if (!(c = resolve_classref_eager(cr)))
                return false;
-       }
 
        /* patch back original code */
 
-#if SIZEOF_VOID_P == 8
-       *((u4 *) (ra + 0 * 4)) = mcode;
-       *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
        *((u4 *) (ra + 0 * 4)) = mcode[0];
        *((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
 
        /* synchronize instruction cache */
 
-       cacheflush(ra, 2 * 4, ICACHE);
+       md_icacheflush(ra, 2 * 4);
 
        /* patch super class' vftbl */
 
@@ -930,9 +762,7 @@ bool patcher_checkcast_instanceof_class(u1 *sp)
 
        /* synchronize data cache */
 
-       cacheflush(pv + disp, SIZEOF_VOID_P, DCACHE);
-
-       PATCHER_MARK_PATCHED_MONITOREXIT;
+       md_dcacheflush(pv + disp, SIZEOF_VOID_P);
 
        return true;
 }
@@ -946,54 +776,31 @@ bool patcher_checkcast_instanceof_class(u1 *sp)
 
 bool patcher_clinit(u1 *sp)
 {
-       u1                *ra;
-       java_objectheader *o;
-#if SIZEOF_VOID_P == 8
-       u8                 mcode;
-#else
-       u4                 mcode[2];
-#endif
-       classinfo         *c;
+       u1        *ra;
+       u4         mcode[2];
+       classinfo *c;
 
        /* get stuff from the stack */
 
-       ra       = (u1 *)                *((ptrint *) (sp + 5 * 8));
-       o        = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
-#if SIZEOF_VOID_P == 8
-       mcode    =                       *((u8 *)     (sp + 3 * 8));
-#else
-       mcode[0] =                       *((u4 *)     (sp + 3 * 8));
-       mcode[1] =                       *((u4 *)     (sp + 3 * 8 + 4));
-#endif
-       c        = (classinfo *)         *((ptrint *) (sp + 2 * 8));
-
-       PATCHER_MONITORENTER;
+       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));
 
        /* check if the class is initialized */
 
-       if (!c->initialized) {
-               if (!initialize_class(c)) {
-                       PATCHER_MONITOREXIT;
-
+       if (!(c->state & CLASS_INITIALIZED))
+               if (!initialize_class(c))
                        return false;
-               }
-       }
 
        /* patch back original code */
 
-#if SIZEOF_VOID_P == 8
-       *((u4 *) (ra + 0 * 4)) = mcode;
-       *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
        *((u4 *) (ra + 0 * 4)) = mcode[0];
        *((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
 
        /* synchronize instruction cache */
 
-       cacheflush(ra, 2 * 4, ICACHE);
-
-       PATCHER_MARK_PATCHED_MONITOREXIT;
+       md_icacheflush(ra, 2 * 4);
 
        return true;
 }
@@ -1010,53 +817,31 @@ bool patcher_clinit(u1 *sp)
 #ifdef ENABLE_VERIFIER
 bool patcher_athrow_areturn(u1 *sp)
 {
-       u1                *ra;
-       java_objectheader *o;
-#if SIZEOF_VOID_P == 8
-       u8                 mcode;
-#else
-       u4                 mcode[2];
-#endif
-       unresolved_class  *uc;
-       classinfo         *c;
+       u1               *ra;
+       u4                mcode[2];
+       unresolved_class *uc;
+       classinfo        *c;
 
        /* get stuff from the stack */
 
-       ra       = (u1 *)                *((ptrint *) (sp + 5 * 8));
-       o        = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
-#if SIZEOF_VOID_P == 8
-       mcode    =                       *((u8 *)     (sp + 3 * 8));
-#else
-       mcode[0] =                       *((u4 *)     (sp + 3 * 8));
-       mcode[1] =                       *((u4 *)     (sp + 3 * 8 + 4));
-#endif
-       uc       = (unresolved_class *)  *((ptrint *) (sp + 2 * 8));
-
-       PATCHER_MONITORENTER;
+       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)) {
-               PATCHER_MONITOREXIT;
-
+       if (!resolve_class(uc, resolveEager, false, &c))
                return false;
-       }
 
        /* patch back original code */
 
-#if SIZEOF_VOID_P == 8
-       *((u4 *) (ra + 0 * 4)) = mcode;
-       *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
        *((u4 *) (ra + 0 * 4)) = mcode[0];
        *((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
 
        /* synchronize instruction cache */
 
-       cacheflush(ra, 2 * 4, ICACHE);
-
-       PATCHER_MARK_PATCHED_MONITOREXIT;
+       md_icacheflush(ra, 2 * 4);
 
        return true;
 }
@@ -1069,63 +854,38 @@ bool patcher_athrow_areturn(u1 *sp)
 
 *******************************************************************************/
 
-#if !defined(ENABLE_STATICVM)
+#if !defined(WITH_STATIC_CLASSPATH)
 bool patcher_resolve_native(u1 *sp)
 {
-       u1                *ra;
-       java_objectheader *o;
-#if SIZEOF_VOID_P == 8
-       u8                 mcode;
-#else
-       u4                 mcode[2];
-#endif
-       methodinfo        *m;
-       s4                 disp;
-       u1                *pv;
-       functionptr        f;
+       u1          *ra;
+       u4           mcode[2];
+       methodinfo  *m;
+       s4           disp;
+       u1          *pv;
+       functionptr  f;
 
        /* get stuff from the stack */
 
-       ra       = (u1 *)                *((ptrint *) (sp + 5 * 8));
-       o        = (java_objectheader *) *((ptrint *) (sp + 4 * 8));
-#if SIZEOF_VOID_P == 8
-       mcode    =                       *((u8 *)     (sp + 3 * 8));
-#else
-       mcode[0] =                       *((u4 *)     (sp + 3 * 8));
-       mcode[1] =                       *((u4 *)     (sp + 3 * 8 + 4));
-#endif
-       m        = (methodinfo *)        *((ptrint *) (sp + 2 * 8));
-       disp     =                       *((s4 *)     (sp + 1 * 8));
-       pv       = (u1 *)                *((ptrint *) (sp + 0 * 8));
-
-       /* calculate and set the new return address */
-
-       ra = ra - 2 * 4;
-       *((ptrint *) (sp + 5 * 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 */
 
-#if SIZEOF_VOID_P == 8
-       *((u4 *) (ra + 0 * 4)) = mcode;
-       *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
        *((u4 *) (ra + 0 * 4)) = mcode[0];
        *((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
 
        /* synchronize instruction cache */
 
-       cacheflush(ra, 2 * 4, ICACHE);
+       md_icacheflush(ra, 2 * 4);
 
        /* patch native function pointer */
 
@@ -1133,13 +893,11 @@ bool patcher_resolve_native(u1 *sp)
 
        /* synchronize data cache */
 
-       cacheflush(pv + disp, SIZEOF_VOID_P, DCACHE);
-
-       PATCHER_MARK_PATCHED_MONITOREXIT;
+       md_dcacheflush(pv + disp, SIZEOF_VOID_P);
 
        return true;
 }
-#endif /* !defined(ENABLE_STATICVM) */
+#endif /* !defined(WITH_STATIC_CLASSPATH) */
 
 
 /*