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