What is new in Java 10 ?

May 01, 2018

Introduction

I will briefly explain all JEPs (JDK Enhancement Proposals) released with Java 10.

All JEPs released with Java 10, and covered in this post, is listed here: http://openjdk.java.net/projects/jdk10/.

JEP 286: Local-Variable Type Inference

Now it is possible to infer the type of variable when it is initialized, so there is no need to write the type of it explicitly.

import java.util.Random;

public class Test {

  public static void main(String[] args) {

    var r = new Random();

    System.out.println(r.nextInt());

  }

}

The type of r is inferred to be java.util.Random implicitly.

JEP 296: Consolidate the JDK Forest into a Single Repository

As I mention in my Custom OpenJDK 10 Builds on Ubuntu 16.04 post, OpenJDK codebase is now consolidated into a single repo, so there is no forest, no need to fetch other repositories after cloning the repo of OpenJDK 10.

JEP 304: Garbage-Collector Interface

The source code of garbage collectors was not well isolated before OpenJDK 10. The aim of this JEP is to make their source code as isolated as possible, thus making it easy to to add a new or remove an existing GC.

The code of GCs are now under src/hotspot/share/gc/GCNAME and maybe under src/hotspot/cpu/share/gc/GCNAME.

Under OpenJDK 10, all GCs are under src/hotspot/share/gc:

$ ls src/hotspot/share/gc
cms  g1  parallel  serial  shared

So the GCs are cms (Concurrent Mark Sweep), g1 (Garbage-First), parallel (Parallel Old and Parallel Scavenge) and serial (Serial).

JEP 307: Parallel Full GC for G1

Garbage-First (G1) GC is the default GC starting with Java 9. However, the full GC implementation of G1 was using a single thread which could make it perform worse than Parallel GC. With Java 10, G1 also does full GC in parallel and the number of threads can be controlled with -XX:ParallelGCThreads option.

JEP 310: Application Class-Data Sharing

Class-Data Sharing enables creating an archive of class metadata, to be memory mapped at startup of an application, thus improving startup time and reducing memory footprint. Until Java 10, it was only possible to use CDS with bootstrap classloader. Java 10 enables CDS for system / application class loader with -XX:+UseAppCDS option.

JEP 312: Thread-Local Handshakes

If a thread is going to be stopped, a global stop had to be issued. With OpenJDK 10, on x64 and SPARC architectures, such operations can be performed per thread, thus eliminating the need for stopping all threads.

JEP 313: Remove the Native-Header Generation Tool (javah)

With Java 8, javac was enhanced to generate native headers with -h option. Thus, javah tool is now removed with Java 10.

JEP 314: Additional Unicode Language-Tag Extensions

java.util.Locale and related APIs are enhanced to support additional Unicode extensions of BCP 47 language tags.

These were already supported in JDK 9:

ca (calendar)
nu (numbers)

and JDK 10 will also support:

cu (currency type)
fw (first day of week)
rg (region override)
tz (time zone)

Here is an example. The default currency of de-CH is CHF:

jshell> Currency.getInstance(Locale.forLanguageTag("de-CH")).getSymbol()
$22 ==> "CHF"
The default currency CHF can be modified providing a cu extension (de-CH-u-cu-usd):
jshell> Currency.getInstance(Locale.forLanguageTag("de-CH-u-cu-usd")).getSymbol()
$25 ==> "$"

JEP 316: Heap Allocation on Alternative Memory Devices

JVM now can allocate the Java Heap on alternative memory devices such as NV-DIMM. The option -XX:AllocateHeapAt=<path> is now supported and the heap is allocated on the path provided using memory mapping.

JEP 317: Experimental Java-Based JIT Compiler

Java-based JIT Compiler Graal is actually already in the JDK codebase and it is the basis of AOT compiler in JDK 9. With JDK 10, it can also be used as a JIT compiler using the JVM Compiler Interface (JVMCI). It is enabled using the following options: -XX:+UnlockExperimentalVMOptions -XX:+UseJVMCICompiler.

JEP 319: Root Certificates

The root certificate store cacerts that is used to validate security protocols before JDK 10 was empty, thus the developers had to import relevant certificates to this store. Starting with JDK 10, cacerts will not be empty and be populated with the certificates of CAs that agreed to be included here.

JEP 322: Time-Based Release Versioning

As a strict, time-based model is being followed after Java 9, the version string is changed to reflect this model. The version string is FEATURE.INTERIM.UPDATE, where:

  • FEATURE is incremented every six months with each new feature release. Thus, JDK 10 released in March 2018 will be followed by September 2018 release of JDK 11.
  • The six-month release model does not have interim releases, so INTERIM is always zero, but it is kept for flexibility.
  • UPDATE is incremented one month after FEATURE is incremented and then every three months. The April 2018 update of JDK 10 is 10.0.1 and the July 2018 will be JDK 10.0.2 .