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

Quan Anh Mai qamai at openjdk.org
Wed Dec 25 15:06:35 UTC 2024


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.

Running tier 1 tests with this flag and `-XX:+StressGCM` reveals several failures. One example is `compiler.arraycopy.TestArrayCopyConjoint`. In the method `testByte(int, int, int)`, we have the final graph before matching:

![image](https://github.com/user-attachments/assets/6627c5c9-8408-44cb-849f-76fb4b26fd86)

`228 CastII` is a cast on `P0` has its type being `int[0, 32]`, it depends on 2 dominating ifs:
- `100 If`, which corresponds to `(P0 < 0) == false`
- `200 If`, which corresponds to `(ConvI2L(P0) u<= 32L) == true`

As a result, `228 CastII` should have its control flow being the `IfTrueNode` projection of `200 If`. However, it is incorrectly wired to the `IfTrueNode` projection of `223 If` (`P0 != 0 == true`), which leads to the verification failure.

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

PR Comment: https://git.openjdk.org/jdk/pull/22880#issuecomment-2561921798


More information about the hotspot-compiler-dev mailing list