Path: blob/master/test/lib/sun/hotspot/cpuinfo/CPUInfo.java
41152 views
/*1* Copyright (c) 2014, 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*/41public class CPUInfo {4243private static final List<String> features;44private static final String additionalCPUInfo;4546static {47WhiteBox wb = WhiteBox.getWhiteBox();4849Pattern additionalCPUInfoRE =50Pattern.compile("([^(]*\\([^)]*\\)[^,]*),\\s*");5152String cpuFeaturesString = wb.getCPUFeatures();53Matcher matcher = additionalCPUInfoRE.matcher(cpuFeaturesString);54if (matcher.find()) {55additionalCPUInfo = matcher.group(1);56} else {57additionalCPUInfo = "";58}59String splittedFeatures[] = matcher.replaceAll("").split("(, )| ");6061features = Collections.unmodifiableList(Arrays.62asList(splittedFeatures));63}6465/**66* Get additional information about CPU.67* For example, on X86 in will be family/model/stepping68* and number of cores.69*70* @return additional CPU info71*/72public static String getAdditionalCPUInfo() {73return additionalCPUInfo;74}7576/**77* Get all known features supported by CPU.78*79* @return unmodifiable list with names of all known features80* supported by CPU.81*/82public static List<String> getFeatures() {83return features;84}8586/**87* Check if some feature is supported by CPU.88*89* @param feature Name of feature to be tested.90* @return <b>true</b> if tested feature is supported by CPU.91*/92public static boolean hasFeature(String feature) {93return features.contains(feature.toLowerCase());94}95}969798