Paul Krill
Editor at Large

Stable values API would speed Java startups

Stable values combine immutable state and flexible timing of initialization, enabling optimizations for user code previously available only to JDK code.

speed fast race car shutterstock 1168856884
Credit: Jamesboy Nuchaikong / Shutterstock

Startup times for Java applications would be improved through a proposed API for stable values, which are objects that hold immutable data.

An OpenJDK Java Enhancement Proposal (JEP) for a preview of stable values notes that stable values are treated as constants by the JVM, enabling the same performance optimizations that are enabled by declaring a field final. Compared to final fields, however, stable values provide greater flexibility as to the timing of initialization. Thus Java application startup would be improved by breaking up the monolithic initialization of application state.

The JEP was updated on January 24, after originally being created in July 2023. The stable values preview would become part of the standard edition of Java, although no specific version of Java was named in the JEP.

Other goals of the stable values proposal include decoupling the creation of stable values from their initialization, without significant performance penalties; guaranteeing that stable values are initialized no more than once, even in multi-threaded programs; and enabling user code to safely enjoy constant-folding optimizations previously only available to JDK-internal code. It is not a goal of the proposal to enhance Java with a means to declare stable values or to alter the semantics of final fields.

In explaining the motivation for the stable values proposal, the JEP notes that Immutability has advantages, because an immutable object can be only in one state and therefore can be shared freely across multiple threads. The Java platform’s tool for managing immutability is final fields, but final fields have limitations, such as the need to be set eagerly, that restrict their applicability in many real-world applications.

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author