RFR: 8367129: Move input validation checks to Java for java.lang.StringLatin1 intrinsics
Volkan Yazici
vyazici at openjdk.org
Mon Feb 9 21:29:37 UTC 2026
On Mon, 15 Dec 2025 20:30:51 GMT, Volkan Yazici <vyazici at openjdk.org> wrote:
> Moves input validation checks to Java for `java.lang.StringLatin1` intrinsics. While doing so, affected `java.lang.StringUTF16` methods needed to be updated due to relaxed checks at intrinsics. The javadocs of the touched methods are extensively overhauled.
src/java.base/share/classes/java/lang/StringLatin1.java line 114:
> 112: // inline_string_equals
> 113: @IntrinsicCandidate
> 114: private static boolean equals0(byte[] value, byte[] other) {
This intrinsic is actually identical to `Arrays::equals`, and can be removed – I'm exploring this in #28717.
src/java.base/share/classes/java/lang/StringLatin1.java line 493:
> 491: byte first = str[0];
> 492: int max = (valueToIndex - strToIndex);
> 493: for (int i = valueFromIndex; i <= max; i++) {
Note that the earlier code used `valueCount` – the same `Count`-suffixed variables are used at the intrinsics too. Though as can be seen from these two lines, what is meant is a `ToIndex`. That is, `valueCount` does *not* denote _"the count of characters"_ after the from index, but instead it denotes _"the (exclusive) index of the last character"_. I've updated the Java code to reflect this, though I've not touched the intrinsic.
Note that the same issue (and the correction) is present in the `StringUTF16::indexOf` family too.
src/java.base/share/classes/java/lang/StringUTF16.java line 1671:
> 1669:
> 1670: // inflatedCopy byte[] -> byte[]
> 1671: static void inflate(byte[] src, int srcOff, byte[] dst, int dstOff, int len) {
Moved this to `StringLatin1`, which happens to be the only caller of this method.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/28832#discussion_r2620787257
PR Review Comment: https://git.openjdk.org/jdk/pull/28832#discussion_r2620776159
PR Review Comment: https://git.openjdk.org/jdk/pull/28832#discussion_r2620792767
More information about the core-libs-dev
mailing list