在Java下面为什么是它下面的代码中表现不同的Java 1.6和1.7
下面public class Test16Jit {
public static void main(String[] s) {
int max = Integer.MAX_VALUE;
int i = 0;
long li = 0;
while (i >= 0) {
i++;
li++;
if (i > max) {
System.out.println("i is : " + i);
System.out.println("max is : " + max);
System.out.println("Woo!! something really went wrong");
}
}
System.out.println("Value of i: " + i);
System.out.println("Total # of iterations: " + li);
}
}
输出码1.7倍
Value of i: -2147483648
Total # of iterations: 2147483648
下面
在产出的Java 1.6倍
i is : 2147483636
max is : 2147483647
Woo!! something really went wrong
Value of i: -2147483648
Total # of iterations: 2147483648
是否有这种行为的原因?
另外,如果我改变
int max = Integer.MAX_VALUE; -> final int max = Integer.MAX_VALUE;
它的行为在1.6倍完全相同和1.7倍
你是否从简单的代码'int max = Integer.MAX_VALUE; int i = 2147483636; System.out.println(i> max);'? –
@AndyTurner我还没有测试,但我猜这应该是一个JIT错误。 – shmosel
打印false @AndyTurner –