The JDK codebase re-created many variants of checkIndex(`grep -I -r 'cehckIndex' jdk/`). A notable variant is java.nio.Buffer.checkIndex, which is annotated with @IntrinsicCandidate and it only has a corresponding C1 intrinsic version.
There is an utility method `jdk.internal.util.Preconditions.checkIndex`(wrapped by java.lang.Objects.checkIndex) that behaves the same as these variants of checkIndex, we can replace these variants with Objects.checkIndex, it would significantly reduce duplicated code and enjoys performance improvement because Preconditions.checkIndex is an @IntrinsicCandidate and it has a corresponding intrinsic method in HotSpot.
But, the problem is currently HotSpot only implements the C2 intrinsic version of Preconditions.checkIndex. To reuse it globally in JDK codebase, I think we can firstly implement its C1 counterpart. There are also a few kinds of stuff 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
There is an utility method `jdk.internal.util.Preconditions.checkIndex`(wrapped by java.lang.Objects.checkIndex) that behaves the same as these variants of checkIndex, we can replace these variants with Objects.checkIndex, it would significantly reduce duplicated code and enjoys performance improvement because Preconditions.checkIndex is an @IntrinsicCandidate and it has a corresponding intrinsic method in HotSpot.
But, the problem is currently HotSpot only implements the C2 intrinsic version of Preconditions.checkIndex. To reuse it globally in JDK codebase, I think we can firstly implement its C1 counterpart. There are also a few kinds of stuff 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
- relates to
-
JDK-8270057 Use Objects.checkFromToIndex for j.u.c.CopyOnWriteArrayList
-
- Open
-
-
JDK-8268698 Use Objects.check{Index,FromToIndex,FromIndexSize} for java.base
-
- Resolved
-
-
JDK-8270058 Use Objects.check{Index,FromIndexSize} for java.desktop
-
- Resolved
-
-
JDK-8276806 Use Objects.checkFromIndexSize where possible in java.base
-
- Resolved
-
(1 links to)