RFR: 8323682: C2: guard check is not generated in Arrays.copyOfRange intrinsic when allocation is eliminated by EA
Tobias Hartmann
thartmann at openjdk.org
Mon Mar 25 14:43:22 UTC 2024
On Mon, 25 Mar 2024 13:28:32 GMT, Daniel Lundén <dlunden at openjdk.org> wrote:
> The library intrinsic `_copyOfRange` does not add a guard for start indices that are larger than the length of the source arrays. Macro expansion of `ArrayCopy` nodes later adds such a guard, but in certain situations escape analysis may result in removing the `ArrayCopy` node before it is expanded. The result is incorrect behavior of the compiled program (as the missing guard may have relevant side effects, such as throwing an exception).
>
> ### Changeset
>
> - Add the missing guard (start index <= source array length).
> - Remove an unnecessary guard (end index >= 0) that holds as a result of the other guards. The updated set of guards then more closely follows the `copyOfRange` [Java API documentation](https://docs.oracle.com/en/java/javase/22/docs/api/java.base/java/util/Arrays.html#copyOfRange(U[],int,int,java.lang.Class)).
> - Add a regression test.
>
> ### Testing
>
> - [GitHub Actions](https://github.com/dlunde/jdk/actions/runs/8388044152)
> - tier1 to tier5 on windows-x64, linux-x64, linux-aarch64, macosx-x64, and macosx-aarch64.
That looks good to me.
-------------
Marked as reviewed by thartmann (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/18472#pullrequestreview-1957933626
More information about the hotspot-compiler-dev
mailing list