1 /*
   2  * Copyright (c) 2011, 2014, 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 "classfile/classLoaderStats.hpp"
  27 #include "gc_implementation/shared/vmGCOperations.hpp"
  28 #include "runtime/javaCalls.hpp"
  29 #include "runtime/os.hpp"
  30 #include "services/diagnosticArgument.hpp"
  31 #include "services/diagnosticCommand.hpp"
  32 #include "services/diagnosticFramework.hpp"
  33 #include "services/heapDumper.hpp"
  34 #include "services/management.hpp"
  35 #include "utilities/macros.hpp"
  36 
  37 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
  38 
  39 void DCmdRegistrant::register_dcmds(){
  40   // Registration of the diagnostic commands
  41   // First argument specifies which interfaces will export the command
  42   // Second argument specifies if the command is enabled
  43   // Third  argument specifies if the command is hidden
  44   uint32_t full_export = DCmd_Source_Internal | DCmd_Source_AttachAPI
  45                          | DCmd_Source_MBean;
  46   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HelpDCmd>(full_export, true, false));
  47   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VersionDCmd>(full_export, true, false));
  48   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CommandLineDCmd>(full_export, true, false));
  49   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PrintSystemPropertiesDCmd>(full_export, true, false));
  50   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PrintVMFlagsDCmd>(full_export, true, false));
  51   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMDynamicLibrariesDCmd>(full_export, true, false));
  52   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMUptimeDCmd>(full_export, true, false));
  53   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SystemGCDCmd>(full_export, true, false));
  54   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<RunFinalizationDCmd>(full_export, true, false));
  55 #if INCLUDE_SERVICES // Heap dumping/inspection supported
  56   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HeapDumpDCmd>(DCmd_Source_Internal | DCmd_Source_AttachAPI, true, false));
  57   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassHistogramDCmd>(full_export, true, false));
  58   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassStatsDCmd>(full_export, true, false));
  59 #endif // INCLUDE_SERVICES
  60   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ThreadDumpDCmd>(full_export, true, false));
  61   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<RotateGCLogDCmd>(full_export, true, false));
  62   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassLoaderStatsDCmd>(full_export, true, false));
  63 
  64   // Enhanced JMX Agent Support
  65   // These commands won't be exported via the DiagnosticCommandMBean until an
  66   // appropriate permission is created for them
  67   uint32_t jmx_agent_export_flags = DCmd_Source_Internal | DCmd_Source_AttachAPI;
  68   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStartRemoteDCmd>(jmx_agent_export_flags, true,false));
  69   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStartLocalDCmd>(jmx_agent_export_flags, true,false));
  70   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStopRemoteDCmd>(jmx_agent_export_flags, true,false));
  71 
  72 }
  73 
  74 #ifndef HAVE_EXTRA_DCMD
  75 void DCmdRegistrant::register_dcmds_ext(){
  76    // Do nothing here
  77 }
  78 #endif
  79 
  80 
  81 HelpDCmd::HelpDCmd(outputStream* output, bool heap) : DCmdWithParser(output, heap),
  82   _all("-all", "Show help for all commands", "BOOLEAN", false, "false"),
  83   _cmd("command name", "The name of the command for which we want help",
  84         "STRING", false) {
  85   _dcmdparser.add_dcmd_option(&_all);
  86   _dcmdparser.add_dcmd_argument(&_cmd);
  87 };
  88 
  89 void HelpDCmd::execute(DCmdSource source, TRAPS) {
  90   if (_all.value()) {
  91     GrowableArray<const char*>* cmd_list = DCmdFactory::DCmd_list(source);
  92     for (int i = 0; i < cmd_list->length(); i++) {
  93       DCmdFactory* factory = DCmdFactory::factory(source, cmd_list->at(i),
  94                                                   strlen(cmd_list->at(i)));
  95       output()->print_cr("%s%s", factory->name(),
  96                          factory->is_enabled() ? "" : " [disabled]");
  97       output()->print_cr("\t%s", factory->description());
  98       output()->cr();
  99       factory = factory->next();
 100     }
 101   } else if (_cmd.has_value()) {
 102     DCmd* cmd = NULL;
 103     DCmdFactory* factory = DCmdFactory::factory(source, _cmd.value(),
 104                                                 strlen(_cmd.value()));
 105     if (factory != NULL) {
 106       output()->print_cr("%s%s", factory->name(),
 107                          factory->is_enabled() ? "" : " [disabled]");
 108       output()->print_cr("%s", factory->description());
 109       output()->print_cr("\nImpact: %s", factory->impact());
 110       JavaPermission p = factory->permission();
 111       if(p._class != NULL) {
 112         if(p._action != NULL) {
 113           output()->print_cr("\nPermission: %s(%s, %s)",
 114                   p._class, p._name == NULL ? "null" : p._name, p._action);
 115         } else {
 116           output()->print_cr("\nPermission: %s(%s)",
 117                   p._class, p._name == NULL ? "null" : p._name);
 118         }
 119       }
 120       output()->cr();
 121       cmd = factory->create_resource_instance(output());
 122       if (cmd != NULL) {
 123         DCmdMark mark(cmd);
 124         cmd->print_help(factory->name());
 125       }
 126     } else {
 127       output()->print_cr("Help unavailable : '%s' : No such command", _cmd.value());
 128     }
 129   } else {
 130     output()->print_cr("The following commands are available:");
 131     GrowableArray<const char *>* cmd_list = DCmdFactory::DCmd_list(source);
 132     for (int i = 0; i < cmd_list->length(); i++) {
 133       DCmdFactory* factory = DCmdFactory::factory(source, cmd_list->at(i),
 134                                                   strlen(cmd_list->at(i)));
 135       output()->print_cr("%s%s", factory->name(),
 136                          factory->is_enabled() ? "" : " [disabled]");
 137       factory = factory->_next;
 138     }
 139     output()->print_cr("\nFor more information about a specific command use 'help <command>'.");
 140   }
 141 }
 142 
 143 int HelpDCmd::num_arguments() {
 144   ResourceMark rm;
 145   HelpDCmd* dcmd = new HelpDCmd(NULL, false);
 146   if (dcmd != NULL) {
 147     DCmdMark mark(dcmd);
 148     return dcmd->_dcmdparser.num_arguments();
 149   } else {
 150     return 0;
 151   }
 152 }
 153 
 154 void VersionDCmd::execute(DCmdSource source, TRAPS) {
 155   output()->print_cr("%s version %s", Abstract_VM_Version::vm_name(),
 156           Abstract_VM_Version::vm_release());
 157   JDK_Version jdk_version = JDK_Version::current();
 158   if (jdk_version.update_version() > 0) {
 159     output()->print_cr("JDK %d.%d_%02d", jdk_version.major_version(),
 160             jdk_version.minor_version(), jdk_version.update_version());
 161   } else {
 162     output()->print_cr("JDK %d.%d", jdk_version.major_version(),
 163             jdk_version.minor_version());
 164   }
 165 }
 166 
 167 PrintVMFlagsDCmd::PrintVMFlagsDCmd(outputStream* output, bool heap) :
 168                                    DCmdWithParser(output, heap),
 169   _all("-all", "Print all flags supported by the VM", "BOOLEAN", false, "false") {
 170   _dcmdparser.add_dcmd_option(&_all);
 171 }
 172 
 173 void PrintVMFlagsDCmd::execute(DCmdSource source, TRAPS) {
 174   if (_all.value()) {
 175     CommandLineFlags::printFlags(output(), true);
 176   } else {
 177     CommandLineFlags::printSetFlags(output());
 178   }
 179 }
 180 
 181 int PrintVMFlagsDCmd::num_arguments() {
 182     ResourceMark rm;
 183     PrintVMFlagsDCmd* dcmd = new PrintVMFlagsDCmd(NULL, false);
 184     if (dcmd != NULL) {
 185       DCmdMark mark(dcmd);
 186       return dcmd->_dcmdparser.num_arguments();
 187     } else {
 188       return 0;
 189     }
 190 }
 191 
 192 void PrintSystemPropertiesDCmd::execute(DCmdSource source, TRAPS) {
 193   // load sun.misc.VMSupport
 194   Symbol* klass = vmSymbols::sun_misc_VMSupport();
 195   Klass* k = SystemDictionary::resolve_or_fail(klass, true, CHECK);
 196   instanceKlassHandle ik (THREAD, k);
 197   if (ik->should_be_initialized()) {
 198     ik->initialize(THREAD);
 199   }
 200   if (HAS_PENDING_EXCEPTION) {
 201     java_lang_Throwable::print(PENDING_EXCEPTION, output());
 202     output()->cr();
 203     CLEAR_PENDING_EXCEPTION;
 204     return;
 205   }
 206 
 207   // invoke the serializePropertiesToByteArray method
 208   JavaValue result(T_OBJECT);
 209   JavaCallArguments args;
 210 
 211   Symbol* signature = vmSymbols::serializePropertiesToByteArray_signature();
 212   JavaCalls::call_static(&result,
 213                          ik,
 214                          vmSymbols::serializePropertiesToByteArray_name(),
 215                          signature,
 216                          &args,
 217                          THREAD);
 218   if (HAS_PENDING_EXCEPTION) {
 219     java_lang_Throwable::print(PENDING_EXCEPTION, output());
 220     output()->cr();
 221     CLEAR_PENDING_EXCEPTION;
 222     return;
 223   }
 224 
 225   // The result should be a [B
 226   oop res = (oop)result.get_jobject();
 227   assert(res->is_typeArray(), "just checking");
 228   assert(TypeArrayKlass::cast(res->klass())->element_type() == T_BYTE, "just checking");
 229 
 230   // copy the bytes to the output stream
 231   typeArrayOop ba = typeArrayOop(res);
 232   jbyte* addr = typeArrayOop(res)->byte_at_addr(0);
 233   output()->print_raw((const char*)addr, ba->length());
 234 }
 235 
 236 VMUptimeDCmd::VMUptimeDCmd(outputStream* output, bool heap) :
 237                            DCmdWithParser(output, heap),
 238   _date("-date", "Add a prefix with current date", "BOOLEAN", false, "false") {
 239   _dcmdparser.add_dcmd_option(&_date);
 240 }
 241 
 242 void VMUptimeDCmd::execute(DCmdSource source, TRAPS) {
 243   if (_date.value()) {
 244     output()->date_stamp(true, "", ": ");
 245   }
 246   output()->time_stamp().update_to(tty->time_stamp().ticks());
 247   output()->stamp();
 248   output()->print_cr(" s");
 249 }
 250 
 251 int VMUptimeDCmd::num_arguments() {
 252   ResourceMark rm;
 253   VMUptimeDCmd* dcmd = new VMUptimeDCmd(NULL, false);
 254   if (dcmd != NULL) {
 255     DCmdMark mark(dcmd);
 256     return dcmd->_dcmdparser.num_arguments();
 257   } else {
 258     return 0;
 259   }
 260 }
 261 
 262 void SystemGCDCmd::execute(DCmdSource source, TRAPS) {
 263   if (!DisableExplicitGC) {
 264     Universe::heap()->collect(GCCause::_java_lang_system_gc);
 265   } else {
 266     output()->print_cr("Explicit GC is disabled, no GC has been performed.");
 267   }
 268 }
 269 
 270 void RunFinalizationDCmd::execute(DCmdSource source, TRAPS) {
 271   Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_System(),
 272                                                  true, CHECK);
 273   instanceKlassHandle klass(THREAD, k);
 274   JavaValue result(T_VOID);
 275   JavaCalls::call_static(&result, klass,
 276                          vmSymbols::run_finalization_name(),
 277                          vmSymbols::void_method_signature(), CHECK);
 278 }
 279 
 280 #if INCLUDE_SERVICES // Heap dumping/inspection supported
 281 HeapDumpDCmd::HeapDumpDCmd(outputStream* output, bool heap) :
 282                            DCmdWithParser(output, heap),
 283   _filename("filename","Name of the dump file", "STRING",true),
 284   _all("-all", "Dump all objects, including unreachable objects",
 285        "BOOLEAN", false, "false") {
 286   _dcmdparser.add_dcmd_option(&_all);
 287   _dcmdparser.add_dcmd_argument(&_filename);
 288 }
 289 
 290 void HeapDumpDCmd::execute(DCmdSource source, TRAPS) {
 291   // Request a full GC before heap dump if _all is false
 292   // This helps reduces the amount of unreachable objects in the dump
 293   // and makes it easier to browse.
 294   HeapDumper dumper(!_all.value() /* request GC if _all is false*/);
 295   int res = dumper.dump(_filename.value());
 296   if (res == 0) {
 297     output()->print_cr("Heap dump file created");
 298   } else {
 299     // heap dump failed
 300     ResourceMark rm;
 301     char* error = dumper.error_as_C_string();
 302     if (error == NULL) {
 303       output()->print_cr("Dump failed - reason unknown");
 304     } else {
 305       output()->print_cr("%s", error);
 306     }
 307   }
 308 }
 309 
 310 int HeapDumpDCmd::num_arguments() {
 311   ResourceMark rm;
 312   HeapDumpDCmd* dcmd = new HeapDumpDCmd(NULL, false);
 313   if (dcmd != NULL) {
 314     DCmdMark mark(dcmd);
 315     return dcmd->_dcmdparser.num_arguments();
 316   } else {
 317     return 0;
 318   }
 319 }
 320 
 321 ClassHistogramDCmd::ClassHistogramDCmd(outputStream* output, bool heap) :
 322                                        DCmdWithParser(output, heap),
 323   _all("-all", "Inspect all objects, including unreachable objects",
 324        "BOOLEAN", false, "false") {
 325   _dcmdparser.add_dcmd_option(&_all);
 326 }
 327 
 328 void ClassHistogramDCmd::execute(DCmdSource source, TRAPS) {
 329   VM_GC_HeapInspection heapop(output(),
 330                               !_all.value() /* request full gc if false */);
 331   VMThread::execute(&heapop);
 332 }
 333 
 334 int ClassHistogramDCmd::num_arguments() {
 335   ResourceMark rm;
 336   ClassHistogramDCmd* dcmd = new ClassHistogramDCmd(NULL, false);
 337   if (dcmd != NULL) {
 338     DCmdMark mark(dcmd);
 339     return dcmd->_dcmdparser.num_arguments();
 340   } else {
 341     return 0;
 342   }
 343 }
 344 
 345 #define DEFAULT_COLUMNS "InstBytes,KlassBytes,CpAll,annotations,MethodCount,Bytecodes,MethodAll,ROAll,RWAll,Total"
 346 ClassStatsDCmd::ClassStatsDCmd(outputStream* output, bool heap) :
 347                                        DCmdWithParser(output, heap),
 348   _csv("-csv", "Print in CSV (comma-separated values) format for spreadsheets",
 349        "BOOLEAN", false, "false"),
 350   _all("-all", "Show all columns",
 351        "BOOLEAN", false, "false"),
 352   _help("-help", "Show meaning of all the columns",
 353        "BOOLEAN", false, "false"),
 354   _columns("columns", "Comma-separated list of all the columns to show. "
 355            "If not specified, the following columns are shown: " DEFAULT_COLUMNS,
 356            "STRING", false) {
 357   _dcmdparser.add_dcmd_option(&_all);
 358   _dcmdparser.add_dcmd_option(&_csv);
 359   _dcmdparser.add_dcmd_option(&_help);
 360   _dcmdparser.add_dcmd_argument(&_columns);
 361 }
 362 
 363 void ClassStatsDCmd::execute(DCmdSource source, TRAPS) {
 364   if (!UnlockDiagnosticVMOptions) {
 365     output()->print_cr("GC.class_stats command requires -XX:+UnlockDiagnosticVMOptions");
 366     return;
 367   }
 368 
 369   VM_GC_HeapInspection heapop(output(),
 370                               true /* request_full_gc */);
 371   heapop.set_csv_format(_csv.value());
 372   heapop.set_print_help(_help.value());
 373   heapop.set_print_class_stats(true);
 374   if (_all.value()) {
 375     if (_columns.has_value()) {
 376       output()->print_cr("Cannot specify -all and individual columns at the same time");
 377       return;
 378     } else {
 379       heapop.set_columns(NULL);
 380     }
 381   } else {
 382     if (_columns.has_value()) {
 383       heapop.set_columns(_columns.value());
 384     } else {
 385       heapop.set_columns(DEFAULT_COLUMNS);
 386     }
 387   }
 388   VMThread::execute(&heapop);
 389 }
 390 
 391 int ClassStatsDCmd::num_arguments() {
 392   ResourceMark rm;
 393   ClassStatsDCmd* dcmd = new ClassStatsDCmd(NULL, false);
 394   if (dcmd != NULL) {
 395     DCmdMark mark(dcmd);
 396     return dcmd->_dcmdparser.num_arguments();
 397   } else {
 398     return 0;
 399   }
 400 }
 401 #endif // INCLUDE_SERVICES
 402 
 403 ThreadDumpDCmd::ThreadDumpDCmd(outputStream* output, bool heap) :
 404                                DCmdWithParser(output, heap),
 405   _locks("-l", "print java.util.concurrent locks", "BOOLEAN", false, "false") {
 406   _dcmdparser.add_dcmd_option(&_locks);
 407 }
 408 
 409 void ThreadDumpDCmd::execute(DCmdSource source, TRAPS) {
 410   // thread stacks
 411   VM_PrintThreads op1(output(), _locks.value());
 412   VMThread::execute(&op1);
 413 
 414   // JNI global handles
 415   VM_PrintJNI op2(output());
 416   VMThread::execute(&op2);
 417 
 418   // Deadlock detection
 419   VM_FindDeadlocks op3(output());
 420   VMThread::execute(&op3);
 421 }
 422 
 423 int ThreadDumpDCmd::num_arguments() {
 424   ResourceMark rm;
 425   ThreadDumpDCmd* dcmd = new ThreadDumpDCmd(NULL, false);
 426   if (dcmd != NULL) {
 427     DCmdMark mark(dcmd);
 428     return dcmd->_dcmdparser.num_arguments();
 429   } else {
 430     return 0;
 431   }
 432 }
 433 
 434 // Enhanced JMX Agent support
 435 
 436 JMXStartRemoteDCmd::JMXStartRemoteDCmd(outputStream *output, bool heap_allocated) :
 437 
 438   DCmdWithParser(output, heap_allocated),
 439 
 440   _config_file
 441   ("config.file",
 442    "set com.sun.management.config.file", "STRING", false),
 443 
 444   _jmxremote_port
 445   ("jmxremote.port",
 446    "set com.sun.management.jmxremote.port", "STRING", false),
 447 
 448   _jmxremote_rmi_port
 449   ("jmxremote.rmi.port",
 450    "set com.sun.management.jmxremote.rmi.port", "STRING", false),
 451 
 452   _jmxremote_ssl
 453   ("jmxremote.ssl",
 454    "set com.sun.management.jmxremote.ssl", "STRING", false),
 455 
 456   _jmxremote_registry_ssl
 457   ("jmxremote.registry.ssl",
 458    "set com.sun.management.jmxremote.registry.ssl", "STRING", false),
 459 
 460   _jmxremote_authenticate
 461   ("jmxremote.authenticate",
 462    "set com.sun.management.jmxremote.authenticate", "STRING", false),
 463 
 464   _jmxremote_password_file
 465   ("jmxremote.password.file",
 466    "set com.sun.management.jmxremote.password.file", "STRING", false),
 467 
 468   _jmxremote_access_file
 469   ("jmxremote.access.file",
 470    "set com.sun.management.jmxremote.access.file", "STRING", false),
 471 
 472   _jmxremote_login_config
 473   ("jmxremote.login.config",
 474    "set com.sun.management.jmxremote.login.config", "STRING", false),
 475 
 476   _jmxremote_ssl_enabled_cipher_suites
 477   ("jmxremote.ssl.enabled.cipher.suites",
 478    "set com.sun.management.jmxremote.ssl.enabled.cipher.suite", "STRING", false),
 479 
 480   _jmxremote_ssl_enabled_protocols
 481   ("jmxremote.ssl.enabled.protocols",
 482    "set com.sun.management.jmxremote.ssl.enabled.protocols", "STRING", false),
 483 
 484   _jmxremote_ssl_need_client_auth
 485   ("jmxremote.ssl.need.client.auth",
 486    "set com.sun.management.jmxremote.need.client.auth", "STRING", false),
 487 
 488   _jmxremote_ssl_config_file
 489   ("jmxremote.ssl.config.file",
 490    "set com.sun.management.jmxremote.ssl_config_file", "STRING", false),
 491 
 492 // JDP Protocol support
 493   _jmxremote_autodiscovery
 494   ("jmxremote.autodiscovery",
 495    "set com.sun.management.jmxremote.autodiscovery", "STRING", false),
 496 
 497    _jdp_port
 498   ("jdp.port",
 499    "set com.sun.management.jdp.port", "INT", false),
 500 
 501    _jdp_address
 502   ("jdp.address",
 503    "set com.sun.management.jdp.address", "STRING", false),
 504 
 505    _jdp_source_addr
 506   ("jdp.source_addr",
 507    "set com.sun.management.jdp.source_addr", "STRING", false),
 508 
 509    _jdp_ttl
 510   ("jdp.ttl",
 511    "set com.sun.management.jdp.ttl", "INT", false),
 512 
 513    _jdp_pause
 514   ("jdp.pause",
 515    "set com.sun.management.jdp.pause", "INT", false),
 516 
 517    _jdp_name
 518   ("jdp.name",
 519    "set com.sun.management.jdp.name", "STRING", false)
 520 
 521   {
 522     _dcmdparser.add_dcmd_option(&_config_file);
 523     _dcmdparser.add_dcmd_option(&_jmxremote_port);
 524     _dcmdparser.add_dcmd_option(&_jmxremote_rmi_port);
 525     _dcmdparser.add_dcmd_option(&_jmxremote_ssl);
 526     _dcmdparser.add_dcmd_option(&_jmxremote_registry_ssl);
 527     _dcmdparser.add_dcmd_option(&_jmxremote_authenticate);
 528     _dcmdparser.add_dcmd_option(&_jmxremote_password_file);
 529     _dcmdparser.add_dcmd_option(&_jmxremote_access_file);
 530     _dcmdparser.add_dcmd_option(&_jmxremote_login_config);
 531     _dcmdparser.add_dcmd_option(&_jmxremote_ssl_enabled_cipher_suites);
 532     _dcmdparser.add_dcmd_option(&_jmxremote_ssl_enabled_protocols);
 533     _dcmdparser.add_dcmd_option(&_jmxremote_ssl_need_client_auth);
 534     _dcmdparser.add_dcmd_option(&_jmxremote_ssl_config_file);
 535     _dcmdparser.add_dcmd_option(&_jmxremote_autodiscovery);
 536     _dcmdparser.add_dcmd_option(&_jdp_port);
 537     _dcmdparser.add_dcmd_option(&_jdp_address);
 538     _dcmdparser.add_dcmd_option(&_jdp_source_addr);
 539     _dcmdparser.add_dcmd_option(&_jdp_ttl);
 540     _dcmdparser.add_dcmd_option(&_jdp_pause);
 541     _dcmdparser.add_dcmd_option(&_jdp_name);
 542 }
 543 
 544 
 545 int JMXStartRemoteDCmd::num_arguments() {
 546   ResourceMark rm;
 547   JMXStartRemoteDCmd* dcmd = new JMXStartRemoteDCmd(NULL, false);
 548   if (dcmd != NULL) {
 549     DCmdMark mark(dcmd);
 550     return dcmd->_dcmdparser.num_arguments();
 551   } else {
 552     return 0;
 553   }
 554 }
 555 
 556 
 557 void JMXStartRemoteDCmd::execute(DCmdSource source, TRAPS) {
 558     ResourceMark rm(THREAD);
 559     HandleMark hm(THREAD);
 560 
 561     // Load and initialize the sun.management.Agent class
 562     // invoke startRemoteManagementAgent(string) method to start
 563     // the remote management server.
 564     // throw java.lang.NoSuchMethodError if the method doesn't exist
 565 
 566     Handle loader = Handle(THREAD, SystemDictionary::java_system_loader());
 567     Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::sun_management_Agent(), loader, Handle(), true, CHECK);
 568     instanceKlassHandle ik (THREAD, k);
 569 
 570     JavaValue result(T_VOID);
 571 
 572     // Pass all command line arguments to java as key=value,...
 573     // All checks are done on java side
 574 
 575     int len = 0;
 576     stringStream options;
 577     char comma[2] = {0,0};
 578 
 579     // Leave default values on Agent.class side and pass only
 580     // agruments explicitly set by user. All arguments passed
 581     // to jcmd override properties with the same name set by
 582     // command line with -D or by managmenent.properties
 583     // file.
 584 #define PUT_OPTION(a) \
 585     if ( (a).is_set() ){ \
 586         options.print(\
 587                ( *((a).type()) == 'I' ) ? "%scom.sun.management.%s=%d" : "%scom.sun.management.%s=%s",\
 588                 comma, (a).name(), (a).value()); \
 589         comma[0] = ','; \
 590     }
 591 
 592     PUT_OPTION(_config_file);
 593     PUT_OPTION(_jmxremote_port);
 594     PUT_OPTION(_jmxremote_rmi_port);
 595     PUT_OPTION(_jmxremote_ssl);
 596     PUT_OPTION(_jmxremote_registry_ssl);
 597     PUT_OPTION(_jmxremote_authenticate);
 598     PUT_OPTION(_jmxremote_password_file);
 599     PUT_OPTION(_jmxremote_access_file);
 600     PUT_OPTION(_jmxremote_login_config);
 601     PUT_OPTION(_jmxremote_ssl_enabled_cipher_suites);
 602     PUT_OPTION(_jmxremote_ssl_enabled_protocols);
 603     PUT_OPTION(_jmxremote_ssl_need_client_auth);
 604     PUT_OPTION(_jmxremote_ssl_config_file);
 605     PUT_OPTION(_jmxremote_autodiscovery);
 606     PUT_OPTION(_jdp_port);
 607     PUT_OPTION(_jdp_address);
 608     PUT_OPTION(_jdp_source_addr);
 609     PUT_OPTION(_jdp_ttl);
 610     PUT_OPTION(_jdp_pause);
 611     PUT_OPTION(_jdp_name);
 612 
 613 #undef PUT_OPTION
 614 
 615     Handle str = java_lang_String::create_from_str(options.as_string(), CHECK);
 616     JavaCalls::call_static(&result, ik, vmSymbols::startRemoteAgent_name(), vmSymbols::string_void_signature(), str, CHECK);
 617 }
 618 
 619 JMXStartLocalDCmd::JMXStartLocalDCmd(outputStream *output, bool heap_allocated) :
 620   DCmd(output, heap_allocated) {
 621   // do nothing
 622 }
 623 
 624 void JMXStartLocalDCmd::execute(DCmdSource source, TRAPS) {
 625     ResourceMark rm(THREAD);
 626     HandleMark hm(THREAD);
 627 
 628     // Load and initialize the sun.management.Agent class
 629     // invoke startLocalManagementAgent(void) method to start
 630     // the local management server
 631     // throw java.lang.NoSuchMethodError if method doesn't exist
 632 
 633     Handle loader = Handle(THREAD, SystemDictionary::java_system_loader());
 634     Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::sun_management_Agent(), loader, Handle(), true, CHECK);
 635     instanceKlassHandle ik (THREAD, k);
 636 
 637     JavaValue result(T_VOID);
 638     JavaCalls::call_static(&result, ik, vmSymbols::startLocalAgent_name(), vmSymbols::void_method_signature(), CHECK);
 639 }
 640 
 641 void JMXStopRemoteDCmd::execute(DCmdSource source, TRAPS) {
 642     ResourceMark rm(THREAD);
 643     HandleMark hm(THREAD);
 644 
 645     // Load and initialize the sun.management.Agent class
 646     // invoke stopRemoteManagementAgent method to stop the
 647     // management server
 648     // throw java.lang.NoSuchMethodError if method doesn't exist
 649 
 650     Handle loader = Handle(THREAD, SystemDictionary::java_system_loader());
 651     Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::sun_management_Agent(), loader, Handle(), true, CHECK);
 652     instanceKlassHandle ik (THREAD, k);
 653 
 654     JavaValue result(T_VOID);
 655     JavaCalls::call_static(&result, ik, vmSymbols::stopRemoteAgent_name(), vmSymbols::void_method_signature(), CHECK);
 656 }
 657 
 658 VMDynamicLibrariesDCmd::VMDynamicLibrariesDCmd(outputStream *output, bool heap_allocated) :
 659   DCmd(output, heap_allocated) {
 660   // do nothing
 661 }
 662 
 663 void VMDynamicLibrariesDCmd::execute(DCmdSource source, TRAPS) {
 664   os::print_dll_info(output());
 665   output()->cr();
 666 }
 667 
 668 void RotateGCLogDCmd::execute(DCmdSource source, TRAPS) {
 669   if (UseGCLogFileRotation) {
 670     VM_RotateGCLog rotateop(output());
 671     VMThread::execute(&rotateop);
 672   } else {
 673     output()->print_cr("Target VM does not support GC log file rotation.");
 674   }
 675 }
 676