1 /*
   2  * Copyright (c) 2011, 2024, 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_SERVICES_DIAGNOSTICCOMMAND_HPP
  26 #define SHARE_SERVICES_DIAGNOSTICCOMMAND_HPP
  27 
  28 #include "classfile/stringTable.hpp"
  29 #include "classfile/symbolTable.hpp"
  30 #include "classfile/systemDictionary.hpp"
  31 #include "classfile/vmSymbols.hpp"
  32 #include "runtime/arguments.hpp"
  33 #include "runtime/os.hpp"
  34 #include "runtime/vmThread.hpp"
  35 #include "services/diagnosticArgument.hpp"
  36 #include "services/diagnosticCommand.hpp"
  37 #include "services/diagnosticFramework.hpp"
  38 #include "utilities/macros.hpp"
  39 #include "utilities/ostream.hpp"
  40 #include "oops/method.hpp"
  41 
  42 class HelpDCmd : public DCmdWithParser {
  43 protected:
  44   DCmdArgument<bool> _all;
  45   DCmdArgument<char*> _cmd;
  46 public:
  47   static int num_arguments() { return 2; }
  48   HelpDCmd(outputStream* output, bool heap);
  49   static const char* name() { return "help"; }
  50   static const char* description() {
  51     return "For more information about a specific command use 'help <command>'. "
  52            "With no argument this will show a list of available commands. "
  53            "'help all' will show help for all commands.";
  54   }
  55   static const char* impact() { return "Low"; }
  56   virtual void execute(DCmdSource source, TRAPS);
  57 };
  58 
  59 class VersionDCmd : public DCmd {
  60 public:
  61   VersionDCmd(outputStream* output, bool heap) : DCmd(output,heap) { }
  62   static const char* name() { return "VM.version"; }
  63   static const char* description() {
  64     return "Print JVM version information.";
  65   }
  66   static const char* impact() { return "Low"; }
  67   static const JavaPermission permission() {
  68     JavaPermission p = {"java.util.PropertyPermission",
  69                         "java.vm.version", "read"};
  70     return p;
  71   }
  72   virtual void execute(DCmdSource source, TRAPS);
  73 };
  74 
  75 class CommandLineDCmd : public DCmd {
  76 public:
  77   CommandLineDCmd(outputStream* output, bool heap) : DCmd(output, heap) { }
  78   static const char* name() { return "VM.command_line"; }
  79   static const char* description() {
  80     return "Print the command line used to start this VM instance.";
  81   }
  82   static const char* impact() { return "Low"; }
  83   static const JavaPermission permission() {
  84     JavaPermission p = {"java.lang.management.ManagementPermission",
  85                         "monitor", nullptr};
  86     return p;
  87   }
  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     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   static int num_arguments() { return 1; }
 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", nullptr};
 129     return p;
 130   }
 131   virtual void execute(DCmdSource source, TRAPS);
 132 };
 133 
 134 class SetVMFlagDCmd : public DCmdWithParser {
 135 protected:
 136   DCmdArgument<char*> _flag;
 137   DCmdArgument<char*> _value;
 138 
 139 public:
 140   static int num_arguments() { return 2; }
 141   SetVMFlagDCmd(outputStream* output, bool heap);
 142   static const char* name() { return "VM.set_flag"; }
 143   static const char* description() {
 144     return "Sets VM flag option using the provided value.";
 145   }
 146   static const char* impact() {
 147     return "Low";
 148   }
 149   static const JavaPermission permission() {
 150     JavaPermission p = {"java.lang.management.ManagementPermission",
 151                         "control", nullptr};
 152     return p;
 153   }
 154   virtual void execute(DCmdSource source, TRAPS);
 155 };
 156 
 157 class JVMTIDataDumpDCmd : public DCmd {
 158 public:
 159   JVMTIDataDumpDCmd(outputStream* output, bool heap) : DCmd(output, heap) { }
 160   static const char* name() { return "JVMTI.data_dump"; }
 161   static const char* description() {
 162     return "Signal the JVM to do a data-dump request for JVMTI.";
 163   }
 164   static const char* impact() {
 165     return "High";
 166   }
 167   static const JavaPermission permission() {
 168     JavaPermission p = {"java.lang.management.ManagementPermission",
 169                         "monitor", nullptr};
 170     return p;
 171   }
 172   virtual void execute(DCmdSource source, TRAPS);
 173 };
 174 
 175 #if INCLUDE_SERVICES
 176 #if INCLUDE_JVMTI
 177 class JVMTIAgentLoadDCmd : public DCmdWithParser {
 178 protected:
 179   DCmdArgument<char*> _libpath;
 180   DCmdArgument<char*> _option;
 181 public:
 182   static int num_arguments() { return 2; }
 183   JVMTIAgentLoadDCmd(outputStream* output, bool heap);
 184   static const char* name() { return "JVMTI.agent_load"; }
 185   static const char* description() {
 186     return "Load JVMTI native agent.";
 187   }
 188   static const char* impact() { return "Low"; }
 189   static const JavaPermission permission() {
 190     JavaPermission p = {"java.lang.management.ManagementPermission",
 191                         "control", nullptr};
 192     return p;
 193   }
 194   virtual void execute(DCmdSource source, TRAPS);
 195 };
 196 #endif // INCLUDE_JVMTI
 197 #endif // INCLUDE_SERVICES
 198 
 199 class VMDynamicLibrariesDCmd : public DCmd {
 200 public:
 201   VMDynamicLibrariesDCmd(outputStream* output, bool heap);
 202   static const char* name() {
 203     return "VM.dynlibs";
 204   }
 205   static const char* description() {
 206     return "Print loaded dynamic libraries.";
 207   }
 208   static const char* impact() {
 209     return "Low";
 210   }
 211   static const JavaPermission permission() {
 212     JavaPermission p = {"java.lang.management.ManagementPermission",
 213                         "monitor", nullptr};
 214     return p;
 215   }
 216   virtual void execute(DCmdSource source, TRAPS);
 217 };
 218 
 219 class VMUptimeDCmd : public DCmdWithParser {
 220 protected:
 221   DCmdArgument<bool> _date;
 222 public:
 223   static int num_arguments() { return 1; }
 224   VMUptimeDCmd(outputStream* output, bool heap);
 225   static const char* name() { return "VM.uptime"; }
 226   static const char* description() {
 227     return "Print VM uptime.";
 228   }
 229   static const char* impact() {
 230     return "Low";
 231   }
 232   virtual void execute(DCmdSource source, TRAPS);
 233 };
 234 
 235 class VMInfoDCmd : public DCmd {
 236 public:
 237   VMInfoDCmd(outputStream* output, bool heap) : DCmd(output, heap) { }
 238   static const char* name() { return "VM.info"; }
 239   static const char* description() {
 240     return "Print information about JVM environment and status.";
 241   }
 242   static const char* impact() { return "Low"; }
 243   static const JavaPermission permission() {
 244     JavaPermission p = {"java.lang.management.ManagementPermission",
 245                         "monitor", nullptr};
 246     return p;
 247   }
 248   virtual void execute(DCmdSource source, TRAPS);
 249 };
 250 
 251 class SystemGCDCmd : public DCmd {
 252 public:
 253   SystemGCDCmd(outputStream* output, bool heap) : DCmd(output, heap) { }
 254     static const char* name() { return "GC.run"; }
 255     static const char* description() {
 256       return "Call java.lang.System.gc().";
 257     }
 258     static const char* impact() {
 259       return "Medium: Depends on Java heap size and content.";
 260     }
 261     virtual void execute(DCmdSource source, TRAPS);
 262 };
 263 
 264 class RunFinalizationDCmd : public DCmd {
 265 public:
 266   RunFinalizationDCmd(outputStream* output, bool heap) : DCmd(output, heap) { }
 267     static const char* name() { return "GC.run_finalization"; }
 268     static const char* description() {
 269       return "Call java.lang.System.runFinalization().";
 270     }
 271     static const char* impact() {
 272       return "Medium: Depends on Java content.";
 273     }
 274     virtual void execute(DCmdSource source, TRAPS);
 275 };
 276 
 277 class HeapInfoDCmd : public DCmd {
 278 public:
 279   HeapInfoDCmd(outputStream* output, bool heap) : DCmd(output, heap) { }
 280   static const char* name() { return "GC.heap_info"; }
 281   static const char* description() {
 282     return "Provide generic Java heap information.";
 283   }
 284   static const char* impact() {
 285     return "Medium";
 286   }
 287   static const JavaPermission permission() {
 288     JavaPermission p = {"java.lang.management.ManagementPermission",
 289       "monitor", nullptr};
 290       return p;
 291   }
 292 
 293   virtual void execute(DCmdSource source, TRAPS);
 294 };
 295 
 296 class FinalizerInfoDCmd : public DCmd {
 297 public:
 298   FinalizerInfoDCmd(outputStream* output, bool heap) : DCmd(output, heap) { }
 299   static const char* name() { return "GC.finalizer_info"; }
 300   static const char* description() {
 301     return "Provide information about Java finalization queue.";
 302   }
 303   static const char* impact() {
 304     return "Medium";
 305   }
 306   static const JavaPermission permission() {
 307     JavaPermission p = {"java.lang.management.ManagementPermission",
 308       "monitor", nullptr};
 309       return p;
 310   }
 311 
 312   virtual void execute(DCmdSource source, TRAPS);
 313 };
 314 
 315 #if INCLUDE_SERVICES   // Heap dumping supported
 316 // See also: dump_heap in attachListener.cpp
 317 class HeapDumpDCmd : public DCmdWithParser {
 318 protected:
 319   DCmdArgument<char*> _filename;
 320   DCmdArgument<bool>  _all;
 321   DCmdArgument<jlong> _gzip;
 322   DCmdArgument<bool> _overwrite;
 323   DCmdArgument<jlong> _parallel;
 324 public:
 325   static int num_arguments() { return 5; }
 326   HeapDumpDCmd(outputStream* output, bool heap);
 327   static const char* name() {
 328     return "GC.heap_dump";
 329   }
 330   static const char* description() {
 331     return "Generate a HPROF format dump of the Java heap.";
 332   }
 333   static const char* impact() {
 334     return "High: Depends on Java heap size and content. "
 335            "Request a full GC unless the '-all' option is specified.";
 336   }
 337   static const JavaPermission permission() {
 338     JavaPermission p = {"java.lang.management.ManagementPermission",
 339                         "monitor", nullptr};
 340     return p;
 341   }
 342   virtual void execute(DCmdSource source, TRAPS);
 343 };
 344 #endif // INCLUDE_SERVICES
 345 
 346 // See also: inspectheap in attachListener.cpp
 347 class ClassHistogramDCmd : public DCmdWithParser {
 348 protected:
 349   DCmdArgument<bool> _all;
 350   DCmdArgument<jlong> _parallel_thread_num;
 351 public:
 352   static int num_arguments() { return 2; }
 353   ClassHistogramDCmd(outputStream* output, bool heap);
 354   static const char* name() {
 355     return "GC.class_histogram";
 356   }
 357   static const char* description() {
 358     return "Provide statistics about the Java heap usage.";
 359   }
 360   static const char* impact() {
 361     return "High: Depends on Java heap size and content.";
 362   }
 363   static const JavaPermission permission() {
 364     JavaPermission p = {"java.lang.management.ManagementPermission",
 365                         "monitor", nullptr};
 366     return p;
 367   }
 368   virtual void execute(DCmdSource source, TRAPS);
 369 };
 370 
 371 class ClassHierarchyDCmd : public DCmdWithParser {
 372 protected:
 373   DCmdArgument<bool> _print_interfaces; // true if inherited interfaces should be printed.
 374   DCmdArgument<bool> _print_subclasses; // true if subclasses of the specified classname should be printed.
 375   DCmdArgument<char*> _classname; // Optional single class name whose hierarchy should be printed.
 376 public:
 377   static int num_arguments() { return 3; }
 378   ClassHierarchyDCmd(outputStream* output, bool heap);
 379   static const char* name() {
 380     return "VM.class_hierarchy";
 381   }
 382   static const char* description() {
 383     return "Print a list of all loaded classes, indented to show the class hierarchy. "
 384            "The name of each class is followed by the ClassLoaderData* of its ClassLoader, "
 385            "or \"null\" if loaded by the bootstrap class loader.";
 386   }
 387   static const char* impact() {
 388       return "Medium: Depends on number of loaded classes.";
 389   }
 390   static const JavaPermission permission() {
 391     JavaPermission p = {"java.lang.management.ManagementPermission",
 392                         "monitor", nullptr};
 393     return p;
 394   }
 395   virtual void execute(DCmdSource source, TRAPS);
 396 };
 397 
 398 class PrintClassLayoutDCmd : public DCmdWithParser {
 399 protected:
 400   DCmdArgument<char*> _classname; // lass name whose layout should be printed.
 401 public:
 402   PrintClassLayoutDCmd(outputStream* output, bool heap);
 403   static const char* name() {
 404     return "VM.class_print_layout";
 405   }
 406   static const char* description() {
 407     return "Print the layout of an instance of a class, including flat fields. "
 408            "The name of each class is followed by the ClassLoaderData* of its ClassLoader, "
 409            "or \"null\" if loaded by the bootstrap class loader.";
 410   }
 411   static const char* impact() {
 412       return "Medium: Depends on number of loaded classes.";
 413   }
 414   static const JavaPermission permission() {
 415     JavaPermission p = {"java.lang.management.ManagementPermission",
 416                         "monitor", nullptr};
 417     return p;
 418   }
 419   static int num_arguments();
 420   virtual void execute(DCmdSource source, TRAPS);
 421 };
 422 
 423 #if INCLUDE_CDS
 424 class DumpSharedArchiveDCmd: public DCmdWithParser {
 425 protected:
 426   DCmdArgument<char*> _suboption;   // option of VM.cds
 427   DCmdArgument<char*> _filename;    // file name, optional
 428 public:
 429   static int num_arguments() { return 2; }
 430   DumpSharedArchiveDCmd(outputStream* output, bool heap);
 431   static const char* name() {
 432     return "VM.cds";
 433   }
 434   static const char* description() {
 435     return "Dump a static or dynamic shared archive including all shareable classes";
 436   }
 437   static const char* impact() {
 438     return "Medium: Pause time depends on number of loaded classes";
 439   }
 440   static const JavaPermission permission() {
 441     JavaPermission p = {"java.lang.management.ManagementPermission",
 442                         "monitor", nullptr};
 443     return p;
 444   }
 445   virtual void execute(DCmdSource source, TRAPS);
 446 };
 447 #endif // INCLUDE_CDS
 448 
 449 // See also: thread_dump in attachListener.cpp
 450 class ThreadDumpDCmd : public DCmdWithParser {
 451 protected:
 452   DCmdArgument<bool> _locks;
 453   DCmdArgument<bool> _extended;
 454 public:
 455   static int num_arguments() { return 2; }
 456   ThreadDumpDCmd(outputStream* output, bool heap);
 457   static const char* name() { return "Thread.print"; }
 458   static const char* description() {
 459     return "Print all threads with stacktraces.";
 460   }
 461   static const char* impact() {
 462     return "Medium: Depends on the number of threads.";
 463   }
 464   static const JavaPermission permission() {
 465     JavaPermission p = {"java.lang.management.ManagementPermission",
 466                         "monitor", nullptr};
 467     return p;
 468   }
 469   virtual void execute(DCmdSource source, TRAPS);
 470 };
 471 
 472 // Enhanced JMX Agent support
 473 
 474 class JMXStartRemoteDCmd : public DCmdWithParser {
 475 
 476   // Explicitly list all properties that could be
 477   // passed to Agent.startRemoteManagementAgent()
 478   // com.sun.management is omitted
 479 
 480   DCmdArgument<char *> _config_file;
 481   DCmdArgument<char *> _jmxremote_host;
 482   DCmdArgument<char *> _jmxremote_port;
 483   DCmdArgument<char *> _jmxremote_rmi_port;
 484   DCmdArgument<char *> _jmxremote_ssl;
 485   DCmdArgument<char *> _jmxremote_registry_ssl;
 486   DCmdArgument<char *> _jmxremote_authenticate;
 487   DCmdArgument<char *> _jmxremote_password_file;
 488   DCmdArgument<char *> _jmxremote_access_file;
 489   DCmdArgument<char *> _jmxremote_login_config;
 490   DCmdArgument<char *> _jmxremote_ssl_enabled_cipher_suites;
 491   DCmdArgument<char *> _jmxremote_ssl_enabled_protocols;
 492   DCmdArgument<char *> _jmxremote_ssl_need_client_auth;
 493   DCmdArgument<char *> _jmxremote_ssl_config_file;
 494 
 495   // JDP support
 496   // Keep autodiscovery char* not bool to pass true/false
 497   // as property value to java level.
 498   DCmdArgument<char *> _jmxremote_autodiscovery;
 499   DCmdArgument<jlong>  _jdp_port;
 500   DCmdArgument<char *> _jdp_address;
 501   DCmdArgument<char *> _jdp_source_addr;
 502   DCmdArgument<jlong>  _jdp_ttl;
 503   DCmdArgument<jlong>  _jdp_pause;
 504   DCmdArgument<char *> _jdp_name;
 505 
 506 public:
 507   static int num_arguments() { return 21; }
 508 
 509   JMXStartRemoteDCmd(outputStream *output, bool heap_allocated);
 510 
 511   static const char *name() {
 512     return "ManagementAgent.start";
 513   }
 514 
 515   static const char *description() {
 516     return "Start remote management agent.";
 517   }
 518 
 519   virtual void execute(DCmdSource source, TRAPS);
 520 };
 521 
 522 class JMXStartLocalDCmd : public DCmd {
 523 
 524   // Explicitly request start of local agent,
 525   // it will not be started by start dcmd
 526 
 527 
 528 public:
 529   JMXStartLocalDCmd(outputStream *output, bool heap_allocated);
 530 
 531   static const char *name() {
 532     return "ManagementAgent.start_local";
 533   }
 534 
 535   static const char *description() {
 536     return "Start local management agent.";
 537   }
 538 
 539   virtual void execute(DCmdSource source, TRAPS);
 540 
 541 };
 542 
 543 class JMXStopRemoteDCmd : public DCmd {
 544 public:
 545   JMXStopRemoteDCmd(outputStream *output, bool heap_allocated) :
 546   DCmd(output, heap_allocated) {
 547     // Do Nothing
 548   }
 549 
 550   static const char *name() {
 551     return "ManagementAgent.stop";
 552   }
 553 
 554   static const char *description() {
 555     return "Stop remote management agent.";
 556   }
 557 
 558   virtual void execute(DCmdSource source, TRAPS);
 559 };
 560 
 561 // Print the JMX system status
 562 class JMXStatusDCmd : public DCmd {
 563 public:
 564   JMXStatusDCmd(outputStream *output, bool heap_allocated);
 565 
 566   static const char *name() {
 567     return "ManagementAgent.status";
 568   }
 569 
 570   static const char *description() {
 571     return "Print the management agent status.";
 572   }
 573 
 574   static const JavaPermission permission() {
 575     JavaPermission p = {"java.lang.management.ManagementPermission",
 576                         "monitor", nullptr};
 577     return p;
 578   }
 579 
 580   virtual void execute(DCmdSource source, TRAPS);
 581 
 582 };
 583 
 584 class CompileQueueDCmd : public DCmd {
 585 public:
 586   CompileQueueDCmd(outputStream* output, bool heap) : DCmd(output, heap) {}
 587   static const char* name() {
 588     return "Compiler.queue";
 589   }
 590   static const char* description() {
 591     return "Print methods queued for compilation.";
 592   }
 593   static const char* impact() {
 594     return "Low";
 595   }
 596   static const JavaPermission permission() {
 597     JavaPermission p = {"java.lang.management.ManagementPermission",
 598                         "monitor", nullptr};
 599     return p;
 600   }
 601   virtual void execute(DCmdSource source, TRAPS);
 602 };
 603 
 604 #ifdef LINUX
 605 class PerfMapDCmd : public DCmdWithParser {
 606 protected:
 607   DCmdArgument<char*> _filename;
 608 public:
 609   static int num_arguments() { return 1; }
 610   PerfMapDCmd(outputStream* output, bool heap);
 611   static const char* name() {
 612     return "Compiler.perfmap";
 613   }
 614   static const char* description() {
 615     return "Write map file for Linux perf tool.";
 616   }
 617   static const char* impact() {
 618     return "Low";
 619   }
 620   static const JavaPermission permission() {
 621     JavaPermission p = {"java.lang.management.ManagementPermission",
 622                         "monitor", nullptr};
 623     return p;
 624   }
 625   virtual void execute(DCmdSource source, TRAPS);
 626 };
 627 #endif // LINUX
 628 
 629 class CodeListDCmd : public DCmd {
 630 public:
 631   CodeListDCmd(outputStream* output, bool heap) : DCmd(output, heap) {}
 632   static const char* name() {
 633     return "Compiler.codelist";
 634   }
 635   static const char* description() {
 636     return "Print all compiled methods in code cache that are alive";
 637   }
 638   static const char* impact() {
 639     return "Medium";
 640   }
 641   static const JavaPermission permission() {
 642     JavaPermission p = {"java.lang.management.ManagementPermission",
 643                         "monitor", nullptr};
 644     return p;
 645   }
 646   virtual void execute(DCmdSource source, TRAPS);
 647 };
 648 
 649 class CodeCacheDCmd : public DCmd {
 650 public:
 651   CodeCacheDCmd(outputStream* output, bool heap) : DCmd(output, heap) {}
 652   static const char* name() {
 653     return "Compiler.codecache";
 654   }
 655   static const char* description() {
 656     return "Print code cache layout and bounds.";
 657   }
 658   static const char* impact() {
 659     return "Low";
 660   }
 661   static const JavaPermission permission() {
 662     JavaPermission p = {"java.lang.management.ManagementPermission",
 663                         "monitor", nullptr};
 664     return p;
 665   }
 666   virtual void execute(DCmdSource source, TRAPS);
 667 };
 668 
 669 //---<  BEGIN  >--- CodeHeap State Analytics.
 670 class CodeHeapAnalyticsDCmd : public DCmdWithParser {
 671 protected:
 672   DCmdArgument<char*> _function;
 673   DCmdArgument<jlong> _granularity;
 674 public:
 675   static int num_arguments() { return 2; }
 676   CodeHeapAnalyticsDCmd(outputStream* output, bool heap);
 677   static const char* name() {
 678     return "Compiler.CodeHeap_Analytics";
 679   }
 680   static const char* description() {
 681     return "Print CodeHeap analytics";
 682   }
 683   static const char* impact() {
 684     return "Low: Depends on code heap size and content. "
 685            "Holds CodeCache_lock during analysis step, usually sub-second duration.";
 686   }
 687   static const JavaPermission permission() {
 688     JavaPermission p = {"java.lang.management.ManagementPermission",
 689                         "monitor", nullptr};
 690     return p;
 691   }
 692   virtual void execute(DCmdSource source, TRAPS);
 693 };
 694 //---<  END  >--- CodeHeap State Analytics.
 695 
 696 class CompilerDirectivesPrintDCmd : public DCmd {
 697 public:
 698   CompilerDirectivesPrintDCmd(outputStream* output, bool heap) : DCmd(output, heap) {}
 699   static const char* name() {
 700     return "Compiler.directives_print";
 701   }
 702   static const char* description() {
 703     return "Print all active compiler directives.";
 704   }
 705   static const char* impact() {
 706     return "Low";
 707   }
 708   static const JavaPermission permission() {
 709     JavaPermission p = {"java.lang.management.ManagementPermission",
 710                         "monitor", nullptr};
 711     return p;
 712   }
 713   virtual void execute(DCmdSource source, TRAPS);
 714 };
 715 
 716 class CompilerDirectivesRemoveDCmd : public DCmd {
 717 public:
 718   CompilerDirectivesRemoveDCmd(outputStream* output, bool heap) : DCmd(output, heap) {}
 719   static const char* name() {
 720     return "Compiler.directives_remove";
 721   }
 722   static const char* description() {
 723     return "Remove latest added compiler directive.";
 724   }
 725   static const char* impact() {
 726     return "Low";
 727   }
 728   static const JavaPermission permission() {
 729     JavaPermission p = {"java.lang.management.ManagementPermission",
 730                         "control", nullptr};
 731     return p;
 732   }
 733   virtual void execute(DCmdSource source, TRAPS);
 734 };
 735 
 736 class CompilerDirectivesAddDCmd : public DCmdWithParser {
 737 protected:
 738   DCmdArgument<char*> _filename;
 739 public:
 740   static int num_arguments() { return 1; }
 741   CompilerDirectivesAddDCmd(outputStream* output, bool heap);
 742   static const char* name() {
 743     return "Compiler.directives_add";
 744   }
 745   static const char* description() {
 746     return "Add compiler directives from file.";
 747   }
 748   static const char* impact() {
 749     return "Low";
 750   }
 751   static const JavaPermission permission() {
 752     JavaPermission p = {"java.lang.management.ManagementPermission",
 753                         "control", nullptr};
 754     return p;
 755   }
 756   virtual void execute(DCmdSource source, TRAPS);
 757 };
 758 
 759 class CompilerDirectivesClearDCmd : public DCmd {
 760 public:
 761   CompilerDirectivesClearDCmd(outputStream* output, bool heap) : DCmd(output, heap) {}
 762   static const char* name() {
 763     return "Compiler.directives_clear";
 764   }
 765   static const char* description() {
 766     return "Remove all compiler directives.";
 767   }
 768   static const char* impact() {
 769     return "Low";
 770   }
 771   static const JavaPermission permission() {
 772     JavaPermission p = {"java.lang.management.ManagementPermission",
 773                         "control", nullptr};
 774     return p;
 775   }
 776   virtual void execute(DCmdSource source, TRAPS);
 777 };
 778 
 779 ///////////////////////////////////////////////////////////////////////
 780 //
 781 // jcmd command support for symbol table, string table and system dictionary dumping:
 782 //   VM.symboltable -verbose: for dumping the symbol table
 783 //   VM.stringtable -verbose: for dumping the string table
 784 //   VM.systemdictionary -verbose: for dumping the system dictionary table
 785 //
 786 class VM_DumpHashtable : public VM_Operation {
 787 private:
 788   outputStream* _out;
 789   int _which;
 790   bool _verbose;
 791 public:
 792   enum {
 793     DumpSymbols = 1 << 0,
 794     DumpStrings = 1 << 1,
 795     DumpSysDict = 1 << 2  // not implemented yet
 796   };
 797   VM_DumpHashtable(outputStream* out, int which, bool verbose) {
 798     _out = out;
 799     _which = which;
 800     _verbose = verbose;
 801   }
 802 
 803   virtual VMOp_Type type() const { return VMOp_DumpHashtable; }
 804 
 805   virtual void doit() {
 806     switch (_which) {
 807     case DumpSymbols:
 808       SymbolTable::dump(_out, _verbose);
 809       break;
 810     case DumpStrings:
 811       StringTable::dump(_out, _verbose);
 812       break;
 813     case DumpSysDict:
 814       SystemDictionary::dump(_out, _verbose);
 815       break;
 816     default:
 817       ShouldNotReachHere();
 818     }
 819   }
 820 };
 821 
 822 class SymboltableDCmd : public DCmdWithParser {
 823 protected:
 824   DCmdArgument<bool> _verbose;
 825 public:
 826   static int num_arguments() { return 1; }
 827   SymboltableDCmd(outputStream* output, bool heap);
 828   static const char* name() {
 829     return "VM.symboltable";
 830   }
 831   static const char* description() {
 832     return "Dump symbol table.";
 833   }
 834   static const char* impact() {
 835     return "Medium: Depends on Java content.";
 836   }
 837   static const JavaPermission permission() {
 838     JavaPermission p = {"java.lang.management.ManagementPermission",
 839                         "monitor", nullptr};
 840     return p;
 841   }
 842   virtual void execute(DCmdSource source, TRAPS);
 843 };
 844 
 845 class StringtableDCmd : public DCmdWithParser {
 846 protected:
 847   DCmdArgument<bool> _verbose;
 848 public:
 849   static int num_arguments() { return 1; }
 850   StringtableDCmd(outputStream* output, bool heap);
 851   static const char* name() {
 852     return "VM.stringtable";
 853   }
 854   static const char* description() {
 855     return "Dump string table.";
 856   }
 857   static const char* impact() {
 858     return "Medium: Depends on Java content.";
 859   }
 860   static const JavaPermission permission() {
 861     JavaPermission p = {"java.lang.management.ManagementPermission",
 862                         "monitor", nullptr};
 863     return p;
 864   }
 865   virtual void execute(DCmdSource source, TRAPS);
 866 };
 867 
 868 class SystemDictionaryDCmd : public DCmdWithParser {
 869 protected:
 870   DCmdArgument<bool> _verbose;
 871 public:
 872   static int num_arguments() { return 1; }
 873   SystemDictionaryDCmd(outputStream* output, bool heap);
 874   static const char* name() {
 875     return "VM.systemdictionary";
 876   }
 877   static const char* description() {
 878     return "Prints the statistics for dictionary hashtable sizes and bucket length";
 879   }
 880   static const char* impact() {
 881       return "Medium: Depends on Java content.";
 882   }
 883   static const JavaPermission permission() {
 884     JavaPermission p = {"java.lang.management.ManagementPermission",
 885                         "monitor", nullptr};
 886     return p;
 887   }
 888   virtual void execute(DCmdSource source, TRAPS);
 889 };
 890 
 891 class ClassesDCmd : public DCmdWithParser {
 892 protected:
 893   DCmdArgument<bool> _verbose;
 894 public:
 895   static int num_arguments() { return 1; }
 896   ClassesDCmd(outputStream* output, bool heap);
 897   static const char* name() {
 898     return "VM.classes";
 899   }
 900   static const char* description() {
 901     return "Print all loaded classes";
 902   }
 903   static const char* impact() {
 904       return "Medium: Depends on number of loaded classes.";
 905   }
 906   static const JavaPermission permission() {
 907     JavaPermission p = {"java.lang.management.ManagementPermission",
 908                         "monitor", nullptr};
 909     return p;
 910   }
 911   virtual void execute(DCmdSource source, TRAPS);
 912 };
 913 
 914 class EventLogDCmd : public DCmdWithParser {
 915 protected:
 916   DCmdArgument<char*> _log;
 917   DCmdArgument<char*> _max;
 918 public:
 919   static int num_arguments() { return 2; }
 920   EventLogDCmd(outputStream* output, bool heap);
 921   static const char* name() {
 922     return "VM.events";
 923   }
 924   static const char* description() {
 925     return "Print VM event logs";
 926   }
 927   static const char* impact() {
 928     return "Low: Depends on event log size. ";
 929   }
 930   static const JavaPermission permission() {
 931     JavaPermission p = {"java.lang.management.ManagementPermission",
 932                         "monitor", nullptr};
 933     return p;
 934   }
 935   virtual void execute(DCmdSource source, TRAPS);
 936 };
 937 
 938 class ThreadDumpToFileDCmd : public DCmdWithParser {
 939 private:
 940   void dumpToFile(Symbol* name, Symbol* signature, const char* path, bool overwrite, TRAPS);
 941 protected:
 942   DCmdArgument<bool> _overwrite;
 943   DCmdArgument<char*> _format;
 944   DCmdArgument<char*> _filepath;
 945 public:
 946   static int num_arguments() { return 3; }
 947   ThreadDumpToFileDCmd(outputStream *output, bool heap);
 948   static const char *name() {
 949     return "Thread.dump_to_file";
 950   }
 951   static const char *description() {
 952     return "Dump threads, with stack traces, to a file in plain text or JSON format.";
 953   }
 954   static const char* impact() {
 955     return "Medium: Depends on the number of threads.";
 956   }
 957   static const JavaPermission permission() {
 958     JavaPermission p = {"java.lang.management.ManagementPermission", "monitor", nullptr};
 959     return p;
 960   }
 961   virtual void execute(DCmdSource source, TRAPS);
 962 };
 963 
 964 class CompilationMemoryStatisticDCmd: public DCmdWithParser {
 965 protected:
 966   DCmdArgument<bool> _human_readable;
 967   DCmdArgument<MemorySizeArgument> _minsize;
 968 public:
 969   static int num_arguments() { return 2; }
 970   CompilationMemoryStatisticDCmd(outputStream* output, bool heap);
 971   static const char* name() {
 972     return "Compiler.memory";
 973   }
 974   static const char* description() {
 975     return "Print compilation footprint";
 976   }
 977   static const char* impact() {
 978     return "Medium: Pause time depends on number of compiled methods";
 979   }
 980   static const JavaPermission permission() {
 981     JavaPermission p = {"java.lang.management.ManagementPermission",
 982                         "monitor", nullptr};
 983     return p;
 984   }
 985   virtual void execute(DCmdSource source, TRAPS);
 986 };
 987 
 988 #if defined(LINUX) || defined(_WIN64)
 989 
 990 class SystemMapDCmd : public DCmd {
 991 public:
 992   SystemMapDCmd(outputStream* output, bool heap);
 993   static const char* name() { return "System.map"; }
 994   static const char* description() {
 995     return "Prints an annotated process memory map of the VM process (linux and Windows only).";
 996   }
 997   static const char* impact() { return "Medium; can be high for very large java heaps."; }
 998   static const JavaPermission permission() {
 999     JavaPermission p = {"java.lang.management.ManagementPermission",
1000                         "control", nullptr};
1001     return p;
1002   }
1003   virtual void execute(DCmdSource source, TRAPS);
1004 };
1005 
1006 class SystemDumpMapDCmd : public DCmdWithParser {
1007   DCmdArgument<char*> _filename;
1008 public:
1009   static int num_arguments() { return 1; }
1010   SystemDumpMapDCmd(outputStream* output, bool heap);
1011   static const char* name() { return "System.dump_map"; }
1012   static const char* description() {
1013     return "Dumps an annotated process memory map to an output file (linux and Windows only).";
1014   }
1015   static const char* impact() { return "Medium; can be high for very large java heaps."; }
1016   static const JavaPermission permission() {
1017     JavaPermission p = {"java.lang.management.ManagementPermission",
1018                         "control", nullptr};
1019     return p;
1020   }
1021   virtual void execute(DCmdSource source, TRAPS);
1022 };
1023 
1024 #endif // LINUX or WINDOWS
1025 
1026 #endif // SHARE_SERVICES_DIAGNOSTICCOMMAND_HPP