3 import Analysis.Locality.LocalityBinding;
4 import Analysis.Locality.LocalityAnalysis;
9 LocalityAnalysis locality;
10 Hashtable<MethodDescriptor, Integer> methodnumber;
11 Hashtable<ClassDescriptor, Integer> classmethodcount;
12 Hashtable<LocalityBinding, Integer> localitynumber;
14 public int getMethodNumber(MethodDescriptor md) {
15 return methodnumber.get(md).intValue();
18 public int getMethodCount(ClassDescriptor md) {
19 return classmethodcount.get(md).intValue();
22 public int getLocalityNumber(LocalityBinding lb) {
23 return localitynumber.get(lb).intValue();
26 public Virtual(State state, LocalityAnalysis locality) {
28 this.locality=locality;
29 classmethodcount=new Hashtable<ClassDescriptor, Integer>();
30 if (state.DSM||state.SINGLETM)
31 localitynumber=new Hashtable<LocalityBinding, Integer>();
33 methodnumber=new Hashtable<MethodDescriptor, Integer>();
37 private void doAnalysis() {
38 Iterator classit=state.getClassSymbolTable().getDescriptorsIterator();
39 while(classit.hasNext()) {
40 ClassDescriptor cd=(ClassDescriptor)classit.next();
41 if (state.DSM||state.SINGLETM)
48 private int numberLocality(ClassDescriptor cd) {
49 if (classmethodcount.containsKey(cd))
50 return classmethodcount.get(cd).intValue();
51 ClassDescriptor superdesc=cd.getSuperDesc();
54 start=numberLocality(superdesc);
56 if (locality.getClassBindings(cd)!=null)
57 for(Iterator<LocalityBinding> lbit=locality.getClassBindings(cd).iterator(); lbit.hasNext();) {
58 LocalityBinding lb=lbit.next();
59 MethodDescriptor md=lb.getMethod();
60 //Is it a static method or constructor
61 if (md.isStatic()||md.getReturnType()==null)
64 if (superdesc!=null) {
65 Set possiblematches=superdesc.getMethodTable().getSet(md.getSymbol());
66 boolean foundmatch=false;
67 for(Iterator matchit=possiblematches.iterator(); matchit.hasNext();) {
68 MethodDescriptor matchmd=(MethodDescriptor)matchit.next();
69 if (md.matches(matchmd)) {
70 Set<LocalityBinding> lbset=locality.getMethodBindings(matchmd);
72 for(Iterator<LocalityBinding> suplbit=lbset.iterator(); suplbit.hasNext();) {
73 LocalityBinding suplb=suplbit.next();
74 if (lb.contextMatches(suplb)) {
76 localitynumber.put(lb, localitynumber.get(suplb));
84 localitynumber.put(lb, new Integer(start++));
86 localitynumber.put(lb, new Integer(start++));
89 classmethodcount.put(cd, new Integer(start));
93 private int numberMethods(ClassDescriptor cd) {
94 if (classmethodcount.containsKey(cd))
95 return classmethodcount.get(cd).intValue();
96 ClassDescriptor superdesc=cd.getSuperDesc();
99 start=numberMethods(superdesc);
101 // TODO add version for normal Java later
102 // check the inherited interfaces
103 Iterator it_sifs = cd.getSuperInterfaces();
104 while(it_sifs.hasNext()) {
105 ClassDescriptor superif = (ClassDescriptor)it_sifs.next();
106 start += numberMethods(superif); // TODO Can there be duplicated methods from multiple ancestors?
109 for(Iterator it=cd.getMethods(); it.hasNext();) {
110 MethodDescriptor md=(MethodDescriptor)it.next();
111 if (md.isStatic()||md.getReturnType()==null)
113 if (superdesc!=null) {
114 Set possiblematches=superdesc.getMethodTable().getSet(md.getSymbol());
115 boolean foundmatch=false;
116 for(Iterator matchit=possiblematches.iterator(); matchit.hasNext();) {
117 MethodDescriptor matchmd=(MethodDescriptor)matchit.next();
118 if (md.matches(matchmd)) {
119 int num=((Integer)methodnumber.get(matchmd)).intValue();
120 methodnumber.put(md, new Integer(num));
126 // TODO add version for normal Java later
128 // check if there is a matched method in inherited interfaces
129 Iterator it_sifs = cd.getSuperInterfaces();
130 while(it_sifs.hasNext() && !foundmatch) {
131 ClassDescriptor superif = (ClassDescriptor)it_sifs.next();
132 Set possiblematches_if=superif.getMethodTable().getSet(md.getSymbol());
133 for(Iterator matchit=possiblematches_if.iterator(); matchit.hasNext();) {
134 MethodDescriptor matchmd=(MethodDescriptor)matchit.next();
135 if (md.matches(matchmd)) {
136 int num=((Integer)methodnumber.get(matchmd)).intValue();
137 methodnumber.put(md, new Integer(num));
146 methodnumber.put(md, new Integer(start++));
148 methodnumber.put(md, new Integer(start++));
151 classmethodcount.put(cd, new Integer(start));