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 CallGraph {
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 isCallable(MethodDescriptor md) {
32 return discovered.contains(md);
35 //Work our way down from main
36 private void buildGraph() {
37 MethodDescriptor main=tu.getMain();
38 HashSet tovisit=new HashSet();
41 Iterator it=state.getClassSymbolTable().getDescriptorsIterator();
44 ClassDescriptor cn=(ClassDescriptor)it.next();
45 Iterator methodit=cn.getMethods();
46 //Iterator through methods
47 while(methodit.hasNext()) {
48 MethodDescriptor md=(MethodDescriptor)methodit.next();
49 if (md.isStaticBlock()) {
57 while(!tovisit.isEmpty()) {
58 MethodDescriptor md=(MethodDescriptor)tovisit.iterator().next();
60 FlatMethod fm=state.getMethodFlat(md);
63 analyzeMethod(md, fm);
64 for(Iterator<FlatNode> fnit=fm.getNodeSet().iterator();fnit.hasNext();) {
65 FlatNode fn=fnit.next();
66 if (fn.kind()==FKind.FlatCall) {
67 FlatCall fcall=(FlatCall)fn;
68 Set callees=fcall.getThis()==null?getMethods(fcall.getMethod()):getMethods(fcall.getMethod(),fcall.getThis().getType());
70 if (fcall.getThis()!=null) {
71 MethodDescriptor methodd=fcall.getMethod();
73 if (methodd.getClassDesc()==tu.getClass(TypeUtil.ThreadClass)&&
74 methodd.getSymbol().equals("start")&&methodd.numParameters()==0&&!methodd.getModifiers().isStatic()) {
76 HashSet ns=new HashSet();
78 ns.addAll(getMethods(tu.getRun(), fcall.getThis().getType()));
79 ns.addAll(getMethods(tu.getStaticStart(), fcall.getThis().getType()));
84 for(Iterator mdit=callees.iterator();mdit.hasNext();) {
85 MethodDescriptor callee=(MethodDescriptor)mdit.next();
86 if (!discovered.contains(callee)) {
87 discovered.add(callee);