On Wed, 15 Jul 2026 03:46:08 GMT, Kuai Wei <[email protected]> wrote:
>> I recently noticed a behavioral discrepancy in
>> jdk.internal.util.ArraysSupport.vectorizedMismatch between the Java
>> implementation and the platform intrinsic implementations.
>>
>> Current behavior
>>
>> The Java implementation may leave a tail of elements unchecked, returning
>> the bitwise complement of the number of remaining elements (i.e.,
>> ~remaining).
>> The x86_64 intrinsic, by contrast, compares all elements and simply returns
>> -1 when no mismatch is found.
>>
>> Proposed change
>>
>> This PR refines the Java implementation so that it always compares all
>> elements and returns -1 when no mismatch is found, matching the x86_64
>> intrinsic behavior.
>>
>> A regression test is included at
>> `test/hotspot/jtreg/compiler/intrinsics/VectorizedMismatchReturnDiffTest.java`
>> which demonstrates the original behavioral difference.
>>
>> ## Test
>> - [x] tier1 test suites on linux x86_64
>> - [x] tier1 test suites on linux aarch64
>>
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> Kuai Wei has updated the pull request incrementally with one additional
> commit since the last revision:
>
> Fix copyright header
Ideally we need to ensure intrinsics return no negative values besides -1.
src/java.base/share/classes/jdk/internal/util/ArraysSupport.java line 114:
> 112: * and {@code length} (exclusive), of the first mismatching pair of
> elements
> 113: * in the two arrays. Otherwise, if a mismatch is not found the
> bitwise
> 114: * compliment of the number of remaining pairs of elements to be
> checked in
I think now we never return a negative value indicating the number of element
to check; we only ever return -1. We need to reflect that fact in the comments
here.
src/java.base/share/classes/jdk/internal/util/ArraysSupport.java line 748:
> 746: // Fall back to slow mechanism
> 747: // ISSUE: Consider looping over vectorizedMismatch
> adjusting ranges
> 748: // However, requires that returned value be relative to
> input ranges
You updated the float[] code but not the double[] code. Please keep their code
consistent.
test/hotspot/jtreg/compiler/intrinsics/VectorizedMismatchReturnDiffTest.java
line 42:
> 40: *
> -XX:CompileCommand=compileonly,compiler.intrinsics.VectorizedMismatchReturnDiffTest::testComp*
> 41: * -Xbatch -XX:-TieredCompilation
> 42: * compiler.intrinsics.VectorizedMismatchReturnDiffTest
Suggestion:
* compiler.intrinsics.VectorizedMismatchReturnDiffTest
-------------
PR Review: https://git.openjdk.org/jdk/pull/31802#pullrequestreview-4709832637
PR Review Comment: https://git.openjdk.org/jdk/pull/31802#discussion_r3592113148
PR Review Comment: https://git.openjdk.org/jdk/pull/31802#discussion_r3592124706
PR Review Comment: https://git.openjdk.org/jdk/pull/31802#discussion_r3592129797