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);
100 for(Iterator it=cd.getMethods(); it.hasNext();) {
101 MethodDescriptor md=(MethodDescriptor)it.next();
102 if (md.isStatic()||md.getReturnType()==null)
104 if (superdesc!=null) {
105 Set possiblematches=superdesc.getMethodTable().getSet(md.getSymbol());
106 boolean foundmatch=false;
107 for(Iterator matchit=possiblematches.iterator(); matchit.hasNext();) {
108 MethodDescriptor matchmd=(MethodDescriptor)matchit.next();
109 if (md.matches(matchmd)) {
110 int num=((Integer)methodnumber.get(matchmd)).intValue();
111 methodnumber.put(md, new Integer(num));
117 methodnumber.put(md, new Integer(start++));
119 methodnumber.put(md, new Integer(start++));
122 classmethodcount.put(cd, new Integer(start));