[Soot-list] Using ThreadLocalObjectAnalysis

Rajendra Kumar Dangwal dangwalrajendra888 at gmail.com
Mon Apr 6 07:28:26 EDT 2020


Hi All,

I want to find all the references to the objects which are not escaping a
thread i.e. Thread local objects. I am using ThreadLocalObjectAnalysis to
do it. But it is throwing NullPointerException in
SmartMethodInfoFlowAnalysis. I don't know the reason. I am using Soot
version 3.0 and Java version 1.7.

Code and output are attached for the reference:

Soot-Args and addition to pack:
-------------------------------------------------------------------
String sootArgs[] = {"-cp", classPath, "-pp", "-keep-bytecode-offset",
"-main-class", "test.Test", "-no-bodies-for-excluded", "-w",
"-process-dir", dirPath, "-p", "cg", "enabled:true", "-p", "cg.spark",
"enabled:true",  "-p", "jb", "use-original-names:true", "test.Test"};

EscapeAnalysis analysisTransformer = new EscapeAnalysis();

PackManager.v().getPack("wjtp").add(new Transform("wjtp.esc",
analysisTransformer));

soot.Main.main(sootArgs);
----------------------------------------------------------------------

Analysis:

public class EscapeAnalysis extends SceneTransformer {

     @Override
     protected void internalTransform(String arg0, Map<String, String>
arg1) {

     ThreadLocalObjectsAnalysis tlo = new ThreadLocalObjectsAnalysis(new
SynchObliviousMhpAnalysis());
     tlo.precompute();

     Chain<SootClass> classChain = Scene.v().getApplicationClasses();
     for(SootClass c : classChain) {
          System.out.println("\nClass : " + c + "\n");
          List<SootMethod> methodList = c.getMethods();

          for(SootMethod m : methodList) {
              if(m.isConcrete()) {
                   System.out.println("\nMethod : "+ m);
                   System.out.print("Thread Local var: ");
                   Chain<Local> localVars =
m.retrieveActiveBody().getLocals();
                   for(Local l : localVars) {
                    if(tlo.isObjectThreadLocal(l, m))
                   System.out.print(l.getName() + " ");
                   }
               }
            }
         }
     }
}


----------------------------------------------------------------------------------------

Code to be analyzed:

package test;

class Test{

  public static void main(String args[]){
    ClassA obj = new ClassA();
    MyThread t1 = new MyThread(obj);
    MyThread t2 = new MyThread(obj);
    t1.start();
    t2.start();

  }
}

class MyThread extends Thread{
  int localInt;
  ClassA obj;
  public MyThread(ClassA obj){
    localInt = 1;
    this.obj = obj;
  }

  public void run(){
    System.out.println("localInt: "+ localInt);
    System.out.println("obj.i: "+ obj.i);
  }
}

class ClassA{
  public int i = 10;
}


-----------------------------------------------------------------------------------

Output:

Soot started on Fri Apr 03 12:09:42 IST 2020
[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.1 seconds.
[Spark] Type masks in 0.0 seconds.
[Spark] Pointer Graph simplified in 0.0 seconds.
[Spark] Propagation in 0.3 seconds.
[Spark] Solution found in 0.3 seconds.
[local-objects] Analyzing local objects for test.MyThread
[local-objects]   preparing class             Fri Apr 03 12:09:44 IST 2020
[local-objects]   analyzing class             Fri Apr 03 12:09:44 IST 2020
java.lang.NullPointerException
at
soot.jimple.toolkits.infoflow.SmartMethodInfoFlowAnalysis.handleInvokeExpr(SmartMethodInfoFlowAnalysis.java:408)
at
soot.jimple.toolkits.infoflow.SmartMethodInfoFlowAnalysis.addFlowToCdfg(SmartMethodInfoFlowAnalysis.java:793)
at
soot.jimple.toolkits.infoflow.SmartMethodInfoFlowAnalysis.generateAbbreviatedInfoFlowGraph(SmartMethodInfoFlowAnalysis.java:151)
at
soot.jimple.toolkits.infoflow.SmartMethodInfoFlowAnalysis.<init>(SmartMethodInfoFlowAnalysis.java:128)
at
soot.jimple.toolkits.infoflow.ClassInfoFlowAnalysis.getMethodInfoFlowSummary(ClassInfoFlowAnalysis.java:91)
.....

Please help.

Thanks,
Rajendra
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.CS.McGill.CA/pipermail/soot-list/attachments/20200406/34c87f61/attachment-0001.html>


More information about the Soot-list mailing list