From b6f745df5795341dab1fc049a188a9e70d563a1a Mon Sep 17 00:00:00 2001 From: Amit Kumar Date: Wed, 30 Oct 2024 03:09:47 +0000 Subject: [PATCH] 8342489: compiler/c2/irTests/TestVectorizationMismatchedAccess.java fails on big-endian platforms Reviewed-by: epeter, mbaesken --- .../TestVectorizationMismatchedAccess.java | 51 ++++++++++--------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/test/hotspot/jtreg/compiler/c2/irTests/TestVectorizationMismatchedAccess.java b/test/hotspot/jtreg/compiler/c2/irTests/TestVectorizationMismatchedAccess.java index 2fdbb0816ad..2d17753ba94 100644 --- a/test/hotspot/jtreg/compiler/c2/irTests/TestVectorizationMismatchedAccess.java +++ b/test/hotspot/jtreg/compiler/c2/irTests/TestVectorizationMismatchedAccess.java @@ -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])); } }