1 /*
   2  * Copyright (c) 2011, 2020, 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   HelpDCmd(outputStream* output, bool heap);
  48   static const char* name() { return "help"; }
  49   static const char* description() {
  50     return "For more information about a specific command use 'help <command>'. "
  51            "With no argument this will show a list of available commands. "
  52            "'help all' will show help for all commands.";
  53   }
  54   static const char* impact() { return "Low"; }
  55   static int num_arguments();
  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   static int num_arguments() { return 0; }
  73   virtual void execute(DCmdSource source, TRAPS);
  74 };
  75 
  76 class CommandLineDCmd : public DCmd {
  77 public:
  78   CommandLineDCmd(outputStream* output, bool heap) : DCmd(output, heap) { }
  79   static const char* name() { return "VM.command_line"; }
  80   static const char* description() {
  81     return "Print the command line used to start this VM instance.";
  82   }
  83   static const char* impact() { return "Low"; }
  84   static const JavaPermission permission() {
  85     JavaPermission p = {"java.lang.management.ManagementPermission",
  86                         "monitor", NULL};
  87     return p;
  88   }
  89   static int num_arguments() { return 0; }
  90   virtual void execute(DCmdSource source, TRAPS) {
  91     Arguments::print_on(_output);
  92   }
  93 };
  94 
  95 // See also: get_system_properties in attachListener.cpp
  96 class PrintSystemPropertiesDCmd : public DCmd {
  97 public:
  98   PrintSystemPropertiesDCmd(outputStream* output, bool heap) : DCmd(output, heap) { }
  99     static const char* name() { return "VM.system_properties"; }
 100     static const char* description() {
 101       return "Print system properties.";
 102     }
 103     static const char* impact() {
 104       return "Low";
 105     }
 106     static const JavaPermission permission() {
 107       JavaPermission p = {"java.util.PropertyPermission",
 108                           "*", "read"};
 109       return p;
 110     }
 111     static int num_arguments() { return 0; }
 112     virtual void execute(DCmdSource source, TRAPS);
 113 };
 114 
 115 // See also: print_flag in attachListener.cpp
 116 class PrintVMFlagsDCmd : public DCmdWithParser {
 117 protected:
 118   DCmdArgument<bool> _all;
 119 public:
 120   PrintVMFlagsDCmd(outputStream* output, bool heap);
 121   static const char* name() { return "VM.flags"; }
 122   static const char* description() {
 123     return "Print VM flag options and their current values.";
 124   }
 125   static const char* impact() {
 126     return "Low";
 127   }
 128   static const JavaPermission permission() {
 129     JavaPermission p = {"java.lang.management.ManagementPermission",
 130                         "monitor", NULL};
 131     return p;
 132   }
 133   static int num_arguments();
 134   virtual void execute(DCmdSource source, TRAPS);
 135 };
 136 
 137 class SetVMFlagDCmd : public DCmdWithParser {
 138 protected:
 139   DCmdArgument<char*> _flag;
 140   DCmdArgument<char*> _value;
 141 
 142 public:
 143   SetVMFlagDCmd(outputStream* output, bool heap);
 144   static const char* name() { return "VM.set_flag"; }
 145   static const char* description() {
 146     return "Sets VM flag option using the provided value.";
 147   }
 148   static const char* impact() {
 149     return "Low";
 150   }
 151   static const JavaPermission permission() {
 152     JavaPermission p = {"java.lang.management.ManagementPermission",
 153                         "control", NULL};
 154     return p;
 155   }
 156   static int num_arguments();
 157   virtual void execute(DCmdSource source, TRAPS);
 158 };
 159 
 160 class JVMTIDataDumpDCmd : public DCmd {
 161 public:
 162   JVMTIDataDumpDCmd(outputStream* output, bool heap) : DCmd(output, heap) { }
 163   static const char* name() { return "JVMTI.data_dump"; }
 164   static const char* description() {
 165     return "Signal the JVM to do a data-dump request for JVMTI.";
 166   }
 167   static const char* impact() {
 168     return "High";
 169   }
 170   static const JavaPermission permission() {
 171     JavaPermission p = {"java.lang.management.ManagementPermission",
 172                         "monitor", NULL};
 173     return p;
 174   }
 175   static int num_arguments() { return 0; }
 176   virtual void execute(DCmdSource source, TRAPS);
 177 };
 178 
 179 #if INCLUDE_SERVICES
 180 #if INCLUDE_JVMTI
 181 class JVMTIAgentLoadDCmd : public DCmdWithParser {
 182 protected:
 183   DCmdArgument<char*> _libpath;
 184   DCmdArgument<char*> _option;
 185 public:
 186   JVMTIAgentLoadDCmd(outputStream* output, bool heap);
 187   static const char* name() { return "JVMTI.agent_load"; }
 188   static const char* description() {
 189     return "Load JVMTI native agent.";
 190   }
 191   static const char* impact() { return "Low"; }
 192   static const JavaPermission permission() {
 193     JavaPermission p = {"java.lang.management.ManagementPermission",
 194                         "control", NULL};
 195     return p;
 196   }
 197   static int num_arguments();
 198   virtual void execute(DCmdSource source, TRAPS);
 199 };
 200 #endif // INCLUDE_JVMTI
 201 #endif // INCLUDE_SERVICES
 202 
 203 class VMDynamicLibrariesDCmd : public DCmd {
 204 public:
 205   VMDynamicLibrariesDCmd(outputStream* output, bool heap);
 206   static const char* name() {
 207     return "VM.dynlibs";
 208   }
 209   static const char* description() {
 210     return "Print loaded dynamic libraries.";
 211   }
 212   static const char* impact() {
 213     return "Low";
 214   }
 215   static const JavaPermission permission() {
 216     JavaPermission p = {"java.lang.management.ManagementPermission",
 217                         "monitor", NULL};
 218     return p;
 219   }
 220   static int num_arguments() {
 221     return 0;
 222   };
 223   virtual void execute(DCmdSource source, TRAPS);
 224 };
 225 
 226 class VMUptimeDCmd : public DCmdWithParser {
 227 protected:
 228   DCmdArgument<bool> _date;
 229 public:
 230   VMUptimeDCmd(outputStream* output, bool heap);
 231   static const char* name() { return "VM.uptime"; }
 232   static const char* description() {
 233     return "Print VM uptime.";
 234   }
 235   static const char* impact() {
 236     return "Low";
 237   }
 238   static int num_arguments();
 239   virtual void execute(DCmdSource source, TRAPS);
 240 };
 241 
 242 class VMInfoDCmd : public DCmd {
 243 public:
 244   VMInfoDCmd(outputStream* output, bool heap) : DCmd(output, heap) { }
 245   static const char* name() { return "VM.info"; }
 246   static const char* description() {
 247     return "Print information about JVM environment and status.";
 248   }
 249   static const char* impact() { return "Low"; }
 250   static const JavaPermission permission() {
 251     JavaPermission p = {"java.lang.management.ManagementPermission",
 252                         "monitor", NULL};
 253     return p;
 254   }
 255   static int num_arguments() { return 0; }
 256   virtual void execute(DCmdSource source, TRAPS);
 257 };
 258 
 259 class SystemGCDCmd : public DCmd {
 260 public:
 261   SystemGCDCmd(outputStream* output, bool heap) : DCmd(output, heap) { }
 262     static const char* name() { return "GC.run"; }
 263     static const char* description() {
 264       return "Call java.lang.System.gc().";
 265     }
 266     static const char* impact() {
 267       return "Medium: Depends on Java heap size and content.";
 268     }
 269     static int num_arguments() { return 0; }
 270     virtual void execute(DCmdSource source, TRAPS);
 271 };
 272 
 273 class RunFinalizationDCmd : public DCmd {
 274 public:
 275   RunFinalizationDCmd(outputStream* output, bool heap) : DCmd(output, heap) { }
 276     static const char* name() { return "GC.run_finalization"; }
 277     static const char* description() {
 278       return "Call java.lang.System.runFinalization().";
 279     }
 280     static const char* impact() {
 281       return "Medium: Depends on Java content.";
 282     }
 283     static int num_arguments() { return 0; }
 284     virtual void execute(DCmdSource source, TRAPS);
 285 };
 286 
 287 class HeapInfoDCmd : public DCmd {
 288 public:
 289   HeapInfoDCmd(outputStream* output, bool heap) : DCmd(output, heap) { }
 290   static const char* name() { return "GC.heap_info"; }
 291   static const char* description() {
 292     return "Provide generic Java heap information.";
 293   }
 294   static const char* impact() {
 295     return "Medium";
 296   }
 297   static int num_arguments() { return 0; }
 298   static const JavaPermission permission() {
 299     JavaPermission p = {"java.lang.management.ManagementPermission",
 300       "monitor", NULL};
 301       return p;
 302   }
 303 
 304   virtual void execute(DCmdSource source, TRAPS);
 305 };
 306 
 307 class FinalizerInfoDCmd : public DCmd {
 308 public:
 309   FinalizerInfoDCmd(outputStream* output, bool heap) : DCmd(output, heap) { }
 310   static const char* name() { return "GC.finalizer_info"; }
 311   static const char* description() {
 312     return "Provide information about Java finalization queue.";
 313   }
 314   static const char* impact() {
 315     return "Medium";
 316   }
 317   static int num_arguments() { return 0; }
 318   static const JavaPermission permission() {
 319     JavaPermission p = {"java.lang.management.ManagementPermission",
 320       "monitor", NULL};
 321       return p;
 322   }
 323 
 324   virtual void execute(DCmdSource source, TRAPS);
 325 };
 326 
 327 #if INCLUDE_SERVICES   // Heap dumping supported
 328 // See also: dump_heap in attachListener.cpp
 329 class HeapDumpDCmd : public DCmdWithParser {
 330 protected:
 331   DCmdArgument<char*> _filename;
 332   DCmdArgument<bool>  _all;
 333   DCmdArgument<bool>  _gzip;
 334   DCmdArgument<jlong> _gzip_level;
 335 public:
 336   HeapDumpDCmd(outputStream* output, bool heap);
 337   static const char* name() {
 338     return "GC.heap_dump";
 339   }
 340   static const char* description() {
 341     return "Generate a HPROF format dump of the Java heap.";
 342   }
 343   static const char* impact() {
 344     return "High: Depends on Java heap size and content. "
 345            "Request a full GC unless the '-all' option is specified.";
 346   }
 347   static const JavaPermission permission() {
 348     JavaPermission p = {"java.lang.management.ManagementPermission",
 349                         "monitor", NULL};
 350     return p;
 351   }
 352   static int num_arguments();
 353   virtual void execute(DCmdSource source, TRAPS);
 354 };
 355 #endif // INCLUDE_SERVICES
 356 
 357 // See also: inspectheap in attachListener.cpp
 358 class ClassHistogramDCmd : public DCmdWithParser {
 359 protected:
 360   DCmdArgument<bool> _all;
 361 public:
 362   ClassHistogramDCmd(outputStream* output, bool heap);
 363   static const char* name() {
 364     return "GC.class_histogram";
 365   }
 366   static const char* description() {
 367     return "Provide statistics about the Java heap usage.";
 368   }
 369   static const char* impact() {
 370     return "High: Depends on Java heap size and content.";
 371   }
 372   static const JavaPermission permission() {
 373     JavaPermission p = {"java.lang.management.ManagementPermission",
 374                         "monitor", NULL};
 375     return p;
 376   }
 377   static int num_arguments();
 378   virtual void execute(DCmdSource source, TRAPS);
 379 };
 380 
 381 class ClassHierarchyDCmd : public DCmdWithParser {
 382 protected:
 383   DCmdArgument<bool> _print_interfaces; // true if inherited interfaces should be printed.
 384   DCmdArgument<bool> _print_subclasses; // true if subclasses of the specified classname should be printed.
 385   DCmdArgument<char*> _classname; // Optional single class name whose hierarchy should be printed.
 386 public:
 387   ClassHierarchyDCmd(outputStream* output, bool heap);
 388   static const char* name() {
 389     return "VM.class_hierarchy";
 390   }
 391   static const char* description() {
 392     return "Print a list of all loaded classes, indented to show the class hiearchy. "
 393            "The name of each class is followed by the ClassLoaderData* of its ClassLoader, "
 394            "or \"null\" if loaded by the bootstrap class loader.";
 395   }
 396   static const char* impact() {
 397       return "Medium: Depends on number of loaded classes.";
 398   }
 399   static const JavaPermission permission() {
 400     JavaPermission p = {"java.lang.management.ManagementPermission",
 401                         "monitor", NULL};
 402     return p;
 403   }
 404   static int num_arguments();
 405   virtual void execute(DCmdSource source, TRAPS);
 406 };
 407 
 408 class TouchedMethodsDCmd : public DCmdWithParser {
 409 public:
 410   TouchedMethodsDCmd(outputStream* output, bool heap);
 411   static const char* name() {
 412     return "VM.print_touched_methods";
 413   }
 414   static const char* description() {
 415     return "Print all methods that have ever been touched during the lifetime of this JVM.";
 416   }
 417   static const char* impact() {
 418     return "Medium: Depends on Java content.";
 419   }
 420   static int num_arguments();
 421   virtual void execute(DCmdSource source, TRAPS);
 422 };
 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   ThreadDumpDCmd(outputStream* output, bool heap);
 431   static const char* name() { return "Thread.print"; }
 432   static const char* description() {
 433     return "Print all threads with stacktraces.";
 434   }
 435   static const char* impact() {
 436     return "Medium: Depends on the number of threads.";
 437   }
 438   static const JavaPermission permission() {
 439     JavaPermission p = {"java.lang.management.ManagementPermission",
 440                         "monitor", NULL};
 441     return p;
 442   }
 443   static int num_arguments();
 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   JMXStartRemoteDCmd(outputStream *output, bool heap_allocated);
 483 
 484   static const char *name() {
 485     return "ManagementAgent.start";
 486   }
 487 
 488   static const char *description() {
 489     return "Start remote management agent.";
 490   }
 491 
 492   static int num_arguments();
 493 
 494   virtual void execute(DCmdSource source, TRAPS);
 495 
 496 };
 497 
 498 class JMXStartLocalDCmd : public DCmd {
 499 
 500   // Explicitly request start of local agent,
 501   // it will not be started by start dcmd
 502 
 503 
 504 public:
 505   JMXStartLocalDCmd(outputStream *output, bool heap_allocated);
 506 
 507   static const char *name() {
 508     return "ManagementAgent.start_local";
 509   }
 510 
 511   static const char *description() {
 512     return "Start local management agent.";
 513   }
 514 
 515   virtual void execute(DCmdSource source, TRAPS);
 516 
 517 };
 518 
 519 class JMXStopRemoteDCmd : public DCmd {
 520 public:
 521   JMXStopRemoteDCmd(outputStream *output, bool heap_allocated) :
 522   DCmd(output, heap_allocated) {
 523     // Do Nothing
 524   }
 525 
 526   static const char *name() {
 527     return "ManagementAgent.stop";
 528   }
 529 
 530   static const char *description() {
 531     return "Stop remote management agent.";
 532   }
 533 
 534   virtual void execute(DCmdSource source, TRAPS);
 535 };
 536 
 537 // Print the JMX system status
 538 class JMXStatusDCmd : public DCmd {
 539 public:
 540   JMXStatusDCmd(outputStream *output, bool heap_allocated);
 541 
 542   static const char *name() {
 543     return "ManagementAgent.status";
 544   }
 545 
 546   static const char *description() {
 547     return "Print the management agent status.";
 548   }
 549 
 550   static const JavaPermission permission() {
 551     JavaPermission p = {"java.lang.management.ManagementPermission",
 552                         "monitor", NULL};
 553     return p;
 554   }
 555 
 556   virtual void execute(DCmdSource source, TRAPS);
 557 
 558 };
 559 
 560 class CompileQueueDCmd : public DCmd {
 561 public:
 562   CompileQueueDCmd(outputStream* output, bool heap) : DCmd(output, heap) {}
 563   static const char* name() {
 564     return "Compiler.queue";
 565   }
 566   static const char* description() {
 567     return "Print methods queued for compilation.";
 568   }
 569   static const char* impact() {
 570     return "Low";
 571   }
 572   static const JavaPermission permission() {
 573     JavaPermission p = {"java.lang.management.ManagementPermission",
 574                         "monitor", NULL};
 575     return p;
 576   }
 577   static int num_arguments() { return 0; }
 578   virtual void execute(DCmdSource source, TRAPS);
 579 };
 580 
 581 class CodeListDCmd : public DCmd {
 582 public:
 583   CodeListDCmd(outputStream* output, bool heap) : DCmd(output, heap) {}
 584   static const char* name() {
 585     return "Compiler.codelist";
 586   }
 587   static const char* description() {
 588     return "Print all compiled methods in code cache that are alive";
 589   }
 590   static const char* impact() {
 591     return "Medium";
 592   }
 593   static const JavaPermission permission() {
 594     JavaPermission p = {"java.lang.management.ManagementPermission",
 595                         "monitor", NULL};
 596     return p;
 597   }
 598   static int num_arguments() { return 0; }
 599   virtual void execute(DCmdSource source, TRAPS);
 600 };
 601 
 602 
 603 class CodeCacheDCmd : public DCmd {
 604 public:
 605   CodeCacheDCmd(outputStream* output, bool heap) : DCmd(output, heap) {}
 606   static const char* name() {
 607     return "Compiler.codecache";
 608   }
 609   static const char* description() {
 610     return "Print code cache layout and bounds.";
 611   }
 612   static const char* impact() {
 613     return "Low";
 614   }
 615   static const JavaPermission permission() {
 616     JavaPermission p = {"java.lang.management.ManagementPermission",
 617                         "monitor", NULL};
 618     return p;
 619   }
 620   static int num_arguments() { return 0; }
 621   virtual void execute(DCmdSource source, TRAPS);
 622 };
 623 
 624 //---<  BEGIN  >--- CodeHeap State Analytics.
 625 class CodeHeapAnalyticsDCmd : public DCmdWithParser {
 626 protected:
 627   DCmdArgument<char*> _function;
 628   DCmdArgument<jlong> _granularity;
 629 public:
 630   CodeHeapAnalyticsDCmd(outputStream* output, bool heap);
 631   static const char* name() {
 632     return "Compiler.CodeHeap_Analytics";
 633   }
 634   static const char* description() {
 635     return "Print CodeHeap analytics";
 636   }
 637   static const char* impact() {
 638     return "Low: Depends on code heap size and content. "
 639            "Holds CodeCache_lock during analysis step, usually sub-second duration.";
 640   }
 641   static const JavaPermission permission() {
 642     JavaPermission p = {"java.lang.management.ManagementPermission",
 643                         "monitor", NULL};
 644     return p;
 645   }
 646   static int num_arguments();
 647   virtual void execute(DCmdSource source, TRAPS);
 648 };
 649 //---<  END  >--- CodeHeap State Analytics.
 650 
 651 class CompilerDirectivesPrintDCmd : public DCmd {
 652 public:
 653   CompilerDirectivesPrintDCmd(outputStream* output, bool heap) : DCmd(output, heap) {}
 654   static const char* name() {
 655     return "Compiler.directives_print";
 656   }
 657   static const char* description() {
 658     return "Print all active compiler directives.";
 659   }
 660   static const char* impact() {
 661     return "Low";
 662   }
 663   static const JavaPermission permission() {
 664     JavaPermission p = {"java.lang.management.ManagementPermission",
 665                         "monitor", NULL};
 666     return p;
 667   }
 668   static int num_arguments() { return 0; }
 669   virtual void execute(DCmdSource source, TRAPS);
 670 };
 671 
 672 class CompilerDirectivesRemoveDCmd : public DCmd {
 673 public:
 674   CompilerDirectivesRemoveDCmd(outputStream* output, bool heap) : DCmd(output, heap) {}
 675   static const char* name() {
 676     return "Compiler.directives_remove";
 677   }
 678   static const char* description() {
 679     return "Remove latest added compiler directive.";
 680   }
 681   static const char* impact() {
 682     return "Low";
 683   }
 684   static const JavaPermission permission() {
 685     JavaPermission p = {"java.lang.management.ManagementPermission",
 686                         "monitor", NULL};
 687     return p;
 688   }
 689   static int num_arguments() { return 0; }
 690   virtual void execute(DCmdSource source, TRAPS);
 691 };
 692 
 693 class CompilerDirectivesAddDCmd : public DCmdWithParser {
 694 protected:
 695   DCmdArgument<char*> _filename;
 696 public:
 697   CompilerDirectivesAddDCmd(outputStream* output, bool heap);
 698   static const char* name() {
 699     return "Compiler.directives_add";
 700   }
 701   static const char* description() {
 702     return "Add compiler directives from file.";
 703   }
 704   static const char* impact() {
 705     return "Low";
 706   }
 707   static const JavaPermission permission() {
 708     JavaPermission p = {"java.lang.management.ManagementPermission",
 709                         "monitor", NULL};
 710     return p;
 711   }
 712   static int num_arguments();
 713   virtual void execute(DCmdSource source, TRAPS);
 714 };
 715 
 716 class CompilerDirectivesClearDCmd : public DCmd {
 717 public:
 718   CompilerDirectivesClearDCmd(outputStream* output, bool heap) : DCmd(output, heap) {}
 719   static const char* name() {
 720     return "Compiler.directives_clear";
 721   }
 722   static const char* description() {
 723     return "Remove all compiler directives.";
 724   }
 725   static const char* impact() {
 726     return "Low";
 727   }
 728   static const JavaPermission permission() {
 729     JavaPermission p = {"java.lang.management.ManagementPermission",
 730                         "monitor", NULL};
 731     return p;
 732   }
 733   static int num_arguments() { return 0; }
 734   virtual void execute(DCmdSource source, TRAPS);
 735 };
 736 
 737 ///////////////////////////////////////////////////////////////////////
 738 //
 739 // jcmd command support for symbol table, string table and system dictionary dumping:
 740 //   VM.symboltable -verbose: for dumping the symbol table
 741 //   VM.stringtable -verbose: for dumping the string table
 742 //   VM.systemdictionary -verbose: for dumping the system dictionary table
 743 //
 744 class VM_DumpHashtable : public VM_Operation {
 745 private:
 746   outputStream* _out;
 747   int _which;
 748   bool _verbose;
 749 public:
 750   enum {
 751     DumpSymbols = 1 << 0,
 752     DumpStrings = 1 << 1,
 753     DumpSysDict = 1 << 2  // not implemented yet
 754   };
 755   VM_DumpHashtable(outputStream* out, int which, bool verbose) {
 756     _out = out;
 757     _which = which;
 758     _verbose = verbose;
 759   }
 760 
 761   virtual VMOp_Type type() const { return VMOp_DumpHashtable; }
 762 
 763   virtual void doit() {
 764     switch (_which) {
 765     case DumpSymbols:
 766       SymbolTable::dump(_out, _verbose);
 767       break;
 768     case DumpStrings:
 769       StringTable::dump(_out, _verbose);
 770       break;
 771     case DumpSysDict:
 772       SystemDictionary::dump(_out, _verbose);
 773       break;
 774     default:
 775       ShouldNotReachHere();
 776     }
 777   }
 778 };
 779 
 780 class SymboltableDCmd : public DCmdWithParser {
 781 protected:
 782   DCmdArgument<bool> _verbose;
 783 public:
 784   SymboltableDCmd(outputStream* output, bool heap);
 785   static const char* name() {
 786     return "VM.symboltable";
 787   }
 788   static const char* description() {
 789     return "Dump symbol table.";
 790   }
 791   static const char* impact() {
 792     return "Medium: Depends on Java content.";
 793   }
 794   static const JavaPermission permission() {
 795     JavaPermission p = {"java.lang.management.ManagementPermission",
 796                         "monitor", NULL};
 797     return p;
 798   }
 799   static int num_arguments();
 800   virtual void execute(DCmdSource source, TRAPS);
 801 };
 802 
 803 class StringtableDCmd : public DCmdWithParser {
 804 protected:
 805   DCmdArgument<bool> _verbose;
 806 public:
 807   StringtableDCmd(outputStream* output, bool heap);
 808   static const char* name() {
 809     return "VM.stringtable";
 810   }
 811   static const char* description() {
 812     return "Dump string table.";
 813   }
 814   static const char* impact() {
 815     return "Medium: Depends on Java content.";
 816   }
 817   static const JavaPermission permission() {
 818     JavaPermission p = {"java.lang.management.ManagementPermission",
 819                         "monitor", NULL};
 820     return p;
 821   }
 822   static int num_arguments();
 823   virtual void execute(DCmdSource source, TRAPS);
 824 };
 825 
 826 class SystemDictionaryDCmd : public DCmdWithParser {
 827 protected:
 828   DCmdArgument<bool> _verbose;
 829 public:
 830   SystemDictionaryDCmd(outputStream* output, bool heap);
 831   static const char* name() {
 832     return "VM.systemdictionary";
 833   }
 834   static const char* description() {
 835     return "Prints the statistics for dictionary hashtable sizes and bucket length";
 836   }
 837   static const char* impact() {
 838       return "Medium: Depends on Java content.";
 839   }
 840   static const JavaPermission permission() {
 841     JavaPermission p = {"java.lang.management.ManagementPermission",
 842                         "monitor", NULL};
 843     return p;
 844   }
 845   static int num_arguments();
 846   virtual void execute(DCmdSource source, TRAPS);
 847 };
 848 
 849 #if INCLUDE_JVMTI
 850 class DebugOnCmdStartDCmd : public DCmdWithParser {
 851 public:
 852   DebugOnCmdStartDCmd(outputStream* output, bool heap);
 853   static const char* name() {
 854     return "VM.start_java_debugging";
 855   }
 856   static const char* description() {
 857     return "Starts up the Java debugging if the jdwp agentlib was enabled with the option onjcmd=y.";
 858   }
 859   static const char* impact() {
 860     return "High: Switches the VM into Java debug mode.";
 861   }
 862   static const JavaPermission permission() {
 863     JavaPermission p = { "java.lang.management.ManagementPermission", "control", NULL };
 864     return p;
 865   }
 866   static int num_arguments() { return 0; }
 867   virtual void execute(DCmdSource source, TRAPS);
 868 };
 869 #endif // INCLUDE_JVMTI
 870 
 871 class EventLogDCmd : public DCmdWithParser {
 872 protected:
 873   DCmdArgument<char*> _log;
 874   DCmdArgument<char*> _max;
 875 public:
 876   EventLogDCmd(outputStream* output, bool heap);
 877   static const char* name() {
 878     return "VM.events";
 879   }
 880   static const char* description() {
 881     return "Print VM event logs";
 882   }
 883   static const char* impact() {
 884     return "Low: Depends on event log size. ";
 885   }
 886   static const JavaPermission permission() {
 887     JavaPermission p = {"java.lang.management.ManagementPermission",
 888                         "monitor", NULL};
 889     return p;
 890   }
 891   static int num_arguments();
 892   virtual void execute(DCmdSource source, TRAPS);
 893 };
 894 
 895 #endif // SHARE_SERVICES_DIAGNOSTICCOMMAND_HPP