* Updated header: Added 2006. Changed address of FSF. Changed email
[cacao.git] / src / vm / jit / powerpc / patcher.c
index f038de11ae807d551348db01b2d94c99f8a10464..ead5e5e04f534120ae5c2a08d8fdba3abbd6f962 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 2683 2005-06-14 17:20:56Z twisti $
+   $Id: patcher.c 4357 2006-01-22 23:33:38Z twisti $
 
 */
 
 
-#include "vm/jit/powerpc/types.h"
+#include "config.h"
+#include "vm/types.h"
 
 #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"
 
 
@@ -63,28 +65,24 @@ bool patcher_get_putstatic(u1 *sp)
        java_objectheader *o;
        u4                 mcode;
        unresolved_field  *uf;
+       s4                 disp;
        u1                *pv;
        fieldinfo         *fi;
-       s2                 offset;
 
        /* get stuff from the stack */
 
-       ra    = (u1 *)                *((ptrint *) (sp + 3 * 4));
-       o     = (java_objectheader *) *((ptrint *) (sp + 2 * 4));
-       mcode =                       *((u4 *)     (sp + 1 * 4));
-       uf    = (unresolved_field *)  *((ptrint *) (sp + 0 * 4));
-       pv    = (u1 *)                *((ptrint *) (sp - 2 * 4));
-
-       /* calculate and set the new return address */
-
-       ra = ra - 4;
-       *((ptrint *) (sp + 3 * 4)) = (ptrint) ra;
+       ra    = (u1 *)                *((ptrint *) (sp + 5 * 4));
+       o     = (java_objectheader *) *((ptrint *) (sp + 4 * 4));
+       mcode =                       *((u4 *)     (sp + 3 * 4));
+       uf    = (unresolved_field *)  *((ptrint *) (sp + 2 * 4));
+       disp  =                       *((s4 *)     (sp + 1 * 4));
+       pv    = (u1 *)                *((ptrint *) (sp + 0 * 4));
 
        PATCHER_MONITORENTER;
 
        /* get the fieldinfo */
 
-       if (!(fi = helper_resolve_fieldinfo(uf))) {
+       if (!(fi = resolve_field_eager(uf))) {
                PATCHER_MONITOREXIT;
 
                return false;
@@ -92,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;
 
@@ -104,22 +102,13 @@ bool patcher_get_putstatic(u1 *sp)
 
        *((u4 *) ra) = mcode;
 
-       /* if we show disassembly, we have to skip the nop */
-
-       if (showdisassemble)
-               ra = ra + 4;
-
-       /* get the offset from machine instruction */
+       /* synchronize instruction cache */
 
-       offset = (s2) (*((u4 *) ra) & 0x0000ffff);
+       asm_cacheflush(ra, 4);
 
        /* patch the field value's address */
 
-       *((ptrint *) (pv + offset)) = (ptrint) &(fi->value);
-
-       /* synchronize instruction cache */
-
-       asm_cacheflush(ra, 4);
+       *((ptrint *) (pv + disp)) = (ptrint) &(fi->value);
 
        PATCHER_MARK_PATCHED_MONITOREXIT;
 
@@ -145,22 +134,17 @@ bool patcher_get_putfield(u1 *sp)
        u1                *pv;
        fieldinfo         *fi;
 
-       ra    = (u1 *)                *((ptrint *) (sp + 3 * 4));
-       o     = (java_objectheader *) *((ptrint *) (sp + 2 * 4));
-       mcode =                       *((u4 *)     (sp + 1 * 4));
-       uf    = (unresolved_field *)  *((ptrint *) (sp + 0 * 4));
-       pv    = (u1 *)                *((ptrint *) (sp - 2 * 4));
-
-       /* calculate and set the new return address */
-
-       ra = ra - 4;
-       *((ptrint *) (sp + 3 * 4)) = (ptrint) ra;
+       ra    = (u1 *)                *((ptrint *) (sp + 5 * 4));
+       o     = (java_objectheader *) *((ptrint *) (sp + 4 * 4));
+       mcode =                       *((u4 *)     (sp + 3 * 4));
+       uf    = (unresolved_field *)  *((ptrint *) (sp + 2 * 4));
+       pv    = (u1 *)                *((ptrint *) (sp + 1 * 4));
 
        PATCHER_MONITORENTER;
 
        /* get the fieldinfo */
 
-       if (!(fi = helper_resolve_fieldinfo(uf))) {
+       if (!(fi = resolve_field_eager(uf))) {
                PATCHER_MONITOREXIT;
 
                return false;
@@ -172,17 +156,20 @@ bool patcher_get_putfield(u1 *sp)
 
        /* if we show disassembly, we have to skip the nop */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 4;
 
        /* patch the field's offset */
 
-       *((u4 *) ra) |= (s2) (fi->offset & 0x0000ffff);
+       if (fi->type == TYPE_LNG) {
+               /* if the field has type long, we have to patch two instructions */
 
-       /* if the field has type long, we need to patch the second move too */
+               *((u4 *) ra) |= (s2) ((fi->offset + 4) & 0x0000ffff);
+               *((u4 *) (ra + 4)) |= (s2) (fi->offset & 0x0000ffff);
 
-       if (fi->type == TYPE_LNG)
-               *((u4 *) (ra + 4)) |= (s2) ((fi->offset + 4) & 0x0000ffff);
+       } else {
+               *((u4 *) ra) |= (s2) (fi->offset & 0x0000ffff);
+       }
 
        /* synchronize instruction cache */
 
@@ -194,46 +181,42 @@ 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
 
 *******************************************************************************/
 
-bool patcher_builtin_new(u1 *sp)
+bool patcher_aconst(u1 *sp)
 {
        u1                *ra;
        java_objectheader *o;
        u4                 mcode;
        constant_classref *cr;
+       s4                 disp;
        u1                *pv;
        classinfo         *c;
-       s2                offset;
 
        /* get stuff from the stack */
 
-       ra    = (u1 *)                *((ptrint *) (sp + 3 * 4));
-       o     = (java_objectheader *) *((ptrint *) (sp + 2 * 4));
-       mcode =                       *((u4 *)     (sp + 1 * 4));
-       cr    = (constant_classref *) *((ptrint *) (sp + 0 * 4));
-       pv    = (u1 *)                *((ptrint *) (sp - 2 * 4));
-
-       /* calculate and set the new return address */
-
-       ra = ra - (4 + 4);
-       *((ptrint *) (sp + 3 * 4)) = (ptrint) ra;
+       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));
 
        PATCHER_MONITORENTER;
 
        /* get the classinfo */
 
-       if (!(c = helper_resolve_classinfo(cr))) {
+       if (!(c = resolve_classref_eager(cr))) {
                PATCHER_MONITOREXIT;
 
                return false;
@@ -241,112 +224,15 @@ bool patcher_builtin_new(u1 *sp)
 
        /* patch back original code */
 
-       *((u4 *) (ra + 4)) = mcode;
-
-       /* get the offset from machine instruction */
-
-       offset = (s2) (*((u4 *) ra) & 0x0000ffff);
-
-       /* patch the classinfo pointer */
-
-       *((ptrint *) (pv + offset)) = (ptrint) c;
-
-       /* if we show disassembly, we have to skip the nop */
-
-       if (showdisassemble)
-               ra = ra + 4;
-
-       /* get the offset from machine instruction */
-
-       offset = (s2) (*((u4 *) (ra + 4)) & 0x0000ffff);
-
-       /* patch new function address */
-
-       *((ptrint *) (pv + offset)) = (ptrint) BUILTIN_new;
+       *((u4 *) ra) = mcode;
 
        /* synchronize instruction cache */
 
-       asm_cacheflush(ra + 4, 4);
-
-       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
-
-*******************************************************************************/
-
-bool patcher_builtin_newarray(u1 *sp)
-{
-       u1                *ra;
-       java_objectheader *o;
-       u4                 mcode;
-       constant_classref *cr;
-       u1                *pv;
-       classinfo         *c;
-       s2                 offset;
-
-       /* get stuff from the stack */
-
-       ra    = (u1 *)                *((ptrint *) (sp + 3 * 4));
-       o     = (java_objectheader *) *((ptrint *) (sp + 2 * 4));
-       mcode =                       *((u4 *)     (sp + 1 * 4));
-       cr    = (constant_classref *) *((ptrint *) (sp + 0 * 4));
-       pv    = (u1 *)                *((ptrint *) (sp - 2 * 4));
-
-       /* calculate and set the new return address */
-
-       ra = ra - 2 * 4;
-       *((ptrint *) (sp + 3 * 4)) = (ptrint) ra;
-
-       PATCHER_MONITORENTER;
-
-       /* get the classinfo */
-
-       if (!(c = helper_resolve_classinfo(cr))) {
-               PATCHER_MONITOREXIT;
-
-               return false;
-       }
-
-       /* patch back original code */
-
-       *((u4 *) (ra + 4)) = mcode;
-
-       /* 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 + 4;
-
-       /* get the offset from machine instruction */
-
-       offset = (s2) (*((u4 *) (ra + 4)) & 0x0000ffff);
+       asm_cacheflush(ra, 4);
 
-       /* patch new function address */
+       /* patch the classinfo pointer */
 
-       *((ptrint *) (pv + offset)) = (ptrint) BUILTIN_newarray;
-
-       /* synchronize instruction cache */
-
-       asm_cacheflush(ra, 4);
+       *((ptrint *) (pv + disp)) = (ptrint) c;
 
        PATCHER_MARK_PATCHED_MONITOREXIT;
 
@@ -359,7 +245,6 @@ bool patcher_builtin_newarray(u1 *sp)
    Machine code:
 
    <patched call position>
-   38600002    li    r3,2
    808dffc0    lwz   r4,-64(r13)
    38a10038    addi  r5,r1,56
    81adffbc    lwz   r13,-68(r13)
@@ -374,28 +259,24 @@ bool patcher_builtin_multianewarray(u1 *sp)
        java_objectheader *o;
        u4                 mcode;
        constant_classref *cr;
+       s4                 disp;
        u1                *pv;
        classinfo         *c;
-       s2                 offset;
 
        /* get stuff from the stack */
 
-       ra    = (u1 *)                *((ptrint *) (sp + 3 * 4));
-       o     = (java_objectheader *) *((ptrint *) (sp + 2 * 4));
-       mcode =                       *((u4 *)     (sp + 1 * 4));
-       cr    = (constant_classref *) *((ptrint *) (sp + 0 * 4));
-       pv    = (u1 *)                *((ptrint *) (sp - 2 * 4));
-
-       /* calculate and set the new return address */
-
-       ra = ra - 4;
-       *((ptrint *) (sp + 3 * 4)) = (ptrint) ra;
+       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));
 
        PATCHER_MONITORENTER;
 
        /* get the classinfo */
 
-       if (!(c = helper_resolve_classinfo(cr))) {
+       if (!(c = resolve_classref_eager(cr))) {
                PATCHER_MONITOREXIT;
 
                return false;
@@ -405,23 +286,14 @@ bool patcher_builtin_multianewarray(u1 *sp)
 
        *((u4 *) ra) = mcode;
 
-       /* if we show disassembly, we have to skip the nop */
-
-       if (showdisassemble)
-               ra = ra + 4;
-
-       /* get the offset from machine instruction */
-
-       offset = (s2) (*((u4 *) (ra + 4)) & 0x0000ffff);
-
-       /* patch the class' vftbl pointer */
-
-       *((ptrint *) (pv + offset)) = (ptrint) c->vftbl;
-
        /* synchronize instruction cache */
 
        asm_cacheflush(ra, 4);
 
+       /* patch the classinfo pointer */
+
+       *((ptrint *) (pv + disp)) = (ptrint) c;
+
        PATCHER_MARK_PATCHED_MONITOREXIT;
 
        return true;
@@ -432,8 +304,8 @@ bool patcher_builtin_multianewarray(u1 *sp)
 
    Machine code:
 
-   808dffd8    lwz   r4,-40(r13)
    <patched call position>
+   808dffd8    lwz   r4,-40(r13)
    81adffd4    lwz   r13,-44(r13)
    7da903a6    mtctr r13
    4e800421    bctrl
@@ -446,28 +318,24 @@ bool patcher_builtin_arraycheckcast(u1 *sp)
        java_objectheader *o;
        u4                 mcode;
        constant_classref *cr;
+       s4                 disp;
        u1                *pv;
        classinfo         *c;
-       s2                 offset;
 
        /* get stuff from the stack */
 
-       ra    = (u1 *)                *((ptrint *) (sp + 3 * 4));
-       o     = (java_objectheader *) *((ptrint *) (sp + 2 * 4));
-       mcode =                       *((u4 *)     (sp + 1 * 4));
-       cr    = (constant_classref *) *((ptrint *) (sp + 0 * 4));
-       pv    = (u1 *)                *((ptrint *) (sp - 2 * 4));
-
-       /* calculate and set the new return address */
-
-       ra = ra - 2 * 4;
-       *((ptrint *) (sp + 3 * 4)) = (ptrint) ra;
+       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));
 
        PATCHER_MONITORENTER;
 
        /* get the classinfo */
 
-       if (!(c = helper_resolve_classinfo(cr))) {
+       if (!(c = resolve_classref_eager(cr))) {
                PATCHER_MONITOREXIT;
 
                return false;
@@ -475,112 +343,15 @@ bool patcher_builtin_arraycheckcast(u1 *sp)
 
        /* patch back original code */
 
-       *((u4 *) (ra + 4)) = mcode;
-
-       /* 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 + 4;
-
-       /* get the offset from machine instruction */
-
-       offset = (s2) (*((u4 *) (ra + 4)) & 0x0000ffff);
-
-       /* patch new function address */
-
-       *((ptrint *) (pv + offset)) = (ptrint) BUILTIN_arraycheckcast;
+       *((u4 *) ra) = mcode;
 
        /* synchronize instruction cache */
 
-       asm_cacheflush(ra + 4, 4);
-
-       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
-
-*******************************************************************************/
-
-bool patcher_builtin_arrayinstanceof(u1 *sp)
-{
-       u1                *ra;
-       java_objectheader *o;
-       u4                 mcode;
-       constant_classref *cr;
-       u1                *pv;
-       classinfo         *c;
-       s4                 offset;
-
-       /* get stuff from the stack */
-
-       ra    = (u1 *)                *((ptrint *) (sp + 3 * 4));
-       o     = (java_objectheader *) *((ptrint *) (sp + 2 * 4));
-       mcode =                       *((u4 *)     (sp + 1 * 4));
-       cr    = (constant_classref *) *((ptrint *) (sp + 0 * 4));
-       pv    = (u1 *)                *((ptrint *) (sp - 2 * 4));
-
-       /* calculate and set the new return address */
-
-       ra = ra - 2 * 4;
-       *((ptrint *) (sp + 3 * 4)) = (ptrint) ra;
-
-       PATCHER_MONITORENTER;
-
-       /* get the classinfo */
-
-       if (!(c = helper_resolve_classinfo(cr))) {
-               PATCHER_MONITOREXIT;
-
-               return false;
-       }
-
-       /* patch back original code */
-
-       *((u4 *) (ra + 4)) = mcode;
-
-       /* 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 + 4;
-
-       /* get the offset from machine instruction */
-
-       offset = (s2) (*((u4 *) (ra + 4)) & 0x0000ffff);
-
-       /* patch new function address */
-
-       *((ptrint *) (pv + offset)) = (ptrint) BUILTIN_arrayinstanceof;
+       asm_cacheflush(ra, 4);
 
-       /* synchronize instruction cache */
+       /* patch the classinfo pointer */
 
-       asm_cacheflush(ra + 4, 4);
+       *((ptrint *) (pv + disp)) = (ptrint) c;
 
        PATCHER_MARK_PATCHED_MONITOREXIT;
 
@@ -605,28 +376,24 @@ bool patcher_invokestatic_special(u1 *sp)
        java_objectheader *o;
        u4                 mcode;
        unresolved_method *um;
+       s4                 disp;
        u1                *pv;
        methodinfo        *m;
-       s4                 offset;
 
        /* get stuff from the stack */
 
-       ra    = (u1 *)                *((ptrint *) (sp + 3 * 4));
-       o     = (java_objectheader *) *((ptrint *) (sp + 2 * 4));
-       mcode =                       *((u4 *)     (sp + 1 * 4));
-       um    = (unresolved_method *) *((ptrint *) (sp + 0 * 4));
-       pv    = (u1 *)                *((ptrint *) (sp - 2 * 4));
-
-       /* calculate and set the new return address */
-
-       ra = ra - 4;
-       *((ptrint *) (sp + 3 * 4)) = (ptrint) ra;
+       ra    = (u1 *)                *((ptrint *) (sp + 5 * 4));
+       o     = (java_objectheader *) *((ptrint *) (sp + 4 * 4));
+       mcode =                       *((u4 *)     (sp + 3 * 4));
+       um    = (unresolved_method *) *((ptrint *) (sp + 2 * 4));
+       disp  =                       *((s4 *)     (sp + 1 * 4));
+       pv    = (u1 *)                *((ptrint *) (sp + 0 * 4));
 
        PATCHER_MONITORENTER;
 
        /* get the fieldinfo */
 
-       if (!(m = helper_resolve_methodinfo(um))) {
+       if (!(m = resolve_method_eager(um))) {
                PATCHER_MONITOREXIT;
 
                return false;
@@ -636,22 +403,13 @@ bool patcher_invokestatic_special(u1 *sp)
 
        *((u4 *) ra) = mcode;
 
-       /* if we show disassembly, we have to skip the nop */
-
-       if (showdisassemble)
-               ra = ra + 4;
-
-       /* get the offset from machine instruction */
+       /* synchronize instruction cache */
 
-       offset = (s2) (*((u4 *) ra) & 0x0000ffff);
+       asm_cacheflush(ra, 4);
 
        /* patch stubroutine */
 
-       *((ptrint *) (pv + offset)) = (ptrint) m->stubroutine;
-
-       /* synchronize instruction cache */
-
-       asm_cacheflush(ra, 4);
+       *((ptrint *) (pv + disp)) = (ptrint) m->stubroutine;
 
        PATCHER_MARK_PATCHED_MONITOREXIT;
 
@@ -681,21 +439,16 @@ bool patcher_invokevirtual(u1 *sp)
 
        /* get stuff from the stack */
 
-       ra    = (u1 *)                *((ptrint *) (sp + 3 * 4));
-       o     = (java_objectheader *) *((ptrint *) (sp + 2 * 4));
-       mcode =                       *((u4 *)     (sp + 1 * 4));
-       um    = (unresolved_method *) *((ptrint *) (sp + 0 * 4));
-
-       /* calculate and set the new return address */
-
-       ra = ra - 4;
-       *((ptrint *) (sp + 3 * 4)) = (ptrint) ra;
+       ra    = (u1 *)                *((ptrint *) (sp + 5 * 4));
+       o     = (java_objectheader *) *((ptrint *) (sp + 4 * 4));
+       mcode =                       *((u4 *)     (sp + 3 * 4));
+       um    = (unresolved_method *) *((ptrint *) (sp + 2 * 4));
 
        PATCHER_MONITORENTER;
 
        /* get the fieldinfo */
 
-       if (!(m = helper_resolve_methodinfo(um))) {
+       if (!(m = resolve_method_eager(um))) {
                PATCHER_MONITOREXIT;
 
                return false;
@@ -707,7 +460,7 @@ bool patcher_invokevirtual(u1 *sp)
 
        /* if we show disassembly, we have to skip the nop */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 4;
 
        /* patch vftbl index */
@@ -748,21 +501,16 @@ bool patcher_invokeinterface(u1 *sp)
 
        /* get stuff from the stack */
 
-       ra    = (u1 *)                *((ptrint *) (sp + 3 * 4));
-       o     = (java_objectheader *) *((ptrint *) (sp + 2 * 4));
-       mcode =                       *((u4 *)     (sp + 1 * 4));
-       um    = (unresolved_method *) *((ptrint *) (sp + 0 * 4));
-
-       /* calculate and set the new return address */
-
-       ra = ra - 4;
-       *((ptrint *) (sp + 3 * 4)) = (ptrint) ra;
+       ra    = (u1 *)                *((ptrint *) (sp + 5 * 4));
+       o     = (java_objectheader *) *((ptrint *) (sp + 4 * 4));
+       mcode =                       *((u4 *)     (sp + 3 * 4));
+       um    = (unresolved_method *) *((ptrint *) (sp + 2 * 4));
 
        PATCHER_MONITORENTER;
 
        /* get the fieldinfo */
 
-       if (!(m = helper_resolve_methodinfo(um))) {
+       if (!(m = resolve_method_eager(um))) {
                PATCHER_MONITOREXIT;
 
                return false;
@@ -774,7 +522,7 @@ bool patcher_invokeinterface(u1 *sp)
 
        /* if we show disassembly, we have to skip the nop */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 4;
 
        /* patch interfacetable index */
@@ -802,6 +550,7 @@ bool patcher_invokeinterface(u1 *sp)
    Machine code:
 
    <patched call position>
+   818dff7c    lwz   r12,-132(r13)
 
 *******************************************************************************/
 
@@ -811,28 +560,24 @@ bool patcher_checkcast_instanceof_flags(u1 *sp)
        java_objectheader *o;
        u4                 mcode;
        constant_classref *cr;
+       s4                 disp;
        u1                *pv;
        classinfo         *c;
-       s2                 offset;
 
        /* get stuff from the stack */
 
-       ra    = (u1 *)                *((ptrint *) (sp + 3 * 4));
-       o     = (java_objectheader *) *((ptrint *) (sp + 2 * 4));
-       mcode =                       *((u4 *)     (sp + 1 * 4));
-       cr    = (constant_classref *) *((ptrint *) (sp + 0 * 4));
-       pv    = (u1 *)                *((ptrint *) (sp - 2 * 4));
-
-       /* calculate and set the new return address */
-
-       ra = ra - 4;
-       *((ptrint *) (sp + 3 * 4)) = (ptrint) ra;
+       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));
 
        PATCHER_MONITORENTER;
 
        /* get the fieldinfo */
 
-       if (!(c = helper_resolve_classinfo(cr))) {
+       if (!(c = resolve_classref_eager(cr))) {
                PATCHER_MONITOREXIT;
 
                return false;
@@ -846,18 +591,9 @@ bool patcher_checkcast_instanceof_flags(u1 *sp)
 
        asm_cacheflush(ra, 4);
 
-       /* if we show disassembly, we have to skip the nop */
-
-       if (showdisassemble)
-               ra = ra + 4;
-
-       /* get the offset from machine instruction */
-
-       offset = (s2) (*((u4 *) ra) & 0x0000ffff);
-
        /* patch class flags */
 
-       *((s4 *) (pv + offset)) = (s4) c->flags;
+       *((s4 *) (pv + disp)) = (s4) c->flags;
 
        PATCHER_MARK_PATCHED_MONITOREXIT;
 
@@ -870,6 +606,11 @@ bool patcher_checkcast_instanceof_flags(u1 *sp)
    Machine code:
 
    <patched call position>
+   81870000    lwz   r12,0(r7)
+   800c0010    lwz   r0,16(r12)
+   34000000    addic.        r0,r0,0
+   408101fc    ble-  0x3002e518
+   800c0000    lwz   r0,0(r12)
 
 *******************************************************************************/
 
@@ -883,21 +624,16 @@ bool patcher_checkcast_instanceof_interface(u1 *sp)
 
        /* get stuff from the stack */
 
-       ra    = (u1 *)                *((ptrint *) (sp + 3 * 4));
-       o     = (java_objectheader *) *((ptrint *) (sp + 2 * 4));
-       mcode =                       *((u4 *)     (sp + 1 * 4));
-       cr    = (constant_classref *) *((ptrint *) (sp + 0 * 4));
-
-       /* calculate and set the new return address */
-
-       ra = ra - 4;
-       *((ptrint *) (sp + 3 * 4)) = (ptrint) ra;
+       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));
 
        PATCHER_MONITORENTER;
 
        /* get the fieldinfo */
 
-       if (!(c = helper_resolve_classinfo(cr))) {
+       if (!(c = resolve_classref_eager(cr))) {
                PATCHER_MONITOREXIT;
 
                return false;
@@ -909,7 +645,7 @@ bool patcher_checkcast_instanceof_interface(u1 *sp)
 
        /* if we show disassembly, we have to skip the nop */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 4;
 
        /* patch super class index */
@@ -934,6 +670,9 @@ bool patcher_checkcast_instanceof_interface(u1 *sp)
    Machine code:
 
    <patched call position>
+   81870000    lwz   r12,0(r7)
+   800c0014    lwz   r0,20(r12)
+   818dff78    lwz   r12,-136(r13)
 
 *******************************************************************************/
 
@@ -943,28 +682,24 @@ bool patcher_checkcast_class(u1 *sp)
        java_objectheader *o;
        u4                 mcode;
        constant_classref *cr;
+       s4                 disp;
        u1                *pv;
        classinfo         *c;
-       s2                 offset;
 
        /* get stuff from the stack */
 
-       ra    = (u1 *)                *((ptrint *) (sp + 3 * 4));
-       o     = (java_objectheader *) *((ptrint *) (sp + 2 * 4));
-       mcode =                       *((u4 *)     (sp + 1 * 4));
-       cr    = (constant_classref *) *((ptrint *) (sp + 0 * 4));
-       pv    = (u1 *)                *((ptrint *) (sp - 2 * 4));
-
-       /* calculate and set the new return address */
-
-       ra = ra - 4;
-       *((ptrint *) (sp + 3 * 4)) = (ptrint) ra;
+       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));
 
        PATCHER_MONITORENTER;
 
        /* get the fieldinfo */
 
-       if (!(c = helper_resolve_classinfo(cr))) {
+       if (!(c = resolve_classref_eager(cr))) {
                PATCHER_MONITOREXIT;
 
                return false;
@@ -978,18 +713,9 @@ bool patcher_checkcast_class(u1 *sp)
 
        asm_cacheflush(ra, 4);
 
-       /* if we show disassembly, we have to skip the nop */
-
-       if (showdisassemble)
-               ra = ra + 4;
-
-       /* get the offset from machine instruction */
-
-       offset = (s2) (*((u4 *) (ra + 2 * 4)) & 0x0000ffff);
-
        /* patch super class' vftbl */
 
-       *((ptrint *) (pv + offset)) = (ptrint) c->vftbl;
+       *((ptrint *) (pv + disp)) = (ptrint) c->vftbl;
 
        PATCHER_MARK_PATCHED_MONITOREXIT;
 
@@ -1002,6 +728,8 @@ bool patcher_checkcast_class(u1 *sp)
    Machine code:
 
    <patched call position>
+   817d0000    lwz   r11,0(r29)
+   818dff8c    lwz   r12,-116(r13)
 
 *******************************************************************************/
 
@@ -1011,28 +739,24 @@ bool patcher_instanceof_class(u1 *sp)
        java_objectheader *o;
        u4                 mcode;
        constant_classref *cr;
+       s4                 disp;
        u1                *pv;
        classinfo         *c;
-       s2                 offset;
 
        /* get stuff from the stack */
 
-       ra    = (u1 *)                *((ptrint *) (sp + 3 * 4));
-       o     = (java_objectheader *) *((ptrint *) (sp + 2 * 4));
-       mcode =                       *((u4 *)     (sp + 1 * 4));
-       cr    = (constant_classref *) *((ptrint *) (sp + 0 * 4));
-       pv    = (u1 *)                *((ptrint *) (sp - 2 * 4));
-
-       /* calculate and set the new return address */
-
-       ra = ra - 4;
-       *((ptrint *) (sp + 3 * 4)) = (ptrint) ra;
+       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));
 
        PATCHER_MONITORENTER;
 
        /* get the fieldinfo */
 
-       if (!(c = helper_resolve_classinfo(cr))) {
+       if (!(c = resolve_classref_eager(cr))) {
                PATCHER_MONITOREXIT;
 
                return false;
@@ -1046,18 +770,9 @@ bool patcher_instanceof_class(u1 *sp)
 
        asm_cacheflush(ra, 4);
 
-       /* if we show disassembly, we have to skip the nop */
-
-       if (showdisassemble)
-               ra = ra + 4;
-
-       /* get the offset from machine instruction */
-
-       offset = (s2) (*((u4 *) (ra + 1 * 4)) & 0x0000ffff);
-
        /* patch super class' vftbl */
 
-       *((ptrint *) (pv + offset)) = (ptrint) c->vftbl;
+       *((ptrint *) (pv + disp)) = (ptrint) c->vftbl;
 
        PATCHER_MARK_PATCHED_MONITOREXIT;
 
@@ -1080,21 +795,16 @@ bool patcher_clinit(u1 *sp)
 
        /* get stuff from the stack */
 
-       ra    = (u1 *)                *((ptrint *) (sp + 3 * 4));
-       o     = (java_objectheader *) *((ptrint *) (sp + 2 * 4));
-       mcode =                       *((u4 *)     (sp + 1 * 4));
-       c     = (classinfo *)         *((ptrint *) (sp + 0 * 4));
-
-       /* calculate and set the new return address */
-
-       ra = ra - 4;
-       *((ptrint *) (sp + 3 * 4)) = (ptrint) ra;
+       ra    = (u1 *)                *((ptrint *) (sp + 5 * 4));
+       o     = (java_objectheader *) *((ptrint *) (sp + 4 * 4));
+       mcode =                       *((u4 *)     (sp + 3 * 4));
+       c     = (classinfo *)         *((ptrint *) (sp + 2 * 4));
 
        PATCHER_MONITORENTER;
 
        /* check if the class is initialized */
 
-       if (!c->initialized) {
+       if (!(c->state & CLASS_INITIALIZED)) {
                if (!initialize_class(c)) {
                        PATCHER_MONITOREXIT;
 
@@ -1116,34 +826,85 @@ 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 */
+
+       asm_cacheflush(ra, 4);
+
+       PATCHER_MARK_PATCHED_MONITOREXIT;
+
+       return true;
+}
+#endif /* ENABLE_VERIFIER */
+
+
 /* patcher_resolve_native ******************************************************
 
    XXX
 
 *******************************************************************************/
 
+#if !defined(ENABLE_STATICVM)
 bool patcher_resolve_native(u1 *sp)
 {
        u1                *ra;
        java_objectheader *o;
        u4                 mcode;
        methodinfo        *m;
+       s4                 disp;
        u1                *pv;
        functionptr        f;
-       s2                 offset;
 
        /* get stuff from the stack */
 
-       ra    = (u1 *)                *((ptrint *) (sp + 3 * 4));
-       o     = (java_objectheader *) *((ptrint *) (sp + 2 * 4));
-       mcode =                       *((u4 *)     (sp + 1 * 4));
-       m     = (methodinfo *)        *((ptrint *) (sp + 0 * 4));
-       pv    = (u1 *)                *((ptrint *) (sp - 2 * 4));
+       ra    = (u1 *)                *((ptrint *) (sp + 5 * 4));
+       o     = (java_objectheader *) *((ptrint *) (sp + 4 * 4));
+       mcode =                       *((u4 *)     (sp + 3 * 4));
+       m     = (methodinfo *)        *((ptrint *) (sp + 2 * 4));
+       disp  =                       *((s4 *)     (sp + 1 * 4));
+       pv    = (u1 *)                *((ptrint *) (sp + 0 * 4));
 
        /* calculate and set the new return address */
 
-       ra = ra - 4;
-       *((ptrint *) (sp + 3 * 4)) = (ptrint) ra;
+       ra = ra - 1 * 4;
+       *((ptrint *) (sp + 5 * 4)) = (ptrint) ra;
 
        PATCHER_MONITORENTER;
 
@@ -1163,23 +924,15 @@ bool patcher_resolve_native(u1 *sp)
 
        asm_cacheflush(ra, 4);
 
-       /* if we show disassembly, we have to skip the nop */
-
-       if (showdisassemble)
-               ra = ra + 4;
-
-       /* get the offset from machine instruction */
-
-       offset = (s2) (*((u4 *) ra) & 0x0000ffff);
-
        /* patch native function pointer */
 
-       *((ptrint *) (pv + offset)) = (ptrint) f;
+       *((ptrint *) (pv + disp)) = (ptrint) f;
 
        PATCHER_MARK_PATCHED_MONITOREXIT;
 
        return true;
 }
+#endif /* !defined(ENABLE_STATICVM) */
 
 
 /*