JDK 13 GA Unveiled: Dynamic CDS, ZGC Uncommit, New Socket API, Switch Expressions & Text Blocks
JDK 13 introduces five major enhancements—Dynamic CDS Archives for faster startup and lower memory, ZGC’s ability to uncommit unused heap memory, a modernized socket API, preview switch expressions, and multi‑line text blocks—each explained with goals, usage examples, and performance impacts.
JDK 13 GA version adds five new features:
350: Dynamic CDS Archives
351: ZGC: Uncommit Unused Memory
353: Reimplement the Legacy Socket API
354: Switch Expressions (Preview)
355: Text Blocks (Preview)
350: Dynamic CDS Archives
Before understanding this feature, you need to know JEP 310: Application Class‑Data Sharing (AppCDS), which improves JVM startup speed and memory usage by allowing application classes to be placed in shared archive files.
JEP 310 goals:
Reduce memory usage by sharing class metadata across Java processes.
Improve startup time.
Allow archived classes to be loaded by custom class loaders.
Enable archived classes to come from the JDK runtime image ($JAVA_HOME/lib/modules).
Success criteria:
Multiple JVM processes save significant memory.
Noticeable reduction in process startup time.
JEP 350 extends CDS so that after a Java application runs, it can dynamically archive classes that were not present in the default CDS archive. Its main goals are:
Increase CDS usability by removing the need for a user‑provided class list.
Enable static archiving via the -Xshare:dump option for both built‑in and custom class loaders.
Previously, using CDS required three steps:
Run the application once (or multiple times) to generate a class list.
Dump an archive using that class list.
Run the application with the created archive.
Example usage:
# JVM exits and creates a shared archive file
bin/java -XX:ArchiveClassesAtExit=hello.jsa -cp hello.jar Hello
# Run the application with the dynamically created archive
bin/java -XX:SharedArchiveFile=hello.jsa -cp hello.jar Hello351: ZGC – Uncommit Unused Memory
This enhancement allows ZGC to return unused heap memory to the operating system, addressing the current limitation where ZGC cannot release memory even after long periods of inactivity.
It benefits memory‑sensitive services such as:
Pay‑as‑you‑go container environments.
Applications that may stay idle for long periods while sharing resources with other workloads.
Applications with highly variable heap requirements during their lifecycle.
Other GCs like G1 and Shenandoah already provide this capability.
In ZGC, the heap consists of regions called ZPage . When a ZPage is reclaimed, it moves to the ZPageCache . Pages in the cache represent unused heap memory that should be returned to the OS. A simple eviction strategy can be based on a timeout value, configurable via JVM flags such as -XX:ZUncommitDelay=seconds. The default timeout is similar to Shenandoah’s 5‑minute delay and can be overridden.
353: Reimplement the Legacy Socket API
The legacy java.net.Socket and java.net.ServerSocket implementations are replaced with a new, easier‑to‑maintain NIO‑based version ( NioSocketImpl) that eliminates native code, reduces reliance on thread‑stack‑based I/O buffers, and uses JUC locks instead of synchronized methods.
Improved maintainability and debugging.
Pure Java NIO implementation, no native code.
Buffer‑cache mechanism removes the need for thread‑stack I/O.
JUC locks replace synchronized methods.
354: Switch Expressions (Preview)
Switch expressions are extended to be usable both as statements and as expressions, supporting traditional case … : syntax as well as the new arrow syntax case … ->. Pattern matching is also introduced (JEP 305).
Example:
if (obj instanceof String s && s.length() > 5) {
// ...
}Preview usage:
switch (day) {
case MONDAY, FRIDAY, SUNDAY -> System.out.println(6);
case TUESDAY -> System.out.println(7);
case THURSDAY, SATURDAY -> System.out.println(8);
case WEDNESDAY -> System.out.println(9);
}355: Text Blocks (Preview)
Text blocks allow multi‑line string literals without needing escape characters, improving readability for embedded HTML, JSON, SQL, etc. The previous raw‑string syntax (JEP 326) was abandoned in favor of triple‑quote delimiters.
Old style (single‑line concatenation):
String html = "<html>
" +
" <body>
" +
" <p>Hello, world</p>
" +
" </body>
" +
"</html>
";New style with text blocks:
String html = """
<html>
<body>
<p>Hello, world</p>
</body>
</html>
""";Reference: OpenJDK JDK 13 project page
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Programmer DD
A tinkering programmer and author of "Spring Cloud Microservices in Action"
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
