Пример #1
0
  private BlockNode processMonitorEnter(
      IRegion curRegion, BlockNode block, InsnNode insn, RegionStack stack) {
    SynchronizedRegion synchRegion = new SynchronizedRegion(curRegion, insn);
    synchRegion.getSubBlocks().add(block);
    curRegion.getSubBlocks().add(synchRegion);

    Set<BlockNode> exits = new HashSet<BlockNode>();
    cacheSet.clear();
    traverseMonitorExits(synchRegion, insn.getArg(0), block, exits, cacheSet);

    for (InsnNode exitInsn : synchRegion.getExitInsns()) {
      InstructionRemover.unbindInsn(mth, exitInsn);
    }

    BlockNode body = getNextBlock(block);
    if (body == null) {
      ErrorsCounter.methodError(mth, "Unexpected end of synchronized block");
      return null;
    }
    BlockNode exit;
    if (exits.size() == 1) {
      exit = getNextBlock(exits.iterator().next());
    } else {
      cacheSet.clear();
      exit = traverseMonitorExitsCross(body, exits, cacheSet);
    }

    stack.push(synchRegion);
    stack.addExit(exit);
    synchRegion.getSubBlocks().add(makeRegion(body, stack));
    stack.pop();
    return exit;
  }
Пример #2
0
 public void processTryCatchBlocks(MethodNode mth) {
   Set<TryCatchBlock> tcs = new HashSet<TryCatchBlock>();
   for (ExceptionHandler handler : mth.getExceptionHandlers()) {
     tcs.add(handler.getTryBlock());
   }
   for (TryCatchBlock tc : tcs) {
     List<BlockNode> blocks = new ArrayList<BlockNode>(tc.getHandlersCount());
     Set<BlockNode> splitters = new HashSet<BlockNode>();
     for (ExceptionHandler handler : tc.getHandlers()) {
       BlockNode handlerBlock = handler.getHandlerBlock();
       if (handlerBlock != null) {
         blocks.add(handlerBlock);
         splitters.addAll(handlerBlock.getPredecessors());
       } else {
         LOG.debug(ErrorsCounter.formatErrorMsg(mth, "No exception handler block: " + handler));
       }
     }
     Set<BlockNode> exits = new HashSet<BlockNode>();
     for (BlockNode splitter : splitters) {
       for (BlockNode handler : blocks) {
         List<BlockNode> s = splitter.getSuccessors();
         if (s.isEmpty()) {
           LOG.debug(ErrorsCounter.formatErrorMsg(mth, "No successors for splitter: " + splitter));
           continue;
         }
         BlockNode ss = s.get(0);
         BlockNode cross = BlockUtils.getPathCross(mth, ss, handler);
         if (cross != null && cross != ss && cross != handler) {
           exits.add(cross);
         }
       }
     }
     for (ExceptionHandler handler : tc.getHandlers()) {
       processExcHandler(handler, exits);
     }
   }
 }