[Soot-list] Re: Exception Table

Richard L. Halpert richardlhalpert at gmail.com
Wed Jul 9 13:14:22 EDT 2008


I don't think this problem is specific to Baf, as I've seen the same
arrangement of exception handling in jimple code dealing with synchronized
regions.  The problem is most likely in the Java to Jimple translation for a
synchronized block.  Unfortunately, I'm really swamped and don't have time
to go take a look...

-Rich

On Wed, Jul 9, 2008 at 9:25 AM, Silviu ANDRICA <silviu.andrica at epfl.ch>
wrote:

> Hello,
>   Thanks for replying so quick.
>
> The Source code is:
>
>
> public class Test {
>   public void m0() {
>       synchronized (this) {
>           synchronized ("Hello") {
>               System.out.println("Hello World");
>           }
>
>       }
>   }
> }
>
> The Jimple version, for the m0 method only,  is:
> public void m0()
>   {
>       Test r0, r2;
>       java.lang.String r3, $r4;
>       java.io.PrintStream $r5;
>       java.lang.Throwable $r6, $r7;
>
>       r0 := @this: Test;
>       r2 = r0;
>       entermonitor r0;
>
>    label0:
>       $r4 = "Hello";
>       r3 = $r4;
>       entermonitor $r4;
>
>    label1:
>       $r5 = <java.lang.System: java.io.PrintStream out>;
>       virtualinvoke $r5.<java.io.PrintStream: void
> println(java.lang.String)>("Hello World");
>       exitmonitor r3;
>
>    label2:
>       goto label6;
>
>    label3:
>       $r6 := @caughtexception;
>
>    label4:
>       exitmonitor r3;
>
>    label5:
>       throw $r6;
>
>    label6:
>       exitmonitor r2;
>
>    label7:
>       goto label11;
>
>    label8:
>       $r7 := @caughtexception;
>
>    label9:
>       exitmonitor r2;
>
>    label10:
>       throw $r7;
>
>    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 problem is the same, "label 3" is not caught by itself.
>
> Best regards,
>   Silviu
>
> Silviu ANDRICA wrote:
>
>> 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
>>
>>
>>
>>
>>
>
> _______________________________________________
> Soot-list mailing list
> Soot-list at sable.mcgill.ca
> http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.CS.McGill.CA/pipermail/soot-list/attachments/20080709/c57ca46c/attachment.htm


More information about the Soot-list mailing list