Package edu.umd.cs.findbugs.ba
Class BetterCFGBuilder2.Subroutine
- java.lang.Object
-
- edu.umd.cs.findbugs.ba.BetterCFGBuilder2.Subroutine
-
- Enclosing class:
- BetterCFGBuilder2
private class BetterCFGBuilder2.Subroutine extends java.lang.Object
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
Fields Modifier and Type Field Description private java.util.IdentityHashMap<org.apache.bcel.generic.InstructionHandle,BasicBlock>
blockMap
private CFG
cfgSub
private java.util.IdentityHashMap<BasicBlock,java.util.List<BetterCFGBuilder2.EscapeTarget>>
escapeTargetListMap
private java.util.BitSet
exitBlockSet
private java.util.BitSet
instructionSet
private java.util.BitSet
returnBlockSet
private org.apache.bcel.generic.InstructionHandle
start
private java.util.BitSet
unhandledExceptionBlockSet
private java.util.LinkedList<BetterCFGBuilder2.WorkListItem>
workList
-
Constructor Summary
Constructors Constructor Description Subroutine(org.apache.bcel.generic.InstructionHandle start)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
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
addItem(BetterCFGBuilder2.WorkListItem item)
Add a work list item for a basic block to be constructed.BasicBlock
allocateBasicBlock()
Allocate a new basic block in the subroutine.boolean
containsInstruction(org.apache.bcel.generic.InstructionHandle handle)
Is the given instruction part of this subroutine?java.util.Iterator<BetterCFGBuilder2.EscapeTarget>
escapeTargetIterator(BasicBlock sourceBlock)
Get an Iterator over the EscapeTargets of given basic block.BasicBlock
getBlock(org.apache.bcel.generic.InstructionHandle start)
Get the basic block in the subroutine for the given instruction.CFG
getCFG()
Get the subroutine's CFG.BasicBlock
getEntry()
Get the entry block for the subroutine's CFG.BasicBlock
getExit()
Get the exit block for the subroutine's CFG.BasicBlock
getStartBlock()
Get the start block for the subroutine's CFG.org.apache.bcel.generic.InstructionHandle
getStartInstruction()
Get the start instruction.boolean
hasMoreWork()
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
isUnhandledExceptionBlock(BasicBlock block)
Does this block throw an unhandled exception?BetterCFGBuilder2.WorkListItem
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
setUnhandledExceptionBlock(BasicBlock block)
Indicate that an unhandled exception may be thrown by the given block.
-
-
-
Field Detail
-
start
private final org.apache.bcel.generic.InstructionHandle start
-
instructionSet
private final java.util.BitSet instructionSet
-
cfgSub
private final CFG cfgSub
-
blockMap
private final java.util.IdentityHashMap<org.apache.bcel.generic.InstructionHandle,BasicBlock> blockMap
-
escapeTargetListMap
private final java.util.IdentityHashMap<BasicBlock,java.util.List<BetterCFGBuilder2.EscapeTarget>> escapeTargetListMap
-
returnBlockSet
private final java.util.BitSet returnBlockSet
-
exitBlockSet
private final java.util.BitSet exitBlockSet
-
unhandledExceptionBlockSet
private final java.util.BitSet unhandledExceptionBlockSet
-
workList
private final java.util.LinkedList<BetterCFGBuilder2.WorkListItem> workList
-
-
Method Detail
-
getStartInstruction
public org.apache.bcel.generic.InstructionHandle getStartInstruction()
Get the start instruction.
-
allocateBasicBlock
public BasicBlock allocateBasicBlock()
Allocate a new basic block in the subroutine.
-
addItem
public void addItem(BetterCFGBuilder2.WorkListItem item)
Add a work list item for a basic block to be constructed.
-
hasMoreWork
public boolean hasMoreWork()
Are there more work list items?
-
nextItem
public BetterCFGBuilder2.WorkListItem nextItem()
Get the next work list item.
-
getEntry
public BasicBlock getEntry()
Get the entry block for the subroutine's CFG.
-
getExit
public BasicBlock getExit()
Get the exit block for the subroutine's CFG.
-
getStartBlock
public BasicBlock getStartBlock()
Get the start block for the subroutine's CFG. (I.e., the block containing the start instruction.)
-
getCFG
public CFG 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
public BasicBlock getBlock(org.apache.bcel.generic.InstructionHandle start)
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
public void setReturnBlock(BasicBlock block)
Indicate that the method returns at the end of the given block.- Parameters:
block
- the returning block
-
isReturnBlock
public boolean isReturnBlock(BasicBlock block)
Does the method return at the end of this block?
-
setExitBlock
public void setExitBlock(BasicBlock block)
Indicate that System.exit() is called at the end of the given block.- Parameters:
block
- the exiting block
-
isExitBlock
public boolean isExitBlock(BasicBlock block)
Is System.exit() called at the end of this block?
-
setUnhandledExceptionBlock
public void setUnhandledExceptionBlock(BasicBlock block)
Indicate that an unhandled exception may be thrown by the given block.- Parameters:
block
- the block throwing an unhandled exception
-
isUnhandledExceptionBlock
public boolean isUnhandledExceptionBlock(BasicBlock block)
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
public void addEdge(BasicBlock sourceBlock, BasicBlock destBlock, @Type int edgeType)
Add an edge to the subroutine's CFG.- Parameters:
sourceBlock
- the source basic blockdestBlock
- the destination basic blockedgeType
- the type of edge
-
escapeTargetIterator
public java.util.Iterator<BetterCFGBuilder2.EscapeTarget> escapeTargetIterator(BasicBlock sourceBlock)
Get an Iterator over the EscapeTargets of given basic block.- Parameters:
sourceBlock
- the basic block- Returns:
- an Iterator over the EscapeTargets
-
-