4 import Analysis.Locality.LocalityBinding;
5 import Analysis.Locality.LocalityAnalysis;
10 LocalityAnalysis locality;
11 Hashtable<MethodDescriptor, Integer> methodnumber;
12 Hashtable<ClassDescriptor, Integer> classmethodcount;
13 Hashtable<LocalityBinding, Integer> localitynumber;
17 SymbolTable if_methods;
19 public Integer getMethodNumber(MethodDescriptor md) {
20 return methodnumber.get(md);
23 public int getMethodCount(ClassDescriptor md) {
24 return classmethodcount.get(md).intValue();
27 public int getLocalityNumber(LocalityBinding lb) {
28 return localitynumber.get(lb).intValue();
31 public Virtual(State state, LocalityAnalysis locality) {
33 this.locality=locality;
35 this.if_methods = new SymbolTable();
36 classmethodcount=new Hashtable<ClassDescriptor, Integer>();
37 if (state.DSM||state.SINGLETM)
38 localitynumber=new Hashtable<LocalityBinding, Integer>();
40 methodnumber=new Hashtable<MethodDescriptor, Integer>();
44 private void doAnalysis() {
45 Iterator classit=state.getClassSymbolTable().getDescriptorsIterator();
46 while(classit.hasNext()) {
47 ClassDescriptor cd=(ClassDescriptor)classit.next();
50 classit=state.getClassSymbolTable().getDescriptorsIterator();
51 while(classit.hasNext()) {
52 ClassDescriptor cd=(ClassDescriptor)classit.next();
53 if (state.DSM||state.SINGLETM)
58 classit=state.getClassSymbolTable().getDescriptorsIterator();
59 while(classit.hasNext()) {
60 ClassDescriptor cd=(ClassDescriptor)classit.next();
61 if(!cd.isInterface()) {
62 int count = classmethodcount.get(cd).intValue();
63 classmethodcount.put(cd, new Integer(count+this.if_starts));
68 private int numberLocality(ClassDescriptor cd) {
69 if (classmethodcount.containsKey(cd))
70 return classmethodcount.get(cd).intValue();
71 ClassDescriptor superdesc=cd.getSuperDesc();
74 start=numberLocality(superdesc);
76 if (locality.getClassBindings(cd)!=null)
77 for(Iterator<LocalityBinding> lbit=locality.getClassBindings(cd).iterator(); lbit.hasNext();) {
78 LocalityBinding lb=lbit.next();
79 MethodDescriptor md=lb.getMethod();
80 //Is it a static method or constructor
81 if (md.isStatic()||md.getReturnType()==null)
84 if (superdesc!=null) {
85 Set possiblematches=superdesc.getMethodTable().getSet(md.getSymbol());
86 boolean foundmatch=false;
87 for(Iterator matchit=possiblematches.iterator(); matchit.hasNext();) {
88 MethodDescriptor matchmd=(MethodDescriptor)matchit.next();
89 if (md.matches(matchmd)) {
90 Set<LocalityBinding> lbset=locality.getMethodBindings(matchmd);
92 for(Iterator<LocalityBinding> suplbit=lbset.iterator(); suplbit.hasNext();) {
93 LocalityBinding suplb=suplbit.next();
94 if (lb.contextMatches(suplb)) {
96 localitynumber.put(lb, localitynumber.get(suplb));
104 localitynumber.put(lb, new Integer(start++));
106 localitynumber.put(lb, new Integer(start++));
109 classmethodcount.put(cd, new Integer(start));
113 private int numberMethodsIF(ClassDescriptor cd) {
114 if(!cd.isInterface()) {
118 if (classmethodcount.containsKey(cd))
119 return classmethodcount.get(cd).intValue();
120 // check the inherited interfaces
121 Iterator it_sifs = cd.getSuperInterfaces();
122 while(it_sifs.hasNext()) {
123 ClassDescriptor superif = (ClassDescriptor)it_sifs.next();
124 mnum += numberMethodsIF(superif);
126 for(Iterator it=cd.getMethods(); it.hasNext();) {
127 MethodDescriptor md=(MethodDescriptor)it.next();
128 if (md.isStatic()||md.getReturnType()==null)
130 boolean foundmatch = false;
131 if(this.state.genAllMethods) {
134 Set vec_md = this.state.getMethod2gen().getSet(md.getSymbol());
135 for(Iterator matchit=vec_md.iterator(); matchit.hasNext();) {
136 MethodDescriptor matchmd=(MethodDescriptor)matchit.next();
137 if (md.matches(matchmd)) {
147 // check if there is a matched method that has been assigned method num
148 Set possiblematches_if = if_methods.getSet(md.getSymbol());
149 for(Iterator matchit=possiblematches_if.iterator(); matchit.hasNext();) {
150 MethodDescriptor matchmd=(MethodDescriptor)matchit.next();
151 if (md.matches(matchmd)) {
152 int num=methodnumber.get(matchmd);
153 methodnumber.put(md, new Integer(num));
159 methodnumber.put(md, new Integer(if_starts++));
164 classmethodcount.put(cd, new Integer(mnum));
168 private int numberMethods(ClassDescriptor cd) {
169 if (classmethodcount.containsKey(cd))
170 return classmethodcount.get(cd).intValue();
171 ClassDescriptor superdesc=cd.getSuperDesc();
174 if (superdesc!=null) {
175 mnum = numberMethods(superdesc);
178 for(Iterator it=cd.getMethods(); it.hasNext();) {
179 MethodDescriptor md=(MethodDescriptor)it.next();
180 if (md.isStatic()||md.getReturnType()==null)
182 boolean foundmatch = false;
183 if(this.state.genAllMethods) {
186 Set vec_md = this.state.getMethod2gen().getSet(md.getSymbol());
187 for(Iterator matchit=vec_md.iterator(); matchit.hasNext();) {
188 MethodDescriptor matchmd=(MethodDescriptor)matchit.next();
189 if (md.matches(matchmd)) {
199 // check if there is a matched method in methods defined in interfaces
200 Set possiblematches_if=if_methods.getSet(md.getSymbol());
201 for(Iterator matchit=possiblematches_if.iterator(); matchit.hasNext();) {
202 MethodDescriptor matchmd=(MethodDescriptor)matchit.next();
203 if (md.matches(matchmd)) {
204 int num = methodnumber.get(matchmd);
205 methodnumber.put(md, new Integer(num));
210 if (!foundmatch && superdesc!=null) {
211 Set possiblematches=superdesc.getMethodTable().getSet(md.getSymbol());
212 for(Iterator matchit=possiblematches.iterator(); matchit.hasNext();) {
213 MethodDescriptor matchmd=(MethodDescriptor)matchit.next();
214 if (md.matches(matchmd)) {
215 int num = methodnumber.get(matchmd);
216 methodnumber.put(md, new Integer(num));
223 methodnumber.put(md, new Integer(start++));
227 classmethodcount.put(cd, new Integer(mnum));