Package edu.umd.cs.findbugs.ba
Class BetterCFGBuilder2
java.lang.Object
edu.umd.cs.findbugs.ba.BetterCFGBuilder2
- All Implemented Interfaces:
CFGBuilder
,Debug
,EdgeTypes
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
Inlining context.private static class
A placeholder for a control edge that escapes its subroutine to return control back to an outer (calling) subroutine.private class
JSR subroutine.private static class
A work list item for creating the CFG for a subroutine. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Map
<FieldDescriptor, Integer> private CFG
private final org.apache.bcel.generic.ConstantPoolGen
private static final boolean
private final ExceptionHandlerMap
private final IdentityHashMap
<org.apache.bcel.generic.InstructionHandle, BetterCFGBuilder2.Subroutine> private final org.apache.bcel.generic.MethodGen
private final LinkedList
<BetterCFGBuilder2.Subroutine> private BetterCFGBuilder2.Subroutine
private final BitSet
Fields inherited from interface edu.umd.cs.findbugs.ba.Debug
VERIFY_INTEGRITY
Fields inherited from interface edu.umd.cs.findbugs.ba.EdgeTypes
BACKEDGE_SOURCE_EDGE, BACKEDGE_TARGET_EDGE, CHECKED_EXCEPTIONS_FLAG, EXIT_EDGE, EXPLICIT_EXCEPTIONS_FLAG, FALL_THROUGH_EDGE, GOTO_EDGE, HANDLED_EXCEPTION_EDGE, IFCMP_EDGE, JSR_EDGE, RET_EDGE, RETURN_EDGE, START_EDGE, SWITCH_DEFAULT_EDGE, SWITCH_EDGE, UNHANDLED_EXCEPTION_EDGE, UNKNOWN_EDGE
-
Constructor Summary
ConstructorsConstructorDescriptionBetterCFGBuilder2
(MethodDescriptor descriptor, org.apache.bcel.generic.MethodGen methodGen) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
build()
Build the CFG.private void
build
(BetterCFGBuilder2.Subroutine subroutine) Build a subroutine.getCFG()
Get the CFG built by this object.int
private void
handleExceptions
(BetterCFGBuilder2.Subroutine subroutine, org.apache.bcel.generic.InstructionHandle pei, BasicBlock etb) Add exception edges for given instruction.void
inline
(BetterCFGBuilder2.Context context) Inline a subroutine into a calling context.private CFG
Inline all JSR subroutines into the top-level subroutine.private static boolean
isMerge
(org.apache.bcel.generic.InstructionHandle handle) Determine whether or not the given instruction is a control flow merge.private boolean
isPEI
(org.apache.bcel.generic.InstructionHandle handle) Return whether or not the given instruction can throw exceptions.private boolean
isSafeFieldSource
(org.apache.bcel.generic.InstructionHandle handle) static void
Test driver.void
optimize
(org.apache.bcel.generic.InstructionList instructionList)
-
Field Details
-
DEBUG
private static final boolean DEBUG -
methodGen
private final org.apache.bcel.generic.MethodGen methodGen -
cpg
private final org.apache.bcel.generic.ConstantPoolGen cpg -
exceptionHandlerMap
-
usedInstructionSet
-
subroutineWorkList
-
jsrSubroutineMap
private final IdentityHashMap<org.apache.bcel.generic.InstructionHandle,BetterCFGBuilder2.Subroutine> jsrSubroutineMap -
addedFields
-
topLevelSubroutine
-
cfg
-
-
Constructor Details
-
BetterCFGBuilder2
public BetterCFGBuilder2(@Nonnull MethodDescriptor descriptor, @Nonnull org.apache.bcel.generic.MethodGen methodGen) Constructor.- Parameters:
methodGen
- the method to build a CFG for
-
-
Method Details
-
getIndex
-
optimize
public void optimize(org.apache.bcel.generic.InstructionList instructionList) -
build
Description copied from interface:CFGBuilder
Build the CFG.- Specified by:
build
in interfaceCFGBuilder
- Throws:
CFGBuilderException
-
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 interfaceCFGBuilder
- Returns:
- the CFG
-
build
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 instructionpei
- the instruction which throws an exceptionetb
- the exception thrower block (ETB) for the instruction
-
isPEI
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
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
-
inline
Inline a subroutine into a calling context.- Parameters:
context
- the Context- Throws:
CFGBuilderException
-
main
Test driver.- Throws:
Exception
-