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 *******************************************************
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;
}
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 */
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;
}
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 */
*((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;
}
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 */
*((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;
}
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 */
/* 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;
}
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;
}
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;
}
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
*******************************************************************************/
/* 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;
}
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;
}
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;
}
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 */
*((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;
}
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 */
*((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;
}
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;
}
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 */
(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;
}
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;
*((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;
}
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)
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;
}
/* patcher_clinit **************************************************************
- XXX
+ Is used int PUT/GETSTATIC and native stub.
+
+ Machine code:
+
+ <patched call position>
*******************************************************************************/
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) */
/*