JDK 19: the latest features for Java 19
Virtual Threads, Pattern Matching for Switch expressions, Vector API, and Linux/RISC-V porting are the latest features targeted for Java 19, the next non-LTS release of standard Java.
Four features have been officially proposed for the JDK 19 development kit scheduled for next September. Two recent additions, virtual threads and pattern filtering (both in preview), come on top of two already formalized functions, namely a vector API (in its fourth incubation) and a port of the JDK on the architecture of open source Linux/RISC-V instruction set (ISA). Potentially, JDK 19, referred to simply as Java 19, could accommodate a large number of features, from universal generics to Value Objects, depending on the ongoing Java improvement projects.
According to the official JDK 19 release schedule published by OpenJDK developers, the production release of Java 19 is scheduled for September 20. This version will be preceded by rampdown phases on June 9 and July 21, and candidate versions will be released on August 11 and 25. JDK 19 will take over from JDK 18 which arrived on March 22, with a new version of standard Java being released every six months. Early access versions of JDK 19 can be accessed at jdk.java.net/19.
Various functions for JDK 19
Features include an overview of virtual threads: these are lightweight threads that greatly simplify the work of writing, maintaining, and watching high-throughput concurrent applications. They should allow server applications written in the simple “thread per request” style to scale with near-optimal hardware utilization; allow existing code that uses the java.lang Thread API to adopt virtual threads with minimal changes; and enable troubleshooting, debugging, and profiling of virtual threads with existing JDK tools. The goal of this proposal is not to modify the basic concurrency model of Java nor to propose a new construction of parallelism by data distribution in the Java language or the Java libraries. Nor is the goal to remove the traditional implementation of threads or to silently migrate existing applications to using virtual threads.
A third preview of pattern matching for Expressions and Switch Statements is introduced. The goal? Allow an expression to be tested against a number of patterns, each with a specific action, so that complex data-driven queries can be expressed concisely and safely. This feature was previously previewed in JDK 17 and JDK 18. The third preview will get some improvements, including replacing protected patterns with when clauses in Switch blocks. Also, the execution semantics of a Pattern Switch, when the value of the Switch statement expression is null, is more closely aligned with the semantics of existing Switch statements. The feature notably aims to extend the expressiveness and applicability of Switch expressions and statements by allowing patterns to appear in case labels, allowing Switch historical null hostility to be relaxed at will, increasing safety of Switch statements and ensuring that existing expressions and Switch statements continue to compile unchanged and run with identical semantics.
A fourth Vector API incubation is also coming. This will be able to express compiled vector calculations reliably at runtime into optimal vector instructions on supported CPU architectures. Using this API, developers will be able to write complex vector algorithms in Java, using the HotSpot auto-vectorizer, but with a user model that makes vectorizations more predictable and robust. The Vector API was previously incubated in JDK 16, JDK 17, and JDK 19.
The improved Vector API
The API enhancements offered for JDK 19 don’t stop there, and relate to loading and storing vectors to and from MemorySegments, as defined by the external function and the Memory API preview. JDK 19 would also add two so-called cross-lane vector operations, compression and expansion, as well as an additional vector mask compression operation. The vector compress operation maps the lanes of a source vector, selected by a mask, to a destination vector in lane order, while the expand operation does the reverse. The compression operation is useful for filtering query results. Another addition regarding the Vector API as we suspected lately: channel-wide bit-integral operations would be expanded, including operations like counting the number of bits 1, inverting bit order, and bit compression and 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 “elegant” degradation, for situations where a vector calculation cannot be fully expressed at runtime as a sequence of vector operations.
In addition to the Linux/RISC-V port, Java would gain support for a hardware instruction set already supported by many 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: model interpreter, JIT C1 compiler (client), JIT C2 compiler (server), and all current 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. Besides the RISC-V port and vector API, an outline of the external function and memory API, allowing Java programs to interact with code and data outside of the JVM runtime, also seems destined to be officially targeted at JDK 19, since the API proposal itself cites JDK 19 as the destination. Like JDK 18, JDK 19 will be a short-term release, with six months of high-level Premier support only. The previous release, JDK 17, was a Long Term Support (LTS) release, which provided several years of support. This latest LTS version was delivered on September 14, 2021.