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/classLoaderStats.hpp"
  28 #include "classfile/compactHashtable.hpp"
  29 #include "compiler/compileBroker.hpp"
  30 #include "compiler/directivesParser.hpp"
  31 #include "gc/shared/vmGCOperations.hpp"
  32 #include "memory/metaspace/metaspaceDCmd.hpp"
  33 #include "memory/resourceArea.hpp"
  34 #include "oops/objArrayOop.inline.hpp"
  35 #include "oops/oop.inline.hpp"
  36 #include "oops/typeArrayOop.inline.hpp"
  37 #include "runtime/flags/jvmFlag.hpp"
  38 #include "runtime/handles.inline.hpp"
  39 #include "runtime/javaCalls.hpp"
  40 #include "runtime/os.hpp"
  41 #include "services/diagnosticArgument.hpp"
  42 #include "services/diagnosticCommand.hpp"
  43 #include "services/diagnosticFramework.hpp"
  44 #include "services/heapDumper.hpp"
  45 #include "services/management.hpp"
  46 #include "services/writeableFlags.hpp"
  47 #include "utilities/debug.hpp"
  48 #include "utilities/formatBuffer.hpp"
  49 #include "utilities/macros.hpp"
  50 
  51 
  52 static void loadAgentModule(TRAPS) {
  53   ResourceMark rm(THREAD);
  54   HandleMark hm(THREAD);
  55 
  56   JavaValue result(T_OBJECT);
  57   Handle h_module_name = java_lang_String::create_from_str("jdk.management.agent", CHECK);
  58   JavaCalls::call_static(&result,
  59                          SystemDictionary::module_Modules_klass(),
  60                          vmSymbols::loadModule_name(),
  61                          vmSymbols::loadModule_signature(),
  62                          h_module_name,
  63                          THREAD);
  64 }
  65 
  66 void DCmdRegistrant::register_dcmds(){
  67   // Registration of the diagnostic commands
  68   // First argument specifies which interfaces will export the command
  69   // Second argument specifies if the command is enabled
  70   // Third  argument specifies if the command is hidden
  71   uint32_t full_export = DCmd_Source_Internal | DCmd_Source_AttachAPI
  72                          | DCmd_Source_MBean;
  73   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HelpDCmd>(full_export, true, false));
  74   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VersionDCmd>(full_export, true, false));
  75   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CommandLineDCmd>(full_export, true, false));
  76   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PrintSystemPropertiesDCmd>(full_export, true, false));
  77   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PrintVMFlagsDCmd>(full_export, true, false));
  78   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SetVMFlagDCmd>(full_export, true, false));
  79   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMDynamicLibrariesDCmd>(full_export, true, false));
  80   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMUptimeDCmd>(full_export, true, false));
  81   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMInfoDCmd>(full_export, true, false));
  82   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SystemGCDCmd>(full_export, true, false));
  83   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<RunFinalizationDCmd>(full_export, true, false));
  84   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HeapInfoDCmd>(full_export, true, false));
  85   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<FinalizerInfoDCmd>(full_export, true, false));
  86 #if INCLUDE_SERVICES
  87   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HeapDumpDCmd>(DCmd_Source_Internal | DCmd_Source_AttachAPI, true, false));
  88   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassHistogramDCmd>(full_export, true, false));
  89   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassStatsDCmd>(full_export, true, false));
  90   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SystemDictionaryDCmd>(full_export, true, false));
  91   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassHierarchyDCmd>(full_export, true, false));
  92   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SymboltableDCmd>(full_export, true, false));
  93   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<StringtableDCmd>(full_export, true, false));
  94   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<metaspace::MetaspaceDCmd>(full_export, true, false));
  95 #if INCLUDE_JVMTI // Both JVMTI and SERVICES have to be enabled to have this dcmd
  96   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JVMTIAgentLoadDCmd>(full_export, true, false));
  97 #endif // INCLUDE_JVMTI
  98 #endif // INCLUDE_SERVICES
  99 #if INCLUDE_JVMTI
 100   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JVMTIDataDumpDCmd>(full_export, true, false));
 101 #endif // INCLUDE_JVMTI
 102   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ThreadDumpDCmd>(full_export, true, false));
 103   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassLoaderStatsDCmd>(full_export, true, false));
 104   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompileQueueDCmd>(full_export, true, false));
 105   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CodeListDCmd>(full_export, true, false));
 106   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CodeCacheDCmd>(full_export, true, false));
 107   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<TouchedMethodsDCmd>(full_export, true, false));
 108   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CodeHeapAnalyticsDCmd>(full_export, true, false));
 109 
 110   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompilerDirectivesPrintDCmd>(full_export, true, false));
 111   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompilerDirectivesAddDCmd>(full_export, true, false));
 112   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompilerDirectivesRemoveDCmd>(full_export, true, false));
 113   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompilerDirectivesClearDCmd>(full_export, true, false));
 114 
 115   // Enhanced JMX Agent Support
 116   // These commands won't be exported via the DiagnosticCommandMBean until an
 117   // appropriate permission is created for them
 118   uint32_t jmx_agent_export_flags = DCmd_Source_Internal | DCmd_Source_AttachAPI;
 119   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStartRemoteDCmd>(jmx_agent_export_flags, true,false));
 120   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStartLocalDCmd>(jmx_agent_export_flags, true,false));
 121   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStopRemoteDCmd>(jmx_agent_export_flags, true,false));
 122   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStatusDCmd>(jmx_agent_export_flags, true,false));
 123 
 124 }
 125 
 126 #ifndef HAVE_EXTRA_DCMD
 127 void DCmdRegistrant::register_dcmds_ext(){
 128    // Do nothing here
 129 }
 130 #endif
 131 
 132 
 133 HelpDCmd::HelpDCmd(outputStream* output, bool heap) : DCmdWithParser(output, heap),
 134   _all("-all", "Show help for all commands", "BOOLEAN", false, "false"),
 135   _cmd("command name", "The name of the command for which we want help",
 136         "STRING", false) {
 137   _dcmdparser.add_dcmd_option(&_all);
 138   _dcmdparser.add_dcmd_argument(&_cmd);
 139 };
 140 
 141 
 142 static int compare_strings(const char** s1, const char** s2) {
 143   return ::strcmp(*s1, *s2);
 144 }
 145 
 146 void HelpDCmd::execute(DCmdSource source, TRAPS) {
 147   if (_all.value()) {
 148     GrowableArray<const char*>* cmd_list = DCmdFactory::DCmd_list(source);
 149     cmd_list->sort(compare_strings);
 150     for (int i = 0; i < cmd_list->length(); i++) {
 151       DCmdFactory* factory = DCmdFactory::factory(source, cmd_list->at(i),
 152                                                   strlen(cmd_list->at(i)));
 153       output()->print_cr("%s%s", factory->name(),
 154                          factory->is_enabled() ? "" : " [disabled]");
 155       output()->print_cr("\t%s", factory->description());
 156       output()->cr();
 157       factory = factory->next();
 158     }
 159   } else if (_cmd.has_value()) {
 160     DCmd* cmd = NULL;
 161     DCmdFactory* factory = DCmdFactory::factory(source, _cmd.value(),
 162                                                 strlen(_cmd.value()));
 163     if (factory != NULL) {
 164       output()->print_cr("%s%s", factory->name(),
 165                          factory->is_enabled() ? "" : " [disabled]");
 166       output()->print_cr("%s", factory->description());
 167       output()->print_cr("\nImpact: %s", factory->impact());
 168       JavaPermission p = factory->permission();
 169       if(p._class != NULL) {
 170         if(p._action != NULL) {
 171           output()->print_cr("\nPermission: %s(%s, %s)",
 172                   p._class, p._name == NULL ? "null" : p._name, p._action);
 173         } else {
 174           output()->print_cr("\nPermission: %s(%s)",
 175                   p._class, p._name == NULL ? "null" : p._name);
 176         }
 177       }
 178       output()->cr();
 179       cmd = factory->create_resource_instance(output());
 180       if (cmd != NULL) {
 181         DCmdMark mark(cmd);
 182         cmd->print_help(factory->name());
 183       }
 184     } else {
 185       output()->print_cr("Help unavailable : '%s' : No such command", _cmd.value());
 186     }
 187   } else {
 188     output()->print_cr("The following commands are available:");
 189     GrowableArray<const char *>* cmd_list = DCmdFactory::DCmd_list(source);
 190     cmd_list->sort(compare_strings);
 191     for (int i = 0; i < cmd_list->length(); i++) {
 192       DCmdFactory* factory = DCmdFactory::factory(source, cmd_list->at(i),
 193                                                   strlen(cmd_list->at(i)));
 194       output()->print_cr("%s%s", factory->name(),
 195                          factory->is_enabled() ? "" : " [disabled]");
 196       factory = factory->_next;
 197     }
 198     output()->print_cr("\nFor more information about a specific command use 'help <command>'.");
 199   }
 200 }
 201 
 202 int HelpDCmd::num_arguments() {
 203   ResourceMark rm;
 204   HelpDCmd* dcmd = new HelpDCmd(NULL, false);
 205   if (dcmd != NULL) {
 206     DCmdMark mark(dcmd);
 207     return dcmd->_dcmdparser.num_arguments();
 208   } else {
 209     return 0;
 210   }
 211 }
 212 
 213 void VersionDCmd::execute(DCmdSource source, TRAPS) {
 214   output()->print_cr("%s version %s", Abstract_VM_Version::vm_name(),
 215           Abstract_VM_Version::vm_release());
 216   JDK_Version jdk_version = JDK_Version::current();
 217   if (jdk_version.patch_version() > 0) {
 218     output()->print_cr("JDK %d.%d.%d.%d", jdk_version.major_version(),
 219             jdk_version.minor_version(), jdk_version.security_version(),
 220             jdk_version.patch_version());
 221   } else {
 222     output()->print_cr("JDK %d.%d.%d", jdk_version.major_version(),
 223             jdk_version.minor_version(), jdk_version.security_version());
 224   }
 225 }
 226 
 227 PrintVMFlagsDCmd::PrintVMFlagsDCmd(outputStream* output, bool heap) :
 228                                    DCmdWithParser(output, heap),
 229   _all("-all", "Print all flags supported by the VM", "BOOLEAN", false, "false") {
 230   _dcmdparser.add_dcmd_option(&_all);
 231 }
 232 
 233 void PrintVMFlagsDCmd::execute(DCmdSource source, TRAPS) {
 234   if (_all.value()) {
 235     JVMFlag::printFlags(output(), true);
 236   } else {
 237     JVMFlag::printSetFlags(output());
 238   }
 239 }
 240 
 241 int PrintVMFlagsDCmd::num_arguments() {
 242     ResourceMark rm;
 243     PrintVMFlagsDCmd* dcmd = new PrintVMFlagsDCmd(NULL, false);
 244     if (dcmd != NULL) {
 245       DCmdMark mark(dcmd);
 246       return dcmd->_dcmdparser.num_arguments();
 247     } else {
 248       return 0;
 249     }
 250 }
 251 
 252 SetVMFlagDCmd::SetVMFlagDCmd(outputStream* output, bool heap) :
 253                                    DCmdWithParser(output, heap),
 254   _flag("flag name", "The name of the flag we want to set",
 255         "STRING", true),
 256   _value("string value", "The value we want to set", "STRING", false) {
 257   _dcmdparser.add_dcmd_argument(&_flag);
 258   _dcmdparser.add_dcmd_argument(&_value);
 259 }
 260 
 261 void SetVMFlagDCmd::execute(DCmdSource source, TRAPS) {
 262   const char* val = NULL;
 263   if (_value.value() != NULL) {
 264     val = _value.value();
 265   }
 266 
 267   FormatBuffer<80> err_msg("%s", "");
 268   int ret = WriteableFlags::set_flag(_flag.value(), val, JVMFlag::MANAGEMENT, err_msg);
 269 
 270   if (ret != JVMFlag::SUCCESS) {
 271     output()->print_cr("%s", err_msg.buffer());
 272   }
 273 }
 274 
 275 int SetVMFlagDCmd::num_arguments() {
 276   ResourceMark rm;
 277   SetVMFlagDCmd* dcmd = new SetVMFlagDCmd(NULL, false);
 278   if (dcmd != NULL) {
 279     DCmdMark mark(dcmd);
 280     return dcmd->_dcmdparser.num_arguments();
 281   } else {
 282     return 0;
 283   }
 284 }
 285 
 286 void JVMTIDataDumpDCmd::execute(DCmdSource source, TRAPS) {
 287   if (JvmtiExport::should_post_data_dump()) {
 288     JvmtiExport::post_data_dump();
 289   }
 290 }
 291 
 292 #if INCLUDE_SERVICES
 293 JVMTIAgentLoadDCmd::JVMTIAgentLoadDCmd(outputStream* output, bool heap) :
 294                                        DCmdWithParser(output, heap),
 295   _libpath("library path", "Absolute path of the JVMTI agent to load.",
 296            "STRING", true),
 297   _option("agent option", "Option string to pass the agent.", "STRING", false) {
 298   _dcmdparser.add_dcmd_argument(&_libpath);
 299   _dcmdparser.add_dcmd_argument(&_option);
 300 }
 301 
 302 void JVMTIAgentLoadDCmd::execute(DCmdSource source, TRAPS) {
 303 
 304   if (_libpath.value() == NULL) {
 305     output()->print_cr("JVMTI.agent_load dcmd needs library path.");
 306     return;
 307   }
 308 
 309   char *suffix = strrchr(_libpath.value(), '.');
 310   bool is_java_agent = (suffix != NULL) && (strncmp(".jar", suffix, 4) == 0);
 311 
 312   if (is_java_agent) {
 313     if (_option.value() == NULL) {
 314       JvmtiExport::load_agent_library("instrument", "false",
 315                                       _libpath.value(), output());
 316     } else {
 317       size_t opt_len = strlen(_libpath.value()) + strlen(_option.value()) + 2;
 318       if (opt_len > 4096) {
 319         output()->print_cr("JVMTI agent attach failed: Options is too long.");
 320         return;
 321       }
 322 
 323       char *opt = (char *)os::malloc(opt_len, mtInternal);
 324       if (opt == NULL) {
 325         output()->print_cr("JVMTI agent attach failed: "
 326                            "Could not allocate " SIZE_FORMAT " bytes for argument.",
 327                            opt_len);
 328         return;
 329       }
 330 
 331       jio_snprintf(opt, opt_len, "%s=%s", _libpath.value(), _option.value());
 332       JvmtiExport::load_agent_library("instrument", "false", opt, output());
 333 
 334       os::free(opt);
 335     }
 336   } else {
 337     JvmtiExport::load_agent_library(_libpath.value(), "true",
 338                                     _option.value(), output());
 339   }
 340 }
 341 
 342 int JVMTIAgentLoadDCmd::num_arguments() {
 343   ResourceMark rm;
 344   JVMTIAgentLoadDCmd* dcmd = new JVMTIAgentLoadDCmd(NULL, false);
 345   if (dcmd != NULL) {
 346     DCmdMark mark(dcmd);
 347     return dcmd->_dcmdparser.num_arguments();
 348   } else {
 349     return 0;
 350   }
 351 }
 352 #endif // INCLUDE_SERVICES
 353 
 354 void PrintSystemPropertiesDCmd::execute(DCmdSource source, TRAPS) {
 355   // load VMSupport
 356   Symbol* klass = vmSymbols::jdk_internal_vm_VMSupport();
 357   Klass* k = SystemDictionary::resolve_or_fail(klass, true, CHECK);
 358   InstanceKlass* ik = InstanceKlass::cast(k);
 359   if (ik->should_be_initialized()) {
 360     ik->initialize(THREAD);
 361   }
 362   if (HAS_PENDING_EXCEPTION) {
 363     java_lang_Throwable::print(PENDING_EXCEPTION, output());
 364     output()->cr();
 365     CLEAR_PENDING_EXCEPTION;
 366     return;
 367   }
 368 
 369   // invoke the serializePropertiesToByteArray method
 370   JavaValue result(T_OBJECT);
 371   JavaCallArguments args;
 372 
 373   Symbol* signature = vmSymbols::serializePropertiesToByteArray_signature();
 374   JavaCalls::call_static(&result,
 375                          ik,
 376                          vmSymbols::serializePropertiesToByteArray_name(),
 377                          signature,
 378                          &args,
 379                          THREAD);
 380   if (HAS_PENDING_EXCEPTION) {
 381     java_lang_Throwable::print(PENDING_EXCEPTION, output());
 382     output()->cr();
 383     CLEAR_PENDING_EXCEPTION;
 384     return;
 385   }
 386 
 387   // The result should be a [B
 388   oop res = (oop)result.get_jobject();
 389   assert(res->is_typeArray(), "just checking");
 390   assert(TypeArrayKlass::cast(res->klass())->element_type() == T_BYTE, "just checking");
 391 
 392   // copy the bytes to the output stream
 393   typeArrayOop ba = typeArrayOop(res);
 394   jbyte* addr = typeArrayOop(res)->byte_at_addr(0);
 395   output()->print_raw((const char*)addr, ba->length());
 396 }
 397 
 398 VMUptimeDCmd::VMUptimeDCmd(outputStream* output, bool heap) :
 399                            DCmdWithParser(output, heap),
 400   _date("-date", "Add a prefix with current date", "BOOLEAN", false, "false") {
 401   _dcmdparser.add_dcmd_option(&_date);
 402 }
 403 
 404 void VMUptimeDCmd::execute(DCmdSource source, TRAPS) {
 405   if (_date.value()) {
 406     output()->date_stamp(true, "", ": ");
 407   }
 408   output()->time_stamp().update_to(tty->time_stamp().ticks());
 409   output()->stamp();
 410   output()->print_cr(" s");
 411 }
 412 
 413 int VMUptimeDCmd::num_arguments() {
 414   ResourceMark rm;
 415   VMUptimeDCmd* dcmd = new VMUptimeDCmd(NULL, false);
 416   if (dcmd != NULL) {
 417     DCmdMark mark(dcmd);
 418     return dcmd->_dcmdparser.num_arguments();
 419   } else {
 420     return 0;
 421   }
 422 }
 423 
 424 void VMInfoDCmd::execute(DCmdSource source, TRAPS) {
 425   VMError::print_vm_info(_output);
 426 }
 427 
 428 void SystemGCDCmd::execute(DCmdSource source, TRAPS) {
 429   Universe::heap()->collect(GCCause::_dcmd_gc_run);
 430 }
 431 
 432 void RunFinalizationDCmd::execute(DCmdSource source, TRAPS) {
 433   Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_System(),
 434                                                  true, CHECK);
 435   JavaValue result(T_VOID);
 436   JavaCalls::call_static(&result, k,
 437                          vmSymbols::run_finalization_name(),
 438                          vmSymbols::void_method_signature(), CHECK);
 439 }
 440 
 441 void HeapInfoDCmd::execute(DCmdSource source, TRAPS) {
 442   MutexLocker hl(Heap_lock);
 443   Universe::heap()->print_on(output());
 444 }
 445 
 446 void FinalizerInfoDCmd::execute(DCmdSource source, TRAPS) {
 447   ResourceMark rm;
 448 
 449   Klass* k = SystemDictionary::resolve_or_fail(
 450     vmSymbols::finalizer_histogram_klass(), true, CHECK);
 451 
 452   JavaValue result(T_ARRAY);
 453 
 454   // We are calling lang.ref.FinalizerHistogram.getFinalizerHistogram() method
 455   // and expect it to return array of FinalizerHistogramEntry as Object[]
 456 
 457   JavaCalls::call_static(&result, k,
 458                          vmSymbols::get_finalizer_histogram_name(),
 459                          vmSymbols::void_finalizer_histogram_entry_array_signature(), CHECK);
 460 
 461   objArrayOop result_oop = (objArrayOop) result.get_jobject();
 462   if (result_oop->length() == 0) {
 463     output()->print_cr("No instances waiting for finalization found");
 464     return;
 465   }
 466 
 467   oop foop = result_oop->obj_at(0);
 468   InstanceKlass* ik = InstanceKlass::cast(foop->klass());
 469 
 470   fieldDescriptor count_fd, name_fd;
 471 
 472   Klass* count_res = ik->find_field(
 473     vmSymbols::finalizer_histogram_entry_count_field(), vmSymbols::int_signature(), &count_fd);
 474 
 475   Klass* name_res = ik->find_field(
 476     vmSymbols::finalizer_histogram_entry_name_field(), vmSymbols::string_signature(), &name_fd);
 477 
 478   assert(count_res != NULL && name_res != NULL, "Unexpected layout of FinalizerHistogramEntry");
 479 
 480   output()->print_cr("Unreachable instances waiting for finalization");
 481   output()->print_cr("#instances  class name");
 482   output()->print_cr("-----------------------");
 483 
 484   for (int i = 0; i < result_oop->length(); ++i) {
 485     oop element_oop = result_oop->obj_at(i);
 486     oop str_oop = element_oop->obj_field(name_fd.offset());
 487     char *name = java_lang_String::as_utf8_string(str_oop);
 488     int count = element_oop->int_field(count_fd.offset());
 489     output()->print_cr("%10d  %s", count, name);
 490   }
 491 }
 492 
 493 #if INCLUDE_SERVICES // Heap dumping/inspection supported
 494 HeapDumpDCmd::HeapDumpDCmd(outputStream* output, bool heap) :
 495                            DCmdWithParser(output, heap),
 496   _filename("filename","Name of the dump file", "STRING",true),
 497   _all("-all", "Dump all objects, including unreachable objects",
 498        "BOOLEAN", false, "false") {
 499   _dcmdparser.add_dcmd_option(&_all);
 500   _dcmdparser.add_dcmd_argument(&_filename);
 501 }
 502 
 503 void HeapDumpDCmd::execute(DCmdSource source, TRAPS) {
 504   // Request a full GC before heap dump if _all is false
 505   // This helps reduces the amount of unreachable objects in the dump
 506   // and makes it easier to browse.
 507   HeapDumper dumper(!_all.value() /* request GC if _all is false*/);
 508   int res = dumper.dump(_filename.value());
 509   if (res == 0) {
 510     output()->print_cr("Heap dump file created");
 511   } else {
 512     // heap dump failed
 513     ResourceMark rm;
 514     char* error = dumper.error_as_C_string();
 515     if (error == NULL) {
 516       output()->print_cr("Dump failed - reason unknown");
 517     } else {
 518       output()->print_cr("%s", error);
 519     }
 520   }
 521 }
 522 
 523 int HeapDumpDCmd::num_arguments() {
 524   ResourceMark rm;
 525   HeapDumpDCmd* dcmd = new HeapDumpDCmd(NULL, false);
 526   if (dcmd != NULL) {
 527     DCmdMark mark(dcmd);
 528     return dcmd->_dcmdparser.num_arguments();
 529   } else {
 530     return 0;
 531   }
 532 }
 533 
 534 ClassHistogramDCmd::ClassHistogramDCmd(outputStream* output, bool heap) :
 535                                        DCmdWithParser(output, heap),
 536   _all("-all", "Inspect all objects, including unreachable objects",
 537        "BOOLEAN", false, "false") {
 538   _dcmdparser.add_dcmd_option(&_all);
 539 }
 540 
 541 void ClassHistogramDCmd::execute(DCmdSource source, TRAPS) {
 542   VM_GC_HeapInspection heapop(output(),
 543                               !_all.value() /* request full gc if false */);
 544   VMThread::execute(&heapop);
 545 }
 546 
 547 int ClassHistogramDCmd::num_arguments() {
 548   ResourceMark rm;
 549   ClassHistogramDCmd* dcmd = new ClassHistogramDCmd(NULL, false);
 550   if (dcmd != NULL) {
 551     DCmdMark mark(dcmd);
 552     return dcmd->_dcmdparser.num_arguments();
 553   } else {
 554     return 0;
 555   }
 556 }
 557 
 558 #define DEFAULT_COLUMNS "InstBytes,KlassBytes,CpAll,annotations,MethodCount,Bytecodes,MethodAll,ROAll,RWAll,Total"
 559 ClassStatsDCmd::ClassStatsDCmd(outputStream* output, bool heap) :
 560                                        DCmdWithParser(output, heap),
 561   _csv("-csv", "Print in CSV (comma-separated values) format for spreadsheets",
 562        "BOOLEAN", false, "false"),
 563   _all("-all", "Show all columns",
 564        "BOOLEAN", false, "false"),
 565   _help("-help", "Show meaning of all the columns",
 566        "BOOLEAN", false, "false"),
 567   _columns("columns", "Comma-separated list of all the columns to show. "
 568            "If not specified, the following columns are shown: " DEFAULT_COLUMNS,
 569            "STRING", false) {
 570   _dcmdparser.add_dcmd_option(&_all);
 571   _dcmdparser.add_dcmd_option(&_csv);
 572   _dcmdparser.add_dcmd_option(&_help);
 573   _dcmdparser.add_dcmd_argument(&_columns);
 574 }
 575 
 576 void ClassStatsDCmd::execute(DCmdSource source, TRAPS) {
 577   VM_GC_HeapInspection heapop(output(),
 578                               true /* request_full_gc */);
 579   heapop.set_csv_format(_csv.value());
 580   heapop.set_print_help(_help.value());
 581   heapop.set_print_class_stats(true);
 582   if (_all.value()) {
 583     if (_columns.has_value()) {
 584       output()->print_cr("Cannot specify -all and individual columns at the same time");
 585       return;
 586     } else {
 587       heapop.set_columns(NULL);
 588     }
 589   } else {
 590     if (_columns.has_value()) {
 591       heapop.set_columns(_columns.value());
 592     } else {
 593       heapop.set_columns(DEFAULT_COLUMNS);
 594     }
 595   }
 596   VMThread::execute(&heapop);
 597 }
 598 
 599 int ClassStatsDCmd::num_arguments() {
 600   ResourceMark rm;
 601   ClassStatsDCmd* dcmd = new ClassStatsDCmd(NULL, false);
 602   if (dcmd != NULL) {
 603     DCmdMark mark(dcmd);
 604     return dcmd->_dcmdparser.num_arguments();
 605   } else {
 606     return 0;
 607   }
 608 }
 609 #endif // INCLUDE_SERVICES
 610 
 611 ThreadDumpDCmd::ThreadDumpDCmd(outputStream* output, bool heap) :
 612                                DCmdWithParser(output, heap),
 613   _locks("-l", "print java.util.concurrent locks", "BOOLEAN", false, "false"),
 614   _extended("-e", "print extended thread information", "BOOLEAN", false, "false") {
 615   _dcmdparser.add_dcmd_option(&_locks);
 616   _dcmdparser.add_dcmd_option(&_extended);
 617 }
 618 
 619 void ThreadDumpDCmd::execute(DCmdSource source, TRAPS) {
 620   // thread stacks
 621   VM_PrintThreads op1(output(), _locks.value(), _extended.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 }