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 taints;
35 public RefEdge(RefSrcNode src,
55 this.preds = ExistPredSet.factory();
61 this.beta = ReachSet.factory();
64 // when edges are not undergoing an operation that
65 // is changing beta info, betaNew is always empty
66 betaNew = ReachSet.factory();
68 if( taints != null ) {
71 this.taints = TaintSet.factory();
76 public RefEdge copy() {
77 RefEdge copy = new RefEdge(src,
88 public boolean equals(Object o) {
93 if( !(o instanceof RefEdge) ) {
97 RefEdge edge = (RefEdge) o;
99 if( !typeEquals(edge.type) ) {
103 if( !fieldEquals(edge.field) ) {
107 // Equality of edges is only valid within a graph, so
108 // compare src and dst by reference
109 if( !(src == edge.src) ||
110 !(dst == edge.dst) ) {
118 // beta and preds contribute towards reaching the
119 // fixed point, so use this method to determine if
120 // an edge is "equal" to some previous visit, basically
122 public boolean equalsIncludingBetaPredsTaints(RefEdge edge) {
123 return equals(edge) &&
124 beta.equals(edge.beta) &&
125 preds.equals(edge.preds) &&
126 taints.equals(edge.taints);
129 public boolean equalsPreds(RefEdge edge) {
130 return preds.equals(edge.preds);
134 // this method SPECIFICALLY does not use the
135 // beta/preds/taints in the hash code--it uses
136 // the same fields as normal equals. Again,
137 // there are two meanings of equality for edges,
138 // one is "this edge is the same edge object" like when
139 // deciding if an edge is already in a set, which
140 // is represented by this hashcode. The other
141 // meaning is "this edge equals an edge from another
142 // graph that is abstractly the same edge"
143 public int hashCode() {
146 hash += type.hashCode()*17;
148 if( field != null ) {
149 hash += field.hashCode()*7;
152 hash += src.hashCode()*11;
153 hash += dst.hashCode();
159 public RefSrcNode getSrc() {
163 public void setSrc(RefSrcNode rsn) {
168 public HeapRegionNode getDst() {
172 public void setDst(HeapRegionNode hrn) {
178 public TypeDescriptor getType() {
182 public void setType(TypeDescriptor td) {
187 public String getField() {
191 public void setField(String s) {
196 public boolean typeEquals(TypeDescriptor td) {
197 return type.equals(td);
200 public boolean fieldEquals(String s) {
201 if( field == null && s == null ) {
204 if( field == null ) {
207 return field.equals(s);
210 public boolean typeAndFieldEquals(RefEdge e) {
211 return typeEquals(e.getType() ) &&
212 fieldEquals(e.getField() );
216 public ReachSet getBeta() {
220 public void setBeta(ReachSet beta) {
225 public ReachSet getBetaNew() {
229 public void setBetaNew(ReachSet beta) {
234 public void applyBetaNew() {
235 assert betaNew != null;
237 betaNew = ReachSet.factory();
241 public ExistPredSet getPreds() {
245 public void setPreds(ExistPredSet preds) {
250 public TaintSet getTaints() {
254 public void setTaints(TaintSet taints) {
255 this.taints = taints;
259 public String toStringDOT(boolean hideReach,
260 boolean hideSubsetReach,
262 boolean hideEdgeTaints,
263 String otherAttributes) {
266 type.toPrettyString()+"\\n"+
269 s += "\\n"+beta.toStringEscNewline(hideSubsetReach);
273 s += "\\n"+preds.toStringEscNewline();
276 if( !hideEdgeTaints ) {
277 if( !taints.isEmpty() ) {
278 s += "\\n"+taints.toStringEscNewline( hidePreds );
282 return s+"\",decorate"+otherAttributes+"]";
285 public String toString() {
286 return new String("("+src+
287 "->"+type.toPrettyString()+
293 public String toStringAndBeta() {
294 return toString()+beta.toString();