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;
148 public boolean isShadow() {
152 public Iterator<RefEdge> iteratorToReferencers() {
153 return referencers.iterator();
156 public Iterator<RefEdge> iteratorToReferencersClone() {
157 HashSet<RefEdge> clone = (HashSet<RefEdge>)referencers.clone();
158 return clone.iterator();
161 public int getNumReferencers() {
162 return referencers.size();
166 // in other words, this node is not functionally
167 // part of the graph (anymore)
168 public boolean isWiped() {
170 getNumReferencers() == 0 &&
171 getNumReferencees() == 0;
175 public void addReferencer(RefEdge edge) {
178 referencers.add(edge);
181 public void removeReferencer(RefEdge edge) {
183 assert referencers.contains(edge);
185 referencers.remove(edge);
188 public RefEdge getReferenceFrom(RefSrcNode rsn,
194 Iterator<RefEdge> itrEdge = referencers.iterator();
195 while( itrEdge.hasNext() ) {
196 RefEdge edge = itrEdge.next();
198 if( edge.getSrc().equals(rsn) &&
199 edge.typeEquals(type) &&
200 edge.fieldEquals(field)
210 public TypeDescriptor getType() {
214 public AllocSite getAllocSite() {
219 public ReachSet getInherent() {
223 public ReachSet getAlpha() {
227 public void setAlpha(ReachSet alpha) {
231 public ReachSet getAlphaNew() {
235 public void setAlphaNew(ReachSet alpha) {
236 this.alphaNew = alpha;
239 public void applyAlphaNew() {
240 assert alphaNew != null;
242 alphaNew = ReachSet.factory();
246 public ExistPredSet getPreds() {
250 public void setPreds(ExistPredSet preds) {
255 // use this method to assert that an out-of-context
256 // heap region node has only out-of-context symbols
257 // in its reachability
258 public boolean reachHasOnlyOOC() {
259 assert isOutOfContext;
261 Iterator<ReachState> stateItr = alpha.iterator();
262 while( stateItr.hasNext() ) {
263 ReachState state = stateItr.next();
265 Iterator<ReachTuple> rtItr = state.iterator();
266 while( rtItr.hasNext() ) {
267 ReachTuple rt = rtItr.next();
269 if( !rt.isOutOfContext() ) {
279 public String getIDString() {
283 s = "minus" + new Integer(-id).toString();
291 public String getDescription() {
295 public String toStringDOT(boolean hideReach,
296 boolean hideSubsetReach,
298 String attributes = "";
300 if( isSingleObject ) {
301 attributes += "shape=box";
303 attributes += "shape=Msquare";
307 attributes += ",style=filled,fillcolor=lightgrey";
314 typeStr = type.toPrettyString();
319 ",label=\"ID"+getIDString()+"\\n"+
324 s += "\\n"+alpha.toStringEscNewline(hideSubsetReach, hidePreds);
328 s += "\\n"+preds.toStringEscNewline();
334 public String toString() {
335 return "HRN"+getIDString();