com.sun.management.HotSpotDiagnosticMXBean Java Examples

The following examples show how to use com.sun.management.HotSpotDiagnosticMXBean. 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 File: JmxSupport.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
HotSpotDiagnosticMXBean getHotSpotDiagnostic() {
    synchronized (hotspotDiagnosticLock) {
        if (hotspotDiagnosticInitialized) {
            return hotspotDiagnosticMXBean;
        }
        JvmMXBeans jmx = getJvmMXBeans();
        if (jmx != null) {
            try {
                hotspotDiagnosticMXBean = jmx.getMXBean(
                        ObjectName.getInstance(HOTSPOT_DIAGNOSTIC_MXBEAN_NAME),
                        HotSpotDiagnosticMXBean.class);
            } catch (MalformedObjectNameException e) {
                ErrorManager.getDefault().log(ErrorManager.WARNING,
                        "Couldn't find HotSpotDiagnosticMXBean: " + // NOI18N
                        e.getLocalizedMessage());
            } catch (IllegalArgumentException ex) {
                ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
            }
        }
        hotspotDiagnosticInitialized = true;
        return hotspotDiagnosticMXBean;
    }
}
 
Example #2
Source File: GetVMOption.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void checkVMOption(HotSpotDiagnosticMXBean mbean) {
    VMOption option = mbean.getVMOption(HEAP_DUMP_ON_OOM);
    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 File: GetVMOption.java    From openjdk-8-source with 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 File: GetVMOption.java    From jdk8u60 with 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
Source File: GetVMOption.java    From openjdk-jdk8u with 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 #6
Source File: JVMUtil.java    From mpush with Apache License 2.0 6 votes vote down vote up
private static HotSpotDiagnosticMXBean getHotSpotMXBean() {
    try {
        return AccessController.doPrivileged(new PrivilegedExceptionAction<HotSpotDiagnosticMXBean>() {
            public HotSpotDiagnosticMXBean run() throws Exception {
                MBeanServer server = ManagementFactory.getPlatformMBeanServer();
                Set<ObjectName> s = server.queryNames(new ObjectName(HOT_SPOT_BEAN_NAME), null);
                Iterator<ObjectName> itr = s.iterator();
                if (itr.hasNext()) {
                    ObjectName name = itr.next();
                    HotSpotDiagnosticMXBean bean = ManagementFactory.newPlatformMXBeanProxy(server,
                            name.toString(), HotSpotDiagnosticMXBean.class);
                    return bean;
                } else {
                    return null;
                }
            }
        });
    } catch (Exception e) {
        LOGGER.error("getHotSpotMXBean Error!", e);
        return null;
    }
}
 
Example #7
Source File: MemoryUtil.java    From antsdb with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) {
    List<BufferPoolMXBean> pools = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
    for (BufferPoolMXBean pool:pools) {
        System.out.println(String.format(
                "%s %d/%d", 
                pool.getName(), 
                pool.getMemoryUsed(), 
                pool.getTotalCapacity()));
    }
    RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean();
    for (String arg:RuntimemxBean.getInputArguments()) {
        System.out.println(arg); 
    }
    HotSpotDiagnosticMXBean hsdiag = ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);
    for (VMOption i:hsdiag.getDiagnosticOptions()) {
        System.out.println(i.getName() + ":" + i.getValue());
    }
    System.out.println(hsdiag.getVMOption("MaxDirectMemorySize"));
    System.out.println(sun.misc.VM.maxDirectMemory());
    System.out.println(getDirectMemoryUsed());
}
 
Example #8
Source File: GetVMOption.java    From jdk8u-jdk with 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 #9
Source File: GetVMOption.java    From hottub with 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 #10
Source File: TestG1HeapRegionSize.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
  HotSpotDiagnosticMXBean diagnostic = ManagementFactoryHelper.getDiagnosticMXBean();

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

  option = diagnostic.getVMOption("G1HeapRegionSize");
  if (!expectedValue.equals(option.getValue())) {
    throw new RuntimeException("Wrong value for G1HeapRegionSize. Expected " + expectedValue + " but got " + option.getValue());
  }
}
 
Example #11
Source File: PrintProcessor.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void accept(OutputAnalyzer outputAnalyzer) {
    boolean wizardMode = false;
    try {
        wizardMode = Boolean.parseBoolean(ManagementFactory
                .getPlatformMXBean(HotSpotDiagnosticMXBean.class)
                .getVMOption("WizardMode").getValue());
    } catch (IllegalArgumentException e) {
        // ignore exception because WizardMode exists in debug only builds
    }
    if (wizardMode) {
        System.out.println("SKIP: WizardMode's output are not supported");
        return;
    }
    for (String line : outputAnalyzer.asLines()) {
        Matcher matcher = COMPILED_METHOD.matcher(line);
        if (matcher.matches()) {
            String method = normalize(matcher.group("name"));
            if (!printMethods.contains(normalize(method))
                    && testMethods.contains(method)) {
                System.out.println(outputAnalyzer.getOutput());
                throw new AssertionError("FAILED: wrong method "
                        + "was printed: " + method + " LINE: " + line);
            }
        }
    }
}
 
Example #12
Source File: GetVMOption.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    List<HotSpotDiagnosticMXBean> list =
        ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);
    HotSpotDiagnosticMXBean mbean = list.get(0);
    checkVMOption(mbean);

    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    mbean = ManagementFactory.newPlatformMXBeanProxy(mbs,
                HOTSPOT_DIAGNOSTIC_MXBEAN_NAME,
                HotSpotDiagnosticMXBean.class);
    checkVMOption(mbean);
}
 
Example #13
Source File: GetDoubleVMOption.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    List<HotSpotDiagnosticMXBean> list =
        ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);
    HotSpotDiagnosticMXBean mbean = list.get(0);
    checkVMOption(mbean);

    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    mbean = ManagementFactory.newPlatformMXBeanProxy(mbs,
                HOTSPOT_DIAGNOSTIC_MXBEAN_NAME,
                HotSpotDiagnosticMXBean.class);
    checkVMOption(mbean);
}
 
Example #14
Source File: TestSummarizeRSetStatsTools.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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 #15
Source File: SetAllVMOptions.java    From jdk8u_jdk with 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 #16
Source File: ProxyClient.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public synchronized HotSpotDiagnosticMXBean getHotSpotDiagnosticMXBean() throws IOException {
    if (hasHotSpotDiagnosticMXBean && hotspotDiagnosticMXBean == null) {
        hotspotDiagnosticMXBean =
            newPlatformMXBeanProxy(server, HOTSPOT_DIAGNOSTIC_MXBEAN_NAME,
                                   HotSpotDiagnosticMXBean.class);
    }
    return hotspotDiagnosticMXBean;
}
 
Example #17
Source File: Utils.java    From openjdk-jdk8u-backup with 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
 */
public static String getVMOption(String name) {
    String result;
    HotSpotDiagnosticMXBean diagnostic
            = ManagementFactoryHelper.getDiagnosticMXBean();
    result = diagnostic.getVMOption(name).getValue();
    return result;
}
 
Example #18
Source File: GetDiagnosticOptions.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    List<HotSpotDiagnosticMXBean> list =
        ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);
    HotSpotDiagnosticMXBean mbean = list.get(0);
    checkDiagnosticOptions(mbean);

    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    mbean = ManagementFactory.newPlatformMXBeanProxy(mbs,
                HOTSPOT_DIAGNOSTIC_MXBEAN_NAME,
                HotSpotDiagnosticMXBean.class);
    checkDiagnosticOptions(mbean);
}
 
Example #19
Source File: CompilerWhiteBoxTest.java    From openjdk-jdk8u-backup with 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 #20
Source File: Utils.java    From openjdk-8 with 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
 */
public static String getVMOption(String name) {
    String result;
    HotSpotDiagnosticMXBean diagnostic
            = ManagementFactoryHelper.getDiagnosticMXBean();
    result = diagnostic.getVMOption(name).getValue();
    return result;
}
 
Example #21
Source File: ProxyClient.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public synchronized HotSpotDiagnosticMXBean getHotSpotDiagnosticMXBean() throws IOException {
    if (hasHotSpotDiagnosticMXBean && hotspotDiagnosticMXBean == null) {
        hotspotDiagnosticMXBean =
            newPlatformMXBeanProxy(server, HOTSPOT_DIAGNOSTIC_MXBEAN_NAME,
                                   HotSpotDiagnosticMXBean.class);
    }
    return hotspotDiagnosticMXBean;
}
 
Example #22
Source File: TestSummarizeRSetStatsTools.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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 #23
Source File: CompilerWhiteBoxTest.java    From openjdk-8 with 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 #24
Source File: ProxyClient.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public synchronized HotSpotDiagnosticMXBean getHotSpotDiagnosticMXBean() throws IOException {
    if (hasHotSpotDiagnosticMXBean && hotspotDiagnosticMXBean == null) {
        hotspotDiagnosticMXBean =
            newPlatformMXBeanProxy(server, HOTSPOT_DIAGNOSTIC_MXBEAN_NAME,
                                   HotSpotDiagnosticMXBean.class);
    }
    return hotspotDiagnosticMXBean;
}
 
Example #25
Source File: GetDiagnosticOptions.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    List<HotSpotDiagnosticMXBean> list =
        ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);
    HotSpotDiagnosticMXBean mbean = list.get(0);
    checkDiagnosticOptions(mbean);

    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    mbean = ManagementFactory.newPlatformMXBeanProxy(mbs,
                HOTSPOT_DIAGNOSTIC_MXBEAN_NAME,
                HotSpotDiagnosticMXBean.class);
    checkDiagnosticOptions(mbean);
}
 
Example #26
Source File: GetDiagnosticOptions.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    List<HotSpotDiagnosticMXBean> list =
        ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);
    HotSpotDiagnosticMXBean mbean = list.get(0);
    checkDiagnosticOptions(mbean);

    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    mbean = ManagementFactory.newPlatformMXBeanProxy(mbs,
                HOTSPOT_DIAGNOSTIC_MXBEAN_NAME,
                HotSpotDiagnosticMXBean.class);
    checkDiagnosticOptions(mbean);
}
 
Example #27
Source File: GetVMOption.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    List<HotSpotDiagnosticMXBean> list =
        ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);
    HotSpotDiagnosticMXBean mbean = list.get(0);
    checkVMOption(mbean);

    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    mbean = ManagementFactory.newPlatformMXBeanProxy(mbs,
                HOTSPOT_DIAGNOSTIC_MXBEAN_NAME,
                HotSpotDiagnosticMXBean.class);
    checkVMOption(mbean);
}
 
Example #28
Source File: GetVMOption.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    List<HotSpotDiagnosticMXBean> list =
        ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);
    HotSpotDiagnosticMXBean mbean = list.get(0);
    checkVMOption(mbean);

    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    mbean = ManagementFactory.newPlatformMXBeanProxy(mbs,
                HOTSPOT_DIAGNOSTIC_MXBEAN_NAME,
                HotSpotDiagnosticMXBean.class);
    checkVMOption(mbean);
}
 
Example #29
Source File: ProxyClient.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public synchronized HotSpotDiagnosticMXBean getHotSpotDiagnosticMXBean() throws IOException {
    if (hasHotSpotDiagnosticMXBean && hotspotDiagnosticMXBean == null) {
        hotspotDiagnosticMXBean =
            newPlatformMXBeanProxy(server, HOTSPOT_DIAGNOSTIC_MXBEAN_NAME,
                                   HotSpotDiagnosticMXBean.class);
    }
    return hotspotDiagnosticMXBean;
}
 
Example #30
Source File: ProxyClient.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public synchronized HotSpotDiagnosticMXBean getHotSpotDiagnosticMXBean() throws IOException {
    if (hasHotSpotDiagnosticMXBean && hotspotDiagnosticMXBean == null) {
        hotspotDiagnosticMXBean =
            newPlatformMXBeanProxy(server, HOTSPOT_DIAGNOSTIC_MXBEAN_NAME,
                                   HotSpotDiagnosticMXBean.class);
    }
    return hotspotDiagnosticMXBean;
}