* patcher_builtin_newarray, patcher_builtin_multianewarray,
[cacao.git] / src / vm / jit / i386 / patcher.c
index 66cee3b234c0c40b1b0f15c436dc7f7dbb1f34c6..2831080f1ca10c3e8a9ceb4e567304087b137f59 100644 (file)
 
    Changes:
 
-   $Id: patcher.c 2475 2005-05-13 14:02:57Z twisti $
+   $Id: patcher.c 3569 2005-11-04 16:47:25Z twisti $
 
 */
 
 
-#include "vm/jit/i386/types.h"
+#include "config.h"
+#include "vm/types.h"
+
+#include "mm/memory.h"
+#include "native/native.h"
 #include "vm/builtin.h"
 #include "vm/field.h"
 #include "vm/initialize.h"
 #include "vm/options.h"
+#include "vm/resolve.h"
 #include "vm/references.h"
-#include "vm/jit/helper.h"
+#include "vm/jit/patcher.h"
 
 
 /* patcher_get_putstatic *******************************************************
@@ -71,53 +76,41 @@ bool patcher_get_putstatic(u1 *sp)
        ra = ra - 5;
        *((ptrint *) (sp + 4 * 4)) = (ptrint) ra;
 
-#if defined(USE_THREADS)
-       /* enter a monitor on the patching position */
-
-       builtin_monitorenter(o);
-
-       /* check if the position has already been patched */
-
-       if (o->vftbl) {
-               builtin_monitorexit(o);
-
-               return true;
-       }
-#endif
+       PATCHER_MONITORENTER;
 
        /* get the fieldinfo */
 
-       if (!(fi = helper_resolve_fieldinfo(uf)))
+       if (!(fi = resolve_field_eager(uf))) {
+               PATCHER_MONITOREXIT;
+
                return false;
+       }
 
        /* check if the field's class is initialized */
 
-       if (!fi->class->initialized)
-               if (!initialize_class(fi->class))
+       if (!fi->class->initialized) {
+               if (!initialize_class(fi->class)) {
+                       PATCHER_MONITOREXIT;
+
                        return false;
+               }
+       }
 
        /* patch back original code */
 
-       *((u8 *) ra) = mcode;
+       *((u4 *) (ra + 0)) = (u4) mcode;
+       *((u1 *) (ra + 4)) = (u1) (mcode >> 32);
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 5;
 
        /* patch the field value's address */
 
        *((ptrint *) (ra + 1)) = (ptrint) &(fi->value);
 
-#if defined(USE_THREADS)
-       /* this position has been patched */
-
-       o->vftbl = (vftbl_t *) 1;
-
-       /* leave the monitor on the patching position */
-
-       builtin_monitorexit(o);
-#endif
+       PATCHER_MARK_PATCHED_MONITOREXIT;
 
        return true;
 }
@@ -152,32 +145,24 @@ bool patcher_getfield(u1 *sp)
        ra = ra - 5;
        *((ptrint *) (sp + 4 * 4)) = (ptrint) ra;
 
-#if defined(USE_THREADS)
-       /* enter a monitor on the patching position */
-
-       builtin_monitorenter(o);
-
-       /* check if the position has already been patched */
-
-       if (o->vftbl) {
-               builtin_monitorexit(o);
-
-               return true;
-       }
-#endif
+       PATCHER_MONITORENTER;
 
        /* get the fieldinfo */
 
-       if (!(fi = helper_resolve_fieldinfo(uf)))
+       if (!(fi = resolve_field_eager(uf))) {
+               PATCHER_MONITOREXIT;
+
                return false;
+       }
 
        /* patch back original code */
 
-       *((u8 *) ra) = mcode;
+       *((u4 *) (ra + 0)) = (u4) mcode;
+       *((u1 *) (ra + 4)) = (u1) (mcode >> 32);
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 5;
 
        /* patch the field's offset */
@@ -189,15 +174,7 @@ bool patcher_getfield(u1 *sp)
        if (fi->type == TYPE_LNG)
                *((u4 *) (ra + 6 + 2)) = (u4) (fi->offset + 4);
 
-#if defined(USE_THREADS)
-       /* this position has been patched */
-
-       o->vftbl = (vftbl_t *) 1;
-
-       /* leave the monitor on the patching position */
-
-       builtin_monitorexit(o);
-#endif
+       PATCHER_MARK_PATCHED_MONITOREXIT;
 
        return true;
 }
@@ -232,32 +209,24 @@ bool patcher_putfield(u1 *sp)
        ra = ra - 5;
        *((ptrint *) (sp + 4 * 4)) = (ptrint) ra;
 
-#if defined(USE_THREADS)
-       /* enter a monitor on the patching position */
-
-       builtin_monitorenter(o);
-
-       /* check if the position has already been patched */
-
-       if (o->vftbl) {
-               builtin_monitorexit(o);
-
-               return true;
-       }
-#endif
+       PATCHER_MONITORENTER;
 
        /* get the fieldinfo */
 
-       if (!(fi = helper_resolve_fieldinfo(uf)))
+       if (!(fi = resolve_field_eager(uf))) {
+               PATCHER_MONITOREXIT;
+
                return false;
+       }
 
        /* patch back original code */
 
-       *((u8 *) ra) = mcode;
+       *((u4 *) (ra + 0)) = (u4) mcode;
+       *((u1 *) (ra + 4)) = (u1) (mcode >> 32);
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 5;
 
        /* patch the field's offset */
@@ -278,15 +247,7 @@ bool patcher_putfield(u1 *sp)
                *((u4 *) (ra + 7 + 7 + 6 + 2)) = (u4) (fi->offset + 4);
        }
 
-#if defined(USE_THREADS)
-       /* this position has been patched */
-
-       o->vftbl = (vftbl_t *) 1;
-
-       /* leave the monitor on the patching position */
-
-       builtin_monitorexit(o);
-#endif
+       PATCHER_MARK_PATCHED_MONITOREXIT;
 
        return true;
 }
@@ -321,32 +282,24 @@ bool patcher_putfieldconst(u1 *sp)
        ra = ra - 5;
        *((ptrint *) (sp + 4 * 4)) = (ptrint) ra;
 
-#if defined(USE_THREADS)
-       /* enter a monitor on the patching position */
-
-       builtin_monitorenter(o);
-
-       /* check if the position has already been patched */
-
-       if (o->vftbl) {
-               builtin_monitorexit(o);
-
-               return true;
-       }
-#endif
+       PATCHER_MONITORENTER;
 
        /* get the fieldinfo */
 
-       if (!(fi = helper_resolve_fieldinfo(uf)))
+       if (!(fi = resolve_field_eager(uf))) {
+               PATCHER_MONITOREXIT;
+
                return false;
+       }
 
        /* patch back original code */
 
-       *((u8 *) ra) = mcode;
+       *((u4 *) (ra + 0)) = (u4) mcode;
+       *((u1 *) (ra + 4)) = (u1) (mcode >> 32);
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 5;
 
        /* patch the field's offset */
@@ -365,15 +318,7 @@ bool patcher_putfieldconst(u1 *sp)
                *((u4 *) (ra + 10 + 2)) = (u4) (fi->offset + 4);
        }
 
-#if defined(USE_THREADS)
-       /* this position has been patched */
-
-       o->vftbl = (vftbl_t *) 1;
-
-       /* leave the monitor on the patching position */
-
-       builtin_monitorexit(o);
-#endif
+       PATCHER_MARK_PATCHED_MONITOREXIT;
 
        return true;
 }
@@ -410,28 +355,20 @@ bool patcher_builtin_new(u1 *sp)
        ra = ra - (7 + 5);
        *((ptrint *) (sp + 4 * 4)) = (ptrint) ra;
 
-#if defined(USE_THREADS)
-       /* enter a monitor on the patching position */
-
-       builtin_monitorenter(o);
-
-       /* check if the position has already been patched */
-
-       if (o->vftbl) {
-               builtin_monitorexit(o);
-
-               return true;
-       }
-#endif
+       PATCHER_MONITORENTER;
 
        /* get the classinfo */
 
-       if (!(c = helper_resolve_classinfo(cr)))
+       if (!(c = resolve_classref_eager_nonabstract(cr))) {
+               PATCHER_MONITOREXIT;
+
                return false;
+       }
 
        /* patch back original code */
 
-       *((u8 *) (ra + 7)) = mcode;
+       *((u4 *) (ra + 7 + 0)) = (u4) mcode;
+       *((u1 *) (ra + 7 + 4)) = (u1) (mcode >> 32);
 
        /* patch the classinfo pointer */
 
@@ -439,22 +376,14 @@ bool patcher_builtin_new(u1 *sp)
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 5;
 
        /* patch new function address */
 
        *((ptrint *) (ra + 7 + 1)) = (ptrint) BUILTIN_new;
 
-#if defined(USE_THREADS)
-       /* this position has been patched */
-
-       o->vftbl = (vftbl_t *) 1;
-
-       /* leave the monitor on the patching position */
-
-       builtin_monitorexit(o);
-#endif
+       PATCHER_MARK_PATCHED_MONITOREXIT;
 
        return true;
 }
@@ -491,51 +420,35 @@ bool patcher_builtin_newarray(u1 *sp)
        ra = ra - (8 + 5);
        *((ptrint *) (sp + 4 * 4)) = (ptrint) ra;
 
-#if defined(USE_THREADS)
-       /* enter a monitor on the patching position */
-
-       builtin_monitorenter(o);
-
-       /* check if the position has already been patched */
-
-       if (o->vftbl) {
-               builtin_monitorexit(o);
-
-               return true;
-       }
-#endif
+       PATCHER_MONITORENTER;
 
        /* get the classinfo */
 
-       if (!(c = helper_resolve_classinfo(cr)))
+       if (!(c = resolve_classref_eager(cr))) {
+               PATCHER_MONITOREXIT;
+
                return false;
+       }
 
        /* patch back original code */
 
-       *((u8 *) (ra + 8)) = mcode;
+       *((u4 *) (ra + 8 + 0)) = (u4) mcode;
+       *((u1 *) (ra + 8 + 4)) = (u1) (mcode >> 32);
 
-       /* patch the class' vftbl pointer */
+       /* patch the classinfo pointer */
 
-       *((ptrint *) (ra + 4)) = (ptrint) c->vftbl;
+       *((ptrint *) (ra + 4)) = (ptrint) c;
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 5;
 
        /* patch new function address */
 
        *((ptrint *) (ra + 8 + 1)) = (ptrint) BUILTIN_newarray;
 
-#if defined(USE_THREADS)
-       /* this position has been patched */
-
-       o->vftbl = (vftbl_t *) 1;
-
-       /* leave the monitor on the patching position */
-
-       builtin_monitorexit(o);
-#endif
+       PATCHER_MARK_PATCHED_MONITOREXIT;
 
        return true;
 }
@@ -576,51 +489,35 @@ bool patcher_builtin_multianewarray(u1 *sp)
        ra = ra - 5;
        *((ptrint *) (sp + 4 * 4)) = (ptrint) ra;
 
-#if defined(USE_THREADS)
-       /* enter a monitor on the patching position */
-
-       builtin_monitorenter(o);
-
-       /* check if the position has already been patched */
-
-       if (o->vftbl) {
-               builtin_monitorexit(o);
-
-               return true;
-       }
-#endif
+       PATCHER_MONITORENTER;
 
        /* get the classinfo */
 
-       if (!(c = helper_resolve_classinfo(cr)))
+       if (!(c = resolve_classref_eager(cr))) {
+               PATCHER_MONITOREXIT;
+
                return false;
+       }
 
        /* patch back original code */
 
-       *((u8 *) ra) = mcode;
+       *((u4 *) (ra + 0)) = (u4) mcode;
+       *((u1 *) (ra + 4)) = (u1) (mcode >> 32);
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 5;
 
-       /* patch the class' vftbl pointer */
+       /* patch the classinfo pointer */
 
-       *((ptrint *) (ra + 7 + 4)) = (ptrint) c->vftbl;
+       *((ptrint *) (ra + 7 + 4)) = (ptrint) c;
 
        /* patch new function address */
 
        *((ptrint *) (ra + 7 + 8 + 2 + 3 + 4 + 1)) = (ptrint) BUILTIN_multianewarray;
 
-#if defined(USE_THREADS)
-       /* this position has been patched */
-
-       o->vftbl = (vftbl_t *) 1;
-
-       /* leave the monitor on the patching position */
-
-       builtin_monitorexit(o);
-#endif
+       PATCHER_MARK_PATCHED_MONITOREXIT;
 
        return true;
 }
@@ -630,10 +527,10 @@ bool patcher_builtin_multianewarray(u1 *sp)
 
    Machine code:
 
-   c7 44 24 08 00 00 00 00    movl   $0x00000000,0x8(%esp)
    <patched call position>
-   b8 00 00 00 00             mov    $0x00000000,%eax
-   ff d0                      call   *%eax
+   c7 44 24 04 00 00 00 00    movl   $0x00000000,0x4(%esp)
+   ba 00 00 00 00             mov    $0x00000000,%edx
+   ff d2                      call   *%edx
 
 *******************************************************************************/
 
@@ -654,54 +551,38 @@ bool patcher_builtin_arraycheckcast(u1 *sp)
 
        /* calculate and set the new return address */
 
-       ra = ra - (8 + 5);
+       ra = ra - 5;
        *((ptrint *) (sp + 4 * 4)) = (ptrint) ra;
 
-#if defined(USE_THREADS)
-       /* enter a monitor on the patching position */
-
-       builtin_monitorenter(o);
-
-       /* check if the position has already been patched */
-
-       if (o->vftbl) {
-               builtin_monitorexit(o);
-
-               return true;
-       }
-#endif
+       PATCHER_MONITORENTER;
 
        /* get the classinfo */
 
-       if (!(c = helper_resolve_classinfo(cr)))
+       if (!(c = resolve_classref_eager(cr))) {
+               PATCHER_MONITOREXIT;
+
                return false;
+       }
 
        /* patch back original code */
 
-       *((u8 *) (ra + 8)) = mcode;
-
-       /* patch the class' vftbl pointer */
-
-       *((ptrint *) (ra + 4)) = (ptrint) c->vftbl;
+       *((u4 *) (ra + 0)) = (u4) mcode;
+       *((u1 *) (ra + 4)) = (u1) (mcode >> 32);
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 5;
 
-       /* patch new function address */
-
-       *((ptrint *) (ra + 8 + 1)) = (ptrint) BUILTIN_arraycheckcast;
+       /* patch the classinfo pointer */
 
-#if defined(USE_THREADS)
-       /* this position has been patched */
+       *((ptrint *) (ra + 4)) = (ptrint) c;
 
-       o->vftbl = (vftbl_t *) 1;
+       /* patch new function address */
 
-       /* leave the monitor on the patching position */
+       *((ptrint *) (ra + 8 + 1)) = (ptrint) BUILTIN_arraycheckcast;
 
-       builtin_monitorexit(o);
-#endif
+       PATCHER_MARK_PATCHED_MONITOREXIT;
 
        return true;
 }
@@ -738,51 +619,35 @@ bool patcher_builtin_arrayinstanceof(u1 *sp)
        ra = ra - (8 + 5);
        *((ptrint *) (sp + 4 * 4)) = (ptrint) ra;
 
-#if defined(USE_THREADS)
-       /* enter a monitor on the patching position */
-
-       builtin_monitorenter(o);
-
-       /* check if the position has already been patched */
-
-       if (o->vftbl) {
-               builtin_monitorexit(o);
-
-               return true;
-       }
-#endif
+       PATCHER_MONITORENTER;
 
        /* get the classinfo */
 
-       if (!(c = helper_resolve_classinfo(cr)))
+       if (!(c = resolve_classref_eager(cr))) {
+               PATCHER_MONITOREXIT;
+
                return false;
+       }
 
        /* patch back original code */
 
-       *((u8 *) (ra + 8)) = mcode;
+       *((u4 *) (ra + 8 + 0)) = (u4) mcode;
+       *((u1 *) (ra + 8 + 4)) = (u1) (mcode >> 32);
 
-       /* patch the class' vftbl pointer */
+       /* patch the classinfo pointer */
 
-       *((ptrint *) (ra + 4)) = (ptrint) c->vftbl;
+       *((ptrint *) (ra + 4)) = (ptrint) c;
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 5;
 
        /* patch new function address */
 
        *((ptrint *) (ra + 8 + 1)) = (ptrint) BUILTIN_arrayinstanceof;
 
-#if defined(USE_THREADS)
-       /* this position has been patched */
-
-       o->vftbl = (vftbl_t *) 1;
-
-       /* leave the monitor on the patching position */
-
-       builtin_monitorexit(o);
-#endif
+       PATCHER_MARK_PATCHED_MONITOREXIT;
 
        return true;
 }
@@ -818,47 +683,31 @@ bool patcher_invokestatic_special(u1 *sp)
        ra = ra - 5;
        *((ptrint *) (sp + 4 * 4)) = (ptrint) ra;
 
-#if defined(USE_THREADS)
-       /* enter a monitor on the patching position */
-
-       builtin_monitorenter(o);
-
-       /* check if the position has already been patched */
-
-       if (o->vftbl) {
-               builtin_monitorexit(o);
-
-               return true;
-       }
-#endif
+       PATCHER_MONITORENTER;
 
        /* get the fieldinfo */
 
-       if (!(m = helper_resolve_methodinfo(um)))
+       if (!(m = resolve_method_eager(um))) {
+               PATCHER_MONITOREXIT;
+
                return false;
+       }
 
        /* patch back original code */
 
-       *((u8 *) ra) = mcode;
+       *((u4 *) (ra + 0)) = (u4) mcode;
+       *((u1 *) (ra + 4)) = (u1) (mcode >> 32);
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 5;
 
        /* patch stubroutine */
 
        *((ptrint *) (ra + 1)) = (ptrint) m->stubroutine;
 
-#if defined(USE_THREADS)
-       /* this position has been patched */
-
-       o->vftbl = (vftbl_t *) 1;
-
-       /* leave the monitor on the patching position */
-
-       builtin_monitorexit(o);
-#endif
+       PATCHER_MARK_PATCHED_MONITOREXIT;
 
        return true;
 }
@@ -895,32 +744,24 @@ bool patcher_invokevirtual(u1 *sp)
        ra = ra - 5;
        *((ptrint *) (sp + 4 * 4)) = (ptrint) ra;
 
-#if defined(USE_THREADS)
-       /* enter a monitor on the patching position */
-
-       builtin_monitorenter(o);
-
-       /* check if the position has already been patched */
-
-       if (o->vftbl) {
-               builtin_monitorexit(o);
-
-               return true;
-       }
-#endif
+       PATCHER_MONITORENTER;
 
        /* get the fieldinfo */
 
-       if (!(m = helper_resolve_methodinfo(um)))
+       if (!(m = resolve_method_eager(um))) {
+               PATCHER_MONITOREXIT;
+
                return false;
+       }
 
        /* patch back original code */
 
-       *((u8 *) ra) = mcode;
+       *((u4 *) (ra + 0)) = (u4) mcode;
+       *((u1 *) (ra + 4)) = (u1) (mcode >> 32);
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 5;
 
        /* patch vftbl index */
@@ -928,15 +769,7 @@ bool patcher_invokevirtual(u1 *sp)
        *((s4 *) (ra + 2 + 2)) = (s4) (OFFSET(vftbl_t, table[0]) +
                                                                   sizeof(methodptr) * m->vftblindex);
 
-#if defined(USE_THREADS)
-       /* this position has been patched */
-
-       o->vftbl = (vftbl_t *) 1;
-
-       /* leave the monitor on the patching position */
-
-       builtin_monitorexit(o);
-#endif
+       PATCHER_MARK_PATCHED_MONITOREXIT;
 
        return true;
 }
@@ -974,32 +807,24 @@ bool patcher_invokeinterface(u1 *sp)
        ra = ra - 5;
        *((ptrint *) (sp + 4 * 4)) = (ptrint) ra;
 
-#if defined(USE_THREADS)
-       /* enter a monitor on the patching position */
-
-       builtin_monitorenter(o);
-
-       /* check if the position has already been patched */
-
-       if (o->vftbl) {
-               builtin_monitorexit(o);
-
-               return true;
-       }
-#endif
+       PATCHER_MONITORENTER;
 
        /* get the fieldinfo */
 
-       if (!(m = helper_resolve_methodinfo(um)))
+       if (!(m = resolve_method_eager(um))) {
+               PATCHER_MONITOREXIT;
+
                return false;
+       }
 
        /* patch back original code */
 
-       *((u8 *) ra) = mcode;
+       *((u4 *) (ra + 0)) = (u4) mcode;
+       *((u1 *) (ra + 4)) = (u1) (mcode >> 32);
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 5;
 
        /* patch interfacetable index */
@@ -1012,15 +837,7 @@ bool patcher_invokeinterface(u1 *sp)
        *((s4 *) (ra + 2 + 6 + 2)) =
                (s4) (sizeof(methodptr) * (m - m->class->methods));
 
-#if defined(USE_THREADS)
-       /* this position has been patched */
-
-       o->vftbl = (vftbl_t *) 1;
-
-       /* leave the monitor on the patching position */
-
-       builtin_monitorexit(o);
-#endif
+       PATCHER_MARK_PATCHED_MONITOREXIT;
 
        return true;
 }
@@ -1055,47 +872,31 @@ bool patcher_checkcast_instanceof_flags(u1 *sp)
        ra = ra - 5;
        *((ptrint *) (sp + 4 * 4)) = (ptrint) ra;
 
-#if defined(USE_THREADS)
-       /* enter a monitor on the patching position */
-
-       builtin_monitorenter(o);
-
-       /* check if the position has already been patched */
-
-       if (o->vftbl) {
-               builtin_monitorexit(o);
-
-               return true;
-       }
-#endif
+       PATCHER_MONITORENTER;
 
        /* get the fieldinfo */
 
-       if (!(c = helper_resolve_classinfo(cr)))
+       if (!(c = resolve_classref_eager(cr))) {
+               PATCHER_MONITOREXIT;
+
                return false;
+       }
 
        /* patch back original code */
 
-       *((u8 *) ra) = mcode;
+       *((u4 *) (ra + 0)) = (u4) mcode;
+       *((u1 *) (ra + 4)) = (u1) (mcode >> 32);
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 5;
 
        /* patch class flags */
 
        *((s4 *) (ra + 1)) = (s4) c->flags;
 
-#if defined(USE_THREADS)
-       /* this position has been patched */
-
-       o->vftbl = (vftbl_t *) 1;
-
-       /* leave the monitor on the patching position */
-
-       builtin_monitorexit(o);
-#endif
+       PATCHER_MARK_PATCHED_MONITOREXIT;
 
        return true;
 }
@@ -1134,32 +935,24 @@ bool patcher_checkcast_instanceof_interface(u1 *sp)
        ra = ra - 5;
        *((ptrint *) (sp + 4 * 4)) = (ptrint) ra;
 
-#if defined(USE_THREADS)
-       /* enter a monitor on the patching position */
-
-       builtin_monitorenter(o);
-
-       /* check if the position has already been patched */
-
-       if (o->vftbl) {
-               builtin_monitorexit(o);
-
-               return true;
-       }
-#endif
+       PATCHER_MONITORENTER;
 
        /* get the fieldinfo */
 
-       if (!(c = helper_resolve_classinfo(cr)))
+       if (!(c = resolve_classref_eager(cr))) {
+               PATCHER_MONITOREXIT;
+
                return false;
+       }
 
        /* patch back original code */
 
-       *((u8 *) ra) = mcode;
+       *((u4 *) (ra + 0)) = (u4) mcode;
+       *((u1 *) (ra + 4)) = (u1) (mcode >> 32);
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 5;
 
        /* patch super class index */
@@ -1170,15 +963,7 @@ bool patcher_checkcast_instanceof_interface(u1 *sp)
                (s4) (OFFSET(vftbl_t, interfacetable[0]) -
                          c->index * sizeof(methodptr*));
 
-#if defined(USE_THREADS)
-       /* this position has been patched */
-
-       o->vftbl = (vftbl_t *) 1;
-
-       /* leave the monitor on the patching position */
-
-       builtin_monitorexit(o);
-#endif
+       PATCHER_MARK_PATCHED_MONITOREXIT;
 
        return true;
 }
@@ -1217,32 +1002,24 @@ bool patcher_checkcast_class(u1 *sp)
        ra = ra - 5;
        *((ptrint *) (sp + 4 * 4)) = (ptrint) ra;
 
-#if defined(USE_THREADS)
-       /* enter a monitor on the patching position */
-
-       builtin_monitorenter(o);
-
-       /* check if the position has already been patched */
-
-       if (o->vftbl) {
-               builtin_monitorexit(o);
-
-               return true;
-       }
-#endif
+       PATCHER_MONITORENTER;
 
        /* get the fieldinfo */
 
-       if (!(c = helper_resolve_classinfo(cr)))
+       if (!(c = resolve_classref_eager(cr))) {
+               PATCHER_MONITOREXIT;
+
                return false;
+       }
 
        /* patch back original code */
 
-       *((u8 *) ra) = mcode;
+       *((u4 *) (ra + 0)) = (u4) mcode;
+       *((u1 *) (ra + 4)) = (u1) (mcode >> 32);
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 5;
 
        /* patch super class' vftbl */
@@ -1250,15 +1027,7 @@ bool patcher_checkcast_class(u1 *sp)
        *((ptrint *) (ra + 1)) = (ptrint) c->vftbl;
        *((ptrint *) (ra + 5 + 6 + 6 + 2 + 1)) = (ptrint) c->vftbl;
 
-#if defined(USE_THREADS)
-       /* this position has been patched */
-
-       o->vftbl = (vftbl_t *) 1;
-
-       /* leave the monitor on the patching position */
-
-       builtin_monitorexit(o);
-#endif
+       PATCHER_MARK_PATCHED_MONITOREXIT;
 
        return true;
 }
@@ -1268,6 +1037,12 @@ bool patcher_checkcast_class(u1 *sp)
 
    Machine code:
 
+   <patched call position>
+   b9 00 00 00 00             mov    $0x0,%ecx
+   8b 40 14                   mov    0x14(%eax),%eax
+   8b 51 18                   mov    0x18(%ecx),%edx
+   8b 49 14                   mov    0x14(%ecx),%ecx
+
 *******************************************************************************/
 
 bool patcher_instanceof_class(u1 *sp)
@@ -1290,47 +1065,31 @@ bool patcher_instanceof_class(u1 *sp)
        ra = ra - 5;
        *((ptrint *) (sp + 4 * 4)) = (ptrint) ra;
 
-#if defined(USE_THREADS)
-       /* enter a monitor on the patching position */
-
-       builtin_monitorenter(o);
-
-       /* check if the position has already been patched */
-
-       if (o->vftbl) {
-               builtin_monitorexit(o);
-
-               return true;
-       }
-#endif
+       PATCHER_MONITORENTER;
 
        /* get the fieldinfo */
 
-       if (!(c = helper_resolve_classinfo(cr)))
+       if (!(c = resolve_classref_eager(cr))) {
+               PATCHER_MONITOREXIT;
+
                return false;
+       }
 
        /* patch back original code */
 
-       *((u8 *) ra) = mcode;
+       *((u4 *) (ra + 0)) = (u4) mcode;
+       *((u1 *) (ra + 4)) = (u1) (mcode >> 32);
 
        /* if we show disassembly, we have to skip the nop's */
 
-       if (showdisassemble)
+       if (opt_showdisassemble)
                ra = ra + 5;
 
        /* patch super class' vftbl */
 
        *((ptrint *) (ra + 1)) = (ptrint) c->vftbl;
 
-#if defined(USE_THREADS)
-       /* this position has been patched */
-
-       o->vftbl = (vftbl_t *) 1;
-
-       /* leave the monitor on the patching position */
-
-       builtin_monitorexit(o);
-#endif
+       PATCHER_MARK_PATCHED_MONITOREXIT;
 
        return true;
 }
@@ -1338,7 +1097,11 @@ bool patcher_instanceof_class(u1 *sp)
 
 /* patcher_clinit **************************************************************
 
-   XXX
+   Is used int PUT/GETSTATIC and native stub.
+
+   Machine code:
+
+   <patched call position>
 
 *******************************************************************************/
 
@@ -1361,42 +1124,139 @@ bool patcher_clinit(u1 *sp)
        ra = ra - 5;
        *((ptrint *) (sp + 4 * 4)) = (ptrint) ra;
 
-#if defined(USE_THREADS)
-       /* enter a monitor on the patching position */
+       PATCHER_MONITORENTER;
+
+       /* check if the class is initialized */
+
+       if (!c->initialized) {
+               if (!initialize_class(c)) {
+                       PATCHER_MONITOREXIT;
+
+                       return false;
+               }
+       }
+
+       /* patch back original code */
+
+       *((u4 *) (ra + 0)) = (u4) mcode;
+       *((u1 *) (ra + 4)) = (u1) (mcode >> 32);
+
+       PATCHER_MARK_PATCHED_MONITOREXIT;
+
+       return true;
+}
+
+
+/* patcher_athrow_areturn ******************************************************
 
-       builtin_monitorenter(o);
+   Machine code:
 
-       /* check if the position has already been patched */
+   <patched call position>
 
-       if (o->vftbl) {
-               builtin_monitorexit(o);
+*******************************************************************************/
+
+bool patcher_athrow_areturn(u1 *sp)
+{
+       u1                *ra;
+       java_objectheader *o;
+       u8                 mcode;
+       unresolved_class  *uc;
+       classinfo         *c;
+
+       /* get stuff from the stack */
+
+       ra    = (u1 *)                *((ptrint *) (sp + 4 * 4));
+       o     = (java_objectheader *) *((ptrint *) (sp + 3 * 4));
+       mcode =                       *((u8 *)     (sp + 1 * 4));
+       uc    = (unresolved_class *)  *((ptrint *) (sp + 0 * 4));
+
+       /* calculate and set the new return address */
 
-               return true;
+       ra = ra - 5;
+       *((ptrint *) (sp + 4 * 4)) = (ptrint) ra;
+
+       PATCHER_MONITORENTER;
+
+       /* resolve the class */
+
+       if (!resolve_class(uc, resolveEager, false, &c)) {
+               PATCHER_MONITOREXIT;
+
+               return false;
        }
-#endif
 
-       /* check if the class is initialized */
+       /* patch back original code */
 
-       if (!c->initialized)
-               if (!initialize_class(c))
-                       return false;
+       *((u4 *) (ra + 0)) = (u4) mcode;
+       *((u1 *) (ra + 4)) = (u1) (mcode >> 32);
+
+       PATCHER_MARK_PATCHED_MONITOREXIT;
+
+       return true;
+}
+
+
+/* patcher_resolve_native ******************************************************
+
+   Is used in native stub.
+
+   Machine code:
+
+   <patched call position>
+   c7 44 24 04 28 90 01 40    movl   $0x40019028,0x4(%esp)
+
+*******************************************************************************/
+
+#if !defined(ENABLE_STATICVM)
+bool patcher_resolve_native(u1 *sp)
+{
+       u1                *ra;
+       java_objectheader *o;
+       u8                 mcode;
+       methodinfo        *m;
+       functionptr        f;
+
+       /* get stuff from the stack */
+
+       ra    = (u1 *)                *((ptrint *) (sp + 4 * 4));
+       o     = (java_objectheader *) *((ptrint *) (sp + 3 * 4));
+       mcode =                       *((u8 *)     (sp + 1 * 4));
+       m     = (methodinfo *)        *((ptrint *) (sp + 0 * 4));
+
+       /* calculate and set the new return address */
+
+       ra = ra - 5;
+       *((ptrint *) (sp + 4 * 4)) = (ptrint) ra;
+
+       PATCHER_MONITORENTER;
+
+       /* resolve native function */
+
+       if (!(f = native_resolve_function(m))) {
+               PATCHER_MONITOREXIT;
+
+               return false;
+       }
 
        /* patch back original code */
 
-       *((u8 *) ra) = mcode;
+       *((u4 *) (ra + 0)) = (u4) mcode;
+       *((u1 *) (ra + 4)) = (u1) (mcode >> 32);
+
+       /* if we show disassembly, we have to skip the nop's */
 
-#if defined(USE_THREADS)
-       /* this position has been patched */
+       if (opt_showdisassemble)
+               ra = ra + 5;
 
-       o->vftbl = (vftbl_t *) 1;
+       /* patch native function pointer */
 
-       /* leave the monitor on the patching position */
+       *((ptrint *) (ra + 4)) = (ptrint) f;
 
-       builtin_monitorexit(o);
-#endif
+       PATCHER_MARK_PATCHED_MONITOREXIT;
 
        return true;
 }
+#endif /* !defined(ENABLE_STATICVM) */
 
 
 /*