public class CallGraph
extends java.lang.Object
Call
s in a program, optimized for retrieval of incoming and outgoing
edges for any method in constant time.Modifier and Type | Field and Description |
---|---|
java.util.Map<MethodSignature,java.util.Set<Call>> |
incoming |
java.util.Map<MethodSignature,java.util.Set<Call>> |
outgoing |
Modifier | Constructor and Description |
---|---|
|
CallGraph()
Create an empty call graph.
|
protected |
CallGraph(java.util.Map<MethodSignature,java.util.Set<Call>> incoming,
java.util.Map<MethodSignature,java.util.Set<Call>> outgoing,
boolean concurrent) |
Modifier and Type | Method and Description |
---|---|
void |
addCall(Call call)
Add a
Call to this call graph. |
void |
clear()
Clear the call graph references.
|
static CallGraph |
concurrentCallGraph()
|
Node |
reconstructCallGraph(ClassPool programClassPool,
MethodSignature start,
int maxDepth,
int maxWidth,
java.util.Set<MethodSignature> stopMethods)
Calculate the incoming call graph for a method of interest, showing how it can be reached from
a given Set of stop methods, which typically are Android lifecycle methods such as an
Activity's onCreate() method:
|
Node |
reconstructCallGraph(ClassPool programClassPool,
MethodSignature start,
java.util.Set<MethodSignature> stopMethods)
|
Node |
reconstructCallGraph(ClassPool programClassPool,
MethodSignature start,
java.util.Set<MethodSignature> stopMethods,
java.util.Set<MethodSignature> reachedMethods)
Extension of
reconstructCallGraph(ClassPool, MethodSignature, Set) that also collects
all reached stop methods. |
public final java.util.Map<MethodSignature,java.util.Set<Call>> incoming
public final java.util.Map<MethodSignature,java.util.Set<Call>> outgoing
public CallGraph()
protected CallGraph(java.util.Map<MethodSignature,java.util.Set<Call>> incoming, java.util.Map<MethodSignature,java.util.Set<Call>> outgoing, boolean concurrent)
public static CallGraph concurrentCallGraph()
CallGraph
, backed by ConcurrentHashMap
s and by
synchronizedSet
s. Not needed without multithreading.public void addCall(Call call)
Call
to this call graph.call
- The call to be added.public void clear()
public Node reconstructCallGraph(ClassPool programClassPool, MethodSignature start, java.util.Set<MethodSignature> stopMethods)
programClassPool
- The current ClassPool
of the program that can be used for
mapping. class names to the actual Clazz
.start
- The MethodSignature
of the method whose incoming call graph should be
calculated.stopMethods
- Set of MethodSignature
to stop exploration at, if desired.Node
that represents the single call graph root, i.e. the start method.public Node reconstructCallGraph(ClassPool programClassPool, MethodSignature start, int maxDepth, int maxWidth, java.util.Set<MethodSignature> stopMethods)
We have an inverted tree structure like the following example:
onCreate() <-- predecessor -- proxy() <-- predecessor -- root()
onResume() <-- predecessor ----| |
unusedMethod() <-- predecessor -------|
Here, root()
is the method whose call graph is to be calculated, and the graph now
shows that it can be reached from onCreate()
via proxy()
, and also directly
from onResume()
or unusedMethod()
.programClassPool
- The current ClassPool
of the program that can be used for
mapping. class names to the actual Clazz
.start
- The MethodSignature
of the method whose incoming call graph should be
calculated.maxDepth
- maximal depth of reconstructed CallGraph
similar to CallGraphWalker.MAX_DEPTH_DEFAULT
.maxWidth
- maximal width of reconstructed CallGraph
similar to CallGraphWalker.MAX_WIDTH_DEFAULT
.stopMethods
- Set of method signatures to stop exploration, for example for entry pointsNode
that represents the single call graph root, i.e. the start method.public Node reconstructCallGraph(ClassPool programClassPool, MethodSignature start, java.util.Set<MethodSignature> stopMethods, java.util.Set<MethodSignature> reachedMethods)
reconstructCallGraph(ClassPool, MethodSignature, Set)
that also collects
all reached stop methods.programClassPool
- The current ClassPool
of the program that can be used for
mapping.start
- The MethodSignature
of the method whose incoming call graph should be
calculated.stopMethods
- A set of MethodSignature
to stop exploration, e.g. app entry pointsreachedMethods
- A set that will be filled with all reached stop methodsNode
that represents the single call graph root, i.e. the start method.