1 package Analysis.OwnershipAnalysis;
7 public class HeapRegionNode extends OwnershipNode {
11 protected boolean isSingleObject;
12 protected boolean isFlagged;
13 protected boolean isNewSummary;
15 protected HashSet<ReferenceEdge> referencers;
17 protected AllocationSite allocSite;
19 protected ReachabilitySet alpha;
20 protected ReachabilitySet alphaNew;
22 protected String description;
26 public HeapRegionNode( Integer id,
27 boolean isSingleObject,
30 AllocationSite allocSite,
31 ReachabilitySet alpha,
32 String description ) {
34 this.isSingleObject = isSingleObject;
35 this.isFlagged = isFlagged;
36 this.isNewSummary = isNewSummary;
37 this.allocSite = allocSite;
39 this.description = description;
41 referencers = new HashSet<ReferenceEdge>();
42 alphaNew = new ReachabilitySet().makeCanonical();
45 public HeapRegionNode copy() {
46 return new HeapRegionNode( id,
56 public Integer getID() {
61 public boolean equalsIncludingAlpha( HeapRegionNode hrn ) {
62 return equals( hrn ) && alpha.equals( hrn.alpha );
66 public boolean equals( Object o ) {
71 if( !( o instanceof HeapRegionNode) ) {
75 HeapRegionNode hrn = (HeapRegionNode) o;
77 if( !id.equals( hrn.getID() ) ) {
81 assert isSingleObject == hrn.isSingleObject();
82 assert isFlagged == hrn.isFlagged();
83 assert isNewSummary == hrn.isNewSummary();
84 assert description.equals( hrn.getDescription() );
89 public int hashCode() {
90 return id.intValue()*17;
94 public boolean isSingleObject() {
95 return isSingleObject;
98 public boolean isFlagged() {
102 public boolean isNewSummary() {
108 public Iterator<ReferenceEdge> iteratorToReferencers() {
109 return referencers.iterator();
112 public Iterator<ReferenceEdge> iteratorToReferencersClone() {
113 HashSet<ReferenceEdge> clone = (HashSet<ReferenceEdge>) referencers.clone();
114 return clone.iterator();
117 public void addReferencer( ReferenceEdge edge ) {
120 referencers.add( edge );
123 public void removeReferencer( ReferenceEdge edge ) {
125 assert referencers.contains( edge );
127 referencers.remove( edge );
130 public ReferenceEdge getReferenceFrom( OwnershipNode on,
131 FieldDescriptor fd ) {
134 Iterator<ReferenceEdge> itrEdge = referencers.iterator();
135 while( itrEdge.hasNext() ) {
136 ReferenceEdge edge = itrEdge.next();
137 if( edge.getSrc().equals( on ) &&
138 edge.getFieldDesc() == fd ) {
147 public AllocationSite getAllocationSite() {
152 public void setAlpha( ReachabilitySet alpha ) {
156 public ReachabilitySet getAlpha() {
160 public ReachabilitySet getAlphaNew() {
164 public void setAlphaNew( ReachabilitySet alpha ) {
165 this.alphaNew = alpha;
168 public void applyAlphaNew() {
169 assert alphaNew != null;
173 alphaNew = new ReachabilitySet();
174 alphaNew = alphaNew.makeCanonical();
178 public String getIDString() {
179 return id.toString();
182 public String getAlphaString() {
183 return alpha.toStringEscapeNewline();
186 public String toString() {
187 return "HRN"+getIDString();
190 // WHY WHY WHY WHY WHY WHY?!
191 public String getDescription() {
192 return new String( description );
193 //return new String( description+" ID "+getIDString() );