[Soot-list] Regarding Purity Analysis

Chengnian Sun chengniansun at gmail.com
Fri Apr 19 11:47:15 EDT 2013


Dear All,

I am using soot to perform purity analysis, and find the result seems not
precise. It will be great if someone can give me some hints on this issue.

I have the following small class to analyze its purity. The purity analysis
outputs that the method "ExceptionTest.test(String)" is impure. But to me,
it is pure as it does not change the heap state before the invocation to
this method. Am I right?

////////////////////////////////////////////////   test code
 //////////////////////////////////
public class ExceptionTest {

  private int size;

  public String test(String i) {
    StringBuffer buffer = new StringBuffer();
    buffer.append("Index:");
    buffer.append(i);
    return buffer.toString();
  }

  public static void main(String[] args) {
    new ExceptionTest().test("1");
  }
}



The following is the code to invoke soot.
////////////////////////////////////////////////  code to invoke soot
////////////////////////////////////////////////

Options.v().set_unfriendly_mode(true);
Options.v().set_whole_program(true);
Options.v().set_soot_classpath(PurityAnalysisConstants.SOOT_CLASS_PATH);
Options.v().set_verbose(false);
PhaseOptions.v().setPhaseOption("cg.spark", "on");
PhaseOptions.v().setPhaseOption("wjap.purity", "on");
Options.v().classes().add(className);

SootClass sootClass = Scene.v().forceResolve(className, SootClass.BODIES);
sootClass.setApplicationClass();
Scene.v().loadNecessaryClasses();
SootMethod mainMethod = sootClass.getMethodByName("main");
Scene.v().setEntryPoints(Arrays.asList(mainMethod));

PackManager.v().runPacks();




And the following is the output by soot.
////////////////////////////////////////////////  output by soot
////////////////////////////////////////////////

[Call Graph] For information on where the call graph may be incomplete, use
the verbose option to the cg phase.
[Spark] Pointer Assignment Graph in 0.7 seconds.
[Spark] Type masks in 0.0 seconds.
[Spark] Pointer Graph simplified in 0.0 seconds.
[Spark] Propagation in 67.9 seconds.
[Spark] Solution found in 67.9 seconds.
[AM] Analysing purity
[AM] number of methods to be analysed: 11
[AM] Analysis began
[AM] Analysis finished
[AM] run time: 0.071 s
[AM] Dumping .dot summaries of analysed methods
[AM] Annotate methods.
  |- method <ExceptionTest: java.lang.String test(java.lang.String)> is
impure
  |   |- this is Safe
  |   |- param 0 is read/write
  |- method <ExceptionTest: void main(java.lang.String[])> is pure
  |   |- param 0 is safe
  |- method <java.lang.StringBuffer: void <init>(int)> is pure
  |   |- this is read/write
  |- method <java.lang.StringBuffer: void expandCapacity(int)> is impure
  |   |- this is read/write
  |- method <java.lang.Object: void <init>()> is pure
  |   |- this is Safe
  |- method <java.lang.StringBuffer: java.lang.StringBuffer
append(java.lang.String)> is impure
  |   |- this is read/write
  |   |- param 0 is read/write
  |- method <java.lang.Object: void finalize()> is pure
  |   |- this is Safe
  |- method <java.lang.String: int length()> is pure
  |   |- this is Safe
  |- method <java.lang.StringBuffer: void <init>()> is pure
  |   |- this is read/write
  |- method <java.lang.String: void getChars(int,int,char[],int)> is impure
  |   |- this is read/write
  |   |- param 2 is read/write
  |- method <ExceptionTest: void <init>()> is pure
  |   |- this is Safe
Transforming ExceptionTest...





-- 
Best Regards.

Chengnian SUN.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.cs.mcgill.ca/pipermail/soot-list/attachments/20130419/fd22b395/attachment.html 


More information about the Soot-list mailing list