SlideShare a Scribd company logo
© Copyright Azul Systems 2017
© Copyright Azul Systems 2015
@speakjava
Migrating Applications
To JDK 9
Simon Ritter
Deputy CTO, Azul Systems
1
© Copyright Azul Systems 2017
JDK 9: Big And Small Changes
2
© Copyright Azul Systems 2017
Migration Guidance From Oracle
3
"Clean applications that just depend on java.se
should just work"
© Copyright Azul Systems 2017
Quick Poll
 What are your plans for moving to JDK 9
1. Mission accomplished, already using it
2. Actively working on moving applications
3. Thinking about it
4. We're waiting for the next LTS release, JDK 18.9
5. We're still using JDK 6!
© Copyright Azul Systems 2017
Module System
© Copyright Azul Systems 2017
Java Platform Module System
 The core Java libraries are now a set of modules
– 97 modules for JDK, 28 of which are Java SE
– No more rt.jar or tools.jar files
 Most internal APIs are now encapsulated
– sun.misc.Unsafe, etc.
– Numerous libraries and frameworks use internal APIs
 Module path used to locate modules
– Separate and distinct from classpath
6
© Copyright Azul Systems 2017
JPMS And Applications
 Initially, leave everything on the classpath
 Anything on the classpath is in the unnamed module
– All packages are exported
– The unnamed module depends on all modules
 Migrate to modules as required
– Try automatic modules
– Move existing jar files from classpath to modulepath
7
© Copyright Azul Systems 2017
Breaking Encapsulation
 "The Big Kill Switch" to turn off encapsulation
– --illegal-access
 permit: Warning for first use of an encapsulated API
 warn: Warning for every use of an encapsulated API
 debug: Warning and stack trace for every use
 deny: No access to encapsulated APIs
8
© Copyright Azul Systems 2017
Breaking Encapsulation
 Allowing direct access to encapsulated APIs
– --add-exports
 Allowing reflective access to encapsulated APIs
– --add-opens
9
--add-exports java.management/com.sun.jmx.remote.internal=mytest
--add-exports java.management/sun.management=ALL-UNNAMED
--add-opens java.base/java.util=ALL-UNNAMED
© Copyright Azul Systems 2017
Breaking Encapsulation
 Using the JAR file manifest
10
Add-Exports: java.base/sun.security.provider
© Copyright Azul Systems 2017
Finding Encapsulated API Use
 jdeps
– Analyses dependencies on APIs
 Example: Minecraft
11
jdeps --list-deps 1.8.jar
java.base
java.datatransfer
java.desktop
java.management
java.naming
not found
unnamed module: 1.8.jar
© Copyright Azul Systems 2017
"Missing" Modules
 Remember, "Clean applications that only use java.se..."
 The java.se.ee module not included by default
– Compilation and runtime
 Affected modules
– java.corba
– java.transaction
– java.activation
– java.xml.bind
– java.xml.ws
– java.xml.ws.annotation
12
© Copyright Azul Systems 2017
Using "Missing" Modules
 Use the command line option
– --add-modules java.corba
 All modules (except CORBA) have standalone versions
– Maven central
– Relevant JSR RI
 Deploy standalone version on the upgrade module path
– --upgrade-module-path <path>
 Deploy standalone version on the classpath
13
© Copyright Azul Systems 2017
Small Incompatibilities
© Copyright Azul Systems 2017
Milling Project Coin (JEP 213)
 A single underscore is now a keyword in Java
 Fear not, two or more underscores can still be used
15
error: as of release 9, '_' is a keyword, and may not be used as
an identifier
© Copyright Azul Systems 2017
Unexpected Exception
 Thread.stop(Throwable) now throws an exception
– UnsupportedOperationException
 The no-arg method, Thread.stop(), does not
16
© Copyright Azul Systems 2017
Deleted Deprecated Methods
 Classes
– java.util.jar.Pack200
– java.util.jar.Unpack200
– java.util.logging.LogManager
 Methods
– addPropertyChangeListener()
– removePropertyChangeListener()
 Removal required for clean modularisation
17
© Copyright Azul Systems 2017
Deleted Deprecated Class
 com.sun.security.auth.callback.DialogCallbackHandle
r
 Part of the Java Authentication and Authorisation Service
– JAAS
– Deprecated in JDK 7
18
© Copyright Azul Systems 2017
Finding Deprecated API Use
 jdeprscan
– New tool in JDK 9
– Statically analyses class files and jar files against Java
SE APIs
– Looks for and reports usage of deprecated Java SE APIs
19
© Copyright Azul Systems 2017
JDK/JRE File Structure (JEP 220)
20
bin
Pre-JDK 9 JDK 9
lib
tools.jar
jre
bin
rt.jar
lib
libconfbin
jre directory
tools.jar
rt.jar
jmods
© Copyright Azul Systems 2017
New Version String Format (JEP 223)
 Old
– Limited update release/Critical patch update (CPU)
– Download: Java SE 8u131, java -version: jdk1.8.0_131
– Which has more patches, JDK 7u55 or JDK 7u60?
 New
– JDK $MAJOR.$MINOR.$SECURITY
– Easy to understand by humans and apps
– Semantic versioning
21
© Copyright Azul Systems 2017
Non-Programmatic Issues
 Java Network Launch Protocol (JNLP) [JSR 52]
– Now uses strict parsing of configuration files
– Some files that did parse may now fail
 Extension mechanism/Endorsed Standards Override
mechanisms removed
– Directories removed
 $JAVA_HOME/lib/ext
 $JAVA_HOME/lib/endorsed
22
<JAVA_HOME>/lib/ext exists, extensions mechanism no longer
supported; Use -classpath instead.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
© Copyright Azul Systems 2017
Removed GC Options (JEP 214)
 Deprecated in JDK 8 (JEP 173)
23
DefNew + CMS : -XX:-UseParNewGC -XX:+UseConcMarkSweepGC
ParNew + SerialOld : -XX:+UseParNewGC
ParNew + iCMS : -Xincgc
ParNew + iCMS : -XX:+CMSIncrementalMode -XX:+UseConcMarkSweepGC
DefNew + iCMS : -XX:+CMSIncrementalMode -XX:+UseConcMarkSweepGC
-XX:-UseParNewGC
CMS foreground : -XX:+UseCMSCompactAtFullCollection
CMS foreground : -XX:+CMSFullGCsBeforeCompaction
CMS foreground : -XX:+UseCMSCollectionPassing
© Copyright Azul Systems 2017
JVM Logging
 Unified JVM logging (JEP 158)
– Common logging system for all components of JVM
 Unified GC logging (JEP 271)
– Re-implement GC logging using unified JVM logging
– Many command line options changed
24
© Copyright Azul Systems 2017
Removed JVM Flags: Ignored
25
 AdaptiveSizePausePolicy
 CodeCacheMinimumFreeSpace
 DefaultThreadPriority
 JNIDetachReleasesMonitors
 LazyBootClassLoader
 NmethodSweepCheckInterval
 NmethodSweepFraction
 PrintOopAddress
 ReflectionWrapResolutionErrors
 StarvationMonitorInterval
 ThreadSafetyMargin
 UseAltSigs
 UseBoundThreads
 UseCompilerSafepoints
 UseFastAccessorMethods
 UseFastEmptyMethods
 BackEdgeThreshold
 PreInflateSpin
Java HotSpot(TM) 64-Bit Server VM warning: Ignoring option
<Option>; support was removed in 9.0
© Copyright Azul Systems 2017
Deprecated JVM Flags
26
© Copyright Azul Systems 2017
Deprecated JVM Flags
 Two forms of warning message
27
warning[gc] -XX:+PrintGC is deprecated. Will use -Xlog:gc instead.
Java HotSpot(TM) 64-Bit Server VM warning: Option
CreateMinidumpOnCrash was deprecated in version 9.0 and will likely
be removed in a future release. Use option CreateCoredumpOnCrash
instead.
© Copyright Azul Systems 2017
JVM Flags: Non-Starters (1)
28
 AdjustConcurrency
 CMSCompactWhenClearAllSoftRefs
 CMSDumpAtPromotionFailure
 CMSFullGCsBeforeCompaction
 CMSIncrementalDutyCycle
 CMSIncrementalDutyCycleMin
 CMSIncrementalMode
 CMSIncrementalOffset
 CMSIncrementalPacing
 CMSParPromoteBlocksToClaim
 CMSPrintEdenSurvivorChunks
 CollectGen0First
 GCLogFileSize
 NumberOfGCLogFiles
 ParallelGCVerbose
 PrintAdaptiveSizePolicy
 PrintCMSInitiationStatistics
 PrintCMSStatistics
 PrintClassHistogramAfterFullGC
 PrintClassHistogramBeforeFullGC
 PrintFLSCensus
 PrintFLSStatistics
 PrintGCApplicationConcurrentTime
 PrintGCApplicationStoppedTime
 PrintGCCause
 PrintGCDateStamps
© Copyright Azul Systems 2017
JVM Flags: Non-Starters (2)
29
 PrintGCTaskTimeStamps
 PrintGCTimeStamps
 PrintHeapAtGC
 PrintHeapAtGCExtended
 PrintJNIGCStalls
 PrintOldPLAB
 PrintPLAB
 PrintParallelOldGCPhaseTimes
 PrintPromotionFailure
 PrintReferenceGC
 PrintTLAB
 PrintTenuringDistribution
 TraceDynamicGCThreads
 TraceGen0Time
 TraceGen1Time
 TraceMetadataHumongousAllocation
 TraceParallelOldGCTasks
 UseCMSCollectionPassing
 UseCMSCompactAtFullCollection
 UseGCLogFileRotation
 UseMemSetInBOT
 UsePPCLWSYNC
 UseVMInterruptibleIO
 WorkAroundNPTLTimedWaitHang
© Copyright Azul Systems 2017
JVM Flags: Non-Starters
 50 command line flags from JDK 8
 Use will cause the JVM to abort at start
– It won't run your application
30
Unrecognized VM option '<Option>'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
© Copyright Azul Systems 2017
Real World Example
© Copyright Azul Systems 2017
HdrHistogram Library
 Open source library (created by Gil Tene, Azul CTO)
 Ideally this should work with JDK 6, 7, 8 and 9 code
– Unchanged and with no special command line flags
 Problem:
– Needs to encode and decode using Base64
 Solutions:
– sun.misc.BASE64Encoder/Decoder (JDK 6, 7, 8)
– javax.xml.bind.DatatypeConverter (JDK 6, 7, 8)
– java.util.Base64.{Encoder,Decoder} (JDK 8, 9)
32
© Copyright Azul Systems 2017
Solution
 Helper class with same named methods as from xml.bind
– printBase64Binary(byte[] array)
– parseBase64Binary(String input)
 Static code to determine which class is available
– Initialise Method object reference
 Helper methods invoke through method reference to
available implementation
33
© Copyright Azul Systems 2017
Solution (1)
 Code in static block
try {
Class<?> javaUtilClass = Class.forName("java.util.Base64");
Method getDecoderMethod = javaUtilClass.getMethod("getDecoder");
decoderObj = getDecoderMethod.invoke(null);
decodeMethod = decoderObj.getClass().getMethod("decode", String.class);
Method getEncoderMethod = javaUtilClass.getMethod("getEncoder");
encoderObj = getEncoderMethod.invoke(null);
encodeMethod = encoderObj.getClass()
.getMethod("encodeToString", byte[].class);
} catch (Throwable e) { // ClassNotFoundException, NoSuchMethodException
decodeMethod = null;
encodeMethod = null;
}
© Copyright Azul Systems 2017
Solution (2)
35
if (encodeMethod == null) {
decoderObj = null;
encoderObj = null;
try {
Class<?> xmlBindClass = Class.forName("javax.xml.bind.DatatypeConverter");
decodeMethod = xmlBindClass.getMethod("parseBase64Binary", String.class);
encodeMethod = xmlBindClass.getMethod("printBase64Binary", byte[].class);
} catch (Throwable e) {
decodeMethod = null;
encodeMethod = null;
}
}
© Copyright Azul Systems 2017
Conclusions
© Copyright Azul Systems 2017
Migrating To JDK 9
 Simple applications will run [almost] unchanged
– Leave everything on the classpath
– May need to change JVM flags
 Encapsulation
– Additional JVM flags
– Identify and rectify issues
 Smaller changes may cause issues
– Removed APIs
– JVM flag changes
37
© Copyright Azul Systems 2017
Useful Links
 docs.oracle.com/javase/9/migrate
 www.azul.com/jdk-9-pitfalls-for-the-unwary
 www.azul.com/jdk-9-xxtra-command-line-options
38
© Copyright Azul Systems 2017
Zulu Java
 Azul’s binary distribution of OpenJDK
– Passes all TCK tests
– Multi-platform (Windows, Linux, Mac)
– FREE!
 Happy to sell you support, including older versions
 JDK 6, 7, 8 and 9
39
www.zulu.org/download
© Copyright Azul Systems 2017
© Copyright Azul Systems 2015
@speakjava
Thank You!
Simon Ritter
Deputy CTO, Azul Systems
40

More Related Content

PPTX
JDK 9: The Start of a New Future for Java
PPTX
JDK 9: Mission Accomplished. What Next For Java?
PPTX
JDK 9: 55 New Features
PPTX
Building a Brain with Raspberry Pi and Zulu Embedded JVM
PPTX
JDK 9 and JDK 10 Deep Dive
PPTX
What's New in Java 9
PPTX
Is An Agile Standard Possible For Java?
PPTX
55 New Features in JDK 9
JDK 9: The Start of a New Future for Java
JDK 9: Mission Accomplished. What Next For Java?
JDK 9: 55 New Features
Building a Brain with Raspberry Pi and Zulu Embedded JVM
JDK 9 and JDK 10 Deep Dive
What's New in Java 9
Is An Agile Standard Possible For Java?
55 New Features in JDK 9

What's hot (20)

PPTX
JDK 9 Deep Dive
PPTX
Java Support: What's changing
PPTX
JDK 9, 10, 11 and Beyond
PPTX
JDK 9, 10, 11 and Beyond
PPTX
JDK 9: Big Changes To Make Java Smaller
PPTX
Modularization With Project Jigsaw in JDK 9
PDF
Oracle Keynote from JMagghreb 2014
PPTX
Real World Java 9 - JetBrains Webinar
PPTX
Java 9 Modularity and Project Jigsaw
PPSX
Java 9 and the impact on Maven Projects (JavaOne 2016)
PDF
Java: Create The Future Keynote
PDF
Pitfalls of migrating projects to JDK 9
PDF
Preparing your code for Java 9
PDF
Java 9 preview
PDF
Intro To OSGi
PDF
Java 2012 conference keynote - Java Strategy & Roadmap - WebLogic & GlassFish...
PDF
Java EE, What's Next? by Anil Gaur
PDF
Apache Karaf - Building OSGi applications on Apache Karaf - T Frank & A Grzesik
PDF
Java EE 7 for WebLogic 12c Developers
PDF
Java 9 and Project Jigsaw
JDK 9 Deep Dive
Java Support: What's changing
JDK 9, 10, 11 and Beyond
JDK 9, 10, 11 and Beyond
JDK 9: Big Changes To Make Java Smaller
Modularization With Project Jigsaw in JDK 9
Oracle Keynote from JMagghreb 2014
Real World Java 9 - JetBrains Webinar
Java 9 Modularity and Project Jigsaw
Java 9 and the impact on Maven Projects (JavaOne 2016)
Java: Create The Future Keynote
Pitfalls of migrating projects to JDK 9
Preparing your code for Java 9
Java 9 preview
Intro To OSGi
Java 2012 conference keynote - Java Strategy & Roadmap - WebLogic & GlassFish...
Java EE, What's Next? by Anil Gaur
Apache Karaf - Building OSGi applications on Apache Karaf - T Frank & A Grzesik
Java EE 7 for WebLogic 12c Developers
Java 9 and Project Jigsaw
Ad

Similar to JDK 9: Migrating Applications (20)

PPTX
55 New Features in JDK 9
PPTX
Is Java Still Free?
PPTX
Moving Towards JDK 12
PPTX
How to Choose a JDK
PDF
Voxxed Days Thessaloniki 2016 - JDK 9 : Big Changes To Make Java Smaller
PDF
Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Sm...
PDF
Haj 4344-java se 9 and the application server-1
PPTX
Keeping Up with Java: Look at All These New Features!
PPTX
JDK 9: Big Changes To Make Java Smaller
PDF
A Journey through the JDKs (Java 9 to Java 11)
PDF
Project Jigsaw in JDK 9: Modularity Comes To Java
PPTX
Project Jigsaw in JDK9
PDF
JavaOne 2016: Life after Modularity
PPTX
Prepare for JDK 9
PDF
What to expect from Java 9
PDF
Java 40 versions_sgp
PDF
JDK 9 Java Platform Module System
PDF
Java 9-10 What's New
PDF
What's New in the JVM in Java 8?
PDF
What's New in the JVM in Java 8?
55 New Features in JDK 9
Is Java Still Free?
Moving Towards JDK 12
How to Choose a JDK
Voxxed Days Thessaloniki 2016 - JDK 9 : Big Changes To Make Java Smaller
Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Sm...
Haj 4344-java se 9 and the application server-1
Keeping Up with Java: Look at All These New Features!
JDK 9: Big Changes To Make Java Smaller
A Journey through the JDKs (Java 9 to Java 11)
Project Jigsaw in JDK 9: Modularity Comes To Java
Project Jigsaw in JDK9
JavaOne 2016: Life after Modularity
Prepare for JDK 9
What to expect from Java 9
Java 40 versions_sgp
JDK 9 Java Platform Module System
Java 9-10 What's New
What's New in the JVM in Java 8?
What's New in the JVM in Java 8?
Ad

More from Simon Ritter (18)

PPTX
Java Pattern Puzzles Java Pattern Puzzles
PPTX
Keeping Your Java Hot by Solving the JVM Warmup Problem
PPTX
Cloud Native Compiler
PPTX
Java On CRaC
PPTX
The Art of Java Type Patterns
PPTX
Modern Java Workshop
PPTX
Java performance monitoring
PPTX
Modern Java Workshop
PPTX
Getting the Most From Modern Java
PPTX
Building a Better JVM
PPTX
JDK 14 Lots of New Features
PPTX
Java after 8
PPTX
Java Programming
PPTX
The Latest in Enterprise JavaBeans Technology
PPTX
Developing Enterprise Applications Using Java Technology
PPTX
Java Is Still Free
PPTX
It's Java, Jim, but not as we know it
PPTX
Whats New For Developers In JDK 9
Java Pattern Puzzles Java Pattern Puzzles
Keeping Your Java Hot by Solving the JVM Warmup Problem
Cloud Native Compiler
Java On CRaC
The Art of Java Type Patterns
Modern Java Workshop
Java performance monitoring
Modern Java Workshop
Getting the Most From Modern Java
Building a Better JVM
JDK 14 Lots of New Features
Java after 8
Java Programming
The Latest in Enterprise JavaBeans Technology
Developing Enterprise Applications Using Java Technology
Java Is Still Free
It's Java, Jim, but not as we know it
Whats New For Developers In JDK 9

Recently uploaded (20)

PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
AI in Product Development-omnex systems
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
Transform Your Business with a Software ERP System
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
ai tools demonstartion for schools and inter college
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
System and Network Administraation Chapter 3
PPTX
Essential Infomation Tech presentation.pptx
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
Operating system designcfffgfgggggggvggggggggg
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Design an Analysis of Algorithms I-SECS-1021-03
Upgrade and Innovation Strategies for SAP ERP Customers
AI in Product Development-omnex systems
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Internet Downloader Manager (IDM) Crack 6.42 Build 41
How to Migrate SBCGlobal Email to Yahoo Easily
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Transform Your Business with a Software ERP System
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Understanding Forklifts - TECH EHS Solution
ai tools demonstartion for schools and inter college
2025 Textile ERP Trends: SAP, Odoo & Oracle
System and Network Administraation Chapter 3
Essential Infomation Tech presentation.pptx
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
wealthsignaloriginal-com-DS-text-... (1).pdf
How to Choose the Right IT Partner for Your Business in Malaysia

JDK 9: Migrating Applications

  • 1. © Copyright Azul Systems 2017 © Copyright Azul Systems 2015 @speakjava Migrating Applications To JDK 9 Simon Ritter Deputy CTO, Azul Systems 1
  • 2. © Copyright Azul Systems 2017 JDK 9: Big And Small Changes 2
  • 3. © Copyright Azul Systems 2017 Migration Guidance From Oracle 3 "Clean applications that just depend on java.se should just work"
  • 4. © Copyright Azul Systems 2017 Quick Poll  What are your plans for moving to JDK 9 1. Mission accomplished, already using it 2. Actively working on moving applications 3. Thinking about it 4. We're waiting for the next LTS release, JDK 18.9 5. We're still using JDK 6!
  • 5. © Copyright Azul Systems 2017 Module System
  • 6. © Copyright Azul Systems 2017 Java Platform Module System  The core Java libraries are now a set of modules – 97 modules for JDK, 28 of which are Java SE – No more rt.jar or tools.jar files  Most internal APIs are now encapsulated – sun.misc.Unsafe, etc. – Numerous libraries and frameworks use internal APIs  Module path used to locate modules – Separate and distinct from classpath 6
  • 7. © Copyright Azul Systems 2017 JPMS And Applications  Initially, leave everything on the classpath  Anything on the classpath is in the unnamed module – All packages are exported – The unnamed module depends on all modules  Migrate to modules as required – Try automatic modules – Move existing jar files from classpath to modulepath 7
  • 8. © Copyright Azul Systems 2017 Breaking Encapsulation  "The Big Kill Switch" to turn off encapsulation – --illegal-access  permit: Warning for first use of an encapsulated API  warn: Warning for every use of an encapsulated API  debug: Warning and stack trace for every use  deny: No access to encapsulated APIs 8
  • 9. © Copyright Azul Systems 2017 Breaking Encapsulation  Allowing direct access to encapsulated APIs – --add-exports  Allowing reflective access to encapsulated APIs – --add-opens 9 --add-exports java.management/com.sun.jmx.remote.internal=mytest --add-exports java.management/sun.management=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED
  • 10. © Copyright Azul Systems 2017 Breaking Encapsulation  Using the JAR file manifest 10 Add-Exports: java.base/sun.security.provider
  • 11. © Copyright Azul Systems 2017 Finding Encapsulated API Use  jdeps – Analyses dependencies on APIs  Example: Minecraft 11 jdeps --list-deps 1.8.jar java.base java.datatransfer java.desktop java.management java.naming not found unnamed module: 1.8.jar
  • 12. © Copyright Azul Systems 2017 "Missing" Modules  Remember, "Clean applications that only use java.se..."  The java.se.ee module not included by default – Compilation and runtime  Affected modules – java.corba – java.transaction – java.activation – java.xml.bind – java.xml.ws – java.xml.ws.annotation 12
  • 13. © Copyright Azul Systems 2017 Using "Missing" Modules  Use the command line option – --add-modules java.corba  All modules (except CORBA) have standalone versions – Maven central – Relevant JSR RI  Deploy standalone version on the upgrade module path – --upgrade-module-path <path>  Deploy standalone version on the classpath 13
  • 14. © Copyright Azul Systems 2017 Small Incompatibilities
  • 15. © Copyright Azul Systems 2017 Milling Project Coin (JEP 213)  A single underscore is now a keyword in Java  Fear not, two or more underscores can still be used 15 error: as of release 9, '_' is a keyword, and may not be used as an identifier
  • 16. © Copyright Azul Systems 2017 Unexpected Exception  Thread.stop(Throwable) now throws an exception – UnsupportedOperationException  The no-arg method, Thread.stop(), does not 16
  • 17. © Copyright Azul Systems 2017 Deleted Deprecated Methods  Classes – java.util.jar.Pack200 – java.util.jar.Unpack200 – java.util.logging.LogManager  Methods – addPropertyChangeListener() – removePropertyChangeListener()  Removal required for clean modularisation 17
  • 18. © Copyright Azul Systems 2017 Deleted Deprecated Class  com.sun.security.auth.callback.DialogCallbackHandle r  Part of the Java Authentication and Authorisation Service – JAAS – Deprecated in JDK 7 18
  • 19. © Copyright Azul Systems 2017 Finding Deprecated API Use  jdeprscan – New tool in JDK 9 – Statically analyses class files and jar files against Java SE APIs – Looks for and reports usage of deprecated Java SE APIs 19
  • 20. © Copyright Azul Systems 2017 JDK/JRE File Structure (JEP 220) 20 bin Pre-JDK 9 JDK 9 lib tools.jar jre bin rt.jar lib libconfbin jre directory tools.jar rt.jar jmods
  • 21. © Copyright Azul Systems 2017 New Version String Format (JEP 223)  Old – Limited update release/Critical patch update (CPU) – Download: Java SE 8u131, java -version: jdk1.8.0_131 – Which has more patches, JDK 7u55 or JDK 7u60?  New – JDK $MAJOR.$MINOR.$SECURITY – Easy to understand by humans and apps – Semantic versioning 21
  • 22. © Copyright Azul Systems 2017 Non-Programmatic Issues  Java Network Launch Protocol (JNLP) [JSR 52] – Now uses strict parsing of configuration files – Some files that did parse may now fail  Extension mechanism/Endorsed Standards Override mechanisms removed – Directories removed  $JAVA_HOME/lib/ext  $JAVA_HOME/lib/endorsed 22 <JAVA_HOME>/lib/ext exists, extensions mechanism no longer supported; Use -classpath instead. Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit.
  • 23. © Copyright Azul Systems 2017 Removed GC Options (JEP 214)  Deprecated in JDK 8 (JEP 173) 23 DefNew + CMS : -XX:-UseParNewGC -XX:+UseConcMarkSweepGC ParNew + SerialOld : -XX:+UseParNewGC ParNew + iCMS : -Xincgc ParNew + iCMS : -XX:+CMSIncrementalMode -XX:+UseConcMarkSweepGC DefNew + iCMS : -XX:+CMSIncrementalMode -XX:+UseConcMarkSweepGC -XX:-UseParNewGC CMS foreground : -XX:+UseCMSCompactAtFullCollection CMS foreground : -XX:+CMSFullGCsBeforeCompaction CMS foreground : -XX:+UseCMSCollectionPassing
  • 24. © Copyright Azul Systems 2017 JVM Logging  Unified JVM logging (JEP 158) – Common logging system for all components of JVM  Unified GC logging (JEP 271) – Re-implement GC logging using unified JVM logging – Many command line options changed 24
  • 25. © Copyright Azul Systems 2017 Removed JVM Flags: Ignored 25  AdaptiveSizePausePolicy  CodeCacheMinimumFreeSpace  DefaultThreadPriority  JNIDetachReleasesMonitors  LazyBootClassLoader  NmethodSweepCheckInterval  NmethodSweepFraction  PrintOopAddress  ReflectionWrapResolutionErrors  StarvationMonitorInterval  ThreadSafetyMargin  UseAltSigs  UseBoundThreads  UseCompilerSafepoints  UseFastAccessorMethods  UseFastEmptyMethods  BackEdgeThreshold  PreInflateSpin Java HotSpot(TM) 64-Bit Server VM warning: Ignoring option <Option>; support was removed in 9.0
  • 26. © Copyright Azul Systems 2017 Deprecated JVM Flags 26
  • 27. © Copyright Azul Systems 2017 Deprecated JVM Flags  Two forms of warning message 27 warning[gc] -XX:+PrintGC is deprecated. Will use -Xlog:gc instead. Java HotSpot(TM) 64-Bit Server VM warning: Option CreateMinidumpOnCrash was deprecated in version 9.0 and will likely be removed in a future release. Use option CreateCoredumpOnCrash instead.
  • 28. © Copyright Azul Systems 2017 JVM Flags: Non-Starters (1) 28  AdjustConcurrency  CMSCompactWhenClearAllSoftRefs  CMSDumpAtPromotionFailure  CMSFullGCsBeforeCompaction  CMSIncrementalDutyCycle  CMSIncrementalDutyCycleMin  CMSIncrementalMode  CMSIncrementalOffset  CMSIncrementalPacing  CMSParPromoteBlocksToClaim  CMSPrintEdenSurvivorChunks  CollectGen0First  GCLogFileSize  NumberOfGCLogFiles  ParallelGCVerbose  PrintAdaptiveSizePolicy  PrintCMSInitiationStatistics  PrintCMSStatistics  PrintClassHistogramAfterFullGC  PrintClassHistogramBeforeFullGC  PrintFLSCensus  PrintFLSStatistics  PrintGCApplicationConcurrentTime  PrintGCApplicationStoppedTime  PrintGCCause  PrintGCDateStamps
  • 29. © Copyright Azul Systems 2017 JVM Flags: Non-Starters (2) 29  PrintGCTaskTimeStamps  PrintGCTimeStamps  PrintHeapAtGC  PrintHeapAtGCExtended  PrintJNIGCStalls  PrintOldPLAB  PrintPLAB  PrintParallelOldGCPhaseTimes  PrintPromotionFailure  PrintReferenceGC  PrintTLAB  PrintTenuringDistribution  TraceDynamicGCThreads  TraceGen0Time  TraceGen1Time  TraceMetadataHumongousAllocation  TraceParallelOldGCTasks  UseCMSCollectionPassing  UseCMSCompactAtFullCollection  UseGCLogFileRotation  UseMemSetInBOT  UsePPCLWSYNC  UseVMInterruptibleIO  WorkAroundNPTLTimedWaitHang
  • 30. © Copyright Azul Systems 2017 JVM Flags: Non-Starters  50 command line flags from JDK 8  Use will cause the JVM to abort at start – It won't run your application 30 Unrecognized VM option '<Option>' Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit.
  • 31. © Copyright Azul Systems 2017 Real World Example
  • 32. © Copyright Azul Systems 2017 HdrHistogram Library  Open source library (created by Gil Tene, Azul CTO)  Ideally this should work with JDK 6, 7, 8 and 9 code – Unchanged and with no special command line flags  Problem: – Needs to encode and decode using Base64  Solutions: – sun.misc.BASE64Encoder/Decoder (JDK 6, 7, 8) – javax.xml.bind.DatatypeConverter (JDK 6, 7, 8) – java.util.Base64.{Encoder,Decoder} (JDK 8, 9) 32
  • 33. © Copyright Azul Systems 2017 Solution  Helper class with same named methods as from xml.bind – printBase64Binary(byte[] array) – parseBase64Binary(String input)  Static code to determine which class is available – Initialise Method object reference  Helper methods invoke through method reference to available implementation 33
  • 34. © Copyright Azul Systems 2017 Solution (1)  Code in static block try { Class<?> javaUtilClass = Class.forName("java.util.Base64"); Method getDecoderMethod = javaUtilClass.getMethod("getDecoder"); decoderObj = getDecoderMethod.invoke(null); decodeMethod = decoderObj.getClass().getMethod("decode", String.class); Method getEncoderMethod = javaUtilClass.getMethod("getEncoder"); encoderObj = getEncoderMethod.invoke(null); encodeMethod = encoderObj.getClass() .getMethod("encodeToString", byte[].class); } catch (Throwable e) { // ClassNotFoundException, NoSuchMethodException decodeMethod = null; encodeMethod = null; }
  • 35. © Copyright Azul Systems 2017 Solution (2) 35 if (encodeMethod == null) { decoderObj = null; encoderObj = null; try { Class<?> xmlBindClass = Class.forName("javax.xml.bind.DatatypeConverter"); decodeMethod = xmlBindClass.getMethod("parseBase64Binary", String.class); encodeMethod = xmlBindClass.getMethod("printBase64Binary", byte[].class); } catch (Throwable e) { decodeMethod = null; encodeMethod = null; } }
  • 36. © Copyright Azul Systems 2017 Conclusions
  • 37. © Copyright Azul Systems 2017 Migrating To JDK 9  Simple applications will run [almost] unchanged – Leave everything on the classpath – May need to change JVM flags  Encapsulation – Additional JVM flags – Identify and rectify issues  Smaller changes may cause issues – Removed APIs – JVM flag changes 37
  • 38. © Copyright Azul Systems 2017 Useful Links  docs.oracle.com/javase/9/migrate  www.azul.com/jdk-9-pitfalls-for-the-unwary  www.azul.com/jdk-9-xxtra-command-line-options 38
  • 39. © Copyright Azul Systems 2017 Zulu Java  Azul’s binary distribution of OpenJDK – Passes all TCK tests – Multi-platform (Windows, Linux, Mac) – FREE!  Happy to sell you support, including older versions  JDK 6, 7, 8 and 9 39 www.zulu.org/download
  • 40. © Copyright Azul Systems 2017 © Copyright Azul Systems 2015 @speakjava Thank You! Simon Ritter Deputy CTO, Azul Systems 40

Editor's Notes

  • #25: Segmented code cache to improve performance and allow future developments (Sumatra and the use of GPUs)