GraalVM Native Image

Measure GraalVM Native Image startup, memory, throughput, and build costs while learning its reachability metadata requirements.

published: reading time: 27 min read author: Geek Workbench updated: November 17, 2026
Quick Summary

Measure GraalVM Native Image startup, memory, throughput, and build costs while learning its reachability metadata requirements.

GraalVM Native Image

Traditional JVM applications load classes and warm up the JIT compiler as they run. That startup behavior matters for short-lived processes and services that scale to zero, but it is only one part of performance. GraalVM Native Image compiles Java ahead of time into a native executable. It can reduce startup time or resident memory for some applications; the result depends on the program, workload, platform, and measurement method.

Introduction

GraalVM Native Image is an ahead-of-time (AOT) compilation technology that transforms Java bytecode into native executables. A native executable includes a runtime designed for the analyzed application and does not need a separate JVM to launch. This can help in environments where cold-start latency matters, such as serverless platforms, frequently scaled services, and command-line tools. Measure readiness from the process start using the application and deployment setup you plan to ship; compilation alone does not guarantee a particular startup time.

Startup, memory, and throughput vary with the application and its runtime environment. Native Image can trade build time and peak throughput for faster startup or lower resident memory, especially in workloads that spend much of their life starting up. Reflection, JNI, dynamic proxies, and resource access may also need reachability metadata. Compare the same application on the same machine and container limits before making a deployment decision.

Version note (checked 2026-11-17): The examples target GraalVM for JDK 25.5.x; the patch checked for this article is GraalVM 25.5.5.0.3, based on OpenJDK 25.0.5.0.3. Confirm the installed version before building. Commands, options, and reachability-metadata behavior can change between releases; use the 25.5 release notes and current Native Image documentation for the version you deploy.

This post covers how Native Image works under the hood, the build process and configuration files you need, trade-offs around memory and performance, common production failure scenarios, and practical implementation guidance for getting a Native Image build working in practice.

When to Use Native Image

Consider Native Image when measured startup or resident-memory behavior matters to the deployment:

  • Serverless functions — compare cold-start time and billed duration for the platform and function configuration you use
  • Containerized microservices — test readiness and scale-up behavior with the same resource limits used in production
  • CLI tools — measure time to the first useful output for representative commands
  • Embedded systems — Resource-constrained environments cannot afford a full JVM
  • Short-lived jobs — Batch jobs that process small inputs and exit quickly benefit from no warmup

When Not to Use Native Image

Native Image is not always the right choice:

  • Long-running servers — Compare sustained throughput after warm-up; a JIT may benefit from runtime profiles, but the result depends on the application and workload
  • Heavy reflection usage — Dynamic features require additional configuration and increase image size
  • Dynamic class loading — Applications that load plugins at runtime need extra setup for native image
  • Applications requiring latest JVM features — Native Image may lag behind the latest JVM releases

How Native Image Works

Native Image performs static analysis at build time. It follows code and resources it can determine from the application entry point and its configuration. Dynamic features such as reflection may need reachability metadata because the analyzer cannot infer every runtime access. This closed-world assumption also lets the compiler exclude code it cannot reach.

flowchart TD
    A["Java Source Code"] --> B[Build Process]
    B --> C["Static Analysis\nTrace all reachable code"]
    C --> D["Heap Snapshot\nPreinitialize reachable classes"]
    D --> E["Native Code Generation\nCompile to ELF/PE/Mach-O"]
    E --> F["Native Executable"]
flowchart TD
    A["Native Executable"] --> B["No JVM needed"]
    A --> C["Startup behavior depends on application and workload"]
    A --> D["Minimal heap\nPre-initialized objects"]

Build Process Phases

  1. Initialization — Native Image launches a JVM to run its own builder, which loads your application classes
  2. Static analysis — Starting from the entry point, the analyzer traces every reachable method, field, and type. It constructs a complete graph of what the application needs
  3. Heap snapshotting — All objects that exist at build time (static fields, string constants) are serialized into the image heap
  4. Native code generation — GraalVM compiles all reachable bytecode to native machine code
  5. Image linking — The compiled code, image heap, and Substrate VM runtime are linked into a single executable

The Substrate VM

Native Image includes a runtime designed for its analyzed application. Some runtime services and choices differ from a conventional JVM, and the exact set depends on GraalVM release and build configuration. For example, it does not use a JIT compiler for the image’s application code:

  • JIT compiler (all compilation is ahead-of-time)
  • Bytecode interpreter

The runtime still provides services such as:

  • Thread management
  • Stack frame management
  • Garbage collection (available collectors and behavior depend on release and build options)
  • Reflection implementation (preconfigured at build time)
  • Native image heap with preinitialized objects

Configuration Files

Native Image uses static analysis, but runtime behavior such as reflection, JNI, dynamic proxies, and resource lookup may not be visible during the build. Current GraalVM releases provide reachability metadata and a tracing agent to help describe those accesses. The agent only records code paths exercised during the run, so review its output and cover representative application flows.

For new configuration, use the current reachability-metadata.json format under META-INF/native-image/. The separate reflect-config.json, resource-config.json, and proxy-config.json examples below show the older per-feature layout; follow the documentation for the selected GraalVM release before adding metadata to a new project.

With GraalVM 25.5.x, including the 25.5.5.0.3 patch checked above, an agent run can collect metadata for flows you exercise:

"$JAVA_HOME/bin/java" \\
  -agentlib:native-image-agent=config-output-dir=target/native-image-config \\
  -jar target/app.jar

After the run, inspect the generated metadata, merge or place the required entries in the application’s META-INF/native-image/ directory, and repeat with inputs that cover other reflective, JNI, proxy, and resource paths. See the Tracing Agent guide and Reachability Metadata reference.

reflect-config.json

[
  {
    "name": "com.example.MyClass",
    "fields": [{ "name": "value", "type": "int" }],
    "methods": [
      { "name": "setValue", "parameterTypes": ["int"] },
      { "name": "getValue", "returnType": "int" }
    ]
  }
]

resource-config.json

{
  "resources": {
    "includes": [
      { "pattern": ".*\\.properties$" },
      { "pattern": ".*/messages/.*\\.xml$" }
    ],
    "excludes": [{ "pattern": ".*/debug/.*" }]
  }
}

proxy-config.json

[
  {
    "interfaces": ["java.lang.reflect.InvocationHandler"]
  }
]

Build-Time Initialization

Native Image may run static initializers (static {} blocks and field initializers) at build time when configured to do so. This can move work from startup into the build, but it can also bake environment-specific values into the executable. Measure the effect and keep runtime-dependent initialization at runtime.

public class Config {
    static final Map<String, String> SETTINGS = new HashMap<>();
    static {
        SETTINGS.put("host", "production.example.com");
        SETTINGS.put("port", "443");
        // This map is built at build time, not runtime
    }
}

In a traditional JVM, this static block runs the first time the class is loaded at runtime. In Native Image, it runs during the build, and the populated map is stored directly in the image heap.

When Initialization Must Be Deferred

Some initialization must happen at runtime:

  • Reading environment variables that differ between environments
  • Accessing system properties that differ between builds
  • Building connections to external services
  • Thread creation that depends on runtime conditions

Use @Substitute and @InjectRuntimeInitialization to defer specific initializations.

Comparing Startup, Memory, Throughput, and Build Cost

Do not compare a warmed-up JVM with a cold native process, or compare runs with different CPU and memory limits. Build both variants from the same application revision and dependencies. Record the GraalVM/JDK release, operating system, architecture, container limits, and workload so another engineer can repeat the comparison.

Measure these separately:

Measure How to compare
Time to readiness Start each process under the same conditions and measure until its health check reports ready. Repeat cold starts and report the distribution.
Resident memory Measure RSS or container memory at startup and under the same representative load; include image-mapped pages consistently.
Request latency and throughput Run the same workload long enough for the JVM to warm up, then compare throughput and latency percentiles.
Build time and artifact size Record the native build duration and output size alongside JVM packaging time.

Native Image may suit short-lived workloads even when the JIT JVM wins on long-running throughput. Memory results also vary with heap sizing, garbage collector, image heap, and workload. The measurements decide whether the trade is useful for your service.

Production Failure Scenarios

Missing Reflection Configuration

If runtime reflection accesses a type that static analysis cannot see and reachability metadata does not include, the native executable may fail at runtime even though the class is present in the source tree.

Example: Using Class.forName() on a plugin class discovered at runtime:

// This works in JVM, fails in Native Image without configuration
String className = pluginRegistry.getPluginClass();
Class<?> clazz = Class.forName(className);  // Class not found in image

Fix: Add the required access to the release’s reachability metadata, or run the tracing agent over representative plugin flows and review the generated entries. Older guides may show reflect-config.json as a separate file.

Missing Resources

Resources loaded dynamically may need reachability metadata so Native Image includes them. A missing resource can return null at runtime, which makes configuration and template failures hard to trace. Exercise resource-loading paths with the tracing agent and review the generated entries; older guides may show a separate resource-config.json file.

For GraalVM 25.5.x, add the required resource entries in the current reachability metadata format. Follow the metadata reference for its schema and placement; older documentation may use this separate-file layout:

{
  "resources": {
    "includes": [
      { "pattern": "config/app.properties" },
      { "pattern": "messages/.*" },
      { "pattern": ".*\\.ftl$" }
    ]
  }
}

The tracing agent can help find reflective access, resource lookups, proxies, and other dynamic behavior exercised while it runs. It records only observed paths, so it cannot discover code that the test or workload did not execute. Exercise classpath scanning, configuration loading, and less common application flows; review the generated metadata and run the native executable through the same paths. The agent output is a starting point for reachability metadata, not proof that every runtime access has been covered.

Static Initialization Accessing Runtime Data

If a static initializer reads a system property or environment variable that differs between build and runtime:

static final String ENV = System.getenv("DATABASE_URL");

This is evaluated at build time in Native Image. The value baked into the image may be wrong for the runtime environment.

Large Image Size

Image size depends on reachable code, included resources, and runtime configuration. Use the Native Image build reports for the selected GraalVM release to inspect what contributes to the binary. Static linking changes system-library dependencies and portability; it is not a general image-size optimization.

Native Image includes code its analysis finds reachable from the application entry points, along with configured dynamic accesses. A dependency can add code even when the application uses only part of it. Compare build reports from the same revision and remove or replace a dependency only after checking reflective or other dynamic use.

Start with the build report and options documented for GraalVM 25.5. Avoid copying internal -H: flags from another release without checking their support and effect. If a dependency appears large, measure a build with and without it, then run application flows that cover reflective or service-loaded use before removing it.

Use static linking only when the target platform and native libraries support it and the deployment requires that linkage model. Check the GraalVM 25.5 build configuration guide and test the executable in the target image; static linking can change compatibility and artifact size.

Slow Build Time

Native Image builds add analysis and native compilation work compared with producing a JVM artifact. Measure build duration in the same CI environment you plan to use and include it in the deployment trade-off. Build caching and incremental options are release- and toolchain-specific; use only features documented for the GraalVM version you pin.

The build performs analysis and native code generation, so its duration depends on the application, dependencies, build host, and options. Record clean and cached build times separately. Do not treat one project’s timing as a general estimate.

If build time is a release bottleneck, use the caching features supported by the build tool and GraalVM release in use. Cache only documented outputs and confirm that changes to dependencies, toolchains, or flags invalidate cached results when required.

Parallelism and separate validation builds may help, but measure their effect on the actual project. Keep the build configuration and artifact identity consistent between the build used for testing and the one promoted to production.

Failure Scenarios and Trade-Off Analysis

When AOT Produces Slower Peak Performance

For long-running server applications, a JIT can use observations from the running workload to optimize hot paths. Native Image compiles ahead of time and may behave differently under sustained load. Which version has better throughput depends on the application and runtime profile, so compare them after warm-up with representative requests and resource limits.

Three specific JIT tricks explain the gap. First, type feedback — if a virtual call receives the same concrete type ten thousand times in a row, the JIT plants a guard and inlines the target directly, cutting out the virtual dispatch entirely. AOT has no runtime type data, so it must generate code that works for every possible receiver type. Second, on-stack replacement (OSR). A running method with a hot inner loop can be recompiled and swapped in mid-execution. AOT compiles once and that is the final code. Third, deoptimization. If a JIT method made bets on a certain type distribution and those bets go bad, the runtime falls back to interpreted code and recompiles. Native Image cannot do any of this.

For a service, compare cold-start-to-ready latency, resident memory, throughput after warm-up, tail latency, and build time. Keep the inputs, container limits, and request mix the same. A workload that scales to zero may value startup more than steady-state throughput; a long-running service may make the opposite choice. Let measured results and operating cost decide.

Image Size Growth from Unchecked Dependencies

Dependencies can increase native executable size when their code or resources are reachable. Inspect build reports and test any dependency or metadata change against application flows; static linking is a deployment choice, not a substitute for that review.

Aspect JVM Runtime Native Image
–––– ———— –––––––
Startup Measure to readiness Measure to readiness
Memory Measure at startup and under load Measure at startup and under load
Peak throughput Depends on warm-up and workload Depends on workload and options
Warmup Happens at runtime Not needed
Reflection Works out of the box Requires configuration
Dynamic classloading Supported Limited, requires configuration
GC Configurable Available options depend on release
Build time Measure packaging/build time Measure native compilation time
Binary portability High (.class files run anywhere) Low (per-OS binary)
Supports all JVM features Yes No (preview features may lag)

Implementation Snippets

Install GraalVM and Native Image

# Install GraalVM 25.5.5.0.3 for OpenJDK 25.0.5.0.3 for your OS and architecture.
# Select the matching archive from https://www.graalvm.org/downloads/.
# Keep that exact distribution pinned in local development and CI.

# Verify that the selected GraalVM and Native Image tool are on PATH.
java --version
native-image --version

Build a Basic Native Image

# Compile Java with the selected GraalVM JDK
javac MyApp.java

# Build a native image for the class on the current class path
native-image -cp . MyApp

# Run the native executable
./MyApp

Build a Spring Boot Application

# With Maven; pin the GraalVM JDK and Native Build Tools plugin in the project.
./mvnw native:compile -Pnative

# With Gradle; pin the GraalVM JDK and Native Build Tools plugin in the project.
./gradlew nativeCompile

# Or use the Spring Boot plugin
./mvnw spring-boot:build-image  # Creates OCI image with native executable

Generate Reflection Configuration Automatically

# Run GraalVM 25.5.5.0.3 (OpenJDK 25.0.5.0.3) against representative inputs.
# Confirm java --version and native-image --version identify the pinned release.
"$JAVA_HOME/bin/java" -agentlib:native-image-agent=config-output-dir=target/native-image-config \
     -jar target/myapp.jar

# Review generated metadata, place required entries under META-INF/native-image/,
# then rebuild with the metadata layout documented for GraalVM 25.5.x.
native-image -jar target/myapp.jar

Build with Custom Heap Size

# Heap and garbage-collector options vary by GraalVM release and runtime.
# Use the GraalVM 25.5 build configuration documentation for supported options.

Observability Checklist

When deploying Native Image in production:

  • Monitor image size — A bloated image indicates unused code is being included
  • Record build time — Compare clean and cached builds on the same CI runner
  • Test in staging with production-like reflection — Agent-generated configs may miss dynamic paths
  • Verify resource bundling — Confirm required resources are in the image
  • Check GC behavior — Record pause time and throughput for the collector and options in use
  • Profile with perf — Use Linux perf to see CPU hotspots in the native binary
  • Test with realistic workloads — Measure readiness, memory, and throughput against service objectives

Security Notes

Native Image changes which runtime components and dynamic-loading paths are present. That can affect an application’s security boundaries, but it does not by itself establish a smaller attack surface. Review the code, native libraries, build environment, and runtime features in the image:

  • Native code vulnerabilities — The native executable is a native process and can be vulnerable to memory corruption exploits
  • Configuration errors — Missing reflection configuration may cause unexpected behavior, but typically manifests as crashes rather than security issues
  • Build environment trust — The build process runs on your infrastructure; ensure build environments are secured

For high-security workloads, use --static linking to avoid dynamic library dependencies, and consider using a minimal operating system base image in containers.

Common Pitfalls / Anti-Patterns

  1. Assuming all classes are included — Native Image includes code that analysis and configuration can reach. Reflection or dynamic proxies may need metadata. Run the tracing agent on representative paths, then review and test its output.

  2. Confusing build-time and runtime initialization — Static blocks run at build time. Code that depends on environment-specific values baked into static fields at build time behaves incorrectly at runtime.

  3. Not testing the native image — Always test the compiled native image, not just the JVM version. Behavior differences between JVM and Native Image are common and must be caught before deployment.

  4. Expecting one runtime to win every workload — A JIT can use runtime profiles; Native Image compiles ahead of time. Compare startup, sustained throughput, latency, and memory with the same program and resource limits.

  5. Forgetting to update configuration after code changes — When you add new reflection calls or resources, you must regenerate the configuration and rebuild the image. Stale configuration causes runtime failures.

Quick Recap Checklist

  • Native Image compiles Java to native executables ahead-of-time
  • Compare time to readiness under the same startup conditions
  • Measure RSS or container memory under the same representative load
  • Closed-world assumption — all reachable code must be determined at build time
  • Reflection, resources, and dynamic proxies may require reachability metadata
  • Use the tracing agent to collect metadata for exercised flows, then review its output
  • Record native build duration and artifact size
  • Compare sustained throughput after the JVM has warmed up
  • Native Image includes runtime services selected for the build and does not JIT-compile its application code
  • Check linking and platform compatibility for the target deployment

Interview Questions

1. Why can Native Image reduce startup work, and how should you measure the effect?

A native executable does not launch a separate JVM or wait for JIT compilation before running its compiled code. It still performs runtime initialization, loads its image and libraries, and starts the application. Measure from process start to readiness using the same app, host, container limits, and readiness check as the JVM build. Repeat cold starts and report the distribution; results vary by application and environment.

2. What is the closed-world assumption in Native Image?

Native Image requires that all code reachable at runtime be determinable at build time. Starting from the main entry point, the static analyzer traces through every method call, field access, and type reference it can find. Any code not reachable through this trace is excluded from the final image. This enables aggressive optimizations — dead code elimination, aggressive inlining, removal of dynamic dispatch — but it means features that work at runtime in a JVM (dynamic class loading, runtime bytecode generation, reflection on unknown types) require explicit configuration or become unavailable. The closed-world assumption is what makes AOT compilation possible and what makes Native Image different from a traditional JVM.

3. Why might a Native Image application have lower peak performance than a JVM application?

A JVM JIT can use runtime observations to optimize hot code and revise assumptions as a workload changes. Native Image compiles ahead of time, so its optimization decisions use build-time analysis instead. This can favor the JIT in some long-running workloads, while other programs may benefit from native startup or footprint. Measure sustained throughput and latency for the application and runtime configuration you plan to ship; neither approach wins every workload.

4. How do you handle reflection in a Native Image application?

Reachability metadata tells Native Image which reflectively accessed types or resources must be included. For new projects, use the reachability-metadata.json format documented for the GraalVM release you pin; the separate *-config.json files shown earlier are a legacy layout. The tracing agent can collect metadata for paths it observes, but it cannot see unexercised code. Run representative flows, review the generated entries, and test the resulting executable.

5. What is the Substrate VM and how does it differ from a traditional JVM?

Native Image links a runtime suited to the analyzed application into its executable. It does not use a JIT compiler or bytecode interpreter for that application, but it still provides runtime services such as threads, memory management, and configured dynamic access. Available garbage collectors and other runtime options depend on the GraalVM release and build configuration. Compare those options in the current documentation rather than assuming one fixed runtime profile.

6. How does the Substrate VM's garbage collector differ from the G1GC or ZGC used in a traditional JVM, and what are the performance implications?

Native Image garbage-collector choices and behavior depend on the GraalVM release, platform, and build options. Do not assume every native executable uses one single-threaded collector or has the same pause behavior. Check the current release documentation, then measure pause time, memory use, and throughput with the application’s allocation pattern and deployment limits.

7. What happens during the Native Image build process's static analysis phase, and why can it fail or produce incomplete results?

Static analysis follows code and resources it can determine from the build inputs and configuration. Runtime reflection, generated proxies, instrumentation, JNI, and dynamically selected resources may need reachability metadata. The tracing agent can record accesses made during an instrumented run, but it only sees exercised paths. Review its output, cover representative and uncommon flows, and test the resulting executable; agent output alone does not establish complete coverage.

8. How does build-time initialization affect environment-specific configuration in Native Image applications?

Native Image runs all static initializers and static field initializers at build time rather than runtime. This means if a static field reads an environment variable, a system property, or any runtime-only value, that value is captured and frozen into the image heap at build time. When the image runs in a different environment (different DATABASE_URL, different JVM options), it still uses the values from build time — causing failures that are difficult to diagnose because the symptom appears at runtime as if the wrong environment variable were set. The solution is to avoid reading environment-specific values in static initializers, and to defer initialization to runtime using annotations like @InjectRuntimeInitialization or by restructuring code to read configuration at startup rather than in static blocks. This is a fundamental difference from traditional JVM behavior that surprises developers who move existing applications to Native Image.

9. What trade-offs can occur between AOT (ahead-of-time) and JIT (just-in-time) compilation?

A JIT can use runtime observations when optimizing hot code, while Native Image compiles ahead of time. The trade-off is workload-specific: measure startup, peak memory, build time, and sustained throughput separately. Compare the same program revision, platform, limits, and workload; do not assume a fixed performance percentage.

10. How does the native-image agent automatically generate reflection and resource configuration?

The tracing agent observes dynamic access while the application runs and records metadata for the paths it sees. It cannot infer code that the run did not exercise, so use representative inputs, review the output, and repeat after relevant code or dependency changes. Place reviewed metadata in the location and format documented for the GraalVM release you pin. Current releases support reachability metadata; older documentation may show separate reflect-config.json, resource-config.json, and proxy-config.json files.

11. What is the difference between the heap snapshot in Native Image and the JVM heap at runtime?

Objects initialized at build time can be stored in the image heap and are available when the executable starts. This changes when initialization work occurs; it does not guarantee lower RSS or eliminate runtime allocation. Measure resident memory under the same workload and container limits, and keep environment-specific values out of build-time state.

12. How does Native Image handle thread management and stack frames compared to a JVM?

Native Image provides Java threads and stack frames through its runtime, with implementation details that differ from a conventional JVM. It does not use JIT deoptimization or on-stack replacement for its compiled application code. Thread and stack costs depend on the application, runtime options, and operating system; measure them under the same concurrency and workload as the JVM comparison.

13. Why does Native Image produce platform-specific executables while JVM applications are portable?

Native Image produces a binary for a target platform, so deployment across operating systems or architectures requires a compatible build for each target. A JAR can run on platforms with a compatible JVM. Native Image may change startup, resident memory, sustained throughput, build time, and artifact size; measure those outcomes on the target platform before deciding whether that portability trade-off is worthwhile.

14. What is the impact of using `--static` linking in a Native Image build, and when would you use it?

Static linking changes how native libraries are resolved and can affect compatibility and artifact size. Use it only when the target platform and libraries support it and the deployment requires it. Check the GraalVM 25.5 build configuration documentation and test the executable in the target image; it is not a universal deployment recommendation.

15. How does Native Image handle dynamic proxy generation compared to the JVM's java.lang.reflect.Proxy?

Runtime-generated proxies may need reachability metadata so Native Image can include the required proxy interfaces. For GraalVM 25.5.x, follow the current metadata documentation; older guides may show a separate proxy-config.json. The tracing agent can record proxy use exercised during a run, but it will miss flows the run does not cover. Review the metadata and test proxy-using paths in the built executable.

16. What is the relationship between GraalVM's Truffle framework and Native Image, and why does Native Image support Truffle languages?

Truffle is a framework for implementing languages on GraalVM. Native Image can compile some language runtimes to native executables, but supported combinations and their performance depend on the language distribution and release. Check the current language documentation and measure the application you intend to ship instead of assuming native startup or throughput will match another runtime.

17. What are the implications of Native Image's lack of class loading for security and memory management?

Native Image uses a closed-world assumption for application code: dynamically chosen classes and runtime-generated bytecode may need metadata or another supported integration path. This can rule out some plugin designs or require dependencies to be known at build time. It changes the loading model, but it does not by itself guarantee a security improvement or lower memory use. Review the application’s runtime loading and trust boundaries, then measure the built image under the intended workload.

18. How does Native Image handle JNI (Java Native Interface) calls and native library integration?

Native Image supports JNI when the required native libraries and access patterns are available to the build and configured for the target platform. JNI access can require reachability metadata; library resolution and linking behavior depend on the deployment and build options. Consult the documentation for the pinned GraalVM release, then test the executable on the target platform with the native calls it will use.

19. How can you investigate what contributes to a Native Image executable's size?

Use the build reports and diagnostics documented for GraalVM 25.5 to inspect the code and resources included in the image. Compare reports from the same revision, then change one dependency or metadata entry at a time. Re-run representative application paths after each change, since reflection and other dynamic access may not be visible to static analysis.

20. How does the image heap in Native Image interact with garbage collection, and why are preinitialized objects not GC'd?

Objects initialized during the build can be stored in the image heap and become part of the executable's initial state. Runtime allocations are still managed by the configured collector. Build-time initialization changes when objects are created and can affect startup, memory mapping, and runtime behavior; it does not guarantee a smaller footprint or lower GC cost. Measure resident memory and allocation behavior under the same workload and container limits as the JVM comparison.

Further Reading

Conclusion

Native Image compiles Java ahead of time and can change startup, memory, and throughput behavior. Whether those changes help depends on the application and its workload. Compare time to readiness, memory under load, sustained throughput, build time, and image size before choosing it. Dynamic access may need reachability metadata; see the current Native Image documentation and JIT Compilation Internals for the runtime comparison.

Category

Related Posts

Async-Profiler: A Practical JVM Profiling Guide

Choose CPU, allocation, lock, or live-object profiling, then compare JVM profiles under a repeatable workload without guessing at overhead.

#jvm #async-profiler #cpu-profiling

CMS and G1 Collectors: Low-Latency Garbage Collection

Understand G1 for current HotSpot deployments and CMS as a historical collector removed in JDK 14, with version-labeled examples and GC logging.

#jvm #garbage-collection #cms

Deoptimization Debugging: When JIT Compiled Code Reverts

Learn what causes the JVM to deoptimize JIT-compiled code, how to detect deoptimization events, and how to fix the underlying issues.

#jvm #jit #deoptimization