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.
If your method is too big, or has method which have been inlined too many times already, your method won't get inlined.
There is a number of parameters which control this.
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.There'a s good blog Julien's tech blog. This seems to list:
Things that will reduce the inlining