🔸 TL;DR
JEP 544 extends Project Leyden by storing optimized native code in Java's Ahead-of-Time (AOT) cache.
Previously, JEP 483 cached loaded/linked classes, and JEP 515 cached method profiles.
Now, JEP 544 also caches compiled CPU instructions, reducing startup and warmup overhead while preserving JIT flexibility.
Let's explore the architecture in 4️⃣ BEFORE vs AFTER changes!
🔸 1️⃣ AOT CACHE: FROM METADATA TO NATIVE CODE
▪️ BEFORE: The AOT cache stored loaded/linked classes and method profiling data.
▪️ AFTER: It additionally stores optimized native machine code for selected methods.
What is native code?
CPU instructions generated from Java bytecode by HotSpot's compilers, executable directly by an x64 or AArch64 processor.
Unlike .class bytecode, these instructions no longer need interpretation or JIT compilation before execution.
Architecture:
💡 This is not a standalone native executable like GraalVM Native Image. HotSpot still manages execution.
#AOTCache
🔸 2️⃣ C1/C2: FROM RUNTIME TO AOT COMPILATION
▪️ BEFORE: C1/C2 compiled hot methods into native code during application execution. This code was lost when the JVM stopped.
▪️ AFTER: The existing C1/C2 compilers can also generate native code during AOT cache creation.
What do C1/C2 actually do?
▪️ C1: Quickly translates Java bytecode into machine instructions with lightweight optimizations.
▪️ C2: Performs advanced optimizations such as method inlining, type specialization and dead-code elimination.
During AOT creation, HotSpot uses profiles captured during a training run to select and optimize methods, then saves their compiled code.
Architecture:
💡 No new compiler! Existing HotSpot compilation technology is reused ahead of production execution.
#JITCompiler
🔸 3️⃣ HOTSPOT: FROM JIT WARMUP TO CODE REUSE
▪️ BEFORE: HotSpot interpreted bytecode and progressively compiled hot methods through JIT during startup and warmup. Cached profiles could accelerate this process.
▪️ AFTER: HotSpot can immediately reuse compatible native code from the AOT cache, avoiding repeated compilation for those methods.
What happens when the workload changes?
HotSpot can still deoptimize cached code and invoke C1/C2 to generate new optimized instructions.
Architecture:
💡 AOT accelerates execution; JIT preserves runtime adaptability.
#HotSpot
🔸 4️⃣ DEPLOYMENT: SAME JAR, EXTERNAL AOT CACHE
▪️ BEFORE: A Java application ran from its JAR, optionally using an AOT cache containing classes and profiles.
▪️ AFTER: The JAR remains unchanged, while the external AOT cache can additionally contain native machine code.
Where is app.aot stored?
It is a separate binary file, NOT embedded inside the JAR.
Architecture:
Generate the cache:
Run in production:
The relative path creates or locates app.aot in the current working directory. It can be packaged alongside the JAR inside a Docker image.
⚠️ Reusing AOT native code requires compatible CPU features and the same garbage collector between training and production.
💡 No new container format, no bytecode changes, no application rewrite!
#JavaDeployment
🔸 TAKEAWAYS 🎯
▪️ AOT CACHE: Now stores native CPU instructions alongside classes and profiles.
▪️ C1/C2: Existing compilers additionally generate reusable code during AOT cache creation.
▪️ HOTSPOT: Executes cached optimized code sooner, with JIT available for changing workloads.
▪️ DEPLOYMENT: Same JAR, external .aot file containing the new compiled code.
▪️ PERFORMANCE: JEP 544 benchmarks report 65 to 80% shorter startup times with AOT code enabled on five framework applications, compared with no AOT cache.
The innovation is not a new compiler or a new Java binary. It is moving compilation work out of production startup and reusing its results across JVM executions!
💬 Would you add an AOT cache to your Java microservices deployment?
https://openjdk.org/jeps/544
#Java #Java28 #JEP544 #ProjectLeyden #JVM #AOT #JIT #HotSpot #JavaPerformance #OpenJDK #JavaArchitecture #Microservices #Docker #SoftwareEngineering
Go further with Java certification:
Java👇
https://bit.ly/javaOCP
Spring👇
https://bit.ly/2v7222
SpringBook👇
https://bit.ly/springtify
JavaFullstackBook👇
https://bit.ly/jfstack27