1 salcianu 1.1.2.1 // MetaCallGraph.java, created Mon Mar 13 15:53:31 2000 by salcianu 2 cananian 1.1.2.7 // Copyright (C) 2000 Alexandru SALCIANU <salcianu@retezat.lcs.mit.edu> 3 salcianu 1.1.2.1 // Licensed under the terms of the GNU GPL; see COPYING for details. 4 salcianu 1.1.2.1 package harpoon.Analysis.MetaMethods; 5 salcianu 1.1.2.1 6 salcianu 1.1.2.1 import java.util.Set; 7 salcianu 1.1.2.1 8 salcianu 1.3 import java.io.PrintStream; 9 salcianu 1.1.2.2 10 salcianu 1.1.2.1 import harpoon.IR.Quads.CALL; 11 salcianu 1.1.2.6 12 salcianu 1.1.2.6 import harpoon.Util.DataStructs.Relation; 13 salcianu 1.1.2.6 import harpoon.Util.DataStructs.LightRelation; 14 salcianu 1.1.2.6 import harpoon.Util.DataStructs.RelationEntryVisitor; 15 salcianu 1.1.2.6 16 salcianu 1.4 import harpoon.Util.Graphs.SCComponent; 17 salcianu 1.4 import harpoon.Util.Graphs.Navigator; 18 salcianu 1.6 import harpoon.Util.Graphs.ForwardNavigator; 19 salcianu 1.5 import harpoon.Util.Graphs.DiGraph; 20 salcianu 1.1.2.1 21 salcianu 1.1.2.1 /** 22 salcianu 1.1.2.1 * <code>MetaCallGraph</code> is for meta methods what <code>callGraph</code> 23 salcianu 1.1.2.1 is for "normal" methods. It provides information on what meta 24 salcianu 1.1.2.1 methods are called by a given meta method [at a specific call site]. 25 salcianu 1.1.2.1 * 26 cananian 1.1.2.7 * @author Alexandru SALCIANU <salcianu@retezat.lcs.mit.edu> 27 salcianu 1.7 * @version $Id: MetaCallGraph.java,v 1.7 2004/03/04 22:32:15 salcianu Exp $ 28 salcianu 1.1.2.1 */ 29 salcianu 1.1.2.1 30 salcianu 1.5 public abstract class MetaCallGraph extends DiGraph/*<MetaMethod>*/ 31 salcianu 1.5 implements java.io.Serializable { 32 salcianu 1.1.2.1 33 salcianu 1.1.2.1 /** Returns the meta methods that can be called by <code>mm</code>. */ 34 salcianu 1.4 public abstract MetaMethod[] getCallees(MetaMethod mm); 35 salcianu 1.1.2.1 36 salcianu 1.1.2.1 /** Returns the meta methods that can be called by <code>mm</code> 37 salcianu 1.1.2.1 at the call site <code>q</code>. */ 38 salcianu 1.4 public abstract MetaMethod[] getCallees(MetaMethod mm, CALL cs); 39 salcianu 1.1.2.1 40 salcianu 1.1.2.1 /** Returns the set of all the call sites in the code of the meta-method 41 salcianu 1.1.2.1 <code>mm</code>. */ 42 salcianu 1.4 public abstract Set getCallSites(MetaMethod mm); 43 salcianu 1.1.2.1 44 salcianu 1.1.2.1 /** Returns the set of all the meta methods that might be called during the 45 salcianu 1.1.2.1 execution of the program. */ 46 salcianu 1.4 public abstract Set getAllMetaMethods(); 47 salcianu 1.1.2.3 48 salcianu 1.1.2.3 /** Returns the set of all the meta methods that might be called, directly 49 salcianu 1.1.2.3 or indirectly, by the meta method <code>mm</code>. It's just the 50 salcianu 1.1.2.3 transitive closure of the <code>getCallees</code> method. */ 51 salcianu 1.4 public abstract Set getTransCallees(MetaMethod mm); 52 salcianu 1.1.2.1 53 salcianu 1.1.2.2 /** Computes the <i>split</i> relation. This is a <code>Relation</code> 54 salcianu 1.1.2.2 that associates to each <code>HMethod</code> the set of 55 salcianu 1.1.2.2 <code>MetaMethod</code>s specialized from it. */ 56 salcianu 1.4 public abstract Relation getSplitRelation(); 57 salcianu 1.1.2.2 58 salcianu 1.1.2.4 /** Returns the set of the meta-methods that could be called as the 59 salcianu 1.1.2.4 body of some thread. */ 60 salcianu 1.4 public abstract Set getRunMetaMethods(); 61 salcianu 1.1.2.4 62 salcianu 1.1.2.2 /** Nice pretty-printer for debug purposes. */ 63 salcianu 1.4 public abstract void print(PrintStream ps, boolean detailed_view, 64 salcianu 1.4 MetaMethod root); 65 salcianu 1.4 66 salcianu 1.7 public Set/*<MetaMethod>*/ getRoots() { 67 salcianu 1.5 // we conservatively return all meta-methods 68 salcianu 1.5 return getAllMetaMethods(); 69 salcianu 1.5 } 70 salcianu 1.5 71 salcianu 1.4 /** Returns a bi-directional top-down graph navigator through 72 salcianu 1.6 <code>this</code> meta-callgraph. Complexity: BIG; at least 73 salcianu 1.6 linear in the number of nodes and edges in the call graph. 74 salcianu 1.6 Therefore, we cache its result internally. */ 75 salcianu 1.7 public Navigator/*<MetaMethod>*/ getNavigator() { 76 salcianu 1.6 if(navigator == null) { 77 salcianu 1.6 final MetaAllCallers mac = new MetaAllCallers(this); 78 salcianu 1.6 navigator = new Navigator/*<MetaMethod>*/() { 79 salcianu 1.6 public Object[] next(Object node) { 80 salcianu 1.6 return getCallees((MetaMethod) node); 81 salcianu 1.6 } 82 salcianu 1.6 public Object[] prev(Object node) { 83 salcianu 1.6 return mac.getCallers((MetaMethod) node); 84 salcianu 1.6 } 85 salcianu 1.6 }; 86 salcianu 1.6 } 87 salcianu 1.6 return navigator; 88 salcianu 1.6 } 89 salcianu 1.6 protected Navigator navigator = null; 90 salcianu 1.6 91 salcianu 1.6 92 salcianu 1.6 /** Returns a forward-only navigator through <code>this</code> 93 salcianu 1.6 meta-callgraph. Complexity: O(1).*/ 94 salcianu 1.7 public ForwardNavigator/*<MetaMethod>*/ getForwardNavigator() { 95 salcianu 1.6 return new ForwardNavigator/*<MetaMethod>*/() { 96 salcianu 1.4 public Object[] next(Object node) { 97 salcianu 1.4 return getCallees((MetaMethod) node); 98 salcianu 1.4 } 99 salcianu 1.4 }; 100 salcianu 1.4 } 101 cananian 1.2 }