1 /*
   2  * Copyright (c) 2011, 2014, 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 "classfile/vmSymbols.hpp"
  29 #include "runtime/arguments.hpp"
  30 #include "runtime/os.hpp"
  31 #include "runtime/vmThread.hpp"
  32 #include "services/diagnosticArgument.hpp"
  33 #include "services/diagnosticCommand.hpp"
  34 #include "services/diagnosticCommand_ext.hpp"
  35 #include "services/diagnosticFramework.hpp"
  36 #include "utilities/macros.hpp"
  37 #include "utilities/ostream.hpp"
  38 
  39 class HelpDCmd : public DCmdWithParser {
  40 protected:
  41   DCmdArgument<bool> _all;
  42   DCmdArgument<char*> _cmd;
  43 public:
  44   HelpDCmd(outputStream* output, bool heap);
  45   static const char* name() { return "help"; }
  46   static const char* description() {
  47     return "For more information about a specific command use 'help <command>'. "
  48            "With no argument this will show a list of available commands. "
  49            "'help all' will show help for all commands.";
  50   }
  51   static const char* impact() { return "Low"; }
  52   static int num_arguments();
  53   virtual void execute(DCmdSource source, TRAPS);
  54 };
  55 
  56 class VersionDCmd : public DCmd {
  57 public:
  58   VersionDCmd(outputStream* output, bool heap) : DCmd(output,heap) { }
  59   static const char* name() { return "VM.version"; }
  60   static const char* description() {
  61     return "Print JVM version information.";
  62   }
  63   static const char* impact() { return "Low"; }
  64   static const JavaPermission permission() {
  65     JavaPermission p = {"java.util.PropertyPermission",
  66                         "java.vm.version", "read"};
  67     return p;
  68   }
  69   static int num_arguments() { return 0; }
  70   virtual void execute(DCmdSource source, TRAPS);
  71 };
  72 
  73 class CommandLineDCmd : public DCmd {
  74 public:
  75   CommandLineDCmd(outputStream* output, bool heap) : DCmd(output, heap) { }
  76   static const char* name() { return "VM.command_line"; }
  77   static const char* description() {
  78     return "Print the command line used to start this VM instance.";
  79   }
  80   static const char* impact() { return "Low"; }
  81   static const JavaPermission permission() {
  82     JavaPermission p = {"java.lang.management.ManagementPermission",
  83                         "monitor", NULL};
  84     return p;
  85   }
  86   static int num_arguments() { return 0; }
  87   virtual void execute(DCmdSource source, TRAPS) {
  88     Arguments::print_on(_output);
  89   }
  90 };
  91 
  92 // See also: get_system_properties in attachListener.cpp
  93 class PrintSystemPropertiesDCmd : public DCmd {
  94 public:
  95   PrintSystemPropertiesDCmd(outputStream* output, bool heap) : DCmd(output, heap) { }
  96     static const char* name() { return "VM.system_properties"; }
  97     static const char* description() {
  98       return "Print system properties.";
  99     }
 100     static const char* impact() {
 101       return "Low";
 102     }
 103     static const JavaPermission permission() {
 104       JavaPermission p = {"java.util.PropertyPermission",
 105                           "*", "read"};
 106       return p;
 107     }
 108     static int num_arguments() { return 0; }
 109     virtual void execute(DCmdSource source, TRAPS);
 110 };
 111 
 112 // See also: print_flag in attachListener.cpp
 113 class PrintVMFlagsDCmd : public DCmdWithParser {
 114 protected:
 115   DCmdArgument<bool> _all;
 116 public:
 117   PrintVMFlagsDCmd(outputStream* output, bool heap);
 118   static const char* name() { return "VM.flags"; }
 119   static const char* description() {
 120     return "Print VM flag options and their current values.";
 121   }
 122   static const char* impact() {
 123     return "Low";
 124   }
 125   static const JavaPermission permission() {
 126     JavaPermission p = {"java.lang.management.ManagementPermission",
 127                         "monitor", NULL};
 128     return p;
 129   }
 130   static int num_arguments();
 131   virtual void execute(DCmdSource source, TRAPS);
 132 };
 133 
 134 class VMDynamicLibrariesDCmd : public DCmd {
 135 public:
 136   VMDynamicLibrariesDCmd(outputStream* output, bool heap);
 137   static const char* name() {
 138     return "VM.dynlibs";
 139   }
 140   static const char* description() {
 141     return "Print loaded dynamic libraries.";
 142   }
 143   static const char* impact() {
 144     return "Low";
 145   }
 146   static const JavaPermission permission() {
 147     JavaPermission p = {"java.lang.management.ManagementPermission",
 148                         "monitor", NULL};
 149     return p;
 150   }
 151   static int num_arguments() {
 152     return 0;
 153   };
 154   virtual void execute(DCmdSource source, TRAPS);
 155 };
 156 
 157 class VMUptimeDCmd : public DCmdWithParser {
 158 protected:
 159   DCmdArgument<bool> _date;
 160 public:
 161   VMUptimeDCmd(outputStream* output, bool heap);
 162   static const char* name() { return "VM.uptime"; }
 163   static const char* description() {
 164     return "Print VM uptime.";
 165   }
 166   static const char* impact() {
 167     return "Low";
 168   }
 169   static int num_arguments();
 170   virtual void execute(DCmdSource source, TRAPS);
 171 };
 172 
 173 class SystemGCDCmd : public DCmd {
 174 public:
 175   SystemGCDCmd(outputStream* output, bool heap) : DCmd(output, heap) { }
 176     static const char* name() { return "GC.run"; }
 177     static const char* description() {
 178       return "Call java.lang.System.gc().";
 179     }
 180     static const char* impact() {
 181       return "Medium: Depends on Java heap size and content.";
 182     }
 183     static int num_arguments() { return 0; }
 184     virtual void execute(DCmdSource source, TRAPS);
 185 };
 186 
 187 class RunFinalizationDCmd : public DCmd {
 188 public:
 189   RunFinalizationDCmd(outputStream* output, bool heap) : DCmd(output, heap) { }
 190     static const char* name() { return "GC.run_finalization"; }
 191     static const char* description() {
 192       return "Call java.lang.System.runFinalization().";
 193     }
 194     static const char* impact() {
 195       return "Medium: Depends on Java content.";
 196     }
 197     static int num_arguments() { return 0; }
 198     virtual void execute(DCmdSource source, TRAPS);
 199 };
 200 
 201 #if INCLUDE_SERVICES   // Heap dumping supported
 202 // See also: dump_heap in attachListener.cpp
 203 class HeapDumpDCmd : public DCmdWithParser {
 204 protected:
 205   DCmdArgument<char*> _filename;
 206   DCmdArgument<bool>  _all;
 207 public:
 208   HeapDumpDCmd(outputStream* output, bool heap);
 209   static const char* name() {
 210     return "GC.heap_dump";
 211   }
 212   static const char* description() {
 213     return "Generate a HPROF format dump of the Java heap.";
 214   }
 215   static const char* impact() {
 216     return "High: Depends on Java heap size and content. "
 217            "Request a full GC unless the '-all' option is specified.";
 218   }
 219   static const JavaPermission permission() {
 220     JavaPermission p = {"java.lang.management.ManagementPermission",
 221                         "monitor", NULL};
 222     return p;
 223   }
 224   static int num_arguments();
 225   virtual void execute(DCmdSource source, TRAPS);
 226 };
 227 #endif // INCLUDE_SERVICES
 228 
 229 // See also: inspectheap in attachListener.cpp
 230 class ClassHistogramDCmd : public DCmdWithParser {
 231 protected:
 232   DCmdArgument<bool> _all;
 233 public:
 234   ClassHistogramDCmd(outputStream* output, bool heap);
 235   static const char* name() {
 236     return "GC.class_histogram";
 237   }
 238   static const char* description() {
 239     return "Provide statistics about the Java heap usage.";
 240   }
 241   static const char* impact() {
 242     return "High: Depends on Java heap size and content.";
 243   }
 244   static const JavaPermission permission() {
 245     JavaPermission p = {"java.lang.management.ManagementPermission",
 246                         "monitor", NULL};
 247     return p;
 248   }
 249   static int num_arguments();
 250   virtual void execute(DCmdSource source, TRAPS);
 251 };
 252 
 253 class ClassStatsDCmd : public DCmdWithParser {
 254 protected:
 255   DCmdArgument<bool> _all;
 256   DCmdArgument<bool> _csv;
 257   DCmdArgument<bool> _help;
 258   DCmdArgument<char*> _columns;
 259 public:
 260   ClassStatsDCmd(outputStream* output, bool heap);
 261   static const char* name() {
 262     return "GC.class_stats";
 263   }
 264   static const char* description() {
 265     return "Provide statistics about Java class meta data. Requires -XX:+UnlockDiagnosticVMOptions.";
 266   }
 267   static const char* impact() {
 268     return "High: Depends on Java heap size and content.";
 269   }
 270   static int num_arguments();
 271   virtual void execute(DCmdSource source, TRAPS);
 272 };
 273 
 274 // See also: thread_dump in attachListener.cpp
 275 class ThreadDumpDCmd : public DCmdWithParser {
 276 protected:
 277   DCmdArgument<bool> _locks;
 278 public:
 279   ThreadDumpDCmd(outputStream* output, bool heap);
 280   static const char* name() { return "Thread.print"; }
 281   static const char* description() {
 282     return "Print all threads with stacktraces.";
 283   }
 284   static const char* impact() {
 285     return "Medium: Depends on the number of threads.";
 286   }
 287   static const JavaPermission permission() {
 288     JavaPermission p = {"java.lang.management.ManagementPermission",
 289                         "monitor", NULL};
 290     return p;
 291   }
 292   static int num_arguments();
 293   virtual void execute(DCmdSource source, TRAPS);
 294 };
 295 
 296 // Enhanced JMX Agent support
 297 
 298 class JMXStartRemoteDCmd : public DCmdWithParser {
 299 
 300   // Explicitly list all properties that could be
 301   // passed to Agent.startRemoteManagementAgent()
 302   // com.sun.management is omitted
 303 
 304   DCmdArgument<char *> _config_file;
 305   DCmdArgument<char *> _jmxremote_port;
 306   DCmdArgument<char *> _jmxremote_rmi_port;
 307   DCmdArgument<char *> _jmxremote_ssl;
 308   DCmdArgument<char *> _jmxremote_registry_ssl;
 309   DCmdArgument<char *> _jmxremote_authenticate;
 310   DCmdArgument<char *> _jmxremote_password_file;
 311   DCmdArgument<char *> _jmxremote_access_file;
 312   DCmdArgument<char *> _jmxremote_login_config;
 313   DCmdArgument<char *> _jmxremote_ssl_enabled_cipher_suites;
 314   DCmdArgument<char *> _jmxremote_ssl_enabled_protocols;
 315   DCmdArgument<char *> _jmxremote_ssl_need_client_auth;
 316   DCmdArgument<char *> _jmxremote_ssl_config_file;
 317 
 318   // JDP support
 319   // Keep autodiscovery char* not bool to pass true/false
 320   // as property value to java level.
 321   DCmdArgument<char *> _jmxremote_autodiscovery;
 322   DCmdArgument<jlong>  _jdp_port;
 323   DCmdArgument<char *> _jdp_address;
 324   DCmdArgument<char *> _jdp_source_addr;
 325   DCmdArgument<jlong>  _jdp_ttl;
 326   DCmdArgument<jlong>  _jdp_pause;
 327   DCmdArgument<char *> _jdp_name;
 328 
 329 public:
 330   JMXStartRemoteDCmd(outputStream *output, bool heap_allocated);
 331 
 332   static const char *name() {
 333     return "ManagementAgent.start";
 334   }
 335 
 336   static const char *description() {
 337     return "Start remote management agent.";
 338   }
 339 
 340   static int num_arguments();
 341 
 342   virtual void execute(DCmdSource source, TRAPS);
 343 
 344 };
 345 
 346 class JMXStartLocalDCmd : public DCmd {
 347 
 348   // Explicitly request start of local agent,
 349   // it will not be started by start dcmd
 350 
 351 
 352 public:
 353   JMXStartLocalDCmd(outputStream *output, bool heap_allocated);
 354 
 355   static const char *name() {
 356     return "ManagementAgent.start_local";
 357   }
 358 
 359   static const char *description() {
 360     return "Start local management agent.";
 361   }
 362 
 363   virtual void execute(DCmdSource source, TRAPS);
 364 
 365 };
 366 
 367 class JMXStopRemoteDCmd : public DCmd {
 368 public:
 369   JMXStopRemoteDCmd(outputStream *output, bool heap_allocated) :
 370   DCmd(output, heap_allocated) {
 371     // Do Nothing
 372   }
 373 
 374   static const char *name() {
 375     return "ManagementAgent.stop";
 376   }
 377 
 378   static const char *description() {
 379     return "Stop remote management agent.";
 380   }
 381 
 382   virtual void execute(DCmdSource source, TRAPS);
 383 };
 384 
 385 class RotateGCLogDCmd : public DCmd {
 386 public:
 387   RotateGCLogDCmd(outputStream* output, bool heap) : DCmd(output, heap) {}
 388   static const char* name() { return "GC.rotate_log"; }
 389   static const char* description() {
 390     return "Force the GC log file to be rotated.";
 391   }
 392   static const char* impact() { return "Low"; }
 393   virtual void execute(DCmdSource source, TRAPS);
 394   static int num_arguments() { return 0; }
 395   static const JavaPermission permission() {
 396     JavaPermission p = {"java.lang.management.ManagementPermission",
 397                         "control", NULL};
 398     return p;
 399   }
 400 };
 401 
 402 class CompileQueueDCmd : public DCmd {
 403 public:
 404   CompileQueueDCmd(outputStream* output, bool heap) : DCmd(output, heap) {}
 405   static const char* name() {
 406     return "Compiler.queue";
 407   }
 408   static const char* description() {
 409     return "Print methods queued for compilation.";
 410   }
 411   static const char* impact() {
 412     return "Low";
 413   }
 414   static const JavaPermission permission() {
 415     JavaPermission p = {"java.lang.management.ManagementPermission",
 416         "monitor", NULL};
 417     return p;
 418   }
 419   static int num_arguments() { return 0; }
 420   virtual void execute(DCmdSource source, TRAPS);
 421 };
 422 
 423 class CodeListDCmd : public DCmd {
 424 public:
 425   CodeListDCmd(outputStream* output, bool heap) : DCmd(output, heap) {}
 426   static const char* name() {
 427     return "Compiler.codelist";
 428   }
 429   static const char* description() {
 430     return "Print all compiled methods in code cache.";
 431   }
 432   static const char* impact() {
 433     return "Medium";
 434   }
 435   static const JavaPermission permission() {
 436     JavaPermission p = {"java.lang.management.ManagementPermission",
 437         "monitor", NULL};
 438     return p;
 439   }
 440   static int num_arguments() { return 0; }
 441   virtual void execute(DCmdSource source, TRAPS);
 442 };
 443 
 444 
 445 class CodeCacheDCmd : public DCmd {
 446 public:
 447   CodeCacheDCmd(outputStream* output, bool heap) : DCmd(output, heap) {}
 448   static const char* name() {
 449     return "Compiler.codecache";
 450   }
 451   static const char* description() {
 452     return "Print code cache layout and bounds.";
 453   }
 454   static const char* impact() {
 455     return "Low";
 456   }
 457   static const JavaPermission permission() {
 458     JavaPermission p = {"java.lang.management.ManagementPermission",
 459         "monitor", NULL};
 460     return p;
 461   }
 462   static int num_arguments() { return 0; }
 463   virtual void execute(DCmdSource source, TRAPS);
 464 };
 465 
 466 #endif // SHARE_VM_SERVICES_DIAGNOSTICCOMMAND_HPP