It’s always sunny with OpenJ9
Dan Heidinga, Eclipse OpenJ9 Project Lead VM Architect, IBM Runtimes @danheidinga DanHeidinga 2 https://upload.wikimedia.org/wikipedia/commons/9/98/Storm_clouds.jpg cjohnson7 from Rochester, Minnesota / CC BY (https://creativecommons.org/licenses/by/2.0)
My Day Job
http://docs.oracle.com/javase/8/docs/index.html Eclipse OpenJ9 Created Sept 2017
http://www.eclipse.org/openj9 https://github.com/eclipse/openj9
Dual License: Eclipse Public License v2.0 Apache 2.0
Users and contributors very welcome
https://github.com/eclipse/openj9/blob/master/CO NTRIBUTING.md
6 A JVM for the cloud
7 Built with the Class Libraries you know and love
JDK JDK JDK JDK 8 11 14 next
Single source stream at OpenJ9 No (LTS) JDK left behind! 8 Right, the cloud
9 Cloud requirements on Java
▪ Fast startup –Faster scaling for increased demand ▪ Small footprint –Improves density on servers –Improves cost for applications ▪ Quick / immediate rampup –GB/hr is key, if you run for less time you pay less money
10 OpenJ9 helps…
… containers out of the box
11 Automatically detect if running in a container
▪ Based on the container limits: – Tune the GC Heap
– Limit GC & active JIT threads
– Constrain Runtime.availableProcessors() to cgroup quotas
– Out of the box idle tuning
12 Avoid rebuilding containers just to adjust heap size
▪ -XX:InitialRAMPercentage=N – Set initial heap size as a percentage of total memory ▪ -XX:MaxRAMPercentage=N – Set maximum heap size as a percentage of total memory ▪ Running in containers with set memory limits? – OpenJ9 will base the default heap size on that limit:
13 Out of the box idle tuning
▪ When’s the best time to schedule a GC? When your app is idle!
▪ OpenJ9 enables -XX:+IdleTuningGcOnIdle when running in a container – When the VM detects your app is idle for a configurable length of time, it can GC – Both scavenge and global collections can occur based on heuristics
14 OpenJ9 helps…
… startup
15
ShareClasses cache
Classfile J9ROMClass J9Class
17 ShareClasses: ROM pays off JVM 1 JVM 2 JVM 3
18 ShareClasses: ROM pays off JVM 1 JVM 2 JVM 3
19 ShareClasses: ROM pays off JVM 1 JVM 2 JVM 3
Faster startup, Smaller footprint Shared Classes Cache
20 “Dynamic” AOT through ShareClasses
Shared Classes Cache
ROM Classes AOT $ java –Xshareclasses ... 21 ShareClasses and AOT
▪ Distinction between ‘cold’ and ‘warm’ runs ▪ Dynamic AOT compilation –Relocatable format –AOT loads are ~100 times faster than JIT compilations –More generic code → slightly less optimized ▪ Generate AOT code only during start-up ▪ Recompilation helps bridge the gap
22 ShareClasses cache
▪-Xshareclasses –enables the share classes cache ▪Enabled for bootclasspath classes by default –Better developer experience out of the box –Still worth enabling explicitly to get full benefit
▪Disable by default running in a container! –Creating a cache only valuable if it persists
23 24 Docker layers are immutable once created
New Layer (Read-Write) DayTrader Layer Open Liberty (Read-only) Layer (Read-only) OpenJ9 Layer (Read-only) Ubuntu 16.04
25 Example of Docker layers
Read-write SCC OpenJ9 OpenJ9 layer data
Read-only Ubuntu 16.04
26 Example of Docker layers
Load OpenJ9 layer data/add Open Liberty SCC tuned on Layer data Docker CoW
SCC Read-write Open Liberty OpenJ9 layer data Liberty layer data
Read-only SCC OpenJ9 OpenJ9 layer data
Read-only Ubuntu 16.04
27 Example of Docker layers
Read-write SCC DayTrader OpenJ9 layer + Liberty layer + DayTrader layer data
Read-only SCC Open Liberty OpenJ9 layer + Liberty layer data
Read-only SCC OpenJ9 OpenJ9 layer data
Read-only Ubuntu 16.04
28 Example of Docker layers
Read-write SCC DayTrader OpenJ9 layer + Liberty layer + DayTrader layer data
Read-only SCC Open Liberty OpenJ9 layer + Liberty layer data
Read-only SCC OpenJ9 OpenJ9 layer data
Read-only Ubuntu 16.04
29 Multi-layer SCC: Make the cache layer aware
Cannot write to a lower layer Write SCC in top layer
Read-write SCC Open Liberty Liberty layer data
Read-only SCC OpenJ9 OpenJ9 layer data
Read-only Ubuntu 16.04
30 Multi-layer SCC
Cannot write to a lower layer Write SCC in top layer SCC becomes layered
Read-write SCC_L1 Open Liberty Liberty layer data
Read-only SCC_L0 OpenJ9 OpenJ9 layer data
Read-only Ubuntu 16.04
31 Multi-layer SCC since OpenJ9 v0.17.0 in October 2019 for JDK 8/11/13
Read DayTrader SCC_L2 write DayTrader layer data
Read-only Open Liberty SCC_L1 Liberty layer data
Read only OpenJ9 SCC_L0 OpenJ9 layer data
Read-only Ubuntu 16.04
32 Command line options on Multi-layer SCC
▪ -Xshareclasses:createLayer – Create a new shared cache layer
▪ -Xshareclasses:layer=
▪ Some applications launch multiple JVMs simultaneously – If each’s running with –Xshareclasses:createLayer, N new layers created – Use layer=
33 Why does this matter? CI/CD!
Build Build Build “base” Test app with framework application layer multi-layer SCC layer layer
34 Reuses previously cached layers in later builds
JDK Framework Application Test JDK Framework Application Test JDK Framework Application Test
35 -Xverify:none never again!
public class A { public static void main(String[] args) { B b = new B(); acceptC(b); }
public void acceptC(C c) {} }
▪ Use -XX:[+|-]ClassRelationshipVerifier instead for fast and safe startup ▪ Added in OpenJ9 v.0.17.0 in Oct 2019 for JDK 8+
36 OpenJ9…
… Innovates for the cloud!
37 Microservice deployment
Pay for the:
• JIT compiler’s memory footprint per instance
• CPU to compile the same classes over and over
JIT JIT JIT JIT
App App App App
38 What if the JIT was moved out of process?
JIT
App App App App
39 What if the JIT became a JIT Server
JIT JVM JIT JIT Orchestrator Server JVM load balancing, affinity, scaling, reliability JIT Server JIT JVM
JVM client identifies methods to compile, but asks server to do the actual compilation • JIT server asks questions to the client JVM (about classes, environment, etc.) • Sends generated code & meta data back to be installed in client’s code cache 40 Benefits of an independent JIT server
• Move much of JIT induced CPU and memory spikes away from client • Client CPU and memory consumption dictated by application
• JIT server connected to client JVM at runtime, so: • Theoretically no loss in performance using same profile and class hierarchy info • Still adaptable to changing conditions • JVM client still platform neutral
41 Could that work?
42 Could that work?
43 Could that work?
44 What about network latency? Won’t that hurt start up and ramp up?
Will it be practical in the cloud?
45 JIT Server works well on Amazon AWS!
46 * JITaaS == JIT Server JIT Server Current Status
• Code is fully open source at Eclipse Open J9 • Has now been merged into our master branch • Now available in AdoptOpenJDK January 2020 update releases for JDK8 and 11 on Linux x86-64 platform
• Simple options lend well to all kinds of Java workload deployments • Server: jitserver –XX:JITServerPort=
• We are seeking feedback on how well it works in real user environments!
• Try it now: • E.g. https://adoptopenjdk.net/releases.html?variant=openjdk8&jvmVariant=openj9 • E.g. Docker pull adoptopenjdk:8-jdk-openj9 (on Linux x86-64 platform) 47 We are really just at the beginning…
• Primary focus has been on mechanics to move JIT compilation to a server
• Once compilation work is redirected to server :
• Do that work more efficiently across a cluster of JVMS (think microservices)
• Classify and categorize JVM clients using machine learning
• Optimize groups of microservices together
• … 48 https://adoptopenjdk.net
Select “OpenJ9” Button!!
49
Thank You !
51 Let us know what you thought of today’s session.
Take a moment to complete the following survey:
http://ibm.biz/WUG-survey http://ibm.biz/usergroupday More Developer webinars coming up … • May 21st Java and Containers - Make it Awesome • May 28th Containing your development – Why Cloud IDEs are the future
Enroll: http://ibm.biz/WUG-dev-series
Join and follow the community to stay informed: http://ibm.biz/WUG-community