Witnessed several vector-api test failures after JDK-8304450 for client VM on platforms like linux-aarch64:
```
# newfailures.txt
jdk/incubator/vector/DoubleMaxVectorLoadStoreTests.java
jdk/incubator/vector/DoubleMaxVectorTests.java
jdk/incubator/vector/LongMaxVectorLoadStoreTests.java
jdk/incubator/vector/LongMaxVectorTests.java
jdk/incubator/vector/Vector64ConversionTests.java#id0
jdk/incubator/vector/VectorMaxConversionTests.java#id0
jdk/incubator/vector/VectorMaxConversionTests.java#id1
```
For example, Vector64ConversionTests has the following error stack when executing the shuffleCast method:
```
java.lang.IllegalArgumentException: Bad vector bit-size: 32
at jdk.incubator.vector/jdk.incubator.vector.VectorShape.forBitSize(VectorShape.java:142)
at jdk.incubator.vector/jdk.incubator.vector.LongMaxVector$LongMaxShuffle.intoArray(LongMaxVector.java:809)
at jdk.incubator.vector/jdk.incubator.vector.AbstractShuffle.toArray(AbstractShuffle.java:76)
at AbstractVectorConversionTest.legal_shuffle_cast_kernel(AbstractVectorConversionTest.java:534)
at Vector64ConversionTests.shuffleCast(Vector64ConversionTests.java:116)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:132)
at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:599)
at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:174)
at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:822)
at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:147)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.testng.TestRunner.privateRun(TestRunner.java:764)
at org.testng.TestRunner.run(TestRunner.java:585)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:384)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:378)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:337)
at org.testng.SuiteRunner.run(SuiteRunner.java:286)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1218)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
at org.testng.TestNG.runSuites(TestNG.java:1069)
at org.testng.TestNG.run(TestNG.java:1037)
at com.sun.javatest.regtest.agent.TestNGRunner.main(TestNGRunner.java:93)
at com.sun.javatest.regtest.agent.TestNGRunner.main(TestNGRunner.java:53)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at com.sun.javatest.regtest.agent.MainWrapper$MainThread.run(MainWrapper.java:125)
at java.base/java.lang.Thread.run(Thread.java:1592)
```
The method for reporting errors:
```
public void intoArray(int[] a, int offset) {
VectorSpecies<Integer> species = VectorSpecies.of(
int.class,
VectorShape.forBitSize(length() * Integer.SIZE));
Vector<Long> v = toBitsVector();
v.convertShape(VectorOperators.L2I, species, 0)
.reinterpretAsInts()
.intoArray(a, offset);
}
```
`DoubleMaxShuffle.intoArray` calculates `length() * Integer.SIZE` equal to 32, so an exception occurs, `VectorShape.forBitSize` is implemented as follows:
```
@ForceInline
public static VectorShape forBitSize(int bitSize) {
switch (bitSize) {
case 64:
return VectorShape.S_64_BIT;
case 128:
return VectorShape.S_128_BIT;
case 256:
return VectorShape.S_256_BIT;
case 512:
return VectorShape.S_512_BIT;
default:
if ((bitSize > 0) && (bitSize <= MAX_VECTOR_SIZE) && (bitSize % INC_VECTOR_SIZE == 0)) {
return VectorShape.S_Max_BIT;
} else {
throw new IllegalArgumentException("Bad vector bit-size: " + bitSize);
}
}
}
```
`length() * Integer.SIZE` is equal to 32 because the length() is 1. The method ` jdk.incubator.vector.VectorShape#getMaxVectorBitSiz` is called in `DoubleMaxVector/LongMaxVector` to get the vector length. This method returns 64 in client mode, and the width of the `Double/Long` data type is also 64.
So `DoubleMaxVector/LongMaxVector` can only handle 1 Double/Long data at a time.
Note: This will also affect other platforms like linux-riscv64 where `Matcher::max_vector_size`[1] will return 0 if RVV extention is not available. Then method ` jdk.incubator.vector.VectorShape#getMaxVectorBitSize` called to get the vector length will also return 64. That means those tests will also fail in this case.
[1] https://github.com/openjdk/jdk/blob/master/src/hotspot/cpu/riscv/riscv.ad#L1919-L1936
```
# newfailures.txt
jdk/incubator/vector/DoubleMaxVectorLoadStoreTests.java
jdk/incubator/vector/DoubleMaxVectorTests.java
jdk/incubator/vector/LongMaxVectorLoadStoreTests.java
jdk/incubator/vector/LongMaxVectorTests.java
jdk/incubator/vector/Vector64ConversionTests.java#id0
jdk/incubator/vector/VectorMaxConversionTests.java#id0
jdk/incubator/vector/VectorMaxConversionTests.java#id1
```
For example, Vector64ConversionTests has the following error stack when executing the shuffleCast method:
```
java.lang.IllegalArgumentException: Bad vector bit-size: 32
at jdk.incubator.vector/jdk.incubator.vector.VectorShape.forBitSize(VectorShape.java:142)
at jdk.incubator.vector/jdk.incubator.vector.LongMaxVector$LongMaxShuffle.intoArray(LongMaxVector.java:809)
at jdk.incubator.vector/jdk.incubator.vector.AbstractShuffle.toArray(AbstractShuffle.java:76)
at AbstractVectorConversionTest.legal_shuffle_cast_kernel(AbstractVectorConversionTest.java:534)
at Vector64ConversionTests.shuffleCast(Vector64ConversionTests.java:116)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:132)
at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:599)
at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:174)
at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:822)
at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:147)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.testng.TestRunner.privateRun(TestRunner.java:764)
at org.testng.TestRunner.run(TestRunner.java:585)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:384)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:378)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:337)
at org.testng.SuiteRunner.run(SuiteRunner.java:286)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1218)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
at org.testng.TestNG.runSuites(TestNG.java:1069)
at org.testng.TestNG.run(TestNG.java:1037)
at com.sun.javatest.regtest.agent.TestNGRunner.main(TestNGRunner.java:93)
at com.sun.javatest.regtest.agent.TestNGRunner.main(TestNGRunner.java:53)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at com.sun.javatest.regtest.agent.MainWrapper$MainThread.run(MainWrapper.java:125)
at java.base/java.lang.Thread.run(Thread.java:1592)
```
The method for reporting errors:
```
public void intoArray(int[] a, int offset) {
VectorSpecies<Integer> species = VectorSpecies.of(
int.class,
VectorShape.forBitSize(length() * Integer.SIZE));
Vector<Long> v = toBitsVector();
v.convertShape(VectorOperators.L2I, species, 0)
.reinterpretAsInts()
.intoArray(a, offset);
}
```
`DoubleMaxShuffle.intoArray` calculates `length() * Integer.SIZE` equal to 32, so an exception occurs, `VectorShape.forBitSize` is implemented as follows:
```
@ForceInline
public static VectorShape forBitSize(int bitSize) {
switch (bitSize) {
case 64:
return VectorShape.S_64_BIT;
case 128:
return VectorShape.S_128_BIT;
case 256:
return VectorShape.S_256_BIT;
case 512:
return VectorShape.S_512_BIT;
default:
if ((bitSize > 0) && (bitSize <= MAX_VECTOR_SIZE) && (bitSize % INC_VECTOR_SIZE == 0)) {
return VectorShape.S_Max_BIT;
} else {
throw new IllegalArgumentException("Bad vector bit-size: " + bitSize);
}
}
}
```
`length() * Integer.SIZE` is equal to 32 because the length() is 1. The method ` jdk.incubator.vector.VectorShape#getMaxVectorBitSiz` is called in `DoubleMaxVector/LongMaxVector` to get the vector length. This method returns 64 in client mode, and the width of the `Double/Long` data type is also 64.
So `DoubleMaxVector/LongMaxVector` can only handle 1 Double/Long data at a time.
Note: This will also affect other platforms like linux-riscv64 where `Matcher::max_vector_size`[1] will return 0 if RVV extention is not available. Then method ` jdk.incubator.vector.VectorShape#getMaxVectorBitSize` called to get the vector length will also return 64. That means those tests will also fail in this case.
[1] https://github.com/openjdk/jdk/blob/master/src/hotspot/cpu/riscv/riscv.ad#L1919-L1936
- relates to
-
JDK-8304450 [vectorapi] Refactor VectorShuffle implementation
-
- Resolved
-