Proposal would implement region pinning in the default GC so that Java threads would never have to wait for a garbage collection operation to complete. Credit: Thinkstock Java garbage collection – the reallocation of memory through deletion of unused objects – would be improved through a proposal being considered by the developers of standard Java. A JDK Enhancement Proposal (JEP) being floated in the OpenJDK Java community calls for reducing latency by implementing region pinning to the G1 (Garbage-First) garbage collector, so collection would not have to be disabled during Java Native Interface (JNI) critical regions. Goals of this plan include: No stalling of threads due to JNI critical regions. No additional latency to start garbage collection due to JNI critical regions. Minimal regressions in GC pauses times when no JNI critical regions are active. No regressions in GC pause times when no critical JNI regions are active. In explaining the motivation for this plan, proponents said that for interoperability with unmanaged programming languages such as C and C++, JNI defines functions to get and then release direct pointers to Java objects. These functions must be in pairs: first, get a pointer to an object; then, after using the object, release the pointer. Code in such function pairs is considered to run in a critical region, and the Java object in use is a critical object. When a Java thread is in a critical region, the JVM must not move the associated critical object during garbage collection. It can do this by pinning such objects to their locations, essentially locking them in place as the GC moves other objects. Or, the JVM might disable GC when a thread is in a critical region. The default GC, G1, takes the latter approach, disabling collection during every critical region. This significantly impacts latency. Under the proposal being considered, Java threads would never wait for a G1 GC operation to complete. Goals of the proposal would be met by extending G1 to pin arbitrary regions during major and minor collection operations. The proposal presumes there will be no changes to expected usage of JNI critical regions; they will continue to be used sparingly and be short in duration. There is a risk of heap exhaustion when an application pins many regions at the same time. There currently is no solution for this, but the fact that the Shenandoah GC pins memory regions during JNI critical regions and does not have this problem suggests it would not be a problem for G1. The proposal currently does not cite a version of Java in which this capability might be introduced. The next version of standard Java, JDK (Java Development Kit) 18, is due March 22, and its feature set has been frozen. JDK 19 would normally follow in September. Related content feature What is Rust? Safe, fast, and easy software development Unlike most programming languages, Rust doesn't make you choose between speed, safety, and ease of use. Find out how Rust delivers better code with fewer compromises, and a few downsides to consider before learning Rust. By Serdar Yegulalp Nov 20, 2024 11 mins Rust Programming Languages Software Development how-to Kotlin for Java developers: Classes and coroutines Kotlin was designed to bring more flexibility and flow to programming in the JVM. Here's an in-depth look at how Kotlin makes working with classes and objects easier and introduces coroutines to modernize concurrency. By Matthew Tyson Nov 20, 2024 9 mins Java Kotlin Programming Languages analysis Azure AI Foundry tools for changes in AI applications Microsoft’s launch of Azure AI Foundry at Ignite 2024 signals a welcome shift from chatbots to agents and to using AI for business process automation. By Simon Bisson Nov 20, 2024 7 mins Microsoft Azure Generative AI Development Tools news Microsoft unveils imaging APIs for Windows Copilot Runtime Generative AI-backed APIs will allow developers to build image super resolution, image segmentation, object erase, and OCR capabilities into Windows applications. By Paul Krill Nov 19, 2024 2 mins Generative AI APIs Development Libraries and Frameworks Resources Videos