Is there anything that will stop java inlining a m

2019-07-12 02:29发布

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.

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

Edit: 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.

标签: java inline
2条回答
欢心
2楼-- · 2019-07-12 03:10

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

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}

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.

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

查看更多
Deceive 欺骗
3楼-- · 2019-07-12 03:24

There'a s good blog Julien's tech blog. This seems to list:

Things that will reduce the inlining

  1. Big methods - make sure each method is a small as is correct.
  2. No warmup - the JIT compiler will not inline until it has statistics on method calls.
查看更多
登录 后发表回答