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 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<VMDynamicLibrariesDCmd>(full_export, true, false)); 51 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMUptimeDCmd>(full_export, true, false)); 52 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SystemGCDCmd>(full_export, true, false)); 53 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<RunFinalizationDCmd>(full_export, true, false)); 54 #if INCLUDE_SERVICES // Heap dumping/inspection supported 55 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HeapDumpDCmd>(DCmd_Source_Internal | DCmd_Source_AttachAPI, true, false)); 56 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassHistogramDCmd>(full_export, true, false)); 57 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassStatsDCmd>(full_export, true, false)); 58 #endif // INCLUDE_SERVICES 59 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ThreadDumpDCmd>(full_export, true, false)); 60 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<RotateGCLogDCmd>(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_raw_cr(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 // Enhanced JMX Agent support 433 434 JMXStartRemoteDCmd::JMXStartRemoteDCmd(outputStream *output, bool heap_allocated) : 435 436 DCmdWithParser(output, heap_allocated), 437 438 _config_file 439 ("config.file", 440 "set com.sun.management.config.file", "STRING", false), 441 442 _jmxremote_port 443 ("jmxremote.port", 444 "set com.sun.management.jmxremote.port", "STRING", false), 445 446 _jmxremote_rmi_port 447 ("jmxremote.rmi.port", 448 "set com.sun.management.jmxremote.rmi.port", "STRING", false), 449 450 _jmxremote_ssl 451 ("jmxremote.ssl", 452 "set com.sun.management.jmxremote.ssl", "STRING", false), 453 454 _jmxremote_registry_ssl 455 ("jmxremote.registry.ssl", 456 "set com.sun.management.jmxremote.registry.ssl", "STRING", false), 457 458 _jmxremote_authenticate 459 ("jmxremote.authenticate", 460 "set com.sun.management.jmxremote.authenticate", "STRING", false), 461 462 _jmxremote_password_file 463 ("jmxremote.password.file", 464 "set com.sun.management.jmxremote.password.file", "STRING", false), 465 466 _jmxremote_access_file 467 ("jmxremote.access.file", 468 "set com.sun.management.jmxremote.access.file", "STRING", false), 469 470 _jmxremote_login_config 471 ("jmxremote.login.config", 472 "set com.sun.management.jmxremote.login.config", "STRING", false), 473 474 _jmxremote_ssl_enabled_cipher_suites 475 ("jmxremote.ssl.enabled.cipher.suites", 476 "set com.sun.management.jmxremote.ssl.enabled.cipher.suite", "STRING", false), 477 478 _jmxremote_ssl_enabled_protocols 479 ("jmxremote.ssl.enabled.protocols", 480 "set com.sun.management.jmxremote.ssl.enabled.protocols", "STRING", false), 481 482 _jmxremote_ssl_need_client_auth 483 ("jmxremote.ssl.need.client.auth", 484 "set com.sun.management.jmxremote.need.client.auth", "STRING", false), 485 486 _jmxremote_ssl_config_file 487 ("jmxremote.ssl.config.file", 488 "set com.sun.management.jmxremote.ssl_config_file", "STRING", false), 489 490 // JDP Protocol support 491 _jmxremote_autodiscovery 492 ("jmxremote.autodiscovery", 493 "set com.sun.management.jmxremote.autodiscovery", "STRING", false), 494 495 _jdp_port 496 ("jdp.port", 497 "set com.sun.management.jdp.port", "INT", false), 498 499 _jdp_address 500 ("jdp.address", 501 "set com.sun.management.jdp.address", "STRING", false), 502 503 _jdp_source_addr 504 ("jdp.source_addr", 505 "set com.sun.management.jdp.source_addr", "STRING", false), 506 507 _jdp_ttl 508 ("jdp.ttl", 509 "set com.sun.management.jdp.ttl", "INT", false), 510 511 _jdp_pause 512 ("jdp.pause", 513 "set com.sun.management.jdp.pause", "INT", false), 514 515 _jdp_name 516 ("jdp.name", 517 "set com.sun.management.jdp.name", "STRING", false) 518 519 { 520 _dcmdparser.add_dcmd_option(&_config_file); 521 _dcmdparser.add_dcmd_option(&_jmxremote_port); 522 _dcmdparser.add_dcmd_option(&_jmxremote_rmi_port); 523 _dcmdparser.add_dcmd_option(&_jmxremote_ssl); 524 _dcmdparser.add_dcmd_option(&_jmxremote_registry_ssl); 525 _dcmdparser.add_dcmd_option(&_jmxremote_authenticate); 526 _dcmdparser.add_dcmd_option(&_jmxremote_password_file); 527 _dcmdparser.add_dcmd_option(&_jmxremote_access_file); 528 _dcmdparser.add_dcmd_option(&_jmxremote_login_config); 529 _dcmdparser.add_dcmd_option(&_jmxremote_ssl_enabled_cipher_suites); 530 _dcmdparser.add_dcmd_option(&_jmxremote_ssl_enabled_protocols); 531 _dcmdparser.add_dcmd_option(&_jmxremote_ssl_need_client_auth); 532 _dcmdparser.add_dcmd_option(&_jmxremote_ssl_config_file); 533 _dcmdparser.add_dcmd_option(&_jmxremote_autodiscovery); 534 _dcmdparser.add_dcmd_option(&_jdp_port); 535 _dcmdparser.add_dcmd_option(&_jdp_address); 536 _dcmdparser.add_dcmd_option(&_jdp_source_addr); 537 _dcmdparser.add_dcmd_option(&_jdp_ttl); 538 _dcmdparser.add_dcmd_option(&_jdp_pause); 539 _dcmdparser.add_dcmd_option(&_jdp_name); 540 } 541 542 543 int JMXStartRemoteDCmd::num_arguments() { 544 ResourceMark rm; 545 JMXStartRemoteDCmd* dcmd = new JMXStartRemoteDCmd(NULL, false); 546 if (dcmd != NULL) { 547 DCmdMark mark(dcmd); 548 return dcmd->_dcmdparser.num_arguments(); 549 } else { 550 return 0; 551 } 552 } 553 554 555 void JMXStartRemoteDCmd::execute(DCmdSource source, TRAPS) { 556 ResourceMark rm(THREAD); 557 HandleMark hm(THREAD); 558 559 // Load and initialize the sun.management.Agent class 560 // invoke startRemoteManagementAgent(string) method to start 561 // the remote management server. 562 // throw java.lang.NoSuchMethodError if the method doesn't exist 563 564 Handle loader = Handle(THREAD, SystemDictionary::java_system_loader()); 565 Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::sun_management_Agent(), loader, Handle(), true, CHECK); 566 instanceKlassHandle ik (THREAD, k); 567 568 JavaValue result(T_VOID); 569 570 // Pass all command line arguments to java as key=value,... 571 // All checks are done on java side 572 573 int len = 0; 574 stringStream options; 575 char comma[2] = {0,0}; 576 577 // Leave default values on Agent.class side and pass only 578 // agruments explicitly set by user. All arguments passed 579 // to jcmd override properties with the same name set by 580 // command line with -D or by managmenent.properties 581 // file. 582 #define PUT_OPTION(a) \ 583 if ( (a).is_set() ){ \ 584 options.print(\ 585 ( *((a).type()) == 'I' ) ? "%scom.sun.management.%s=%d" : "%scom.sun.management.%s=%s",\ 586 comma, (a).name(), (a).value()); \ 587 comma[0] = ','; \ 588 } 589 590 PUT_OPTION(_config_file); 591 PUT_OPTION(_jmxremote_port); 592 PUT_OPTION(_jmxremote_rmi_port); 593 PUT_OPTION(_jmxremote_ssl); 594 PUT_OPTION(_jmxremote_registry_ssl); 595 PUT_OPTION(_jmxremote_authenticate); 596 PUT_OPTION(_jmxremote_password_file); 597 PUT_OPTION(_jmxremote_access_file); 598 PUT_OPTION(_jmxremote_login_config); 599 PUT_OPTION(_jmxremote_ssl_enabled_cipher_suites); 600 PUT_OPTION(_jmxremote_ssl_enabled_protocols); 601 PUT_OPTION(_jmxremote_ssl_need_client_auth); 602 PUT_OPTION(_jmxremote_ssl_config_file); 603 PUT_OPTION(_jmxremote_autodiscovery); 604 PUT_OPTION(_jdp_port); 605 PUT_OPTION(_jdp_address); 606 PUT_OPTION(_jdp_source_addr); 607 PUT_OPTION(_jdp_ttl); 608 PUT_OPTION(_jdp_pause); 609 PUT_OPTION(_jdp_name); 610 611 #undef PUT_OPTION 612 613 Handle str = java_lang_String::create_from_str(options.as_string(), CHECK); 614 JavaCalls::call_static(&result, ik, vmSymbols::startRemoteAgent_name(), vmSymbols::string_void_signature(), str, CHECK); 615 } 616 617 JMXStartLocalDCmd::JMXStartLocalDCmd(outputStream *output, bool heap_allocated) : 618 DCmd(output, heap_allocated) { 619 // do nothing 620 } 621 622 void JMXStartLocalDCmd::execute(DCmdSource source, TRAPS) { 623 ResourceMark rm(THREAD); 624 HandleMark hm(THREAD); 625 626 // Load and initialize the sun.management.Agent class 627 // invoke startLocalManagementAgent(void) method to start 628 // the local management server 629 // throw java.lang.NoSuchMethodError if method doesn't exist 630 631 Handle loader = Handle(THREAD, SystemDictionary::java_system_loader()); 632 Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::sun_management_Agent(), loader, Handle(), true, CHECK); 633 instanceKlassHandle ik (THREAD, k); 634 635 JavaValue result(T_VOID); 636 JavaCalls::call_static(&result, ik, vmSymbols::startLocalAgent_name(), vmSymbols::void_method_signature(), CHECK); 637 } 638 639 void JMXStopRemoteDCmd::execute(DCmdSource source, TRAPS) { 640 ResourceMark rm(THREAD); 641 HandleMark hm(THREAD); 642 643 // Load and initialize the sun.management.Agent class 644 // invoke stopRemoteManagementAgent method to stop the 645 // management server 646 // throw java.lang.NoSuchMethodError if method doesn't exist 647 648 Handle loader = Handle(THREAD, SystemDictionary::java_system_loader()); 649 Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::sun_management_Agent(), loader, Handle(), true, CHECK); 650 instanceKlassHandle ik (THREAD, k); 651 652 JavaValue result(T_VOID); 653 JavaCalls::call_static(&result, ik, vmSymbols::stopRemoteAgent_name(), vmSymbols::void_method_signature(), CHECK); 654 } 655 656 VMDynamicLibrariesDCmd::VMDynamicLibrariesDCmd(outputStream *output, bool heap_allocated) : 657 DCmd(output, heap_allocated) { 658 // do nothing 659 } 660 661 void VMDynamicLibrariesDCmd::execute(DCmdSource source, TRAPS) { 662 os::print_dll_info(output()); 663 output()->cr(); 664 } 665 666 void RotateGCLogDCmd::execute(DCmdSource source, TRAPS) { 667 if (UseGCLogFileRotation) { 668 VM_RotateGCLog rotateop(output()); 669 VMThread::execute(&rotateop); 670 } else { 671 output()->print_cr("Target VM does not support GC log file rotation."); 672 } 673 } 674