[Soot-list] Loop Finder: Identify Synchronized Block as Loops

Eric Bodden bodden at st.informatik.tu-darmstadt.de
Wed Aug 19 04:05:56 EDT 2009


I just double-checked this. Oddly enough, apparently Soot *is*
generating correct code. There has to be a loop there! (and javac and
eclipse generate a loop there too) Here's why:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4414101

Short summary: The monitorenter can fail through an exception.
However, by definition, the program is not allowed to proceed past the
synchronized block without releasing the monitor. Therefore the
program has to "retry". This can obviously lead to an infinite loop -
a deadlock (or livelock if you will). That's sort of a very odd corner
case in the language definition.

Eric

2009/8/18 Eric Bodden <bodden at st.informatik.tu-darmstadt.de>:
> This seems to be a (known?) bug in Soot with respect to synchronized
> blocks. Soot generates for this snippet...
>
>    public TestLoop() throws Exception {
>
>        synchronized (System.out) {
>            ;
>        }
>
>    }
>
> ... the following Jimple code:
>
> ...
>     label0:
>        nop;
>        exitmonitor temp$0;
>        goto label2;
>
>     label1:
>        nop;
>        temp$1 := @caughtexception;
>        exitmonitor temp$0;
>        throw temp$1;
>
>     label2:
>        nop;
>        return;
>
>        catch java.lang.Throwable from label0 to label2 with label1;
>
> The problem is here the catch clause at the end. I think it should
> read "from label0 to label1 with label1" instead. The way it's wired
> up right now, there is indeed an exceptional flow edge from anything
> between label1 and label2 back to label1, which yields a loop.
>
> I think Patrick Lam tried to fix this a while ago but his fix was
> invalid. I guess we will have to look into this again. (It's less
> trivial than one might think because that code in Soot is quite old
> and nobody seems to know any more quite how it works. :-))
>
> Eric
>
> 2009/8/18 Kelvin Tian <kevinn.tian at gmail.com>:
>> OK, sure. Here's a simple test example. To see the result, just use the
>> LoopFinder to transform it.  Thanks for the consistent help.
>>
>>
>> class TestLoop {
>>
>>     public TestLoop() throws Exception {
>>
>>         synchronized (System.out) {
>>             ;
>>         }
>>         synchronized (System.err) {
>>             ;
>>         }
>>
>>     }
>>
>>
>>     public static void main(String[] args) {
>>
>>         int loopcnt = 0;
>>
>>         for (int i = 0; i < 5; i++) {
>>             int j=0;
>>
>>             while(j<3){
>>                 loopcnt++;
>>                 j++;
>>             }
>>         }
>>     }
>>
>> }
>>
>>
>>
>> --
>> Best regards,
>> Kelvin
>>
>>
>>
>> On Tue, Aug 18, 2009 at 2:27 AM, Eric Bodden
>> <bodden at st.informatik.tu-darmstadt.de> wrote:
>>>
>>> Hi Kelvin.
>>>
>>> This sounds like a bug to me. There is certainly no transformation
>>> into loops as you describe it.
>>>
>>> Can you please send a minimal example to the list where this occurs?
>>>
>>> Eric
>>>
>>> 2009/8/17 Kelvin Tian <kevinn.tian at gmail.com>:
>>> > Hi,
>>> >
>>> >      I need to collect some profiling information based on loops, and I
>>> > reused the LoopFinder class to find loops, but when I tried to collect
>>> > some
>>> > information from the Dacapo benchmark, I found a lot of problems. One
>>> > major
>>> > problem is that LoopFinder always took synchronized block as multiple
>>> > loops
>>> > (normally 3 loops from one synchronized block).  Is this a possible bug
>>> > or
>>> > Synchronized block is translated to be some kind of loops in Soot?
>>> >
>>> >
>>> > --
>>> > Best regards,
>>> > Kelvin
>>> >
>>> >
>>> > _______________________________________________
>>> > Soot-list mailing list
>>> > Soot-list at sable.mcgill.ca
>>> > http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list
>>> >
>>> >
>>>
>>>
>>>
>>> --
>>> Eric Bodden
>>> Software Technology Group
>>> Technical University Darmstadt, Germany
>>
>>
>
>
>
> --
> Eric Bodden
> Software Technology Group
> Technical University Darmstadt, Germany
>



-- 
Eric Bodden
Software Technology Group
Technical University Darmstadt, Germany


More information about the Soot-list mailing list