Video in progress

How do you make a move from Java 17 to 21, or to a new GC flag, safe on prod?

I treat a JVM change like a code release: I deploy it separately, with no other changes, collect the same metrics (p99, CPU, RSS, GC time) before and after, roll out gradually through a canary, and keep a quick way back ready.

📖 Answer

A JVM version or GC flag affects the behavior of all the code, and problems often show up hours or days later (metaspace growth, a rare deoptimization, library compatibility). So:

1. Preparation.

  • Check the release notes for removed flags: an old flag can stop the JVM from starting. Compare the default differences with java -XX:+PrintFlagsFinal -version.
  • jdeps --jdk-internals shows use of internal APIs.
  • Libraries: those that manipulate bytecode (ByteBuddy, ASM, Lombok, Mockito, JaCoCo, APM agents) must support the new class file version.
  • Run the tests on both JDKs in parallel in CI.

2. Baseline. At least a week: p50/p99 latency, CPU, RSS, GC pauses and GC CPU share, allocation rate, startup time, error count.

3. Only one change. If you ship a Spring Boot version and a new feature together with the JDK upgrade, you won't know who caused a regression.

4. Canary. 1 pod → 10% → 50% → 100%, with at least a few hours at each stage or a full daily cycle (so the night jobs run too). GC log and JFR must definitely be on in the canary.

5. Rollback. If the JDK version in the image is a separate layer or an argument, rollback is a single deploy. Passing GC flags through configuration (JAVA_TOOL_OPTIONS or Helm values) simplifies rollback further.

In my experience, going from 17 to 21 usually brings pleasant changes (G1 improvements, lower memory), but agents and old libraries cause problems. On one project an old version of the APM agent crashed at startup on Java 21, and staging caught it, not prod.