java compiler optimization

前端 未结 5 1342
北荒
北荒 2020-12-11 11:10

Is the Java compiler smart enough to optimize loop below, by extracting the

Double average = new Double( totalTime / callCount ); 

out of t

5条回答
  •  悲&欢浪女
    2020-12-11 11:46

    Nothing prevents the bytecode compiler (java->bytecode) from performing optimizations. When I worked at Symantec, and they did a Java IDE, the compiler write did look into putting some optimizations into our compiler but said nobody (in the outside world) seemed to be interested and the focus was on the Just In Time (JIT) compiler that is roughly the same as HotSpot in modern Sun VMs.

    There is nothing that prevents a bytecode compiler from performing optimizations, but I am not aware of any that do so. There is huge focus on runtime optimizations, but those are pretty much hidden at runtime.

    So, the source->bytecode compiler probably does not optimize it but the VM probably does. If you are on something like an Android then it probably performs no runtime optimization.

提交回复
热议问题