有什么可以阻止Java内联方法的吗? [英] Is there anything that will stop java inlining a method?

查看:193
本文介绍了有什么可以阻止Java内联方法的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在某些情况下,如果方法调用成为瓶颈,则Java将内联"方法主体,以避免方法调用的开销.但是,我找不到任何会阻止Java进行此操作的信息.例如.我可以想象,如果方法是非静态的或修改了字段,那么这可能会阻止Java内联方法主体.

In certain situations java will "inline" a method body to avoid the overhead of the method call, if the method call becomes a bottleneck. However, I can't find any information about anything that will stop java from doing this. E.g. I can imagine perhaps that if the method is non-static or modifies fields, then this could stop java from inlining the method body.

是否可以内联所有方法,或者我的代码中是否有某些元素会阻止Java内联方法?

Can all methods be inlined, or are there certain elements of my code that would stop java from inlining a method?

不是想要阻止它-我想了解是否有阻止它的事情,所以我可以避免这样做.我正在专门考虑代码中的内容(修饰符,字段访问等),而不是jvm args.

I do not want to prevent it - I want to understand if there are things that would stop it, so I can avoid doing those things. I'm thinking specifically of things in code (modifiers, field access etc), not jvm args.

推荐答案

如果您的方法太大,或者已经被内联了太多次,则您的方法将不会被内联.

If your method is too big, or has method which have been inlined too many times already, your method won't get inlined.

是否可以内联所有方法,或者我的代码中是否有某些元素会阻止Java内联方法?

Can all methods be inlined, or are there certain elements of my code that would stop java from inlining a method?

有许多参数可以控制这一点.

There is a number of parameters which control this.

$ java -XX:+PrintFlagsFinal -version | grep Inline
     bool C1ProfileInlinedCalls                     = true                                {C1 product}
     intx FreqInlineSize                            = 325                                 {pd product}
     bool IncrementalInline                         = true                                {C2 product}
     bool Inline                                    = true                                {product}
    ccstr InlineDataFile                            =                                     {product}
     intx InlineSmallCode                           = 2000                                {pd product}
     bool InlineSynchronizedMethods                 = true                                {C1 product}
     intx MaxInlineLevel                            = 9                                   {product}
     intx MaxInlineSize                             = 35                                  {product}
     intx MaxRecursiveInlineLevel                   = 1                                   {product}
     intx Tier23InlineeNotifyFreqLog                = 20                                  {product}
     bool UseInlineCaches                           = true                                {product}
     bool UseOnlyInlinedBimorphic                   = true                                {C2 product}

值得注意的是:MaxInlineSize限制了内联的深度.通常,这不值得增加,因为它会增加代码大小并减慢编程速度. FrehInlineSize是即使是经常调用的方法也将被内联的最大大小.我发现将其稍微增加可以对某些程序有所帮​​助.

Of note: the MaxInlineSize limits the depth of inlining. In general this is not worth increasing as it can increase you code size and slow you program. The FrehInlineSize is the maximum size even frequently called methods will be inlined. I have found that increasing this a little can help for some programs.

MaxInlineSize是即使不经常调用的小方法也需要内联的字节数.

The MaxInlineSize is the number of bytes that a small method needs to be to be inlined even if it is not frequently called.

这篇关于有什么可以阻止Java内联方法的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆