RFR: 8346836: C2: Introduce a way to verify the correctness of ConstraintCastNodes at runtime

Emanuel Peter epeter at openjdk.org
Wed Jan 8 07:26:36 UTC 2025


On Wed, 25 Dec 2024 14:54:02 GMT, Quan Anh Mai <qamai at openjdk.org> wrote:

> Hi,
> 
> This patch adds a develop flag `VerifyConstraintCasts`, which will verify the correctness of `CastIINode`s and `CastLLNode`s at runtime and crash the VM if the dynamic value lies outside the type value range.
> 
> Please take a look, thanks a lot.

Looks interesting :)

Would we have caught any bug with this, do you have an example?

If I remember correctly, we relax/widen the Cast ranges somewhere later in optimizations, so that different CastII etc can common. Probably happens after loop-opts. So the ranges usually go from `[1..10]` -> `[0, max]` or `[-1 .. 1]` -> `int`. So this verification would then not be super effective, right? Things might have gone wrong much earlier with bad assumptions. I mean it could still catch issues, but I'm not sure how likely that is?

TLDR: I'd like some more context / motivation for this patch ;)

And: you should have at least one plain test where you enable the flag, and it compiles everything required to run an empty `main` function.

Ah, I actually see that you have some examples. So you plan on introducing this flag first, and only then fixing the issues? But does it fail with a simple `java --version`? Or an empty `main` method, maybe with `-Xcomp`?

-------------

Changes requested by epeter (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/22880#pullrequestreview-2536189779
PR Comment: https://git.openjdk.org/jdk/pull/22880#issuecomment-2576918982


More information about the hotspot-compiler-dev mailing list