Package edu.umd.cs.findbugs.ba
Class BetterCFGBuilder2.Subroutine
java.lang.Object
edu.umd.cs.findbugs.ba.BetterCFGBuilder2.Subroutine
- Enclosing class:
BetterCFGBuilder2
JSR subroutine. The top level subroutine is where execution starts. Each
subroutine has its own CFG. Eventually, all JSR subroutines will be
inlined into the top level subroutine, resulting in an accurate CFG for
the overall method.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final IdentityHashMap
<org.apache.bcel.generic.InstructionHandle, BasicBlock> private final CFG
private final IdentityHashMap
<BasicBlock, List<BetterCFGBuilder2.EscapeTarget>> private final BitSet
private final BitSet
private final BitSet
private final org.apache.bcel.generic.InstructionHandle
private final BitSet
private final LinkedList
<BetterCFGBuilder2.WorkListItem> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addEdge
(BasicBlock sourceBlock, BasicBlock destBlock, int edgeType) Add an edge to the subroutine's CFG.void
addEdgeAndExplore
(BasicBlock sourceBlock, org.apache.bcel.generic.InstructionHandle target, int edgeType) Add a control flow edge to the subroutine.void
addInstruction
(org.apache.bcel.generic.InstructionHandle handle) Add an instruction to the subroutine.void
Add a work list item for a basic block to be constructed.Allocate a new basic block in the subroutine.boolean
containsInstruction
(org.apache.bcel.generic.InstructionHandle handle) Is the given instruction part of this subroutine?escapeTargetIterator
(BasicBlock sourceBlock) Get an Iterator over the EscapeTargets of given basic block.getBlock
(org.apache.bcel.generic.InstructionHandle start) Get the basic block in the subroutine for the given instruction.getCFG()
Get the subroutine's CFG.getEntry()
Get the entry block for the subroutine's CFG.getExit()
Get the exit block for the subroutine's CFG.Get the start block for the subroutine's CFG.org.apache.bcel.generic.InstructionHandle
Get the start instruction.boolean
Are there more work list items?boolean
isExitBlock
(BasicBlock block) Is System.exit() called at the end of this block?boolean
isReturnBlock
(BasicBlock block) Does the method return at the end of this block?boolean
Does this block throw an unhandled exception?nextItem()
Get the next work list item.void
setExitBlock
(BasicBlock block) Indicate that System.exit() is called at the end of the given block.void
setReturnBlock
(BasicBlock block) Indicate that the method returns at the end of the given block.void
Indicate that an unhandled exception may be thrown by the given block.
-
Field Details
-
start
private final org.apache.bcel.generic.InstructionHandle start -
instructionSet
-
cfgSub
-
blockMap
-
escapeTargetListMap
-
returnBlockSet
-
exitBlockSet
-
unhandledExceptionBlockSet
-
workList
-
-
Constructor Details
-
Subroutine
public Subroutine(org.apache.bcel.generic.InstructionHandle start) Constructor.- Parameters:
start
- the start instruction for the subroutine
-
-
Method Details
-
getStartInstruction
public org.apache.bcel.generic.InstructionHandle getStartInstruction()Get the start instruction. -
allocateBasicBlock
Allocate a new basic block in the subroutine. -
addItem
Add a work list item for a basic block to be constructed. -
hasMoreWork
public boolean hasMoreWork()Are there more work list items? -
nextItem
Get the next work list item. -
getEntry
Get the entry block for the subroutine's CFG. -
getExit
Get the exit block for the subroutine's CFG. -
getStartBlock
Get the start block for the subroutine's CFG. (I.e., the block containing the start instruction.) -
getCFG
Get the subroutine's CFG. -
addInstruction
public void addInstruction(org.apache.bcel.generic.InstructionHandle handle) throws CFGBuilderException Add an instruction to the subroutine. We keep track of which instructions are part of which subroutines. No instruction may be part of more than one subroutine.- Parameters:
handle
- the instruction to be added to the subroutine- Throws:
CFGBuilderException
-
containsInstruction
public boolean containsInstruction(org.apache.bcel.generic.InstructionHandle handle) Is the given instruction part of this subroutine? -
getBlock
Get the basic block in the subroutine for the given instruction. If the block doesn't exist yet, it is created, and a work list item is added which will populate it. Note that if start is an exception thrower, the block returned will be its ETB.- Parameters:
start
- the start instruction for the block- Returns:
- the basic block for the instruction
-
setReturnBlock
Indicate that the method returns at the end of the given block.- Parameters:
block
- the returning block
-
isReturnBlock
Does the method return at the end of this block? -
setExitBlock
Indicate that System.exit() is called at the end of the given block.- Parameters:
block
- the exiting block
-
isExitBlock
Is System.exit() called at the end of this block? -
setUnhandledExceptionBlock
Indicate that an unhandled exception may be thrown by the given block.- Parameters:
block
- the block throwing an unhandled exception
-
isUnhandledExceptionBlock
Does this block throw an unhandled exception? -
addEdgeAndExplore
public void addEdgeAndExplore(BasicBlock sourceBlock, org.apache.bcel.generic.InstructionHandle target, @Type int edgeType) Add a control flow edge to the subroutine. If the control target has not yet been added to the subroutine, a new work list item is added. If the control target is in another subroutine, an EscapeTarget is added.- Parameters:
sourceBlock
- the source basic blocktarget
- the control targetedgeType
- the type of control edge
-
addEdge
Add an edge to the subroutine's CFG.- Parameters:
sourceBlock
- the source basic blockdestBlock
- the destination basic blockedgeType
- the type of edge
-
escapeTargetIterator
Get an Iterator over the EscapeTargets of given basic block.- Parameters:
sourceBlock
- the basic block- Returns:
- an Iterator over the EscapeTargets
-