Fundamentals 5 min read

Can Java Threads Skip GC Pauses? Exploring G1 Region Fixation Proposal

This article explains the JEP 423 proposal to fix regions in the G1 garbage collector, allowing Java threads to avoid pauses during JNI critical sections and reducing GC latency, while discussing implementation details, potential heap exhaustion risks, and upcoming JDK release timelines.

21CTO
21CTO
21CTO
Can Java Threads Skip GC Pauses? Exploring G1 Region Fixation Proposal

Proposal to implement region fixation in default GC so Java threads never wait for GC.

Concept of Java garbage collection: It reclaims memory by deleting unused objects. This functionality will be improved by the proposal considered by Java standard developers.

The OpenJDK JDK Enhancement Proposal (JEP 423) calls for fixing regions to G1 (Garbage‑First) to reduce GC latency, allowing JNI critical regions without disabling collection. The goals are:

JNI critical regions do not cause thread stop.

Starting GC during JNI critical region adds no extra delay.

When no JNI critical region is active, GC has minimal regression pause.

When no critical JNI region is active, GC pause time has no regression.

Proponents note that for interoperability with unmanaged languages like C/C++, JNI defines functions to obtain and release direct pointers to Java objects, which must be used in pairs.

Code using such functions is considered to run in a critical section; the Java objects used become the critical region. When a Java thread is in a critical region, the JVM must not move the associated objects during GC, effectively locking them. The JVM may disable GC while the thread is in the critical region.

The default G1 GC will adopt the latter approach, disabling collection in each critical region, significantly reducing latency. Under the proposal, Java threads will no longer wait for G1 GC operations to finish. The proposal aims to extend G1 to fix arbitrary regions during major and minor collections.

The proposal assumes JNI critical regions will continue to be used cautiously and briefly. When multiple regions are fixed simultaneously, there is a risk of heap exhaustion. No solution yet, but Shenandoah GC locks memory regions during JNI critical regions without this issue, indicating it may not be a problem for G1.

The proposal does not yet reference a Java version that will introduce this feature.

The next standard Java release, JDK 18, is scheduled for March 22, 2022, with its feature set frozen; JDK 19 is expected in September.

Source: Oracle official website
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaGarbage CollectionJNIg1-gcJEP 423Region Fixation
21CTO
Written by

21CTO

21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.