Going AOT: Everything you need to know about GraalVM for Java applications
alinayurenko
185 views
34 slides
Jun 20, 2024
Slide 1 of 34
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
About This Presentation
Going AOT: Everything you need to know about GraalVM for Java applications
Size: 12.31 MB
Language: en
Added: Jun 20, 2024
Slides: 34 pages
Slide Content
Going AOT: Everything you need to know about GraalVM for Java applications Alina Yurenko Oracle Platinum Sponsors
Going AOT: Everything You Need To Know About GraalVM for Java Applications Alina Yurenko
Alina Yurenko / @alina_yurenko Developer Advocate for GraalVM at Oracle Love open source and communities 🤝 Love both programming 👩 💻 & natural languages 🗣 🐱🐶 About me @alina_yurenko
GRAALVM
An advanced JDK with ahead-of-time Native Image compilation
2017 Year 2018 2019 2020 2021 2022 2023 2005 2011 ... ... Sun Labs’ Maxine Java JVM initial release December Native Image open sourced April Twitter uses Graal JIT for core microservices October Micronaut 1.0 with Native Image support April GraalVM 1.0 released April Thomas Wuerthinger joins Oracle and starts Graal compiler project March Spring Native goes beta November Quarkus 1.0 with Native Image support May GraalVM goes GA (19.0 release) September MicroDoc announces GraalVM for embedded July Alibaba deploys Native Image in production July Facebook deploys GraalVM in production May AWS SDK support for Native Image November Spring Boot 3 with Native Image support December OpenJDK Galahad project proposed July Google Cloud Platform SDK support for Native Image June GraalVM Free Terms and Conditions license September GraalOS & Layered Native Image announced March Azure SDK support for Native Image September Oracle Cloud runs services on GraalVM Graal History 🎉 🎉 🎉 @alina_yurenko
GraalVM Native Image AOT Compilation Ahead-of-Time Compilation Application Libraries JDK Substrate VM Points-to Analysis Run Initializations Heap Snapshotting Input: All classes from application, libraries, and VM Code in Text Section Image Heap in Data Section Image Heap Writing Output: Native executable @alina_yurenko shift work to build time 🏗️ closed-world assumption 🔮
DEMO 🚀
GraalVM Native Image—Fast Start Up and Much More Improved Security Fast Start & Scale Lower Resource Usage Compact Packaging Predictable Performance Supported Azure AWS GCP OCI @alina_yurenko
NATIVE IMAGE, LIBRARIES, AND FRAMEWORKS
GraalVM Native Image AOT Compilation Ahead-of-Time Compilation Application Libraries JDK Substrate VM Points-to Analysis Run Initializations Heap Snapshotting Input: All classes from application, libraries, and VM Code in Text Section Image Heap in Data Section Image Heap Writing Output: Native executable @alina_yurenko shift work to build time 🏗️ closed-world assumption 🔮
NATIVE IMAGE BUILD-TIME DISCOVERY AND CONFIGURATION SPRING BOOT RUN-TIME DISCOVERY AND CONFIGURATION
SPRING BOOT NATIVE IMAGE SPRING AOT
SPRING AOT
SPRING AOT JAVA SOURCE FILES BYTECODE HINT FILES
MORE DEMOS:)
Libraries, dynamic Java features, and Native Image Libraries might be Native-Image friendly out of the box twitter.com/YunaMorgenstern/status/1729039787351536084 Libraries might include config for Native Image: github.com/h2database/h2database/blob/master/h2/src/main/META-INF/native-image/ Libraries might contain config in the Reachability Metadata Repository github.com/oracle/graalvm-reachability-metadata/tree/master/metadata/io.netty You can use framework support to produce custom “hints” for Native Image runtimeHints.resources().registerPattern(“config/app.properties”); You can use the Tracing Agent to produce the necessary config automatically graalvm.org/latest/reference-manual/native-image/metadata/AutomaticMetadataCollection/ You can provide/extend config for reflection, JNI, resources, serialization, and predefined classes manually in JSON: graalvm.org/latest/reference-manual/native-image/metadata/#specifying-metadata-with-json Happy path; most of the cases Custom code/ libraries @alina_yurenko
Ready for GraalVM Native Image graalvm.org/native-image/libraries-and-frameworks @alina_yurenko
GraalVM Native Image & JUnit @EnabledInNativeImage used to signal that the annotated test class or test method is only enabled when executing within GraalVM native images when applied at the class level, all test methods within that class will be enabled within a native image @DisabledInNativeImage used to signal that the annotated test class or test method is only disabled when executing within a GraalVM native image.
PERFORMANCE
AOT at the speed of JIT 🚀 Profile-guided optimizations Collect and use profiles at build time to optimize for the specific runtime behaviour of your application ML-enabled PGO Use a ML model to automatically predict the profile of the application G1 GC Optimize GC for peak throughput `-march=native` Optimize for the specific hardware features of the machine you’ll be running on @alina_yurenko
Spring PetClinic: Peak throughput @alina_yurenko
Spring PetClinic: Memory Efficiency @alina_yurenko
Cross-Platform Builds on GitHub Actions Windows Executable macOS Executable Linux Executable .class .jar .class .jar GraalVM GitHub Action 🏗️ @alina_yurenko
Reduced attack surface area due to dead code removal—unused classes, methods, and fields not included in executable Improved Security Not vulnerable to JIT compiler attacks all code is AOT compiled SBOM supporting industry standards Embedded in executables CycloneDX format Not vulnerable to deserialization attacks via class loading—executable includes only required and specified classes Reduced Attack Surface 🛡️ @alina_yurenko
Migrate 🚀 Add Native Build Tools Alternatively, use recent versions of frameworks Evaluate libraries: graalvm.org/native-image/libraries-and-frameworks Build and deploy 👷♀️ Build and test on GraalVM as the JVM, build with Native Image closer to the deployment Quick build mode with `-Ob` Use CI/CD systems (e.g. GitHub actions) for deployment and cross-platform builds Run faster 🚀 PGO ML-enabled PGO G1 GC `-march=native` Recommendations @alina_yurenko
WHAT’S NEXT?
Java 22 features The fastest GraalVM yet :) Developer experience improvements Learn more: medium.com/graalvm GraalVM for JDK 22 🚀 @alina_yurenko