memory. All functions writing values into the data area return the offset
relative the begin of the code area (start of procedure).
- $Id: codegen-common.c 4609 2006-03-15 05:13:21Z edwin $
+ $Id: codegen-common.c 4615 2006-03-15 16:36:43Z twisti $
*/
cd->datareferences = NULL;
#endif
- cd->xboundrefs = NULL;
- cd->xnullrefs = NULL;
- cd->xcastrefs = NULL;
- cd->xstorerefs = NULL;
- cd->xdivrefs = NULL;
- cd->xexceptionrefs = NULL;
- cd->patchrefs = NULL;
+ cd->exceptionrefs = NULL;
+ cd->patchrefs = NULL;
cd->linenumberreferences = NULL;
cd->linenumbertablesizepos = 0;
}
-/* codegen_addxboundrefs *******************************************************
+/* codegen_add_exception_ref ***************************************************
- Adds an ArrayIndexOutOfBoundsException branch to the list.
+ Adds an exception branch to the list.
*******************************************************************************/
-void codegen_addxboundrefs(codegendata *cd, void *branchptr, s4 reg)
+static void codegen_add_exception_ref(codegendata *cd, void *branchptr, s4 reg,
+ functionptr function)
{
- s4 branchpos;
- branchref *br;
+ s4 branchpos;
+ exceptionref *eref;
branchpos = (u1 *) branchptr - cd->mcodebase;
- br = DNEW(branchref);
+ eref = DNEW(exceptionref);
- br->branchpos = branchpos;
- br->reg = reg;
- br->next = cd->xboundrefs;
+ eref->branchpos = branchpos;
+ eref->reg = reg;
+ eref->function = function;
+ eref->next = cd->exceptionrefs;
- cd->xboundrefs = br;
+ cd->exceptionrefs = eref;
}
-/* codegen_addxcastrefs ********************************************************
+/* codegen_add_arithmeticexception_ref *****************************************
- Adds an ClassCastException branch to the list.
+ Adds an ArithmeticException branch to the list.
*******************************************************************************/
-void codegen_addxcastrefs(codegendata *cd, void *branchptr)
+void codegen_add_arithmeticexception_ref(codegendata *cd, void *branchptr)
{
- s4 branchpos;
- branchref *br;
-
- branchpos = (u1 *) branchptr - cd->mcodebase;
-
- br = DNEW(branchref);
-
- br->branchpos = branchpos;
- br->next = cd->xcastrefs;
-
- cd->xcastrefs = br;
+ codegen_add_exception_ref(cd, branchptr, -1,
+ STACKTRACE_inline_arithmeticexception);
}
-/* codegen_addxdivrefs *********************************************************
+/* codegen_add_arrayindexoutofboundsexception_ref ******************************
- Adds an ArithmeticException branch to the list.
+ Adds an ArrayIndexOutOfBoundsException branch to the list.
*******************************************************************************/
-void codegen_addxdivrefs(codegendata *cd, void *branchptr)
+void codegen_add_arrayindexoutofboundsexception_ref(codegendata *cd,
+ void *branchptr, s4 reg)
{
- s4 branchpos;
- branchref *br;
-
- branchpos = (u1 *) branchptr - cd->mcodebase;
-
- br = DNEW(branchref);
-
- br->branchpos = branchpos;
- br->next = cd->xdivrefs;
-
- cd->xdivrefs = br;
+ codegen_add_exception_ref(cd, branchptr, reg,
+ STACKTRACE_inline_arrayindexoutofboundsexception);
}
-/* codegen_addxstorerefs *******************************************************
+/* codegen_add_arraystoreexception_ref *****************************************
Adds an ArrayStoreException branch to the list.
*******************************************************************************/
-void codegen_addxstorerefs(codegendata *cd, void *branchptr)
+void codegen_add_arraystoreexception_ref(codegendata *cd, void *branchptr)
{
- s4 branchpos;
- branchref *br;
+ codegen_add_exception_ref(cd, branchptr, -1,
+ STACKTRACE_inline_arraystoreexception);
+}
- branchpos = (u1 *) branchptr - cd->mcodebase;
- br = DNEW(branchref);
+/* codegen_add_classcastexception_ref ******************************************
+
+ Adds an ClassCastException branch to the list.
- br->branchpos = branchpos;
- br->next = cd->xstorerefs;
+*******************************************************************************/
- cd->xstorerefs = br;
+void codegen_add_classcastexception_ref(codegendata *cd, void *branchptr)
+{
+ codegen_add_exception_ref(cd, branchptr, -1,
+ STACKTRACE_inline_classcastexception);
}
-/* codegen_addxnullrefs ********************************************************
+/* codegen_add_nullpointerexception_ref ****************************************
Adds an NullPointerException branch to the list.
*******************************************************************************/
-void codegen_addxnullrefs(codegendata *cd, void *branchptr)
+void codegen_add_nullpointerexception_ref(codegendata *cd, void *branchptr)
{
- s4 branchpos;
- branchref *br;
-
- branchpos = (u1 *) branchptr - cd->mcodebase;
-
- br = DNEW(branchref);
-
- br->branchpos = branchpos;
- br->next = cd->xnullrefs;
-
- cd->xnullrefs = br;
+ codegen_add_exception_ref(cd, branchptr, -1,
+ STACKTRACE_inline_nullpointerexception);
}
-/* codegen_addxexceptionsrefs **************************************************
+/* codegen_add_fillinstacktrace_ref ********************************************
- Adds an common exception branch to the list.
+ Adds a fillInStackTrace branch to the list.
*******************************************************************************/
-void codegen_addxexceptionrefs(codegendata *cd, void *branchptr)
+void codegen_add_fillinstacktrace_ref(codegendata *cd, void *branchptr)
{
- s4 branchpos;
- branchref *br;
-
- branchpos = (u1 *) branchptr - cd->mcodebase;
-
- br = DNEW(branchref);
-
- br->branchpos = branchpos;
- br->next = cd->xexceptionrefs;
-
- cd->xexceptionrefs = br;
+ codegen_add_exception_ref(cd, branchptr, -1,
+ STACKTRACE_inline_fillInStackTrace);
}
Changes: Christian Ullrich
Edwin Steiner
- $Id: codegen.c 4598 2006-03-14 22:16:47Z edwin $
+ $Id: codegen.c 4615 2006-03-15 16:36:43Z twisti $
*/
if (opt_prof) {
/* count frequency */
- M_MOV_IMM((ptrint) m, REG_ITMP3);
+ M_MOV_IMM(m, REG_ITMP3);
M_IINC_MEMBASE(REG_ITMP3, OFFSET(methodinfo, frequency));
PROFILE_CYCLE_START;
/* decide which monitor enter function to call */
if (m->flags & ACC_STATIC) {
- M_MOV_IMM((ptrint) m->class, REG_ITMP1);
+ M_MOV_IMM(m->class, REG_ITMP1);
M_AST(REG_ITMP1, REG_SP, s1 * 8);
M_INTMOVE(REG_ITMP1, rd->argintregs[0]);
- M_MOV_IMM((ptrint) BUILTIN_staticmonitorenter, REG_ITMP1);
+ M_MOV_IMM(BUILTIN_staticmonitorenter, REG_ITMP1);
M_CALL(REG_ITMP1);
} else {
M_TEST(rd->argintregs[0]);
- x86_64_jcc(cd, X86_64_CC_Z, 0);
- codegen_addxnullrefs(cd, cd->mcodeptr);
+ M_BEQ(0);
+ codegen_add_nullpointerexception_ref(cd, cd->mcodeptr);
M_AST(rd->argintregs[0], REG_SP, s1 * 8);
- M_MOV_IMM((ptrint) BUILTIN_monitorenter, REG_ITMP1);
+ M_MOV_IMM(BUILTIN_monitorenter, REG_ITMP1);
M_CALL(REG_ITMP1);
}
}
}
- M_MOV_IMM((ptrint) m, REG_ITMP2);
+ M_MOV_IMM(m, REG_ITMP2);
M_AST(REG_ITMP2, REG_SP, 0 * 8);
- M_MOV_IMM((ptrint) builtin_trace_args, REG_ITMP1);
+ M_MOV_IMM(builtin_trace_args, REG_ITMP1);
M_CALL(REG_ITMP1);
/* restore integer argument registers */
if (opt_prof_bb) {
/* count frequency */
- M_MOV_IMM((ptrint) m->bbfrequency, REG_ITMP2);
+ M_MOV_IMM(m->bbfrequency, REG_ITMP2);
M_IINC_MEMBASE(REG_ITMP2, bptr->debug_nr * 4);
/* if this is an exception handler, start profiling again */
else
M_TEST(src->regoff);
M_BEQ(0);
- codegen_addxnullrefs(cd, cd->mcodeptr);
+ codegen_add_nullpointerexception_ref(cd, cd->mcodeptr);
break;
/* constant operations ************************************************/
/* PROFILE_CYCLE_START; */
- M_MOV_IMM((ptrint) iptr->val.a, d);
+ M_MOV_IMM(iptr->val.a, d);
} else {
if (iptr->val.a == 0)
M_CLR(d);
else
- M_MOV_IMM((ptrint) iptr->val.a, d);
+ M_MOV_IMM(iptr->val.a, d);
}
store_reg_to_var_int(iptr->dst, d);
break;
M_MOV(s1, rd->argintregs[0]);
M_MOV(s3, rd->argintregs[1]);
- M_MOV_IMM((ptrint) BUILTIN_canstore, REG_ITMP1);
+ M_MOV_IMM(BUILTIN_canstore, REG_ITMP1);
M_CALL(REG_ITMP1);
M_TEST(REG_RESULT);
M_BEQ(0);
- codegen_addxstorerefs(cd, cd->mcodeptr);
+ codegen_add_arraystoreexception_ref(cd, cd->mcodeptr);
var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
var_to_reg_int(s2, src->prev, REG_ITMP2);
M_CALL_IMM(0); /* passing exception pc */
M_POP(REG_ITMP2_XPC);
- M_MOV_IMM((ptrint) asm_handle_exception, REG_ITMP3);
+ M_MOV_IMM(asm_handle_exception, REG_ITMP3);
M_JMP(REG_ITMP3);
break;
break;
}
- M_MOV_IMM((ptrint) builtin_monitorexit, REG_ITMP1);
+ M_MOV_IMM(builtin_monitorexit, REG_ITMP1);
M_CALL(REG_ITMP1);
/* and now restore the proper return value */
if (iptr->op1 == true) {
M_TEST(REG_RESULT);
M_BEQ(0);
- codegen_addxexceptionrefs(cd, cd->mcodeptr);
+ codegen_add_fillinstacktrace_ref(cd, cd->mcodeptr);
}
break;
case ICMD_INVOKESPECIAL:
M_TEST(rd->argintregs[0]);
M_BEQ(0);
- codegen_addxnullrefs(cd, cd->mcodeptr);
+ codegen_add_nullpointerexception_ref(cd, cd->mcodeptr);
/* first argument contains pointer */
/* gen_nullptr_check(rd->argintregs[0]); */
M_LSUB_IMM32(superindex, REG_ITMP3);
M_TEST(REG_ITMP3);
M_BLE(0);
- codegen_addxcastrefs(cd, cd->mcodeptr);
+ codegen_add_classcastexception_ref(cd, cd->mcodeptr);
x86_64_mov_membase32_reg(cd, REG_ITMP2,
OFFSET(vftbl_t, interfacetable[0]) -
superindex * sizeof(methodptr*),
REG_ITMP3);
M_TEST(REG_ITMP3);
M_BEQ(0);
- codegen_addxcastrefs(cd, cd->mcodeptr);
+ codegen_add_classcastexception_ref(cd, cd->mcodeptr);
if (!super)
M_JMP_IMM(s3);
}
}
- M_MOV_IMM((ptrint) supervftbl, REG_ITMP3);
+ M_MOV_IMM(supervftbl, REG_ITMP3);
#if defined(USE_THREADS) && defined(NATIVE_THREADS)
codegen_threadcritstart(cd, cd->mcodeptr - cd->mcodebase);
#endif
OFFSET(vftbl_t, baseval),
REG_ITMP3);
M_LSUB(REG_ITMP3, REG_ITMP2);
- M_MOV_IMM((ptrint) supervftbl, REG_ITMP3);
+ M_MOV_IMM(supervftbl, REG_ITMP3);
M_ILD(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, diffval));
/* } */
#if defined(USE_THREADS) && defined(NATIVE_THREADS)
#endif
M_CMP(REG_ITMP3, REG_ITMP2);
M_BA(0); /* (u) REG_ITMP1 > (u) REG_ITMP2 -> jump */
- codegen_addxcastrefs(cd, cd->mcodeptr);
+ codegen_add_classcastexception_ref(cd, cd->mcodeptr);
}
d = reg_of_var(rd, iptr->dst, REG_ITMP3);
}
}
- M_MOV_IMM((ptrint) iptr->val.a, rd->argintregs[1]);
- M_MOV_IMM((ptrint) BUILTIN_arraycheckcast, REG_ITMP1);
+ M_MOV_IMM(iptr->val.a, rd->argintregs[1]);
+ M_MOV_IMM(BUILTIN_arraycheckcast, REG_ITMP1);
M_CALL(REG_ITMP1);
M_TEST(REG_RESULT);
M_BEQ(0);
- codegen_addxcastrefs(cd, cd->mcodeptr);
+ codegen_add_classcastexception_ref(cd, cd->mcodeptr);
var_to_reg_int(s1, src, REG_ITMP1);
d = reg_of_var(rd, iptr->dst, REG_ITMP1);
/* a1 = arrayvftbl */
- M_MOV_IMM((ptrint) iptr->val.a, rd->argintregs[1]);
+ M_MOV_IMM(iptr->val.a, rd->argintregs[1]);
/* a2 = pointer to dimensions = stack pointer */
M_MOV(REG_SP, rd->argintregs[2]);
- M_MOV_IMM((ptrint) BUILTIN_multianewarray, REG_ITMP1);
+ M_MOV_IMM(BUILTIN_multianewarray, REG_ITMP1);
M_CALL(REG_ITMP1);
/* check for exception before result assignment */
M_TEST(REG_RESULT);
M_BEQ(0);
- codegen_addxexceptionrefs(cd, cd->mcodeptr);
+ codegen_add_fillinstacktrace_ref(cd, cd->mcodeptr);
s1 = reg_of_var(rd, iptr->dst, REG_RESULT);
M_INTMOVE(REG_RESULT, s1);
dseg_createlinenumbertable(cd);
- {
-
- u1 *xcodeptr;
- branchref *bref;
-
- /* generate ArithmeticException stubs */
-
- xcodeptr = NULL;
-
- for (bref = cd->xdivrefs; bref != NULL; bref = bref->next) {
- gen_resolvebranch(cd->mcodebase + bref->branchpos,
- bref->branchpos,
- cd->mcodeptr - cd->mcodebase);
-
- MCODECHECK(512);
-
- M_MOV_IMM(0, REG_ITMP2_XPC); /* 10 bytes */
- dseg_adddata(cd, cd->mcodeptr);
- M_AADD_IMM32(bref->branchpos - 6, REG_ITMP2_XPC); /* 7 bytes */
-
- if (xcodeptr != NULL) {
- M_JMP_IMM(xcodeptr - cd->mcodeptr - 5);
-
- } else {
- xcodeptr = cd->mcodeptr;
-
- x86_64_lea_membase_reg(cd, RIP, -(((ptrint) cd->mcodeptr + 7) - (ptrint) cd->mcodebase), rd->argintregs[0]);
- M_MOV(REG_SP, rd->argintregs[1]);
- M_ALD(rd->argintregs[2], REG_SP, parentargs_base * 8);
- M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
-
- M_ASUB_IMM(2 * 8, REG_SP);
- M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8);
-
- M_MOV_IMM((ptrint) stacktrace_inline_arithmeticexception,
- REG_ITMP3);
- M_CALL(REG_ITMP3);
-
- M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8);
- M_AADD_IMM(2 * 8, REG_SP);
-
- M_MOV_IMM((ptrint) asm_handle_exception, REG_ITMP3);
- M_JMP(REG_ITMP3);
- }
- }
-
- /* generate ArrayIndexOutOfBoundsException stubs */
-
- xcodeptr = NULL;
-
- for (bref = cd->xboundrefs; bref != NULL; bref = bref->next) {
- gen_resolvebranch(cd->mcodebase + bref->branchpos,
- bref->branchpos,
- cd->mcodeptr - cd->mcodebase);
-
- MCODECHECK(512);
-
- /* move index register into REG_ITMP1 */
-
- M_MOV(bref->reg, REG_ITMP1); /* 3 bytes */
-
- M_MOV_IMM(0, REG_ITMP2_XPC); /* 10 bytes */
- dseg_adddata(cd, cd->mcodeptr);
- M_AADD_IMM32(bref->branchpos - 6, REG_ITMP2_XPC); /* 7 bytes */
-
- if (xcodeptr != NULL) {
- M_JMP_IMM(xcodeptr - cd->mcodeptr - 5);
-
- } else {
- xcodeptr = cd->mcodeptr;
-
- x86_64_lea_membase_reg(cd, RIP, -(((ptrint) cd->mcodeptr + 7) - (ptrint) cd->mcodebase), rd->argintregs[0]);
- M_MOV(REG_SP, rd->argintregs[1]);
- M_ALD(rd->argintregs[2], REG_SP, parentargs_base * 8);
- M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
- M_MOV(REG_ITMP1, rd->argintregs[4]);
-
- M_ASUB_IMM(2 * 8, REG_SP);
- M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8);
-
- M_MOV_IMM((ptrint) stacktrace_inline_arrayindexoutofboundsexception,
- REG_ITMP3);
- M_CALL(REG_ITMP3);
-
- M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8);
- M_AADD_IMM(2 * 8, REG_SP);
-
- M_MOV_IMM((ptrint) asm_handle_exception, REG_ITMP3);
- M_JMP(REG_ITMP3);
- }
- }
-
- /* generate ArrayStoreException stubs */
-
- xcodeptr = NULL;
-
- for (bref = cd->xstorerefs; bref != NULL; bref = bref->next) {
- gen_resolvebranch(cd->mcodebase + bref->branchpos,
- bref->branchpos,
- cd->mcodeptr - cd->mcodebase);
-
- MCODECHECK(512);
-
- M_MOV_IMM(0, REG_ITMP2_XPC); /* 10 bytes */
- dseg_adddata(cd, cd->mcodeptr);
- M_AADD_IMM32(bref->branchpos - 6, REG_ITMP2_XPC); /* 7 bytes */
-
- if (xcodeptr != NULL) {
- M_JMP_IMM(xcodeptr - cd->mcodeptr - 5);
-
- } else {
- xcodeptr = cd->mcodeptr;
-
- x86_64_lea_membase_reg(cd, RIP, -(((ptrint) cd->mcodeptr + 7) - (ptrint) cd->mcodebase), rd->argintregs[0]);
- M_MOV(REG_SP, rd->argintregs[1]);
- M_ALD(rd->argintregs[2], REG_SP, parentargs_base * 8);
- M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
-
- M_ASUB_IMM(2 * 8, REG_SP);
- M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8);
- M_MOV_IMM((ptrint) stacktrace_inline_arraystoreexception,
- REG_ITMP3);
- M_CALL(REG_ITMP3);
+ /* generate exception and patcher stubs */
- M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8);
- M_AADD_IMM(2 * 8, REG_SP);
-
- M_MOV_IMM((ptrint) asm_handle_exception, REG_ITMP3);
- M_JMP(REG_ITMP3);
- }
- }
-
- /* generate ClassCastException stubs */
-
- xcodeptr = NULL;
-
- for (bref = cd->xcastrefs; bref != NULL; bref = bref->next) {
- gen_resolvebranch(cd->mcodebase + bref->branchpos,
- bref->branchpos,
- cd->mcodeptr - cd->mcodebase);
-
- MCODECHECK(512);
-
- M_MOV_IMM(0, REG_ITMP2_XPC); /* 10 bytes */
- dseg_adddata(cd, cd->mcodeptr);
- M_AADD_IMM32(bref->branchpos - 6, REG_ITMP2_XPC); /* 7 bytes */
-
- if (xcodeptr != NULL) {
- M_JMP_IMM(xcodeptr - cd->mcodeptr - 5);
-
- } else {
- xcodeptr = cd->mcodeptr;
-
- x86_64_lea_membase_reg(cd, RIP, -(((ptrint) cd->mcodeptr + 7) - (ptrint) cd->mcodebase), rd->argintregs[0]);
- M_MOV(REG_SP, rd->argintregs[1]);
- M_ALD(rd->argintregs[2], REG_SP, parentargs_base * 8);
- M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
-
- M_ASUB_IMM(2 * 8, REG_SP);
- M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8);
-
- M_MOV_IMM((ptrint) stacktrace_inline_classcastexception, REG_ITMP3);
- M_CALL(REG_ITMP3);
-
- M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8);
- M_AADD_IMM(2 * 8, REG_SP);
-
- M_MOV_IMM((ptrint) asm_handle_exception, REG_ITMP3);
- M_JMP(REG_ITMP3);
- }
- }
+ {
+ exceptionref *eref;
+ patchref *pref;
+ ptrint mcode;
+ u1 *savedmcodeptr;
+ u1 *tmpmcodeptr;
- /* generate NullpointerException stubs */
+ savedmcodeptr = NULL;
- xcodeptr = NULL;
+ /* generate exception stubs */
- for (bref = cd->xnullrefs; bref != NULL; bref = bref->next) {
- gen_resolvebranch(cd->mcodebase + bref->branchpos,
- bref->branchpos,
- cd->mcodeptr - cd->mcodebase);
-
- MCODECHECK(512);
-
- M_MOV_IMM(0, REG_ITMP2_XPC); /* 10 bytes */
- dseg_adddata(cd, cd->mcodeptr);
- M_AADD_IMM32(bref->branchpos - 6, REG_ITMP2_XPC); /* 7 bytes */
+ for (eref = cd->exceptionrefs; eref != NULL; eref = eref->next) {
+ gen_resolvebranch(cd->mcodebase + eref->branchpos,
+ eref->branchpos,
+ cd->mcodeptr - cd->mcodebase);
- if (xcodeptr != NULL) {
- M_JMP_IMM(xcodeptr - cd->mcodeptr - 5);
-
- } else {
- xcodeptr = cd->mcodeptr;
+ MCODECHECK(512);
- x86_64_lea_membase_reg(cd, RIP, -(((ptrint) cd->mcodeptr + 7) - (ptrint) cd->mcodebase), rd->argintregs[0]);
- M_MOV(REG_SP, rd->argintregs[1]);
- M_ALD(rd->argintregs[2], REG_SP, parentargs_base * 8);
- M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
+ /* Check if the exception is an
+ ArrayIndexOutOfBoundsException. If so, move index register
+ into REG_ITMP1. */
- M_ASUB_IMM(2 * 8, REG_SP);
- M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8);
+ if (eref->reg != -1)
+ M_MOV(eref->reg, REG_ITMP1);
- M_MOV_IMM((ptrint) stacktrace_inline_nullpointerexception,
- REG_ITMP3);
- M_CALL(REG_ITMP3);
+ /* calcuate exception address */
- M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8);
- M_AADD_IMM(2 * 8, REG_SP);
+ M_MOV_IMM(0, REG_ITMP2_XPC);
+ dseg_adddata(cd, cd->mcodeptr);
+ M_AADD_IMM32(eref->branchpos - 6, REG_ITMP2_XPC);
- M_MOV_IMM((ptrint) asm_handle_exception, REG_ITMP3);
- M_JMP(REG_ITMP3);
- }
- }
+ /* move function to call into REG_ITMP3 */
- /* generate exception check stubs */
+ M_MOV_IMM(eref->function, REG_ITMP3);
- xcodeptr = NULL;
-
- for (bref = cd->xexceptionrefs; bref != NULL; bref = bref->next) {
- gen_resolvebranch(cd->mcodebase + bref->branchpos,
- bref->branchpos,
- cd->mcodeptr - cd->mcodebase);
-
- MCODECHECK(512);
-
- M_MOV_IMM(0, REG_ITMP2_XPC); /* 10 bytes */
- dseg_adddata(cd, cd->mcodeptr);
- M_AADD_IMM32(bref->branchpos - 6, REG_ITMP2_XPC); /* 7 bytes */
-
- if (xcodeptr != NULL) {
- M_JMP_IMM(xcodeptr - cd->mcodeptr - 5);
+ if (savedmcodeptr != NULL) {
+ M_JMP_IMM(savedmcodeptr - cd->mcodeptr - 5);
- } else {
- xcodeptr = cd->mcodeptr;
+ } else {
+ savedmcodeptr = cd->mcodeptr;
- x86_64_lea_membase_reg(cd, RIP, -(((ptrint) cd->mcodeptr + 7) - (ptrint) cd->mcodebase), rd->argintregs[0]);
- M_MOV(REG_SP, rd->argintregs[1]);
- M_ALD(rd->argintregs[2], REG_SP, parentargs_base * 8);
- M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
+ x86_64_lea_membase_reg(cd, RIP, -(((ptrint) cd->mcodeptr + 7) - (ptrint) cd->mcodebase), rd->argintregs[0]);
+ M_MOV(REG_SP, rd->argintregs[1]);
+ M_ALD(rd->argintregs[2], REG_SP, parentargs_base * 8);
+ M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
+ M_MOV(REG_ITMP1, rd->argintregs[4]); /* for AIOOBE */
- M_ASUB_IMM(2 * 8, REG_SP);
- M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8);
+ M_ASUB_IMM(2 * 8, REG_SP);
+ M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8);
- M_MOV_IMM((ptrint) stacktrace_inline_fillInStackTrace, REG_ITMP3);
- M_CALL(REG_ITMP3);
+ M_CALL(REG_ITMP3);
- M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8);
- M_AADD_IMM(2 * 8, REG_SP);
+ M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8);
+ M_AADD_IMM(2 * 8, REG_SP);
- M_MOV_IMM((ptrint) asm_handle_exception, REG_ITMP3);
- M_JMP(REG_ITMP3);
+ M_MOV_IMM(asm_handle_exception, REG_ITMP3);
+ M_JMP(REG_ITMP3);
+ }
}
- }
- /* generate code patching stub call code */
- {
- patchref *pref;
- codegendata *tmpcd;
- ptrint mcode;
-
- tmpcd = DNEW(codegendata);
+ /* generate code patching stub call code */
for (pref = cd->patchrefs; pref != NULL; pref = pref->next) {
/* check size of code segment */
MCODECHECK(512);
- /* Get machine code which is patched back in later. A */
- /* `call rel32' is 5 bytes long (but read 8 bytes). */
+ /* Get machine code which is patched back in later. A
+ `call rel32' is 5 bytes long (but read 8 bytes). */
- xcodeptr = cd->mcodebase + pref->branchpos;
- mcode = *((ptrint *) xcodeptr);
+ savedmcodeptr = cd->mcodebase + pref->branchpos;
+ mcode = *((ptrint *) savedmcodeptr);
- /* patch in `call rel32' to call the following code */
+ /* patch in `call rel32' to call the following code */
- tmpcd->mcodeptr = xcodeptr; /* set dummy mcode pointer */
- x86_64_call_imm(tmpcd, cd->mcodeptr - (xcodeptr + 5));
+ tmpmcodeptr = cd->mcodeptr; /* save current mcodeptr */
+ cd->mcodeptr = savedmcodeptr; /* set mcodeptr to patch position */
+
+ M_CALL_IMM(tmpmcodeptr - (savedmcodeptr + PATCHER_CALL_SIZE));
+
+ cd->mcodeptr = tmpmcodeptr; /* restore the current mcodeptr */
/* move pointer to java_objectheader onto stack */
/* move machine code bytes and classinfo pointer into registers */
- M_MOV_IMM((ptrint) mcode, REG_ITMP3);
+ M_MOV_IMM(mcode, REG_ITMP3);
M_PUSH(REG_ITMP3);
- M_MOV_IMM((ptrint) pref->ref, REG_ITMP3);
+ M_MOV_IMM(pref->ref, REG_ITMP3);
M_PUSH(REG_ITMP3);
- M_MOV_IMM((ptrint) pref->disp, REG_ITMP3);
+ M_MOV_IMM(pref->disp, REG_ITMP3);
M_PUSH(REG_ITMP3);
- M_MOV_IMM((ptrint) pref->patcher, REG_ITMP3);
+ M_MOV_IMM(pref->patcher, REG_ITMP3);
M_PUSH(REG_ITMP3);
- M_MOV_IMM((ptrint) asm_wrapper_patcher, REG_ITMP3);
+ M_MOV_IMM(asm_wrapper_patcher, REG_ITMP3);
M_JMP(REG_ITMP3);
}
}
- }
codegen_finish(m, cd, (s4) ((u1 *) cd->mcodeptr - cd->mcodebase));
if (opt_prof) {
/* count frequency */
- M_MOV_IMM((ptrint) m, REG_ITMP2);
+ M_MOV_IMM(m, REG_ITMP2);
M_IINC_MEMBASE(REG_ITMP2, OFFSET(methodinfo, frequency));
}
}
}
- M_MOV_IMM((ptrint) m, REG_ITMP1);
+ M_MOV_IMM(m, REG_ITMP1);
M_AST(REG_ITMP1, REG_SP, 0 * 8);
- M_MOV_IMM((ptrint) builtin_trace_args, REG_ITMP1);
+ M_MOV_IMM(builtin_trace_args, REG_ITMP1);
M_CALL(REG_ITMP1);
/* restore integer and float argument registers */
}
#endif
- M_MOV_IMM((ptrint) f, REG_ITMP3);
+ M_MOV_IMM(f, REG_ITMP3);
/* save integer and float argument registers */
x86_64_lea_membase_reg(cd, RIP, -(((ptrint) cd->mcodeptr + 7) - (ptrint) cd->mcodebase), rd->argintregs[1]);
M_ALEA(REG_SP, stackframesize * 8 + SIZEOF_VOID_P, rd->argintregs[2]);
M_ALD(rd->argintregs[3], REG_SP, stackframesize * 8);
- M_MOV_IMM((ptrint) codegen_start_native_call, REG_ITMP1);
+ M_MOV_IMM(codegen_start_native_call, REG_ITMP1);
M_CALL(REG_ITMP1);
/* restore integer and float argument registers */
/* put class into second argument register */
if (m->flags & ACC_STATIC)
- M_MOV_IMM((ptrint) m->class, rd->argintregs[1]);
+ M_MOV_IMM(m->class, rd->argintregs[1]);
/* put env into first argument register */
- M_MOV_IMM((ptrint) _Jv_env, rd->argintregs[0]);
+ M_MOV_IMM(_Jv_env, rd->argintregs[0]);
/* do the native function call */
/* remove native stackframe info */
M_ALEA(REG_SP, stackframesize * 8, rd->argintregs[0]);
- M_MOV_IMM((ptrint) codegen_finish_native_call, REG_ITMP1);
+ M_MOV_IMM(codegen_finish_native_call, REG_ITMP1);
M_CALL(REG_ITMP1);
/* generate call trace */
M_DLD(REG_FRESULT, REG_SP, 0 * 8);
}
- M_MOV_IMM((ptrint) m, rd->argintregs[0]);
+ M_MOV_IMM(m, rd->argintregs[0]);
M_MOV(REG_RESULT, rd->argintregs[1]);
M_FLTMOVE(REG_FRESULT, rd->argfltregs[0]);
M_FLTMOVE(REG_FRESULT, rd->argfltregs[1]);
- M_MOV_IMM((ptrint) builtin_displaymethodstop, REG_ITMP1);
+ M_MOV_IMM(builtin_displaymethodstop, REG_ITMP1);
M_CALL(REG_ITMP1);
}
/* check for exception */
#if defined(USE_THREADS) && defined(NATIVE_THREADS)
- M_MOV_IMM((ptrint) builtin_get_exceptionptrptr, REG_ITMP3);
+ M_MOV_IMM(builtin_get_exceptionptrptr, REG_ITMP3);
M_CALL(REG_ITMP3);
#else
- M_MOV_IMM((ptrint) &_no_threads_exceptionptr, REG_RESULT);
+ M_MOV_IMM(&_no_threads_exceptionptr, REG_RESULT);
#endif
M_ALD(REG_ITMP2, REG_RESULT, 0);
#if defined(USE_THREADS) && defined(NATIVE_THREADS)
M_LST(REG_ITMP2, REG_SP, 0 * 8);
- M_MOV_IMM((ptrint) builtin_get_exceptionptrptr, REG_ITMP3);
+ M_MOV_IMM(builtin_get_exceptionptrptr, REG_ITMP3);
M_CALL(REG_ITMP3);
M_AST_IMM32(0, REG_RESULT, 0); /* clear exception pointer */
M_LLD(REG_ITMP1_XPTR, REG_SP, 0 * 8);
#else
M_MOV(REG_ITMP3, REG_ITMP1_XPTR);
- M_MOV_IMM((ptrint) &_no_threads_exceptionptr, REG_ITMP3);
+ M_MOV_IMM(&_no_threads_exceptionptr, REG_ITMP3);
M_AST_IMM32(0, REG_ITMP3, 0); /* clear exception pointer */
#endif
M_LLD(REG_ITMP2_XPC, REG_SP, 0 * 8); /* get return address from stack */
M_ASUB_IMM(3, REG_ITMP2_XPC); /* callq */
- M_MOV_IMM((ptrint) asm_handle_nat_exception, REG_ITMP3);
+ M_MOV_IMM(asm_handle_nat_exception, REG_ITMP3);
M_JMP(REG_ITMP3);
/* process patcher calls **************************************************/
{
- u1 *xcodeptr;
- patchref *pref;
- codegendata *tmpcd;
- ptrint mcode;
+ patchref *pref;
+ ptrint mcode;
+ u1 *savedmcodeptr;
+ u1 *tmpmcodeptr;
#if defined(USE_THREADS) && defined(NATIVE_THREADS)
- s4 disp;
+ s4 disp;
#endif
- tmpcd = DNEW(codegendata);
-
for (pref = cd->patchrefs; pref != NULL; pref = pref->next) {
- /* Get machine code which is patched back in later. A */
- /* `call rel32' is 5 bytes long (but read 8 bytes). */
+ /* Get machine code which is patched back in later. A
+ `call rel32' is 5 bytes long (but read 8 bytes). */
- xcodeptr = cd->mcodebase + pref->branchpos;
- mcode = *((ptrint *) xcodeptr);
+ savedmcodeptr = cd->mcodebase + pref->branchpos;
+ mcode = *((ptrint *) savedmcodeptr);
/* patch in `call rel32' to call the following code */
- tmpcd->mcodeptr = xcodeptr; /* set dummy mcode pointer */
- x86_64_call_imm(tmpcd, cd->mcodeptr - (xcodeptr + 5));
+ tmpmcodeptr = cd->mcodeptr; /* save current mcodeptr */
+ cd->mcodeptr = savedmcodeptr; /* set mcodeptr to patch position */
+
+ M_CALL_IMM(tmpmcodeptr - (savedmcodeptr + PATCHER_CALL_SIZE));
+
+ cd->mcodeptr = tmpmcodeptr; /* restore the current mcodeptr */
/* move pointer to java_objectheader onto stack */
/* move machine code bytes and classinfo pointer into registers */
- M_MOV_IMM((ptrint) mcode, REG_ITMP3);
+ M_MOV_IMM(mcode, REG_ITMP3);
M_PUSH(REG_ITMP3);
- M_MOV_IMM((ptrint) pref->ref, REG_ITMP3);
+ M_MOV_IMM(pref->ref, REG_ITMP3);
M_PUSH(REG_ITMP3);
- M_MOV_IMM((ptrint) pref->disp, REG_ITMP3);
+ M_MOV_IMM(pref->disp, REG_ITMP3);
M_PUSH(REG_ITMP3);
- M_MOV_IMM((ptrint) pref->patcher, REG_ITMP3);
+ M_MOV_IMM(pref->patcher, REG_ITMP3);
M_PUSH(REG_ITMP3);
- M_MOV_IMM((ptrint) asm_wrapper_patcher, REG_ITMP3);
+ M_MOV_IMM(asm_wrapper_patcher, REG_ITMP3);
M_JMP(REG_ITMP3);
}
}