Create analysis model for string literals in disjointness analysis that supports...
[IRC.git] / Robust / src / Analysis / Disjoint / ReachGraph.java
index 6cd946f9ccebef7649c6be7b0fa03a817ccb7ea2..6eedd6ba33374576d5dc230d3447b230b10450b5 100644 (file)
@@ -12,8 +12,18 @@ public class ReachGraph {
   protected static final boolean DISABLE_STRONG_UPDATES = false;
   protected static final boolean DISABLE_GLOBAL_SWEEP   = false;
 
-  // a special out-of-scope temp
-  protected static final TempDescriptor tdReturn = new TempDescriptor("_Return___");
+  // a special out-of-scope temps
+  protected static TempDescriptor tdReturn;
+  protected static TempDescriptor tdStrLiteralBytes;
+  
+  public static void initOutOfScopeTemps() {
+    tdReturn = new TempDescriptor("_Return___");
+
+    tdStrLiteralBytes = 
+      new TempDescriptor("_strLiteralBytes___",
+                         new TypeDescriptor(TypeDescriptor.CHAR).makeArray( state )
+                         );
+  }
 
   // predicate constants
   public static final ExistPred predTrue   = ExistPred.factory();    // if no args, true
@@ -380,6 +390,26 @@ public class ReachGraph {
   //
   ////////////////////////////////////////////////////
 
+  public void assignTempEqualToStringLiteral(TempDescriptor  x,
+                                             AllocSite       asStringLiteral,
+                                             AllocSite       asStringLiteralBytes,
+                                             FieldDescriptor fdStringBytesField) {
+    // model this to get points-to information right for
+    // pointers to string literals, even though it doesn't affect
+    // reachability paths in the heap
+    assignTempEqualToNewAlloc( x, 
+                               asStringLiteral );
+
+    assignTempEqualToNewAlloc( tdStrLiteralBytes, 
+                               asStringLiteralBytes );
+
+    assignTempXFieldFEqualToTempY( x,
+                                   fdStringBytesField,
+                                   tdStrLiteralBytes,
+                                   null );
+  }
+
+
   public void assignTempXEqualToTempY(TempDescriptor x,
                                       TempDescriptor y) {
     assignTempXEqualToCastedTempY(x, y, null);
@@ -5194,17 +5224,24 @@ public class ReachGraph {
 
 
   public Set<Alloc> canPointTo( TempDescriptor x ) {
-    VariableNode vn = getVariableNodeNoMutation( x );
-    if( vn == null ) {
-      return null;
+
+    if( !DisjointAnalysis.shouldAnalysisTrack( x.getType() ) ) {
+      // if we don't care to track it, return null which means
+      // "a client of this result shouldn't care either"
+      return HeapAnalysis.DONTCARE_PTR;
     }
 
     Set<Alloc> out = new HashSet<Alloc>();
 
+    VariableNode vn = getVariableNodeNoMutation( x );
+    if( vn == null ) {
+      // the empty set means "can't point to anything"
+      return out;
+    }
+
     Iterator<RefEdge> edgeItr = vn.iteratorToReferencees();
     while( edgeItr.hasNext() ) {
       HeapRegionNode hrn = edgeItr.next().getDst();
-
       out.add( hrn.getAllocSite() );
     }
 
@@ -5214,20 +5251,34 @@ public class ReachGraph {
 
 
   public Hashtable< Alloc, Set<Alloc> > canPointTo( TempDescriptor x,
-                                                    String         field ) {
+                                                    String         field,
+                                                    TypeDescriptor fieldType ) {
+
+    if( !DisjointAnalysis.shouldAnalysisTrack( x.getType() ) ) {
+      // if we don't care to track it, return null which means
+      // "a client of this result shouldn't care either"
+      return HeapAnalysis.DONTCARE_DREF;
+    }
+
+    Hashtable< Alloc, Set<Alloc> > out = new Hashtable< Alloc, Set<Alloc> >();
     
     VariableNode vn = getVariableNodeNoMutation( x );
     if( vn == null ) {
-      return null;
+      // the empty table means "x can't point to anything"
+      return out;
     }
 
-    Hashtable< Alloc, Set<Alloc> > out = new Hashtable< Alloc, Set<Alloc> >();
-
     Iterator<RefEdge> edgeItr = vn.iteratorToReferencees();
     while( edgeItr.hasNext() ) {
       HeapRegionNode hrn = edgeItr.next().getDst();
+      Alloc          key = hrn.getAllocSite();
 
-      Alloc key = hrn.getAllocSite();
+      if( !DisjointAnalysis.shouldAnalysisTrack( fieldType ) ) {
+        // if we don't care to track it, put no entry which means
+        // "a client of this result shouldn't care either"
+        out.put( key, HeapAnalysis.DONTCARE_PTR );
+        continue;
+      }
 
       Set<Alloc> moreValues = new HashSet<Alloc>();
       Iterator<RefEdge> edgeItr2 = hrn.iteratorToReferencees();