java什么时候需要编译_即时编译 – 它何时实际发生在Java中?

这取决于您的JVM及其设置.维基百科:

For example,Sun’s Java Virtual Machine has two major modes—client and server. In client mode,minimal compilation and optimization is performed,to reduce startup time. In server mode,extensive compilation and optimization is performed,to maximize performance once the application is running by sacrificing startup time. Other Java just-in-time compilers have used a runtime measurement of the number of times a method has executed combined with the bytecode size of a method as a heuristic to decide when to compile.[4] Still another uses the number of times executed combined with the detection of loops.[5]

对于vanilla HotSpot JVM in -server模式的粗略近似是当JVM注意到某个方法已被大量调用时,通常会超过某些特定次数,从而发生JIT. (这就是为什么JVM被称为“HotSpot” – 因为它识别并优化代码中的“热点”.)此时,JVM知道一些事情:

>它知道这种方法值得花时间进行优化,因为它会被调用很多.

>它对这个函数的真实世界特征了解很多:

>如果if语句的一个分支比另一个分支更常见,那么它可以改进branch prediction

>如果是传递给此方法的List通常是一个ArrayList,因此它可以针对ArrayList的特定情况进行优化和内联.

请注意,如果您事先编译为机器代码,则不会有大量此类信息需要优化 – 编译器事先并不知道哪些路径比其他路径更常见.但是,如果您等到实际数据之后再进行优化,则可以做出更好的优化决策.

关于JIT做什么的更多细节是here.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值