1 /* 2 * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. 3 * Copyright (c) 2020, Arm Ltd. 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 26 /** 27 * @test 28 * 29 * @requires os.arch == "aarch64" & vm.compiler2.enabled 30 * @summary Verify VM SVE checking behavior 31 * @library /test/lib 32 * @run main/othervm/native compiler.c2.aarch64.TestSVEWithJNI 33 * 34 */ 35 36 package compiler.c2.aarch64; 37 38 import java.util.ArrayList; 39 import java.util.Collections; 40 import java.util.List; 41 import jdk.test.lib.process.ProcessTools; 42 import jdk.test.lib.process.OutputAnalyzer; 43 44 public class TestSVEWithJNI { 45 static { 46 System.loadLibrary("TestSVEWithJNI"); 47 } 48 49 static final int EXIT_CODE = 99; 50 // Returns a nonnegative on success, or a negative value on error. 51 public static native int setVectorLength(int arg); 52 // Returns a nonnegative value on success, or a negative value on error. 53 public static native int getVectorLength(); 54 55 public static final String MSG = "Current Vector Size: "; 56 public static void testNormal() { 57 int vlen = getVectorLength(); 58 System.out.println(MSG + vlen); 59 // Should be fine if no vector length changed. 60 if (setVectorLength(vlen) < 0) { 61 throw new Error("Error in setting vector length."); 62 } 63 } 64 65 public static void testAbort() { 66 int vlen = getVectorLength(); 67 if (vlen <= 16) { 68 throw new Error("Error: unsupported vector length."); 69 } 70 if (setVectorLength(16) < 0) { 71 throw new Error("Error: setting vector length failed."); 72 } 73 } 74 75 public static ProcessBuilder createProcessBuilder(String [] args, String mode) { 76 List<String> vmopts = new ArrayList<>(); 77 String testjdkPath = System.getProperty("test.jdk"); 78 Collections.addAll(vmopts, "-Dtest.jdk=" + testjdkPath); 79 Collections.addAll(vmopts, args); 80 Collections.addAll(vmopts, TestSVEWithJNI.class.getName(), mode); 81 return ProcessTools.createJavaProcessBuilder(vmopts.toArray(new String[vmopts.size()])); 82 } 83 84 public static void main(String [] args) throws Exception { 85 if (args.length == 0) { 86 int vlen = getVectorLength(); 87 if (vlen < 0) { 88 return; 89 } 90 String [][] testOpts = { 91 {"-Xint", "-XX:UseSVE=1"}, 92 {"-Xcomp", "-XX:UseSVE=1"}, 93 }; 94 ProcessBuilder pb; 95 OutputAnalyzer output; 96 for (String [] opts : testOpts) { 97 pb = createProcessBuilder(opts, "normal"); 98 output = new OutputAnalyzer(pb.start()); 99 output.shouldHaveExitValue(EXIT_CODE); 100 101 pb = createProcessBuilder(opts, "abort"); 102 output = new OutputAnalyzer(pb.start()); 103 output.shouldNotHaveExitValue(EXIT_CODE); 104 output.shouldMatch("(error|Error|ERROR)"); 105 } 106 107 // Verify MaxVectorSize 108 109 // Any SVE architecture should support 128-bit vector size. 110 pb = createProcessBuilder(new String []{"-XX:UseSVE=1", "-XX:MaxVectorSize=16"}, "normal"); 111 output = new OutputAnalyzer(pb.start()); 112 output.shouldHaveExitValue(EXIT_CODE); 113 output.shouldContain(MSG + 16); 114 115 // An unsupported large vector size value. 116 pb = createProcessBuilder(new String []{"-XX:UseSVE=1", "-XX:MaxVectorSize=512"}, "normal"); 117 output = new OutputAnalyzer(pb.start()); 118 output.shouldHaveExitValue(EXIT_CODE); 119 output.shouldContain("warning"); 120 } else if (args[0].equals("normal")) { 121 testNormal(); 122 System.exit(EXIT_CODE); 123 } else if (args[0].equals("abort")) { 124 testAbort(); 125 System.exit(EXIT_CODE); 126 } 127 } 128 }