How to test a G1-by-default switch in small containers before upgrading to JDK 27
With JDK 27, G1 becomes the default garbage collector in all environments. In small containers this change happens silently. Here is what to check before you upgrade.
When JDK 27 was released, attention went mostly to compact object headers and post-quantum TLS. JEP 523 received less attention. Its description sounds like routine maintenance at first glance: G1 will become the default garbage collector in all environments. For most applications this will make no difference. But in a specific group of containers, the garbage collector changes without any warning in the logs and without any startup error. In this post I explain what that group is, why it goes unnoticed, and how you can test before upgrading.
What is changing
In Java, garbage collector selection has long been done by an "ergonomics" mechanism that depends on the characteristics of the machine the JVM runs on. If the machine was powerful enough, G1 was selected; on machines considered weak, the simpler Serial GC with its lower memory footprint was used. With JEP 523 this distinction goes away, and G1 becomes the default regardless of the machine's capacity.
This may sound like a small detail, but the consequences are significant. A service that previously ran with Serial GC will start with G1 after the upgrade. That means memory management behavior, pause times, and the resources the JVM consumes in the background will all change. This change leaves no trace in the code, so if you are not careful you can move it into a production environment without noticing.
What happens in small containers
The real risk appears when the CPU and memory limits of containers are kept low. In such environments the old ergonomics rules already preferred Serial GC, because G1's internal structures (regions, remembered sets, concurrent worker threads) could add overhead in a small memory space. Now those same containers will run with G1.
It cannot be said that G1 performs badly with small heaps, but its behavior is different. A small heap affects G1's region sizes and how often it rebalances. Additionally, the JVM's total memory footprint can grow through native memory and thread count. In services running close to the container's memory limit, this difference can turn into an OOMKilled event. Conversely, GC pauses may become shorter, but that is not always guaranteed. What matters is measuring the change instead of guessing it.
How to test before upgrading
The first step is to know which garbage collector the existing application uses. On a JVM running in production, without changing the classpath or startup parameters, you can read the active GC from the UseSerialGC or UseG1GC lines in the -XX:+PrintFlagsFinal output. This information immediately shows whether the change affects you.
The second step is to set up a test environment with JDK 27 under the same container limits. It is important to reproduce the real load profile as closely as possible. Enable GC logs (-Xlog:gc*) for both the old and new versions, and compare pause times, the heap usage curve, collection frequency, and peak memory values. Also monitor the container's RSS value and OOM events, because problems usually show up not in the heap graph but in total memory usage.
The third step is to explicitly select Serial GC as a temporary safeguard. This is the simplest way to pin the change down as a conscious decision. Still, do not treat this as a permanent solution; Serial GC's support and recommendations in the new version should be evaluated separately. In the long run, re-evaluating your settings with G1 is the healthier path.
Highlights
- With JEP 523, G1 becomes the default garbage collector in all environments, regardless of machine characteristics.
- The change produces no warning in logs or at startup, so it is not easy to notice.
- The group most affected is services running in containers with low CPU and memory limits.
- The main risks are pause time, memory footprint, and OOM events, which can be measured with GC logs and RSS monitoring.
- Verifying the active GC before upgrading and running a load comparison in the test environment is the safest approach.
When to use this
Apply these checks whenever you plan a move to JDK 27, and especially for services running in low-resource containers. For applications running on machines with large memory and many cores, no urgent risk is apparent, but reviewing a few GC logs is still worthwhile. Make decisions such as reverting to Serial GC or changing G1 settings only after you have measurements; speculative tuning often leads to new problems.
Comments (0)
No comments yet; be the first.
Leave a comment