SlideShare ist ein Scribd-Unternehmen logo
1 von 49
Downloaden Sie, um offline zu lesen
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 ?

Weitere ähnliche Inhalte

Was ist angesagt?

JDK9 Features (Summary, 31/Jul/2015) #JJUG
JDK9 Features (Summary, 31/Jul/2015) #JJUGJDK9 Features (Summary, 31/Jul/2015) #JJUG
JDK9 Features (Summary, 31/Jul/2015) #JJUGYuji Kubota
 
Adding replication protocol support for psycopg2
Adding replication protocol support for psycopg2Adding replication protocol support for psycopg2
Adding replication protocol support for psycopg2Alexander Shulgin
 
Find bottleneck and tuning in Java Application
Find bottleneck and tuning in Java ApplicationFind bottleneck and tuning in Java Application
Find bottleneck and tuning in Java Applicationguest1f2740
 
Lessons Learned: Troubleshooting Replication
Lessons Learned: Troubleshooting ReplicationLessons Learned: Troubleshooting Replication
Lessons Learned: Troubleshooting ReplicationSveta Smirnova
 
What’s the Best PostgreSQL High Availability Framework? PAF vs. repmgr vs. Pa...
What’s the Best PostgreSQL High Availability Framework? PAF vs. repmgr vs. Pa...What’s the Best PostgreSQL High Availability Framework? PAF vs. repmgr vs. Pa...
What’s the Best PostgreSQL High Availability Framework? PAF vs. repmgr vs. Pa...ScaleGrid.io
 
配置Golden gate同步ddl语句
配置Golden gate同步ddl语句配置Golden gate同步ddl语句
配置Golden gate同步ddl语句maclean liu
 
자바 성능 강의
자바 성능 강의자바 성능 강의
자바 성능 강의Terry Cho
 
MySQL Replication Troubleshooting for Oracle DBAs
MySQL Replication Troubleshooting for Oracle DBAsMySQL Replication Troubleshooting for Oracle DBAs
MySQL Replication Troubleshooting for Oracle DBAsSveta Smirnova
 
Embedded systems
Embedded systems Embedded systems
Embedded systems Katy Anton
 
What's new in MySQL 5.6
What's new in MySQL 5.6What's new in MySQL 5.6
What's new in MySQL 5.6Shlomi Noach
 
JDK 9 and JDK 10 Deep Dive
JDK 9 and JDK 10 Deep DiveJDK 9 and JDK 10 Deep Dive
JDK 9 and JDK 10 Deep DiveSimon Ritter
 
The Full MySQL and MariaDB Parallel Replication Tutorial
The Full MySQL and MariaDB Parallel Replication TutorialThe Full MySQL and MariaDB Parallel Replication Tutorial
The Full MySQL and MariaDB Parallel Replication TutorialJean-François Gagné
 
Java 8 -12: da Oracle a Eclipse. Due anni e una rivoluzione
Java 8 -12: da Oracle a Eclipse. Due anni e una rivoluzioneJava 8 -12: da Oracle a Eclipse. Due anni e una rivoluzione
Java 8 -12: da Oracle a Eclipse. Due anni e una rivoluzioneThinkOpen
 
Managing and Visualizing your Replication Topologies with Orchestrator
Managing and Visualizing your Replication Topologies with OrchestratorManaging and Visualizing your Replication Topologies with Orchestrator
Managing and Visualizing your Replication Topologies with OrchestratorShlomi Noach
 
MySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitationsMySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitationsJean-François Gagné
 

Was ist angesagt? (20)

JDK9 Features (Summary, 31/Jul/2015) #JJUG
JDK9 Features (Summary, 31/Jul/2015) #JJUGJDK9 Features (Summary, 31/Jul/2015) #JJUG
JDK9 Features (Summary, 31/Jul/2015) #JJUG
 
De Java 8 a Java 11 y 14
De Java 8 a Java 11 y 14De Java 8 a Java 11 y 14
De Java 8 a Java 11 y 14
 
java8-features
java8-featuresjava8-features
java8-features
 
Adding replication protocol support for psycopg2
Adding replication protocol support for psycopg2Adding replication protocol support for psycopg2
Adding replication protocol support for psycopg2
 
Find bottleneck and tuning in Java Application
Find bottleneck and tuning in Java ApplicationFind bottleneck and tuning in Java Application
Find bottleneck and tuning in Java Application
 
Lessons Learned: Troubleshooting Replication
Lessons Learned: Troubleshooting ReplicationLessons Learned: Troubleshooting Replication
Lessons Learned: Troubleshooting Replication
 
De Java 8 ate Java 14
De Java 8 ate Java 14De Java 8 ate Java 14
De Java 8 ate Java 14
 
What’s the Best PostgreSQL High Availability Framework? PAF vs. repmgr vs. Pa...
What’s the Best PostgreSQL High Availability Framework? PAF vs. repmgr vs. Pa...What’s the Best PostgreSQL High Availability Framework? PAF vs. repmgr vs. Pa...
What’s the Best PostgreSQL High Availability Framework? PAF vs. repmgr vs. Pa...
 
配置Golden gate同步ddl语句
配置Golden gate同步ddl语句配置Golden gate同步ddl语句
配置Golden gate同步ddl语句
 
자바 성능 강의
자바 성능 강의자바 성능 강의
자바 성능 강의
 
ClassLoader Leaks
ClassLoader LeaksClassLoader Leaks
ClassLoader Leaks
 
MySQL Replication Troubleshooting for Oracle DBAs
MySQL Replication Troubleshooting for Oracle DBAsMySQL Replication Troubleshooting for Oracle DBAs
MySQL Replication Troubleshooting for Oracle DBAs
 
Embedded systems
Embedded systems Embedded systems
Embedded systems
 
What's new in MySQL 5.6
What's new in MySQL 5.6What's new in MySQL 5.6
What's new in MySQL 5.6
 
Dropwizard
DropwizardDropwizard
Dropwizard
 
JDK 9 and JDK 10 Deep Dive
JDK 9 and JDK 10 Deep DiveJDK 9 and JDK 10 Deep Dive
JDK 9 and JDK 10 Deep Dive
 
The Full MySQL and MariaDB Parallel Replication Tutorial
The Full MySQL and MariaDB Parallel Replication TutorialThe Full MySQL and MariaDB Parallel Replication Tutorial
The Full MySQL and MariaDB Parallel Replication Tutorial
 
Java 8 -12: da Oracle a Eclipse. Due anni e una rivoluzione
Java 8 -12: da Oracle a Eclipse. Due anni e una rivoluzioneJava 8 -12: da Oracle a Eclipse. Due anni e una rivoluzione
Java 8 -12: da Oracle a Eclipse. Due anni e una rivoluzione
 
Managing and Visualizing your Replication Topologies with Orchestrator
Managing and Visualizing your Replication Topologies with OrchestratorManaging and Visualizing your Replication Topologies with Orchestrator
Managing and Visualizing your Replication Topologies with Orchestrator
 
MySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitationsMySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitations
 

Ähnlich wie Java 9-10 What's New

QConSP 2018 - Java Module System
QConSP 2018 - Java Module SystemQConSP 2018 - Java Module System
QConSP 2018 - Java Module SystemLeonardo Zanivan
 
Prepare for JDK 9
Prepare for JDK 9Prepare for JDK 9
Prepare for JDK 9haochenglee
 
Native Java with GraalVM
Native Java with GraalVMNative Java with GraalVM
Native Java with GraalVMSylvain Wallez
 
What to expect from Java 9
What to expect from Java 9What to expect from Java 9
What to expect from Java 9Ivan Krylov
 
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010JUG Lausanne
 
Online Upgrade Using Logical Replication.
Online Upgrade Using Logical Replication.Online Upgrade Using Logical Replication.
Online Upgrade Using Logical Replication.EDB
 
Drools, jBPM OptaPlanner presentation
Drools, jBPM OptaPlanner presentationDrools, jBPM OptaPlanner presentation
Drools, jBPM OptaPlanner presentationMark Proctor
 
OpenCms Days 2016: Next generation content repository
OpenCms Days 2016: Next generation content repository OpenCms Days 2016: Next generation content repository
OpenCms Days 2016: Next generation content repository Alkacon Software GmbH & Co. KG
 
JDK 9, 10, 11 and Beyond
JDK 9, 10, 11 and BeyondJDK 9, 10, 11 and Beyond
JDK 9, 10, 11 and BeyondSimon Ritter
 
Modern Java Workshop
Modern Java WorkshopModern Java Workshop
Modern Java WorkshopSimon Ritter
 
JDD2015: Taste of new in Java 9 - Arkadiusz Sokołowski
JDD2015: Taste of new in Java 9 - Arkadiusz SokołowskiJDD2015: Taste of new in Java 9 - Arkadiusz Sokołowski
JDD2015: Taste of new in Java 9 - Arkadiusz SokołowskiPROIDEA
 
AD111 -- Harnessing the Power of Server-Side JavaScript and Other Advanced XP...
AD111 -- Harnessing the Power of Server-Side JavaScript and Other Advanced XP...AD111 -- Harnessing the Power of Server-Side JavaScript and Other Advanced XP...
AD111 -- Harnessing the Power of Server-Side JavaScript and Other Advanced XP...ddrschiw
 
Jigsaw - Javaforum 2015Q4
Jigsaw - Javaforum 2015Q4Jigsaw - Javaforum 2015Q4
Jigsaw - Javaforum 2015Q4Rikard Thulin
 
Getting started with drupal 8 code
Getting started with drupal 8 codeGetting started with drupal 8 code
Getting started with drupal 8 codeForum One
 
Streaming replication in practice
Streaming replication in practiceStreaming replication in practice
Streaming replication in practiceAlexey Lesovsky
 

Ähnlich wie Java 9-10 What's New (20)

QConSP 2018 - Java Module System
QConSP 2018 - Java Module SystemQConSP 2018 - Java Module System
QConSP 2018 - Java Module System
 
Prepare for JDK 9
Prepare for JDK 9Prepare for JDK 9
Prepare for JDK 9
 
Java 9 and Project Jigsaw
Java 9 and Project JigsawJava 9 and Project Jigsaw
Java 9 and Project Jigsaw
 
PostgreSQL and PL/Java
PostgreSQL and PL/JavaPostgreSQL and PL/Java
PostgreSQL and PL/Java
 
Native Java with GraalVM
Native Java with GraalVMNative Java with GraalVM
Native Java with GraalVM
 
What to expect from Java 9
What to expect from Java 9What to expect from Java 9
What to expect from Java 9
 
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010
 
Online Upgrade Using Logical Replication.
Online Upgrade Using Logical Replication.Online Upgrade Using Logical Replication.
Online Upgrade Using Logical Replication.
 
Grails 101
Grails 101Grails 101
Grails 101
 
Drools, jBPM OptaPlanner presentation
Drools, jBPM OptaPlanner presentationDrools, jBPM OptaPlanner presentation
Drools, jBPM OptaPlanner presentation
 
OpenCms Days 2016: Next generation content repository
OpenCms Days 2016: Next generation content repository OpenCms Days 2016: Next generation content repository
OpenCms Days 2016: Next generation content repository
 
JDK 9, 10, 11 and Beyond
JDK 9, 10, 11 and BeyondJDK 9, 10, 11 and Beyond
JDK 9, 10, 11 and Beyond
 
Modern Java Workshop
Modern Java WorkshopModern Java Workshop
Modern Java Workshop
 
Java 9 sneak peek
Java 9 sneak peekJava 9 sneak peek
Java 9 sneak peek
 
JDD2015: Taste of new in Java 9 - Arkadiusz Sokołowski
JDD2015: Taste of new in Java 9 - Arkadiusz SokołowskiJDD2015: Taste of new in Java 9 - Arkadiusz Sokołowski
JDD2015: Taste of new in Java 9 - Arkadiusz Sokołowski
 
Ad111
Ad111Ad111
Ad111
 
AD111 -- Harnessing the Power of Server-Side JavaScript and Other Advanced XP...
AD111 -- Harnessing the Power of Server-Side JavaScript and Other Advanced XP...AD111 -- Harnessing the Power of Server-Side JavaScript and Other Advanced XP...
AD111 -- Harnessing the Power of Server-Side JavaScript and Other Advanced XP...
 
Jigsaw - Javaforum 2015Q4
Jigsaw - Javaforum 2015Q4Jigsaw - Javaforum 2015Q4
Jigsaw - Javaforum 2015Q4
 
Getting started with drupal 8 code
Getting started with drupal 8 codeGetting started with drupal 8 code
Getting started with drupal 8 code
 
Streaming replication in practice
Streaming replication in practiceStreaming replication in practice
Streaming replication in practice
 

Mehr von Nicola Pedot

AI, ML e l'anello mancante
AI, ML e l'anello mancanteAI, ML e l'anello mancante
AI, ML e l'anello mancanteNicola Pedot
 
Say No To Dependency Hell
Say No To Dependency Hell Say No To Dependency Hell
Say No To Dependency Hell Nicola Pedot
 
Java al servizio della data science - Java developers' meeting
Java al servizio della data science - Java developers' meetingJava al servizio della data science - Java developers' meeting
Java al servizio della data science - Java developers' meetingNicola Pedot
 
BDD & design paradoxes appunti devoxx2012
BDD & design paradoxes   appunti devoxx2012BDD & design paradoxes   appunti devoxx2012
BDD & design paradoxes appunti devoxx2012Nicola Pedot
 
Tom EE appunti devoxx2012
Tom EE   appunti devoxx2012 Tom EE   appunti devoxx2012
Tom EE appunti devoxx2012 Nicola Pedot
 
Presentazione+Android
Presentazione+AndroidPresentazione+Android
Presentazione+AndroidNicola Pedot
 

Mehr von Nicola Pedot (13)

AI, ML e l'anello mancante
AI, ML e l'anello mancanteAI, ML e l'anello mancante
AI, ML e l'anello mancante
 
Ethic clean
Ethic cleanEthic clean
Ethic clean
 
Say No To Dependency Hell
Say No To Dependency Hell Say No To Dependency Hell
Say No To Dependency Hell
 
Java al servizio della data science - Java developers' meeting
Java al servizio della data science - Java developers' meetingJava al servizio della data science - Java developers' meeting
Java al servizio della data science - Java developers' meeting
 
Jakarta EE 2018
Jakarta EE 2018Jakarta EE 2018
Jakarta EE 2018
 
Lazy Java
Lazy JavaLazy Java
Lazy Java
 
JavaEE6 my way
JavaEE6 my wayJavaEE6 my way
JavaEE6 my way
 
Java 8 Overview
Java 8 OverviewJava 8 Overview
Java 8 Overview
 
BDD & design paradoxes appunti devoxx2012
BDD & design paradoxes   appunti devoxx2012BDD & design paradoxes   appunti devoxx2012
BDD & design paradoxes appunti devoxx2012
 
Tom EE appunti devoxx2012
Tom EE   appunti devoxx2012 Tom EE   appunti devoxx2012
Tom EE appunti devoxx2012
 
Eclipse Svn
Eclipse SvnEclipse Svn
Eclipse Svn
 
Eclipse
EclipseEclipse
Eclipse
 
Presentazione+Android
Presentazione+AndroidPresentazione+Android
Presentazione+Android
 

Kürzlich hochgeladen

Communication Accommodation Theory Kaylyn Benton.pptx
Communication Accommodation Theory Kaylyn Benton.pptxCommunication Accommodation Theory Kaylyn Benton.pptx
Communication Accommodation Theory Kaylyn Benton.pptxkb31670
 
ISO 25964-1Working Group ISO/TC 46/SC 9/WG 8
ISO 25964-1Working Group ISO/TC 46/SC 9/WG 8ISO 25964-1Working Group ISO/TC 46/SC 9/WG 8
ISO 25964-1Working Group ISO/TC 46/SC 9/WG 8Access Innovations, Inc.
 
Dynamics of Professional Presentationpdf
Dynamics of Professional PresentationpdfDynamics of Professional Presentationpdf
Dynamics of Professional Presentationpdfravleel42
 
The Real Story Of Project Manager/Scrum Master From Where It Came?!
The Real Story Of Project Manager/Scrum Master From Where It Came?!The Real Story Of Project Manager/Scrum Master From Where It Came?!
The Real Story Of Project Manager/Scrum Master From Where It Came?!Loay Mohamed Ibrahim Aly
 
Juan Pablo Sugiura - eCommerce Day Bolivia 2024
Juan Pablo Sugiura - eCommerce Day Bolivia 2024Juan Pablo Sugiura - eCommerce Day Bolivia 2024
Juan Pablo Sugiura - eCommerce Day Bolivia 2024eCommerce Institute
 
Machine learning workshop, CZU Prague 2024
Machine learning workshop, CZU Prague 2024Machine learning workshop, CZU Prague 2024
Machine learning workshop, CZU Prague 2024Gokulks007
 
Communication Accommodation Theory Kaylyn Benton.pptx
Communication Accommodation Theory Kaylyn Benton.pptxCommunication Accommodation Theory Kaylyn Benton.pptx
Communication Accommodation Theory Kaylyn Benton.pptxkb31670
 
Burning Issue presentation of Zhazgul N. , Cycle 54
Burning Issue presentation of Zhazgul N. , Cycle 54Burning Issue presentation of Zhazgul N. , Cycle 54
Burning Issue presentation of Zhazgul N. , Cycle 54ZhazgulNurdinova
 

Kürzlich hochgeladen (8)

Communication Accommodation Theory Kaylyn Benton.pptx
Communication Accommodation Theory Kaylyn Benton.pptxCommunication Accommodation Theory Kaylyn Benton.pptx
Communication Accommodation Theory Kaylyn Benton.pptx
 
ISO 25964-1Working Group ISO/TC 46/SC 9/WG 8
ISO 25964-1Working Group ISO/TC 46/SC 9/WG 8ISO 25964-1Working Group ISO/TC 46/SC 9/WG 8
ISO 25964-1Working Group ISO/TC 46/SC 9/WG 8
 
Dynamics of Professional Presentationpdf
Dynamics of Professional PresentationpdfDynamics of Professional Presentationpdf
Dynamics of Professional Presentationpdf
 
The Real Story Of Project Manager/Scrum Master From Where It Came?!
The Real Story Of Project Manager/Scrum Master From Where It Came?!The Real Story Of Project Manager/Scrum Master From Where It Came?!
The Real Story Of Project Manager/Scrum Master From Where It Came?!
 
Juan Pablo Sugiura - eCommerce Day Bolivia 2024
Juan Pablo Sugiura - eCommerce Day Bolivia 2024Juan Pablo Sugiura - eCommerce Day Bolivia 2024
Juan Pablo Sugiura - eCommerce Day Bolivia 2024
 
Machine learning workshop, CZU Prague 2024
Machine learning workshop, CZU Prague 2024Machine learning workshop, CZU Prague 2024
Machine learning workshop, CZU Prague 2024
 
Communication Accommodation Theory Kaylyn Benton.pptx
Communication Accommodation Theory Kaylyn Benton.pptxCommunication Accommodation Theory Kaylyn Benton.pptx
Communication Accommodation Theory Kaylyn Benton.pptx
 
Burning Issue presentation of Zhazgul N. , Cycle 54
Burning Issue presentation of Zhazgul N. , Cycle 54Burning Issue presentation of Zhazgul N. , Cycle 54
Burning Issue presentation of Zhazgul N. , Cycle 54
 

Java 9-10 What's New

  • 2. Simone Bordet ● @simonebordet ● sbordet@webtide.com ● Java Champion ● Works @ Webtide ● The company behind Jetty and CometD ● JVM Tuning Expert
  • 3. 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
  • 4. 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.
  • 6. 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
  • 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 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
  • 14. 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
  • 15. 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
  • 16. 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
  • 17. 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>
  • 18. 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
  • 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 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
  • 21. Java 9 New Features ● JEP 213 - Small Language Changes ● Enhanced try-with-resources InputStream input = ...; ... try (input) { ... }
  • 22. 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);
  • 23. 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);
  • 24. 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(...)) ... } }
  • 25. 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()) );
  • 26. 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)
  • 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 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
  • 29. 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
  • 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 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
  • 37. 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
  • 38. Java 10 ● Experimental Graal JIT ○ https://www.graalvm.org/ ● -XX:+UnlockExperimentalVMOptions -XX:+UseJVMCICompiler ● Not yet recommended in production
  • 39. 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
  • 40. 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
  • 41. 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
  • 42. Java 10 ● Planned removals for JDK 11 ● java.corba (CORBA) ● java.xml.bind (JAXB) ● java.xml.ws (SOAP) ● java.xml.ws.annotation (@PostConstruct, @PreDestroy, ...)
  • 43. 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;
  • 44. 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
  • 45. Java 10 ● More controversy: 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 !