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 Object alignVector = wb.getVMFlag("AlignVector"); 54 if (alignVector != null && !((Boolean)alignVector)) { 55 if (ByteOrder.nativeOrder() != ByteOrder.LITTLE_ENDIAN) { 56 throw new RuntimeException("fix test that was written for a little endian platform"); 57 } 58 TestFramework.runWithFlags("--add-modules", "java.base", "--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED"); 59 } 60 } 61 62 static int size = 1024; 63 static byte[] byteArray = new byte[size * 8]; 64 static long[] longArray = new long[size]; 65 static byte[] verifyByteArray = new byte[size * 8]; 66 static long[] verifyLongArray = new long[size]; 67 static long baseOffset = 0; 68 static long baseOffHeap = UNSAFE.allocateMemory(size * 8); 69 70 71 static { 72 for (int i = 0; i < verifyByteArray.length; i++) { 73 verifyByteArray[i] = (byte)RANDOM.nextInt(Byte.MAX_VALUE); 74 } 75 for (int i = 0; i < verifyLongArray.length; i++) { 76 verifyLongArray[i] = 0; 77 for (int j = 0; j < 8; j++) { 78 verifyLongArray[i] = verifyLongArray[i] | (((long)verifyByteArray[8 * i + j]) << 8 * j); 79 } 80 } 81 } 82 83 static private void runAndVerify(Runnable test, int offset) { 84 System.arraycopy(verifyLongArray, 0, longArray, 0, longArray.length); 85 Arrays.fill(byteArray, (byte)0); 86 test.run(); 87 int i; 88 for (i = 0; i < Math.max(offset, 0); i++) { 89 if (byteArray[i] != 0) { 90 throw new RuntimeException("Incorrect result at " + i + " " + byteArray[i] + " != 0"); 91 } 92 } 93 for (; i < Math.min(byteArray.length + offset, byteArray.length); i++) { 94 if (byteArray[i] != verifyByteArray[i - offset]) { 95 throw new RuntimeException("Incorrect result at " + i + " " + byteArray[i] + " != " + verifyByteArray[i-offset]); 96 } 97 } 98 for (; i < byteArray.length; i++) { 99 if (byteArray[i] != 0) { 100 throw new RuntimeException("Incorrect result at " + i + " " + byteArray[i] + " != 0"); 101 } 102 } 103 } 104 105 static private void runAndVerify2(Runnable test, int offset) { 106 System.arraycopy(verifyByteArray, 0, byteArray, 0, byteArray.length); 107 test.run(); 108 int i; 109 for (i = 0; i < Math.max(offset, 0); i++) { 110 if (byteArray[i] != verifyByteArray[i]) { 111 throw new RuntimeException("Incorrect result at " + i + " " + byteArray[i] + " != " + verifyByteArray[i]); 112 } 113 } 114 for (; i < Math.min(byteArray.length + offset, byteArray.length); i++) { 115 int val = offset > 0 ? verifyByteArray[(i-offset) % 8] : verifyByteArray[i-offset]; 116 if (byteArray[i] != val) { 117 throw new RuntimeException("Incorrect result at " + i + " " + byteArray[i] + " != " + verifyByteArray[i-offset]); 118 } 119 } 120 for (; i < byteArray.length; i++) { 121 if (byteArray[i] != verifyByteArray[i]) { 122 throw new RuntimeException("Incorrect result at " + i + " " + byteArray[i] + " != " + verifyByteArray[i]); 123 } 124 } 125 } 126 127 128 static private void runAndVerify3(Runnable test, int offset) { 129 System.arraycopy(verifyLongArray, 0, longArray, 0, longArray.length); 130 for (int i = 0; i < size * 8; i++) { 131 UNSAFE.putByte(null, baseOffHeap + i, (byte)0); 132 } 133 test.run(); 134 int i; 135 for (i = 0; i < Math.max(offset, 0); i++) { 136 if (UNSAFE.getByte(null, baseOffHeap + i) != 0) { 137 throw new RuntimeException("Incorrect result at " + i + " " + byteArray[i] + " != 0"); 138 } 139 } 140 for (; i < Math.min(size * 8 + offset, size * 8); i++) { 141 if (UNSAFE.getByte(null, baseOffHeap + i) != verifyByteArray[i - offset]) { 142 throw new RuntimeException("Incorrect result at " + i + " " + byteArray[i] + " != " + verifyByteArray[i-offset]); 143 } 144 } 145 for (; i < byteArray.length; i++) { 146 if (UNSAFE.getByte(null, baseOffHeap + i) != 0) { 147 throw new RuntimeException("Incorrect result at " + i + " " + byteArray[i] + " != 0"); 148 } 149 } 150 } 151 152 @Test 153 @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }, 154 applyIfCPUFeatureOr = {"sse2", "true", "asimd", "true"}, 155 applyIfPlatform = {"64-bit", "true"}, 156 applyIf = {"UseCompactObjectHeaders", "false"}) 157 // 32-bit: offsets are badly aligned (UNSAFE.ARRAY_BYTE_BASE_OFFSET is 4 byte aligned, but not 8 byte aligned). 158 // might get fixed with JDK-8325155. 159 public static void testByteLong1a(byte[] dest, long[] src) { 160 for (int i = 0; i < src.length; i++) { 161 UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * i, src[i]); 162 } 163 } 164 165 @Test 166 @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }, 167 applyIfCPUFeatureOr = {"sse2", "true", "asimd", "true"}, 168 applyIfPlatform = {"64-bit", "true"}, 169 applyIf = {"UseCompactObjectHeaders", "false"}) 170 // 32-bit: address has ConvL2I for cast of long to address, not supported. 171 public static void testByteLong1b(byte[] dest, long[] src) { 172 for (int i = 0; i < src.length; i++) { 173 UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * i, src[i]); 174 } 175 } 176 177 @Test 178 @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }, 179 applyIfCPUFeatureOr = {"sse2", "true", "asimd", "true"}, 180 applyIf = {"UseCompactObjectHeaders", "false"}) 181 public static void testByteLong1c(byte[] dest, long[] src) { 182 long base = 64; // make sure it is big enough and 8 byte aligned (required for 32-bit) 183 for (int i = 0; i < src.length - 8; i++) { 184 UNSAFE.putLongUnaligned(dest, base + 8 * i, src[i]); 185 } 186 } 187 188 @Test 189 @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }, 190 applyIfCPUFeatureOr = {"sse2", "true", "asimd", "true"}, 191 applyIfPlatform = {"64-bit", "true"}, 192 applyIf = {"UseCompactObjectHeaders", "false"}) 193 // 32-bit: address has ConvL2I for cast of long to address, not supported. 194 public static void testByteLong1d(byte[] dest, long[] src) { 195 long base = 64; // make sure it is big enough and 8 byte aligned (required for 32-bit) 196 for (int i = 0; i < src.length - 8; i++) { 197 UNSAFE.putLongUnaligned(dest, base + 8L * i, src[i]); 198 } 199 } 200 201 @Run(test = {"testByteLong1a", "testByteLong1b", "testByteLong1c", "testByteLong1d"}) 202 public static void testByteLong1_runner() { 203 runAndVerify(() -> testByteLong1a(byteArray, longArray), 0); 204 runAndVerify(() -> testByteLong1b(byteArray, longArray), 0); 205 testByteLong1c(byteArray, longArray); 206 testByteLong1d(byteArray, longArray); 207 } 208 209 @Test 210 @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }, 211 applyIfCPUFeatureOr = {"sse2", "true", "asimd", "true"}, 212 applyIfPlatform = {"64-bit", "true"}, 213 applyIf = {"UseCompactObjectHeaders", "false"}) 214 // 32-bit: offsets are badly aligned (UNSAFE.ARRAY_BYTE_BASE_OFFSET is 4 byte aligned, but not 8 byte aligned). 215 // might get fixed with JDK-8325155. 216 public static void testByteLong2a(byte[] dest, long[] src) { 217 for (int i = 1; i < src.length; i++) { 218 UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * (i - 1), src[i]); 219 } 220 } 221 222 @Test 223 @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }, 224 applyIfCPUFeatureOr = {"sse2", "true", "asimd", "true"}, 225 applyIfPlatform = {"64-bit", "true"}, 226 applyIf = {"UseCompactObjectHeaders", "false"}) 227 // 32-bit: address has ConvL2I for cast of long to address, not supported. 228 public static void testByteLong2b(byte[] dest, long[] src) { 229 for (int i = 1; i < src.length; i++) { 230 UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * (i - 1), src[i]); 231 } 232 } 233 234 @Run(test = {"testByteLong2a", "testByteLong2b"}) 235 public static void testByteLong2_runner() { 236 runAndVerify(() -> testByteLong2a(byteArray, longArray), -8); 237 runAndVerify(() -> testByteLong2b(byteArray, longArray), -8); 238 } 239 240 @Test 241 @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }, 242 applyIfCPUFeatureOr = {"sse2", "true", "asimd", "true"}, 243 applyIfPlatform = {"64-bit", "true"}, 244 applyIf = {"UseCompactObjectHeaders", "false"}) 245 // 32-bit: offsets are badly aligned (UNSAFE.ARRAY_BYTE_BASE_OFFSET is 4 byte aligned, but not 8 byte aligned). 246 // might get fixed with JDK-8325155. 247 public static void testByteLong3a(byte[] dest, long[] src) { 248 for (int i = 0; i < src.length - 1; i++) { 249 UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * (i + 1), src[i]); 250 } 251 } 252 253 @Test 254 @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }, 255 applyIfCPUFeatureOr = {"sse2", "true", "asimd", "true"}, 256 applyIfPlatform = {"64-bit", "true"}, 257 applyIf = {"UseCompactObjectHeaders", "false"}) 258 // 32-bit: address has ConvL2I for cast of long to address, not supported. 259 public static void testByteLong3b(byte[] dest, long[] src) { 260 for (int i = 0; i < src.length - 1; i++) { 261 UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * (i + 1), src[i]); 262 } 263 } 264 265 @Run(test = {"testByteLong3a", "testByteLong3b"}) 266 public static void testByteLong3_runner() { 267 runAndVerify(() -> testByteLong3a(byteArray, longArray), 8); 268 runAndVerify(() -> testByteLong3b(byteArray, longArray), 8); 269 } 270 271 @Test 272 @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }, 273 applyIfCPUFeatureOr = {"sse2", "true", "asimd", "true"}, 274 applyIfPlatform = {"64-bit", "true"}) 275 // 32-bit: offsets are badly aligned (UNSAFE.ARRAY_BYTE_BASE_OFFSET is 4 byte aligned, but not 8 byte aligned). 276 // might get fixed with JDK-8325155. 277 public static void testByteLong4a(byte[] dest, long[] src, int start, int stop) { 278 for (int i = start; i < stop; i++) { 279 UNSAFE.putLongUnaligned(dest, 8 * i + baseOffset, src[i]); 280 } 281 } 282 283 @Test 284 @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }, 285 applyIfCPUFeatureOr = {"sse2", "true", "asimd", "true"}, 286 applyIfPlatform = {"64-bit", "true"}) 287 // 32-bit: address has ConvL2I for cast of long to address, not supported. 288 public static void testByteLong4b(byte[] dest, long[] src, int start, int stop) { 289 for (int i = start; i < stop; i++) { 290 UNSAFE.putLongUnaligned(dest, 8L * i + baseOffset, src[i]); 291 } 292 } 293 294 @Run(test = {"testByteLong4a", "testByteLong4b"}) 295 public static void testByteLong4_runner() { 296 baseOffset = UNSAFE.ARRAY_BYTE_BASE_OFFSET; 297 runAndVerify(() -> testByteLong4a(byteArray, longArray, 0, size), 0); 298 runAndVerify(() -> testByteLong4b(byteArray, longArray, 0, size), 0); 299 } 300 301 @Test 302 @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }, 303 applyIfCPUFeatureOr = {"sse2", "true", "asimd", "true"}, 304 applyIfPlatform = {"64-bit", "true"}, 305 applyIf = {"UseCompactObjectHeaders", "false"}) 306 // 32-bit: offsets are badly aligned (UNSAFE.ARRAY_BYTE_BASE_OFFSET is 4 byte aligned, but not 8 byte aligned). 307 // might get fixed with JDK-8325155. 308 public static void testByteLong5a(byte[] dest, long[] src, int start, int stop) { 309 for (int i = start; i < stop; i++) { 310 UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * (i + baseOffset), src[i]); 311 } 312 } 313 314 @Test 315 @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }, 316 applyIfCPUFeatureOr = {"sse2", "true", "asimd", "true"}, 317 applyIfPlatform = {"64-bit", "true"}, 318 applyIf = {"UseCompactObjectHeaders", "false"}) 319 // 32-bit: address has ConvL2I for cast of long to address, not supported. 320 public static void testByteLong5b(byte[] dest, long[] src, int start, int stop) { 321 for (int i = start; i < stop; i++) { 322 UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * (i + baseOffset), src[i]); 323 } 324 } 325 326 @Run(test = {"testByteLong5a", "testByteLong5b"}) 327 public static void testByteLong5_runner() { 328 baseOffset = 1; 329 runAndVerify(() -> testByteLong5a(byteArray, longArray, 0, size-1), 8); 330 runAndVerify(() -> testByteLong5b(byteArray, longArray, 0, size-1), 8); 331 } 332 333 @Test 334 @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }, 335 applyIfCPUFeatureOr = {"sse2", "true", "asimd", "true"}, 336 applyIfPlatform = {"64-bit", "true"}, 337 applyIf = {"UseCompactObjectHeaders", "false"}) 338 // 32-bit: offsets are badly aligned (UNSAFE.ARRAY_BYTE_BASE_OFFSET is 4 byte aligned, but not 8 byte aligned). 339 // might get fixed with JDK-8325155. 340 public static void testByteByte1a(byte[] dest, byte[] src) { 341 for (int i = 0; i < src.length / 8; i++) { 342 UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * i, UNSAFE.getLongUnaligned(src, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * i)); 343 } 344 } 345 346 @Test 347 @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }, 348 applyIfCPUFeatureOr = {"sse2", "true", "asimd", "true"}, 349 applyIfPlatform = {"64-bit", "true"}, 350 applyIf = {"UseCompactObjectHeaders", "false"}) 351 // 32-bit: address has ConvL2I for cast of long to address, not supported. 352 public static void testByteByte1b(byte[] dest, byte[] src) { 353 for (int i = 0; i < src.length / 8; i++) { 354 UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * i, UNSAFE.getLongUnaligned(src, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * i)); 355 } 356 } 357 358 @Run(test = {"testByteByte1a", "testByteByte1b"}) 359 public static void testByteByte1_runner() { 360 runAndVerify2(() -> testByteByte1a(byteArray, byteArray), 0); 361 runAndVerify2(() -> testByteByte1b(byteArray, byteArray), 0); 362 } 363 364 @Test 365 // It would be legal to vectorize this one but it's not currently 366 //@IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }, 367 // applyIfCPUFeatureOr = {"sse2", "true", "asimd", "true"}, 368 // applyIfPlatform = {"64-bit", "true"}) 369 // 32-bit: offsets are badly aligned (UNSAFE.ARRAY_BYTE_BASE_OFFSET is 4 byte aligned, but not 8 byte aligned). 370 // might get fixed with JDK-8325155. 371 public static void testByteByte2a(byte[] dest, byte[] src) { 372 for (int i = 1; i < src.length / 8; i++) { 373 UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * (i - 1), UNSAFE.getLongUnaligned(src, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * i)); 374 } 375 } 376 377 @Test 378 // It would be legal to vectorize this one but it's not currently 379 //@IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }, 380 // applyIfCPUFeatureOr = {"sse2", "true", "asimd", "true"}, 381 // applyIfPlatform = {"64-bit", "true"}) 382 // 32-bit: address has ConvL2I for cast of long to address, not supported. 383 public static void testByteByte2b(byte[] dest, byte[] src) { 384 for (int i = 1; i < src.length / 8; i++) { 385 UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * (i - 1), UNSAFE.getLongUnaligned(src, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * i)); 386 } 387 } 388 389 @Run(test = {"testByteByte2a", "testByteByte2b"}) 390 public static void testByteByte2_runner() { 391 runAndVerify2(() -> testByteByte2a(byteArray, byteArray), -8); 392 runAndVerify2(() -> testByteByte2b(byteArray, byteArray), -8); 393 } 394 395 @Test 396 @IR(failOn = { IRNode.LOAD_VECTOR_L, IRNode.STORE_VECTOR }) 397 public static void testByteByte3a(byte[] dest, byte[] src) { 398 for (int i = 0; i < src.length / 8 - 1; i++) { 399 UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * (i + 1), UNSAFE.getLongUnaligned(src, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * i)); 400 } 401 } 402 403 @Test 404 @IR(failOn = { IRNode.LOAD_VECTOR_L, IRNode.STORE_VECTOR }) 405 public static void testByteByte3b(byte[] dest, byte[] src) { 406 for (int i = 0; i < src.length / 8 - 1; i++) { 407 UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * (i + 1), UNSAFE.getLongUnaligned(src, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * i)); 408 } 409 } 410 411 @Run(test = {"testByteByte3a", "testByteByte3b"}) 412 public static void testByteByte3_runner() { 413 runAndVerify2(() -> testByteByte3a(byteArray, byteArray), 8); 414 runAndVerify2(() -> testByteByte3b(byteArray, byteArray), 8); 415 } 416 417 @Test 418 @IR(failOn = { IRNode.LOAD_VECTOR_L, IRNode.STORE_VECTOR }) 419 public static void testByteByte4a(byte[] dest, byte[] src, int start, int stop) { 420 for (int i = start; i < stop; i++) { 421 UNSAFE.putLongUnaligned(dest, 8 * i + baseOffset, UNSAFE.getLongUnaligned(src, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * i)); 422 } 423 } 424 425 @Test 426 @IR(failOn = { IRNode.LOAD_VECTOR_L, IRNode.STORE_VECTOR }) 427 public static void testByteByte4b(byte[] dest, byte[] src, int start, int stop) { 428 for (int i = start; i < stop; i++) { 429 UNSAFE.putLongUnaligned(dest, 8L * i + baseOffset, UNSAFE.getLongUnaligned(src, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * i)); 430 } 431 } 432 433 @Run(test = {"testByteByte4a", "testByteByte4b"}) 434 public static void testByteByte4_runner() { 435 baseOffset = UNSAFE.ARRAY_BYTE_BASE_OFFSET; 436 runAndVerify2(() -> testByteByte4a(byteArray, byteArray, 0, size), 0); 437 runAndVerify2(() -> testByteByte4b(byteArray, byteArray, 0, size), 0); 438 } 439 440 @Test 441 @IR(failOn = { IRNode.LOAD_VECTOR_L, IRNode.STORE_VECTOR }) 442 public static void testByteByte5a(byte[] dest, byte[] src, int start, int stop) { 443 for (int i = start; i < stop; i++) { 444 UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * (i + baseOffset), UNSAFE.getLongUnaligned(src, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * i)); 445 } 446 } 447 448 @Test 449 @IR(failOn = { IRNode.LOAD_VECTOR_L, IRNode.STORE_VECTOR }) 450 public static void testByteByte5b(byte[] dest, byte[] src, int start, int stop) { 451 for (int i = start; i < stop; i++) { 452 UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * (i + baseOffset), UNSAFE.getLongUnaligned(src, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * i)); 453 } 454 } 455 456 @Run(test = {"testByteByte5a", "testByteByte5b"}) 457 public static void testByteByte5_runner() { 458 baseOffset = 1; 459 runAndVerify2(() -> testByteByte5a(byteArray, byteArray, 0, size-1), 8); 460 runAndVerify2(() -> testByteByte5b(byteArray, byteArray, 0, size-1), 8); 461 } 462 463 @Test 464 @IR(counts = { IRNode.LOAD_VECTOR_L, "=0", IRNode.STORE_VECTOR, "=0" }) // temporary 465 // @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }) 466 // FAILS: adr is CastX2P(dest + 8 * (i + int_con)) 467 // See: JDK-8331576 468 public static void testOffHeapLong1a(long dest, long[] src) { 469 for (int i = 0; i < src.length; i++) { 470 UNSAFE.putLongUnaligned(null, dest + 8 * i, src[i]); 471 } 472 } 473 474 @Test 475 @IR(counts = { IRNode.LOAD_VECTOR_L, "=0", IRNode.STORE_VECTOR, "=0" }) // temporary 476 // @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }) 477 // FAILS: adr is CastX2P(dest + 8L * (i + int_con)) 478 // See: JDK-8331576 479 public static void testOffHeapLong1b(long dest, long[] src) { 480 for (int i = 0; i < src.length; i++) { 481 UNSAFE.putLongUnaligned(null, dest + 8L * i, src[i]); 482 } 483 } 484 485 @Run(test = {"testOffHeapLong1a", "testOffHeapLong1b"}) 486 public static void testOffHeapLong1_runner() { 487 runAndVerify3(() -> testOffHeapLong1a(baseOffHeap, longArray), 0); 488 runAndVerify3(() -> testOffHeapLong1b(baseOffHeap, longArray), 0); 489 } 490 491 @Test 492 @IR(counts = { IRNode.LOAD_VECTOR_L, "=0", IRNode.STORE_VECTOR, "=0" }) // temporary 493 // @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }) 494 // FAILS: adr is CastX2P 495 // See: JDK-8331576 496 public static void testOffHeapLong2a(long dest, long[] src) { 497 for (int i = 1; i < src.length; i++) { 498 UNSAFE.putLongUnaligned(null, dest + 8 * (i - 1), src[i]); 499 } 500 } 501 502 @Test 503 @IR(counts = { IRNode.LOAD_VECTOR_L, "=0", IRNode.STORE_VECTOR, "=0" }) // temporary 504 // @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }) 505 // FAILS: adr is CastX2P 506 // See: JDK-8331576 507 public static void testOffHeapLong2b(long dest, long[] src) { 508 for (int i = 1; i < src.length; i++) { 509 UNSAFE.putLongUnaligned(null, dest + 8L * (i - 1), src[i]); 510 } 511 } 512 513 @Run(test = {"testOffHeapLong2a", "testOffHeapLong2b"}) 514 public static void testOffHeapLong2_runner() { 515 runAndVerify3(() -> testOffHeapLong2a(baseOffHeap, longArray), -8); 516 runAndVerify3(() -> testOffHeapLong2b(baseOffHeap, longArray), -8); 517 } 518 519 @Test 520 @IR(counts = { IRNode.LOAD_VECTOR_L, "=0", IRNode.STORE_VECTOR, "=0" }) // temporary 521 // @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }) 522 // FAILS: adr is CastX2P 523 // See: JDK-8331576 524 public static void testOffHeapLong3a(long dest, long[] src) { 525 for (int i = 0; i < src.length - 1; i++) { 526 UNSAFE.putLongUnaligned(null, dest + 8 * (i + 1), src[i]); 527 } 528 } 529 530 @Test 531 @IR(counts = { IRNode.LOAD_VECTOR_L, "=0", IRNode.STORE_VECTOR, "=0" }) // temporary 532 // @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }) 533 // FAILS: adr is CastX2P 534 // See: JDK-8331576 535 public static void testOffHeapLong3b(long dest, long[] src) { 536 for (int i = 0; i < src.length - 1; i++) { 537 UNSAFE.putLongUnaligned(null, dest + 8L * (i + 1), src[i]); 538 } 539 } 540 541 @Run(test = {"testOffHeapLong3a", "testOffHeapLong3b"}) 542 public static void testOffHeapLong3_runner() { 543 runAndVerify3(() -> testOffHeapLong3a(baseOffHeap, longArray), 8); 544 runAndVerify3(() -> testOffHeapLong3b(baseOffHeap, longArray), 8); 545 } 546 547 @Test 548 @IR(counts = { IRNode.LOAD_VECTOR_L, "=0", IRNode.STORE_VECTOR, "=0" }) // temporary 549 // @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }) 550 // FAILS: adr is CastX2P 551 // See: JDK-8331576 552 public static void testOffHeapLong4a(long dest, long[] src, int start, int stop) { 553 for (int i = start; i < stop; i++) { 554 UNSAFE.putLongUnaligned(null, dest + 8 * i + baseOffset, src[i]); 555 } 556 } 557 558 @Test 559 @IR(counts = { IRNode.LOAD_VECTOR_L, "=0", IRNode.STORE_VECTOR, "=0" }) // temporary 560 // @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }) 561 // FAILS: adr is CastX2P 562 // See: JDK-8331576 563 public static void testOffHeapLong4b(long dest, long[] src, int start, int stop) { 564 for (int i = start; i < stop; i++) { 565 UNSAFE.putLongUnaligned(null, dest + 8L * i + baseOffset, src[i]); 566 } 567 } 568 569 @Run(test = {"testOffHeapLong4a", "testOffHeapLong4b"}) 570 public static void testOffHeapLong4_runner() { 571 baseOffset = 8; 572 runAndVerify3(() -> testOffHeapLong4a(baseOffHeap, longArray, 0, size-1), 8); 573 runAndVerify3(() -> testOffHeapLong4b(baseOffHeap, longArray, 0, size-1), 8); 574 } 575 }