JIT not optimizing loop that involves Integer.MAX_VALUE
While writing an answer to another question , I noticed a strange border case for JIT optimization. The following program is not a "Microbenchmark" and not intended to reliably measure an execution time (as pointed out in the answers to the other question). It is solely intended as an MCVE to reproduce the issue: class MissedLoopOptimization { public static void main(String args[]) { for (int j=0; j<3; j++) { for (int i=0; i<5; i++) { long before = System.nanoTime(); runWithMaxValue(); long after = System.nanoTime(); System.out.println("With MAX_VALUE : "+(after-before)/1e6); } for (int i=0; i