Class ExceptionalUnitGraph
- java.lang.Object
-
- soot.toolkits.graph.UnitGraph
-
- soot.toolkits.graph.ExceptionalUnitGraph
-
- All Implemented Interfaces:
Iterable<Unit>,DirectedBodyGraph<Unit>,DirectedGraph<Unit>,ExceptionalGraph<Unit>
- Direct Known Subclasses:
CompleteUnitGraph
public class ExceptionalUnitGraph extends UnitGraph implements ExceptionalGraph<Unit>
Represents a control flow graph for a
Bodyinstance where the nodes areUnitinstances, and where control flow associated with exceptions is taken into account.To describe precisely the circumstances under which exceptional edges are added to the graph, we need to distinguish the exceptions thrown explicitly by a
throwinstruction from the exceptions which are thrown implicitly by the VM to signal an error it encounters in the course of executing an instruction, which need not be athrow.For every
ThrowInstorThrowStmtUnitwhich may explicitly throw an exception that would be caught by aTrapin theBody, there will be an edge from thethrowUnitto theTraphandler's firstUnit.For every
Unitwhich may implicitly throw an exception that could be caught by aTrapin theBody, there will be an edge from each of the exceptingUnit's predecessors to theTraphandler's firstUnit(since any of those predecessors may have been the lastUnitto complete execution before the handler starts execution). If the exceptingUnitmight have the side effect of changing some field, then there will definitely be an edge from the exceptingUnititself to its handlers, since the side effect might occur before the exception is raised. If the exceptingUnithas no side effects, then parameters passed to theExceptionalUnitGraphconstructor determine whether or not there is an edge from the exceptingUnititself to the handlerUnit.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classExceptionalUnitGraph.ExceptionDest
-
Field Summary
Fields Modifier and Type Field Description protected ThrowAnalysisthrowAnalysisprotected Map<Unit,List<Unit>>unitToExceptionalPredsprotected Map<Unit,List<Unit>>unitToExceptionalSuccsprotected Map<Unit,Collection<ExceptionalUnitGraph.ExceptionDest>>unitToExceptionDestsprotected Map<Unit,List<Unit>>unitToUnexceptionalPredsprotected Map<Unit,List<Unit>>unitToUnexceptionalSuccs-
Fields inherited from class soot.toolkits.graph.UnitGraph
body, heads, method, tails, unitChain, unitToPreds, unitToSuccs
-
-
Constructor Summary
Constructors Modifier Constructor Description ExceptionalUnitGraph(Body body)Constructs the graph from a given Body instance, using theScene's defaultThrowAnalysisto estimate the set of exceptions that eachUnitmight throw and a default value, provided by theOptionsclass, for theomitExceptingUnitEdgesparameter.protectedExceptionalUnitGraph(Body body, boolean ignoredBogusParameter)Allocates anExceptionalUnitGraphobject without initializing it.ExceptionalUnitGraph(Body body, ThrowAnalysis throwAnalysis)Constructs the graph from a given Body instance using the passedThrowAnalysisand a default value, provided by theOptionsclass, for theomitExceptingUnitEdgesparameter.ExceptionalUnitGraph(Body body, ThrowAnalysis throwAnalysis, boolean omitExceptingUnitEdges)Constructs the graph for a given Body instance, using theThrowAnalysisandomitExceptingUnitEdgesvalue that are passed as parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Set<Unit>buildExceptionalEdges(ThrowAnalysis throwAnalysis, Map<Unit,Collection<ExceptionalUnitGraph.ExceptionDest>> unitToExceptionDests, Map<Unit,List<Unit>> unitToSuccs, Map<Unit,List<Unit>> unitToPreds, boolean omitExceptingUnitEdges)Method to compute the edges corresponding to exceptional control flow.protected Map<Unit,Collection<ExceptionalUnitGraph.ExceptionDest>>buildExceptionDests(ThrowAnalysis throwAnalysis)Utility method used in the construction ofUnitGraphvariants which include exceptional control flow.protected voidbuildHeadsAndTails()A placeholder that overridesUnitGraph.buildHeadsAndTails()with a method which always throws an exception.List<Unit>getExceptionalPredsOf(Unit u)Returns a list of nodes which are predecessors of a given node when only exceptional control flow is considered.List<Unit>getExceptionalSuccsOf(Unit u)Returns a list of nodes which are successors of a given node when only exceptional control flow is considered.Collection<ExceptionalUnitGraph.ExceptionDest>getExceptionDests(Unit u)Returns a collection ofExceptionDestobjects which represent how exceptions thrown by a specified unit will be handled.ThrowAnalysisgetThrowAnalysis()Return theThrowAnalysisused to construct this graph, if the graph contains noTraps, ornullif the graph does containTraps.List<Unit>getUnexceptionalPredsOf(Unit u)Returns a list of nodes which are predecessors of a given node when only unexceptional control flow is considered.List<Unit>getUnexceptionalSuccsOf(Unit u)Returns a list of nodes which are successors of a given node when only unexceptional control flow is considered.protected voidinitialize(ThrowAnalysis throwAnalysis, boolean omitExceptingUnitEdges)Performs the real work of constructing anExceptionalUnitGraph, factored out of the constructors so that subclasses have the option to delay creating the graph's edges until after they have performed some subclass-specific initialization.StringtoString()-
Methods inherited from class soot.toolkits.graph.UnitGraph
addEdge, buildUnexceptionalEdges, combineMapValues, getBody, getExtendedBasicBlockPathBetween, getHeads, getPredsOf, getSuccsOf, getTails, iterator, size
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface soot.toolkits.graph.DirectedGraph
getHeads, getPredsOf, getSuccsOf, getTails, iterator, size
-
Methods inherited from interface soot.toolkits.graph.ExceptionalGraph
getBody
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Field Detail
-
unitToExceptionDests
protected Map<Unit,Collection<ExceptionalUnitGraph.ExceptionDest>> unitToExceptionDests
-
throwAnalysis
protected ThrowAnalysis throwAnalysis
-
-
Constructor Detail
-
ExceptionalUnitGraph
public ExceptionalUnitGraph(Body body, ThrowAnalysis throwAnalysis, boolean omitExceptingUnitEdges)
Constructs the graph for a given Body instance, using theThrowAnalysisandomitExceptingUnitEdgesvalue that are passed as parameters.- Parameters:
body- theBodyfrom which to build a graph.throwAnalysis- the source of information about the exceptions which eachUnitmay throw.omitExceptingUnitEdges- indicates whether the CFG should omit edges to a handler from trappedUnits which may implicitly throw an exception which the handler catches but which have no potential side effects. The CFG will contain edges to the handler from all predecessors ofUnits which may implicitly throw a caught exception regardless of the setting for this parameter. If this parameter isfalse, there will also be edges to the handler from all the potentially exceptingUnits themselves. If this parameter istrue, there will be edges to the handler from the exceptingUnits themselves only if they have potential side effects (or if they are themselves the predecessors of other potentially exceptingUnits). A setting oftrueproduces CFGs which allow for more precise analyses, since aUnitwithout side effects has no effect on the computational state when it throws an exception. Use settings offalsefor compatibility with more conservative analyses, or to cater to conservative bytecode verifiers.
-
ExceptionalUnitGraph
public ExceptionalUnitGraph(Body body, ThrowAnalysis throwAnalysis)
Constructs the graph from a given Body instance using the passedThrowAnalysisand a default value, provided by theOptionsclass, for theomitExceptingUnitEdgesparameter.
-
ExceptionalUnitGraph
public ExceptionalUnitGraph(Body body)
Constructs the graph from a given Body instance, using theScene's defaultThrowAnalysisto estimate the set of exceptions that eachUnitmight throw and a default value, provided by theOptionsclass, for theomitExceptingUnitEdgesparameter.- Parameters:
body- theBodyfrom which to build a graph.
-
ExceptionalUnitGraph
protected ExceptionalUnitGraph(Body body, boolean ignoredBogusParameter)
Allocates an
ExceptionalUnitGraphobject without initializing it. This “partial constructor” is provided for the benefit of subclasses whose constructors need to perform some subclass-specific processing before actually creating the graph edges (because, for example, the subclass overrides a utility method likebuildExceptionDests(ThrowAnalysis)orbuildExceptionalEdges(ThrowAnalysis, Map, Map, Map, boolean)with a replacement method that depends on additional parameters passed to the subclass's constructor). The subclass constructor is responsible for callinginitialize(ThrowAnalysis, boolean), or otherwise performing the initialization required to implementExceptionalUnitGraph's interface.Clients who opt to extend
ExceptionalUnitGraphshould be warned that the class has not been carefully designed for inheritance; code that uses theprotectedmembers of this class may need to be rewritten for each new Soot release.- Parameters:
body- theBodyfrom which to build a graph.ignoredBogusParameter- a meaningless placeholder, which exists solely to distinguish this constructor from the publicExceptionalUnitGraph(Body)constructor.
-
-
Method Detail
-
initialize
protected void initialize(ThrowAnalysis throwAnalysis, boolean omitExceptingUnitEdges)
Performs the real work of constructing anExceptionalUnitGraph, factored out of the constructors so that subclasses have the option to delay creating the graph's edges until after they have performed some subclass-specific initialization.- Parameters:
throwAnalysis- the source of information about the exceptions which eachUnitmay throw.omitExceptingUnitEdges- indicates whether the CFG should omit edges to a handler from trappedUnits which may throw an exception which the handler catches but which have no potential side effects.
-
buildExceptionDests
protected Map<Unit,Collection<ExceptionalUnitGraph.ExceptionDest>> buildExceptionDests(ThrowAnalysis throwAnalysis)
Utility method used in the construction of
UnitGraphvariants which include exceptional control flow. It determines whichUnits may throw exceptions that would be caught byTraps within the method.- Parameters:
throwAnalysis- The source of information about which exceptions eachUnitmay throw.- Returns:
nullif noUnits in the method throw any exceptions caught within the method. Otherwise, aMapfromUnits toCollections ofExceptionalUnitGraph.ExceptionDests.The returned map has an idiosyncracy which is hidden from most client code, but which is exposed to subclasses extending
ExceptionalUnitGraph. If aUnitthrows one or more exceptions which are caught within the method, it will be mapped to aCollectionofExceptionDests describing the sets of exceptions that theUnitmight throw to eachTrap. But if all of aUnit's exceptions escape the method, it will be mapped tonullCollection containing a singleExceptionDestwith anulltrap. (The special case forUnits with no caught exceptions allowsbuildExceptionDests()to ignore completelyUnits which are outside the scope of allTraps.)
-
buildExceptionalEdges
protected Set<Unit> buildExceptionalEdges(ThrowAnalysis throwAnalysis, Map<Unit,Collection<ExceptionalUnitGraph.ExceptionDest>> unitToExceptionDests, Map<Unit,List<Unit>> unitToSuccs, Map<Unit,List<Unit>> unitToPreds, boolean omitExceptingUnitEdges)
Method to compute the edges corresponding to exceptional control flow.- Parameters:
throwAnalysis- the source of information about the exceptions which eachUnitmay throw.unitToExceptionDests- AMapfromUnits toCollections ofExceptionDests which represent the handlers that might catch exceptions thrown by theUnit. This is an ``in parameter''.unitToSuccs- AMapfromUnits toLists ofUnits. This is an ``out parameter'';buildExceptionalEdgeswill add a mapping from everyUnitin the body that may throw an exception that could be caught by aTrapin the body to a list of its exceptional successors.unitToPreds- AMapfromUnits toLists ofUnits. This is an ``out parameter'';buildExceptionalEdgeswill add a mapping from each handler unit that may catch an exception to the list ofUnits whose exceptions it may catch.omitExceptingUnitEdges- Indicates whether to omit exceptional edges from excepting units which lack side effects- Returns:
- a
Setof trapUnits that might catch exceptions thrown by the firstUnitin theBodyassociated with the graph being constructed. Such trapUnits may need to be added to the list of heads (depending on your definition of heads), since they can be the firstUnitin theBodywhich actually completes execution.
-
buildHeadsAndTails
protected void buildHeadsAndTails() throws IllegalStateExceptionA placeholder that overrides
UnitGraph.buildHeadsAndTails()with a method which always throws an exception. The placeholder serves to indicate thatExceptionalUnitGraphdoes not usebuildHeadsAndTails(), and to document the conditions under whichExceptionalUnitGraph considers a node to be a head or tail.ExceptionalUnitGraphdefines the graph's set of heads to include the firstUnitin the graph's body, together with the firstUnitin any exception handler which might catch an exception thrown by the firstUnitin the body (because any of thoseUnits might be the first to successfully complete execution).ExceptionalUnitGraphdefines the graph's set of tails to include allUnits which represent some variety of return bytecode or anathrowbytecode whose argument might escape the method.- Overrides:
buildHeadsAndTailsin classUnitGraph- Throws:
IllegalStateException
-
getExceptionDests
public Collection<ExceptionalUnitGraph.ExceptionDest> getExceptionDests(Unit u)
Returns a collection ofExceptionDestobjects which represent how exceptions thrown by a specified unit will be handled.- Specified by:
getExceptionDestsin interfaceExceptionalGraph<Unit>- Parameters:
u- The unit for which to provide exception information. (umust be aUnit, though the parameter is declared as anObjectto satisfy the interface ofExceptionalGraph.- Returns:
- a collection of
ExceptionDestobjects describing the traps, if any, which catch the exceptions which may be thrown byu.
-
getUnexceptionalPredsOf
public List<Unit> getUnexceptionalPredsOf(Unit u)
Description copied from interface:ExceptionalGraphReturns a list of nodes which are predecessors of a given node when only unexceptional control flow is considered.- Specified by:
getUnexceptionalPredsOfin interfaceExceptionalGraph<Unit>- Parameters:
u- The node whose predecessors are to be returned.- Returns:
- a
Listof the nodes in this graph from which there is an unexceptional edge ton.
-
getUnexceptionalSuccsOf
public List<Unit> getUnexceptionalSuccsOf(Unit u)
Description copied from interface:ExceptionalGraphReturns a list of nodes which are successors of a given node when only unexceptional control flow is considered.- Specified by:
getUnexceptionalSuccsOfin interfaceExceptionalGraph<Unit>- Parameters:
u- The node whose successors are to be returned.- Returns:
- a
Listof nodes in this graph to which there is an unexceptional edge fromn.
-
getExceptionalPredsOf
public List<Unit> getExceptionalPredsOf(Unit u)
Description copied from interface:ExceptionalGraphReturns a list of nodes which are predecessors of a given node when only exceptional control flow is considered.- Specified by:
getExceptionalPredsOfin interfaceExceptionalGraph<Unit>- Parameters:
u- The node whose predecessors are to be returned.- Returns:
- a
Listof nodes in this graph from which there is an exceptional edge ton.
-
getExceptionalSuccsOf
public List<Unit> getExceptionalSuccsOf(Unit u)
Description copied from interface:ExceptionalGraphReturns a list of nodes which are successors of a given node when only exceptional control flow is considered.- Specified by:
getExceptionalSuccsOfin interfaceExceptionalGraph<Unit>- Parameters:
u- The node whose successors are to be returned.- Returns:
- a
Listof nodes in this graph to which there is an exceptional edge fromn.
-
getThrowAnalysis
public ThrowAnalysis getThrowAnalysis()
Return the
ThrowAnalysisused to construct this graph, if the graph contains noTraps, ornullif the graph does containTraps. A reference to theThrowAnalysisis kept when there are noTraps so that the graph can generate responses toExceptionalGraph.getExceptionDests(Object)on the fly, rather than precomputing information that may never be needed.This method is package-private because it exposes a detail of the implementation of
ExceptionalUnitGraphso that theExceptionalBlockGraphconstructor can cache the sameThrowAnalysisfor the same purpose.- Returns:
- the
ThrowAnalysisused to generate this graph if the graph contains noTraps, ornullif the graph contains one or moreTraps.
-
-