Class CallGraph
- java.lang.Object
-
- proguard.analysis.datastructure.callgraph.CallGraph
-
public class CallGraph extends java.lang.ObjectCollection of allCalls in a program, optimized for retrieval of incoming and outgoing edges for any method in constant time.
-
-
Field Summary
Fields Modifier and Type Field Description java.util.Map<MethodSignature,java.util.Set<Call>>incomingjava.util.Map<MethodSignature,java.util.Set<Call>>outgoing
-
Constructor Summary
Constructors Modifier Constructor Description CallGraph()Create an empty call graph.protectedCallGraph(java.util.Map<MethodSignature,java.util.Set<Call>> incoming, java.util.Map<MethodSignature,java.util.Set<Call>> outgoing, boolean concurrent)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddCall(Call call)Add aCallto this call graph.voidclear()Clear the call graph references.static CallGraphconcurrentCallGraph()NodereconstructCallGraph(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:NodereconstructCallGraph(ClassPool programClassPool, MethodSignature start, java.util.Set<MethodSignature> stopMethods)NodereconstructCallGraph(ClassPool programClassPool, MethodSignature start, java.util.Set<MethodSignature> stopMethods, java.util.Set<MethodSignature> reachedMethods)Extension ofreconstructCallGraph(ClassPool, MethodSignature, Set)that also collects all reached stop methods.
-
-
-
Field Detail
-
incoming
public final java.util.Map<MethodSignature,java.util.Set<Call>> incoming
-
outgoing
public final java.util.Map<MethodSignature,java.util.Set<Call>> outgoing
-
-
Constructor Detail
-
CallGraph
public CallGraph()
Create an empty call graph.
-
CallGraph
protected CallGraph(java.util.Map<MethodSignature,java.util.Set<Call>> incoming, java.util.Map<MethodSignature,java.util.Set<Call>> outgoing, boolean concurrent)
-
-
Method Detail
-
concurrentCallGraph
public static CallGraph concurrentCallGraph()
Provides concurrency readyCallGraph, backed byConcurrentHashMaps and bysynchronizedSets. Not needed without multithreading.
-
addCall
public void addCall(Call call)
Add aCallto this call graph.- Parameters:
call- The call to be added.
-
clear
public void clear()
Clear the call graph references.
-
reconstructCallGraph
public Node reconstructCallGraph(ClassPool programClassPool, MethodSignature start, java.util.Set<MethodSignature> stopMethods)
- Parameters:
programClassPool- The currentClassPoolof the program that can be used for mapping. class names to the actualClazz.start- TheMethodSignatureof the method whose incoming call graph should be calculated.stopMethods- Set ofMethodSignatureto stop exploration at, if desired.- Returns:
- A
Nodethat represents the single call graph root, i.e. the start method.
-
reconstructCallGraph
public 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:We have an inverted tree structure like the following example:
Here,onCreate() <-- predecessor -- proxy() <-- predecessor -- root() onResume() <-- predecessor ----| | unusedMethod() <-- predecessor -------|root()is the method whose call graph is to be calculated, and the graph now shows that it can be reached fromonCreate()viaproxy(), and also directly fromonResume()orunusedMethod().- Parameters:
programClassPool- The currentClassPoolof the program that can be used for mapping. class names to the actualClazz.start- TheMethodSignatureof the method whose incoming call graph should be calculated.maxDepth- maximal depth of reconstructedCallGraphsimilar toCallGraphWalker.MAX_DEPTH_DEFAULT.maxWidth- maximal width of reconstructedCallGraphsimilar toCallGraphWalker.MAX_WIDTH_DEFAULT.stopMethods- Set of method signatures to stop exploration, for example for entry points- Returns:
- A
Nodethat represents the single call graph root, i.e. the start method.
-
reconstructCallGraph
public Node reconstructCallGraph(ClassPool programClassPool, MethodSignature start, java.util.Set<MethodSignature> stopMethods, java.util.Set<MethodSignature> reachedMethods)
Extension ofreconstructCallGraph(ClassPool, MethodSignature, Set)that also collects all reached stop methods.- Parameters:
programClassPool- The currentClassPoolof the program that can be used for mapping.start- TheMethodSignatureof the method whose incoming call graph should be calculated.stopMethods- A set ofMethodSignatureto stop exploration, e.g. app entry pointsreachedMethods- A set that will be filled with all reached stop methods- Returns:
- A
Nodethat represents the single call graph root, i.e. the start method.
-
-