< 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"

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

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

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
























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

 102   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PrintSystemPropertiesDCmd>(full_export));
 103   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PrintSecurityPropertiesDCmd>(full_export));
 104   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PrintVMFlagsDCmd>(full_export));
 105   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SetVMFlagDCmd>(full_export));
 106   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMDynamicLibrariesDCmd>(full_export));
 107   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMUptimeDCmd>(full_export));
 108   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMInfoDCmd>(full_export));
 109   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SystemGCDCmd>(full_export));
 110   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<RunFinalizationDCmd>(full_export));
 111   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HeapInfoDCmd>(full_export));
 112   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<FinalizerInfoDCmd>(full_export));
 113 #if INCLUDE_SERVICES
 114   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HeapDumpDCmd>(DCmd_Source_Internal | DCmd_Source_AttachAPI));
 115   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassHistogramDCmd>(full_export));
 116   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SystemDictionaryDCmd>(full_export));
 117   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassHierarchyDCmd>(full_export));
 118   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassesDCmd>(full_export));
 119   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SymboltableDCmd>(full_export));
 120   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<StringtableDCmd>(full_export));
 121   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<metaspace::MetaspaceDCmd>(full_export));
 122   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PrintClassLayoutDCmd>(full_export));
 123   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<EventLogDCmd>(full_export));
 124 #if INCLUDE_JVMTI // Both JVMTI and SERVICES have to be enabled to have this dcmd
 125   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JVMTIAgentLoadDCmd>(full_export));
 126 #endif // INCLUDE_JVMTI
 127 #endif // INCLUDE_SERVICES
 128 #if INCLUDE_JVMTI
 129   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JVMTIDataDumpDCmd>(full_export));
 130 #endif // INCLUDE_JVMTI
 131   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ThreadDumpDCmd>(full_export));
 132 #if INCLUDE_JVMTI
 133   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ThreadDumpToFileDCmd>(full_export));
 134 #endif // INCLUDE_JVMTI
 135   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VThreadSchedulerDCmd>(full_export));
 136   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VThreadPollersDCmd>(full_export));
 137   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassLoaderStatsDCmd>(full_export));
 138   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassLoaderHierarchyDCmd>(full_export));
 139   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompileQueueDCmd>(full_export));
 140   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CodeListDCmd>(full_export));
 141   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CodeCacheDCmd>(full_export));
 142 #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   refArrayOop result_oop = oop_cast<refArrayOop>(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 
 949 PrintClassLayoutDCmd::PrintClassLayoutDCmd(outputStream* output, bool heap) :
 950                                        DCmdWithParser(output, heap),
 951   _classname("classname", "Name of class whose layout should be printed. ",
 952              "STRING", true) {
 953   _dcmdparser.add_dcmd_argument(&_classname);
 954 }
 955 
 956 void PrintClassLayoutDCmd::execute(DCmdSource source, TRAPS) {
 957   VM_PrintClassLayout printClassLayoutOp(output(), _classname.value());
 958   VMThread::execute(&printClassLayoutOp);
 959 }
 960 
 961 int PrintClassLayoutDCmd::num_arguments() {
 962   ResourceMark rm;
 963   PrintClassLayoutDCmd* dcmd = new PrintClassLayoutDCmd(nullptr, false);
 964   if (dcmd != nullptr) {
 965     DCmdMark mark(dcmd);
 966     return dcmd->_dcmdparser.num_arguments();
 967   } else {
 968     return 0;
 969   }
 970 }
 971 
 972 #endif // INCLUDE_SERVICES
 973 
 974 ClassesDCmd::ClassesDCmd(outputStream* output, bool heap) :
 975                                      DCmdWithParser(output, heap),
 976   _verbose("-verbose",
 977            "Dump the detailed content of a Java class. "
 978            "Some classes are annotated with flags: "
 979            "F = has, or inherits, a non-empty finalize method, "
 980            "f = has final method, "
 981            "W = methods rewritten, "
 982            "C = marked with @Contended annotation, "
 983            "R = has been redefined, "
 984            "S = is shared class",
 985            "BOOLEAN", false, "false") {
 986   _dcmdparser.add_dcmd_option(&_verbose);
 987 }
 988 
 989 class VM_PrintClasses : public VM_Operation {
 990 private:
 991   outputStream* _out;
 992   bool _verbose;
< prev index next >