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 DumpSharedArchiveDCmd: public DCmdWithParser {
330 protected:
331   DCmdArgument<char*> _suboption;   // option of VM.cds
332   DCmdArgument<char*> _filename;    // file name, optional
333 public:
334   static int num_arguments() { return 2; }
335   DumpSharedArchiveDCmd(outputStream* output, bool heap);
336   static const char* name() {
337     return "VM.cds";
338   }
339   static const char* description() {
340     return "Dump a static or dynamic shared archive including all shareable classes";
341   }
342   static const char* impact() {
343     return "Medium: Pause time depends on number of loaded classes";
344   }
345   virtual void execute(DCmdSource source, TRAPS);
346 };
347 #endif // INCLUDE_CDS
348 
349 // See also: thread_dump in attachListener.cpp
350 class ThreadDumpDCmd : public DCmdWithParser {
351 protected:
352   DCmdArgument<bool> _locks;
353   DCmdArgument<bool> _extended;
354 public:
355   static int num_arguments() { return 2; }
356   ThreadDumpDCmd(outputStream* output, bool heap);
357   static const char* name() { return "Thread.print"; }
358   static const char* description() {
359     return "Print all platform threads, and mounted virtual threads, "
360            "with stack traces. The Thread.dump_to_file command will "
361            "print all threads to a file.";
362   }
363   static const char* impact() {
364     return "Medium: Depends on the number of threads.";
365   }
366   virtual void execute(DCmdSource source, TRAPS);
367 };
368 
369 // Enhanced JMX Agent support
370 
371 class JMXStartRemoteDCmd : public DCmdWithParser {
372 
373   // Explicitly list all properties that could be
374   // passed to Agent.startRemoteManagementAgent()
375   // com.sun.management is omitted
376 
377   DCmdArgument<char *> _config_file;
378   DCmdArgument<char *> _jmxremote_host;
379   DCmdArgument<char *> _jmxremote_port;
380   DCmdArgument<char *> _jmxremote_rmi_port;
381   DCmdArgument<char *> _jmxremote_ssl;
382   DCmdArgument<char *> _jmxremote_registry_ssl;
383   DCmdArgument<char *> _jmxremote_authenticate;
384   DCmdArgument<char *> _jmxremote_password_file;
385   DCmdArgument<char *> _jmxremote_access_file;
386   DCmdArgument<char *> _jmxremote_login_config;
387   DCmdArgument<char *> _jmxremote_ssl_enabled_cipher_suites;
388   DCmdArgument<char *> _jmxremote_ssl_enabled_protocols;
389   DCmdArgument<char *> _jmxremote_ssl_need_client_auth;
390   DCmdArgument<char *> _jmxremote_ssl_config_file;
391 
392   // JDP support
393   // Keep autodiscovery char* not bool to pass true/false
394   // as property value to java level.
395   DCmdArgument<char *> _jmxremote_autodiscovery;
396   DCmdArgument<jlong>  _jdp_port;
397   DCmdArgument<char *> _jdp_address;
398   DCmdArgument<char *> _jdp_source_addr;
399   DCmdArgument<jlong>  _jdp_ttl;
400   DCmdArgument<jlong>  _jdp_pause;
401   DCmdArgument<char *> _jdp_name;
402 
403 public:
404   static int num_arguments() { return 21; }
405 
406   JMXStartRemoteDCmd(outputStream *output, bool heap_allocated);
407 
408   static const char *name() {
409     return "ManagementAgent.start";
410   }
411 
412   static const char *description() {
413     return "Start remote management agent.";
414   }
415 
416   virtual void execute(DCmdSource source, TRAPS);
417 };
418 
419 class JMXStartLocalDCmd : public DCmd {
420 
421   // Explicitly request start of local agent,
422   // it will not be started by start dcmd
423 
424 
425 public:
426   JMXStartLocalDCmd(outputStream *output, bool heap_allocated);
427 
428   static const char *name() {
429     return "ManagementAgent.start_local";
430   }
431 
432   static const char *description() {
433     return "Start local management agent.";
434   }
435 
436   virtual void execute(DCmdSource source, TRAPS);
437 
438 };
439 
440 class JMXStopRemoteDCmd : public DCmd {
441 public:
442   JMXStopRemoteDCmd(outputStream *output, bool heap_allocated) :
443   DCmd(output, heap_allocated) {
444     // Do Nothing
445   }
446 
447   static const char *name() {
448     return "ManagementAgent.stop";
449   }
450 
451   static const char *description() {
452     return "Stop remote management agent.";
453   }
454 
455   virtual void execute(DCmdSource source, TRAPS);
456 };
457 
458 // Print the JMX system status
459 class JMXStatusDCmd : public DCmd {
460 public:
461   JMXStatusDCmd(outputStream *output, bool heap_allocated);
462 
463   static const char *name() {
464     return "ManagementAgent.status";
465   }
466 
467   static const char *description() {
468     return "Print the management agent status.";
469   }
470 
471   virtual void execute(DCmdSource source, TRAPS);
472 
473 };
474 
475 class CompileQueueDCmd : public DCmd {
476 public:
477   CompileQueueDCmd(outputStream* output, bool heap) : DCmd(output, heap) {}
478   static const char* name() {
479     return "Compiler.queue";
480   }
481   static const char* description() {
482     return "Print methods queued for compilation.";
483   }
484   static const char* impact() {
485     return "Low";
486   }
487   virtual void execute(DCmdSource source, TRAPS);
488 };
489 
490 #ifdef LINUX
491 class PerfMapDCmd : public DCmdWithParser {
492 protected:
493   DCmdArgument<char*> _filename;
494 public:
495   static int num_arguments() { return 1; }
496   PerfMapDCmd(outputStream* output, bool heap);
497   static const char* name() {
498     return "Compiler.perfmap";
499   }
500   static const char* description() {
501     return "Write map file for Linux perf tool.";
502   }
503   static const char* impact() {
504     return "Low";
505   }
506   virtual void execute(DCmdSource source, TRAPS);
507 };
508 #endif // LINUX
509 
510 class CodeListDCmd : public DCmd {
511 public:
512   CodeListDCmd(outputStream* output, bool heap) : DCmd(output, heap) {}
513   static const char* name() {
514     return "Compiler.codelist";
515   }
516   static const char* description() {
517     return "Print all compiled methods in code cache that are alive";
518   }
519   static const char* impact() {
520     return "Medium";
521   }
522   virtual void execute(DCmdSource source, TRAPS);
523 };
524 
525 class CodeCacheDCmd : public DCmd {
526 public:
527   CodeCacheDCmd(outputStream* output, bool heap) : DCmd(output, heap) {}
528   static const char* name() {
529     return "Compiler.codecache";
530   }
531   static const char* description() {
532     return "Print code cache layout and bounds.";
533   }
534   static const char* impact() {
535     return "Low";
536   }
537   virtual void execute(DCmdSource source, TRAPS);
538 };
539 
540 //---<  BEGIN  >--- CodeHeap State Analytics.
541 class CodeHeapAnalyticsDCmd : public DCmdWithParser {
542 protected:
543   DCmdArgument<char*> _function;
544   DCmdArgument<jlong> _granularity;
545 public:
546   static int num_arguments() { return 2; }
547   CodeHeapAnalyticsDCmd(outputStream* output, bool heap);
548   static const char* name() {
549     return "Compiler.CodeHeap_Analytics";
550   }
551   static const char* description() {
552     return "Print CodeHeap analytics";
553   }
554   static const char* impact() {
555     return "Low: Depends on code heap size and content. "
556            "Holds CodeCache_lock during analysis step, usually sub-second duration.";
557   }
558   virtual void execute(DCmdSource source, TRAPS);
559 };
560 //---<  END  >--- CodeHeap State Analytics.
561 
562 class CompilerDirectivesPrintDCmd : public DCmd {
563 public:
564   CompilerDirectivesPrintDCmd(outputStream* output, bool heap) : DCmd(output, heap) {}
565   static const char* name() {
566     return "Compiler.directives_print";
567   }
568   static const char* description() {
569     return "Print all active compiler directives.";
570   }
571   static const char* impact() {
572     return "Low";
573   }
574   virtual void execute(DCmdSource source, TRAPS);
575 };
576 
577 class CompilerDirectivesRemoveDCmd : public DCmd {
578 public:
579   CompilerDirectivesRemoveDCmd(outputStream* output, bool heap) : DCmd(output, heap) {}
580   static const char* name() {
581     return "Compiler.directives_remove";
582   }
583   static const char* description() {
584     return "Remove latest added compiler directive.";
585   }
586   static const char* impact() {
587     return "Low";
588   }
589   virtual void execute(DCmdSource source, TRAPS);
590 };
591 
592 class CompilerDirectivesAddDCmd : public DCmdWithParser {
593 protected:
594   DCmdArgument<char*> _filename;
595 public:
596   static int num_arguments() { return 1; }
597   CompilerDirectivesAddDCmd(outputStream* output, bool heap);
598   static const char* name() {
599     return "Compiler.directives_add";
600   }
601   static const char* description() {
602     return "Add compiler directives from file.";
603   }
604   static const char* impact() {
605     return "Low";
606   }
607   virtual void execute(DCmdSource source, TRAPS);
608 };
609 
610 class CompilerDirectivesClearDCmd : public DCmd {
611 public:
612   CompilerDirectivesClearDCmd(outputStream* output, bool heap) : DCmd(output, heap) {}
613   static const char* name() {
614     return "Compiler.directives_clear";
615   }
616   static const char* description() {
617     return "Remove all compiler directives.";
618   }
619   static const char* impact() {
620     return "Low";
621   }
622   virtual void execute(DCmdSource source, TRAPS);
623 };
624 
625 ///////////////////////////////////////////////////////////////////////
626 //
627 // jcmd command support for symbol table, string table and system dictionary dumping:
628 //   VM.symboltable -verbose: for dumping the symbol table
629 //   VM.stringtable -verbose: for dumping the string table
630 //   VM.systemdictionary -verbose: for dumping the system dictionary table
631 //
632 class VM_DumpHashtable : public VM_Operation {
633 private:
634   outputStream* _out;
635   int _which;
636   bool _verbose;
637 public:
638   enum {
639     DumpSymbols = 1 << 0,
640     DumpStrings = 1 << 1,
641     DumpSysDict = 1 << 2  // not implemented yet
642   };
643   VM_DumpHashtable(outputStream* out, int which, bool verbose) {
644     _out = out;
645     _which = which;
646     _verbose = verbose;
647   }
648 
649   virtual VMOp_Type type() const { return VMOp_DumpHashtable; }
650 
651   virtual void doit() {
652     switch (_which) {
653     case DumpSymbols:
654       SymbolTable::dump(_out, _verbose);
655       break;
656     case DumpStrings:
657       StringTable::dump(_out, _verbose);
658       break;
659     case DumpSysDict:
660       SystemDictionary::dump(_out, _verbose);
661       break;
662     default:
663       ShouldNotReachHere();
664     }
665   }
666 };
667 
668 class SymboltableDCmd : public DCmdWithParser {
669 protected:
670   DCmdArgument<bool> _verbose;
671 public:
672   static int num_arguments() { return 1; }
673   SymboltableDCmd(outputStream* output, bool heap);
674   static const char* name() {
675     return "VM.symboltable";
676   }
677   static const char* description() {
678     return "Dump symbol table.";
679   }
680   static const char* impact() {
681     return "Medium: Depends on Java content.";
682   }
683   virtual void execute(DCmdSource source, TRAPS);
684 };
685 
686 class StringtableDCmd : public DCmdWithParser {
687 protected:
688   DCmdArgument<bool> _verbose;
689 public:
690   static int num_arguments() { return 1; }
691   StringtableDCmd(outputStream* output, bool heap);
692   static const char* name() {
693     return "VM.stringtable";
694   }
695   static const char* description() {
696     return "Dump string table.";
697   }
698   static const char* impact() {
699     return "Medium: Depends on Java content.";
700   }
701   virtual void execute(DCmdSource source, TRAPS);
702 };
703 
704 class SystemDictionaryDCmd : public DCmdWithParser {
705 protected:
706   DCmdArgument<bool> _verbose;
707 public:
708   static int num_arguments() { return 1; }
709   SystemDictionaryDCmd(outputStream* output, bool heap);
710   static const char* name() {
711     return "VM.systemdictionary";
712   }
713   static const char* description() {
714     return "Prints the statistics for dictionary hashtable sizes and bucket length";
715   }
716   static const char* impact() {
717       return "Medium: Depends on Java content.";
718   }
719   virtual void execute(DCmdSource source, TRAPS);
720 };
721 
722 class ClassesDCmd : public DCmdWithParser {
723 protected:
724   DCmdArgument<bool> _verbose;
725 public:
726   static int num_arguments() { return 1; }
727   ClassesDCmd(outputStream* output, bool heap);
728   static const char* name() {
729     return "VM.classes";
730   }
731   static const char* description() {
732     return "Print all loaded classes";
733   }
734   static const char* impact() {
735       return "Medium: Depends on number of loaded classes.";
736   }
737   virtual void execute(DCmdSource source, TRAPS);
738 };
739 
740 class EventLogDCmd : public DCmdWithParser {
741 protected:
742   DCmdArgument<char*> _log;
743   DCmdArgument<jlong> _max;
744 public:
745   static int num_arguments() { return 2; }
746   EventLogDCmd(outputStream* output, bool heap);
747   static const char* name() {
748     return "VM.events";
749   }
750   static const char* description() {
751     return "Print VM event logs";
752   }
753   static const char* impact() {
754     return "Low: Depends on event log size. ";
755   }
756   virtual void execute(DCmdSource source, TRAPS);
757 };
758 
759 class ThreadDumpToFileDCmd : public DCmdWithParser {
760 private:
761   void dumpToFile(Symbol* name, Symbol* signature, const char* path, bool overwrite, TRAPS);
762 protected:
763   DCmdArgument<bool> _overwrite;
764   DCmdArgument<char*> _format;
765   DCmdArgument<char*> _filepath;
766 public:
767   static int num_arguments() { return 3; }
768   ThreadDumpToFileDCmd(outputStream *output, bool heap);
769   static const char *name() {
770     return "Thread.dump_to_file";
771   }
772   static const char *description() {
773     return "Dump all threads, with stack traces, "
774            "to a file in plain text or JSON format.";
775   }
776   static const char* impact() {
777     return "Medium: Depends on the number of threads.";
778   }
779   virtual void execute(DCmdSource source, TRAPS);
780 };
781 
782 class VThreadSchedulerDCmd : public DCmd {
783 public:
784   VThreadSchedulerDCmd(outputStream* output, bool heap) : DCmd(output, heap) { }
785   static const char* name() {
786     return "Thread.vthread_scheduler";
787   }
788   static const char* description() {
789     return "Print the virtual thread scheduler, and the delayed task schedulers that support "
790            "virtual threads doing timed operations.";
791   }
792   static const char* impact() { return "Low"; }
793   virtual void execute(DCmdSource source, TRAPS);
794 };
795 
796 class VThreadPollersDCmd : public DCmd {
797 public:
798   VThreadPollersDCmd(outputStream* output, bool heap) : DCmd(output, heap) { }
799   static const char* name() {
800     return "Thread.vthread_pollers";
801   }
802   static const char* description() {
803     return "Print the I/O pollers that support virtual threads doing blocking network I/O operations.";
804   }
805   static const char* impact() { return "Low"; }
806   virtual void execute(DCmdSource source, TRAPS);
807 };
808 
809 class CompilationMemoryStatisticDCmd: public DCmdWithParser {
810 protected:
811   DCmdArgument<bool> _verbose;
812   DCmdArgument<bool> _legend;
813   DCmdArgument<MemorySizeArgument> _minsize;
814 public:
815   static int num_arguments() { return 3; }
816   CompilationMemoryStatisticDCmd(outputStream* output, bool heap);
817   static const char* name() {
818     return "Compiler.memory";
819   }
820   static const char* description() {
821     return "Print compilation footprint";
822   }
823   static const char* impact() {
824     return "Medium: Pause time depends on number of compiled methods";
825   }
826   virtual void execute(DCmdSource source, TRAPS);
827 };
828 
829 #if defined(LINUX) || defined(_WIN64) || defined(__APPLE__)
830 
831 class SystemMapDCmd : public DCmd {
832 public:
833   SystemMapDCmd(outputStream* output, bool heap);
834   static const char* name() { return "System.map"; }
835   static const char* description() {
836     return "Prints an annotated process memory map of the VM process (linux, Windows and MacOS only).";
837   }
838   static const char* impact() { return "Medium; can be high for very large java heaps."; }
839   virtual void execute(DCmdSource source, TRAPS);
840 };
841 
842 class SystemDumpMapDCmd : public DCmdWithParser {
843   DCmdArgument<char*> _filename;
844 public:
845   static int num_arguments() { return 1; }
846   SystemDumpMapDCmd(outputStream* output, bool heap);
847   static const char* name() { return "System.dump_map"; }
848   static const char* description() {
849     return "Dumps an annotated process memory map to an output file (linux, Windows and MacOS only).";
850   }
851   static const char* impact() { return "Medium; can be high for very large java heaps."; }
852   virtual void execute(DCmdSource source, TRAPS);
853 };
854 
855 #endif // LINUX, WINDOWS or MACOS
856 
857 #endif // SHARE_SERVICES_DIAGNOSTICCOMMAND_HPP