java jit技术,Java:JIT方法内联

Java JIT编译器通常会自动内联小型final或伪最终方法,无需运行时统计。对于非final方法,它基于运行时统计来决定是否内联,以确保优化效果。内联非final方法时需要防止意外的子类导致问题。具体触发内联的次数因JVM实现而异,并且在运行时可能会变化。
摘要由CSDN通过智能技术生成

When does Java JIT inline a method call? Is it based on #times the caller method is called (if yes, what would that number be?), or some other criteria (and what would that be?)

I've read that JIT can inline 'final' methods, but it also inlines nonfinal methods based on runtime statistics, so want to know what is that triggering criteria.

I guess the answers would differ based on JVM implementation, but maybe there's something common across all of them?

解决方案

The short answer is whenever it wants.

Very often a JITC will inline small final or pseudo-final methods automatically, without first gathering any stats. This is because it's easy to see that the inlining actually saves code bytes vs coding the call (or at least that it's nearly a "wash").

Inlining truly non-final methods is not usually done unless stats suggest it's worthwhile, since inlined non-finals must be "guarded" somehow in case an unexpected subclass comes through.

As to the number of times something may be called before it's JITCed or inlined, that's highly variable, and is likely to vary even within a running JVM.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值