RFR: 8323682: C2: guard check is not generated in Arrays.copyOfRange intrinsic when allocation is eliminated by EA
Daniel Lundén
dlunden at openjdk.org
Mon Mar 25 13:33:34 UTC 2024
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.
-------------
Commit messages:
- Grammar fix
- Fix
Changes: https://git.openjdk.org/jdk/pull/18472/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=18472&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8323682
Stats: 73 lines in 3 files changed: 65 ins; 2 del; 6 mod
Patch: https://git.openjdk.org/jdk/pull/18472.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/18472/head:pull/18472
PR: https://git.openjdk.org/jdk/pull/18472
More information about the hotspot-compiler-dev
mailing list