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