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  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "jvm.h"
  27 #include "classfile/classLoaderHierarchyDCmd.hpp"
  28 #include "classfile/classLoaderStats.hpp"
  29 #include "classfile/compactHashtable.hpp"
  30 #include "compiler/compileBroker.hpp"
  31 #include "compiler/directivesParser.hpp"
  32 #include "gc/shared/vmGCOperations.hpp"
  33 #include "memory/metaspace/metaspaceDCmd.hpp"
  34 #include "memory/resourceArea.hpp"
  35 #include "oops/objArrayOop.inline.hpp"
  36 #include "oops/oop.inline.hpp"
  37 #include "oops/typeArrayOop.inline.hpp"
  38 #include "runtime/flags/jvmFlag.hpp"
  39 #include "runtime/handles.inline.hpp"
  40 #include "runtime/javaCalls.hpp"
  41 #include "runtime/os.hpp"
  42 #include "services/diagnosticArgument.hpp"
  43 #include "services/diagnosticCommand.hpp"
  44 #include "services/diagnosticFramework.hpp"
  45 #include "services/heapDumper.hpp"
  46 #include "services/management.hpp"
  47 #include "services/writeableFlags.hpp"
  48 #include "utilities/debug.hpp"
  49 #include "utilities/formatBuffer.hpp"
  50 #include "utilities/macros.hpp"
  51 
  52 
  53 static void loadAgentModule(TRAPS) {
  54   ResourceMark rm(THREAD);
  55   HandleMark hm(THREAD);
  56 
  57   JavaValue result(T_OBJECT);
  58   Handle h_module_name = java_lang_String::create_from_str("jdk.management.agent", CHECK);
  59   JavaCalls::call_static(&result,
  60                          SystemDictionary::module_Modules_klass(),
  61                          vmSymbols::loadModule_name(),
  62                          vmSymbols::loadModule_signature(),
  63                          h_module_name,
  64                          THREAD);
  65 }
  66 
  67 void DCmdRegistrant::register_dcmds(){
  68   // Registration of the diagnostic commands
  69   // First argument specifies which interfaces will export the command
  70   // Second argument specifies if the command is enabled
  71   // Third  argument specifies if the command is hidden
  72   uint32_t full_export = DCmd_Source_Internal | DCmd_Source_AttachAPI
  73                          | DCmd_Source_MBean;
  74   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HelpDCmd>(full_export, true, false));
  75   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VersionDCmd>(full_export, true, false));
  76   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CommandLineDCmd>(full_export, true, false));
  77   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PrintSystemPropertiesDCmd>(full_export, true, false));
  78   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PrintVMFlagsDCmd>(full_export, true, false));
  79   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SetVMFlagDCmd>(full_export, true, false));
  80   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMDynamicLibrariesDCmd>(full_export, true, false));
  81   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMUptimeDCmd>(full_export, true, false));
  82   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMInfoDCmd>(full_export, true, false));
  83   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SystemGCDCmd>(full_export, true, false));
  84   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<RunFinalizationDCmd>(full_export, true, false));
  85   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HeapInfoDCmd>(full_export, true, false));
  86   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<FinalizerInfoDCmd>(full_export, true, false));
  87 #if INCLUDE_SERVICES
  88   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HeapDumpDCmd>(DCmd_Source_Internal | DCmd_Source_AttachAPI, true, false));
  89   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassHistogramDCmd>(full_export, true, false));
  90   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassStatsDCmd>(full_export, true, false));
  91   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SystemDictionaryDCmd>(full_export, true, false));
  92   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassHierarchyDCmd>(full_export, true, false));
  93   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SymboltableDCmd>(full_export, true, false));
  94   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<StringtableDCmd>(full_export, true, false));
  95   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<metaspace::MetaspaceDCmd>(full_export, true, false));
  96 #if INCLUDE_JVMTI // Both JVMTI and SERVICES have to be enabled to have this dcmd
  97   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JVMTIAgentLoadDCmd>(full_export, true, false));
  98 #endif // INCLUDE_JVMTI
  99 #endif // INCLUDE_SERVICES
 100 #if INCLUDE_JVMTI
 101   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JVMTIDataDumpDCmd>(full_export, true, false));
 102 #endif // INCLUDE_JVMTI
 103   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ThreadDumpDCmd>(full_export, true, false));
 104   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassLoaderStatsDCmd>(full_export, true, false));
 105   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassLoaderHierarchyDCmd>(full_export, true, false));
 106   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompileQueueDCmd>(full_export, true, false));
 107   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CodeListDCmd>(full_export, true, false));
 108   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CodeCacheDCmd>(full_export, true, false));
 109   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<TouchedMethodsDCmd>(full_export, true, false));
 110   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CodeHeapAnalyticsDCmd>(full_export, true, false));
 111 
 112   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompilerDirectivesPrintDCmd>(full_export, true, false));
 113   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompilerDirectivesAddDCmd>(full_export, true, false));
 114   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompilerDirectivesRemoveDCmd>(full_export, true, false));
 115   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompilerDirectivesClearDCmd>(full_export, true, false));
 116 
 117   // Enhanced JMX Agent Support
 118   // These commands won't be exported via the DiagnosticCommandMBean until an
 119   // appropriate permission is created for them
 120   uint32_t jmx_agent_export_flags = DCmd_Source_Internal | DCmd_Source_AttachAPI;
 121   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStartRemoteDCmd>(jmx_agent_export_flags, true,false));
 122   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStartLocalDCmd>(jmx_agent_export_flags, true,false));
 123   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStopRemoteDCmd>(jmx_agent_export_flags, true,false));
 124   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStatusDCmd>(jmx_agent_export_flags, true,false));
 125 
 126 }
 127 
 128 #ifndef HAVE_EXTRA_DCMD
 129 void DCmdRegistrant::register_dcmds_ext(){
 130    // Do nothing here
 131 }
 132 #endif
 133 
 134 
 135 HelpDCmd::HelpDCmd(outputStream* output, bool heap) : DCmdWithParser(output, heap),
 136   _all("-all", "Show help for all commands", "BOOLEAN", false, "false"),
 137   _cmd("command name", "The name of the command for which we want help",
 138         "STRING", false) {
 139   _dcmdparser.add_dcmd_option(&_all);
 140   _dcmdparser.add_dcmd_argument(&_cmd);
 141 };
 142 
 143 
 144 static int compare_strings(const char** s1, const char** s2) {
 145   return ::strcmp(*s1, *s2);
 146 }
 147 
 148 void HelpDCmd::execute(DCmdSource source, TRAPS) {
 149   if (_all.value()) {
 150     GrowableArray<const char*>* cmd_list = DCmdFactory::DCmd_list(source);
 151     cmd_list->sort(compare_strings);
 152     for (int i = 0; i < cmd_list->length(); i++) {
 153       DCmdFactory* factory = DCmdFactory::factory(source, cmd_list->at(i),
 154                                                   strlen(cmd_list->at(i)));
 155       output()->print_cr("%s%s", factory->name(),
 156                          factory->is_enabled() ? "" : " [disabled]");
 157       output()->print_cr("\t%s", factory->description());
 158       output()->cr();
 159       factory = factory->next();
 160     }
 161   } else if (_cmd.has_value()) {
 162     DCmd* cmd = NULL;
 163     DCmdFactory* factory = DCmdFactory::factory(source, _cmd.value(),
 164                                                 strlen(_cmd.value()));
 165     if (factory != NULL) {
 166       output()->print_cr("%s%s", factory->name(),
 167                          factory->is_enabled() ? "" : " [disabled]");
 168       output()->print_cr("%s", factory->description());
 169       output()->print_cr("\nImpact: %s", factory->impact());
 170       JavaPermission p = factory->permission();
 171       if(p._class != NULL) {
 172         if(p._action != NULL) {
 173           output()->print_cr("\nPermission: %s(%s, %s)",
 174                   p._class, p._name == NULL ? "null" : p._name, p._action);
 175         } else {
 176           output()->print_cr("\nPermission: %s(%s)",
 177                   p._class, p._name == NULL ? "null" : p._name);
 178         }
 179       }
 180       output()->cr();
 181       cmd = factory->create_resource_instance(output());
 182       if (cmd != NULL) {
 183         DCmdMark mark(cmd);
 184         cmd->print_help(factory->name());
 185       }
 186     } else {
 187       output()->print_cr("Help unavailable : '%s' : No such command", _cmd.value());
 188     }
 189   } else {
 190     output()->print_cr("The following commands are available:");
 191     GrowableArray<const char *>* cmd_list = DCmdFactory::DCmd_list(source);
 192     cmd_list->sort(compare_strings);
 193     for (int i = 0; i < cmd_list->length(); i++) {
 194       DCmdFactory* factory = DCmdFactory::factory(source, cmd_list->at(i),
 195                                                   strlen(cmd_list->at(i)));
 196       output()->print_cr("%s%s", factory->name(),
 197                          factory->is_enabled() ? "" : " [disabled]");
 198       factory = factory->_next;
 199     }
 200     output()->print_cr("\nFor more information about a specific command use 'help <command>'.");
 201   }
 202 }
 203 
 204 int HelpDCmd::num_arguments() {
 205   ResourceMark rm;
 206   HelpDCmd* dcmd = new HelpDCmd(NULL, false);
 207   if (dcmd != NULL) {
 208     DCmdMark mark(dcmd);
 209     return dcmd->_dcmdparser.num_arguments();
 210   } else {
 211     return 0;
 212   }
 213 }
 214 
 215 void VersionDCmd::execute(DCmdSource source, TRAPS) {
 216   output()->print_cr("%s version %s", Abstract_VM_Version::vm_name(),
 217           Abstract_VM_Version::vm_release());
 218   JDK_Version jdk_version = JDK_Version::current();
 219   if (jdk_version.patch_version() > 0) {
 220     output()->print_cr("JDK %d.%d.%d.%d", jdk_version.major_version(),
 221             jdk_version.minor_version(), jdk_version.security_version(),
 222             jdk_version.patch_version());
 223   } else {
 224     output()->print_cr("JDK %d.%d.%d", jdk_version.major_version(),
 225             jdk_version.minor_version(), jdk_version.security_version());
 226   }
 227 }
 228 
 229 PrintVMFlagsDCmd::PrintVMFlagsDCmd(outputStream* output, bool heap) :
 230                                    DCmdWithParser(output, heap),
 231   _all("-all", "Print all flags supported by the VM", "BOOLEAN", false, "false") {
 232   _dcmdparser.add_dcmd_option(&_all);
 233 }
 234 
 235 void PrintVMFlagsDCmd::execute(DCmdSource source, TRAPS) {
 236   if (_all.value()) {
 237     JVMFlag::printFlags(output(), true);
 238   } else {
 239     JVMFlag::printSetFlags(output());
 240   }
 241 }
 242 
 243 int PrintVMFlagsDCmd::num_arguments() {
 244     ResourceMark rm;
 245     PrintVMFlagsDCmd* dcmd = new PrintVMFlagsDCmd(NULL, false);
 246     if (dcmd != NULL) {
 247       DCmdMark mark(dcmd);
 248       return dcmd->_dcmdparser.num_arguments();
 249     } else {
 250       return 0;
 251     }
 252 }
 253 
 254 SetVMFlagDCmd::SetVMFlagDCmd(outputStream* output, bool heap) :
 255                                    DCmdWithParser(output, heap),
 256   _flag("flag name", "The name of the flag we want to set",
 257         "STRING", true),
 258   _value("string value", "The value we want to set", "STRING", false) {
 259   _dcmdparser.add_dcmd_argument(&_flag);
 260   _dcmdparser.add_dcmd_argument(&_value);
 261 }
 262 
 263 void SetVMFlagDCmd::execute(DCmdSource source, TRAPS) {
 264   const char* val = NULL;
 265   if (_value.value() != NULL) {
 266     val = _value.value();
 267   }
 268 
 269   FormatBuffer<80> err_msg("%s", "");
 270   int ret = WriteableFlags::set_flag(_flag.value(), val, JVMFlag::MANAGEMENT, err_msg);
 271 
 272   if (ret != JVMFlag::SUCCESS) {
 273     output()->print_cr("%s", err_msg.buffer());
 274   }
 275 }
 276 
 277 int SetVMFlagDCmd::num_arguments() {
 278   ResourceMark rm;
 279   SetVMFlagDCmd* dcmd = new SetVMFlagDCmd(NULL, false);
 280   if (dcmd != NULL) {
 281     DCmdMark mark(dcmd);
 282     return dcmd->_dcmdparser.num_arguments();
 283   } else {
 284     return 0;
 285   }
 286 }
 287 
 288 void JVMTIDataDumpDCmd::execute(DCmdSource source, TRAPS) {
 289   if (JvmtiExport::should_post_data_dump()) {
 290     JvmtiExport::post_data_dump();
 291   }
 292 }
 293 
 294 #if INCLUDE_SERVICES
 295 JVMTIAgentLoadDCmd::JVMTIAgentLoadDCmd(outputStream* output, bool heap) :
 296                                        DCmdWithParser(output, heap),
 297   _libpath("library path", "Absolute path of the JVMTI agent to load.",
 298            "STRING", true),
 299   _option("agent option", "Option string to pass the agent.", "STRING", false) {
 300   _dcmdparser.add_dcmd_argument(&_libpath);
 301   _dcmdparser.add_dcmd_argument(&_option);
 302 }
 303 
 304 void JVMTIAgentLoadDCmd::execute(DCmdSource source, TRAPS) {
 305 
 306   if (_libpath.value() == NULL) {
 307     output()->print_cr("JVMTI.agent_load dcmd needs library path.");
 308     return;
 309   }
 310 
 311   char *suffix = strrchr(_libpath.value(), '.');
 312   bool is_java_agent = (suffix != NULL) && (strncmp(".jar", suffix, 4) == 0);
 313 
 314   if (is_java_agent) {
 315     if (_option.value() == NULL) {
 316       JvmtiExport::load_agent_library("instrument", "false",
 317                                       _libpath.value(), output());
 318     } else {
 319       size_t opt_len = strlen(_libpath.value()) + strlen(_option.value()) + 2;
 320       if (opt_len > 4096) {
 321         output()->print_cr("JVMTI agent attach failed: Options is too long.");
 322         return;
 323       }
 324 
 325       char *opt = (char *)os::malloc(opt_len, mtInternal);
 326       if (opt == NULL) {
 327         output()->print_cr("JVMTI agent attach failed: "
 328                            "Could not allocate " SIZE_FORMAT " bytes for argument.",
 329                            opt_len);
 330         return;
 331       }
 332 
 333       jio_snprintf(opt, opt_len, "%s=%s", _libpath.value(), _option.value());
 334       JvmtiExport::load_agent_library("instrument", "false", opt, output());
 335 
 336       os::free(opt);
 337     }
 338   } else {
 339     JvmtiExport::load_agent_library(_libpath.value(), "true",
 340                                     _option.value(), output());
 341   }
 342 }
 343 
 344 int JVMTIAgentLoadDCmd::num_arguments() {
 345   ResourceMark rm;
 346   JVMTIAgentLoadDCmd* dcmd = new JVMTIAgentLoadDCmd(NULL, false);
 347   if (dcmd != NULL) {
 348     DCmdMark mark(dcmd);
 349     return dcmd->_dcmdparser.num_arguments();
 350   } else {
 351     return 0;
 352   }
 353 }
 354 #endif // INCLUDE_SERVICES
 355 
 356 void PrintSystemPropertiesDCmd::execute(DCmdSource source, TRAPS) {
 357   // load VMSupport
 358   Symbol* klass = vmSymbols::jdk_internal_vm_VMSupport();
 359   Klass* k = SystemDictionary::resolve_or_fail(klass, true, CHECK);
 360   InstanceKlass* ik = InstanceKlass::cast(k);
 361   if (ik->should_be_initialized()) {
 362     ik->initialize(THREAD);
 363   }
 364   if (HAS_PENDING_EXCEPTION) {
 365     java_lang_Throwable::print(PENDING_EXCEPTION, output());
 366     output()->cr();
 367     CLEAR_PENDING_EXCEPTION;
 368     return;
 369   }
 370 
 371   // invoke the serializePropertiesToByteArray method
 372   JavaValue result(T_OBJECT);
 373   JavaCallArguments args;
 374 
 375   Symbol* signature = vmSymbols::serializePropertiesToByteArray_signature();
 376   JavaCalls::call_static(&result,
 377                          ik,
 378                          vmSymbols::serializePropertiesToByteArray_name(),
 379                          signature,
 380                          &args,
 381                          THREAD);
 382   if (HAS_PENDING_EXCEPTION) {
 383     java_lang_Throwable::print(PENDING_EXCEPTION, output());
 384     output()->cr();
 385     CLEAR_PENDING_EXCEPTION;
 386     return;
 387   }
 388 
 389   // The result should be a [B
 390   oop res = (oop)result.get_jobject();
 391   assert(res->is_typeArray(), "just checking");
 392   assert(TypeArrayKlass::cast(res->klass())->element_type() == T_BYTE, "just checking");
 393 
 394   // copy the bytes to the output stream
 395   typeArrayOop ba = typeArrayOop(res);
 396   jbyte* addr = typeArrayOop(res)->byte_at_addr(0);
 397   output()->print_raw((const char*)addr, ba->length());
 398 }
 399 
 400 VMUptimeDCmd::VMUptimeDCmd(outputStream* output, bool heap) :
 401                            DCmdWithParser(output, heap),
 402   _date("-date", "Add a prefix with current date", "BOOLEAN", false, "false") {
 403   _dcmdparser.add_dcmd_option(&_date);
 404 }
 405 
 406 void VMUptimeDCmd::execute(DCmdSource source, TRAPS) {
 407   if (_date.value()) {
 408     output()->date_stamp(true, "", ": ");
 409   }
 410   output()->time_stamp().update_to(tty->time_stamp().ticks());
 411   output()->stamp();
 412   output()->print_cr(" s");
 413 }
 414 
 415 int VMUptimeDCmd::num_arguments() {
 416   ResourceMark rm;
 417   VMUptimeDCmd* dcmd = new VMUptimeDCmd(NULL, false);
 418   if (dcmd != NULL) {
 419     DCmdMark mark(dcmd);
 420     return dcmd->_dcmdparser.num_arguments();
 421   } else {
 422     return 0;
 423   }
 424 }
 425 
 426 void VMInfoDCmd::execute(DCmdSource source, TRAPS) {
 427   VMError::print_vm_info(_output);
 428 }
 429 
 430 void SystemGCDCmd::execute(DCmdSource source, TRAPS) {
 431   Universe::heap()->collect(GCCause::_dcmd_gc_run);
 432 }
 433 
 434 void RunFinalizationDCmd::execute(DCmdSource source, TRAPS) {
 435   Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_System(),
 436                                                  true, CHECK);
 437   JavaValue result(T_VOID);
 438   JavaCalls::call_static(&result, k,
 439                          vmSymbols::run_finalization_name(),
 440                          vmSymbols::void_method_signature(), CHECK);
 441 }
 442 
 443 void HeapInfoDCmd::execute(DCmdSource source, TRAPS) {
 444   MutexLocker hl(Heap_lock);
 445   Universe::heap()->print_on(output());
 446 }
 447 
 448 void FinalizerInfoDCmd::execute(DCmdSource source, TRAPS) {
 449   ResourceMark rm;
 450 
 451   Klass* k = SystemDictionary::resolve_or_fail(
 452     vmSymbols::finalizer_histogram_klass(), true, CHECK);
 453 
 454   JavaValue result(T_ARRAY);
 455 
 456   // We are calling lang.ref.FinalizerHistogram.getFinalizerHistogram() method
 457   // and expect it to return array of FinalizerHistogramEntry as Object[]
 458 
 459   JavaCalls::call_static(&result, k,
 460                          vmSymbols::get_finalizer_histogram_name(),
 461                          vmSymbols::void_finalizer_histogram_entry_array_signature(), CHECK);
 462 
 463   objArrayOop result_oop = (objArrayOop) result.get_jobject();
 464   if (result_oop->length() == 0) {
 465     output()->print_cr("No instances waiting for finalization found");
 466     return;
 467   }
 468 
 469   oop foop = result_oop->obj_at(0);
 470   InstanceKlass* ik = InstanceKlass::cast(foop->klass());
 471 
 472   fieldDescriptor count_fd, name_fd;
 473 
 474   Klass* count_res = ik->find_field(
 475     vmSymbols::finalizer_histogram_entry_count_field(), vmSymbols::int_signature(), &count_fd);
 476 
 477   Klass* name_res = ik->find_field(
 478     vmSymbols::finalizer_histogram_entry_name_field(), vmSymbols::string_signature(), &name_fd);
 479 
 480   assert(count_res != NULL && name_res != NULL, "Unexpected layout of FinalizerHistogramEntry");
 481 
 482   output()->print_cr("Unreachable instances waiting for finalization");
 483   output()->print_cr("#instances  class name");
 484   output()->print_cr("-----------------------");
 485 
 486   for (int i = 0; i < result_oop->length(); ++i) {
 487     oop element_oop = result_oop->obj_at(i);
 488     oop str_oop = element_oop->obj_field(name_fd.offset());
 489     char *name = java_lang_String::as_utf8_string(str_oop);
 490     int count = element_oop->int_field(count_fd.offset());
 491     output()->print_cr("%10d  %s", count, name);
 492   }
 493 }
 494 
 495 #if INCLUDE_SERVICES // Heap dumping/inspection supported
 496 HeapDumpDCmd::HeapDumpDCmd(outputStream* output, bool heap) :
 497                            DCmdWithParser(output, heap),
 498   _filename("filename","Name of the dump file", "STRING",true),
 499   _all("-all", "Dump all objects, including unreachable objects",
 500        "BOOLEAN", false, "false") {
 501   _dcmdparser.add_dcmd_option(&_all);
 502   _dcmdparser.add_dcmd_argument(&_filename);
 503 }
 504 
 505 void HeapDumpDCmd::execute(DCmdSource source, TRAPS) {
 506   // Request a full GC before heap dump if _all is false
 507   // This helps reduces the amount of unreachable objects in the dump
 508   // and makes it easier to browse.
 509   HeapDumper dumper(!_all.value() /* request GC if _all is false*/);
 510   int res = dumper.dump(_filename.value());
 511   if (res == 0) {
 512     output()->print_cr("Heap dump file created");
 513   } else {
 514     // heap dump failed
 515     ResourceMark rm;
 516     char* error = dumper.error_as_C_string();
 517     if (error == NULL) {
 518       output()->print_cr("Dump failed - reason unknown");
 519     } else {
 520       output()->print_cr("%s", error);
 521     }
 522   }
 523 }
 524 
 525 int HeapDumpDCmd::num_arguments() {
 526   ResourceMark rm;
 527   HeapDumpDCmd* dcmd = new HeapDumpDCmd(NULL, false);
 528   if (dcmd != NULL) {
 529     DCmdMark mark(dcmd);
 530     return dcmd->_dcmdparser.num_arguments();
 531   } else {
 532     return 0;
 533   }
 534 }
 535 
 536 ClassHistogramDCmd::ClassHistogramDCmd(outputStream* output, bool heap) :
 537                                        DCmdWithParser(output, heap),
 538   _all("-all", "Inspect all objects, including unreachable objects",
 539        "BOOLEAN", false, "false") {
 540   _dcmdparser.add_dcmd_option(&_all);
 541 }
 542 
 543 void ClassHistogramDCmd::execute(DCmdSource source, TRAPS) {
 544   VM_GC_HeapInspection heapop(output(),
 545                               !_all.value() /* request full gc if false */);
 546   VMThread::execute(&heapop);
 547 }
 548 
 549 int ClassHistogramDCmd::num_arguments() {
 550   ResourceMark rm;
 551   ClassHistogramDCmd* dcmd = new ClassHistogramDCmd(NULL, false);
 552   if (dcmd != NULL) {
 553     DCmdMark mark(dcmd);
 554     return dcmd->_dcmdparser.num_arguments();
 555   } else {
 556     return 0;
 557   }
 558 }
 559 
 560 #define DEFAULT_COLUMNS "InstBytes,KlassBytes,CpAll,annotations,MethodCount,Bytecodes,MethodAll,ROAll,RWAll,Total"
 561 ClassStatsDCmd::ClassStatsDCmd(outputStream* output, bool heap) :
 562                                        DCmdWithParser(output, heap),
 563   _csv("-csv", "Print in CSV (comma-separated values) format for spreadsheets",
 564        "BOOLEAN", false, "false"),
 565   _all("-all", "Show all columns",
 566        "BOOLEAN", false, "false"),
 567   _help("-help", "Show meaning of all the columns",
 568        "BOOLEAN", false, "false"),
 569   _columns("columns", "Comma-separated list of all the columns to show. "
 570            "If not specified, the following columns are shown: " DEFAULT_COLUMNS,
 571            "STRING", false) {
 572   _dcmdparser.add_dcmd_option(&_all);
 573   _dcmdparser.add_dcmd_option(&_csv);
 574   _dcmdparser.add_dcmd_option(&_help);
 575   _dcmdparser.add_dcmd_argument(&_columns);
 576 }
 577 
 578 void ClassStatsDCmd::execute(DCmdSource source, TRAPS) {
 579   VM_GC_HeapInspection heapop(output(),
 580                               true /* request_full_gc */);
 581   heapop.set_csv_format(_csv.value());
 582   heapop.set_print_help(_help.value());
 583   heapop.set_print_class_stats(true);
 584   if (_all.value()) {
 585     if (_columns.has_value()) {
 586       output()->print_cr("Cannot specify -all and individual columns at the same time");
 587       return;
 588     } else {
 589       heapop.set_columns(NULL);
 590     }
 591   } else {
 592     if (_columns.has_value()) {
 593       heapop.set_columns(_columns.value());
 594     } else {
 595       heapop.set_columns(DEFAULT_COLUMNS);
 596     }
 597   }
 598   VMThread::execute(&heapop);
 599 }
 600 
 601 int ClassStatsDCmd::num_arguments() {
 602   ResourceMark rm;
 603   ClassStatsDCmd* dcmd = new ClassStatsDCmd(NULL, false);
 604   if (dcmd != NULL) {
 605     DCmdMark mark(dcmd);
 606     return dcmd->_dcmdparser.num_arguments();
 607   } else {
 608     return 0;
 609   }
 610 }
 611 #endif // INCLUDE_SERVICES
 612 
 613 ThreadDumpDCmd::ThreadDumpDCmd(outputStream* output, bool heap) :
 614                                DCmdWithParser(output, heap),
 615   _locks("-l", "print java.util.concurrent locks", "BOOLEAN", false, "false") {
 616   _dcmdparser.add_dcmd_option(&_locks);
 617 }
 618 
 619 void ThreadDumpDCmd::execute(DCmdSource source, TRAPS) {
 620   // thread stacks
 621   VM_PrintThreads op1(output(), _locks.value());
 622   VMThread::execute(&op1);
 623 
 624   // JNI global handles
 625   VM_PrintJNI op2(output());
 626   VMThread::execute(&op2);
 627 
 628   // Deadlock detection
 629   VM_FindDeadlocks op3(output());
 630   VMThread::execute(&op3);
 631 }
 632 
 633 int ThreadDumpDCmd::num_arguments() {
 634   ResourceMark rm;
 635   ThreadDumpDCmd* dcmd = new ThreadDumpDCmd(NULL, false);
 636   if (dcmd != NULL) {
 637     DCmdMark mark(dcmd);
 638     return dcmd->_dcmdparser.num_arguments();
 639   } else {
 640     return 0;
 641   }
 642 }
 643 
 644 // Enhanced JMX Agent support
 645 
 646 JMXStartRemoteDCmd::JMXStartRemoteDCmd(outputStream *output, bool heap_allocated) :
 647 
 648   DCmdWithParser(output, heap_allocated),
 649 
 650   _config_file
 651   ("config.file",
 652    "set com.sun.management.config.file", "STRING", false),
 653 
 654   _jmxremote_host
 655   ("jmxremote.host",
 656    "set com.sun.management.jmxremote.host", "STRING", false),
 657 
 658   _jmxremote_port
 659   ("jmxremote.port",
 660    "set com.sun.management.jmxremote.port", "STRING", false),
 661 
 662   _jmxremote_rmi_port
 663   ("jmxremote.rmi.port",
 664    "set com.sun.management.jmxremote.rmi.port", "STRING", false),
 665 
 666   _jmxremote_ssl
 667   ("jmxremote.ssl",
 668    "set com.sun.management.jmxremote.ssl", "STRING", false),
 669 
 670   _jmxremote_registry_ssl
 671   ("jmxremote.registry.ssl",
 672    "set com.sun.management.jmxremote.registry.ssl", "STRING", false),
 673 
 674   _jmxremote_authenticate
 675   ("jmxremote.authenticate",
 676    "set com.sun.management.jmxremote.authenticate", "STRING", false),
 677 
 678   _jmxremote_password_file
 679   ("jmxremote.password.file",
 680    "set com.sun.management.jmxremote.password.file", "STRING", false),
 681 
 682   _jmxremote_access_file
 683   ("jmxremote.access.file",
 684    "set com.sun.management.jmxremote.access.file", "STRING", false),
 685 
 686   _jmxremote_login_config
 687   ("jmxremote.login.config",
 688    "set com.sun.management.jmxremote.login.config", "STRING", false),
 689 
 690   _jmxremote_ssl_enabled_cipher_suites
 691   ("jmxremote.ssl.enabled.cipher.suites",
 692    "set com.sun.management.jmxremote.ssl.enabled.cipher.suite", "STRING", false),
 693 
 694   _jmxremote_ssl_enabled_protocols
 695   ("jmxremote.ssl.enabled.protocols",
 696    "set com.sun.management.jmxremote.ssl.enabled.protocols", "STRING", false),
 697 
 698   _jmxremote_ssl_need_client_auth
 699   ("jmxremote.ssl.need.client.auth",
 700    "set com.sun.management.jmxremote.need.client.auth", "STRING", false),
 701 
 702   _jmxremote_ssl_config_file
 703   ("jmxremote.ssl.config.file",
 704    "set com.sun.management.jmxremote.ssl_config_file", "STRING", false),
 705 
 706 // JDP Protocol support
 707   _jmxremote_autodiscovery
 708   ("jmxremote.autodiscovery",
 709    "set com.sun.management.jmxremote.autodiscovery", "STRING", false),
 710 
 711    _jdp_port
 712   ("jdp.port",
 713    "set com.sun.management.jdp.port", "INT", false),
 714 
 715    _jdp_address
 716   ("jdp.address",
 717    "set com.sun.management.jdp.address", "STRING", false),
 718 
 719    _jdp_source_addr
 720   ("jdp.source_addr",
 721    "set com.sun.management.jdp.source_addr", "STRING", false),
 722 
 723    _jdp_ttl
 724   ("jdp.ttl",
 725    "set com.sun.management.jdp.ttl", "INT", false),
 726 
 727    _jdp_pause
 728   ("jdp.pause",
 729    "set com.sun.management.jdp.pause", "INT", false),
 730 
 731    _jdp_name
 732   ("jdp.name",
 733    "set com.sun.management.jdp.name", "STRING", false)
 734 
 735   {
 736     _dcmdparser.add_dcmd_option(&_config_file);
 737     _dcmdparser.add_dcmd_option(&_jmxremote_host);
 738     _dcmdparser.add_dcmd_option(&_jmxremote_port);
 739     _dcmdparser.add_dcmd_option(&_jmxremote_rmi_port);
 740     _dcmdparser.add_dcmd_option(&_jmxremote_ssl);
 741     _dcmdparser.add_dcmd_option(&_jmxremote_registry_ssl);
 742     _dcmdparser.add_dcmd_option(&_jmxremote_authenticate);
 743     _dcmdparser.add_dcmd_option(&_jmxremote_password_file);
 744     _dcmdparser.add_dcmd_option(&_jmxremote_access_file);
 745     _dcmdparser.add_dcmd_option(&_jmxremote_login_config);
 746     _dcmdparser.add_dcmd_option(&_jmxremote_ssl_enabled_cipher_suites);
 747     _dcmdparser.add_dcmd_option(&_jmxremote_ssl_enabled_protocols);
 748     _dcmdparser.add_dcmd_option(&_jmxremote_ssl_need_client_auth);
 749     _dcmdparser.add_dcmd_option(&_jmxremote_ssl_config_file);
 750     _dcmdparser.add_dcmd_option(&_jmxremote_autodiscovery);
 751     _dcmdparser.add_dcmd_option(&_jdp_port);
 752     _dcmdparser.add_dcmd_option(&_jdp_address);
 753     _dcmdparser.add_dcmd_option(&_jdp_source_addr);
 754     _dcmdparser.add_dcmd_option(&_jdp_ttl);
 755     _dcmdparser.add_dcmd_option(&_jdp_pause);
 756     _dcmdparser.add_dcmd_option(&_jdp_name);
 757 }
 758 
 759 
 760 int JMXStartRemoteDCmd::num_arguments() {
 761   ResourceMark rm;
 762   JMXStartRemoteDCmd* dcmd = new JMXStartRemoteDCmd(NULL, false);
 763   if (dcmd != NULL) {
 764     DCmdMark mark(dcmd);
 765     return dcmd->_dcmdparser.num_arguments();
 766   } else {
 767     return 0;
 768   }
 769 }
 770 
 771 
 772 void JMXStartRemoteDCmd::execute(DCmdSource source, TRAPS) {
 773     ResourceMark rm(THREAD);
 774     HandleMark hm(THREAD);
 775 
 776     // Load and initialize the jdk.internal.agent.Agent class
 777     // invoke startRemoteManagementAgent(string) method to start
 778     // the remote management server.
 779     // throw java.lang.NoSuchMethodError if the method doesn't exist
 780 
 781     loadAgentModule(CHECK);
 782     Handle loader = Handle(THREAD, SystemDictionary::java_system_loader());
 783     Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::jdk_internal_agent_Agent(), loader, Handle(), true, CHECK);
 784 
 785     JavaValue result(T_VOID);
 786 
 787     // Pass all command line arguments to java as key=value,...
 788     // All checks are done on java side
 789 
 790     int len = 0;
 791     stringStream options;
 792     char comma[2] = {0,0};
 793 
 794     // Leave default values on Agent.class side and pass only
 795     // agruments explicitly set by user. All arguments passed
 796     // to jcmd override properties with the same name set by
 797     // command line with -D or by managmenent.properties
 798     // file.
 799 #define PUT_OPTION(a) \
 800     do { \
 801         if ( (a).is_set() ){ \
 802             if ( *((a).type()) == 'I' ) { \
 803                 options.print("%scom.sun.management.%s=" JLONG_FORMAT, comma, (a).name(), (jlong)((a).value())); \
 804             } else { \
 805                 options.print("%scom.sun.management.%s=%s", comma, (a).name(), (char*)((a).value())); \
 806             } \
 807             comma[0] = ','; \
 808         }\
 809     } while(0);
 810 
 811 
 812     PUT_OPTION(_config_file);
 813     PUT_OPTION(_jmxremote_host);
 814     PUT_OPTION(_jmxremote_port);
 815     PUT_OPTION(_jmxremote_rmi_port);
 816     PUT_OPTION(_jmxremote_ssl);
 817     PUT_OPTION(_jmxremote_registry_ssl);
 818     PUT_OPTION(_jmxremote_authenticate);
 819     PUT_OPTION(_jmxremote_password_file);
 820     PUT_OPTION(_jmxremote_access_file);
 821     PUT_OPTION(_jmxremote_login_config);
 822     PUT_OPTION(_jmxremote_ssl_enabled_cipher_suites);
 823     PUT_OPTION(_jmxremote_ssl_enabled_protocols);
 824     PUT_OPTION(_jmxremote_ssl_need_client_auth);
 825     PUT_OPTION(_jmxremote_ssl_config_file);
 826     PUT_OPTION(_jmxremote_autodiscovery);
 827     PUT_OPTION(_jdp_port);
 828     PUT_OPTION(_jdp_address);
 829     PUT_OPTION(_jdp_source_addr);
 830     PUT_OPTION(_jdp_ttl);
 831     PUT_OPTION(_jdp_pause);
 832     PUT_OPTION(_jdp_name);
 833 
 834 #undef PUT_OPTION
 835 
 836     Handle str = java_lang_String::create_from_str(options.as_string(), CHECK);
 837     JavaCalls::call_static(&result, k, vmSymbols::startRemoteAgent_name(), vmSymbols::string_void_signature(), str, CHECK);
 838 }
 839 
 840 JMXStartLocalDCmd::JMXStartLocalDCmd(outputStream *output, bool heap_allocated) :
 841   DCmd(output, heap_allocated) {
 842   // do nothing
 843 }
 844 
 845 void JMXStartLocalDCmd::execute(DCmdSource source, TRAPS) {
 846     ResourceMark rm(THREAD);
 847     HandleMark hm(THREAD);
 848 
 849     // Load and initialize the jdk.internal.agent.Agent class
 850     // invoke startLocalManagementAgent(void) method to start
 851     // the local management server
 852     // throw java.lang.NoSuchMethodError if method doesn't exist
 853 
 854     loadAgentModule(CHECK);
 855     Handle loader = Handle(THREAD, SystemDictionary::java_system_loader());
 856     Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::jdk_internal_agent_Agent(), loader, Handle(), true, CHECK);
 857 
 858     JavaValue result(T_VOID);
 859     JavaCalls::call_static(&result, k, vmSymbols::startLocalAgent_name(), vmSymbols::void_method_signature(), CHECK);
 860 }
 861 
 862 void JMXStopRemoteDCmd::execute(DCmdSource source, TRAPS) {
 863     ResourceMark rm(THREAD);
 864     HandleMark hm(THREAD);
 865 
 866     // Load and initialize the jdk.internal.agent.Agent class
 867     // invoke stopRemoteManagementAgent method to stop the
 868     // management server
 869     // throw java.lang.NoSuchMethodError if method doesn't exist
 870 
 871     loadAgentModule(CHECK);
 872     Handle loader = Handle(THREAD, SystemDictionary::java_system_loader());
 873     Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::jdk_internal_agent_Agent(), loader, Handle(), true, CHECK);
 874 
 875     JavaValue result(T_VOID);
 876     JavaCalls::call_static(&result, k, vmSymbols::stopRemoteAgent_name(), vmSymbols::void_method_signature(), CHECK);
 877 }
 878 
 879 JMXStatusDCmd::JMXStatusDCmd(outputStream *output, bool heap_allocated) :
 880   DCmd(output, heap_allocated) {
 881   // do nothing
 882 }
 883 
 884 void JMXStatusDCmd::execute(DCmdSource source, TRAPS) {
 885   ResourceMark rm(THREAD);
 886   HandleMark hm(THREAD);
 887 
 888   // Load and initialize the jdk.internal.agent.Agent class
 889   // invoke getManagementAgentStatus() method to generate the status info
 890   // throw java.lang.NoSuchMethodError if method doesn't exist
 891 
 892   loadAgentModule(CHECK);
 893   Handle loader = Handle(THREAD, SystemDictionary::java_system_loader());
 894   Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::jdk_internal_agent_Agent(), loader, Handle(), true, CHECK);
 895 
 896   JavaValue result(T_OBJECT);
 897   JavaCalls::call_static(&result, k, vmSymbols::getAgentStatus_name(), vmSymbols::void_string_signature(), CHECK);
 898 
 899   jvalue* jv = (jvalue*) result.get_value_addr();
 900   oop str = (oop) jv->l;
 901   if (str != NULL) {
 902       char* out = java_lang_String::as_utf8_string(str);
 903       if (out) {
 904           output()->print_cr("%s", out);
 905           return;
 906       }
 907   }
 908   output()->print_cr("Error obtaining management agent status");
 909 }
 910 
 911 VMDynamicLibrariesDCmd::VMDynamicLibrariesDCmd(outputStream *output, bool heap_allocated) :
 912   DCmd(output, heap_allocated) {
 913   // do nothing
 914 }
 915 
 916 void VMDynamicLibrariesDCmd::execute(DCmdSource source, TRAPS) {
 917   os::print_dll_info(output());
 918   output()->cr();
 919 }
 920 
 921 void CompileQueueDCmd::execute(DCmdSource source, TRAPS) {
 922   VM_PrintCompileQueue printCompileQueueOp(output());
 923   VMThread::execute(&printCompileQueueOp);
 924 }
 925 
 926 void CodeListDCmd::execute(DCmdSource source, TRAPS) {
 927   CodeCache::print_codelist(output());
 928 }
 929 
 930 void CodeCacheDCmd::execute(DCmdSource source, TRAPS) {
 931   CodeCache::print_layout(output());
 932 }
 933 
 934 //---<  BEGIN  >--- CodeHeap State Analytics.
 935 CodeHeapAnalyticsDCmd::CodeHeapAnalyticsDCmd(outputStream* output, bool heap) :
 936                                              DCmdWithParser(output, heap),
 937   _function("function", "Function to be performed (aggregate, UsedSpace, FreeSpace, MethodCount, MethodSpace, MethodAge, MethodNames, discard", "STRING", false, "all"),
 938   _granularity("granularity", "Detail level - smaller value -> more detail", "STRING", false, "4096") {
 939   _dcmdparser.add_dcmd_argument(&_function);
 940   _dcmdparser.add_dcmd_argument(&_granularity);
 941 }
 942 
 943 void CodeHeapAnalyticsDCmd::execute(DCmdSource source, TRAPS) {
 944   CompileBroker::print_heapinfo(output(), _function.value(), _granularity.value());
 945 }
 946 
 947 int CodeHeapAnalyticsDCmd::num_arguments() {
 948   ResourceMark rm;
 949   CodeHeapAnalyticsDCmd* dcmd = new CodeHeapAnalyticsDCmd(NULL, false);
 950   if (dcmd != NULL) {
 951     DCmdMark mark(dcmd);
 952     return dcmd->_dcmdparser.num_arguments();
 953   } else {
 954     return 0;
 955   }
 956 }
 957 //---<  END  >--- CodeHeap State Analytics.
 958 
 959 void CompilerDirectivesPrintDCmd::execute(DCmdSource source, TRAPS) {
 960   DirectivesStack::print(output());
 961 }
 962 
 963 CompilerDirectivesAddDCmd::CompilerDirectivesAddDCmd(outputStream* output, bool heap) :
 964                            DCmdWithParser(output, heap),
 965   _filename("filename","Name of the directives file", "STRING",true) {
 966   _dcmdparser.add_dcmd_argument(&_filename);
 967 }
 968 
 969 void CompilerDirectivesAddDCmd::execute(DCmdSource source, TRAPS) {
 970   DirectivesParser::parse_from_file(_filename.value(), output());
 971 }
 972 
 973 int CompilerDirectivesAddDCmd::num_arguments() {
 974   ResourceMark rm;
 975   CompilerDirectivesAddDCmd* dcmd = new CompilerDirectivesAddDCmd(NULL, false);
 976   if (dcmd != NULL) {
 977     DCmdMark mark(dcmd);
 978     return dcmd->_dcmdparser.num_arguments();
 979   } else {
 980     return 0;
 981   }
 982 }
 983 
 984 void CompilerDirectivesRemoveDCmd::execute(DCmdSource source, TRAPS) {
 985   DirectivesStack::pop(1);
 986 }
 987 
 988 void CompilerDirectivesClearDCmd::execute(DCmdSource source, TRAPS) {
 989   DirectivesStack::clear();
 990 }
 991 #if INCLUDE_SERVICES
 992 ClassHierarchyDCmd::ClassHierarchyDCmd(outputStream* output, bool heap) :
 993                                        DCmdWithParser(output, heap),
 994   _print_interfaces("-i", "Inherited interfaces should be printed.", "BOOLEAN", false, "false"),
 995   _print_subclasses("-s", "If a classname is specified, print its subclasses. "
 996                     "Otherwise only its superclasses are printed.", "BOOLEAN", false, "false"),
 997   _classname("classname", "Name of class whose hierarchy should be printed. "
 998              "If not specified, all class hierarchies are printed.",
 999              "STRING", false) {
1000   _dcmdparser.add_dcmd_option(&_print_interfaces);
1001   _dcmdparser.add_dcmd_option(&_print_subclasses);
1002   _dcmdparser.add_dcmd_argument(&_classname);
1003 }
1004 
1005 void ClassHierarchyDCmd::execute(DCmdSource source, TRAPS) {
1006   VM_PrintClassHierarchy printClassHierarchyOp(output(), _print_interfaces.value(),
1007                                                _print_subclasses.value(), _classname.value());
1008   VMThread::execute(&printClassHierarchyOp);
1009 }
1010 
1011 int ClassHierarchyDCmd::num_arguments() {
1012   ResourceMark rm;
1013   ClassHierarchyDCmd* dcmd = new ClassHierarchyDCmd(NULL, false);
1014   if (dcmd != NULL) {
1015     DCmdMark mark(dcmd);
1016     return dcmd->_dcmdparser.num_arguments();
1017   } else {
1018     return 0;
1019   }
1020 }
1021 
1022 #endif
1023 
1024 class VM_DumpTouchedMethods : public VM_Operation {
1025 private:
1026   outputStream* _out;
1027 public:
1028   VM_DumpTouchedMethods(outputStream* out) {
1029     _out = out;
1030   }
1031 
1032   virtual VMOp_Type type() const { return VMOp_DumpTouchedMethods; }
1033 
1034   virtual void doit() {
1035     Method::print_touched_methods(_out);
1036   }
1037 };
1038 
1039 TouchedMethodsDCmd::TouchedMethodsDCmd(outputStream* output, bool heap) :
1040                                        DCmdWithParser(output, heap)
1041 {}
1042 
1043 void TouchedMethodsDCmd::execute(DCmdSource source, TRAPS) {
1044   if (!LogTouchedMethods) {
1045     output()->print_cr("VM.print_touched_methods command requires -XX:+LogTouchedMethods");
1046     return;
1047   }
1048   VM_DumpTouchedMethods dumper(output());
1049   VMThread::execute(&dumper);
1050 }
1051 
1052 int TouchedMethodsDCmd::num_arguments() {
1053   return 0;
1054 }