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