Java 9/10
What’s New
Simone Bordet
● @simonebordet
● sbordet@webtide.com
● Java Champion
● Works @ Webtide
● The company behind Jetty and CometD
● JVM Tuning Expert
Java 9
● Java 9 & 10 are NOTLong Term Support (LTS) Releases
● Java 8 current LTS Release supported March 2014 - January 2019
● Java 9 supported September 2017 - March 2018
● Java 10 supported March 2018 - September 2018
● Java 11 new LTS Release September 2018
● But “LTS” has a special meaning
Java 9
● “Long Term Support” is only for Oracle customers
● For Oracle customers Java 11 will be supported for 3 years
● For all the others Java 11 will last the usual 6 months only
● You will be “Long Term Supported” by moving to Java 12
● Other JDK vendors may give you support where Oracle does not
○ Azul, RedHat, London Java Community (LJC), etc.
https://www.azul.com/products/zulu-and-zulu-enterprise/zulu-enterprise-java-support-options/
Java 9
● Java 9 comes with a MASSIVE number of changes
○ 91 JEPs (!)
● Biggest change: Jigsaw modules
● Upgrade to Java 9 not as smooth as past JDKs
○ Needs very thorough testing
● Removed tools.jar
○ Attach APIs
○ Programmatically call javac (JSP compilation), javadoc, etc.
● tools.jar content split into packages
○ jdk.attach
○ jdk.compiler (but use module java.compiler)
○ jdk.javadoc
● Removed JavaDB
○ Rebranding of Apache Derby
Java 9 Removals
Java 9 Removals
● Removed endorsed directory mechanism
$JAVA_HOME/lib/endorsed
● Could only contain updates for:
○ CORBA
○ XML DOM
○ XML SAX
● Rarely used to update the implementations shipped with the JDK
Java 9 Removals
● Removed Extension Directory Mechanism
○ Moved to modules
$JAVA_HOME/jre/lib/ext
nashorn.jar
jfxrt.jar
sunec.jar
sunjce_provider.jar
zipfs.jar
...
Java 9 Changes
● ClassLoader Hierarchy
● Java 8
Boot CL <- Extension CL <- System CL
ClassLoader.getSystemClassLoader()
● Java 9
Boot CL <- Platform CL <- System CL
ClassLoader.getPlatformClassLoader()
ClassLoader.getSystemClassLoader()
Java 9 Changes
● ClassLoading Implementation Changes
// Throws ClassCastException now!
URLClassLoader system = (URLClassLoader)ClassLoader.getSystemClassLoader();
● ClassLoader Resources
URL resource = system.getResource("java/lang/String.class");
resource = jrt:/java.base/java/lang/String.class
● Class scanning for annotations
○ Previous techniques not working in JDK 9
○ Cannot retrieve the list of jars to open
Java 9 Changes
● JEP 223 - New Version String Scheme
○ System.getProperty("java.version")
○ 1.8.0_152 -> 9.0.1
○ Broke many Maven Plugins, Jetty, etc.
● JDK 9’s java.lang.Runtime.Version class
○ Cannot parse JDK 8 version string
○ Must implement custom parsing to support both
Java 9 New Features
● JEP 260 - Encapsulate Internal APIs
● Non-critical internal APIs have been removed
○ sun.misc.Base64Decoder
● Critical internal APIs without replacement -> retained
○ In module jdk.unsupported
○ For example, sun.misc.Unsafe
○ Don’t use them
● Critical internal APIs with replacement -> encapsulated
○ Use the replacements
Java 9 New Features
● JEP 260 - Encapsulate Internal APIs
● Most internal APIs now have a public replacement
● Finalization
○ sun.misc.Cleaner replaced by java.lang.ref.Cleaner
○ Object.finalize() is now deprecated
● Unsafe access
○ Some sun.misc.Unsafe usage replaced by VarHandle
Java 9 New Features
● JEP 260 - Encapsulate Internal APIs
● jdeps tool produces a report of class/jar/module dependencies
$ jdeps -s jetty-util-9.4.8-SNAPSHOT.jar
jetty-util-9.4.8-SNAPSHOT.jar -> java.base
jetty-util-9.4.8-SNAPSHOT.jar -> java.desktop
jetty-util-9.4.8-SNAPSHOT.jar -> java.logging
jetty-util-9.4.8-SNAPSHOT.jar -> java.naming
jetty-util-9.4.8-SNAPSHOT.jar -> java.sql
jetty-util-9.4.8-SNAPSHOT.jar -> java.xml
jetty-util-9.4.8-SNAPSHOT.jar -> not found
Java 9 New Features
● JEP 247 - Compile for older platforms
● New switch --release to javac
○ Supports up to 3 previous releases
● $JAVA_HOME/lib/ct.sym
○ Zipped file containing the symbols for each platform
Java 9 New Features
<profile>
<id>jdk9</id>
<activation>
<jdk>[1.9,)</jdk>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0+</version>
<configuration>
<release>8</release>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Java 9 New Features
● JEP 238 - Multi Release jars
com/
acme/
A.class
B.class
C.class
META-INF/
versions/
9/
com/
acme/
A.class
D.class
Java 9 Changes
● URLStreamHandler
● Java 8: Magic Reflection
○ sun.net.www.protocol.<scheme>.Handler
● Java 9: ServiceLoader
○ Implement java.net.spi.URLStreamHandlerProvider
● Difficult to make a jar with both solutions
○ Service files cannot be versioned
Java 9 New Features
● JEP 213 - Small Language Changes
● Cannot use "_" as identifier
○ Object _ = new Object();
● Improved type inference
○ Use diamond notation in anonymous inner classes
● Private methods in interfaces
○ Useful to AOP frameworks
○ Avoids code duplications in default methods
Java 9 New Features
● JEP 213 - Small Language Changes
● Enhanced try-with-resources
InputStream input = ...;
...
try (input) {
...
}
Java 9 New Features
● JEP 264 - Platform Logging APIs
○ Implementation defaults to java.util.logging
System.getLogger("name")
.log(Level.INFO, () -> "a" + " - " + "b");
System.getLogger("name")
.log(Level.INFO, "%s - %s", a, b);
Java 9 New Features
● JEP 254 - Compact Strings
○ java.lang.String now stores a byte[], not a char[]
● JEP 280 - String concatenation using invokedynamic
○ Faster and allocates less
● JEP 269 - Collections factory methods
○ Space efficient
List.of("a", "b", "c");
Set.of("a", "b", "c");
Map.of("a", 1, "b", 2, "c", 3);
Java 9 New Features
● JEP 193 - Variable Handles
class ConcurrentLinkedQueue_BAD {
AtomicReference<Node> head; // BAD, adds indirection
}
class ConcurrentLinkedQueue {
Node head;
private static final VarHandle HEAD;
static {
HEAD = MethodHandles.lookup()
.findVarHandle(ConcurrentLinkedQueue.class, "head", Node.class);
}
public void m() {
if (HEAD.compareAndSet(...))
...
}
}
Java 9 New Features
● JEP 102 - Process API
Process p = new ProcessBuilder()
.command("java")
.directory(new File("/tmp"))
.redirectOutput(Redirect.DISCARD)
.start();
ProcessHandle.of(p.pid())
.orElseThrow(IllegalStateException::new)
.onExit()
.thenAccept(h ->
System.err.printf("%d exited%n", h.pid())
);
Java 9 New Features
● JEP 266 - Concurrent APIs Enhancements
● java.util.concurrent.Flow
○ Identical API and semantic of ReactiveStreams
● CompletableFuture Enhancements
○ Common scheduler for timeout functionalities
CompletableFuture.supplyAsync(() -> longJob())
.completeOnTimeout("N/A", 1, TimeUnit.SECONDS)
CompletableFuture.supplyAsync(() -> longJob())
.orTimeout(1, TimeUnit.SECONDS)
● JEP 143 - Improve Contended Locking
○ synchronized now as scalable as java.util.concurrent.Lock
http://vmlens.com/articles/performance-improvements-of-java-monitor/
Java 9 Changes
Java 9 New Features
● JEP 295: Ahead-of-Time Compilation
○ Experimental
○ Based on the Java-based Graal JIT compiler
https://mjg123.github.io/2017/10/02/JVM-startup.html
Java 9 New Features
● JEP 222 - jshell Read-Eval-Print-Loop (REPL)
○ Can be accessed programmatically via module jdk.jshell
● Pretty powerful !
○ Completion
○ Imports
○ Variable creation
○ Documentation
○ Functions and Forward References
○ History
○ Search
○ External Editor
Java 9 Changes
● JEP 248 - Make G1 the Default Collector
● 250+ Improvements
○ Adaptive start of concurrent mark -XX:+G1UseAdaptiveIHOP
○ Made internal data structures more concurrent
○ More phases parallelized
○ Reduced contention
○ Reduced memory consumption
○ …
● 180+ Bug Fixes
Java 9 Changes
● JEP 158 - Unified JVM Logging
● Logs have a message, tags (finally) and a level; can be decorated
● Tags
○ gc, ref, ergo, …
● Levels
○ error, warning, info, debug, trace
● Output
○ stdout, stderr, file
● Decorators
○ time (various formats), pid, tid, level, tags
● Default
○ -Xlog:all=warning:stderr:uptime,level,tags
Java 9 Changes
● JEP 271 - Unified GC Logging
○ Done using JEP 158 - Unified JVM Logging
● Example for GC logging
○ -Xlog:gc*,ergo*=trace,ref*=debug:file=logs/gc.log:time,level,tags
● Not compatible with previous logging formats
○ Need to parse the logs differently
Java 9 Changes
● JVM Options Changes
○ 50 Removed - JVM refuses to start
○ 18 Ignored, 12 Deprecated
● Important JVM Options Removed
○ GCLogFileSize
○ NumberOfGCLogFiles
○ PrintAdaptiveSizePolicy
○ PrintGCApplicationStoppedTime
○ PrintGCCause
○ PrintGCDateStamps
○ PrintGCTimeStamps
○ PrintReferenceGC
○ PrintTenuringDistribution
○ ...
Java 9 Changes
● JEP 277 - Enhanced Deprecation
@Deprecated(since="1.8", forRemoval=true)
● jdeprscan
○ Produces a report of deprecations
Java 9 Changes
● JEP 229 - Keystore Defaults to PKCS12
● PKCS12
○ Standard format, more secure, more extensible
○ Already supported in JDK 8
● JDK 9
○ keytool by default creates PKCS12 keystores
○ Autodetects JKS and PKCS12 keystores
Java 9 New Features
● JEP 219 - Datagram Transport Layer Security (DTLS)
● JEP 244 - TLS Application-Layer Protocol Negotiation Extension (ALPN)
● JEP 246 - Leverage CPU Instructions for GHASH and RSA
● JEP 249 - OCSP Stapling for TLS
● JEP 273 - DRBG-Based SecureRandom Implementations
● JEP 287 - SHA-3 Hash Algorithms
● JEP 288 - Disable SHA-1 Certificates
Java 10
● Parallel full GC for G1
● In Java 9, if G1 must perform a full GC it’s single threaded
○ Very slow
● In Java 10, it has been parallelized
[5.423s] GC(59) Pause Full 4028M->3286M(4096M) 513.026ms
[5.423s] GC(59) User=2.80s Sys=0.04s Real=0.52s
Java 10
● Experimental Graal JIT
○ https://www.graalvm.org/
● -XX:+UnlockExperimentalVMOptions -XX:+UseJVMCICompiler
● Not yet recommended in production
Java 10
● Application class-data sharing
○ https://blog.codefx.org/java/application-class-data-sharing/
● -Xshare:dump
○ Dumps JDK classes
○ Faster startup times
$ java
-XX:+UseAppCDS
-Xshare:dump
-XX:SharedClassListFile=classes.lst
-XX:SharedArchiveFile=app-cds.jsa
--class-path app.jar
Java 10
● Thread-Local Handshakes
● Improves JVM performance
○ Reduces Time-To-SafePoint (TTSP)
● No need to have a global SafePoint to get stack traces
○ Great benefit to profilers for stack sampling
Java 10
● Docker awareness (Linux only)
○ https://blog.docker.com/2018/04/improved-docker-container-integration-with-java-10/
○ It is on by default
● -XX:-UseContainerSupport
● -XX:ActiveProcessorCount=n
● -XX:MinRAMPercentage=p
● -XX:InitialRAMPercentage=p
● -XX:MaxRAMPercentage=p
Java 10
● Planned removals for JDK 11
● java.corba (CORBA)
● java.xml.bind (JAXB)
● java.xml.ws (SOAP)
● java.xml.ws.annotation (@PostConstruct, @PreDestroy, ...)
Java 10
● Local variable type inference (a.k.a. var)
○ http://openjdk.java.net/projects/amber/LVTIstyle.html
var list = new ArrayList<String>(); // infers ArrayList<String>
var stream = list.stream(); // infers Stream<String>
● var is not a keyword, it is a reserved type name
○ It’s a valid identifier, unless used in places where the compiler expects a type name
int var = 13;
Java 10
● var comes with some controversy
var message = "warning, too many features"; // Good
● Consider:
List<String> list = new ArrayList<>();
list.trimToSize(); // Does not compile
var list = new ArrayList<String>();
list.trimToSize(); // Compiles
Java 10
● More controversy:
var result = processor.run(); // What type ?
var list = new <ctrl+space> // IDE cannot help you
Java 9/10 Migration
● Migrating to Java 9/10 is an iterative process
○ Typically cannot be done in one step only
● Update dependencies
○ Build tools
○ Libraries
● Run jdeps -jdkinternals
● Fix usages of encapsulated APIs
● Using EE modules ?
● Add --add-modules to command line
Java 9/10 Migration
● Update command line options
● Fix GC logging
● Fix your System.getProperty("java.version") usages
● Do not do deep reflection on JDK classes
○ Do not use setAccessible(true);
● Verify your ClassLoader usages
● Verify your sun.* usages
Java 9/10 Migration
● Java 9 upgrade may introduce different behaviors at runtime
● Java code may throw exceptions when running in Java 9
○ Parsing of "java.version"
○ Playing with ClassLoaders and resources
○ URLStreamHandlers
○ Use of internal APIs
○ Etc.
● You can only discover these incompatibilities by extensive testing
○ Requires time to do, so start immediately !
Questions ?

Java 9-10 What's New

  • 1.
  • 2.
    Simone Bordet ● @simonebordet ●sbordet@webtide.com ● Java Champion ● Works @ Webtide ● The company behind Jetty and CometD ● JVM Tuning Expert
  • 3.
    Java 9 ● Java9 & 10 are NOTLong Term Support (LTS) Releases ● Java 8 current LTS Release supported March 2014 - January 2019 ● Java 9 supported September 2017 - March 2018 ● Java 10 supported March 2018 - September 2018 ● Java 11 new LTS Release September 2018 ● But “LTS” has a special meaning
  • 4.
    Java 9 ● “LongTerm Support” is only for Oracle customers ● For Oracle customers Java 11 will be supported for 3 years ● For all the others Java 11 will last the usual 6 months only ● You will be “Long Term Supported” by moving to Java 12 ● Other JDK vendors may give you support where Oracle does not ○ Azul, RedHat, London Java Community (LJC), etc.
  • 5.
  • 6.
    Java 9 ● Java9 comes with a MASSIVE number of changes ○ 91 JEPs (!) ● Biggest change: Jigsaw modules ● Upgrade to Java 9 not as smooth as past JDKs ○ Needs very thorough testing
  • 7.
    ● Removed tools.jar ○Attach APIs ○ Programmatically call javac (JSP compilation), javadoc, etc. ● tools.jar content split into packages ○ jdk.attach ○ jdk.compiler (but use module java.compiler) ○ jdk.javadoc ● Removed JavaDB ○ Rebranding of Apache Derby Java 9 Removals
  • 8.
    Java 9 Removals ●Removed endorsed directory mechanism $JAVA_HOME/lib/endorsed ● Could only contain updates for: ○ CORBA ○ XML DOM ○ XML SAX ● Rarely used to update the implementations shipped with the JDK
  • 9.
    Java 9 Removals ●Removed Extension Directory Mechanism ○ Moved to modules $JAVA_HOME/jre/lib/ext nashorn.jar jfxrt.jar sunec.jar sunjce_provider.jar zipfs.jar ...
  • 10.
    Java 9 Changes ●ClassLoader Hierarchy ● Java 8 Boot CL <- Extension CL <- System CL ClassLoader.getSystemClassLoader() ● Java 9 Boot CL <- Platform CL <- System CL ClassLoader.getPlatformClassLoader() ClassLoader.getSystemClassLoader()
  • 11.
    Java 9 Changes ●ClassLoading Implementation Changes // Throws ClassCastException now! URLClassLoader system = (URLClassLoader)ClassLoader.getSystemClassLoader(); ● ClassLoader Resources URL resource = system.getResource("java/lang/String.class"); resource = jrt:/java.base/java/lang/String.class ● Class scanning for annotations ○ Previous techniques not working in JDK 9 ○ Cannot retrieve the list of jars to open
  • 12.
    Java 9 Changes ●JEP 223 - New Version String Scheme ○ System.getProperty("java.version") ○ 1.8.0_152 -> 9.0.1 ○ Broke many Maven Plugins, Jetty, etc. ● JDK 9’s java.lang.Runtime.Version class ○ Cannot parse JDK 8 version string ○ Must implement custom parsing to support both
  • 13.
    Java 9 NewFeatures ● JEP 260 - Encapsulate Internal APIs ● Non-critical internal APIs have been removed ○ sun.misc.Base64Decoder ● Critical internal APIs without replacement -> retained ○ In module jdk.unsupported ○ For example, sun.misc.Unsafe ○ Don’t use them ● Critical internal APIs with replacement -> encapsulated ○ Use the replacements
  • 14.
    Java 9 NewFeatures ● JEP 260 - Encapsulate Internal APIs ● Most internal APIs now have a public replacement ● Finalization ○ sun.misc.Cleaner replaced by java.lang.ref.Cleaner ○ Object.finalize() is now deprecated ● Unsafe access ○ Some sun.misc.Unsafe usage replaced by VarHandle
  • 15.
    Java 9 NewFeatures ● JEP 260 - Encapsulate Internal APIs ● jdeps tool produces a report of class/jar/module dependencies $ jdeps -s jetty-util-9.4.8-SNAPSHOT.jar jetty-util-9.4.8-SNAPSHOT.jar -> java.base jetty-util-9.4.8-SNAPSHOT.jar -> java.desktop jetty-util-9.4.8-SNAPSHOT.jar -> java.logging jetty-util-9.4.8-SNAPSHOT.jar -> java.naming jetty-util-9.4.8-SNAPSHOT.jar -> java.sql jetty-util-9.4.8-SNAPSHOT.jar -> java.xml jetty-util-9.4.8-SNAPSHOT.jar -> not found
  • 16.
    Java 9 NewFeatures ● JEP 247 - Compile for older platforms ● New switch --release to javac ○ Supports up to 3 previous releases ● $JAVA_HOME/lib/ct.sym ○ Zipped file containing the symbols for each platform
  • 17.
    Java 9 NewFeatures <profile> <id>jdk9</id> <activation> <jdk>[1.9,)</jdk> </activation> <build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.6.0+</version> <configuration> <release>8</release> </configuration> </plugin> </plugins> </build> </profile>
  • 18.
    Java 9 NewFeatures ● JEP 238 - Multi Release jars com/ acme/ A.class B.class C.class META-INF/ versions/ 9/ com/ acme/ A.class D.class
  • 19.
    Java 9 Changes ●URLStreamHandler ● Java 8: Magic Reflection ○ sun.net.www.protocol.<scheme>.Handler ● Java 9: ServiceLoader ○ Implement java.net.spi.URLStreamHandlerProvider ● Difficult to make a jar with both solutions ○ Service files cannot be versioned
  • 20.
    Java 9 NewFeatures ● JEP 213 - Small Language Changes ● Cannot use "_" as identifier ○ Object _ = new Object(); ● Improved type inference ○ Use diamond notation in anonymous inner classes ● Private methods in interfaces ○ Useful to AOP frameworks ○ Avoids code duplications in default methods
  • 21.
    Java 9 NewFeatures ● JEP 213 - Small Language Changes ● Enhanced try-with-resources InputStream input = ...; ... try (input) { ... }
  • 22.
    Java 9 NewFeatures ● JEP 264 - Platform Logging APIs ○ Implementation defaults to java.util.logging System.getLogger("name") .log(Level.INFO, () -> "a" + " - " + "b"); System.getLogger("name") .log(Level.INFO, "%s - %s", a, b);
  • 23.
    Java 9 NewFeatures ● JEP 254 - Compact Strings ○ java.lang.String now stores a byte[], not a char[] ● JEP 280 - String concatenation using invokedynamic ○ Faster and allocates less ● JEP 269 - Collections factory methods ○ Space efficient List.of("a", "b", "c"); Set.of("a", "b", "c"); Map.of("a", 1, "b", 2, "c", 3);
  • 24.
    Java 9 NewFeatures ● JEP 193 - Variable Handles class ConcurrentLinkedQueue_BAD { AtomicReference<Node> head; // BAD, adds indirection } class ConcurrentLinkedQueue { Node head; private static final VarHandle HEAD; static { HEAD = MethodHandles.lookup() .findVarHandle(ConcurrentLinkedQueue.class, "head", Node.class); } public void m() { if (HEAD.compareAndSet(...)) ... } }
  • 25.
    Java 9 NewFeatures ● JEP 102 - Process API Process p = new ProcessBuilder() .command("java") .directory(new File("/tmp")) .redirectOutput(Redirect.DISCARD) .start(); ProcessHandle.of(p.pid()) .orElseThrow(IllegalStateException::new) .onExit() .thenAccept(h -> System.err.printf("%d exited%n", h.pid()) );
  • 26.
    Java 9 NewFeatures ● JEP 266 - Concurrent APIs Enhancements ● java.util.concurrent.Flow ○ Identical API and semantic of ReactiveStreams ● CompletableFuture Enhancements ○ Common scheduler for timeout functionalities CompletableFuture.supplyAsync(() -> longJob()) .completeOnTimeout("N/A", 1, TimeUnit.SECONDS) CompletableFuture.supplyAsync(() -> longJob()) .orTimeout(1, TimeUnit.SECONDS)
  • 27.
    ● JEP 143- Improve Contended Locking ○ synchronized now as scalable as java.util.concurrent.Lock http://vmlens.com/articles/performance-improvements-of-java-monitor/ Java 9 Changes
  • 28.
    Java 9 NewFeatures ● JEP 295: Ahead-of-Time Compilation ○ Experimental ○ Based on the Java-based Graal JIT compiler https://mjg123.github.io/2017/10/02/JVM-startup.html
  • 29.
    Java 9 NewFeatures ● JEP 222 - jshell Read-Eval-Print-Loop (REPL) ○ Can be accessed programmatically via module jdk.jshell ● Pretty powerful ! ○ Completion ○ Imports ○ Variable creation ○ Documentation ○ Functions and Forward References ○ History ○ Search ○ External Editor
  • 30.
    Java 9 Changes ●JEP 248 - Make G1 the Default Collector ● 250+ Improvements ○ Adaptive start of concurrent mark -XX:+G1UseAdaptiveIHOP ○ Made internal data structures more concurrent ○ More phases parallelized ○ Reduced contention ○ Reduced memory consumption ○ … ● 180+ Bug Fixes
  • 31.
    Java 9 Changes ●JEP 158 - Unified JVM Logging ● Logs have a message, tags (finally) and a level; can be decorated ● Tags ○ gc, ref, ergo, … ● Levels ○ error, warning, info, debug, trace ● Output ○ stdout, stderr, file ● Decorators ○ time (various formats), pid, tid, level, tags ● Default ○ -Xlog:all=warning:stderr:uptime,level,tags
  • 32.
    Java 9 Changes ●JEP 271 - Unified GC Logging ○ Done using JEP 158 - Unified JVM Logging ● Example for GC logging ○ -Xlog:gc*,ergo*=trace,ref*=debug:file=logs/gc.log:time,level,tags ● Not compatible with previous logging formats ○ Need to parse the logs differently
  • 33.
    Java 9 Changes ●JVM Options Changes ○ 50 Removed - JVM refuses to start ○ 18 Ignored, 12 Deprecated ● Important JVM Options Removed ○ GCLogFileSize ○ NumberOfGCLogFiles ○ PrintAdaptiveSizePolicy ○ PrintGCApplicationStoppedTime ○ PrintGCCause ○ PrintGCDateStamps ○ PrintGCTimeStamps ○ PrintReferenceGC ○ PrintTenuringDistribution ○ ...
  • 34.
    Java 9 Changes ●JEP 277 - Enhanced Deprecation @Deprecated(since="1.8", forRemoval=true) ● jdeprscan ○ Produces a report of deprecations
  • 35.
    Java 9 Changes ●JEP 229 - Keystore Defaults to PKCS12 ● PKCS12 ○ Standard format, more secure, more extensible ○ Already supported in JDK 8 ● JDK 9 ○ keytool by default creates PKCS12 keystores ○ Autodetects JKS and PKCS12 keystores
  • 36.
    Java 9 NewFeatures ● JEP 219 - Datagram Transport Layer Security (DTLS) ● JEP 244 - TLS Application-Layer Protocol Negotiation Extension (ALPN) ● JEP 246 - Leverage CPU Instructions for GHASH and RSA ● JEP 249 - OCSP Stapling for TLS ● JEP 273 - DRBG-Based SecureRandom Implementations ● JEP 287 - SHA-3 Hash Algorithms ● JEP 288 - Disable SHA-1 Certificates
  • 37.
    Java 10 ● Parallelfull GC for G1 ● In Java 9, if G1 must perform a full GC it’s single threaded ○ Very slow ● In Java 10, it has been parallelized [5.423s] GC(59) Pause Full 4028M->3286M(4096M) 513.026ms [5.423s] GC(59) User=2.80s Sys=0.04s Real=0.52s
  • 38.
    Java 10 ● ExperimentalGraal JIT ○ https://www.graalvm.org/ ● -XX:+UnlockExperimentalVMOptions -XX:+UseJVMCICompiler ● Not yet recommended in production
  • 39.
    Java 10 ● Applicationclass-data sharing ○ https://blog.codefx.org/java/application-class-data-sharing/ ● -Xshare:dump ○ Dumps JDK classes ○ Faster startup times $ java -XX:+UseAppCDS -Xshare:dump -XX:SharedClassListFile=classes.lst -XX:SharedArchiveFile=app-cds.jsa --class-path app.jar
  • 40.
    Java 10 ● Thread-LocalHandshakes ● Improves JVM performance ○ Reduces Time-To-SafePoint (TTSP) ● No need to have a global SafePoint to get stack traces ○ Great benefit to profilers for stack sampling
  • 41.
    Java 10 ● Dockerawareness (Linux only) ○ https://blog.docker.com/2018/04/improved-docker-container-integration-with-java-10/ ○ It is on by default ● -XX:-UseContainerSupport ● -XX:ActiveProcessorCount=n ● -XX:MinRAMPercentage=p ● -XX:InitialRAMPercentage=p ● -XX:MaxRAMPercentage=p
  • 42.
    Java 10 ● Plannedremovals for JDK 11 ● java.corba (CORBA) ● java.xml.bind (JAXB) ● java.xml.ws (SOAP) ● java.xml.ws.annotation (@PostConstruct, @PreDestroy, ...)
  • 43.
    Java 10 ● Localvariable type inference (a.k.a. var) ○ http://openjdk.java.net/projects/amber/LVTIstyle.html var list = new ArrayList<String>(); // infers ArrayList<String> var stream = list.stream(); // infers Stream<String> ● var is not a keyword, it is a reserved type name ○ It’s a valid identifier, unless used in places where the compiler expects a type name int var = 13;
  • 44.
    Java 10 ● varcomes with some controversy var message = "warning, too many features"; // Good ● Consider: List<String> list = new ArrayList<>(); list.trimToSize(); // Does not compile var list = new ArrayList<String>(); list.trimToSize(); // Compiles
  • 45.
    Java 10 ● Morecontroversy: var result = processor.run(); // What type ? var list = new <ctrl+space> // IDE cannot help you
  • 46.
    Java 9/10 Migration ●Migrating to Java 9/10 is an iterative process ○ Typically cannot be done in one step only ● Update dependencies ○ Build tools ○ Libraries ● Run jdeps -jdkinternals ● Fix usages of encapsulated APIs ● Using EE modules ? ● Add --add-modules to command line
  • 47.
    Java 9/10 Migration ●Update command line options ● Fix GC logging ● Fix your System.getProperty("java.version") usages ● Do not do deep reflection on JDK classes ○ Do not use setAccessible(true); ● Verify your ClassLoader usages ● Verify your sun.* usages
  • 48.
    Java 9/10 Migration ●Java 9 upgrade may introduce different behaviors at runtime ● Java code may throw exceptions when running in Java 9 ○ Parsing of "java.version" ○ Playing with ClassLoaders and resources ○ URLStreamHandlers ○ Use of internal APIs ○ Etc. ● You can only discover these incompatibilities by extensive testing ○ Requires time to do, so start immediately !
  • 49.