JDK 19: What’s new in Java 19
Java Development Kit 19, scheduled for September, has just been offered a seventh feature: JDK 19: structured concurrency, to simplify multithreaded programming. Structured concurrency joins six previous features, including record models, a preview of a foreign function and memory API, and Linux/RISC instruction set architecture (ISA) support -V open-source.
JDK 19, or simply Java 19, could potentially host a large number of features, ranging from universal generics to valuable objects, depending on current plans to improve Java. JDK 19 would follow JDK 18, which arrived on March 22. Standard Java is on a six month release cadence.
OpenJDK developers have released an official release schedule for JDK 19, which will arrive on September 20 as a production release, preceded by slowdowns on June 9 and July 21, and candidate builds to be released on August 11 and August 25.
Early access versions of JDK 19 can be accessed from jdk.java.net/19. JDK 19 features offered include:
- Structured concurrency, in an incubator phase, aims to simplify multithreaded programming through a structured concurrency library. This concurrency treats multiple tasks running in different threads as a single unit of work, to streamline error handling and cancellation. Reliability and observability are improved.
- An overview of record patterns, to deconstruct record values. Record patterns and type patterns can be nested to allow a declarative, powerful, and composable form of navigation and data processing. The goals of the proposal include extending pattern matching to express more sophisticated and composable data queries without changing the syntax or semantics of type patterns. This proposal relies on pattern matching to
instanceofshipped in JDK 16 in March 2021. Future plans may require extending record templates with features such as array templates and
varargpatterns. Record Templates are part of Project Amber, an effort to explore and incubate smaller, productivity-focused Java features.
- An overview of a Foreign Function and Memory API, which would introduce an API through which Java programs can interact with code and data outside of the Java runtime environment. By efficiently invoking foreign functions (i.e. code outside the Java runtime environment) and safely accessing foreign memory (i.e. unmanaged memory by the JVM), the API allows Java programs to call native libraries and process native data without the danger and fragility of Java. Native interface (JNI). The Foreign Function and Memory API combines two earlier incubation APIs: the Foreign Memory Access API and the Foreign Linker API. The Foreign Function and Memory API was previously incubated in JDK 17 and re-incubated in JDK 18. Goals of the proposal include usability, performance, generality, and security.
- An overview of virtual threads, which are lightweight threads that significantly reduce the effort of writing, maintaining, and watching high-throughput concurrent applications. Goals include enabling server applications written in the single-threaded per-request style to scale with near-optimal hardware utilization, allowing legacy code that uses the
java.langThread API to adopt virtual threads with minimal changes and enable troubleshooting, debugging and profiling of virtual threads with existing JDK tools. It is not an objective of this proposal to change the basic concurrency model in Java or to offer a new construct of data parallelism in the Java language or Java libraries. Nor is the goal to remove the traditional implementation of threads or to silently migrate existing applications to use virtual threads.
- A third preview of pattern matching for switch expressions and statements, extending pattern matching to
switch, to allow an expression to be tested against a number of patterns, each with a specific action, so that complex data-oriented queries can be expressed concisely and safely. This feature was previously previewed in JDK 17 and JDK 18. The third preview would add improvements including replacing protected templates with
switchblocks. Also, the semantics of executing a model switch when the value of the selector expression is null is more closely aligned with inheritance.
switchsemantics. The objectives of the plan include expanding the expressiveness and applicability of
switchexpressions and declarations by allowing patterns to appear in case labels. Other goals include the ability for developers to relax the historical null hostility of
switchwhenever you want, increasing the safety of
switchdeclarations and ensure that the
switchexpressions and statements continue to compile unchanged and run with identical semantics.
- A fourth incubation of a vector API that would express vector computations that reliably compile at runtime to optimal vector instructions on supported processor architectures, thus achieving performance superior to equivalent scalar computations. Developers using the API gain a way to write complex vector algorithms in Java, using HotSpot’s automatic vectorizer but with a user model that makes vectorizations more predictable and robust. API Vector was previously incubated in JDK 16, JDK 17 and JDK 19.
Proposed API enhancements for JDK 19 include enhancements for loading and storing vectors to and from
MemorySegments, as defined by the Foreign Functions and Memory API preview. JDK 19 would also add two cross-path vector operations, compress and expand, and an additional vector mask compress operation. The vector compress operation maps the lanes of a source vector, selected by a mask, onto a destination vector in lane order, while the expand operation does the reverse. The compression operation is useful for filtering query results.
In another addition to the Vector API, bitwise integral channel operations would be extended, including operations such as counting the number of bits one, reversing bit order, and compressing and l bit expansion. The goals of the API were to be clear and concise, platform independent, to have reliable runtime and compile-time performance on x64 and AArch64 architectures, and to allow “graceful” degradation, for situations in which a vector calculation cannot be fully expressed at runtime as a sequence of vector operations.
- With the Linux/RISC-V port, Java would support a hardware instruction set already supported by a wide range of language toolchains. RISC-V is actually a family of related ISAs. The Linux/RISC-V port would only support the RV64GV configuration of RISC-V, a general-purpose 64-bit ISA that includes vector instructions. Java developers may consider other RISC-V configurations in the future.
The port would support the following HotSpot VM options: template interpreter, JIT C1 compiler (client), JIT C2 compiler (server), and all current mainline garbage collectors, including ZGC and Shenandoah. The actual porting is almost complete; The goal of the JDK Enhancement Proposal (JEP) is to integrate the port into the main JDK repository.
Like JDK 18, JDK 19 is expected to be a short-term release, with just six months of high-level Premier support.
The previous release, JDK 17, was a Long Term Support (LTS) release, with several years of support. It arrived on September 14, 2021.
Copyright © 2022 IDG Communications, Inc.