1 package Analysis.Disjoint;
7 public class HeapRegionNode extends RefSrcNode {
11 protected boolean isSingleObject;
12 protected boolean isFlagged;
13 protected boolean isNewSummary;
15 // special nodes that represent heap parts
16 // outside of the current method context
17 protected boolean isOutOfContext;
19 protected HashSet<RefEdge> referencers;
21 protected TypeDescriptor type;
23 protected AllocSite allocSite;
25 // some reachability states are inherent
26 // to a node by its definition
27 protected ReachSet inherent;
29 // use alpha for the current reach states
30 // and alphaNew during iterative calculations
32 protected ReachSet alpha;
33 protected ReachSet alphaNew;
35 protected String description;
37 // existence predicates must be true in a caller
38 // context for this node to transfer from this
39 // callee to that context
40 protected ExistPredSet preds;
43 public HeapRegionNode( Integer id,
44 boolean isSingleObject,
47 boolean isOutOfContext,
57 this.isSingleObject = isSingleObject;
58 this.isFlagged = isFlagged;
59 this.isNewSummary = isNewSummary;
60 this.isOutOfContext = isOutOfContext;
62 this.allocSite = allocSite;
63 this.inherent = inherent;
66 this.description = description;
68 referencers = new HashSet<RefEdge>();
69 alphaNew = ReachSet.factory();
72 public HeapRegionNode copy() {
73 return new HeapRegionNode( id,
87 public Integer getID() {
92 // alpha and preds contribute towards reaching the
93 // fixed point, so use this method to determine if
94 // a node is "equal" to some previous visit, basically
95 public boolean equalsIncludingAlphaAndPreds( HeapRegionNode hrn ) {
97 return equals( 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 public String getIDString() {
256 s = "minus" + new Integer( -id ).toString();
264 public String getDescription() {
268 public String toStringDOT( boolean hideSubsetReach ) {
270 String attributes = "";
272 if( isSingleObject ) {
273 attributes += "shape=box";
275 attributes += "shape=Msquare";
279 attributes += ",style=filled,fillcolor=lightgrey";
286 typeStr = type.toPrettyString();
289 return new String( "["+attributes+
290 ",label=\"ID"+getIDString()+"\\n"+
293 alpha.toStringEscNewline( hideSubsetReach )+"\\n"+
298 public String toString() {
299 return "HRN"+getIDString();