1 package Analysis.Locality;
2 import IR.MethodDescriptor;
4 public class LocalityBinding {
5 private MethodDescriptor md;
6 private Integer[] isglobal;
7 private boolean isatomic;
8 private Integer isglobalreturn;
9 private Integer isglobalthis;
10 private LocalityBinding parent;
11 private boolean hasatomic;
13 public LocalityBinding(MethodDescriptor md, boolean atomic) {
15 isglobal=new Integer[md.numParameters()];
19 public void setHasAtomic() {
23 public boolean getHasAtomic() {
27 private static String globalToString(Integer g) {
30 else if (g==LocalityAnalysis.GLOBAL)
32 else if (g==LocalityAnalysis.LOCAL)
34 else if (g==LocalityAnalysis.EITHER)
36 else if (g==LocalityAnalysis.CONFLICT)
38 else if (g==LocalityAnalysis.SCRATCH)
40 else if (g==LocalityAnalysis.NORMAL)
42 else if (g==(LocalityAnalysis.STMCONFLICT))
44 else if (g==(LocalityAnalysis.STMEITHER))
46 else throw new Error("unknown value"+g);
49 public String getSignature() {
50 if (md.getModifiers().isNative())
57 if (isglobalthis==null)
60 st+=globalToString(isglobalthis);
61 for(int i=0; i<isglobal.length; i++) {
62 st+=globalToString(isglobal[i]);
68 /* Use this for an explanation */
69 public void setParent(LocalityBinding lb) {
73 public String getExplanation() {
77 return parent.getExplanation()+"\n"+toString();
80 public String toString() {
81 String st=md.toString()+" ";
82 if (isglobalthis==null) {
85 if (isglobalthis.equals(LocalityAnalysis.LOCAL))
87 else if (isglobalthis.equals(LocalityAnalysis.GLOBAL))
89 else if (isglobalthis.equals(LocalityAnalysis.EITHER))
91 else if (isglobalthis.equals(LocalityAnalysis.CONFLICT))
94 st+="[this="+isglobalthis+"]";
96 for(int i=0; i<isglobal.length; i++)
97 if (isglobal[i]==null)
99 else if (isglobal[i].equals(LocalityAnalysis.LOCAL))
101 else if (isglobal[i].equals(LocalityAnalysis.GLOBAL))
103 else if (isglobal[i].equals(LocalityAnalysis.EITHER))
105 else if (isglobal[i].equals(LocalityAnalysis.CONFLICT))
108 st+="["+isglobal[i]+"]";
112 public void setGlobal(int i, Integer global) {
116 public Integer isGlobal(int i) {
120 public void setGlobalReturn(Integer global) {
121 isglobalreturn=global;
124 public Integer getGlobalReturn() {
125 return isglobalreturn;
128 public void setGlobalThis(Integer global) {
132 public Integer getGlobalThis() {
136 public MethodDescriptor getMethod() {
140 public boolean isAtomic() {
144 public boolean contextMatches(LocalityBinding lb) {
145 if (isglobal.length!=lb.isglobal.length)
147 for(int i=0; i<isglobal.length; i++)
148 if (!equiv(isglobal[i],lb.isglobal[i]))
151 if (!equiv(isglobalthis, lb.isglobalthis))
153 return (isatomic==lb.isatomic);
156 public static boolean equiv(Integer a, Integer b) {
159 } else if (b==null) {
161 } else return a.equals(b);
164 public boolean equals(Object o) {
165 if (o instanceof LocalityBinding) {
166 LocalityBinding lb=(LocalityBinding)o;
170 for(int i=0; i<isglobal.length; i++)
171 if (!equiv(isglobal[i], lb.isglobal[i]))
174 if (!equiv(isglobalthis, lb.isglobalthis))
176 return (isatomic==lb.isatomic);
181 public int hashCode() {
182 int hashcode=md.hashCode();
183 for(int i=0; i<isglobal.length; i++) {
184 if (isglobal[i]!=null)
185 hashcode=hashcode*31+(isglobal[i].intValue());
187 hashcode=hashcode*31+(isatomic ? 1 : 0);