SlideShare a Scribd company logo
Alina Yurenko
Developer Advocate for GraalVM
Oracle Labs
Cape Town Java Community
Everything you need to know about
GraalVM Native Image
Photo by Andrea Brataas on Unsplash
• Alina Yurenko / @alina_yurenko
• Developer Advocate for GraalVM at
Oracle Labs
• Love open source and communities 🤝
• Love both programming 👩💻 & natural
languages 🗣
About me
3
Ahead-of-Time (AOT)
“Native Image” toolchain
Language Runtimes
High-performance
optimizing compiler
native-image MyMainClass
./mymainclass
JIT AOT
java MyMainClass
native-image MyMainClass
./mymainclass
JIT AOT
java MyMainClass
Clojure
Open source on GitHub: github.com/oracle/graal
GraalVM
Native Image
GraalVM Native Image
• Enables compiling Java programs into
standalone native executables
• Performs static analysis to identify all code
reachable from the entry point
• Instant startup, low memory footprint,
perfect for cloud deployments
• Integrations with Java microservices
frameworks
Native Image Build Process
Ahead-of-Time
Compilation
Application
Libraries
JDK
Substrate VM
Points-to Analysis
Run Initializations
Heap Snapshotting
Input:
All classes from application,
libraries, and VM
Iterative analysis until
fixed point is reached
Code in
Text Section
Image Heap in
Data Section
Image Heap
Writing
Output:
Native executable
AOT vs JIT: Startup Time
JIT
Load JVM executable
Load classes from file system
Verify bytecodes
Start interpreting
Run static initializers
First tier compilation (C1)
Gather profiling feedback
Second tier compilation (GraalVM or C2)
Finally run with best machine code
AOT
▪ Load executable with prepared heap
▪ Immediately start with optimized machine code
AOT vs JIT: Memory Footprint
JIT
Loaded JVM executable
Application data
Loaded bytecodes
Reflection meta-data
Code cache
Profiling data
JIT compiler data structures
AOT
▪ Loaded application executable
▪ Application data
Tips & Tricks 🛠
14
JIT AOT
Application payload
Dynamic Code
Cache
Metaspace
Class Files
VM Runtime and
Compiler
Garbage
Collector
Profiling
Feedback
Memory Scalability
Application payload
Application
Machine Code
Garbage
Collector
Application payload
Application payload
Application payload
Application payload
Application payload
Compilation
Data Structures
Application payload
Dynamic Code
Cache
Metaspace
Class Files
Profiling
Feedback
Compilation
Data Structures
Application payload
Dynamic Code
Cache
Metaspace
Class Files
Profiling
Feedback
Compilation
Data Structures
Application payload
Dynamic Code
Cache
Metaspace
Class Files
Profiling
Feedback
Compilation
Data Structures
Application payload
Dynamic Code
Cache
Metaspace
Class Files
Profiling
Feedback
Compilation
Data Structures
Application payload
Dynamic Code
Cache
Metaspace
Class Files
Profiling
Feedback
Compilation
Data Structures
shared
duplicated
per process
Example: horizontal scaling of microservices
Java HotSpot VM
• 4 VM instances = 4 times the memory
Native Image
• 4 VM instances = 2 times the memory
• Image heap shared between processes
• Machine code shared between processes
Memory Usage in MB
Quarkus Apache Tika ODT in a “tiny” configuration and with the serial GC
(1 CPU core per process, -Xms32m -Xmx128m) – JDK 11
0
200
400
600
800
1000
1200
1 process 2 processes 3 processes 4 processes
1109.0562
842.6914
576.3267
309.9619
132.2417
107.793
83.3442
58.8955
Native Image EE HotSpot C2
Tips & Tricks 🛠
• Build, test and run Java applications as native executables
• Out-of-the-box support for native JUnit 5 testing
• testing Java code with JUnit 5 behaves in the same way in native
execution as with the JVM
• allows libraries in the JVM ecosystem to run their test suites
via GraalVM Native Image
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
</plugin>
Native Build tools: Official Gradle and Maven Plugins 🏗
Demo: Testing Native Image appliсations
16
• @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.
GraalVM Native Image & JUnit
Native Integration Tests
18
• GraalVM 🤝 Reflection!
• Native Image tries to resolve the target elements through a static
analysis that detects calls to the Reflection API
• If the analysis can not automatically detect your use of
reflection, you might need additional configuration
• Trace reflection, JNI, resource usage on the JVM with the tracing
agent:
• Agent to record usage and produce configuration files for
native images
• java -agentlib:native-image-agent=config-output-dir=META-
INF/native-image ...
• Manual adjustment / addition might still be necessary
• Many frameworks & libraries ship reflection config that will be
automatically picked up
GraalVM & Reflection?
19
GraalVM & Reflection: demo
20
What about reflection in 3rd-party libraries?
graalvm.org/native-image/libraries-and-frameworks
Is there an easier way to handle reflection? Yes!
22
Optimizing
Performance 🚀
Optimizing performance of native image
native-image
--pgo-instrument
Instrumented Binary
native-image --pgo optimized binary 🚀
Profiles (.iprof)
Relevant
Workloads
AOT at the speed of JIT 🚀
Performance of Spring Petclinic with Oracle GraalVM Native Image, GraalVM CE Native Image, and GraalVM CE with C2 JIT.
Benchmark details: https://medium.com/graalvm/graalvm-for-jdk-21-is-here-ee01177dd12d
AOT at the speed of JIT 🚀
Performance of Spring Petclinic with Oracle GraalVM Native Image, GraalVM CE Native Image, and GraalVM CE with C2 JIT.
Benchmark details: https://medium.com/graalvm/graalvm-for-jdk-21-is-here-ee01177dd12d
Compressing native images with UPX
* more aggressive compression algorithms can have runtime impact
Static native images
• statically linked against musl-libc , which can be used
without any additional library dependencies
• great for deploying on slim or distroless container images
FROM gcr.io/distroless/base
COPY build/native-image/application app
ENTRYPOINT ["/app"]
Mostly static native images
• statically link against all libraries except libc
• great for deploying such native images on distroless
container images
Static and Mostly Static Images
28
Reduced Attack Surface 🛡
• No new unknown code can be loaded at run time
• Only paths proven reachable by the application are included in the image
• Reflection is disabled by default and needs an explicit include list
• Deserialization only enabled for specified list of classes
• Just-in-time compiler crashes, wrong compilations, or “JIT spraying” to create
machine code gadgets are impossible
What’s the catch?
• GraalVM 🤝 Reflection!
• Native Image tries to resolve the target elements through a static analysis that detects calls to
the Reflection API
• If the analysis can not automatically detect your use of reflection, you might need
additional configuration
• Trace reflection, JNI, resource usage on the JVM with the tracing agent
• Manual adjustment / addition might still be necessary
GraalVM & Reflection?
31
Required Build Time Step
• Computational effort necessary at build time
• Need a powerful machine with the same target architecture & OS
• Use GraalVM with GitHub Actions: github.com/marketplace/actions/github-action-for-graalvm
• Many larger apps can build with 2 GB of memory
• Develop in JIT mode for fast development, only use AOT for final deployment
• For best throughput, use profile-guided optimizations
What’s new in GraalVM
34
35
https://github.com/oracle/graal/issues/7626
GraalVM Community roadmap on GitHub
https://github.com/orgs/oracle/projects/6
Get started with
GraalVM
Get started with GraalVM
graalvm.org
or
sdk install java 21-graal
40
Questions & let’s connect! GraalVM resources
Thank you!
Alina Yurenko
@alina_yurenko

More Related Content

PDF
GraalVM, CRaC, Leyden and friends
PDF
GraalVM Native and Spring Boot 3.0
PDF
Graal and Truffle: One VM to Rule Them All
PPTX
JVM++: The Graal VM
PPSX
Spring - Part 1 - IoC, Di and Beans
PPTX
Discover Quarkus and GraalVM
PDF
GraalVm and Quarkus
GraalVM, CRaC, Leyden and friends
GraalVM Native and Spring Boot 3.0
Graal and Truffle: One VM to Rule Them All
JVM++: The Graal VM
Spring - Part 1 - IoC, Di and Beans
Discover Quarkus and GraalVM
GraalVm and Quarkus

What's hot (20)

PDF
Operator Framework Overview
PPTX
Introduction to kubernetes
PDF
Capacitor 1.0 launch
PPTX
GitLab.pptx
PPTX
Introduction to GraalVM
PPT
Java EE and Spring Side-by-Side
PPTX
Spring Security 5
PDF
Gitlab ci-cd
PPTX
ISTIO Deep Dive
PDF
GraalVM Overview Compact version
PDF
Serverless with Google Cloud
PPTX
GitHub Basics - Derek Bable
PPT
Local Dev on Virtual Machines - Vagrant, VirtualBox and Ansible
PDF
API Gateway report
PDF
Introduction to kubernetes
PDF
The Beginner’s Guide To Spring Cloud
PPTX
Getting started with Jenkins
PPT
Maven Introduction
PPTX
CI/CD with Bitbucket pipelines
Operator Framework Overview
Introduction to kubernetes
Capacitor 1.0 launch
GitLab.pptx
Introduction to GraalVM
Java EE and Spring Side-by-Side
Spring Security 5
Gitlab ci-cd
ISTIO Deep Dive
GraalVM Overview Compact version
Serverless with Google Cloud
GitHub Basics - Derek Bable
Local Dev on Virtual Machines - Vagrant, VirtualBox and Ansible
API Gateway report
Introduction to kubernetes
The Beginner’s Guide To Spring Cloud
Getting started with Jenkins
Maven Introduction
CI/CD with Bitbucket pipelines
Ad

Similar to Everything you need to know about GraalVM Native Image (20)

PPTX
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
PPTX
All you need to know about Spring Boot and GraalVM
PPTX
GOING AOT WITH GRAALVM FOR JAVA - JAVAZONE
PDF
Peru JUG Micronaut & GraalVM
PDF
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
PPTX
Bring the Action: Using GraalVM in Production
PPTX
Going AOT: Everything you need to know about GraalVM for Java applications
PDF
AOT and Native with Spring Boot 3.0
PDF
GraalVM - MadridJUG 2019-10-22
PDF
GraalVM - OpenSlava 2019-10-18
PDF
JDK Tools For Performance Diagnostics
PPTX
GraalVM - A Step Ahead of JVM Presentation
PPTX
OpenCV @ Droidcon 2012
PPTX
Шлигін Олександр “Розробка ігор в Unity загальні помилки” GameDev Conference ...
PDF
Commit to excellence - Java in containers
PDF
Webinar: Zing Vision: Answering your toughest production Java performance que...
PDF
TechGIG_Memory leaks in_java_webnair_26th_july_2012
PPTX
Gradle Again
PPTX
Diagnosing issues in your ASP.NET applications in production with Visual Stud...
PDF
Micronaut: Evolving Java for the Microservices and Serverless Era
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
All you need to know about Spring Boot and GraalVM
GOING AOT WITH GRAALVM FOR JAVA - JAVAZONE
Peru JUG Micronaut & GraalVM
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
Bring the Action: Using GraalVM in Production
Going AOT: Everything you need to know about GraalVM for Java applications
AOT and Native with Spring Boot 3.0
GraalVM - MadridJUG 2019-10-22
GraalVM - OpenSlava 2019-10-18
JDK Tools For Performance Diagnostics
GraalVM - A Step Ahead of JVM Presentation
OpenCV @ Droidcon 2012
Шлигін Олександр “Розробка ігор в Unity загальні помилки” GameDev Conference ...
Commit to excellence - Java in containers
Webinar: Zing Vision: Answering your toughest production Java performance que...
TechGIG_Memory leaks in_java_webnair_26th_july_2012
Gradle Again
Diagnosing issues in your ASP.NET applications in production with Visual Stud...
Micronaut: Evolving Java for the Microservices and Serverless Era
Ad

Recently uploaded (20)

PPTX
history of c programming in notes for students .pptx
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
top salesforce developer skills in 2025.pdf
PDF
medical staffing services at VALiNTRY
PDF
Digital Strategies for Manufacturing Companies
PDF
System and Network Administration Chapter 2
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Nekopoi APK 2025 free lastest update
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
history of c programming in notes for students .pptx
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
top salesforce developer skills in 2025.pdf
medical staffing services at VALiNTRY
Digital Strategies for Manufacturing Companies
System and Network Administration Chapter 2
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
How Creative Agencies Leverage Project Management Software.pdf
Nekopoi APK 2025 free lastest update
ManageIQ - Sprint 268 Review - Slide Deck
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Operating system designcfffgfgggggggvggggggggg
How to Migrate SBCGlobal Email to Yahoo Easily

Everything you need to know about GraalVM Native Image

  • 1. Alina Yurenko Developer Advocate for GraalVM Oracle Labs Cape Town Java Community Everything you need to know about GraalVM Native Image Photo by Andrea Brataas on Unsplash
  • 2. • Alina Yurenko / @alina_yurenko • Developer Advocate for GraalVM at Oracle Labs • Love open source and communities 🤝 • Love both programming 👩💻 & natural languages 🗣 About me
  • 3. 3 Ahead-of-Time (AOT) “Native Image” toolchain Language Runtimes High-performance optimizing compiler
  • 6. Open source on GitHub: github.com/oracle/graal
  • 8. GraalVM Native Image • Enables compiling Java programs into standalone native executables • Performs static analysis to identify all code reachable from the entry point • Instant startup, low memory footprint, perfect for cloud deployments • Integrations with Java microservices frameworks
  • 9. Native Image Build Process Ahead-of-Time Compilation Application Libraries JDK Substrate VM Points-to Analysis Run Initializations Heap Snapshotting Input: All classes from application, libraries, and VM Iterative analysis until fixed point is reached Code in Text Section Image Heap in Data Section Image Heap Writing Output: Native executable
  • 10. AOT vs JIT: Startup Time JIT Load JVM executable Load classes from file system Verify bytecodes Start interpreting Run static initializers First tier compilation (C1) Gather profiling feedback Second tier compilation (GraalVM or C2) Finally run with best machine code AOT ▪ Load executable with prepared heap ▪ Immediately start with optimized machine code
  • 11. AOT vs JIT: Memory Footprint JIT Loaded JVM executable Application data Loaded bytecodes Reflection meta-data Code cache Profiling data JIT compiler data structures AOT ▪ Loaded application executable ▪ Application data
  • 12. Tips & Tricks 🛠 14 JIT AOT Application payload Dynamic Code Cache Metaspace Class Files VM Runtime and Compiler Garbage Collector Profiling Feedback Memory Scalability Application payload Application Machine Code Garbage Collector Application payload Application payload Application payload Application payload Application payload Compilation Data Structures Application payload Dynamic Code Cache Metaspace Class Files Profiling Feedback Compilation Data Structures Application payload Dynamic Code Cache Metaspace Class Files Profiling Feedback Compilation Data Structures Application payload Dynamic Code Cache Metaspace Class Files Profiling Feedback Compilation Data Structures Application payload Dynamic Code Cache Metaspace Class Files Profiling Feedback Compilation Data Structures Application payload Dynamic Code Cache Metaspace Class Files Profiling Feedback Compilation Data Structures shared duplicated per process
  • 13. Example: horizontal scaling of microservices Java HotSpot VM • 4 VM instances = 4 times the memory Native Image • 4 VM instances = 2 times the memory • Image heap shared between processes • Machine code shared between processes Memory Usage in MB Quarkus Apache Tika ODT in a “tiny” configuration and with the serial GC (1 CPU core per process, -Xms32m -Xmx128m) – JDK 11 0 200 400 600 800 1000 1200 1 process 2 processes 3 processes 4 processes 1109.0562 842.6914 576.3267 309.9619 132.2417 107.793 83.3442 58.8955 Native Image EE HotSpot C2
  • 15. • Build, test and run Java applications as native executables • Out-of-the-box support for native JUnit 5 testing • testing Java code with JUnit 5 behaves in the same way in native execution as with the JVM • allows libraries in the JVM ecosystem to run their test suites via GraalVM Native Image <plugin> <groupId>org.graalvm.buildtools</groupId> <artifactId>native-maven-plugin</artifactId> </plugin> Native Build tools: Official Gradle and Maven Plugins 🏗
  • 16. Demo: Testing Native Image appliсations 16
  • 17. • @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. GraalVM Native Image & JUnit
  • 19. • GraalVM 🤝 Reflection! • Native Image tries to resolve the target elements through a static analysis that detects calls to the Reflection API • If the analysis can not automatically detect your use of reflection, you might need additional configuration • Trace reflection, JNI, resource usage on the JVM with the tracing agent: • Agent to record usage and produce configuration files for native images • java -agentlib:native-image-agent=config-output-dir=META- INF/native-image ... • Manual adjustment / addition might still be necessary • Many frameworks & libraries ship reflection config that will be automatically picked up GraalVM & Reflection? 19
  • 21. What about reflection in 3rd-party libraries? graalvm.org/native-image/libraries-and-frameworks
  • 22. Is there an easier way to handle reflection? Yes! 22
  • 24. Optimizing performance of native image native-image --pgo-instrument Instrumented Binary native-image --pgo optimized binary 🚀 Profiles (.iprof) Relevant Workloads
  • 25. AOT at the speed of JIT 🚀 Performance of Spring Petclinic with Oracle GraalVM Native Image, GraalVM CE Native Image, and GraalVM CE with C2 JIT. Benchmark details: https://medium.com/graalvm/graalvm-for-jdk-21-is-here-ee01177dd12d
  • 26. AOT at the speed of JIT 🚀 Performance of Spring Petclinic with Oracle GraalVM Native Image, GraalVM CE Native Image, and GraalVM CE with C2 JIT. Benchmark details: https://medium.com/graalvm/graalvm-for-jdk-21-is-here-ee01177dd12d
  • 27. Compressing native images with UPX * more aggressive compression algorithms can have runtime impact
  • 28. Static native images • statically linked against musl-libc , which can be used without any additional library dependencies • great for deploying on slim or distroless container images FROM gcr.io/distroless/base COPY build/native-image/application app ENTRYPOINT ["/app"] Mostly static native images • statically link against all libraries except libc • great for deploying such native images on distroless container images Static and Mostly Static Images 28
  • 29. Reduced Attack Surface 🛡 • No new unknown code can be loaded at run time • Only paths proven reachable by the application are included in the image • Reflection is disabled by default and needs an explicit include list • Deserialization only enabled for specified list of classes • Just-in-time compiler crashes, wrong compilations, or “JIT spraying” to create machine code gadgets are impossible
  • 31. • GraalVM 🤝 Reflection! • Native Image tries to resolve the target elements through a static analysis that detects calls to the Reflection API • If the analysis can not automatically detect your use of reflection, you might need additional configuration • Trace reflection, JNI, resource usage on the JVM with the tracing agent • Manual adjustment / addition might still be necessary GraalVM & Reflection? 31
  • 32. Required Build Time Step • Computational effort necessary at build time • Need a powerful machine with the same target architecture & OS • Use GraalVM with GitHub Actions: github.com/marketplace/actions/github-action-for-graalvm • Many larger apps can build with 2 GB of memory • Develop in JIT mode for fast development, only use AOT for final deployment • For best throughput, use profile-guided optimizations
  • 33. What’s new in GraalVM
  • 34. 34
  • 35. 35
  • 37. GraalVM Community roadmap on GitHub https://github.com/orgs/oracle/projects/6
  • 39. Get started with GraalVM graalvm.org or sdk install java 21-graal
  • 40. 40 Questions & let’s connect! GraalVM resources