|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsoot.toolkits.graph.UnitGraph
soot.toolkits.graph.ExceptionalUnitGraph
public class ExceptionalUnitGraph
Represents a control flow graph for a Body
instance
where the nodes are Unit
instances, 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 throw
instruction
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 a throw
.
For every ThrowInst
or ThrowStmt
Unit
which may explicitly throw an exception that
would be caught by a Trap
in the Body
, there
will be an edge from the throw
Unit
to
the Trap
handler's first Unit
.
For every Unit
which may implicitly throw an
exception that could be caught by a Trap
in the
Body
, there will be an edge from each of the
excepting Unit
's predecessors to the
Trap
handler's first Unit
(since any of
those predecessors may have been the last Unit
to
complete execution before the handler starts execution). If the
excepting Unit
might have the side effect of changing
some field, then there will definitely be an edge from the excepting
Unit
itself to its handlers, since the side effect
might occur before the exception is raised. If the excepting
Unit
has no side effects, then parameters passed to
the ExceptionalUnitGraph
constructor determine
whether or not there is an edge from the excepting
Unit
itself to the handler Unit
.
Nested Class Summary | |
---|---|
static class |
ExceptionalUnitGraph.ExceptionDest
|
Field Summary | |
---|---|
protected ThrowAnalysis |
throwAnalysis
|
protected Map<Unit,List<Unit>> |
unitToExceptionalPreds
|
protected Map<Unit,List<Unit>> |
unitToExceptionalSuccs
|
protected Map<Unit,Collection<ExceptionalUnitGraph.ExceptionDest>> |
unitToExceptionDests
|
protected Map<Unit,List<Unit>> |
unitToUnexceptionalPreds
|
protected Map<Unit,List<Unit>> |
unitToUnexceptionalSuccs
|
Fields inherited from class soot.toolkits.graph.UnitGraph |
---|
body, heads, method, tails, unitChain, unitToPreds, unitToSuccs |
Constructor Summary | |
---|---|
|
ExceptionalUnitGraph(Body body)
Constructs the graph from a given Body instance, using the Scene 's default ThrowAnalysis to estimate the
set of exceptions that each Unit might throw and a
default value, provided by the Options class, for the
omitExceptingUnitEdges parameter. |
protected |
ExceptionalUnitGraph(Body body,
boolean ignoredBogusParameter)
Allocates an ExceptionalUnitGraph object
without initializing it. |
|
ExceptionalUnitGraph(Body body,
ThrowAnalysis throwAnalysis)
Constructs the graph from a given Body instance using the passed ThrowAnalysis and a default value, provided by
the Options class, for the
omitExceptingUnitEdges parameter. |
|
ExceptionalUnitGraph(Body body,
ThrowAnalysis throwAnalysis,
boolean omitExceptingUnitEdges)
Constructs the graph for a given Body instance, using the ThrowAnalysis and omitExceptingUnitEdges
value that are passed as parameters. |
Method Summary | |
---|---|
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 of UnitGraph
variants which include exceptional control flow. |
protected void |
buildHeadsAndTails()
A placeholder that overrides UnitGraph.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 of ExceptionDest
objects which represent how exceptions thrown by a specified
unit will be handled. |
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 void |
initialize(ThrowAnalysis throwAnalysis,
boolean omitExceptingUnitEdges)
Performs the real work of constructing an ExceptionalUnitGraph , 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. |
String |
toString()
|
Methods inherited from class soot.toolkits.graph.UnitGraph |
---|
addEdge, buildUnexceptionalEdges, combineMapValues, getBody, getExtendedBasicBlockPathBetween, getHeads, getPredsOf, getSuccsOf, getTails, iterator, makeMappedListsUnmodifiable, 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.ExceptionalGraph |
---|
getBody |
Methods inherited from interface soot.toolkits.graph.DirectedGraph |
---|
getHeads, getPredsOf, getSuccsOf, getTails, iterator, size |
Field Detail |
---|
protected Map<Unit,List<Unit>> unitToUnexceptionalSuccs
protected Map<Unit,List<Unit>> unitToUnexceptionalPreds
protected Map<Unit,List<Unit>> unitToExceptionalSuccs
protected Map<Unit,List<Unit>> unitToExceptionalPreds
protected Map<Unit,Collection<ExceptionalUnitGraph.ExceptionDest>> unitToExceptionDests
protected ThrowAnalysis throwAnalysis
Constructor Detail |
---|
public ExceptionalUnitGraph(Body body, ThrowAnalysis throwAnalysis, boolean omitExceptingUnitEdges)
ThrowAnalysis
and omitExceptingUnitEdges
value that are passed as parameters.
body
- the Body
from which to build a graph.throwAnalysis
- the source of information about the exceptions
which each Unit
may throw.omitExceptingUnitEdges
- indicates whether the CFG should
omit edges to a handler from trapped
Unit
s 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 of
Unit
s which may implicitly throw
a caught exception regardless of the setting for
this parameter. If this parameter is
false
, there will also be
edges to the handler from all the
potentially excepting Unit
s
themselves. If this parameter is
true
, there will be edges to
the handler from the excepting
Unit
s themselves only if they
have potential side effects (or if they
are themselves the predecessors of other
potentially excepting Unit
s).
A setting of true
produces
CFGs which allow for more precise
analyses, since a Unit
without
side effects has no effect on the
computational state when it throws an
exception. Use settings of
false
for compatibility with
more conservative analyses, or to cater
to conservative bytecode verifiers.public ExceptionalUnitGraph(Body body, ThrowAnalysis throwAnalysis)
ThrowAnalysis
and a default value, provided by
the Options
class, for the
omitExceptingUnitEdges
parameter.
body
- the Body
from which to build a graph.throwAnalysis
- the source of information about the exceptions
which each Unit
may throw.public ExceptionalUnitGraph(Body body)
Scene
's default ThrowAnalysis
to estimate the
set of exceptions that each Unit
might throw and a
default value, provided by the Options
class, for the
omitExceptingUnitEdges
parameter.
body
- the Body
from which to build a graph.protected ExceptionalUnitGraph(Body body, boolean ignoredBogusParameter)
Allocates an ExceptionalUnitGraph
object
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 like
buildExceptionDests(ThrowAnalysis)
or buildExceptionalEdges(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 calling initialize(ThrowAnalysis, boolean)
, or otherwise performing
the initialization required to implement
ExceptionalUnitGraph
's interface.
Clients who opt to extend ExceptionalUnitGraph
should be warned that the class has not been carefully
designed for inheritance; code that uses the
protected
members of this class may need to be
rewritten for each new Soot release.
body
- the Body
from which to build a graph.ignoredBogusParameter
- a meaningless placeholder, which exists
solely to distinguish this
constructor from the public
ExceptionalUnitGraph(Body)
constructor.Method Detail |
---|
protected void initialize(ThrowAnalysis throwAnalysis, boolean omitExceptingUnitEdges)
ExceptionalUnitGraph
, 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.
throwAnalysis
- the source of information about the exceptions
which each Unit
may throw.omitExceptingUnitEdges
- indicates whether the CFG should
omit edges to a handler from trapped
Unit
s which may throw an
exception which the handler catches but
which have no potential side effects.protected Map<Unit,Collection<ExceptionalUnitGraph.ExceptionDest>> buildExceptionDests(ThrowAnalysis throwAnalysis)
Utility method used in the construction of
UnitGraph
variants which include exceptional control flow. It determines
which Unit
s may throw exceptions that would be caught
by Trap
s within the method.
throwAnalysis
- The source of information about which
exceptions each Unit
may throw.
null
if no Unit
s in the method throw
any exceptions caught within the method. Otherwise, a
Map
from Unit
s to Collection
s of ExceptionalUnitGraph.ExceptionDest
s.
The returned map has an idiosyncracy which is hidden
from most client code, but which is exposed to
subclasses extending ExceptionalUnitGraph
.
If a Unit
throws one or more exceptions
which are caught within the method, it will be mapped
to a Collection
of
ExceptionDest
s describing the sets of
exceptions that the Unit
might throw to
each Trap
. But if all of a Unit
's
exceptions escape the method, it will be mapped to
null
Collection containing a single
ExceptionDest
with a null
trap. (The special case for Unit
s with
no caught exceptions allows
buildExceptionDests()
to ignore completely
Unit
s which are outside the scope of all
Trap
s.)
protected Set<Unit> buildExceptionalEdges(ThrowAnalysis throwAnalysis, Map<Unit,Collection<ExceptionalUnitGraph.ExceptionDest>> unitToExceptionDests, Map<Unit,List<Unit>> unitToSuccs, Map<Unit,List<Unit>> unitToPreds, boolean omitExceptingUnitEdges)
throwAnalysis
- the source of information about the exceptions
which each Unit
may throw.unitToExceptionDests2
- A Map
from Unit
s to
Collection
s of ExceptionDest
s which represent the handlers
that might catch exceptions thrown by the
Unit
. This is an ``in
parameter''.unitToSuccs
- A Map
from Unit
s to
List
s of Unit
s. This is
an ``out parameter'';
buildExceptionalEdges
will add
a mapping from every Unit
in
the body that may throw an exception that
could be caught by a Trap
in the
body to a list of its exceptional
successors.unitToPreds
- A Map
from Unit
s to
List
s of
Unit
s. This is an ``out
parameter'';
buildExceptionalEdges
will add
a mapping from each handler unit that may
catch an exception to the list of
Unit
s whose exceptions it may
catch.omitExceptingUnitEdges
- Indicates whether to omit
exceptional edges from excepting units which
lack side effects
Set
of trap Unit
s that might catch
exceptions thrown by the first Unit
in the
Body
associated with the graph being
constructed. Such trap Unit
s may need to
be added to the list of heads (depending on your
definition of heads), since they can be the first
Unit
in the Body
which
actually completes execution.protected void buildHeadsAndTails() throws IllegalStateException
A placeholder that overrides UnitGraph.buildHeadsAndTails()
with a method which always throws an exception. The placeholder serves
to indicate that ExceptionalUnitGraph
does not use
buildHeadsAndTails()
, and to document the conditions under
which ExceptionalUnitGraph considers a node to be a head or
tail.
ExceptionalUnitGraph
defines the graph's set of
heads to include the first Unit
in the graph's body,
together with the first Unit
in any exception
handler which might catch an exception thrown by the first
Unit
in the body (because any of those
Unit
s might be the first to successfully complete
execution). ExceptionalUnitGraph
defines the
graph's set of tails to include all Unit
s which
represent some variety of return bytecode or an
athrow
bytecode whose argument might escape the
method.
buildHeadsAndTails
in class UnitGraph
IllegalStateException
public Collection<ExceptionalUnitGraph.ExceptionDest> getExceptionDests(Unit u)
ExceptionDest
objects which represent how exceptions thrown by a specified
unit will be handled.
getExceptionDests
in interface ExceptionalGraph<Unit>
u
- The unit for which to provide exception information.
(u
must be a Unit
, though the parameter is
declared as an Object
to satisfy the interface of
ExceptionalGraph
.
ExceptionDest
objects describing
the traps, if any, which catch the exceptions
which may be thrown by u
.public List<Unit> getUnexceptionalPredsOf(Unit u)
ExceptionalGraph
getUnexceptionalPredsOf
in interface ExceptionalGraph<Unit>
u
- The node whose predecessors are to be returned.
List
of the nodes in this graph from which
there is an unexceptional edge to n
.public List<Unit> getUnexceptionalSuccsOf(Unit u)
ExceptionalGraph
getUnexceptionalSuccsOf
in interface ExceptionalGraph<Unit>
u
- The node whose successors are to be returned.
List
of nodes in this graph to which
there is an unexceptional edge from n
.public List<Unit> getExceptionalPredsOf(Unit u)
ExceptionalGraph
getExceptionalPredsOf
in interface ExceptionalGraph<Unit>
u
- The node whose predecessors are to be returned.
List
of nodes in this graph from which
there is an exceptional edge to n
.public List<Unit> getExceptionalSuccsOf(Unit u)
ExceptionalGraph
getExceptionalSuccsOf
in interface ExceptionalGraph<Unit>
u
- The node whose successors are to be returned.
List
of nodes in this graph to which
there is an exceptional edge from n
.public String toString()
toString
in class UnitGraph
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |