5. JEP 286 (Project Amber)
Local-Variable Type Inference
var list = new ArrayList<String>(); // infers ArrayList<String>
var stream = list.stream(); // infers Stream<String>
strictly speaking
var list = new ArrayList<String>()
is the same as
ArrayList<String> list = new ArrayList<String>();
List<String> list = new ArrayList<String>();
is the same as
var list = (List<String>) new ArrayList<String>()
6. JEP 307
Parallel Full GC for G1
Goal:
● Improve G1 worst-case latencies (when the concurrent collections can't
reclaim memory fast enough) by making the full GC parallel.
7. 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
8. 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
9. Miscellanious 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
10. Miscellanious 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
„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
16. 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)
17. JEP 318
Epsilon: A No-Op Garbage Collector
Goals:
● Provide a completely passive GC implementation with a bounded
allocation limit and the lowest latency overhead possible, at the expense of
memory footprint and memory throughput
● Measure performance of other GCs
18. 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
19. JEP 332
Transport Layer Security 1.3
Goal:
● Implement version 1.3 of the Transport Layer Security (TLS) Protocol
20. Miscellanious API Changes
● File.isSameContents() in addition to File.isSameFile()
● New methods and behaviour on the Java String class
– 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
– isBlank() : true if the string is empty or contains only white space
– stripLeading(), stripTrailing() : removal of Unicode white space from the beginning/end
Sources: https://bugs.openjdk.java.net/browse/JDK-8202285
https://www.javacodegeeks.com/2018/05/new-jdk-11-files-method-issamecontent.html
23. JEP 305
Pattern Matching
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);
}
24. JEP 305
Pattern Matching
int numberOfLetters =switch(season) {
case FALL -> 4;
case WINTER, SPRING, SUMMER -> 6;
default -> throw new IllegalStateException(„unknown season “+season);
};
25. 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); }
26. 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();
}
30. Project Valhalla
Benefits:
● Reduced memory usage
● Reduced indirection
● Increased locality
Codes like a class, works like a primitive (Brian Goetz)
32. Project Valhalla
Value Types
Can
● have method and field
● implement interfaces
● use encapsulation
● be generic
Can’t
● be muted
● be sub-classed
33. Project Valhalla
Specialized Generics
List<Long> points= new ArrayList<Long>();
List<Point> points= new ArrayList<Point>();
class Box<any T> { T value; }
class Box{T=Long} { Long value; }
class Box{T=Point} { Point value; }
Source: John Rose: http://cr.openjdk.java.net/~jrose/values/value-type-hygiene.html
35. 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
36. 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/
43. Difference Between Substrate VM & JVM Models
Source: Kevin Menard : “Improving TruffleRuby’s Startup Time with the SubstrateVM” https://www.youtube.com/watch?v=hIMldcAzd5o
44. 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
45. 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
46. 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.
48. 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
50. Project Loom
Fibers
2 options how to implement:
● Thread (Runnable, ThreadSchedular)
● 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
55. Project Loom
Fibers Use Cases
● Fibers are serializable
– fibers can be sent via network
– advantages when calling external APIs in serverless environment
– shutdown container after sending request, startup after the response arrived and save money
(pause-resume functionality is currently missing for serverless)
● Retriable exceptions
56. Projects Panama
Goal:
● improve and enrich the connections between the JVM and well-defined non-Java
APIs, including many interfaces commonly used by C programmers
Sources: http://openjdk.java.net/projects/panama
Talk by Jim Laskey: “Native Script Engine or Go Panama” https://www.youtube.com/watch?v=-JLhwsbMvjQ
57. Project Shenandoah
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
58. is still an interesting and great
programming language