3 import Analysis.Locality.LocalityBinding;
4 import Analysis.Locality.LocalityAnalysis;
8 LocalityAnalysis locality;
9 Hashtable<MethodDescriptor, Integer> methodnumber;
10 Hashtable<ClassDescriptor, Integer> classmethodcount;
11 Hashtable<LocalityBinding, Integer> localitynumber;
13 public int getMethodNumber(MethodDescriptor md) {
14 return methodnumber.get(md).intValue();
17 public int getMethodCount(ClassDescriptor md) {
18 return classmethodcount.get(md).intValue();
21 public int getLocalityNumber(LocalityBinding lb) {
22 return localitynumber.get(lb).intValue();
25 public Virtual(State state, LocalityAnalysis locality) {
27 this.locality=locality;
28 classmethodcount=new Hashtable<ClassDescriptor, Integer>();
30 localitynumber=new Hashtable<LocalityBinding, Integer>();
32 methodnumber=new Hashtable<MethodDescriptor, Integer>();
36 private void doAnalysis() {
37 Iterator classit=state.getClassSymbolTable().getDescriptorsIterator();
38 while(classit.hasNext()) {
39 ClassDescriptor cd=(ClassDescriptor)classit.next();
47 private int numberLocality(ClassDescriptor cd) {
48 if (classmethodcount.containsKey(cd))
49 return classmethodcount.get(cd).intValue();
50 ClassDescriptor superdesc=cd.getSuperDesc();
53 start=numberLocality(superdesc);
55 if (locality.getClassBindings(cd)!=null)
56 for(Iterator<LocalityBinding> lbit=locality.getClassBindings(cd).iterator();lbit.hasNext();) {
57 LocalityBinding lb=lbit.next();
58 MethodDescriptor md=lb.getMethod();
59 //Is it a static method or constructor
60 if (md.isStatic()||md.getReturnType()==null)
63 if (superdesc!=null) {
64 Set possiblematches=superdesc.getMethodTable().getSet(md.getSymbol());
65 boolean foundmatch=false;
66 for(Iterator matchit=possiblematches.iterator();matchit.hasNext();) {
67 MethodDescriptor matchmd=(MethodDescriptor)matchit.next();
68 if (md.matches(matchmd)) {
69 Set<LocalityBinding> lbset=locality.getMethodBindings(matchmd);
71 for(Iterator<LocalityBinding> suplbit=lbset.iterator();suplbit.hasNext();) {
72 LocalityBinding suplb=suplbit.next();
73 if (lb.contextMatches(suplb)) {
75 localitynumber.put(lb, localitynumber.get(suplb));
83 localitynumber.put(lb, new Integer(start++));
85 localitynumber.put(lb, new Integer(start++));
88 classmethodcount.put(cd, new Integer(start));
92 private int numberMethods(ClassDescriptor cd) {
93 if (classmethodcount.containsKey(cd))
94 return classmethodcount.get(cd).intValue();
95 ClassDescriptor superdesc=cd.getSuperDesc();
98 start=numberMethods(superdesc);
99 for(Iterator it=cd.getMethods();it.hasNext();) {
100 MethodDescriptor md=(MethodDescriptor)it.next();
101 if (md.isStatic()||md.getReturnType()==null)
103 if (superdesc!=null) {
104 Set possiblematches=superdesc.getMethodTable().getSet(md.getSymbol());
105 boolean foundmatch=false;
106 for(Iterator matchit=possiblematches.iterator();matchit.hasNext();) {
107 MethodDescriptor matchmd=(MethodDescriptor)matchit.next();
108 if (md.matches(matchmd)) {
109 int num=((Integer)methodnumber.get(matchmd)).intValue();
110 methodnumber.put(md, new Integer(num));
116 methodnumber.put(md, new Integer(start++));
118 methodnumber.put(md, new Integer(start++));
121 classmethodcount.put(cd, new Integer(start));