- Latest (22.3)
- Dev Build
- Native Image
- Build Output
- Build Configuration
- Tracing Agent
- Experimental Agent Options
- Native Image Compatibility and Optimization Guide
- Class Initialization in Native Image
- Static Native Images
- Native Image Options
- Native Image Hosted and Runtime Options
- Native Image Inspection Tool
- Native Image C API
- Implementing Native Methods in Java with Native Image
- LLVM Backend for Native Image
- Debug Info Feature
- Points-to Analysis Reports
- Using System Properties in Native Image
- Profile-Guided Optimizations
- Memory Management at Image Run Time
- Generating Heap Dumps from Native Images
- JDK Flight Recorder with Native Image
- JCA Security Services on Native Image
- Dynamic Proxy on Native Image
- Java Native Interface (JNI) on Native Image
- Reflection on Native Image
- Accessing Resources in Native Images
- Logging on Native Image
- URL Protocols on Native Image
- Native Image ARM64 Support
- GraalVM Updater
- Languages References
- Embedding Reference
- Polyglot Programming
GraalVM Enterprise allows to apply profile-guided optimizations (PGO) for additional performance gain and higher throughput of native images. With PGO you can collect the profiling data in advance and then feed it to the native image builder, which will use this information to optimize the performance of the resulting binary.
Note: This feature is available with GraalVM Enterprise only.
Here is how you can build an optimized native image, using the OptimizedImage.java example program.
1. Save this Java program that iterates over
ArrayList using a lambda expression to a file and compile it:
2. Build an instrumented native image by appending the
--pgo-instrument option, whose execution will collect the code-execution-frequency profiles:
native-image --pgo-instrument OptimizedImage
3. Run this instrumented image, saving the result in a profile.iprof file, if nothing else is specified:
4. Lastly, create the second native image by specifying the path to the profile.iprof file and execute it.
native-image --pgo=profile.iprof OptimizedImage ./optimizedimage
You can specify where to write the profile when running an instrumented native image by passing the
-XX:ProfilesDumpFile=YourFileName option at run time.
You can also collect multiple profile files, by specifying different names, and add them to the image build.