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