Optimizer optimizing away too much?

Bryce McKinlay mckinlay@redhat.com
Tue Aug 10 20:36:00 GMT 2004


Could you post a full test case please? That behaviour would surprise 
me, too.

Thanks

Bryce

Thomas Aeby wrote:

>Hello
>
>Great oops for me: I just found out, that GCJ (3.4.0), using
>with "-O" optimizes away something like
>
>    ...
>    public synchronized void increment() {
>        value++;
>    }
>
>I assume the optimizer thinks "value++" is just an unused value
>and does not respect that this also changes the value of value.
>
>If I add a System.out after value++ like
>
>   public ...
>   {
>	value++;
>	System.out( "value of value: " + value );
>   }
>
>or change value++ into value = value + 1 everything wroks well.
>
>I was kind of surprised :-)
>
>Am I expecting something totally silly, shouldn't one ever use
>optimization? What is your experience with GCJ and optimization?
>
>Best regards,
>Tom
>  
>



More information about the Java mailing list