8023093: Add ManagementAgent.status diagnostic command
authorjbachorik
Thu, 26 Mar 2015 10:37:10 +0100
changeset 30134 ecd7b08105e9
parent 30130 386d3e9878bc
child 30135 bbb14e0a0c79
8023093: Add ManagementAgent.status diagnostic command Reviewed-by: sla
hotspot/src/share/vm/classfile/vmSymbols.hpp
hotspot/src/share/vm/services/diagnosticCommand.cpp
hotspot/src/share/vm/services/diagnosticCommand.hpp
--- a/hotspot/src/share/vm/classfile/vmSymbols.hpp	Wed Apr 01 15:27:04 2015 +0200
+++ b/hotspot/src/share/vm/classfile/vmSymbols.hpp	Thu Mar 26 10:37:10 2015 +0100
@@ -559,6 +559,7 @@
   template(startRemoteAgent_name,                      "startRemoteManagementAgent")                              \
   template(startLocalAgent_name,                       "startLocalManagementAgent")                               \
   template(stopRemoteAgent_name,                       "stopRemoteManagementAgent")                               \
+  template(getAgentStatus_name,                        "getManagementAgentStatus")                                \
   template(java_lang_management_ThreadInfo_constructor_signature, "(Ljava/lang/Thread;ILjava/lang/Object;Ljava/lang/Thread;JJJJ[Ljava/lang/StackTraceElement;)V") \
   template(java_lang_management_ThreadInfo_with_locks_constructor_signature, "(Ljava/lang/Thread;ILjava/lang/Object;Ljava/lang/Thread;JJJJ[Ljava/lang/StackTraceElement;[Ljava/lang/Object;[I[Ljava/lang/Object;)V") \
   template(long_long_long_long_void_signature,         "(JJJJ)V")                                                 \
--- a/hotspot/src/share/vm/services/diagnosticCommand.cpp	Wed Apr 01 15:27:04 2015 +0200
+++ b/hotspot/src/share/vm/services/diagnosticCommand.cpp	Thu Mar 26 10:37:10 2015 +0100
@@ -81,6 +81,7 @@
   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStartRemoteDCmd>(jmx_agent_export_flags, true,false));
   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStartLocalDCmd>(jmx_agent_export_flags, true,false));
   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStopRemoteDCmd>(jmx_agent_export_flags, true,false));
+  DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStatusDCmd>(jmx_agent_export_flags, true,false));
 
 }
 
@@ -708,6 +709,38 @@
     JavaCalls::call_static(&result, ik, vmSymbols::stopRemoteAgent_name(), vmSymbols::void_method_signature(), CHECK);
 }
 
+JMXStatusDCmd::JMXStatusDCmd(outputStream *output, bool heap_allocated) :
+  DCmd(output, heap_allocated) {
+  // do nothing
+}
+
+void JMXStatusDCmd::execute(DCmdSource source, TRAPS) {
+  ResourceMark rm(THREAD);
+  HandleMark hm(THREAD);
+
+  // Load and initialize the sun.management.Agent class
+  // invoke getManagementAgentStatus() method to generate the status info
+  // throw java.lang.NoSuchMethodError if method doesn't exist
+
+  Handle loader = Handle(THREAD, SystemDictionary::java_system_loader());
+  Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::sun_management_Agent(), loader, Handle(), true, CHECK);
+  instanceKlassHandle ik (THREAD, k);
+
+  JavaValue result(T_OBJECT);
+  JavaCalls::call_static(&result, ik, vmSymbols::getAgentStatus_name(), vmSymbols::void_string_signature(), CHECK);
+
+  jvalue* jv = (jvalue*) result.get_value_addr();
+  oop str = (oop) jv->l;
+  if (str != NULL) {
+      char* out = java_lang_String::as_utf8_string(str);
+      if (out) {
+          output()->print_cr("%s", out);
+          return;
+      }
+  }
+  output()->print_cr("Error obtaining management agent status");
+}
+
 VMDynamicLibrariesDCmd::VMDynamicLibrariesDCmd(outputStream *output, bool heap_allocated) :
   DCmd(output, heap_allocated) {
   // do nothing
--- a/hotspot/src/share/vm/services/diagnosticCommand.hpp	Wed Apr 01 15:27:04 2015 +0200
+++ b/hotspot/src/share/vm/services/diagnosticCommand.hpp	Thu Mar 26 10:37:10 2015 +0100
@@ -452,6 +452,29 @@
   virtual void execute(DCmdSource source, TRAPS);
 };
 
+// Print the JMX system status
+class JMXStatusDCmd : public DCmd {
+public:
+  JMXStatusDCmd(outputStream *output, bool heap_allocated);
+
+  static const char *name() {
+    return "ManagementAgent.status";
+  }
+
+  static const char *description() {
+    return "Print the management agent status.";
+  }
+
+  static const JavaPermission permission() {
+    JavaPermission p = {"java.lang.management.ManagementPermission",
+                        "monitor", NULL};
+    return p;
+  }
+
+  virtual void execute(DCmdSource source, TRAPS);
+
+};
+
 class RotateGCLogDCmd : public DCmd {
 public:
   RotateGCLogDCmd(outputStream* output, bool heap) : DCmd(output, heap) {}