< prev index next >

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

Print this page

 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.test.whitebox.WhiteBox;
 29 import jdk.internal.misc.Unsafe;
 30 import java.util.Random;
 31 import java.util.Arrays;
 32 import java.nio.ByteOrder;
 33 







 34 /*
 35  * @test
 36  * @bug 8300258
 37  * @key randomness
 38  * @requires (os.simpleArch == "x64") | (os.simpleArch == "aarch64")
 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);

 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.test.whitebox.WhiteBox;
 29 import jdk.internal.misc.Unsafe;
 30 import java.util.Random;
 31 import java.util.Arrays;
 32 import java.nio.ByteOrder;
 33 
 34 // Note Lilliput:
 35 // Tests test that vectorization is used to fill destination byte array if alignment allows. That works in Stock VM
 36 // since for both byte[] and long[] members start at the same offset. It does not work in Lilliput, nor would it work
 37 // in stock if we fix "8139457: Array bases are aligned at HeapWord granularity", since bytes start at offset 12, long
 38 // at offset 16.
 39 // For now I just enforce -CompactObjectHeaders.
 40 
 41 /*
 42  * @test
 43  * @bug 8300258
 44  * @key randomness
 45  * @requires (os.simpleArch == "x64") | (os.simpleArch == "aarch64")
 46  * @summary C2: vectorization fails on simple ByteBuffer loop
 47  * @modules java.base/jdk.internal.misc
 48  * @library /test/lib /
 49  * @build jdk.test.whitebox.WhiteBox
 50  * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
 51  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI compiler.c2.irTests.TestVectorizationMismatchedAccess
 52  */
 53 
 54 public class TestVectorizationMismatchedAccess {
 55     private static final Unsafe UNSAFE = Unsafe.getUnsafe();
 56     private static final Random RANDOM = Utils.getRandomInstance();
 57     private final static WhiteBox wb = WhiteBox.getWhiteBox();
 58 
 59     public static void main(String[] args) {
 60         Object alignVector = wb.getVMFlag("AlignVector");
 61         if (alignVector != null && !((Boolean)alignVector)) {
 62             if (ByteOrder.nativeOrder() != ByteOrder.LITTLE_ENDIAN) {
 63                 throw new RuntimeException("fix test that was written for a little endian platform");
 64             }
 65             TestFramework.runWithFlags("-XX:+UnlockExperimentalVMOptions", "-XX:-UseCompactObjectHeaders", "--add-modules", "java.base", "--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED");
 66         }
 67     }
 68 
 69     static int size = 1024;
 70     static byte[] byteArray = new byte[size * 8];
 71     static long[] longArray = new long[size];
 72     static byte[] verifyByteArray = new byte[size * 8];
 73     static long[] verifyLongArray = new long[size];
 74     static long baseOffset = 0;
 75     static long baseOffHeap = UNSAFE.allocateMemory(size * 8);
 76 
 77 
 78     static {
 79         for (int i = 0; i < verifyByteArray.length; i++) {
 80             verifyByteArray[i] = (byte)RANDOM.nextInt(Byte.MAX_VALUE);
 81         }
 82         for (int i = 0; i < verifyLongArray.length; i++) {
 83             verifyLongArray[i] = 0;
 84             for (int j = 0; j < 8; j++) {
 85                 verifyLongArray[i] = verifyLongArray[i] | (((long)verifyByteArray[8 * i + j]) << 8 * j);
< prev index next >