author | tschatzl |
Fri, 07 Aug 2015 15:37:07 +0200 | |
changeset 32193 | 862a68285b1e |
parent 28154 | 342e86350dc8 |
child 41533 | 64e1caddf380 |
permissions | -rw-r--r-- |
28154
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
1 |
/* |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
4 |
* |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
8 |
* |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
13 |
* accompanied this code). |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
14 |
* |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
18 |
* |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
21 |
* questions. |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
22 |
* |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
23 |
*/ |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
24 |
|
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
25 |
package sun.hotspot.cpuinfo; |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
26 |
|
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
27 |
import java.util.List; |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
28 |
import java.util.Arrays; |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
29 |
import java.util.Collections; |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
30 |
import java.util.regex.Pattern; |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
31 |
import java.util.regex.Matcher; |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
32 |
|
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
33 |
import sun.hotspot.WhiteBox; |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
34 |
|
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
35 |
/** |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
36 |
* Information about CPU on test box. |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
37 |
* |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
38 |
* CPUInfo uses WhiteBox to gather information, |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
39 |
* so WhiteBox class should be added to bootclasspath |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
40 |
* and option -XX:+WhiteBoxAPI should expclicetly |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
41 |
* specified on command line. |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
42 |
*/ |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
43 |
public class CPUInfo { |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
44 |
|
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
45 |
private static final List<String> features; |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
46 |
private static final String additionalCPUInfo; |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
47 |
|
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
48 |
static { |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
49 |
WhiteBox wb = WhiteBox.getWhiteBox(); |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
50 |
|
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
51 |
Pattern additionalCPUInfoRE = |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
52 |
Pattern.compile("([^(]*\\([^)]*\\)[^,]*),\\s*"); |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
53 |
|
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
54 |
String cpuFeaturesString = wb.getCPUFeatures(); |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
55 |
Matcher matcher = additionalCPUInfoRE.matcher(cpuFeaturesString); |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
56 |
if (matcher.find()) { |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
57 |
additionalCPUInfo = matcher.group(1); |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
58 |
} else { |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
59 |
additionalCPUInfo = ""; |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
60 |
} |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
61 |
String splittedFeatures[] = matcher.replaceAll("").split("(, )| "); |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
62 |
|
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
63 |
features = Collections.unmodifiableList(Arrays. |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
64 |
asList(splittedFeatures)); |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
65 |
} |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
66 |
|
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
67 |
/** |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
68 |
* Get additional information about CPU. |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
69 |
* For example, on X86 in will be family/model/stepping |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
70 |
* and number of cores. |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
71 |
* |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
72 |
* @return additional CPU info |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
73 |
*/ |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
74 |
public static String getAdditionalCPUInfo() { |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
75 |
return additionalCPUInfo; |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
76 |
} |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
77 |
|
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
78 |
/** |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
79 |
* Get all known features supported by CPU. |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
80 |
* |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
81 |
* @return unmodifiable list with names of all known features |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
82 |
* supported by CPU. |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
83 |
*/ |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
84 |
public static List<String> getFeatures() { |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
85 |
return features; |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
86 |
} |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
87 |
|
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
88 |
/** |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
89 |
* Check if some feature is supported by CPU. |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
90 |
* |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
91 |
* @param feature Name of feature to be tested. |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
92 |
* @return <b>true</b> if tested feature is supported by CPU. |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
93 |
*/ |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
94 |
public static boolean hasFeature(String feature) { |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
95 |
return features.contains(feature.toLowerCase()); |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
96 |
} |
342e86350dc8
8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff
changeset
|
97 |
} |