#include "vm/types.h"
+#include "vm/jit/sparc64/codegen.h"
+
#include "mm/memory.h"
#include "native/native.h"
#include "vm/builtin.h"
u1 *xpc;
u1 *javasp;
java_objectheader *o;
+#if SIZEOF_VOID_P == 8
+ u8 mcode;
+#else
+ u4 mcode[2];
+#endif
functionptr f;
bool result;
java_objectheader *e;
return e;
}
+ /* patch back original code */
+
+#if SIZEOF_VOID_P == 8
+ mcode = *((u8 *) (sp + 3 * 8));
+
+ *((u4 *) (xpc + 0 * 4)) = mcode;
+ *((u4 *) (xpc + 1 * 4)) = mcode >> 32;
+#else
+ mcode[0] = *((u4 *) (sp + 3 * 8));
+ mcode[1] = *((u4 *) (sp + 3 * 8 + 4));
+
+ *((u4 *) (xpc + 0 * 4)) = mcode[0];
+ *((u4 *) (xpc + 1 * 4)) = mcode[1];
+#endif
+
+
+ /* synchronize instruction cache */
+
+ md_icacheflush(xpc, PATCHER_CALL_SIZE);
+
PATCHER_MARK_PATCHED_MONITOREXIT;
return NULL;
Machine code:
<patched call position>
- dfc1ffb8 ld at,-72(s8)
- fc250000 sd a1,0(at)
+ xxx ldx at,-72(pv)
+ xxx ld a1,0(at)
*******************************************************************************/
bool patcher_get_putstatic(u1 *sp)
{
- u1 *ra;
-#if SIZEOF_VOID_P == 8
- u8 mcode;
-#else
- u4 mcode[2];
-#endif
unresolved_field *uf;
s4 disp;
u1 *pv;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 5 * 8));
-#if SIZEOF_VOID_P == 8
- mcode = *((u8 *) (sp + 3 * 8));
-#else
- mcode[0] = *((u4 *) (sp + 3 * 8));
- mcode[1] = *((u4 *) (sp + 3 * 8 + 4));
-#endif
+
uf = (unresolved_field *) *((ptrint *) (sp + 2 * 8));
disp = *((s4 *) (sp + 1 * 8));
pv = (u1 *) *((ptrint *) (sp + 0 * 8));
if (!initialize_class(fi->class))
return false;
- /* patch back original code */
-
-#if SIZEOF_VOID_P == 8
- *((u4 *) (ra + 0 * 4)) = mcode;
- *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
- *((u4 *) (ra + 0 * 4)) = mcode[0];
- *((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
-
- /* synchronize instruction cache */
-
- md_icacheflush(ra, 2 * 4);
-
/* patch the field value's address */
*((ptrint *) (pv + disp)) = (ptrint) &(fi->value);
/* synchronize data cache */
- /*md_dcacheflush(pv + disp, SIZEOF_VOID_P);*/
+ md_dcacheflush(pv + disp, SIZEOF_VOID_P);
return true;
}
unresolved_field *uf;
fieldinfo *fi;
+ assert(0);
+
ra = (u1 *) *((ptrint *) (sp + 5 * 8));
#if SIZEOF_VOID_P == 8
mcode = *((u8 *) (sp + 3 * 8));
/* if we show disassembly, we have to skip the nop's */
- if (opt_showdisassemble)
- ra = ra + 2 * 4;
-
- /* patch the field's offset */
+ if (opt_shownops) {
+ ra = ra + PATCHER_CALL_SIZE;
#if SIZEOF_VOID_P == 4
if (fi->type == TYPE_LNG) {
else {
md_icacheflush(ra, 2 * 4);
}
+}
return true;
}
Machine code:
<patched call postition>
- dfc4ff98 ld a0,-104(s8)
+ xxx ld a0,-104(pv)
*******************************************************************************/
bool patcher_aconst(u1 *sp)
{
- u1 *ra;
-#if SIZEOF_VOID_P == 8
- u8 mcode;
-#else
- u4 mcode[2];
-#endif
constant_classref *cr;
s4 disp;
u1 *pv;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 5 * 8));
-#if SIZEOF_VOID_P == 8
- mcode = *((u8 *) (sp + 3 * 8));
-#else
- mcode[0] = *((u4 *) (sp + 3 * 8));
- mcode[1] = *((u4 *) (sp + 3 * 8 + 4));
-#endif
cr = (constant_classref *) *((ptrint *) (sp + 2 * 8));
disp = *((s4 *) (sp + 1 * 8));
pv = (u1 *) *((ptrint *) (sp + 0 * 8));
if (!(c = resolve_classref_eager(cr)))
return false;
- /* patch back original code */
-
-#if SIZEOF_VOID_P == 8
- *((u4 *) (ra + 0 * 4)) = mcode;
- *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
- *((u4 *) (ra + 0 * 4)) = mcode[0];
- *((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
-
- /* synchronize instruction cache */
-
- md_icacheflush(ra, 2 * 4);
-
/* patch the classinfo pointer */
*((ptrint *) (pv + disp)) = (ptrint) c;
/* synchronize data cache */
- /*md_dcacheflush(pv + disp, SIZEOF_VOID_P);*/
+ md_dcacheflush(pv + disp, SIZEOF_VOID_P);
return true;
}
bool patcher_builtin_multianewarray(u1 *sp)
{
- u1 *ra;
-#if SIZEOF_VOID_P == 8
- u8 mcode;
-#else
- u4 mcode[2];
-#endif
constant_classref *cr;
s4 disp;
u1 *pv;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 5 * 8));
-#if SIZEOF_VOID_P == 8
- mcode = *((u8 *) (sp + 3 * 8));
-#else
- mcode[0] = *((u4 *) (sp + 3 * 8));
- mcode[1] = *((u4 *) (sp + 3 * 8 + 4));
-#endif
cr = (constant_classref *) *((ptrint *) (sp + 2 * 8));
disp = *((s4 *) (sp + 1 * 8));
pv = (u1 *) *((ptrint *) (sp + 0 * 8));
if (!(c = resolve_classref_eager(cr)))
return false;
- /* patch back original code */
-
-#if SIZEOF_VOID_P == 8
- *((u4 *) (ra + 0 * 4)) = mcode;
- *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
- *((u4 *) (ra + 0 * 4)) = mcode[0];
- *((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
-
- /* synchronize instruction cache */
-
- md_icacheflush(ra, 2 * 4);
-
/* patch the classinfo pointer */
*((ptrint *) (pv + disp)) = (ptrint) c;
/* synchronize data cache */
- /* md_dcacheflush(pv + disp, SIZEOF_VOID_P);*/
+ md_dcacheflush(pv + disp, SIZEOF_VOID_P);
return true;
}
bool patcher_builtin_arraycheckcast(u1 *sp)
{
- u1 *ra;
-#if SIZEOF_VOID_P == 8
- u8 mcode;
-#else
- u4 mcode[2];
-#endif
constant_classref *cr;
s4 disp;
u1 *pv;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 5 * 8));
-#if SIZEOF_VOID_P == 8
- mcode = *((u8 *) (sp + 3 * 8));
-#else
- mcode[0] = *((u4 *) (sp + 3 * 8));
- mcode[1] = *((u4 *) (sp + 3 * 8 + 4));
-#endif
cr = (constant_classref *) *((ptrint *) (sp + 2 * 8));
disp = *((s4 *) (sp + 1 * 8));
pv = (u1 *) *((ptrint *) (sp + 0 * 8));
if (!(c = resolve_classref_eager(cr)))
return false;
- /* patch back original code */
-
-#if SIZEOF_VOID_P == 8
- *((u4 *) (ra + 0 * 4)) = mcode;
- *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
- *((u4 *) (ra + 0 * 4)) = mcode[0];
- *((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
-
- /* synchronize instruction cache */
-
- md_icacheflush(ra, 2 * 4);
-
/* patch the classinfo pointer */
*((ptrint *) (pv + disp)) = (ptrint) c;
/* synchronize data cache */
- /*md_dcacheflush(pv + disp, SIZEOF_VOID_P); */
+ md_dcacheflush(pv + disp, SIZEOF_VOID_P);
return true;
}
bool patcher_invokestatic_special(u1 *sp)
{
- u1 *ra;
-#if SIZEOF_VOID_P == 8
- u8 mcode;
-#else
- u4 mcode[2];
-#endif
unresolved_method *um;
s4 disp;
u1 *pv;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 5 * 8));
-#if SIZEOF_VOID_P == 8
- mcode = *((u8 *) (sp + 3 * 8));
-#else
- mcode[0] = *((u4 *) (sp + 3 * 8));
- mcode[1] = *((u4 *) (sp + 3 * 8 + 4));
-#endif
um = (unresolved_method *) *((ptrint *) (sp + 2 * 8));
disp = *((s4 *) (sp + 1 * 8));
pv = (u1 *) *((ptrint *) (sp + 0 * 8));
if (!(m = resolve_method_eager(um)))
return false;
- /* patch back original code */
-
-#if SIZEOF_VOID_P == 8
- *((u4 *) (ra + 0 * 4)) = mcode;
- *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
- *((u4 *) (ra + 0 * 4)) = mcode[0];
- *((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
-
- /* synchronize instruction cache */
-
- md_icacheflush(ra, 2 * 4);
-
/* patch stubroutine */
*((ptrint *) (pv + disp)) = (ptrint) m->stubroutine;
/* synchronize data cache */
- /* md_dcacheflush(pv + disp, SIZEOF_VOID_P);*/
+ md_dcacheflush(pv + disp, SIZEOF_VOID_P);
return true;
}
Machine code:
<patched call position>
- dc990000 ld t9,0(a0)
- df3e0040 ld s8,64(t9)
- 03c0f809 jalr s8
+ xxx ldx t9,0(a0)
+ xxx ldx s8,64(t9)
+ xxx jmpl s8
00000000 nop
*******************************************************************************/
bool patcher_invokevirtual(u1 *sp)
{
u1 *ra;
-#if SIZEOF_VOID_P == 8
- u8 mcode;
-#else
- u4 mcode[2];
-#endif
unresolved_method *um;
methodinfo *m;
+ assert(0);
+
/* get stuff from the stack */
ra = (u1 *) *((ptrint *) (sp + 5 * 8));
-#if SIZEOF_VOID_P == 8
- mcode = *((u8 *) (sp + 3 * 8));
-#else
- mcode[0] = *((u4 *) (sp + 3 * 8));
- mcode[1] = *((u4 *) (sp + 3 * 8 + 4));
-#endif
um = (unresolved_method *) *((ptrint *) (sp + 2 * 8));
/* get the fieldinfo */
if (!(m = resolve_method_eager(um)))
return false;
- /* patch back original code */
-
-#if SIZEOF_VOID_P == 8
- *((u4 *) (ra + 0 * 4)) = mcode;
- *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
- *((u4 *) (ra + 0 * 4)) = mcode[0];
- *((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
-
/* if we show disassembly, we have to skip the nop's */
- if (opt_showdisassemble)
- ra = ra + 2 * 4;
+ if (opt_shownops) {
+ ra = ra + PATCHER_CALL_SIZE;
/* patch vftbl index */
- *((s4 *) (ra + 1 * 4)) |= (s4) ((OFFSET(vftbl_t, table[0]) +
- sizeof(methodptr) * m->vftblindex) & 0x0000ffff);
+ *((s4 *) (ra + 1 * 4)) |=
+ (s4) ((OFFSET(vftbl_t, table[0]) +
+ sizeof(methodptr) * m->vftblindex) & 0x00001fff);
/* synchronize instruction cache */
- if (opt_showdisassemble)
- md_icacheflush(ra - 2 * 4, 4 * 4);
- else
- md_icacheflush(ra, 2 * 4);
+ md_icacheflush(ra + 1 * 4, 1 * 4);
+ }
+ else {
+ /* patch vftbl index */
+
+ *((s4 *) (sp + 3 * 8 + 4)) |=
+ (s4) ((OFFSET(vftbl_t, table[0]) +
+ sizeof(methodptr) * m->vftblindex) & 0x00001fff);
+ }
return true;
}
unresolved_method *um;
methodinfo *m;
+ assert(0);
+
/* get stuff from the stack */
ra = (u1 *) *((ptrint *) (sp + 5 * 8));
bool patcher_checkcast_instanceof_flags(u1 *sp)
{
- u1 *ra;
-#if SIZEOF_VOID_P == 8
- u8 mcode;
-#else
- u4 mcode[2];
-#endif
constant_classref *cr;
s4 disp;
u1 *pv;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 5 * 8));
-#if SIZEOF_VOID_P == 8
- mcode = *((u8 *) (sp + 3 * 8));
-#else
- mcode[0] = *((u4 *) (sp + 3 * 8));
- mcode[1] = *((u4 *) (sp + 3 * 8 + 4));
-#endif
cr = (constant_classref *) *((ptrint *) (sp + 2 * 8));
disp = *((s4 *) (sp + 1 * 8));
pv = (u1 *) *((ptrint *) (sp + 0 * 8));
if (!(c = resolve_classref_eager(cr)))
return false;
- /* patch back original code */
-
-#if SIZEOF_VOID_P == 8
- *((u4 *) (ra + 0 * 4)) = mcode;
- *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
- *((u4 *) (ra + 0 * 4)) = mcode[0];
- *((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
-
- /* synchronize instruction cache */
-
- md_icacheflush(ra, 2 * 4);
-
/* patch class flags */
*((s4 *) (pv + disp)) = (s4) c->flags;
/* synchronize data cache */
- /*md_dcacheflush(pv + disp, sizeof(s4)); */
+ md_dcacheflush(pv + disp, sizeof(s4));
return true;
}
constant_classref *cr;
classinfo *c;
+ assert(0);
+
/* get stuff from the stack */
ra = (u1 *) *((ptrint *) (sp + 5 * 8));
bool patcher_checkcast_instanceof_class(u1 *sp)
{
- u1 *ra;
-#if SIZEOF_VOID_P == 8
- u8 mcode;
-#else
- u4 mcode[2];
-#endif
constant_classref *cr;
s4 disp;
u1 *pv;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 5 * 8));
-#if SIZEOF_VOID_P == 8
- mcode = *((u8 *) (sp + 3 * 8));
-#else
- mcode[0] = *((u4 *) (sp + 3 * 8));
- mcode[1] = *((u4 *) (sp + 3 * 8 + 4));
-#endif
cr = (constant_classref *) *((ptrint *) (sp + 2 * 8));
disp = *((s4 *) (sp + 1 * 8));
pv = (u1 *) *((ptrint *) (sp + 0 * 8));
if (!(c = resolve_classref_eager(cr)))
return false;
- /* patch back original code */
-
-#if SIZEOF_VOID_P == 8
- *((u4 *) (ra + 0 * 4)) = mcode;
- *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
- *((u4 *) (ra + 0 * 4)) = mcode[0];
- *((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
-
- /* synchronize instruction cache */
-
- md_icacheflush(ra, 2 * 4);
-
/* patch super class' vftbl */
*((ptrint *) (pv + disp)) = (ptrint) c->vftbl;
/* synchronize data cache */
- /*md_dcacheflush(pv + disp, SIZEOF_VOID_P);*/
+ md_dcacheflush(pv + disp, SIZEOF_VOID_P);
return true;
}
bool patcher_clinit(u1 *sp)
{
- u1 *ra;
-#if SIZEOF_VOID_P == 8
- u8 mcode;
-#else
- u4 mcode[2];
-#endif
classinfo *c;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 5 * 8));
-#if SIZEOF_VOID_P == 8
- mcode = *((u8 *) (sp + 3 * 8));
-#else
- mcode[0] = *((u4 *) (sp + 3 * 8));
- mcode[1] = *((u4 *) (sp + 3 * 8 + 4));
-#endif
c = (classinfo *) *((ptrint *) (sp + 2 * 8));
/* check if the class is initialized */
if (!initialize_class(c))
return false;
- /* patch back original code */
-
-#if SIZEOF_VOID_P == 8
- *((u4 *) (ra + 0 * 4)) = mcode;
- *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
- *((u4 *) (ra + 0 * 4)) = mcode[0];
- *((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
-
- /* synchronize instruction cache */
-
- md_icacheflush(ra, 2 * 4);
-
return true;
}
#ifdef ENABLE_VERIFIER
bool patcher_athrow_areturn(u1 *sp)
{
- u1 *ra;
-#if SIZEOF_VOID_P == 8
- u8 mcode;
-#else
- u4 mcode[2];
-#endif
unresolved_class *uc;
classinfo *c;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 5 * 8));
-#if SIZEOF_VOID_P == 8
- mcode = *((u8 *) (sp + 3 * 8));
-#else
- mcode[0] = *((u4 *) (sp + 3 * 8));
- mcode[1] = *((u4 *) (sp + 3 * 8 + 4));
-#endif
uc = (unresolved_class *) *((ptrint *) (sp + 2 * 8));
/* resolve the class */
if (!resolve_class(uc, resolveEager, false, &c))
return false;
- /* patch back original code */
-
-#if SIZEOF_VOID_P == 8
- *((u4 *) (ra + 0 * 4)) = mcode;
- *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
- *((u4 *) (ra + 0 * 4)) = mcode[0];
- *((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
-
- /* synchronize instruction cache */
-
- md_icacheflush(ra, 2 * 4);
-
return true;
}
#endif /* ENABLE_VERIFIER */
#if !defined(WITH_STATIC_CLASSPATH)
bool patcher_resolve_native(u1 *sp)
{
- u1 *ra;
-#if SIZEOF_VOID_P == 8
- u8 mcode;
-#else
- u4 mcode[2];
-#endif
methodinfo *m;
s4 disp;
u1 *pv;
/* get stuff from the stack */
- ra = (u1 *) *((ptrint *) (sp + 5 * 8));
-#if SIZEOF_VOID_P == 8
- mcode = *((u8 *) (sp + 3 * 8));
-#else
- mcode[0] = *((u4 *) (sp + 3 * 8));
- mcode[1] = *((u4 *) (sp + 3 * 8 + 4));
-#endif
m = (methodinfo *) *((ptrint *) (sp + 2 * 8));
disp = *((s4 *) (sp + 1 * 8));
pv = (u1 *) *((ptrint *) (sp + 0 * 8));
if (!(f = native_resolve_function(m)))
return false;
- /* patch back original code */
-
-#if SIZEOF_VOID_P == 8
- *((u4 *) (ra + 0 * 4)) = mcode;
- *((u4 *) (ra + 1 * 4)) = mcode >> 32;
-#else
- *((u4 *) (ra + 0 * 4)) = mcode[0];
- *((u4 *) (ra + 1 * 4)) = mcode[1];
-#endif
-
- /* synchronize instruction cache */
-
- md_icacheflush(ra, 2 * 4);
-
/* patch native function pointer */
*((ptrint *) (pv + disp)) = (ptrint) f;
/* synchronize data cache */
- /*md_dcacheflush(pv + disp, SIZEOF_VOID_P);*/
+ md_dcacheflush(pv + disp, SIZEOF_VOID_P);
return true;
}