< prev index next >

src/hotspot/share/services/diagnosticCommand.cpp

Print this page


   1 /*
   2  * Copyright (c) 2011, 2019, 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 "gc/shared/gcVMOperations.hpp"
  32 #include "memory/metaspace/metaspaceDCmd.hpp"
  33 #include "memory/resourceArea.hpp"
  34 #include "memory/universe.hpp"
  35 #include "oops/objArrayOop.inline.hpp"
  36 #include "oops/oop.inline.hpp"
  37 #include "oops/typeArrayOop.inline.hpp"
  38 #include "runtime/fieldDescriptor.inline.hpp"
  39 #include "runtime/flags/jvmFlag.hpp"
  40 #include "runtime/handles.inline.hpp"
  41 #include "runtime/interfaceSupport.inline.hpp"
  42 #include "runtime/javaCalls.hpp"
  43 #include "runtime/os.hpp"
  44 #include "services/diagnosticArgument.hpp"
  45 #include "services/diagnosticCommand.hpp"
  46 #include "services/diagnosticFramework.hpp"
  47 #include "services/heapDumper.hpp"
  48 #include "services/management.hpp"
  49 #include "services/writeableFlags.hpp"
  50 #include "utilities/debug.hpp"
  51 #include "utilities/events.hpp"
  52 #include "utilities/formatBuffer.hpp"
  53 #include "utilities/macros.hpp"
  54 
  55 
  56 static void loadAgentModule(TRAPS) {
  57   ResourceMark rm(THREAD);
  58   HandleMark hm(THREAD);
  59 
  60   JavaValue result(T_OBJECT);
  61   Handle h_module_name = java_lang_String::create_from_str("jdk.management.agent", CHECK);
  62   JavaCalls::call_static(&result,
  63                          SystemDictionary::module_Modules_klass(),
  64                          vmSymbols::loadModule_name(),
  65                          vmSymbols::loadModule_signature(),
  66                          h_module_name,
  67                          THREAD);
  68 }
  69 
  70 void DCmdRegistrant::register_dcmds(){
  71   // Registration of the diagnostic commands


  79   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CommandLineDCmd>(full_export, true, false));
  80   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PrintSystemPropertiesDCmd>(full_export, true, false));
  81   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PrintVMFlagsDCmd>(full_export, true, false));
  82   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SetVMFlagDCmd>(full_export, true, false));
  83   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMDynamicLibrariesDCmd>(full_export, true, false));
  84   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMUptimeDCmd>(full_export, true, false));
  85   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMInfoDCmd>(full_export, true, false));
  86   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SystemGCDCmd>(full_export, true, false));
  87   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<RunFinalizationDCmd>(full_export, true, false));
  88   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HeapInfoDCmd>(full_export, true, false));
  89   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<FinalizerInfoDCmd>(full_export, true, false));
  90 #if INCLUDE_SERVICES
  91   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HeapDumpDCmd>(DCmd_Source_Internal | DCmd_Source_AttachAPI, true, false));
  92   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassHistogramDCmd>(full_export, true, false));
  93   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassStatsDCmd>(full_export, true, false));
  94   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SystemDictionaryDCmd>(full_export, true, false));
  95   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassHierarchyDCmd>(full_export, true, false));
  96   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SymboltableDCmd>(full_export, true, false));
  97   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<StringtableDCmd>(full_export, true, false));
  98   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<metaspace::MetaspaceDCmd>(full_export, true, false));
  99   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<EventLogDCmd>(full_export, true, false));
 100 #if INCLUDE_JVMTI // Both JVMTI and SERVICES have to be enabled to have this dcmd
 101   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JVMTIAgentLoadDCmd>(full_export, true, false));
 102 #endif // INCLUDE_JVMTI
 103 #endif // INCLUDE_SERVICES
 104 #if INCLUDE_JVMTI
 105   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JVMTIDataDumpDCmd>(full_export, true, false));
 106 #endif // INCLUDE_JVMTI
 107   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ThreadDumpDCmd>(full_export, true, false));
 108   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassLoaderStatsDCmd>(full_export, true, false));
 109   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassLoaderHierarchyDCmd>(full_export, true, false));
 110   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompileQueueDCmd>(full_export, true, false));
 111   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CodeListDCmd>(full_export, true, false));
 112   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CodeCacheDCmd>(full_export, true, false));
 113   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<TouchedMethodsDCmd>(full_export, true, false));
 114   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CodeHeapAnalyticsDCmd>(full_export, true, false));
 115 
 116   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompilerDirectivesPrintDCmd>(full_export, true, false));
 117   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompilerDirectivesAddDCmd>(full_export, true, false));
 118   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompilerDirectivesRemoveDCmd>(full_export, true, false));
 119   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompilerDirectivesClearDCmd>(full_export, true, false));


 929   output()->cr();
 930 }
 931 
 932 void CompileQueueDCmd::execute(DCmdSource source, TRAPS) {
 933   VM_PrintCompileQueue printCompileQueueOp(output());
 934   VMThread::execute(&printCompileQueueOp);
 935 }
 936 
 937 void CodeListDCmd::execute(DCmdSource source, TRAPS) {
 938   CodeCache::print_codelist(output());
 939 }
 940 
 941 void CodeCacheDCmd::execute(DCmdSource source, TRAPS) {
 942   CodeCache::print_layout(output());
 943 }
 944 
 945 //---<  BEGIN  >--- CodeHeap State Analytics.
 946 CodeHeapAnalyticsDCmd::CodeHeapAnalyticsDCmd(outputStream* output, bool heap) :
 947                                              DCmdWithParser(output, heap),
 948   _function("function", "Function to be performed (aggregate, UsedSpace, FreeSpace, MethodCount, MethodSpace, MethodAge, MethodNames, discard", "STRING", false, "all"),
 949   _granularity("granularity", "Detail level - smaller value -> more detail", "INT", false, "4096") {
 950   _dcmdparser.add_dcmd_argument(&_function);
 951   _dcmdparser.add_dcmd_argument(&_granularity);
 952 }
 953 
 954 void CodeHeapAnalyticsDCmd::execute(DCmdSource source, TRAPS) {
 955   jlong granularity = _granularity.value();
 956   if (granularity < 1) {
 957     Exceptions::fthrow(THREAD_AND_LOCATION, vmSymbols::java_lang_IllegalArgumentException(),
 958                        "Invalid granularity value " JLONG_FORMAT  ". Should be positive.\n", granularity);
 959     return;
 960   }
 961 
 962   CompileBroker::print_heapinfo(output(), _function.value(), granularity);
 963 }
 964 
 965 int CodeHeapAnalyticsDCmd::num_arguments() {
 966   ResourceMark rm;
 967   CodeHeapAnalyticsDCmd* dcmd = new CodeHeapAnalyticsDCmd(NULL, false);
 968   if (dcmd != NULL) {
 969     DCmdMark mark(dcmd);
 970     return dcmd->_dcmdparser.num_arguments();
 971   } else {
 972     return 0;
 973   }
 974 }
 975 //---<  END  >--- CodeHeap State Analytics.
 976 
 977 EventLogDCmd::EventLogDCmd(outputStream* output, bool heap) :
 978   DCmdWithParser(output, heap),
 979   _log("log", "Name of log to be printed. If omitted, all logs are printed.", "STRING", false, NULL),
 980   _max("max", "Maximum number of events to be printed (newest first). If omitted, all events are printed.", "STRING", false, NULL)
 981 {
 982   _dcmdparser.add_dcmd_option(&_log);
 983   _dcmdparser.add_dcmd_option(&_max);
 984 }
 985 
 986 void EventLogDCmd::execute(DCmdSource source, TRAPS) {
 987   const char* max_value = _max.value();
 988   long max = -1;
 989   if (max_value != NULL) {
 990     char* endptr = NULL;
 991     max = ::strtol(max_value, &endptr, 10);
 992     if (max == 0 && max_value == endptr) {
 993       output()->print_cr("Invalid max option: \"%s\".", max_value);
 994       return;
 995     }
 996   }
 997   const char* log_name = _log.value();
 998   if (log_name != NULL) {
 999     Events::print_one(output(), log_name, max);
1000   } else {
1001     Events::print_all(output(), max);
1002   }
1003 }
1004 
1005 int EventLogDCmd::num_arguments() {
1006   ResourceMark rm;
1007   EventLogDCmd* dcmd = new EventLogDCmd(NULL, false);
1008   if (dcmd != NULL) {
1009     DCmdMark mark(dcmd);
1010     return dcmd->_dcmdparser.num_arguments();
1011   } else {
1012     return 0;
1013   }
1014 }
1015 
1016 void CompilerDirectivesPrintDCmd::execute(DCmdSource source, TRAPS) {
1017   DirectivesStack::print(output());
1018 }
1019 
1020 CompilerDirectivesAddDCmd::CompilerDirectivesAddDCmd(outputStream* output, bool heap) :
1021                            DCmdWithParser(output, heap),
1022   _filename("filename","Name of the directives file", "STRING",true) {
1023   _dcmdparser.add_dcmd_argument(&_filename);
1024 }
1025 
1026 void CompilerDirectivesAddDCmd::execute(DCmdSource source, TRAPS) {
1027   DirectivesParser::parse_from_file(_filename.value(), output());
1028 }
1029 
1030 int CompilerDirectivesAddDCmd::num_arguments() {
1031   ResourceMark rm;
1032   CompilerDirectivesAddDCmd* dcmd = new CompilerDirectivesAddDCmd(NULL, false);
1033   if (dcmd != NULL) {
1034     DCmdMark mark(dcmd);


   1 /*
   2  * Copyright (c) 2011, 2018, 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 "gc/shared/gcVMOperations.hpp"
  32 #include "memory/metaspace/metaspaceDCmd.hpp"
  33 #include "memory/resourceArea.hpp"
  34 #include "memory/universe.hpp"
  35 #include "oops/objArrayOop.inline.hpp"
  36 #include "oops/oop.inline.hpp"
  37 #include "oops/typeArrayOop.inline.hpp"
  38 #include "runtime/fieldDescriptor.inline.hpp"
  39 #include "runtime/flags/jvmFlag.hpp"
  40 #include "runtime/handles.inline.hpp"
  41 #include "runtime/interfaceSupport.inline.hpp"
  42 #include "runtime/javaCalls.hpp"
  43 #include "runtime/os.hpp"
  44 #include "services/diagnosticArgument.hpp"
  45 #include "services/diagnosticCommand.hpp"
  46 #include "services/diagnosticFramework.hpp"
  47 #include "services/heapDumper.hpp"
  48 #include "services/management.hpp"
  49 #include "services/writeableFlags.hpp"
  50 #include "utilities/debug.hpp"

  51 #include "utilities/formatBuffer.hpp"
  52 #include "utilities/macros.hpp"
  53 
  54 
  55 static void loadAgentModule(TRAPS) {
  56   ResourceMark rm(THREAD);
  57   HandleMark hm(THREAD);
  58 
  59   JavaValue result(T_OBJECT);
  60   Handle h_module_name = java_lang_String::create_from_str("jdk.management.agent", CHECK);
  61   JavaCalls::call_static(&result,
  62                          SystemDictionary::module_Modules_klass(),
  63                          vmSymbols::loadModule_name(),
  64                          vmSymbols::loadModule_signature(),
  65                          h_module_name,
  66                          THREAD);
  67 }
  68 
  69 void DCmdRegistrant::register_dcmds(){
  70   // Registration of the diagnostic commands


  78   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CommandLineDCmd>(full_export, true, false));
  79   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PrintSystemPropertiesDCmd>(full_export, true, false));
  80   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PrintVMFlagsDCmd>(full_export, true, false));
  81   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SetVMFlagDCmd>(full_export, true, false));
  82   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMDynamicLibrariesDCmd>(full_export, true, false));
  83   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMUptimeDCmd>(full_export, true, false));
  84   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMInfoDCmd>(full_export, true, false));
  85   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SystemGCDCmd>(full_export, true, false));
  86   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<RunFinalizationDCmd>(full_export, true, false));
  87   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HeapInfoDCmd>(full_export, true, false));
  88   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<FinalizerInfoDCmd>(full_export, true, false));
  89 #if INCLUDE_SERVICES
  90   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HeapDumpDCmd>(DCmd_Source_Internal | DCmd_Source_AttachAPI, true, false));
  91   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassHistogramDCmd>(full_export, true, false));
  92   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassStatsDCmd>(full_export, true, false));
  93   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SystemDictionaryDCmd>(full_export, true, false));
  94   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassHierarchyDCmd>(full_export, true, false));
  95   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SymboltableDCmd>(full_export, true, false));
  96   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<StringtableDCmd>(full_export, true, false));
  97   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<metaspace::MetaspaceDCmd>(full_export, true, false));

  98 #if INCLUDE_JVMTI // Both JVMTI and SERVICES have to be enabled to have this dcmd
  99   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JVMTIAgentLoadDCmd>(full_export, true, false));
 100 #endif // INCLUDE_JVMTI
 101 #endif // INCLUDE_SERVICES
 102 #if INCLUDE_JVMTI
 103   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JVMTIDataDumpDCmd>(full_export, true, false));
 104 #endif // INCLUDE_JVMTI
 105   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ThreadDumpDCmd>(full_export, true, false));
 106   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassLoaderStatsDCmd>(full_export, true, false));
 107   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassLoaderHierarchyDCmd>(full_export, true, false));
 108   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompileQueueDCmd>(full_export, true, false));
 109   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CodeListDCmd>(full_export, true, false));
 110   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CodeCacheDCmd>(full_export, true, false));
 111   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<TouchedMethodsDCmd>(full_export, true, false));
 112   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CodeHeapAnalyticsDCmd>(full_export, true, false));
 113 
 114   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompilerDirectivesPrintDCmd>(full_export, true, false));
 115   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompilerDirectivesAddDCmd>(full_export, true, false));
 116   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompilerDirectivesRemoveDCmd>(full_export, true, false));
 117   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompilerDirectivesClearDCmd>(full_export, true, false));


 927   output()->cr();
 928 }
 929 
 930 void CompileQueueDCmd::execute(DCmdSource source, TRAPS) {
 931   VM_PrintCompileQueue printCompileQueueOp(output());
 932   VMThread::execute(&printCompileQueueOp);
 933 }
 934 
 935 void CodeListDCmd::execute(DCmdSource source, TRAPS) {
 936   CodeCache::print_codelist(output());
 937 }
 938 
 939 void CodeCacheDCmd::execute(DCmdSource source, TRAPS) {
 940   CodeCache::print_layout(output());
 941 }
 942 
 943 //---<  BEGIN  >--- CodeHeap State Analytics.
 944 CodeHeapAnalyticsDCmd::CodeHeapAnalyticsDCmd(outputStream* output, bool heap) :
 945                                              DCmdWithParser(output, heap),
 946   _function("function", "Function to be performed (aggregate, UsedSpace, FreeSpace, MethodCount, MethodSpace, MethodAge, MethodNames, discard", "STRING", false, "all"),
 947   _granularity("granularity", "Detail level - smaller value -> more detail", "STRING", false, "4096") {
 948   _dcmdparser.add_dcmd_argument(&_function);
 949   _dcmdparser.add_dcmd_argument(&_granularity);
 950 }
 951 
 952 void CodeHeapAnalyticsDCmd::execute(DCmdSource source, TRAPS) {
 953   CompileBroker::print_heapinfo(output(), _function.value(), _granularity.value());







 954 }
 955 
 956 int CodeHeapAnalyticsDCmd::num_arguments() {
 957   ResourceMark rm;
 958   CodeHeapAnalyticsDCmd* dcmd = new CodeHeapAnalyticsDCmd(NULL, false);
 959   if (dcmd != NULL) {
 960     DCmdMark mark(dcmd);
 961     return dcmd->_dcmdparser.num_arguments();
 962   } else {
 963     return 0;
 964   }
 965 }
 966 //---<  END  >--- CodeHeap State Analytics.







































 967 
 968 void CompilerDirectivesPrintDCmd::execute(DCmdSource source, TRAPS) {
 969   DirectivesStack::print(output());
 970 }
 971 
 972 CompilerDirectivesAddDCmd::CompilerDirectivesAddDCmd(outputStream* output, bool heap) :
 973                            DCmdWithParser(output, heap),
 974   _filename("filename","Name of the directives file", "STRING",true) {
 975   _dcmdparser.add_dcmd_argument(&_filename);
 976 }
 977 
 978 void CompilerDirectivesAddDCmd::execute(DCmdSource source, TRAPS) {
 979   DirectivesParser::parse_from_file(_filename.value(), output());
 980 }
 981 
 982 int CompilerDirectivesAddDCmd::num_arguments() {
 983   ResourceMark rm;
 984   CompilerDirectivesAddDCmd* dcmd = new CompilerDirectivesAddDCmd(NULL, false);
 985   if (dcmd != NULL) {
 986     DCmdMark mark(dcmd);


< prev index next >