[Soot-list] Exception Table

Silviu ANDRICA silviu.andrica at epfl.ch
Wed Jul 9 05:35:46 EDT 2008


Hello,
    I am trying to develop a static analysis for Java applications and I 
have to deal with Control Flow Graphs. In this endeavour I found a 
"problem" relating to the Exception table translation from Java bytecode 
to Baf.

Consider, for example, the following method:

public void m0();
  Code:
   0:    aload_0
   1:    dup
   2:    astore_1
   3:    monitorenter
   4:    ldc    #16; //String Hello
   6:    dup
   7:    astore_2
   8:    monitorenter
   9:    getstatic    #18; //Field 
java/lang/System.out:Ljava/io/PrintStream;
   12:    ldc    #24; //String Hello World
   14:    invokevirtual    #26; //Method 
java/io/PrintStream.println:(Ljava/lang/String;)V
   17:    aload_2
   18:    monitorexit
   19:    goto    25
   22:    aload_2
   23:    monitorexit
   24:    athrow
   25:    aload_1
   26:    monitorexit
   27:    goto    33
   30:    aload_1
   31:    monitorexit
   32:    athrow
   33:    return
  Exception table:
   from   to  target type
     9    19    22   any
    22    24    22   any
     4    27    30   any
    30    32    30   any

In this case, instructions 22 and 23, corresponding to an exception 
handler, are caught by themselves. So, any exception thrown in this 
exception handler can't escape it. It is the same for the second 
exception handler.

When translating it to Baf, the following code results:

 public void m0()
    {
        word r0, r2, $r6;

        r0 := @this: Test;
        load.r r0;
        store.r r2;
        load.r r0;
        entermonitor;

     label0:
        push "Hello";
        dup1.r;
        store.r r0;
        entermonitor;

     label1:
        staticget <java.lang.System: java.io.PrintStream out>;
        push "Hello World";
        virtualinvoke <java.io.PrintStream: void println(java.lang.String)>;
        load.r r0;
        exitmonitor;

     label2:
        goto label6;

     label3:
        store.r $r6;

     label4:
        load.r r0;
        exitmonitor;

     label5:
        load.r $r6;
        athrow;

     label6:
        load.r r2;
        exitmonitor;

     label7:
        goto label11;

     label8:
        store.r $r6;

     label9:
        load.r r2;
        exitmonitor;

     label10:
        load.r $r6;
        athrow;

     label11:
        return;

        catch java.lang.Throwable from label1 to label2 with label3;
        catch java.lang.Throwable from label4 to label5 with label3;
        catch java.lang.Throwable from label0 to label7 with label8;
        catch java.lang.Throwable from label9 to label10 with label8;
    }
The Baf translation adds, for the first trap, "label3: store.r $r6;". 
The problem is that, now an exceptional edge from it to the second trap 
handler: "label8: store.r $r6;" which does not guarantee that the second 
acquired lock is released: if the first exitmonitor fails and then 
"label 3" fails, then control reaches "label 8" and then only one, the 
first, lock is released.

Any ideas how to solve this?

Best regards,
    Silviu




More information about the Soot-list mailing list