Java's AOT cache can crash your JVM on older CPUs
Java's new AOT cache feature is in a rough state
The JDK's AOT cache promises faster startup by recording a training run and replaying it, but XPipe found it generates CPU-specific adapter code that crashes the JVM with SIGILL on machines lacking features like AVX-512. The fix, -XX:-AOTAdapterCaching, is undocumented and off by default only in name. JDK 27 adds CPU feature checks, but JDK 28's exact-match requirement may make AOT code useless for distributed apps.
So essentially a free startup boost, but only under certain conditions, and with free crashes included.
- lazystone
> In theory, the whole AOT cache idea sounds like something that should only affect the class data and not perform any native compilation
> Non-Goals
> It is not a goal to support cross-compilation. Code compiled in a training run must run on the same CPU architecture, with the same set of features, in subsequent production runs.
- pron
For the past several years, Java features are released piecemeal, with each piece released as soon as it can be useful to some significant portion of users or users who can offer useful feedback (and when it's not expected to restrict future pieces). The AOT cache is already used in production despite not being as user-friendly as it could be, because the companies using it find it valuable.
The first use case is the very common one (for Java) where developers control deployment (internal deployment). The last basic building block, caching machine code, will be released next year in JDK 28, and then the feature is likely to evolve to better support other use cases, such as external deployment.
- pjmlp
Note this is all about OpenJDK and Project Leyden.
There are plenty of other AOT/JIT cache approaches in the Java ecosystem already, with more mature deployment experience of several years, namely:
OpenJ9, Azul, PTC, Aicas, the Android cousin since Android 7
Technology based on process snapshots CRaC for Amazon OpenJDK distro (Correcto), and OpenJ9, is also another approach available for some time.
- deepsun
> What would be needed is some sort of compatibility switch that disables all optional CPU features. Sure, you will get some reduced performance of the compiled code, but in exchange, a faster startup time.
I think other AOT-compiled languages don't opt in for the lowest set of CPU features -- they just detect them at runtime and use whenever present, all in compiled machine code.
- _old_dude_
The Inside Java podcast episode on AOT caching covers the issue in this segment: