Skip to content

Commit

Permalink
fix: search exception handler splitter block by offset if jump source…
Browse files Browse the repository at this point in the history
… unknown (#406)
  • Loading branch information
skylot committed Dec 25, 2018
1 parent fbf750f commit e9591ef
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,13 @@ private static void setupConnections(MethodNode mth, Map<Integer, BlockNode> blo
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) {
Expand All @@ -237,7 +238,7 @@ private static void connectExceptionHandlers(BlockNode block, InsnNode insn) {
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)) {
Expand All @@ -251,6 +252,16 @@ private static void connectExceptionHandlers(BlockNode block, InsnNode insn) {
}
}

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) {
Expand Down

0 comments on commit e9591ef

Please sign in to comment.