1 package Analysis.CallGraph;
3 import IR.Flat.FlatMethod;
4 import IR.Flat.FlatNode;
5 import IR.Flat.FlatCall;
8 import IR.ClassDescriptor;
9 import IR.MethodDescriptor;
10 import IR.TaskDescriptor;
11 import IR.TypeDescriptor;
16 public class JavaCallGraph extends BaseCallGraph {
20 public JavaCallGraph(State state, TypeUtil tu) {
22 mapVirtual2ImplementationSet = new Hashtable();
23 mapCaller2CalleeSet = new Hashtable();
24 mapCallee2CallerSet = new Hashtable();
25 discovered=new HashSet();
31 public boolean isCalled(MethodDescriptor md) {
35 public boolean isCallable(MethodDescriptor md) {
36 return discovered.contains(md);
39 //Work our way down from main
40 private void buildGraph() {
41 MethodDescriptor main=tu.getMain();
42 HashSet tovisit=new HashSet();
45 Iterator it=state.getClassSymbolTable().getDescriptorsIterator();
48 ClassDescriptor cn=(ClassDescriptor)it.next();
49 Iterator methodit=cn.getMethods();
50 //Iterator through methods
51 while(methodit.hasNext()) {
52 MethodDescriptor md=(MethodDescriptor)methodit.next();
53 if (md.isStaticBlock()) {
61 while(!tovisit.isEmpty()) {
62 MethodDescriptor md=(MethodDescriptor)tovisit.iterator().next();
64 FlatMethod fm=state.getMethodFlat(md);
67 analyzeMethod(md, fm);
68 for(Iterator<FlatNode> fnit=fm.getNodeSet().iterator(); fnit.hasNext(); ) {
69 FlatNode fn=fnit.next();
70 if (fn.kind()==FKind.FlatCall) {
71 FlatCall fcall=(FlatCall)fn;
72 Set callees=fcall.getThis()==null?getMethods(fcall.getMethod()):getMethods(fcall.getMethod(),fcall.getThis().getType());
74 if (fcall.getThis()!=null) {
75 MethodDescriptor methodd=fcall.getMethod();
77 if (methodd.getClassDesc()==tu.getClass(TypeUtil.ThreadClass)&&
78 methodd.getSymbol().equals("start")&&methodd.numParameters()==0&&!methodd.getModifiers().isStatic()) {
80 HashSet ns=new HashSet();
82 ns.addAll(getMethods(tu.getRun(), fcall.getThis().getType()));
83 ns.addAll(getMethods(tu.getStaticStart(), fcall.getThis().getType()));
88 for(Iterator mdit=callees.iterator(); mdit.hasNext(); ) {
89 MethodDescriptor callee=(MethodDescriptor)mdit.next();
90 if (!discovered.contains(callee)) {
91 discovered.add(callee);