Oracle Turns Java up to 11

Jason Lee, Sr. Principal Software Engineer

Oracle | NetSuite Inc.

Agenda

  • Introduction

  • A quick look at Java 10

  • Java 11

    • The boring stuff

    • What’s gone

    • What you won’t see

    • What you care about

  • Links

Who am I?

  • Jason Lee

  • Sr. Principal Software Engineer for Oracle | NetSuite

    • Tribe (Team) Architect

  • Commerce Site Management Tools

    • WYSIWYG tool for managing content on SuiteCommerce sites

  • Author, Java 9 Programming Blueprints

A quick look at Java 10

  • 6-month release cycle

  • New Long-time Support (LTS) every 3 years (?)

Java 10: Misc

  • Parallel Full GC for G1

    • "Improve G1 worst-case latencies by making the full GC parallel."

  • Garbage Collector Interface

    • "Improve the source code isolation of different garbage collectors by introducing a clean garbage collector (GC) interface."

Java 10: Misc

  • Thread-Local Handshakes

    • Avoid global VM safepoint

    • "A handshake operation is a callback that is executed for each JavaThread while that thread is in a safepoint safe state…​ The big difference between safepointing and handshaking is that the per thread operation will be performed on all threads as soon as possible and they will continue to execute as soon as its own operation is completed."

Java 10: Misc

  • Graal, an experimental Java-based JIT compiler

    • "…​the basis of the experimental Ahead-of-Time (AOT) compiler introduced in JDK 9."

graal perf

Java 10: Local-Variable Type Inference

Enhance the Java Language to extend type inference to declarations of local variables with initializers.

Java 10: Local-Variable Type Inference

Java already had some type inference with the diamond operator

List<String> foo = new ArrayList<>();
Map<Customer, List<Order>> orderMap = new HashMap<>();

Java 10: Local-Variable Type Inference

Expand that to include local variables

var foo = new ArrayList<String>();
var orderMap = new HashMap<Customer, List<Order>>;
var stream = list.stream(); // infers Stream<String>

Not applicable for lambdas (and method params, obviously)

Java 10: Application Data-Class 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. It can also reduce dynamic memory footprint when multiple JVMs share the same archive file."

Java 10: Application Data-Class Sharing

Goals

  • Reduce footprint by sharing common class metadata across different Java processes.

  • Improve startup time.

Java 10: Application Data-Class Sharing

# Determining the classes to archive
java -Xshare:off -XX:+UseAppCDS -XX:DumpLoadedClassList=hello.lst \
    -cp hello.jar HelloWorld

# Creating the AppCDS archive
java -Xshare:dump -XX:+UseAppCDS -XX:SharedClassListFile=hello.lst \
    -XX:SharedArchiveFile=hello.jsa -cp hello.jar

# Using the AppCDS archive
java -Xshare:on -XX:+UseAppCDS -XX:SharedArchiveFile=hello.jsa \
    -cp hello.jar HelloWorld

Java 10: Application Data-Class Sharing

For illustrative purposes:

  • We can save about 340MB of RAM for a Java EE app server that includes 6 JVM processes consuming a total of 13GB of RAM (~2GB of that is for class meta data).

  • We can improve the startup time of the JEdit benchmark by 20-30%.

What’s new in Java 11

Java 11: Licensing!

  • Oracle JDK now "costs". Kinda.

    • Requires license for production use.

    • "Free" updates for 6 months

    • Security updates for Java SE, directly from Oracle (for 8 years)

    • Access to My Oracle Support (MOS) 24x7, support in 27 languages,

    • Java SE 8 Desktop management, monitoring, and deployment features

Java 11: Licensing!

  • THAT’S HORRIBLE! I’M SWITCHING TO JAVASCRIPT!!!

  • Now you have NaN problems…​

Java 11: Licensing!

watman

(Yes, it’s gratuitous, but I couldn’t resist :)

Java 11: Licensing!

  • OpenJDK is the most important build. Should be the go-to source.

    • Oracle JDK built of OpenJDK

    • The two are basically identical

  • "Starting with JDK 11, the Oracle JDK and builds of Oracle OpenJDK will be interchangeable!"

Java 11: Misc

  • Removal of the Java EE and CORBA Modules

  • ZGC: A Scalable Low-Latency Garbage Collector (Experimental, and Linux/x64 only ATM)

  • Dynamic Class-File Constants

Java 11: Misc

  • More Deprecations

    • Nashorn

      • Will be removed in a future release

      • Only options are Rhino or perhaps Graal

    • Pack200 Tools and API

  • JavaFX has been decoupled

Java 11: Epsilon: A No-Op Garbage Collector

  • Garbage collector that…​

  • …​ does nothing

  • Ideal for testing, shell scripts, other short-lived invocations

Java 11: Local-Variable Syntax for Lambda Parameters

Allow var to be used when declaring the formal parameters of implicitly typed lambda expressions."

(var x, var y) -> x.process(y)
(x, y) -> x.process(y)

Java 11: HTTP Client (Standard)

  • Introduced in Java 9 as an incubating feature in jdk.incubator.http

  • Promoted to java.net.http in 11

Java 11: HTTP Client (Standard)

HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
      .uri(URI.create("http://openjdk.java.net/"))
      .build();
client.sendAsync(request, asString())
      .thenApply(HttpResponse::body)
      .thenAccept(System.out::println)
      .join();

Java 11: API Updates

  • Character.toString(int)

  • CharSequence.compare(java.lang.CharSequence, java.lang.CharSequence)

  • String.repeat(int)

  • String.isBlank()

  • String.strip()/stripTrailing()/stripLeading()

  • String.lines()

Java 11: API Updates

  • java.nio.file.Path.of()

Path path = FileSystems.getDefault().getPath("logs", "access.log");
// ...
var path2 = Path.of("logs/access.log")
var userHome = Path.of(System.getProperty("user.home"));

Java 11: Flight Recorder

Provide a low-overhead data collection framework for troubleshooting Java applications and the HotSpot JVM.

Java 11: Flight Recorder

@Label("Hello World")
@Description("Helps the programmer getting started")
class HelloWorld extends Event {
   @Label("Message")
   String message;
}

public static void main(String... args) throws IOException {
    HelloWorld event = new HelloWorld();
    event.message = "hello, world!";
    event.commit();
}

Java 11: Launch Single-File Source-Code Programs

java Factorial.java 3 4 5

is informally equivalent to

javac -d <memory> Factorial.java
java -cp <memory> Factorial 3 4 5

Java 11: Launch Single-File Source-Code Programs

"Shebang" files supported:

#!/path/to/java

./factorial