1 /* 2 * Copyright (c) 2020, Oracle and/or its affiliates. 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 /** 25 * @test 26 * @library /test/lib / 27 * 28 * @build sun.hotspot.WhiteBox 29 * @run driver ClassFileInstaller sun.hotspot.WhiteBox 30 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 31 * -XX:+WhiteBoxAPI 32 * CPUInfoTest 33 */ 34 35 import java.util.Set; 36 import java.util.List; 37 import jdk.test.lib.Platform; 38 import sun.hotspot.WhiteBox; 39 import sun.hotspot.cpuinfo.CPUInfo; 40 41 import static jdk.test.lib.Asserts.*; 42 43 public class CPUInfoTest { 44 static final WhiteBox WB = WhiteBox.getWhiteBox(); 45 46 private static final Set<String> wellKnownCPUFeatures; 47 48 static { 49 if (Platform.isX86() || Platform.isX64()) { 50 wellKnownCPUFeatures = Set.of( 51 "adx", "aes", "bmi1", "bmi2", "cmov", "cx8", "fxsr", "mmx", "clmul", "clflush", "clflushopt", "clwb", 52 "sha", "fma", "popcnt", "vzeroupper", "erms", "rtm", "mmxext", "3dnowpref", "lzcnt", "ht", 53 "tsc", "tscinvbit", "tscinv", "sse", "sse2", "sse3", "ssse3", "sse4.1", "sse4.2", "sse4a", "avx", "avx2", 54 "avx512f", "avx512dq", "avx512pf", "avx512er", "avx512cd", "avx512bw", "avx512vl", 55 "avx512_vpopcntdq", "avx512_vpclmulqdq", "avx512_vbmi2", "avx512_vaes", "avx512_vnni"); 56 } else { 57 wellKnownCPUFeatures = null; 58 } 59 } 60 main(String args[])61 public static void main(String args[]) throws Throwable { 62 System.out.println("WB.getCPUFeatures(): \"" + WB.getCPUFeatures() + "\""); 63 64 String additionalCpuInfo = CPUInfo.getAdditionalCPUInfo(); 65 assertTrue(additionalCpuInfo != null); 66 System.out.println("CPUInfo.getAdditionalCPUInfo(): \"" + additionalCpuInfo + "\""); 67 68 List<String> features = CPUInfo.getFeatures(); 69 assertTrue(features != null); 70 System.out.println("CPUInfo.getFeatures(): " + features); 71 72 for (String feature : features) { 73 assertTrue(CPUInfo.hasFeature(feature), feature); 74 } 75 76 if (wellKnownCPUFeatures != null) { 77 System.out.println("Well-known CPU features: " + wellKnownCPUFeatures); 78 assertTrue(wellKnownCPUFeatures.containsAll(features), "not all features are known"); 79 } 80 81 System.out.println("TEST PASSED"); 82 } 83 } 84