Class BlockUtils


  • public class BlockUtils
    extends java.lang.Object
    • Method Detail

      • getBlockByOffset

        public static BlockNode getBlockByOffset​(int offset,
                                                 java.lang.Iterable<BlockNode> casesBlocks)
      • isExceptionHandlerPath

        public static boolean isExceptionHandlerPath​(BlockNode b)
      • cleanBitSet

        public static void cleanBitSet​(MethodNode mth,
                                       java.util.BitSet bs)
        Remove exception handlers from block nodes bitset
      • isFollowBackEdge

        public static boolean isFollowBackEdge​(BlockNode block)
      • blockContains

        public static boolean blockContains​(BlockNode block,
                                            InsnNode insn)
        Check if instruction contains in block (use == for comparison, not equals)
      • checkFirstInsn

        public static boolean checkFirstInsn​(IBlock block,
                                             java.util.function.Predicate<InsnNode> predicate)
      • checkLastInsnType

        public static boolean checkLastInsnType​(IBlock block,
                                                InsnType expectedType)
      • getFirstSourceLine

        public static int getFirstSourceLine​(IBlock block)
      • getFirstInsn

        @Nullable
        public static @Nullable InsnNode getFirstInsn​(@Nullable
                                                      @Nullable IBlock block)
      • getLastInsn

        @Nullable
        public static @Nullable InsnNode getLastInsn​(@Nullable
                                                     @Nullable IBlock block)
      • isExitBlock

        public static boolean isExitBlock​(BlockNode block)
      • containsExitInsn

        public static boolean containsExitInsn​(IBlock block)
      • newBlocksBitSet

        public static java.util.BitSet newBlocksBitSet​(MethodNode mth)
      • copyBlocksBitSet

        public static java.util.BitSet copyBlocksBitSet​(MethodNode mth,
                                                        java.util.BitSet bitSet)
      • blocksToBitSet

        public static java.util.BitSet blocksToBitSet​(MethodNode mth,
                                                      java.util.Collection<BlockNode> blocks)
      • bitSetToOneBlock

        @Nullable
        public static @Nullable BlockNode bitSetToOneBlock​(MethodNode mth,
                                                           java.util.BitSet bs)
      • bitSetToBlocks

        public static java.util.List<BlockNode> bitSetToBlocks​(MethodNode mth,
                                                               java.util.BitSet bs)
      • forEachBlockFromBitSet

        public static void forEachBlockFromBitSet​(MethodNode mth,
                                                  java.util.BitSet bs,
                                                  java.util.function.Consumer<BlockNode> consumer)
      • getNextBlock

        @Nullable
        public static @Nullable BlockNode getNextBlock​(BlockNode block)
        Return first successor which not exception handler and not follow loop back edge
      • getPrevBlock

        @Nullable
        public static @Nullable BlockNode getPrevBlock​(BlockNode block)
      • getNextBlockToPath

        public static BlockNode getNextBlockToPath​(BlockNode block,
                                                   BlockNode pathEnd)
        Return successor on path to 'pathEnd' block
      • getPrevBlockOnPath

        @Nullable
        public static @Nullable BlockNode getPrevBlockOnPath​(MethodNode mth,
                                                             BlockNode block,
                                                             BlockNode pathStart)
        Return predecessor on path from 'pathStart' block
      • visitBlocksOnPath

        public static boolean visitBlocksOnPath​(MethodNode mth,
                                                BlockNode start,
                                                BlockNode end,
                                                java.util.function.Consumer<BlockNode> visitor)
        Visit blocks on any path from start to end. Only one path will be visited!
      • collectAllSuccessors

        public static java.util.List<BlockNode> collectAllSuccessors​(MethodNode mth,
                                                                     BlockNode startBlock,
                                                                     boolean clean)
      • visitDFS

        public static void visitDFS​(MethodNode mth,
                                    java.util.function.Consumer<BlockNode> visitor)
      • visitReverseDFS

        public static void visitReverseDFS​(MethodNode mth,
                                           java.util.function.Consumer<BlockNode> visitor)
      • visitPredecessorsUntil

        public static void visitPredecessorsUntil​(MethodNode mth,
                                                  BlockNode start,
                                                  java.util.function.Predicate<BlockNode> visitor)
      • getAllPathsBlocks

        public static java.util.Set<BlockNode> getAllPathsBlocks​(BlockNode start,
                                                                 BlockNode end)
        Collect blocks from all possible execution paths from 'start' to 'end'
      • atLeastOnePathExists

        public static boolean atLeastOnePathExists​(java.util.Collection<BlockNode> startBlocks,
                                                   BlockNode end)
        Search at least one path from startBlocks to end
      • isAllPathExists

        public static boolean isAllPathExists​(java.util.Collection<BlockNode> startBlocks,
                                              BlockNode end)
        Check if exist path from every startBlocks to end
      • isAnyPathExists

        public static boolean isAnyPathExists​(BlockNode start,
                                              BlockNode end)
      • getBottomBlock

        @Nullable
        public static @Nullable BlockNode getBottomBlock​(java.util.List<BlockNode> blocks)
        Search last block in control flow graph from input set.
      • isOnlyOnePathExists

        public static boolean isOnlyOnePathExists​(BlockNode start,
                                                  BlockNode end)
      • traverseWhileDominates

        public static BlockNode traverseWhileDominates​(BlockNode dom,
                                                       BlockNode start)
        Search for first node which not dominated by dom, starting from start
      • getCommonDominator

        @Nullable
        public static @Nullable BlockNode getCommonDominator​(MethodNode mth,
                                                             java.util.List<BlockNode> blocks)
        Search the lowest common ancestor in dominator tree for input set.
      • getPathCross

        @Nullable
        public static @Nullable BlockNode getPathCross​(MethodNode mth,
                                                       java.util.Collection<BlockNode> blocks)
        Return common cross block for input set.
        Returns:
        could be one of the giving blocks. null if cross is a method exit block.
      • collectBlocksDominatedBy

        public static java.util.List<BlockNode> collectBlocksDominatedBy​(MethodNode mth,
                                                                         BlockNode dominator,
                                                                         BlockNode start)
        Collect all block dominated by 'dominator', starting from 'start'
      • collectBlocksDominatedByWithExcHandlers

        public static java.util.Set<BlockNode> collectBlocksDominatedByWithExcHandlers​(MethodNode mth,
                                                                                       BlockNode dominator,
                                                                                       BlockNode start)
        Collect all block dominated by 'dominator', starting from 'start', including exception handlers
      • visitSinglePath

        public static void visitSinglePath​(BlockNode startBlock,
                                           java.util.function.Consumer<BlockNode> visitor)
        Visit blocks on path without branching or merging paths.
      • getNextSinglePathBlock

        @Nullable
        public static @Nullable BlockNode getNextSinglePathBlock​(BlockNode block)
      • buildSimplePath

        public static java.util.List<BlockNode> buildSimplePath​(BlockNode block)
      • skipPredSyntheticPaths

        public static void skipPredSyntheticPaths​(BlockNode block)
        Set 'SKIP' flag for all synthetic predecessors from start block.
      • followEmptyPath

        public static BlockNode followEmptyPath​(BlockNode start)
        Follow empty blocks and return end of path block (first not empty). Return start block if no such path.
      • visitBlocksOnEmptyPath

        public static void visitBlocksOnEmptyPath​(BlockNode start,
                                                  java.util.function.Consumer<BlockNode> visitor)
      • isEmptySimplePath

        public static boolean isEmptySimplePath​(BlockNode start,
                                                BlockNode end)
        Return true if on path from start to end no instructions and no branches.
      • skipSyntheticPredecessor

        public static BlockNode skipSyntheticPredecessor​(BlockNode block)
        Return predecessor of synthetic block or same block otherwise.
      • isAllBlocksEmpty

        public static boolean isAllBlocksEmpty​(java.util.List<BlockNode> blocks)
      • collectAllInsns

        public static java.util.List<InsnNode> collectAllInsns​(java.util.List<BlockNode> blocks)
      • collectInsnsWithLimit

        public static java.util.List<InsnNode> collectInsnsWithLimit​(java.util.List<BlockNode> blocks,
                                                                     int limit)
        Return limited number of instructions from method. Return empty list if method contains more than limit.
      • getOnlyOneInsnFromMth

        @Nullable
        public static @Nullable InsnNode getOnlyOneInsnFromMth​(MethodNode mth)
        Return insn if it is only one instruction in this method. Return null otherwise.
      • replaceInsn

        public static void replaceInsn​(MethodNode mth,
                                       BlockNode block,
                                       int i,
                                       InsnNode insn)
        Replace insn by index i in block, for proper copy attributes, assume attributes are not overlap
      • getInsnIndexInBlock

        public static int getInsnIndexInBlock​(BlockNode block,
                                              InsnNode insn)
      • getTopSplitterForHandler

        public static BlockNode getTopSplitterForHandler​(BlockNode handlerBlock)
      • getBlockWithFlag

        @Nullable
        public static @Nullable BlockNode getBlockWithFlag​(java.util.List<BlockNode> blocks,
                                                           AFlag flag)
      • isEqualReturnBlocks

        public static boolean isEqualReturnBlocks​(BlockNode b1,
                                                  BlockNode b2)
      • isDuplicateBlockPath

        public static boolean isDuplicateBlockPath​(BlockNode first,
                                                   BlockNode second)
      • isSameInsnsBlocks

        public static boolean isSameInsnsBlocks​(BlockNode first,
                                                BlockNode second)