X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fvm%2Fjit%2Falpha%2Fcodegen.c;h=a49b1a0af59426899539c7e7a9ec37272353f68e;hb=8c6bb03b79a31fcdb02e2331a91a928d558c2845;hp=0c05829ec4da8291204d5daa096180f2c6754c72;hpb=bc95b5349cb98311849b9e3e0540755d3bff76b0;p=cacao.git diff --git a/src/vm/jit/alpha/codegen.c b/src/vm/jit/alpha/codegen.c index 0c05829ec..a49b1a0af 100644 --- a/src/vm/jit/alpha/codegen.c +++ b/src/vm/jit/alpha/codegen.c @@ -1,9 +1,7 @@ /* src/vm/jit/alpha/codegen.c - machine code generator for Alpha - 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 + Copyright (C) 1996-2005, 2006, 2007, 2008 + CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO This file is part of CACAO. @@ -38,38 +36,41 @@ #include "vm/jit/alpha/arch.h" #include "vm/jit/alpha/codegen.h" -#include "mm/memory.h" +#include "mm/memory.hpp" -#include "native/jni.h" -#include "native/localref.h" -#include "native/native.h" +#include "native/localref.hpp" +#include "native/native.hpp" -#include "threads/lock-common.h" +#include "threads/lock.hpp" -#include "vm/builtin.h" -#include "vm/exceptions.h" +#include "vm/jit/builtin.hpp" +#include "vm/exceptions.hpp" #include "vm/global.h" -#include "vm/vm.h" +#include "vm/loader.hpp" +#include "vm/options.h" +#include "vm/vm.hpp" #include "vm/jit/abi.h" #include "vm/jit/asmpart.h" -#include "vm/jit/codegen-common.h" +#include "vm/jit/codegen-common.hpp" #include "vm/jit/dseg.h" -#include "vm/jit/emit-common.h" -#include "vm/jit/jit.h" -#include "vm/jit/parse.h" -#include "vm/jit/patcher-common.h" +#include "vm/jit/emit-common.hpp" +#include "vm/jit/jit.hpp" +#include "vm/jit/linenumbertable.hpp" +#include "vm/jit/parse.hpp" +#include "vm/jit/patcher-common.hpp" #include "vm/jit/reg.h" -#include "vm/jit/replace.h" -#include "vm/jit/stacktrace.h" - -#if defined(ENABLE_LSRA) +#include "vm/jit/replace.hpp" +#include "vm/jit/stacktrace.hpp" +#include "vm/jit/trap.h" + +#if defined(ENABLE_SSA) +# include "vm/jit/optimizing/lsra.h" +# include "vm/jit/optimizing/ssa.h" +#elif defined(ENABLE_LSRA) # include "vm/jit/allocator/lsra.h" #endif -#include "vmcore/loader.h" -#include "vmcore/options.h" - /* codegen_emit **************************************************************** @@ -87,7 +88,6 @@ bool codegen_emit(jitdata *jd) varinfo *var; basicblock *bptr; instruction *iptr; - exception_entry *ex; u2 currentline; methodinfo *lm; /* local methodinfo for ICMD_INVOKE* */ unresolved_method *um; @@ -118,7 +118,7 @@ bool codegen_emit(jitdata *jd) s4 i, p, t, l; s4 savedregs_num; - savedregs_num = (jd->isleafmethod) ? 0 : 1; /* space to save the RA */ + savedregs_num = code_is_leafmethod(code) ? 0 : 1; /* space to save the RA */ /* space to save used callee saved registers */ @@ -128,7 +128,7 @@ bool codegen_emit(jitdata *jd) cd->stackframesize = rd->memuse + savedregs_num; #if defined(ENABLE_THREADS) /* space to save argument of monitor_enter */ - if (checksync && (m->flags & ACC_SYNCHRONIZED)) + if (checksync && code_is_synchronized(code)) cd->stackframesize++; #endif @@ -141,36 +141,18 @@ bool codegen_emit(jitdata *jd) (void) dseg_add_unique_address(cd, code); /* CodeinfoPointer */ (void) dseg_add_unique_s4(cd, cd->stackframesize * 8); /* FrameSize */ -#if defined(ENABLE_THREADS) - /* IsSync contains the offset relative to the stack pointer for the - argument of monitor_exit used in the exception handler. Since the - offset could be zero and give a wrong meaning of the flag it is - offset by one. - */ - - if (checksync && (m->flags & ACC_SYNCHRONIZED)) - (void) dseg_add_unique_s4(cd, (rd->memuse + 1) * 8); /* IsSync */ + code->synchronizedoffset = rd->memuse * 8; + + /* REMOVEME: We still need it for exception handling in assembler. */ + + if (code_is_leafmethod(code)) + (void) dseg_add_unique_s4(cd, 1); else -#endif - (void) dseg_add_unique_s4(cd, 0); /* IsSync */ + (void) dseg_add_unique_s4(cd, 0); - (void) dseg_add_unique_s4(cd, jd->isleafmethod); /* IsLeaf */ (void) dseg_add_unique_s4(cd, INT_SAV_CNT - rd->savintreguse); /* IntSave */ (void) dseg_add_unique_s4(cd, FLT_SAV_CNT - rd->savfltreguse); /* FltSave */ - dseg_addlinenumbertablesize(cd); - - (void) dseg_add_unique_s4(cd, jd->exceptiontablelength); /* ExTableSize */ - - /* create exception table */ - - for (ex = jd->exceptiontable; ex != NULL; ex = ex->down) { - dseg_add_target(cd, ex->start); - dseg_add_target(cd, ex->end); - dseg_add_target(cd, ex->handler); - (void) dseg_add_unique_address(cd, ex->catchtype.any); - } - /* create stack frame (if necessary) */ if (cd->stackframesize) @@ -179,7 +161,7 @@ bool codegen_emit(jitdata *jd) /* save return address and used callee saved registers */ p = cd->stackframesize; - if (!jd->isleafmethod) { + if (!code_is_leafmethod(code)) { p--; M_AST(REG_RA, REG_SP, p * 8); } for (i = INT_SAV_CNT - 1; i >= rd->savintreguse; i--) { @@ -242,7 +224,7 @@ bool codegen_emit(jitdata *jd) /* call monitorenter function */ #if defined(ENABLE_THREADS) - if (checksync && (m->flags & ACC_SYNCHRONIZED)) { + if (checksync && code_is_synchronized(code)) { /* stack offset for monitor argument */ s1 = rd->memuse; @@ -264,12 +246,12 @@ bool codegen_emit(jitdata *jd) /* decide which monitor enter function to call */ if (m->flags & ACC_STATIC) { - disp = dseg_add_address(cd, &m->class->object.header); + disp = dseg_add_address(cd, &m->clazz->object.header); M_ALD(REG_A0, REG_PV, disp); } else { M_BNEZ(REG_A0, 1); - M_ALD_INTERN(REG_ZERO, REG_ZERO, EXCEPTION_HARDWARE_NULLPOINTER); + M_ALD_INTERN(REG_ZERO, REG_ZERO, TRAP_NullPointerException); } M_AST(REG_A0, REG_SP, s1 * 8); @@ -367,7 +349,7 @@ bool codegen_emit(jitdata *jd) for (iptr = bptr->iinstr; len > 0; len--, iptr++) { if (iptr->line != currentline) { - dseg_addlinenumber(cd, iptr->line); + linenumbertable_list_entry_add(cd, iptr->line); currentline = iptr->line; } @@ -387,14 +369,14 @@ bool codegen_emit(jitdata *jd) case ICMD_INLINE_BODY: REPLACEMENT_POINT_INLINE_BODY(cd, iptr); - dseg_addlinenumber_inline_start(cd, iptr); - dseg_addlinenumber(cd, iptr->line); + linenumbertable_list_entry_add_inline_start(cd, iptr); + linenumbertable_list_entry_add(cd, iptr->line); break; case ICMD_INLINE_END: - dseg_addlinenumber_inline_end(cd, iptr); - dseg_addlinenumber(cd, iptr->line); + linenumbertable_list_entry_add_inline_end(cd, iptr); + linenumbertable_list_entry_add(cd, iptr->line); break; case ICMD_CHECKNULL: /* ..., objectref ==> ..., objectref */ @@ -1133,17 +1115,13 @@ bool codegen_emit(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_FTMP1); s2 = emit_load_s2(jd, iptr, REG_FTMP2); d = codegen_reg_of_dst(jd, iptr, REG_FTMP3); - if (opt_noieee) { - M_FADD(s1, s2, d); + if (d == s1 || d == s2) { + M_FADDS(s1, s2, REG_FTMP3); + M_TRAPB; + M_FMOV(REG_FTMP3, d); } else { - if (d == s1 || d == s2) { - M_FADDS(s1, s2, REG_FTMP3); - M_TRAPB; - M_FMOV(REG_FTMP3, d); - } else { - M_FADDS(s1, s2, d); - M_TRAPB; - } + M_FADDS(s1, s2, d); + M_TRAPB; } emit_store_dst(jd, iptr, d); break; @@ -1153,17 +1131,13 @@ bool codegen_emit(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_FTMP1); s2 = emit_load_s2(jd, iptr, REG_FTMP2); d = codegen_reg_of_dst(jd, iptr, REG_FTMP3); - if (opt_noieee) { - M_DADD(s1, s2, d); + if (d == s1 || d == s2) { + M_DADDS(s1, s2, REG_FTMP3); + M_TRAPB; + M_FMOV(REG_FTMP3, d); } else { - if (d == s1 || d == s2) { - M_DADDS(s1, s2, REG_FTMP3); - M_TRAPB; - M_FMOV(REG_FTMP3, d); - } else { - M_DADDS(s1, s2, d); - M_TRAPB; - } + M_DADDS(s1, s2, d); + M_TRAPB; } emit_store_dst(jd, iptr, d); break; @@ -1173,17 +1147,13 @@ bool codegen_emit(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_FTMP1); s2 = emit_load_s2(jd, iptr, REG_FTMP2); d = codegen_reg_of_dst(jd, iptr, REG_FTMP3); - if (opt_noieee) { - M_FSUB(s1, s2, d); + if (d == s1 || d == s2) { + M_FSUBS(s1, s2, REG_FTMP3); + M_TRAPB; + M_FMOV(REG_FTMP3, d); } else { - if (d == s1 || d == s2) { - M_FSUBS(s1, s2, REG_FTMP3); - M_TRAPB; - M_FMOV(REG_FTMP3, d); - } else { - M_FSUBS(s1, s2, d); - M_TRAPB; - } + M_FSUBS(s1, s2, d); + M_TRAPB; } emit_store_dst(jd, iptr, d); break; @@ -1193,17 +1163,13 @@ bool codegen_emit(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_FTMP1); s2 = emit_load_s2(jd, iptr, REG_FTMP2); d = codegen_reg_of_dst(jd, iptr, REG_FTMP3); - if (opt_noieee) { - M_DSUB(s1, s2, d); + if (d == s1 || d == s2) { + M_DSUBS(s1, s2, REG_FTMP3); + M_TRAPB; + M_FMOV(REG_FTMP3, d); } else { - if (d == s1 || d == s2) { - M_DSUBS(s1, s2, REG_FTMP3); - M_TRAPB; - M_FMOV(REG_FTMP3, d); - } else { - M_DSUBS(s1, s2, d); - M_TRAPB; - } + M_DSUBS(s1, s2, d); + M_TRAPB; } emit_store_dst(jd, iptr, d); break; @@ -1213,17 +1179,13 @@ bool codegen_emit(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_FTMP1); s2 = emit_load_s2(jd, iptr, REG_FTMP2); d = codegen_reg_of_dst(jd, iptr, REG_FTMP3); - if (opt_noieee) { - M_FMUL(s1, s2, d); + if (d == s1 || d == s2) { + M_FMULS(s1, s2, REG_FTMP3); + M_TRAPB; + M_FMOV(REG_FTMP3, d); } else { - if (d == s1 || d == s2) { - M_FMULS(s1, s2, REG_FTMP3); - M_TRAPB; - M_FMOV(REG_FTMP3, d); - } else { - M_FMULS(s1, s2, d); - M_TRAPB; - } + M_FMULS(s1, s2, d); + M_TRAPB; } emit_store_dst(jd, iptr, d); break; @@ -1233,17 +1195,13 @@ bool codegen_emit(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_FTMP1); s2 = emit_load_s2(jd, iptr, REG_FTMP2); d = codegen_reg_of_dst(jd, iptr, REG_FTMP3); - if (opt_noieee) { - M_DMUL(s1, s2, d); + if (d == s1 || d == s2) { + M_DMULS(s1, s2, REG_FTMP3); + M_TRAPB; + M_FMOV(REG_FTMP3, d); } else { - if (d == s1 || d == s2) { - M_DMULS(s1, s2, REG_FTMP3); - M_TRAPB; - M_FMOV(REG_FTMP3, d); - } else { - M_DMULS(s1, s2, d); - M_TRAPB; - } + M_DMULS(s1, s2, d); + M_TRAPB; } emit_store_dst(jd, iptr, d); break; @@ -1253,17 +1211,13 @@ bool codegen_emit(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_FTMP1); s2 = emit_load_s2(jd, iptr, REG_FTMP2); d = codegen_reg_of_dst(jd, iptr, REG_FTMP3); - if (opt_noieee) { - M_FDIV(s1, s2, d); + if (d == s1 || d == s2) { + M_FDIVS(s1, s2, REG_FTMP3); + M_TRAPB; + M_FMOV(REG_FTMP3, d); } else { - if (d == s1 || d == s2) { - M_FDIVS(s1, s2, REG_FTMP3); - M_TRAPB; - M_FMOV(REG_FTMP3, d); - } else { - M_FDIVS(s1, s2, d); - M_TRAPB; - } + M_FDIVS(s1, s2, d); + M_TRAPB; } emit_store_dst(jd, iptr, d); break; @@ -1273,17 +1227,13 @@ bool codegen_emit(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_FTMP1); s2 = emit_load_s2(jd, iptr, REG_FTMP2); d = codegen_reg_of_dst(jd, iptr, REG_FTMP3); - if (opt_noieee) { - M_DDIV(s1, s2, d); + if (d == s1 || d == s2) { + M_DDIVS(s1, s2, REG_FTMP3); + M_TRAPB; + M_FMOV(REG_FTMP3, d); } else { - if (d == s1 || d == s2) { - M_DDIVS(s1, s2, REG_FTMP3); - M_TRAPB; - M_FMOV(REG_FTMP3, d); - } else { - M_DDIVS(s1, s2, d); - M_TRAPB; - } + M_DDIVS(s1, s2, d); + M_TRAPB; } emit_store_dst(jd, iptr, d); break; @@ -1292,7 +1242,7 @@ bool codegen_emit(jitdata *jd) case ICMD_L2F: s1 = emit_load_s1(jd, iptr, REG_ITMP1); d = codegen_reg_of_dst(jd, iptr, REG_FTMP3); - disp = dseg_add_unique_double(cd, 0.0); + disp = dseg_add_unique_double(cd, 0.0); /* FIXME Not thread safe! */ M_LST(s1, REG_PV, disp); M_DLD(d, REG_PV, disp); M_CVTLF(d, d); @@ -1303,7 +1253,7 @@ bool codegen_emit(jitdata *jd) case ICMD_L2D: s1 = emit_load_s1(jd, iptr, REG_ITMP1); d = codegen_reg_of_dst(jd, iptr, REG_FTMP3); - disp = dseg_add_unique_double(cd, 0.0); + disp = dseg_add_unique_double(cd, 0.0); /* FIXME Not thread safe! */ M_LST(s1, REG_PV, disp); M_DLD(d, REG_PV, disp); M_CVTLD(d, d); @@ -1314,7 +1264,7 @@ bool codegen_emit(jitdata *jd) case ICMD_D2I: s1 = emit_load_s1(jd, iptr, REG_FTMP1); d = codegen_reg_of_dst(jd, iptr, REG_ITMP3); - disp = dseg_add_unique_double(cd, 0.0); + disp = dseg_add_unique_double(cd, 0.0); /* FIXME Not thread safe! */ M_CVTDL_C(s1, REG_FTMP2); M_CVTLI(REG_FTMP2, REG_FTMP3); M_DST(REG_FTMP3, REG_PV, disp); @@ -1326,7 +1276,7 @@ bool codegen_emit(jitdata *jd) case ICMD_D2L: s1 = emit_load_s1(jd, iptr, REG_FTMP1); d = codegen_reg_of_dst(jd, iptr, REG_ITMP3); - disp = dseg_add_unique_double(cd, 0.0); + disp = dseg_add_unique_double(cd, 0.0); /* FIXME Not thread safe! */ M_CVTDL_C(s1, REG_FTMP2); M_DST(REG_FTMP2, REG_PV, disp); M_LLD(d, REG_PV, disp); @@ -1346,12 +1296,8 @@ bool codegen_emit(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_FTMP1); d = codegen_reg_of_dst(jd, iptr, REG_FTMP3); - if (opt_noieee) { - M_CVTDF(s1, d); - } else { - M_CVTDFS(s1, d); - M_TRAPB; - } + M_CVTDFS(s1, d); + M_TRAPB; emit_store_dst(jd, iptr, d); break; @@ -1360,25 +1306,15 @@ bool codegen_emit(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_FTMP1); s2 = emit_load_s2(jd, iptr, REG_FTMP2); d = codegen_reg_of_dst(jd, iptr, REG_ITMP3); - if (opt_noieee) { - M_LSUB_IMM(REG_ZERO, 1, d); - M_FCMPEQ(s1, s2, REG_FTMP3); - M_FBEQZ (REG_FTMP3, 1); /* jump over next instructions */ - M_CLR (d); - M_FCMPLT(s2, s1, REG_FTMP3); - M_FBEQZ (REG_FTMP3, 1); /* jump over next instruction */ - M_LADD_IMM(REG_ZERO, 1, d); - } else { - M_LSUB_IMM(REG_ZERO, 1, d); - M_FCMPEQS(s1, s2, REG_FTMP3); - M_TRAPB; - M_FBEQZ (REG_FTMP3, 1); /* jump over next instructions */ - M_CLR (d); - M_FCMPLTS(s2, s1, REG_FTMP3); - M_TRAPB; - M_FBEQZ (REG_FTMP3, 1); /* jump over next instruction */ - M_LADD_IMM(REG_ZERO, 1, d); - } + M_LSUB_IMM(REG_ZERO, 1, d); + M_FCMPEQS(s1, s2, REG_FTMP3); + M_TRAPB; + M_FBEQZ (REG_FTMP3, 1); /* jump over next instructions */ + M_CLR (d); + M_FCMPLTS(s2, s1, REG_FTMP3); + M_TRAPB; + M_FBEQZ (REG_FTMP3, 1); /* jump over next instruction */ + M_LADD_IMM(REG_ZERO, 1, d); emit_store_dst(jd, iptr, d); break; @@ -1387,25 +1323,15 @@ bool codegen_emit(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_FTMP1); s2 = emit_load_s2(jd, iptr, REG_FTMP2); d = codegen_reg_of_dst(jd, iptr, REG_ITMP3); - if (opt_noieee) { - M_LADD_IMM(REG_ZERO, 1, d); - M_FCMPEQ(s1, s2, REG_FTMP3); - M_FBEQZ (REG_FTMP3, 1); /* jump over next instruction */ - M_CLR (d); - M_FCMPLT(s1, s2, REG_FTMP3); - M_FBEQZ (REG_FTMP3, 1); /* jump over next instruction */ - M_LSUB_IMM(REG_ZERO, 1, d); - } else { - M_LADD_IMM(REG_ZERO, 1, d); - M_FCMPEQS(s1, s2, REG_FTMP3); - M_TRAPB; - M_FBEQZ (REG_FTMP3, 1); /* jump over next instruction */ - M_CLR (d); - M_FCMPLTS(s1, s2, REG_FTMP3); - M_TRAPB; - M_FBEQZ (REG_FTMP3, 1); /* jump over next instruction */ - M_LSUB_IMM(REG_ZERO, 1, d); - } + M_LADD_IMM(REG_ZERO, 1, d); + M_FCMPEQS(s1, s2, REG_FTMP3); + M_TRAPB; + M_FBEQZ (REG_FTMP3, 1); /* jump over next instruction */ + M_CLR (d); + M_FCMPLTS(s1, s2, REG_FTMP3); + M_TRAPB; + M_FBEQZ (REG_FTMP3, 1); /* jump over next instruction */ + M_LSUB_IMM(REG_ZERO, 1, d); emit_store_dst(jd, iptr, d); break; @@ -1801,8 +1727,8 @@ bool codegen_emit(jitdata *jd) fieldtype = fi->type; disp = dseg_add_address(cd, fi->value); - if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) - patcher_add_patch_ref(jd, PATCHER_initialize_class, fi->class, + if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->clazz)) + patcher_add_patch_ref(jd, PATCHER_initialize_class, fi->clazz, 0); } @@ -1846,8 +1772,8 @@ bool codegen_emit(jitdata *jd) fieldtype = fi->type; disp = dseg_add_address(cd, fi->value); - if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) - patcher_add_patch_ref(jd, PATCHER_initialize_class, fi->class, + if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->clazz)) + patcher_add_patch_ref(jd, PATCHER_initialize_class, fi->clazz, 0); } @@ -1892,8 +1818,8 @@ bool codegen_emit(jitdata *jd) fieldtype = fi->type; disp = dseg_add_address(cd, fi->value); - if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) - patcher_add_patch_ref(jd, PATCHER_initialize_class, fi->class, + if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->clazz)) + patcher_add_patch_ref(jd, PATCHER_initialize_class, fi->clazz, 0); } @@ -2386,7 +2312,7 @@ nowperformreturn: #endif #if defined(ENABLE_THREADS) - if (checksync && (m->flags & ACC_SYNCHRONIZED)) { + if (checksync && code_is_synchronized(code)) { M_ALD(REG_A0, REG_SP, rd->memuse * 8); switch (iptr->opc) { @@ -2423,7 +2349,7 @@ nowperformreturn: /* restore return address */ - if (!jd->isleafmethod) { + if (!code_is_leafmethod(code)) { p--; M_LLD(REG_RA, REG_SP, p * 8); } @@ -2671,9 +2597,9 @@ gen_method: } else { s1 = OFFSET(vftbl_t, interfacetable[0]) - - sizeof(methodptr*) * lm->class->index; + sizeof(methodptr*) * lm->clazz->index; - s2 = sizeof(methodptr) * (lm - lm->class->methods); + s2 = sizeof(methodptr) * (lm - lm->clazz->methods); } /* implicit null-pointer check */ @@ -2725,9 +2651,6 @@ gen_method: superindex = super->index; } - if ((super == NULL) || !(super->flags & ACC_INTERFACE)) - CODEGEN_CRITICAL_SECTION_NEW; - s1 = emit_load_s1(jd, iptr, REG_ITMP1); /* if class is not resolved, check which code to call */ @@ -2799,28 +2722,49 @@ gen_method: M_ALD(REG_ITMP2, s1, OFFSET(java_object_t, vftbl)); M_ALD(REG_ITMP3, REG_PV, disp); - 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)); */ - /* M_ILD(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, diffval)); */ - /* #if defined(ENABLE_THREADS) */ - /* codegen_threadcritstop(cd, (u1 *) mcodeptr - cd->mcodebase); */ - /* #endif */ - /* M_ISUB(REG_ITMP2, REG_ITMP1, REG_ITMP2); */ - - /* } else { */ - M_ILD(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, baseval)); - 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)); - - CODEGEN_CRITICAL_SECTION_END; - - /* } */ - M_CMPULE(REG_ITMP2, REG_ITMP3, REG_ITMP3); - emit_classcast_check(cd, iptr, BRANCH_EQ, REG_ITMP3, s1); + if (super == NULL || super->vftbl->subtype_depth >= DISPLAY_SIZE) { + M_ILD(REG_ITMP1, REG_ITMP3, OFFSET(vftbl_t, subtype_offset)); + M_LADD(REG_ITMP1, REG_ITMP2, REG_ITMP1); + M_ALD(REG_ITMP1, REG_ITMP1, 0); + M_CMPEQ(REG_ITMP1, REG_ITMP3, REG_ITMP1); + emit_label_bnez(cd, BRANCH_LABEL_6, REG_ITMP1); /* good */ + + if (super == NULL) { + M_ILD(REG_ITMP1, REG_ITMP3, OFFSET(vftbl_t, subtype_offset)); + M_CMPEQ_IMM(REG_ITMP1, OFFSET(vftbl_t, subtype_display[DISPLAY_SIZE]), REG_ITMP1); + emit_label_beqz(cd, BRANCH_LABEL_10, REG_ITMP1); /* throw */ + } + + M_ILD(REG_ITMP1, REG_ITMP3, OFFSET(vftbl_t, subtype_depth)); + M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, subtype_depth)); + M_CMPLE(REG_ITMP1, REG_ITMP3, REG_ITMP3); + emit_label_beqz(cd, BRANCH_LABEL_9, REG_ITMP3); /* throw */ + /* reload */ + M_ALD(REG_ITMP3, REG_PV, disp); + M_ALD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, subtype_overflow)); + M_S8ADDQ(REG_ITMP1, REG_ITMP2, REG_ITMP2); + M_ALD(REG_ITMP1, REG_ITMP2, -DISPLAY_SIZE*8); + M_CMPEQ(REG_ITMP1, REG_ITMP3, REG_ITMP1); + emit_label_bnez(cd, BRANCH_LABEL_7, REG_ITMP1); /* good */ + + emit_label(cd, BRANCH_LABEL_9); + if (super == NULL) + emit_label(cd, BRANCH_LABEL_10); + + /* reload s1, might have been destroyed */ + emit_load_s1(jd, iptr, REG_ITMP1); + M_ALD_INTERN(s1, REG_ZERO, TRAP_ClassCastException); + + emit_label(cd, BRANCH_LABEL_7); + emit_label(cd, BRANCH_LABEL_6); + /* reload s1, might have been destroyed */ + emit_load_s1(jd, iptr, REG_ITMP1); + } + else { + M_ALD(REG_ITMP2, REG_ITMP2, super->vftbl->subtype_offset); + M_CMPEQ(REG_ITMP2, REG_ITMP3, REG_ITMP2); + emit_classcast_check(cd, iptr, BRANCH_EQ, REG_ITMP2, s1); + } if (super != NULL) emit_label(cd, BRANCH_LABEL_5); @@ -2885,9 +2829,6 @@ gen_method: supervftbl = super->vftbl; } - 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); @@ -2967,19 +2908,53 @@ gen_method: emit_label_beqz(cd, BRANCH_LABEL_5, s1); } - M_ALD(REG_ITMP1, s1, OFFSET(java_object_t, vftbl)); - M_ALD(REG_ITMP2, REG_PV, disp); + M_ALD(REG_ITMP2, s1, OFFSET(java_object_t, vftbl)); + M_ALD(REG_ITMP3, REG_PV, disp); - CODEGEN_CRITICAL_SECTION_START; + if (super == NULL || super->vftbl->subtype_depth >= DISPLAY_SIZE) { + M_ILD(REG_ITMP1, REG_ITMP3, OFFSET(vftbl_t, subtype_offset)); + M_LADD(REG_ITMP1, REG_ITMP2, REG_ITMP1); + M_ALD(REG_ITMP1, REG_ITMP1, 0); + M_CMPEQ(REG_ITMP1, REG_ITMP3, REG_ITMP1); + emit_label_beqz(cd, BRANCH_LABEL_8, REG_ITMP1); + ICONST(d, 1); + emit_label_br(cd, BRANCH_LABEL_6); /* true */ + emit_label(cd, BRANCH_LABEL_8); - 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 (super == NULL) { + M_ILD(REG_ITMP1, REG_ITMP3, OFFSET(vftbl_t, subtype_offset)); + M_CMPEQ_IMM(REG_ITMP1, OFFSET(vftbl_t, subtype_display[DISPLAY_SIZE]), REG_ITMP1); + emit_label_beqz(cd, BRANCH_LABEL_10, REG_ITMP1); /* false */ + } - CODEGEN_CRITICAL_SECTION_END; + M_ILD(REG_ITMP1, REG_ITMP3, OFFSET(vftbl_t, subtype_depth)); - M_ISUB(REG_ITMP1, REG_ITMP3, REG_ITMP1); - M_CMPULE(REG_ITMP1, REG_ITMP2, d); + M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, subtype_depth)); + M_CMPLE(REG_ITMP1, REG_ITMP3, REG_ITMP3); + emit_label_beqz(cd, BRANCH_LABEL_9, REG_ITMP3); /* false */ + /* reload */ + M_ALD(REG_ITMP3, REG_PV, disp); + M_ALD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, subtype_overflow)); + M_S8ADDQ(REG_ITMP1, REG_ITMP2, REG_ITMP2); + M_ALD(REG_ITMP1, REG_ITMP2, -DISPLAY_SIZE*8); + M_CMPEQ(REG_ITMP1, REG_ITMP3, d); + + if (d == REG_ITMP2) + emit_label_br(cd, BRANCH_LABEL_7); + emit_label(cd, BRANCH_LABEL_9); + if (super == NULL) + emit_label(cd, BRANCH_LABEL_10); + if (d == REG_ITMP2) { + M_CLR(d); + + emit_label(cd, BRANCH_LABEL_7); + } + emit_label(cd, BRANCH_LABEL_6); + } + else { + M_ALD(REG_ITMP2, REG_ITMP2, super->vftbl->subtype_offset); + M_CMPEQ(REG_ITMP2, REG_ITMP3, d); + } if (super != NULL) emit_label(cd, BRANCH_LABEL_5); @@ -3064,8 +3039,6 @@ gen_method: } /* if (bptr -> flags >= BBREACHED) */ } /* for basic block */ - dseg_createlinenumbertable(cd); - /* generate traps */ emit_patcher_traps(jd); @@ -3076,30 +3049,6 @@ gen_method: } -/* codegen_emit_stub_compiler ************************************************** - - Emits a stub routine which calls the compiler. - -*******************************************************************************/ - -void codegen_emit_stub_compiler(jitdata *jd) -{ - methodinfo *m; - codegendata *cd; - - /* get required compiler data */ - - 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 */ -} - - /* codegen_emit_stub_native **************************************************** Emits a stub routine which calls a native method. @@ -3112,10 +3061,10 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f, int s codeinfo *code; codegendata *cd; methoddesc *md; - s4 i, j; /* count variables */ - s4 t; - s4 s1, s2, disp; - s4 funcdisp; /* displacement of the function */ + int i, j; + int t; + int s1, s2; + int disp; /* get required compiler data */ @@ -3131,7 +3080,7 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f, int s cd->stackframesize = 1 + /* return address */ - sizeof(stackframeinfo) / SIZEOF_VOID_P + + sizeof(stackframeinfo_t) / SIZEOF_VOID_P + sizeof(localref_table) / SIZEOF_VOID_P + 1 + /* methodinfo for call trace */ md->paramcount + @@ -3141,31 +3090,21 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f, int s (void) dseg_add_unique_address(cd, code); /* CodeinfoPointer */ (void) dseg_add_unique_s4(cd, cd->stackframesize * 8); /* FrameSize */ - (void) dseg_add_unique_s4(cd, 0); /* IsSync */ (void) dseg_add_unique_s4(cd, 0); /* IsLeaf */ (void) dseg_add_unique_s4(cd, 0); /* IntSave */ (void) dseg_add_unique_s4(cd, 0); /* FltSave */ - (void) dseg_addlinenumbertablesize(cd); - (void) dseg_add_unique_s4(cd, 0); /* ExTableSize */ /* generate stub code */ M_LDA(REG_SP, REG_SP, -(cd->stackframesize * 8)); M_AST(REG_RA, REG_SP, cd->stackframesize * 8 - SIZEOF_VOID_P); - /* get function address (this must happen before the stackframeinfo) */ - - funcdisp = dseg_add_functionptr(cd, f); - - if (f == NULL) - patcher_add_patch_ref(jd, PATCHER_resolve_native_function, m, funcdisp); - #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); + disp = cd->stackframesize * 8 - SIZEOF_VOID_P - sizeof(stackframeinfo_t) + + OFFSET(stackframeinfo_t, intregs); for (i = 0; i < INT_SAV_CNT; i++) M_AST(abi_registers_integer_saved[i], REG_SP, disp + i * 8); @@ -3288,13 +3227,14 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f, int s /* put env into first argument register */ - disp = dseg_add_address(cd, _Jv_env); + disp = dseg_add_address(cd, VM_get_jnienv()); M_ALD(REG_A0, REG_PV, disp); } - /* do the native function call */ + /* Call the native function. */ - M_ALD(REG_PV, REG_PV, funcdisp); + disp = dseg_add_functionptr(cd, f); + M_ALD(REG_PV, REG_PV, disp); M_JSR(REG_RA, REG_PV); /* call native method */ disp = (s4) (cd->mcodeptr - cd->mcodebase); M_LDA(REG_PV, REG_RA, -disp); /* recompute pv from ra */ @@ -3350,8 +3290,8 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f, int s /* 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); + disp = cd->stackframesize * 8 - SIZEOF_VOID_P - sizeof(stackframeinfo_t) + + OFFSET(stackframeinfo_t, intregs); for (i = 0; i < INT_SAV_CNT; i++) M_ALD(abi_registers_integer_saved[i], REG_SP, disp + i * 8); @@ -3372,10 +3312,6 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f, int s disp = dseg_add_functionptr(cd, asm_handle_nat_exception); 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_traps(jd); }