1 /* 2 * Copyright (c) 2023, Red Hat, Inc. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package compiler.c2.irTests; 25 26 import compiler.lib.ir_framework.*; 27 import jdk.test.lib.Utils; 28 import jdk.internal.misc.Unsafe; 29 import java.util.Objects; 30 import java.util.Random; 31 32 /* 33 * @test 34 * @bug 8300256 35 * @modules java.base/jdk.internal.misc 36 * @library /test/lib / 37 * @run driver compiler.c2.irTests.TestVectorizationNotRun 38 */ 39 40 public class TestVectorizationNotRun { 41 private static final Unsafe UNSAFE = Unsafe.getUnsafe(); 42 43 public static void main(String[] args) { 44 // Cross-product: +-AlignVector and +-UseCompactObjectHeaders 45 TestFramework.runWithFlags("--add-modules", "java.base", "--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED", 46 "-XX:+UnlockExperimentalVMOptions", "-XX:-UseCompactObjectHeaders", 47 "-XX:-AlignVector"); 48 TestFramework.runWithFlags("--add-modules", "java.base", "--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED", 49 "-XX:+UnlockExperimentalVMOptions", "-XX:-UseCompactObjectHeaders", 50 "-XX:+AlignVector"); 51 TestFramework.runWithFlags("--add-modules", "java.base", "--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED", 52 "-XX:+UnlockExperimentalVMOptions", "-XX:+UseCompactObjectHeaders", 53 "-XX:-AlignVector"); 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 } 58 59 static int size = 1024; 60 static int sizeBytes = 8 * size; 61 static byte[] byteArray = new byte[sizeBytes]; 62 static long[] longArray = new long[size]; 63 64 @Test 65 @IR(counts = { IRNode.LOAD_VECTOR_L, ">=1", IRNode.STORE_VECTOR, ">=1" }, 66 applyIfOr = { "UseCompactObjectHeaders", "false", "AlignVector", "false" }, 67 applyIfPlatform = {"64-bit", "true"}, 68 applyIfCPUFeatureOr = {"sse4.1", "true", "asimd", "true"}) 69 public static void test(byte[] dest, long[] src) { 70 for (int i = 0; i < src.length; i++) { 71 if ((i < 0) || (8 > sizeBytes - i)) { 72 throw new IndexOutOfBoundsException(); 73 } 74 UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + i * 8, src[i]); 75 // For UseCompactObjectHeaders and AlignVector, we must 8-byte align all vector loads/stores. 76 // But the long-stores to the byte-array are never aligned: 77 // adr = base + UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8*iter 78 // = 16 (or 12 if UseCompactObjectHeaders=true) 79 } 80 } 81 82 @Run(test = "test") 83 public static void test_runner() { 84 test(byteArray, longArray); 85 } 86 }