The JDK-19 landed last month and may look like yet another routine release except it is not: Project Loom has finally delivered first bits! Alhough still in half-incubation / half-preview, it is a really big deal to the future of OpenJDK platform. Interestingly enough, a vast majority of the JDK-19 JEPs are either preview or incubating features. So, what JDK-19 has to offer?
JEP-425: Virtual Threads (Preview): introduces virtual threads to the Java Platform. Virtual threads are lightweight threads that dramatically reduce the effort of writing, maintaining, and observing high-throughput concurrent applications.
JEP-428: Structured Concurrency (Incubator): simplifies multithreaded programming by introducing an API for structured concurrency. Structured concurrency treats multiple tasks running in different threads as a single unit of work, thereby streamlining error handling and cancellation, improving reliability, and enhancing observability.
JEP-405: Record Patterns (Preview): enhances the Java programming language with record patterns to deconstruct record values. Record patterns and type patterns can be nested to enable a powerful, declarative, and composable form of data navigation and processing.
JEP-422: Linux/RISC-V Port: ports the JDK to RISC-V hardware.
JEP-424: Foreign Function & Memory API (Preview): introduces an API by which Java programs can interoperate with code and data outside of the Java runtime. By efficiently invoking foreign functions (i.e., code outside the JVM), and by safely accessing foreign memory (i.e., memory not managed by the JVM), the API enables Java programs to call native libraries and process native data without the brittleness and danger of JNI. The JEP comes with a whole new java.lang.foreign package.
JEP-426: Vector API (Fourth Incubator): introduces an API to express vector computations that reliably compile at runtime to optimal vector instructions on supported CPU architectures, thus achieving performance superior to equivalent scalar computations.
JEP-427: Pattern Matching for switch (Third Preview): enhances the Java programming language with pattern matching for switch expressions and statements. Extending pattern matching to switch allows 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.
JDK-8283620: New System Properties for `System.out` and `System.err`: two new system properties,
stdout.encoding
andstderr.encoding
, have been introduced. The value of these system properties is the encoding used by theSystem.out
andSystem.err
streams respectively (the default values of these system properties depend on the platform and fallback to thenative.encoding
property when the console streams are not available).JDK-8212136: Remove finalizer implementation in SSLSocketImpl: the underlying native resource releases are now done by the Socket implementation (the TLS
close_notify
messages will no longer be emitted if SSLSocket is not explicitly closed).JDK-8255495: Support CDS Archived Heap for uncompressed oops: adds support for uncompressed oops for CDS archived heap (for now, only G1 GC is supported, ZGC as a future target).
JDK-8261455: Automatically generate the CDS archive if necessary: allows the CDS archive to be automatically generated if necessary (e.g., if the specified archive doesn't exist, or if it's out of date because the JDK version was updated).
java -XX:+AutoCreateSharedArchive -XX:SharedArchiveFile=app.jsa -cp app.jar AppMain
In the previous JDKs, the CDS archive must be explicitly created before usage (with
-Xshare:dump
or-XX:ArchiveClassesAtExit
).JDK-8278067: Make HttpURLConnection default keep alive timeout configurable: two new system properties have been added,
http.keepAlive.time.server
andhttp.keepAlive.time.proxy
, which control the keep alive behavior of HttpURLConnection in the case where the server does not specify a keep alive time (by means ofKeep-Alive
header).JDK-8268081: Update Unicode Data Files to 14.0.0: introduces support of the Unicode Standard version 14.0.
JDK-8281181: Do not use CPU Shares to compute active processor count: addresses an incorrect interpretation of the Linux cgroups parameter
cpu.shares
which might cause the JVM inside a container to use fewer CPUs than available.JDK-8274788: Support archived heap objects in ParallelGC: improves startup time since the module graph could be loaded from the archive.
JDK-8280396: G1: Full gc mark stack draining should prefer to make work available to other threads and JDK-8280705: Parallel: Full gc mark stack draining should prefer to make work available to other threads: allow other threads to steal and distribute work.
JDK-8176706: Additional Date-Time Formats: introduces additional date/time formats in the java.time.format.DateTimeFormatter and java.time.format.DateTimeFormatterBuilder classes. The new methods have been added to support that:
JDK-8285660: New System Property to Disable Windows Alternate Data Stream Support in java.io.File: a new system property
jdk.io.File.enableADS
has been added to control the access to NTFS Alternate Data Streams (ADS) on Windows (which is enabled by default).JDK-8280357: User's Home Directory set to $HOME if Invalid: on Linux and macOS, the system property
user.home
is set to the home directory provided by the operating system but if the directory name provided is empty or only a single character, the value of the environment variableHOME
is going to be used instead.JDK-4511638: Double.toString(double) and Float.toString(float) may Return Slightly Different Results: the specification of these methods has been tightened comparing to earlier releases and the new JDK-19 implementation fully adheres to it. As a consequence, some returned strings are now shorter than when using earlier releases, and for inputs at the extremes of the subnormal ranges near zero, might look differently.
JDK-8186958: New Methods to Create Preallocated HashMaps and HashSets: introduces new static factory methods to allow creation of
HashMap
and related instances that are preallocated to accommodate an expected number of mappings or elements.Class java.util.HashMap<K, V>
Class java.util.HashSet<E>
JDK-8274148: JShell Highlights Deprecated Elements, Variables, and Keywords: JShell now marks deprecated elements and highlights variables and keywords in the console.
JDK-8271585: JFR: Scrub recording data: adds programmatic and command-line support to scrub a recording file (to scrub a recording file means to remove sensitive or uninteresting data to reduce the file size).
jfr scrub [filters] [recording-file] [output-file]
Please check out this short but insightful JFR Scrub - Sip of Java blog post to learn more about this JFR new command.
From the standard library point of view, a large chunk of changes went into the classes under java.util.concurrent package so let us start from those:
The java.util.concurrent.Future<T> (and its implementations like java.util.concurrent.CompletableFuture<T>, java.util.concurrent.FutureTask<T>, java.util.concurrent.ForkJoinTask<T>) got three new methods and one enumeration:
The java.util.concurrent.ExecutorService now implements java.lang.AutoCloseable interface
The java.util.concurrent.ForkJoinPool also implements java.lang.AutoCloseable interface and has two more methods:
The java.util.concurrent.ForkJoinTask<T> additionally was enriched with:
The java.util.concurrent.Executors factory became even more capable with preview APIs:
The java.lang.Thread comes at the end with whole bunch of additions (some also in preview):
static java.lang.Thread startVirtualThread(java.lang.Runnable task)
interface Thread.Builder.OfVirtual
interface Thread.Builder.OfPlatform
interface Thread.Builder
The java.lang.Long has introduced a new methods:
Similarly, the java.lang.Integer has introduced this pair of methods:
The class java.math.BigInteger got parallel multiplication support:
The class java.util.Locale was added a number of factory methods:
The quite useful java.util.Objects utility class was not forgotten:
The new factory method made it to java.util.Random class:
The interface java.time.chrono.Chronology was enriched with new method:
Minor but useful addition to java.text.DecimalFormatSymbols class:
And java.lang.invoke.MethodHandles wraps it up with tons of new preview APIs:
From the security perspective, a few notable changes to mention (but feel free to go over much more detailed overview in the JDK 19 Security Enhancements post by Sean Mullan):
JDK-8281561: Disable http DIGEST mechanism with MD5 and SHA-1 by default: the MD5 and SHA-1 message digest algorithms have been disabled by default for HTTP Digest authentication, they can re-enabled on an opt-in basis by setting a new system property
http.auth.digest.reEnabledAlgorithms
.JDK-8280494: (D)TLS signature schemes: introduces new APIs to customize the signature schemes for individual TLS or DTLS connections, for fine control of the security properties. The javax.net.ssl.SSLParameters was extended in these regards with two new methods:
JDK-8279842: HTTPS Channel Binding support for Java GSS/Kerberos: adds the support for TLS channel binding tokens for Negotiate/Kerberos authentication over HTTPS through HttpsURLConnection.
If you are one of the early adopters, please note that JDK-19 introduced a native memory usage regression very late in the release process so that the fix could not be integrated any more (JDK-8292654). The regression has already been addressed in JDK 19.0.1 and later.
With that, hope you are as excited as I am about JDK-19 release, the peaceful revolution is looming! And the JDK-20 early access builds are already there, looking very promising!
I πΊπ¦ stand πΊπ¦ with πΊπ¦ Ukraine.