Java Code Examples for sun.management.ManagementFactoryHelper#getDiagnosticCommandMBean()

The following examples show how to use sun.management.ManagementFactoryHelper#getDiagnosticCommandMBean() . 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: DcmdUtil.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static String executeDcmd(String cmd, String ... args) {
    DiagnosticCommandMBean dcmd = ManagementFactoryHelper.getDiagnosticCommandMBean();
    Object[] dcmdArgs = {args};
    String[] signature = {String[].class.getName()};

    try {
        System.out.print("> " + cmd + " ");
        for (String s : args) {
            System.out.print(s + " ");
        }
        System.out.println(":");
        String result = (String) dcmd.invoke(transform(cmd), dcmdArgs, signature);
        System.out.println(result);
        return result;
    } catch(Exception ex) {
        ex.printStackTrace();
    }
    return null;
}
 
Example 2
Source File: NMTHelper.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private static String executeDcmd(String cmd, String ... args) {
    DiagnosticCommandMBean dcmd = ManagementFactoryHelper.getDiagnosticCommandMBean();
    Object[] dcmdArgs = {args};
    String[] signature = {String[].class.getName()};

    try {
        System.out.print("> " + cmd + " ");
        for (String s : args) {
            System.out.print(s + " ");
        }
        System.out.println(":");
        String result = (String) dcmd.invoke(cmd, dcmdArgs, signature);
        System.out.println(result);
        return result;
    } catch(Exception ex) {
        ex.printStackTrace();
    }
    return null;
}
 
Example 3
Source File: NMTHelper.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private static String executeDcmd(String cmd, String ... args) {
    DiagnosticCommandMBean dcmd = ManagementFactoryHelper.getDiagnosticCommandMBean();
    Object[] dcmdArgs = {args};
    String[] signature = {String[].class.getName()};

    try {
        System.out.print("> " + cmd + " ");
        for (String s : args) {
            System.out.print(s + " ");
        }
        System.out.println(":");
        String result = (String) dcmd.invoke(cmd, dcmdArgs, signature);
        System.out.println(result);
        return result;
    } catch(Exception ex) {
        ex.printStackTrace();
    }
    return null;
}
 
Example 4
Source File: NMTHelper.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 5
Source File: NMTHelper.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 6
Source File: NMTHelper.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 7
Source File: NMTHelper.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 8
Source File: NMTHelper.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 9
Source File: NMTHelper.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 10
Source File: DcmdUtil.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static String executeDcmd(String cmd, String ... args) {
    DiagnosticCommandMBean dcmd = ManagementFactoryHelper.getDiagnosticCommandMBean();
    Object[] dcmdArgs = {args};
    String[] signature = {String[].class.getName()};

    try {
        System.out.print("> " + cmd + " ");
        for (String s : args) {
            System.out.print(s + " ");
        }
        System.out.println(":");
        String result = (String) dcmd.invoke(transform(cmd), dcmdArgs, signature);
        System.out.println(result);
        return result;
    } catch(Exception ex) {
        ex.printStackTrace();
    }
    return null;
}
 
Example 11
Source File: RedefineMethodInBacktraceApp.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 12
Source File: RedefineMethodInBacktraceApp.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 13
Source File: RedefineMethodInBacktraceApp.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 14
Source File: RedefineMethodInBacktraceApp.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 15
Source File: RedefineMethodInBacktraceApp.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 16
Source File: RedefineMethodInBacktraceApp.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 17
Source File: RedefineMethodInBacktraceApp.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 18
Source File: RedefineMethodInBacktraceApp.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 19
Source File: RedefineMethodInBacktraceApp.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 20
Source File: RedefineMethodInBacktraceApp.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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();
}