What's New In JDK 12 Release

Introduction

 
JDK 12 is the open-source reference implementation, of version 12 of the Java SE Platform, as specified by JSR 386, in the Java Community Process.  Java has become a popular language, among developers and programmers.  There are several new languages in the market, though java is a widely-used language and has not lost its charm, since 1996 when it was launched.  Now, JDK 12 has launched.  There are several features and performance improvements, to Java and JVM utilities.
  
The list of changes is shown below.
  • Shenandoah: A Low-Pause-Time Garbage Collector (Experimental)
  • Microbenchmark Suite
  • Switch Expressions (Preview)
  • JVM Constants API
  • One AArch64 Port, Not Two
  • Default CDS Archives
  • Abortable Mixed Collections for G1
  • Promptly Return Unused Committed Memory from G1
     

Shenandoah: A Low-Pause-Time Garbage Collector (Experimental)

 
JDK 12 has added a new Garbage Collection(GC) algorithm, named Shenandoah, which reduces GC pause times, by doing evacuation work concurrently with the running Java threads.  It will be provided as an experimental feature, so in order to use it, XX:+UnlockExperimentalVMOptions is needed together with -XX:+UseShenandoahGC.  This Garbage collector is implemented and supported by RedHat, for aarch64 and amd64.
 

Switch Expressions (Preview)

 
There are two main changes: 
  • Introduction of case L -> syntax that removes the need for break statements, because only the statements next to -> are executed.
     
  • Switch can be an expression, so it can have a value, or it can return a value.
Let's take an example to explain this.  We have a traditional switch-case and new switch case; both features can be seen from the code, as shown below.
  1. public class SwitchCaseFeature {  
  2.  public static void main(String[] args) {  
  3.   final int day = Integer.valueOf(args[0]);  
  4.   switch (day) {  
  5.    case 2:  
  6.    case 3:  
  7.    case 4:  
  8.    case 5:  
  9.    case 6:  
  10.     System.out.println("weekday");  
  11.     break;  
  12.    case 7:  
  13.    case 1:  
  14.     System.out.println("weekend");  
  15.     break;  
  16.    default:  
  17.     System.out.println("invalid");  
  18.   }  
  19.   switch (day) {  
  20.    case 23456 -> System.out.println("weekday");  
  21.    case 71 -> System.out.println("weekend");  
  22.    default -> System.out.println("invalid");  
  23.   }  
  24.   final String attr =  
  25.    switch (day) {  
  26.     case 23456 -> "weekday";  
  27.     case 71 -> "weekend";  
  28.     default -> {  
  29.      break "invalid";  
  30.     }  
  31.    };  
  32.   System.out.println(attr);  
  33.  }  
  34. }  


Microbenchmark Suite

 
A basic suite of microbenchmarks is added to JDK 12 source code, which makes it easy for developers to run existing microbenchmarks and create new ones.
 
  • Based on the [Java Microbenchmark Harness (JMH)]
     
  • Stable and tuned benchmarks, targeted for continuous performance testing


One AArch64 Port, Not Two

 
Earlier, there were two ports contributed by Oracle.  Both were targetting ARM 64-bit in jdk i.e. arm64 and aarch64.  Remove all of the sources related to the arm64 port, while retaining the 32-bit ARM port and the 64-bit aarch64 port.
  

JVM Constants API

 
This release has introduced a constant API, to model nominal descriptions of key class-file and run-time artifacts, in particular constants that are loadable from the constant pool.  This is a useful feature for tools to manipulate classes and methods.
 

Default CDS Archives

 
CDS stands for class data-sharing, this feature enhances the build process, to generate a class data-sharing (CDS) archive, using the default class list, on 64-bit platforms.
  • Startup time improvements out-of-the-box
     
  • Eliminates the need for users to run -Xshare: dump to benefit from CDS


>Abortable Mixed Collections for G1

 
The G1 Garbage Collector aborts the garbage collection process, in order to meet user-supplied pause time target, by splitting the set of to-be garbage collected regions (mixed collection set) into mandatory and optional parts, and aborts the garbage collection of optional parts, if pause time target will not be reached otherwise.
  

Promptly Return Unused Committed Memory from G1

 
When low application activity is detected over a period, then this G1 garbage collector automatically returns the garbage-collected memory to the operating system.  In prior releases, G1 was returning memory to the operating system, after a full GC scan.
 

Conclusion

 
This JDK release has a few java language changes, but more in the performance of java and its utilities.  The garbage collection feature has been enhanced with class data-sharing improvements and so on.  For a more detailed description, you can read here.


Similar Articles