Disclaimer Most of the information shown in this presentation is based on multiple talks in JavaOne 2015 and Devoxx BE 2015. This presentation is focused on features that are under active development, and as such, a lot can change before the final release.
JDK 9 Flexibility and scalability Security and maintainability improvements Easing the construction, maintainability, deployment and upgrade of large scale applications Enabling performance improvements Coming to you, March 2017 (postponed on Tuesday)
Incompatible JDK 9 Changes ● Encapsulate most internal APIs (JEP 260) ● Remove the JRE ● Changing the binary structure of the JDK ● Removed endorsed standards override and extension mechanisms ● Removed bootclasspath ● New version-string format ● No more ‘_’ variables!
Most used JDK-internal APIs ● sun.misc.BASE64Encoder ● sun.misc.BASE64Decoder ● sun.misc.Unsafe ● sun.reflect.* ● com.sun.image.* ● sun.security.* ● sun.net.* ● Non-critical ○ Only used internally ○ Used for convenience ● Critical ○ Difficult to implement outside the JDK
JEP 260 ● Encapsulate non-critical APIs ● Encapsulate critical internal APIs with replacements in 8 ● Do not encapsulate critical APIs ○ Deprecate in 9 ○ Plan to remove in 10 ● sun.misc.Unsafe ● sun.misc.Signal ● sun.misc.SignalHandler ● sun.misc.Cleaner ● sun.reflect.Reflection:: getCallerClass ● sun.reflect.ReflectionFactory
What can I do to prepare? Remove usages of JDK-internal APIs Check for code that relies on the JDK version number format Check for usages of underscore as an identifier Test your code with the early access builds
Why Jigsaw ? ● JAR/Classpath Hell ○ unfulfilled dependencies will only be discovered at runtime. NoClassDefFoundError ● Weak Encapsulation Across Packages ○ Across package boundaries there is only one visibility: public ○ class loader folds all loaded packages into one big ball of mud ■ “jar file is a filesystem on a stick” - Mark Reinhold (lead Jigsaw Oracle developer)
Why Jigsaw ? ● Rigid Java Runtime ○ Java8 introduced compact profiles but are still cluttered ○ large runtime image footprint (not ready for IoT and server containers) ● Startup Performance ○ class loading executes a linear scan of all JARs on the class path
Jigsaw - What gives ? The jdk9 itself built using modules ● Reliable Configuration ○ module/classes dependency graph available at any time (even runtime) ● Strong Encapsulation ○ A class that is private to a module should be private in exactly the same way that a private field is private to a class. In other words, module boundaries should determine not just the visibility of classes and interfaces but also their accessibility.
Jigsaw - What gives ? ● Improved Security And Maintainability ○ strong encapsulation of module internal API ○ critical code is now effectively hidden ○ maintenance easier as a module’s public API can more easily be kept small. ● Improved Performance ○ optimization techniques can be more effective when it is known that a class can refer only to classes in a few other specific components rather than to any class loaded at run time ● Scalable Platform ○ cherry pick the functionality needed and create their own JDK ○ important for small devices as well as for containers
Jigsaw - What is a Module ? org.fenixedu.foo.alpha.Alpha org.fenixedu.foo.alpha.AlphaFactory org.fenixedu.foo.alpha.AlphaService org.fenixedu.foo.beta.Beta org.fenixedu.foo.beta.BetaFactory org.fenixedu.foo.beta.BetaService org.fenixedu.foo.internal.GreekUtil fenixedu-foo.jar
Automatic Modules “Real” modules Module name based on JAR file name (with some dark wizardry) Simply move the non-modular JARs from the classpath to the modulepath Exports all packages Requires all modules on the modulepath
Bottom Up Migration $ java -mp mlib -cp lib/foo.jar:lib/bar.jar -addmods jackson.databind org. fenixedu.bar.gamma.Gamma Exception in thread "main" java.lang.reflect. InaccessibleObjectException: Unable to make member of class org.fenixedu.bar.gamma.Gamma accessible: module jackson.databind does not read
Unnamed Module All non-modular JARs in the classpath are added to the ‘Unnamed Module’ Reads all other modules in the application Exports all its packages Real modules are not allowed to explicitly depend on the unnamed module Read-node may be added in runtime via reflection
Unnamed Module package java.lang.reflect; public final class Module { public String getName(); public boolean canRead(Module source); public Module addReads(Module source); ... }
Go forth and modularize! Download the Jigsaw Early-Access build http://openjdk.java.net/projects/jigsaw/ea Try out this presentation code https://github.com/sergiofbsilva/jigsaw