Changes:
- $Id: patcher.c 2676 2005-06-13 16:20:32Z 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"
/* 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 value's address */
/* 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 */
/* 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 */
/* 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 */
/* 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 */
/* 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 */
/* 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 */
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;
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 the classinfo pointer */
+
+ *((ptrint *) (ra + 4)) = (ptrint) c;
+
/* patch new function address */
*((ptrint *) (ra + 8 + 1)) = (ptrint) BUILTIN_arraycheckcast;
/* 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 */
/* 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 */
/* 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 */
/* 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 */
/* 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 */
/* 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 */
/* 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 */
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)
/* 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 */
/* patcher_clinit **************************************************************
- XXX
+ Is used int PUT/GETSTATIC and native stub.
+
+ Machine code:
+
+ <patched call position>
*******************************************************************************/
/* patch back original code */
- *((u8 *) ra) = mcode;
+ *((u4 *) (ra + 0)) = (u4) mcode;
+ *((u1 *) (ra + 4)) = (u1) (mcode >> 32);
+
+ PATCHER_MARK_PATCHED_MONITOREXIT;
+
+ return true;
+}
+
+
+/* patcher_athrow_areturn ******************************************************
+
+ Machine code:
+
+ <patched call position>
+
+*******************************************************************************/
+
+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 */
+
+ 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;
+ }
+
+ /* patch back original code */
+
+ *((u4 *) (ra + 0)) = (u4) mcode;
+ *((u1 *) (ra + 4)) = (u1) (mcode >> 32);
PATCHER_MARK_PATCHED_MONITOREXIT;
/* patcher_resolve_native ******************************************************
- XXX
+ 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;
/* 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 native function pointer */
- *((ptrint *) (ra + 1)) = (ptrint) f;
+ *((ptrint *) (ra + 4)) = (ptrint) f;
PATCHER_MARK_PATCHED_MONITOREXIT;
return true;
}
+#endif /* !defined(ENABLE_STATICVM) */
/*