Hi, The following java code :
public static void aaa() { int i = 0; while (i < 5) { i = i+1; } assertEquals(5, i); } is compiled into the following bytecode : public static void aaa(); Code: 0: iconst_0 1: istore_0 2: goto 8 5: iinc 0, 1 8: iload_0 9: iconst_5 10: if_icmplt 5 13: iconst_5 14: iload_0 15: invokestatic #16; //Method assertEquals:(II)V 18: return We can see 4 basic blocks: 0..5 (first inclusive, second exclusive) 8..13 5..8 13..19 Jato generates the following HIR: Control Flow Graph: #: Range 0xa448c10 0..5 0xa448d80 5..8 0xa448de8 13..19 0xa44ac30 8..13 .. so apparently we get the blocks right. The order is strange but ok. (Annotated by A.H.) High-Level Intermediate Representation: [bb 0xa448c10]: STORE: -- initialize i store_dest: [local int 0] store_src: [value int 0x0] GOTO: goto_target: [bb 0xa44ac30] -- do the comparison [bb 0xa448d80]: STORE: -- increase i store_dest: [local int 0] store_src: BINOP: vm_type: [int] binary_operator: [add] binary_left: [local int 0] binary_right: [value int 0x1] ///HERE HERE HERE HERE HERE/// As you can see, no branching, no nothing. We fall through to the next block which calls assertEquals, instead of properly branching to the block which does the comparison. Had the two blocks below been swapped, we would not need branching. [bb 0xa448de8]: EXPRESSION: expression: INVOKE: target_method: [0xa422a10 'jamvm/TestCase.assertEquals(II)V'] args_list: ARGS_LIST: args_left: ARG: arg_expression: [local int 0] args_right: ARG: arg_expression: [value int 0x5] VOID_RETURN [bb 0xa44ac30]: IF: if_conditional: -- test whether to continue the loop BINOP: vm_type: [int] binary_operator: [lt] binary_left: [local int 0] binary_right: [value int 0x5] if_true: [bb 0xa448d80] -- continue looping. Conclusion: either basic blocks are not ordered correctly, or we need a few more GOTOs. Help appreciated. -- Greetings, A.H. ------------------------------------------------------------------------------ Stay on top of everything new and different, both inside and around Java (TM) technology - register by April 22, and save $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. 300 plus technical and hands-on sessions. Register today. Use priority code J9JMT32. http://p.sf.net/sfu/p _______________________________________________ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel