Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

What is GraalVM native image, and what does the closed-world assumption mean for a Java application?

GraalVM native image compiles a Java application, together with the parts of the JDK it uses, ahead of time into a standalone executable that starts in milliseconds and needs much less memory. To do that, the build assumes a closed world: it analyses the program to find every class and method that can be reached, and only those are included. Anything reached dynamically, such as reflection, proxies, resources, serialization and JNI, must be declared in reachability metadata, which Spring Boot 3 generates for most of the application through its AOT processing.

Why this question is asked

Native image is one of the biggest changes to how Java can be deployed since containers arrived. A Spring Boot service that needs three seconds and 300 MB on the JVM can start in a tenth of a second with a fraction of the memory, which matters for serverless functions, command-line tools and services that scale to zero. But it does so by changing one of Java's oldest promises: that any class can be loaded at any time. Interviewers ask about the closed-world assumption because it explains both the benefits and almost every problem teams meet. In this answer, we will see how a native image is built, what the closed-world assumption means, what the analysis cannot see, what we gain and pay, and how Spring Boot 3 supports it.

1From Bytecode to a Native Executable

Normally a Java program is compiled to bytecode, and the JVM reads that bytecode at run time, loads classes as they are needed, interprets them, and compiles hot methods to machine code with its JIT compiler. Everything happens while the program runs, which is flexible but costs startup time and memory for the JVM's own machinery.

The native-image tool, part of GraalVM, moves that work to build time. It takes our classes, our libraries and the JDK classes we use, compiles them ahead of time into machine code, and links them into one executable file for a given operating system and CPU. It can also run some static initializers at build time and store the resulting objects in an image heap, so they exist the moment the program starts. The result needs no separate JVM installation.

Step throughWhat goes into a native executable
  1. Application classesour code, as compiled bytecode
  2. Librariesjars on the class path, such as Spring and Jackson
  3. Reachability metadatawhat reflection, proxies and resources need
  4. Points-to analysisfinds every reachable class, method and field
  5. Ahead-of-time compilationreachable code compiled to machine code
  6. Executablecode, image heap and a small runtime (Substrate VM)

6 layers, from the top down. Step through them one at a time.

Only what the analysis finds reaches the bottom layer.

2What the Closed-World Assumption Means

To compile ahead of time, the build has to know all the code that could ever run. So it assumes a closed world: no class that is not visible at build time will appear later. Starting from the main method, it follows every call, field access and type use to build the set of reachable code, an analysis known as points-to analysis. Code that is never reached is left out, which is a big part of why native executables are small.

Notice the consequence. On the JVM, a class that is not referenced anywhere can still be loaded at run time by name, from a plugin jar or a configuration value. In a native image, if the analysis did not find it, it is simply not there, and there is no class loader that could fetch it from a jar later.

3What the Analysis Cannot See

The analysis follows ordinary calls easily. It struggles with anything where the target is decided at run time: reflection, dynamic proxies, resources loaded by name, Java serialization and JNI calls into native code.

Java
// Seen: a plain call, the analysis follows it
new Invoice().total(); // included
// Seen: a constant class name is folded at build time
Class.forName("com.shop.Invoice"); // included
// Not seen: the name only exists at run time
String name = System.getenv("REPORT_CLASS");
Class<?> c = Class.forName(name); // ClassNotFoundException unless declared
// Not seen: a resource found by name
getClass().getResourceAsStream("/templates/invoice.html"); // null unless declared

For these cases we give the build reachability metadata, a set of JSON files under META-INF/native-image in a jar, which list the classes, methods, resources and proxy interfaces that must be included and made available for reflection. The exact file names and format have changed across GraalVM releases, so check your version. Many popular libraries ship their own metadata, and a shared repository, the GraalVM reachability metadata repository, covers others. A tracing agent can also watch the application on a normal JVM and write the metadata it observed.

4What We Gain and What We Pay

The gains are large in the right place. Startup drops from seconds to tens of milliseconds, because there is no class loading, no bytecode verification and no JIT warmup. Memory use is lower, often by half or more, because there is no JIT compiler, no class metadata for unused classes and no bytecode to keep around.

The costs are real too. Builds take minutes and gigabytes of memory instead of seconds. Peak throughput can be lower than a warmed-up JIT, unless we use profile-guided optimisation, which is available in Oracle GraalVM. Libraries that generate bytecode at run time or use reflection heavily need metadata or do not work, and we must test the native executable itself, because behaviour can differ from the JVM where metadata is missing.

JVM compared with native image
AspectJVM (JIT)Native image
StartupSeconds for a Spring serviceTens of milliseconds
MemoryJIT, metadata, code cacheMuch lower
Build timeSecondsMinutes, high build memory
Peak throughputHigh after warmupLower without PGO
Dynamic class loadingAny class, any timeOnly what the build included
TestingNormal testsAlso native tests

5Native Images in Spring Boot 3

Spring relies on reflection and proxies everywhere, so on its own it would need a mountain of metadata. Spring Boot 3 solves this with AOT processing at build time: it starts the application context in a special build step, works out the bean definitions, and generates plain Java code that creates those beans directly, together with the reachability metadata Spring itself needs. The native image then contains this generated code instead of the reflective startup path.

Text
# Maven with the native profile from the Spring Boot parent
./mvnw -Pnative native:compile # target/orders, a native executable
./target/orders # Started OrdersApplication in 0.08 seconds (example)
# Or build a container image with Cloud Native Buildpacks
./mvnw -Pnative spring-boot:build-image
# Gradle with the GraalVM native plugin
./gradlew nativeCompile

Notice that AOT processing also fixes some choices at build time, such as which beans exist and which profiles are active when the context is evaluated, because the closed world applies to the bean graph too. Application code that uses reflection or loads classes by name still needs its own hints, which Spring lets us provide through the RuntimeHints API.

6Follow-up questions

Is native image the same as the JDK AOT cache?

No. The AOT cache keeps the normal JVM and stores loaded and linked classes and profiles to start faster; everything dynamic still works. Native image replaces the JVM with an ahead-of-time compiled executable under a closed-world assumption. It starts much faster but needs metadata for dynamic features and native testing.

Why does a native image use less memory?

It carries no JIT compiler, no class files or class metadata for unused code, and a smaller runtime. Objects created at build time live in the image heap, which is mapped from the executable. The garbage-collected heap still exists, so a service with large data still needs memory for that data.

Can a native image load a plugin jar at run time?

Not in the usual way. There is no class loader that can bring new bytecode into the image, so plugins must be known at build time and compiled in. That is the closed-world assumption at its most visible.

7Conclusion

In this answer, we saw that GraalVM native image compiles an application and the JDK parts it uses ahead of time into a standalone executable. Its closed-world assumption means build-time analysis includes only the code it can reach, so reflection, proxies, resources, serialization and JNI must be declared in reachability metadata. The payoff is fast startup and low memory, at the cost of long builds, native testing and no loading of unknown classes, and Spring Boot 3 makes it practical through AOT processing that generates code and metadata for the application context.

What to say in the interviewAbout 80 seconds aloud

Open with

GraalVM native image takes my application, the libraries and the parts of the JDK that are actually used, and compiles them ahead of time into a single native executable.

Then, if they want more

There is no JVM at run time, no class loading and no JIT warmup, so a Spring Boot service can start in tens of milliseconds and use much less memory.

To compile everything ahead of time, the build makes a closed-world assumption: it assumes all code that can run is visible at build time, and it does a points-to analysis from the main method to find every reachable class, method and field. Anything it does not find is not in the executable.

That is why dynamic features need reachability metadata: reflection, dynamic proxies, resources loaded by name, serialization and JNI. Many libraries ship this metadata, and there is a tracing agent that records it from a JVM run.

The trade-offs are long builds with high memory, lower peak throughput unless you use profile-guided optimisation, and the need to test the native binary itself.

In Spring Boot 3, AOT processing runs at build time, evaluates the bean definitions, generates Java code to create the beans and the metadata Spring needs, so for most applications only custom reflection needs extra hints.

About this answer

Last updated
12 November 2026
Versions it names
Spring Boot 3
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What is GraalVM native image, and what does the closed-world assumption mean for a Java...": https://scrivio-interview-library.netlify.app/java/startup-and-footprint/ac47d13837/