Search in sources :

Example 1 with VMOption

use of com.sun.management.VMOption in project appengine-java-standard by GoogleCloudPlatform.

the class MainServlet method performJmxListVmOptions.

/**
 * Lists all writable JMX VM options from HotSpotDiagnosticMXBean.
 *
 * @param w response writer
 */
private static void performJmxListVmOptions(PrintWriter w) throws IOException {
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    HotSpotDiagnosticMXBean bean = ManagementFactory.newPlatformMXBeanProxy(server, "com.sun.management:type=HotSpotDiagnostic", HotSpotDiagnosticMXBean.class);
    for (VMOption option : bean.getDiagnosticOptions()) {
        emitf(w, "%s = %s", option.getName(), option.getValue());
    }
}
Also used : HotSpotDiagnosticMXBean(com.sun.management.HotSpotDiagnosticMXBean) VMOption(com.sun.management.VMOption) MBeanServer(javax.management.MBeanServer)

Example 2 with VMOption

use of com.sun.management.VMOption in project jdk8u_jdk by JetBrains.

the class GetVMOption method checkVMOption.

private static void checkVMOption(HotSpotDiagnosticMXBean mbean) {
    VMOption option = mbean.getVMOption(PRINT_GC_DETAILS);
    if (!option.getValue().equalsIgnoreCase(EXPECTED_VALUE)) {
        throw new RuntimeException("Unexpected value: " + option.getValue() + " expected: " + EXPECTED_VALUE);
    }
    boolean iae = false;
    try {
        mbean.getVMOption(BAD_OPTION);
    } catch (IllegalArgumentException e) {
        iae = true;
    }
    if (!iae) {
        throw new RuntimeException("Invalid VM Option" + " was not detected");
    }
}
Also used : VMOption(com.sun.management.VMOption)

Example 3 with VMOption

use of com.sun.management.VMOption in project jdk8u_jdk by JetBrains.

the class SetVMOption method main.

public static void main(String[] args) throws Exception {
    mbean = ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);
    VMOption option = findPrintGCDetailsOption();
    if (!option.getValue().equalsIgnoreCase(EXPECTED_VALUE)) {
        throw new RuntimeException("Unexpected value: " + option.getValue() + " expected: " + EXPECTED_VALUE);
    }
    if (option.getOrigin() != Origin.VM_CREATION) {
        throw new RuntimeException("Unexpected origin: " + option.getOrigin() + " expected: VM_CREATION");
    }
    if (!option.isWriteable()) {
        throw new RuntimeException("Expected " + PRINT_GC_DETAILS + " to be writeable");
    }
    // set VM option to a new value
    mbean.setVMOption(PRINT_GC_DETAILS, NEW_VALUE);
    option = findPrintGCDetailsOption();
    if (!option.getValue().equalsIgnoreCase(NEW_VALUE)) {
        throw new RuntimeException("Unexpected value: " + option.getValue() + " expected: " + NEW_VALUE);
    }
    if (option.getOrigin() != Origin.MANAGEMENT) {
        throw new RuntimeException("Unexpected origin: " + option.getOrigin() + " expected: MANAGEMENT");
    }
    VMOption o = mbean.getVMOption(PRINT_GC_DETAILS);
    if (!option.getValue().equals(o.getValue())) {
        throw new RuntimeException("Unmatched value: " + option.getValue() + " expected: " + o.getValue());
    }
    if (!option.getValue().equals(o.getValue())) {
        throw new RuntimeException("Unmatched value: " + option.getValue() + " expected: " + o.getValue());
    }
    if (option.getOrigin() != o.getOrigin()) {
        throw new RuntimeException("Unmatched origin: " + option.getOrigin() + " expected: " + o.getOrigin());
    }
    if (option.isWriteable() != o.isWriteable()) {
        throw new RuntimeException("Unmatched writeable: " + option.isWriteable() + " expected: " + o.isWriteable());
    }
    // check if ManagementServer is not writeable
    List<VMOption> options = mbean.getDiagnosticOptions();
    VMOption mgmtServerOption = null;
    for (VMOption o1 : options) {
        if (o1.getName().equals(MANAGEMENT_SERVER)) {
            mgmtServerOption = o1;
            break;
        }
    }
    if (mgmtServerOption != null) {
        throw new RuntimeException(MANAGEMENT_SERVER + " is not expected to be writeable");
    }
    mgmtServerOption = mbean.getVMOption(MANAGEMENT_SERVER);
    if (mgmtServerOption == null) {
        throw new RuntimeException(MANAGEMENT_SERVER + " should exist.");
    }
    if (mgmtServerOption.getOrigin() != Origin.DEFAULT) {
        throw new RuntimeException(MANAGEMENT_SERVER + " should have the default value.");
    }
    if (mgmtServerOption.isWriteable()) {
        throw new RuntimeException(MANAGEMENT_SERVER + " is not expected to be writeable");
    }
}
Also used : HotSpotDiagnosticMXBean(com.sun.management.HotSpotDiagnosticMXBean) VMOption(com.sun.management.VMOption)

Example 4 with VMOption

use of com.sun.management.VMOption in project jdk8u_jdk by JetBrains.

the class SetAllVMOptions method setAllVMOptions.

private static void setAllVMOptions(HotSpotDiagnosticMXBean mbean) {
    List<VMOption> options = mbean.getDiagnosticOptions();
    for (VMOption opt : options) {
        String name = opt.getName();
        String val = opt.getValue();
        System.out.println("option: " + name + "=" + val);
        mbean.setVMOption(name, val);
    }
}
Also used : VMOption(com.sun.management.VMOption)

Example 5 with VMOption

use of com.sun.management.VMOption in project jdk8u_jdk by JetBrains.

the class SetVMOption method findPrintGCDetailsOption.

public static VMOption findPrintGCDetailsOption() {
    List<VMOption> options = mbean.getDiagnosticOptions();
    VMOption gcDetails = null;
    for (VMOption o : options) {
        if (o.getName().equals(PRINT_GC_DETAILS)) {
            gcDetails = o;
            break;
        }
    }
    if (gcDetails == null) {
        throw new RuntimeException("VM option " + PRINT_GC_DETAILS + " not found");
    }
    return gcDetails;
}
Also used : VMOption(com.sun.management.VMOption)

Aggregations

VMOption (com.sun.management.VMOption)9 HotSpotDiagnosticMXBean (com.sun.management.HotSpotDiagnosticMXBean)5 Command (com.shulie.instrument.simulator.api.annotation.Command)2 VmOption (com.shulie.instrument.simulator.module.model.vmoption.VmOption)1 ArrayList (java.util.ArrayList)1 MBeanServer (javax.management.MBeanServer)1