- Latest (GraalVM for JDK 21)
- Dev Build
- GraalVM for JDK 21
- GraalVM for JDK 20
- GraalVM for JDK 17
- GraalVM 22.3
- GraalVM 22.2
- GraalVM 22.1
- GraalVM 22.0
- GraalVM 21.3
- Native Image
- Build Output
- Build Configuration
- Tracing Agent
- 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 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 Images
- 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
Note
This documentation may be out of date. See the latest version.
Profile-Guided Optimizations
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:
import java.util.ArrayList;
class OptimizedImage {
public static void main(String[] args) {
ArrayList<String> languages = new ArrayList<>();
languages.add("JavaScript");
languages.add("Python");
languages.add("Ruby");
System.out.print("ArrayList: ");
languages.forEach((e) -> {
System.out.print(e + ", ");
});
}
}
javac OptimizedImage.java
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:
./optimizedimage
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.