1 package Analysis.Disjoint;
8 public class HeapRegionNode extends RefSrcNode {
12 protected boolean isSingleObject;
13 protected boolean isFlagged;
14 protected boolean isNewSummary;
16 // special nodes that represent heap parts
17 // outside of the current method context
18 protected boolean isOutOfContext;
20 protected HashSet<RefEdge> referencers;
22 protected TypeDescriptor type;
24 protected AllocSite allocSite;
26 // some reachability states are inherent
27 // to a node by its definition
28 protected ReachSet inherent;
30 // use alpha for the current reach states
31 // and alphaNew during iterative calculations
33 protected ReachSet alpha;
34 protected ReachSet alphaNew;
36 protected String description;
38 // existence predicates must be true in a caller
39 // context for this node to transfer from this
40 // callee to that context
41 protected ExistPredSet preds;
44 public HeapRegionNode(Integer id,
45 boolean isSingleObject,
48 boolean isOutOfContext,
58 this.isSingleObject = isSingleObject;
59 this.isFlagged = isFlagged;
60 this.isNewSummary = isNewSummary;
61 this.isOutOfContext = isOutOfContext;
63 this.allocSite = allocSite;
64 this.inherent = inherent;
67 this.description = description;
69 referencers = new HashSet<RefEdge>();
70 alphaNew = ReachSet.factory();
73 public HeapRegionNode copy() {
74 return new HeapRegionNode(id,
88 public Integer getID() {
93 // alpha and preds contribute towards reaching the
94 // fixed point, so use this method to determine if
95 // a node is "equal" to some previous visit, basically
96 public boolean equalsIncludingAlphaAndPreds(HeapRegionNode hrn) {
98 alpha.equals(hrn.alpha) &&
99 preds.equals(hrn.preds);
103 public boolean equals(Object o) {
108 if( !(o instanceof HeapRegionNode) ) {
112 HeapRegionNode hrn = (HeapRegionNode) o;
114 if( !id.equals(hrn.getID() ) ) {
118 assert isSingleObject == hrn.isSingleObject();
119 assert isFlagged == hrn.isFlagged();
120 assert isNewSummary == hrn.isNewSummary();
121 assert isOutOfContext == hrn.isOutOfContext();
122 //assert description.equals( hrn.getDescription() );
127 public int hashCode() {
128 return id.intValue()*17;
132 public boolean isSingleObject() {
133 return isSingleObject;
136 public boolean isFlagged() {
140 public boolean isNewSummary() {
144 public boolean isOutOfContext() {
145 return isOutOfContext;
149 public Iterator<RefEdge> iteratorToReferencers() {
150 return referencers.iterator();
153 public Iterator<RefEdge> iteratorToReferencersClone() {
154 HashSet<RefEdge> clone = (HashSet<RefEdge>)referencers.clone();
155 return clone.iterator();
158 public int getNumReferencers() {
159 return referencers.size();
163 // in other words, this node is not functionally
164 // part of the graph (anymore)
165 public boolean isWiped() {
167 getNumReferencers() == 0 &&
168 getNumReferencees() == 0;
172 public void addReferencer(RefEdge edge) {
175 referencers.add(edge);
178 public void removeReferencer(RefEdge edge) {
180 assert referencers.contains(edge);
182 referencers.remove(edge);
185 public RefEdge getReferenceFrom(RefSrcNode rsn,
191 Iterator<RefEdge> itrEdge = referencers.iterator();
192 while( itrEdge.hasNext() ) {
193 RefEdge edge = itrEdge.next();
195 if( edge.getSrc().equals(rsn) &&
196 edge.typeEquals(type) &&
197 edge.fieldEquals(field)
207 public TypeDescriptor getType() {
211 public AllocSite getAllocSite() {
216 public ReachSet getInherent() {
220 public ReachSet getAlpha() {
224 public void setAlpha(ReachSet alpha) {
228 public ReachSet getAlphaNew() {
232 public void setAlphaNew(ReachSet alpha) {
233 this.alphaNew = alpha;
236 public void applyAlphaNew() {
237 assert alphaNew != null;
239 alphaNew = ReachSet.factory();
243 public ExistPredSet getPreds() {
247 public void setPreds(ExistPredSet preds) {
252 // use this method to assert that an out-of-context
253 // heap region node has only out-of-context symbols
254 // in its reachability
255 public boolean reachHasOnlyOOC() {
256 assert isOutOfContext;
258 Iterator<ReachState> stateItr = alpha.iterator();
259 while( stateItr.hasNext() ) {
260 ReachState state = stateItr.next();
262 Iterator<ReachTuple> rtItr = state.iterator();
263 while( rtItr.hasNext() ) {
264 ReachTuple rt = rtItr.next();
266 if( !rt.isOutOfContext() ) {
276 public String getIDString() {
280 s = "minus" + new Integer(-id).toString();
288 public String getDescription() {
292 public String toStringDOT(boolean hideReach,
293 boolean hideSubsetReach,
295 String attributes = "";
297 if( isSingleObject ) {
298 attributes += "shape=box";
300 attributes += "shape=Msquare";
304 attributes += ",style=filled,fillcolor=lightgrey";
311 typeStr = type.toPrettyString();
316 ",label=\"ID"+getIDString()+"\\n"+
321 s += "\\n"+alpha.toStringEscNewline(hideSubsetReach, hidePreds);
325 s += "\\n"+preds.toStringEscNewline();
331 public String toString() {
332 return "HRN"+getIDString();