When the JIT gets it wrong
Overview I have often wondered what you would see if the JIT compiled code incorrectly, but it has been a long time since I found an example. A not so infinite loop There are many way to write an infinite loop. One confusing way is to write for(int i=0; i <= Integer.MAX_VALUE; i++) This is an infinite loop because i as an int value is always less than or equal to the maximum value, by definition. The JIT can detect this and take action. However the action taken in Oracle Java 6 update 25 is surprising. It just stops the loop, first at a rather random point and later after one iteration. public static void main(String[] args) { for(int i=0;i<10;i++) generate(Integer.MAX_VALUE); for(int i=0;i<10;i++) generate2(Integer.MAX_VALUE); System.out.println("End of Main"); } // generate primes. public static void generate(int limit) { int lastPrime = 0; for (int i = 3; i <= limit; i += 2) if (isPrime(i))