JDK 9: Migrating Applications
-
Upload
simon-ritter -
Category
Software
-
view
612 -
download
2
Transcript of JDK 9: Migrating Applications
![Page 1: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/1.jpg)
© Copyright Azul Systems 2017
© Copyright Azul Systems 2015
@speakjava
Migrating ApplicationsTo JDK 9
Simon Ritter
Deputy CTO, Azul Systems
1
![Page 2: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/2.jpg)
© Copyright Azul Systems 2017
JDK 9: Big And Small Changes
2
![Page 3: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/3.jpg)
© Copyright Azul Systems 2017
Migration Guidance From Oracle
3
"Clean applications that just depend on java.se
should just work"
![Page 4: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/4.jpg)
© 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!
![Page 5: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/5.jpg)
© Copyright Azul Systems 2017
Module System
![Page 6: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/6.jpg)
© 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
![Page 7: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/7.jpg)
© 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
![Page 8: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/8.jpg)
© 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
![Page 9: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/9.jpg)
© 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
![Page 10: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/10.jpg)
© Copyright Azul Systems 2017
Breaking Encapsulation
Using the JAR file manifest
10
Add-Exports: java.base/sun.security.provider
![Page 11: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/11.jpg)
© Copyright Azul Systems 2017
Finding Encapsulated API Use
jdeps
– Analyses dependencies on APIs
Example: Minecraft
11
jdeps --list-deps 1.8.jarjava.basejava.datatransferjava.desktopjava.managementjava.namingnot foundunnamed module: 1.8.jar
![Page 12: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/12.jpg)
© 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
![Page 13: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/13.jpg)
© 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
![Page 14: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/14.jpg)
© Copyright Azul Systems 2017
Small Incompatibilities
![Page 15: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/15.jpg)
© 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
![Page 16: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/16.jpg)
© Copyright Azul Systems 2017
Unexpected Exception
Thread.stop(Throwable) now throws an exception
– UnsupportedOperationException
The no-arg method, Thread.stop(), does not
16
![Page 17: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/17.jpg)
© 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
![Page 18: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/18.jpg)
© Copyright Azul Systems 2017
Deleted Deprecated Class
com.sun.security.auth.callback.DialogCallbackHandler
Part of the Java Authentication and Authorisation Service
– JAAS
– Deprecated in JDK 7
18
![Page 19: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/19.jpg)
© 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
![Page 20: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/20.jpg)
© 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
![Page 21: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/21.jpg)
© 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
![Page 22: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/22.jpg)
© 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.
![Page 23: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/23.jpg)
© Copyright Azul Systems 2017
Removed GC Options (JEP 214)
Deprecated in JDK 8 (JEP 173)
23
DefNew + CMS : -XX:-UseParNewGC -XX:+UseConcMarkSweepGCParNew + SerialOld : -XX:+UseParNewGCParNew + iCMS : -XincgcParNew + iCMS : -XX:+CMSIncrementalMode -XX:+UseConcMarkSweepGCDefNew + iCMS : -XX:+CMSIncrementalMode -XX:+UseConcMarkSweepGC
-XX:-UseParNewGCCMS foreground : -XX:+UseCMSCompactAtFullCollectionCMS foreground : -XX:+CMSFullGCsBeforeCompactionCMS foreground : -XX:+UseCMSCollectionPassing
![Page 24: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/24.jpg)
© 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
![Page 25: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/25.jpg)
© 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
![Page 26: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/26.jpg)
© Copyright Azul Systems 2017
Deprecated JVM Flags
26
![Page 27: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/27.jpg)
© 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.
![Page 28: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/28.jpg)
© 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
![Page 29: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/29.jpg)
© 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
![Page 30: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/30.jpg)
© 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.
![Page 31: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/31.jpg)
© Copyright Azul Systems 2017
Real World Example
![Page 32: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/32.jpg)
© 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
![Page 33: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/33.jpg)
© 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
![Page 34: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/34.jpg)
© 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, NoSuchMethodExceptiondecodeMethod = null;encodeMethod = null;
}
![Page 35: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/35.jpg)
© 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;
}}
![Page 36: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/36.jpg)
© Copyright Azul Systems 2017
Conclusions
![Page 37: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/37.jpg)
© 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
![Page 38: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/38.jpg)
© 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
![Page 39: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/39.jpg)
© 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
![Page 40: JDK 9: Migrating Applications](https://reader033.fdocuments.in/reader033/viewer/2022042605/5a6eaa0b7f8b9a70728b5c6d/html5/thumbnails/40.jpg)
© Copyright Azul Systems 2017
© Copyright Azul Systems 2015
@speakjava
Thank You!
Simon Ritter
Deputy CTO, Azul Systems
40