Skip to content

Commit ca6ae2d

Browse files
author
duke
committed
Backport b6f745d
1 parent e534863 commit ca6ae2d

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

test/hotspot/jtreg/compiler/c2/irTests/TestVectorizationMismatchedAccess.java

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ public class TestVectorizationMismatchedAccess {
5050
private final static WhiteBox wb = WhiteBox.getWhiteBox();
5151

5252
public static void main(String[] args) {
53-
if (ByteOrder.nativeOrder() != ByteOrder.LITTLE_ENDIAN) {
54-
throw new RuntimeException("fix test that was written for a little endian platform");
55-
}
5653
TestFramework.runWithFlags("--add-modules", "java.base", "--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED");
5754
}
5855

@@ -77,6 +74,14 @@ public static void main(String[] args) {
7774
}
7875
}
7976

77+
// Method to adjust the value for the native byte order
78+
static private long handleByteOrder(long value) {
79+
if (ByteOrder.nativeOrder() != ByteOrder.LITTLE_ENDIAN) {
80+
value = Long.reverseBytes(value);
81+
}
82+
return value;
83+
}
84+
8085
static private void runAndVerify(Runnable test, int offset) {
8186
System.arraycopy(verifyLongArray, 0, longArray, 0, longArray.length);
8287
Arrays.fill(byteArray, (byte)0);
@@ -154,7 +159,7 @@ static private void runAndVerify3(Runnable test, int offset) {
154159
// might get fixed with JDK-8325155.
155160
public static void testByteLong1a(byte[] dest, long[] src) {
156161
for (int i = 0; i < src.length; i++) {
157-
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * i, src[i]);
162+
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * i, handleByteOrder(src[i]));
158163
}
159164
}
160165

@@ -165,7 +170,7 @@ public static void testByteLong1a(byte[] dest, long[] src) {
165170
// 32-bit: address has ConvL2I for cast of long to address, not supported.
166171
public static void testByteLong1b(byte[] dest, long[] src) {
167172
for (int i = 0; i < src.length; i++) {
168-
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * i, src[i]);
173+
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * i, handleByteOrder(src[i]));
169174
}
170175
}
171176

@@ -175,7 +180,7 @@ public static void testByteLong1b(byte[] dest, long[] src) {
175180
public static void testByteLong1c(byte[] dest, long[] src) {
176181
long base = 64; // make sure it is big enough and 8 byte aligned (required for 32-bit)
177182
for (int i = 0; i < src.length - 8; i++) {
178-
UNSAFE.putLongUnaligned(dest, base + 8 * i, src[i]);
183+
UNSAFE.putLongUnaligned(dest, base + 8 * i, handleByteOrder(src[i]));
179184
}
180185
}
181186

@@ -187,7 +192,7 @@ public static void testByteLong1c(byte[] dest, long[] src) {
187192
public static void testByteLong1d(byte[] dest, long[] src) {
188193
long base = 64; // make sure it is big enough and 8 byte aligned (required for 32-bit)
189194
for (int i = 0; i < src.length - 8; i++) {
190-
UNSAFE.putLongUnaligned(dest, base + 8L * i, src[i]);
195+
UNSAFE.putLongUnaligned(dest, base + 8L * i, handleByteOrder(src[i]));
191196
}
192197
}
193198

@@ -207,7 +212,7 @@ public static void testByteLong1_runner() {
207212
// might get fixed with JDK-8325155.
208213
public static void testByteLong2a(byte[] dest, long[] src) {
209214
for (int i = 1; i < src.length; i++) {
210-
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * (i - 1), src[i]);
215+
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * (i - 1), handleByteOrder(src[i]));
211216
}
212217
}
213218

@@ -218,7 +223,7 @@ public static void testByteLong2a(byte[] dest, long[] src) {
218223
// 32-bit: address has ConvL2I for cast of long to address, not supported.
219224
public static void testByteLong2b(byte[] dest, long[] src) {
220225
for (int i = 1; i < src.length; i++) {
221-
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * (i - 1), src[i]);
226+
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * (i - 1), handleByteOrder(src[i]));
222227
}
223228
}
224229

@@ -236,7 +241,7 @@ public static void testByteLong2_runner() {
236241
// might get fixed with JDK-8325155.
237242
public static void testByteLong3a(byte[] dest, long[] src) {
238243
for (int i = 0; i < src.length - 1; i++) {
239-
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * (i + 1), src[i]);
244+
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * (i + 1), handleByteOrder(src[i]));
240245
}
241246
}
242247

@@ -247,7 +252,7 @@ public static void testByteLong3a(byte[] dest, long[] src) {
247252
// 32-bit: address has ConvL2I for cast of long to address, not supported.
248253
public static void testByteLong3b(byte[] dest, long[] src) {
249254
for (int i = 0; i < src.length - 1; i++) {
250-
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * (i + 1), src[i]);
255+
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * (i + 1), handleByteOrder(src[i]));
251256
}
252257
}
253258

@@ -267,7 +272,7 @@ public static void testByteLong3_runner() {
267272
// AlignVector cannot guarantee that invar is aligned.
268273
public static void testByteLong4a(byte[] dest, long[] src, int start, int stop) {
269274
for (int i = start; i < stop; i++) {
270-
UNSAFE.putLongUnaligned(dest, 8 * i + baseOffset, src[i]);
275+
UNSAFE.putLongUnaligned(dest, 8 * i + baseOffset, handleByteOrder(src[i]));
271276
}
272277
}
273278

@@ -280,7 +285,7 @@ public static void testByteLong4a(byte[] dest, long[] src, int start, int stop)
280285
// AlignVector cannot guarantee that invar is aligned.
281286
public static void testByteLong4b(byte[] dest, long[] src, int start, int stop) {
282287
for (int i = start; i < stop; i++) {
283-
UNSAFE.putLongUnaligned(dest, 8L * i + baseOffset, src[i]);
288+
UNSAFE.putLongUnaligned(dest, 8L * i + baseOffset, handleByteOrder(src[i]));
284289
}
285290
}
286291

@@ -299,7 +304,7 @@ public static void testByteLong4_runner() {
299304
// might get fixed with JDK-8325155.
300305
public static void testByteLong5a(byte[] dest, long[] src, int start, int stop) {
301306
for (int i = start; i < stop; i++) {
302-
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * (i + baseOffset), src[i]);
307+
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * (i + baseOffset), handleByteOrder(src[i]));
303308
}
304309
}
305310

@@ -310,7 +315,7 @@ public static void testByteLong5a(byte[] dest, long[] src, int start, int stop)
310315
// 32-bit: address has ConvL2I for cast of long to address, not supported.
311316
public static void testByteLong5b(byte[] dest, long[] src, int start, int stop) {
312317
for (int i = start; i < stop; i++) {
313-
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * (i + baseOffset), src[i]);
318+
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * (i + baseOffset), handleByteOrder(src[i]));
314319
}
315320
}
316321

@@ -454,7 +459,7 @@ public static void testByteByte5_runner() {
454459
// See: JDK-8331576
455460
public static void testOffHeapLong1a(long dest, long[] src) {
456461
for (int i = 0; i < src.length; i++) {
457-
UNSAFE.putLongUnaligned(null, dest + 8 * i, src[i]);
462+
UNSAFE.putLongUnaligned(null, dest + 8 * i, handleByteOrder(src[i]));
458463
}
459464
}
460465

@@ -465,7 +470,7 @@ public static void testOffHeapLong1a(long dest, long[] src) {
465470
// See: JDK-8331576
466471
public static void testOffHeapLong1b(long dest, long[] src) {
467472
for (int i = 0; i < src.length; i++) {
468-
UNSAFE.putLongUnaligned(null, dest + 8L * i, src[i]);
473+
UNSAFE.putLongUnaligned(null, dest + 8L * i, handleByteOrder(src[i]));
469474
}
470475
}
471476

@@ -482,7 +487,7 @@ public static void testOffHeapLong1_runner() {
482487
// See: JDK-8331576
483488
public static void testOffHeapLong2a(long dest, long[] src) {
484489
for (int i = 1; i < src.length; i++) {
485-
UNSAFE.putLongUnaligned(null, dest + 8 * (i - 1), src[i]);
490+
UNSAFE.putLongUnaligned(null, dest + 8 * (i - 1), handleByteOrder(src[i]));
486491
}
487492
}
488493

@@ -493,7 +498,7 @@ public static void testOffHeapLong2a(long dest, long[] src) {
493498
// See: JDK-8331576
494499
public static void testOffHeapLong2b(long dest, long[] src) {
495500
for (int i = 1; i < src.length; i++) {
496-
UNSAFE.putLongUnaligned(null, dest + 8L * (i - 1), src[i]);
501+
UNSAFE.putLongUnaligned(null, dest + 8L * (i - 1), handleByteOrder(src[i]));
497502
}
498503
}
499504

@@ -510,7 +515,7 @@ public static void testOffHeapLong2_runner() {
510515
// See: JDK-8331576
511516
public static void testOffHeapLong3a(long dest, long[] src) {
512517
for (int i = 0; i < src.length - 1; i++) {
513-
UNSAFE.putLongUnaligned(null, dest + 8 * (i + 1), src[i]);
518+
UNSAFE.putLongUnaligned(null, dest + 8 * (i + 1), handleByteOrder(src[i]));
514519
}
515520
}
516521

@@ -521,7 +526,7 @@ public static void testOffHeapLong3a(long dest, long[] src) {
521526
// See: JDK-8331576
522527
public static void testOffHeapLong3b(long dest, long[] src) {
523528
for (int i = 0; i < src.length - 1; i++) {
524-
UNSAFE.putLongUnaligned(null, dest + 8L * (i + 1), src[i]);
529+
UNSAFE.putLongUnaligned(null, dest + 8L * (i + 1), handleByteOrder(src[i]));
525530
}
526531
}
527532

@@ -540,7 +545,7 @@ public static void testOffHeapLong3_runner() {
540545
// AlignVector cannot guarantee that invar is aligned.
541546
public static void testOffHeapLong4a(long dest, long[] src, int start, int stop) {
542547
for (int i = start; i < stop; i++) {
543-
UNSAFE.putLongUnaligned(null, dest + 8 * i + baseOffset, src[i]);
548+
UNSAFE.putLongUnaligned(null, dest + 8 * i + baseOffset, handleByteOrder(src[i]));
544549
}
545550
}
546551

@@ -553,7 +558,7 @@ public static void testOffHeapLong4a(long dest, long[] src, int start, int stop)
553558
// AlignVector cannot guarantee that invar is aligned.
554559
public static void testOffHeapLong4b(long dest, long[] src, int start, int stop) {
555560
for (int i = start; i < stop; i++) {
556-
UNSAFE.putLongUnaligned(null, dest + 8L * i + baseOffset, src[i]);
561+
UNSAFE.putLongUnaligned(null, dest + 8L * i + baseOffset, handleByteOrder(src[i]));
557562
}
558563
}
559564

0 commit comments

Comments
 (0)