In this quick tutorial, we will discuss the performance improvements that come along with the latest Java 10 release.
These improvements apply to all applications running under JDK 10, with no need for any code changes to leverage them.
2. Parallel Full GC for G1
The G1 garbage collector is the default one since JDK 9. However, the full GC for G1 used a single threaded mark-sweep-compact algorithm.
This has been changed to the parallel mark-sweep-compact algorithm in Java 10 effectively reducing the stop-the-world time during full GC.
3. Application Class-Data Sharing
Class-Data Sharing, introduced in JDK 5, allows a set of classes to be pre-processed into a shared archive file that can then be memory-mapped at runtime to reduce startup time which can also reduce dynamic memory footprint when multiple JVMs share the same archive file.
CDS only allowed the bootstrap class loader, limiting the feature to system classes only. Application CDS (AppCDS) extends CDS to allow the built-in system class loader (a.k.a., the “app class loader”), the built-in platform class loader, and custom class loaders to load archived classes. This makes it possible to use the feature for application classes.
We can use the following steps to make use of this feature:
1. Get the list of classes to archive
The following command will dump the classes loaded by the HelloWorld application into hello.lst:
$ java -Xshare:off -XX:+UseAppCDS -XX:DumpLoadedClassList=hello.lst \ -cp hello.jar HelloWorld
2. Create the AppCDS archive
Following command creates hello.js a using the hello.lst as input:
$ java -Xshare:dump -XX:+UseAppCDS -XX:SharedClassListFile=hello.lst \ -XX:SharedArchiveFile=hello.jsa -cp hello.jar
3. Use the AppCDS archive
Following command starts the HelloWorld application with hello.jsa as input:
$ java -Xshare:on -XX:+UseAppCDS -XX:SharedArchiveFile=hello.jsa \ -cp hello.jar HelloWorld
AppCDS was a commercial feature in Oracle JDK for JDK 8 and JDK 9. Now it is open sourced and made publicly available.
4. Experimental Java-Based JIT Compiler
Graal is a dynamic compiler written in Java that integrates with the HotSpot JVM; it’s focused on high performance and extensibility. It’s also the basis of the experimental Ahead-of-Time (AOT) compiler introduced in JDK 9.
JDK 10 enables the Graal compiler, to be used as an experimental JIT compiler on the Linux/x64 platform.
To enable Graal as the JIT compiler, use the following options on the java command line:
Note that this is an experimental feature and we may not necessarily get better performance than the existing JIT compilers.
In this quick article, we focused on and explored the performance improvement features in Java 10.