model the allocation of string literals in heap analysis
authorjjenista <jjenista>
Fri, 13 May 2011 22:06:20 +0000 (22:06 +0000)
committerjjenista <jjenista>
Fri, 13 May 2011 22:06:20 +0000 (22:06 +0000)
Robust/src/Analysis/Disjoint/DisjointAnalysis.java
Robust/src/Analysis/Disjoint/HeapAnalysis.java
Robust/src/Analysis/Disjoint/PointerMethod.java
Robust/src/Analysis/Pointer/Pointer.java
Robust/src/IR/Flat/BCXPointsToCheckVRuntime.java
Robust/src/IR/Flat/BCXallocsiteObjectField.java
Robust/src/IR/Flat/BuildCode.java
Robust/src/IR/Flat/BuildCodeExtension.java
Robust/src/IR/TypeUtil.java

index 583aa3d18272774cb965a05b6b1760f4ea95495c..802a6ca023c9ae8fce62a59c2ffc49434f2fb486 100644 (file)
@@ -359,6 +359,10 @@ public class DisjointAnalysis implements HeapAnalysis {
   public Alloc getCmdLineArgBytesAlloc() {
     return getAllocationSiteFromFlatNew( constructedCmdLineArgBytesNew );
   }
+  public Alloc getNewStringLiteralAlloc() {
+    return newStringLiteralAlloc;
+  }
+
   ///////////////////////////////////////////
   //
   // end public interface
@@ -569,6 +573,11 @@ public class DisjointAnalysis implements HeapAnalysis {
   protected FlatNew constructedCmdLineArgNew;
   protected FlatNew constructedCmdLineArgBytesNew;
 
+  
+  // similar to above, the runtime allocates new strings
+  // for literal nodes, so make up an alloc to model that
+  protected TypeDescriptor strLiteralType;
+  protected AllocSite      newStringLiteralAlloc;
 
 
 
@@ -757,9 +766,9 @@ public class DisjointAnalysis implements HeapAnalysis {
       = state.DISJOINTDEBUGCALLSTOPAFTER;
 
     ReachGraph.debugCallSiteVisitCounter
-      = 0; // count visits from 1, is incremented before first visit
+      = 0; // count visits from 1, is incremented before first visit    
+
 
-    
 
 
     if( suppressOutput ) {
@@ -768,6 +777,23 @@ public class DisjointAnalysis implements HeapAnalysis {
 
     allocateStructures();
 
+    // model the implicit alloction site for new string literals
+    strLiteralType = new TypeDescriptor( typeUtil.getClass( typeUtil.StringClass ) );
+    TempDescriptor throwAway =
+      new TempDescriptor("stringLiteralTemp_dummy",
+                         strLiteralType
+                         );
+    FlatNew fnStringLiteral =
+      new FlatNew(strLiteralType,
+                  throwAway,
+                  false  // is global
+                  );
+    newStringLiteralAlloc
+      = getAllocSiteFromFlatNewPRIVATE( fnStringLiteral );
+
+
+
+
     double timeStartAnalysis = (double) System.nanoTime();
 
     // start interprocedural fixed-point computation
@@ -888,6 +914,7 @@ public class DisjointAnalysis implements HeapAnalysis {
     }
 
 
+
     // now, depending on the interprocedural mode for visiting
     // methods, set up the needed data structures
 
@@ -1481,6 +1508,21 @@ public class DisjointAnalysis implements HeapAnalysis {
       }
       break;
 
+      
+    case FKind.FlatLiteralNode:
+      // BIG NOTE: this transfer function is only here for
+      // points-to information for String literals.  That's it.
+      // Effects and disjoint reachability and all of that don't
+      // care about references to literals.
+      FlatLiteralNode fln = (FlatLiteralNode) fn;
+
+      if( fln.getType().equals( strLiteralType ) ) {
+        rg.assignTempEqualToNewAlloc( fln.getDst(),
+                                      newStringLiteralAlloc );
+      }      
+      break;
+
+
     case FKind.FlatSESEEnterNode:
       sese = (FlatSESEEnterNode) fn;
 
index ce041e8f5f89083400af034e6967b22936ba47c1..04b96a9cf08070fb80eadc8834cc5e32660755f4 100644 (file)
@@ -24,6 +24,12 @@ public interface HeapAnalysis {
   public Alloc getCmdLineArgAlloc();     // a String
   public Alloc getCmdLineArgBytesAlloc();// an array of char
 
+
+  // similar to above, new string literals have a runtime alloc site (not in
+  // code explicitly) so make one in your model and return it here
+  public Alloc getNewStringLiteralAlloc(); // a String
+
+
   // Use these methods to find out what allocation sites
   // the given pointer might point to at or after the 
   // given program point.  In the case of a variable and
index 501ecdfe782a19af907e043df0a0b285d46017b6..5246c9b8deb1923e9a11ac37042f18a517a0e530 100644 (file)
@@ -92,6 +92,7 @@ public class PointerMethod {
     case FKind.FlatElementNode:
     case FKind.FlatSetElementNode:
     case FKind.FlatNew:
+    case FKind.FlatLiteralNode:
     case FKind.FlatCall:
     case FKind.FlatReturnNode:
     case FKind.FlatBackEdge:
index efaf3fe856eb28ec6dc77028844fae85e5e9f2bc..2c76a76d65fa6ecbd79d6d715dd54dc3daf94cf9 100644 (file)
@@ -2105,6 +2105,9 @@ nextdelta:
   public Alloc getCmdLineArgBytesAlloc() {
     return null;
   }
+  public Alloc getNewStringLiteralAlloc() {
+    return null;
+  }
 
 
   public Set<Alloc> canPointToAt( TempDescriptor x,
index 1aa948b160e563d04952534ad628f187992242d7..3f658db523d51c01f4fd0b551595db025185f1f2 100644 (file)
@@ -388,4 +388,5 @@ public class BCXPointsToCheckVRuntime implements BuildCodeExtension {
   public void additionalIncludesStructsHeader(PrintWriter outstructs) {}
   public void additionalCodeAtTopMethodsImplementation(PrintWriter outmethod) {}
   public void additionalCodeNewObject(PrintWriter outmethod, String dstVar, FlatNew flatNew) {}
+  public void additionalCodeNewStringLiteral(PrintWriter output, String dstVar) {}
 }
index 096de3ecb78726db7282e0bd488475a9b637c43b..ee8dc81cba627c8c1545aa55ae4534936758661d 100644 (file)
@@ -34,6 +34,7 @@ public class BCXallocsiteObjectField implements BuildCodeExtension {
     outclassdefs.println("  int allocsite;");    
   }
 
+
   public void additionalCodeForCommandLineArgs(PrintWriter outmethod, String argsVar) {
 
     ClassDescriptor cdString = typeUtil.getClass( typeUtil.StringClass );
@@ -75,6 +76,7 @@ public class BCXallocsiteObjectField implements BuildCodeExtension {
     outmethod.println("");
   }
 
+
   public void additionalCodeNewObject(PrintWriter outmethod, String dstVar, FlatNew flatNew) {
     outmethod.println(dstVar+"->allocsite = "+
                       heapAnalysis.getAllocationSiteFromFlatNew( flatNew ).getUniqueAllocSiteID()+
@@ -83,6 +85,15 @@ public class BCXallocsiteObjectField implements BuildCodeExtension {
   }
 
 
+  public void additionalCodeNewStringLiteral(PrintWriter output, String dstVar) {
+    output.println(dstVar+"->allocsite = "+
+                   heapAnalysis.getNewStringLiteralAlloc().getUniqueAllocSiteID()+
+                   ";"
+                   );    
+  }
+
+
+
   public void printExtraArrayFields(PrintWriter outclassdefs) {}
   public void outputTransCode(PrintWriter output) {}
   public void buildCodeSetup() {}
index 6544c721f18492a3427064af632a39a81c64e0d7..b87e6e63e7ac333d49ecde2ea4e7ab49ce3880de 100644 (file)
@@ -3005,6 +3005,11 @@ fldloop:
       } else {
         output.println(generateTemp(fm, fln.getDst())+"=NewStringShort(str"+flncount+" ,"+((String)fln.getValue()).length()+");");
       }
+      
+      for(BuildCodeExtension bcx: extensions) {
+        bcx.additionalCodeNewStringLiteral(output, generateTemp(fm, fln.getDst()));
+      }      
+
       output.println("}");
       flncount++;
     } else if (fln.getType().isBoolean()) {
index e7f013334f33f5957de239b51fcb4e2d225c916b..53484f64c4b510cf38bf56922790ecd8c004602a 100644 (file)
@@ -34,4 +34,5 @@ public interface BuildCodeExtension {
   public void additionalCodePreNode(FlatMethod fm, FlatNode fn, PrintWriter output);
   public void additionalCodePostNode(FlatMethod fm, FlatNode fn, PrintWriter output);
   public void additionalCodeNewObject(PrintWriter outmethod, String dstVar, FlatNew flatNew);
+  public void additionalCodeNewStringLiteral(PrintWriter output, String dstVar);
 }
index 2921e1e5bbc814e728db0d393909fd401c093999..cdb2a1712064bc637e82607e4b74bd8fd64400e3 100644 (file)
@@ -470,7 +470,7 @@ NextMethod:
     while(cd2!=null) {
       cd2=getSuper(cd2);
       if (cd2==possiblesuper)
-        return true;
+         return true;
 
       // check cd2's interface ancestors
       if(cd2 != null) {