1 package Analysis.Disjoint;
11 public static final int read = 1;
12 public static final int write = 2;
13 public static final int strongupdate = 4;
15 // identify an allocation site of affected object
16 protected Alloc affectedAllocSite;
18 // identify operation type
22 protected FieldDescriptor field;
24 // for debugging purposes, keep the compilation
25 // unit and line number of this effect--only if state
27 protected int lineNumber;
28 protected ClassDescriptor compilationUnit;
29 protected static Hashtable<FlatNode, ClassDescriptor> fn2cd =
30 new Hashtable<FlatNode, ClassDescriptor>();
33 public Effect(Alloc affectedAS, int type, FieldDescriptor field, FlatNode currentProgramPoint) {
34 this.affectedAllocSite = affectedAS;
39 // NOTE: this line number+compilation unit is collected for debugging,
40 // so we don't want to spend time on this unless OOODEBUG or some new
41 // option controls it. Disjoint and Pointer analysis use this currently.
43 compilationUnit = null;
45 // find the class the current program point belongs to
46 if( currentProgramPoint == null ) {
49 Set<FlatNode> visited = new HashSet<FlatNode>();
50 Set<FlatNode> toVisit = new HashSet<FlatNode>();
51 toVisit.add( currentProgramPoint );
53 while( !toVisit.isEmpty() ) {
54 FlatNode fn = toVisit.iterator().next();
58 // when we find a flat method, remember every node we visited
59 // belongs to that compilation unit
60 if( fn instanceof FlatMethod ) {
61 MethodDescriptor md = ((FlatMethod)fn).getMethod();
63 ClassDescriptor cd = md.getClassDesc();
70 if( fn2cd.containsKey( fn ) ) {
71 compilationUnit = fn2cd.get( fn );
73 for( FlatNode fnKnown: visited ) {
74 fn2cd.put( fnKnown, compilationUnit );
77 lineNumber = currentProgramPoint.getNumLine();
81 for( int i = 0; i < fn.numPrev(); ++i ) {
82 FlatNode prev = fn.getPrev( i );
83 if( !visited.contains( prev ) ) {
90 public static boolean isWrite(int effect) {
91 return (effect & Effect.write)==Effect.write;
94 public boolean isWrite() {
98 public boolean isRead() {
102 public Alloc getAffectedAllocSite() {
103 return affectedAllocSite;
106 public void setAffectedAllocSite(Alloc affectedAllocSite) {
107 this.affectedAllocSite = affectedAllocSite;
110 public int getType() {
114 public void setType(int type) {
118 public FieldDescriptor getField() {
122 public void setField(FieldDescriptor field) {
126 public boolean equals(Object o) {
132 if (!(o instanceof Effect)) {
136 Effect in = (Effect) o;
138 if (affectedAllocSite.equals(in.getAffectedAllocSite())
139 && type == in.getType()
140 && ((field!=null&&field.equals(in.getField()))||
141 (field==null&&in.getField()==null))) {
148 public int hashCode() {
150 int hash = affectedAllocSite.hashCode();
155 hash = hash ^ field.hashCode();
162 public String toString() {
165 s += affectedAllocSite.toStringBrief();
169 } else if (type == write) {
178 s += ", " + field.toStringBrief();
181 if( compilationUnit != null ) {
182 s += ", "+compilationUnit.getSymbol()+":"+lineNumber;