}
}
}
if (i instanceof IfInstruction) {
IfInstruction ii = (IfInstruction) i;
InstructionHandle target = ii.getTarget();
InstructionHandle next = head.getNext();
if (target.equals(next)) {
int consumed = ii.consumeStack(methodGen.getConstantPool());
if (consumed != 1 && consumed != 2) {
throw new IllegalStateException();
}
head.swapInstruction(consumed == 1 ? new POP() : new POP2());
}
}
if (i instanceof IFNULL || i instanceof IFNONNULL) {
IfInstruction ii = (IfInstruction) i;
InstructionHandle target = ii.getTarget();
InstructionHandle next1 = head.getNext(); // ICONST
if (next1 == null) {
break;
}
if (next1.getInstruction() instanceof ICONST) {
InstructionHandle next2 = next1.getNext(); // GOTO
if (next2 == null) {
break;
}
InstructionHandle next3 = next2.getNext(); // ICONST
if (next3== null) {
break;
}
InstructionHandle next4 = next3.getNext();
if (next4 == null) {
break;
}
if (target.equals(next3) && next2.getInstruction() instanceof GOTO
&& next3.getInstruction() instanceof ICONST && next1.getTargeters().length == 0
&& next2.getTargeters().length == 0 && next3.getTargeters().length == 1
&& next4.getTargeters().length == 1) {
int c1 = ((ICONST) next1.getInstruction()).getValue().intValue();
GOTO g = (GOTO) next2.getInstruction();
int c2 = ((ICONST) next3.getInstruction()).getValue().intValue();
if (g.getTarget().equals(next4) && (c1 == 1 && c2 == 0 || c1 == 0 && c2 == 1)) {
boolean nullIsTrue = i instanceof IFNULL && c2 == 1 || i instanceof IFNONNULL && c2 == 0;
if (nullIsTrue) {
// System.out.println("Found NULL2Z instruction");
head.swapInstruction(new NULL2Z());
} else {
// System.out.println("Found NONNULL2Z instruction");
head.swapInstruction(new NONNULL2Z());
}
next3.removeAllTargeters();
next4.removeAllTargeters();
next1.swapInstruction(new NOP());
next2.swapInstruction(new NOP());
next3.swapInstruction(new NOP());
}
}
}
}
if (i instanceof ACONST_NULL) {
InstructionHandle next = head.getNext();
assert next != null;
InstructionHandle next2 = next.getNext();
if (next2 != null && next.getInstruction() instanceof ALOAD) {
Instruction check = next2.getInstruction();
if (check instanceof IF_ACMPNE || check instanceof IF_ACMPEQ) {
// need to update
head.swapInstruction(new NOP());
IfInstruction ifTest = (IfInstruction) check;
if (check instanceof IF_ACMPNE) {
next2.swapInstruction(new IFNONNULL(ifTest.getTarget()));
} else {
next2.swapInstruction(new IFNULL(ifTest.getTarget()));
}
}
}
}
head = head.getNext();