Scrivio Interview library
ConceptIntermediate6 min read · updated 12 November 2026

What is the Graal compiler, how does it plug into HotSpot, and what is its status in OpenJDK compared with GraalVM distributions?

Graal is an optimising JIT compiler written in Java that plugs into HotSpot through the JVM Compiler Interface (JVMCI, added in JDK 9), replacing C2 as the top-tier compiler. OpenJDK shipped it as an experimental JIT from JDK 10 and removed the experimental Graal JIT and AOT compiler in JDK 17, while GraalVM distributions use Graal as their top-tier JIT and as the compiler behind native image. It is known for strong partial escape analysis and inlining, and because GraalVM's release model and licensing have changed over time, we check the current vendor roadmap before planning around it.

Why this question is asked

Graal comes up whenever teams talk about native images, polyglot runtimes or squeezing more throughput out of Java. It is also often confused with GraalVM, native image and the old jaotc tool. Interviewers ask about it to see whether we can separate those pieces and know what is actually available in a standard OpenJDK build today. In this answer, we will recap HotSpot's compilers, see how JVMCI lets a Java-written compiler plug in, trace Graal's history in OpenJDK, compare that with GraalVM distributions, and look at the optimisations Graal is known for.

1A Quick Recap: HotSpot's Built-In Compilers

Standard HotSpot has two JIT compilers written in C++. C1 compiles quickly with moderate optimisation; C2 compiles slowly but produces highly optimised code using run-time profiles. With tiered compilation, code moves from the interpreter to C1 and then to C2. C2 is mature and fast, but it is large, complex C++ code that is hard to extend, which is part of what motivated a compiler written in Java.

2How Graal Plugs Into HotSpot: JVMCI

JVMCI, the JVM Compiler Interface, was added in JDK 9 (JEP 243). It is an interface through which a compiler written in Java can receive compilation requests from HotSpot, read the bytecode and profiles of the method to compile, and hand back machine code together with the metadata HotSpot needs, such as where objects are on the stack for the GC and how to deoptimise. HotSpot keeps doing everything else: the interpreter, profiling, C1, garbage collection and deoptimisation. Graal just takes the place of C2 at the top tier.

A compiler written in Java has a curious problem: it is itself Java code that needs to be compiled and warmed up. GraalVM solves this by shipping Graal precompiled as a native shared library, called libgraal, so the compiler starts fast and does not compete with the application for heap and JIT time.

Text
# OpenJDK 10 to 16 (experimental, check your version)
java -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler -jar app.jar
# GraalVM distribution: Graal is already the top-tier JIT
java -jar app.jar
Step throughHotSpot with Graal as the top tier
  1. Application bytecodethe same JARs as on any JVM
  2. Interpreter and C1start-up tiers and profiling, unchanged
  3. JVMCIinterface for compilers written in Java
  4. Graal compilertop-tier JIT in place of C2
  5. HotSpot runtimeGC, deoptimisation, code cache

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

3Graal's History in OpenJDK

OpenJDK included Graal as an experimental JIT compiler in JDK 10 (JEP 317), enabled with the flags shown above. It had arrived slightly earlier as the engine behind jaotc, an experimental ahead-of-time compiler added in JDK 9 (JEP 295). Usage of both in OpenJDK builds stayed low, and maintaining them in the JDK repository was costly, so JDK 17 removed the experimental AOT and JIT compiler (JEP 410). JVMCI itself remained, so external builds can still plug Graal in.

So on a standard OpenJDK 17, 21 or 25 build, the top-tier JIT is C2. To use Graal as the JIT, we use a distribution that ships it.

4GraalVM Distributions

GraalVM is a family of JDK distributions built on OpenJDK that include Graal. In them, Graal is the top-tier JIT through JVMCI, and it is also the compiler behind native image, which compiles an application ahead of time into a standalone executable under a closed-world assumption. GraalVM also carries the Truffle framework for languages such as JavaScript and Python on the JVM.

The packaging around it has changed several times: Community and Enterprise editions, then Oracle GraalVM under different licence terms, and changes to how GraalVM releases line up with Java releases and which products are bundled with Java SE subscriptions. There has also been an OpenJDK project, Galahad, aimed at bringing Graal JIT technology into OpenJDK. Because of all this, we check the current vendor roadmap and licence before planning a production platform around a specific GraalVM edition.

Where Graal is and is not
BuildTop-tier JITNative image
OpenJDK 9C2 (JVMCI added)no (jaotc experimental)
OpenJDK 10 to 16C2, Graal experimental by flagno
OpenJDK 17 and laterC2 (Graal removed, JVMCI kept)no
GraalVM distributionsGraal via JVMCIyes, Graal compiles it

5What Graal Is Good At

Graal is known especially for partial escape analysis. Classic escape analysis, as in C2, removes an allocation only if the object never escapes the compiled code on any path. Partial escape analysis handles the common case where the object escapes only on some paths, for example an error path: it keeps the object as plain local values on the fast path and allocates it only on the branch where it escapes. Code that creates many small temporary objects, such as streams, lambdas, iterators, Optional and boxed values, can benefit noticeably.

Graal also has an aggressive inliner that can inline through more polymorphic call sites than C2's two-type limit, and it was designed to be extended, which is why it serves as the base for Truffle language implementations. Gains depend heavily on the code: some workloads run faster on Graal, others run the same or slower than on C2, so we measure on our own services.

Java
Optional<Price> discount(Order o) {
Price p = new Price(o.total() * 0.9); // temporary object
if (p.amount() < 0) throw new BadOrder(p); // p escapes only on this rare path
return Optional.of(p); // inlined caller unwraps it immediately
}
// Partial escape analysis: on the fast path, no Price or Optional is allocated;
// the allocation happens only if the exception branch is taken

6Follow-up questions

Is Graal the same as native image?

No. Graal is the compiler. As a JIT, it compiles hot methods at run time inside a normal JVM with profiles and deoptimisation. Native image is a tool in GraalVM that uses the Graal compiler ahead of time to build a standalone executable with a closed world. The same compiler is used in two very different ways.

Why was the experimental Graal JIT removed from OpenJDK 17?

Very few users enabled it in OpenJDK builds, and keeping it in the JDK repository meant ongoing maintenance work in sync with GraalVM's own development. Users who wanted it already used GraalVM distributions. JVMCI was kept, so plugging Graal in from outside remained possible.

Does Graal replace C1 too?

In typical GraalVM configurations, C1 and the interpreter remain as the early tiers with profiling, and Graal replaces C2 at the top tier. The tiered model with profiling feeding the top-tier compiler stays the same.

7Conclusion

In this answer, we saw that Graal is an optimising JIT written in Java that plugs into HotSpot through JVMCI, added in JDK 9, in place of C2. OpenJDK offered it experimentally from JDK 10 and removed it, along with the jaotc AOT compiler, in JDK 17, keeping JVMCI. GraalVM distributions use it as the top-tier JIT and as the compiler behind native image. Its partial escape analysis and inlining help code with many temporary objects, and since GraalVM's packaging and licensing keep changing, we check the current roadmap before depending on it.

What to say in the interviewAbout 80 seconds aloud

Open with

Graal is an optimising JIT compiler written in Java. It plugs into HotSpot through JVMCI, the JVM Compiler Interface added in JDK 9, which lets a Java-written compiler receive compilation requests, read bytecode and profiles, and return machine code with the metadata HotSpot needs for GC and deoptimisation.

Then, if they want more

In that setup Graal replaces C2 as the top tier, while the interpreter, C1 profiling, the GC and deoptimisation stay HotSpot's. In OpenJDK it was available as an experimental JIT from JDK 10, enabled with UseJVMCICompiler, and the experimental Graal JIT and the jaotc AOT compiler were removed in JDK 17 because few people used them; JVMCI stayed.

So on standard OpenJDK 17, 21 or 25, the top-tier compiler is C2. GraalVM distributions are where Graal lives: it is the top-tier JIT there, shipped as libgraal so the compiler itself does not need warming up, and it is also the compiler native image uses ahead of time.

Graal is known for partial escape analysis, which can avoid allocations even when an object escapes only on a rare path, and for aggressive inlining, which helps code with lots of small temporary objects. GraalVM's editions, release model and licensing have changed several times, so I would check the current vendor roadmap before planning around it.

About this answer

Last updated
12 November 2026
Versions it names
Java 9, Java 10, Java 17
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 the Graal compiler, how does it plug into HotSpot, and what is its status in...": https://scrivio-interview-library.netlify.app/java/jit-compilation/f12d406c8d/