From 18557c7e9d7ece9b3173ff7bce74d999b45b557d Mon Sep 17 00:00:00 2001 From: ajordan Date: Tue, 28 Nov 2006 01:07:49 +0000 Subject: [PATCH] * src/vm/jit/sparc64/asmpart.S: fixed asm_patcher_wrapper * src/vm/jit/sparc64/patcher.c: updated some patchers and the wrapper * src/vm/jit/sparc64/emit.c: likewise * src/vm/jit/sparc64/codegen.h: fixed M_BRACC * src/vm/jit/sparc64/codegen.c: added reg window workaround for arg register copying. some patch ref updates * src/vm/jit/sparc64/md.c: updated md_codegen_patch_branch() --- src/vm/jit/sparc64/asmpart.S | 10 +- src/vm/jit/sparc64/codegen.c | 189 ++++++++--------- src/vm/jit/sparc64/codegen.h | 13 +- src/vm/jit/sparc64/emit.c | 14 +- src/vm/jit/sparc64/md-abi.c | 2 +- src/vm/jit/sparc64/md.c | 67 ++++-- src/vm/jit/sparc64/patcher.c | 384 ++++++----------------------------- 7 files changed, 226 insertions(+), 453 deletions(-) diff --git a/src/vm/jit/sparc64/asmpart.S b/src/vm/jit/sparc64/asmpart.S index f6f981809..3d402670b 100644 --- a/src/vm/jit/sparc64/asmpart.S +++ b/src/vm/jit/sparc64/asmpart.S @@ -357,9 +357,9 @@ asm_abstractmethoderror: asm_patcher_wrapper: - /* get pv and ra from current window */ - mov ra_callee,temp4 - mov pv_callee,temp5 + /* get pv and ra, since the emit code is not passing it on */ + mov ra_callee,ra_caller + mov pv_callee,pv_caller /* create window and stack frame */ save %sp,-((FLT_ARG_CNT+FLT_TMP_CNT+ABICALL_OFF+4)*8),%sp @@ -371,8 +371,8 @@ asm_patcher_wrapper: mov itmp2,%l1 /* save itmp2 */ add %fp,USESTACK,%o0 /* pass pseudo SP */ - mov temp5,%o1 /* pass PV */ - mov temp4,%o2 /* pass RA (correct for leafs) */ + mov pv_callee,%o1 /* pass PV */ + mov ra_callee,%o2 /* pass RA (correct for leafs) */ call patcher_wrapper nop diff --git a/src/vm/jit/sparc64/codegen.c b/src/vm/jit/sparc64/codegen.c index e4396290c..687c4c481 100644 --- a/src/vm/jit/sparc64/codegen.c +++ b/src/vm/jit/sparc64/codegen.c @@ -99,6 +99,7 @@ bool codegen(jitdata *jd) instruction *iptr; exception_entry *ex; u2 currentline; + constant_classref *cr; methodinfo *lm; /* local methodinfo for ICMD_INVOKE* */ unresolved_method *um; builtintable_entry *bte; @@ -183,17 +184,35 @@ bool codegen(jitdata *jd) if (cd->stackframesize) M_SAVE(REG_SP, -cd->stackframesize * 8, REG_SP); - /* save return address and used callee saved registers */ + /* save callee saved float registers */ p = cd->stackframesize; for (i = FLT_SAV_CNT - 1; i >= rd->savfltreguse; i--) { - p--; M_DST(rd->savfltregs[i], REG_SP, (WINSAVE_CNT + p) * 8); + p--; M_DST(rd->savfltregs[i], REG_SP, USESTACK + (p * 8)); } + /* take arguments out of register or stack frame */ - + md = m->parseddesc; + /* when storing locals, use this as base */ + int localbase = USESTACK; + + /* since the register allocator does not know about the shifting window + * arg regs need to be copied via the stack + */ + if (md->argintreguse > 0) { + /* allocate scratch space for copying in to save(i&l) regs */ + M_SUB_IMM(REG_SP, INT_ARG_CNT * 8, REG_SP); + + localbase += INT_ARG_CNT * 8; + + for (p = 0; p < INT_ARG_CNT; p++) + M_STX(REG_WINDOW_TRANSPOSE(rd->argintregs[p]), REG_SP, USESTACK + (p * 8)); + } + + for (p = 0, l = 0; p < md->paramcount; p++) { t = md->paramtypes[p].type; @@ -211,18 +230,22 @@ bool codegen(jitdata *jd) s1 = md->params[p].regoff; if (IS_INT_LNG_TYPE(t)) { /* integer args */ if (!md->params[p].inmemory) { /* register arguments */ - s2 = rd->argintregs[s1]; - s2 = REG_WINDOW_TRANSPOSE(s2); + /*s2 = rd->argintregs[s1];*/ + /*s2 = REG_WINDOW_TRANSPOSE(s2);*/ if (!(var->flags & INMEMORY)) { /* reg arg -> register */ - M_INTMOVE(s2, var->vv.regoff); + /*M_INTMOVE(s2, var->vv.regoff);*/ + M_LDX(var->vv.regoff, REG_SP, USESTACK + (s1 * 8)); } else { /* reg arg -> spilled */ - M_STX(s2, REG_SP, (WINSAVE_CNT + var->vv.regoff) * 8); + /*M_STX(s2, REG_SP, (WINSAVE_CNT + var->vv.regoff) * 8);*/ + + M_LDX(REG_ITMP1, REG_SP, USESTACK + (s1 * 8)); + M_STX(REG_ITMP1, REG_SP, localbase + (var->vv.regoff * 8)); } } else { /* stack arguments */ if (!(var->flags & INMEMORY)) { /* stack arg -> register */ - M_LDX(var->vv.regoff, REG_SP, (cd->stackframesize + s1) * 8); + M_LDX(var->vv.regoff, REG_FP, (WINSAVE_CNT + s1) * 8); } else { /* stack arg -> spilled */ var->vv.regoff = cd->stackframesize + s1; @@ -236,12 +259,12 @@ bool codegen(jitdata *jd) M_FLTMOVE(s2, var->vv.regoff); } else { /* reg arg -> spilled */ - M_DST(s2, REG_SP, (WINSAVE_CNT + var->vv.regoff) * 8); + M_DST(s2, REG_SP, localbase + (var->vv.regoff) * 8); } } else { /* stack arguments */ if (!(var->flags & INMEMORY)) { /* stack-arg -> register */ - M_DLD(var->vv.regoff, REG_SP, (cd->stackframesize + s1) * 8); + M_DLD(var->vv.regoff, REG_FP, (WINSAVE_CNT + s1) * 8); } else { /* stack-arg -> spilled */ var->vv.regoff = cd->stackframesize + s1; @@ -250,6 +273,11 @@ bool codegen(jitdata *jd) } } /* end for */ + if (md->argintreguse > 0) { + /* release scratch space */ + M_ADD_IMM(REG_SP, INT_ARG_CNT * 8, REG_SP); + } + /* XXX monitor enter */ @@ -275,21 +303,17 @@ bool codegen(jitdata *jd) /* branch resolving */ - { - branchref *brefs; - for (brefs = bptr->branchrefs; brefs != NULL; brefs = brefs->next) { - gen_resolvebranch((u1*) cd->mcodebase + brefs->branchpos, - brefs->branchpos, bptr->mpc); - } - } + codegen_resolve_branchrefs(cd, bptr); /* handle replacement points */ +#if 0 if (bptr->bitflags & BBFLAG_REPLACEMENT) { replacementpoint->pc = (u1*)(ptrint)bptr->mpc; /* will be resolved later */ replacementpoint++; } +#endif /* copy interface registers to their destination */ @@ -385,23 +409,20 @@ bool codegen(jitdata *jd) d = codegen_reg_of_dst(jd, iptr, REG_ITMP1); if (INSTRUCTION_IS_UNRESOLVED(iptr)) { - disp = dseg_addaddress(cd, NULL); - - codegen_addpatchref(cd, PATCHER_aconst, - iptr->sx.val.c.ref, - disp); + cr = iptr->sx.val.c.ref; + disp = dseg_add_unique_address(cd, cr); - if (opt_showdisassemble) { - M_NOP; M_NOP; - } + codegen_add_patch_ref(cd, PATCHER_aconst, cr, disp); M_ALD(d, REG_PV, disp); - } else { + } + else { if (iptr->sx.val.anyptr == NULL) { M_INTMOVE(REG_ZERO, d); - } else { - disp = dseg_addaddress(cd, iptr->sx.val.anyptr); + } + else { + disp = dseg_add_address(cd, iptr->sx.val.anyptr); M_ALD(d, REG_PV, disp); } } @@ -1469,59 +1490,45 @@ bool codegen(jitdata *jd) if (INSTRUCTION_IS_UNRESOLVED(iptr)) { unresolved_field *uf = iptr->sx.s23.s3.uf; - fieldtype = uf->fieldref->parseddesc.fd->type; + disp = dseg_add_unique_address(cd, uf); - disp = dseg_addaddress(cd, NULL); - - codegen_addpatchref(cd, PATCHER_get_putstatic, uf, disp); - - if (opt_showdisassemble) { - M_NOP; M_NOP; - } - - } else { + codegen_add_patch_ref(cd, PATCHER_get_putstatic, uf, disp); + } + else { fieldinfo *fi = iptr->sx.s23.s3.fmiref->p.field; + fieldtype = fi->type; + disp = dseg_add_address(cd, &(fi->value)); - disp = dseg_addaddress(cd, &(fi->value)); - - if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) { - codegen_addpatchref(cd, PATCHER_clinit, fi->class, 0); - - if (opt_showdisassemble) { - M_NOP; M_NOP; - } - } + if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) + codegen_add_patch_ref(cd, PATCHER_clinit, fi->class, disp); } M_ALD(REG_ITMP1, REG_PV, disp); + switch (fieldtype) { case TYPE_INT: d = codegen_reg_of_dst(jd, iptr, REG_ITMP2); M_ILD_INTERN(d, REG_ITMP1, 0); - emit_store_dst(jd, iptr, d); break; case TYPE_LNG: d = codegen_reg_of_dst(jd, iptr, REG_ITMP2); M_LDX_INTERN(d, REG_ITMP1, 0); - emit_store_dst(jd, iptr, d); break; case TYPE_ADR: d = codegen_reg_of_dst(jd, iptr, REG_ITMP2); M_ALD_INTERN(d, REG_ITMP1, 0); - emit_store_dst(jd, iptr, d); break; case TYPE_FLT: d = codegen_reg_of_dst(jd, iptr, REG_FTMP1); M_FLD_INTERN(d, REG_ITMP1, 0); - emit_store_dst(jd, iptr, d); break; case TYPE_DBL: d = codegen_reg_of_dst(jd, iptr, REG_FTMP1); M_DLD_INTERN(d, REG_ITMP1, 0); - emit_store_dst(jd, iptr, d); break; } + emit_store_dst(jd, iptr, d); break; case ICMD_PUTSTATIC: /* ..., value ==> ... */ @@ -1530,51 +1537,41 @@ bool codegen(jitdata *jd) unresolved_field *uf = iptr->sx.s23.s3.uf; fieldtype = uf->fieldref->parseddesc.fd->type; + disp = dseg_add_unique_address(cd, uf); - disp = dseg_addaddress(cd, NULL); - - codegen_addpatchref(cd, PATCHER_get_putstatic, - iptr->sx.s23.s3.uf, disp); - - if (opt_showdisassemble) { - M_NOP; M_NOP; - } - - } else { + codegen_add_patch_ref(cd, PATCHER_get_putstatic, uf, disp); + } + else { fieldinfo *fi = iptr->sx.s23.s3.fmiref->p.field; + fieldtype = fi->type; + disp = dseg_add_address(cd, &(fi->value)); - disp = dseg_addaddress(cd, &(fi->value)); - - if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) { - codegen_addpatchref(cd, PATCHER_clinit, fi->class, 0); - - if (opt_showdisassemble) { - M_NOP; M_NOP; - } - } + if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) + codegen_add_patch_ref(cd, PATCHER_clinit, fi->class, disp); } M_ALD(REG_ITMP1, REG_PV, disp); + switch (fieldtype) { case TYPE_INT: - s2 = emit_load_s2(jd, iptr, REG_ITMP2); - M_IST_INTERN(s2, REG_ITMP1, 0); + s1 = emit_load_s1(jd, iptr, REG_ITMP2); + M_IST_INTERN(s1, REG_ITMP1, 0); break; case TYPE_LNG: - s2 = emit_load_s2(jd, iptr, REG_ITMP2); - M_STX_INTERN(s2, REG_ITMP1, 0); + s1 = emit_load_s1(jd, iptr, REG_ITMP2); + M_STX_INTERN(s1, REG_ITMP1, 0); break; case TYPE_ADR: - s2 = emit_load_s2(jd, iptr, REG_ITMP2); - M_AST_INTERN(s2, REG_ITMP1, 0); + s1 = emit_load_s1(jd, iptr, REG_ITMP2); + M_AST_INTERN(s1, REG_ITMP1, 0); break; case TYPE_FLT: - s2 = emit_load_s2(jd, iptr, REG_FTMP2); - M_FST_INTERN(s2, REG_ITMP1, 0); + s1 = emit_load_s1(jd, iptr, REG_FTMP2); + M_FST_INTERN(s1, REG_ITMP1, 0); break; case TYPE_DBL: - s2 = emit_load_s2(jd, iptr, REG_FTMP2); - M_DST_INTERN(s2, REG_ITMP1, 0); + s1 = emit_load_s1(jd, iptr, REG_FTMP2); + M_DST_INTERN(s1, REG_ITMP1, 0); break; } break; @@ -1585,36 +1582,22 @@ bool codegen(jitdata *jd) if (INSTRUCTION_IS_UNRESOLVED(iptr)) { unresolved_field *uf = iptr->sx.s23.s3.uf; - fieldtype = uf->fieldref->parseddesc.fd->type; + disp = dseg_add_unique_address(cd, uf); - disp = dseg_addaddress(cd, NULL); - - codegen_addpatchref(cd, PATCHER_get_putstatic, - uf, disp); - - if (opt_showdisassemble) { - M_NOP; M_NOP; - } - - } else { + codegen_add_patch_ref(cd, PATCHER_get_putstatic, uf, disp); + } + else { fieldinfo *fi = iptr->sx.s23.s3.fmiref->p.field; - fieldtype = fi->type; + disp = dseg_add_address(cd, &(fi->value)); - - disp = dseg_addaddress(cd, &(fi->value)); - - if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) { - codegen_addpatchref(cd, PATCHER_clinit, fi->class, 0); - - if (opt_showdisassemble) { - M_NOP; M_NOP; - } - } + if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) + codegen_add_patch_ref(cd, PATCHER_clinit, fi->class, disp); } M_ALD(REG_ITMP1, REG_PV, disp); + switch (fieldtype) { case TYPE_INT: M_IST_INTERN(REG_ZERO, REG_ITMP1, 0); diff --git a/src/vm/jit/sparc64/codegen.h b/src/vm/jit/sparc64/codegen.h index e1587fe00..2bbe9dcc4 100644 --- a/src/vm/jit/sparc64/codegen.h +++ b/src/vm/jit/sparc64/codegen.h @@ -42,6 +42,11 @@ #include "vm/jit/jit.h" +/* some defines ***************************************************************/ + +#define PATCHER_CALL_INSTRUCTIONS 2 /* number of instructions */ +#define PATCHER_CALL_SIZE 2 * 4 /* size in bytes of a patcher call */ + /* additional functions and macros to generate code ***************************/ @@ -81,6 +86,12 @@ if ((s4) ((ptrint) cd->mcodeptr & 7)) { \ M_NOP; \ } + +#define PATCHER_NOPS \ + do { \ + M_NOP; \ + M_NOP; \ + } while (0) /* M_INTMOVE: @@ -228,7 +239,7 @@ #define M_BRACC(op,op2,cond,disp19,ccx,p,anul) \ do { \ *((u4 *) cd->mcodeptr) = ( (((s4)(op))<<30) | ((anul)<<29) | ((cond)<<25) | (op2<<22) | (ccx<<20) | \ - (p << 19 ) | (disp19) ); \ + (p << 19 ) | ((disp19) & 0x007ffff) ); \ cd->mcodeptr += 4; \ } while (0) diff --git a/src/vm/jit/sparc64/emit.c b/src/vm/jit/sparc64/emit.c index 9ce6e5121..299b162a7 100644 --- a/src/vm/jit/sparc64/emit.c +++ b/src/vm/jit/sparc64/emit.c @@ -254,12 +254,12 @@ void emit_patcher_stubs(jitdata *jd) savedmcodeptr = cd->mcodeptr; /* save current mcodeptr */ cd->mcodeptr = tmpmcodeptr; /* set mcodeptr to patch position */ - disp = ((u4 *) savedmcodeptr) - (((u4 *) tmpmcodeptr) + 1); -/* XXX TODO imm?? */ - if ((disp < (s4) 0xffff8000) || (disp > (s4) 0x00007fff)) { + disp = ((u4 *) savedmcodeptr) - (((u4 *) tmpmcodeptr) ); + + if ((disp < (s4) 0xfffc0000) || (disp > (s4) 0x003ffff)) { *exceptionptr = new_internalerror("Jump offset is out of range: %d > +/-%d", - disp, 0x00007fff); + disp, 0x003ffff); return; } @@ -323,14 +323,14 @@ void emit_patcher_stubs(jitdata *jd) if (targetdisp == 0) { targetdisp = ((u4 *) cd->mcodeptr) - ((u4 *) cd->mcodebase); - disp = dseg_addaddress(cd, asm_patcher_wrapper); + disp = dseg_add_functionptr(cd, asm_patcher_wrapper); M_ALD(REG_ITMP3, REG_PV, disp); M_JMP(REG_ZERO, REG_ITMP3, REG_ZERO); M_NOP; -} + } else { disp = (((u4 *) cd->mcodebase) + targetdisp) - - (((u4 *) cd->mcodeptr) + 1); + (((u4 *) cd->mcodeptr)); M_BR(disp); M_NOP; diff --git a/src/vm/jit/sparc64/md-abi.c b/src/vm/jit/sparc64/md-abi.c index a6c5e8a6b..0e746cbc8 100644 --- a/src/vm/jit/sparc64/md-abi.c +++ b/src/vm/jit/sparc64/md-abi.c @@ -54,7 +54,7 @@ s4 nregdescint[] = { /* zero itmp1/g1 itmp2/g2 itmp3/g3 temp/g4 temp/g5 sys/g6 sys/g7 */ REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, - /* o0 o1 o2 o3 o4 pv/o5 sp/o6 o7/ra */ + /* o0 o1 o2 o3 o4 pv/o5 sp/o6 ra/o7 */ REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_RES, REG_RES, REG_RES, /* l0 l1 l2 l3 l4 l5 l6 l7 */ diff --git a/src/vm/jit/sparc64/md.c b/src/vm/jit/sparc64/md.c index f07db41df..67a169167 100644 --- a/src/vm/jit/sparc64/md.c +++ b/src/vm/jit/sparc64/md.c @@ -61,8 +61,6 @@ void md_codegen_patch_branch(codegendata *cd, s4 branchmpc, s4 targetmpc) s4 mcode; s4 disp; /* branch displacement */ - assert(0); - /* calculate the patch position */ mcodeptr = (s4 *) (cd->mcodebase + branchmpc); @@ -71,23 +69,43 @@ void md_codegen_patch_branch(codegendata *cd, s4 branchmpc, s4 targetmpc) mcode = mcodeptr[-1]; - /* check for BPcc instruction */ - if (((mcode >> 16) & 0xc1c0) != 0x0040) - assert(0); - - /* Calculate the branch displacement. For branches we need a - displacement relative and shifted to the branch PC. */ - - disp = (targetmpc - branchmpc) >> 2; - - /* check branch displacement */ - - if ((disp < (s4) 0xfffc0000) || (disp > (s4) 0x003ffff)) - vm_abort("branch displacement is out of range: %d > +/-%d", disp, 0x003ffff); - - /* patch the branch instruction before the mcodeptr */ + /* check for BPcc or FBPfcc instruction */ + if (((mcode >> 16) & 0xc1c0) == 0x0040) { + + + /* Calculate the branch displacement. For branches we need a + displacement relative and shifted to the branch PC. */ + + disp = (targetmpc - branchmpc) >> 2; + + /* check branch displacement (19-bit)*/ + + if ((disp < (s4) 0xfffc0000) || (disp > (s4) 0x003ffff)) + vm_abort("branch displacement is out of range: %d > +/-%d", disp, 0x003ffff); + + /* patch the branch instruction before the mcodeptr */ + + mcodeptr[-1] |= (disp & 0x003ffff); + } + /* check for BPr instruction */ + else if (((mcode >> 16) & 0xd1c0) == 0x00c0) { - mcodeptr[-1] |= (disp & 0x003ffff); + /* check branch displacement (16-bit)*/ + + disp = (targetmpc - branchmpc) >> 2; + + if ((disp < (s4) 0xffff8000) || (disp > (s4) 0x0007fff)) + vm_abort("branch displacement is out of range: %d > +/-%d", disp, 0x0007fff); + + /* patch the upper 2-bit of the branch displacement */ + mcodeptr[-1] |= ((disp & 0xc000) << 6); + + /* patch the lower 14-bit of the branch displacement */ + mcodeptr[-1] |= (disp & 0x003fff); + + } + else + assert(0); } @@ -297,7 +315,18 @@ void md_cacheflush(u1 *addr, s4 nbytes) void md_icacheflush(u1 *addr, s4 nbytes) { - /* don't know yet */ + /* XXX don't know yet */ +} + +/* md_dcacheflush ************************************************************** + + Calls the system's function to flush the data cache. + +*******************************************************************************/ + +void md_dcacheflush(u1 *addr, s4 nbytes) +{ + /* XXX don't know yet */ } diff --git a/src/vm/jit/sparc64/patcher.c b/src/vm/jit/sparc64/patcher.c index a8a03d1b4..0939fd2c6 100644 --- a/src/vm/jit/sparc64/patcher.c +++ b/src/vm/jit/sparc64/patcher.c @@ -39,6 +39,8 @@ #include "vm/types.h" +#include "vm/jit/sparc64/codegen.h" + #include "mm/memory.h" #include "native/native.h" #include "vm/builtin.h" @@ -72,6 +74,11 @@ java_objectheader *patcher_wrapper(u1 *sp, u1 *pv, u1 *ra) 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; @@ -127,6 +134,26 @@ java_objectheader *patcher_wrapper(u1 *sp, u1 *pv, u1 *ra) 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; @@ -138,19 +165,13 @@ java_objectheader *patcher_wrapper(u1 *sp, u1 *pv, u1 *ra) Machine code: - 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; @@ -158,13 +179,7 @@ bool patcher_get_putstatic(u1 *sp) /* 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)); @@ -180,27 +195,13 @@ bool patcher_get_putstatic(u1 *sp) 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; } @@ -226,6 +227,8 @@ bool patcher_get_putfield(u1 *sp) unresolved_field *uf; fieldinfo *fi; + assert(0); + ra = (u1 *) *((ptrint *) (sp + 5 * 8)); #if SIZEOF_VOID_P == 8 mcode = *((u8 *) (sp + 3 * 8)); @@ -252,10 +255,8 @@ bool patcher_get_putfield(u1 *sp) /* 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) { @@ -285,6 +286,7 @@ bool patcher_get_putfield(u1 *sp) else { md_icacheflush(ra, 2 * 4); } +} return true; } @@ -295,18 +297,12 @@ bool patcher_get_putfield(u1 *sp) Machine code: - 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; @@ -314,13 +310,6 @@ bool patcher_aconst(u1 *sp) /* 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)); @@ -330,27 +319,13 @@ bool patcher_aconst(u1 *sp) 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; } @@ -371,12 +346,6 @@ bool patcher_aconst(u1 *sp) 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; @@ -384,13 +353,6 @@ bool patcher_builtin_multianewarray(u1 *sp) /* 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)); @@ -400,27 +362,13 @@ bool patcher_builtin_multianewarray(u1 *sp) 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; } @@ -440,12 +388,6 @@ bool patcher_builtin_multianewarray(u1 *sp) 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; @@ -453,13 +395,6 @@ bool patcher_builtin_arraycheckcast(u1 *sp) /* 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)); @@ -469,27 +404,13 @@ bool patcher_builtin_arraycheckcast(u1 *sp) 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; } @@ -508,12 +429,6 @@ bool patcher_builtin_arraycheckcast(u1 *sp) 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; @@ -521,13 +436,6 @@ bool patcher_invokestatic_special(u1 *sp) /* 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)); @@ -537,27 +445,13 @@ bool patcher_invokestatic_special(u1 *sp) 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; } @@ -568,9 +462,9 @@ bool patcher_invokestatic_special(u1 *sp) Machine code: - 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 *******************************************************************************/ @@ -578,23 +472,14 @@ bool patcher_invokestatic_special(u1 *sp) 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 */ @@ -602,32 +487,28 @@ bool patcher_invokevirtual(u1 *sp) 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; } @@ -657,6 +538,8 @@ bool patcher_invokeinterface(u1 *sp) unresolved_method *um; methodinfo *m; + assert(0); + /* get stuff from the stack */ ra = (u1 *) *((ptrint *) (sp + 5 * 8)); @@ -723,12 +606,6 @@ bool patcher_invokeinterface(u1 *sp) 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; @@ -736,13 +613,6 @@ bool patcher_checkcast_instanceof_flags(u1 *sp) /* 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)); @@ -752,27 +622,13 @@ bool patcher_checkcast_instanceof_flags(u1 *sp) 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; } @@ -803,6 +659,8 @@ bool patcher_checkcast_instanceof_interface(u1 *sp) constant_classref *cr; classinfo *c; + assert(0); + /* get stuff from the stack */ ra = (u1 *) *((ptrint *) (sp + 5 * 8)); @@ -864,12 +722,6 @@ bool patcher_checkcast_instanceof_interface(u1 *sp) 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; @@ -877,13 +729,6 @@ bool patcher_checkcast_instanceof_class(u1 *sp) /* 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)); @@ -893,27 +738,13 @@ bool patcher_checkcast_instanceof_class(u1 *sp) 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; } @@ -927,23 +758,10 @@ bool patcher_checkcast_instanceof_class(u1 *sp) 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 */ @@ -952,20 +770,6 @@ bool patcher_clinit(u1 *sp) 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; } @@ -981,24 +785,11 @@ bool patcher_clinit(u1 *sp) #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 */ @@ -1006,20 +797,6 @@ bool patcher_athrow_areturn(u1 *sp) 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 */ @@ -1034,12 +811,6 @@ bool patcher_athrow_areturn(u1 *sp) #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; @@ -1047,13 +818,6 @@ bool patcher_resolve_native(u1 *sp) /* 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)); @@ -1065,27 +829,13 @@ bool patcher_resolve_native(u1 *sp) 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; } -- 2.25.1