CPUInfo.java revision 1265:c82ea5393dda
13070Spst/* 23070Spst * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 33070Spst * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 43070Spst * 53070Spst * This code is free software; you can redistribute it and/or modify it 63070Spst * under the terms of the GNU General Public License version 2 only, as 73070Spst * published by the Free Software Foundation. 83070Spst * 93070Spst * This code is distributed in the hope that it will be useful, but WITHOUT 103070Spst * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 113070Spst * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 123070Spst * version 2 for more details (a copy is included in the LICENSE file that 133070Spst * accompanied this code). 143070Spst * 153070Spst * You should have received a copy of the GNU General Public License version 163070Spst * 2 along with this work; if not, write to the Free Software Foundation, 173070Spst * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 183070Spst * 193070Spst * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 203070Spst * or visit www.oracle.com if you need additional information or have any 213070Spst * questions. 223070Spst * 233070Spst */ 243070Spst 253070Spstpackage sun.hotspot.cpuinfo; 263070Spst 273070Spstimport java.util.List; 283070Spstimport java.util.Arrays; 293070Spstimport java.util.Collections; 303070Spstimport java.util.regex.Pattern; 313070Spstimport java.util.regex.Matcher; 323070Spst 333070Spstimport sun.hotspot.WhiteBox; 343070Spst 353070Spst/** 363070Spst * Information about CPU on test box. 373070Spst * 383070Spst * CPUInfo uses WhiteBox to gather information, 393070Spst * so WhiteBox class should be added to bootclasspath 403070Spst * and option -XX:+WhiteBoxAPI should expclicetly 413070Spst * specified on command line. 423070Spst */ 433070Spstpublic class CPUInfo { 443070Spst 453070Spst private static final List<String> features; 463070Spst private static final String additionalCPUInfo; 473070Spst 483070Spst static { 493070Spst WhiteBox wb = WhiteBox.getWhiteBox(); 503070Spst 513070Spst Pattern additionalCPUInfoRE = 523070Spst Pattern.compile("([^(]*\\([^)]*\\)[^,]*),\\s*"); 533070Spst 543070Spst String cpuFeaturesString = wb.getCPUFeatures(); 553070Spst Matcher matcher = additionalCPUInfoRE.matcher(cpuFeaturesString); 563070Spst if (matcher.find()) { 573070Spst additionalCPUInfo = matcher.group(1); 583070Spst } else { 593070Spst additionalCPUInfo = ""; 603070Spst } 613070Spst String splittedFeatures[] = matcher.replaceAll("").split("(, )| "); 623070Spst 633070Spst features = Collections.unmodifiableList(Arrays. 643070Spst asList(splittedFeatures)); 653070Spst } 663070Spst 673070Spst /** 683070Spst * Get additional information about CPU. 693070Spst * For example, on X86 in will be family/model/stepping 703070Spst * and number of cores. 713070Spst * 723070Spst * @return additional CPU info 733070Spst */ 743070Spst public static String getAdditionalCPUInfo() { 753070Spst return additionalCPUInfo; 763070Spst } 773070Spst 783070Spst /** 793070Spst * Get all known features supported by CPU. 803070Spst * 813070Spst * @return unmodifiable list with names of all known features 823070Spst * supported by CPU. 833070Spst */ 843070Spst public static List<String> getFeatures() { 853070Spst return features; 863070Spst } 873070Spst 883070Spst /** 893070Spst * Check if some feature is supported by CPU. 903070Spst * 913070Spst * @param feature Name of feature to be tested. 923070Spst * @return <b>true</b> if tested feature is supported by CPU. 933070Spst */ 943070Spst public static boolean hasFeature(String feature) { 953070Spst return features.contains(feature.toLowerCase()); 963070Spst } 973070Spst} 983070Spst