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/fieldDescriptor.inline.hpp"
  39 #include "runtime/flags/jvmFlag.hpp"
  40 #include "runtime/handles.inline.hpp"
  41 #include "runtime/javaCalls.hpp"
  42 #include "runtime/os.hpp"
  43 #include "services/diagnosticArgument.hpp"
  44 #include "services/diagnosticCommand.hpp"
  45 #include "services/diagnosticFramework.hpp"
  46 #include "services/heapDumper.hpp"
  47 #include "services/management.hpp"
  48 #include "services/writeableFlags.hpp"
  49 #include "utilities/debug.hpp"
  50 #include "utilities/formatBuffer.hpp"
  51 #include "utilities/macros.hpp"
  52 
  53 
  54 static void loadAgentModule(TRAPS) {
  55   ResourceMark rm(THREAD);
  56   HandleMark hm(THREAD);
  57 
  58   JavaValue result(T_OBJECT);
  59   Handle h_module_name = java_lang_String::create_from_str("jdk.management.agent", CHECK);
  60   JavaCalls::call_static(&result,
  61                          SystemDictionary::module_Modules_klass(),
  62                          vmSymbols::loadModule_name(),
  63                          vmSymbols::loadModule_signature(),
  64                          h_module_name,
  65                          THREAD);
  66 }
  67 
  68 void DCmdRegistrant::register_dcmds(){
  69   // Registration of the diagnostic commands
  70   // First argument specifies which interfaces will export the command
  71   // Second argument specifies if the command is enabled
  72   // Third  argument specifies if the command is hidden
  73   uint32_t full_export = DCmd_Source_Internal | DCmd_Source_AttachAPI
  74                          | DCmd_Source_MBean;
  75   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HelpDCmd>(full_export, true, false));
  76   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VersionDCmd>(full_export, true, false));
  77   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CommandLineDCmd>(full_export, true, false));
  78   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PrintSystemPropertiesDCmd>(full_export, true, false));
  79   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PrintVMFlagsDCmd>(full_export, true, false));
  80   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SetVMFlagDCmd>(full_export, true, false));
  81   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMDynamicLibrariesDCmd>(full_export, true, false));
  82   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMUptimeDCmd>(full_export, true, false));
  83   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMInfoDCmd>(full_export, true, false));
  84   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SystemGCDCmd>(full_export, true, false));
  85   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<RunFinalizationDCmd>(full_export, true, false));
  86   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HeapInfoDCmd>(full_export, true, false));
  87   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<FinalizerInfoDCmd>(full_export, true, false));
  88 #if INCLUDE_SERVICES
  89   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HeapDumpDCmd>(DCmd_Source_Internal | DCmd_Source_AttachAPI, true, false));
  90   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassHistogramDCmd>(full_export, true, false));
  91   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassStatsDCmd>(full_export, true, false));
  92   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SystemDictionaryDCmd>(full_export, true, false));
  93   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassHierarchyDCmd>(full_export, true, false));
  94   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SymboltableDCmd>(full_export, true, false));
  95   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<StringtableDCmd>(full_export, true, false));
  96   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<metaspace::MetaspaceDCmd>(full_export, true, false));
  97 #if INCLUDE_JVMTI // Both JVMTI and SERVICES have to be enabled to have this dcmd
  98   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JVMTIAgentLoadDCmd>(full_export, true, false));
  99 #endif // INCLUDE_JVMTI
 100 #endif // INCLUDE_SERVICES
 101 #if INCLUDE_JVMTI
 102   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JVMTIDataDumpDCmd>(full_export, true, false));
 103 #endif // INCLUDE_JVMTI
 104   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ThreadDumpDCmd>(full_export, true, false));
 105   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassLoaderStatsDCmd>(full_export, true, false));
 106   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassLoaderHierarchyDCmd>(full_export, true, false));
 107   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompileQueueDCmd>(full_export, true, false));
 108   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CodeListDCmd>(full_export, true, false));
 109   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CodeCacheDCmd>(full_export, true, false));
 110   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<TouchedMethodsDCmd>(full_export, true, false));
 111   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CodeHeapAnalyticsDCmd>(full_export, true, false));
 112 
 113   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompilerDirectivesPrintDCmd>(full_export, true, false));
 114   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompilerDirectivesAddDCmd>(full_export, true, false));
 115   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompilerDirectivesRemoveDCmd>(full_export, true, false));
 116   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompilerDirectivesClearDCmd>(full_export, true, false));
 117 
 118   // Enhanced JMX Agent Support
 119   // These commands won't be exported via the DiagnosticCommandMBean until an
 120   // appropriate permission is created for them
 121   uint32_t jmx_agent_export_flags = DCmd_Source_Internal | DCmd_Source_AttachAPI;
 122   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStartRemoteDCmd>(jmx_agent_export_flags, true,false));
 123   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStartLocalDCmd>(jmx_agent_export_flags, true,false));
 124   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStopRemoteDCmd>(jmx_agent_export_flags, true,false));
 125   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStatusDCmd>(jmx_agent_export_flags, true,false));
 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   _all("-all", "Show all columns",
 564        "BOOLEAN", false, "false"),
 565   _csv("-csv", "Print in CSV (comma-separated values) format for spreadsheets",
 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   _extended("-e", "print extended thread information", "BOOLEAN", false, "false") {
 617   _dcmdparser.add_dcmd_option(&_locks);
 618   _dcmdparser.add_dcmd_option(&_extended);
 619 }
 620 
 621 void ThreadDumpDCmd::execute(DCmdSource source, TRAPS) {
 622   // thread stacks
 623   VM_PrintThreads op1(output(), _locks.value(), _extended.value());
 624   VMThread::execute(&op1);
 625 
 626   // JNI global handles
 627   VM_PrintJNI op2(output());
 628   VMThread::execute(&op2);
 629 
 630   // Deadlock detection
 631   VM_FindDeadlocks op3(output());
 632   VMThread::execute(&op3);
 633 }
 634 
 635 int ThreadDumpDCmd::num_arguments() {
 636   ResourceMark rm;
 637   ThreadDumpDCmd* dcmd = new ThreadDumpDCmd(NULL, false);
 638   if (dcmd != NULL) {
 639     DCmdMark mark(dcmd);
 640     return dcmd->_dcmdparser.num_arguments();
 641   } else {
 642     return 0;
 643   }
 644 }
 645 
 646 // Enhanced JMX Agent support
 647 
 648 JMXStartRemoteDCmd::JMXStartRemoteDCmd(outputStream *output, bool heap_allocated) :
 649 
 650   DCmdWithParser(output, heap_allocated),
 651 
 652   _config_file
 653   ("config.file",
 654    "set com.sun.management.config.file", "STRING", false),
 655 
 656   _jmxremote_host
 657   ("jmxremote.host",
 658    "set com.sun.management.jmxremote.host", "STRING", false),
 659 
 660   _jmxremote_port
 661   ("jmxremote.port",
 662    "set com.sun.management.jmxremote.port", "STRING", false),
 663 
 664   _jmxremote_rmi_port
 665   ("jmxremote.rmi.port",
 666    "set com.sun.management.jmxremote.rmi.port", "STRING", false),
 667 
 668   _jmxremote_ssl
 669   ("jmxremote.ssl",
 670    "set com.sun.management.jmxremote.ssl", "STRING", false),
 671 
 672   _jmxremote_registry_ssl
 673   ("jmxremote.registry.ssl",
 674    "set com.sun.management.jmxremote.registry.ssl", "STRING", false),
 675 
 676   _jmxremote_authenticate
 677   ("jmxremote.authenticate",
 678    "set com.sun.management.jmxremote.authenticate", "STRING", false),
 679 
 680   _jmxremote_password_file
 681   ("jmxremote.password.file",
 682    "set com.sun.management.jmxremote.password.file", "STRING", false),
 683 
 684   _jmxremote_access_file
 685   ("jmxremote.access.file",
 686    "set com.sun.management.jmxremote.access.file", "STRING", false),
 687 
 688   _jmxremote_login_config
 689   ("jmxremote.login.config",
 690    "set com.sun.management.jmxremote.login.config", "STRING", false),
 691 
 692   _jmxremote_ssl_enabled_cipher_suites
 693   ("jmxremote.ssl.enabled.cipher.suites",
 694    "set com.sun.management.jmxremote.ssl.enabled.cipher.suite", "STRING", false),
 695 
 696   _jmxremote_ssl_enabled_protocols
 697   ("jmxremote.ssl.enabled.protocols",
 698    "set com.sun.management.jmxremote.ssl.enabled.protocols", "STRING", false),
 699 
 700   _jmxremote_ssl_need_client_auth
 701   ("jmxremote.ssl.need.client.auth",
 702    "set com.sun.management.jmxremote.need.client.auth", "STRING", false),
 703 
 704   _jmxremote_ssl_config_file
 705   ("jmxremote.ssl.config.file",
 706    "set com.sun.management.jmxremote.ssl_config_file", "STRING", false),
 707 
 708 // JDP Protocol support
 709   _jmxremote_autodiscovery
 710   ("jmxremote.autodiscovery",
 711    "set com.sun.management.jmxremote.autodiscovery", "STRING", false),
 712 
 713    _jdp_port
 714   ("jdp.port",
 715    "set com.sun.management.jdp.port", "INT", false),
 716 
 717    _jdp_address
 718   ("jdp.address",
 719    "set com.sun.management.jdp.address", "STRING", false),
 720 
 721    _jdp_source_addr
 722   ("jdp.source_addr",
 723    "set com.sun.management.jdp.source_addr", "STRING", false),
 724 
 725    _jdp_ttl
 726   ("jdp.ttl",
 727    "set com.sun.management.jdp.ttl", "INT", false),
 728 
 729    _jdp_pause
 730   ("jdp.pause",
 731    "set com.sun.management.jdp.pause", "INT", false),
 732 
 733    _jdp_name
 734   ("jdp.name",
 735    "set com.sun.management.jdp.name", "STRING", false)
 736 
 737   {
 738     _dcmdparser.add_dcmd_option(&_config_file);
 739     _dcmdparser.add_dcmd_option(&_jmxremote_host);
 740     _dcmdparser.add_dcmd_option(&_jmxremote_port);
 741     _dcmdparser.add_dcmd_option(&_jmxremote_rmi_port);
 742     _dcmdparser.add_dcmd_option(&_jmxremote_ssl);
 743     _dcmdparser.add_dcmd_option(&_jmxremote_registry_ssl);
 744     _dcmdparser.add_dcmd_option(&_jmxremote_authenticate);
 745     _dcmdparser.add_dcmd_option(&_jmxremote_password_file);
 746     _dcmdparser.add_dcmd_option(&_jmxremote_access_file);
 747     _dcmdparser.add_dcmd_option(&_jmxremote_login_config);
 748     _dcmdparser.add_dcmd_option(&_jmxremote_ssl_enabled_cipher_suites);
 749     _dcmdparser.add_dcmd_option(&_jmxremote_ssl_enabled_protocols);
 750     _dcmdparser.add_dcmd_option(&_jmxremote_ssl_need_client_auth);
 751     _dcmdparser.add_dcmd_option(&_jmxremote_ssl_config_file);
 752     _dcmdparser.add_dcmd_option(&_jmxremote_autodiscovery);
 753     _dcmdparser.add_dcmd_option(&_jdp_port);
 754     _dcmdparser.add_dcmd_option(&_jdp_address);
 755     _dcmdparser.add_dcmd_option(&_jdp_source_addr);
 756     _dcmdparser.add_dcmd_option(&_jdp_ttl);
 757     _dcmdparser.add_dcmd_option(&_jdp_pause);
 758     _dcmdparser.add_dcmd_option(&_jdp_name);
 759 }
 760 
 761 
 762 int JMXStartRemoteDCmd::num_arguments() {
 763   ResourceMark rm;
 764   JMXStartRemoteDCmd* dcmd = new JMXStartRemoteDCmd(NULL, false);
 765   if (dcmd != NULL) {
 766     DCmdMark mark(dcmd);
 767     return dcmd->_dcmdparser.num_arguments();
 768   } else {
 769     return 0;
 770   }
 771 }
 772 
 773 
 774 void JMXStartRemoteDCmd::execute(DCmdSource source, TRAPS) {
 775     ResourceMark rm(THREAD);
 776     HandleMark hm(THREAD);
 777 
 778     // Load and initialize the jdk.internal.agent.Agent class
 779     // invoke startRemoteManagementAgent(string) method to start
 780     // the remote management server.
 781     // throw java.lang.NoSuchMethodError if the method doesn't exist
 782 
 783     loadAgentModule(CHECK);
 784     Handle loader = Handle(THREAD, SystemDictionary::java_system_loader());
 785     Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::jdk_internal_agent_Agent(), loader, Handle(), true, CHECK);
 786 
 787     JavaValue result(T_VOID);
 788 
 789     // Pass all command line arguments to java as key=value,...
 790     // All checks are done on java side
 791 
 792     int len = 0;
 793     stringStream options;
 794     char comma[2] = {0,0};
 795 
 796     // Leave default values on Agent.class side and pass only
 797     // agruments explicitly set by user. All arguments passed
 798     // to jcmd override properties with the same name set by
 799     // command line with -D or by managmenent.properties
 800     // file.
 801 #define PUT_OPTION(a) \
 802     do { \
 803         if ( (a).is_set() ){ \
 804             if ( *((a).type()) == 'I' ) { \
 805                 options.print("%scom.sun.management.%s=" JLONG_FORMAT, comma, (a).name(), (jlong)((a).value())); \
 806             } else { \
 807                 options.print("%scom.sun.management.%s=%s", comma, (a).name(), (char*)((a).value())); \
 808             } \
 809             comma[0] = ','; \
 810         }\
 811     } while(0);
 812 
 813 
 814     PUT_OPTION(_config_file);
 815     PUT_OPTION(_jmxremote_host);
 816     PUT_OPTION(_jmxremote_port);
 817     PUT_OPTION(_jmxremote_rmi_port);
 818     PUT_OPTION(_jmxremote_ssl);
 819     PUT_OPTION(_jmxremote_registry_ssl);
 820     PUT_OPTION(_jmxremote_authenticate);
 821     PUT_OPTION(_jmxremote_password_file);
 822     PUT_OPTION(_jmxremote_access_file);
 823     PUT_OPTION(_jmxremote_login_config);
 824     PUT_OPTION(_jmxremote_ssl_enabled_cipher_suites);
 825     PUT_OPTION(_jmxremote_ssl_enabled_protocols);
 826     PUT_OPTION(_jmxremote_ssl_need_client_auth);
 827     PUT_OPTION(_jmxremote_ssl_config_file);
 828     PUT_OPTION(_jmxremote_autodiscovery);
 829     PUT_OPTION(_jdp_port);
 830     PUT_OPTION(_jdp_address);
 831     PUT_OPTION(_jdp_source_addr);
 832     PUT_OPTION(_jdp_ttl);
 833     PUT_OPTION(_jdp_pause);
 834     PUT_OPTION(_jdp_name);
 835 
 836 #undef PUT_OPTION
 837 
 838     Handle str = java_lang_String::create_from_str(options.as_string(), CHECK);
 839     JavaCalls::call_static(&result, k, vmSymbols::startRemoteAgent_name(), vmSymbols::string_void_signature(), str, CHECK);
 840 }
 841 
 842 JMXStartLocalDCmd::JMXStartLocalDCmd(outputStream *output, bool heap_allocated) :
 843   DCmd(output, heap_allocated) {
 844   // do nothing
 845 }
 846 
 847 void JMXStartLocalDCmd::execute(DCmdSource source, TRAPS) {
 848     ResourceMark rm(THREAD);
 849     HandleMark hm(THREAD);
 850 
 851     // Load and initialize the jdk.internal.agent.Agent class
 852     // invoke startLocalManagementAgent(void) method to start
 853     // the local management server
 854     // throw java.lang.NoSuchMethodError if method doesn't exist
 855 
 856     loadAgentModule(CHECK);
 857     Handle loader = Handle(THREAD, SystemDictionary::java_system_loader());
 858     Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::jdk_internal_agent_Agent(), loader, Handle(), true, CHECK);
 859 
 860     JavaValue result(T_VOID);
 861     JavaCalls::call_static(&result, k, vmSymbols::startLocalAgent_name(), vmSymbols::void_method_signature(), CHECK);
 862 }
 863 
 864 void JMXStopRemoteDCmd::execute(DCmdSource source, TRAPS) {
 865     ResourceMark rm(THREAD);
 866     HandleMark hm(THREAD);
 867 
 868     // Load and initialize the jdk.internal.agent.Agent class
 869     // invoke stopRemoteManagementAgent method to stop the
 870     // management server
 871     // throw java.lang.NoSuchMethodError if method doesn't exist
 872 
 873     loadAgentModule(CHECK);
 874     Handle loader = Handle(THREAD, SystemDictionary::java_system_loader());
 875     Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::jdk_internal_agent_Agent(), loader, Handle(), true, CHECK);
 876 
 877     JavaValue result(T_VOID);
 878     JavaCalls::call_static(&result, k, vmSymbols::stopRemoteAgent_name(), vmSymbols::void_method_signature(), CHECK);
 879 }
 880 
 881 JMXStatusDCmd::JMXStatusDCmd(outputStream *output, bool heap_allocated) :
 882   DCmd(output, heap_allocated) {
 883   // do nothing
 884 }
 885 
 886 void JMXStatusDCmd::execute(DCmdSource source, TRAPS) {
 887   ResourceMark rm(THREAD);
 888   HandleMark hm(THREAD);
 889 
 890   // Load and initialize the jdk.internal.agent.Agent class
 891   // invoke getManagementAgentStatus() method to generate the status info
 892   // throw java.lang.NoSuchMethodError if method doesn't exist
 893 
 894   loadAgentModule(CHECK);
 895   Handle loader = Handle(THREAD, SystemDictionary::java_system_loader());
 896   Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::jdk_internal_agent_Agent(), loader, Handle(), true, CHECK);
 897 
 898   JavaValue result(T_OBJECT);
 899   JavaCalls::call_static(&result, k, vmSymbols::getAgentStatus_name(), vmSymbols::void_string_signature(), CHECK);
 900 
 901   jvalue* jv = (jvalue*) result.get_value_addr();
 902   oop str = (oop) jv->l;
 903   if (str != NULL) {
 904       char* out = java_lang_String::as_utf8_string(str);
 905       if (out) {
 906           output()->print_cr("%s", out);
 907           return;
 908       }
 909   }
 910   output()->print_cr("Error obtaining management agent status");
 911 }
 912 
 913 VMDynamicLibrariesDCmd::VMDynamicLibrariesDCmd(outputStream *output, bool heap_allocated) :
 914   DCmd(output, heap_allocated) {
 915   // do nothing
 916 }
 917 
 918 void VMDynamicLibrariesDCmd::execute(DCmdSource source, TRAPS) {
 919   os::print_dll_info(output());
 920   output()->cr();
 921 }
 922 
 923 void CompileQueueDCmd::execute(DCmdSource source, TRAPS) {
 924   VM_PrintCompileQueue printCompileQueueOp(output());
 925   VMThread::execute(&printCompileQueueOp);
 926 }
 927 
 928 void CodeListDCmd::execute(DCmdSource source, TRAPS) {
 929   CodeCache::print_codelist(output());
 930 }
 931 
 932 void CodeCacheDCmd::execute(DCmdSource source, TRAPS) {
 933   CodeCache::print_layout(output());
 934 }
 935 
 936 //---<  BEGIN  >--- CodeHeap State Analytics.
 937 CodeHeapAnalyticsDCmd::CodeHeapAnalyticsDCmd(outputStream* output, bool heap) :
 938                                              DCmdWithParser(output, heap),
 939   _function("function", "Function to be performed (aggregate, UsedSpace, FreeSpace, MethodCount, MethodSpace, MethodAge, MethodNames, discard", "STRING", false, "all"),
 940   _granularity("granularity", "Detail level - smaller value -> more detail", "STRING", false, "4096") {
 941   _dcmdparser.add_dcmd_argument(&_function);
 942   _dcmdparser.add_dcmd_argument(&_granularity);
 943 }
 944 
 945 void CodeHeapAnalyticsDCmd::execute(DCmdSource source, TRAPS) {
 946   CompileBroker::print_heapinfo(output(), _function.value(), _granularity.value());
 947 }
 948 
 949 int CodeHeapAnalyticsDCmd::num_arguments() {
 950   ResourceMark rm;
 951   CodeHeapAnalyticsDCmd* dcmd = new CodeHeapAnalyticsDCmd(NULL, false);
 952   if (dcmd != NULL) {
 953     DCmdMark mark(dcmd);
 954     return dcmd->_dcmdparser.num_arguments();
 955   } else {
 956     return 0;
 957   }
 958 }
 959 //---<  END  >--- CodeHeap State Analytics.
 960 
 961 void CompilerDirectivesPrintDCmd::execute(DCmdSource source, TRAPS) {
 962   DirectivesStack::print(output());
 963 }
 964 
 965 CompilerDirectivesAddDCmd::CompilerDirectivesAddDCmd(outputStream* output, bool heap) :
 966                            DCmdWithParser(output, heap),
 967   _filename("filename","Name of the directives file", "STRING",true) {
 968   _dcmdparser.add_dcmd_argument(&_filename);
 969 }
 970 
 971 void CompilerDirectivesAddDCmd::execute(DCmdSource source, TRAPS) {
 972   DirectivesParser::parse_from_file(_filename.value(), output());
 973 }
 974 
 975 int CompilerDirectivesAddDCmd::num_arguments() {
 976   ResourceMark rm;
 977   CompilerDirectivesAddDCmd* dcmd = new CompilerDirectivesAddDCmd(NULL, false);
 978   if (dcmd != NULL) {
 979     DCmdMark mark(dcmd);
 980     return dcmd->_dcmdparser.num_arguments();
 981   } else {
 982     return 0;
 983   }
 984 }
 985 
 986 void CompilerDirectivesRemoveDCmd::execute(DCmdSource source, TRAPS) {
 987   DirectivesStack::pop(1);
 988 }
 989 
 990 void CompilerDirectivesClearDCmd::execute(DCmdSource source, TRAPS) {
 991   DirectivesStack::clear();
 992 }
 993 #if INCLUDE_SERVICES
 994 ClassHierarchyDCmd::ClassHierarchyDCmd(outputStream* output, bool heap) :
 995                                        DCmdWithParser(output, heap),
 996   _print_interfaces("-i", "Inherited interfaces should be printed.", "BOOLEAN", false, "false"),
 997   _print_subclasses("-s", "If a classname is specified, print its subclasses. "
 998                     "Otherwise only its superclasses are printed.", "BOOLEAN", false, "false"),
 999   _classname("classname", "Name of class whose hierarchy should be printed. "
1000              "If not specified, all class hierarchies are printed.",
1001              "STRING", false) {
1002   _dcmdparser.add_dcmd_option(&_print_interfaces);
1003   _dcmdparser.add_dcmd_option(&_print_subclasses);
1004   _dcmdparser.add_dcmd_argument(&_classname);
1005 }
1006 
1007 void ClassHierarchyDCmd::execute(DCmdSource source, TRAPS) {
1008   VM_PrintClassHierarchy printClassHierarchyOp(output(), _print_interfaces.value(),
1009                                                _print_subclasses.value(), _classname.value());
1010   VMThread::execute(&printClassHierarchyOp);
1011 }
1012 
1013 int ClassHierarchyDCmd::num_arguments() {
1014   ResourceMark rm;
1015   ClassHierarchyDCmd* dcmd = new ClassHierarchyDCmd(NULL, false);
1016   if (dcmd != NULL) {
1017     DCmdMark mark(dcmd);
1018     return dcmd->_dcmdparser.num_arguments();
1019   } else {
1020     return 0;
1021   }
1022 }
1023 
1024 #endif
1025 
1026 class VM_DumpTouchedMethods : public VM_Operation {
1027 private:
1028   outputStream* _out;
1029 public:
1030   VM_DumpTouchedMethods(outputStream* out) {
1031     _out = out;
1032   }
1033 
1034   virtual VMOp_Type type() const { return VMOp_DumpTouchedMethods; }
1035 
1036   virtual void doit() {
1037     Method::print_touched_methods(_out);
1038   }
1039 };
1040 
1041 TouchedMethodsDCmd::TouchedMethodsDCmd(outputStream* output, bool heap) :
1042                                        DCmdWithParser(output, heap)
1043 {}
1044 
1045 void TouchedMethodsDCmd::execute(DCmdSource source, TRAPS) {
1046   if (!LogTouchedMethods) {
1047     output()->print_cr("VM.print_touched_methods command requires -XX:+LogTouchedMethods");
1048     return;
1049   }
1050   VM_DumpTouchedMethods dumper(output());
1051   VMThread::execute(&dumper);
1052 }
1053 
1054 int TouchedMethodsDCmd::num_arguments() {
1055   return 0;
1056 }
1057