Download - JDK-9: Modules and Java Linker
![Page 1: JDK-9: Modules and Java Linker](https://reader030.vdocuments.site/reader030/viewer/2022020203/58f9aabd1a28abe94a8b4585/html5/thumbnails/1.jpg)
JDK-9 Modules and Java Linker (JLink)
G. Bhanu Prakash
Java Platform Team
Oracle India Private Limited
8/30/2016 1 Copyright 2016, Oracle and/or it's affiliates. All rights reserved
![Page 2: JDK-9: Modules and Java Linker](https://reader030.vdocuments.site/reader030/viewer/2022020203/58f9aabd1a28abe94a8b4585/html5/thumbnails/2.jpg)
Agenda 1. Modules
2. Module Dependencies
3. Jlink and Packaging
4. Jlink Plugins
5. Example Plugins 1. System Module Descriptor Plugin
2. Compress Plugin
3. Release-Info Plugin
8/30/2016 2 Copyright 2016, Oracle and/or it's affiliates.
All rights reserved
![Page 3: JDK-9: Modules and Java Linker](https://reader030.vdocuments.site/reader030/viewer/2022020203/58f9aabd1a28abe94a8b4585/html5/thumbnails/3.jpg)
SAFE HARBOR STATEMENT
The following is intended to outline our general product direction. It is intended for information purpose only, and may not be incorporated in any contract. It is not a commitment to deliver any material, code, or
functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or
functionality described for Oracle’s products remains at the sole discretion of Oracle
8/30/2016 Copyright 2016, Oracle and/or it's affiliates.
All rights reserved 3
![Page 4: JDK-9: Modules and Java Linker](https://reader030.vdocuments.site/reader030/viewer/2022020203/58f9aabd1a28abe94a8b4585/html5/thumbnails/4.jpg)
Jigsaw Problems Problems
Platform scalability (small devices)
Jar Hell or Classpath Hell
• Java runtime crashes with NoClassDefFoundError
• Shadowing of classes
Performance
• Startup
• Download
8/30/2016 4 Copyright 2016, Oracle and/or it's affiliates.
All rights reserved
![Page 5: JDK-9: Modules and Java Linker](https://reader030.vdocuments.site/reader030/viewer/2022020203/58f9aabd1a28abe94a8b4585/html5/thumbnails/5.jpg)
Jigsaw Solutions Problems
Platform scalability
• Modularize JDK
Jar Hell or Classpath Hell
• Replace classpath with module dependencies
Performance
• Startup – install optimizations in module library
• Download - incremental modules in demand
8/30/2016 5 Copyright 2016, Oracle and/or it's affiliates.
All rights reserved
![Page 6: JDK-9: Modules and Java Linker](https://reader030.vdocuments.site/reader030/viewer/2022020203/58f9aabd1a28abe94a8b4585/html5/thumbnails/6.jpg)
• What is Module
• Module-Info.java – Visibility Rules
• REQUIRES
• EXPORTS
• REQUIRES PUBLIC
8/30/2016 6 Copyright 2016, Oracle and/or it's affiliates.
All rights reserved
Modules
![Page 7: JDK-9: Modules and Java Linker](https://reader030.vdocuments.site/reader030/viewer/2022020203/58f9aabd1a28abe94a8b4585/html5/thumbnails/7.jpg)
8/30/2016 7 Copyright 2016, Oracle and/or it's affiliates.
All rights reserved
“public” no longer means “accessible”
Modules
![Page 8: JDK-9: Modules and Java Linker](https://reader030.vdocuments.site/reader030/viewer/2022020203/58f9aabd1a28abe94a8b4585/html5/thumbnails/8.jpg)
com.foo.app module-info.java module com.foo.app { requires com.foo.bar; requires java.sql; }
8/30/2016 8 Copyright 2016, Oracle and/or it's affiliates.
All rights reserved
Example: com.foo.app
Modules Example
com.foo.bar module com.foo.app { exports com.foo.bar; }
![Page 9: JDK-9: Modules and Java Linker](https://reader030.vdocuments.site/reader030/viewer/2022020203/58f9aabd1a28abe94a8b4585/html5/thumbnails/9.jpg)
Actual Module Dependencies (com.foo.app)
8/30/2016 9 Copyright 2016, Oracle and/or it's affiliates.
All rights reserved
![Page 10: JDK-9: Modules and Java Linker](https://reader030.vdocuments.site/reader030/viewer/2022020203/58f9aabd1a28abe94a8b4585/html5/thumbnails/10.jpg)
8/30/2016 10 Copyright 2016, Oracle and/or it's affiliates.
All rights reserved
Transitive Dependencies (com.foo.app)
![Page 11: JDK-9: Modules and Java Linker](https://reader030.vdocuments.site/reader030/viewer/2022020203/58f9aabd1a28abe94a8b4585/html5/thumbnails/11.jpg)
JDK Platform Modules
8/30/2016 11 Copyright 2016, Oracle and/or it's affiliates.
All rights reserved
![Page 12: JDK-9: Modules and Java Linker](https://reader030.vdocuments.site/reader030/viewer/2022020203/58f9aabd1a28abe94a8b4585/html5/thumbnails/12.jpg)
How to compile modules
Inputs Jmods, Modular jar files
Exploded modules
1. Compile com.foo.bar (base)
javac -d mods\com.foo.bar
src\com.foo.bar\module-info.java
src\com.foo.bar\com\foo\bar\*.java
2. Compile com.foo.app (main application)
javac -modulepath mods
-d mods\com.foo.app
src\com.foo.app\module-info.java
src\com.foo.app\com\foo\app\*.java
Or
javac –modulesourcepath src –d mods …
8/30/2016 12
Copyright 2016, Oracle and/or it's affiliates. All rights reserved
![Page 13: JDK-9: Modules and Java Linker](https://reader030.vdocuments.site/reader030/viewer/2022020203/58f9aabd1a28abe94a8b4585/html5/thumbnails/13.jpg)
Create Modules
Create module com.foo.bar
jmod create
--class-path mods\com.foo.bar
com.foo.bar
Create module com.foo.app jmod create
--class-path mods\com.foo.app
com.foo.app
8/30/2016 13 Copyright 2016, Oracle and/or it's affiliates.
All rights reserved
![Page 14: JDK-9: Modules and Java Linker](https://reader030.vdocuments.site/reader030/viewer/2022020203/58f9aabd1a28abe94a8b4585/html5/thumbnails/14.jpg)
Module Information
• jmod describe com.foo.bar com.foo.bar
requires mandated java.base
exports com.foo.bar
• jmod describe com.foo.app com.foo.app
requires com.foo.bar
requires mandated java.base
requires java.sql
conceals com.foo.app
8/30/2016 14 Copyright 2016, Oracle and/or it's affiliates.
All rights reserved
![Page 15: JDK-9: Modules and Java Linker](https://reader030.vdocuments.site/reader030/viewer/2022020203/58f9aabd1a28abe94a8b4585/html5/thumbnails/15.jpg)
8/30/2016 15 Copyright 2016, Oracle and/or it's affiliates.
All rights reserved
![Page 16: JDK-9: Modules and Java Linker](https://reader030.vdocuments.site/reader030/viewer/2022020203/58f9aabd1a28abe94a8b4585/html5/thumbnails/16.jpg)
Linking
8/30/2016 Copyright 2016, Oracle and/or it's affiliates.
All rights reserved 16
![Page 17: JDK-9: Modules and Java Linker](https://reader030.vdocuments.site/reader030/viewer/2022020203/58f9aabd1a28abe94a8b4585/html5/thumbnails/17.jpg)
Jlink and Packaging (JEP-282)
Brief History Jrecreate was introduced in Java 8 with EJDK (JavaSE Embedded)
Instead of binaries we ship the EJDK
Jlink Usage: Command line tool to link module modules into jimage file
generate runtime images
JEP-282: “Link time is an opportunity to do whole-world optimizations that are otherwise difficult at compile or costly at runtime”
8/30/2016 17
Copyright 2016, Oracle and/or it's affiliates. All rights reserved
![Page 18: JDK-9: Modules and Java Linker](https://reader030.vdocuments.site/reader030/viewer/2022020203/58f9aabd1a28abe94a8b4585/html5/thumbnails/18.jpg)
Jlink Packaging
8/30/2016 18 Copyright 2016, Oracle and/or it's affiliates.
All rights reserved
Legacy JDK image
JDK-9 Generated Image
![Page 19: JDK-9: Modules and Java Linker](https://reader030.vdocuments.site/reader030/viewer/2022020203/58f9aabd1a28abe94a8b4585/html5/thumbnails/19.jpg)
Jlink Packaging
Create image file
jlink --output myimage
--addmods com.foo.app
--modulepath jdk-9b131\jmods;mods
>ls myimage
bin lib conf release
8/30/2016 Copyright 2016, Oracle and/or it's affiliates.
All rights reserved 19
![Page 20: JDK-9: Modules and Java Linker](https://reader030.vdocuments.site/reader030/viewer/2022020203/58f9aabd1a28abe94a8b4585/html5/thumbnails/20.jpg)
App execution from Generated image
>myimage\bin\java -listmods
com.foo.app
com.foo.bar
java.base@9-ea
java.logging@9-ea
java.sql@9-ea
java.xml@9-ea
>java -m com.greetings/com.greetings.Main
Output: Greetings (com.foo.app.Main) : World (from com.foo.bar)
>java -m com.foo.app/com.foo.app.App2
Output: Exception:oracle.jdbc.driver.OracleDriver
8/30/2016 20 Copyright 2016, Oracle and/or it's affiliates.
All rights reserved
-modulepath mods Not required
![Page 21: JDK-9: Modules and Java Linker](https://reader030.vdocuments.site/reader030/viewer/2022020203/58f9aabd1a28abe94a8b4585/html5/thumbnails/21.jpg)
Jlink Plugins
Image customization enabled using a set of predefined plugins
12 builtin plugins. Example: compress-resources
release-info
sort-resources
exclude-files
gen-installed-modules
replace-file
Programmatic access to jlink features
As per the JEP, the plugin API is strictly experimental
8/30/2016 21
Copyright 2016, Oracle and/or it's affiliates. All rights reserved
![Page 22: JDK-9: Modules and Java Linker](https://reader030.vdocuments.site/reader030/viewer/2022020203/58f9aabd1a28abe94a8b4585/html5/thumbnails/22.jpg)
8/30/2016 22 Copyright 2016, Oracle and/or it's affiliates.
All rights reserved
Plugins and Image creation - WorkFlow
![Page 23: JDK-9: Modules and Java Linker](https://reader030.vdocuments.site/reader030/viewer/2022020203/58f9aabd1a28abe94a8b4585/html5/thumbnails/23.jpg)
Optimizing Java startup Problem: Significant time spent parsing and validating
module-info.class for each module in system image itself
Solution: Implement jlink plugin to generate a pre-
validated system module graph
SystemModuleDescriptorPlugin
8/30/2016 23 Copyright 2016, Oracle and/or it's affiliates.
All rights reserved
--installed-modules Startup time
Disabled 510 ms
Enabled 220 ms
![Page 24: JDK-9: Modules and Java Linker](https://reader030.vdocuments.site/reader030/viewer/2022020203/58f9aabd1a28abe94a8b4585/html5/thumbnails/24.jpg)
• Reduces memory use by a sizable amount
• This plugin is ON by default (--installed-modules on)
8/30/2016 Copyright 2016, Oracle and/or it's affiliates.
All rights reserved 24
![Page 25: JDK-9: Modules and Java Linker](https://reader030.vdocuments.site/reader030/viewer/2022020203/58f9aabd1a28abe94a8b4585/html5/thumbnails/25.jpg)
Compress Plugin
LEVEL_0
StringSharingPlugin - Scans image classes constant pool (UTF-8 Strings)
LEVEL_1:
ZipPlugin(resFilter) - Zip compression of image classes
LEVEL_2:
StringSharingPlugin(resFilter)
ZipPlugin(resFilter)
8/30/2016 25 Copyright 2016, Oracle and/or it's affiliates.
All rights reserved
Compression level
Size (~)
None 28.5 MB
LEVEL_0 17.3 MB
LEVEL_1 11.7 MB
LEVEL_2 11.5 MB
Table: Jlink generated image size
![Page 26: JDK-9: Modules and Java Linker](https://reader030.vdocuments.site/reader030/viewer/2022020203/58f9aabd1a28abe94a8b4585/html5/thumbnails/26.jpg)
Release-info Plugin
Normal JDK myimage>cat release
#Wed Aug 24 09:19:38 IST 2016 MODULES=java.sql,com.foo.bar,com.foo.app,java.logging,java.xml,java.base OS_VERSION=5.2 OS_ARCH=amd64 OS_NAME=Windows JAVA_VERSION=9-ea
With Release Plugin: jlink --release-info
add:build_type=fastdebug,source=oraclejdk,java_version=9+101 …
myimage2>cat release #Wed Aug 24 09:32:36 IST 2016 MODULES=java.sql,com.foo.bar,com.foo.app,java.logging,java.xml,java.base OS_VERSION=5.2 OS_ARCH=amd64 OS_NAME=Windows JAVA_VERSION=9-ea
build_type=fastdebug,source\=oraclejdk,java_version\=9+101
8/30/2016 26 Copyright 2016, Oracle and/or it's affiliates.
All rights reserved
![Page 27: JDK-9: Modules and Java Linker](https://reader030.vdocuments.site/reader030/viewer/2022020203/58f9aabd1a28abe94a8b4585/html5/thumbnails/27.jpg)
Summary
• Accessibility is enforced by the compiler, VM, and Core Reflection
• Freedom to adopt modules at your own pace – Modularize the application
– Modularize the libraries
• Some libraries may require more changes to work as modules
8/30/2016 Copyright 2016, Oracle and/or it's affiliates.
All rights reserved 27
![Page 28: JDK-9: Modules and Java Linker](https://reader030.vdocuments.site/reader030/viewer/2022020203/58f9aabd1a28abe94a8b4585/html5/thumbnails/28.jpg)
More Information
OpenJDK Project Jigsaw page
http://openjdk.java.net/project/jigsaw
mailto: [email protected]
Module Usage at Compile Time slides http://openjdk.java.net/projects/jigsaw/doc/ModulesAndJavac.pdf
Javadoc for Java Module java APIs:
http://cr.openjdk.java.net/~mr/jigsaw/api/
Modules in the Java Language and VM http://openjdk.java.net/projects/jigsaw/doc/lang-vm.html
8/30/2016 28 Copyright 2016, Oracle and/or it's affiliates.
All rights reserved
![Page 29: JDK-9: Modules and Java Linker](https://reader030.vdocuments.site/reader030/viewer/2022020203/58f9aabd1a28abe94a8b4585/html5/thumbnails/29.jpg)
Thank You. Questions?
8/30/2016 Copyright 2016, Oracle and/or it's affiliates.
All rights reserved 29