Mercurial > hg > graal-compiler
comparison src/share/vm/services/diagnosticCommand.cpp @ 5895:645162d94294
7110104: It should be possible to stop and start JMX Agent at runtime
Summary: Added a capability to start and stop JMX Agent by jcmd
Reviewed-by: acorn, mchung
author | dsamersoff |
---|---|
date | Wed, 22 Feb 2012 19:43:22 +0400 |
parents | a42c07c38c47 |
children | da91efe96a93 |
comparison
equal
deleted
inserted
replaced
4962:38fd165da001 | 5895:645162d94294 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 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 | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
46 #ifndef SERVICES_KERNEL // Heap dumping not supported | 46 #ifndef SERVICES_KERNEL // Heap dumping not supported |
47 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HeapDumpDCmd>(true, false)); | 47 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HeapDumpDCmd>(true, false)); |
48 #endif // SERVICES_KERNEL | 48 #endif // SERVICES_KERNEL |
49 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassHistogramDCmd>(true, false)); | 49 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassHistogramDCmd>(true, false)); |
50 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ThreadDumpDCmd>(true, false)); | 50 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ThreadDumpDCmd>(true, false)); |
51 | |
52 //Enhanced JMX Agent Support | |
53 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStartRemoteDCmd>(true,false)); | |
54 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStartLocalDCmd>(true,false)); | |
55 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStopRemoteDCmd>(true,false)); | |
51 | 56 |
52 } | 57 } |
53 | 58 |
54 #ifndef HAVE_EXTRA_DCMD | 59 #ifndef HAVE_EXTRA_DCMD |
55 void DCmdRegistrant::register_dcmds_ext(){ | 60 void DCmdRegistrant::register_dcmds_ext(){ |
342 return dcmd->_dcmdparser.num_arguments(); | 347 return dcmd->_dcmdparser.num_arguments(); |
343 } else { | 348 } else { |
344 return 0; | 349 return 0; |
345 } | 350 } |
346 } | 351 } |
352 | |
353 // Enhanced JMX Agent support | |
354 | |
355 JMXStartRemoteDCmd::JMXStartRemoteDCmd(outputStream *output, bool heap_allocated) : | |
356 | |
357 DCmdWithParser(output, heap_allocated), | |
358 | |
359 _config_file | |
360 ("config.file", | |
361 "set com.sun.management.config.file", "STRING", false), | |
362 | |
363 _jmxremote_port | |
364 ("jmxremote.port", | |
365 "set com.sun.management.jmxremote.port", "STRING", false), | |
366 | |
367 _jmxremote_rmi_port | |
368 ("jmxremote.rmi.port", | |
369 "set com.sun.management.jmxremote.rmi.port", "STRING", false), | |
370 | |
371 _jmxremote_ssl | |
372 ("jmxremote.ssl", | |
373 "set com.sun.management.jmxremote.ssl", "STRING", false), | |
374 | |
375 _jmxremote_registry_ssl | |
376 ("jmxremote.registry.ssl", | |
377 "set com.sun.management.jmxremote.registry.ssl", "STRING", false), | |
378 | |
379 _jmxremote_authenticate | |
380 ("jmxremote.authenticate", | |
381 "set com.sun.management.jmxremote.authenticate", "STRING", false), | |
382 | |
383 _jmxremote_password_file | |
384 ("jmxremote.password.file", | |
385 "set com.sun.management.jmxremote.password.file", "STRING", false), | |
386 | |
387 _jmxremote_access_file | |
388 ("jmxremote.access.file", | |
389 "set com.sun.management.jmxremote.access.file", "STRING", false), | |
390 | |
391 _jmxremote_login_config | |
392 ("jmxremote.login.config", | |
393 "set com.sun.management.jmxremote.login.config", "STRING", false), | |
394 | |
395 _jmxremote_ssl_enabled_cipher_suites | |
396 ("jmxremote.ssl.enabled.cipher.suites", | |
397 "set com.sun.management.jmxremote.ssl.enabled.cipher.suite", "STRING", false), | |
398 | |
399 _jmxremote_ssl_enabled_protocols | |
400 ("jmxremote.ssl.enabled.protocols", | |
401 "set com.sun.management.jmxremote.ssl.enabled.protocols", "STRING", false), | |
402 | |
403 _jmxremote_ssl_need_client_auth | |
404 ("jmxremote.ssl.need.client.auth", | |
405 "set com.sun.management.jmxremote.need.client.auth", "STRING", false), | |
406 | |
407 _jmxremote_ssl_config_file | |
408 ("jmxremote.ssl.config.file", | |
409 "set com.sun.management.jmxremote.ssl_config_file", "STRING", false) | |
410 | |
411 { | |
412 _dcmdparser.add_dcmd_option(&_config_file); | |
413 _dcmdparser.add_dcmd_option(&_jmxremote_port); | |
414 _dcmdparser.add_dcmd_option(&_jmxremote_rmi_port); | |
415 _dcmdparser.add_dcmd_option(&_jmxremote_ssl); | |
416 _dcmdparser.add_dcmd_option(&_jmxremote_registry_ssl); | |
417 _dcmdparser.add_dcmd_option(&_jmxremote_authenticate); | |
418 _dcmdparser.add_dcmd_option(&_jmxremote_password_file); | |
419 _dcmdparser.add_dcmd_option(&_jmxremote_access_file); | |
420 _dcmdparser.add_dcmd_option(&_jmxremote_login_config); | |
421 _dcmdparser.add_dcmd_option(&_jmxremote_ssl_enabled_cipher_suites); | |
422 _dcmdparser.add_dcmd_option(&_jmxremote_ssl_enabled_protocols); | |
423 _dcmdparser.add_dcmd_option(&_jmxremote_ssl_need_client_auth); | |
424 _dcmdparser.add_dcmd_option(&_jmxremote_ssl_config_file); | |
425 } | |
426 | |
427 | |
428 int JMXStartRemoteDCmd::num_arguments() { | |
429 ResourceMark rm; | |
430 JMXStartRemoteDCmd* dcmd = new JMXStartRemoteDCmd(NULL, false); | |
431 if (dcmd != NULL) { | |
432 DCmdMark mark(dcmd); | |
433 return dcmd->_dcmdparser.num_arguments(); | |
434 } else { | |
435 return 0; | |
436 } | |
437 } | |
438 | |
439 | |
440 void JMXStartRemoteDCmd::execute(TRAPS) { | |
441 ResourceMark rm(THREAD); | |
442 HandleMark hm(THREAD); | |
443 | |
444 // Load and initialize the sun.management.Agent class | |
445 // invoke startRemoteManagementAgent(string) method to start | |
446 // the remote management server. | |
447 // throw java.lang.NoSuchMethodError if the method doesn't exist | |
448 | |
449 Handle loader = Handle(THREAD, SystemDictionary::java_system_loader()); | |
450 klassOop k = SystemDictionary::resolve_or_fail(vmSymbols::sun_management_Agent(), loader, Handle(), true, CHECK); | |
451 instanceKlassHandle ik (THREAD, k); | |
452 | |
453 JavaValue result(T_VOID); | |
454 | |
455 // Pass all command line arguments to java as key=value,... | |
456 // All checks are done on java side | |
457 | |
458 int len = 0; | |
459 stringStream options; | |
460 char comma[2] = {0,0}; | |
461 | |
462 // Leave default values on Agent.class side and pass only | |
463 // agruments explicitly set by user. All arguments passed | |
464 // to jcmd override properties with the same name set by | |
465 // command line with -D or by managmenent.properties | |
466 // file. | |
467 #define PUT_OPTION(a) \ | |
468 if ( (a).is_set() ){ \ | |
469 options.print("%scom.sun.management.%s=%s", comma, (a).name(), (a).value()); \ | |
470 comma[0] = ','; \ | |
471 } | |
472 | |
473 PUT_OPTION(_config_file); | |
474 PUT_OPTION(_jmxremote_port); | |
475 PUT_OPTION(_jmxremote_rmi_port); | |
476 PUT_OPTION(_jmxremote_ssl); | |
477 PUT_OPTION(_jmxremote_registry_ssl); | |
478 PUT_OPTION(_jmxremote_authenticate); | |
479 PUT_OPTION(_jmxremote_password_file); | |
480 PUT_OPTION(_jmxremote_access_file); | |
481 PUT_OPTION(_jmxremote_login_config); | |
482 PUT_OPTION(_jmxremote_ssl_enabled_cipher_suites); | |
483 PUT_OPTION(_jmxremote_ssl_enabled_protocols); | |
484 PUT_OPTION(_jmxremote_ssl_need_client_auth); | |
485 PUT_OPTION(_jmxremote_ssl_config_file); | |
486 | |
487 #undef PUT_OPTION | |
488 | |
489 Handle str = java_lang_String::create_from_str(options.as_string(), CHECK); | |
490 JavaCalls::call_static(&result, ik, vmSymbols::startRemoteAgent_name(), vmSymbols::string_void_signature(), str, CHECK); | |
491 } | |
492 | |
493 JMXStartLocalDCmd::JMXStartLocalDCmd(outputStream *output, bool heap_allocated) : | |
494 DCmd(output, heap_allocated) | |
495 { | |
496 // do nothing | |
497 } | |
498 | |
499 void JMXStartLocalDCmd::execute(TRAPS) { | |
500 ResourceMark rm(THREAD); | |
501 HandleMark hm(THREAD); | |
502 | |
503 // Load and initialize the sun.management.Agent class | |
504 // invoke startLocalManagementAgent(void) method to start | |
505 // the local management server | |
506 // throw java.lang.NoSuchMethodError if method doesn't exist | |
507 | |
508 Handle loader = Handle(THREAD, SystemDictionary::java_system_loader()); | |
509 klassOop k = SystemDictionary::resolve_or_fail(vmSymbols::sun_management_Agent(), loader, Handle(), true, CHECK); | |
510 instanceKlassHandle ik (THREAD, k); | |
511 | |
512 JavaValue result(T_VOID); | |
513 JavaCalls::call_static(&result, ik, vmSymbols::startLocalAgent_name(), vmSymbols::void_method_signature(), CHECK); | |
514 } | |
515 | |
516 | |
517 void JMXStopRemoteDCmd::execute(TRAPS) { | |
518 ResourceMark rm(THREAD); | |
519 HandleMark hm(THREAD); | |
520 | |
521 // Load and initialize the sun.management.Agent class | |
522 // invoke stopRemoteManagementAgent method to stop the | |
523 // management server | |
524 // throw java.lang.NoSuchMethodError if method doesn't exist | |
525 | |
526 Handle loader = Handle(THREAD, SystemDictionary::java_system_loader()); | |
527 klassOop k = SystemDictionary::resolve_or_fail(vmSymbols::sun_management_Agent(), loader, Handle(), true, CHECK); | |
528 instanceKlassHandle ik (THREAD, k); | |
529 | |
530 JavaValue result(T_VOID); | |
531 JavaCalls::call_static(&result, ik, vmSymbols::stopRemoteAgent_name(), vmSymbols::void_method_signature(), CHECK); | |
532 } | |
533 |