Path: blob/master/test/jdk/com/sun/management/HotSpotDiagnosticMXBean/GetVMOption.java
41153 views
/*1* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 631491326* @summary Basic Test for HotSpotDiagnosticMXBean.getVMOption()27* @author Mandy Chung28*29* @run main/othervm -XX:+HeapDumpOnOutOfMemoryError GetVMOption30*/3132import com.sun.management.HotSpotDiagnosticMXBean;33import com.sun.management.VMOption;34import java.lang.management.ManagementFactory;35import java.util.List;36import javax.management.MBeanServer;3738public class GetVMOption {39private static final String HEAP_DUMP_ON_OOM = "HeapDumpOnOutOfMemoryError";40private static final String EXPECTED_VALUE = "true";41private static final String BAD_OPTION = "BadOption";42private static final String HOTSPOT_DIAGNOSTIC_MXBEAN_NAME =43"com.sun.management:type=HotSpotDiagnostic";4445public static void main(String[] args) throws Exception {46List<HotSpotDiagnosticMXBean> list =47ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);48HotSpotDiagnosticMXBean mbean = list.get(0);49checkVMOption(mbean);5051MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();52mbean = ManagementFactory.newPlatformMXBeanProxy(mbs,53HOTSPOT_DIAGNOSTIC_MXBEAN_NAME,54HotSpotDiagnosticMXBean.class);55checkVMOption(mbean);56}5758private static void checkVMOption(HotSpotDiagnosticMXBean mbean) {59VMOption option = mbean.getVMOption(HEAP_DUMP_ON_OOM);60if (!option.getValue().equalsIgnoreCase(EXPECTED_VALUE)) {61throw new RuntimeException("Unexpected value: " +62option.getValue() + " expected: " + EXPECTED_VALUE);63}64boolean iae = false;65try {66mbean.getVMOption(BAD_OPTION);67} catch (IllegalArgumentException e) {68iae = true;69}70if (!iae) {71throw new RuntimeException("Invalid VM Option" +72" was not detected");73}74}75}767778