4 import Analysis.Locality.LocalityBinding;
5 import Analysis.Locality.LocalityAnalysis;
6 import Analysis.CallGraph.CallGraph;
10 LocalityAnalysis locality;
11 Hashtable<MethodDescriptor, Integer> methodnumber;
12 Hashtable<ClassDescriptor, Integer> classmethodcount;
13 Hashtable<LocalityBinding, Integer> localitynumber;
18 SymbolTable if_methods;
20 public Integer getMethodNumber(MethodDescriptor md) {
21 return methodnumber.get(md);
24 public int getMethodCount(ClassDescriptor md) {
25 return classmethodcount.get(md).intValue();
28 public int getLocalityNumber(LocalityBinding lb) {
29 return localitynumber.get(lb).intValue();
32 public Virtual(State state, LocalityAnalysis locality, CallGraph callgraph) {
34 this.locality=locality;
36 this.if_methods = new SymbolTable();
37 this.callgraph=callgraph;
38 classmethodcount=new Hashtable<ClassDescriptor, Integer>();
39 if (state.DSM||state.SINGLETM)
40 localitynumber=new Hashtable<LocalityBinding, Integer>();
42 methodnumber=new Hashtable<MethodDescriptor, Integer>();
46 private void doAnalysis() {
47 Iterator classit=state.getClassSymbolTable().getDescriptorsIterator();
48 while(classit.hasNext()) {
49 ClassDescriptor cd=(ClassDescriptor)classit.next();
52 classit=state.getClassSymbolTable().getDescriptorsIterator();
53 while(classit.hasNext()) {
54 ClassDescriptor cd=(ClassDescriptor)classit.next();
55 if (state.DSM||state.SINGLETM)
60 classit=state.getClassSymbolTable().getDescriptorsIterator();
61 while(classit.hasNext()) {
62 ClassDescriptor cd=(ClassDescriptor)classit.next();
63 if(!cd.isInterface()) {
64 int count = classmethodcount.get(cd).intValue();
65 classmethodcount.put(cd, new Integer(count+this.if_starts));
70 private int numberLocality(ClassDescriptor cd) {
71 if (classmethodcount.containsKey(cd))
72 return classmethodcount.get(cd).intValue();
73 ClassDescriptor superdesc=cd.getSuperDesc();
76 start=numberLocality(superdesc);
78 if (locality.getClassBindings(cd)!=null)
79 for(Iterator<LocalityBinding> lbit=locality.getClassBindings(cd).iterator(); lbit.hasNext();) {
80 LocalityBinding lb=lbit.next();
81 MethodDescriptor md=lb.getMethod();
82 //Is it a static method or constructor
83 if (md.isStatic()||md.getReturnType()==null)
86 if (superdesc!=null) {
87 Set possiblematches=superdesc.getMethodTable().getSet(md.getSymbol());
88 boolean foundmatch=false;
89 for(Iterator matchit=possiblematches.iterator(); matchit.hasNext();) {
90 MethodDescriptor matchmd=(MethodDescriptor)matchit.next();
91 if (md.matches(matchmd)) {
92 Set<LocalityBinding> lbset=locality.getMethodBindings(matchmd);
94 for(Iterator<LocalityBinding> suplbit=lbset.iterator(); suplbit.hasNext();) {
95 LocalityBinding suplb=suplbit.next();
96 if (lb.contextMatches(suplb)) {
98 localitynumber.put(lb, localitynumber.get(suplb));
106 localitynumber.put(lb, new Integer(start++));
108 localitynumber.put(lb, new Integer(start++));
111 classmethodcount.put(cd, new Integer(start));
115 private int numberMethodsIF(ClassDescriptor cd) {
116 if(!cd.isInterface()) {
120 if (classmethodcount.containsKey(cd))
121 return classmethodcount.get(cd).intValue();
122 // check the inherited interfaces
123 Iterator it_sifs = cd.getSuperInterfaces();
124 while(it_sifs.hasNext()) {
125 ClassDescriptor superif = (ClassDescriptor)it_sifs.next();
126 mnum += numberMethodsIF(superif);
128 for(Iterator it=cd.getMethods(); it.hasNext();) {
129 MethodDescriptor md=(MethodDescriptor)it.next();
130 if (md.isStatic()||md.getReturnType()==null)
133 if (!callgraph.isCallable(md))
135 boolean foundmatch=false;
136 // check if there is a matched method that has been assigned method num
137 Set possiblematches_if = if_methods.getSet(md.getSymbol());
138 for(Iterator matchit=possiblematches_if.iterator(); matchit.hasNext();) {
139 MethodDescriptor matchmd=(MethodDescriptor)matchit.next();
140 if (md.matches(matchmd)) {
141 int num=methodnumber.get(matchmd);
142 methodnumber.put(md, new Integer(num));
148 methodnumber.put(md, new Integer(if_starts++));
153 classmethodcount.put(cd, new Integer(mnum));
157 private int numberMethods(ClassDescriptor cd) {
158 if (classmethodcount.containsKey(cd))
159 return classmethodcount.get(cd).intValue();
160 ClassDescriptor superdesc=cd.getSuperDesc();
163 if (superdesc!=null) {
164 mnum = numberMethods(superdesc);
168 for(Iterator it=cd.getMethods(); it.hasNext();) {
169 MethodDescriptor md=(MethodDescriptor)it.next();
170 if (md.isStatic()||md.getReturnType()==null)
172 if (!callgraph.isCallable(md))
174 // check if there is a matched method in methods defined in interfaces
175 Set possiblematches_if=if_methods.getSet(md.getSymbol());
176 for(Iterator matchit=possiblematches_if.iterator(); matchit.hasNext();) {
177 MethodDescriptor matchmd=(MethodDescriptor)matchit.next();
178 if (md.matches(matchmd)) {
180 if (!methodnumber.containsKey(matchmd)) {
183 methodnumber.put(matchmd,num);
185 num = methodnumber.get(matchmd);
186 methodnumber.put(md, new Integer(num));
190 if (superdesc!=null) {
191 Set possiblematches=superdesc.getMethodTable().getSet(md.getSymbol());
192 for(Iterator matchit=possiblematches.iterator(); matchit.hasNext();) {
193 MethodDescriptor matchmd=(MethodDescriptor)matchit.next();
194 if (md.matches(matchmd)) {
196 if (!methodnumber.containsKey(matchmd)) {
199 methodnumber.put(matchmd,num);
201 num = methodnumber.get(matchmd);
202 methodnumber.put(md, new Integer(num));
208 methodnumber.put(md, new Integer(start++));
211 classmethodcount.put(cd, new Integer(mnum));