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