jdk/test/com/sun/management/HotSpotDiagnosticMXBean/SetAllVMOptions.java
author alanb
Fri, 11 Jan 2013 20:19:55 +0000
changeset 15254 3997a6f357cb
parent 5506 202f599c92aa
child 30376 2ccf2cf7ea48
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:
4240
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4240
diff changeset
     2
 * Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved.
4240
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
     4
 *
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
     7
 * published by the Free Software Foundation.
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
     8
 *
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    13
 * accompanied this code).
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    14
 *
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4240
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4240
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4240
diff changeset
    21
 * questions.
4240
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    22
 */
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    23
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    24
/*
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    25
 * @test
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    26
 * @bug     6858708
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    27
 * @summary Basic Test for HotSpotDiagnosticMXBean.setVMOption()
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    28
 * @author  Tomas Hurka, Daniel Fuchs
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    29
 *
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    30
 * @run main SetAllVMOptions
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    31
 */
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    32
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    33
import com.sun.management.HotSpotDiagnosticMXBean;
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    34
import com.sun.management.VMOption;
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    35
import java.lang.management.ManagementFactory;
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    36
import java.util.List;
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    37
import javax.management.MBeanServer;
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    38
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    39
public class SetAllVMOptions {
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    40
    private static String HOTSPOT_DIAGNOSTIC_MXBEAN_NAME =
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    41
        "com.sun.management:type=HotSpotDiagnostic";
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    42
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    43
    public static void main(String[] args) throws Exception {
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    44
        List<HotSpotDiagnosticMXBean> list =
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    45
            ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    46
        HotSpotDiagnosticMXBean mbean = list.get(0);
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    47
        setAllVMOptions(mbean);
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    48
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    49
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    50
        mbean = ManagementFactory.newPlatformMXBeanProxy(mbs,
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    51
                    HOTSPOT_DIAGNOSTIC_MXBEAN_NAME,
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    52
                    HotSpotDiagnosticMXBean.class);
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    53
        setAllVMOptions(mbean);
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    54
    }
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    55
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    56
    private static void setAllVMOptions(HotSpotDiagnosticMXBean mbean) {
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    57
        List<VMOption> options = mbean.getDiagnosticOptions();
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    58
        for (VMOption opt : options) {
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    59
            String name = opt.getName();
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    60
            String val = opt.getValue();
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    61
            System.out.println("option: "+name+"="+val);
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    62
            mbean.setVMOption(name,val);
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    63
        }
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    64
    }
ca8d98aeb09e 6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException
thurka
parents:
diff changeset
    65
}