JIT优化的小问题
同事问了个问题,挺有意思的,代码:
public class TestJIT{ private static boolean sss; public static void main(String[] args) throws InterruptedException { // TODO Auto-generated method stub new Thread(new Runnable(){ public void run(){ double i=0; while(!sss){ i++; // System.out.println(i); } } }).start(); Thread.sleep(1000); sss = true; } }
代码最终会发生什么?
1:OOM,2:死循环,3:正常退出,4:异常。。。
如果去掉注释的system.out,又是什么结果?
去掉Syste.out,代码正常退出。
进一步:
使用解释模式执行,代码证成退出。
使用混合模式执行,代码死循环。
即,JIT在优化的时候出现了BUG?导致两种模式执行的效果不一致,还是优化者认为这种情况无需理会?毕竟少有这种故意写成死循环的代码,死循环也没什么好refix了?
浙公网安备 33010602011771号