Java Code Examples for com.sun.management.VMOption

The following examples show how to use com.sun.management.VMOption. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: TencentKona-8   Source File: GetVMOption.java    License: GNU General Public License v2.0 6 votes vote down vote up
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");
    }
}
 
Example 2
Source Project: jdk8u-dev-jdk   Source File: GetVMOption.java    License: GNU General Public License v2.0 6 votes vote down vote up
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");
    }
}
 
Example 3
Source Project: openjdk-8   Source File: GetVMOption.java    License: GNU General Public License v2.0 6 votes vote down vote up
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");
    }
}
 
Example 4
Source Project: jdk8u-jdk   Source File: GetVMOption.java    License: GNU General Public License v2.0 6 votes vote down vote up
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");
    }
}
 
Example 5
public List<VMOption> getDiagnosticOptions() {
    List<Flag> allFlags = Flag.getAllFlags();
    List<VMOption> result = new ArrayList<>();
    for (Flag flag : allFlags) {
        if (flag.isWriteable() && flag.isExternal()) {
            result.add(flag.getVMOption());
        }
    }
    return result;
}
 
Example 6
private static void checkVMOption(HotSpotDiagnosticMXBean mbean) {
    VMOption option = mbean.getVMOption(COMPILE_THRESHOLD_SCALING);
    if (!option.getValue().equalsIgnoreCase(EXPECTED_VALUE)) {
        throw new RuntimeException("Unexpected value: " +
            option.getValue() + " expected: " + EXPECTED_VALUE);
    }
}
 
Example 7
Object toOpenTypeData(Object data) throws OpenDataException {
    if (data instanceof MemoryUsage) {
        return MemoryUsageCompositeData.toCompositeData((MemoryUsage) data);
    }

    if (data instanceof ThreadInfo) {
        return ThreadInfoCompositeData.toCompositeData((ThreadInfo) data);
    }

    if (data instanceof LockInfo) {
        if (data instanceof java.lang.management.MonitorInfo) {
            return MonitorInfoCompositeData.toCompositeData((MonitorInfo) data);
        }
        return LockInfoCompositeData.toCompositeData((LockInfo) data);
    }

    if (data instanceof MemoryNotificationInfo) {
        return MemoryNotifInfoCompositeData.
            toCompositeData((MemoryNotificationInfo) data);
    }

    if (data instanceof VMOption) {
        return VMOptionCompositeData.toCompositeData((VMOption) data);
    }

    if (isCompositeData) {
        // Classes that implement CompositeData
        //
        // construct a new CompositeDataSupport object
        // so that no other classes are sent over the wire
        CompositeData cd = (CompositeData) data;
        CompositeType ct = cd.getCompositeType();
        String[] itemNames = ct.keySet().toArray(new String[0]);
        Object[] itemValues = cd.getAll(itemNames);
        return new CompositeDataSupport(ct, itemNames, itemValues);
    }

    throw new OpenDataException(javaClass.getName() +
        " is not supported for platform MXBeans");
}
 
Example 8
Source Project: dragonwell8_jdk   Source File: SetVMOption.java    License: GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 9
public static void main(String[] args) {
  HotSpotDiagnosticMXBean diagnostic = ManagementFactoryHelper.getDiagnosticMXBean();

  VMOption option = diagnostic.getVMOption("UseG1GC");
  if (option.getValue().equals("false")) {
    System.out.println("Skipping this test. It is only a G1 test.");
    return;
  }

  String expectedValue = getExpectedValue(args);
  option = diagnostic.getVMOption("G1HeapRegionSize");
  if (!expectedValue.equals(option.getValue())) {
    throw new RuntimeException("Wrong value for G1HeapRegionSize. Expected " + expectedValue + " but got " + option.getValue());
  }
}
 
Example 10
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);
    }
}
 
Example 11
public static boolean testingG1GC() {
    HotSpotDiagnosticMXBean diagnostic = ManagementFactoryHelper.getDiagnosticMXBean();

    VMOption option = diagnostic.getVMOption("UseG1GC");
    if (option.getValue().equals("false")) {
      System.out.println("Skipping this test. It is only a G1 test.");
      return false;
    }
    return true;
}
 
Example 12
/**
 * Returns value of VM option.
 *
 * @param name option's name
 * @return value of option or {@code null}, if option doesn't exist
 * @throws NullPointerException if name is null
 */
protected static String getVMOption(String name) {
    Objects.requireNonNull(name);
    HotSpotDiagnosticMXBean diagnostic
            = ManagementFactoryHelper.getDiagnosticMXBean();
    VMOption tmp;
    try {
        tmp = diagnostic.getVMOption(name);
    } catch (IllegalArgumentException e) {
        tmp = null;
    }
    return (tmp == null ? null : tmp.getValue());
}
 
Example 13
Source Project: openjdk-8-source   Source File: SetVMOption.java    License: GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 14
Source Project: hottub   Source File: SetVMOption.java    License: GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 15
Object toOpenTypeData(Object data) throws OpenDataException {
    if (data instanceof MemoryUsage) {
        return MemoryUsageCompositeData.toCompositeData((MemoryUsage) data);
    }

    if (data instanceof ThreadInfo) {
        return ThreadInfoCompositeData.toCompositeData((ThreadInfo) data);
    }

    if (data instanceof LockInfo) {
        if (data instanceof java.lang.management.MonitorInfo) {
            return MonitorInfoCompositeData.toCompositeData((MonitorInfo) data);
        }
        return LockInfoCompositeData.toCompositeData((LockInfo) data);
    }

    if (data instanceof MemoryNotificationInfo) {
        return MemoryNotifInfoCompositeData.
            toCompositeData((MemoryNotificationInfo) data);
    }

    if (data instanceof VMOption) {
        return VMOptionCompositeData.toCompositeData((VMOption) data);
    }

    if (isCompositeData) {
        // Classes that implement CompositeData
        //
        // construct a new CompositeDataSupport object
        // so that no other classes are sent over the wire
        CompositeData cd = (CompositeData) data;
        CompositeType ct = cd.getCompositeType();
        String[] itemNames = ct.keySet().toArray(new String[0]);
        Object[] itemValues = cd.getAll(itemNames);
        return new CompositeDataSupport(ct, itemNames, itemValues);
    }

    throw new OpenDataException(javaClass.getName() +
        " is not supported for platform MXBeans");
}
 
Example 16
Source Project: hottub   Source File: MappedMXBeanType.java    License: GNU General Public License v2.0 5 votes vote down vote up
Object toOpenTypeData(Object data) throws OpenDataException {
    if (data instanceof MemoryUsage) {
        return MemoryUsageCompositeData.toCompositeData((MemoryUsage) data);
    }

    if (data instanceof ThreadInfo) {
        return ThreadInfoCompositeData.toCompositeData((ThreadInfo) data);
    }

    if (data instanceof LockInfo) {
        if (data instanceof java.lang.management.MonitorInfo) {
            return MonitorInfoCompositeData.toCompositeData((MonitorInfo) data);
        }
        return LockInfoCompositeData.toCompositeData((LockInfo) data);
    }

    if (data instanceof MemoryNotificationInfo) {
        return MemoryNotifInfoCompositeData.
            toCompositeData((MemoryNotificationInfo) data);
    }

    if (data instanceof VMOption) {
        return VMOptionCompositeData.toCompositeData((VMOption) data);
    }

    if (isCompositeData) {
        // Classes that implement CompositeData
        //
        // construct a new CompositeDataSupport object
        // so that no other classes are sent over the wire
        CompositeData cd = (CompositeData) data;
        CompositeType ct = cd.getCompositeType();
        String[] itemNames = ct.keySet().toArray(new String[0]);
        Object[] itemValues = cd.getAll(itemNames);
        return new CompositeDataSupport(ct, itemNames, itemValues);
    }

    throw new OpenDataException(javaClass.getName() +
        " is not supported for platform MXBeans");
}
 
Example 17
public List<VMOption> getDiagnosticOptions() {
    List<Flag> allFlags = Flag.getAllFlags();
    List<VMOption> result = new ArrayList<>();
    for (Flag flag : allFlags) {
        if (flag.isWriteable() && flag.isExternal()) {
            result.add(flag.getVMOption());
        }
    }
    return result;
}
 
Example 18
public static boolean testingG1GC() {
    HotSpotDiagnosticMXBean diagnostic = ManagementFactoryHelper.getDiagnosticMXBean();

    VMOption option = diagnostic.getVMOption("UseG1GC");
    if (option.getValue().equals("false")) {
      System.out.println("Skipping this test. It is only a G1 test.");
      return false;
    }
    return true;
}
 
Example 19
Source Project: jdk8u_jdk   Source File: SetVMOption.java    License: GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 20
Source Project: jdk8u60   Source File: CompilerWhiteBoxTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns value of VM option.
 *
 * @param name option's name
 * @return value of option or {@code null}, if option doesn't exist
 * @throws NullPointerException if name is null
 */
protected static String getVMOption(String name) {
    Objects.requireNonNull(name);
    HotSpotDiagnosticMXBean diagnostic
            = ManagementFactoryHelper.getDiagnosticMXBean();
    VMOption tmp;
    try {
        tmp = diagnostic.getVMOption(name);
    } catch (IllegalArgumentException e) {
        tmp = null;
    }
    return (tmp == null ? null : tmp.getValue());
}
 
Example 21
Source Project: jdk8u60   Source File: HotSpotDiagnostic.java    License: GNU General Public License v2.0 5 votes vote down vote up
public List<VMOption> getDiagnosticOptions() {
    List<Flag> allFlags = Flag.getAllFlags();
    List<VMOption> result = new ArrayList<>();
    for (Flag flag : allFlags) {
        if (flag.isWriteable() && flag.isExternal()) {
            result.add(flag.getVMOption());
        }
    }
    return result;
}
 
Example 22
Source Project: jdk8u60   Source File: HotSpotDiagnostic.java    License: GNU General Public License v2.0 5 votes vote down vote up
public VMOption getVMOption(String name) {
    if (name == null) {
        throw new NullPointerException("name cannot be null");
    }

    Flag f = Flag.getFlag(name);
    if (f == null) {
        throw new IllegalArgumentException("VM option \"" +
            name + "\" does not exist");
    }
    return f.getVMOption();
}
 
Example 23
Source Project: jdk8u60   Source File: MappedMXBeanType.java    License: GNU General Public License v2.0 5 votes vote down vote up
Object toOpenTypeData(Object data) throws OpenDataException {
    if (data instanceof MemoryUsage) {
        return MemoryUsageCompositeData.toCompositeData((MemoryUsage) data);
    }

    if (data instanceof ThreadInfo) {
        return ThreadInfoCompositeData.toCompositeData((ThreadInfo) data);
    }

    if (data instanceof LockInfo) {
        if (data instanceof java.lang.management.MonitorInfo) {
            return MonitorInfoCompositeData.toCompositeData((MonitorInfo) data);
        }
        return LockInfoCompositeData.toCompositeData((LockInfo) data);
    }

    if (data instanceof MemoryNotificationInfo) {
        return MemoryNotifInfoCompositeData.
            toCompositeData((MemoryNotificationInfo) data);
    }

    if (data instanceof VMOption) {
        return VMOptionCompositeData.toCompositeData((VMOption) data);
    }

    if (isCompositeData) {
        // Classes that implement CompositeData
        //
        // construct a new CompositeDataSupport object
        // so that no other classes are sent over the wire
        CompositeData cd = (CompositeData) data;
        CompositeType ct = cd.getCompositeType();
        String[] itemNames = ct.keySet().toArray(new String[0]);
        Object[] itemValues = cd.getAll(itemNames);
        return new CompositeDataSupport(ct, itemNames, itemValues);
    }

    throw new OpenDataException(javaClass.getName() +
        " is not supported for platform MXBeans");
}
 
Example 24
Source Project: jdk8u-jdk   Source File: SetAllVMOptions.java    License: GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example 25
/**
 * Returns value of VM option.
 *
 * @param name option's name
 * @return value of option or {@code null}, if option doesn't exist
 * @throws NullPointerException if name is null
 */
protected static String getVMOption(String name) {
    Objects.requireNonNull(name);
    HotSpotDiagnosticMXBean diagnostic
            = ManagementFactoryHelper.getDiagnosticMXBean();
    VMOption tmp;
    try {
        tmp = diagnostic.getVMOption(name);
    } catch (IllegalArgumentException e) {
        tmp = null;
    }
    return (tmp == null ? null : tmp.getValue());
}
 
Example 26
Source Project: openjdk-jdk9   Source File: SetVMOption.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static VMOption findHeapDumpOnOomOption() {
    List<VMOption> options = mbean.getDiagnosticOptions();
    VMOption gcDetails = null;
    for (VMOption o : options) {
        if (o.getName().equals(HEAP_DUMP_ON_OOM)) {
             gcDetails = o;
             break;
        }
    }
    if (gcDetails == null) {
        throw new RuntimeException("VM option " + HEAP_DUMP_ON_OOM +
            " not found");
    }
    return gcDetails;
}
 
Example 27
private static long getCompressedClassSpaceSize() {
  HotSpotDiagnosticMXBean diagnostic =
      ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);

  VMOption option = diagnostic.getVMOption("CompressedClassSpaceSize");
  return Long.parseLong(option.getValue());
}
 
Example 28
Source Project: jdk8u-dev-jdk   Source File: SetVMOption.java    License: GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 29
public VMOption getVMOption(String name) {
    if (name == null) {
        throw new NullPointerException("name cannot be null");
    }

    Flag f = Flag.getFlag(name);
    if (f == null) {
        throw new IllegalArgumentException("VM option \"" +
            name + "\" does not exist");
    }
    return f.getVMOption();
}
 
Example 30
Object toOpenTypeData(Object data) throws OpenDataException {
    if (data instanceof MemoryUsage) {
        return MemoryUsageCompositeData.toCompositeData((MemoryUsage) data);
    }

    if (data instanceof ThreadInfo) {
        return ThreadInfoCompositeData.toCompositeData((ThreadInfo) data);
    }

    if (data instanceof LockInfo) {
        if (data instanceof java.lang.management.MonitorInfo) {
            return MonitorInfoCompositeData.toCompositeData((MonitorInfo) data);
        }
        return LockInfoCompositeData.toCompositeData((LockInfo) data);
    }

    if (data instanceof MemoryNotificationInfo) {
        return MemoryNotifInfoCompositeData.
            toCompositeData((MemoryNotificationInfo) data);
    }

    if (data instanceof VMOption) {
        return VMOptionCompositeData.toCompositeData((VMOption) data);
    }

    if (isCompositeData) {
        // Classes that implement CompositeData
        //
        // construct a new CompositeDataSupport object
        // so that no other classes are sent over the wire
        CompositeData cd = (CompositeData) data;
        CompositeType ct = cd.getCompositeType();
        String[] itemNames = ct.keySet().toArray(new String[0]);
        Object[] itemValues = cd.getAll(itemNames);
        return new CompositeDataSupport(ct, itemNames, itemValues);
    }

    throw new OpenDataException(javaClass.getName() +
        " is not supported for platform MXBeans");
}