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 equals( Object o ) {
66 if( !( o instanceof HeapRegionNode) ) {
70 HeapRegionNode hrn = (HeapRegionNode) o;
72 if( !id.equals( hrn.getID() ) ) {
76 assert isSingleObject == hrn.isSingleObject();
77 assert isFlagged == hrn.isFlagged();
78 assert isNewSummary == hrn.isNewSummary();
79 assert description.equals( hrn.getDescription() );
81 return alpha.equals( hrn.getAlpha() );
84 return id.equals( hrn.getID() ) &&
85 isSingleObject == hrn.isSingleObject() &&
86 isFlagged == hrn.isFlagged() &&
87 isNewSummary == hrn.isNewSummary() &&
88 alpha.equals( hrn.getAlpha() ) &&
89 description.equals( hrn.getDescription() );
93 public int hashCode() {
94 return id.intValue()*17 + alpha.hashCode();
98 public boolean isSingleObject() {
99 return isSingleObject;
102 public boolean isFlagged() {
106 public boolean isNewSummary() {
112 public Iterator<ReferenceEdge> iteratorToReferencers() {
113 return referencers.iterator();
116 public Iterator<ReferenceEdge> iteratorToReferencersClone() {
117 HashSet<ReferenceEdge> clone = (HashSet<ReferenceEdge>) referencers.clone();
118 return clone.iterator();
121 public void addReferencer( ReferenceEdge edge ) {
124 referencers.add( edge );
127 public void removeReferencer( ReferenceEdge edge ) {
129 assert referencers.contains( edge );
131 referencers.remove( edge );
134 public ReferenceEdge getReferenceFrom( OwnershipNode on,
135 FieldDescriptor fd ) {
138 Iterator<ReferenceEdge> itrEdge = referencers.iterator();
139 while( itrEdge.hasNext() ) {
140 ReferenceEdge edge = itrEdge.next();
141 if( edge.getSrc().equals( on ) &&
142 edge.getFieldDesc() == fd ) {
151 public AllocationSite getAllocationSite() {
156 public void setAlpha( ReachabilitySet alpha ) {
160 public ReachabilitySet getAlpha() {
164 public ReachabilitySet getAlphaNew() {
168 public void setAlphaNew( ReachabilitySet alpha ) {
169 this.alphaNew = alpha;
172 public void applyAlphaNew() {
173 assert alphaNew != null;
177 alphaNew = new ReachabilitySet();
178 alphaNew = alphaNew.makeCanonical();
182 public String getIDString() {
183 return id.toString();
186 public String getAlphaString() {
187 return alpha.toStringEscapeNewline();
190 public String toString() {
191 return "HRN"+getIDString();
194 // WHY WHY WHY WHY WHY WHY?!
195 public String getDescription() {
196 return new String( description );
197 //return new String( description+" ID "+getIDString() );