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 #if INCLUDE_CDS
 399 class DumpSharedArchiveDCmd: public DCmdWithParser {
 400 protected:
 401   DCmdArgument<char*> _suboption;   // option of VM.cds
 402   DCmdArgument<char*> _filename;    // file name, optional
 403 public:
 404   static int num_arguments() { return 2; }
 405   DumpSharedArchiveDCmd(outputStream* output, bool heap);
 406   static const char* name() {
 407     return "VM.cds";
 408   }
 409   static const char* description() {
 410     return "Dump a static or dynamic shared archive including all shareable classes";
 411   }
 412   static const char* impact() {
 413     return "Medium: Pause time depends on number of loaded classes";
 414   }
 415   static const JavaPermission permission() {
 416     JavaPermission p = {"java.lang.management.ManagementPermission",
 417                         "monitor", nullptr};
 418     return p;
 419   }
 420   virtual void execute(DCmdSource source, TRAPS);
 421 };
 422 #endif // INCLUDE_CDS
 423 
 424 // See also: thread_dump in attachListener.cpp
 425 class ThreadDumpDCmd : public DCmdWithParser {
 426 protected:
 427   DCmdArgument<bool> _locks;
 428   DCmdArgument<bool> _extended;
 429 public:
 430   static int num_arguments() { return 2; }
 431   ThreadDumpDCmd(outputStream* output, bool heap);
 432   static const char* name() { return "Thread.print"; }
 433   static const char* description() {
 434     return "Print all threads with stacktraces.";
 435   }
 436   static const char* impact() {
 437     return "Medium: Depends on the number of threads.";
 438   }
 439   static const JavaPermission permission() {
 440     JavaPermission p = {"java.lang.management.ManagementPermission",
 441                         "monitor", nullptr};
 442     return p;
 443   }
 444   virtual void execute(DCmdSource source, TRAPS);
 445 };
 446 
 447 // Enhanced JMX Agent support
 448 
 449 class JMXStartRemoteDCmd : public DCmdWithParser {
 450 
 451   // Explicitly list all properties that could be
 452   // passed to Agent.startRemoteManagementAgent()
 453   // com.sun.management is omitted
 454 
 455   DCmdArgument<char *> _config_file;
 456   DCmdArgument<char *> _jmxremote_host;
 457   DCmdArgument<char *> _jmxremote_port;
 458   DCmdArgument<char *> _jmxremote_rmi_port;
 459   DCmdArgument<char *> _jmxremote_ssl;
 460   DCmdArgument<char *> _jmxremote_registry_ssl;
 461   DCmdArgument<char *> _jmxremote_authenticate;
 462   DCmdArgument<char *> _jmxremote_password_file;
 463   DCmdArgument<char *> _jmxremote_access_file;
 464   DCmdArgument<char *> _jmxremote_login_config;
 465   DCmdArgument<char *> _jmxremote_ssl_enabled_cipher_suites;
 466   DCmdArgument<char *> _jmxremote_ssl_enabled_protocols;
 467   DCmdArgument<char *> _jmxremote_ssl_need_client_auth;
 468   DCmdArgument<char *> _jmxremote_ssl_config_file;
 469 
 470   // JDP support
 471   // Keep autodiscovery char* not bool to pass true/false
 472   // as property value to java level.
 473   DCmdArgument<char *> _jmxremote_autodiscovery;
 474   DCmdArgument<jlong>  _jdp_port;
 475   DCmdArgument<char *> _jdp_address;
 476   DCmdArgument<char *> _jdp_source_addr;
 477   DCmdArgument<jlong>  _jdp_ttl;
 478   DCmdArgument<jlong>  _jdp_pause;
 479   DCmdArgument<char *> _jdp_name;
 480 
 481 public:
 482   static int num_arguments() { return 21; }
 483 
 484   JMXStartRemoteDCmd(outputStream *output, bool heap_allocated);
 485 
 486   static const char *name() {
 487     return "ManagementAgent.start";
 488   }
 489 
 490   static const char *description() {
 491     return "Start remote management agent.";
 492   }
 493 
 494   virtual void execute(DCmdSource source, TRAPS);
 495 };
 496 
 497 class JMXStartLocalDCmd : public DCmd {
 498 
 499   // Explicitly request start of local agent,
 500   // it will not be started by start dcmd
 501 
 502 
 503 public:
 504   JMXStartLocalDCmd(outputStream *output, bool heap_allocated);
 505 
 506   static const char *name() {
 507     return "ManagementAgent.start_local";
 508   }
 509 
 510   static const char *description() {
 511     return "Start local management agent.";
 512   }
 513 
 514   virtual void execute(DCmdSource source, TRAPS);
 515 
 516 };
 517 
 518 class JMXStopRemoteDCmd : public DCmd {
 519 public:
 520   JMXStopRemoteDCmd(outputStream *output, bool heap_allocated) :
 521   DCmd(output, heap_allocated) {
 522     // Do Nothing
 523   }
 524 
 525   static const char *name() {
 526     return "ManagementAgent.stop";
 527   }
 528 
 529   static const char *description() {
 530     return "Stop remote management agent.";
 531   }
 532 
 533   virtual void execute(DCmdSource source, TRAPS);
 534 };
 535 
 536 // Print the JMX system status
 537 class JMXStatusDCmd : public DCmd {
 538 public:
 539   JMXStatusDCmd(outputStream *output, bool heap_allocated);
 540 
 541   static const char *name() {
 542     return "ManagementAgent.status";
 543   }
 544 
 545   static const char *description() {
 546     return "Print the management agent status.";
 547   }
 548 
 549   static const JavaPermission permission() {
 550     JavaPermission p = {"java.lang.management.ManagementPermission",
 551                         "monitor", nullptr};
 552     return p;
 553   }
 554 
 555   virtual void execute(DCmdSource source, TRAPS);
 556 
 557 };
 558 
 559 class CompileQueueDCmd : public DCmd {
 560 public:
 561   CompileQueueDCmd(outputStream* output, bool heap) : DCmd(output, heap) {}
 562   static const char* name() {
 563     return "Compiler.queue";
 564   }
 565   static const char* description() {
 566     return "Print methods queued for compilation.";
 567   }
 568   static const char* impact() {
 569     return "Low";
 570   }
 571   static const JavaPermission permission() {
 572     JavaPermission p = {"java.lang.management.ManagementPermission",
 573                         "monitor", nullptr};
 574     return p;
 575   }
 576   virtual void execute(DCmdSource source, TRAPS);
 577 };
 578 
 579 #ifdef LINUX
 580 class PerfMapDCmd : public DCmdWithParser {
 581 protected:
 582   DCmdArgument<char*> _filename;
 583 public:
 584   static int num_arguments() { return 1; }
 585   PerfMapDCmd(outputStream* output, bool heap);
 586   static const char* name() {
 587     return "Compiler.perfmap";
 588   }
 589   static const char* description() {
 590     return "Write map file for Linux perf tool.";
 591   }
 592   static const char* impact() {
 593     return "Low";
 594   }
 595   static const JavaPermission permission() {
 596     JavaPermission p = {"java.lang.management.ManagementPermission",
 597                         "monitor", nullptr};
 598     return p;
 599   }
 600   virtual void execute(DCmdSource source, TRAPS);
 601 };
 602 #endif // LINUX
 603 
 604 class CodeListDCmd : public DCmd {
 605 public:
 606   CodeListDCmd(outputStream* output, bool heap) : DCmd(output, heap) {}
 607   static const char* name() {
 608     return "Compiler.codelist";
 609   }
 610   static const char* description() {
 611     return "Print all compiled methods in code cache that are alive";
 612   }
 613   static const char* impact() {
 614     return "Medium";
 615   }
 616   static const JavaPermission permission() {
 617     JavaPermission p = {"java.lang.management.ManagementPermission",
 618                         "monitor", nullptr};
 619     return p;
 620   }
 621   virtual void execute(DCmdSource source, TRAPS);
 622 };
 623 
 624 class CodeCacheDCmd : public DCmd {
 625 public:
 626   CodeCacheDCmd(outputStream* output, bool heap) : DCmd(output, heap) {}
 627   static const char* name() {
 628     return "Compiler.codecache";
 629   }
 630   static const char* description() {
 631     return "Print code cache layout and bounds.";
 632   }
 633   static const char* impact() {
 634     return "Low";
 635   }
 636   static const JavaPermission permission() {
 637     JavaPermission p = {"java.lang.management.ManagementPermission",
 638                         "monitor", nullptr};
 639     return p;
 640   }
 641   virtual void execute(DCmdSource source, TRAPS);
 642 };
 643 
 644 //---<  BEGIN  >--- CodeHeap State Analytics.
 645 class CodeHeapAnalyticsDCmd : public DCmdWithParser {
 646 protected:
 647   DCmdArgument<char*> _function;
 648   DCmdArgument<jlong> _granularity;
 649 public:
 650   static int num_arguments() { return 2; }
 651   CodeHeapAnalyticsDCmd(outputStream* output, bool heap);
 652   static const char* name() {
 653     return "Compiler.CodeHeap_Analytics";
 654   }
 655   static const char* description() {
 656     return "Print CodeHeap analytics";
 657   }
 658   static const char* impact() {
 659     return "Low: Depends on code heap size and content. "
 660            "Holds CodeCache_lock during analysis step, usually sub-second duration.";
 661   }
 662   static const JavaPermission permission() {
 663     JavaPermission p = {"java.lang.management.ManagementPermission",
 664                         "monitor", nullptr};
 665     return p;
 666   }
 667   virtual void execute(DCmdSource source, TRAPS);
 668 };
 669 //---<  END  >--- CodeHeap State Analytics.
 670 
 671 class CompilerDirectivesPrintDCmd : public DCmd {
 672 public:
 673   CompilerDirectivesPrintDCmd(outputStream* output, bool heap) : DCmd(output, heap) {}
 674   static const char* name() {
 675     return "Compiler.directives_print";
 676   }
 677   static const char* description() {
 678     return "Print all active compiler directives.";
 679   }
 680   static const char* impact() {
 681     return "Low";
 682   }
 683   static const JavaPermission permission() {
 684     JavaPermission p = {"java.lang.management.ManagementPermission",
 685                         "monitor", nullptr};
 686     return p;
 687   }
 688   virtual void execute(DCmdSource source, TRAPS);
 689 };
 690 
 691 class CompilerDirectivesRemoveDCmd : public DCmd {
 692 public:
 693   CompilerDirectivesRemoveDCmd(outputStream* output, bool heap) : DCmd(output, heap) {}
 694   static const char* name() {
 695     return "Compiler.directives_remove";
 696   }
 697   static const char* description() {
 698     return "Remove latest added compiler directive.";
 699   }
 700   static const char* impact() {
 701     return "Low";
 702   }
 703   static const JavaPermission permission() {
 704     JavaPermission p = {"java.lang.management.ManagementPermission",
 705                         "control", nullptr};
 706     return p;
 707   }
 708   virtual void execute(DCmdSource source, TRAPS);
 709 };
 710 
 711 class CompilerDirectivesAddDCmd : public DCmdWithParser {
 712 protected:
 713   DCmdArgument<char*> _filename;
 714 public:
 715   static int num_arguments() { return 1; }
 716   CompilerDirectivesAddDCmd(outputStream* output, bool heap);
 717   static const char* name() {
 718     return "Compiler.directives_add";
 719   }
 720   static const char* description() {
 721     return "Add compiler directives from file.";
 722   }
 723   static const char* impact() {
 724     return "Low";
 725   }
 726   static const JavaPermission permission() {
 727     JavaPermission p = {"java.lang.management.ManagementPermission",
 728                         "control", nullptr};
 729     return p;
 730   }
 731   virtual void execute(DCmdSource source, TRAPS);
 732 };
 733 
 734 class CompilerDirectivesClearDCmd : public DCmd {
 735 public:
 736   CompilerDirectivesClearDCmd(outputStream* output, bool heap) : DCmd(output, heap) {}
 737   static const char* name() {
 738     return "Compiler.directives_clear";
 739   }
 740   static const char* description() {
 741     return "Remove all compiler directives.";
 742   }
 743   static const char* impact() {
 744     return "Low";
 745   }
 746   static const JavaPermission permission() {
 747     JavaPermission p = {"java.lang.management.ManagementPermission",
 748                         "control", nullptr};
 749     return p;
 750   }
 751   virtual void execute(DCmdSource source, TRAPS);
 752 };
 753 
 754 ///////////////////////////////////////////////////////////////////////
 755 //
 756 // jcmd command support for symbol table, string table and system dictionary dumping:
 757 //   VM.symboltable -verbose: for dumping the symbol table
 758 //   VM.stringtable -verbose: for dumping the string table
 759 //   VM.systemdictionary -verbose: for dumping the system dictionary table
 760 //
 761 class VM_DumpHashtable : public VM_Operation {
 762 private:
 763   outputStream* _out;
 764   int _which;
 765   bool _verbose;
 766 public:
 767   enum {
 768     DumpSymbols = 1 << 0,
 769     DumpStrings = 1 << 1,
 770     DumpSysDict = 1 << 2  // not implemented yet
 771   };
 772   VM_DumpHashtable(outputStream* out, int which, bool verbose) {
 773     _out = out;
 774     _which = which;
 775     _verbose = verbose;
 776   }
 777 
 778   virtual VMOp_Type type() const { return VMOp_DumpHashtable; }
 779 
 780   virtual void doit() {
 781     switch (_which) {
 782     case DumpSymbols:
 783       SymbolTable::dump(_out, _verbose);
 784       break;
 785     case DumpStrings:
 786       StringTable::dump(_out, _verbose);
 787       break;
 788     case DumpSysDict:
 789       SystemDictionary::dump(_out, _verbose);
 790       break;
 791     default:
 792       ShouldNotReachHere();
 793     }
 794   }
 795 };
 796 
 797 class SymboltableDCmd : public DCmdWithParser {
 798 protected:
 799   DCmdArgument<bool> _verbose;
 800 public:
 801   static int num_arguments() { return 1; }
 802   SymboltableDCmd(outputStream* output, bool heap);
 803   static const char* name() {
 804     return "VM.symboltable";
 805   }
 806   static const char* description() {
 807     return "Dump symbol table.";
 808   }
 809   static const char* impact() {
 810     return "Medium: Depends on Java content.";
 811   }
 812   static const JavaPermission permission() {
 813     JavaPermission p = {"java.lang.management.ManagementPermission",
 814                         "monitor", nullptr};
 815     return p;
 816   }
 817   virtual void execute(DCmdSource source, TRAPS);
 818 };
 819 
 820 class StringtableDCmd : public DCmdWithParser {
 821 protected:
 822   DCmdArgument<bool> _verbose;
 823 public:
 824   static int num_arguments() { return 1; }
 825   StringtableDCmd(outputStream* output, bool heap);
 826   static const char* name() {
 827     return "VM.stringtable";
 828   }
 829   static const char* description() {
 830     return "Dump string table.";
 831   }
 832   static const char* impact() {
 833     return "Medium: Depends on Java content.";
 834   }
 835   static const JavaPermission permission() {
 836     JavaPermission p = {"java.lang.management.ManagementPermission",
 837                         "monitor", nullptr};
 838     return p;
 839   }
 840   virtual void execute(DCmdSource source, TRAPS);
 841 };
 842 
 843 class SystemDictionaryDCmd : public DCmdWithParser {
 844 protected:
 845   DCmdArgument<bool> _verbose;
 846 public:
 847   static int num_arguments() { return 1; }
 848   SystemDictionaryDCmd(outputStream* output, bool heap);
 849   static const char* name() {
 850     return "VM.systemdictionary";
 851   }
 852   static const char* description() {
 853     return "Prints the statistics for dictionary hashtable sizes and bucket length";
 854   }
 855   static const char* impact() {
 856       return "Medium: Depends on Java content.";
 857   }
 858   static const JavaPermission permission() {
 859     JavaPermission p = {"java.lang.management.ManagementPermission",
 860                         "monitor", nullptr};
 861     return p;
 862   }
 863   virtual void execute(DCmdSource source, TRAPS);
 864 };
 865 
 866 class ClassesDCmd : public DCmdWithParser {
 867 protected:
 868   DCmdArgument<bool> _verbose;
 869 public:
 870   static int num_arguments() { return 1; }
 871   ClassesDCmd(outputStream* output, bool heap);
 872   static const char* name() {
 873     return "VM.classes";
 874   }
 875   static const char* description() {
 876     return "Print all loaded classes";
 877   }
 878   static const char* impact() {
 879       return "Medium: Depends on number of loaded classes.";
 880   }
 881   static const JavaPermission permission() {
 882     JavaPermission p = {"java.lang.management.ManagementPermission",
 883                         "monitor", nullptr};
 884     return p;
 885   }
 886   virtual void execute(DCmdSource source, TRAPS);
 887 };
 888 
 889 class EventLogDCmd : public DCmdWithParser {
 890 protected:
 891   DCmdArgument<char*> _log;
 892   DCmdArgument<char*> _max;
 893 public:
 894   static int num_arguments() { return 2; }
 895   EventLogDCmd(outputStream* output, bool heap);
 896   static const char* name() {
 897     return "VM.events";
 898   }
 899   static const char* description() {
 900     return "Print VM event logs";
 901   }
 902   static const char* impact() {
 903     return "Low: Depends on event log size. ";
 904   }
 905   static const JavaPermission permission() {
 906     JavaPermission p = {"java.lang.management.ManagementPermission",
 907                         "monitor", nullptr};
 908     return p;
 909   }
 910   virtual void execute(DCmdSource source, TRAPS);
 911 };
 912 
 913 class ThreadDumpToFileDCmd : public DCmdWithParser {
 914 private:
 915   void dumpToFile(Symbol* name, Symbol* signature, const char* path, bool overwrite, TRAPS);
 916 protected:
 917   DCmdArgument<bool> _overwrite;
 918   DCmdArgument<char*> _format;
 919   DCmdArgument<char*> _filepath;
 920 public:
 921   static int num_arguments() { return 3; }
 922   ThreadDumpToFileDCmd(outputStream *output, bool heap);
 923   static const char *name() {
 924     return "Thread.dump_to_file";
 925   }
 926   static const char *description() {
 927     return "Dump threads, with stack traces, to a file in plain text or JSON format.";
 928   }
 929   static const char* impact() {
 930     return "Medium: Depends on the number of threads.";
 931   }
 932   static const JavaPermission permission() {
 933     JavaPermission p = {"java.lang.management.ManagementPermission", "monitor", nullptr};
 934     return p;
 935   }
 936   virtual void execute(DCmdSource source, TRAPS);
 937 };
 938 
 939 class CompilationMemoryStatisticDCmd: public DCmdWithParser {
 940 protected:
 941   DCmdArgument<bool> _human_readable;
 942   DCmdArgument<MemorySizeArgument> _minsize;
 943 public:
 944   static int num_arguments() { return 2; }
 945   CompilationMemoryStatisticDCmd(outputStream* output, bool heap);
 946   static const char* name() {
 947     return "Compiler.memory";
 948   }
 949   static const char* description() {
 950     return "Print compilation footprint";
 951   }
 952   static const char* impact() {
 953     return "Medium: Pause time depends on number of compiled methods";
 954   }
 955   static const JavaPermission permission() {
 956     JavaPermission p = {"java.lang.management.ManagementPermission",
 957                         "monitor", nullptr};
 958     return p;
 959   }
 960   virtual void execute(DCmdSource source, TRAPS);
 961 };
 962 
 963 #if defined(LINUX) || defined(_WIN64)
 964 
 965 class SystemMapDCmd : public DCmd {
 966 public:
 967   SystemMapDCmd(outputStream* output, bool heap);
 968   static const char* name() { return "System.map"; }
 969   static const char* description() {
 970     return "Prints an annotated process memory map of the VM process (linux and Windows only).";
 971   }
 972   static const char* impact() { return "Medium; can be high for very large java heaps."; }
 973   static const JavaPermission permission() {
 974     JavaPermission p = {"java.lang.management.ManagementPermission",
 975                         "control", nullptr};
 976     return p;
 977   }
 978   virtual void execute(DCmdSource source, TRAPS);
 979 };
 980 
 981 class SystemDumpMapDCmd : public DCmdWithParser {
 982   DCmdArgument<char*> _filename;
 983 public:
 984   static int num_arguments() { return 1; }
 985   SystemDumpMapDCmd(outputStream* output, bool heap);
 986   static const char* name() { return "System.dump_map"; }
 987   static const char* description() {
 988     return "Dumps an annotated process memory map to an output file (linux and Windows only).";
 989   }
 990   static const char* impact() { return "Medium; can be high for very large java heaps."; }
 991   static const JavaPermission permission() {
 992     JavaPermission p = {"java.lang.management.ManagementPermission",
 993                         "control", nullptr};
 994     return p;
 995   }
 996   virtual void execute(DCmdSource source, TRAPS);
 997 };
 998 
 999 #endif // LINUX or WINDOWS
1000 
1001 #endif // SHARE_SERVICES_DIAGNOSTICCOMMAND_HPP