ih != null;
ih = ih.getNext()) {
Instruction inst = ih.getInstruction();
if (inst instanceof IfInstruction) {
IfInstruction oldIfInst = (IfInstruction)inst;
BranchHandle oldIfHandle = (BranchHandle)ih;
InstructionHandle target = oldIfInst.getTarget();
int relativeTargetOffset = target.getPosition()
- oldIfHandle.getPosition();
// Consider the worst case scenario in which the conditional
// branch and its target are separated by all the instructions
// in the method that might increase in size. If that results
// in a relative offset that cannot be represented as a 32-bit
// signed quantity, rewrite the instruction as described above.
if ((relativeTargetOffset - maxOffsetChange
< MIN_BRANCH_TARGET_OFFSET)
|| (relativeTargetOffset + maxOffsetChange
> MAX_BRANCH_TARGET_OFFSET)) {
// Invert the logic of the IF instruction, and append
// that to the InstructionList following the original IF
// instruction
InstructionHandle nextHandle = oldIfHandle.getNext();
IfInstruction invertedIfInst = oldIfInst.negate();
BranchHandle invertedIfHandle = il.append(oldIfHandle,
invertedIfInst);
// Append an unconditional branch to the target of the
// original IF instruction after the new IF instruction