hotspot/src/share/vm/services/diagnosticFramework.cpp
author coleenp
Fri, 23 Mar 2012 11:16:05 -0400
changeset 12263 d20640f4f8fe
parent 11776 519643dbbefb
child 13200 7b506e7b406e
permissions -rw-r--r--
7150058: Allocate symbols from null boot loader to an arena for NMT Summary: Move symbol allocation to an arena so NMT doesn't have to track them at startup. Reviewed-by: never, kamg, zgu
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
     1
/*
11776
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11441
diff changeset
     2
 * Copyright (c) 2011, 2012, 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"
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    27
#include "runtime/javaCalls.hpp"
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    28
#include "runtime/mutexLocker.hpp"
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    29
#include "services/diagnosticArgument.hpp"
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    30
#include "services/diagnosticFramework.hpp"
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    31
#include "services/management.hpp"
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    32
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    33
CmdLine::CmdLine(const char* line, size_t len, bool no_command_name) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    34
  assert(line != NULL, "Command line string should not be NULL");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    35
  const char* line_end;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    36
  const char* cmd_end;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    37
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    38
  _cmd = line;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    39
  line_end = &line[len];
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    40
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    41
  // Skip whitespace in the beginning of the line.
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    42
  while (_cmd < line_end && isspace((int) _cmd[0])) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    43
    _cmd++;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    44
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    45
  cmd_end = _cmd;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    46
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    47
  if (no_command_name) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    48
    _cmd = NULL;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    49
    _cmd_len = 0;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    50
  } else {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    51
    // Look for end of the command name
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    52
    while (cmd_end < line_end && !isspace((int) cmd_end[0])) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    53
      cmd_end++;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    54
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    55
    _cmd_len = cmd_end - _cmd;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    56
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    57
  _args = cmd_end;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    58
  _args_len = line_end - _args;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    59
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    60
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    61
bool DCmdArgIter::next(TRAPS) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    62
  if (_len == 0) return false;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    63
  // skipping spaces
11776
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11441
diff changeset
    64
  while (_cursor < _len - 1 && _buffer[_cursor] == _delim) {
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    65
    _cursor++;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    66
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    67
  // handling end of command line
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    68
  if (_cursor >= _len - 1) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    69
    _cursor = _len - 1;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    70
    _key_addr = &_buffer[_len - 1];
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    71
    _key_len = 0;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    72
    _value_addr = &_buffer[_len - 1];
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    73
    _value_len = 0;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    74
    return false;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    75
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    76
  // extracting first item, argument or option name
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    77
  _key_addr = &_buffer[_cursor];
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    78
  while (_cursor <= _len - 1 && _buffer[_cursor] != '=' && _buffer[_cursor] != _delim) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    79
    // argument can be surrounded by single or double quotes
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    80
    if (_buffer[_cursor] == '\"' || _buffer[_cursor] == '\'') {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    81
      _key_addr++;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    82
      char quote = _buffer[_cursor];
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    83
      while (_cursor < _len - 1) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    84
        _cursor++;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    85
        if (_buffer[_cursor] == quote && _buffer[_cursor - 1] != '\\') {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    86
          break;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    87
        }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    88
      }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    89
      if (_buffer[_cursor] != quote) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    90
        THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    91
                "Format error in diagnostic command arguments", false);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    92
      }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    93
      break;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    94
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    95
    _cursor++;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    96
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    97
  _key_len = &_buffer[_cursor] - _key_addr;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    98
  // check if the argument has the <key>=<value> format
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    99
  if (_cursor <= _len -1 && _buffer[_cursor] == '=') {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   100
    _cursor++;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   101
    _value_addr = &_buffer[_cursor];
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   102
    // extract the value
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   103
    while (_cursor <= _len - 1 && _buffer[_cursor] != _delim) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   104
      // value can be surrounded by simple or double quotes
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   105
      if (_buffer[_cursor] == '\"' || _buffer[_cursor] == '\'') {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   106
        _value_addr++;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   107
        char quote = _buffer[_cursor];
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   108
        while (_cursor < _len - 1) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   109
          _cursor++;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   110
          if (_buffer[_cursor] == quote && _buffer[_cursor - 1] != '\\') {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   111
            break;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   112
          }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   113
        }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   114
        if (_buffer[_cursor] != quote) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   115
          THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   116
                  "Format error in diagnostic command arguments", false);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   117
        }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   118
        break;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   119
      }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   120
      _cursor++;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   121
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   122
    _value_len = &_buffer[_cursor] - _value_addr;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   123
  } else {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   124
    _value_addr = NULL;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   125
    _value_len = 0;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   126
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   127
  return _key_len != 0;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   128
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   129
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   130
bool DCmdInfo::by_name(void* cmd_name, DCmdInfo* info) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   131
  if (info == NULL) return false;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   132
  return strcmp((const char*)cmd_name, info->name()) == 0;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   133
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   134
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   135
void DCmdParser::add_dcmd_option(GenDCmdArgument* arg) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   136
  assert(arg != NULL, "Sanity");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   137
  if (_options == NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   138
    _options = arg;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   139
  } else {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   140
    GenDCmdArgument* o = _options;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   141
    while (o->next() != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   142
      o = o->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   143
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   144
    o->set_next(arg);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   145
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   146
  arg->set_next(NULL);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   147
  Thread* THREAD = Thread::current();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   148
  arg->init_value(THREAD);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   149
  if (HAS_PENDING_EXCEPTION) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   150
    fatal("Initialization must be successful");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   151
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   152
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   153
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   154
void DCmdParser::add_dcmd_argument(GenDCmdArgument* arg) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   155
  assert(arg != NULL, "Sanity");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   156
  if (_arguments_list == NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   157
    _arguments_list = arg;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   158
  } else {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   159
    GenDCmdArgument* a = _arguments_list;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   160
    while (a->next() != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   161
      a = a->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   162
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   163
    a->set_next(arg);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   164
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   165
  arg->set_next(NULL);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   166
  Thread* THREAD = Thread::current();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   167
  arg->init_value(THREAD);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   168
  if (HAS_PENDING_EXCEPTION) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   169
    fatal("Initialization must be successful");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   170
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   171
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   172
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   173
void DCmdParser::parse(CmdLine* line, char delim, TRAPS) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   174
  GenDCmdArgument* next_argument = _arguments_list;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   175
  DCmdArgIter iter(line->args_addr(), line->args_len(), delim);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   176
  bool cont = iter.next(CHECK);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   177
  while (cont) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   178
    GenDCmdArgument* arg = lookup_dcmd_option(iter.key_addr(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   179
            iter.key_length());
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   180
    if (arg != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   181
      arg->read_value(iter.value_addr(), iter.value_length(), CHECK);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   182
    } else {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   183
      if (next_argument != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   184
        arg = next_argument;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   185
        arg->read_value(iter.key_addr(), iter.key_length(), CHECK);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   186
        next_argument = next_argument->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   187
      } else {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   188
        THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   189
          "Unknown argument in diagnostic command");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   190
      }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   191
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   192
    cont = iter.next(CHECK);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   193
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   194
  check(CHECK);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   195
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   196
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   197
GenDCmdArgument* DCmdParser::lookup_dcmd_option(const char* name, size_t len) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   198
  GenDCmdArgument* arg = _options;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   199
  while (arg != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   200
    if (strlen(arg->name()) == len &&
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   201
      strncmp(name, arg->name(), len) == 0) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   202
      return arg;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   203
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   204
    arg = arg->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   205
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   206
  return NULL;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   207
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   208
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   209
void DCmdParser::check(TRAPS) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   210
  GenDCmdArgument* arg = _arguments_list;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   211
  while (arg != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   212
    if (arg->is_mandatory() && !arg->has_value()) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   213
      THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   214
              "Missing argument for diagnostic command");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   215
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   216
    arg = arg->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   217
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   218
  arg = _options;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   219
  while (arg != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   220
    if (arg->is_mandatory() && !arg->has_value()) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   221
      THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   222
              "Missing option for diagnostic command");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   223
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   224
    arg = arg->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   225
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   226
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   227
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   228
void DCmdParser::print_help(outputStream* out, const char* cmd_name) {
11441
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   229
  out->print("Syntax : %s %s", cmd_name, _options == NULL ? "" : "[options]");
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   230
  GenDCmdArgument* arg = _arguments_list;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   231
  while (arg != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   232
    if (arg->is_mandatory()) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   233
      out->print(" <%s>", arg->name());
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   234
    } else {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   235
      out->print(" [<%s>]", arg->name());
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   236
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   237
    arg = arg->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   238
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   239
  out->print_cr("");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   240
  if (_arguments_list != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   241
    out->print_cr("\nArguments:");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   242
    arg = _arguments_list;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   243
    while (arg != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   244
      out->print("\t%s : %s %s (%s, ", arg->name(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   245
                 arg->is_mandatory() ? "" : "[optional]",
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   246
                 arg->description(), arg->type());
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   247
      if (arg->has_default()) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   248
        out->print(arg->default_string());
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   249
      } else {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   250
        out->print("no default value");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   251
      }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   252
      out->print_cr(")");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   253
      arg = arg->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   254
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   255
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   256
  if (_options != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   257
    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
   258
    arg = _options;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   259
    while (arg != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   260
      out->print("\t%s : %s %s (%s, ", arg->name(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   261
                 arg->is_mandatory() ? "" : "[optional]",
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   262
                 arg->description(), arg->type());
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   263
      if (arg->has_default()) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   264
        out->print(arg->default_string());
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   265
      } else {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   266
        out->print("no default value");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   267
      }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   268
      out->print_cr(")");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   269
      arg = arg->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   270
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   271
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   272
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   273
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   274
void DCmdParser::reset(TRAPS) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   275
  GenDCmdArgument* arg = _arguments_list;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   276
  while (arg != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   277
    arg->reset(CHECK);
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
  arg = _options;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   281
  while (arg != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   282
    arg->reset(CHECK);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   283
    arg = arg->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   284
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   285
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   286
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   287
void DCmdParser::cleanup() {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   288
  GenDCmdArgument* arg = _arguments_list;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   289
  while (arg != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   290
    arg->cleanup();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   291
    arg = arg->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   292
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   293
  arg = _options;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   294
  while (arg != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   295
    arg->cleanup();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   296
    arg = arg->next();
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
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   300
int DCmdParser::num_arguments() {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   301
  GenDCmdArgument* arg = _arguments_list;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   302
  int count = 0;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   303
  while (arg != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   304
    count++;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   305
    arg = arg->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   306
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   307
  arg = _options;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   308
  while (arg != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   309
    count++;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   310
    arg = arg->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   311
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   312
  return count;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   313
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   314
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   315
GrowableArray<const char *>* DCmdParser::argument_name_array() {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   316
  int count = num_arguments();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   317
  GrowableArray<const char *>* array = new GrowableArray<const char *>(count);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   318
  GenDCmdArgument* arg = _arguments_list;
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
    array->append(arg->name());
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
  arg = _options;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   324
  while (arg != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   325
    array->append(arg->name());
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   326
    arg = arg->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   327
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   328
  return array;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   329
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   330
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   331
GrowableArray<DCmdArgumentInfo*>* DCmdParser::argument_info_array() {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   332
  int count = num_arguments();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   333
  GrowableArray<DCmdArgumentInfo*>* array = new GrowableArray<DCmdArgumentInfo *>(count);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   334
  int idx = 0;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   335
  GenDCmdArgument* arg = _arguments_list;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   336
  while (arg != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   337
    array->append(new DCmdArgumentInfo(arg->name(), arg->description(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   338
                  arg->type(), arg->default_string(), arg->is_mandatory(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   339
                  false, idx));
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   340
    idx++;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   341
    arg = arg->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   342
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   343
  arg = _options;
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(new DCmdArgumentInfo(arg->name(), arg->description(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   346
                  arg->type(), arg->default_string(), arg->is_mandatory(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   347
                  true));
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   348
    arg = arg->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   349
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   350
  return array;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   351
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   352
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   353
DCmdFactory* DCmdFactory::_DCmdFactoryList = NULL;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   354
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   355
void DCmd::parse_and_execute(outputStream* out, const char* cmdline,
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   356
                             char delim, TRAPS) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   357
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   358
  if (cmdline == NULL) return; // Nothing to do!
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   359
  DCmdIter iter(cmdline, '\n');
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   360
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   361
  while (iter.has_next()) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   362
    CmdLine line = iter.next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   363
    if (line.is_stop()) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   364
      break;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   365
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   366
    if (line.is_executable()) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   367
      DCmd* command = DCmdFactory::create_local_DCmd(line, out, CHECK);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   368
      assert(command != NULL, "command error must be handled before this line");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   369
      DCmdMark mark(command);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   370
      command->parse(&line, delim, CHECK);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   371
      command->execute(CHECK);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   372
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   373
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   374
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   375
11441
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   376
void DCmdWithParser::parse(CmdLine* line, char delim, TRAPS) {
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   377
  _dcmdparser.parse(line, delim, CHECK);
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   378
}
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   379
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   380
void DCmdWithParser::print_help(const char* name) {
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   381
  _dcmdparser.print_help(output(), name);
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   382
}
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   383
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   384
void DCmdWithParser::reset(TRAPS) {
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   385
  _dcmdparser.reset(CHECK);
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   386
}
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   387
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   388
void DCmdWithParser::cleanup() {
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   389
  _dcmdparser.cleanup();
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   390
}
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   391
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   392
GrowableArray<const char*>* DCmdWithParser::argument_name_array() {
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   393
  return _dcmdparser.argument_name_array();
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   394
}
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   395
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   396
GrowableArray<DCmdArgumentInfo*>* DCmdWithParser::argument_info_array() {
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   397
  return _dcmdparser.argument_info_array();
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   398
}
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   399
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   400
Mutex* DCmdFactory::_dcmdFactory_lock = new Mutex(Mutex::leaf, "DCmdFactory", true);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   401
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   402
DCmdFactory* DCmdFactory::factory(const char* name, size_t len) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   403
  MutexLockerEx ml(_dcmdFactory_lock, Mutex::_no_safepoint_check_flag);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   404
  DCmdFactory* factory = _DCmdFactoryList;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   405
  while (factory != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   406
    if (strlen(factory->name()) == len &&
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   407
        strncmp(name, factory->name(), len) == 0) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   408
      return factory;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   409
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   410
    factory = factory->_next;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   411
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   412
  return NULL;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   413
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   414
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   415
int DCmdFactory::register_DCmdFactory(DCmdFactory* factory) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   416
  MutexLockerEx ml(_dcmdFactory_lock, Mutex::_no_safepoint_check_flag);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   417
  factory->_next = _DCmdFactoryList;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   418
  _DCmdFactoryList = factory;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   419
  return 0; // Actually, there's no checks for duplicates
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   420
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   421
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   422
DCmd* DCmdFactory::create_global_DCmd(CmdLine &line, outputStream* out, TRAPS) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   423
  DCmdFactory* f = factory(line.cmd_addr(), line.cmd_len());
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   424
  if (f != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   425
    if (f->is_enabled()) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   426
      THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   427
                     f->disabled_message());
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   428
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   429
    return f->create_Cheap_instance(out);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   430
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   431
  THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   432
             "Unknown diagnostic command");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   433
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   434
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   435
DCmd* DCmdFactory::create_local_DCmd(CmdLine &line, outputStream* out, TRAPS) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   436
  DCmdFactory* f = factory(line.cmd_addr(), line.cmd_len());
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   437
  if (f != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   438
    if (!f->is_enabled()) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   439
      THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   440
                     f->disabled_message());
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   441
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   442
    return f->create_resource_instance(out);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   443
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   444
  THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   445
             "Unknown diagnostic command");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   446
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   447
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   448
GrowableArray<const char*>* DCmdFactory::DCmd_list() {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   449
  MutexLockerEx ml(_dcmdFactory_lock, Mutex::_no_safepoint_check_flag);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   450
  GrowableArray<const char*>* array = new GrowableArray<const char*>();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   451
  DCmdFactory* factory = _DCmdFactoryList;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   452
  while (factory != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   453
    if (!factory->is_hidden()) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   454
      array->append(factory->name());
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   455
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   456
    factory = factory->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   457
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   458
  return array;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   459
}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   460
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   461
GrowableArray<DCmdInfo*>* DCmdFactory::DCmdInfo_list() {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   462
  MutexLockerEx ml(_dcmdFactory_lock, Mutex::_no_safepoint_check_flag);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   463
  GrowableArray<DCmdInfo*>* array = new GrowableArray<DCmdInfo*>();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   464
  DCmdFactory* factory = _DCmdFactoryList;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   465
  while (factory != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   466
    if (!factory->is_hidden()) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   467
      array->append(new DCmdInfo(factory->name(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   468
                    factory->description(), factory->impact(),
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   469
                    factory->num_arguments(), factory->is_enabled()));
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   470
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   471
    factory = factory->next();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   472
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   473
  return array;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   474
}