import IR.*;
import IR.Flat.*;
import java.util.*;
+import java.io.*;
public class HeapRegionNode extends RefSrcNode {
// some reachability states are inherent
// to a node by its definition
- protected ReachSet inherent;
+ protected ReachSet inherent;
// use alpha for the current reach states
// and alphaNew during iterative calculations
// existence predicates must be true in a caller
// context for this node to transfer from this
- // callee to that context--NOTE, existence predicates
- // do not factor into node comparisons
+ // callee to that context
protected ExistPredSet preds;
- public HeapRegionNode( Integer id,
- boolean isSingleObject,
- boolean isFlagged,
- boolean isNewSummary,
- boolean isOutOfContext,
- TypeDescriptor type,
- AllocSite allocSite,
- ReachSet inherent,
- ReachSet alpha,
- ExistPredSet preds,
- String description
- ) {
+ public HeapRegionNode(Integer id,
+ boolean isSingleObject,
+ boolean isFlagged,
+ boolean isNewSummary,
+ boolean isOutOfContext,
+ TypeDescriptor type,
+ AllocSite allocSite,
+ ReachSet inherent,
+ ReachSet alpha,
+ ExistPredSet preds,
+ String description
+ ) {
this.id = id;
this.isSingleObject = isSingleObject;
}
public HeapRegionNode copy() {
- return new HeapRegionNode( id,
- isSingleObject,
- isFlagged,
- isNewSummary,
- isOutOfContext,
- type,
- allocSite,
- inherent,
- alpha,
- preds,
- description );
+ return new HeapRegionNode(id,
+ isSingleObject,
+ isFlagged,
+ isNewSummary,
+ isOutOfContext,
+ type,
+ allocSite,
+ inherent,
+ alpha,
+ preds,
+ description);
}
// alpha and preds contribute towards reaching the
// fixed point, so use this method to determine if
// a node is "equal" to some previous visit, basically
- public boolean equalsIncludingAlphaAndPreds( HeapRegionNode hrn ) {
+ public boolean equalsIncludingAlphaAndPreds(HeapRegionNode hrn) {
- return equals( hrn ) &&
- alpha.equals( hrn.alpha ) &&
- preds.equals( hrn.preds );
+ return equals(hrn) &&
+ alpha.equals(hrn.alpha) &&
+ preds.equals(hrn.preds);
}
- public boolean equals( Object o ) {
+ public boolean equals(Object o) {
if( o == null ) {
return false;
}
HeapRegionNode hrn = (HeapRegionNode) o;
- if( !id.equals( hrn.getID() ) ) {
+ if( !id.equals(hrn.getID() ) ) {
return false;
}
assert isFlagged == hrn.isFlagged();
assert isNewSummary == hrn.isNewSummary();
assert isOutOfContext == hrn.isOutOfContext();
- assert description.equals( hrn.getDescription() );
+ //assert description.equals( hrn.getDescription() );
return true;
}
}
- // in other words, this node is not functionally
+ // in other words, this node is not functionally
// part of the graph (anymore)
public boolean isWiped() {
- return
+ return
getNumReferencers() == 0 &&
getNumReferencees() == 0;
}
- public void addReferencer( RefEdge edge ) {
+ public void addReferencer(RefEdge edge) {
assert edge != null;
- referencers.add( edge );
+ referencers.add(edge);
}
- public void removeReferencer( RefEdge edge ) {
+ public void removeReferencer(RefEdge edge) {
assert edge != null;
- assert referencers.contains( edge );
+ assert referencers.contains(edge);
- referencers.remove( edge );
+ referencers.remove(edge);
}
- public RefEdge getReferenceFrom( RefSrcNode rsn,
- TypeDescriptor type,
- String field
- ) {
+ public RefEdge getReferenceFrom(RefSrcNode rsn,
+ TypeDescriptor type,
+ String field
+ ) {
assert rsn != null;
Iterator<RefEdge> itrEdge = referencers.iterator();
while( itrEdge.hasNext() ) {
RefEdge edge = itrEdge.next();
- if( edge.getSrc().equals( rsn ) &&
- edge.typeEquals( type ) &&
- edge.fieldEquals( field )
+ if( edge.getSrc().equals(rsn) &&
+ edge.typeEquals(type) &&
+ edge.fieldEquals(field)
) {
- return edge;
+ return edge;
}
}
public TypeDescriptor getType() {
return type;
- }
+ }
public AllocSite getAllocSite() {
return allocSite;
}
-
+
public ReachSet getInherent() {
return inherent;
}
-
+
public ReachSet getAlpha() {
return alpha;
}
- public void setAlpha( ReachSet alpha ) {
+ public void setAlpha(ReachSet alpha) {
this.alpha = alpha;
}
return alphaNew;
}
- public void setAlphaNew( ReachSet alpha ) {
+ public void setAlphaNew(ReachSet alpha) {
this.alphaNew = alpha;
}
return preds;
}
- public void setPreds( ExistPredSet preds ) {
+ public void setPreds(ExistPredSet preds) {
this.preds = preds;
}
+ // use this method to assert that an out-of-context
+ // heap region node has only out-of-context symbols
+ // in its reachability
+ public boolean reachHasOnlyOOC() {
+ assert isOutOfContext;
+
+ Iterator<ReachState> stateItr = alpha.iterator();
+ while( stateItr.hasNext() ) {
+ ReachState state = stateItr.next();
+
+ Iterator<ReachTuple> rtItr = state.iterator();
+ while( rtItr.hasNext() ) {
+ ReachTuple rt = rtItr.next();
+
+ if( !rt.isOutOfContext() ) {
+ return false;
+ }
+ }
+ }
+
+ return true;
+ }
+
+
public String getIDString() {
String s;
if( id < 0 ) {
- s = "minus" + new Integer( -id ).toString();
+ s = "minus" + new Integer(-id).toString();
} else {
s = id.toString();
}
public String getDescription() {
return description;
- }
+ }
- public String toStringDOT( boolean hideSubsetReach ) {
+ public String toStringDOT(boolean hideReach,
+ boolean hideSubsetReach,
+ boolean hidePreds) {
String attributes = "";
-
+
if( isSingleObject ) {
attributes += "shape=box";
} else {
attributes += ",style=filled,fillcolor=lightgrey";
}
- return new String( "["+attributes+
- ",label=\"ID"+getIDString()+"\\n"+
- type.toPrettyString()+"\\n"+
- description+"\\n"+
- alpha.toStringEscNewline( hideSubsetReach )+"\\n"+
- preds+"\"]"
- );
+ String typeStr;
+ if( type == null ) {
+ typeStr = "null";
+ } else {
+ typeStr = type.toPrettyString();
+ }
+
+ String s =
+ "["+attributes+
+ ",label=\"ID"+getIDString()+"\\n"+
+ typeStr+"\\n"+
+ description;
+
+ if( !hideReach ) {
+ s += "\\n"+alpha.toStringEscNewline(hideSubsetReach);
+ }
+
+ if( !hidePreds ) {
+ s += "\\n"+preds.toStringEscNewline();
+ }
+
+ return s+"\"]";
}
public String toString() {