/* src/vm/jit/m68k/codegen.c
- 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.
#include <stdint.h>
#include "md-abi.h"
-#include "md-os.h"
#include "vm/types.h"
#include "vm/jit/m68k/codegen.h"
#include "vm/jit/m68k/emit.h"
#include "mm/memory.h"
-#include "native/jni.h"
-#include "native/localref.h"
-#include "native/native.h"
-#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/utf8.h"
+#include "vm/vm.hpp"
#include "vm/jit/asmpart.h"
-#include "vm/jit/codegen-common.h"
+#include "vm/jit/codegen-common.hpp"
+#include "vm/jit/patcher-common.hpp"
#include "vm/jit/dseg.h"
-#include "vm/jit/emit-common.h"
-#include "vm/jit/jit.h"
+#include "vm/jit/linenumbertable.hpp"
+#include "vm/jit/emit-common.hpp"
+#include "vm/jit/jit.hpp"
#include "vm/jit/abi.h"
-#include "vm/jit/parse.h"
-#include "vm/jit/patcher.h"
+#include "vm/jit/parse.hpp"
#include "vm/jit/reg.h"
-#include "vm/jit/replace.h"
-#include "vm/jit/stacktrace.h"
-#include "vm/jit/md.h"
-
-#include "vmcore/loader.h"
-#include "vmcore/options.h"
-#include "vmcore/utf8.h"
+#include "vm/jit/replace.hpp"
+#include "vm/jit/stacktrace.hpp"
+#include "vm/jit/trap.h"
bool codegen_emit(jitdata *jd)
codegendata *cd;
registerdata *rd;
s4 len, s1, s2, s3, d, disp;
- ptrint a;
varinfo *var;
basicblock *bptr;
instruction *iptr;
- exception_entry *ex;
u2 currentline;
methodinfo *lm; /* local methodinfo for ICMD_INVOKE* */
unresolved_method *um;
#if 0
#if defined(ENABLE_THREADS)
/* we need additional space to save argument of monitor_enter */
- if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
+ if (checksync && code_is_synchronized(code)) {
if (IS_2_WORD_TYPE(m->parseddesc->returntype.type)) {
cd->stackframesize += 2;
} else {
/* create method header */
(void) dseg_add_unique_address(cd, code); /* CodeinfoPointer */
(void) dseg_add_unique_s4(cd, cd->stackframesize); /* FrameSize */
-#if defined(ENABLE_THREADS)
- 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, jd->isleafmethod); /* IsLeaf */
+ (void) dseg_add_unique_s4(cd, 0);
/* XXX we use the IntSave a split field for the adr now */
(void) dseg_add_unique_s4(cd, (ADR_SAV_CNT - rd->savadrreguse) << 16 | (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);
- }
-
#if defined(ENABLE_PROFILING)
assert(0);
#endif
#if defined(ENABLE_THREADS)
/* call lock_monitor_enter function */
- if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
+ if (checksync && code_is_synchronized(code)) {
if (m->flags & ACC_STATIC) {
- M_AMOV_IMM((&m->class->object.header), REG_ATMP1);
+ M_AMOV_IMM((&m->clazz->object.header), REG_ATMP1);
} else {
/* for non-static case the first arg is the object */
M_ALD(REG_ATMP1, REG_SP, cd->stackframesize + 4);
M_ATST(REG_ATMP1);
M_BNE(2);
- M_TRAP(M68K_EXCEPTION_HARDWARE_NULLPOINTER);
+ M_TRAP(TRAP_NullPointerException);
}
M_AST(REG_ATMP1, REG_SP, rd->memuse * 8);
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;
}
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_intern(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(cd, iptr);
+ linenumbertable_list_entry_add(cd, iptr->line);
break;
case ICMD_CHECKNULL: /* ..., objectref ==> ..., objectref */
if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
constant_classref *cr = iptr->sx.val.c.ref;;
- codegen_addpatchref(cd, PATCHER_resolve_classref_to_classinfo, cr, 0);
+ patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo, cr, 0);
M_AMOV_IMM(0, d);
} else {
M_AMOV_IMM(iptr->sx.val.anyptr, d);
if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
unresolved_class *uc = iptr->sx.s23.s2.uc;
- codegen_addpatchref(cd, PATCHER_resolve_class, uc, 0);
+ patcher_add_patch_ref(jd, PATCHER_resolve_class, uc, 0);
}
#endif /* ENABLE_VERIFIER */
M_JSR_PCREL(2); /* get current PC */
fieldtype = uf->fieldref->parseddesc.fd->type;
disp = 0;
- codegen_addpatchref(cd, PATCHER_get_putstatic, uf, 0);
+ patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, 0);
}
else {
fi = iptr->sx.s23.s3.fmiref->p.field;
fieldtype = fi->type;
disp = (intptr_t) fi->value;
- if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
- codegen_addpatchref(cd, PATCHER_initialize_class, fi->class,
+ if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->clazz)) {
+ patcher_add_patch_ref(jd, PATCHER_initialize_class, fi->clazz,
0);
}
}
fieldtype = uf->fieldref->parseddesc.fd->type;
disp = 0;
- codegen_addpatchref(cd, PATCHER_get_putstatic, uf, 0);
+ patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, 0);
}
else {
fi = iptr->sx.s23.s3.fmiref->p.field;
fieldtype = fi->type;
disp = (intptr_t) fi->value;
- if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class))
- codegen_addpatchref(cd, PATCHER_initialize_class, fi->class,
+ if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->clazz))
+ patcher_add_patch_ref(jd, PATCHER_initialize_class, fi->clazz,
0);
}
fieldtype = uf->fieldref->parseddesc.fd->type;
disp = 0;
- codegen_addpatchref(cd, PATCHER_get_putfield, uf, 0);
+ patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
}
else {
fi = iptr->sx.s23.s3.fmiref->p.field;
}
if (INSTRUCTION_IS_UNRESOLVED(iptr))
- codegen_addpatchref(cd, PATCHER_get_putfield, uf, 0);
+ patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
/* implicit null-pointer check */
switch (fieldtype) {
s3 = emit_load_s3(jd, iptr, REG_ATMP2);
/* XXX what if array is NULL */
- disp = dseg_add_functionptr(cd, BUILTIN_canstore);
+ disp = dseg_add_functionptr(cd, BUILTIN_FAST_canstore);
M_AST(s1, REG_SP, 0*4);
M_AST(s3, REG_SP, 1*4);
- M_JSR_IMM(BUILTIN_canstore);
- emit_exception_check(cd, iptr);
+ M_JSR_IMM(BUILTIN_FAST_canstore);
+ emit_arraystore_check(cd, iptr);
s1 = emit_load_s1(jd, iptr, REG_ATMP1);
s2 = emit_load_s2(jd, iptr, REG_ITMP1);
/* arguments in place now */
switch(iptr->opc) {
- case ICMD_BUILTIN:
- disp = (ptrint) bte->fp;
+ case ICMD_BUILTIN:
+ if (bte->stub == NULL)
+ disp = (ptrint) bte->fp;
+ else
+ disp = (ptrint) bte->stub;
d = md->returntype.type;
M_JSR_IMM(disp);
REPLACEMENT_POINT_INVOKE_RETURN(cd, iptr);
- emit_exception_check(cd, iptr);
break;
case ICMD_INVOKESPECIAL:
/* fall through */
case ICMD_INVOKESTATIC:
if (lm == NULL) {
- codegen_addpatchref(cd, PATCHER_invokestatic_special, um, 0);
+ patcher_add_patch_ref(jd, PATCHER_invokestatic_special, um, 0);
disp = 0;
M_AMOV_IMM(disp, REG_ATMP1);
} else {
case ICMD_INVOKEVIRTUAL:
if (lm == NULL) {
- codegen_addpatchref(cd, PATCHER_invokevirtual, um, 0);
+ patcher_add_patch_ref(jd, PATCHER_invokevirtual, um, 0);
s1 = 0;
} else {
s1 = OFFSET(vftbl_t, table[0]) + sizeof(methodptr) * lm->vftblindex;
break;
case ICMD_INVOKEINTERFACE:
if (lm == NULL) {
- codegen_addpatchref(cd, PATCHER_invokeinterface, um, 0);
+ patcher_add_patch_ref(jd, PATCHER_invokeinterface, um, 0);
s1 = 0;
s2 = 0;
} else {
- s1 = OFFSET(vftbl_t, interfacetable[0]) - sizeof(methodptr*) * lm->class->index;
- s2 = sizeof(methodptr) * (lm - lm->class->methods);
+ s1 = OFFSET(vftbl_t, interfacetable[0]) - sizeof(methodptr*) * lm->clazz->index;
+ s2 = sizeof(methodptr) * (lm - lm->clazz->methods);
}
/* load object pointer (==argument 0) */
M_ALD(REG_ATMP1, REG_SP, 0);
if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
unresolved_class *uc = iptr->sx.s23.s2.uc;
- codegen_addpatchref(cd, PATCHER_resolve_class, uc, 0);
+ patcher_add_patch_ref(jd, PATCHER_resolve_class, uc, 0);
}
#endif /* ENABLE_VERIFIER */
goto nowperformreturn;
#if defined(ENABLE_THREADS)
/* call lock_monitor_exit */
- if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
+ if (checksync && code_is_synchronized(code)) {
M_ILD(REG_ITMP3, REG_SP, rd->memuse * 8);
/* we need to save the proper return value */
/* restore return address */
#if 0
- if (!jd->isleafmethod) {
+ if (!code_is_leafmethod(code)) {
/* ATTENTION: Don't use REG_ZERO (r0) here, as M_ALD
may have a displacement overflow. */
superindex = super->index;
}
- if ((super == NULL) || !(super->flags & ACC_INTERFACE))
- CODEGEN_CRITICAL_SECTION_NEW;
-
s1 = emit_load_s1(jd, iptr, REG_ATMP1);
d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
M_ATST(s1);
emit_label_beq(cd, BRANCH_LABEL_1);
- codegen_addpatchref(cd, PATCHER_resolve_classref_to_flags, iptr->sx.s23.s3.c.ref, 0);
+ patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_flags, iptr->sx.s23.s3.c.ref, 0);
M_IMOV_IMM32(0, REG_ITMP3);
M_IAND_IMM(ACC_INTERFACE, REG_ITMP3);
if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
if (super == NULL) {
- codegen_addpatchref(cd, PATCHER_instanceof_interface, iptr->sx.s23.s3.c.ref, 0);
+ patcher_add_patch_ref(jd, PATCHER_instanceof_interface, iptr->sx.s23.s3.c.ref, 0);
} else {
M_ATST(s1);
emit_label_beq(cd, BRANCH_LABEL_3);
if (super == NULL) {
emit_label(cd, BRANCH_LABEL_2);
- codegen_addpatchref(cd, PATCHER_resolve_classref_to_vftbl, iptr->sx.s23.s3.c.ref, 0);
+ patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_vftbl, iptr->sx.s23.s3.c.ref, 0);
M_AMOV_IMM(0, REG_ATMP2);
} else {
M_AMOV_IMM(super->vftbl, REG_ATMP2);
M_ALD(REG_ATMP1, s1, OFFSET(java_object_t, vftbl));
- CODEGEN_CRITICAL_SECTION_START;
-
M_ILD(REG_ITMP1, REG_ATMP1, OFFSET(vftbl_t, baseval));
M_ILD(REG_ITMP3, REG_ATMP2, OFFSET(vftbl_t, baseval));
M_ILD(REG_ITMP2, REG_ATMP2, OFFSET(vftbl_t, diffval));
- CODEGEN_CRITICAL_SECTION_END;
-
M_ISUB(REG_ITMP3, REG_ITMP1);
M_ICMP(REG_ITMP2, REG_ITMP1);
M_BHI(4);
superindex = super->index;
}
- if ((super == NULL) || !(super->flags & ACC_INTERFACE))
- CODEGEN_CRITICAL_SECTION_NEW;
-
s1 = emit_load_s1(jd, iptr, REG_ATMP1);
assert(VAROP(iptr->s1)->type == TYPE_ADR);
M_ATST(s1);
emit_label_beq(cd, BRANCH_LABEL_1);
- codegen_addpatchref(cd, PATCHER_resolve_classref_to_flags, iptr->sx.s23.s3.c.ref, 0);
+ patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_flags, iptr->sx.s23.s3.c.ref, 0);
M_IMOV_IMM32(0, REG_ITMP2);
M_IAND_IMM(ACC_INTERFACE, REG_ITMP2);
if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
if (super == NULL) {
- codegen_addpatchref(cd, PATCHER_checkcast_interface, iptr->sx.s23.s3.c.ref, 0);
+ patcher_add_patch_ref(jd, PATCHER_checkcast_interface, iptr->sx.s23.s3.c.ref, 0);
} else {
M_ATST(s1);
emit_label_beq(cd, BRANCH_LABEL_3);
if (super == NULL) {
emit_label(cd, BRANCH_LABEL_2);
- codegen_addpatchref(cd, PATCHER_resolve_classref_to_vftbl, iptr->sx.s23.s3.c.ref, 0);
+ patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_vftbl, iptr->sx.s23.s3.c.ref, 0);
M_AMOV_IMM(0, REG_ATMP3);
} else {
M_AMOV_IMM(super->vftbl, REG_ATMP3);
M_ALD(REG_ATMP2, s1, OFFSET(java_object_t, vftbl));
- CODEGEN_CRITICAL_SECTION_START;
-
M_ILD(REG_ITMP3, REG_ATMP2, OFFSET(vftbl_t, baseval)); /* REG_ITMP3 == sub->vftbl->baseval */
M_ILD(REG_ITMP1, REG_ATMP3, OFFSET(vftbl_t, baseval));
M_ILD(REG_ITMP2, REG_ATMP3, OFFSET(vftbl_t, diffval));
- CODEGEN_CRITICAL_SECTION_END;
-
M_ISUB(REG_ITMP1, REG_ITMP3);
M_ICMP(REG_ITMP2, REG_ITMP3); /* XXX was CMPU */
s1 = emit_load_s1(jd, iptr, REG_ATMP2);
if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
- codegen_addpatchref(cd, PATCHER_resolve_classref_to_classinfo, iptr->sx.s23.s3.c.ref, 0);
+ patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo, iptr->sx.s23.s3.c.ref, 0);
M_AMOV_IMM(0, REG_ATMP1);
} else {
M_AMOV_IMM(iptr->sx.s23.s3.c.cls, REG_ATMP1);
/* a1 = arraydescriptor */
if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
- codegen_addpatchref(cd, PATCHER_resolve_classref_to_classinfo, iptr->sx.s23.s3.c.ref, 0);
+ patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo, iptr->sx.s23.s3.c.ref, 0);
M_AMOV_IMM(0, REG_ATMP1);
} else {
M_AMOV_IMM(iptr->sx.s23.s3.c.cls, REG_ATMP1);
} /* if (btpre->flags >= BBREACHED) */
} /* for each basic block */
- dseg_createlinenumbertable(cd);
-
/* generate stubs */
- emit_patcher_stubs(jd);
+ emit_patcher_traps(jd);
return true;
}
-
-/* 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_AMOV_IMM(m, REG_ATMP1);
- M_AMOV_IMM(asm_call_jit_compiler, REG_ATMP3);
- M_JMP(REG_ATMP3);
-}
-
-/* codegen_emit_stub_builtin ***************************************************
-
- Creates a stub routine which calls a builtin function.
-
-*******************************************************************************/
-
-void codegen_emit_stub_builtin(jitdata *jd, builtintable_entry *bte)
-{
- codeinfo *code;
- codegendata *cd;
- methoddesc *md;
- s4 i;
- s4 disp;
- s4 s1, s2;
-
- /* get required compiler data */
- code = jd->code;
- cd = jd->cd;
-
- /* set some variables */
- md = bte->md;
-
- /* calculate stack frame size */
- cd->stackframesize =
- sizeof(stackframeinfo) / SIZEOF_VOID_P +
- 4; /* 4 arguments or return value */
-
- /* create method header */
- (void) dseg_add_unique_address(cd, code); /* CodeinfoPointer */
- (void) dseg_add_unique_s4(cd, cd->stackframesize * 4); /* 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_AADD_IMM(-(cd->stackframesize*4), REG_SP);
-
-#if defined(ENABLE_GC_CACAO)
- /* Save callee saved integer registers in stackframeinfo (GC may
- need to recover them during a collection). */
-
- disp = cd->stackframesize * 4 - sizeof(stackframeinfo) +
- OFFSET(stackframeinfo, adrregs);
-
- for (i = 0; i < ADR_SAV_CNT; i++)
- M_AST(abi_registers_address_saved[i], REG_SP, disp + i * 4);
-#endif
-
- /* create dynamic stack info */
-
- M_AMOV(REG_SP, REG_ATMP1);
- M_AADD_IMM(cd->stackframesize * 4, REG_ATMP1);
- M_AST(REG_ATMP1, REG_SP, 0 * 4); /* datasp */
-
- M_AMOV_IMM(0, REG_ATMP1); /* we need pv patched in */
- dseg_adddata(cd); /* this does the trick */
- M_AST(REG_ATMP1, REG_SP, 1 * 4); /* pv */
-
- M_AMOV(REG_SP, REG_ATMP1);
- M_AADD_IMM(cd->stackframesize * 4 + SIZEOF_VOID_P, REG_ATMP1);
- M_AST(REG_ATMP1, REG_SP, 2 * 4); /* sp */
-
- M_ALD(REG_ATMP3, REG_SP, cd->stackframesize * 4);
- M_AST(REG_ATMP3, REG_SP, 3 * 4); /* ra */
-
- M_JSR_IMM(codegen_stub_builtin_enter);
-
- /* copy arguments into new stackframe */
-
- for (i = 0; i < md->paramcount; i++) {
- if (!md->params[i].inmemory) {
- log_text("No integer argument registers available!");
- assert(0);
-
- } else { /* float/double in memory can be copied like int/longs */
- s1 = md->params[i].regoff + cd->stackframesize * 4 + 4;
- s2 = md->params[i].regoff;
-
- M_ILD(REG_ITMP1, REG_SP, s1);
- M_IST(REG_ITMP1, REG_SP, s2);
- if (IS_2_WORD_TYPE(md->paramtypes[i].type)) {
- M_ILD(REG_ITMP1, REG_SP, s1 + 4);
- M_IST(REG_ITMP1, REG_SP, s2 + 4);
- }
-
- }
- }
-
- /* call the builtin function */
-
- M_AMOV_IMM(bte->fp, REG_ATMP3);
- M_JSR(REG_ATMP3);
-
- /* save return value */
- switch (md->returntype.type) {
- case TYPE_VOID: break;
-
- /* natives return float arguments in %d0, %d1, cacao expects them in %fp0 */
- case TYPE_DBL:
- case TYPE_LNG:
- M_IST(REG_D1, REG_SP, 2 * 4);
- /* fall through */
-
- case TYPE_FLT:
- case TYPE_INT:
- case TYPE_ADR:
- M_IST(REG_D0, REG_SP, 1 * 4);
- break;
-
- default: assert(0);
- }
-
- /* remove native stackframe info */
-
- M_AMOV(REG_SP, REG_ATMP1);
- M_AADD_IMM(cd->stackframesize * 4, REG_ATMP1);
- M_AST(REG_ATMP1, REG_SP, 0 * 4);
-
- M_JSR_IMM(codegen_stub_builtin_exit);
-
- /* restore return value */
- switch (md->returntype.type) {
- case TYPE_VOID: break;
-
- case TYPE_DBL:
- case TYPE_LNG:
- M_ILD(REG_D1, REG_SP, 2 * 4);
- /* fall through */
-
- case TYPE_FLT:
- case TYPE_INT:
- case TYPE_ADR:
- M_ILD(REG_D0, REG_SP, 1 * 4);
- break;
-
- default: assert(0);
- }
-
-#if defined(ENABLE_GC_CACAO)
- /* Restore callee saved integer registers from stackframeinfo (GC
- might have modified them during a collection). */
-
- disp = cd->stackframesize * 4 - sizeof(stackframeinfo) +
- OFFSET(stackframeinfo, adrregs);
-
- for (i = 0; i < ADR_SAV_CNT; i++)
- M_ALD(abi_registers_address_saved[i], REG_SP, disp + i * 4);
-#endif
-
- /* remove stackframe */
- M_AADD_IMM(cd->stackframesize * 4, REG_SP);
- M_RET;
-}
-
-
-
-
/* codegen_emit_stub_native ****************************************************
Emits a stub routine which calls a native method.
*******************************************************************************/
-void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
+void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f, int skipparams)
{
methodinfo *m;
codeinfo *code;
codegendata *cd;
registerdata *rd;
methoddesc *md;
- s4 nativeparams, i, j, t, s1, s2;
+ s4 i, j, t, s1, s2;
/* get required compiler data */
rd = jd->rd;
md = m->parseddesc;
- nativeparams = (m->flags & ACC_STATIC) ? 2 : 1;
/* calc stackframe size */
- cd->stackframesize = sizeof(stackframeinfo) / SIZEOF_VOID_P +
- sizeof(localref_table) / SIZEOF_VOID_P +
- nmd->memuse +
- 1 + /* functionptr */
- 4; /* args for codegen_start_native_call */
+ cd->stackframesize =
+ sizeof(stackframeinfo_t) / SIZEOF_VOID_P +
+ sizeof(localref_table) / SIZEOF_VOID_P +
+ nmd->memuse +
+ 1 + /* functionptr */
+ 4; /* args for codegen_start_native_call */
/* create method header */
(void) dseg_add_unique_address(cd, code); /* CodeinfoPointer */
- (void) dseg_add_unique_s4(cd, cd->stackframesize * 4); /* FrameSize */
- (void) dseg_add_unique_s4(cd, 0); /* IsSync */
+ (void) dseg_add_unique_s4(cd, cd->stackframesize * 8); /* FrameSize */
(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 */
-
- /* print call trace */
-#if !defined(NDEBUG)
- if (JITDATA_HAS_FLAG_VERBOSECALL(jd)) {
- emit_verbosecall_enter(jd);
- }
-#endif
/* generate code */
- M_AADD_IMM(-(cd->stackframesize*4), REG_SP);
-
- /* get function address (this must happen before the stackframeinfo) */
-#if !defined(WITH_STATIC_CLASSPATH)
- if (f == NULL) {
- codegen_addpatchref(cd, PATCHER_resolve_native_function, m, 0);
- }
-#endif
- M_AMOV_IMM(f, REG_ATMP2); /* do not move this line, the patcher is needed */
-
- M_AST(REG_ATMP2, REG_SP, 4 * 4);
+ M_AADD_IMM(-(cd->stackframesize*8), REG_SP);
/* put arguments for codegen_start_native_call onto stack */
/* void codegen_start_native_call(u1 *datasp, u1 *pv, u1 *sp, u1 *ra) */
M_AMOV(REG_SP, REG_ATMP1);
- M_AADD_IMM(cd->stackframesize * 4, REG_ATMP1);
-
- M_ALD(REG_ATMP3, REG_ATMP1, 0 * 4);
- M_AST(REG_ATMP3, REG_SP, 3 * 4); /* ra */
-
- M_AST(REG_ATMP1, REG_SP, 0 * 4); /* datasp */
-
- M_AADD_IMM(1 * 4 , REG_ATMP1);
- M_AST(REG_ATMP1, REG_SP, 2 * 4); /* sp */
+ M_AST(REG_ATMP1, REG_SP, 0 * 4); /* currentsp */
M_AMOV_IMM(0, REG_ATMP2); /* 0 needs to patched */
dseg_adddata(cd); /* this patches it */
M_JSR_IMM(codegen_start_native_call);
- /* load function pointer */
- M_ALD(REG_ATMP2, REG_SP, 4 * 4);
+ /* remember class argument */
+ if (m->flags & ACC_STATIC)
+ M_INT2ADRMOVE(REG_RESULT, REG_ATMP3);
/* copy arguments into stackframe */
- for (i = md->paramcount -1, j = i + nativeparams; i >= 0; --i, --j) {
+ for (i = md->paramcount -1, j = i + skipparams; i >= 0; --i, --j) {
t = md->paramtypes[i].type;
/* all arguments via stack */
assert(md->params[i].inmemory);
- s1 = md->params[i].regoff + cd->stackframesize * 4 + 4;
+ s1 = md->params[i].regoff + cd->stackframesize * 8 + 4;
s2 = nmd->params[j].regoff;
/* simply copy argument stack */
}
}
- /* for static function class as second arg */
- if (m->flags & ACC_STATIC) {
- M_AMOV_IMM(m->class, REG_ATMP1);
- M_AST(REG_ATMP1, REG_SP, 1 * 4);
+ /* builtins are not invoked like natives, environemtn and clazz are only needed for natives */
+ if (m->flags & ACC_NATIVE) {
+ /* for static function class as second arg */
+ if (m->flags & ACC_STATIC)
+ M_AST(REG_ATMP3, REG_SP, 1 * 4);
+
+ /* env ist first argument */
+ M_AMOV_IMM(VM_get_jnienv(), REG_ATMP1);
+ M_AST(REG_ATMP1, REG_SP, 0 * 4);
}
- /* env ist first argument */
- M_AMOV_IMM(_Jv_env, REG_ATMP1);
- M_AST(REG_ATMP1, REG_SP, 0 * 4);
/* call the native function */
+ M_AMOV_IMM(f, REG_ATMP2);
M_JSR(REG_ATMP2);
/* save return value */
/* natives return float arguments in %d0, %d1, cacao expects them in %fp0 */
case TYPE_DBL:
case TYPE_LNG:
- M_IST(REG_D1, REG_SP, 2 * 4);
+ M_IST(REG_D1, REG_SP, 2 * 8);
/* fall through */
case TYPE_FLT:
case TYPE_INT:
case TYPE_ADR:
- M_IST(REG_D0, REG_SP, 1 * 4);
+ M_IST(REG_D0, REG_SP, 2 * 8); /* XXX can this be correct ? */
break;
default: assert(0);
}
-
- /* print call trace */
-#if ! defined(NDEBUG)
- if (JITDATA_HAS_FLAG_VERBOSECALL(jd)) {
- emit_verbosecall_exit(jd);
- }
-#endif
+
/* remove native stackframe info */
/* therefore we call: java_objectheader *codegen_finish_native_call(u1 *datasp) */
- M_AMOV(REG_SP, REG_ATMP3);
- M_AADD_IMM(cd->stackframesize * 4, REG_ATMP3);
- M_AST(REG_ATMP3, REG_SP, 0 * 4); /* datasp */
+ M_AMOV(REG_SP, REG_ATMP1);
+ M_AST(REG_ATMP1, REG_SP, 0 * 4); /* currentsp */
+
+ M_AMOV_IMM(0, REG_ATMP2); /* 0 needs to patched */
+ dseg_adddata(cd); /* this patches it */
+
+ M_AST(REG_ATMP2, REG_SP, 1 * 4); /* pv */
+
M_JSR_IMM(codegen_finish_native_call);
M_INT2ADRMOVE(REG_RESULT, REG_ATMP1);
case TYPE_VOID: break;
case TYPE_DBL:
- case TYPE_LNG:
- M_ILD(REG_D1, REG_SP, 2 * 4);
+ case TYPE_LNG: M_ILD(REG_D1, REG_SP, 2 * 8);
/* fall through */
case TYPE_FLT:
case TYPE_INT:
case TYPE_ADR:
- M_ILD(REG_D0, REG_SP, 1 * 4);
+ M_ILD(REG_D0, REG_SP, 2 * 8); /* XXX */
break;
default: assert(0);
* as cacao jit code expects them there */
switch (md->returntype.type) {
case TYPE_FLT:
- M_FLD(REG_D0, REG_SP, 1 * 4);
+ M_FLD(REG_D0, REG_SP, 2 * 8);
break;
case TYPE_DBL:
- M_DLD(REG_D0, REG_SP, 1 * 4);
+ M_DLD(REG_D0, REG_SP, 2 * 8); /* XXX */
break;
}
#endif
/* restore saved registers */
- M_AADD_IMM(cd->stackframesize*4, REG_SP);
+ M_AADD_IMM(cd->stackframesize*8, REG_SP);
/* check for exception */
M_ATST(REG_ATMP1);
M_BNE(2);
/* should never be reached from within jit code*/
M_JSR_IMM(0);
-
- /* generate patcher stub call code */
- emit_patcher_stubs(jd);
}