< prev index next >

src/hotspot/share/services/diagnosticCommand.cpp

Print this page

   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  *

  31 #include "classfile/javaClasses.hpp"
  32 #include "classfile/systemDictionary.hpp"
  33 #include "classfile/vmClasses.hpp"
  34 #include "code/codeCache.hpp"
  35 #include "compiler/compilationMemoryStatistic.hpp"
  36 #include "compiler/compileBroker.hpp"
  37 #include "compiler/compiler_globals.hpp"
  38 #include "compiler/directivesParser.hpp"
  39 #include "gc/shared/gcVMOperations.hpp"
  40 #include "jvm.h"
  41 #include "memory/metaspace/metaspaceDCmd.hpp"
  42 #include "memory/metaspaceUtils.hpp"
  43 #include "memory/resourceArea.hpp"
  44 #include "memory/universe.hpp"
  45 #include "nmt/memMapPrinter.hpp"
  46 #include "nmt/memTracker.hpp"
  47 #include "nmt/nmtDCmd.hpp"
  48 #include "oops/instanceKlass.hpp"
  49 #include "oops/objArrayOop.inline.hpp"
  50 #include "oops/oop.inline.hpp"

  51 #include "oops/typeArrayOop.inline.hpp"
  52 #include "prims/jvmtiAgentList.hpp"
  53 #include "runtime/fieldDescriptor.inline.hpp"
  54 #include "runtime/flags/jvmFlag.hpp"
  55 #include "runtime/handles.inline.hpp"
  56 #include "runtime/javaCalls.hpp"
  57 #include "runtime/jniHandles.hpp"
  58 #include "runtime/os.hpp"
  59 #include "runtime/vm_version.hpp"
  60 #include "runtime/vmOperations.hpp"
  61 #include "services/diagnosticArgument.hpp"
  62 #include "services/diagnosticCommand.hpp"
  63 #include "services/diagnosticFramework.hpp"
  64 #include "services/heapDumper.hpp"
  65 #include "services/management.hpp"
  66 #include "services/writeableFlags.hpp"
  67 #include "utilities/debug.hpp"
  68 #include "utilities/events.hpp"
  69 #include "utilities/formatBuffer.hpp"
  70 #include "utilities/macros.hpp"

 100   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CommandLineDCmd>(full_export));
 101   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PrintSystemPropertiesDCmd>(full_export));
 102   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PrintVMFlagsDCmd>(full_export));
 103   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SetVMFlagDCmd>(full_export));
 104   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMDynamicLibrariesDCmd>(full_export));
 105   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMUptimeDCmd>(full_export));
 106   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMInfoDCmd>(full_export));
 107   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SystemGCDCmd>(full_export));
 108   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<RunFinalizationDCmd>(full_export));
 109   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HeapInfoDCmd>(full_export));
 110   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<FinalizerInfoDCmd>(full_export));
 111 #if INCLUDE_SERVICES
 112   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HeapDumpDCmd>(DCmd_Source_Internal | DCmd_Source_AttachAPI));
 113   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassHistogramDCmd>(full_export));
 114   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SystemDictionaryDCmd>(full_export));
 115   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassHierarchyDCmd>(full_export));
 116   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassesDCmd>(full_export));
 117   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SymboltableDCmd>(full_export));
 118   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<StringtableDCmd>(full_export));
 119   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<metaspace::MetaspaceDCmd>(full_export));

 120   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<EventLogDCmd>(full_export));
 121 #if INCLUDE_JVMTI // Both JVMTI and SERVICES have to be enabled to have this dcmd
 122   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JVMTIAgentLoadDCmd>(full_export));
 123 #endif // INCLUDE_JVMTI
 124 #endif // INCLUDE_SERVICES
 125 #if INCLUDE_JVMTI
 126   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JVMTIDataDumpDCmd>(full_export));
 127 #endif // INCLUDE_JVMTI
 128   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ThreadDumpDCmd>(full_export));
 129 #if INCLUDE_JVMTI
 130   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ThreadDumpToFileDCmd>(full_export));
 131 #endif // INCLUDE_JVMTI
 132   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VThreadSchedulerDCmd>(full_export));
 133   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VThreadPollersDCmd>(full_export));
 134   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassLoaderStatsDCmd>(full_export));
 135   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassLoaderHierarchyDCmd>(full_export));
 136   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompileQueueDCmd>(full_export));
 137   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CodeListDCmd>(full_export));
 138   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CodeCacheDCmd>(full_export));
 139 #ifdef LINUX

 417 void FinalizerInfoDCmd::execute(DCmdSource source, TRAPS) {
 418   ResourceMark rm(THREAD);
 419 
 420   if (!InstanceKlass::is_finalization_enabled()) {
 421     output()->print_cr("Finalization is disabled");
 422     return;
 423   }
 424 
 425   Klass* k = SystemDictionary::resolve_or_fail(
 426     vmSymbols::finalizer_histogram_klass(), true, CHECK);
 427 
 428   JavaValue result(T_ARRAY);
 429 
 430   // We are calling lang.ref.FinalizerHistogram.getFinalizerHistogram() method
 431   // and expect it to return array of FinalizerHistogramEntry as Object[]
 432 
 433   JavaCalls::call_static(&result, k,
 434                          vmSymbols::get_finalizer_histogram_name(),
 435                          vmSymbols::void_finalizer_histogram_entry_array_signature(), CHECK);
 436 
 437   objArrayOop result_oop = (objArrayOop) result.get_oop();
 438   if (result_oop->length() == 0) {
 439     output()->print_cr("No instances waiting for finalization found");
 440     return;
 441   }
 442 
 443   oop foop = result_oop->obj_at(0);
 444   InstanceKlass* ik = InstanceKlass::cast(foop->klass());
 445 
 446   fieldDescriptor count_fd, name_fd;
 447 
 448   Klass* count_res = ik->find_field(
 449     vmSymbols::finalizer_histogram_entry_count_field(), vmSymbols::int_signature(), &count_fd);
 450 
 451   Klass* name_res = ik->find_field(
 452     vmSymbols::finalizer_histogram_entry_name_field(), vmSymbols::string_signature(), &name_fd);
 453 
 454   assert(count_res != nullptr && name_res != nullptr, "Unexpected layout of FinalizerHistogramEntry");
 455 
 456   output()->print_cr("Unreachable instances waiting for finalization");
 457   output()->print_cr("#instances  class name");

 928 #if INCLUDE_SERVICES
 929 ClassHierarchyDCmd::ClassHierarchyDCmd(outputStream* output, bool heap) :
 930                                        DCmdWithParser(output, heap),
 931   _print_interfaces("-i", "Inherited interfaces should be printed.", "BOOLEAN", false, "false"),
 932   _print_subclasses("-s", "If a classname is specified, print its subclasses "
 933                     "in addition to its superclasses. Without this option only the "
 934                     "superclasses will be printed.", "BOOLEAN", false, "false"),
 935   _classname("classname", "Name of class whose hierarchy should be printed. "
 936              "If not specified, all class hierarchies are printed.",
 937              "STRING", false) {
 938   _dcmdparser.add_dcmd_option(&_print_interfaces);
 939   _dcmdparser.add_dcmd_option(&_print_subclasses);
 940   _dcmdparser.add_dcmd_argument(&_classname);
 941 }
 942 
 943 void ClassHierarchyDCmd::execute(DCmdSource source, TRAPS) {
 944   VM_PrintClassHierarchy printClassHierarchyOp(output(), _print_interfaces.value(),
 945                                                _print_subclasses.value(), _classname.value());
 946   VMThread::execute(&printClassHierarchyOp);
 947 }
 948 #endif
























 949 
 950 ClassesDCmd::ClassesDCmd(outputStream* output, bool heap) :
 951                                      DCmdWithParser(output, heap),
 952   _verbose("-verbose",
 953            "Dump the detailed content of a Java class. "
 954            "Some classes are annotated with flags: "
 955            "F = has, or inherits, a non-empty finalize method, "
 956            "f = has final method, "
 957            "W = methods rewritten, "
 958            "C = marked with @Contended annotation, "
 959            "R = has been redefined, "
 960            "S = is shared class",
 961            "BOOLEAN", false, "false") {
 962   _dcmdparser.add_dcmd_option(&_verbose);
 963 }
 964 
 965 class VM_PrintClasses : public VM_Operation {
 966 private:
 967   outputStream* _out;
 968   bool _verbose;

   1 /*
   2  * Copyright (c) 2011, 2026, 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  *

  31 #include "classfile/javaClasses.hpp"
  32 #include "classfile/systemDictionary.hpp"
  33 #include "classfile/vmClasses.hpp"
  34 #include "code/codeCache.hpp"
  35 #include "compiler/compilationMemoryStatistic.hpp"
  36 #include "compiler/compileBroker.hpp"
  37 #include "compiler/compiler_globals.hpp"
  38 #include "compiler/directivesParser.hpp"
  39 #include "gc/shared/gcVMOperations.hpp"
  40 #include "jvm.h"
  41 #include "memory/metaspace/metaspaceDCmd.hpp"
  42 #include "memory/metaspaceUtils.hpp"
  43 #include "memory/resourceArea.hpp"
  44 #include "memory/universe.hpp"
  45 #include "nmt/memMapPrinter.hpp"
  46 #include "nmt/memTracker.hpp"
  47 #include "nmt/nmtDCmd.hpp"
  48 #include "oops/instanceKlass.hpp"
  49 #include "oops/objArrayOop.inline.hpp"
  50 #include "oops/oop.inline.hpp"
  51 #include "oops/oopCast.inline.hpp"
  52 #include "oops/typeArrayOop.inline.hpp"
  53 #include "prims/jvmtiAgentList.hpp"
  54 #include "runtime/fieldDescriptor.inline.hpp"
  55 #include "runtime/flags/jvmFlag.hpp"
  56 #include "runtime/handles.inline.hpp"
  57 #include "runtime/javaCalls.hpp"
  58 #include "runtime/jniHandles.hpp"
  59 #include "runtime/os.hpp"
  60 #include "runtime/vm_version.hpp"
  61 #include "runtime/vmOperations.hpp"
  62 #include "services/diagnosticArgument.hpp"
  63 #include "services/diagnosticCommand.hpp"
  64 #include "services/diagnosticFramework.hpp"
  65 #include "services/heapDumper.hpp"
  66 #include "services/management.hpp"
  67 #include "services/writeableFlags.hpp"
  68 #include "utilities/debug.hpp"
  69 #include "utilities/events.hpp"
  70 #include "utilities/formatBuffer.hpp"
  71 #include "utilities/macros.hpp"

 101   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CommandLineDCmd>(full_export));
 102   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PrintSystemPropertiesDCmd>(full_export));
 103   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PrintVMFlagsDCmd>(full_export));
 104   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SetVMFlagDCmd>(full_export));
 105   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMDynamicLibrariesDCmd>(full_export));
 106   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMUptimeDCmd>(full_export));
 107   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMInfoDCmd>(full_export));
 108   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SystemGCDCmd>(full_export));
 109   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<RunFinalizationDCmd>(full_export));
 110   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HeapInfoDCmd>(full_export));
 111   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<FinalizerInfoDCmd>(full_export));
 112 #if INCLUDE_SERVICES
 113   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HeapDumpDCmd>(DCmd_Source_Internal | DCmd_Source_AttachAPI));
 114   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassHistogramDCmd>(full_export));
 115   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SystemDictionaryDCmd>(full_export));
 116   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassHierarchyDCmd>(full_export));
 117   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassesDCmd>(full_export));
 118   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SymboltableDCmd>(full_export));
 119   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<StringtableDCmd>(full_export));
 120   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<metaspace::MetaspaceDCmd>(full_export));
 121   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PrintClassLayoutDCmd>(full_export));
 122   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<EventLogDCmd>(full_export));
 123 #if INCLUDE_JVMTI // Both JVMTI and SERVICES have to be enabled to have this dcmd
 124   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JVMTIAgentLoadDCmd>(full_export));
 125 #endif // INCLUDE_JVMTI
 126 #endif // INCLUDE_SERVICES
 127 #if INCLUDE_JVMTI
 128   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JVMTIDataDumpDCmd>(full_export));
 129 #endif // INCLUDE_JVMTI
 130   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ThreadDumpDCmd>(full_export));
 131 #if INCLUDE_JVMTI
 132   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ThreadDumpToFileDCmd>(full_export));
 133 #endif // INCLUDE_JVMTI
 134   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VThreadSchedulerDCmd>(full_export));
 135   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VThreadPollersDCmd>(full_export));
 136   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassLoaderStatsDCmd>(full_export));
 137   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassLoaderHierarchyDCmd>(full_export));
 138   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompileQueueDCmd>(full_export));
 139   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CodeListDCmd>(full_export));
 140   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CodeCacheDCmd>(full_export));
 141 #ifdef LINUX

 419 void FinalizerInfoDCmd::execute(DCmdSource source, TRAPS) {
 420   ResourceMark rm(THREAD);
 421 
 422   if (!InstanceKlass::is_finalization_enabled()) {
 423     output()->print_cr("Finalization is disabled");
 424     return;
 425   }
 426 
 427   Klass* k = SystemDictionary::resolve_or_fail(
 428     vmSymbols::finalizer_histogram_klass(), true, CHECK);
 429 
 430   JavaValue result(T_ARRAY);
 431 
 432   // We are calling lang.ref.FinalizerHistogram.getFinalizerHistogram() method
 433   // and expect it to return array of FinalizerHistogramEntry as Object[]
 434 
 435   JavaCalls::call_static(&result, k,
 436                          vmSymbols::get_finalizer_histogram_name(),
 437                          vmSymbols::void_finalizer_histogram_entry_array_signature(), CHECK);
 438 
 439   refArrayOop result_oop = oop_cast<refArrayOop>(result.get_oop());
 440   if (result_oop->length() == 0) {
 441     output()->print_cr("No instances waiting for finalization found");
 442     return;
 443   }
 444 
 445   oop foop = result_oop->obj_at(0);
 446   InstanceKlass* ik = InstanceKlass::cast(foop->klass());
 447 
 448   fieldDescriptor count_fd, name_fd;
 449 
 450   Klass* count_res = ik->find_field(
 451     vmSymbols::finalizer_histogram_entry_count_field(), vmSymbols::int_signature(), &count_fd);
 452 
 453   Klass* name_res = ik->find_field(
 454     vmSymbols::finalizer_histogram_entry_name_field(), vmSymbols::string_signature(), &name_fd);
 455 
 456   assert(count_res != nullptr && name_res != nullptr, "Unexpected layout of FinalizerHistogramEntry");
 457 
 458   output()->print_cr("Unreachable instances waiting for finalization");
 459   output()->print_cr("#instances  class name");

 930 #if INCLUDE_SERVICES
 931 ClassHierarchyDCmd::ClassHierarchyDCmd(outputStream* output, bool heap) :
 932                                        DCmdWithParser(output, heap),
 933   _print_interfaces("-i", "Inherited interfaces should be printed.", "BOOLEAN", false, "false"),
 934   _print_subclasses("-s", "If a classname is specified, print its subclasses "
 935                     "in addition to its superclasses. Without this option only the "
 936                     "superclasses will be printed.", "BOOLEAN", false, "false"),
 937   _classname("classname", "Name of class whose hierarchy should be printed. "
 938              "If not specified, all class hierarchies are printed.",
 939              "STRING", false) {
 940   _dcmdparser.add_dcmd_option(&_print_interfaces);
 941   _dcmdparser.add_dcmd_option(&_print_subclasses);
 942   _dcmdparser.add_dcmd_argument(&_classname);
 943 }
 944 
 945 void ClassHierarchyDCmd::execute(DCmdSource source, TRAPS) {
 946   VM_PrintClassHierarchy printClassHierarchyOp(output(), _print_interfaces.value(),
 947                                                _print_subclasses.value(), _classname.value());
 948   VMThread::execute(&printClassHierarchyOp);
 949 }
 950 
 951 PrintClassLayoutDCmd::PrintClassLayoutDCmd(outputStream* output, bool heap) :
 952                                        DCmdWithParser(output, heap),
 953   _classname("classname", "Name of class whose layout should be printed. ",
 954              "STRING", true) {
 955   _dcmdparser.add_dcmd_argument(&_classname);
 956 }
 957 
 958 void PrintClassLayoutDCmd::execute(DCmdSource source, TRAPS) {
 959   VM_PrintClassLayout printClassLayoutOp(output(), _classname.value());
 960   VMThread::execute(&printClassLayoutOp);
 961 }
 962 
 963 int PrintClassLayoutDCmd::num_arguments() {
 964   ResourceMark rm;
 965   PrintClassLayoutDCmd* dcmd = new PrintClassLayoutDCmd(nullptr, false);
 966   if (dcmd != nullptr) {
 967     DCmdMark mark(dcmd);
 968     return dcmd->_dcmdparser.num_arguments();
 969   } else {
 970     return 0;
 971   }
 972 }
 973 
 974 #endif // INCLUDE_SERVICES
 975 
 976 ClassesDCmd::ClassesDCmd(outputStream* output, bool heap) :
 977                                      DCmdWithParser(output, heap),
 978   _verbose("-verbose",
 979            "Dump the detailed content of a Java class. "
 980            "Some classes are annotated with flags: "
 981            "F = has, or inherits, a non-empty finalize method, "
 982            "f = has final method, "
 983            "W = methods rewritten, "
 984            "C = marked with @Contended annotation, "
 985            "R = has been redefined, "
 986            "S = is shared class",
 987            "BOOLEAN", false, "false") {
 988   _dcmdparser.add_dcmd_option(&_verbose);
 989 }
 990 
 991 class VM_PrintClasses : public VM_Operation {
 992 private:
 993   outputStream* _out;
 994   bool _verbose;
< prev index next >