7. JEP 286 (Project Amber)
Local-Variable Type Inference
URL url = new URL(„www.jugko.de“);
URLConnection connection = url.openConnection();
Reader reader = new BufferedReader (
new InputStreamReader(connection.getInputStream()));
var url = new URL(„www.jugko.de“);
var connection = url.openConnection();
var reader = new BufferedReader (
new InputStreamReader(connection.getInputStream()));
8. JEP 304
Garbage Collector Interface
Goals:
● Better modularity for HotSpot internal GC code
● Make it simpler to add a new GC to HotSpot without perturbing the current
code base
● Make it easier to exclude a GC from a JDK build
9. JEP 317
Experimental Java-Based JIT Compiler
Graal, a Java-based JIT compiler on the Linux/x64 platform, is the basis of the
experimental Ahead-of-Time (AOT) compiler introduced in JDK 9.
To Enable:
-XX:+UnlockExperimentalVMOptions -XX:+UseJVMCICompiler
10. Miscellaneous API Changes
Better container-awareness
● Before later versions of Java 8
– Runtime.getRuntime().availableProcessors() -> retrieves value from sysconf, means the total
number of processors for VM
– Runtime.getRuntime().maxMemory() -> gets the value for VM overall memory
● Java 9 is container-aware automatically detecting cpusets
JVM considers cgroups memory limits if the following flags are specified:
– -XX:+UseCGroupMemoryLimitForHeap
– -XX:+UnlockExperimentalVMOptions
– Max Heap space will be automatically set (if not overwritten) to the limit specified by the cgroup
„Improve docker container detection and resource configuration usage” https://bugs.openjdk.java.net/browse/JDK-8146115
„ Better containerized JVMs in JDK 10” https://jaxenter.com/better-containerized-jvms-jdk-10-140593.html
11. Miscellaneous API Changes
Better container-awareness
● For “fixing” CPU shares in Java 9 overwrite
– -XMX for memory
– -XX:ParallelGCThreads and -XX:ConcGCThreads for CPU
– -System property java.util.concurrent.ForkJoinPool.common.parallelism for ForkJoinPool
● Better container-awareness in Java 10 (CPU shares support is included)
– Runtime.getRuntime().availableProcessors()
– Runtime.getRuntime().maxMemory()
Sources: „Java SE 9 support for Docker CPU and memory limits“https://blogs.oracle.com/java-platform-group/java-se-support-for-
docker-cpu-and-memory-limits
„ Nobody puts Java in a container” https://jaxenter.com/nobody-puts-java-container-139373.html
18. JEP 323 (Project Amber)
Local-Variable Syntax for Lambda Parameters
● (x, y) -> x.process(y) // implicitly typed lambda expression
● (var x, var y) -> x.process(y) // implicit typed lambda expression
● (@NonNull var x, @NonNull var y) -> x.process(y)
19. JEP 321
HTTP Client
Goals:
● Standardize the incubated HTTP Client API introduced in JDK 9, via JEP
110, and updated in JDK 10
● HTTP 2.0 Support
20. JEP 332
Transport Layer Security 1.3
Goal:
● Implement version 1.3 of the Transport Layer Security (TLS) Protocol
21. Miscellaneous API Changes
● File.isSameContents() in addition to File.isSameFile()
● New methods and behaviour on the Java String class
– String#trim method : uses the definition of space as any codepoint that is less than or equal to the
space character codepoint (u0040.)
– String#lines and String#strip also use this definition of String#trim method
– String#isBlank : true if the string is empty or contains only white space
– String#stripLeading, String#stripTrailing : removal of Unicode white space from the beginning/end
– String#repeat(int numberOfTimes) : repeat a string given number if times
Sources: https://bugs.openjdk.java.net/browse/JDK-8202285
https://www.javacodegeeks.com/2018/05/new-jdk-11-files-method-issamecontent.html
23. JEP 2
Preview Language and VM Features
Goals:
● A preview language or VM feature is a new feature of the Java SE
Platform that is fully specified, fully implemented, and yet impermanent. It
is available in a JDK feature release to provoke developer feedback based
on real world use
On JDK 12:
javac Foo.java // Do not enable any preview features
javac --release 12 --enable-preview Foo.java // Enable all preview features of Java SE 12
javac --release 11 --enable-preview Foo.java // DISALLOWED
On JDK 13:
javac Foo.java // Do not enable any preview features
javac --release 13 --enable-preview Foo.java // Enable all preview features of Java SE 13
javac --release 12 --enable-preview Foo.java // DISALLOWED
24. JEP 325
Switch Expressions (Preview)
int numberOfLetters;
switch(season) {
case FALL:
numberOfLetters=4;
break;
case WINTER:
case SPRING:
case SUMMER:
numberOfLetters=6;
break;
default:
throw new IllegalStateException(„unknown season “+season);
}
25. JEP 325
Switch Expressions (Preview)
int numberOfLetters =switch(season) {
case FALL -> 4;
case WINTER, SPRING, SUMMER -> 6;
};
26. JEP 326
Raw String Literals (Preview)
Old way With Raw String Literals
Runtime.getRuntime().exec(""C:Program
Filesfoo" bar");
Runtime.getRuntime().exec(`"C:Progra
m Filesfoo" bar`);
System.out.println("this".matches("wwww")); System.out.println("this".matches(`ww
ww`));
String html = "<html>n" +
" <body>n" +
" <p>Hello World.</p>n" +
" </body>n" +
"</html>n";
String html = `
<html>
<body>
<p>Hello World.</p>
</body>
</html>
`.align();
Sources: https://openjdk.java.net/jeps/326
27. JEP 230
Microbenchmark Suite
Goal:
● Add a basic suite of microbenchmarks based on the Java Microbenchmark
Harness (JMH) to the JDK source code, and make it easy for developers
to run existing microbenchmarks and create new ones.
28. JEP 189
Project Shenandoah: Low-Pause-Time GC (Experimental)
Goals :
● ultra-low pause time garbage collector that reduces GC pause times by
performing more garbage collection work concurrently with the running Java
program
● CMS and G1 both perform concurrent marking of live objects. Shenandoah adds
concurrent compaction
Sources: http://openjdk.java.net/projects/shenandoah
Talk by Alexey Shipilev: “Shenandoah: The Garbage Collector That Could” https://www.youtube.com/watch?v=VCeHkcwfF9Q
31. JEP 305
Pattern Matching
String formatted = "unknown";
if (obj instanceof Integer) {
int i = (Integer) obj;
formatted = String.format("int %d", i);
} else if (obj instanceof Byte) {
byte b = (Byte) obj;
formatted = String.format("byte %d", b);
} else if (obj instanceof Long) {
long l = (Long) obj;
formatted = String.format("long %d", l);
} else if (obj instanceof Double) {
double d = (Double) obj;
formatted = String.format(“double %f", d);
} else if (obj instanceof String) {
String s = (String) obj;
formatted = String.format("String %s", s); }
32. JEP 305
Pattern Matching
String formatted;
switch (obj) {
case Integer i: formatted = String.format("int %d", i);
break;
case Byte b: formatted = String.format("byte %d", b);
break;
case Long l: formatted = String.format("long %d", l);
break;
case Double d: formatted = String.format(“double %f", d);
break;
case String s: formatted = String.format("String %s", s);
break;
default: formatted = obj.toString();
}
33. Records
public class Point {
private final int x, y;
public Point (int x, int y) {
this.x=x;
this.y=y;
}
public int hashCode() { ... }
public boolean equals(Object obj) { ... }
public String toString() { ... }
}
36. Project Valhalla
Goal:
● Reboot the layout of data in memory
Source: Brian Goetz, Oracle „Evolving the Java Language” https://www.youtube.com/watch?v=A-mxj2vhVAA
37. Project Valhalla
Motivation:
● Hardware has changed
– Multi-core
– The cost of cache misses has increased
Source: Brian Goetz, Oracle „Evolving the Java Language” https://www.youtube.com/watch?v=A-mxj2vhVAA
41. Project Valhalla
Benefits:
● Reduced memory usage
● Reduced indirection
● Increased locality
Codes like a class, works like a primitive (Brian Goetz)
43. Project Valhalla
Value Types
Can
● have method and field
● implement interfaces
● use encapsulation
● be generic
Can’t
● be mutated
● be sub-classed
44. Project Valhalla
Generics over Values and Specialized Generics
List<Long> points= new ArrayList<Long>();
List<Point> points= new ArrayList<Point>();
class Box<any T> { T value; }
class Box<T=Long>
class Box<T=Point>
Source: John Rose: http://cr.openjdk.java.net/~jrose/values/value-type-hygiene.html
45. Project Valhalla
Current Status:
● Released public prototype LW1
– VM support for „value types“ (as subtypes of Object)
– Only language support for „value types“ (no support for „generics over values“ and „specialized
generics“)
– No support for migrating existing classes to „value types“ yet
Source: Brian Goetz, Oracle „Evolving the Java Language” https://www.youtube.com/watch?v=A-mxj2vhVAA
46. Project Metropolis
Polyglot GraalVM for Java 8
(current version 1.0-RC10 as of 2018-12-05)
Source: http://openjdk.java.net/projects/metropolis
47. Project Metropolis
Goals:
● High performance for all languages
● Zero overhead interoperability between languages
● Language-level virtualization level for shared tooling
Source: Oleg Selajev : “Run Code in Any Language Anywhere with GraalVM” https://www.youtube.com/watch?v=JoDOo4FyYMU
48. GraalVM
Architecture
Sources: Practical Partial Evaluation for High-Performance Dynamic Language Runtimes
http://chrisseaton.com/rubytruffle/pldi17-truffle/pldi17-truffle.pdf
„The LLVM Compiler Infrastructure“ https://llvm.org/
49. Project Sulong
Source: Thomas Würthinger, Oracle : “One VM to Rule Them All” https://www.youtube.com/watch?v=mMmOntDWSgw
50. GraalVM
Architecture
Sources: Practical Partial Evaluation for High-Performance Dynamic Language Runtimes
http://chrisseaton.com/rubytruffle/pldi17-truffle/pldi17-truffle.pdf
„The LLVM Compiler Infrastructure“ https://llvm.org/
51. SubstrateVM
Source: Oleg Šelajev, Thomas Wuerthinger, Oracle: “Deep dive into using GraalVM for Java and JavaScript”
https://www.youtube.com/watch?v=a-XEZobXspo
52. GraalVM and SubstrateVM
Source: Oleg Selajev, Oracle : “Run Code in Any Language Anywhere with GraalVM” https://www.youtube.com/watch?v=JoDOo4FyYMU
53. Difference Between Substrate VM & JVM Models
Source: Kevin Menard : “Improving TruffleRuby’s Startup Time with the SubstrateVM” https://www.youtube.com/watch?v=hIMldcAzd5o
54. GraalVM on SubstrateVM
A game changer for Java & Serverless?
Cold Start :
Source: Ajay Nair „Become a Serverless Black Belt” https://www.youtube.com/watch?v=oQFORsso2go
55. AWS Lambda cold start time
by supported language
Source: Yan Cui: https://read.acloud.guru/does-coding-language-memory-or-package-size-affect-cold-starts-of-aws-lambda-a15e26d12c76
56. GraalVM on SubstrateVM
A game changer for Java & Serverless?
Java Function compiled into a native executable using GraalVM on
SubstrateVM reduces
● “cold start” times
● memory footprint
by order of magnitude compared to running on JVM.
58. Project Loom
Motivation:
● Developers currently have 2 choices
– use blocking/synchronous API, which is simple, but less scalable (number of threads, that OS
supports is far less that open and concurrent connections required or supported)
– asynchronous API (Spring Project Reactor, RXJava 2), which is scalable, but complex, harder to
debug and profile and limited (no asynchronous JDBC standard in this area)
Source: Alan Bateman, Oracle „Project Loom: Fibers and Continuations for Java” https://www.youtube.com/watch?v=vbGbXUjlRyQ
59. Project Loom
Goals:
● explore and incubate Java VM features and APIs built on top of them for
the implementation of lightweight user-mode threads (fibers), delimited
continuations.
● add another option to use write blocking, but scalable code
61. Continuation
package java.lang;
public class Continuation {
public Continuation (ContinuationScope scope, Runnable target)
public final void run()
public static void yield (ContinuationScope scope)
public boolean isDone()
}
http://hg.openjdk.java.net/loom/loom/file/d6496338e000/src/java.base/share/classes/java/lang/Continuation.java
62. Project Loom
Continuations
example () {
var scope = new ContinuationScope(„Example_Scope“);
var continuation = new Continuation (scope, () -> {
out.print(„1“);
Continuation.yield(scope);
out.print(„2“);
Continuation.yield(scope);
out.print(„3“);
Continuation.yield(scope);
});
while (! continuation.isDone()) {
out.print(„ run.. “);
continuation.run();
}
}
Output: run.. 1 run.. 2 run.. 3
63. Project Loom
Fibers
Fibre is a lightweight thread scheduled not by the OS, but by
the Java Runtime with low memory footprint and low task-
switching cost
64. Project Loom
Fibers
Strand (abstract thread)
Fiber Thread
Source: Talk „Project Loom: Fibers and Continuations for the Java Virtual Machine“ by Ron Pressler
https://www.youtube.com/watch?v=fpyub8fbrVE
67. Project Loom
Fibers
● java.lang.Fibre currently supports:
– scheduling
– parking/unparking
– waiting for a fibre to terminate
● java.util.concurrent can park/unpark fibres
● Socket and Pipe APIs park fibers rather than block threads
in syscalls
Source: Alan Bateman, Oracle „Project Loom: Fibers and Continuations for Java” https://www.youtube.com/watch?v=vbGbXUjlRyQ
68. Project Loom
Current Status:
● Implemented initial prototype with Continuation and Fiber support
● Current prototype of Continuations and Fibers can run existing code (with
some limitations)
● Current focus on
– Performance improvement
– Stable Fiber API
– Debugger support
Source: Alan Bateman, Oracle „Project Loom: Fibers and Continuations for Java” https://www.youtube.com/watch?v=vbGbXUjlRyQ
http://hg.openjdk.java.net/loom
69. Project Loom
Open Questions:
● Should the existing Thread API be completely re-examined?
● Can all existing code be run on top of Fibers?
Source: Alan Bateman, Oracle „Project Loom: Fibers and Continuations for Java” https://www.youtube.com/watch?v=vbGbXUjlRyQ
70. is still an interesting and great
programming language