[Soot-list] Counting exits in a loop - understanding Jimple "goto [?= nop]"

John Dean jdean4 at kc.rr.com
Mon Jul 16 08:53:18 EDT 2012


All,
My goal is to determine the number of exits in a loop. I've written code that retrieves a list of Stmt objects that comprise a loop. I use the following code to count the number of exits within a loop's statements:

for (Stmt s : loopStmts)
{
  for (Unit succ : g.getSuccsOf(s))
  {
    if (!loopStmts.contains(succ))
    {
      numOfExits++;
    }
  }
}

I borrowed the code above from soot's Loop.getLoopExits(), so I think it's correct, but not 100% sure.
When I run my program on the following sample loop, the program says that there are 3 exits in the outer loop and 1 exit in the inner loop:

for (int j=0; j<2; j++)
{
  System.out.println("J = " + j);
  for (int k=0; k<2; k++)
  {
    System.out.println("k = " + k);
  }
}

I think my program should say 1 exit in each loop. Thus, I'm trying to figure out why it mistakenly says 3 exits in the outer loop instead of 1 exit.

For debugging purposes, I've printed the statements that my program has generated for each loop. Here is the list of statements for just the outer loop:

[java] [nop, if j < 2 goto nop, nop, temp$8 = <java.lang.System: java.io.PrintStream out>, temp$9 = new java.lang.StringBuffer, specialinvoke temp$9.<java.lang.StringBuffer: void <init>()>(), nop, uniqueArgLocal1 = "J = ", retval$2 = virtualinvoke temp$9.<java.lang.StringBuffer: java.lang.StringBuffer append(java.lang.Object)>(uniqueArgLocal1), retval$3 = virtualinvoke temp$9.<java.lang.StringBuffer: java.lang.StringBuffer append(int)>(j), temp$10 = virtualinvoke temp$9.<java.lang.StringBuffer: java.lang.String toString()>(), virtualinvoke temp$8.<java.io.PrintStream: void println(java.lang.String)>(temp$10), k = 0, nop, temp$11 = <java.lang.System: java.io.PrintStream out>, temp$12 = new java.lang.StringBuffer, specialinvoke temp$12.<java.lang.StringBuffer: void <init>()>(), nop, uniqueArgLocal2 = "k = ", retval$4 = virtualinvoke temp$12.<java.lang.StringBuffer: java.lang.StringBuffer append(java.lang.Object)>(uniqueArgLocal2), retval$5 = virtualinvoke temp$12.<java.lang.StringBuffer: java.lang.StringBuffer append(int)>(k), temp$13 = virtualinvoke temp$12.<java.lang.StringBuffer: java.lang.String toString()>(), virtualinvoke temp$11.<java.io.PrintStream: void println(java.lang.String)>(temp$13), nop, temp$14 = k, temp$15 = temp$14 + 1, k = temp$15, goto [?= nop], goto [?= nop], nop, nop, temp$16 = j, temp$17 = temp$16 + 1, j = temp$17, goto [?= nop]]

In trying to understand why my program determines that those statements have 3 exits, my guess so far is that it has something to do with the 3 goto [?= nop] statements near the end, but I'm not sure.

I'm new to soot, and trying to understand the statements shown above. I am assuming they are Jimple statements, so I've searched for Jimple documentation to help, but I've not found anything that helps me yet.

I'm guessing that there's a bug in my program's generation of the loop's statements, but it's hard to debug it when I don't understand the resulting statements.

1. What is the meaning of "goto [?= nop]"
2. Any guidance on why there are 3 exits in the loop statements shown above?
3. Any advice on Jimple documentation that might help me to understand things better?

Thanks,
John



More information about the Soot-list mailing list