Scrivio Interview library
InternalsIntermediate7 min read · updated 12 November 2026

Why is inlining considered the most important JIT optimisation, and what limits it in HotSpot? How can you see inlining decisions?

Inlining replaces a call with the body of the called method, which removes the call overhead but, much more importantly, puts the callee's code in front of the optimiser, so escape analysis, constant folding and range check elimination can work across what used to be a boundary. HotSpot limits it by size (MaxInlineSize, 35 bytecodes, for any method, and FreqInlineSize for hot ones), by depth (MaxInlineLevel) and recursion, and by call site shape, since virtual calls only inline with one or two profiled receiver types. We see the decisions with -XX:+UnlockDiagnosticVMOptions -XX:+PrintInlining or with JITWatch.

Why this question is asked

Java code is full of small methods: getters, wrappers, lambdas, stream stages. If each of those were a real call, idiomatic Java would be slow. Inlining is what makes it fast, and when it fails, performance drops in ways that are hard to explain without looking at the JIT's decisions. Interviewers ask this to see whether we understand why the JIT works the way it does and can diagnose it. In this answer, we will recap what inlining is, see why it unlocks the other optimisations, go through the limits HotSpot applies, read the inlining log, and finish with why splitting a large method can make hot code faster.

1A Quick Recap of Inlining

A method call normally means saving some state, jumping to the method's code, running it and jumping back. Inlining means the JIT copies the callee's body into the caller at the call site, so there is no call at all. For a getter, the call disappears and only a field load remains.

Java
// What we write
int total(Order o) { return o.getQty() * o.getPrice(); }
// What C2 effectively compiles after inlining both getters
int total(Order o) { return o.qty * o.price; } // two field loads and a multiply, no calls

2Why It Unlocks Every Other Optimisation

The removed call is the small part of the gain. The large part is that the compiler now sees the caller and callee as one piece of code, and its other optimisations work only within the code it can see. Constant folding can compute results that depend on arguments known at the call site. Range check elimination can remove array bounds checks once it sees that a loop index stays within the array. Null checks can be merged. Most importantly, escape analysis, which decides whether an object ever leaves the method, can only prove that a temporary object does not escape if every method it is passed to has been inlined. If it does not escape, C2 can replace it with plain local values, so the allocation disappears.

Java
record Point(int x, int y) { Point plus(Point o) { return new Point(x + o.x, y + o.y); } }
int sumX(int[] xs) {
Point acc = new Point(0, 0);
for (int x : xs) acc = acc.plus(new Point(x, 0)); // with plus() inlined: no allocations at all
return acc.x(); // C2 keeps acc.x in a register
}
// plus() inlined: 0 bytes allocated per call (escape analysis removed the Points)
// plus() not inlined: two Point objects allocated per iteration

Notice that the code looks allocation-heavy, but after inlining and escape analysis it runs like a loop over ints. If something prevents plus() from being inlined, the same code allocates millions of objects. That is why inlining is often called the gateway optimisation.

3The Limits HotSpot Applies

Inlining everything would make compiled code huge, slow to compile and bad for the CPU's instruction cache. So HotSpot applies limits, measured in bytecode size, not source lines. Any method up to MaxInlineSize, 35 bytes of bytecode by default, can be inlined even if it is not hot, because small methods are almost always worth it. A hot call site, one the profile shows is called frequently, can inline a method up to FreqInlineSize, 325 bytes on common 64-bit platforms. Beyond that, the method is compiled on its own and called normally.

There is also a depth limit, MaxInlineLevel, which bounds how many levels of nested calls are inlined into one compilation; it was raised from 9 to 15 in JDK 14. Recursive inlining is restricted to a small depth. There is a limit on the total size of a compilation unit as well, so a method that has already inlined a lot stops inlining more. And methods that are already compiled to very large native code may be refused with a message that the callee is already compiled into a big method. Exact defaults vary by platform and release, so check your version with -XX:+PrintFlagsFinal.

Main inlining limits in HotSpot C2
LimitDefault (check your version)Typical log message
MaxInlineSize35 bytecodes, any calltoo big
FreqInlineSize325 bytecodes, hot callshot method too big
MaxInlineLevel15 levels (9 before JDK 14)inlining too deep
Recursionsmall depth onlyrecursive inlining is too deep
Virtual call shape1 or 2 profiled receiver typesvirtual call / no static binding

4Virtual Calls and Inlining

A virtual call can only be inlined if the JIT knows which method will run. Sometimes it knows for sure, for example when the method is final, private or static, or class hierarchy analysis shows only one implementation is loaded. Otherwise it relies on the type profile collected at the call site. With one or two receiver types, C2 inlines them behind type checks. With more, the site is megamorphic and becomes a real virtual call, so nothing behind it is inlined, unless one type is strongly dominant.

5Seeing the Decisions

The diagnostic flag PrintInlining prints, for every C2 and C1 compilation, a tree of call sites with the decision for each. It needs UnlockDiagnosticVMOptions.

Shell
java -XX:+UnlockDiagnosticVMOptions -XX:+PrintCompilation -XX:+PrintInlining -jar app.jar
// Excerpt (format varies by version)
// @ 12 com.shop.Order::getQty (5 bytes) accessor
// @ 19 com.shop.Order::getPrice (5 bytes) accessor
// @ 31 com.shop.Pricing::applyRules (512 bytes) hot method too big
// @ 44 com.shop.Shape::area (0 bytes) virtual call
// @ 58 java.lang.Math::max (11 bytes) (intrinsic)
Step throughInlining decision at a call site (simplified)
  1. Target known (static, final, CHA) or 1-2 profiled types?
    YescontinueNovirtual call, not inlined
  2. Size <= MaxInlineSize?
    YesinlineNocheck if hot
  3. Hot and size <= FreqInlineSize?
    YesinlineNohot method too big
  4. Depth and total size within limits?
    YesinlineNotoo deep or unit too big

4 steps in order. Play them, or step through them one at a time.

Each line shows the bytecode index of the call, the target, its size and the reason. inline or accessor means it was inlined; hot method too big means FreqInlineSize stopped it; virtual call means a megamorphic or unknown target; intrinsic means the JIT replaced the call with hand-written machine code. For larger investigations, we log compilations to a file with -XX:+LogCompilation and open it in JITWatch, a free tool that shows the inlining tree next to the source and bytecode, which is much easier to read than the raw log.

6Follow-up questions

Why can splitting a very large method into smaller ones speed up hot code?

A large method above FreqInlineSize is never inlined into its callers, so none of the optimisations across the boundary happen. If the method is mostly a rare path wrapped around a small hot path, moving the rare code, such as error handling or logging, into a separate method shrinks the hot method below the limit. Then it can be inlined, and its callers get escape analysis and constant folding across it. Very large methods are also compiled less well on their own, and methods above about 8,000 bytes of bytecode are not compiled at all by default because of the HugeMethodLimit check.

Should we raise FreqInlineSize to fix hot method too big?

Rarely. Raising it globally makes every compilation larger, increases compile time and code cache use, and can make other code slower through instruction cache misses. Restructuring the specific method is safer. If a flag change is tested, it should be measured with JMH and production-like load, and reviewed at each JDK upgrade.

What is an intrinsic?

An intrinsic is a method the JIT recognises and replaces with specially written machine code instead of compiling its bytecode, for example Math.max, System.arraycopy, String.equals or some crypto and array methods. Intrinsics often use CPU instructions that ordinary compilation would not generate.

7Conclusion

In this answer, we saw that inlining copies a callee's body into its caller, and that its real value is exposing that code to escape analysis, constant folding and range check elimination. HotSpot limits it with MaxInlineSize for any call, FreqInlineSize for hot calls, MaxInlineLevel for depth, restrictions on recursion and total size, and the receiver-type profile for virtual calls. PrintInlining and JITWatch show every decision and the reason, which is how we find hot methods that are too big or call sites that became megamorphic.

What to say in the interviewAbout 90 seconds aloud

Open with

Inlining is the most important JIT optimisation because it is the one that enables the others. Removing the call overhead is nice, but the real gain is that the callee's code becomes part of the caller's compilation, so the optimiser can see across the boundary.

Then, if they want more

Escape analysis can only remove an allocation if every method the object is passed to is inlined; constant folding and range check elimination also work only on code the compiler can see. HotSpot limits inlining in a few ways.

Any method up to MaxInlineSize, 35 bytes of bytecode, can be inlined; hot methods up to FreqInlineSize, 325 bytes on typical 64-bit platforms. MaxInlineLevel limits nesting depth, 15 since JDK 14, recursion is restricted, and there is a limit on the size of the whole compilation.

For virtual calls the JIT needs to know the target: static, final or a single implementation by class hierarchy analysis, or a profile with one or two receiver types; megamorphic sites become real calls.

To see the decisions I use UnlockDiagnosticVMOptions with PrintInlining, which prints each call site with a reason like hot method too big or virtual call, or LogCompilation with JITWatch for a friendlier view. Splitting a large hot method so its hot path fits under the limit is a common fix.

About this answer

Last updated
12 November 2026
Versions it names
Java 14
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Why is inlining considered the most important JIT optimisation, and what limits it in...": https://scrivio-interview-library.netlify.app/java/jit-compilation/53157965c5/