void (ControlFlowGraph graph, BasicBlock oldBlock, BasicBlock newBlock) { List<BasicBlock> blocks = new ArrayList<>(); blocks.addAll(oldBlock.getPredecessors()); blocks.addAll(oldBlock.getPredecessorExceptions()); // replace predecessors for (BasicBlock predecessor : blocks) { predecessor.replaceSuccessor(oldBlock, newBlock); } // copy exception edges and extend protected ranges for (BasicBlock hd : oldBlock.getSuccessorExceptions()) { newBlock.addSuccessorException(hd); ExceptionRangeCFG range = graph.getExceptionRange(hd, oldBlock); range.getProtectedRange().add(newBlock); } // replace handler for (ExceptionRangeCFG range : graph.getExceptions()) { if (range.getHandler() == oldBlock) { range.setHandler(newBlock); } } newBlock.addSuccessor(oldBlock); graph.getBlocks().addWithKey(newBlock, newBlock.id); if (graph.getFirst() == oldBlock) { graph.setFirst(newBlock); } }