1 /*
   2  * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_SERVICES_DIAGNOSTICCOMMAND_HPP
  26 #define SHARE_VM_SERVICES_DIAGNOSTICCOMMAND_HPP
  27 
  28 #include "runtime/arguments.hpp"
  29 #include "classfile/vmSymbols.hpp"
  30 #include "utilities/ostream.hpp"
  31 #include "runtime/vm_version.hpp"
  32 #include "runtime/vmThread.hpp"
  33 #include "runtime/os.hpp"
  34 #include "services/diagnosticArgument.hpp"
  35 #include "services/diagnosticCommand.hpp"
  36 #include "services/diagnosticFramework.hpp"
  37 #include "services/diagnosticCommand_ext.hpp"
  38 #include "utilities/macros.hpp"
  39 
  40 class HelpDCmd : public DCmdWithParser {
  41 protected:
  42   DCmdArgument<bool> _all;
  43   DCmdArgument<char*> _cmd;
  44 public:
  45   HelpDCmd(outputStream* output, bool heap);
  46   static const char* name() { return "help"; }
  47   static const char* description() {
  48     return "For more information about a specific command use 'help <command>'. "
  49            "With no argument this will show a list of available commands. "
  50            "'help all' will show help for all commands.";
  51   }
  52   static const char* impact() { return "Low"; }
  53   static int num_arguments();
  54   virtual void execute(DCmdSource source, TRAPS);
  55 };
  56 
  57 class VersionDCmd : public DCmd {
  58 public:
  59   VersionDCmd(outputStream* output, bool heap) : DCmd(output,heap) { }
  60   static const char* name() { return "VM.version"; }
  61   static const char* description() {
  62     return "Print JVM version information.";
  63   }
  64   static const char* impact() { return "Low"; }
  65   static const JavaPermission permission() {
  66     JavaPermission p = {"java.util.PropertyPermission",
  67                         "java.vm.version", "read"};
  68     return p;
  69   }
  70   static int num_arguments() { return 0; }
  71   virtual void execute(DCmdSource source, TRAPS);
  72 };
  73 
  74 class CommandLineDCmd : public DCmd {
  75 public:
  76   CommandLineDCmd(outputStream* output, bool heap) : DCmd(output, heap) { }
  77   static const char* name() { return "VM.command_line"; }
  78   static const char* description() {
  79     return "Print the command line used to start this VM instance.";
  80   }
  81   static const char* impact() { return "Low"; }
  82   static const JavaPermission permission() {
  83     JavaPermission p = {"java.lang.management.ManagementPermission",
  84                         "monitor", NULL};
  85     return p;
  86   }
  87   static int num_arguments() { return 0; }
  88   virtual void execute(DCmdSource source, TRAPS) {
  89     Arguments::print_on(_output);
  90   }
  91 };
  92 
  93 // See also: get_system_properties in attachListener.cpp
  94 class PrintSystemPropertiesDCmd : public DCmd {
  95 public:
  96   PrintSystemPropertiesDCmd(outputStream* output, bool heap) : DCmd(output, heap) { }
  97     static const char* name() { return "VM.system_properties"; }
  98     static const char* description() {
  99       return "Print system properties.";
 100     }
 101     static const char* impact() {
 102       return "Low";
 103     }
 104     static const JavaPermission permission() {
 105       JavaPermission p = {"java.util.PropertyPermission",
 106                           "*", "read"};
 107       return p;
 108     }
 109     static int num_arguments() { return 0; }
 110     virtual void execute(DCmdSource source, TRAPS);
 111 };
 112 
 113 // See also: print_flag in attachListener.cpp
 114 class PrintVMFlagsDCmd : public DCmdWithParser {
 115 protected:
 116   DCmdArgument<bool> _all;
 117 public:
 118   PrintVMFlagsDCmd(outputStream* output, bool heap);
 119   static const char* name() { return "VM.flags"; }
 120   static const char* description() {
 121     return "Print VM flag options and their current values.";
 122   }
 123   static const char* impact() {
 124     return "Low";
 125   }
 126   static const JavaPermission permission() {
 127     JavaPermission p = {"java.lang.management.ManagementPermission",
 128                         "monitor", NULL};
 129     return p;
 130   }
 131   static int num_arguments();
 132   virtual void execute(DCmdSource source, TRAPS);
 133 };
 134 
 135 class VMUptimeDCmd : public DCmdWithParser {
 136 protected:
 137   DCmdArgument<bool> _date;
 138 public:
 139   VMUptimeDCmd(outputStream* output, bool heap);
 140   static const char* name() { return "VM.uptime"; }
 141   static const char* description() {
 142     return "Print VM uptime.";
 143   }
 144   static const char* impact() {
 145     return "Low";
 146   }
 147   static int num_arguments();
 148   virtual void execute(DCmdSource source, TRAPS);
 149 };
 150 
 151 class SystemGCDCmd : public DCmd {
 152 public:
 153   SystemGCDCmd(outputStream* output, bool heap) : DCmd(output, heap) { }
 154     static const char* name() { return "GC.run"; }
 155     static const char* description() {
 156       return "Call java.lang.System.gc().";
 157     }
 158     static const char* impact() {
 159       return "Medium: Depends on Java heap size and content.";
 160     }
 161     static int num_arguments() { return 0; }
 162     virtual void execute(DCmdSource source, TRAPS);
 163 };
 164 
 165 class RunFinalizationDCmd : public DCmd {
 166 public:
 167   RunFinalizationDCmd(outputStream* output, bool heap) : DCmd(output, heap) { }
 168     static const char* name() { return "GC.run_finalization"; }
 169     static const char* description() {
 170       return "Call java.lang.System.runFinalization().";
 171     }
 172     static const char* impact() {
 173       return "Medium: Depends on Java content.";
 174     }
 175     static int num_arguments() { return 0; }
 176     virtual void execute(DCmdSource source, TRAPS);
 177 };
 178 
 179 #if INCLUDE_SERVICES   // Heap dumping supported
 180 // See also: dump_heap in attachListener.cpp
 181 class HeapDumpDCmd : public DCmdWithParser {
 182 protected:
 183   DCmdArgument<char*> _filename;
 184   DCmdArgument<bool>  _all;
 185 public:
 186   HeapDumpDCmd(outputStream* output, bool heap);
 187   static const char* name() {
 188     return "GC.heap_dump";
 189   }
 190   static const char* description() {
 191     return "Generate a HPROF format dump of the Java heap.";
 192   }
 193   static const char* impact() {
 194     return "High: Depends on Java heap size and content. "
 195            "Request a full GC unless the '-all' option is specified.";
 196   }
 197   static const JavaPermission permission() {
 198     JavaPermission p = {"java.lang.management.ManagementPermission",
 199                         "monitor", NULL};
 200     return p;
 201   }
 202   static int num_arguments();
 203   virtual void execute(DCmdSource source, TRAPS);
 204 };
 205 #endif // INCLUDE_SERVICES
 206 
 207 // See also: inspectheap in attachListener.cpp
 208 class ClassHistogramDCmd : public DCmdWithParser {
 209 protected:
 210   DCmdArgument<bool> _all;
 211 public:
 212   ClassHistogramDCmd(outputStream* output, bool heap);
 213   static const char* name() {
 214     return "GC.class_histogram";
 215   }
 216   static const char* description() {
 217     return "Provide statistics about the Java heap usage.";
 218   }
 219   static const char* impact() {
 220     return "High: Depends on Java heap size and content.";
 221   }
 222   static const JavaPermission permission() {
 223     JavaPermission p = {"java.lang.management.ManagementPermission",
 224                         "monitor", NULL};
 225     return p;
 226   }
 227   static int num_arguments();
 228   virtual void execute(DCmdSource source, TRAPS);
 229 };
 230 
 231 class ClassStatsDCmd : public DCmdWithParser {
 232 protected:
 233   DCmdArgument<bool> _all;
 234   DCmdArgument<bool> _csv;
 235   DCmdArgument<bool> _help;
 236   DCmdArgument<char*> _columns;
 237 public:
 238   ClassStatsDCmd(outputStream* output, bool heap);
 239   static const char* name() {
 240     return "GC.class_stats";
 241   }
 242   static const char* description() {
 243     return "Provide statistics about Java class meta data. Requires -XX:+UnlockDiagnosticVMOptions.";
 244   }
 245   static const char* impact() {
 246     return "High: Depends on Java heap size and content.";
 247   }
 248   static int num_arguments();
 249   virtual void execute(DCmdSource source, TRAPS);
 250 };
 251 
 252 // See also: thread_dump in attachListener.cpp
 253 class ThreadDumpDCmd : public DCmdWithParser {
 254 protected:
 255   DCmdArgument<bool> _locks;
 256 public:
 257   ThreadDumpDCmd(outputStream* output, bool heap);
 258   static const char* name() { return "Thread.print"; }
 259   static const char* description() {
 260     return "Print all threads with stacktraces.";
 261   }
 262   static const char* impact() {
 263     return "Medium: Depends on the number of threads.";
 264   }
 265   static const JavaPermission permission() {
 266     JavaPermission p = {"java.lang.management.ManagementPermission",
 267                         "monitor", NULL};
 268     return p;
 269   }
 270   static int num_arguments();
 271   virtual void execute(DCmdSource source, TRAPS);
 272 };
 273 
 274 // Enhanced JMX Agent support
 275 
 276 class JMXStartRemoteDCmd : public DCmdWithParser {
 277 
 278   // Explicitly list all properties that could be
 279   // passed to Agent.startRemoteManagementAgent()
 280   // com.sun.management is omitted
 281 
 282   DCmdArgument<char *> _config_file;
 283   DCmdArgument<char *> _jmxremote_port;
 284   DCmdArgument<char *> _jmxremote_rmi_port;
 285   DCmdArgument<char *> _jmxremote_ssl;
 286   DCmdArgument<char *> _jmxremote_registry_ssl;
 287   DCmdArgument<char *> _jmxremote_authenticate;
 288   DCmdArgument<char *> _jmxremote_password_file;
 289   DCmdArgument<char *> _jmxremote_access_file;
 290   DCmdArgument<char *> _jmxremote_login_config;
 291   DCmdArgument<char *> _jmxremote_ssl_enabled_cipher_suites;
 292   DCmdArgument<char *> _jmxremote_ssl_enabled_protocols;
 293   DCmdArgument<char *> _jmxremote_ssl_need_client_auth;
 294   DCmdArgument<char *> _jmxremote_ssl_config_file;
 295 
 296   // JDP support
 297   // Keep autodiscovery char* not bool to pass true/false
 298   // as property value to java level.
 299   DCmdArgument<char *> _jmxremote_autodiscovery;
 300   DCmdArgument<jlong>  _jdp_port;
 301   DCmdArgument<char *> _jdp_address;
 302   DCmdArgument<char *> _jdp_source_addr;
 303   DCmdArgument<jlong>  _jdp_ttl;
 304   DCmdArgument<jlong>  _jdp_pause;
 305   DCmdArgument<char *> _jdp_name;
 306 
 307 public:
 308   JMXStartRemoteDCmd(outputStream *output, bool heap_allocated);
 309 
 310   static const char *name() {
 311     return "ManagementAgent.start";
 312   }
 313 
 314   static const char *description() {
 315     return "Start remote management agent.";
 316   }
 317 
 318   static int num_arguments();
 319 
 320   virtual void execute(DCmdSource source, TRAPS);
 321 
 322 };
 323 
 324 class JMXStartLocalDCmd : public DCmd {
 325 
 326   // Explicitly request start of local agent,
 327   // it will not be started by start dcmd
 328 
 329 
 330 public:
 331   JMXStartLocalDCmd(outputStream *output, bool heap_allocated);
 332 
 333   static const char *name() {
 334     return "ManagementAgent.start_local";
 335   }
 336 
 337   static const char *description() {
 338     return "Start local management agent.";
 339   }
 340 
 341   virtual void execute(DCmdSource source, TRAPS);
 342 
 343 };
 344 
 345 class JMXStopRemoteDCmd : public DCmd {
 346 public:
 347   JMXStopRemoteDCmd(outputStream *output, bool heap_allocated) :
 348   DCmd(output, heap_allocated) {
 349     // Do Nothing
 350   }
 351 
 352   static const char *name() {
 353     return "ManagementAgent.stop";
 354   }
 355 
 356   static const char *description() {
 357     return "Stop remote management agent.";
 358   }
 359 
 360   virtual void execute(DCmdSource source, TRAPS);
 361 };
 362 
 363 #endif // SHARE_VM_SERVICES_DIAGNOSTICCOMMAND_HPP