Scrivio Interview library
ScenarioAdvanced6 min read · updated 12 November 2026

After upgrading 200 services from JDK 17 to JDK 21, five services show about 10 percent higher CPU at the same load. Lead the investigation and decide how the fleet upgrade continues.

I would keep the fleet upgrade going for the 195 services without regressions, and treat the five as a separate investigation. For those, we compare CPU flame graphs before and after at the same load to find which code paths got slower, then check JIT behaviour in those paths (inlining decisions, intrinsics and deoptimisation events from JFR or compilation logs) as well as changed defaults such as GC behaviour or library versions. The five stay on JDK 17 as a time-limited exception with an owner, and if the cause is a JDK regression we report it to the vendor or OpenJDK with a minimal reproducer.

Why this question is asked

A large JDK upgrade is mostly a programme management problem with a technical tail. Most services move without trouble, and a few show something odd. A 10 percent CPU increase is too big to ignore at scale, but too small and too local to justify stopping everything. Interviewers ask this to see how we balance progress and risk and how we turn a vague regression into a concrete cause. In this answer, we will decide how the upgrade continues, set up a fair comparison, find the slower paths with flame graphs, examine the JIT and the other things that changed, and close the loop with exceptions and upstream reports.

1Decide First: Do Not Block the Fleet

195 services upgraded without regressions are getting the benefits of JDK 21: newer GC improvements, virtual threads, security fixes and a support window that lasts years longer. Stopping them because five services behave differently would delay all of that for every team. The regression is specific to five services, so the response should be specific too. We continue the rollout and open a focused investigation, with the five services held back.

Step throughHandling the upgrade with five regressions
  1. Continue rollout for services without regressions195 services move on
  2. Hold the five on JDK 17time-limited exception with an owner
  3. Reproduce at the same load on both JDKssame build, same traffic
  4. Compare flame graphs, JIT events, defaultsfind the slower code path
  5. Cause in our code or libraries?
    Yesfix it and upgradeNominimal reproducer, report upstream

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

2Setting Up a Fair Comparison

Before blaming the JDK, we make sure the comparison is fair. The same application build should run on JDK 17 and JDK 21, side by side, with the same traffic, either as a canary taking a share of production traffic or with replayed load. We compare CPU per request, not total CPU, because traffic varies. We check that container sizes, JVM flags and the base image are the same, because an upgrade often changes several things at once: a new base image, a different default collector setting, or a new library version pulled in with the upgrade.

If CPU per request is 10 percent higher on JDK 21 with everything else equal, we have a real regression to explain.

3Finding the Slower Paths With Flame Graphs

A CPU flame graph shows where CPU time goes, as stacked call frames, with the width of each frame proportional to the time spent in it. We record one on each JDK with async-profiler under the same load, then compare them. async-profiler can produce a differential view, or we compare the top frames by hand. The goal is a short list of frames that are wider on JDK 21.

Properties
# 60 s of CPU profiling on each version, same load
asprof -e cpu -d 60 -f /tmp/jdk17.html <pid-on-17>
asprof -e cpu -d 60 -f /tmp/jdk21.html <pid-on-21>
# Example finding (illustrative)
# JDK 17: com.acme.codec.Json::writeString 4.1% of samples
# JDK 21: com.acme.codec.Json::writeString 9.8% of samples
# + java.lang.StringLatin1::... frames now visible below it

Notice what the example suggests: a method that was cheap now takes more than twice the time, and frames that were previously inlined away now appear separately below it. Frames appearing that were not there before are often a hint that an inlining decision changed.

4Checking the JIT in the Hot Paths

Once we know the slower method, we look at how the JIT compiled it on each version. With -XX:+UnlockDiagnosticVMOptions -XX:+PrintInlining, or LogCompilation and JITWatch, we compare the inlining trees: a callee that was inlined on 17 may be rejected on 21, for example because a JDK method it calls grew past an inlining limit. We also check intrinsics, methods the JIT replaces with special machine code, since a change in a JDK class can move a hot call from an intrinsic to normal code or the other way round.

Then we check deoptimisation. JFR records jdk.Deoptimization events with the method, the reason and the action. A method that keeps being deoptimised and recompiled on JDK 21, but not on 17, wastes CPU in recompilation and in slower code between compilations.

Shell
jcmd <pid> JFR.start name=jit settings=profile duration=120s filename=/tmp/jit.jfr
jfr print --events jdk.Deoptimization /tmp/jit.jfr | head
# jdk.Deoptimization { method = com.acme.codec.Json.writeString(...) reason = "class_check"
# action = "maybe_recompile" lineNumber = 88 ... }
jfr summary /tmp/jit.jfr # count of Deoptimization and Compilation events per version

5Checking Other Defaults and Libraries

Not every CPU regression is the JIT. Between 17 and 21 several things can change around the application. GC behaviour may differ, for example G1 heuristics or region sizing, so we compare GC CPU share and pause frequency on both versions. Library versions may have moved with the upgrade, since teams often update frameworks at the same time, and a new library version can be the real cause. Some JDK behaviours changed too, such as default security providers, the default charset becoming UTF-8 in JDK 18 for code that relied on another platform default, and deprecated APIs whose replacements behave differently. A list of what changed besides the JDK is part of the investigation.

Where a 10% CPU regression can come from
AreaWhat to compareTool
JIT inlining and intrinsicsinlining trees of the hot methodsPrintInlining, JITWatch
Deoptimisationdeopt events per method and reasonJFR jdk.Deoptimization
GCGC CPU share, pause countsGC logs, jvm.gc metrics
Librariesversions changed with the upgradedependency diff
JDK defaultscharset, security, flagsrelease notes, PrintFlagsFinal

6Exceptions and Reporting Upstream

While we investigate, the five services stay on JDK 17 as an exception with a named owner and an end date, for example two months, so it does not quietly become permanent. If the cause is in our code or a library, we fix it and upgrade the service. If it is a JDK regression, we reduce it to a minimal reproducer, ideally a JMH benchmark that shows the difference between 17 and 21, and report it to our JDK vendor or to the OpenJDK bug system. A small, clear reproducer is what gets a regression fixed in a later update. We also check newer JDK 21 updates or JDK 25, because the issue may already be fixed.

7Follow-up questions

What if the reproducer shows the regression but nobody fixes it soon?

We look for a local mitigation. Sometimes a small code change avoids the slow path, for example restructuring a method so it is inlined again. If the gain from JDK 21 for that service is small, it can stay on 17 within the vendor's support window, but with the exception reviewed regularly, since JDK 17 support will end.

How do you avoid this situation next time?

By running a performance comparison as part of the upgrade process: a canary on the new JDK for each service, with CPU per request and latency compared automatically before full rollout. Then regressions are caught per service at the canary stage instead of after the whole fleet has moved.

Would you ever use a JIT flag to restore the old behaviour?

Only as a temporary, documented measure for a specific service, if it is proven to fix the regression and the flag is supported on the new JDK. It must be reviewed at the next upgrade, because flags that compensate for one release's behaviour often become wrong in the next.

8Conclusion

In this answer, we kept the fleet upgrade moving and isolated the five services. We compared the same build on both JDKs at the same load, used flame graphs to find the slower paths, and checked inlining, intrinsics and deoptimisation events in those paths, as well as GC behaviour, library versions and JDK defaults. The five stayed on JDK 17 with an owner and an end date, and a confirmed JDK regression was reported upstream with a minimal reproducer.

What to say in the interviewAbout 90 seconds aloud

Open with

First, I would not stop the fleet. 195 services upgraded without regression, so they continue, and the five become a separate investigation and stay on JDK 17 as a time-limited exception with a named owner.

Then, if they want more

For the five, I would set up a fair comparison: the same build on 17 and 21, same container size and flags, same load, and compare CPU per request rather than total CPU. Then I would record CPU flame graphs with async-profiler on both and look for frames that got wider.

Once I know the slow paths, I would check the JIT there: compare inlining decisions with PrintInlining or JITWatch, check whether intrinsics changed, and look at JFR deoptimization events for methods that are repeatedly deoptimised.

I would also check what else changed with the upgrade: GC behaviour, library versions upgraded at the same time, and JDK default changes like the UTF-8 default charset. If it is our code or a library, we fix it and upgrade.

If it is a JDK regression, I would build a minimal reproducer, ideally a JMH benchmark comparing 17 and 21, check whether a newer update already fixes it, and report it to the vendor or OpenJDK. Next time, a per-service canary with automatic CPU comparison should be part of the upgrade.

About this answer

Last updated
12 November 2026
Versions it names
Java 21, Java 17, Java 18, Java 25
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 "After upgrading 200 services from JDK 17 to JDK 21, five services show about 10 percent...": https://scrivio-interview-library.netlify.app/java/jit-compilation/af53d50dec/