joeq.Compiler.Quad
Class CallGraph

java.lang.Object
  extended by java.util.AbstractMap
      extended by jwutil.collections.UnmodifiableMultiMap
          extended by joeq.Compiler.Quad.CallGraph
All Implemented Interfaces:
Map, jwutil.collections.BinaryRelation, jwutil.collections.MultiMap, jwutil.graphs.Graph
Direct Known Subclasses:
CachedCallGraph, CHACallGraph, FilteredCallGraph, LoadedCallGraph, PACallGraph, PrimitivePACallGraph

public abstract class CallGraph
extends jwutil.collections.UnmodifiableMultiMap
implements jwutil.graphs.Graph

Abstract representation of a call graph.

Version:
$Id: CallGraph.java 2238 2005-03-21 05:01:17Z joewhaley $
Author:
John Whaley

Nested Class Summary
 class CallGraph.CallGraphCSNavigator
           
static class CallGraph.CallGraphMap
           
 class CallGraph.CallGraphMethodNavigator
           
static class CallGraph.CallSiteMap
           
 class CallGraph.CallTargetMap
           
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
 
Fields inherited from class jwutil.collections.UnmodifiableMultiMap
DEFAULT_HISTOGRAM_SIZE
 
Constructor Summary
CallGraph()
           
 
Method Summary
 Map calculateCallerRelation()
          Calculate a multimap between methods and their callers.
 jwutil.collections.InvertibleMultiMap calculateEdgeRelation()
          Returns the call graph edge relation in the form of an invertible multi-map.
 Set calculateReachableMethods(Collection roots)
          Returns the set of methods that are reachable from the given method root set.
 boolean contains(Object a, Object b)
           
 Set entrySet()
           
 Collection[] findDepths()
           
 Collection getAllCallSites()
          Returns the collection of all call sites in the call graph.
 Collection getAllMethods()
          Returns the collection of all methods in the call graph.
 Collection getCallees(ControlFlowGraph cfg)
          Returns the set of methods that are called by the given CFG.
 Collection getCallees(jq_Method caller)
          Returns the set of methods that are called by the given method.
 Collection getCallerMethods(jq_Method callee)
          Returns the set of methods that can call the given method.
 Collection getCallers(jq_Method callee)
          Returns the set of call sites that can call the given method.
 jwutil.collections.MultiMap getCallGraphMap()
           
 jwutil.collections.MultiMap getCallSiteMap()
           
 jwutil.graphs.Navigator getCallSiteNavigator()
           
 Collection getCallSites(ControlFlowGraph cfg)
          Returns the set of call sites in the given CFG.
 Collection getCallSites(jq_Method caller)
          Returns the set of call sites in the given method.
static Collection getCallSites0(ControlFlowGraph cfg)
           
static Collection getCallSites0(jq_Method caller)
           
static Collection getCallSites1(ControlFlowGraph cfg)
           
 jwutil.graphs.Navigator getMethodNavigator()
           
 jwutil.graphs.Navigator getNavigator()
           
abstract  Collection getRoots()
          Returns the collection of root methods for this call graph.
 jq_Method getTargetMethod(Object context, ProgramLocation callSite)
          Returns the target method of the given call site under the given context, assuming that it is a single target.
abstract  Collection getTargetMethods(Object context, ProgramLocation callSite)
          Returns the possible target methods of the given call site under the given context.
 Collection getTargetMethods(ProgramLocation callSite)
          Returns the possible target methods of the given call site.
 Collection getValues(Object key)
           
static CallGraph makeCallGraph(Collection rootMethods, Map callsToTargets)
           
 int numberOfTargetMethods(Object context, ProgramLocation callSite)
          Returns the number of possible target methods of the given call site under the given context.
 int numberOfTargetMethods(ProgramLocation callSite)
          Returns the number of possible target methods of the given call site.
abstract  void setRoots(Collection roots)
          Sets up the root methods to be the given set.
 String toString()
          Returns a string representation of this call graph.
 
Methods inherited from class jwutil.collections.UnmodifiableMultiMap
add, addAll, addAll, clear, computeHistogram, computeHistogram, entrySetHelper, proxy, put, putAll, remove, remove, removeAll, retainAll
 
Methods inherited from class java.util.AbstractMap
clone, containsKey, containsValue, equals, get, hashCode, isEmpty, keySet, size, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface jwutil.collections.MultiMap
get, size
 
Methods inherited from interface java.util.Map
containsKey, containsValue, equals, hashCode, isEmpty, keySet, values
 

Constructor Detail

CallGraph

public CallGraph()
Method Detail

setRoots

public abstract void setRoots(Collection roots)
Sets up the root methods to be the given set. Later call graph queries use the value that you pass in here. Implementing this method is optional -- it is only necessary if you use methods that require a root set, like getReachableMethods().

Parameters:
roots - collection of root methods

getRoots

public abstract Collection getRoots()
Returns the collection of root methods for this call graph.

Specified by:
getRoots in interface jwutil.graphs.Graph

getAllMethods

public Collection getAllMethods()
Returns the collection of all methods in the call graph. The default implementation recalculates the reachable methods based on the root set.

Returns:
Collection of all call sites in the call graph

getAllCallSites

public Collection getAllCallSites()
Returns the collection of all call sites in the call graph. The default implementation just iterates through all of the methods to build up the collection.

Returns:
Collection of all call sites in the call graph

getTargetMethods

public abstract Collection getTargetMethods(Object context,
                                            ProgramLocation callSite)
Returns the possible target methods of the given call site under the given context. The interpretation of the context object is specific to the type of call graph.

Parameters:
context -
callSite -
Returns:
Collection of jq_Methods that are the possible targets

getTargetMethods

public Collection getTargetMethods(ProgramLocation callSite)
Returns the possible target methods of the given call site.

Parameters:
callSite -
Returns:
Collection of jq_Methods that are the possible targets

numberOfTargetMethods

public int numberOfTargetMethods(Object context,
                                 ProgramLocation callSite)
Returns the number of possible target methods of the given call site under the given context. The interpretation of the context object is specific to the type of call graph.

Parameters:
context -
callSite -
Returns:
number of possible targets

numberOfTargetMethods

public int numberOfTargetMethods(ProgramLocation callSite)
Returns the number of possible target methods of the given call site.

Parameters:
callSite -
Returns:
number of possible targets

getTargetMethod

public jq_Method getTargetMethod(Object context,
                                 ProgramLocation callSite)
Returns the target method of the given call site under the given context, assuming that it is a single target. The interpretation of the context object is specific to the type of call graph.

Parameters:
context -
callSite -
Returns:
target method

getCallSites

public Collection getCallSites(jq_Method caller)
Returns the set of call sites in the given method.

Parameters:
caller -
Returns:
set of call sites

getCallSites0

public static Collection getCallSites0(jq_Method caller)

getCallSites

public Collection getCallSites(ControlFlowGraph cfg)
Returns the set of call sites in the given CFG.

Parameters:
cfg -
Returns:
set of call sites

getCallSites0

public static Collection getCallSites0(ControlFlowGraph cfg)

getCallSites1

public static Collection getCallSites1(ControlFlowGraph cfg)

getCallees

public Collection getCallees(jq_Method caller)
Returns the set of methods that are called by the given method.

Parameters:
caller -
Returns:
set of callee methods

getCallees

public Collection getCallees(ControlFlowGraph cfg)
Returns the set of methods that are called by the given CFG.

Parameters:
cfg -
Returns:
set of callee methods

getCallers

public Collection getCallers(jq_Method callee)
Returns the set of call sites that can call the given method.

Parameters:
callee -
Returns:
set of callers

getCallerMethods

public Collection getCallerMethods(jq_Method callee)
Returns the set of methods that can call the given method.

Parameters:
callee -
Returns:
set of caller methods

calculateReachableMethods

public Set calculateReachableMethods(Collection roots)
Returns the set of methods that are reachable from the given method root set.

Parameters:
roots -
Returns:
set of reachable methods

toString

public String toString()
Returns a string representation of this call graph.

Overrides:
toString in class AbstractMap

calculateCallerRelation

public Map calculateCallerRelation()
Calculate a multimap between methods and their callers.


calculateEdgeRelation

public jwutil.collections.InvertibleMultiMap calculateEdgeRelation()
Returns the call graph edge relation in the form of an invertible multi-map. The edge relation contains both the relations between methods and their call sites and between call sites and their target methods.

Returns:
set of caller methods

findDepths

public Collection[] findDepths()

getNavigator

public jwutil.graphs.Navigator getNavigator()
Specified by:
getNavigator in interface jwutil.graphs.Graph

getMethodNavigator

public jwutil.graphs.Navigator getMethodNavigator()

getCallSiteNavigator

public jwutil.graphs.Navigator getCallSiteNavigator()

getCallSiteMap

public jwutil.collections.MultiMap getCallSiteMap()

getCallGraphMap

public jwutil.collections.MultiMap getCallGraphMap()

entrySet

public Set entrySet()
Specified by:
entrySet in interface Map
Specified by:
entrySet in interface jwutil.collections.MultiMap
Specified by:
entrySet in class jwutil.collections.UnmodifiableMultiMap

contains

public boolean contains(Object a,
                        Object b)
Specified by:
contains in interface jwutil.collections.BinaryRelation
Specified by:
contains in interface jwutil.collections.MultiMap

getValues

public Collection getValues(Object key)
Specified by:
getValues in interface jwutil.collections.MultiMap

makeCallGraph

public static CallGraph makeCallGraph(Collection rootMethods,
                                      Map callsToTargets)


Copyright © 2001-2008 John Whaley. All Rights Reserved.