voxxed days thessaloniki 2016 - keynote - jdk 9 : big changes to make java smaller

53
© Copyright Azul Systems 2016 © Copyright Azul Systems 2015 @speakjava JDK 9: Big Changes To Make Java Smaller Simon Ritter Deputy CTO, Azul Systems 1

Upload: voxxed-days-thessaloniki

Post on 16-Apr-2017

46 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

© Copyright Azul Systems 2015

@speakjava

JDK 9: Big Changes To Make Java Smaller

Simon RitterDeputy CTO, Azul Systems

1

Page 2: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

API Structural Changes

Page 3: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

API Classification

Supported, intended for public use– JCP specified: java.*, javax.*– JDK specific: some com.sun.*, some jdk.*

Unsupported, not intended for public use– Mostly sun.*– Most infamous is sun.misc.Unsafe

3

Page 4: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

General Java Compatability Policy

If an application uses only supported APIs on version N of Java it should work on version N+1, even without recompilation

Supported APIs can be removed–But only with advanced notice

JDK 8 has 18 interfaces, 23 classes, 64 fields, 358 methods and 20 constructors that have been deprecated

–None have been removed–Until now

4

Page 5: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

JDK 9: Incompatible Changes

Encapsulate most JDK internal APIs Remove a small number of supported APIs

– 6 in total, all add/remove PropertyChangeListener– Already flagged in JSR 337 (Java SE 8), JEP 162

Change the binary structure of the JRE and JDK New version string format A single underscore will no longer be allowed as an

identifier in source code

5

Page 6: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Removed In JDK 9

Endorsed standard API override mechanism Extension mechanism

No longer required now we have a module system

6

Page 7: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Most Popular Unsupported APIs

1. sun.misc.BASE64Encoder

2. sun.misc.Unsafe

3. sun.misc.BASE64Decoder

7

Oracle dataset based on internal application code

Page 8: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

JDK Internal API Classification

Non-critical– Little or no use outside the JDK– Used only for convenience (alternatives exist)

Critical– Functionality that would be difficult, if not impossible to

implement outside the JDK

8

Page 9: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

JEP 260 Proposal

Encapsulate all non-critical JDK-internal APIs Encapsulate all critical JDK-internal APIs, for which

supported replacements exist in JDK 8 Do not encapsulate other critical JDK-internal APIs

– Deprecate these in JDK 9– Plan to encapsulate or remove them in JDK 10– Provide command-line option to access encapsulated

critical APIs

9

Page 10: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Reviewing Your Own Code

jdeps tool– Introduced in JDK 8, improved in JDK 9– Maven jdeps plugin

jdeps –jdkinternals path/myapp.jar

10

path/myapp.jar -> /opt/jdk1.8.0/jre/lib/rt.jar <unnamed> (myapp.jar) -> sun.misc.Unsafe -> ...

Page 11: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Project Jigsaw And Modules

Page 12: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Goals For Project Jigsaw

Make Java SE more scalable and flexible– Internet of Things– Microservices

Improve security, maintainability and performance

Simplify construction, deployment and maintenance of large scale applications

Eliminate classpath hell

12

Page 13: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Module Fundamentals

Module is a grouping of code– For Java this is a collection of packages

Modules can contain other things– Native code– Resources– Configuration data

13

com.azul.zoop

com.azul.zoop.alpha.Namecom.azul.zoop.alpha.Positioncom.azul.zoop.beta.Animalcom.azul.zoop.beta.Zoo

Page 14: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Module Declaration

14

module com.azul.zoop {}

module-info.javacom/azul/zoop/alpha/Name.javacom/azul/zoop/alpha/Position.javacom/azul/zoop/beta/Animal.javacom/azul/zoop/beta/Zoo.java

Page 15: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Module Dependencies

module com.azul.zoop { requires com.azul.zeta;} com.azul.zoop

com.azul.zeta

Page 16: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Module Dependencies

module com.azul.app { requires com.azul.zoop; requires java.sql;}

com.azul.app

com.azul.zoop java.sql

Page 17: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Module Dependency Graph

com.azul.app

java.base

java.sqlcom.azul.zoop

com.azul.zetajava.xml java.logging

explicitimplicit

Page 18: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Readability v. Dependency

com.azul.app

java.sql

java.logging

module java.sql { requires public java.logging;}

Driver d = …Logger l = d.getParentLogger();l.log(“azul’);

Implied readability

Page 19: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Module Implied Readability Graph

com.azul.app

java.base

java.sqlcom.azul.zoop

com.azul.zetajava.xml java.logging

explicitimplicitimplied

Page 20: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Package Visibility

module com.azul.zoop { requires com.azul.zeta; exports com.azul.zoop.alpha; exports com.azul.zoop.beta to com.azul.app;}

com.azul.zoop

com.azul.zoop.alpha

com.azul.zoop.betacom.azul.zoop.thetacom.azul.app only

Page 21: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

More Package Visibility

weak module com.azul.zoop { requires com.azul.zeta;}

com.azul.zoop

com.azul.zoop.alphacom.azul.zoop.beta com.azul.zoop.theta

Page 22: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Even More Package Visibilitymodule com.azul.zoop { requires com.azul.zeta; exports com.azul.zoop.alpha; exports com.azul.zoop.beta to com.azul.app; exports private com.azul.theta;}

com.azul.zoop

com.azul.zoop.thetaREFLECTIONGENERAL

com.azul.zoop.alpha

com.azul.zoop.betacom.azul.app only

Page 23: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Accessibility

For a package to be visible– The package must be exported by the containing module– The containing module must be read by the using module

Public types from those packages can then be used

com.azul.zoopcom.azul.app

reads

Page 24: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Java Accessibility (pre-JDK 9)

publicprotected<package>private

Page 25: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Java Accessibility (JDK 9)

public to everyonepublic, but only to specific modulespublic only within a module protected<package>private

public ≠ accessible (fundamental change to Java)

Page 26: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

JDK 8 Dependencies

Page 27: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

JDK 9 Platform Modules

27

java.se

java.compact3

java.compact2

java.compact1

java.scripting

java.instrument

java.base

java.logging

java.sql

java.sql.rowset

java.xml

java.desktop

java.rmi

java.prefsjava.datatransfer

java.compiler

java.management

java.security.jgss

java.naming

java.security.sasl

All modules depend on java.base

no impliedreadability=

Page 28: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

JDK 9 Platform Modules

28

java.se.ee java.se

java.xml.bind

java.corba

java.compiler

java.desktop

java.annotations.common

java.rmi

java.datatransfer

java.management

java.xml.ws

java.naming

java.transaction

java.activation

All modules depend on java.base

Page 29: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Using Modules

Page 30: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Module Path

$ javac –modulepath dir1:dir2:dir3

Page 31: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Compilation With Module Path

31

$ javac –modulepath mods –d mods \ src/module-info.java \ src/com/azul/zoop/alpha/Name.java

mods/module-info.classmods/com/azul/zoop/alpha/Name.class

src/module-info.javasrc/com/azul/zoop/alpha/Name.java

Page 32: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Application Execution

-modulepath can be abbreviated to -mp

$ java –mp mods –m com.azul.app/com.azul.app.Main

Azul application initialised!

module name main class

Page 33: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Packaging With Modular JAR Files

mods/module-info.classmods/com/azul/app/Main.class

$ jar --create --file mylib/app.jar \ --main-class com.azul.app.Main \ -C mods .

module-info.classcom/azul/app/Main.class

app.jar

Page 34: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

JAR Files & Module Information

$ jar --file mylib/app.jar –pName: com.azul.zoopRequires: com.azul.zeta java.base [MANDATED] java.sqlMain class: com.azul.zoop.Main

Page 35: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Application Execution (JAR)

$ java –mp mylib:mods –m com.azul.app

Azul application initialised!

Page 36: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

LinkingModular run-time

image

…confbin

jlink

$ jlink --modulepath $JDKMODS \ --addmods java.base –output myimage

$ myimage/bin/java –[email protected]

Page 37: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Linking An Application

$ jlink --modulepath $JDKMODS:$MYMODS \ --addmods com.azul.app –output myimage

$ myimage/bin/java –[email protected]@[email protected]@[email protected]@[email protected]

Version numbering forinformation purposes only“It is not a goal of the module system to solve the version-

selection problem”

Page 38: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Application Migration

Page 39: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Typical Application (JDK 8)

jarjar

jar

JDK

jar

jarjarjar jar

jarjar

jar

jar

Cla

sspa

th

Page 40: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Typical Application (JDK 9)

jarjar

jar

modulejava.base

modulejava.desktop

modulejava.datatransfer

modulejava.xml

jar

jarjarjar jar

jarjar

jar

jar

Unnamed module

Page 41: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Sample Application

myapp.jar

libgl.jar

mylib.jar

gluegen.jar jogl.jar

modulejava.base

modulejava.desktop

modulejava.datatransfer

modulejava.xml

Page 42: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Run Application With Classpath

$ java –classpath \ lib/myapp.jar: \ lib/mylib.jar: \ lib/libgl.jar: \ lib/gluegen.jar: \ lib/jogl.jar: \ myapp.Main

Page 43: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Sample Application

modulemyapp.ja

r

libgl.jar

modulemylib.jar

gluegen.jar jogl.jar

modulejava.base

modulejava.desktop

modulejava.datatransfer

modulejava.xml

Page 44: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Application module-info.java

module myapp { requires mylib; requires java.base; requires java.sql; requires libgl; ???? requires gluegen; ???? requires jogl; ????}

Page 45: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Sample Application

modulemyapp.ja

r

modulelibgl.jar

modulemylib.jar

modulegluegen.jar

modulejogl.jar

modulejava.base

modulejava.desktop

modulejava.datatransfer

modulejava.xml

Page 46: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Automatic Modules

Real modules Simply place unmodified jar file on module path

– Rather than classpath No changes to JAR file Module name derived from JAR file name Exports all its packages

– No selectivity Automatically requires all modules on the module path

46

Page 47: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Application Module Dependencies

modulemyapp.ja

r

modulelibgl.jar

modulemylib.jar

modulegluegen.jar

modulejogl.jar

modulejava.base

modulejava.desktop

modulejava.datatransfer

modulejava.xml

ImplicitExplicit

Page 48: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Run Application With Modules

$ java –classpath \ lib/myapp.jar: \ lib/mylib.jar: \ lib/libgl.jar: \ lib/gluegen.jar: \ lib/jogl.jar: \ myapp.Main

$ java –mp mylib:lib –m myapp

Page 49: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Summary

Page 50: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Summary

Modularisation is a big change for Java– JVM/JRE rather than language/APIs

Potentially disruptive changes to exposure of non-public APIs– Is it safe?

Developing modular code will require some learning– Not a huge change, though

50

Page 51: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Zulu.org

Azul binary distribution of OpenJDK source code Passed all TCK tests Completely FREE!

– Pay us if you’d like enterprise level support Just announced: Embedded Zulu support for ARM 32-bit

– Intel already supported– “Requires no licensing fee”

51

Page 52: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

Further Information

openjdk.java.net openjdk.java.net/jeps openjdk.java.net/projects/jigsaw jcp.org

52

Page 53: Voxxed Days Thessaloniki 2016 - Keynote - JDK 9 : Big Changes To Make Java Smaller

© Copyright Azul Systems 2016

© Copyright Azul Systems 2015

@speakjava

Thank You!

Simon RitterDeputy CTO, Azul Systems

53