X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=src%2Fvm%2Fjit%2Falpha%2Fcodegen.c;h=419ba3728a845c604ba62cecf291a54020dbb1e0;hb=bfb7d15b502b8170ec8a9b348c546418c0e44ace;hp=d15ef45f1a0a6633798c0f1f2e3e30025d14d8a5;hpb=ac984301eb527bd1f5d6793b8b99df7f24d8eeb8;p=cacao.git diff --git a/src/vm/jit/alpha/codegen.c b/src/vm/jit/alpha/codegen.c index d15ef45f1..419ba3728 100644 --- a/src/vm/jit/alpha/codegen.c +++ b/src/vm/jit/alpha/codegen.c @@ -1,6 +1,6 @@ /* src/vm/jit/alpha/codegen.c - machine code generator for Alpha - Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel, + Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger, Institut f. Computersprachen - TU Wien @@ -22,16 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - Contact: cacao@cacaojvm.org - - Authors: Andreas Krall - Reinhard Grafl - Joseph Wenninger - Christian Thalinger - Christian Ullrich - Edwin Steiner - - $Id: codegen.c 6165 2006-12-10 22:07:02Z twisti $ + $Id: codegen.c 7918 2007-05-20 20:42:18Z michi $ */ @@ -49,20 +40,19 @@ #include "vm/jit/alpha/arch.h" #include "vm/jit/alpha/codegen.h" +#include "mm/memory.h" + #include "native/jni.h" #include "native/native.h" -#if defined(ENABLE_THREADS) -# include "threads/native/lock.h" -#endif +#include "threads/lock-common.h" #include "vm/builtin.h" #include "vm/exceptions.h" #include "vm/global.h" -#include "vm/loader.h" -#include "vm/options.h" -#include "vm/stringlocal.h" #include "vm/vm.h" + +#include "vm/jit/abi.h" #include "vm/jit/asmpart.h" #include "vm/jit/codegen-common.h" #include "vm/jit/dseg.h" @@ -72,19 +62,23 @@ #include "vm/jit/patcher.h" #include "vm/jit/reg.h" #include "vm/jit/replace.h" +#include "vm/jit/stacktrace.h" #if defined(ENABLE_LSRA) # include "vm/jit/allocator/lsra.h" #endif +#include "vmcore/loader.h" +#include "vmcore/options.h" -/* codegen ********************************************************************* + +/* codegen_emit **************************************************************** Generates machine code. *******************************************************************************/ -bool codegen(jitdata *jd) +bool codegen_emit(jitdata *jd) { methodinfo *m; codeinfo *code; @@ -218,43 +212,33 @@ bool codegen(jitdata *jd) if (IS_INT_LNG_TYPE(t)) { /* integer args */ if (!md->params[p].inmemory) { /* register arguments */ - s2 = rd->argintregs[s1]; - if (!IS_INMEMORY(var->flags)) { /* reg arg -> register */ - M_INTMOVE(s2, var->vv.regoff); - - } else { /* reg arg -> spilled */ - M_LST(s2, REG_SP, var->vv.regoff * 8); - } - - } else { /* stack arguments */ - if (!IS_INMEMORY(var->flags)) { /* stack arg -> register */ + if (!IS_INMEMORY(var->flags)) + M_INTMOVE(s1, var->vv.regoff); + else + M_LST(s1, REG_SP, var->vv.regoff * 8); + } + else { /* stack arguments */ + if (!IS_INMEMORY(var->flags)) M_LLD(var->vv.regoff, REG_SP, (cd->stackframesize + s1) *8); - - } else { /* stack arg -> spilled */ + else var->vv.regoff = cd->stackframesize + s1; - } } - - } else { /* floating args */ + } + else { /* floating args */ if (!md->params[p].inmemory) { /* register arguments */ - s2 = rd->argfltregs[s1]; - if (!IS_INMEMORY(var->flags)) { /* reg arg -> register */ - M_FLTMOVE(s2, var->vv.regoff); - - } else { /* reg arg -> spilled */ - M_DST(s2, REG_SP, var->vv.regoff * 8); - } - - } else { /* stack arguments */ - if (!(var->flags & INMEMORY)) { /* stack-arg -> register */ + if (!IS_INMEMORY(var->flags)) + M_FLTMOVE(s1, var->vv.regoff); + else + M_DST(s1, REG_SP, var->vv.regoff * 8); + } + else { /* stack arguments */ + if (!(var->flags & INMEMORY)) M_DLD(var->vv.regoff, REG_SP, (cd->stackframesize + s1) * 8); - - } else { /* stack-arg -> spilled */ + else var->vv.regoff = cd->stackframesize + s1; - } } } - } /* end for */ + } /* call monitorenter function */ @@ -269,10 +253,10 @@ bool codegen(jitdata *jd) M_LDA(REG_SP, REG_SP, -(INT_ARG_CNT + FLT_ARG_CNT) * 8); for (p = 0; p < INT_ARG_CNT; p++) - M_LST(rd->argintregs[p], REG_SP, p * 8); + M_LST(abi_registers_integer_argument[p], REG_SP, p * 8); for (p = 0; p < FLT_ARG_CNT; p++) - M_DST(rd->argfltregs[p], REG_SP, (INT_ARG_CNT + p) * 8); + M_DST(abi_registers_float_argument[p], REG_SP, (INT_ARG_CNT + p) * 8); s1 += INT_ARG_CNT + FLT_ARG_CNT; } @@ -285,8 +269,8 @@ bool codegen(jitdata *jd) M_ALD(REG_A0, REG_PV, disp); } else { - M_BEQZ(REG_A0, 0); - codegen_add_nullpointerexception_ref(cd); + M_BNEZ(REG_A0, 1); + M_ALD_INTERN(REG_ZERO, REG_ZERO, EXCEPTION_HARDWARE_NULLPOINTER); } M_AST(REG_A0, REG_SP, s1 * 8); @@ -299,10 +283,10 @@ bool codegen(jitdata *jd) #if !defined(NDEBUG) if (opt_verbosecall) { for (p = 0; p < INT_ARG_CNT; p++) - M_LLD(rd->argintregs[p], REG_SP, p * 8); + M_LLD(abi_registers_integer_argument[p], REG_SP, p * 8); for (p = 0; p < FLT_ARG_CNT; p++) - M_DLD(rd->argfltregs[p], REG_SP, (INT_ARG_CNT + p) * 8); + M_DLD(abi_registers_float_argument[p], REG_SP, (INT_ARG_CNT + p) * 8); M_LDA(REG_SP, REG_SP, (INT_ARG_CNT + FLT_ARG_CNT) * 8); } @@ -497,13 +481,13 @@ bool codegen(jitdata *jd) case ICMD_COPY: case ICMD_MOVE: - emit_copy(jd, iptr, VAROP(iptr->s1), VAROP(iptr->dst)); + emit_copy(jd, iptr); break; case ICMD_ASTORE: if (!(iptr->flags.bits & INS_FLAG_RETADDR)) - emit_copy(jd, iptr, VAROP(iptr->s1), VAROP(iptr->dst)); + emit_copy(jd, iptr); break; @@ -721,14 +705,13 @@ bool codegen(jitdata *jd) case ICMD_IDIV: /* ..., val1, val2 ==> ..., val1 / val2 */ case ICMD_IREM: /* ..., val1, val2 ==> ..., val1 % val2 */ - s1 = emit_load_s1(jd, iptr, REG_ITMP1); - s2 = emit_load_s2(jd, iptr, REG_ITMP2); + s1 = emit_load_s1(jd, iptr, REG_A0); + s2 = emit_load_s2(jd, iptr, REG_A1); d = codegen_reg_of_dst(jd, iptr, REG_RESULT); - M_BEQZ(s2, 0); - codegen_add_arithmeticexception_ref(cd); + emit_arithmetic_check(cd, iptr, s2); - M_MOV(s1, REG_A0); - M_MOV(s2, REG_A1); + M_INTMOVE(s1, REG_A0); + M_INTMOVE(s2, REG_A1); bte = iptr->sx.s23.s3.bte; disp = dseg_add_functionptr(cd, bte->fp); M_ALD(REG_PV, REG_PV, disp); @@ -743,16 +726,14 @@ bool codegen(jitdata *jd) case ICMD_LDIV: /* ..., val1, val2 ==> ..., val1 / val2 */ case ICMD_LREM: /* ..., val1, val2 ==> ..., val1 % val2 */ - bte = iptr->sx.s23.s3.bte; - s1 = emit_load_s1(jd, iptr, REG_A0); s2 = emit_load_s2(jd, iptr, REG_A1); d = codegen_reg_of_dst(jd, iptr, REG_RESULT); - M_BEQZ(s2, 0); - codegen_add_arithmeticexception_ref(cd); + emit_arithmetic_check(cd, iptr, s2); M_INTMOVE(s1, REG_A0); M_INTMOVE(s2, REG_A1); + bte = iptr->sx.s23.s3.bte; disp = dseg_add_functionptr(cd, bte->fp); M_ALD(REG_PV, REG_PV, disp); M_JSR(REG_RA, REG_PV); @@ -1436,7 +1417,7 @@ bool codegen(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_ITMP1); d = codegen_reg_of_dst(jd, iptr, REG_ITMP2); - emit_nullpointer_check(cd, iptr, s1); + /* implicit null-pointer check */ M_ILD(d, s1, OFFSET(java_arrayheader, size)); emit_store_dst(jd, iptr, d); break; @@ -1446,7 +1427,8 @@ bool codegen(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_ITMP1); s2 = emit_load_s2(jd, iptr, REG_ITMP2); d = codegen_reg_of_dst(jd, iptr, REG_ITMP2); - emit_array_checks(cd, iptr, s1, s2); + /* implicit null-pointer check */ + emit_arrayindexoutofbounds_check(cd, iptr, s1, s2); if (has_ext_instr_set) { M_LADD(s2, s1, REG_ITMP1); M_BLDU(d, REG_ITMP1, OFFSET (java_bytearray, data[0])); @@ -1467,7 +1449,8 @@ bool codegen(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_ITMP1); s2 = emit_load_s2(jd, iptr, REG_ITMP2); d = codegen_reg_of_dst(jd, iptr, REG_ITMP2); - emit_array_checks(cd, iptr, s1, s2); + /* implicit null-pointer check */ + emit_arrayindexoutofbounds_check(cd, iptr, s1, s2); if (has_ext_instr_set) { M_LADD(s2, s1, REG_ITMP1); M_LADD(s2, REG_ITMP1, REG_ITMP1); @@ -1488,7 +1471,8 @@ bool codegen(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_ITMP1); s2 = emit_load_s2(jd, iptr, REG_ITMP2); d = codegen_reg_of_dst(jd, iptr, REG_ITMP2); - emit_array_checks(cd, iptr, s1, s2); + /* implicit null-pointer check */ + emit_arrayindexoutofbounds_check(cd, iptr, s1, s2); if (has_ext_instr_set) { M_LADD(s2, s1, REG_ITMP1); M_LADD(s2, REG_ITMP1, REG_ITMP1); @@ -1510,7 +1494,8 @@ bool codegen(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_ITMP1); s2 = emit_load_s2(jd, iptr, REG_ITMP2); d = codegen_reg_of_dst(jd, iptr, REG_ITMP2); - emit_array_checks(cd, iptr, s1, s2); + /* implicit null-pointer check */ + emit_arrayindexoutofbounds_check(cd, iptr, s1, s2); M_S4ADDQ(s2, s1, REG_ITMP1); M_ILD(d, REG_ITMP1, OFFSET(java_intarray, data[0])); emit_store_dst(jd, iptr, d); @@ -1521,7 +1506,8 @@ bool codegen(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_ITMP1); s2 = emit_load_s2(jd, iptr, REG_ITMP2); d = codegen_reg_of_dst(jd, iptr, REG_ITMP2); - emit_array_checks(cd, iptr, s1, s2); + /* implicit null-pointer check */ + emit_arrayindexoutofbounds_check(cd, iptr, s1, s2); M_S8ADDQ(s2, s1, REG_ITMP1); M_LLD(d, REG_ITMP1, OFFSET(java_longarray, data[0])); emit_store_dst(jd, iptr, d); @@ -1532,7 +1518,8 @@ bool codegen(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_ITMP1); s2 = emit_load_s2(jd, iptr, REG_ITMP2); d = codegen_reg_of_dst(jd, iptr, REG_FTMP2); - emit_array_checks(cd, iptr, s1, s2); + /* implicit null-pointer check */ + emit_arrayindexoutofbounds_check(cd, iptr, s1, s2); M_S4ADDQ(s2, s1, REG_ITMP1); M_FLD(d, REG_ITMP1, OFFSET(java_floatarray, data[0])); emit_store_dst(jd, iptr, d); @@ -1543,7 +1530,8 @@ bool codegen(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_ITMP1); s2 = emit_load_s2(jd, iptr, REG_ITMP2); d = codegen_reg_of_dst(jd, iptr, REG_FTMP2); - emit_array_checks(cd, iptr, s1, s2); + /* implicit null-pointer check */ + emit_arrayindexoutofbounds_check(cd, iptr, s1, s2); M_S8ADDQ(s2, s1, REG_ITMP1); M_DLD(d, REG_ITMP1, OFFSET(java_doublearray, data[0])); emit_store_dst(jd, iptr, d); @@ -1554,7 +1542,8 @@ bool codegen(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_ITMP1); s2 = emit_load_s2(jd, iptr, REG_ITMP2); d = codegen_reg_of_dst(jd, iptr, REG_ITMP2); - emit_array_checks(cd, iptr, s1, s2); + /* implicit null-pointer check */ + emit_arrayindexoutofbounds_check(cd, iptr, s1, s2); M_SAADDQ(s2, s1, REG_ITMP1); M_ALD(d, REG_ITMP1, OFFSET(java_objectarray, data[0])); emit_store_dst(jd, iptr, d); @@ -1565,7 +1554,8 @@ bool codegen(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_ITMP1); s2 = emit_load_s2(jd, iptr, REG_ITMP2); - emit_array_checks(cd, iptr, s1, s2); + /* implicit null-pointer check */ + emit_arrayindexoutofbounds_check(cd, iptr, s1, s2); s3 = emit_load_s3(jd, iptr, REG_ITMP3); if (has_ext_instr_set) { M_LADD(s2, s1, REG_ITMP1); @@ -1586,7 +1576,8 @@ bool codegen(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_ITMP1); s2 = emit_load_s2(jd, iptr, REG_ITMP2); - emit_array_checks(cd, iptr, s1, s2); + /* implicit null-pointer check */ + emit_arrayindexoutofbounds_check(cd, iptr, s1, s2); s3 = emit_load_s3(jd, iptr, REG_ITMP3); if (has_ext_instr_set) { M_LADD(s2, s1, REG_ITMP1); @@ -1609,7 +1600,8 @@ bool codegen(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_ITMP1); s2 = emit_load_s2(jd, iptr, REG_ITMP2); - emit_array_checks(cd, iptr, s1, s2); + /* implicit null-pointer check */ + emit_arrayindexoutofbounds_check(cd, iptr, s1, s2); s3 = emit_load_s3(jd, iptr, REG_ITMP3); if (has_ext_instr_set) { M_LADD(s2, s1, REG_ITMP1); @@ -1632,7 +1624,8 @@ bool codegen(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_ITMP1); s2 = emit_load_s2(jd, iptr, REG_ITMP2); - emit_array_checks(cd, iptr, s1, s2); + /* implicit null-pointer check */ + emit_arrayindexoutofbounds_check(cd, iptr, s1, s2); s3 = emit_load_s3(jd, iptr, REG_ITMP3); M_S4ADDQ(s2, s1, REG_ITMP1); M_IST(s3, REG_ITMP1, OFFSET(java_intarray, data[0])); @@ -1642,7 +1635,8 @@ bool codegen(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_ITMP1); s2 = emit_load_s2(jd, iptr, REG_ITMP2); - emit_array_checks(cd, iptr, s1, s2); + /* implicit null-pointer check */ + emit_arrayindexoutofbounds_check(cd, iptr, s1, s2); s3 = emit_load_s3(jd, iptr, REG_ITMP3); M_S8ADDQ(s2, s1, REG_ITMP1); M_LST(s3, REG_ITMP1, OFFSET(java_longarray, data[0])); @@ -1652,7 +1646,8 @@ bool codegen(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_ITMP1); s2 = emit_load_s2(jd, iptr, REG_ITMP2); - emit_array_checks(cd, iptr, s1, s2); + /* implicit null-pointer check */ + emit_arrayindexoutofbounds_check(cd, iptr, s1, s2); s3 = emit_load_s3(jd, iptr, REG_FTMP3); M_S4ADDQ(s2, s1, REG_ITMP1); M_FST(s3, REG_ITMP1, OFFSET(java_floatarray, data[0])); @@ -1662,7 +1657,8 @@ bool codegen(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_ITMP1); s2 = emit_load_s2(jd, iptr, REG_ITMP2); - emit_array_checks(cd, iptr, s1, s2); + /* implicit null-pointer check */ + emit_arrayindexoutofbounds_check(cd, iptr, s1, s2); s3 = emit_load_s3(jd, iptr, REG_FTMP3); M_S8ADDQ(s2, s1, REG_ITMP1); M_DST(s3, REG_ITMP1, OFFSET(java_doublearray, data[0])); @@ -1672,7 +1668,8 @@ bool codegen(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_A0); s2 = emit_load_s2(jd, iptr, REG_ITMP2); - emit_array_checks(cd, iptr, s1, s2); + /* implicit null-pointer check */ + emit_arrayindexoutofbounds_check(cd, iptr, s1, s2); s3 = emit_load_s3(jd, iptr, REG_A1); M_INTMOVE(s1, REG_A0); @@ -1683,9 +1680,7 @@ bool codegen(jitdata *jd) M_JSR(REG_RA, REG_PV); disp = (s4) (cd->mcodeptr - cd->mcodebase); M_LDA(REG_PV, REG_RA, -disp); - - M_BEQZ(REG_RESULT, 0); - codegen_add_arraystoreexception_ref(cd); + emit_exception_check(cd, iptr); s1 = emit_load_s1(jd, iptr, REG_ITMP1); s2 = emit_load_s2(jd, iptr, REG_ITMP2); @@ -1699,7 +1694,8 @@ bool codegen(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_ITMP1); s2 = emit_load_s2(jd, iptr, REG_ITMP2); - emit_array_checks(cd, iptr, s1, s2); + /* implicit null-pointer check */ + emit_arrayindexoutofbounds_check(cd, iptr, s1, s2); if (has_ext_instr_set) { M_LADD(s2, s1, REG_ITMP1); M_BST(REG_ZERO, REG_ITMP1, OFFSET(java_bytearray, data[0])); @@ -1719,7 +1715,8 @@ bool codegen(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_ITMP1); s2 = emit_load_s2(jd, iptr, REG_ITMP2); - emit_array_checks(cd, iptr, s1, s2); + /* implicit null-pointer check */ + emit_arrayindexoutofbounds_check(cd, iptr, s1, s2); if (has_ext_instr_set) { M_LADD(s2, s1, REG_ITMP1); M_LADD(s2, REG_ITMP1, REG_ITMP1); @@ -1741,7 +1738,8 @@ bool codegen(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_ITMP1); s2 = emit_load_s2(jd, iptr, REG_ITMP2); - emit_array_checks(cd, iptr, s1, s2); + /* implicit null-pointer check */ + emit_arrayindexoutofbounds_check(cd, iptr, s1, s2); if (has_ext_instr_set) { M_LADD(s2, s1, REG_ITMP1); M_LADD(s2, REG_ITMP1, REG_ITMP1); @@ -1763,7 +1761,8 @@ bool codegen(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_ITMP1); s2 = emit_load_s2(jd, iptr, REG_ITMP2); - emit_array_checks(cd, iptr, s1, s2); + /* implicit null-pointer check */ + emit_arrayindexoutofbounds_check(cd, iptr, s1, s2); M_S4ADDQ(s2, s1, REG_ITMP1); M_IST(REG_ZERO, REG_ITMP1, OFFSET(java_intarray, data[0])); break; @@ -1772,7 +1771,8 @@ bool codegen(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_ITMP1); s2 = emit_load_s2(jd, iptr, REG_ITMP2); - emit_array_checks(cd, iptr, s1, s2); + /* implicit null-pointer check */ + emit_arrayindexoutofbounds_check(cd, iptr, s1, s2); M_S8ADDQ(s2, s1, REG_ITMP1); M_LST(REG_ZERO, REG_ITMP1, OFFSET(java_longarray, data[0])); break; @@ -1781,7 +1781,8 @@ bool codegen(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_ITMP1); s2 = emit_load_s2(jd, iptr, REG_ITMP2); - emit_array_checks(cd, iptr, s1, s2); + /* implicit null-pointer check */ + emit_arrayindexoutofbounds_check(cd, iptr, s1, s2); M_SAADDQ(s2, s1, REG_ITMP1); M_AST(REG_ZERO, REG_ITMP1, OFFSET(java_objectarray, data[0])); break; @@ -1921,7 +1922,6 @@ bool codegen(jitdata *jd) case ICMD_GETFIELD: /* ... ==> ..., value */ s1 = emit_load_s1(jd, iptr, REG_ITMP1); - emit_nullpointer_check(cd, iptr, s1); if (INSTRUCTION_IS_UNRESOLVED(iptr)) { uf = iptr->sx.s23.s3.uf; @@ -1936,6 +1936,7 @@ bool codegen(jitdata *jd) disp = fi->offset; } + /* implicit null-pointer check */ switch (fieldtype) { case TYPE_INT: d = codegen_reg_of_dst(jd, iptr, REG_ITMP2); @@ -1964,7 +1965,6 @@ bool codegen(jitdata *jd) case ICMD_PUTFIELD: /* ..., objectref, value ==> ... */ s1 = emit_load_s1(jd, iptr, REG_ITMP1); - emit_nullpointer_check(cd, iptr, s1); if (INSTRUCTION_IS_UNRESOLVED(iptr)) { uf = iptr->sx.s23.s3.uf; @@ -1986,6 +1986,7 @@ bool codegen(jitdata *jd) if (INSTRUCTION_IS_UNRESOLVED(iptr)) codegen_add_patch_ref(cd, PATCHER_get_putfield, uf, 0); + /* implicit null-pointer check */ switch (fieldtype) { case TYPE_INT: M_IST(s2, s1, disp); @@ -2010,7 +2011,6 @@ bool codegen(jitdata *jd) /* following NOP) */ s1 = emit_load_s1(jd, iptr, REG_ITMP1); - emit_nullpointer_check(cd, iptr, s1); if (INSTRUCTION_IS_UNRESOLVED(iptr)) { uf = iptr->sx.s23.s3.uf; @@ -2025,6 +2025,7 @@ bool codegen(jitdata *jd) disp = fi->offset; } + /* implicit null-pointer check */ switch (fieldtype) { case TYPE_INT: M_IST(REG_ZERO, s1, disp); @@ -2071,258 +2072,213 @@ bool codegen(jitdata *jd) case ICMD_GOTO: /* ... ==> ... */ case ICMD_RET: /* ... ==> ... */ - M_BR(0); - codegen_add_branch_ref(cd, iptr->dst.block); + emit_br(cd, iptr->dst.block); ALIGNCODENOP; break; case ICMD_JSR: /* ... ==> ... */ - M_BR(0); - codegen_add_branch_ref(cd, iptr->sx.s23.s3.jsrtarget.block); + emit_br(cd, iptr->sx.s23.s3.jsrtarget.block); ALIGNCODENOP; break; case ICMD_IFNULL: /* ..., value ==> ... */ + case ICMD_IFNONNULL: s1 = emit_load_s1(jd, iptr, REG_ITMP1); - M_BEQZ(s1, 0); - codegen_add_branch_ref(cd, iptr->dst.block); - break; - - case ICMD_IFNONNULL: /* ..., value ==> ... */ - - s1 = emit_load_s1(jd, iptr, REG_ITMP1); - M_BNEZ(s1, 0); - codegen_add_branch_ref(cd, iptr->dst.block); + emit_bccz(cd, iptr->dst.block, iptr->opc - ICMD_IFNULL, s1, BRANCH_OPT_NONE); break; case ICMD_IFEQ: /* ..., value ==> ... */ s1 = emit_load_s1(jd, iptr, REG_ITMP1); - if (iptr->sx.val.i == 0) { - M_BEQZ(s1, 0); - } + if (iptr->sx.val.i == 0) + emit_beqz(cd, iptr->dst.block, s1); else { - if ((iptr->sx.val.i > 0) && (iptr->sx.val.i <= 255)) { + if ((iptr->sx.val.i > 0) && (iptr->sx.val.i <= 255)) M_CMPEQ_IMM(s1, iptr->sx.val.i, REG_ITMP1); - } else { ICONST(REG_ITMP2, iptr->sx.val.i); M_CMPEQ(s1, REG_ITMP2, REG_ITMP1); - } - M_BNEZ(REG_ITMP1, 0); } - codegen_add_branch_ref(cd, iptr->dst.block); + emit_bnez(cd, iptr->dst.block, REG_ITMP1); + } break; case ICMD_IFLT: /* ..., value ==> ... */ s1 = emit_load_s1(jd, iptr, REG_ITMP1); - if (iptr->sx.val.i == 0) { - M_BLTZ(s1, 0); - } + if (iptr->sx.val.i == 0) + emit_bltz(cd, iptr->dst.block, s1); else { - if ((iptr->sx.val.i > 0) && (iptr->sx.val.i <= 255)) { + if ((iptr->sx.val.i > 0) && (iptr->sx.val.i <= 255)) M_CMPLT_IMM(s1, iptr->sx.val.i, REG_ITMP1); - } else { ICONST(REG_ITMP2, iptr->sx.val.i); M_CMPLT(s1, REG_ITMP2, REG_ITMP1); - } - M_BNEZ(REG_ITMP1, 0); } - codegen_add_branch_ref(cd, iptr->dst.block); + emit_bnez(cd, iptr->dst.block, REG_ITMP1); + } break; case ICMD_IFLE: /* ..., value ==> ... */ s1 = emit_load_s1(jd, iptr, REG_ITMP1); - if (iptr->sx.val.i == 0) { - M_BLEZ(s1, 0); - } + if (iptr->sx.val.i == 0) + emit_blez(cd, iptr->dst.block, s1); else { - if ((iptr->sx.val.i > 0) && (iptr->sx.val.i <= 255)) { + if ((iptr->sx.val.i > 0) && (iptr->sx.val.i <= 255)) M_CMPLE_IMM(s1, iptr->sx.val.i, REG_ITMP1); - } else { ICONST(REG_ITMP2, iptr->sx.val.i); M_CMPLE(s1, REG_ITMP2, REG_ITMP1); - } - M_BNEZ(REG_ITMP1, 0); } - codegen_add_branch_ref(cd, iptr->dst.block); + emit_bnez(cd, iptr->dst.block, REG_ITMP1); + } break; case ICMD_IFNE: /* ..., value ==> ... */ s1 = emit_load_s1(jd, iptr, REG_ITMP1); - if (iptr->sx.val.i == 0) { - M_BNEZ(s1, 0); - } + if (iptr->sx.val.i == 0) + emit_bnez(cd, iptr->dst.block, s1); else { - if ((iptr->sx.val.i > 0) && (iptr->sx.val.i <= 255)) { + if ((iptr->sx.val.i > 0) && (iptr->sx.val.i <= 255)) M_CMPEQ_IMM(s1, iptr->sx.val.i, REG_ITMP1); - } else { ICONST(REG_ITMP2, iptr->sx.val.i); M_CMPEQ(s1, REG_ITMP2, REG_ITMP1); - } - M_BEQZ(REG_ITMP1, 0); } - codegen_add_branch_ref(cd, iptr->dst.block); + emit_beqz(cd, iptr->dst.block, REG_ITMP1); + } break; case ICMD_IFGT: /* ..., value ==> ... */ s1 = emit_load_s1(jd, iptr, REG_ITMP1); - if (iptr->sx.val.i == 0) { - M_BGTZ(s1, 0); - } + if (iptr->sx.val.i == 0) + emit_bgtz(cd, iptr->dst.block, s1); else { - if ((iptr->sx.val.i > 0) && (iptr->sx.val.i <= 255)) { + if ((iptr->sx.val.i > 0) && (iptr->sx.val.i <= 255)) M_CMPLE_IMM(s1, iptr->sx.val.i, REG_ITMP1); - } else { ICONST(REG_ITMP2, iptr->sx.val.i); M_CMPLE(s1, REG_ITMP2, REG_ITMP1); - } - M_BEQZ(REG_ITMP1, 0); } - codegen_add_branch_ref(cd, iptr->dst.block); + emit_beqz(cd, iptr->dst.block, REG_ITMP1); + } break; case ICMD_IFGE: /* ..., value ==> ... */ s1 = emit_load_s1(jd, iptr, REG_ITMP1); - if (iptr->sx.val.i == 0) { - M_BGEZ(s1, 0); - } + if (iptr->sx.val.i == 0) + emit_bgez(cd, iptr->dst.block, s1); else { - if ((iptr->sx.val.i > 0) && (iptr->sx.val.i <= 255)) { + if ((iptr->sx.val.i > 0) && (iptr->sx.val.i <= 255)) M_CMPLT_IMM(s1, iptr->sx.val.i, REG_ITMP1); - } else { ICONST(REG_ITMP2, iptr->sx.val.i); M_CMPLT(s1, REG_ITMP2, REG_ITMP1); - } - M_BEQZ(REG_ITMP1, 0); } - codegen_add_branch_ref(cd, iptr->dst.block); + emit_beqz(cd, iptr->dst.block, REG_ITMP1); + } break; case ICMD_IF_LEQ: /* ..., value ==> ... */ s1 = emit_load_s1(jd, iptr, REG_ITMP1); - if (iptr->sx.val.l == 0) { - M_BEQZ(s1, 0); - } + if (iptr->sx.val.l == 0) + emit_beqz(cd, iptr->dst.block, s1); else { - if ((iptr->sx.val.l > 0) && (iptr->sx.val.l <= 255)) { + if ((iptr->sx.val.l > 0) && (iptr->sx.val.l <= 255)) M_CMPEQ_IMM(s1, iptr->sx.val.l, REG_ITMP1); - } else { LCONST(REG_ITMP2, iptr->sx.val.l); M_CMPEQ(s1, REG_ITMP2, REG_ITMP1); - } - M_BNEZ(REG_ITMP1, 0); } - codegen_add_branch_ref(cd, iptr->dst.block); + emit_bnez(cd, iptr->dst.block, REG_ITMP1); + } break; case ICMD_IF_LLT: /* ..., value ==> ... */ s1 = emit_load_s1(jd, iptr, REG_ITMP1); - if (iptr->sx.val.l == 0) { - M_BLTZ(s1, 0); - } + if (iptr->sx.val.l == 0) + emit_bltz(cd, iptr->dst.block, s1); else { - if ((iptr->sx.val.l > 0) && (iptr->sx.val.l <= 255)) { + if ((iptr->sx.val.l > 0) && (iptr->sx.val.l <= 255)) M_CMPLT_IMM(s1, iptr->sx.val.l, REG_ITMP1); - } else { LCONST(REG_ITMP2, iptr->sx.val.l); M_CMPLT(s1, REG_ITMP2, REG_ITMP1); - } - M_BNEZ(REG_ITMP1, 0); } - codegen_add_branch_ref(cd, iptr->dst.block); + emit_bnez(cd, iptr->dst.block, REG_ITMP1); + } break; case ICMD_IF_LLE: /* ..., value ==> ... */ s1 = emit_load_s1(jd, iptr, REG_ITMP1); - if (iptr->sx.val.l == 0) { - M_BLEZ(s1, 0); - } + if (iptr->sx.val.l == 0) + emit_blez(cd, iptr->dst.block, s1); else { - if ((iptr->sx.val.l > 0) && (iptr->sx.val.l <= 255)) { + if ((iptr->sx.val.l > 0) && (iptr->sx.val.l <= 255)) M_CMPLE_IMM(s1, iptr->sx.val.l, REG_ITMP1); - } else { LCONST(REG_ITMP2, iptr->sx.val.l); M_CMPLE(s1, REG_ITMP2, REG_ITMP1); - } - M_BNEZ(REG_ITMP1, 0); } - codegen_add_branch_ref(cd, iptr->dst.block); + emit_bnez(cd, iptr->dst.block, REG_ITMP1); + } break; case ICMD_IF_LNE: /* ..., value ==> ... */ s1 = emit_load_s1(jd, iptr, REG_ITMP1); - if (iptr->sx.val.l == 0) { - M_BNEZ(s1, 0); - } + if (iptr->sx.val.l == 0) + emit_bnez(cd, iptr->dst.block, s1); else { - if ((iptr->sx.val.l > 0) && (iptr->sx.val.l <= 255)) { + if ((iptr->sx.val.l > 0) && (iptr->sx.val.l <= 255)) M_CMPEQ_IMM(s1, iptr->sx.val.l, REG_ITMP1); - } else { LCONST(REG_ITMP2, iptr->sx.val.l); M_CMPEQ(s1, REG_ITMP2, REG_ITMP1); - } - M_BEQZ(REG_ITMP1, 0); } - codegen_add_branch_ref(cd, iptr->dst.block); + emit_beqz(cd, iptr->dst.block, REG_ITMP1); + } break; case ICMD_IF_LGT: /* ..., value ==> ... */ s1 = emit_load_s1(jd, iptr, REG_ITMP1); - if (iptr->sx.val.l == 0) { - M_BGTZ(s1, 0); - } + if (iptr->sx.val.l == 0) + emit_bgtz(cd, iptr->dst.block, s1); else { - if ((iptr->sx.val.l > 0) && (iptr->sx.val.l <= 255)) { + if ((iptr->sx.val.l > 0) && (iptr->sx.val.l <= 255)) M_CMPLE_IMM(s1, iptr->sx.val.l, REG_ITMP1); - } else { LCONST(REG_ITMP2, iptr->sx.val.l); M_CMPLE(s1, REG_ITMP2, REG_ITMP1); - } - M_BEQZ(REG_ITMP1, 0); } - codegen_add_branch_ref(cd, iptr->dst.block); + emit_beqz(cd, iptr->dst.block, REG_ITMP1); + } break; case ICMD_IF_LGE: /* ..., value ==> ... */ s1 = emit_load_s1(jd, iptr, REG_ITMP1); - if (iptr->sx.val.l == 0) { - M_BGEZ(s1, 0); - } + if (iptr->sx.val.l == 0) + emit_bgez(cd, iptr->dst.block, s1); else { - if ((iptr->sx.val.l > 0) && (iptr->sx.val.l <= 255)) { + if ((iptr->sx.val.l > 0) && (iptr->sx.val.l <= 255)) M_CMPLT_IMM(s1, iptr->sx.val.l, REG_ITMP1); - } else { LCONST(REG_ITMP2, iptr->sx.val.l); M_CMPLT(s1, REG_ITMP2, REG_ITMP1); - } - M_BEQZ(REG_ITMP1, 0); } - codegen_add_branch_ref(cd, iptr->dst.block); + emit_beqz(cd, iptr->dst.block, REG_ITMP1); + } break; case ICMD_IF_ICMPEQ: /* ..., value, value ==> ... */ @@ -2332,8 +2288,7 @@ bool codegen(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_ITMP1); s2 = emit_load_s2(jd, iptr, REG_ITMP2); M_CMPEQ(s1, s2, REG_ITMP1); - M_BNEZ(REG_ITMP1, 0); - codegen_add_branch_ref(cd, iptr->dst.block); + emit_bnez(cd, iptr->dst.block, REG_ITMP1); break; case ICMD_IF_ICMPNE: /* ..., value, value ==> ... */ @@ -2343,8 +2298,7 @@ bool codegen(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_ITMP1); s2 = emit_load_s2(jd, iptr, REG_ITMP2); M_CMPEQ(s1, s2, REG_ITMP1); - M_BEQZ(REG_ITMP1, 0); - codegen_add_branch_ref(cd, iptr->dst.block); + emit_beqz(cd, iptr->dst.block, REG_ITMP1); break; case ICMD_IF_ICMPLT: /* ..., value, value ==> ... */ @@ -2353,8 +2307,7 @@ bool codegen(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_ITMP1); s2 = emit_load_s2(jd, iptr, REG_ITMP2); M_CMPLT(s1, s2, REG_ITMP1); - M_BNEZ(REG_ITMP1, 0); - codegen_add_branch_ref(cd, iptr->dst.block); + emit_bnez(cd, iptr->dst.block, REG_ITMP1); break; case ICMD_IF_ICMPGT: /* ..., value, value ==> ... */ @@ -2363,8 +2316,7 @@ bool codegen(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_ITMP1); s2 = emit_load_s2(jd, iptr, REG_ITMP2); M_CMPLE(s1, s2, REG_ITMP1); - M_BEQZ(REG_ITMP1, 0); - codegen_add_branch_ref(cd, iptr->dst.block); + emit_beqz(cd, iptr->dst.block, REG_ITMP1); break; case ICMD_IF_ICMPLE: /* ..., value, value ==> ... */ @@ -2373,8 +2325,7 @@ bool codegen(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_ITMP1); s2 = emit_load_s2(jd, iptr, REG_ITMP2); M_CMPLE(s1, s2, REG_ITMP1); - M_BNEZ(REG_ITMP1, 0); - codegen_add_branch_ref(cd, iptr->dst.block); + emit_bnez(cd, iptr->dst.block, REG_ITMP1); break; case ICMD_IF_ICMPGE: /* ..., value, value ==> ... */ @@ -2383,8 +2334,7 @@ bool codegen(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_ITMP1); s2 = emit_load_s2(jd, iptr, REG_ITMP2); M_CMPLT(s1, s2, REG_ITMP1); - M_BEQZ(REG_ITMP1, 0); - codegen_add_branch_ref(cd, iptr->dst.block); + emit_beqz(cd, iptr->dst.block, REG_ITMP1); break; @@ -2529,8 +2479,7 @@ nowperformreturn: M_LDA(REG_ITMP2, REG_ZERO, i - 1); M_CMPULE(REG_ITMP1, REG_ITMP2, REG_ITMP2); } - M_BEQZ(REG_ITMP2, 0); - codegen_add_branch_ref(cd, table[0].block); + emit_beqz(cd, table[0].block, REG_ITMP2); /* build jump table top down and use address of lowest entry */ @@ -2576,15 +2525,11 @@ nowperformreturn: } M_CMPEQ(s1, REG_ITMP2, REG_ITMP2); } - M_BNEZ(REG_ITMP2, 0); - codegen_add_branch_ref(cd, lookup->target.block); + emit_bnez(cd, lookup->target.block, REG_ITMP2); lookup++; } - M_BR(0); - - codegen_add_branch_ref(cd, iptr->sx.s23.s3.lookupdefault.block); - + emit_br(cd, iptr->sx.s23.s3.lookupdefault.block); ALIGNCODENOP; break; } @@ -2624,31 +2569,31 @@ gen_method: for (s3 = s3 - 1; s3 >= 0; s3--) { var = VAR(iptr->sx.s23.s2.args[s3]); + d = md->params[s3].regoff; + + /* already preallocated (ARGVAR)? */ - /* Already Preallocated (ARGVAR) ? */ if (var->flags & PREALLOC) continue; if (IS_INT_LNG_TYPE(var->type)) { if (!md->params[s3].inmemory) { - s1 = rd->argintregs[md->params[s3].regoff]; - d = emit_load(jd, iptr, var, s1); - M_INTMOVE(d, s1); + s1 = emit_load(jd, iptr, var, d); + M_INTMOVE(s1, d); } else { - d = emit_load(jd, iptr, var, REG_ITMP1); - M_LST(d, REG_SP, md->params[s3].regoff * 8); + s1 = emit_load(jd, iptr, var, REG_ITMP1); + M_LST(s1, REG_SP, d * 8); } } else { if (!md->params[s3].inmemory) { - s1 = rd->argfltregs[md->params[s3].regoff]; - d = emit_load(jd, iptr, var, s1); - M_FLTMOVE(d, s1); + s1 = emit_load(jd, iptr, var, d); + M_FLTMOVE(s1, d); } else { - d = emit_load(jd, iptr, var, REG_FTMP1); - M_DST(d, REG_SP, md->params[s3].regoff * 8); + s1 = emit_load(jd, iptr, var, REG_FTMP1); + M_DST(s1, REG_SP, d * 8); } } } @@ -2658,12 +2603,20 @@ gen_method: disp = dseg_add_functionptr(cd, bte->fp); M_ALD(REG_PV, REG_PV, disp); /* Pointer to built-in-function */ + + /* generate the actual call */ + + M_JSR(REG_RA, REG_PV); + REPLACEMENT_POINT_INVOKE_RETURN(cd, iptr); + disp = (s4) (cd->mcodeptr - cd->mcodebase); + M_LDA(REG_PV, REG_RA, -disp); + + emit_exception_check(cd, iptr); break; case ICMD_INVOKESPECIAL: - M_BEQZ(REG_A0, 0); - codegen_add_nullpointerexception_ref(cd); - /* fall through */ + emit_nullpointer_check(cd, iptr, REG_A0); + /* fall-through */ case ICMD_INVOKESTATIC: if (lm == NULL) { @@ -2676,11 +2629,16 @@ gen_method: disp = dseg_add_address(cd, lm->stubroutine); M_ALD(REG_PV, REG_PV, disp); /* method pointer in r27 */ + + /* generate the actual call */ + + M_JSR(REG_RA, REG_PV); + REPLACEMENT_POINT_INVOKE_RETURN(cd, iptr); + disp = (s4) (cd->mcodeptr - cd->mcodebase); + M_LDA(REG_PV, REG_RA, -disp); break; case ICMD_INVOKEVIRTUAL: - emit_nullpointer_check(cd, iptr, REG_A0); - if (lm == NULL) { codegen_add_patch_ref(cd, PATCHER_invokevirtual, um, 0); @@ -2690,14 +2648,19 @@ gen_method: s1 = OFFSET(vftbl_t, table[0]) + sizeof(methodptr) * lm->vftblindex; - M_ALD(REG_METHODPTR, REG_A0, - OFFSET(java_objectheader, vftbl)); + /* implicit null-pointer check */ + M_ALD(REG_METHODPTR, REG_A0, OFFSET(java_objectheader, vftbl)); M_ALD(REG_PV, REG_METHODPTR, s1); + + /* generate the actual call */ + + M_JSR(REG_RA, REG_PV); + REPLACEMENT_POINT_INVOKE_RETURN(cd, iptr); + disp = (s4) (cd->mcodeptr - cd->mcodebase); + M_LDA(REG_PV, REG_RA, -disp); break; case ICMD_INVOKEINTERFACE: - emit_nullpointer_check(cd, iptr, REG_A0); - if (lm == NULL) { codegen_add_patch_ref(cd, PATCHER_invokeinterface, um, 0); @@ -2711,25 +2674,18 @@ gen_method: s2 = sizeof(methodptr) * (lm - lm->class->methods); } - M_ALD(REG_METHODPTR, REG_A0, - OFFSET(java_objectheader, vftbl)); + /* implicit null-pointer check */ + M_ALD(REG_METHODPTR, REG_A0, OFFSET(java_objectheader, vftbl)); M_ALD(REG_METHODPTR, REG_METHODPTR, s1); M_ALD(REG_PV, REG_METHODPTR, s2); - break; - } - /* generate the actual call */ + /* generate the actual call */ - M_JSR(REG_RA, REG_PV); - REPLACEMENT_POINT_INVOKE_RETURN(cd, iptr); - disp = (s4) (cd->mcodeptr - cd->mcodebase); - M_LDA(REG_PV, REG_RA, -disp); - - /* actually only used for ICMD_BUILTIN */ - - if (INSTRUCTION_MUST_CHECK(iptr)) { - M_BEQZ(REG_RESULT, 0); - codegen_add_fillinstacktrace_ref(cd); + M_JSR(REG_RA, REG_PV); + REPLACEMENT_POINT_INVOKE_RETURN(cd, iptr); + disp = (s4) (cd->mcodeptr - cd->mcodebase); + M_LDA(REG_PV, REG_RA, -disp); + break; } /* store the return value */ @@ -2752,60 +2708,30 @@ gen_method: case ICMD_CHECKCAST: /* ..., objectref ==> ..., objectref */ - /* val.a: (classinfo*) superclass */ - - /* superclass is an interface: - * - * OK if ((sub == NULL) || - * (sub->vftbl->interfacetablelength > super->index) && - * (sub->vftbl->interfacetable[-super->index] != NULL)); - * - * superclass is a class: - * - * OK if ((sub == NULL) || (0 - * <= (sub->vftbl->baseval - super->vftbl->baseval) <= - * super->vftbl->diffval)); - */ - if (!(iptr->flags.bits & INS_FLAG_ARRAY)) { /* object type cast-check */ classinfo *super; - vftbl_t *supervftbl; s4 superindex; if (INSTRUCTION_IS_UNRESOLVED(iptr)) { - super = NULL; + super = NULL; superindex = 0; - supervftbl = NULL; } else { - super = iptr->sx.s23.s3.c.cls; + super = iptr->sx.s23.s3.c.cls; superindex = super->index; - supervftbl = super->vftbl; } -#if defined(ENABLE_THREADS) - codegen_threadcritrestart(cd, cd->mcodeptr - cd->mcodebase); -#endif - s1 = emit_load_s1(jd, iptr, REG_ITMP1); - - /* calculate interface checkcast code size */ + if ((super == NULL) || !(super->flags & ACC_INTERFACE)) + CODEGEN_CRITICAL_SECTION_NEW; - s2 = 6; - if (super == NULL) - s2 += opt_shownops ? 1 : 0; - - /* calculate class checkcast code size */ - - s3 = 9 /* 8 + (s1 == REG_ITMP1) */; - if (super == NULL) - s3 += opt_shownops ? 1 : 0; + s1 = emit_load_s1(jd, iptr, REG_ITMP1); /* if class is not resolved, check which code to call */ if (super == NULL) { - M_BEQZ(s1, 4 + (opt_shownops ? 1 : 0) + s2 + 1 + s3); + emit_label_beqz(cd, BRANCH_LABEL_1, s1); disp = dseg_add_unique_s4(cd, 0); /* super->flags */ @@ -2817,7 +2743,7 @@ gen_method: disp = dseg_add_s4(cd, ACC_INTERFACE); M_ILD(REG_ITMP3, REG_PV, disp); M_AND(REG_ITMP2, REG_ITMP3, REG_ITMP2); - M_BEQZ(REG_ITMP2, s2 + 1); + emit_label_beqz(cd, BRANCH_LABEL_2, REG_ITMP2); } /* interface checkcast code */ @@ -2825,33 +2751,36 @@ gen_method: if ((super == NULL) || (super->flags & ACC_INTERFACE)) { if (super == NULL) { codegen_add_patch_ref(cd, - PATCHER_checkcast_instanceof_interface, + PATCHER_checkcast_interface, iptr->sx.s23.s3.c.ref, 0); } else - M_BEQZ(s1, s2); + emit_label_beqz(cd, BRANCH_LABEL_3, s1); M_ALD(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl)); M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, interfacetablelength)); M_LDA(REG_ITMP3, REG_ITMP3, -superindex); - M_BLEZ(REG_ITMP3, 0); - codegen_add_classcastexception_ref(cd, s1); + emit_classcast_check(cd, iptr, BRANCH_LE, REG_ITMP3, s1); + M_ALD(REG_ITMP3, REG_ITMP2, (s4) (OFFSET(vftbl_t, interfacetable[0]) - superindex * sizeof(methodptr*))); - M_BEQZ(REG_ITMP3, 0); - codegen_add_classcastexception_ref(cd, s1); + emit_classcast_check(cd, iptr, BRANCH_EQ, REG_ITMP3, s1); if (super == NULL) - M_BR(s3); + emit_label_br(cd, BRANCH_LABEL_4); + else + emit_label(cd, BRANCH_LABEL_3); } /* class checkcast code */ if ((super == NULL) || !(super->flags & ACC_INTERFACE)) { if (super == NULL) { + emit_label(cd, BRANCH_LABEL_2); + disp = dseg_add_unique_address(cd, NULL); codegen_add_patch_ref(cd, @@ -2860,16 +2789,16 @@ gen_method: disp); } else { - disp = dseg_add_address(cd, supervftbl); + disp = dseg_add_address(cd, super->vftbl); - M_BEQZ(s1, s3); + emit_label_beqz(cd, BRANCH_LABEL_5, s1); } M_ALD(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl)); M_ALD(REG_ITMP3, REG_PV, disp); -#if defined(ENABLE_THREADS) - codegen_threadcritstart(cd, cd->mcodeptr - cd->mcodebase); -#endif + + CODEGEN_CRITICAL_SECTION_START; + M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, baseval)); /* if (s1 != REG_ITMP1) { */ /* M_ILD(REG_ITMP1, REG_ITMP3, OFFSET(vftbl_t, baseval)); */ @@ -2884,13 +2813,20 @@ gen_method: M_ISUB(REG_ITMP2, REG_ITMP3, REG_ITMP2); M_ALD(REG_ITMP3, REG_PV, disp); M_ILD(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, diffval)); -#if defined(ENABLE_THREADS) - codegen_threadcritstop(cd, cd->mcodeptr - cd->mcodebase); -#endif + + CODEGEN_CRITICAL_SECTION_END; + /* } */ M_CMPULE(REG_ITMP2, REG_ITMP3, REG_ITMP3); - M_BEQZ(REG_ITMP3, 0); - codegen_add_classcastexception_ref(cd, s1); + emit_classcast_check(cd, iptr, BRANCH_EQ, REG_ITMP3, s1); + + if (super != NULL) + emit_label(cd, BRANCH_LABEL_5); + } + + if (super == NULL) { + emit_label(cd, BRANCH_LABEL_1); + emit_label(cd, BRANCH_LABEL_4); } d = codegen_reg_of_dst(jd, iptr, s1); @@ -2920,8 +2856,7 @@ gen_method: M_LDA(REG_PV, REG_RA, -disp); s1 = emit_load_s1(jd, iptr, REG_ITMP1); - M_BEQZ(REG_RESULT, 0); - codegen_add_classcastexception_ref(cd, s1); + emit_classcast_check(cd, iptr, BRANCH_EQ, REG_RESULT, s1); d = codegen_reg_of_dst(jd, iptr, s1); } @@ -2932,21 +2867,6 @@ gen_method: case ICMD_INSTANCEOF: /* ..., objectref ==> ..., intresult */ - /* val.a: (classinfo*) superclass */ - - /* superclass is an interface: - * - * return (sub != NULL) && - * (sub->vftbl->interfacetablelength > super->index) && - * (sub->vftbl->interfacetable[-super->index] != NULL); - * - * superclass is a class: - * - * return ((sub != NULL) && (0 - * <= (sub->vftbl->baseval - super->vftbl->baseval) <= - * super->vftbl->diffvall)); - */ - { classinfo *super; vftbl_t *supervftbl; @@ -2963,33 +2883,22 @@ gen_method: supervftbl = super->vftbl; } -#if defined(ENABLE_THREADS) - codegen_threadcritrestart(cd, cd->mcodeptr - cd->mcodebase); -#endif + if ((super == NULL) || !(super->flags & ACC_INTERFACE)) + CODEGEN_CRITICAL_SECTION_NEW; + s1 = emit_load_s1(jd, iptr, REG_ITMP1); d = codegen_reg_of_dst(jd, iptr, REG_ITMP2); + if (s1 == d) { M_MOV(s1, REG_ITMP1); s1 = REG_ITMP1; } - /* calculate interface instanceof code size */ - - s2 = 6; - if (super == NULL) - s2 += (d == REG_ITMP2 ? 1 : 0) + (opt_shownops ? 1 : 0); - - /* calculate class instanceof code size */ - - s3 = 7; - if (super == NULL) - s3 += (opt_shownops ? 1 : 0); - /* if class is not resolved, check which code to call */ if (super == NULL) { M_CLR(d); - M_BEQZ(s1, 4 + (opt_shownops ? 1 : 0) + s2 + 1 + s3); + emit_label_beqz(cd, BRANCH_LABEL_1, s1); disp = dseg_add_unique_s4(cd, 0); /* super->flags */ @@ -3001,7 +2910,7 @@ gen_method: disp = dseg_add_s4(cd, ACC_INTERFACE); M_ILD(REG_ITMP2, REG_PV, disp); M_AND(REG_ITMP3, REG_ITMP2, REG_ITMP3); - M_BEQZ(REG_ITMP3, s2 + 1); + emit_label_beqz(cd, BRANCH_LABEL_2, REG_ITMP3); } /* interface instanceof code */ @@ -3014,12 +2923,12 @@ gen_method: M_CLR(d); codegen_add_patch_ref(cd, - PATCHER_checkcast_instanceof_interface, + PATCHER_instanceof_interface, iptr->sx.s23.s3.c.ref, 0); } else { M_CLR(d); - M_BEQZ(s1, s2); + emit_label_beqz(cd, BRANCH_LABEL_3, s1); } M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl)); @@ -3032,13 +2941,17 @@ gen_method: M_CMPULT(REG_ZERO, REG_ITMP1, d); /* REG_ITMP1 != 0 */ if (super == NULL) - M_BR(s3); + emit_label_br(cd, BRANCH_LABEL_4); + else + emit_label(cd, BRANCH_LABEL_3); } /* class instanceof code */ if ((super == NULL) || !(super->flags & ACC_INTERFACE)) { if (super == NULL) { + emit_label(cd, BRANCH_LABEL_2); + disp = dseg_add_unique_address(cd, NULL); codegen_add_patch_ref(cd, PATCHER_resolve_classref_to_vftbl, @@ -3049,23 +2962,32 @@ gen_method: disp = dseg_add_address(cd, supervftbl); M_CLR(d); - M_BEQZ(s1, s3); + emit_label_beqz(cd, BRANCH_LABEL_5, s1); } M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl)); M_ALD(REG_ITMP2, REG_PV, disp); -#if defined(ENABLE_THREADS) - codegen_threadcritstart(cd, cd->mcodeptr - cd->mcodebase); -#endif + + CODEGEN_CRITICAL_SECTION_START; + M_ILD(REG_ITMP1, REG_ITMP1, OFFSET(vftbl_t, baseval)); M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval)); M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval)); -#if defined(ENABLE_THREADS) - codegen_threadcritstop(cd, cd->mcodeptr - cd->mcodebase); -#endif + + CODEGEN_CRITICAL_SECTION_END; + M_ISUB(REG_ITMP1, REG_ITMP3, REG_ITMP1); M_CMPULE(REG_ITMP1, REG_ITMP2, d); + + if (super != NULL) + emit_label(cd, BRANCH_LABEL_5); + } + + if (super == NULL) { + emit_label(cd, BRANCH_LABEL_1); + emit_label(cd, BRANCH_LABEL_4); } + emit_store_dst(jd, iptr, d); } break; @@ -3122,8 +3044,7 @@ gen_method: /* check for exception before result assignment */ - M_BEQZ(REG_RESULT, 0); - codegen_add_fillinstacktrace_ref(cd); + emit_exception_check(cd, iptr); d = codegen_reg_of_dst(jd, iptr, REG_RESULT); M_INTMOVE(REG_RESULT, d); @@ -3131,8 +3052,8 @@ gen_method: break; default: - *exceptionptr = - new_internalerror("Unknown ICMD %d", iptr->opc); + exceptions_throw_internalerror("Unknown ICMD %d during code generation", + iptr->opc); return false; } /* switch */ @@ -3145,102 +3066,62 @@ gen_method: /* generate stubs */ - emit_exception_stubs(jd); emit_patcher_stubs(jd); REPLACEMENT_EMIT_STUBS(jd); - codegen_finish(jd); - /* everything's ok */ return true; } -/* createcompilerstub ********************************************************** +/* codegen_emit_stub_compiler ************************************************** - Creates a stub routine which calls the compiler. + Emits a stub routine which calls the compiler. *******************************************************************************/ -#define COMPILERSTUB_DATASIZE 3 * SIZEOF_VOID_P -#define COMPILERSTUB_CODESIZE 3 * 4 - -#define COMPILERSTUB_SIZE COMPILERSTUB_DATASIZE + COMPILERSTUB_CODESIZE - - -u1 *createcompilerstub(methodinfo *m) +void codegen_emit_stub_compiler(jitdata *jd) { - u1 *s; /* memory to hold the stub */ - ptrint *d; + methodinfo *m; codegendata *cd; - s4 dumpsize; /* code generation pointer */ - - s = CNEW(u1, COMPILERSTUB_SIZE); - - /* set data pointer and code pointer */ - - d = (ptrint *) s; - s = s + COMPILERSTUB_DATASIZE; - - /* mark start of dump memory area */ - - dumpsize = dump_size(); - cd = DNEW(codegendata); - cd->mcodeptr = s; - - /* The codeinfo pointer is actually a pointer to the - methodinfo. This fakes a codeinfo structure. */ + /* get required compiler data */ - d[0] = (ptrint) asm_call_jit_compiler; - d[1] = (ptrint) m; - d[2] = (ptrint) &d[1]; /* fake code->m */ + m = jd->m; + cd = jd->cd; /* code for the stub */ M_ALD(REG_ITMP1, REG_PV, -2 * 8); /* load codeinfo pointer */ M_ALD(REG_PV, REG_PV, -3 * 8); /* load pointer to the compiler */ M_JMP(REG_ZERO, REG_PV); /* jump to the compiler */ - -#if defined(ENABLE_STATISTICS) - if (opt_stat) - count_cstub_len += COMPILERSTUB_SIZE; -#endif - - /* release dump area */ - - dump_release(dumpsize); - - return s; } -/* createnativestub ************************************************************ +/* codegen_emit_stub_native **************************************************** - Creates a stub routine which calls a native method. + Emits a stub routine which calls a native method. *******************************************************************************/ -u1 *createnativestub(functionptr f, jitdata *jd, methoddesc *nmd) +void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f) { - methodinfo *m; - codeinfo *code; - codegendata *cd; - registerdata *rd; - methoddesc *md; - s4 nativeparams; - s4 i, j; /* count variables */ - s4 t; - s4 s1, s2, disp; - s4 funcdisp; /* displacement of the function */ + methodinfo *m; + codeinfo *code; + codegendata *cd; + methoddesc *md; + s4 nativeparams; + s4 i, j; /* count variables */ + s4 t; + s4 s1, s2, disp; + s4 funcdisp; /* displacement of the function */ /* get required compiler data */ m = jd->m; code = jd->code; cd = jd->cd; - rd = jd->rd; /* initialize variables */ @@ -3254,7 +3135,7 @@ u1 *createnativestub(functionptr f, jitdata *jd, methoddesc *nmd) sizeof(stackframeinfo) / SIZEOF_VOID_P + sizeof(localref_table) / SIZEOF_VOID_P + 1 + /* methodinfo for call trace */ - (md->paramcount > INT_ARG_CNT ? INT_ARG_CNT : md->paramcount) + + md->paramcount + nmd->memuse; /* create method header */ @@ -3289,19 +3170,34 @@ u1 *createnativestub(functionptr f, jitdata *jd, methoddesc *nmd) codegen_add_patch_ref(cd, PATCHER_resolve_native_function, m, funcdisp); #endif +#if defined(ENABLE_GC_CACAO) + /* Save callee saved integer registers in stackframeinfo (GC may + need to recover them during a collection). */ + + disp = cd->stackframesize * 8 - SIZEOF_VOID_P - sizeof(stackframeinfo) + + OFFSET(stackframeinfo, intregs); + + for (i = 0; i < INT_SAV_CNT; i++) + M_AST(abi_registers_integer_saved[i], REG_SP, disp + i * 8); +#endif + /* save integer and float argument registers */ - for (i = 0, j = 0; i < md->paramcount && i < INT_ARG_CNT; i++) { - if (IS_INT_LNG_TYPE(md->paramtypes[i].type)) { - M_LST(rd->argintregs[i], REG_SP, j * 8); - j++; - } - } + for (i = 0; i < md->paramcount; i++) { + if (!md->params[i].inmemory) { + s1 = md->params[i].regoff; - for (i = 0; i < md->paramcount && i < FLT_ARG_CNT; i++) { - if (IS_FLT_DBL_TYPE(md->paramtypes[i].type)) { - M_DST(rd->argfltregs[i], REG_SP, j * 8); - j++; + switch (md->paramtypes[i].type) { + case TYPE_INT: + case TYPE_LNG: + case TYPE_ADR: + M_LST(s1, REG_SP, i * 8); + break; + case TYPE_FLT: + case TYPE_DBL: + M_DST(s1, REG_SP, i * 8); + break; + } } } @@ -3319,17 +3215,21 @@ u1 *createnativestub(functionptr f, jitdata *jd, methoddesc *nmd) /* restore integer and float argument registers */ - for (i = 0, j = 0; i < md->paramcount && i < INT_ARG_CNT; i++) { - if (IS_INT_LNG_TYPE(md->paramtypes[i].type)) { - M_LLD(rd->argintregs[i], REG_SP, j * 8); - j++; - } - } + for (i = 0; i < md->paramcount; i++) { + if (!md->params[i].inmemory) { + s1 = md->params[i].regoff; - for (i = 0; i < md->paramcount && i < FLT_ARG_CNT; i++) { - if (IS_FLT_DBL_TYPE(md->paramtypes[i].type)) { - M_DLD(rd->argfltregs[i], REG_SP, j * 8); - j++; + switch (md->paramtypes[i].type) { + case TYPE_INT: + case TYPE_LNG: + case TYPE_ADR: + M_LLD(s1, REG_SP, i * 8); + break; + case TYPE_FLT: + case TYPE_DBL: + M_DLD(s1, REG_SP, i * 8); + break; + } } } @@ -3340,41 +3240,36 @@ u1 *createnativestub(functionptr f, jitdata *jd, methoddesc *nmd) if (IS_INT_LNG_TYPE(t)) { if (!md->params[i].inmemory) { - s1 = rd->argintregs[md->params[i].regoff]; + s1 = md->params[i].regoff; + s2 = nmd->params[j].regoff; - if (!nmd->params[j].inmemory) { - s2 = rd->argintregs[nmd->params[j].regoff]; + if (!nmd->params[j].inmemory) M_INTMOVE(s1, s2); - - } else { - s2 = nmd->params[j].regoff; + else M_LST(s1, REG_SP, s2 * 8); - } - - } else { + } + else { s1 = md->params[i].regoff + cd->stackframesize; s2 = nmd->params[j].regoff; M_LLD(REG_ITMP1, REG_SP, s1 * 8); M_LST(REG_ITMP1, REG_SP, s2 * 8); } - - } else { + } + else { if (!md->params[i].inmemory) { - s1 = rd->argfltregs[md->params[i].regoff]; + s1 = md->params[i].regoff; + s2 = nmd->params[j].regoff; - if (!nmd->params[j].inmemory) { - s2 = rd->argfltregs[nmd->params[j].regoff]; + if (!nmd->params[j].inmemory) M_FLTMOVE(s1, s2); - - } else { - s2 = nmd->params[j].regoff; + else { if (IS_2_WORD_TYPE(t)) M_DST(s1, REG_SP, s2 * 8); else M_FST(s1, REG_SP, s2 * 8); } - - } else { + } + else { s1 = md->params[i].regoff + cd->stackframesize; s2 = nmd->params[j].regoff; M_DLD(REG_FTMP1, REG_SP, s1 * 8); @@ -3407,11 +3302,18 @@ u1 *createnativestub(functionptr f, jitdata *jd, methoddesc *nmd) /* save return value */ - if (md->returntype.type != TYPE_VOID) { - if (IS_INT_LNG_TYPE(md->returntype.type)) - M_LST(REG_RESULT, REG_SP, 0 * 8); - else - M_DST(REG_FRESULT, REG_SP, 0 * 8); + switch (md->returntype.type) { + case TYPE_INT: + case TYPE_LNG: + case TYPE_ADR: + M_LST(REG_RESULT, REG_SP, 0 * 8); + break; + case TYPE_FLT: + case TYPE_DBL: + M_DST(REG_FRESULT, REG_SP, 0 * 8); + break; + case TYPE_VOID: + break; } /* call finished trace */ @@ -3433,13 +3335,31 @@ u1 *createnativestub(functionptr f, jitdata *jd, methoddesc *nmd) /* restore return value */ - if (md->returntype.type != TYPE_VOID) { - if (IS_INT_LNG_TYPE(md->returntype.type)) - M_LLD(REG_RESULT, REG_SP, 0 * 8); - else - M_DLD(REG_FRESULT, REG_SP, 0 * 8); + switch (md->returntype.type) { + case TYPE_INT: + case TYPE_LNG: + case TYPE_ADR: + M_LLD(REG_RESULT, REG_SP, 0 * 8); + break; + case TYPE_FLT: + case TYPE_DBL: + M_DLD(REG_FRESULT, REG_SP, 0 * 8); + break; + case TYPE_VOID: + break; } +#if defined(ENABLE_GC_CACAO) + /* Restore callee saved integer registers from stackframeinfo (GC + might have modified them during a collection). */ + + disp = cd->stackframesize * 8 - SIZEOF_VOID_P - sizeof(stackframeinfo) + + OFFSET(stackframeinfo, intregs); + + for (i = 0; i < INT_SAV_CNT; i++) + M_ALD(abi_registers_integer_saved[i], REG_SP, disp + i * 8); +#endif + M_ALD(REG_RA, REG_SP, (cd->stackframesize - 1) * 8); /* get RA */ M_LDA(REG_SP, REG_SP, cd->stackframesize * 8); @@ -3456,14 +3376,9 @@ u1 *createnativestub(functionptr f, jitdata *jd, methoddesc *nmd) M_ALD(REG_ITMP3, REG_PV, disp); /* load asm exception handler address */ M_JMP(REG_ZERO, REG_ITMP3); /* jump to asm exception handler */ - /* generate patcher stubs */ emit_patcher_stubs(jd); - - codegen_finish(jd); - - return code->entrypoint; }