Class BetterCFGBuilder2

  • All Implemented Interfaces:
    CFGBuilder, Debug, EdgeTypes

    public class BetterCFGBuilder2
    extends java.lang.Object
    implements CFGBuilder, EdgeTypes, Debug
    A CFGBuilder that really tries to construct accurate control flow graphs. The CFGs it creates have accurate exception edges, and have accurately inlined JSR subroutines.
    See Also:
    CFG
    • Field Detail

      • DEBUG

        private static final boolean DEBUG
      • methodGen

        private final org.apache.bcel.generic.MethodGen methodGen
      • cpg

        private final org.apache.bcel.generic.ConstantPoolGen cpg
      • usedInstructionSet

        private final java.util.BitSet usedInstructionSet
      • jsrSubroutineMap

        private final java.util.IdentityHashMap<org.apache.bcel.generic.InstructionHandle,​BetterCFGBuilder2.Subroutine> jsrSubroutineMap
      • addedFields

        private final java.util.Map<FieldDescriptor,​java.lang.Integer> addedFields
      • cfg

        private CFG cfg
    • Constructor Detail

      • BetterCFGBuilder2

        public BetterCFGBuilder2​(@Nonnull
                                 MethodDescriptor descriptor,
                                 @Nonnull
                                 org.apache.bcel.generic.MethodGen methodGen)
        Constructor.
        Parameters:
        methodGen - the method to build a CFG for
    • Method Detail

      • optimize

        public void optimize​(org.apache.bcel.generic.InstructionList instructionList)
      • getCFG

        public CFG getCFG()
        Description copied from interface: CFGBuilder
        Get the CFG built by this object. Assumes that the build() method has already been called.
        Specified by:
        getCFG in interface CFGBuilder
        Returns:
        the CFG
      • build

        private void build​(BetterCFGBuilder2.Subroutine subroutine)
                    throws CFGBuilderException
        Build a subroutine. We iteratively add basic blocks to the subroutine until there are no more blocks reachable from the calling context. As JSR instructions are encountered, new Subroutines are added to the subroutine work list.
        Parameters:
        subroutine - the subroutine
        Throws:
        CFGBuilderException
      • handleExceptions

        private void handleExceptions​(BetterCFGBuilder2.Subroutine subroutine,
                                      org.apache.bcel.generic.InstructionHandle pei,
                                      BasicBlock etb)
        Add exception edges for given instruction.
        Parameters:
        subroutine - the subroutine containing the instruction
        pei - the instruction which throws an exception
        etb - the exception thrower block (ETB) for the instruction
      • isPEI

        private boolean isPEI​(org.apache.bcel.generic.InstructionHandle handle)
                       throws CFGBuilderException
        Return whether or not the given instruction can throw exceptions.
        Parameters:
        handle - the instruction
        Returns:
        true if the instruction can throw an exception, false otherwise
        Throws:
        CFGBuilderException
      • isSafeFieldSource

        private boolean isSafeFieldSource​(org.apache.bcel.generic.InstructionHandle handle)
        Parameters:
        handle - instruction handle which loads the object for further GETFIELD/PUTFIELD operation
        Returns:
        true if this object is known to be non-null
      • isMerge

        private static boolean isMerge​(org.apache.bcel.generic.InstructionHandle handle)
        Determine whether or not the given instruction is a control flow merge.
        Parameters:
        handle - the instruction
        Returns:
        true if the instruction is a control merge, false otherwise
      • inlineAll

        private CFG inlineAll()
                       throws CFGBuilderException
        Inline all JSR subroutines into the top-level subroutine. This produces a complete CFG for the entire method, in which all JSR subroutines are inlined.
        Returns:
        the CFG for the method
        Throws:
        CFGBuilderException
      • main

        public static void main​(java.lang.String[] argv)
                         throws java.lang.Exception
        Test driver.
        Throws:
        java.lang.Exception