Search in sources :

Example 1 with DiagnosticCommandMBean

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

the class ManagementFactoryHelper method getPlatformDynamicMBeans.

public static HashMap<ObjectName, DynamicMBean> getPlatformDynamicMBeans() {
    HashMap<ObjectName, DynamicMBean> map = new HashMap<>();
    DiagnosticCommandMBean diagMBean = getDiagnosticCommandMBean();
    if (diagMBean != null) {
        map.put(Util.newObjectName(HOTSPOT_DIAGNOSTIC_COMMAND_MBEAN_NAME), diagMBean);
    }
    return map;
}
Also used : DynamicMBean(javax.management.DynamicMBean) HashMap(java.util.HashMap) DiagnosticCommandMBean(com.sun.management.DiagnosticCommandMBean) ObjectName(javax.management.ObjectName)

Example 2 with DiagnosticCommandMBean

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

the class RedefineMethodInBacktraceApp method doMethodInBacktraceTestB.

private void doMethodInBacktraceTestB() throws Exception {
    // Start a thread which blocks in method
    Thread t = new Thread(RedefineMethodInBacktraceTargetB::methodToRedefine);
    t.setDaemon(true);
    t.start();
    // Wait here until the new thread is in the method we want to redefine
    called.await();
    // Now redefine the class while the method is still on the stack of the new thread
    doRedefine(RedefineMethodInBacktraceTargetB.class);
    // Do thread dumps in two different ways (to exercise different code paths)
    // while the old class is still on the stack
    ThreadInfo[] tis = ManagementFactory.getThreadMXBean().dumpAllThreads(false, false);
    for (ThreadInfo ti : tis) {
        System.out.println(ti);
    }
    String[] threadPrintArgs = {};
    Object[] dcmdArgs = { threadPrintArgs };
    String[] signature = { String[].class.getName() };
    DiagnosticCommandMBean dcmd = ManagementFactoryHelper.getDiagnosticCommandMBean();
    System.out.println(dcmd.invoke("threadPrint", dcmdArgs, signature));
    // release the thread
    stop.countDown();
}
Also used : ThreadInfo(java.lang.management.ThreadInfo) DiagnosticCommandMBean(com.sun.management.DiagnosticCommandMBean)

Example 3 with DiagnosticCommandMBean

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

the class NMTHelper method executeDcmd.

private static String executeDcmd(String cmd, String... args) {
    DiagnosticCommandMBean dcmd = ManagementFactoryHelper.getDiagnosticCommandMBean();
    Object[] dcmdArgs = { args };
    String[] signature = { String[].class.getName() };
    String cmdString = cmd + " " + Arrays.stream(args).collect(Collectors.joining(" "));
    File f = new File("dcmdoutput-" + cmd + "-" + System.currentTimeMillis() + ".txt");
    System.out.println("Output from Dcmd '" + cmdString + "' is being written to file " + f);
    try (FileWriter fw = new FileWriter(f)) {
        fw.write("> " + cmdString + ":");
        String result = (String) dcmd.invoke(cmd, dcmdArgs, signature);
        fw.write(result);
        return result;
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return null;
}
Also used : DiagnosticCommandMBean(com.sun.management.DiagnosticCommandMBean) FileWriter(java.io.FileWriter) File(java.io.File)

Aggregations

DiagnosticCommandMBean (com.sun.management.DiagnosticCommandMBean)3 File (java.io.File)1 FileWriter (java.io.FileWriter)1 ThreadInfo (java.lang.management.ThreadInfo)1 HashMap (java.util.HashMap)1 DynamicMBean (javax.management.DynamicMBean)1 ObjectName (javax.management.ObjectName)1