I use buildpack that takes care of training run, building the docker image and runtime arguments. I have never seen the issues that you mentioned on the article.
It depends on the context. With docker images, your environment is more stable compared to an application that is run in a user's own environment. With the crashes, they don't occur for a lot of users, only those that have more exotic types of CPUs. I wasn't aware initially as well about this, only after some users reported those issues to me
The JDK generated assembly that is not supported on all CPUs by default while not mentioning this anywhere in the JEPs or docs. The AOT cache feature is not advertised a feature that even does native code generation. The main parts of it is class-related data
That’s literally how the JIT has always worked. It has always generated architecture specific instructions. It’s like half of the point of using a jit compiler.
I'm not sure what you're trying to say, but the AOT cache caches JIT output; it is, intentionally, not an AOT compiler. Yes, the JIT could be configured differently in the training run, but that's another matter.
Are we talking about the AOT cache in general or the AOT code cache? Also are we talking about general JIT data or actual natively compiled code? At least this original JEP 483, this is not mentioned.
The follow-up JEPs like 515 talk about JIT, but not the native compilation part, which that guy was most likely talking about. So technically there is probably some JIT output, but no native output.
I am no expert on the exact names for everything, but by saying JIT output, I was taking https://openjdk.org/jeps/515 into account where the cache can contain information for the JIT compiler from the training runs to instruct it what to compile instantly. So I counted things like generated JIT profiles as JIT output.
I was talking about the code cache. The problem with the adapters may well be a bug (the JVM shouldn't crash). Newer features are far more likely to have bugs, including serious ones, than older features.
All runs must use the same JDK release and be on the same hardware architecture (e.g., x64 or aarch64) and operating system.
I guess this isn't what you mean by "The JDK generated assembly that is not supported on all platforms by default while not mentioning this anywhere in the JEPs or docs."?
edit: ok I see you saying elsewhere that the problem also occurs when e.g. disabling AVX
I updated my message to explicitly mean "CPU features" instead of platform. The post never was about CPU architectures, that word is also never used in my blog post. It is about individual CPU features like AVX
How the fuck do you think they produce an AOT cache? Jesus Christ man. It’s Java. Do you think that this stuff doesn’t have to do with the JIT compiler? Why do you think you need to do training runs instead of just running a command ahead of time? Connect it together man.
Ya know I shouldn’t be surprised with the lack of thought in 2026 software engineering but it keeps happening.
I don't think you are right in the way you think you are or at least he is not wrong in the way you think he is.
He is pretty clearly talking about phase 2 JIT optimization (or whatever it's called), which is actually native, not being cached. And if you would have been a smidge more charitable, it's pretty clear what he is talking about when he says "it has nothing to do with JIT".
His mistake (other than not reading the manual) is just thinking that the JVM class metadata is platform agnostic, because it doesn't include the native code, which is pretty reasonable.
First, new features tend to have rough edges and more bugs than established ones.
Second, the matter of shipping the AOT cache can well have two modes that are reasonable in different situations. For internal deployment to a cloud, there's more value in shipping the cache, and because you control the deployment environment, it will probably work well. When it comes to shipping a binary to external users, it may well be that the approach to aim for is not to ship the cache, and have the program's startup automatically and transparently improve from one run to the next.
Third, on the matter final field mutation, the intention is for the JDK to rely on that (and for the warning to become an error). So the option of getting a warning and AOT working is a temporary and unintended side-effect.
In general, there's is and has always been a fundamental tension between using anything that's AOT and dynamism (and it's not specific to Java; that's the case in all languages). The point of the feature is to allow you to choose between them, and it might be not a binary choice but a point on a spectrum, but you can't have both applied to their maximum at the same time. For example, you could have the JDK optimise things based on the assumption that fields that should not change indeed do not change or you can choose to have your program change them nevertheless, but you can't have both the dynamic change and the optimisation that depends on that not occurring at the same time.
I wouldn't call it that new anymore, it has been out for 1.5 years already. Plus the new JDK feature release model where features are only included when they are supposed to be ready. I would at least expect the rough edges to be gone 1.5 years after a feature is designated as ready for full release.
About not shipping the cache when dealing with user environments, I don't think that is the vision behind the feature. There aren't technical reasons why this can't be done if it is implemented correctly. Without the CPU feature dependency (not CPU architecture as some people in here misinterpreted) issue which hopefully will get fixed properly at some point and better docs, this can be done without any downsides. Even the JDK28 AOT code cache could be done properly with some compatiblity switch to disable optional CPU features like other native compilation tasks can do.
About the final field mutation, I don't see the explicit need why this disables AOT class linking. If someone does this during class loading or with a static field or something like an interned String, I can see the issues. But that would be at your own risk and only a very rare case. And that is what the warning is for to tell you that it's dangerous. It's just annoying for the majority of people affected by it who can't disable the warning in this transition phase, even if it is their judgement that this is acceptable behaviour for now. I wouldn't do final mutations at all, it's always some dependencies doing that.
I would at least expect the rough edges to be gone 1.5 years after a feature is designated as ready for full release.
We can argue over whether this is reasonable or not, but language and API features preview for two years on average before they're made permanent, and having rough edges and not being production ready are two very different things. Companies are using the AOT cache in production, even though it's perhaps not as easy as it could be, because they're pleased with the results.
this can be done without any downsides
Not quite. You either have to cater to the lowest feature-set in each architecture (giving up on peak performance) or to ship a bigger cache.
like other native compilation tasks can do.
They do this by either generating a bigger binary or aiming for the lowest common feature set at the expense of peak performance, not "without any downsides".
But even if one or both of these downsides is acceptable, that doesn't mean we should do it, because there may be better options. AOT-compiled languages have to do something like this because it impacts their ability to run at all as well as their performance. In Java, it only impacts warmup, i.e. you'd have to sacrifice either cache size or peak performance just to save warmup time on the first run only. Is that really what we should be aiming for? I'm not saying it definitely isn't, but it's not obvious that it is.
But that would be at your own risk and only a very rare case.
I'm not aware of any language that intentionally allows miscompilation, breaking its own spec, even in the rarest of cases, certainly not by default, because miscompilation is probably the hardest bug to debug. Not to mention that the more optimisations we add to the compiler that depend on this, the less rare miscompilation is going to be.
Now, it is hypothetically possible to have a feature that allows opting into this risk, but the number of users who would accept the risk of miscompilation just to save on warmup is probably very low, and I don't think that working on a feature for a tiny portion of users at the expense of the majority of users is a good choice.
The whole point is that in Java we have more optimisation opportunities, and more tradeoffs to play with, than with languages that rely on AOT. We should take advantage of that, not do something only because more constrained languages need to do it.
And that is what the warning is for to tell you that it's dangerous.
No, the warning is merely there to prepare users for when this becomes an error. The warning even states that.
who can't disable the warning in this transition phase
Why can't they disable the warning? And if they can't, their program won't run at all on a future runtime. Again, a future runtime won't make this work despite the risk; it will refuse to run programs that don't declare their final field mutation at all.
We can argue over whether this is reasonable or not, but language and API features preview for two years on average befoer they're made permanent, and having rough edges and not being production ready are two very different things. Companies are using the AOT cache in production, even though it's perhaps not as easy as it could be, because they're pleased with the results.
If those edges would be documented better I wouldn't have written that post. I would say that is the main area of improvement I would like to see, ideally on the initial release of a feature.
Not quite. You either have to cater to the lowest feature-set in each architecture (giving up on peak performance) or to ship a bigger cache.
If those options would exist (plus no native compilation at all like the JDK24 AOT did), then that would be fine. Then everyone could choose the smallest downside for their app. But right now that isn't there.
Even the JDK28 AOT code cache could be done properly with some compatiblity switch to disable optional CPU features like other native compilation tasks can do.
The downsides part wasn't really meant for the JDK28 part. So yes, that is true. But if I see that correctly, a compatbility switch is also not possible or even planned. That is what I meant by done properly, these options could be exposed like in other tasks.
In Java, it only impacts warmup, i.e. you'd have to sacrifice either cache size or peak performance just to save warmup time on the first run only. Is that really what we should be aiming for? I'm not saying it definitely isn't, but it's not obvious that it is.
True, if the AOTCache option handling for the actual cache file would be improved, that could also be done. But right now, putting the newly generated AOT cache on the target system into the right spot, also considering readonly dirs, isn't straightforward. There is no default file path. You can't use absolute paths on a user's target system. You can pass a relative file path but only relative to the working directory. And if the installation dir is read-only or you lack permissions, you can't generate an AOT cache where you want. And using other env vars is also not possible for the -XX:AOTCache file. So I don't see how this can be reliably done.
Now, it is hypothetically possible to have a feature that allows opting into this risk, but the number of users who would accept the risk of miscompilation just to save on warmup is probably very low, and I don't think that working on a feature for a tiny portion of users at the expense of the majority of users is a good choice.
But I don't see why the sheer presence of the option to disable a warning for final field mutation (or do some illegal native access, same thing) preemtively disables AOT class linking, at least in the transition phase while this is still a warning. This is the point I am on about in case we are not talking about the same thing here. Like nothing changes other than the warning being printed. I can still do the same operation. This feels just like a sort of negative incentive to fix your final field mutations in your app while preparing for the removal of this option. Which I understand, yet the only thing it does it being annoying in cases you can't fix it yourself and depend on something else.
No, the warning is merely there to prepare users for when this becomes an error. The warning even states that.
Yes you are correct, my mistake.
Why can't they disable the warning?
You can't disable the warning because that disables the AOT class linking (I mean you can disable the warning, you just lose the optimizations). I want to have the JVM option for production. I can't change JVM args for the training runs because that will disable the AOT cache if the args differs from the production args.
If those options would exist (plus no native compilation at all like the JDK24 AOT did), then that would be fine. Then everyone could choose the smallest downside for their app. But right now that isn't there.
I get what you're saying, but offering every option that any user may want is sometimes not the best thing to do, because you end up spending time catering to a small group at the expense of a larger one. Rather than just offering all options, we'd rather weigh which use patterns make the most sense for most people.
That is what I meant by done properly, these options could be exposed like in other tasks.
That's one possibility, but doing things properly could also mean not doing that but doing something else. There may be better options than bundling some cache that compromises something with your binary.
But right now, putting the newly generated AOT cache on the target system into the right spot, also considering readonly dirs, isn't straightforward.
Yes, but Leyden isn't done yet. Because many Java apps are server apps, the first use cases to choose to tackle are naturally those where the developers do control the deployment. Again, the AOT cache is already used in production by happy users. Not all use cases are covered yet because we're not done.
But I don't see why the sheer presence of the option to disable a warning for final field mutation (or do some illegal native access, same thing) preemtively disables AOT class linking
I don't think you need to see it unless you're a JDK developer. The lack of these flags means that the JDK can trust that certain things that could break certain assumptions don't happen.
You can't disable the warning because that disables the AOT class linking (I mean you can disable the warning, you just lose the optimizations).
The problem here is that the optimisation "works" when the warning is not disabled not that it doesn't work when the flag is present. This will be fixed when the warning becomes an error.
I get what you're saying, but offering every option that any user may want is sometimes not the best thing to do, because you end up spending time catering to a small group at the expense of a larger one. Rather than just offering all options, we'd rather weigh which use patterns make the most sense for most people.
I mean it's not about offering every option, just open at least multiple possible directions to weigh between compatibility and performance. Because right now I only see focus on one (also for AOT features still in development). Of course, you will have more people running Java backend applications on their own internal infrastructure. But there is also a long tail of applications out there that do not follow that pattern.
Yes, but Leyden isn't done yet.
Yes, but same thing as before, I don't see the focus being put on more exotic workflows at all to improve those kinds of issues. Right now, you can't reliably generate the AOT cache later for any kind of desktop application, CLI, or anything that does not run on a server. Simply because of the limited argument handling capabilities of the AOTCache JVM argument.
I don't think you need to see it unless you're a JDK developer. The lack of these flags means that the JDK can trust that certain things that could break certain assumptions don't happen.
Ok that is a good point, I wasn't aware of that. Still, a proper documentation page that would have listed those options, and I wouldn't have to ask about this. Effects like this should be listed somewhere and ideally explained with one short sentence.
In general, what I would like to see the JDK team take away from this is that they should write proper documentation for new features like the AOT cache for the release. A JEP does not count as a full documentation, more like an introduction. The aot log messages can also be made more self-documenting, but a proper reference for everything would be the best.
just open at least multiple possible directions to weigh between compatibility and performance
Or perhaps do something even better. Offering more knobs is not always better than offering just the right ones.
But there is also a long tail of applications out there that do not follow that pattern.
Of course, and we'll need to find the best features to address that use case. I'm just saying that offering all options is not obviously the best thing to do for that use case.
I don't see the focus being put on more exotic workflows at all to improve those kinds of issues.
Because the more basic features aren't done yet! The last of the basic building blocks is yet to be delivered. Let's deliver that, see how people use it, find the next biggest problem to solve, and only then try to find the best solution to that problem.
As you know, this is how we deliver features: in small increments. Every increment may make the feature useful to a larger group of people.
Effects like this should be listed somewhere and ideally explained with one short sentence.
Maybe (and sometimes we're not perfect), but it's important to understand that our primary job isn't to explain to Java users why we've made every technical decision (most aren't interested), but to deliver the features that ultimately create the greatest value for the greatest number; in other words, to deliver the product that makes most people happy.
As long as the JDK developers understand why they should be doing X instead of Y, they have what they need to deliver the right product. That every Java developer understands the reasoning behind every decision could be a nice bonus, but it's not essential for the main job.
But right now, putting the newly generated AOT cache on the target system into the right spot, also considering readonly dirs, isn't straightforward.
I think all three platforms worth talking about effectively offer the equivalent of %LOCALAPPDATA%, and the application author is within their right to just give up if that path does not work. If you have a launcher script I don't see how this is an issue, and if you don't have a launcher script I don't see how this is the bigger issue.
In fact, that seems to me like the ideal scenario. I've used CDS into AOT in production in read-only environments for multiple years, and while it's reliable and effective, having to distribute a static frozen cache alongside the application means the capacity for optimization is really limited. In a maybe-writable environment I could just ignore the optimization on the first run for a negligible delay in responsiveness (consider: users are launching entire web browsers just to edit text files), then on the second run automatically have a much better profile or, alternatively, not, in which case, whatever.
The main problem is not finding a suitable location, it is about telling the JVM about this location. The AOTCache option does not support env vars or anything useful. If you ship an application, the launcher code that starts the JVM is also usually fixed. You can in theory create a launcher script that dynamically determines the dir, but for something like jpackage that is not possible.
Alright that is technically correct, I should have used that title instead to prevent misunderstandings. I don't think that I can change the title in reddit though
I think you misunderstand the point of the AOT cache (not AOT compilation) in the context of the JDK. The AOT cache (and CDS before) is not envisioned as shipping native code and introducing CPU feature (not CPU arch) dependencies in the JEP, all ahead-of-time optimizations should be designed for the class data. Therefore, if you read the JEPs and use the feature how it is described, this is unexpected behaviour.
The will be another addition for JDK28 that is actually supposed to ship native code, but that is not related to this.
CPU architecture usually refers to something like x86_64 or aarch64. That description is not correct as the AOT cache is also dependent on individual CPU features like AVX support. That is the point of the blog post. You can even run one app on two of the exact same CPUs, disable AVX on one, and it will still crash. At least in JDK25, the JDK27 release changed the handling. But most people are probably still not on JDK27.
The point that this manpage entry is trying to make is that you shouldn't put an AOT cache made on Windows x64 on a Linux aarch64 machine, which is obvious as there are probably some class data that is different for each combination. Not that there is native code in the AOT cache.
I don’t think I misunderstand. Any reasonable reading of these features would expect native assembly or architecture specific optimizations to be produced. It honestly seems like you’re the one who didn’t understand since you shipped incompatible assembly to your users.
Of course. But fwiw software engineers should generally test their applications, understand the things they’re shipping, and take responsibility when they fuck up instead of blaming it on other people.
Just to clarify, we are talking about https://openjdk.org/jeps/483 . If you read through that, you will see that this is not about native compilation at all. It is just a more advanced implementation of CDS, which also never dealt with native code. The JEP clearly explains what it should and shouldn't do, and none of things even mentioned is native compilation.
You mean the jep that clearly states it needs to be on the same hardware architecture? You’d think that would have something to do with native instructions if you thought for just a minute.
Look man you’re wrong, you shipped broken shit to your users. Take some responsibility
Hardware architecture != CPU features. The blog post is about individual CPU features causing crashes, not hardware architecture. It never used that word
The note about the hardware architecture is primarily meant so that you don't generate the cache on a Linux x86_64 system and then put it on a Linux aarch64 system, which is reasonable as the JDK implementations on those systems have different class data. It is not related to native code.
Native compilation of your application is not the only reason for the cache do be platform dependent. The class metadata is also platform dependent. JEPs don't mention it, nor do they mention the need for training runs to be performed on the target platform, it's just assumed.
JEPs are not docs. If you really want to know how to use something and how something works, then you should read the docs. If you want to know how the feature came around, then you should read the JEPs.
When you say platform dependent, do you interpret platform as the exact system with the exact same CPU (not just architecture)? My whole point is that even small differences in the CPU feature support like AVX can cause crashes, even if the "platform" is the same like Linux x86_64.
Stuff like AVX is quite literally considered part of the architecture when talking about CPUs. Specifically it’s usually referred to as the microARCHITECTURE.
Technically yes, but if you didn't know about these issues beforehand, you wouldn't interpret this statement as also including CPU features as CPU arch is usually used in a more informal manner. Especially in the context of Java where it is usually about x86_64 or aarch64.
Still, I can have the same CPU with the same CPU microarch, and still get crashes by having a certain CPU feature disabled in for example the Linux kernel with something like clearcpuid or in the BIOS.
Hi, For what it's worth, in the interested of preventing what looks to me like gaslighting, I think milchshakee you are mostly right, vips7L blazmrak and oelang are acting in bad faith. However the initial tone of the blog post was too negative which is probably what invited these reactions (the frustration from the aot experience is legitimate but sharing it in this way was actually detrimental to improving the underlying system)
Project Leyden is just AppCDS 2.0: a pile of hacks bolted into the JDK, with no spec. It has worse usability and worse startup numbers than the alternatives (see Project Crema below).
The alternative is Project Crema, from the Graal team. It augments Native Image with runtime class loading and provides a "smooth slider" so developers can "gradually" choose which parts of the application are AOT-compiled and which remain dynamic.
Code and classes loaded at runtime use Graal as a JIT, and Truffle languages also support runtime compilation. Its startup numbers have always been much better than Leyden's, and Crema doesn't require training runs or cache management. The developer distributing the application (the one who cares) is responsible for packaging it properly.
Crema also enables a FAST development mode. The JDK and frameworks (Micronaut/Spring/Quarkus) are AOT-compiled once, and only the user code is JIT-compiled at runtime. No AOT rebuild is needed during development. Finally, Crema is a HotSpot-less JVM written entirely in Java.
*Disclaimer: I used to work on the Graal team and wrote the runtime class loading and dynamic bits behind Project Crema as it exists today. It's all written in Java. Beautiful.
> You will run into the consequences of this if your training system supports something like AVX, and the running system does not (or not to the same level, like no support for AVX-512, which corresponds to the JDK's -XX:UseAVX=3 level). Because then, your JVM will crash with:
This looks like an oversight. AOT cache should contain required CPU features and native code from that AOT should not be used on incompatible CPU.
Meh, I think it should just crash more gracefully: "AOT cache requires CPU missing feature X, aborting". It must be clear that the AOT cache can't be used.
When using AOT from OpenJ9, this is indeed the case, you can chose between more conservative machine code for portability, or similar to the machine that the JIT cache was generated on.
As mentioned on other replies, this is specific to OpenJDK only, other JVMs have better options already.
Alternatively, Java AOT was designed just like .NET AOT. Training run happens AFTER installation, not before, therefore incompatible jre or processor is non-issue.
what kind of startup gains were you actually seeing when it did work? unless youre running short-lived serverless functions, the extra build pipeline complexity usually outweighs saving a couple seconds on boot
It is actually for user-facing GUI and CLI applications. When users run those often, they will feel a difference of 0.5s in startup. The gains are completely dependent on the user's system, but I would estimate it reduces the startup time of the application by 50% when all optimizations are enabled
This is a great post, thanks! It's very useful to see where the user's frustrations are, as those are typically quite opaque to those of us who use these systems every day and are much more intimately familiar with them.
21
u/gtiwari333 Oct 26 '26
I use buildpack that takes care of training run, building the docker image and runtime arguments. I have never seen the issues that you mentioned on the article.
18
u/pron98 Oct 26 '26
First, new features tend to have rough edges and more bugs than established ones.
Second, the matter of shipping the AOT cache can well have two modes that are reasonable in different situations. For internal deployment to a cloud, there's more value in shipping the cache, and because you control the deployment environment, it will probably work well. When it comes to shipping a binary to external users, it may well be that the approach to aim for is not to ship the cache, and have the program's startup automatically and transparently improve from one run to the next.
Third, on the matter final field mutation, the intention is for the JDK to rely on that (and for the warning to become an error). So the option of getting a warning and AOT working is a temporary and unintended side-effect.
In general, there's is and has always been a fundamental tension between using anything that's AOT and dynamism (and it's not specific to Java; that's the case in all languages). The point of the feature is to allow you to choose between them, and it might be not a binary choice but a point on a spectrum, but you can't have both applied to their maximum at the same time. For example, you could have the JDK optimise things based on the assumption that fields that should not change indeed do not change or you can choose to have your program change them nevertheless, but you can't have both the dynamic change and the optimisation that depends on that not occurring at the same time.
10
u/pjmlp Oct 26 '26
This is not "Java's new AOT cache feature", rather "OpenJDK's new AOT cache feature".
Folks really should learn about Java ecosystem, there are other JIT cache implementations, with their own plus and minus.
OpenJ9, Azul, PTC, Aicas, and the Android cousin, with GraalVM, PTC and Aicas for classical AOT as well.
6
u/vips7L Oct 26 '26
No fucking shit? AOT compilation ships native code?!
26
u/SleeperAwakened Oct 26 '26
Everybody who has used a cache knows that getting it right is hard.
I can only imagine the complexity for the JDK.
5
u/mukel90 Oct 27 '26 edited 29d ago
Project Leyden is just AppCDS 2.0: a pile of hacks bolted into the JDK, with no spec. It has worse usability and worse startup numbers than the alternatives (see Project Crema below).
The alternative is Project Crema, from the Graal team. It augments Native Image with runtime class loading and provides a "smooth slider" so developers can "gradually" choose which parts of the application are AOT-compiled and which remain dynamic.
Code and classes loaded at runtime use Graal as a JIT, and Truffle languages also support runtime compilation. Its startup numbers have always been much better than Leyden's, and Crema doesn't require training runs or cache management. The developer distributing the application (the one who cares) is responsible for packaging it properly.
Crema also enables a FAST development mode. The JDK and frameworks (Micronaut/Spring/Quarkus) are AOT-compiled once, and only the user code is JIT-compiled at runtime. No AOT rebuild is needed during development. Finally, Crema is a HotSpot-less JVM written entirely in Java.
*Disclaimer: I used to work on the Graal team and wrote the runtime class loading and dynamic bits behind Project Crema as it exists today. It's all written in Java. Beautiful.
8
u/Scf37 Oct 26 '26
> You will run into the consequences of this if your training system supports something like AVX, and the running system does not (or not to the same level, like no support for AVX-512, which corresponds to the JDK's
-XX:UseAVX=3level). Because then, your JVM will crash with:This looks like an oversight. AOT cache should contain required CPU features and native code from that AOT should not be used on incompatible CPU.
1
u/Puzzled-Comb1369 17d ago
what kind of startup gains were you actually seeing when it did work? unless youre running short-lived serverless functions, the extra build pipeline complexity usually outweighs saving a couple seconds on boot
4
u/Life_Sink9598 Oct 26 '26
This is a great post, thanks! It's very useful to see where the user's frustrations are, as those are typically quite opaque to those of us who use these systems every day and are much more intimately familiar with them.