Commit e9591efd authored by Skylot's avatar Skylot

fix: search exception handler splitter block by offset if jump source unknown (#406)

parent fbf750f5
......@@ -223,12 +223,13 @@ public class BlockSplitter extends AbstractVisitor {
BlockNode thisBlock = getBlock(jump.getDest(), blocksMap);
connect(srcBlock, thisBlock);
}
connectExceptionHandlers(block, insn);
connectExceptionHandlers(block, insn, blocksMap);
}
}
}
private static void connectExceptionHandlers(BlockNode block, InsnNode insn) {
private static void connectExceptionHandlers(BlockNode block, InsnNode insn,
Map<Integer, BlockNode> blocksMap) {
CatchAttr catches = insn.get(AType.CATCH_BLOCK);
SplitterBlockAttr spl = block.get(AType.SPLITTER_BLOCK);
if (catches == null || spl == null) {
......@@ -237,7 +238,7 @@ public class BlockSplitter extends AbstractVisitor {
BlockNode splitterBlock = spl.getBlock();
boolean tryEnd = insn.contains(AFlag.TRY_LEAVE);
for (ExceptionHandler h : catches.getTryBlock().getHandlers()) {
BlockNode handlerBlock = h.getHandlerBlock();
BlockNode handlerBlock = initHandlerBlock(h, blocksMap);
// skip self loop in handler
if (splitterBlock != handlerBlock) {
if (!handlerBlock.contains(AType.SPLITTER_BLOCK)) {
......@@ -251,6 +252,16 @@ public class BlockSplitter extends AbstractVisitor {
}
}
private static BlockNode initHandlerBlock(ExceptionHandler excHandler, Map<Integer, BlockNode> blocksMap) {
BlockNode handlerBlock = excHandler.getHandlerBlock();
if (handlerBlock != null) {
return handlerBlock;
}
BlockNode blockByOffset = getBlock(excHandler.getHandleOffset(), blocksMap);
excHandler.setHandlerBlock(blockByOffset);
return blockByOffset;
}
private static boolean isSplitByJump(InsnNode prevInsn, InsnNode currentInsn) {
List<JumpInfo> pJumps = prevInsn.getAll(AType.JUMP);
for (JumpInfo jump : pJumps) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment