jdk/test/com/sun/management/HotSpotDiagnosticMXBean/GetVMOption.java
author alanb
Fri, 11 Jan 2013 20:19:55 +0000
changeset 15254 3997a6f357cb
parent 5506 202f599c92aa
child 27493 8a2a7d7c52a0
permissions -rw-r--r--
8005978: shell tests need to use the $COMPILEJDK for javac, jar and other tools Reviewed-by: chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     2
 * Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug     6314913
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Basic Test for HotSpotDiagnosticMXBean.getVMOption()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @author  Mandy Chung
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @run main/othervm -XX:+PrintGCDetails GetVMOption
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import com.sun.management.HotSpotDiagnosticMXBean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import com.sun.management.VMOption;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import com.sun.management.VMOption.Origin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.lang.management.ManagementFactory;
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
    37
import java.util.List;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.management.MBeanServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
public class GetVMOption {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private static String PRINT_GC_DETAILS = "PrintGCDetails";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private static String EXPECTED_VALUE = "true";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private static String BAD_OPTION = "BadOption";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private static String HOTSPOT_DIAGNOSTIC_MXBEAN_NAME =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        "com.sun.management:type=HotSpotDiagnostic";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    public static void main(String[] args) throws Exception {
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
    48
        List<HotSpotDiagnosticMXBean> list =
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
    49
            ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
    50
        HotSpotDiagnosticMXBean mbean = list.get(0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        checkVMOption(mbean);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        mbean = ManagementFactory.newPlatformMXBeanProxy(mbs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
                    HOTSPOT_DIAGNOSTIC_MXBEAN_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
                    HotSpotDiagnosticMXBean.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        checkVMOption(mbean);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private static void checkVMOption(HotSpotDiagnosticMXBean mbean) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        VMOption option = mbean.getVMOption(PRINT_GC_DETAILS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        if (!option.getValue().equalsIgnoreCase(EXPECTED_VALUE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            throw new RuntimeException("Unexpected value: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                option.getValue() + " expected: " + EXPECTED_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        boolean iae = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            mbean.getVMOption(BAD_OPTION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            iae = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        if (!iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            throw new RuntimeException("Invalid VM Option" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                " was not detected");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
}