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