1 package Analysis.OwnershipAnalysis;
7 public class ReferenceEdge {
9 // null descriptors mean "any field"
10 protected TypeDescriptor type;
11 protected String field;
13 protected boolean isInitialParam;
15 protected ReachabilitySet beta;
16 protected ReachabilitySet betaNew;
18 protected OwnershipNode src;
19 protected HeapRegionNode dst;
20 private int taintIdentifier;
21 private int SESEtaintIdentifier;
24 public ReferenceEdge(OwnershipNode src,
28 boolean isInitialParam,
29 ReachabilitySet beta) {
35 this.isInitialParam = isInitialParam;
36 this.taintIdentifier = 0;
37 this.SESEtaintIdentifier = 0;
42 this.beta = new ReachabilitySet().makeCanonical();
45 // when edges are not undergoing a transitional operation
46 // that is changing beta info, betaNew is always empty
47 betaNew = new ReachabilitySet().makeCanonical();
51 public ReferenceEdge copy() {
52 ReferenceEdge copy= new ReferenceEdge(src,
58 copy.setTaintIdentifier(this.taintIdentifier);
63 public boolean equals(Object o) {
68 if( !(o instanceof ReferenceEdge) ) {
72 ReferenceEdge edge = (ReferenceEdge) o;
74 if( !typeEquals( edge.type ) ) {
78 if( !fieldEquals( edge.field ) ) {
82 // Equality of edges is only valid within a graph, so
83 // compare src and dst by reference
84 if( !(src == edge.src) ||
85 !(dst == edge.dst) ) {
93 public boolean equalsIncludingBeta(ReferenceEdge edge) {
94 return equals(edge) && beta.equals(edge.beta);
98 public int hashCode() {
102 hash += type.hashCode()*17;
105 if( field != null ) {
106 hash += field.hashCode()*7;
109 hash += src.hashCode()*11;
110 hash += dst.hashCode();
116 public OwnershipNode getSrc() {
120 public void setSrc(OwnershipNode on) {
125 public HeapRegionNode getDst() {
129 public void setDst(HeapRegionNode hrn) {
135 public TypeDescriptor getType() {
139 public void setType( TypeDescriptor td ) {
143 public String getField() {
147 public void setField( String s ) {
152 public boolean typeEquals( TypeDescriptor td ) {
153 if( type == null && td == null ) {
159 return type.equals( td );
162 public boolean fieldEquals( String s ) {
163 if( field == null && s == null ) {
166 if( field == null ) {
169 return field.equals( s );
172 public boolean typeAndFieldEquals( ReferenceEdge e ) {
173 return typeEquals ( e.getType() ) &&
174 fieldEquals( e.getField() );
178 public boolean isInitialParam() {
179 return isInitialParam;
182 public void setIsInitialParam(boolean isInitialParam) {
183 this.isInitialParam = isInitialParam;
187 public ReachabilitySet getBeta() {
191 public void setBeta(ReachabilitySet beta) {
196 public ReachabilitySet getBetaNew() {
200 public void setBetaNew(ReachabilitySet beta) {
205 public void applyBetaNew() {
206 assert betaNew != null;
209 betaNew = new ReachabilitySet().makeCanonical();
213 public String toGraphEdgeString(boolean hideSubsetReachability,
214 boolean hideEdgeTaints) {
215 String edgeLabel = "";
218 edgeLabel += type.toPrettyString() + "\\n";
222 edgeLabel += field + "\\n";
225 if (isInitialParam) {
226 edgeLabel += "*init*\\n";
229 if( !hideEdgeTaints ) {
230 edgeLabel += "*taint*=" + Integer.toBinaryString(taintIdentifier)
231 + "\\n*SESE*=" + Integer.toBinaryString(SESEtaintIdentifier)
235 edgeLabel += beta.toStringEscapeNewline(hideSubsetReachability);
240 public String toString() {
242 return new String("("+src+"->"+type.toPrettyString()+" "+field+"->"+dst+")");
245 return new String("("+src+"->"+type+" "+field+"->"+dst+")");
248 public void tainedBy(Integer paramIdx){
249 int newTaint=(int) Math.pow(2, paramIdx.intValue());
250 taintIdentifier=taintIdentifier | newTaint;
253 public void setTaintIdentifier(int newTaint){
254 taintIdentifier=newTaint;
257 public void unionTaintIdentifier(int newTaint){
258 taintIdentifier=taintIdentifier | newTaint;
261 public void minusTaintIdentifier(int removedTaint){
262 taintIdentifier = taintIdentifier & (~removedTaint);
265 public int getTaintIdentifier(){
266 return taintIdentifier;
269 public int getSESETaintIdentifier(){
270 return SESEtaintIdentifier;
273 public void setSESETaintIdentifier(int newTaint){
274 SESEtaintIdentifier=newTaint;
277 public void unionSESETaintIdentifier(int newTaint){
278 SESEtaintIdentifier=SESEtaintIdentifier | newTaint;