What to Expect from Java 10 — One Developer’s View

11 Essential Features to Know About

Muktesh mishra
Capital One Tech

--

Over the years, Java has evolved as an ecosystem rather than merely a programming language. Java developers know that Java has committed themselves to a six month release cycles, with Java 10 (JDK 10) knocking on the door and JDK 11 scheduled for fall.

As a member of the Java Community Process(SM) Program, I was able to play around and get my hands dirty on an early release of JDK 10. Although there are well over 100 JEPs/JSRs that are going to be part of JDK 10, in my opinion these 11 features are going to be the game changers *:

*Please note for every release these features are tracked through either Java Enhancement Process (JEP) or Java Community Process (JCP) and some of these features can be discarded in final version (GA).

1. More Container Support

Containers are one of the newest revolutions in software and have changed the paradigm of how software is developed and deployed. There are various container solutions available in the market — Docker, Rocker, DCOS, and many more — which are suitable for various usages. Here is how after JDK 10 changes how containers work in Java.

  • With JDK 10, Java will be self-aware about whether it is running inside a container or on a host.
  • JDK 10 will introduce new JVM options for how containers control Memory and CPU settings. Both options will be used for configuring JVM inside containers so that it takes maximum heap size from Linux CGroup:
  • XX:-UseContainerSupport — to allow container support to be disabled. Default: True i.e.: Enabled.

§ -XX:+UseCGroupMemoryLimitForHeap — to opt-in to using the value in /sys/fs/cgroup/memory/memory.limit_in_bytes as the value for phys_mem.

§ -XX:ActiveProcessorCount=xx — this allows the number of CPUs to be overridden. This flag will be honored even if UseContainerSupport is not enabled.

§ -XX:+UnlockExperimentalVMOptions — enables experimental VM options supported for containers.

docker run -m 2.5G -ti — rm openjdk:10-jdk java -XshowSettings:vm -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -XX:MaxRAMFraction=1 -version
Max. Heap Size (Estimated): 1.84G

2. Local-Variable Type Inference

Allows the developer to declare variable by enhancing type inference, in other words, allows you to declare variables without defining the associated type.

That means this becomes legitimate in JDK 10:

  • var myList = new ArrayList<String>();
  • var myStream = list.stream();

This will be limited to local variables and indexes in loop. This will not be available in JDK 10 for method formals, constructor formals, method return types, fields, catch formals, or any other kind of variable declaration.

jshell> var myList=new ArrayList<>();myList ==> []jshell> myList.add(“Muktesh”);$5 ==> truejshell> myList.add(“Java10”);$6 ==> truejshell> System.out.println(myList);[Muktesh, Java10]jshell> System.out.println(myList.getClass().getName());java.util.ArrayListjshell> var x;| Error:| cannot infer type for local variable x| (cannot use ‘var’ on variable without initializer)| var x;| ^ — — ^

3. Collection Improvements

Like every Java version, in JDK 10 an upgrade has been made to Collections. New methods toUnmodifiableList, toUnmodifiableSet, and toUnmodifiableMapwere have been added to the Collectors class in the Stream package, allowing the elements of a Stream to be collected into an unmodifiable collection.

4. Accessing Non-Java APIs Through Java

Also known as Project Panama. This Java community is working to open doors for non-Java APIs (a lot of them are native C/C++ interfaces). This will enable:

  • Creating new data layouts in Heap.
  • Native metadata definition for JVM.
  • Native-oriented JIT optimizations.
  • Native data access from JVM or inside JVM
  • Also, with this JVM is trying to introduce Native-oriented interpreter especially developed for native languages

5. Polyglot VM Support

Also known as Project Graal, this allows for exposing VM functionalities via API. This is an effort to expose new polyglot runtimes for JVM. This can be implemented via:

  • Graal — the dynamic compiler.
  • Truffle — for implementing languages which use Graal as a compiler.
  • SubstrateVM — to implement Ahead-of-Time compilation of Java applications leveraging Graal.
  • Graal SDK — API collection for Graal VM.

6. Application Class-Data Sharing

Class data sharing has existed in Java fora long time. It has a lot of benefits such as improving JVM start up performance and reducing memory by sharing the same data between different Java process.

  • In JDK 10, the built-in system class loader, the built-in platform class loader, and custom class loaders can load archived classes. Earlier, it was restricted to the bootstrap class loader only.

· -XX:+UseAppCDS will allow all class loaders to share data.

  • Also, it can be turn off by allowing only specified set of classes to be archived. This can be done by turning off entire sharing and only enabling selected sharing.
Jshell> java -Xshare:off -XX:+UseAppCDS -XX:DumpLoadedClassList=com.test -cp Test.jar EntryClass

7. Improving Root Certificate Configuration aka Cacerts

The cacerts keystore (part of JDK) contains a set of root certs. Currently, it comes empty, which is why configuring security protocols (such as TLS) can become so difficult. With JDK 10, it will provide a default set of root certification certificates in JDK.

8. Improvements to Garbage Collection

Like every other release, garbage collection will be improved in JDK 10. This includes:

  • Parallel full garbage collection for G1 garbage collector. G1 was made the default GC in JDK 9 and is now becoming more powerful by allowing full GC parallel.
  • Garbage collector interface has been added which will enable users to configure alternative garbage collectors.

9. Allocating Heap on Multiple Devices

This change will enable users to allocate JVM heap onto multiple devices. This is a WIP but will enable large applications — such as big data applications — to run in multiple and heaps. As of now, it is not fully decided what will stay in DRAM and what will go in alternate memory location.

  • A new flag in JVM will be introduced XX:AllocateHeapAt=<path> which will enable to allocate heap on alternate path.

10. Thread-Local Handshakes

JDK 10 is going to improve a lot of efficiency in concurrent code by allowing execution of a callback on threads without performing a global VM safe point. This will make it easy and cheaper to stop individual threads. It will also improve VM latency since it will spend less effort querying thread states in global VM.

11. Generic Data Type Creation or Generic Runtime Types

Also called Project Valhalla, this will allow developers to define flat data types — i.e. reference-free data types — in Heap. This will result in reduced memory usage and increased locality.

Overall, it seems that Java is planning on a frequent release cycle for new improvements, with core areas of the roadmap focused and committed to containerization and optimization. With a new version scheduled every six months, we will continue to see a series of exciting improvements over time.

I encourage all of you to try out JDK 10 and check out these new features — including the ones I did not list here — yourself.

DISCLOSURE STATEMENT: These opinions are those of the author. Unless noted otherwise in this post, Capital One is not affiliated with, nor is it endorsed by, any of the companies mentioned. All trademarks and other intellectual property used or displayed are the ownership of their respective owners. This article is © 2018 Capital One.

--

--

Muktesh mishra
Capital One Tech

Can code (polyglot), cook, cheer and care. In love with MicroServices, Open Source and new technology. In short: “Nothing special, but passionately curious”.