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,
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 int getNumReferencers() {
118 return referencers.size();
122 public void addReferencer(ReferenceEdge edge) {
125 referencers.add(edge);
128 public void removeReferencer(ReferenceEdge edge) {
130 assert referencers.contains(edge);
132 referencers.remove(edge);
135 public ReferenceEdge getReferenceFrom(OwnershipNode on,
136 FieldDescriptor fd) {
139 Iterator<ReferenceEdge> itrEdge = referencers.iterator();
140 while( itrEdge.hasNext() ) {
141 ReferenceEdge edge = itrEdge.next();
142 if( edge.getSrc().equals(on) &&
143 edge.getFieldDesc() == fd ) {
152 public AllocationSite getAllocationSite() {
157 public void setAlpha(ReachabilitySet alpha) {
161 public ReachabilitySet getAlpha() {
165 public ReachabilitySet getAlphaNew() {
169 public void setAlphaNew(ReachabilitySet alpha) {
170 this.alphaNew = alpha;
173 public void applyAlphaNew() {
174 assert alphaNew != null;
178 alphaNew = new ReachabilitySet();
179 alphaNew = alphaNew.makeCanonical();
183 public String getIDString() {
184 return id.toString();
187 public String getAlphaString() {
188 return alpha.toStringEscapeNewline();
191 public String toString() {
192 return "HRN"+getIDString();
195 // WHY WHY WHY WHY WHY WHY?!
196 public String getDescription() {
197 return new String(description);
198 //return new String( description+" ID "+getIDString() );