1 package Analysis.OwnershipAnalysis;
7 public class HeapRegionNode extends OwnershipNode {
11 protected boolean isSingleObject;
12 protected boolean isFlagged;
13 protected boolean isParameter;
14 protected boolean isNewSummary;
16 protected HashSet<ReferenceEdge> referencers;
18 protected TypeDescriptor type;
20 protected AllocationSite allocSite;
22 protected ReachabilitySet alpha;
23 protected ReachabilitySet alphaNew;
25 protected String description;
27 protected String globalIdentifier;
31 public HeapRegionNode(Integer id,
32 boolean isSingleObject,
37 AllocationSite allocSite,
38 ReachabilitySet alpha,
40 String globalIdentifier) {
42 this.isSingleObject = isSingleObject;
43 this.isFlagged = isFlagged;
44 this.isParameter = isParameter;
45 this.isNewSummary = isNewSummary;
47 this.allocSite = allocSite;
49 this.description = description;
50 this.globalIdentifier = globalIdentifier;
52 referencers = new HashSet<ReferenceEdge>();
53 alphaNew = new ReachabilitySet().makeCanonical();
56 public HeapRegionNode copy() {
57 return new HeapRegionNode(id,
70 public Integer getID() {
75 public boolean equalsIncludingAlpha(HeapRegionNode hrn) {
76 return equals(hrn) && alpha.equals(hrn.alpha);
80 public boolean equals(Object o) {
85 if( !( o instanceof HeapRegionNode) ) {
89 HeapRegionNode hrn = (HeapRegionNode) o;
91 if( !id.equals(hrn.getID() ) ) {
95 assert isSingleObject == hrn.isSingleObject();
96 assert isFlagged == hrn.isFlagged();
97 assert isParameter == hrn.isParameter();
98 assert isNewSummary == hrn.isNewSummary();
99 assert description.equals(hrn.getDescription() );
104 public int hashCode() {
105 return id.intValue()*17;
109 public boolean isSingleObject() {
110 return isSingleObject;
113 public boolean isFlagged() {
117 public boolean isParameter() {
121 public boolean isNewSummary() {
127 public Iterator<ReferenceEdge> iteratorToReferencers() {
128 return referencers.iterator();
131 public Iterator<ReferenceEdge> iteratorToReferencersClone() {
132 HashSet<ReferenceEdge> clone = (HashSet<ReferenceEdge>)referencers.clone();
133 return clone.iterator();
136 public int getNumReferencers() {
137 return referencers.size();
141 public void addReferencer(ReferenceEdge edge) {
144 referencers.add(edge);
147 public void removeReferencer(ReferenceEdge edge) {
149 assert referencers.contains(edge);
151 referencers.remove(edge);
154 public ReferenceEdge getReferenceFrom(OwnershipNode on,
159 Iterator<ReferenceEdge> itrEdge = referencers.iterator();
160 while( itrEdge.hasNext() ) {
161 ReferenceEdge edge = itrEdge.next();
162 if( edge.getSrc().equals(on) &&
163 edge.typeEquals(type) &&
164 edge.fieldEquals(field) ) {
173 public TypeDescriptor getType() {
177 public AllocationSite getAllocationSite() {
182 public void setAlpha(ReachabilitySet alpha) {
186 public ReachabilitySet getAlpha() {
190 public ReachabilitySet getAlphaNew() {
194 public void setAlphaNew(ReachabilitySet alpha) {
195 this.alphaNew = alpha;
198 public void applyAlphaNew() {
199 assert alphaNew != null;
201 alphaNew = new ReachabilitySet().makeCanonical();
205 public String getIDString() {
209 s = "minus" + new Integer(-id).toString();
217 public String getAlphaString(boolean hideSubsetReachability) {
218 return alpha.toStringEscapeNewline(hideSubsetReachability);
221 public String toString() {
222 return "HRN"+getIDString();
225 // WHY WHY WHY WHY WHY WHY?!
226 public String getDescription() {
227 return new String(description);
228 //return new String( description+" ID "+getIDString() );
231 public String getGloballyUniqueIdentifier() {
232 return globalIdentifier;
235 public long getGloballyUniqueIntegerIdentifier() {
236 String fristpart = globalIdentifier;
237 fristpart = fristpart.replaceAll("FN", "1");
238 fristpart = fristpart.replaceAll("FM", "2");
239 int idx = fristpart.indexOf(".");
240 String endpart = fristpart.substring(idx + 1);
241 endpart = endpart.replaceAll("S", "1");
242 endpart = endpart.replaceAll("P", "2");
243 endpart = endpart.replaceAll("A", "3");
244 endpart = endpart.replace(".", "");
245 String modified = fristpart.substring(0, idx) + endpart;
246 return Long.parseLong(modified);