I want to start with disclaimer that the following code has a bug -
Integer overflow.

public class Main
{
    public static void main(String... args )
    {
        int start = Integer.MIN_VALUE;
        int end   = Integer.MAX_VALUE;
        int i = 0;

        System.out.println("Start:");

        for( i = start; i <= end; i++ )
        {
            if ( ( i % 1000000 ) == 0 )
                System.out.println(i);
        }

        System.out.println("End: " + String.valueOf(i) );
    }
}

The loop termination condition is wrong.  It should have been 'i <
end'.  The above loop should not terminate - "i" will be just
overflow.

One interesting behavior is that if I use '-client' option, the
program never terminates.  However, when I use '-server' option, the
program terminates in the middle.  The result of "i" is different each
time.  I am guessing that this is caused by HotSpot optimization.

First, is this correct behavior?  Having '-client' and '-server'
acting differently?
Second, how can I find more information about it?  I tried '-XX:
+PrintOptoAssembly' using debug JDK but no clue how to interpret it.

Any help will be greatly appreciated.

Thanks.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "The 
Java Posse" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to