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