Skip to content

alina-yur/fun-with-native-image-flags

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

10 Commits
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Fun With (Native Image) Flags ๐Ÿ

Overview ๐Ÿฐ

  • Intro
  • General approach to the flags
  • Development
  • Performance
  • Sonitoring
  • Security
  • GraalVM for JDK 25

Development Flags: Must have ๐Ÿ› ๏ธ

  • -Ob: Optimize for build time
  • -Os: Optimize for executable size
  • -o: file output: name and location
  • --emit-build-report: extensive report about the build & executable
  • Linking: dynamic (default), mostly static: --static-nolibc, static: --static --libc=musl
  • ๐Ÿ‘ฉโ€๐Ÿ’ป demo: native-micronaut

Development Flags: Advanced ๐Ÿ› ๏ธ

  • -g: generate debugging information
  • --parallelism: specify the maximum number of threads to use concurrently during native executable generation
  • --dry-run: output the command line that would be used for the build

Performance Flags ๐Ÿš€

  • -O3: Optimize for best performance
  • -pgo: profile-guided optimizations
  • --gc=G1: use the G1 GC for high throughput
  • -march=native: specialize for the given hardware
  • ๐Ÿ‘ฉโ€๐Ÿ’ป demo: swiss-dictionary

Montitoring ๐Ÿ“ˆ

  • --enable-monitoring=jfr
  • --enable-monitoring=jvmstat
  • --enable-monitoring=heapdump
  • OpenTelemetry, Micrometer
  • Spring Boot Actuator / Micronaut Management
  • Vendor and cloud solutions โ€” check your deployment environment
  • OS-level: perf stat, vmmap, etc

Security ๐Ÿ›ก๏ธ

  • --enable-sbom=embed
  • --enable-sbom=classpath (for programmatic access and external tooling)
  • --enable-sbom=export
  • Vulnerability scanning: native-image-inspect --sbom ./target/demo-sbom | grype -v
  • --enable-sbom=class-level (specific classses, fields, methods, etc)
  • ๐Ÿ‘ฉโ€๐Ÿ’ป demo: native-micronaut

New 25.0 flags ๐Ÿ”ฎ

  • -H:Preserve=all: include everything
    • or a module/package/cp entry
  • -H:+RelativeCodePointers: extra security at high performance with PIE
  • -H:+ReportDynamicAccess: a visual report of reflection and other dynamic access config More performance and security :)

About

Prepared for JavaZone 2025

Resources

License

Stars

Watchers

Forks