#91 Bytecode instructions not preserved

decompiler (49)
Trevor Harmon

After JODE completes its analysis, all of the bytecode instructions it has read from the class files are discarded. This is a problem for building tools on top of JODE that need the bytecode data, such as WCET analyzers.

The attached patch fixes that problem, based on advice from Jochen. See: http://sourceforge.net/forum/message.php?msg_id=4050121

The patch simply modifies StructuredBlock.java so that it holds a list of bytecode instructions corresponding to the block. It also modifies Opcodes.java so that when blocks are created, a handle to the bytecode instruction is passed to it. This required changing several subclasses of StructuredBlock to take in an instruction parameter. Finally, the StrucutredBlock.moveDefinitions function was implemented to copy the instructions so that they are preserved during transformations.

(The moveDefinitions function should probably be renamed copyBytecode or something so that it better reflects the purpose of the function. But I left that alone for now.)


  • Trevor Harmon
    Trevor Harmon

    Logged In: YES
    Originator: YES

    I've done some more testing on this, and it works for everything except loop conditions. In the original patch, the moveDefinitions method copies bytecode instructions from "from.getSubBlocks()[0]", but if "from" is a ConditionalBlock, apparently it should instead copy from "from" directly. (I'm not sure why; perhaps there is a bug in the moveDefinitions calls in FlowBlock?)

    In any case, here's a revised implementation of moveDefinitions that works for ConditionalBlocks and all other types of StructuredBlocks:

    // Special-case handling of ConditionalBlocks (bug in FlowBlock?)
    if ( !(from instanceof ConditionalBlock) )
    from = from.getSubBlocks()[0];

    // Copy all instructions from "from" to the beginning of this block's instruction list
    bytecodeInstructions.addAll(0, from.bytecodeInstructions);