public class ControlFlowGraph
extends java.lang.Object
It also adds edges for abnormal control flow, such as the possibility of a method call throwing a runtime exception.
Modifier and Type | Class and Description |
---|---|
static class |
ControlFlowGraph.Node
A
ControlFlowGraph.Node is a node in the control flow graph for a method, pointing to
the instruction and its possible successors |
Constructor and Description |
---|
ControlFlowGraph() |
Modifier and Type | Method and Description |
---|---|
protected void |
add(org.objectweb.asm.tree.AbstractInsnNode from,
org.objectweb.asm.tree.AbstractInsnNode to)
Adds an exception flow to this graph
|
static ControlFlowGraph |
create(ControlFlowGraph initial,
org.objectweb.asm.tree.ClassNode classNode,
org.objectweb.asm.tree.MethodNode method)
Creates a new
ControlFlowGraph and populates it with the flow
control for the given method. |
protected void |
exception(org.objectweb.asm.tree.AbstractInsnNode from,
org.objectweb.asm.tree.AbstractInsnNode to)
Adds an exception flow to this graph
|
protected void |
exception(org.objectweb.asm.tree.AbstractInsnNode from,
org.objectweb.asm.tree.TryCatchBlockNode tcb)
Adds an exception try block node to this graph
|
ControlFlowGraph.Node |
getNode(org.objectweb.asm.tree.AbstractInsnNode instruction)
Looks up (and if necessary) creates a graph node for the given instruction
|
boolean |
isConnected(org.objectweb.asm.tree.AbstractInsnNode from,
org.objectweb.asm.tree.AbstractInsnNode to)
Checks whether there is a path from the given instruction to the given
instruction node
|
boolean |
isConnected(ControlFlowGraph.Node from,
ControlFlowGraph.Node to)
Checks whether there is a path from the given source node to the given
destination node
|
java.lang.String |
toDot(java.util.Set<ControlFlowGraph.Node> highlight)
Generates dot output of the graph.
|
java.lang.String |
toString() |
java.lang.String |
toString(ControlFlowGraph.Node start)
Creates a human readable version of the graph
|
@NonNull public static ControlFlowGraph create(@Nullable ControlFlowGraph initial, @NonNull org.objectweb.asm.tree.ClassNode classNode, @NonNull org.objectweb.asm.tree.MethodNode method) throws org.objectweb.asm.tree.analysis.AnalyzerException
ControlFlowGraph
and populates it with the flow
control for the given method. If the optional initial
parameter is
provided with an existing graph, then the graph is simply populated, not
created. This allows subclassing of the graph instance, if necessary.initial
- usually null, but can point to an existing instance of a
ControlFlowGraph
in which that graph is reused (but
populated with new edges)classNode
- the class containing the method to be analyzedmethod
- the method to be analyzedControlFlowGraph
with nodes for the control flow in the
given methodorg.objectweb.asm.tree.analysis.AnalyzerException
- if the underlying bytecode library is unable to
analyze the method bytecodepublic boolean isConnected(@NonNull ControlFlowGraph.Node from, @NonNull ControlFlowGraph.Node to)
public boolean isConnected(@NonNull org.objectweb.asm.tree.AbstractInsnNode from, @NonNull org.objectweb.asm.tree.AbstractInsnNode to)
protected void add(@NonNull org.objectweb.asm.tree.AbstractInsnNode from, @NonNull org.objectweb.asm.tree.AbstractInsnNode to)
protected void exception(@NonNull org.objectweb.asm.tree.AbstractInsnNode from, @NonNull org.objectweb.asm.tree.AbstractInsnNode to)
protected void exception(@NonNull org.objectweb.asm.tree.AbstractInsnNode from, @NonNull org.objectweb.asm.tree.TryCatchBlockNode tcb)
@NonNull public ControlFlowGraph.Node getNode(@NonNull org.objectweb.asm.tree.AbstractInsnNode instruction)
instruction
- the instruction@NonNull public java.lang.String toString(@Nullable ControlFlowGraph.Node start)
start
- the starting instruction, or null if not known or to use the
first instructionpublic java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toDot(@Nullable java.util.Set<ControlFlowGraph.Node> highlight)
$ dot -Tps graph1.gv -o graph1.psto generate a postscript file, which you can then view with "gv graph1.ps". (There are also some online web sites where you can paste in dot graphs and see the visualization right there in the browser.)