src/hotspot/share/services/diagnosticFramework.cpp
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 46560 hotspot/src/share/vm/services/diagnosticFramework.cpp@388aa8d67c80
child 47765 b7c7428eaab9
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
     1
/*
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 37248
diff changeset
     2
 * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
     4
 *
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
     7
 * published by the Free Software Foundation.
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
     8
 *
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    13
 * accompanied this code).
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    14
 *
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    18
 *
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    21
 * questions.
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    22
 *
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    23
 */
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    24
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    25
#include "precompiled.hpp"
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    26
#include "memory/oopFactory.hpp"
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 30247
diff changeset
    27
#include "memory/resourceArea.hpp"
29081
c61eb4914428 8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents: 28163
diff changeset
    28
#include "oops/oop.inline.hpp"
46560
388aa8d67c80 8181449: Fix debug.hpp / globalDefinitions.hpp dependency inversion
kbarrett
parents: 46329
diff changeset
    29
#include "prims/jvm.h"
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    30
#include "runtime/javaCalls.hpp"
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    31
#include "runtime/mutexLocker.hpp"
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    32
#include "services/diagnosticArgument.hpp"
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    33
#include "services/diagnosticFramework.hpp"
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    34
#include "services/management.hpp"
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    35
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    36
CmdLine::CmdLine(const char* line, size_t len, bool no_command_name) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    37
  assert(line != NULL, "Command line string should not be NULL");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    38
  const char* line_end;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    39
  const char* cmd_end;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    40
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    41
  _cmd = line;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    42
  line_end = &line[len];
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    43
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    44
  // Skip whitespace in the beginning of the line.
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    45
  while (_cmd < line_end && isspace((int) _cmd[0])) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    46
    _cmd++;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    47
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    48
  cmd_end = _cmd;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    49
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    50
  if (no_command_name) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    51
    _cmd = NULL;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    52
    _cmd_len = 0;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    53
  } else {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    54
    // Look for end of the command name
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    55
    while (cmd_end < line_end && !isspace((int) cmd_end[0])) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    56
      cmd_end++;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    57
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    58
    _cmd_len = cmd_end - _cmd;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    59
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    60
  _args = cmd_end;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    61
  _args_len = line_end - _args;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    62
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    63
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    64
bool DCmdArgIter::next(TRAPS) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    65
  if (_len == 0) return false;
27879
419385282044 8065783: DCMD parser fails to recognize one character argument when it's positioned last
jbachorik
parents: 24424
diff changeset
    66
  // skipping delimiters
11776
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11441
diff changeset
    67
  while (_cursor < _len - 1 && _buffer[_cursor] == _delim) {
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    68
    _cursor++;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    69
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    70
  // handling end of command line
27879
419385282044 8065783: DCMD parser fails to recognize one character argument when it's positioned last
jbachorik
parents: 24424
diff changeset
    71
  if (_cursor == _len - 1 && _buffer[_cursor] == _delim) {
419385282044 8065783: DCMD parser fails to recognize one character argument when it's positioned last
jbachorik
parents: 24424
diff changeset
    72
    _key_addr = &_buffer[_cursor];
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    73
    _key_len = 0;
27879
419385282044 8065783: DCMD parser fails to recognize one character argument when it's positioned last
jbachorik
parents: 24424
diff changeset
    74
    _value_addr = &_buffer[_cursor];
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    75
    _value_len = 0;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    76
    return false;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    77
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    78
  // extracting first item, argument or option name
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    79
  _key_addr = &_buffer[_cursor];
13200
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 11776
diff changeset
    80
  bool arg_had_quotes = false;
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    81
  while (_cursor <= _len - 1 && _buffer[_cursor] != '=' && _buffer[_cursor] != _delim) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    82
    // argument can be surrounded by single or double quotes
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    83
    if (_buffer[_cursor] == '\"' || _buffer[_cursor] == '\'') {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    84
      _key_addr++;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    85
      char quote = _buffer[_cursor];
13200
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 11776
diff changeset
    86
      arg_had_quotes = true;
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    87
      while (_cursor < _len - 1) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    88
        _cursor++;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    89
        if (_buffer[_cursor] == quote && _buffer[_cursor - 1] != '\\') {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    90
          break;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    91
        }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    92
      }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    93
      if (_buffer[_cursor] != quote) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    94
        THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    95
                "Format error in diagnostic command arguments", false);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    96
      }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    97
      break;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    98
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    99
    _cursor++;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   100
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   101
  _key_len = &_buffer[_cursor] - _key_addr;
13200
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 11776
diff changeset
   102
  if (arg_had_quotes) {
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 11776
diff changeset
   103
    // if the argument was quoted, we need to step past the last quote here
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 11776
diff changeset
   104
    _cursor++;
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 11776
diff changeset
   105
  }
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   106
  // check if the argument has the <key>=<value> format
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   107
  if (_cursor <= _len -1 && _buffer[_cursor] == '=') {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   108
    _cursor++;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   109
    _value_addr = &_buffer[_cursor];
13200
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 11776
diff changeset
   110
    bool value_had_quotes = false;
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   111
    // extract the value
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   112
    while (_cursor <= _len - 1 && _buffer[_cursor] != _delim) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   113
      // value can be surrounded by simple or double quotes
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   114
      if (_buffer[_cursor] == '\"' || _buffer[_cursor] == '\'') {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   115
        _value_addr++;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   116
        char quote = _buffer[_cursor];
13200
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 11776
diff changeset
   117
        value_had_quotes = true;
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   118
        while (_cursor < _len - 1) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   119
          _cursor++;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   120
          if (_buffer[_cursor] == quote && _buffer[_cursor - 1] != '\\') {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   121
            break;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   122
          }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   123
        }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   124
        if (_buffer[_cursor] != quote) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   125
          THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   126
                  "Format error in diagnostic command arguments", false);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   127
        }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   128
        break;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   129
      }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   130
      _cursor++;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   131
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   132
    _value_len = &_buffer[_cursor] - _value_addr;
13200
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 11776
diff changeset
   133
    if (value_had_quotes) {
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 11776
diff changeset
   134
      // if the value was quoted, we need to step past the last quote here
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 11776
diff changeset
   135
      _cursor++;
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 11776
diff changeset
   136
    }
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   137
  } else {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   138
    _value_addr = NULL;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   139
    _value_len = 0;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   140
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   141
  return _key_len != 0;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   142
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   143
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   144
bool DCmdInfo::by_name(void* cmd_name, DCmdInfo* info) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   145
  if (info == NULL) return false;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   146
  return strcmp((const char*)cmd_name, info->name()) == 0;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   147
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   148
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   149
void DCmdParser::add_dcmd_option(GenDCmdArgument* arg) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   150
  assert(arg != NULL, "Sanity");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   151
  if (_options == NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   152
    _options = arg;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   153
  } else {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   154
    GenDCmdArgument* o = _options;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   155
    while (o->next() != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   156
      o = o->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   157
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   158
    o->set_next(arg);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   159
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   160
  arg->set_next(NULL);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   161
  Thread* THREAD = Thread::current();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   162
  arg->init_value(THREAD);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   163
  if (HAS_PENDING_EXCEPTION) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   164
    fatal("Initialization must be successful");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   165
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   166
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   167
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   168
void DCmdParser::add_dcmd_argument(GenDCmdArgument* arg) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   169
  assert(arg != NULL, "Sanity");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   170
  if (_arguments_list == NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   171
    _arguments_list = arg;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   172
  } else {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   173
    GenDCmdArgument* a = _arguments_list;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   174
    while (a->next() != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   175
      a = a->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   176
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   177
    a->set_next(arg);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   178
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   179
  arg->set_next(NULL);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   180
  Thread* THREAD = Thread::current();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   181
  arg->init_value(THREAD);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   182
  if (HAS_PENDING_EXCEPTION) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   183
    fatal("Initialization must be successful");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   184
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   185
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   186
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   187
void DCmdParser::parse(CmdLine* line, char delim, TRAPS) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   188
  GenDCmdArgument* next_argument = _arguments_list;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   189
  DCmdArgIter iter(line->args_addr(), line->args_len(), delim);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   190
  bool cont = iter.next(CHECK);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   191
  while (cont) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   192
    GenDCmdArgument* arg = lookup_dcmd_option(iter.key_addr(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   193
            iter.key_length());
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   194
    if (arg != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   195
      arg->read_value(iter.value_addr(), iter.value_length(), CHECK);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   196
    } else {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   197
      if (next_argument != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   198
        arg = next_argument;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   199
        arg->read_value(iter.key_addr(), iter.key_length(), CHECK);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   200
        next_argument = next_argument->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   201
      } else {
13200
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 11776
diff changeset
   202
        const size_t buflen    = 120;
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 11776
diff changeset
   203
        const size_t argbuflen = 30;
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 11776
diff changeset
   204
        char buf[buflen];
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 11776
diff changeset
   205
        char argbuf[argbuflen];
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 11776
diff changeset
   206
        size_t len = MIN2<size_t>(iter.key_length(), argbuflen - 1);
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 11776
diff changeset
   207
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 11776
diff changeset
   208
        strncpy(argbuf, iter.key_addr(), len);
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 11776
diff changeset
   209
        argbuf[len] = '\0';
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 11776
diff changeset
   210
        jio_snprintf(buf, buflen - 1, "Unknown argument '%s' in diagnostic command.", argbuf);
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 11776
diff changeset
   211
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 11776
diff changeset
   212
        THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), buf);
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   213
      }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   214
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   215
    cont = iter.next(CHECK);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   216
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   217
  check(CHECK);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   218
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   219
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   220
GenDCmdArgument* DCmdParser::lookup_dcmd_option(const char* name, size_t len) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   221
  GenDCmdArgument* arg = _options;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   222
  while (arg != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   223
    if (strlen(arg->name()) == len &&
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   224
      strncmp(name, arg->name(), len) == 0) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   225
      return arg;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   226
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   227
    arg = arg->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   228
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   229
  return NULL;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   230
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   231
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   232
void DCmdParser::check(TRAPS) {
13200
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 11776
diff changeset
   233
  const size_t buflen = 256;
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 11776
diff changeset
   234
  char buf[buflen];
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   235
  GenDCmdArgument* arg = _arguments_list;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   236
  while (arg != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   237
    if (arg->is_mandatory() && !arg->has_value()) {
13200
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 11776
diff changeset
   238
      jio_snprintf(buf, buflen - 1, "The argument '%s' is mandatory.", arg->name());
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 11776
diff changeset
   239
      THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), buf);
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   240
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   241
    arg = arg->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   242
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   243
  arg = _options;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   244
  while (arg != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   245
    if (arg->is_mandatory() && !arg->has_value()) {
13200
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 11776
diff changeset
   246
      jio_snprintf(buf, buflen - 1, "The option '%s' is mandatory.", arg->name());
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 11776
diff changeset
   247
      THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), buf);
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   248
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   249
    arg = arg->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   250
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   251
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   252
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   253
void DCmdParser::print_help(outputStream* out, const char* cmd_name) {
11441
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   254
  out->print("Syntax : %s %s", cmd_name, _options == NULL ? "" : "[options]");
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   255
  GenDCmdArgument* arg = _arguments_list;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   256
  while (arg != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   257
    if (arg->is_mandatory()) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   258
      out->print(" <%s>", arg->name());
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   259
    } else {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   260
      out->print(" [<%s>]", arg->name());
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   261
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   262
    arg = arg->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   263
  }
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 17296
diff changeset
   264
  out->cr();
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   265
  if (_arguments_list != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   266
    out->print_cr("\nArguments:");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   267
    arg = _arguments_list;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   268
    while (arg != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   269
      out->print("\t%s : %s %s (%s, ", arg->name(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   270
                 arg->is_mandatory() ? "" : "[optional]",
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   271
                 arg->description(), arg->type());
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   272
      if (arg->has_default()) {
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 17296
diff changeset
   273
        out->print("%s", arg->default_string());
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   274
      } else {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   275
        out->print("no default value");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   276
      }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   277
      out->print_cr(")");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   278
      arg = arg->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   279
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   280
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   281
  if (_options != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   282
    out->print_cr("\nOptions: (options must be specified using the <key> or <key>=<value> syntax)");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   283
    arg = _options;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   284
    while (arg != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   285
      out->print("\t%s : %s %s (%s, ", arg->name(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   286
                 arg->is_mandatory() ? "" : "[optional]",
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   287
                 arg->description(), arg->type());
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   288
      if (arg->has_default()) {
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 17296
diff changeset
   289
        out->print("%s", arg->default_string());
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   290
      } else {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   291
        out->print("no default value");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   292
      }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   293
      out->print_cr(")");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   294
      arg = arg->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   295
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   296
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   297
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   298
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   299
void DCmdParser::reset(TRAPS) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   300
  GenDCmdArgument* arg = _arguments_list;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   301
  while (arg != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   302
    arg->reset(CHECK);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   303
    arg = arg->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   304
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   305
  arg = _options;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   306
  while (arg != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   307
    arg->reset(CHECK);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   308
    arg = arg->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   309
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   310
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   311
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   312
void DCmdParser::cleanup() {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   313
  GenDCmdArgument* arg = _arguments_list;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   314
  while (arg != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   315
    arg->cleanup();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   316
    arg = arg->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   317
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   318
  arg = _options;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   319
  while (arg != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   320
    arg->cleanup();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   321
    arg = arg->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   322
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   323
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   324
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   325
int DCmdParser::num_arguments() {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   326
  GenDCmdArgument* arg = _arguments_list;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   327
  int count = 0;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   328
  while (arg != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   329
    count++;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   330
    arg = arg->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   331
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   332
  arg = _options;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   333
  while (arg != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   334
    count++;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   335
    arg = arg->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   336
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   337
  return count;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   338
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   339
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   340
GrowableArray<const char *>* DCmdParser::argument_name_array() {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   341
  int count = num_arguments();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   342
  GrowableArray<const char *>* array = new GrowableArray<const char *>(count);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   343
  GenDCmdArgument* arg = _arguments_list;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   344
  while (arg != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   345
    array->append(arg->name());
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   346
    arg = arg->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   347
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   348
  arg = _options;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   349
  while (arg != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   350
    array->append(arg->name());
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   351
    arg = arg->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   352
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   353
  return array;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   354
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   355
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   356
GrowableArray<DCmdArgumentInfo*>* DCmdParser::argument_info_array() {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   357
  int count = num_arguments();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   358
  GrowableArray<DCmdArgumentInfo*>* array = new GrowableArray<DCmdArgumentInfo *>(count);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   359
  int idx = 0;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   360
  GenDCmdArgument* arg = _arguments_list;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   361
  while (arg != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   362
    array->append(new DCmdArgumentInfo(arg->name(), arg->description(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   363
                  arg->type(), arg->default_string(), arg->is_mandatory(),
17296
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   364
                  false, arg->allow_multiple(), idx));
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   365
    idx++;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   366
    arg = arg->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   367
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   368
  arg = _options;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   369
  while (arg != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   370
    array->append(new DCmdArgumentInfo(arg->name(), arg->description(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   371
                  arg->type(), arg->default_string(), arg->is_mandatory(),
17296
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   372
                  true, arg->allow_multiple()));
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   373
    arg = arg->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   374
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   375
  return array;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   376
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   377
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   378
DCmdFactory* DCmdFactory::_DCmdFactoryList = NULL;
17296
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   379
bool DCmdFactory::_has_pending_jmx_notification = false;
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   380
17296
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   381
void DCmd::parse_and_execute(DCmdSource source, outputStream* out,
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   382
                             const char* cmdline, char delim, TRAPS) {
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   383
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   384
  if (cmdline == NULL) return; // Nothing to do!
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   385
  DCmdIter iter(cmdline, '\n');
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   386
17296
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   387
  int count = 0;
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   388
  while (iter.has_next()) {
17296
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   389
    if(source == DCmd_Source_MBean && count > 0) {
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   390
      // When diagnostic commands are invoked via JMX, each command line
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   391
      // must contains one and only one command because of the Permission
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   392
      // checks performed by the DiagnosticCommandMBean
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   393
      THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   394
              "Invalid syntax");
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   395
    }
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   396
    CmdLine line = iter.next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   397
    if (line.is_stop()) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   398
      break;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   399
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   400
    if (line.is_executable()) {
17296
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   401
      DCmd* command = DCmdFactory::create_local_DCmd(source, line, out, CHECK);
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   402
      assert(command != NULL, "command error must be handled before this line");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   403
      DCmdMark mark(command);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   404
      command->parse(&line, delim, CHECK);
17296
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   405
      command->execute(source, CHECK);
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   406
    }
17296
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   407
    count++;
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   408
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   409
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   410
11441
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   411
void DCmdWithParser::parse(CmdLine* line, char delim, TRAPS) {
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   412
  _dcmdparser.parse(line, delim, CHECK);
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   413
}
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   414
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   415
void DCmdWithParser::print_help(const char* name) {
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   416
  _dcmdparser.print_help(output(), name);
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   417
}
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   418
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   419
void DCmdWithParser::reset(TRAPS) {
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   420
  _dcmdparser.reset(CHECK);
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   421
}
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   422
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   423
void DCmdWithParser::cleanup() {
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   424
  _dcmdparser.cleanup();
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   425
}
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   426
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   427
GrowableArray<const char*>* DCmdWithParser::argument_name_array() {
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   428
  return _dcmdparser.argument_name_array();
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   429
}
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   430
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   431
GrowableArray<DCmdArgumentInfo*>* DCmdWithParser::argument_info_array() {
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   432
  return _dcmdparser.argument_info_array();
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   433
}
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   434
17296
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   435
void DCmdFactory::push_jmx_notification_request() {
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   436
  MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   437
  _has_pending_jmx_notification = true;
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   438
  Service_lock->notify_all();
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   439
}
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   440
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   441
void DCmdFactory::send_notification(TRAPS) {
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   442
  DCmdFactory::send_notification_internal(THREAD);
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   443
  // Clearing pending exception to avoid premature termination of
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   444
  // the service thread
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   445
  if (HAS_PENDING_EXCEPTION) {
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   446
    CLEAR_PENDING_EXCEPTION;
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   447
  }
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   448
}
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   449
void DCmdFactory::send_notification_internal(TRAPS) {
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   450
  ResourceMark rm(THREAD);
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   451
  HandleMark hm(THREAD);
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   452
  bool notif = false;
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   453
  {
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   454
    MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   455
    notif = _has_pending_jmx_notification;
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   456
    _has_pending_jmx_notification = false;
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   457
  }
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   458
  if (notif) {
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   459
30247
9925b07bba5b 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents: 29081
diff changeset
   460
    Klass* k = Management::com_sun_management_internal_DiagnosticCommandImpl_klass(CHECK);
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 37248
diff changeset
   461
    InstanceKlass* dcmd_mbean_klass = InstanceKlass::cast(k);
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   462
17296
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   463
    JavaValue result(T_OBJECT);
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   464
    JavaCalls::call_static(&result,
30247
9925b07bba5b 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents: 29081
diff changeset
   465
            dcmd_mbean_klass,
17296
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   466
            vmSymbols::getDiagnosticCommandMBean_name(),
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   467
            vmSymbols::getDiagnosticCommandMBean_signature(),
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   468
            CHECK);
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   469
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   470
    instanceOop m = (instanceOop) result.get_jobject();
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   471
    instanceHandle dcmd_mbean_h(THREAD, m);
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   472
30247
9925b07bba5b 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents: 29081
diff changeset
   473
    if (!dcmd_mbean_h->is_a(k)) {
17296
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   474
      THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
30247
9925b07bba5b 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents: 29081
diff changeset
   475
              "DiagnosticCommandImpl.getDiagnosticCommandMBean didn't return a DiagnosticCommandMBean instance");
17296
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   476
    }
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   477
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   478
    JavaValue result2(T_VOID);
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   479
    JavaCallArguments args2(dcmd_mbean_h);
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   480
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   481
    JavaCalls::call_virtual(&result2,
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   482
            dcmd_mbean_klass,
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   483
            vmSymbols::createDiagnosticFrameworkNotification_name(),
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   484
            vmSymbols::void_method_signature(),
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   485
            &args2,
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   486
            CHECK);
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   487
  }
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   488
}
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   489
28163
322d55d167be 8047290: Make Mutex::_no_safepoint_check_flag locks verify that this lock never checks for safepoint
coleenp
parents: 27879
diff changeset
   490
Mutex* DCmdFactory::_dcmdFactory_lock = new Mutex(Mutex::leaf, "DCmdFactory", true, Monitor::_safepoint_check_never);
17296
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   491
bool DCmdFactory::_send_jmx_notification = false;
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   492
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   493
DCmdFactory* DCmdFactory::factory(DCmdSource source, const char* name, size_t len) {
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   494
  MutexLockerEx ml(_dcmdFactory_lock, Mutex::_no_safepoint_check_flag);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   495
  DCmdFactory* factory = _DCmdFactoryList;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   496
  while (factory != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   497
    if (strlen(factory->name()) == len &&
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   498
        strncmp(name, factory->name(), len) == 0) {
17296
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   499
      if(factory->export_flags() & source) {
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   500
        return factory;
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   501
      } else {
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   502
        return NULL;
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   503
      }
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   504
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   505
    factory = factory->_next;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   506
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   507
  return NULL;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   508
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   509
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   510
int DCmdFactory::register_DCmdFactory(DCmdFactory* factory) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   511
  MutexLockerEx ml(_dcmdFactory_lock, Mutex::_no_safepoint_check_flag);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   512
  factory->_next = _DCmdFactoryList;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   513
  _DCmdFactoryList = factory;
17296
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   514
  if (_send_jmx_notification && !factory->_hidden
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   515
      && (factory->_export_flags & DCmd_Source_MBean)) {
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   516
    DCmdFactory::push_jmx_notification_request();
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   517
  }
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   518
  return 0; // Actually, there's no checks for duplicates
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   519
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   520
17296
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   521
DCmd* DCmdFactory::create_global_DCmd(DCmdSource source, CmdLine &line,
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   522
                                      outputStream* out, TRAPS) {
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   523
  DCmdFactory* f = factory(source, line.cmd_addr(), line.cmd_len());
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   524
  if (f != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   525
    if (f->is_enabled()) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   526
      THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   527
                     f->disabled_message());
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   528
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   529
    return f->create_Cheap_instance(out);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   530
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   531
  THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   532
             "Unknown diagnostic command");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   533
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   534
17296
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   535
DCmd* DCmdFactory::create_local_DCmd(DCmdSource source, CmdLine &line,
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   536
                                     outputStream* out, TRAPS) {
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   537
  DCmdFactory* f = factory(source, line.cmd_addr(), line.cmd_len());
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   538
  if (f != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   539
    if (!f->is_enabled()) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   540
      THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   541
                     f->disabled_message());
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   542
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   543
    return f->create_resource_instance(out);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   544
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   545
  THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   546
             "Unknown diagnostic command");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   547
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   548
17296
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   549
GrowableArray<const char*>* DCmdFactory::DCmd_list(DCmdSource source) {
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   550
  MutexLockerEx ml(_dcmdFactory_lock, Mutex::_no_safepoint_check_flag);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   551
  GrowableArray<const char*>* array = new GrowableArray<const char*>();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   552
  DCmdFactory* factory = _DCmdFactoryList;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   553
  while (factory != NULL) {
17296
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   554
    if (!factory->is_hidden() && (factory->export_flags() & source)) {
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   555
      array->append(factory->name());
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   556
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   557
    factory = factory->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   558
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   559
  return array;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   560
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   561
17296
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   562
GrowableArray<DCmdInfo*>* DCmdFactory::DCmdInfo_list(DCmdSource source ) {
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   563
  MutexLockerEx ml(_dcmdFactory_lock, Mutex::_no_safepoint_check_flag);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   564
  GrowableArray<DCmdInfo*>* array = new GrowableArray<DCmdInfo*>();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   565
  DCmdFactory* factory = _DCmdFactoryList;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   566
  while (factory != NULL) {
17296
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   567
    if (!factory->is_hidden() && (factory->export_flags() & source)) {
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   568
      array->append(new DCmdInfo(factory->name(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   569
                    factory->description(), factory->impact(),
17296
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   570
                    factory->permission(), factory->num_arguments(),
68557efd8583 8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents: 13200
diff changeset
   571
                    factory->is_enabled()));
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   572
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   573
    factory = factory->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   574
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   575
  return array;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   576
}