1 /* 2 * Copyright (c) 2023, Red Hat, Inc. All rights reserved. 3 * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 */ 24 25 package compiler.c2.irTests; 26 27 import compiler.lib.ir_framework.*; 28 import jdk.test.lib.Utils; 29 import jdk.test.whitebox.WhiteBox; 30 import jdk.internal.misc.Unsafe; 31 import java.util.Random; 32 import java.util.Arrays; 33 import java.nio.ByteOrder; 34 35 /* 36 * @test 37 * @bug 8300258 38 * @key randomness 39 * @summary C2: vectorization fails on simple ByteBuffer loop 40 * @modules java.base/jdk.internal.misc 41 * @library /test/lib / 42 * @build jdk.test.whitebox.WhiteBox 43 * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox 44 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI compiler.c2.irTests.TestVectorizationMismatchedAccess 45 */ 46 47 public class TestVectorizationMismatchedAccess { 48 private static final Unsafe UNSAFE = Unsafe.getUnsafe(); 49 private static final Random RANDOM = Utils.getRandomInstance(); 50 private final static WhiteBox wb = WhiteBox.getWhiteBox(); 51 52 public static void main(String[] args) { 53 // Cross-product: +-AlignVector and +-UseCompactObjectHeaders 54 TestFramework.runWithFlags("--add-modules", "java.base", "--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED", 55 "-XX:+UnlockExperimentalVMOptions", "-XX:-UseCompactObjectHeaders", 56 "-XX:-AlignVector"); 57 TestFramework.runWithFlags("--add-modules", "java.base", "--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED", 58 "-XX:+UnlockExperimentalVMOptions", "-XX:-UseCompactObjectHeaders", 59 "-XX:+AlignVector"); 60 TestFramework.runWithFlags("--add-modules", "java.base", "--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED", 61 "-XX:+UnlockExperimentalVMOptions", "-XX:+UseCompactObjectHeaders", 62 "-XX:-AlignVector"); 63 TestFramework.runWithFlags("--add-modules", "java.base", "--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED", 64 "-XX:+UnlockExperimentalVMOptions", "-XX:+UseCompactObjectHeaders", 65 "-XX:+AlignVector"); 66 } 67 68 static int size = 1024; 69 static byte[] byteArray = new byte[size * 8]; 70 static long[] longArray = new long[size]; 71 static byte[] verifyByteArray = new byte[size * 8]; 72 static long[] verifyLongArray = new long[size]; 73 static long baseOffset = 0; 74 static long baseOffHeap = UNSAFE.allocateMemory(size * 8); 75 76 77 static { 78 for (int i = 0; i < verifyByteArray.length; i++) { 79 verifyByteArray[i] = (byte)RANDOM.nextInt(Byte.MAX_VALUE); 80 } 81 for (int i = 0; i < verifyLongArray.length; i++) { 82 verifyLongArray[i] = 0; 83 for (int j = 0; j < 8; j++) { 84 verifyLongArray[i] = verifyLongArray[i] | (((long)verifyByteArray[8 * i + j]) << 8 * j); 85 } 86 } 87 } 88 89 // Method to adjust the value for the native byte order 90 static private long handleByteOrder(long value) { 91 if (ByteOrder.nativeOrder() != ByteOrder.LITTLE_ENDIAN) { 92 value = Long.reverseBytes(value); 93 } 94 return value; 95 } 96 97 static private void runAndVerify(Runnable test, int offset) { 98 System.arraycopy(verifyLongArray, 0, longArray, 0, longArray.length); 99 Arrays.fill(byteArray, (byte)0); 100 test.run(); 101 int i; 102 for (i = 0; i < Math.max(offset, 0); i++) { 103 if (byteArray[i] != 0) { 104 throw new RuntimeException("Incorrect result at " + i + " " + byteArray[i] + " != 0"); 105 } 106 } 107 for (; i < Math.min(byteArray.length + offset, byteArray.length); i++) { 108 if (byteArray[i] != verifyByteArray[i - offset]) { 109 throw new RuntimeException("Incorrect result at " + i + " " + byteArray[i] + " != " + verifyByteArray[i-offset]); 110 } 111 } 112 for (; i < byteArray.length; i++) { 113 if (byteArray[i] != 0) { 114 throw new RuntimeException("Incorrect result at " + i + " " + byteArray[i] + " != 0"); 115 } 116 } 117 } 118 119 static private void runAndVerify2(Runnable test, int offset) { 120 System.arraycopy(verifyByteArray, 0, byteArray, 0, byteArray.length); 121 test.run(); 122 int i; 123 for (i = 0; i < Math.max(offset, 0); i++) { 124 if (byteArray[i] != verifyByteArray[i]) { 125 throw new RuntimeException("Incorrect result at " + i + " " + byteArray[i] + " != " + verifyByteArray[i]); 126 } 127 } 128 for (; i < Math.min(byteArray.length + offset, byteArray.length); i++) { 129 int val = offset > 0 ? verifyByteArray[(i-offset) % 8] : verifyByteArray[i-offset]; 130 if (byteArray[i] != val) { 131 throw new RuntimeException("Incorrect result at " + i + " " + byteArray[i] + " != " + verifyByteArray[i-offset]); 132 } 133 } 134 for (; i < byteArray.length; i++) { 135 if (byteArray[i] != verifyByteArray[i]) { 136 throw new RuntimeException("Incorrect result at " + i + " " + byteArray[i] + " != " + verifyByteArray[i]); 137 } 138 } 139 } 140 141 142 static private void runAndVerify3(Runnable test, int offset) { 143 System.arraycopy(verifyLongArray, 0, longArray, 0, longArray.length); 144 for (int i = 0; i < size * 8; i++) { 145 UNSAFE.putByte(null, baseOffHeap + i, (byte)0); 146 } 147 test.run(); 148 int i; 149 for (i = 0; i < Math.max(offset, 0); i++) { 150 if (UNSAFE.getByte(null, baseOffHeap + i) != 0) { 151 throw new RuntimeException("Incorrect result at " + i + " " + byteArray[i] + " != 0"); 152 } 153 } 154 for (; i < Math.min(size * 8 + offset, size * 8); i++) { 155 if (UNSAFE.getByte(null, baseOffHeap + i) != verifyByteArray[i - offset]) { 156 throw new RuntimeException("Incorrect result at " + i + " " + byteArray[i] + " != " + verifyByteArray[i-offset]); 157 } 158 } 159 for (; i < byteArray.length; i++) { 160 if (UNSAFE.getByte(null, baseOffHeap + i) != 0) { 161 throw new RuntimeException("Incorrect result at " + i + " " + byteArray[i] + " != 0"); 162 } 163 } 164 } 165 166 @Test 167 @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }, 168 applyIfCPUFeatureOr = {"sse2", "true", "asimd", "true"}, 169 applyIfPlatform = {"64-bit", "true"}) 170 // 32-bit: offsets are badly aligned (UNSAFE.ARRAY_BYTE_BASE_OFFSET is 4 byte aligned, but not 8 byte aligned). 171 // might get fixed with JDK-8325155. 172 public static void testByteLong1a(byte[] dest, long[] src) { 173 for (int i = 0; i < src.length; i++) { 174 UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * i, handleByteOrder(src[i])); 175 } 176 } 177 178 @Test 179 @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }, 180 applyIfCPUFeatureOr = {"sse2", "true", "asimd", "true"}, 181 applyIfPlatform = {"64-bit", "true"}) 182 // 32-bit: address has ConvL2I for cast of long to address, not supported. 183 public static void testByteLong1b(byte[] dest, long[] src) { 184 for (int i = 0; i < src.length; i++) { 185 UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * i, handleByteOrder(src[i])); 186 } 187 } 188 189 @Test 190 @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }, 191 applyIfCPUFeatureOr = {"sse2", "true", "asimd", "true"}) 192 public static void testByteLong1c(byte[] dest, long[] src) { 193 long base = 64; // make sure it is big enough and 8 byte aligned (required for 32-bit) 194 for (int i = 0; i < src.length - 8; i++) { 195 UNSAFE.putLongUnaligned(dest, base + 8 * i, handleByteOrder(src[i])); 196 } 197 } 198 199 @Test 200 @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }, 201 applyIfCPUFeatureOr = {"sse2", "true", "asimd", "true"}, 202 applyIfPlatform = {"64-bit", "true"}) 203 // 32-bit: address has ConvL2I for cast of long to address, not supported. 204 public static void testByteLong1d(byte[] dest, long[] src) { 205 long base = 64; // make sure it is big enough and 8 byte aligned (required for 32-bit) 206 for (int i = 0; i < src.length - 8; i++) { 207 UNSAFE.putLongUnaligned(dest, base + 8L * i, handleByteOrder(src[i])); 208 } 209 } 210 211 @Run(test = {"testByteLong1a", "testByteLong1b", "testByteLong1c", "testByteLong1d"}) 212 public static void testByteLong1_runner() { 213 runAndVerify(() -> testByteLong1a(byteArray, longArray), 0); 214 runAndVerify(() -> testByteLong1b(byteArray, longArray), 0); 215 testByteLong1c(byteArray, longArray); 216 testByteLong1d(byteArray, longArray); 217 } 218 219 @Test 220 @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }, 221 applyIfCPUFeatureOr = {"sse2", "true", "asimd", "true"}, 222 applyIfPlatform = {"64-bit", "true"}) 223 // 32-bit: offsets are badly aligned (UNSAFE.ARRAY_BYTE_BASE_OFFSET is 4 byte aligned, but not 8 byte aligned). 224 // might get fixed with JDK-8325155. 225 public static void testByteLong2a(byte[] dest, long[] src) { 226 for (int i = 1; i < src.length; i++) { 227 UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * (i - 1), handleByteOrder(src[i])); 228 } 229 } 230 231 @Test 232 @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }, 233 applyIfCPUFeatureOr = {"sse2", "true", "asimd", "true"}, 234 applyIfPlatform = {"64-bit", "true"}) 235 // 32-bit: address has ConvL2I for cast of long to address, not supported. 236 public static void testByteLong2b(byte[] dest, long[] src) { 237 for (int i = 1; i < src.length; i++) { 238 UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * (i - 1), handleByteOrder(src[i])); 239 } 240 } 241 242 @Run(test = {"testByteLong2a", "testByteLong2b"}) 243 public static void testByteLong2_runner() { 244 runAndVerify(() -> testByteLong2a(byteArray, longArray), -8); 245 runAndVerify(() -> testByteLong2b(byteArray, longArray), -8); 246 } 247 248 @Test 249 @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }, 250 applyIfCPUFeatureOr = {"sse2", "true", "asimd", "true"}, 251 applyIfPlatform = {"64-bit", "true"}) 252 // 32-bit: offsets are badly aligned (UNSAFE.ARRAY_BYTE_BASE_OFFSET is 4 byte aligned, but not 8 byte aligned). 253 // might get fixed with JDK-8325155. 254 public static void testByteLong3a(byte[] dest, long[] src) { 255 for (int i = 0; i < src.length - 1; i++) { 256 UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * (i + 1), handleByteOrder(src[i])); 257 } 258 } 259 260 @Test 261 @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }, 262 applyIfCPUFeatureOr = {"sse2", "true", "asimd", "true"}, 263 applyIfPlatform = {"64-bit", "true"}) 264 // 32-bit: address has ConvL2I for cast of long to address, not supported. 265 public static void testByteLong3b(byte[] dest, long[] src) { 266 for (int i = 0; i < src.length - 1; i++) { 267 UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * (i + 1), handleByteOrder(src[i])); 268 } 269 } 270 271 @Run(test = {"testByteLong3a", "testByteLong3b"}) 272 public static void testByteLong3_runner() { 273 runAndVerify(() -> testByteLong3a(byteArray, longArray), 8); 274 runAndVerify(() -> testByteLong3b(byteArray, longArray), 8); 275 } 276 277 @Test 278 @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }, 279 applyIfCPUFeatureOr = {"sse2", "true", "asimd", "true"}, 280 applyIfPlatform = {"64-bit", "true"}, 281 applyIf = {"AlignVector", "false"}) 282 // 32-bit: offsets are badly aligned (UNSAFE.ARRAY_BYTE_BASE_OFFSET is 4 byte aligned, but not 8 byte aligned). 283 // might get fixed with JDK-8325155. 284 // AlignVector cannot guarantee that invar is aligned. 285 public static void testByteLong4a(byte[] dest, long[] src, int start, int stop) { 286 for (int i = start; i < stop; i++) { 287 UNSAFE.putLongUnaligned(dest, 8 * i + baseOffset, handleByteOrder(src[i])); 288 } 289 } 290 291 @Test 292 @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }, 293 applyIfCPUFeatureOr = {"sse2", "true", "asimd", "true"}, 294 applyIfPlatform = {"64-bit", "true"}, 295 applyIf = {"AlignVector", "false"}) 296 // 32-bit: address has ConvL2I for cast of long to address, not supported. 297 // AlignVector cannot guarantee that invar is aligned. 298 public static void testByteLong4b(byte[] dest, long[] src, int start, int stop) { 299 for (int i = start; i < stop; i++) { 300 UNSAFE.putLongUnaligned(dest, 8L * i + baseOffset, handleByteOrder(src[i])); 301 } 302 } 303 304 @Run(test = {"testByteLong4a", "testByteLong4b"}) 305 public static void testByteLong4_runner() { 306 baseOffset = UNSAFE.ARRAY_BYTE_BASE_OFFSET; 307 runAndVerify(() -> testByteLong4a(byteArray, longArray, 0, size), 0); 308 runAndVerify(() -> testByteLong4b(byteArray, longArray, 0, size), 0); 309 } 310 311 @Test 312 @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }, 313 applyIfCPUFeatureOr = {"sse2", "true", "asimd", "true"}, 314 applyIfPlatform = {"64-bit", "true"}) 315 // 32-bit: offsets are badly aligned (UNSAFE.ARRAY_BYTE_BASE_OFFSET is 4 byte aligned, but not 8 byte aligned). 316 // might get fixed with JDK-8325155. 317 public static void testByteLong5a(byte[] dest, long[] src, int start, int stop) { 318 for (int i = start; i < stop; i++) { 319 UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * (i + baseOffset), handleByteOrder(src[i])); 320 } 321 } 322 323 @Test 324 @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }, 325 applyIfCPUFeatureOr = {"sse2", "true", "asimd", "true"}, 326 applyIfPlatform = {"64-bit", "true"}) 327 // 32-bit: address has ConvL2I for cast of long to address, not supported. 328 public static void testByteLong5b(byte[] dest, long[] src, int start, int stop) { 329 for (int i = start; i < stop; i++) { 330 UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * (i + baseOffset), handleByteOrder(src[i])); 331 } 332 } 333 334 @Run(test = {"testByteLong5a", "testByteLong5b"}) 335 public static void testByteLong5_runner() { 336 baseOffset = 1; 337 runAndVerify(() -> testByteLong5a(byteArray, longArray, 0, size-1), 8); 338 runAndVerify(() -> testByteLong5b(byteArray, longArray, 0, size-1), 8); 339 } 340 341 @Test 342 @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }, 343 applyIfCPUFeatureOr = {"sse2", "true", "asimd", "true"}, 344 applyIfPlatform = {"64-bit", "true"}) 345 // 32-bit: offsets are badly aligned (UNSAFE.ARRAY_BYTE_BASE_OFFSET is 4 byte aligned, but not 8 byte aligned). 346 // might get fixed with JDK-8325155. 347 public static void testByteByte1a(byte[] dest, byte[] src) { 348 for (int i = 0; i < src.length / 8; i++) { 349 UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * i, UNSAFE.getLongUnaligned(src, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * i)); 350 } 351 } 352 353 @Test 354 @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }, 355 applyIfCPUFeatureOr = {"sse2", "true", "asimd", "true"}, 356 applyIfPlatform = {"64-bit", "true"}) 357 // 32-bit: address has ConvL2I for cast of long to address, not supported. 358 public static void testByteByte1b(byte[] dest, byte[] src) { 359 for (int i = 0; i < src.length / 8; i++) { 360 UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * i, UNSAFE.getLongUnaligned(src, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * i)); 361 } 362 } 363 364 @Run(test = {"testByteByte1a", "testByteByte1b"}) 365 public static void testByteByte1_runner() { 366 runAndVerify2(() -> testByteByte1a(byteArray, byteArray), 0); 367 runAndVerify2(() -> testByteByte1b(byteArray, byteArray), 0); 368 } 369 370 @Test 371 @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }, 372 applyIfCPUFeatureOr = {"sse2", "true", "asimd", "true"}, 373 applyIfPlatform = {"64-bit", "true"}) 374 // 32-bit: offsets are badly aligned (UNSAFE.ARRAY_BYTE_BASE_OFFSET is 4 byte aligned, but not 8 byte aligned). 375 // might get fixed with JDK-8325155. 376 public static void testByteByte2a(byte[] dest, byte[] src) { 377 for (int i = 1; i < src.length / 8; i++) { 378 UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * (i - 1), UNSAFE.getLongUnaligned(src, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * i)); 379 } 380 } 381 382 @Test 383 @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }, 384 applyIfCPUFeatureOr = {"sse2", "true", "asimd", "true"}, 385 applyIfPlatform = {"64-bit", "true"}) 386 // 32-bit: address has ConvL2I for cast of long to address, not supported. 387 public static void testByteByte2b(byte[] dest, byte[] src) { 388 for (int i = 1; i < src.length / 8; i++) { 389 UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * (i - 1), UNSAFE.getLongUnaligned(src, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * i)); 390 } 391 } 392 393 @Run(test = {"testByteByte2a", "testByteByte2b"}) 394 public static void testByteByte2_runner() { 395 runAndVerify2(() -> testByteByte2a(byteArray, byteArray), -8); 396 runAndVerify2(() -> testByteByte2b(byteArray, byteArray), -8); 397 } 398 399 @Test 400 @IR(failOn = { IRNode.LOAD_VECTOR_L, IRNode.STORE_VECTOR }) 401 public static void testByteByte3a(byte[] dest, byte[] src) { 402 for (int i = 0; i < src.length / 8 - 1; i++) { 403 UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * (i + 1), UNSAFE.getLongUnaligned(src, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * i)); 404 } 405 } 406 407 @Test 408 @IR(failOn = { IRNode.LOAD_VECTOR_L, IRNode.STORE_VECTOR }) 409 public static void testByteByte3b(byte[] dest, byte[] src) { 410 for (int i = 0; i < src.length / 8 - 1; i++) { 411 UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * (i + 1), UNSAFE.getLongUnaligned(src, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * i)); 412 } 413 } 414 415 @Run(test = {"testByteByte3a", "testByteByte3b"}) 416 public static void testByteByte3_runner() { 417 runAndVerify2(() -> testByteByte3a(byteArray, byteArray), 8); 418 runAndVerify2(() -> testByteByte3b(byteArray, byteArray), 8); 419 } 420 421 @Test 422 @IR(failOn = { IRNode.LOAD_VECTOR_L, IRNode.STORE_VECTOR }) 423 public static void testByteByte4a(byte[] dest, byte[] src, int start, int stop) { 424 for (int i = start; i < stop; i++) { 425 UNSAFE.putLongUnaligned(dest, 8 * i + baseOffset, UNSAFE.getLongUnaligned(src, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * i)); 426 } 427 } 428 429 @Test 430 @IR(failOn = { IRNode.LOAD_VECTOR_L, IRNode.STORE_VECTOR }) 431 public static void testByteByte4b(byte[] dest, byte[] src, int start, int stop) { 432 for (int i = start; i < stop; i++) { 433 UNSAFE.putLongUnaligned(dest, 8L * i + baseOffset, UNSAFE.getLongUnaligned(src, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * i)); 434 } 435 } 436 437 @Run(test = {"testByteByte4a", "testByteByte4b"}) 438 public static void testByteByte4_runner() { 439 baseOffset = UNSAFE.ARRAY_BYTE_BASE_OFFSET; 440 runAndVerify2(() -> testByteByte4a(byteArray, byteArray, 0, size), 0); 441 runAndVerify2(() -> testByteByte4b(byteArray, byteArray, 0, size), 0); 442 } 443 444 @Test 445 @IR(failOn = { IRNode.LOAD_VECTOR_L, IRNode.STORE_VECTOR }) 446 public static void testByteByte5a(byte[] dest, byte[] src, int start, int stop) { 447 for (int i = start; i < stop; i++) { 448 UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * (i + baseOffset), UNSAFE.getLongUnaligned(src, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * i)); 449 } 450 } 451 452 @Test 453 @IR(failOn = { IRNode.LOAD_VECTOR_L, IRNode.STORE_VECTOR }) 454 public static void testByteByte5b(byte[] dest, byte[] src, int start, int stop) { 455 for (int i = start; i < stop; i++) { 456 UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * (i + baseOffset), UNSAFE.getLongUnaligned(src, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * i)); 457 } 458 } 459 460 @Run(test = {"testByteByte5a", "testByteByte5b"}) 461 public static void testByteByte5_runner() { 462 baseOffset = 1; 463 runAndVerify2(() -> testByteByte5a(byteArray, byteArray, 0, size-1), 8); 464 runAndVerify2(() -> testByteByte5b(byteArray, byteArray, 0, size-1), 8); 465 } 466 467 @Test 468 @IR(counts = { IRNode.LOAD_VECTOR_L, "=0", IRNode.STORE_VECTOR, "=0" }) // temporary 469 // @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }) 470 // FAILS: adr is CastX2P(dest + 8 * (i + int_con)) 471 // See: JDK-8331576 472 public static void testOffHeapLong1a(long dest, long[] src) { 473 for (int i = 0; i < src.length; i++) { 474 UNSAFE.putLongUnaligned(null, dest + 8 * i, handleByteOrder(src[i])); 475 } 476 } 477 478 @Test 479 @IR(counts = { IRNode.LOAD_VECTOR_L, "=0", IRNode.STORE_VECTOR, "=0" }) // temporary 480 // @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }) 481 // FAILS: adr is CastX2P(dest + 8L * (i + int_con)) 482 // See: JDK-8331576 483 public static void testOffHeapLong1b(long dest, long[] src) { 484 for (int i = 0; i < src.length; i++) { 485 UNSAFE.putLongUnaligned(null, dest + 8L * i, handleByteOrder(src[i])); 486 } 487 } 488 489 @Run(test = {"testOffHeapLong1a", "testOffHeapLong1b"}) 490 public static void testOffHeapLong1_runner() { 491 runAndVerify3(() -> testOffHeapLong1a(baseOffHeap, longArray), 0); 492 runAndVerify3(() -> testOffHeapLong1b(baseOffHeap, longArray), 0); 493 } 494 495 @Test 496 @IR(counts = { IRNode.LOAD_VECTOR_L, "=0", IRNode.STORE_VECTOR, "=0" }) // temporary 497 // @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }) 498 // FAILS: adr is CastX2P 499 // See: JDK-8331576 500 public static void testOffHeapLong2a(long dest, long[] src) { 501 for (int i = 1; i < src.length; i++) { 502 UNSAFE.putLongUnaligned(null, dest + 8 * (i - 1), handleByteOrder(src[i])); 503 } 504 } 505 506 @Test 507 @IR(counts = { IRNode.LOAD_VECTOR_L, "=0", IRNode.STORE_VECTOR, "=0" }) // temporary 508 // @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }) 509 // FAILS: adr is CastX2P 510 // See: JDK-8331576 511 public static void testOffHeapLong2b(long dest, long[] src) { 512 for (int i = 1; i < src.length; i++) { 513 UNSAFE.putLongUnaligned(null, dest + 8L * (i - 1), handleByteOrder(src[i])); 514 } 515 } 516 517 @Run(test = {"testOffHeapLong2a", "testOffHeapLong2b"}) 518 public static void testOffHeapLong2_runner() { 519 runAndVerify3(() -> testOffHeapLong2a(baseOffHeap, longArray), -8); 520 runAndVerify3(() -> testOffHeapLong2b(baseOffHeap, longArray), -8); 521 } 522 523 @Test 524 @IR(counts = { IRNode.LOAD_VECTOR_L, "=0", IRNode.STORE_VECTOR, "=0" }) // temporary 525 // @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }) 526 // FAILS: adr is CastX2P 527 // See: JDK-8331576 528 public static void testOffHeapLong3a(long dest, long[] src) { 529 for (int i = 0; i < src.length - 1; i++) { 530 UNSAFE.putLongUnaligned(null, dest + 8 * (i + 1), handleByteOrder(src[i])); 531 } 532 } 533 534 @Test 535 @IR(counts = { IRNode.LOAD_VECTOR_L, "=0", IRNode.STORE_VECTOR, "=0" }) // temporary 536 // @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }) 537 // FAILS: adr is CastX2P 538 // See: JDK-8331576 539 public static void testOffHeapLong3b(long dest, long[] src) { 540 for (int i = 0; i < src.length - 1; i++) { 541 UNSAFE.putLongUnaligned(null, dest + 8L * (i + 1), handleByteOrder(src[i])); 542 } 543 } 544 545 @Run(test = {"testOffHeapLong3a", "testOffHeapLong3b"}) 546 public static void testOffHeapLong3_runner() { 547 runAndVerify3(() -> testOffHeapLong3a(baseOffHeap, longArray), 8); 548 runAndVerify3(() -> testOffHeapLong3b(baseOffHeap, longArray), 8); 549 } 550 551 @Test 552 @IR(counts = { IRNode.LOAD_VECTOR_L, "=0", IRNode.STORE_VECTOR, "=0" }) // temporary 553 // @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }, 554 // applyIf = {"AlignVector", "false"}) 555 // FAILS: adr is CastX2P 556 // See: JDK-8331576 557 // AlignVector cannot guarantee that invar is aligned. 558 public static void testOffHeapLong4a(long dest, long[] src, int start, int stop) { 559 for (int i = start; i < stop; i++) { 560 UNSAFE.putLongUnaligned(null, dest + 8 * i + baseOffset, handleByteOrder(src[i])); 561 } 562 } 563 564 @Test 565 @IR(counts = { IRNode.LOAD_VECTOR_L, "=0", IRNode.STORE_VECTOR, "=0" }) // temporary 566 // @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }, 567 // applyIf = {"AlignVector", "false"}) 568 // FAILS: adr is CastX2P 569 // See: JDK-8331576 570 // AlignVector cannot guarantee that invar is aligned. 571 public static void testOffHeapLong4b(long dest, long[] src, int start, int stop) { 572 for (int i = start; i < stop; i++) { 573 UNSAFE.putLongUnaligned(null, dest + 8L * i + baseOffset, handleByteOrder(src[i])); 574 } 575 } 576 577 @Run(test = {"testOffHeapLong4a", "testOffHeapLong4b"}) 578 public static void testOffHeapLong4_runner() { 579 baseOffset = 8; 580 runAndVerify3(() -> testOffHeapLong4a(baseOffHeap, longArray, 0, size-1), 8); 581 runAndVerify3(() -> testOffHeapLong4b(baseOffHeap, longArray, 0, size-1), 8); 582 } 583 }