8200384: jcmd help output should be sorted
authorstuefe
Wed, 28 Mar 2018 22:03:57 +0200
changeset 49750 bdcfe8154201
parent 49749 bebec5011846
child 49751 c3a10df652c0
8200384: jcmd help output should be sorted Reviewed-by: sspitsyn, clanger
src/hotspot/share/services/diagnosticCommand.cpp
--- a/src/hotspot/share/services/diagnosticCommand.cpp	Wed Apr 11 20:56:56 2018 +0300
+++ b/src/hotspot/share/services/diagnosticCommand.cpp	Wed Mar 28 22:03:57 2018 +0200
@@ -137,9 +137,15 @@
   _dcmdparser.add_dcmd_argument(&_cmd);
 };
 
+
+static int compare_strings(const char** s1, const char** s2) {
+  return ::strcmp(*s1, *s2);
+}
+
 void HelpDCmd::execute(DCmdSource source, TRAPS) {
   if (_all.value()) {
     GrowableArray<const char*>* cmd_list = DCmdFactory::DCmd_list(source);
+    cmd_list->sort(compare_strings);
     for (int i = 0; i < cmd_list->length(); i++) {
       DCmdFactory* factory = DCmdFactory::factory(source, cmd_list->at(i),
                                                   strlen(cmd_list->at(i)));
@@ -180,6 +186,7 @@
   } else {
     output()->print_cr("The following commands are available:");
     GrowableArray<const char *>* cmd_list = DCmdFactory::DCmd_list(source);
+    cmd_list->sort(compare_strings);
     for (int i = 0; i < cmd_list->length(); i++) {
       DCmdFactory* factory = DCmdFactory::factory(source, cmd_list->at(i),
                                                   strlen(cmd_list->at(i)));