Native Image Quick Reference

Build a native IMAGE Build an optimized Native Image Configure a Native Image

Build a native image from a JAR file with all dependencies: Build an image with profile-guided optimizations: Static analysis requires configuration for some language native-image [options] -jar myApp.jar native-image --pgo-instrument MyApp [imagename] features: accessing resources, serialization, reflection, JNI, Run the image to record the profile:./myapp etc. Specify classes search path for directories, JARs, ZIPs: native-image --pgo default.iprof MyApp -cp jar:com/package/**/myApp.jar Select GraalVM’s garbage collector implementation: Run a process with tracing agent to generate the configuration: Specify the custom main class: --gc=G1 java -agentlib:native-image-agent= -H:Class=MyApp config-output-dir=/path/to/config-dir/ Control classes initialization at build or run time: Build a shared library -jar MyApp.jar --initialize-at-build/run-time= Specify the configuration to use for building a native image: native-image -jar jarfile [libraryname] com.example.MyClass,org.package -H:ConfigurationFileDirectories=/path/to/ --shared Include resources matching Java RegEx: config-dir/ -H:IncludeResource=/com/package/**/file.xml

Enable HTTPS support: Annotate the entry point method(s) with the Configuration files in META-INF/native-image on the classpath are included automatically. --enable-https @CEntryPoint annotation. Entry point methods must be static, have non-object parameters and return types. Install exit handlers: Configure at run time: --install-exit-handlers ./imagename -Xmx -Xmn Include all security service classes: @CEntryPoint Configure default heap settings at build time: --enable-all-security-services static int add(IsolateThread thread,int a, int b) { -:MaxHeapSize= -R:MaxNewSize= return a + b; Add all charsets support: } Debug a Native Image -H:+AddAllCharsets Build a native image with debug information: Include all timezones pre-initialized: -g -H:+IncludeAllTimeZones Java Native image Print garbage collection logs: Build a statically linked image with libc implementation: Binary code bytecode build ./imagename -XX:+PrintGC -XX:+VerboseGC --static --libc=glibc|musl Your app Trace the initialization path for a certain class: Build a statically linked image with libc dynamically linked (distroless): Static analysis Compile code -H:+TraceClassInitialization= -H:+StaticExecutableWithDynamicLibC Code package.class.Name Dependencies Initialization Enable polyglot support: Image heap Print classes intialized detected by the static analysis: --language:java|js|python|ruby||wasm Store -H:+PrintClassInitialization JDK classes Snapshot image heap Attach a debugger to the build process: Gather the diagnostic data for GraalVM Dashboard: --debug-attach=[port] -H:+DashboardAll -H:DashboardDump= More info at www.graalvm.org ver: 2.000