This bugfix is related to the one in commit a6cc64dea7ea078e173fe0bea89ad54e54038826 "vm: do not return jboolean from VM natives.". It implements the other approach described in the changelog of that commit. We must put conversion instructions after native invocations because JNI methods do not perform the conversion.
Therefore it is now safe to use jbyte, jboolean, jchar and jshort as VM native implementation return type. Signed-off-by: Tomek Grabiec <tgrab...@gmail.com> --- arch/x86/insn-selector.brg | 32 ++++++++++++++++++++++++++++++++ 1 files changed, 32 insertions(+), 0 deletions(-) diff --git a/arch/x86/insn-selector.brg b/arch/x86/insn-selector.brg index 443fa2e..3b1f102 100644 --- a/arch/x86/insn-selector.brg +++ b/arch/x86/insn-selector.brg @@ -3090,6 +3090,38 @@ void save_invoke_result(struct basic_block *s, struct tree_node *tree, select_insn(s, tree, reg_reg_insn(INSN_MOV_REG_REG, edx, tmp->tmp_high)); break; case J_INT: + eax = get_fixed_var(s->b_parent, MACH_REG_xAX); + + if (vm_method_is_native(method)) { + /* + * Native methods (especially JNI methods) might + * not cast return value to int for byte, boolean, + * char and short so we must do this here. + */ + switch (method->return_type.vm_type) { + case J_BYTE: + /* Fall through */ + case J_BOOLEAN: + select_insn(s, tree, reg_reg_insn(INSN_MOVSX_8_REG_REG, eax, tmp->tmp_low)); + break; + case J_CHAR: + select_insn(s, tree, reg_reg_insn(INSN_MOVZX_16_REG_REG, eax, tmp->tmp_low)); + break; + case J_SHORT: + select_insn(s, tree, reg_reg_insn(INSN_MOVSX_16_REG_REG, eax, tmp->tmp_low)); + break; + case J_INT: + select_insn(s, tree, reg_reg_insn(INSN_MOV_REG_REG, eax, tmp->tmp_low)); + break; + default: + error("unexpected return type"); + } + + break; + } + + select_insn(s, tree, reg_reg_insn(INSN_MOV_REG_REG, eax, tmp->tmp_low)); + break; case J_REFERENCE: eax = get_fixed_var(s->b_parent, MACH_REG_xAX); select_insn(s, tree, reg_reg_insn(INSN_MOV_REG_REG, eax, tmp->tmp_low)); -- 1.6.0.4 ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel