test/lib/sun/hotspot/cpuinfo/CPUInfo.java
author ksrini
Wed, 21 Jun 2017 19:39:51 -0700
changeset 45742 36bf0f2436ad
parent 41533 64e1caddf380
child 50339 ede65c4fb6da
permissions -rw-r--r--
8177511: Remove the old standard doclet Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
package sun.hotspot.cpuinfo;
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    25
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    26
import java.util.List;
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    27
import java.util.Arrays;
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    28
import java.util.Collections;
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    29
import java.util.regex.Pattern;
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    30
import java.util.regex.Matcher;
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    31
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    32
import sun.hotspot.WhiteBox;
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    33
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
 * Information about CPU on test box.
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    36
 *
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    37
 * CPUInfo uses WhiteBox to gather information,
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    38
 * so WhiteBox class should be added to bootclasspath
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    39
 * and option -XX:+WhiteBoxAPI should expclicetly
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    40
 * specified on command line.
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    41
 */
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    42
public class CPUInfo {
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    43
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    44
    private static final List<String> features;
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    45
    private static final String additionalCPUInfo;
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    46
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    47
    static {
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    48
        WhiteBox wb = WhiteBox.getWhiteBox();
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    49
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    50
        Pattern additionalCPUInfoRE =
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    51
            Pattern.compile("([^(]*\\([^)]*\\)[^,]*),\\s*");
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    52
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    53
        String cpuFeaturesString = wb.getCPUFeatures();
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    54
        Matcher matcher = additionalCPUInfoRE.matcher(cpuFeaturesString);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    55
        if (matcher.find()) {
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    56
            additionalCPUInfo = matcher.group(1);
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    57
        } else {
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    58
            additionalCPUInfo = "";
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    59
        }
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    60
        String splittedFeatures[] = matcher.replaceAll("").split("(, )| ");
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    61
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    62
        features = Collections.unmodifiableList(Arrays.
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    63
                                                asList(splittedFeatures));
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    64
    }
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
     * Get additional information about CPU.
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    68
     * For example, on X86 in will be family/model/stepping
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    69
     * and number of cores.
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    70
     *
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    71
     * @return additional CPU info
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    72
     */
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    73
    public static String getAdditionalCPUInfo() {
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    74
        return additionalCPUInfo;
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    75
    }
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
     * Get all known features supported by CPU.
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    79
     *
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    80
     * @return unmodifiable list with names of all known features
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    81
     *         supported by CPU.
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    82
     */
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    83
    public static List<String> getFeatures() {
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    84
        return features;
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    85
    }
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
     * Check if some feature is supported by CPU.
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    89
     *
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    90
     * @param feature Name of feature to be tested.
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    91
     * @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
    92
     */
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    93
    public static boolean hasFeature(String feature) {
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    94
        return features.contains(feature.toLowerCase());
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    95
    }
342e86350dc8 8066433: Move Whitebox test library to top level repository
thartmann
parents:
diff changeset
    96
}