if (program.basicBlockCount() == 0) {
return;
}
InstructionTransitionExtractor transitionExtractor = new InstructionTransitionExtractor();
boolean[] reachable = new boolean[program.basicBlockCount()];
IntegerStack stack = new IntegerStack(program.basicBlockCount());
stack.push(0);
while (!stack.isEmpty()) {
int i = stack.pop();
if (reachable[i]) {
continue;
}
reachable[i] = true;
BasicBlock block = program.basicBlockAt(i);
block.getLastInstruction().acceptVisitor(transitionExtractor);
for (BasicBlock successor : transitionExtractor.getTargets()) {
if (!reachable[successor.getIndex()]) {
stack.push(successor.getIndex());
}
}
for (TryCatchBlock tryCatch : block.getTryCatchBlocks()) {
stack.push(tryCatch.getHandler().getIndex());
}
}
for (int i = 0; i < reachable.length; ++i) {
if (!reachable[i]) {
program.deleteBasicBlock(i);