8342489: compiler/c2/irTests/TestVectorizationMismatchedAccess.java fails on big-endian platforms

Reviewed-by: epeter, mbaesken
This commit is contained in:
Amit Kumar 2024-10-30 03:09:47 +00:00
parent bd795946e7
commit b6f745df57

View File

@ -50,9 +50,6 @@ public class TestVectorizationMismatchedAccess {
private final static WhiteBox wb = WhiteBox.getWhiteBox();
public static void main(String[] args) {
if (ByteOrder.nativeOrder() != ByteOrder.LITTLE_ENDIAN) {
throw new RuntimeException("fix test that was written for a little endian platform");
}
TestFramework.runWithFlags("--add-modules", "java.base", "--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED");
}
@ -77,6 +74,14 @@ public class TestVectorizationMismatchedAccess {
}
}
// Method to adjust the value for the native byte order
static private long handleByteOrder(long value) {
if (ByteOrder.nativeOrder() != ByteOrder.LITTLE_ENDIAN) {
value = Long.reverseBytes(value);
}
return value;
}
static private void runAndVerify(Runnable test, int offset) {
System.arraycopy(verifyLongArray, 0, longArray, 0, longArray.length);
Arrays.fill(byteArray, (byte)0);
@ -154,7 +159,7 @@ public class TestVectorizationMismatchedAccess {
// might get fixed with JDK-8325155.
public static void testByteLong1a(byte[] dest, long[] src) {
for (int i = 0; i < src.length; i++) {
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * i, src[i]);
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * i, handleByteOrder(src[i]));
}
}
@ -165,7 +170,7 @@ public class TestVectorizationMismatchedAccess {
// 32-bit: address has ConvL2I for cast of long to address, not supported.
public static void testByteLong1b(byte[] dest, long[] src) {
for (int i = 0; i < src.length; i++) {
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * i, src[i]);
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * i, handleByteOrder(src[i]));
}
}
@ -175,7 +180,7 @@ public class TestVectorizationMismatchedAccess {
public static void testByteLong1c(byte[] dest, long[] src) {
long base = 64; // make sure it is big enough and 8 byte aligned (required for 32-bit)
for (int i = 0; i < src.length - 8; i++) {
UNSAFE.putLongUnaligned(dest, base + 8 * i, src[i]);
UNSAFE.putLongUnaligned(dest, base + 8 * i, handleByteOrder(src[i]));
}
}
@ -187,7 +192,7 @@ public class TestVectorizationMismatchedAccess {
public static void testByteLong1d(byte[] dest, long[] src) {
long base = 64; // make sure it is big enough and 8 byte aligned (required for 32-bit)
for (int i = 0; i < src.length - 8; i++) {
UNSAFE.putLongUnaligned(dest, base + 8L * i, src[i]);
UNSAFE.putLongUnaligned(dest, base + 8L * i, handleByteOrder(src[i]));
}
}
@ -207,7 +212,7 @@ public class TestVectorizationMismatchedAccess {
// might get fixed with JDK-8325155.
public static void testByteLong2a(byte[] dest, long[] src) {
for (int i = 1; i < src.length; i++) {
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * (i - 1), src[i]);
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * (i - 1), handleByteOrder(src[i]));
}
}
@ -218,7 +223,7 @@ public class TestVectorizationMismatchedAccess {
// 32-bit: address has ConvL2I for cast of long to address, not supported.
public static void testByteLong2b(byte[] dest, long[] src) {
for (int i = 1; i < src.length; i++) {
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * (i - 1), src[i]);
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * (i - 1), handleByteOrder(src[i]));
}
}
@ -236,7 +241,7 @@ public class TestVectorizationMismatchedAccess {
// might get fixed with JDK-8325155.
public static void testByteLong3a(byte[] dest, long[] src) {
for (int i = 0; i < src.length - 1; i++) {
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * (i + 1), src[i]);
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * (i + 1), handleByteOrder(src[i]));
}
}
@ -247,7 +252,7 @@ public class TestVectorizationMismatchedAccess {
// 32-bit: address has ConvL2I for cast of long to address, not supported.
public static void testByteLong3b(byte[] dest, long[] src) {
for (int i = 0; i < src.length - 1; i++) {
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * (i + 1), src[i]);
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * (i + 1), handleByteOrder(src[i]));
}
}
@ -267,7 +272,7 @@ public class TestVectorizationMismatchedAccess {
// AlignVector cannot guarantee that invar is aligned.
public static void testByteLong4a(byte[] dest, long[] src, int start, int stop) {
for (int i = start; i < stop; i++) {
UNSAFE.putLongUnaligned(dest, 8 * i + baseOffset, src[i]);
UNSAFE.putLongUnaligned(dest, 8 * i + baseOffset, handleByteOrder(src[i]));
}
}
@ -280,7 +285,7 @@ public class TestVectorizationMismatchedAccess {
// AlignVector cannot guarantee that invar is aligned.
public static void testByteLong4b(byte[] dest, long[] src, int start, int stop) {
for (int i = start; i < stop; i++) {
UNSAFE.putLongUnaligned(dest, 8L * i + baseOffset, src[i]);
UNSAFE.putLongUnaligned(dest, 8L * i + baseOffset, handleByteOrder(src[i]));
}
}
@ -299,7 +304,7 @@ public class TestVectorizationMismatchedAccess {
// might get fixed with JDK-8325155.
public static void testByteLong5a(byte[] dest, long[] src, int start, int stop) {
for (int i = start; i < stop; i++) {
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * (i + baseOffset), src[i]);
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * (i + baseOffset), handleByteOrder(src[i]));
}
}
@ -310,7 +315,7 @@ public class TestVectorizationMismatchedAccess {
// 32-bit: address has ConvL2I for cast of long to address, not supported.
public static void testByteLong5b(byte[] dest, long[] src, int start, int stop) {
for (int i = start; i < stop; i++) {
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * (i + baseOffset), src[i]);
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * (i + baseOffset), handleByteOrder(src[i]));
}
}
@ -454,7 +459,7 @@ public class TestVectorizationMismatchedAccess {
// See: JDK-8331576
public static void testOffHeapLong1a(long dest, long[] src) {
for (int i = 0; i < src.length; i++) {
UNSAFE.putLongUnaligned(null, dest + 8 * i, src[i]);
UNSAFE.putLongUnaligned(null, dest + 8 * i, handleByteOrder(src[i]));
}
}
@ -465,7 +470,7 @@ public class TestVectorizationMismatchedAccess {
// See: JDK-8331576
public static void testOffHeapLong1b(long dest, long[] src) {
for (int i = 0; i < src.length; i++) {
UNSAFE.putLongUnaligned(null, dest + 8L * i, src[i]);
UNSAFE.putLongUnaligned(null, dest + 8L * i, handleByteOrder(src[i]));
}
}
@ -482,7 +487,7 @@ public class TestVectorizationMismatchedAccess {
// See: JDK-8331576
public static void testOffHeapLong2a(long dest, long[] src) {
for (int i = 1; i < src.length; i++) {
UNSAFE.putLongUnaligned(null, dest + 8 * (i - 1), src[i]);
UNSAFE.putLongUnaligned(null, dest + 8 * (i - 1), handleByteOrder(src[i]));
}
}
@ -493,7 +498,7 @@ public class TestVectorizationMismatchedAccess {
// See: JDK-8331576
public static void testOffHeapLong2b(long dest, long[] src) {
for (int i = 1; i < src.length; i++) {
UNSAFE.putLongUnaligned(null, dest + 8L * (i - 1), src[i]);
UNSAFE.putLongUnaligned(null, dest + 8L * (i - 1), handleByteOrder(src[i]));
}
}
@ -510,7 +515,7 @@ public class TestVectorizationMismatchedAccess {
// See: JDK-8331576
public static void testOffHeapLong3a(long dest, long[] src) {
for (int i = 0; i < src.length - 1; i++) {
UNSAFE.putLongUnaligned(null, dest + 8 * (i + 1), src[i]);
UNSAFE.putLongUnaligned(null, dest + 8 * (i + 1), handleByteOrder(src[i]));
}
}
@ -521,7 +526,7 @@ public class TestVectorizationMismatchedAccess {
// See: JDK-8331576
public static void testOffHeapLong3b(long dest, long[] src) {
for (int i = 0; i < src.length - 1; i++) {
UNSAFE.putLongUnaligned(null, dest + 8L * (i + 1), src[i]);
UNSAFE.putLongUnaligned(null, dest + 8L * (i + 1), handleByteOrder(src[i]));
}
}
@ -540,7 +545,7 @@ public class TestVectorizationMismatchedAccess {
// AlignVector cannot guarantee that invar is aligned.
public static void testOffHeapLong4a(long dest, long[] src, int start, int stop) {
for (int i = start; i < stop; i++) {
UNSAFE.putLongUnaligned(null, dest + 8 * i + baseOffset, src[i]);
UNSAFE.putLongUnaligned(null, dest + 8 * i + baseOffset, handleByteOrder(src[i]));
}
}
@ -553,7 +558,7 @@ public class TestVectorizationMismatchedAccess {
// AlignVector cannot guarantee that invar is aligned.
public static void testOffHeapLong4b(long dest, long[] src, int start, int stop) {
for (int i = start; i < stop; i++) {
UNSAFE.putLongUnaligned(null, dest + 8L * i + baseOffset, src[i]);
UNSAFE.putLongUnaligned(null, dest + 8L * i + baseOffset, handleByteOrder(src[i]));
}
}