RFR: 8265518: C1: Intrinsic support for Preconditions.checkIndex

Yi Yang yyang at openjdk.java.net
Thu Apr 22 07:01:45 UTC 2021


The JDK codebase re-created many variants of checkIndex(`grep -I -r 'cehckIndex' jdk/`). An notable variant is java.nio.Buffer.checkIndex, which annotated with @IntrinsicCandidate and it only has corresponding C1 intrinsic version.

In fact, there is an utilitiy method `jdk.internal.util.Preconditions.checkIndex`(wrapped by java.lang.Objects.checkIndex) that behaves the same as these variants of checkIndex, we can replaces these re-created variants of checkIndex by Objects.checkIndex, it would significantly reduce duplicated code and enjoys performance improvement because Preconditions.checkIndex is @IntrinsicCandidate and it has corresponding intrinsic method in HotSpot.

But, the problem is currently HotSpot only implements the C2 version of Preconditions.checkIndex. To reuse it global-widely in JDK code, I think we can firstly implement its C1 counterpart. There are also a few stuffs we can do later:

1. Replace all variants of checkIndex by Objects.checkIndex in the whole JDK codebase.
2. Remove Buffer.checkIndex and obsolete/deprecate InlineNIOCheckIndex flag

Testing: compiler and jdk

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

Commit messages:
 - consolidate

Changes: https://git.openjdk.java.net/jdk/pull/3615/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=3615&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8265518
  Stats: 253 lines in 11 files changed: 184 ins; 48 del; 21 mod
  Patch: https://git.openjdk.java.net/jdk/pull/3615.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/3615/head:pull/3615

PR: https://git.openjdk.java.net/jdk/pull/3615


More information about the hotspot-dev mailing list