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;
}
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();
}
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;
}
Aggregations