Path: blob/master/test/lib/sun/hotspot/cpuinfo/CPUInfo.java
66644 views
/*1* Copyright (c) 2014, 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*/2223package sun.hotspot.cpuinfo;2425import java.util.List;26import java.util.Arrays;27import java.util.Collections;28import java.util.regex.Pattern;29import java.util.regex.Matcher;3031import sun.hotspot.WhiteBox;3233/**34* Information about CPU on test box.35*36* CPUInfo uses WhiteBox to gather information,37* so WhiteBox class should be added to bootclasspath38* and option -XX:+WhiteBoxAPI should be explicitly39* specified on command line.40*/41@Deprecated42public class CPUInfo {4344private static final List<String> features;45private static final String additionalCPUInfo;4647static {48WhiteBox wb = WhiteBox.getWhiteBox();4950Pattern additionalCPUInfoRE =51Pattern.compile("([^(]*\\([^)]*\\)[^,]*),\\s*");5253String cpuFeaturesString = wb.getCPUFeatures();54Matcher matcher = additionalCPUInfoRE.matcher(cpuFeaturesString);55if (matcher.find()) {56additionalCPUInfo = matcher.group(1);57} else {58additionalCPUInfo = "";59}60String splittedFeatures[] = matcher.replaceAll("").split("(, )| ");6162features = Collections.unmodifiableList(Arrays.63asList(splittedFeatures));64}6566/**67* Get additional information about CPU.68* For example, on X86 in will be family/model/stepping69* and number of cores.70*71* @return additional CPU info72*/73public static String getAdditionalCPUInfo() {74return additionalCPUInfo;75}7677/**78* Get all known features supported by CPU.79*80* @return unmodifiable list with names of all known features81* supported by CPU.82*/83public static List<String> getFeatures() {84return features;85}8687/**88* Check if some feature is supported by CPU.89*90* @param feature Name of feature to be tested.91* @return <b>true</b> if tested feature is supported by CPU.92*/93public static boolean hasFeature(String feature) {94return features.contains(feature.toLowerCase());95}96}979899