Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the size of methods that JIT automatically inlines?

I've heard that JIT automatically inlines small methods, like getters (they have about 5 bytes). What is the boundary? Is there any JVM flag?

like image 206
user123454321 Avatar asked Apr 12 '16 22:04

user123454321


People also ask

What is method inlining in Java?

What Method Inlining Is? Basically, inlining is a way to optimize compiled source code at runtime by replacing the invocations of the most often executed methods with its bodies. Although there's compilation involved, it's not performed by the traditional javac compiler, but by the JVM itself.

What is JIT inlining?

The JIT aggressively inlines methods, removing the overhead of method calls. Methods that can be inlined include static, private or final methods but also public methods if it can be determined that they are not overridden. Because of this, subsequent class loading can invalidate the previously generated code.


1 Answers

HotSpot JIT inlining policy is rather complicated. It involves many heuristics like caller method size, callee method size, IR node count, inlining depth, invocation count, call site count, throw count, method signatures etc.

Some limits are skipped for accessor methods (getters/setters) and for trivial methods (bytecode count less than 6).

The related source code is mostly in bytecodeInfo.cpp.
See InlineTree::try_to_inline, should_inline, should_not_inline functions.

The main JVM flags to control inlining are

-XX:MaxInlineLevel (maximum number of nested calls that are inlined)
-XX:MaxInlineSize (maximum bytecode size of a method to be inlined)
-XX:FreqInlineSize (maximum bytecode size of a frequent method to be inlined)
-XX:MaxTrivialSize (maximum bytecode size of a trivial method to be inlined)
-XX:MinInliningThreshold (min. invocation count a method needs to have to be inlined)
-XX:LiveNodeCountInliningCutoff (max number of live nodes in a method)
like image 109
apangin Avatar answered Oct 14 '22 03:10

apangin