1 /*
  2  * Copyright (c) 2011, 2025, 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 "oops/method.hpp"
 33 #include "runtime/arguments.hpp"
 34 #include "runtime/os.hpp"
 35 #include "runtime/vmThread.hpp"
 36 #include "services/diagnosticArgument.hpp"
 37 #include "services/diagnosticCommand.hpp"
 38 #include "services/diagnosticFramework.hpp"
 39 #include "utilities/macros.hpp"
 40 #include "utilities/ostream.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   virtual void execute(DCmdSource source, TRAPS);
 68 };
 69 
 70 class CommandLineDCmd : public DCmd {
 71 public:
 72   CommandLineDCmd(outputStream* output, bool heap) : DCmd(output, heap) { }
 73   static const char* name() { return "VM.command_line"; }
 74   static const char* description() {
 75     return "Print the command line used to start this VM instance.";
 76   }
 77   static const char* impact() { return "Low"; }
 78   virtual void execute(DCmdSource source, TRAPS) {
 79     Arguments::print_on(_output);
 80   }
 81 };
 82 
 83 // See also: get_system_properties in attachListener.cpp
 84 class PrintSystemPropertiesDCmd : public DCmd {
 85 public:
 86   PrintSystemPropertiesDCmd(outputStream* output, bool heap) : DCmd(output, heap) { }
 87     static const char* name() { return "VM.system_properties"; }
 88     static const char* description() {
 89       return "Print system properties.";
 90     }
 91     static const char* impact() {
 92       return "Low";
 93     }
 94     virtual void execute(DCmdSource source, TRAPS);
 95 };
 96 
 97 // See also: print_flag in attachListener.cpp
 98 class PrintVMFlagsDCmd : public DCmdWithParser {
 99 protected:
100   DCmdArgument<bool> _all;
101 public:
102   static int num_arguments() { return 1; }
103   PrintVMFlagsDCmd(outputStream* output, bool heap);
104   static const char* name() { return "VM.flags"; }
105   static const char* description() {
106     return "Print VM flag options and their current values.";
107   }
108   static const char* impact() {
109     return "Low";
110   }
111   virtual void execute(DCmdSource source, TRAPS);
112 };
113 
114 class SetVMFlagDCmd : public DCmdWithParser {
115 protected:
116   DCmdArgument<char*> _flag;
117   DCmdArgument<char*> _value;
118 
119 public:
120   static int num_arguments() { return 2; }
121   SetVMFlagDCmd(outputStream* output, bool heap);
122   static const char* name() { return "VM.set_flag"; }
123   static const char* description() {
124     return "Sets VM flag option using the provided value.";
125   }
126   static const char* impact() {
127     return "Low";
128   }
129   virtual void execute(DCmdSource source, TRAPS);
130 };
131 
132 class JVMTIDataDumpDCmd : public DCmd {
133 public:
134   JVMTIDataDumpDCmd(outputStream* output, bool heap) : DCmd(output, heap) { }
135   static const char* name() { return "JVMTI.data_dump"; }
136   static const char* description() {
137     return "Signal the JVM to do a data-dump request for JVMTI.";
138   }
139   static const char* impact() {
140     return "High";
141   }
142   virtual void execute(DCmdSource source, TRAPS);
143 };
144 
145 #if INCLUDE_SERVICES
146 #if INCLUDE_JVMTI
147 class JVMTIAgentLoadDCmd : public DCmdWithParser {
148 protected:
149   DCmdArgument<char*> _libpath;
150   DCmdArgument<char*> _option;
151 public:
152   static int num_arguments() { return 2; }
153   JVMTIAgentLoadDCmd(outputStream* output, bool heap);
154   static const char* name() { return "JVMTI.agent_load"; }
155   static const char* description() {
156     return "Load JVMTI native agent.";
157   }
158   static const char* impact() { return "Low"; }
159   virtual void execute(DCmdSource source, TRAPS);
160 };
161 #endif // INCLUDE_JVMTI
162 #endif // INCLUDE_SERVICES
163 
164 class VMDynamicLibrariesDCmd : public DCmd {
165 public:
166   VMDynamicLibrariesDCmd(outputStream* output, bool heap);
167   static const char* name() {
168     return "VM.dynlibs";
169   }
170   static const char* description() {
171     return "Print loaded dynamic libraries.";
172   }
173   static const char* impact() {
174     return "Low";
175   }
176   virtual void execute(DCmdSource source, TRAPS);
177 };
178 
179 class VMUptimeDCmd : public DCmdWithParser {
180 protected:
181   DCmdArgument<bool> _date;
182 public:
183   static int num_arguments() { return 1; }
184   VMUptimeDCmd(outputStream* output, bool heap);
185   static const char* name() { return "VM.uptime"; }
186   static const char* description() {
187     return "Print VM uptime.";
188   }
189   static const char* impact() {
190     return "Low";
191   }
192   virtual void execute(DCmdSource source, TRAPS);
193 };
194 
195 class VMInfoDCmd : public DCmd {
196 public:
197   VMInfoDCmd(outputStream* output, bool heap) : DCmd(output, heap) { }
198   static const char* name() { return "VM.info"; }
199   static const char* description() {
200     return "Print information about JVM environment and status.";
201   }
202   static const char* impact() { return "Low"; }
203   virtual void execute(DCmdSource source, TRAPS);
204 };
205 
206 class SystemGCDCmd : public DCmd {
207 public:
208   SystemGCDCmd(outputStream* output, bool heap) : DCmd(output, heap) { }
209     static const char* name() { return "GC.run"; }
210     static const char* description() {
211       return "Call java.lang.System.gc().";
212     }
213     static const char* impact() {
214       return "Medium: Depends on Java heap size and content.";
215     }
216     virtual void execute(DCmdSource source, TRAPS);
217 };
218 
219 class RunFinalizationDCmd : public DCmd {
220 public:
221   RunFinalizationDCmd(outputStream* output, bool heap) : DCmd(output, heap) { }
222     static const char* name() { return "GC.run_finalization"; }
223     static const char* description() {
224       return "Call java.lang.System.runFinalization().";
225     }
226     static const char* impact() {
227       return "Medium: Depends on Java content.";
228     }
229     virtual void execute(DCmdSource source, TRAPS);
230 };
231 
232 class HeapInfoDCmd : public DCmd {
233 public:
234   HeapInfoDCmd(outputStream* output, bool heap) : DCmd(output, heap) { }
235   static const char* name() { return "GC.heap_info"; }
236   static const char* description() {
237     return "Provide generic Java heap information.";
238   }
239   static const char* impact() {
240     return "Medium";
241   }
242 
243   virtual void execute(DCmdSource source, TRAPS);
244 };
245 
246 class FinalizerInfoDCmd : public DCmd {
247 public:
248   FinalizerInfoDCmd(outputStream* output, bool heap) : DCmd(output, heap) { }
249   static const char* name() { return "GC.finalizer_info"; }
250   static const char* description() {
251     return "Provide information about Java finalization queue.";
252   }
253   static const char* impact() {
254     return "Medium";
255   }
256 
257   virtual void execute(DCmdSource source, TRAPS);
258 };
259 
260 #if INCLUDE_SERVICES   // Heap dumping supported
261 // See also: dump_heap in attachListener.cpp
262 class HeapDumpDCmd : public DCmdWithParser {
263 protected:
264   DCmdArgument<char*> _filename;
265   DCmdArgument<bool>  _all;
266   DCmdArgument<jlong> _gzip;
267   DCmdArgument<bool> _overwrite;
268   DCmdArgument<jlong> _parallel;
269 public:
270   static int num_arguments() { return 5; }
271   HeapDumpDCmd(outputStream* output, bool heap);
272   static const char* name() {
273     return "GC.heap_dump";
274   }
275   static const char* description() {
276     return "Generate a HPROF format dump of the Java heap.";
277   }
278   static const char* impact() {
279     return "High: Depends on Java heap size and content. "
280            "Request a full GC unless the '-all' option is specified.";
281   }
282   virtual void execute(DCmdSource source, TRAPS);
283 };
284 #endif // INCLUDE_SERVICES
285 
286 // See also: inspectheap in attachListener.cpp
287 class ClassHistogramDCmd : public DCmdWithParser {
288 protected:
289   DCmdArgument<bool> _all;
290   DCmdArgument<jlong> _parallel_thread_num;
291 public:
292   static int num_arguments() { return 2; }
293   ClassHistogramDCmd(outputStream* output, bool heap);
294   static const char* name() {
295     return "GC.class_histogram";
296   }
297   static const char* description() {
298     return "Provide statistics about the Java heap usage.";
299   }
300   static const char* impact() {
301     return "High: Depends on Java heap size and content.";
302   }
303   virtual void execute(DCmdSource source, TRAPS);
304 };
305 
306 class ClassHierarchyDCmd : public DCmdWithParser {
307 protected:
308   DCmdArgument<bool> _print_interfaces; // true if inherited interfaces should be printed.
309   DCmdArgument<bool> _print_subclasses; // true if subclasses of the specified classname should be printed.
310   DCmdArgument<char*> _classname; // Optional single class name whose hierarchy should be printed.
311 public:
312   static int num_arguments() { return 3; }
313   ClassHierarchyDCmd(outputStream* output, bool heap);
314   static const char* name() {
315     return "VM.class_hierarchy";
316   }
317   static const char* description() {
318     return "Print a list of all loaded classes, indented to show the class hierarchy. "
319            "The name of each class is followed by the ClassLoaderData* of its ClassLoader, "
320            "or \"null\" if loaded by the bootstrap class loader.";
321   }
322   static const char* impact() {
323       return "Medium: Depends on number of loaded classes.";
324   }
325   virtual void execute(DCmdSource source, TRAPS);
326 };
327 
328 #if INCLUDE_CDS
329 class AOTEndTrainingDCmd : public DCmd {
330 public:
331   AOTEndTrainingDCmd(outputStream* output, bool heap) : DCmd(output, heap) { }
332     static const char* name() { return "AOT.end_training"; }
333     static const char* description() {
334       return "End AOT training and create the cache.";
335     }
336     static const char* impact() {
337       return "Medium: Pause time depends on number of loaded classes";
338     }
339     virtual void execute(DCmdSource source, TRAPS);
340 };
341 #endif // INCLUDE_CDS
342 
343 #if INCLUDE_CDS
344 class DumpSharedArchiveDCmd: public DCmdWithParser {
345 protected:
346   DCmdArgument<char*> _suboption;   // option of VM.cds
347   DCmdArgument<char*> _filename;    // file name, optional
348 public:
349   static int num_arguments() { return 2; }
350   DumpSharedArchiveDCmd(outputStream* output, bool heap);
351   static const char* name() {
352     return "VM.cds";
353   }
354   static const char* description() {
355     return "Dump a static or dynamic shared archive including all shareable classes";
356   }
357   static const char* impact() {
358     return "Medium: Pause time depends on number of loaded classes";
359   }
360   virtual void execute(DCmdSource source, TRAPS);
361 };
362 #endif // INCLUDE_CDS
363 
364 // See also: thread_dump in attachListener.cpp
365 class ThreadDumpDCmd : public DCmdWithParser {
366 protected:
367   DCmdArgument<bool> _locks;
368   DCmdArgument<bool> _extended;
369 public:
370   static int num_arguments() { return 2; }
371   ThreadDumpDCmd(outputStream* output, bool heap);
372   static const char* name() { return "Thread.print"; }
373   static const char* description() {
374     return "Print all platform threads, and mounted virtual threads, "
375            "with stack traces. The Thread.dump_to_file command will "
376            "print all threads to a file.";
377   }
378   static const char* impact() {
379     return "Medium: Depends on the number of threads.";
380   }
381   virtual void execute(DCmdSource source, TRAPS);
382 };
383 
384 // Enhanced JMX Agent support
385 
386 class JMXStartRemoteDCmd : public DCmdWithParser {
387 
388   // Explicitly list all properties that could be
389   // passed to Agent.startRemoteManagementAgent()
390   // com.sun.management is omitted
391 
392   DCmdArgument<char *> _config_file;
393   DCmdArgument<char *> _jmxremote_host;
394   DCmdArgument<char *> _jmxremote_port;
395   DCmdArgument<char *> _jmxremote_rmi_port;
396   DCmdArgument<char *> _jmxremote_ssl;
397   DCmdArgument<char *> _jmxremote_registry_ssl;
398   DCmdArgument<char *> _jmxremote_authenticate;
399   DCmdArgument<char *> _jmxremote_password_file;
400   DCmdArgument<char *> _jmxremote_access_file;
401   DCmdArgument<char *> _jmxremote_login_config;
402   DCmdArgument<char *> _jmxremote_ssl_enabled_cipher_suites;
403   DCmdArgument<char *> _jmxremote_ssl_enabled_protocols;
404   DCmdArgument<char *> _jmxremote_ssl_need_client_auth;
405   DCmdArgument<char *> _jmxremote_ssl_config_file;
406 
407   // JDP support
408   // Keep autodiscovery char* not bool to pass true/false
409   // as property value to java level.
410   DCmdArgument<char *> _jmxremote_autodiscovery;
411   DCmdArgument<jlong>  _jdp_port;
412   DCmdArgument<char *> _jdp_address;
413   DCmdArgument<char *> _jdp_source_addr;
414   DCmdArgument<jlong>  _jdp_ttl;
415   DCmdArgument<jlong>  _jdp_pause;
416   DCmdArgument<char *> _jdp_name;
417 
418 public:
419   static int num_arguments() { return 21; }
420 
421   JMXStartRemoteDCmd(outputStream *output, bool heap_allocated);
422 
423   static const char *name() {
424     return "ManagementAgent.start";
425   }
426 
427   static const char *description() {
428     return "Start remote management agent.";
429   }
430 
431   virtual void execute(DCmdSource source, TRAPS);
432 };
433 
434 class JMXStartLocalDCmd : public DCmd {
435 
436   // Explicitly request start of local agent,
437   // it will not be started by start dcmd
438 
439 
440 public:
441   JMXStartLocalDCmd(outputStream *output, bool heap_allocated);
442 
443   static const char *name() {
444     return "ManagementAgent.start_local";
445   }
446 
447   static const char *description() {
448     return "Start local management agent.";
449   }
450 
451   virtual void execute(DCmdSource source, TRAPS);
452 
453 };
454 
455 class JMXStopRemoteDCmd : public DCmd {
456 public:
457   JMXStopRemoteDCmd(outputStream *output, bool heap_allocated) :
458   DCmd(output, heap_allocated) {
459     // Do Nothing
460   }
461 
462   static const char *name() {
463     return "ManagementAgent.stop";
464   }
465 
466   static const char *description() {
467     return "Stop remote management agent.";
468   }
469 
470   virtual void execute(DCmdSource source, TRAPS);
471 };
472 
473 // Print the JMX system status
474 class JMXStatusDCmd : public DCmd {
475 public:
476   JMXStatusDCmd(outputStream *output, bool heap_allocated);
477 
478   static const char *name() {
479     return "ManagementAgent.status";
480   }
481 
482   static const char *description() {
483     return "Print the management agent status.";
484   }
485 
486   virtual void execute(DCmdSource source, TRAPS);
487 
488 };
489 
490 class CompileQueueDCmd : public DCmd {
491 public:
492   CompileQueueDCmd(outputStream* output, bool heap) : DCmd(output, heap) {}
493   static const char* name() {
494     return "Compiler.queue";
495   }
496   static const char* description() {
497     return "Print methods queued for compilation.";
498   }
499   static const char* impact() {
500     return "Low";
501   }
502   virtual void execute(DCmdSource source, TRAPS);
503 };
504 
505 #ifdef LINUX
506 class PerfMapDCmd : public DCmdWithParser {
507 protected:
508   DCmdArgument<char*> _filename;
509 public:
510   static int num_arguments() { return 1; }
511   PerfMapDCmd(outputStream* output, bool heap);
512   static const char* name() {
513     return "Compiler.perfmap";
514   }
515   static const char* description() {
516     return "Write map file for Linux perf tool.";
517   }
518   static const char* impact() {
519     return "Low";
520   }
521   virtual void execute(DCmdSource source, TRAPS);
522 };
523 #endif // LINUX
524 
525 class CodeListDCmd : public DCmd {
526 public:
527   CodeListDCmd(outputStream* output, bool heap) : DCmd(output, heap) {}
528   static const char* name() {
529     return "Compiler.codelist";
530   }
531   static const char* description() {
532     return "Print all compiled methods in code cache that are alive";
533   }
534   static const char* impact() {
535     return "Medium";
536   }
537   virtual void execute(DCmdSource source, TRAPS);
538 };
539 
540 class CodeCacheDCmd : public DCmd {
541 public:
542   CodeCacheDCmd(outputStream* output, bool heap) : DCmd(output, heap) {}
543   static const char* name() {
544     return "Compiler.codecache";
545   }
546   static const char* description() {
547     return "Print code cache layout and bounds.";
548   }
549   static const char* impact() {
550     return "Low";
551   }
552   virtual void execute(DCmdSource source, TRAPS);
553 };
554 
555 //---<  BEGIN  >--- CodeHeap State Analytics.
556 class CodeHeapAnalyticsDCmd : public DCmdWithParser {
557 protected:
558   DCmdArgument<char*> _function;
559   DCmdArgument<jlong> _granularity;
560 public:
561   static int num_arguments() { return 2; }
562   CodeHeapAnalyticsDCmd(outputStream* output, bool heap);
563   static const char* name() {
564     return "Compiler.CodeHeap_Analytics";
565   }
566   static const char* description() {
567     return "Print CodeHeap analytics";
568   }
569   static const char* impact() {
570     return "Low: Depends on code heap size and content. "
571            "Holds CodeCache_lock during analysis step, usually sub-second duration.";
572   }
573   virtual void execute(DCmdSource source, TRAPS);
574 };
575 //---<  END  >--- CodeHeap State Analytics.
576 
577 class CompilerDirectivesPrintDCmd : public DCmd {
578 public:
579   CompilerDirectivesPrintDCmd(outputStream* output, bool heap) : DCmd(output, heap) {}
580   static const char* name() {
581     return "Compiler.directives_print";
582   }
583   static const char* description() {
584     return "Print all active compiler directives.";
585   }
586   static const char* impact() {
587     return "Low";
588   }
589   virtual void execute(DCmdSource source, TRAPS);
590 };
591 
592 class CompilerDirectivesRemoveDCmd : public DCmd {
593 public:
594   CompilerDirectivesRemoveDCmd(outputStream* output, bool heap) : DCmd(output, heap) {}
595   static const char* name() {
596     return "Compiler.directives_remove";
597   }
598   static const char* description() {
599     return "Remove latest added compiler directive.";
600   }
601   static const char* impact() {
602     return "Low";
603   }
604   virtual void execute(DCmdSource source, TRAPS);
605 };
606 
607 class CompilerDirectivesAddDCmd : public DCmdWithParser {
608 protected:
609   DCmdArgument<char*> _filename;
610 public:
611   static int num_arguments() { return 1; }
612   CompilerDirectivesAddDCmd(outputStream* output, bool heap);
613   static const char* name() {
614     return "Compiler.directives_add";
615   }
616   static const char* description() {
617     return "Add compiler directives from file.";
618   }
619   static const char* impact() {
620     return "Low";
621   }
622   virtual void execute(DCmdSource source, TRAPS);
623 };
624 
625 class CompilerDirectivesClearDCmd : public DCmd {
626 public:
627   CompilerDirectivesClearDCmd(outputStream* output, bool heap) : DCmd(output, heap) {}
628   static const char* name() {
629     return "Compiler.directives_clear";
630   }
631   static const char* description() {
632     return "Remove all compiler directives.";
633   }
634   static const char* impact() {
635     return "Low";
636   }
637   virtual void execute(DCmdSource source, TRAPS);
638 };
639 
640 ///////////////////////////////////////////////////////////////////////
641 //
642 // jcmd command support for symbol table, string table and system dictionary dumping:
643 //   VM.symboltable -verbose: for dumping the symbol table
644 //   VM.stringtable -verbose: for dumping the string table
645 //   VM.systemdictionary -verbose: for dumping the system dictionary table
646 //
647 class VM_DumpHashtable : public VM_Operation {
648 private:
649   outputStream* _out;
650   int _which;
651   bool _verbose;
652 public:
653   enum {
654     DumpSymbols = 1 << 0,
655     DumpStrings = 1 << 1,
656     DumpSysDict = 1 << 2  // not implemented yet
657   };
658   VM_DumpHashtable(outputStream* out, int which, bool verbose) {
659     _out = out;
660     _which = which;
661     _verbose = verbose;
662   }
663 
664   virtual VMOp_Type type() const { return VMOp_DumpHashtable; }
665 
666   virtual void doit() {
667     switch (_which) {
668     case DumpSymbols:
669       SymbolTable::dump(_out, _verbose);
670       break;
671     case DumpStrings:
672       StringTable::dump(_out, _verbose);
673       break;
674     case DumpSysDict:
675       SystemDictionary::dump(_out, _verbose);
676       break;
677     default:
678       ShouldNotReachHere();
679     }
680   }
681 };
682 
683 class SymboltableDCmd : public DCmdWithParser {
684 protected:
685   DCmdArgument<bool> _verbose;
686 public:
687   static int num_arguments() { return 1; }
688   SymboltableDCmd(outputStream* output, bool heap);
689   static const char* name() {
690     return "VM.symboltable";
691   }
692   static const char* description() {
693     return "Dump symbol table.";
694   }
695   static const char* impact() {
696     return "Medium: Depends on Java content.";
697   }
698   virtual void execute(DCmdSource source, TRAPS);
699 };
700 
701 class StringtableDCmd : public DCmdWithParser {
702 protected:
703   DCmdArgument<bool> _verbose;
704 public:
705   static int num_arguments() { return 1; }
706   StringtableDCmd(outputStream* output, bool heap);
707   static const char* name() {
708     return "VM.stringtable";
709   }
710   static const char* description() {
711     return "Dump string table.";
712   }
713   static const char* impact() {
714     return "Medium: Depends on Java content.";
715   }
716   virtual void execute(DCmdSource source, TRAPS);
717 };
718 
719 class SystemDictionaryDCmd : public DCmdWithParser {
720 protected:
721   DCmdArgument<bool> _verbose;
722 public:
723   static int num_arguments() { return 1; }
724   SystemDictionaryDCmd(outputStream* output, bool heap);
725   static const char* name() {
726     return "VM.systemdictionary";
727   }
728   static const char* description() {
729     return "Prints the statistics for dictionary hashtable sizes and bucket length";
730   }
731   static const char* impact() {
732       return "Medium: Depends on Java content.";
733   }
734   virtual void execute(DCmdSource source, TRAPS);
735 };
736 
737 class ClassesDCmd : public DCmdWithParser {
738 protected:
739   DCmdArgument<bool> _verbose;
740 public:
741   static int num_arguments() { return 1; }
742   ClassesDCmd(outputStream* output, bool heap);
743   static const char* name() {
744     return "VM.classes";
745   }
746   static const char* description() {
747     return "Print all loaded classes";
748   }
749   static const char* impact() {
750       return "Medium: Depends on number of loaded classes.";
751   }
752   virtual void execute(DCmdSource source, TRAPS);
753 };
754 
755 class EventLogDCmd : public DCmdWithParser {
756 protected:
757   DCmdArgument<char*> _log;
758   DCmdArgument<jlong> _max;
759 public:
760   static int num_arguments() { return 2; }
761   EventLogDCmd(outputStream* output, bool heap);
762   static const char* name() {
763     return "VM.events";
764   }
765   static const char* description() {
766     return "Print VM event logs";
767   }
768   static const char* impact() {
769     return "Low: Depends on event log size. ";
770   }
771   virtual void execute(DCmdSource source, TRAPS);
772 };
773 
774 class ThreadDumpToFileDCmd : public DCmdWithParser {
775 private:
776   void dumpToFile(Symbol* name, Symbol* signature, const char* path, bool overwrite, TRAPS);
777 protected:
778   DCmdArgument<bool> _overwrite;
779   DCmdArgument<char*> _format;
780   DCmdArgument<char*> _filepath;
781 public:
782   static int num_arguments() { return 3; }
783   ThreadDumpToFileDCmd(outputStream *output, bool heap);
784   static const char *name() {
785     return "Thread.dump_to_file";
786   }
787   static const char *description() {
788     return "Dump all threads, with stack traces, "
789            "to a file in plain text or JSON format.";
790   }
791   static const char* impact() {
792     return "Medium: Depends on the number of threads.";
793   }
794   virtual void execute(DCmdSource source, TRAPS);
795 };
796 
797 class VThreadSchedulerDCmd : public DCmd {
798 public:
799   VThreadSchedulerDCmd(outputStream* output, bool heap) : DCmd(output, heap) { }
800   static const char* name() {
801     return "Thread.vthread_scheduler";
802   }
803   static const char* description() {
804     return "Print the virtual thread scheduler, and the delayed task schedulers that support "
805            "virtual threads doing timed operations.";
806   }
807   static const char* impact() { return "Low"; }
808   virtual void execute(DCmdSource source, TRAPS);
809 };
810 
811 class VThreadPollersDCmd : public DCmd {
812 public:
813   VThreadPollersDCmd(outputStream* output, bool heap) : DCmd(output, heap) { }
814   static const char* name() {
815     return "Thread.vthread_pollers";
816   }
817   static const char* description() {
818     return "Print the I/O pollers that support virtual threads doing blocking network I/O operations.";
819   }
820   static const char* impact() { return "Low"; }
821   virtual void execute(DCmdSource source, TRAPS);
822 };
823 
824 class CompilationMemoryStatisticDCmd: public DCmdWithParser {
825 protected:
826   DCmdArgument<bool> _verbose;
827   DCmdArgument<bool> _legend;
828   DCmdArgument<MemorySizeArgument> _minsize;
829 public:
830   static int num_arguments() { return 3; }
831   CompilationMemoryStatisticDCmd(outputStream* output, bool heap);
832   static const char* name() {
833     return "Compiler.memory";
834   }
835   static const char* description() {
836     return "Print compilation footprint";
837   }
838   static const char* impact() {
839     return "Medium: Pause time depends on number of compiled methods";
840   }
841   virtual void execute(DCmdSource source, TRAPS);
842 };
843 
844 #if defined(LINUX) || defined(_WIN64) || defined(__APPLE__)
845 
846 class SystemMapDCmd : public DCmd {
847 public:
848   SystemMapDCmd(outputStream* output, bool heap);
849   static const char* name() { return "System.map"; }
850   static const char* description() {
851     return "Prints an annotated process memory map of the VM process (linux, Windows and MacOS only).";
852   }
853   static const char* impact() { return "Medium; can be high for very large java heaps."; }
854   virtual void execute(DCmdSource source, TRAPS);
855 };
856 
857 class SystemDumpMapDCmd : public DCmdWithParser {
858   DCmdArgument<char*> _filename;
859 public:
860   static int num_arguments() { return 1; }
861   SystemDumpMapDCmd(outputStream* output, bool heap);
862   static const char* name() { return "System.dump_map"; }
863   static const char* description() {
864     return "Dumps an annotated process memory map to an output file (linux, Windows and MacOS only).";
865   }
866   static const char* impact() { return "Medium; can be high for very large java heaps."; }
867   virtual void execute(DCmdSource source, TRAPS);
868 };
869 
870 #endif // LINUX, WINDOWS or MACOS
871 
872 #endif // SHARE_SERVICES_DIAGNOSTICCOMMAND_HPP