001: package soot.jimple.toolkits.thread.mhp;
002:
003: import java.util.*;
004: import soot.toolkits.scalar.*;
005:
006: // *** USE AT YOUR OWN RISK ***
007: // May Happen in Parallel (MHP) analysis by Lin Li.
008: // This code should be treated as beta-quality code.
009: // It was written in 2003, but not incorporated into Soot until 2006.
010: // As such, it may contain incorrect assumptions about the usage
011: // of certain Soot classes.
012: // Some portions of this MHP analysis have been quality-checked, and are
013: // now used by the Transactions toolkit.
014: //
015: // -Richard L. Halpert, 2006-11-30
016:
017: public class MonitorSet extends ArraySparseSet {
018:
019: // int size = 0;
020:
021: MonitorSet() {
022: super ();
023: }
024:
025: public Object getMonitorDepth(String objName) {
026: Iterator it = iterator();
027: while (it.hasNext()) {
028: Object obj = it.next();
029: if (obj instanceof MonitorDepth) {
030: MonitorDepth md = (MonitorDepth) obj;
031: if (md.getObjName().equals(objName))
032: return md;
033: }
034: }
035: return null;
036: }
037:
038: public MonitorSet clone() {
039: MonitorSet newSet = new MonitorSet();
040: newSet.union(this );
041: return newSet;
042: }
043:
044: /*public void copy(MonitorSet dest){
045: System.out.println("====begin copy");
046: dest.clear();
047: Iterator iterator = iterator();
048: while (iterator.hasNext()){
049: Object obj = iterator.next();
050: if (obj instanceof MonitorDepth) {
051: System.out.println("obj: "+((MonitorDepth)obj).getObjName());
052: System.out.println("depth: "+((MonitorDepth)obj).getDepth());
053: }
054: else
055: System.out.println("obj: "+obj);
056: if (!dest.contains(obj)) dest.add(obj);
057: else System.out.println("dest contains "+obj);
058: }
059: System.out.println("===finish copy===");
060: }
061: */
062:
063: /**
064: * Returns the union (join) of this MonitorSet and <code>other</code>, putting
065: * result into <code>this</code>. */
066: public void union(MonitorSet other) {
067:
068: }
069:
070: /**
071: * Returns the union (join) of this MonitorSet and <code>other</code>, putting
072: * result into <code>dest</code>. <code>dest</code>, <code>other</code> and
073: * <code>this</code> could be the same object.
074: */
075: /*ublic void union(MonitorSet other, MonitorSet dest){
076: other.copy(dest);
077: Iterator iterator = iterator();
078: while (iterator.hasNext()){
079:
080: MonitorDepth md = (MonitorDepth)iterator.next();
081: Object obj = dest.getMonitorDepth(md.getObjName());
082: if ( obj == null){
083: dest.add(md);
084: }
085: else{
086: if (obj instanceof MonitorDepth){
087: if (md.getDepth() != ((MonitorDepth)obj).getDepth())
088: throw new RuntimeException("Find different monitor depth at merge point!");
089:
090: }
091: else
092: throw new RuntimeException("MonitorSet contains non MonitorDepth element!");
093: }
094:
095: }
096:
097: }
098: */
099: public void intersection(MonitorSet other, MonitorSet dest) {
100: /*
101: System.out.println("this:");
102: this.test();
103: System.out.println("other:");
104: other.test();
105: */
106: if (other.contains("&")) {
107:
108: this .copy(dest);
109: //System.out.println("copy this to dest: ");
110: //dest.test();
111: } else if (this .contains("&")) {
112: other.copy(dest);
113: //System.out.println("copy other to dest: ");
114: //dest.test();
115: } else {
116: Iterator it = iterator();
117: while (it.hasNext()) {
118: Object o = it.next();
119: if (o instanceof MonitorDepth) {
120: MonitorDepth md = (MonitorDepth) o;
121: Object obj = dest.getMonitorDepth(md.getObjName());
122: if (obj != null)
123:
124: if (md.getDepth() != ((MonitorDepth) obj)
125: .getDepth()) {
126: throw new RuntimeException(
127: "stmt inside different monitor depth !");
128: } else
129: dest.add(obj);
130: }
131: }
132:
133: }
134:
135: }
136:
137: public void test() {
138: System.out.println("====MonitorSet===");
139: Iterator it = iterator();
140: while (it.hasNext()) {
141: Object obj = it.next();
142: if (obj instanceof MonitorDepth) {
143: MonitorDepth md = (MonitorDepth) obj;
144: ;
145: System.out.println("obj: " + md.getObjName());
146: System.out.println("depth: " + md.getDepth());
147: } else
148: System.out.println(obj);
149: }
150: System.out.println("====MonitorSet end====");
151: }
152:
153: }
|