1 package Analysis.Disjoint;
10 // all edges should have a non-null
12 protected TypeDescriptor type;
14 // the field name may be null if this
15 // edge models a variable reference
16 protected String field;
18 protected ReachSet beta;
19 protected ReachSet betaNew;
21 protected RefSrcNode src;
22 protected HeapRegionNode dst;
24 // existence predicates must be true in a caller
25 // context for this edge to transfer from this
26 // callee to that context--NOTE, existence predicates
27 // do not factor into edge comparisons
28 protected ExistPredSet preds;
30 // taint sets indicate which heap roots have
31 // tainted this edge-->meaning which heap roots
32 // code must have had access to in order to
33 // read or write through this edge
34 protected TaintSet taints;
37 public RefEdge(RefSrcNode src,
57 this.preds = ExistPredSet.factory();
63 this.beta = ReachSet.factory();
66 // when edges are not undergoing an operation that
67 // is changing beta info, betaNew is always empty
68 betaNew = ReachSet.factory();
70 setTaints( taints != null ? taints : TaintSet.factory() );
74 public RefEdge copy() {
75 RefEdge copy = new RefEdge(src,
86 public boolean equals(Object o) {
91 if( !(o instanceof RefEdge) ) {
95 RefEdge edge = (RefEdge) o;
97 if( !typeEquals(edge.type) ) {
101 if( !fieldEquals(edge.field) ) {
105 if( src instanceof VariableNode ) {
106 VariableNode vsrc = (VariableNode) src;
108 if( !(edge.src instanceof VariableNode) ) {
112 if( !vsrc.equals( (VariableNode) edge.src ) ) {
116 HeapRegionNode hsrc = (HeapRegionNode) src;
118 if( !(edge.src instanceof HeapRegionNode) ) {
122 if( !hsrc.equalsIncludingAlphaAndPreds( (HeapRegionNode) edge.src ) ) {
127 if( !dst.equalsIncludingAlphaAndPreds( edge.dst ) ) {
135 // beta and preds contribute towards reaching the
136 // fixed point, so use this method to determine if
137 // an edge is "equal" to some previous visit, basically
139 public boolean equalsIncludingBetaPredsTaints(RefEdge edge) {
140 return equals(edge) &&
141 beta.equals(edge.beta) &&
142 preds.equals(edge.preds) &&
143 taints.equals(edge.taints);
146 public boolean equalsPreds(RefEdge edge) {
147 return preds.equals(edge.preds);
151 // this method SPECIFICALLY does not use the
152 // beta/preds/taints in the hash code--it uses
153 // the same fields as normal equals. Again,
154 // there are two meanings of equality for edges,
155 // one is "this edge is the same edge object" like when
156 // deciding if an edge is already in a set, which
157 // is represented by this hashcode. The other
158 // meaning is "this edge equals an edge from another
159 // graph that is abstractly the same edge"
160 public int hashCode() {
163 hash += type.hashCode()*17;
165 if( field != null ) {
166 hash += field.hashCode()*7;
169 hash += src.hashCode()*11;
170 hash += dst.hashCode();
176 public RefSrcNode getSrc() {
180 public void setSrc(RefSrcNode rsn) {
185 public HeapRegionNode getDst() {
189 public void setDst(HeapRegionNode hrn) {
195 public TypeDescriptor getType() {
199 public void setType(TypeDescriptor td) {
204 public String getField() {
208 public void setField(String s) {
213 public boolean typeEquals(TypeDescriptor td) {
214 return type.equals(td);
217 public boolean fieldEquals(String s) {
218 if( field == null && s == null ) {
221 if( field == null ) {
224 return field.equals(s);
227 public boolean typeAndFieldEquals(RefEdge e) {
228 return typeEquals(e.getType() ) &&
229 fieldEquals(e.getField() );
233 public ReachSet getBeta() {
237 public void setBeta(ReachSet beta) {
242 public ReachSet getBetaNew() {
246 public void setBetaNew(ReachSet beta) {
251 public void applyBetaNew() {
252 assert betaNew != null;
254 betaNew = ReachSet.factory();
258 public ExistPredSet getPreds() {
262 public void setPreds(ExistPredSet preds) {
267 public TaintSet getTaints() {
271 public void setTaints(TaintSet taints) {
272 this.taints = taints;
276 public String toStringDOT(boolean hideReach,
277 boolean hideSubsetReach,
279 boolean hideEdgeTaints,
280 String otherAttributes) {
283 type.toPrettyString()+"\\n"+
286 s += "\\n"+beta.toStringEscNewline(hideSubsetReach, hidePreds);
290 s += "\\n"+preds.toStringEscNewline();
293 if( !hideEdgeTaints ) {
294 if( !taints.isEmpty() ) {
295 s += "\\n"+taints.toStringEscNewline( hidePreds );
299 return s+"\",decorate"+otherAttributes+"]";
302 public String toString() {
303 return new String("("+src+
304 "->"+type.toPrettyString()+
310 public String toStringAndBeta() {
311 return toString()+beta.toString();