1 package Analysis.Disjoint;
8 // all edges should have a non-null
10 protected TypeDescriptor type;
12 // the field name may be null if this
13 // edge models a variable reference
14 protected String field;
16 protected ReachSet beta;
17 protected ReachSet betaNew;
19 protected RefSrcNode src;
20 protected HeapRegionNode dst;
22 // existence predicates must be true in a caller
23 // context for this edge to transfer from this
24 // callee to that context--NOTE, existence predicates
25 // do not factor into edge comparisons
26 protected ExistPredSet preds;
28 // taint sets indicate which heap roots have
29 // tainted this edge-->meaning which heap roots
30 // code must have had access to in order to
31 // read or write through this edge
32 protected TaintSet paramTaints;
33 protected TaintSet rblockTaints;
36 public RefEdge( RefSrcNode src,
43 TaintSet rblockTaints ) {
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 if( paramTaints != null ) {
71 this.paramTaints = paramTaints;
73 this.paramTaints = TaintSet.factory();
76 if( rblockTaints != null ) {
77 this.rblockTaints = rblockTaints;
79 this.rblockTaints = TaintSet.factory();
84 public RefEdge copy() {
85 RefEdge copy = new RefEdge( src,
97 public boolean equals( Object o ) {
102 if( !(o instanceof RefEdge) ) {
106 RefEdge edge = (RefEdge) o;
108 if( !typeEquals( edge.type ) ) {
112 if( !fieldEquals( edge.field ) ) {
116 // Equality of edges is only valid within a graph, so
117 // compare src and dst by reference
118 if( !(src == edge.src) ||
119 !(dst == edge.dst) ) {
127 // beta and preds contribute towards reaching the
128 // fixed point, so use this method to determine if
129 // an edge is "equal" to some previous visit, basically
131 public boolean equalsIncludingBetaPredsTaints( RefEdge edge ) {
132 return equals( edge ) &&
133 beta.equals( edge.beta ) &&
134 preds.equals( edge.preds ) &&
135 paramTaints.equals( edge.paramTaints ) &&
136 rblockTaints.equals( edge.rblockTaints );
139 public boolean equalsPreds( RefEdge edge ) {
140 return preds.equals( edge.preds );
144 // this method SPECIFICALLY does not use the
145 // beta/preds/taints in the hash code--it uses
146 // the same fields as normal equals. Again,
147 // there are two meanings of equality for edges,
148 // one is "this edge is the same edge object" like when
149 // deciding if an edge is already in a set, which
150 // is represented by this hashcode. The other
151 // meaning is "this edge equals an edge from another
152 // graph that is abstractly the same edge"
153 public int hashCode() {
156 hash += type.hashCode()*17;
158 if( field != null ) {
159 hash += field.hashCode()*7;
162 hash += src.hashCode()*11;
163 hash += dst.hashCode();
169 public RefSrcNode getSrc() {
173 public void setSrc( RefSrcNode rsn ) {
178 public HeapRegionNode getDst() {
182 public void setDst( HeapRegionNode hrn ) {
188 public TypeDescriptor getType() {
192 public void setType( TypeDescriptor td ) {
197 public String getField() {
201 public void setField( String s ) {
206 public boolean typeEquals( TypeDescriptor td ) {
207 return type.equals( td );
210 public boolean fieldEquals( String s ) {
211 if( field == null && s == null ) {
214 if( field == null ) {
217 return field.equals( s );
220 public boolean typeAndFieldEquals( RefEdge e ) {
221 return typeEquals ( e.getType() ) &&
222 fieldEquals( e.getField() );
226 public ReachSet getBeta() {
230 public void setBeta( ReachSet beta ) {
235 public ReachSet getBetaNew() {
239 public void setBetaNew( ReachSet beta ) {
244 public void applyBetaNew() {
245 assert betaNew != null;
247 betaNew = ReachSet.factory();
251 public ExistPredSet getPreds() {
255 public void setPreds( ExistPredSet preds ) {
260 public TaintSet getParamTaints() {
264 public void setParamTaints( TaintSet taints ) {
265 this.paramTaints = taints;
268 public TaintSet getRblockTaints() {
272 public void setRblockTaints( TaintSet taints ) {
273 this.rblockTaints = taints;
278 public String toStringDOT( boolean hideReach,
279 boolean hideSubsetReach,
281 boolean hideEdgeTaints,
282 String otherAttributes ) {
285 type.toPrettyString()+"\\n"+
288 s += "\\n"+beta.toStringEscNewline( hideSubsetReach );
292 s += "\\n"+preds.toStringEscNewline();
295 if( !hideEdgeTaints ) {
296 if( !paramTaints.isEmpty() ) {
297 s += "\\npt: "+paramTaints.toString();
300 if( !rblockTaints.isEmpty() ) {
301 s += "\\nrt: "+rblockTaints.toString();
305 return s+"\",decorate"+otherAttributes+"]";
308 public String toString() {
309 return new String( "("+src+
310 "->"+type.toPrettyString()+
316 public String toStringAndBeta() {
317 return toString()+beta.toString();