edu.umd.cs.findbugs.ba.obl
Class ObligationAnalysis

java.lang.Object
  extended by edu.umd.cs.findbugs.ba.AbstractDataflowAnalysis<Fact>
      extended by edu.umd.cs.findbugs.ba.ForwardDataflowAnalysis<StateSet>
          extended by edu.umd.cs.findbugs.ba.obl.ObligationAnalysis
All Implemented Interfaces:
DataflowAnalysis<StateSet>

public class ObligationAnalysis
extends ForwardDataflowAnalysis<StateSet>

Dataflow analysis to track obligations (i/o streams and other resources which must be closed).

See Weimer and Necula, Finding and preventing run-time error handling mistakes, OOPSLA 2004.

Author:
David Hovemeyer

Constructor Summary
ObligationAnalysis(DepthFirstSearch dfs, TypeDataflow typeDataflow, org.apache.bcel.generic.MethodGen methodGen, ObligationFactory factory, PolicyDatabase database, RepositoryLookupFailureCallback lookupFailureCallback)
          Constructor.
 
Method Summary
 void copy(StateSet src, StateSet dest)
          Copy dataflow facts.
 StateSet createFact()
          Create empty (uninitialized) dataflow facts for one program point.
 void endTransfer(BasicBlock basicBlock, org.apache.bcel.generic.InstructionHandle end, java.lang.Object result_)
          Subclasses may override this.
 void initEntryFact(StateSet fact)
          Initialize the "entry" fact for the graph.
 void initResultFact(StateSet fact)
          Initialize result fact for block.
 boolean isFactValid(StateSet fact)
          Determine whether the given fact is valid (neither top nor bottom).
 void makeFactTop(StateSet fact)
          Make given fact the top value.
 void meetInto(StateSet fact, Edge edge, StateSet result)
          Meet a dataflow fact associated with an incoming edge into another fact.
 boolean same(StateSet a, StateSet b)
          Are given dataflow facts the same?
 void transferInstruction(org.apache.bcel.generic.InstructionHandle handle, BasicBlock basicBlock, StateSet fact)
          Transfer function for a single instruction.
 
Methods inherited from class edu.umd.cs.findbugs.ba.ForwardDataflowAnalysis
getBlockOrder, getDepthFirstSearch, isForwards
 
Methods inherited from class edu.umd.cs.findbugs.ba.AbstractDataflowAnalysis
factToString, getFactAfterLocation, getFactAtLocation, getResultFact, getStartFact, resultFactIterator, startTransfer, transfer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObligationAnalysis

public ObligationAnalysis(DepthFirstSearch dfs,
                          TypeDataflow typeDataflow,
                          org.apache.bcel.generic.MethodGen methodGen,
                          ObligationFactory factory,
                          PolicyDatabase database,
                          RepositoryLookupFailureCallback lookupFailureCallback)
Constructor.

Parameters:
dfs - a DepthFirstSearch on the method to be analyzed
methodGen - the MethodGen of the method being analyzed
factory - the ObligationFactory defining the obligation types
database - the PolicyDatabase defining the methods which add and delete obligations
lookupFailureCallback - callback to use when reporting missing classes
Method Detail

createFact

public StateSet createFact()
Description copied from interface: DataflowAnalysis
Create empty (uninitialized) dataflow facts for one program point. A valid value will be copied into it before it is used.


isFactValid

public boolean isFactValid(StateSet fact)
Description copied from class: AbstractDataflowAnalysis
Determine whether the given fact is valid (neither top nor bottom).

Specified by:
isFactValid in class AbstractDataflowAnalysis<StateSet>

transferInstruction

public void transferInstruction(org.apache.bcel.generic.InstructionHandle handle,
                                BasicBlock basicBlock,
                                StateSet fact)
                         throws DataflowAnalysisException
Description copied from class: AbstractDataflowAnalysis
Transfer function for a single instruction.

Specified by:
transferInstruction in class AbstractDataflowAnalysis<StateSet>
Parameters:
handle - the instruction
basicBlock - the BasicBlock containing the instruction; needed to disambiguate instructions in inlined JSR subroutines
fact - which should be modified based on the instruction
Throws:
DataflowAnalysisException

endTransfer

public void endTransfer(BasicBlock basicBlock,
                        org.apache.bcel.generic.InstructionHandle end,
                        java.lang.Object result_)
                 throws DataflowAnalysisException
Description copied from class: AbstractDataflowAnalysis
Subclasses may override this. Due to a bug in the 2.2 version of the generics-enabled javac, it is not possible to directly override the transfer() method. This method will be called just before exiting transfer().

Overrides:
endTransfer in class AbstractDataflowAnalysis<StateSet>
Parameters:
basicBlock - the basic block
end - last instruction analyzed (null if entire block was analyzed)
result_ - the result fact for the block
Throws:
DataflowAnalysisException

copy

public void copy(StateSet src,
                 StateSet dest)
Description copied from interface: DataflowAnalysis
Copy dataflow facts.


initEntryFact

public void initEntryFact(StateSet fact)
                   throws DataflowAnalysisException
Description copied from interface: DataflowAnalysis
Initialize the "entry" fact for the graph.

Throws:
DataflowAnalysisException

initResultFact

public void initResultFact(StateSet fact)
Description copied from interface: DataflowAnalysis
Initialize result fact for block. The start facts for a block are initialized as the meet of the "logical" predecessor's result facts. Note that a "logical predecessor" is actually a CFG successor if the analysis is backwards.


makeFactTop

public void makeFactTop(StateSet fact)
Description copied from interface: DataflowAnalysis
Make given fact the top value.


same

public boolean same(StateSet a,
                    StateSet b)
Description copied from interface: DataflowAnalysis
Are given dataflow facts the same?


meetInto

public void meetInto(StateSet fact,
                     Edge edge,
                     StateSet result)
              throws DataflowAnalysisException
Description copied from interface: DataflowAnalysis
Meet a dataflow fact associated with an incoming edge into another fact. This is used to determine the start fact for a basic block.

Parameters:
fact - the predecessor fact (incoming edge)
edge - the edge from the predecessor
result - the result fact
Throws:
DataflowAnalysisException