# HG changeset patch # User fparain # Date 1329331615 28800 # Node ID b6c37f4753fd1ba1dde3300d246dc53b876a9a82 # Parent b1e37377b2a3c9ba9f4e4fb0daf205c4b11ece94 7145925: Removing remote access to diagnostic commands in the HotSpotDiagnosticMBean Reviewed-by: acorn, mchung, phh diff -r b1e37377b2a3 -r b6c37f4753fd jdk/make/java/management/mapfile-vers --- a/jdk/make/java/management/mapfile-vers Wed Feb 15 09:29:05 2012 -0800 +++ b/jdk/make/java/management/mapfile-vers Wed Feb 15 10:46:55 2012 -0800 @@ -54,9 +54,6 @@ Java_sun_management_GcInfoBuilder_getLastGcInfo0; Java_sun_management_GcInfoBuilder_getNumGcExtAttributes; Java_sun_management_HotSpotDiagnostic_dumpHeap; - Java_sun_management_HotSpotDiagnostic_executeDiagnosticCommand0; - Java_sun_management_HotSpotDiagnostic_getDiagnosticCommandInfo0; - Java_sun_management_HotSpotDiagnostic_getDiagnosticCommands0; Java_sun_management_HotspotThread_getInternalThreadCount; Java_sun_management_HotspotThread_getInternalThreadTimes0; Java_sun_management_MemoryImpl_getMemoryManagers0; diff -r b1e37377b2a3 -r b6c37f4753fd jdk/src/share/classes/com/sun/management/DiagnosticCommandArgumentInfo.java --- a/jdk/src/share/classes/com/sun/management/DiagnosticCommandArgumentInfo.java Wed Feb 15 09:29:05 2012 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,151 +0,0 @@ -/* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.management; - -import java.beans.ConstructorProperties; - -/** - * Diagnostic Command Argument information. It contains the description - * of one parameter of the diagnostic command. A parameter can either be an - * option or an argument. Options are identified by the option name while - * arguments are identified by their position in the command line. The generic - * syntax of a diagnostic command is: - *
- * <command name> [<option>=<value>] [<argument_value>] - *
- * Example: - *
- * command_name option1=value1 option2=value argumentA argumentB argumentC - *
- * In this command line, the diagnostic command receives five parameters, two - * options named {@code option1} and {@code option2}, and three arguments. - * argumentA's position is 0, argumentB's position is 1 and argumentC's - * position is 2. - * - * @author Frederic Parain - * @since 7u4 - */ - -public class DiagnosticCommandArgumentInfo { - private final String name; - private final String description; - private final String type; - private final String defaultValue; - private final boolean mandatory; - private final boolean option; - private final int position; - - /** - * Returns the argument name - * - * @return the argument name - */ - public String getName() { - return name; - } - - /** - * Returns the argument description - * - * @return the argument description - */ - public String getDescription() { - return description; - } - - /** - * Returns the argument type - * - * @return the argument type - */ - public String getType() { - return type; - } - - /** - * Returns the default value as a String if a default value - * is defined, null otherwise. - * - * @return the default value as a String if a default value - * is defined, null otherwise. - */ - public String getDefault() { - return defaultValue; - } - - /** - * Returns {@code true} if the argument is mandatory, - * {@code false} otherwise - * - * @return {@code true} if the argument is mandatory, - * {@code false} otherwise - */ - public boolean isMandatory() { - return mandatory; - } - - /** - * Returns {@code true} if the argument is an option, - * {@code false} otherwise. Options have to be specified using the - * <key>=<value> syntax on the command line, while other - * arguments are specified with a single <value> field and are - * identified by their position on command line. - * - * @return {@code true} if the argument is an option, - * {@code false} otherwise - */ - public boolean isOption() { - return option; - } - - /** - * Returns the expected position of this argument if it is not an option, - * -1 otherwise. Argument position if defined from left to right, - * starting at zero and ignoring the diagnostic command name and - * options. - * - * @return the expected position of this argument if it is not an option, - * -1 otherwise. - */ - public int getPosition() { - return position; - } - - @ConstructorProperties({"name","description","type","default", - "mandatory","option","position"}) - public DiagnosticCommandArgumentInfo(String name, String description, - String type, String defaultValue, - boolean mandatory, boolean option, - int position) { - this.name = name; - this.description = description; - this.type = type; - this.defaultValue = defaultValue; - this.mandatory = mandatory; - this.option = option; - this.position = position; - } -} diff -r b1e37377b2a3 -r b6c37f4753fd jdk/src/share/classes/com/sun/management/DiagnosticCommandInfo.java --- a/jdk/src/share/classes/com/sun/management/DiagnosticCommandInfo.java Wed Feb 15 09:29:05 2012 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.management; - -import java.beans.ConstructorProperties; -import java.util.List; - -/** - * Diagnostic command information. It contains the description of a - * diagnostic command. - * - * @author Frederic Parain - * @since 7u4 - */ - -public class DiagnosticCommandInfo { - private final String name; - private final String description; - private final String impact; - private final boolean enabled; - private final List arguments; - - /** - * Returns the diagnostic command name - * - * @return the diagnostic command name - */ - public String getName() { - return name; - } - - /** - * Returns the diagnostic command description - * - * @return the diagnostic command description - */ - public String getDescription() { - return description; - } - - /** - * Returns the potential impact of the diagnostic command execution - * on the Java virtual machine behavior - * - * @return the potential impact of the diagnostic command execution - * on the Java virtual machine behavior - */ - public String getImpact() { - return impact; - } - - /** - * Returns {@code true} if the diagnostic command is enabled, - * {@code false} otherwise. The enabled/disabled - * status of a diagnostic command can evolve during - * the lifetime of the Java virtual machine. - * - * @return {@code true} if the diagnostic command is enabled, - * {@code false} otherwise - */ - public boolean isEnabled() { - return enabled; - } - - /** - * Returns the list of the diagnostic command arguments description. - * If the diagnostic command has no arguments, it returns an empty list. - * - * @return a list of the diagnostic command arguments description - */ - public List getArgumentsInfo() { - return arguments; - } - - @ConstructorProperties({"name", "description","impact","enabled", - "argumentsInfo"}) - public DiagnosticCommandInfo(String name, String description, - String impact, boolean enabled, - List arguments) - { - this.name = name; - this.description = description; - this.impact = impact; - this.enabled = enabled; - this.arguments = arguments; - } -} diff -r b1e37377b2a3 -r b6c37f4753fd jdk/src/share/classes/com/sun/management/HotSpotDiagnosticMXBean.java --- a/jdk/src/share/classes/com/sun/management/HotSpotDiagnosticMXBean.java Wed Feb 15 09:29:05 2012 -0800 +++ b/jdk/src/share/classes/com/sun/management/HotSpotDiagnosticMXBean.java Wed Feb 15 10:46:55 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -31,11 +31,6 @@ /** * Diagnostic management interface for the HotSpot Virtual Machine. * - *

{@linkplain #getDiagnosticCommands Diagnostic commands} - * are actions that can be invoked dynamically and - * executed in a target Java virtual machine, mainly for troubleshooting - * and diagnosis. - * *

The diagnostic MBean is registered to the platform MBeanServer * as are other platform MBeans. * @@ -116,108 +111,4 @@ * ManagementPermission("control"). */ public void setVMOption(String name, String value); - - /** - * Returns the {@linkplain DiagnosticCommandInfo#getName() names} - * of all diagnostic commands. - * A diagnostic command is an action that can be invoked dynamically - * mainly for troubleshooting and diagnosis. The list of diagnostic - * commands may change at runtime. A diagnostic command may be - * {@linkplain DiagnosticCommandInfo#isEnabled disabled} but will - * not be removed from a previously returned list. - * - * @return the names of all diagnostic commands. - * - * @since 7u4 - */ - public List getDiagnosticCommands(); - - /** - * Returns a {@code DiagnosticCommandInfo} object describing the - * diagnostic command of the specified name {@code command} - * - * @param command a diagnostic command name - * @return a {@code DiagnosticCommandInfo} object - * @throws java.lang.IllegalArgumentException if the {@code command} - * doesn't match any diagnostic command registered in the - * targeted Java virtual machine. - * - * @since 7u4 - */ - public DiagnosticCommandInfo getDiagnosticCommandInfo(String command); - - /** - * Returns a list of {@code DiagnosticCommandInfo} object describing - * all diagnostic commands available on the targeted Java virtual machine - * - * @return a list of {@code DiagnosticCommandInfo} objects - * - * @since 7u4 - */ - public List getDiagnosticCommandInfo(); - - /** - * Returns a list of {@code DiagnosticCommandInfo} object describing - * all diagnostic commands specified in the {@code commands} list. - * - * @param commands {@code List} of {@code String} containing diagnostic - * command names - * @return a {@code List} of {@code DiagnosticCommandInfo} objects - * - * @throws java.lang.IllegalArgumentException if at least one - * command specified in the {@code commands } list - * doesn't match any diagnostic command registered in the - * targeted Java virtual machine. - * - * @since 7u4 - */ - public List getDiagnosticCommandInfo(List commands); - - /** - * Executes the command line {@code commandLine}. The command line must - * start with a diagnostic command name, optionally followed by parameters. - * Each command has its own syntax but the generic syntax for a diagnostic - * command line is: - *

- * <command name> [<option>=<value>] [<argument_value>] - *
- * - * @param commandLine command line to execute - * @return a {@code String} object containing the diagnostic command - * output. - * - * @throws java.lang.IllegalArgumentException if the command line doesn't - * match any diagnostic command registered in the virtual machine - * of if the parameters don't match the diagnostic command syntax. - * @throws java.lang.SecurityException - * if a security manager exists and the caller does not have - * ManagementPermission("control"). - * - * @since 7u4 - */ - public String execute(String commandLine); - - /** - * Invokes the diagnostic command named {@code cmd} with the parameters - * specified in {@code args}. Each command has its own syntax but - * the generic syntax for parameters is: - *
- * [<option>=<value>] [<argument_value>] - *
- * - * @param cmd a diagnostic command name - * @param args the command parameters - * @return a {@code String} object containing the diagnostic command - * output. - * - * @throws java.lang.IllegalArgumentException if the command line doesn't - * match any diagnostic command registered in the virtual machine - * of if the parameters don't match the diagnostic command syntax. - * @throws java.lang.SecurityException - * if a security manager exists and the caller does not have - * ManagementPermission("control"). - * - * @since 7u4 - */ - public String execute(String cmd, String... args); } diff -r b1e37377b2a3 -r b6c37f4753fd jdk/src/share/classes/sun/management/HotSpotDiagnostic.java --- a/jdk/src/share/classes/sun/management/HotSpotDiagnostic.java Wed Feb 15 09:29:05 2012 -0800 +++ b/jdk/src/share/classes/sun/management/HotSpotDiagnostic.java Wed Feb 15 10:46:55 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -27,13 +27,9 @@ import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import javax.management.ObjectName; -import com.sun.management.DiagnosticCommandInfo; -import com.sun.management.DiagnosticCommandArgumentInfo; import com.sun.management.HotSpotDiagnosticMXBean; import com.sun.management.VMOption; @@ -120,54 +116,7 @@ } } - public List getDiagnosticCommands() { - String[] commands = getDiagnosticCommands0(); - return commands == null ? Collections.emptyList() : - Arrays.asList(commands); - } - - public DiagnosticCommandInfo getDiagnosticCommandInfo(String command) { - String[] array = new String[] { command }; - return getDiagnosticCommandInfo0(array)[0]; - } - - public List getDiagnosticCommandInfo() { - String[] commands = getDiagnosticCommands0(); - return Arrays.asList(getDiagnosticCommandInfo0(commands)); - } - - public List getDiagnosticCommandInfo( - List commands) { - return Arrays.asList(getDiagnosticCommandInfo0( - commands.toArray(new String[commands.size()]))); - } - - public String execute(String command) { - Util.checkControlAccess(); - return executeDiagnosticCommand0(command); - } - - public String execute(String cmd, String... arguments) { - if(cmd == null) { - throw new NullPointerException("Missing command name"); - } - StringBuilder sb = new StringBuilder(); - sb.append(cmd); - sb.append(" "); - for(String arg : arguments) { - sb.append(arg); - sb.append(" "); - } - return execute(sb.toString()); - } - public ObjectName getObjectName() { return Util.newObjectName("com.sun.management:type=HotSpotDiagnostic"); } - - private native String[] getDiagnosticCommands0(); - private native DiagnosticCommandInfo[] getDiagnosticCommandInfo0( - String[] commands) throws IllegalArgumentException; - private native String executeDiagnosticCommand0(String command) - throws IllegalArgumentException; } diff -r b1e37377b2a3 -r b6c37f4753fd jdk/src/share/native/sun/management/HotSpotDiagnostic.c --- a/jdk/src/share/native/sun/management/HotSpotDiagnostic.c Wed Feb 15 09:29:05 2012 -0800 +++ b/jdk/src/share/native/sun/management/HotSpotDiagnostic.c Wed Feb 15 10:46:55 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -34,141 +34,3 @@ { jmm_interface->DumpHeap0(env, outputfile, live); } - -JNIEXPORT jobjectArray JNICALL -Java_sun_management_HotSpotDiagnostic_getDiagnosticCommands0 - (JNIEnv *env, jobject dummy) -{ - if ((jmm_version > JMM_VERSION_1_2_1) - || (jmm_version == JMM_VERSION_1_2 && ((jmm_version&0xFF)>=2))) { - return jmm_interface->GetDiagnosticCommands(env); - } - JNU_ThrowByName(env, "java/lang/UnsupportedOperationException", - "Diagnostic commands are not supported by this VM"); -} - -jobject getDiagnosticCommandArgumentInfoArray(JNIEnv *env, jstring command, - int num_arg) { - int i; - jobject obj; - jobjectArray result; - dcmdArgInfo* dcmd_arg_info_array; - jclass dcmdArgInfoCls; - jclass arraysCls; - jmethodID mid; - jobject resultList; - - dcmd_arg_info_array = (dcmdArgInfo*) malloc(num_arg * sizeof(dcmdArgInfo)); - if (dcmd_arg_info_array == NULL) { - return NULL; - } - jmm_interface->GetDiagnosticCommandArgumentsInfo(env, command, - dcmd_arg_info_array); - dcmdArgInfoCls = (*env)->FindClass(env, - "com/sun/management/DiagnosticCommandArgumentInfo"); - result = (*env)->NewObjectArray(env, num_arg, dcmdArgInfoCls, NULL); - if (result == NULL) { - free(dcmd_arg_info_array); - return NULL; - } - for (i=0; iNewStringUTF(env,dcmd_arg_info_array[i].name), - (*env)->NewStringUTF(env,dcmd_arg_info_array[i].description), - (*env)->NewStringUTF(env,dcmd_arg_info_array[i].type), - dcmd_arg_info_array[i].default_string == NULL ? NULL: - (*env)->NewStringUTF(env, dcmd_arg_info_array[i].default_string), - dcmd_arg_info_array[i].mandatory, - dcmd_arg_info_array[i].option, - dcmd_arg_info_array[i].position); - if (obj == NULL) { - free(dcmd_arg_info_array); - return NULL; - } - (*env)->SetObjectArrayElement(env, result, i, obj); - } - free(dcmd_arg_info_array); - arraysCls = (*env)->FindClass(env, "java/util/Arrays"); - mid = (*env)->GetStaticMethodID(env, arraysCls, - "asList", "([Ljava/lang/Object;)Ljava/util/List;"); - resultList = (*env)->CallStaticObjectMethod(env, arraysCls, mid, result); - return resultList; -} - -/* Throws IllegalArgumentException if at least one the diagnostic command - * passed in argument is not supported by the JVM - */ -JNIEXPORT jobjectArray JNICALL -Java_sun_management_HotSpotDiagnostic_getDiagnosticCommandInfo0 -(JNIEnv *env, jobject dummy, jobjectArray commands) -{ - int i; - jclass dcmdInfoCls; - jobject result; - jobjectArray args; - jobject obj; - - if (commands == NULL) { - JNU_ThrowNullPointerException(env, "Invalid String Array"); - return NULL; - } - if ((jmm_version > JMM_VERSION_1_2_1) - || (jmm_version == JMM_VERSION_1_2 && ((jmm_version&0xFF)>=2))) { - jsize num_commands = (*env)->GetArrayLength(env, commands); - dcmdInfo* dcmd_info_array = (dcmdInfo*) malloc(num_commands * - sizeof(dcmdInfo)); - if (dcmd_info_array == NULL) { - JNU_ThrowOutOfMemoryError(env, NULL); - } - jmm_interface->GetDiagnosticCommandInfo(env, commands, dcmd_info_array); - dcmdInfoCls = (*env)->FindClass(env, - "com/sun/management/DiagnosticCommandInfo"); - result = (*env)->NewObjectArray(env, num_commands, dcmdInfoCls, NULL); - if (result == NULL) { - free(dcmd_info_array); - JNU_ThrowOutOfMemoryError(env, 0); - } - for (i=0; iGetObjectArrayElement(env,commands,i), - dcmd_info_array[i].num_arguments); - if (args == NULL) { - free(dcmd_info_array); - JNU_ThrowOutOfMemoryError(env, 0); - } - obj = JNU_NewObjectByName(env, - "com/sun/management/DiagnosticCommandInfo", - "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZLjava/util/List;)V", - (*env)->NewStringUTF(env,dcmd_info_array[i].name), - (*env)->NewStringUTF(env,dcmd_info_array[i].description), - (*env)->NewStringUTF(env,dcmd_info_array[i].impact), - dcmd_info_array[i].enabled, - args); - if (obj == NULL) { - free(dcmd_info_array); - JNU_ThrowOutOfMemoryError(env, 0); - } - (*env)->SetObjectArrayElement(env, result, i, obj); - } - free(dcmd_info_array); - return result; - } - JNU_ThrowByName(env, "java/lang/UnsupportedOperationException", - "Diagnostic commands are not supported by this VM"); -} - -/* Throws IllegalArgumentException if the diagnostic command - * passed in argument is not supported by the JVM - */ -JNIEXPORT jstring JNICALL -Java_sun_management_HotSpotDiagnostic_executeDiagnosticCommand0 -(JNIEnv *env, jobject dummy, jstring command) { - if((jmm_version > JMM_VERSION_1_2_1 ) - || (jmm_version == JMM_VERSION_1_2 && ((jmm_version&0xFF)>=2))) { - return jmm_interface->ExecuteDiagnosticCommand(env, command); - } - JNU_ThrowByName(env, "java/lang/UnsupportedOperationException", - "Diagnostic commands are not supported by this VM"); -} diff -r b1e37377b2a3 -r b6c37f4753fd jdk/test/com/sun/management/HotSpotDiagnosticMXBean/ExecuteDiagnosticCommand.java --- a/jdk/test/com/sun/management/HotSpotDiagnosticMXBean/ExecuteDiagnosticCommand.java Wed Feb 15 09:29:05 2012 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - * @test - * @bug 7104647 - * @summary Basic Test for HotSpotDiagnosticMXBean.execute() - * @author Frederic Parain - * - * @run main ExecuteDiagnosticCommand - */ - -import com.sun.management.HotSpotDiagnosticMXBean; -import com.sun.management.VMOption; -import java.lang.management.ManagementFactory; -import java.util.List; -import javax.management.MBeanServer; - -public class ExecuteDiagnosticCommand { - private static String HOTSPOT_DIAGNOSTIC_MXBEAN_NAME = - "com.sun.management:type=HotSpotDiagnostic"; - - public static void main(String[] args) throws Exception { - HotSpotDiagnosticMXBean mbean = - ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class); - executeDiagnosticCommand(mbean); - - MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); - mbean = ManagementFactory.newPlatformMXBeanProxy(mbs, - HOTSPOT_DIAGNOSTIC_MXBEAN_NAME, - HotSpotDiagnosticMXBean.class); - executeDiagnosticCommand(mbean); - } - - private static void executeDiagnosticCommand(HotSpotDiagnosticMXBean mbean) { - String s = mbean.execute("help help"); - System.out.println(s); - s = mbean.execute("help", "help"); - System.out.println(s); - String tab[] = { "help"}; - s = mbean.execute("help", tab); - System.out.println(s); - } -} diff -r b1e37377b2a3 -r b6c37f4753fd jdk/test/com/sun/management/HotSpotDiagnosticMXBean/GetDiagnosticCommandInfo.java --- a/jdk/test/com/sun/management/HotSpotDiagnosticMXBean/GetDiagnosticCommandInfo.java Wed Feb 15 09:29:05 2012 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - * @test - * @bug 7104647 - * @summary Basic Test for HotSpotDiagnosticMXBean.getDiagnosticCommandInfo() - * @author Frederic Parain - * - * @run main GetDiagnosticCommandInfo - */ - -import com.sun.management.HotSpotDiagnosticMXBean; -import com.sun.management.DiagnosticCommandInfo; -import com.sun.management.DiagnosticCommandArgumentInfo; -import com.sun.management.VMOption; -import java.lang.management.ManagementFactory; -import java.util.List; -import javax.management.MBeanServer; - -public class GetDiagnosticCommandInfo { - private static String HOTSPOT_DIAGNOSTIC_MXBEAN_NAME = - "com.sun.management:type=HotSpotDiagnostic"; - - public static void main(String[] args) throws Exception { - HotSpotDiagnosticMXBean mbean = - ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class); - checkDiagnosticCommandArguments(mbean); - - MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); - mbean = ManagementFactory.newPlatformMXBeanProxy(mbs, - HOTSPOT_DIAGNOSTIC_MXBEAN_NAME, - HotSpotDiagnosticMXBean.class); - checkDiagnosticCommandArguments(mbean); - } - - private static void checkDiagnosticCommandArguments(HotSpotDiagnosticMXBean mbean) { - // check getDiagnosticCommandInfo() - StringBuilder sb = new StringBuilder(); - List infoList = mbean.getDiagnosticCommandInfo(); - for(DiagnosticCommandInfo info : infoList) { - printCommandInfo(info,sb); - } - // check getDiagnosticCommandInfo(List) - List commands = mbean.getDiagnosticCommands(); - List list2 = - mbean.getDiagnosticCommandInfo(commands); - for(DiagnosticCommandInfo info : list2) { - printCommandInfo(info,sb); - } - // check getDiagnosticCommandInfo(String) - for(String cmd : commands) { - DiagnosticCommandInfo info2 = mbean.getDiagnosticCommandInfo(cmd); - printCommandInfo(info2,sb); - } - System.out.println(sb.toString()); - } - - private static void printCommandInfo(DiagnosticCommandInfo info, - StringBuilder sb) { - sb.append("\t").append(info.getName()).append(":\n"); - sb.append("\t\tDescription=").append(info.getDescription()).append("\n"); - sb.append("\t\tImpact=").append(info.getImpact()).append("\n"); - sb.append("\t\tStatus="); - if (info.isEnabled()) { - sb.append("Enabled\n"); - } else { - sb.append("Disbled\n"); - } - sb.append("\t\tArguments="); - for(DiagnosticCommandArgumentInfo arg : info.getArgumentsInfo()) { - printArgumentInfo(arg,sb); - } - } - - private static void printArgumentInfo(DiagnosticCommandArgumentInfo info, - StringBuilder sb) { - sb.append("\t\t\t").append(info.getName()).append(":\n"); - sb.append("\t\t\t\tType=").append(info.getType()).append("\n"); - sb.append("\t\t\t\tDescription=").append(info.getDescription()).append("\n"); - if(info.getDefault() != null) { - sb.append("\t\t\t\tDefault=").append(info.getDefault()).append("\n"); - } - if(info.isMandatory()) { - sb.append("\t\t\t\tMandatory\n"); - } else { - sb.append("\t\t\t\tOptional\n"); - } - if(info.isOption()) { - sb.append("\t\t\t\tIs an option\n"); - } else { - sb.append("\t\t\t\tIs an argument expected at position"); - sb.append(info.getPosition()); - sb.append("\n"); - } - } -} diff -r b1e37377b2a3 -r b6c37f4753fd jdk/test/com/sun/management/HotSpotDiagnosticMXBean/GetDiagnosticCommands.java --- a/jdk/test/com/sun/management/HotSpotDiagnosticMXBean/GetDiagnosticCommands.java Wed Feb 15 09:29:05 2012 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - * @test - * @bug 7104647 - * @summary Basic Test for HotSpotDiagnosticMXBean.getDiagnosticCommands() - * @author Frederic Parain - * - * @run main GetDiagnosticCommands - */ - -import com.sun.management.HotSpotDiagnosticMXBean; -import com.sun.management.VMOption; -import java.lang.management.ManagementFactory; -import java.util.List; -import javax.management.MBeanServer; - -public class GetDiagnosticCommands { - private static String HOTSPOT_DIAGNOSTIC_MXBEAN_NAME = - "com.sun.management:type=HotSpotDiagnostic"; - - public static void main(String[] args) throws Exception { - HotSpotDiagnosticMXBean mbean = - ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class); - checkDiagnosticCommands(mbean); - - MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); - mbean = ManagementFactory.newPlatformMXBeanProxy(mbs, - HOTSPOT_DIAGNOSTIC_MXBEAN_NAME, - HotSpotDiagnosticMXBean.class); - checkDiagnosticCommands(mbean); - } - - private static void checkDiagnosticCommands(HotSpotDiagnosticMXBean mbean) { - List commands = mbean.getDiagnosticCommands(); - System.out.println("Commands:"); - for (String cmd : commands) { - System.out.println(cmd); - } - } -}