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) {
99 alpha.equals(hrn.alpha) &&
100 preds.equals(hrn.preds);
104 public boolean equals(Object o) {
109 if( !(o instanceof HeapRegionNode) ) {
113 HeapRegionNode hrn = (HeapRegionNode) o;
115 if( !id.equals(hrn.getID() ) ) {
119 assert isSingleObject == hrn.isSingleObject();
120 assert isFlagged == hrn.isFlagged();
121 assert isNewSummary == hrn.isNewSummary();
122 assert isOutOfContext == hrn.isOutOfContext();
123 //assert description.equals( hrn.getDescription() );
128 public int hashCode() {
129 return id.intValue()*17;
133 public boolean isSingleObject() {
134 return isSingleObject;
137 public boolean isFlagged() {
141 public boolean isNewSummary() {
145 public boolean isOutOfContext() {
146 return isOutOfContext;
150 public Iterator<RefEdge> iteratorToReferencers() {
151 return referencers.iterator();
154 public Iterator<RefEdge> iteratorToReferencersClone() {
155 HashSet<RefEdge> clone = (HashSet<RefEdge>)referencers.clone();
156 return clone.iterator();
159 public int getNumReferencers() {
160 return referencers.size();
164 // in other words, this node is not functionally
165 // part of the graph (anymore)
166 public boolean isWiped() {
168 getNumReferencers() == 0 &&
169 getNumReferencees() == 0;
173 public void addReferencer(RefEdge edge) {
176 referencers.add(edge);
179 public void removeReferencer(RefEdge edge) {
181 assert referencers.contains(edge);
183 referencers.remove(edge);
186 public RefEdge getReferenceFrom(RefSrcNode rsn,
192 Iterator<RefEdge> itrEdge = referencers.iterator();
193 while( itrEdge.hasNext() ) {
194 RefEdge edge = itrEdge.next();
196 if( edge.getSrc().equals(rsn) &&
197 edge.typeEquals(type) &&
198 edge.fieldEquals(field)
208 public TypeDescriptor getType() {
212 public AllocSite getAllocSite() {
217 public ReachSet getInherent() {
221 public ReachSet getAlpha() {
225 public void setAlpha(ReachSet alpha) {
229 public ReachSet getAlphaNew() {
233 public void setAlphaNew(ReachSet alpha) {
234 this.alphaNew = alpha;
237 public void applyAlphaNew() {
238 assert alphaNew != null;
240 alphaNew = ReachSet.factory();
244 public ExistPredSet getPreds() {
248 public void setPreds(ExistPredSet preds) {
253 // use this method to assert that an out-of-context
254 // heap region node has only out-of-context symbols
255 // in its reachability
256 public boolean reachHasOnlyOOC() {
257 assert isOutOfContext;
259 Iterator<ReachState> stateItr = alpha.iterator();
260 while( stateItr.hasNext() ) {
261 ReachState state = stateItr.next();
263 Iterator<ReachTuple> rtItr = state.iterator();
264 while( rtItr.hasNext() ) {
265 ReachTuple rt = rtItr.next();
267 if( !rt.isOutOfContext() ) {
277 public String getIDString() {
281 s = "minus" + new Integer(-id).toString();
289 public String getDescription() {
293 public String toStringDOT(boolean hideReach,
294 boolean hideSubsetReach,
296 String attributes = "";
298 if( isSingleObject ) {
299 attributes += "shape=box";
301 attributes += "shape=Msquare";
305 attributes += ",style=filled,fillcolor=lightgrey";
312 typeStr = type.toPrettyString();
317 ",label=\"ID"+getIDString()+"\\n"+
322 s += "\\n"+alpha.toStringEscNewline(hideSubsetReach, hidePreds);
326 s += "\\n"+preds.toStringEscNewline();
332 public String toString() {
333 return "HRN"+getIDString();