fixes on PCLOC generation, intermediate node insertion, etc...
[IRC.git] / Robust / src / Analysis / SSJava / SSJavaAnalysis.java
index 0212365576022fc031de8500cbea1789b1ee01c6..adf303d533a74f549615468aa7e2591430ad0ced 100644 (file)
@@ -6,18 +6,19 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 import java.util.StringTokenizer;
 import java.util.Vector;
 
 import Analysis.CallGraph.CallGraph;
 import Analysis.Loops.GlobalFieldType;
-import Analysis.Loops.LoopFinder;
 import Analysis.Loops.LoopOptimize;
 import Analysis.Loops.LoopTerminate;
 import IR.AnnotationDescriptor;
@@ -41,6 +42,7 @@ public class SSJavaAnalysis {
   public static final String THISLOC = "THISLOC";
   public static final String GLOBALLOC = "GLOBALLOC";
   public static final String RETURNLOC = "RETURNLOC";
+  public static final String PCLOC = "PCLOC";
   public static final String LOC = "LOC";
   public static final String DELTA = "DELTA";
   public static final String TERMINATE = "TERMINATE";
@@ -84,6 +86,9 @@ public class SSJavaAnalysis {
   // the set of method descriptors annotated as "TRUST"
   Set<MethodDescriptor> trustWorthyMDSet;
 
+  // method -> the initial program counter location
+  Map<MethodDescriptor, CompositeLocation> md2pcLoc;
+
   // points to method containing SSJAVA Loop
   private MethodDescriptor methodContainingSSJavaLoop;
 
@@ -123,20 +128,24 @@ public class SSJavaAnalysis {
     this.sameHeightWriteFlatNodeSet = new HashSet<FlatNode>();
     this.mapDescriptorToSetDependents = new Hashtable<Descriptor, Set<MethodDescriptor>>();
     this.sortedDescriptors = new LinkedList<MethodDescriptor>();
+    this.md2pcLoc = new HashMap<MethodDescriptor, CompositeLocation>();
   }
 
   public void doCheck() {
     doMethodAnnotationCheck();
-    computeLinearTypeCheckMethodSet();
-    doLinearTypeCheck();
 
-    init();
+    if (state.SSJAVA && !state.SSJAVAINFER) {
+      computeLinearTypeCheckMethodSet();
+      doLinearTypeCheck();
+      init();
+    }
 
     if (state.SSJAVADEBUG) {
-      debug_printAnnotationRequiredSet();
+      // debug_printAnnotationRequiredSet();
     }
     if (state.SSJAVAINFER) {
       inference();
+      System.exit(0);
     } else {
       parseLocationAnnotation();
       doFlowDownCheck();
@@ -145,7 +154,7 @@ public class SSJavaAnalysis {
     }
   }
 
-  private void init() {
+  public void init() {
     // perform topological sort over the set of methods accessed by the main
     // event loop
     Set<MethodDescriptor> methodDescriptorsToAnalyze = new HashSet<MethodDescriptor>();
@@ -256,6 +265,10 @@ public class SSJavaAnalysis {
     methodAnnotationChecker = new MethodAnnotationCheck(this, state, tu);
     methodAnnotationChecker.methodAnnoatationCheck();
     methodAnnotationChecker.methodAnnoataionInheritanceCheck();
+    if (state.SSJAVAINFER) {
+      annotationRequireClassSet.add(methodContainingSSJavaLoop.getClassDesc());
+      annotationRequireSet.add(methodContainingSSJavaLoop);
+    }
     state.setAnnotationRequireSet(annotationRequireSet);
   }
 
@@ -332,15 +345,23 @@ public class SSJavaAnalysis {
 
   public <T> void writeLatticeDotFile(ClassDescriptor cd, MethodDescriptor md,
       SSJavaLattice<T> locOrder) {
+    writeLatticeDotFile(cd, md, locOrder, "");
+
+  }
+
+  public <T> void writeLatticeDotFile(ClassDescriptor cd, MethodDescriptor md,
+      SSJavaLattice<T> locOrder, String nameSuffix) {
 
     String fileName = "lattice_";
     if (md != null) {
       fileName +=
-          cd.getSymbol().replaceAll("[\\W_]", "") + "_" + md.getSymbol().replaceAll("[\\W_]", "");
+          cd.getSymbol().replaceAll("[\\W_]", "") + "_" + md.toString().replaceAll("[\\W_]", "");
     } else {
       fileName += cd.getSymbol().replaceAll("[\\W_]", "");
     }
 
+    fileName += nameSuffix;
+
     Set<Pair<T, T>> pairSet = locOrder.getOrderingPairSet();
 
     if (pairSet.size() > 0) {
@@ -366,7 +387,7 @@ public class SSJavaAnalysis {
           } else {
             lowLocStr = lowLocId.toString();
           }
-          bw.write(highLocId + " -> " + lowLocId + ";\n");
+          bw.write(highLocStr + " -> " + lowLocStr + ";\n");
         }
         bw.write("}\n");
         bw.close();
@@ -444,7 +465,7 @@ public class SSJavaAnalysis {
         locOrder.put(higherLoc, lowerLoc);
         if (locOrder.isIntroducingCycle(higherLoc)) {
           throw new Error("Error: the order relation " + lowerLoc + " < " + higherLoc
-              + " introduces a cycle.");
+              + " introduces a cycle in the class lattice " + cd);
         }
       } else if (orderElement.contains("*")) {
         // spin loc definition
@@ -500,6 +521,19 @@ public class SSJavaAnalysis {
     }
   }
 
+  public CompositeLocation getPCLocation(MethodDescriptor md) {
+    if (!md2pcLoc.containsKey(md)) {
+      // by default, the initial pc location is TOP
+      CompositeLocation pcLoc = new CompositeLocation(new Location(md, Location.TOP));
+      md2pcLoc.put(md, pcLoc);
+    }
+    return md2pcLoc.get(md);
+  }
+
+  public void setPCLocation(MethodDescriptor md, CompositeLocation pcLoc) {
+    md2pcLoc.put(md, pcLoc);
+  }
+
   public boolean needToCheckLinearType(MethodDescriptor md) {
     return linearTypeCheckMethodSet.contains(md);
   }