#include "vm/jit/patcher-common.hpp"
-#define PATCH_BACK_ORIGINAL_MCODE \
- *((u4 *) pr->mpc) = (u4) pr->mcode; \
- md_icacheflush((u1 *) pr->mpc, 4);
-
-
/* patcher_patch_code **********************************************************
Just patches back the original machine code.
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((void*) pr->mpc, 1 * 4);
}
if (!(c = resolve_classref_eager(cr)))
return false;
- PATCH_BACK_ORIGINAL_MCODE;
-
/* patch the classinfo pointer */
*((ptrint *) datap) = (ptrint) c;
md_dcacheflush(datap, SIZEOF_VOID_P);
+ // 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;
md_dcacheflush(datap, SIZEOF_VOID_P);
+ // 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;
md_dcacheflush(datap, SIZEOF_VOID_P);
+ // 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;
md_dcacheflush(datap, SIZEOF_VOID_P);
+ // Patch back the original code.
+ patcher_patch_code(pr);
+
return true;
}
if (!(fi = resolve_field_eager(uf)))
return false;
- PATCH_BACK_ORIGINAL_MCODE;
-
/* patch the field's offset */
if (IS_LNG_TYPE(fi->type)) {
is first. We do that with the offset of the first
instruction. */
- uint32_t disp = (*((uint32_t*) (ra + 0 * 4)) & 0x0000ffff);
+ uint32_t disp = (pr->mcode & 0x0000ffff);
if (disp == 4) {
- *((u4 *) (ra + 0 * 4)) &= 0xffff0000;
- *((u4 *) (ra + 0 * 4)) |= (s2) ((fi->offset + 4) & 0x0000ffff);
- *((u4 *) (ra + 1 * 4)) |= (s2) ((fi->offset + 0) & 0x0000ffff);
+ pr->mcode &= 0xffff0000;
+ pr->mcode |= ((fi->offset + 4) & 0x0000ffff);
+ *((u4 *) (ra + 1 * 4)) |= ((fi->offset + 0) & 0x0000ffff);
}
else {
- *((u4 *) (ra + 0 * 4)) |= (s2) ((fi->offset + 0) & 0x0000ffff);
+ pr->mcode |= ((fi->offset + 0) & 0x0000ffff);
*((u4 *) (ra + 1 * 4)) &= 0xffff0000;
- *((u4 *) (ra + 1 * 4)) |= (s2) ((fi->offset + 4) & 0x0000ffff);
+ *((u4 *) (ra + 1 * 4)) |= ((fi->offset + 4) & 0x0000ffff);
}
- }
- else
- *((u4 *) (ra + 0 * 4)) |= (s2) (fi->offset & 0x0000ffff);
- /* synchronize instruction cache */
+ // Synchronize instruction cache.
+ md_icacheflush(ra + 1 * 4, 1 * 4);
+ }
+ else {
+ pr->mcode |= (fi->offset & 0x0000ffff);
+ }
- md_icacheflush(ra + 0 * 4, 2 * 4);
+ // 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;
md_dcacheflush(datap, SIZEOF_VOID_P);
+ // 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 */
disp = (OFFSET(vftbl_t, table[0]) + sizeof(methodptr) * m->vftblindex);
md_icacheflush(ra + 1 * 4, 1 * 4);
+ // 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 */
disp = OFFSET(vftbl_t, interfacetable[0]) -
md_icacheflush(ra + 1 * 4, 2 * 4);
+ // 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 */
disp = -(c->index);
md_icacheflush(ra + 2 * 4, 4 * 4);
+ // 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 */
disp = -(c->index);
md_icacheflush(ra + 2 * 4, 3 * 4);
+ // Patch back the original code.
+ patcher_patch_code(pr);
+
return true;
}