Chapter 4. New features for OpenJDK
OpenJDK 17 includes new features that enhance the use of your Java applications.
OpenJDK 17 includes the following new features:
Context-specific deserialization filters
OpenJDK 17 provides the capability for Java programs to configure context-specific and dynamically-selected deserialization filters by using a JVM-wide filter factory. A Java program invokes this filter factory to select a filter for each deserialization operation.
For more information about context-specific deserialization filters, see JEP 415: Context-Specific Deserialization Filters.
Edwards-Curve Digital Signature Algorithm (EdDSA)
OpenJDK 17 supports using an EdDSA algorithm to implement cryptographic signatures.
For more information about EdDSA, see JEP 339: Edwards-Curve Digital Signature Algorithm (EdDSA).
File mapping modes
OpenJDK 17 includes JDK-specific file mapping modes to the
FileChannel API, so that you can create a
MappedByteBuffer instance that maps to non-volatile memory (NVM).
For more information about the JDK-specific file mapping modes, see JEP 352: Non-Volatile Mapped Byte Buffers.
Foreign Linker API (Incubator feature)
OpenJDK 17 introduces the Foreign Linker API. This API provides Java programs with the following capabilities:
- Statically-typed Java access to native code.
- Simplified binding to a native library.
For more information about the Foreign Linker API , see JEP 389: Foreign Linker API.
Foreign-Memory Access API (Incubator feature)
OpenJDK 17 introduces the Foreign-Memory Access API that Java programs can safely and efficiently use to access foreign memory that exists outside of the Java heap.
For more information about the Foreign-Memory Access API, see JEP 393: Foreign-Memory Access API.
Foreign Function and Memory API (Incubator feature)
OpenJDK 17 introduces the Foreign Function and Memory API. Java programs can use this API to interact with code and data outside of the Java runtime.
By efficiently invoking foreign functions, such as code outside the JVM, and by safely accessing foreign memory, such as memory not managed by the JVM, the API provides the following capabilities:
- Enable Java programs to call native libraries.
- Process native data without experiencing any common Java Native Interface (JNI) issues.
For more information about the Foreign Function and Memory API, see JEP 412: Foreign Function & Memory API.
OpenJDK 17 supports hidden classes. Bytecode in other classes cannot use such hidden classes.
A framework can generate these classes at run time and use them indirectly through a process known as reflection. A hidden class can be defined as a member of an access control nest.
For more information about the hidden classes, see JEP 371: Hidden Classes.
HotSpot class-metadata memory
OpenJDK 17 promptly returns unused HotSpot class-metadata memory, such as metaspace, to your operating system. This reduces high off-heap memory usage and simplifies the amount of metaspace code.
For more information about HotSpot class-metadata memory, see JEP 387: Elastic Metaspace.
OpenJDK 17 includes the new package
java.lang.invoke.constant. This package includes an API that you can use to model nominal descriptions for class files and run time artifacts, such as constants that are loadable from the constant pool.
For more information about the
java.lang.invoke.constant package, see JEP 334: JVM Constants API.
JDK Flight Recorder (JFR) data
OpenJDK 17 provides JFR data in a data stream format that you can use to continuously monitor your application’s performance.
For more information about JFR data streams, see JEP 349: JFR Event Streaming.
OpenJDK 17 includes the
jpackage tool that you can use to package self-contained Java applications.
For more information about the
jpackage tool, see JEP 392: Packaging Tool.
Pattern matching for the
instanceof operator supports pattern matching. Pattern matching supports common logic in a program. The
instanceof operator can use pattern matching to conditionally extract components from objects in a concise and safe manner.
For more information about pattern matching, see JEP 394: Pattern Matching for
Pseudo-random number generators
OpenJDK 17 includes additional interface types and implementations for pseudo-random number generators (PRNGs). Java programs can use any of these interface types to reduce duplicate code in existing PRNGs or reuse PRNG algorithms in other applications. These interface types are listed as follows:
For more information about new interface types, see JEP 356: Enhanced Pseudo-Random Number Generators.
You can use record classes to enhance your Java code. Record classes provide a compact syntax for declaring classes, because record classes act as transparent classes for immutable data.
For more information about record classes, see JEP 395: Records.
You can use sealed classes and their interfaces to enhance your Java code. Sealed classes and their interfaces restrict which other classes or interfaces can extend or implement them.
For more information about sealed classes, see JEP 409: Sealed Classes.
OpenJDK 17 includes text blocks. A text block is a multi-line string literal that provides the following functionality:
- Formats a string automatically and predictably.
- Provides a user with the option to format a string.
- Reduces the need for escape sequencing in Java code.
For more information about text blocks see JEP 378: Text Blocks.
Vector API (Incubator feature)
OpenJDK 17 provides an initial iteration of an incubator module,
jdk.incubator.vector, to express vector computations that reliably compile at run time.
Vector computations provide optimal vector hardware instructions on supported CPU architectures, so that these architectures perform better when compared to architectures with scalar computations.
For more information about vector APIs, see JEP 414: Vector API.
Unix domain socket channels
OpenJDK 17 adds support for the Unix-domain,
AF_UNIX, socket to the socket channel and server-socket channel APIs in the
java.nio.channels package. This extends the inherited channel mechanism to support Unix-domain socket channels and server socket channels.
For more information about UNIX domain socket channels see JEP 380: Unix-Domain Socket Channels.
Z Garbage Collector (ZGC)
OpenJDK 17 includes the ZGC as a product feature that you can use as a low-latency collector. ZGC in OpenJDK 17 moves thread-stack processing from safepoints to a concurrent phase, which is similar to that of the Shenandoah GC.
Additionally, OpenJDK 17 provides the following enhancements to the ZGC as Technology Preview features:
Technology Preview features are not supported with Red Hat production service level agreements (SLAs) and might not be functionally complete. Red Hat does not recommend using them in production. These features provide early access to upcoming product features, enabling customers to test functionality and provide feedback during the development process. For more information about the support scope of Red Hat Technology Preview features, see Technology Preview Features Support Scope.
For more information about the ZGC, see JEP 377: ZGC: A Scalable Low-Latency Garbage Collector.
For more information about concurrent thread-stack processing, see JEP 376: ZGC: Concurrent Thread-Stack Processing.