hotspot/src/share/vm/services/diagnosticFramework.hpp
author coleenp
Fri, 23 Mar 2012 11:16:05 -0400
changeset 12263 d20640f4f8fe
parent 11776 519643dbbefb
child 13195 be27e1b6a4b9
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: 11598
diff changeset
     2
 * Copyright (c) 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
#ifndef SHARE_VM_SERVICES_DIAGNOSTICFRAMEWORK_HPP
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    26
#define SHARE_VM_SERVICES_DIAGNOSTICFRAMEWORK_HPP
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    27
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    28
#include "classfile/vmSymbols.hpp"
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    29
#include "memory/allocation.hpp"
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    30
#include "runtime/arguments.hpp"
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    31
#include "runtime/os.hpp"
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    32
#include "runtime/vm_version.hpp"
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    33
#include "runtime/vmThread.hpp"
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    34
#include "utilities/ostream.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
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    37
// CmdLine is the class used to handle a command line containing a single
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    38
// diagnostic command and its arguments. It provides methods to access the
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    39
// command name and the beginning of the arguments. The class is also
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    40
// able to identify commented command lines and the "stop" keyword
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    41
class CmdLine : public StackObj {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    42
private:
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    43
  const char* _cmd;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    44
  size_t      _cmd_len;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    45
  const char* _args;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    46
  size_t      _args_len;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    47
public:
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    48
  CmdLine(const char* line, size_t len, bool no_command_name);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    49
  const char* args_addr() const { return _args; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    50
  size_t args_len() const { return _args_len; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    51
  const char* cmd_addr() const { return _cmd; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    52
  size_t cmd_len() const { return _cmd_len; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    53
  bool is_empty() { return _cmd_len == 0; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    54
  bool is_executable() { return is_empty() || _cmd[0] != '#'; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    55
  bool is_stop() { return !is_empty() && strncmp("stop", _cmd, _cmd_len) == 0; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    56
};
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    57
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    58
// Iterator class taking a character string in input and returning a CmdLine
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    59
// instance for each command line. The argument delimiter has to be specified.
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    60
class DCmdIter : public StackObj {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    61
  friend class DCmd;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    62
private:
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    63
  const char* _str;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    64
  char        _delim;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    65
  size_t      _len;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    66
  size_t      _cursor;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    67
public:
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    68
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    69
  DCmdIter(const char* str, char delim) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    70
    _str = str;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    71
    _delim = delim;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    72
    _len = strlen(str);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    73
    _cursor = 0;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    74
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    75
  bool has_next() { return _cursor < _len; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    76
  CmdLine next() {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    77
    assert(_cursor <= _len, "Cannot iterate more");
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    78
    size_t n = _cursor;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    79
    while (n < _len && _str[n] != _delim) n++;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    80
    CmdLine line(&(_str[_cursor]), n - _cursor, false);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    81
    _cursor = n + 1;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    82
    // The default copy constructor of CmdLine is used to return a CmdLine
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    83
    // instance to the caller.
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    84
    return line;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    85
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    86
};
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    87
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    88
// Iterator class to iterate over diagnostic command arguments
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    89
class DCmdArgIter : public ResourceObj {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    90
  const char* _buffer;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    91
  size_t      _len;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    92
  size_t      _cursor;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    93
  const char* _key_addr;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    94
  size_t      _key_len;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    95
  const char* _value_addr;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    96
  size_t      _value_len;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    97
  char        _delim;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    98
public:
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    99
  DCmdArgIter(const char* buf, size_t len, char delim) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   100
    _buffer = buf;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   101
    _len = len;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   102
    _delim = delim;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   103
    _cursor = 0;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   104
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   105
  bool next(TRAPS);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   106
  const char* key_addr() { return _key_addr; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   107
  size_t key_length() { return _key_len; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   108
  const char* value_addr() { return _value_addr; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   109
  size_t value_length() { return _value_len; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   110
};
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   111
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   112
// A DCmdInfo instance provides a description of a diagnostic command. It is
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   113
// used to export the description to the JMX interface of the framework.
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   114
class DCmdInfo : public ResourceObj {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   115
protected:
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   116
  const char* _name;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   117
  const char* _description;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   118
  const char* _impact;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   119
  int         _num_arguments;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   120
  bool        _is_enabled;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   121
public:
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   122
  DCmdInfo(const char* name,
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   123
          const char* description,
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   124
          const char* impact,
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   125
          int num_arguments,
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   126
          bool enabled) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   127
    this->_name = name;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   128
    this->_description = description;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   129
    this->_impact = impact;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   130
    this->_num_arguments = num_arguments;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   131
    this->_is_enabled = enabled;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   132
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   133
  const char* name() const { return _name; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   134
  const char* description() const { return _description; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   135
  const char* impact() const { return _impact; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   136
  int num_arguments() const { return _num_arguments; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   137
  bool is_enabled() const { return _is_enabled; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   138
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   139
  static bool by_name(void* name, DCmdInfo* info);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   140
};
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   141
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   142
// A DCmdArgumentInfo instance provides a description of a diagnostic command
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   143
// argument. It is used to export the description to the JMX interface of the
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   144
// framework.
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   145
class DCmdArgumentInfo : public ResourceObj {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   146
protected:
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   147
  const char* _name;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   148
  const char* _description;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   149
  const char* _type;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   150
  const char* _default_string;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   151
  bool        _mandatory;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   152
  bool        _option;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   153
  int         _position;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   154
public:
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   155
  DCmdArgumentInfo(const char* name, const char* description, const char* type,
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   156
                   const char* default_string, bool mandatory, bool option) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   157
    this->_name = name;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   158
    this->_description = description;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   159
    this->_type = type;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   160
    this->_default_string = default_string;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   161
    this->_option = option;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   162
    this->_mandatory = mandatory;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   163
    this->_option = option;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   164
    this->_position = -1;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   165
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   166
  DCmdArgumentInfo(const char* name, const char* description, const char* type,
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   167
                   const char* default_string, bool mandatory, bool option,
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   168
                   int position) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   169
    this->_name = name;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   170
    this->_description = description;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   171
    this->_type = type;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   172
    this->_default_string = default_string;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   173
    this->_option = option;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   174
    this->_mandatory = mandatory;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   175
    this->_option = option;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   176
    this->_position = position;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   177
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   178
  const char* name() const { return _name; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   179
  const char* description() const { return _description; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   180
  const char* type() const { return _type; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   181
  const char* default_string() const { return _default_string; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   182
  bool is_mandatory() const { return _mandatory; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   183
  bool is_option() const { return _option; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   184
  int position() const { return _position; }
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
// The DCmdParser class can be used to create an argument parser for a
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   188
// diagnostic command. It is not mandatory to use it to parse arguments.
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   189
class DCmdParser {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   190
private:
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   191
  GenDCmdArgument* _options;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   192
  GenDCmdArgument* _arguments_list;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   193
  char             _delim;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   194
public:
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   195
  DCmdParser() {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   196
    _options = NULL;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   197
    _arguments_list = NULL;
11776
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11598
diff changeset
   198
    _delim = ' ';
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   199
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   200
  void add_dcmd_option(GenDCmdArgument* arg);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   201
  void add_dcmd_argument(GenDCmdArgument* arg);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   202
  GenDCmdArgument* lookup_dcmd_option(const char* name, size_t len);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   203
  GenDCmdArgument* arguments_list() { return _arguments_list; };
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   204
  void check(TRAPS);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   205
  void parse(CmdLine* line, char delim, TRAPS);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   206
  void print_help(outputStream* out, const char* cmd_name);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   207
  void reset(TRAPS);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   208
  void cleanup();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   209
  int num_arguments();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   210
  GrowableArray<const char*>* argument_name_array();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   211
  GrowableArray<DCmdArgumentInfo*>* argument_info_array();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   212
};
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   213
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   214
// The DCmd class is the parent class of all diagnostic commands
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   215
// Diagnostic command instances should not be instantiated directly but
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   216
// created using the associated factory. The factory can be retrieved with
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   217
// the DCmdFactory::getFactory() method.
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   218
// A diagnostic command instance can either be allocated in the resource Area
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   219
// or in the C-heap. Allocation in the resource area is recommended when the
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   220
// current thread is the only one which will access the diagnostic command
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   221
// instance. Allocation in the C-heap is required when the diagnostic command
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   222
// is accessed by several threads (for instance to perform asynchronous
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   223
// execution).
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   224
// To ensure a proper cleanup, it's highly recommended to use a DCmdMark for
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   225
// each diagnostic command instance. In case of a C-heap allocated diagnostic
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   226
// command instance, the DCmdMark must be created in the context of the last
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   227
// thread that will access the instance.
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   228
class DCmd : public ResourceObj {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   229
protected:
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   230
  outputStream* _output;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   231
  bool          _is_heap_allocated;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   232
public:
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   233
  DCmd(outputStream* output, bool heap_allocated) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   234
    _output = output;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   235
    _is_heap_allocated = heap_allocated;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   236
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   237
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   238
  static const char* name() { return "No Name";}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   239
  static const char* description() { return "No Help";}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   240
  static const char* disabled_message() { return "Diagnostic command currently disabled"; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   241
  static const char* impact() { return "Low: No impact"; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   242
  static int num_arguments() { return 0; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   243
  outputStream* output() { return _output; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   244
  bool is_heap_allocated()  { return _is_heap_allocated; }
11441
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   245
  virtual void print_help(const char* name) {
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   246
    output()->print_cr("Syntax: %s", name);
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   247
  }
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   248
  virtual void parse(CmdLine* line, char delim, TRAPS) {
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   249
    DCmdArgIter iter(line->args_addr(), line->args_len(), delim);
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   250
    bool has_arg = iter.next(CHECK);
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   251
    if (has_arg) {
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   252
      THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   253
                "Unknown argument in diagnostic command");
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   254
    }
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   255
  }
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   256
  virtual void execute(TRAPS) { }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   257
  virtual void reset(TRAPS) { }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   258
  virtual void cleanup() { }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   259
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   260
  // support for the JMX interface
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   261
  virtual GrowableArray<const char*>* argument_name_array() {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   262
    GrowableArray<const char*>* array = new GrowableArray<const char*>(0);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   263
    return array;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   264
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   265
  virtual GrowableArray<DCmdArgumentInfo*>* argument_info_array() {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   266
    GrowableArray<DCmdArgumentInfo*>* array = new GrowableArray<DCmdArgumentInfo*>(0);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   267
    return array;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   268
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   269
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   270
  // main method to invoke the framework
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   271
  static void parse_and_execute(outputStream* out, const char* cmdline,
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   272
                                char delim, TRAPS);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   273
};
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   274
11441
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   275
class DCmdWithParser : public DCmd {
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   276
protected:
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   277
  DCmdParser _dcmdparser;
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   278
public:
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   279
  DCmdWithParser (outputStream *output, bool heap=false) : DCmd(output, heap) { }
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   280
  static const char* name() { return "No Name";}
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   281
  static const char* description() { return "No Help";}
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   282
  static const char* disabled_message() { return "Diagnostic command currently disabled"; }
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   283
  static const char* impact() { return "Low: No impact"; }
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   284
  static int num_arguments() { return 0; }
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   285
  virtual void parse(CmdLine *line, char delim, TRAPS);
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   286
  virtual void execute(TRAPS) { }
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   287
  virtual void reset(TRAPS);
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   288
  virtual void cleanup();
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   289
  virtual void print_help(const char* name);
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   290
  virtual GrowableArray<const char*>* argument_name_array();
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   291
  virtual GrowableArray<DCmdArgumentInfo*>* argument_info_array();
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   292
};
a89f443814cd 7120511: Add diagnostic commands
fparain
parents: 11209
diff changeset
   293
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   294
class DCmdMark : public StackObj {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   295
  DCmd* _ref;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   296
public:
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   297
  DCmdMark(DCmd* cmd) { _ref = cmd; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   298
  ~DCmdMark() {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   299
    if (_ref != NULL) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   300
      _ref->cleanup();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   301
      if (_ref->is_heap_allocated()) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   302
        delete _ref;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   303
      }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   304
    }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   305
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   306
};
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   307
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   308
// Diagnostic commands are not directly instantiated but created with a factory.
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   309
// Each diagnostic command class has its own factory. The DCmdFactory class also
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   310
// manages the status of the diagnostic command (hidden, enabled). A DCmdFactory
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   311
// has to be registered to make the diagnostic command available (see
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   312
// management.cpp)
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   313
class DCmdFactory: public CHeapObj {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   314
private:
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   315
  static Mutex*       _dcmdFactory_lock;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   316
  // Pointer to the next factory in the singly-linked list of registered
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   317
  // diagnostic commands
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   318
  DCmdFactory*        _next;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   319
  // When disabled, a diagnostic command cannot be executed. Any attempt to
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   320
  // execute it will result in the printing of the disabled message without
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   321
  // instantiating the command.
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   322
  bool                _enabled;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   323
  // When hidden, a diagnostic command doesn't appear in the list of commands
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   324
  // provided by the 'help' command.
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   325
  bool                _hidden;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   326
  int                 _num_arguments;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   327
  static DCmdFactory* _DCmdFactoryList;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   328
public:
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   329
  DCmdFactory(int num_arguments, bool enabled, bool hidden) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   330
    _next = NULL;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   331
    _enabled = enabled;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   332
    _hidden = hidden;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   333
    _num_arguments = num_arguments;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   334
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   335
  bool is_enabled() const { return _enabled; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   336
  void set_enabled(bool b) { _enabled = b; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   337
  bool is_hidden() const { return _hidden; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   338
  void set_hidden(bool b) { _hidden = b; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   339
  int num_arguments() { return _num_arguments; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   340
  DCmdFactory* next() { return _next; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   341
  virtual DCmd* create_Cheap_instance(outputStream* output) = 0;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   342
  virtual DCmd* create_resource_instance(outputStream* output) = 0;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   343
  virtual const char* name() const = 0;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   344
  virtual const char* description() const = 0;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   345
  virtual const char* impact() const = 0;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   346
  virtual const char* disabled_message() const = 0;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   347
  // Register a DCmdFactory to make a diagnostic command available.
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   348
  // Once registered, a diagnostic command must not be unregistered.
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   349
  // To prevent a diagnostic command from being executed, just set the
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   350
  // enabled flag to false.
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   351
  static int register_DCmdFactory(DCmdFactory* factory);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   352
  static DCmdFactory* factory(const char* cmd, size_t len);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   353
  // Returns a C-heap allocated diagnostic command for the given command line
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   354
  static DCmd* create_global_DCmd(CmdLine &line, outputStream* out, TRAPS);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   355
  // Returns a resourceArea allocated diagnostic command for the given command line
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   356
  static DCmd* create_local_DCmd(CmdLine &line, outputStream* out, TRAPS);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   357
  static GrowableArray<const char*>* DCmd_list();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   358
  static GrowableArray<DCmdInfo*>* DCmdInfo_list();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   359
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   360
  friend class HelpDCmd;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   361
};
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   362
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   363
// Template to easily create DCmdFactory instances. See management.cpp
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   364
// where this template is used to create and register factories.
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   365
template <class DCmdClass> class DCmdFactoryImpl : public DCmdFactory {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   366
public:
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   367
  DCmdFactoryImpl(bool enabled, bool hidden) :
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   368
    DCmdFactory(DCmdClass::num_arguments(), enabled, hidden) { }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   369
  // Returns a C-heap allocated instance
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   370
  virtual DCmd* create_Cheap_instance(outputStream* output) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   371
    return new (ResourceObj::C_HEAP) DCmdClass(output, true);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   372
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   373
  // Returns a resourceArea allocated instance
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   374
  virtual DCmd* create_resource_instance(outputStream* output) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   375
    return new DCmdClass(output, false);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   376
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   377
  virtual const char* name() const {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   378
    return DCmdClass::name();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   379
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   380
  virtual const char* description() const {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   381
    return DCmdClass::description();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   382
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   383
  virtual const char* impact() const {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   384
    return DCmdClass::impact();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   385
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   386
  virtual const char* disabled_message() const {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   387
     return DCmdClass::disabled_message();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   388
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   389
};
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   390
11598
db8931f2a56d 7132515: Add dcmd to manage UnlockingCommercialFeature flag
dsamersoff
parents: 11441
diff changeset
   391
// This class provides a convenient way to register Dcmds, without a need to change
db8931f2a56d 7132515: Add dcmd to manage UnlockingCommercialFeature flag
dsamersoff
parents: 11441
diff changeset
   392
// management.cpp every time. Body of these two methods resides in
db8931f2a56d 7132515: Add dcmd to manage UnlockingCommercialFeature flag
dsamersoff
parents: 11441
diff changeset
   393
// diagnosticCommand.cpp
db8931f2a56d 7132515: Add dcmd to manage UnlockingCommercialFeature flag
dsamersoff
parents: 11441
diff changeset
   394
db8931f2a56d 7132515: Add dcmd to manage UnlockingCommercialFeature flag
dsamersoff
parents: 11441
diff changeset
   395
class DCmdRegistrant : public AllStatic {
db8931f2a56d 7132515: Add dcmd to manage UnlockingCommercialFeature flag
dsamersoff
parents: 11441
diff changeset
   396
db8931f2a56d 7132515: Add dcmd to manage UnlockingCommercialFeature flag
dsamersoff
parents: 11441
diff changeset
   397
private:
db8931f2a56d 7132515: Add dcmd to manage UnlockingCommercialFeature flag
dsamersoff
parents: 11441
diff changeset
   398
    static void register_dcmds();
db8931f2a56d 7132515: Add dcmd to manage UnlockingCommercialFeature flag
dsamersoff
parents: 11441
diff changeset
   399
    static void register_dcmds_ext();
db8931f2a56d 7132515: Add dcmd to manage UnlockingCommercialFeature flag
dsamersoff
parents: 11441
diff changeset
   400
db8931f2a56d 7132515: Add dcmd to manage UnlockingCommercialFeature flag
dsamersoff
parents: 11441
diff changeset
   401
    friend class Management;
db8931f2a56d 7132515: Add dcmd to manage UnlockingCommercialFeature flag
dsamersoff
parents: 11441
diff changeset
   402
};
db8931f2a56d 7132515: Add dcmd to manage UnlockingCommercialFeature flag
dsamersoff
parents: 11441
diff changeset
   403
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   404
#endif // SHARE_VM_SERVICES_DIAGNOSTICFRAMEWORK_HPP