#include "vm/jit/methodheader.h"
-#define PATCH_BACK_ORIGINAL_MCODE \
- *((u4 *) pr->mpc) = (u4) pr->mcode; \
- md_icacheflush(NULL, 0);
-
-
/* patcher_patch_code **********************************************************
Just patches back the original machine code.
*******************************************************************************/
-void patcher_patch_code(patchref_t *pr)
+void patcher_patch_code(patchref_t* pr)
{
- PATCH_BACK_ORIGINAL_MCODE;
+ // Patch back original code.
+ *((uint32_t*) pr->mpc) = pr->mcode;
+
+ // Synchronize instruction cache.
+ md_icacheflush(NULL, 0);
}
if (!(c = resolve_classref_eager(cr)))
return false;
- PATCH_BACK_ORIGINAL_MCODE;
-
/* patch the classinfo pointer */
*((ptrint *) datap) = (ptrint) c;
+ // Patch back the original code.
+ patcher_patch_code(pr);
+
return true;
}
if (!(c = resolve_classref_eager(cr)))
return false;
- PATCH_BACK_ORIGINAL_MCODE;
-
/* patch super class' vftbl */
*((ptrint *) datap) = (ptrint) c->vftbl;
+ // Patch back the original code.
+ patcher_patch_code(pr);
+
return true;
}
if (!(c = resolve_classref_eager(cr)))
return false;
- PATCH_BACK_ORIGINAL_MCODE;
-
/* patch class flags */
*((s4 *) datap) = (s4) c->flags;
+ // Patch back the original code.
+ patcher_patch_code(pr);
+
return true;
}
if (!initialize_class(fi->clazz))
return false;
- PATCH_BACK_ORIGINAL_MCODE;
-
/* patch the field value's address */
*((intptr_t *) datap) = (intptr_t) fi->value;
+ // Patch back the original code.
+ patcher_patch_code(pr);
+
return true;
}
bool patcher_get_putfield(patchref_t *pr)
{
- u1 *ra;
unresolved_field *uf;
fieldinfo *fi;
- ra = (u1 *) pr->mpc;
uf = (unresolved_field *) pr->ref;
/* get the fieldinfo */
if (!(fi = resolve_field_eager(uf)))
return false;
- PATCH_BACK_ORIGINAL_MCODE;
-
/* patch the field's offset into the instruction */
- *((u4 *) ra) |= (s2) (fi->offset & 0x0000ffff);
+ pr->mcode |= (s2) (fi->offset & 0x0000ffff);
- md_icacheflush(NULL, 0);
+ // Patch back the original code.
+ patcher_patch_code(pr);
return true;
}
if (!(m = resolve_method_eager(um)))
return false;
- PATCH_BACK_ORIGINAL_MCODE;
-
/* patch stubroutine */
*((ptrint *) datap) = (ptrint) m->stubroutine;
+ // Patch back the original code.
+ patcher_patch_code(pr);
+
return true;
}
if (!(m = resolve_method_eager(um)))
return false;
- PATCH_BACK_ORIGINAL_MCODE;
-
/* patch vftbl index */
*((s4 *) (ra + 4)) |= (s4) ((OFFSET(vftbl_t, table[0]) +
md_icacheflush(NULL, 0);
+ // Patch back the original code.
+ patcher_patch_code(pr);
+
return true;
}
if (!(m = resolve_method_eager(um)))
return false;
- PATCH_BACK_ORIGINAL_MCODE;
-
/* patch interfacetable index */
*((s4 *) (ra + 4)) |= (s4) ((OFFSET(vftbl_t, interfacetable[0]) -
md_icacheflush(NULL, 0);
+ // Patch back the original code.
+ patcher_patch_code(pr);
+
return true;
}
if (!(c = resolve_classref_eager(cr)))
return false;
- PATCH_BACK_ORIGINAL_MCODE;
-
/* patch super class index */
*((s4 *) (ra + 2 * 4)) |= (s4) (-(c->index) & 0x0000ffff);
md_icacheflush(NULL, 0);
+ // Patch back the original code.
+ patcher_patch_code(pr);
+
return true;
}
if (!(c = resolve_classref_eager(cr)))
return false;
- PATCH_BACK_ORIGINAL_MCODE;
-
/* patch super class index */
*((s4 *) (ra + 2 * 4)) |= (s4) (-(c->index) & 0x0000ffff);
md_icacheflush(NULL, 0);
+ // Patch back the original code.
+ patcher_patch_code(pr);
+
return true;
}