Path: blob/master/test/lib-test/sun/hotspot/whitebox/CPUInfoTest.java
41149 views
/*1* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @library /test/lib /26*27* @build sun.hotspot.WhiteBox28* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox29* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions30* -XX:+WhiteBoxAPI31* CPUInfoTest32*/3334import java.util.Set;35import java.util.List;36import jdk.test.lib.Platform;37import sun.hotspot.WhiteBox;38import sun.hotspot.cpuinfo.CPUInfo;3940import static jdk.test.lib.Asserts.*;4142public class CPUInfoTest {43static final WhiteBox WB = WhiteBox.getWhiteBox();4445private static final Set<String> wellKnownCPUFeatures;4647static {48if (Platform.isX86() || Platform.isX64()) {49// @formatter:off50// Checkstyle: stop51// See hotspot/cpu/x86/vm_version_x86.hpp for the list of supported features.52wellKnownCPUFeatures = Set.of(53"cx8", "cmov", "fxsr", "ht",54"mmx", "3dnowpref", "sse", "sse2",55"sse3", "ssse3", "sse4a", "sse4.1",56"sse4.2", "popcnt", "lzcnt", "tsc",57"tscinvbit", "tscinv", "avx", "avx2",58"aes", "erms", "clmul", "bmi1",59"bmi2", "rtm", "adx", "avx512f",60"avx512dq", "avx512pf", "avx512er", "avx512cd",61"avx512bw", "avx512vl", "sha", "fma",62"vzeroupper", "avx512_vpopcntdq", "avx512_vpclmulqdq", "avx512_vaes",63"avx512_vnni", "clflush", "clflushopt", "clwb",64"avx512_vbmi2", "avx512_vbmi", "hv"65);66// @formatter:on67// Checkstyle: resume68} else {69wellKnownCPUFeatures = null;70}71}7273public static void main(String args[]) throws Throwable {74System.out.println("WB.getCPUFeatures(): \"" + WB.getCPUFeatures() + "\"");7576String additionalCpuInfo = CPUInfo.getAdditionalCPUInfo();77assertTrue(additionalCpuInfo != null);78System.out.println("CPUInfo.getAdditionalCPUInfo(): \"" + additionalCpuInfo + "\"");7980List<String> features = CPUInfo.getFeatures();81assertTrue(features != null);82System.out.println("CPUInfo.getFeatures(): " + features);8384for (String feature : features) {85assertTrue(CPUInfo.hasFeature(feature), feature);86}8788if (wellKnownCPUFeatures != null) {89System.out.println("Well-known CPU features: " + wellKnownCPUFeatures);90assertTrue(wellKnownCPUFeatures.containsAll(features), "not all features are known");91}9293System.out.println("TEST PASSED");94}95}969798