src/share/vm/services/diagnosticCommand.cpp

Wed, 23 Jan 2013 13:02:39 -0500

author
jprovino
date
Wed, 23 Jan 2013 13:02:39 -0500
changeset 4542
db9981fd3124
parent 4167
9855b7e559ae
child 4544
3c9bc17b9403
permissions
-rw-r--r--

8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
Summary: Rename INCLUDE_ALTERNATE_GCS to INCLUDE_ALL_GCS and replace SERIALGC with INCLUDE_ALL_GCS.
Reviewed-by: coleenp, stefank

     1 /*
     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.
     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  */
    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"
    35 void DCmdRegistrant::register_dcmds(){
    36   // Registration of the diagnostic commands
    37   // First boolean argument specifies if the command is enabled
    38   // Second boolean argument specifies if the command is hidden
    39   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HelpDCmd>(true, false));
    40   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VersionDCmd>(true, false));
    41   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CommandLineDCmd>(true, false));
    42   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PrintSystemPropertiesDCmd>(true, false));
    43   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PrintVMFlagsDCmd>(true, false));
    44   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMUptimeDCmd>(true, false));
    45   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SystemGCDCmd>(true, false));
    46   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<RunFinalizationDCmd>(true, false));
    47 #if INCLUDE_SERVICES // Heap dumping supported
    48   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HeapDumpDCmd>(true, false));
    49 #endif // INCLUDE_SERVICES
    50   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassHistogramDCmd>(true, false));
    51   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ThreadDumpDCmd>(true, false));
    53   //Enhanced JMX Agent Support
    54   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStartRemoteDCmd>(true,false));
    55   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStartLocalDCmd>(true,false));
    56   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStopRemoteDCmd>(true,false));
    58 }
    60 #ifndef HAVE_EXTRA_DCMD
    61 void DCmdRegistrant::register_dcmds_ext(){
    62    // Do nothing here
    63 }
    64 #endif
    67 HelpDCmd::HelpDCmd(outputStream* output, bool heap) : DCmdWithParser(output, heap),
    68   _all("-all", "Show help for all commands", "BOOLEAN", false, "false"),
    69   _cmd("command name", "The name of the command for which we want help",
    70         "STRING", false) {
    71   _dcmdparser.add_dcmd_option(&_all);
    72   _dcmdparser.add_dcmd_argument(&_cmd);
    73 };
    75 void HelpDCmd::execute(TRAPS) {
    76   if (_all.value()) {
    77     GrowableArray<const char*>* cmd_list = DCmdFactory::DCmd_list();
    78     for (int i = 0; i < cmd_list->length(); i++) {
    79       DCmdFactory* factory = DCmdFactory::factory(cmd_list->at(i),
    80                                                   strlen(cmd_list->at(i)));
    81       if (!factory->is_hidden()) {
    82         output()->print_cr("%s%s", factory->name(),
    83                            factory->is_enabled() ? "" : " [disabled]");
    84         output()->print_cr("\t%s", factory->description());
    85         output()->cr();
    86       }
    87       factory = factory->next();
    88     }
    89   } else if (_cmd.has_value()) {
    90     DCmd* cmd = NULL;
    91     DCmdFactory* factory = DCmdFactory::factory(_cmd.value(),
    92                                                 strlen(_cmd.value()));
    93     if (factory != NULL) {
    94       output()->print_cr("%s%s", factory->name(),
    95                          factory->is_enabled() ? "" : " [disabled]");
    96       output()->print_cr(factory->description());
    97       output()->print_cr("\nImpact: %s", factory->impact());
    98       output()->cr();
    99       cmd = factory->create_resource_instance(output());
   100       if (cmd != NULL) {
   101         DCmdMark mark(cmd);
   102         cmd->print_help(factory->name());
   103       }
   104     } else {
   105       output()->print_cr("Help unavailable : '%s' : No such command", _cmd.value());
   106     }
   107   } else {
   108     output()->print_cr("The following commands are available:");
   109     GrowableArray<const char *>* cmd_list = DCmdFactory::DCmd_list();
   110     for (int i = 0; i < cmd_list->length(); i++) {
   111       DCmdFactory* factory = DCmdFactory::factory(cmd_list->at(i),
   112                                                   strlen(cmd_list->at(i)));
   113       if (!factory->is_hidden()) {
   114         output()->print_cr("%s%s", factory->name(),
   115                            factory->is_enabled() ? "" : " [disabled]");
   116       }
   117       factory = factory->_next;
   118     }
   119     output()->print_cr("\nFor more information about a specific command use 'help <command>'.");
   120   }
   121 }
   123 int HelpDCmd::num_arguments() {
   124   ResourceMark rm;
   125   HelpDCmd* dcmd = new HelpDCmd(NULL, false);
   126   if (dcmd != NULL) {
   127     DCmdMark mark(dcmd);
   128     return dcmd->_dcmdparser.num_arguments();
   129   } else {
   130     return 0;
   131   }
   132 }
   134 void VersionDCmd::execute(TRAPS) {
   135   output()->print_cr("%s version %s", Abstract_VM_Version::vm_name(),
   136           Abstract_VM_Version::vm_release());
   137   JDK_Version jdk_version = JDK_Version::current();
   138   if (jdk_version.update_version() > 0) {
   139     output()->print_cr("JDK %d.%d_%02d", jdk_version.major_version(),
   140             jdk_version.minor_version(), jdk_version.update_version());
   141   } else {
   142     output()->print_cr("JDK %d.%d", jdk_version.major_version(),
   143             jdk_version.minor_version());
   144   }
   145 }
   147 PrintVMFlagsDCmd::PrintVMFlagsDCmd(outputStream* output, bool heap) :
   148                                    DCmdWithParser(output, heap),
   149   _all("-all", "Print all flags supported by the VM", "BOOLEAN", false, "false") {
   150   _dcmdparser.add_dcmd_option(&_all);
   151 }
   153 void PrintVMFlagsDCmd::execute(TRAPS) {
   154   if (_all.value()) {
   155     CommandLineFlags::printFlags(output(), true);
   156   } else {
   157     CommandLineFlags::printSetFlags(output());
   158   }
   159 }
   161 int PrintVMFlagsDCmd::num_arguments() {
   162     ResourceMark rm;
   163     PrintVMFlagsDCmd* dcmd = new PrintVMFlagsDCmd(NULL, false);
   164     if (dcmd != NULL) {
   165       DCmdMark mark(dcmd);
   166       return dcmd->_dcmdparser.num_arguments();
   167     } else {
   168       return 0;
   169     }
   170 }
   172 void PrintSystemPropertiesDCmd::execute(TRAPS) {
   173   // load sun.misc.VMSupport
   174   Symbol* klass = vmSymbols::sun_misc_VMSupport();
   175   Klass* k = SystemDictionary::resolve_or_fail(klass, true, CHECK);
   176   instanceKlassHandle ik (THREAD, k);
   177   if (ik->should_be_initialized()) {
   178     ik->initialize(THREAD);
   179   }
   180   if (HAS_PENDING_EXCEPTION) {
   181     java_lang_Throwable::print(PENDING_EXCEPTION, output());
   182     output()->cr();
   183     CLEAR_PENDING_EXCEPTION;
   184     return;
   185   }
   187   // invoke the serializePropertiesToByteArray method
   188   JavaValue result(T_OBJECT);
   189   JavaCallArguments args;
   191   Symbol* signature = vmSymbols::serializePropertiesToByteArray_signature();
   192   JavaCalls::call_static(&result,
   193                          ik,
   194                          vmSymbols::serializePropertiesToByteArray_name(),
   195                          signature,
   196                          &args,
   197                          THREAD);
   198   if (HAS_PENDING_EXCEPTION) {
   199     java_lang_Throwable::print(PENDING_EXCEPTION, output());
   200     output()->cr();
   201     CLEAR_PENDING_EXCEPTION;
   202     return;
   203   }
   205   // The result should be a [B
   206   oop res = (oop)result.get_jobject();
   207   assert(res->is_typeArray(), "just checking");
   208   assert(TypeArrayKlass::cast(res->klass())->element_type() == T_BYTE, "just checking");
   210   // copy the bytes to the output stream
   211   typeArrayOop ba = typeArrayOop(res);
   212   jbyte* addr = typeArrayOop(res)->byte_at_addr(0);
   213   output()->print_raw((const char*)addr, ba->length());
   214 }
   216 VMUptimeDCmd::VMUptimeDCmd(outputStream* output, bool heap) :
   217                            DCmdWithParser(output, heap),
   218   _date("-date", "Add a prefix with current date", "BOOLEAN", false, "false") {
   219   _dcmdparser.add_dcmd_option(&_date);
   220 }
   222 void VMUptimeDCmd::execute(TRAPS) {
   223   if (_date.value()) {
   224     output()->date_stamp(true, "", ": ");
   225   }
   226   output()->time_stamp().update_to(tty->time_stamp().ticks());
   227   output()->stamp();
   228   output()->print_cr(" s");
   229 }
   231 int VMUptimeDCmd::num_arguments() {
   232   ResourceMark rm;
   233   VMUptimeDCmd* dcmd = new VMUptimeDCmd(NULL, false);
   234   if (dcmd != NULL) {
   235     DCmdMark mark(dcmd);
   236     return dcmd->_dcmdparser.num_arguments();
   237   } else {
   238     return 0;
   239   }
   240 }
   242 void SystemGCDCmd::execute(TRAPS) {
   243   Universe::heap()->collect(GCCause::_java_lang_system_gc);
   244 }
   246 void RunFinalizationDCmd::execute(TRAPS) {
   247   Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_System(),
   248                                                  true, CHECK);
   249   instanceKlassHandle klass(THREAD, k);
   250   JavaValue result(T_VOID);
   251   JavaCalls::call_static(&result, klass,
   252                          vmSymbols::run_finalization_name(),
   253                          vmSymbols::void_method_signature(), CHECK);
   254 }
   256 #if INCLUDE_SERVICES // Heap dumping supported
   257 HeapDumpDCmd::HeapDumpDCmd(outputStream* output, bool heap) :
   258                            DCmdWithParser(output, heap),
   259   _filename("filename","Name of the dump file", "STRING",true),
   260   _all("-all", "Dump all objects, including unreachable objects",
   261        "BOOLEAN", false, "false") {
   262   _dcmdparser.add_dcmd_option(&_all);
   263   _dcmdparser.add_dcmd_argument(&_filename);
   264 }
   266 void HeapDumpDCmd::execute(TRAPS) {
   267   // Request a full GC before heap dump if _all is false
   268   // This helps reduces the amount of unreachable objects in the dump
   269   // and makes it easier to browse.
   270   HeapDumper dumper(!_all.value() /* request GC if _all is false*/);
   271   int res = dumper.dump(_filename.value());
   272   if (res == 0) {
   273     output()->print_cr("Heap dump file created");
   274   } else {
   275     // heap dump failed
   276     ResourceMark rm;
   277     char* error = dumper.error_as_C_string();
   278     if (error == NULL) {
   279       output()->print_cr("Dump failed - reason unknown");
   280     } else {
   281       output()->print_cr("%s", error);
   282     }
   283   }
   284 }
   286 int HeapDumpDCmd::num_arguments() {
   287   ResourceMark rm;
   288   HeapDumpDCmd* dcmd = new HeapDumpDCmd(NULL, false);
   289   if (dcmd != NULL) {
   290     DCmdMark mark(dcmd);
   291     return dcmd->_dcmdparser.num_arguments();
   292   } else {
   293     return 0;
   294   }
   295 }
   296 #endif // INCLUDE_SERVICES
   298 ClassHistogramDCmd::ClassHistogramDCmd(outputStream* output, bool heap) :
   299                                        DCmdWithParser(output, heap),
   300   _all("-all", "Inspect all objects, including unreachable objects",
   301        "BOOLEAN", false, "false") {
   302   _dcmdparser.add_dcmd_option(&_all);
   303 }
   305 void ClassHistogramDCmd::execute(TRAPS) {
   306   VM_GC_HeapInspection heapop(output(),
   307                               !_all.value() /* request full gc if false */,
   308                               true /* need_prologue */);
   309   VMThread::execute(&heapop);
   310 }
   312 int ClassHistogramDCmd::num_arguments() {
   313   ResourceMark rm;
   314   ClassHistogramDCmd* dcmd = new ClassHistogramDCmd(NULL, false);
   315   if (dcmd != NULL) {
   316     DCmdMark mark(dcmd);
   317     return dcmd->_dcmdparser.num_arguments();
   318   } else {
   319     return 0;
   320   }
   321 }
   323 ThreadDumpDCmd::ThreadDumpDCmd(outputStream* output, bool heap) :
   324                                DCmdWithParser(output, heap),
   325   _locks("-l", "print java.util.concurrent locks", "BOOLEAN", false, "false") {
   326   _dcmdparser.add_dcmd_option(&_locks);
   327 }
   329 void ThreadDumpDCmd::execute(TRAPS) {
   330   // thread stacks
   331   VM_PrintThreads op1(output(), _locks.value());
   332   VMThread::execute(&op1);
   334   // JNI global handles
   335   VM_PrintJNI op2(output());
   336   VMThread::execute(&op2);
   338   // Deadlock detection
   339   VM_FindDeadlocks op3(output());
   340   VMThread::execute(&op3);
   341 }
   343 int ThreadDumpDCmd::num_arguments() {
   344   ResourceMark rm;
   345   ThreadDumpDCmd* dcmd = new ThreadDumpDCmd(NULL, false);
   346   if (dcmd != NULL) {
   347     DCmdMark mark(dcmd);
   348     return dcmd->_dcmdparser.num_arguments();
   349   } else {
   350     return 0;
   351   }
   352 }
   354 // Enhanced JMX Agent support
   356 JMXStartRemoteDCmd::JMXStartRemoteDCmd(outputStream *output, bool heap_allocated) :
   358   DCmdWithParser(output, heap_allocated),
   360   _config_file
   361   ("config.file",
   362    "set com.sun.management.config.file", "STRING", false),
   364   _jmxremote_port
   365   ("jmxremote.port",
   366    "set com.sun.management.jmxremote.port", "STRING", false),
   368   _jmxremote_rmi_port
   369   ("jmxremote.rmi.port",
   370    "set com.sun.management.jmxremote.rmi.port", "STRING", false),
   372   _jmxremote_ssl
   373   ("jmxremote.ssl",
   374    "set com.sun.management.jmxremote.ssl", "STRING", false),
   376   _jmxremote_registry_ssl
   377   ("jmxremote.registry.ssl",
   378    "set com.sun.management.jmxremote.registry.ssl", "STRING", false),
   380   _jmxremote_authenticate
   381   ("jmxremote.authenticate",
   382    "set com.sun.management.jmxremote.authenticate", "STRING", false),
   384   _jmxremote_password_file
   385   ("jmxremote.password.file",
   386    "set com.sun.management.jmxremote.password.file", "STRING", false),
   388   _jmxremote_access_file
   389   ("jmxremote.access.file",
   390    "set com.sun.management.jmxremote.access.file", "STRING", false),
   392   _jmxremote_login_config
   393   ("jmxremote.login.config",
   394    "set com.sun.management.jmxremote.login.config", "STRING", false),
   396   _jmxremote_ssl_enabled_cipher_suites
   397   ("jmxremote.ssl.enabled.cipher.suites",
   398    "set com.sun.management.jmxremote.ssl.enabled.cipher.suite", "STRING", false),
   400   _jmxremote_ssl_enabled_protocols
   401   ("jmxremote.ssl.enabled.protocols",
   402    "set com.sun.management.jmxremote.ssl.enabled.protocols", "STRING", false),
   404   _jmxremote_ssl_need_client_auth
   405   ("jmxremote.ssl.need.client.auth",
   406    "set com.sun.management.jmxremote.need.client.auth", "STRING", false),
   408   _jmxremote_ssl_config_file
   409   ("jmxremote.ssl.config.file",
   410    "set com.sun.management.jmxremote.ssl_config_file", "STRING", false)
   412   {
   413     _dcmdparser.add_dcmd_option(&_config_file);
   414     _dcmdparser.add_dcmd_option(&_jmxremote_port);
   415     _dcmdparser.add_dcmd_option(&_jmxremote_rmi_port);
   416     _dcmdparser.add_dcmd_option(&_jmxremote_ssl);
   417     _dcmdparser.add_dcmd_option(&_jmxremote_registry_ssl);
   418     _dcmdparser.add_dcmd_option(&_jmxremote_authenticate);
   419     _dcmdparser.add_dcmd_option(&_jmxremote_password_file);
   420     _dcmdparser.add_dcmd_option(&_jmxremote_access_file);
   421     _dcmdparser.add_dcmd_option(&_jmxremote_login_config);
   422     _dcmdparser.add_dcmd_option(&_jmxremote_ssl_enabled_cipher_suites);
   423     _dcmdparser.add_dcmd_option(&_jmxremote_ssl_enabled_protocols);
   424     _dcmdparser.add_dcmd_option(&_jmxremote_ssl_need_client_auth);
   425     _dcmdparser.add_dcmd_option(&_jmxremote_ssl_config_file);
   426 }
   429 int JMXStartRemoteDCmd::num_arguments() {
   430   ResourceMark rm;
   431   JMXStartRemoteDCmd* dcmd = new JMXStartRemoteDCmd(NULL, false);
   432   if (dcmd != NULL) {
   433     DCmdMark mark(dcmd);
   434     return dcmd->_dcmdparser.num_arguments();
   435   } else {
   436     return 0;
   437   }
   438 }
   441 void JMXStartRemoteDCmd::execute(TRAPS) {
   442     ResourceMark rm(THREAD);
   443     HandleMark hm(THREAD);
   445     // Load and initialize the sun.management.Agent class
   446     // invoke startRemoteManagementAgent(string) method to start
   447     // the remote management server.
   448     // throw java.lang.NoSuchMethodError if the method doesn't exist
   450     Handle loader = Handle(THREAD, SystemDictionary::java_system_loader());
   451     Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::sun_management_Agent(), loader, Handle(), true, CHECK);
   452     instanceKlassHandle ik (THREAD, k);
   454     JavaValue result(T_VOID);
   456     // Pass all command line arguments to java as key=value,...
   457     // All checks are done on java side
   459     int len = 0;
   460     stringStream options;
   461     char comma[2] = {0,0};
   463     // Leave default values on Agent.class side and pass only
   464     // agruments explicitly set by user. All arguments passed
   465     // to jcmd override properties with the same name set by
   466     // command line with -D or by managmenent.properties
   467     // file.
   468 #define PUT_OPTION(a) \
   469     if ( (a).is_set() ){ \
   470         options.print("%scom.sun.management.%s=%s", comma, (a).name(), (a).value()); \
   471         comma[0] = ','; \
   472     }
   474     PUT_OPTION(_config_file);
   475     PUT_OPTION(_jmxremote_port);
   476     PUT_OPTION(_jmxremote_rmi_port);
   477     PUT_OPTION(_jmxremote_ssl);
   478     PUT_OPTION(_jmxremote_registry_ssl);
   479     PUT_OPTION(_jmxremote_authenticate);
   480     PUT_OPTION(_jmxremote_password_file);
   481     PUT_OPTION(_jmxremote_access_file);
   482     PUT_OPTION(_jmxremote_login_config);
   483     PUT_OPTION(_jmxremote_ssl_enabled_cipher_suites);
   484     PUT_OPTION(_jmxremote_ssl_enabled_protocols);
   485     PUT_OPTION(_jmxremote_ssl_need_client_auth);
   486     PUT_OPTION(_jmxremote_ssl_config_file);
   488 #undef PUT_OPTION
   490     Handle str = java_lang_String::create_from_str(options.as_string(), CHECK);
   491     JavaCalls::call_static(&result, ik, vmSymbols::startRemoteAgent_name(), vmSymbols::string_void_signature(), str, CHECK);
   492 }
   494 JMXStartLocalDCmd::JMXStartLocalDCmd(outputStream *output, bool heap_allocated) :
   495   DCmd(output, heap_allocated)
   496 {
   497   // do nothing
   498 }
   500 void JMXStartLocalDCmd::execute(TRAPS) {
   501     ResourceMark rm(THREAD);
   502     HandleMark hm(THREAD);
   504     // Load and initialize the sun.management.Agent class
   505     // invoke startLocalManagementAgent(void) method to start
   506     // the local management server
   507     // throw java.lang.NoSuchMethodError if method doesn't exist
   509     Handle loader = Handle(THREAD, SystemDictionary::java_system_loader());
   510     Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::sun_management_Agent(), loader, Handle(), true, CHECK);
   511     instanceKlassHandle ik (THREAD, k);
   513     JavaValue result(T_VOID);
   514     JavaCalls::call_static(&result, ik, vmSymbols::startLocalAgent_name(), vmSymbols::void_method_signature(), CHECK);
   515 }
   518 void JMXStopRemoteDCmd::execute(TRAPS) {
   519     ResourceMark rm(THREAD);
   520     HandleMark hm(THREAD);
   522     // Load and initialize the sun.management.Agent class
   523     // invoke stopRemoteManagementAgent method to stop the
   524     // management server
   525     // throw java.lang.NoSuchMethodError if method doesn't exist
   527     Handle loader = Handle(THREAD, SystemDictionary::java_system_loader());
   528     Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::sun_management_Agent(), loader, Handle(), true, CHECK);
   529     instanceKlassHandle ik (THREAD, k);
   531     JavaValue result(T_VOID);
   532     JavaCalls::call_static(&result, ik, vmSymbols::stopRemoteAgent_name(), vmSymbols::void_method_signature(), CHECK);
   533 }

mercurial