X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=src%2Fvm%2Fjit%2Fi386%2Fcodegen.c;h=8eab0fbf0511a4cce0d56cac92d930db7c06b8ed;hb=8c6bb03b79a31fcdb02e2331a91a928d558c2845;hp=f8507a12652c03163a02a0ed1f810a827947b318;hpb=f2423f5b76bb1f5093780e605f4e67ec0f95285f;p=cacao.git diff --git a/src/vm/jit/i386/codegen.c b/src/vm/jit/i386/codegen.c index f8507a126..8eab0fbf0 100644 --- a/src/vm/jit/i386/codegen.c +++ b/src/vm/jit/i386/codegen.c @@ -36,31 +36,34 @@ #include "vm/jit/i386/codegen.h" #include "vm/jit/i386/emit.h" -#include "mm/memory.h" -#include "native/jni.h" -#include "native/localref.h" -#include "native/native.h" +#include "mm/memory.hpp" -#include "threads/lock-common.h" +#include "native/localref.hpp" +#include "native/native.hpp" -#include "vm/builtin.h" -#include "vm/exceptions.h" +#include "threads/lock.hpp" + +#include "vm/jit/builtin.hpp" +#include "vm/exceptions.hpp" #include "vm/global.h" -#include "vm/stringlocal.h" -#include "vm/vm.h" +#include "vm/loader.hpp" +#include "vm/options.h" +#include "vm/primitive.hpp" +#include "vm/utf8.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/linenumbertable.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" +#include "vm/jit/replace.hpp" +#include "vm/jit/stacktrace.hpp" #include "vm/jit/trap.h" #if defined(ENABLE_SSA) @@ -70,10 +73,6 @@ # include "vm/jit/allocator/lsra.h" #endif -#include "vmcore/loader.h" -#include "vmcore/options.h" -#include "vmcore/utf8.h" - /* codegen_emit **************************************************************** @@ -407,9 +406,7 @@ bool codegen_emit(jitdata *jd) if (bptr->bitflags & BBFLAG_REPLACEMENT) { if (cd->replacementpoint[-1].flags & RPLPOINT_FLAG_COUNTDOWN) { MCODECHECK(32); - disp = (s4) &(m->hitcountdown); - M_ISUB_IMM_MEMABS(1, disp); - M_BS(0); + emit_trap_countdown(cd, &(m->hitcountdown)); } } #endif @@ -2224,7 +2221,7 @@ bool codegen_emit(jitdata *jd) break; case ICMD_PUTSTATIC: /* ..., value ==> ... */ - + if (INSTRUCTION_IS_UNRESOLVED(iptr)) { uf = iptr->sx.s23.s3.uf; fieldtype = uf->fieldref->parseddesc.fd->type; @@ -2303,6 +2300,10 @@ bool codegen_emit(jitdata *jd) s1 = emit_load_s1(jd, iptr, REG_ITMP1); emit_nullpointer_check(cd, iptr, s1); +#if defined(ENABLE_ESCAPE_CHECK) + /*emit_escape_check(cd, s1);*/ +#endif + if (INSTRUCTION_IS_UNRESOLVED(iptr)) { uf = iptr->sx.s23.s3.uf; fieldtype = uf->fieldref->parseddesc.fd->type; @@ -2886,6 +2887,21 @@ nowperformreturn: bte = iptr->sx.s23.s3.bte; md = bte->md; + +#if defined(ENABLE_ESCAPE_REASON) + if (bte->fp == BUILTIN_escape_reason_new) { + void set_escape_reasons(void *); + M_ASUB_IMM(8, REG_SP); + M_MOV_IMM(iptr->escape_reasons, REG_ITMP1); + M_AST(EDX, REG_SP, 4); + M_AST(REG_ITMP1, REG_SP, 0); + M_MOV_IMM(set_escape_reasons, REG_ITMP1); + M_CALL(REG_ITMP1); + M_ALD(EDX, REG_SP, 4); + M_AADD_IMM(8, REG_SP); + } +#endif + goto gen_method; case ICMD_INVOKESTATIC: /* ..., [arg1, [arg2 ...]] ==> ... */ @@ -2960,6 +2976,12 @@ gen_method: M_MOV_IMM(bte->stub, REG_ITMP1); } M_CALL(REG_ITMP1); + +#if defined(ENABLE_ESCAPE_CHECK) + if (bte->opcode == ICMD_NEW || bte->opcode == ICMD_NEWARRAY) { + /*emit_escape_annotate_object(cd, m);*/ + } +#endif break; case ICMD_INVOKESPECIAL: @@ -3093,9 +3115,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); /* if class is not resolved, check which code to call */ @@ -3159,39 +3178,49 @@ gen_method: } M_ALD(REG_ITMP2, s1, OFFSET(java_object_t, vftbl)); - if (super == NULL) { patcher_add_patch_ref(jd, PATCHER_checkcast_class, iptr->sx.s23.s3.c.ref, 0); } - M_MOV_IMM(supervftbl, REG_ITMP3); - 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_CMP_MEMINDEX(REG_ITMP2, 0, REG_ITMP1, 0, REG_ITMP3); + emit_label_beq(cd, BRANCH_LABEL_6); /* good */ + + if (super == NULL) { + M_ICMP_IMM(OFFSET(vftbl_t, subtype_display[DISPLAY_SIZE]), REG_ITMP1); + emit_label_bne(cd, BRANCH_LABEL_10); /* throw */ + } - M_ILD32(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, baseval)); + M_ILD(REG_ITMP1, REG_ITMP3, OFFSET(vftbl_t, subtype_depth)); + M_CMP_MEMBASE(REG_ITMP2, OFFSET(vftbl_t, subtype_depth), REG_ITMP1); + emit_label_bgt(cd, BRANCH_LABEL_9); /* throw */ - /* if (s1 != REG_ITMP1) { */ - /* emit_mov_membase_reg(cd, REG_ITMP3, OFFSET(vftbl_t, baseval), REG_ITMP1); */ - /* emit_mov_membase_reg(cd, REG_ITMP3, OFFSET(vftbl_t, diffval), REG_ITMP3); */ - /* #if defined(ENABLE_THREADS) */ - /* codegen_threadcritstop(cd, cd->mcodeptr - cd->mcodebase); */ - /* #endif */ - /* emit_alu_reg_reg(cd, ALU_SUB, REG_ITMP1, REG_ITMP2); */ + M_ALD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, subtype_overflow)); + M_CMP_MEMINDEX(REG_ITMP2, -4*DISPLAY_SIZE, REG_ITMP1, 2, REG_ITMP3); + emit_label_beq(cd, BRANCH_LABEL_7); /* good */ - /* } else { */ - M_ILD32(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, baseval)); - M_ISUB(REG_ITMP3, REG_ITMP2); - M_MOV_IMM(supervftbl, REG_ITMP3); - M_ILD(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, diffval)); + emit_label(cd, BRANCH_LABEL_9); + if (super == NULL) + emit_label(cd, BRANCH_LABEL_10); - CODEGEN_CRITICAL_SECTION_END; + /* reload s1, might have been destroyed */ + emit_load_s1(jd, iptr, REG_ITMP1); + M_ALD_MEM(s1, 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_CMP_MEMBASE(REG_ITMP2, super->vftbl->subtype_offset, REG_ITMP3); - M_CMP(REG_ITMP3, REG_ITMP2); - emit_classcast_check(cd, iptr, BRANCH_ULE, REG_ITMP3, s1); + emit_classcast_check(cd, iptr, BRANCH_NE, REG_ITMP3, s1); + } if (super != NULL) emit_label(cd, BRANCH_LABEL_5); @@ -3248,9 +3277,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); @@ -3325,28 +3351,72 @@ gen_method: emit_label_beq(cd, BRANCH_LABEL_5); } - M_ALD(REG_ITMP1, s1, OFFSET(java_object_t, vftbl)); - + M_ALD(REG_ITMP2, s1, OFFSET(java_object_t, vftbl)); if (super == NULL) { patcher_add_patch_ref(jd, PATCHER_instanceof_class, iptr->sx.s23.s3.c.ref, 0); } + M_MOV_IMM(supervftbl, REG_ITMP3); + + if (super == NULL || super->vftbl->subtype_depth >= DISPLAY_SIZE) { + M_ILD(REG_ITMP1, REG_ITMP3, OFFSET(vftbl_t, subtype_offset)); + M_CMP_MEMINDEX(REG_ITMP2, 0, REG_ITMP1, 0, REG_ITMP3); + emit_label_bne(cd, BRANCH_LABEL_8); /* jump over INC/SETE */ + if (d == REG_ITMP2) { + M_SETE(d); + M_BSEXT(d, d); + } else + M_IINC(d); + emit_label_br(cd, BRANCH_LABEL_6); /* true */ + emit_label(cd, BRANCH_LABEL_8); + + if (super == NULL) { + M_ICMP_IMM(OFFSET(vftbl_t, subtype_display[DISPLAY_SIZE]), REG_ITMP1); + emit_label_bne(cd, BRANCH_LABEL_10); /* false */ + } - M_MOV_IMM(supervftbl, REG_ITMP2); + M_ILD(REG_ITMP1, REG_ITMP3, OFFSET(vftbl_t, subtype_depth)); + M_CMP_MEMBASE(REG_ITMP2, OFFSET(vftbl_t, subtype_depth), REG_ITMP1); + emit_label_bgt(cd, BRANCH_LABEL_9); /* false */ - CODEGEN_CRITICAL_SECTION_START; + M_ALD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, subtype_overflow)); + M_CMP_MEMINDEX(REG_ITMP2, -4*DISPLAY_SIZE, REG_ITMP1, 2, REG_ITMP3); + if (d >= 4) { + M_SETE(REG_ITMP1); + M_BSEXT(REG_ITMP1, d); + } + else { + M_SETE(d); + if (d == REG_ITMP2) { + M_BSEXT(d, d); - M_ILD(REG_ITMP1, REG_ITMP1, OFFSET(vftbl_t, baseval)); - M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, diffval)); - M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, baseval)); + emit_label_br(cd, BRANCH_LABEL_7); /* jump over M_CLR */ + } + } - CODEGEN_CRITICAL_SECTION_END; + emit_label(cd, BRANCH_LABEL_9); + if (super == NULL) + emit_label(cd, BRANCH_LABEL_10); + if (d == REG_ITMP2) { + M_CLR(d); - M_ISUB(REG_ITMP2, REG_ITMP1); - M_CLR(d); /* may be REG_ITMP2 */ - M_CMP(REG_ITMP3, REG_ITMP1); - M_BA(5); - M_MOV_IMM(1, d); + emit_label(cd, BRANCH_LABEL_7); + } + emit_label(cd, BRANCH_LABEL_6); + } + else { + M_CMP_MEMBASE(REG_ITMP2, super->vftbl->subtype_offset, REG_ITMP3); + + if (d >= 4) { + M_SETE(REG_ITMP1); + M_BSEXT(REG_ITMP1, d); + } + else { + M_SETE(d); + if (d == REG_ITMP2) + M_BSEXT(d, d); + } + } if (super != NULL) emit_label(cd, BRANCH_LABEL_5); @@ -3611,7 +3681,7 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f, int s /* put env into first argument */ - M_AST_IMM(_Jv_env, REG_SP, 0 * 4); + M_AST_IMM(VM_get_jnienv(), REG_SP, 0 * 4); } /* Call the native function. */ @@ -3627,6 +3697,20 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f, int s switch (md->returntype.type) { case TYPE_INT: case TYPE_ADR: + switch (md->returntype.primitivetype) { + case PRIMITIVETYPE_BOOLEAN: + M_BZEXT(REG_RESULT, REG_RESULT); + break; + case PRIMITIVETYPE_BYTE: + M_BSEXT(REG_RESULT, REG_RESULT); + break; + case PRIMITIVETYPE_CHAR: + M_CZEXT(REG_RESULT, REG_RESULT); + break; + case PRIMITIVETYPE_SHORT: + M_SSEXT(REG_RESULT, REG_RESULT); + break; + } M_IST(REG_RESULT, REG_SP, 1 * 8); break; case TYPE_LNG: