Tue, 09 Oct 2012 10:09:34 -0700
7197424: update copyright year to match last edit in jdk8 hotspot repository
Summary: Update copyright year to 2012 for relevant files
Reviewed-by: dholmes, coleenp
fparain@3329 | 1 | /* |
fparain@3559 | 2 | * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
fparain@3329 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
fparain@3329 | 4 | * |
fparain@3329 | 5 | * This code is free software; you can redistribute it and/or modify it |
fparain@3329 | 6 | * under the terms of the GNU General Public License version 2 only, as |
fparain@3329 | 7 | * published by the Free Software Foundation. |
fparain@3329 | 8 | * |
fparain@3329 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
fparain@3329 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
fparain@3329 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
fparain@3329 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
fparain@3329 | 13 | * accompanied this code). |
fparain@3329 | 14 | * |
fparain@3329 | 15 | * You should have received a copy of the GNU General Public License version |
fparain@3329 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
fparain@3329 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
fparain@3329 | 18 | * |
fparain@3329 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
fparain@3329 | 20 | * or visit www.oracle.com if you need additional information or have any |
fparain@3329 | 21 | * questions. |
fparain@3329 | 22 | * |
fparain@3329 | 23 | */ |
fparain@3329 | 24 | |
fparain@3329 | 25 | #ifndef SHARE_VM_SERVICES_DIAGNOSTICFRAMEWORK_HPP |
fparain@3329 | 26 | #define SHARE_VM_SERVICES_DIAGNOSTICFRAMEWORK_HPP |
fparain@3329 | 27 | |
fparain@3329 | 28 | #include "classfile/vmSymbols.hpp" |
fparain@3329 | 29 | #include "memory/allocation.hpp" |
fparain@3329 | 30 | #include "runtime/arguments.hpp" |
fparain@3329 | 31 | #include "runtime/os.hpp" |
fparain@3329 | 32 | #include "runtime/vm_version.hpp" |
fparain@3329 | 33 | #include "runtime/vmThread.hpp" |
fparain@3329 | 34 | #include "utilities/ostream.hpp" |
fparain@3329 | 35 | |
fparain@3329 | 36 | |
fparain@3329 | 37 | // CmdLine is the class used to handle a command line containing a single |
fparain@3329 | 38 | // diagnostic command and its arguments. It provides methods to access the |
fparain@3329 | 39 | // command name and the beginning of the arguments. The class is also |
fparain@3329 | 40 | // able to identify commented command lines and the "stop" keyword |
fparain@3329 | 41 | class CmdLine : public StackObj { |
fparain@3329 | 42 | private: |
fparain@3329 | 43 | const char* _cmd; |
fparain@3329 | 44 | size_t _cmd_len; |
fparain@3329 | 45 | const char* _args; |
fparain@3329 | 46 | size_t _args_len; |
fparain@3329 | 47 | public: |
fparain@3329 | 48 | CmdLine(const char* line, size_t len, bool no_command_name); |
fparain@3329 | 49 | const char* args_addr() const { return _args; } |
fparain@3329 | 50 | size_t args_len() const { return _args_len; } |
fparain@3329 | 51 | const char* cmd_addr() const { return _cmd; } |
fparain@3329 | 52 | size_t cmd_len() const { return _cmd_len; } |
fparain@3329 | 53 | bool is_empty() { return _cmd_len == 0; } |
fparain@3329 | 54 | bool is_executable() { return is_empty() || _cmd[0] != '#'; } |
fparain@3329 | 55 | bool is_stop() { return !is_empty() && strncmp("stop", _cmd, _cmd_len) == 0; } |
fparain@3329 | 56 | }; |
fparain@3329 | 57 | |
fparain@3329 | 58 | // Iterator class taking a character string in input and returning a CmdLine |
fparain@3329 | 59 | // instance for each command line. The argument delimiter has to be specified. |
fparain@3329 | 60 | class DCmdIter : public StackObj { |
fparain@3329 | 61 | friend class DCmd; |
fparain@3329 | 62 | private: |
fparain@3329 | 63 | const char* _str; |
fparain@3329 | 64 | char _delim; |
fparain@3329 | 65 | size_t _len; |
fparain@3329 | 66 | size_t _cursor; |
fparain@3329 | 67 | public: |
fparain@3329 | 68 | |
fparain@3329 | 69 | DCmdIter(const char* str, char delim) { |
fparain@3329 | 70 | _str = str; |
fparain@3329 | 71 | _delim = delim; |
fparain@3329 | 72 | _len = strlen(str); |
fparain@3329 | 73 | _cursor = 0; |
fparain@3329 | 74 | } |
fparain@3329 | 75 | bool has_next() { return _cursor < _len; } |
fparain@3329 | 76 | CmdLine next() { |
fparain@3329 | 77 | assert(_cursor <= _len, "Cannot iterate more"); |
fparain@3329 | 78 | size_t n = _cursor; |
fparain@3329 | 79 | while (n < _len && _str[n] != _delim) n++; |
fparain@3329 | 80 | CmdLine line(&(_str[_cursor]), n - _cursor, false); |
fparain@3329 | 81 | _cursor = n + 1; |
fparain@3329 | 82 | // The default copy constructor of CmdLine is used to return a CmdLine |
fparain@3329 | 83 | // instance to the caller. |
fparain@3329 | 84 | return line; |
fparain@3329 | 85 | } |
fparain@3329 | 86 | }; |
fparain@3329 | 87 | |
fparain@3329 | 88 | // Iterator class to iterate over diagnostic command arguments |
fparain@3329 | 89 | class DCmdArgIter : public ResourceObj { |
fparain@3329 | 90 | const char* _buffer; |
fparain@3329 | 91 | size_t _len; |
fparain@3329 | 92 | size_t _cursor; |
fparain@3329 | 93 | const char* _key_addr; |
fparain@3329 | 94 | size_t _key_len; |
fparain@3329 | 95 | const char* _value_addr; |
fparain@3329 | 96 | size_t _value_len; |
fparain@3329 | 97 | char _delim; |
fparain@3329 | 98 | public: |
fparain@3329 | 99 | DCmdArgIter(const char* buf, size_t len, char delim) { |
fparain@3329 | 100 | _buffer = buf; |
fparain@3329 | 101 | _len = len; |
fparain@3329 | 102 | _delim = delim; |
fparain@3329 | 103 | _cursor = 0; |
fparain@3329 | 104 | } |
fparain@3329 | 105 | bool next(TRAPS); |
fparain@3329 | 106 | const char* key_addr() { return _key_addr; } |
fparain@3329 | 107 | size_t key_length() { return _key_len; } |
fparain@3329 | 108 | const char* value_addr() { return _value_addr; } |
fparain@3329 | 109 | size_t value_length() { return _value_len; } |
fparain@3329 | 110 | }; |
fparain@3329 | 111 | |
fparain@3329 | 112 | // A DCmdInfo instance provides a description of a diagnostic command. It is |
fparain@3329 | 113 | // used to export the description to the JMX interface of the framework. |
fparain@3329 | 114 | class DCmdInfo : public ResourceObj { |
fparain@3329 | 115 | protected: |
fparain@3329 | 116 | const char* _name; |
fparain@3329 | 117 | const char* _description; |
fparain@3329 | 118 | const char* _impact; |
fparain@3329 | 119 | int _num_arguments; |
fparain@3329 | 120 | bool _is_enabled; |
fparain@3329 | 121 | public: |
fparain@3329 | 122 | DCmdInfo(const char* name, |
fparain@3329 | 123 | const char* description, |
fparain@3329 | 124 | const char* impact, |
fparain@3329 | 125 | int num_arguments, |
fparain@3329 | 126 | bool enabled) { |
fparain@3329 | 127 | this->_name = name; |
fparain@3329 | 128 | this->_description = description; |
fparain@3329 | 129 | this->_impact = impact; |
fparain@3329 | 130 | this->_num_arguments = num_arguments; |
fparain@3329 | 131 | this->_is_enabled = enabled; |
fparain@3329 | 132 | } |
fparain@3329 | 133 | const char* name() const { return _name; } |
fparain@3329 | 134 | const char* description() const { return _description; } |
fparain@3329 | 135 | const char* impact() const { return _impact; } |
fparain@3329 | 136 | int num_arguments() const { return _num_arguments; } |
fparain@3329 | 137 | bool is_enabled() const { return _is_enabled; } |
fparain@3329 | 138 | |
fparain@3329 | 139 | static bool by_name(void* name, DCmdInfo* info); |
fparain@3329 | 140 | }; |
fparain@3329 | 141 | |
fparain@3329 | 142 | // A DCmdArgumentInfo instance provides a description of a diagnostic command |
fparain@3329 | 143 | // argument. It is used to export the description to the JMX interface of the |
fparain@3329 | 144 | // framework. |
fparain@3329 | 145 | class DCmdArgumentInfo : public ResourceObj { |
fparain@3329 | 146 | protected: |
fparain@3329 | 147 | const char* _name; |
fparain@3329 | 148 | const char* _description; |
fparain@3329 | 149 | const char* _type; |
fparain@3329 | 150 | const char* _default_string; |
fparain@3329 | 151 | bool _mandatory; |
fparain@3329 | 152 | bool _option; |
fparain@3329 | 153 | int _position; |
fparain@3329 | 154 | public: |
fparain@3329 | 155 | DCmdArgumentInfo(const char* name, const char* description, const char* type, |
fparain@3329 | 156 | const char* default_string, bool mandatory, bool option) { |
fparain@3329 | 157 | this->_name = name; |
fparain@3329 | 158 | this->_description = description; |
fparain@3329 | 159 | this->_type = type; |
fparain@3329 | 160 | this->_default_string = default_string; |
fparain@3329 | 161 | this->_option = option; |
fparain@3329 | 162 | this->_mandatory = mandatory; |
fparain@3329 | 163 | this->_option = option; |
fparain@3329 | 164 | this->_position = -1; |
fparain@3329 | 165 | } |
fparain@3329 | 166 | DCmdArgumentInfo(const char* name, const char* description, const char* type, |
fparain@3329 | 167 | const char* default_string, bool mandatory, bool option, |
fparain@3329 | 168 | int position) { |
fparain@3329 | 169 | this->_name = name; |
fparain@3329 | 170 | this->_description = description; |
fparain@3329 | 171 | this->_type = type; |
fparain@3329 | 172 | this->_default_string = default_string; |
fparain@3329 | 173 | this->_option = option; |
fparain@3329 | 174 | this->_mandatory = mandatory; |
fparain@3329 | 175 | this->_option = option; |
fparain@3329 | 176 | this->_position = position; |
fparain@3329 | 177 | } |
fparain@3329 | 178 | const char* name() const { return _name; } |
fparain@3329 | 179 | const char* description() const { return _description; } |
fparain@3329 | 180 | const char* type() const { return _type; } |
fparain@3329 | 181 | const char* default_string() const { return _default_string; } |
fparain@3329 | 182 | bool is_mandatory() const { return _mandatory; } |
fparain@3329 | 183 | bool is_option() const { return _option; } |
fparain@3329 | 184 | int position() const { return _position; } |
fparain@3329 | 185 | }; |
fparain@3329 | 186 | |
fparain@3329 | 187 | // The DCmdParser class can be used to create an argument parser for a |
fparain@3329 | 188 | // diagnostic command. It is not mandatory to use it to parse arguments. |
fparain@3329 | 189 | class DCmdParser { |
fparain@3329 | 190 | private: |
fparain@3329 | 191 | GenDCmdArgument* _options; |
fparain@3329 | 192 | GenDCmdArgument* _arguments_list; |
fparain@3329 | 193 | char _delim; |
fparain@3329 | 194 | public: |
fparain@3329 | 195 | DCmdParser() { |
fparain@3329 | 196 | _options = NULL; |
fparain@3329 | 197 | _arguments_list = NULL; |
fparain@3559 | 198 | _delim = ' '; |
fparain@3329 | 199 | } |
fparain@3329 | 200 | void add_dcmd_option(GenDCmdArgument* arg); |
fparain@3329 | 201 | void add_dcmd_argument(GenDCmdArgument* arg); |
fparain@3329 | 202 | GenDCmdArgument* lookup_dcmd_option(const char* name, size_t len); |
fparain@3329 | 203 | GenDCmdArgument* arguments_list() { return _arguments_list; }; |
fparain@3329 | 204 | void check(TRAPS); |
fparain@3329 | 205 | void parse(CmdLine* line, char delim, TRAPS); |
fparain@3329 | 206 | void print_help(outputStream* out, const char* cmd_name); |
fparain@3329 | 207 | void reset(TRAPS); |
fparain@3329 | 208 | void cleanup(); |
fparain@3329 | 209 | int num_arguments(); |
fparain@3329 | 210 | GrowableArray<const char*>* argument_name_array(); |
fparain@3329 | 211 | GrowableArray<DCmdArgumentInfo*>* argument_info_array(); |
fparain@3329 | 212 | }; |
fparain@3329 | 213 | |
fparain@3329 | 214 | // The DCmd class is the parent class of all diagnostic commands |
fparain@3329 | 215 | // Diagnostic command instances should not be instantiated directly but |
fparain@3329 | 216 | // created using the associated factory. The factory can be retrieved with |
fparain@3329 | 217 | // the DCmdFactory::getFactory() method. |
fparain@3329 | 218 | // A diagnostic command instance can either be allocated in the resource Area |
fparain@3329 | 219 | // or in the C-heap. Allocation in the resource area is recommended when the |
fparain@3329 | 220 | // current thread is the only one which will access the diagnostic command |
fparain@3329 | 221 | // instance. Allocation in the C-heap is required when the diagnostic command |
fparain@3329 | 222 | // is accessed by several threads (for instance to perform asynchronous |
fparain@3329 | 223 | // execution). |
fparain@3329 | 224 | // To ensure a proper cleanup, it's highly recommended to use a DCmdMark for |
fparain@3329 | 225 | // each diagnostic command instance. In case of a C-heap allocated diagnostic |
fparain@3329 | 226 | // command instance, the DCmdMark must be created in the context of the last |
fparain@3329 | 227 | // thread that will access the instance. |
fparain@3329 | 228 | class DCmd : public ResourceObj { |
fparain@3329 | 229 | protected: |
fparain@3329 | 230 | outputStream* _output; |
fparain@3329 | 231 | bool _is_heap_allocated; |
fparain@3329 | 232 | public: |
fparain@3329 | 233 | DCmd(outputStream* output, bool heap_allocated) { |
fparain@3329 | 234 | _output = output; |
fparain@3329 | 235 | _is_heap_allocated = heap_allocated; |
fparain@3329 | 236 | } |
fparain@3329 | 237 | |
fparain@3329 | 238 | static const char* name() { return "No Name";} |
fparain@3329 | 239 | static const char* description() { return "No Help";} |
fparain@3329 | 240 | static const char* disabled_message() { return "Diagnostic command currently disabled"; } |
sla@3905 | 241 | // The impact() method returns a description of the intrusiveness of the diagnostic |
sla@3905 | 242 | // command on the Java Virtual Machine behavior. The rational for this method is that some |
sla@3905 | 243 | // diagnostic commands can seriously disrupt the behavior of the Java Virtual Machine |
sla@3905 | 244 | // (for instance a Thread Dump for an application with several tens of thousands of threads, |
sla@3905 | 245 | // or a Head Dump with a 40GB+ heap size) and other diagnostic commands have no serious |
sla@3905 | 246 | // impact on the JVM (for instance, getting the command line arguments or the JVM version). |
sla@3905 | 247 | // The recommended format for the description is <impact level>: [longer description], |
sla@3905 | 248 | // where the impact level is selected among this list: {Low, Medium, High}. The optional |
sla@3905 | 249 | // longer description can provide more specific details like the fact that Thread Dump |
sla@3905 | 250 | // impact depends on the heap size. |
fparain@3329 | 251 | static const char* impact() { return "Low: No impact"; } |
fparain@3329 | 252 | static int num_arguments() { return 0; } |
fparain@3329 | 253 | outputStream* output() { return _output; } |
fparain@3329 | 254 | bool is_heap_allocated() { return _is_heap_allocated; } |
fparain@3402 | 255 | virtual void print_help(const char* name) { |
fparain@3402 | 256 | output()->print_cr("Syntax: %s", name); |
fparain@3402 | 257 | } |
fparain@3402 | 258 | virtual void parse(CmdLine* line, char delim, TRAPS) { |
fparain@3402 | 259 | DCmdArgIter iter(line->args_addr(), line->args_len(), delim); |
fparain@3402 | 260 | bool has_arg = iter.next(CHECK); |
fparain@3402 | 261 | if (has_arg) { |
fparain@3402 | 262 | THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
sla@3905 | 263 | "The argument list of this diagnostic command should be empty."); |
fparain@3402 | 264 | } |
fparain@3402 | 265 | } |
fparain@3329 | 266 | virtual void execute(TRAPS) { } |
fparain@3329 | 267 | virtual void reset(TRAPS) { } |
fparain@3329 | 268 | virtual void cleanup() { } |
fparain@3329 | 269 | |
fparain@3329 | 270 | // support for the JMX interface |
fparain@3329 | 271 | virtual GrowableArray<const char*>* argument_name_array() { |
fparain@3329 | 272 | GrowableArray<const char*>* array = new GrowableArray<const char*>(0); |
fparain@3329 | 273 | return array; |
fparain@3329 | 274 | } |
fparain@3329 | 275 | virtual GrowableArray<DCmdArgumentInfo*>* argument_info_array() { |
fparain@3329 | 276 | GrowableArray<DCmdArgumentInfo*>* array = new GrowableArray<DCmdArgumentInfo*>(0); |
fparain@3329 | 277 | return array; |
fparain@3329 | 278 | } |
fparain@3329 | 279 | |
fparain@3329 | 280 | // main method to invoke the framework |
fparain@3329 | 281 | static void parse_and_execute(outputStream* out, const char* cmdline, |
fparain@3329 | 282 | char delim, TRAPS); |
fparain@3329 | 283 | }; |
fparain@3329 | 284 | |
fparain@3402 | 285 | class DCmdWithParser : public DCmd { |
fparain@3402 | 286 | protected: |
fparain@3402 | 287 | DCmdParser _dcmdparser; |
fparain@3402 | 288 | public: |
fparain@3402 | 289 | DCmdWithParser (outputStream *output, bool heap=false) : DCmd(output, heap) { } |
fparain@3402 | 290 | static const char* name() { return "No Name";} |
fparain@3402 | 291 | static const char* description() { return "No Help";} |
fparain@3402 | 292 | static const char* disabled_message() { return "Diagnostic command currently disabled"; } |
fparain@3402 | 293 | static const char* impact() { return "Low: No impact"; } |
fparain@3402 | 294 | static int num_arguments() { return 0; } |
fparain@3402 | 295 | virtual void parse(CmdLine *line, char delim, TRAPS); |
fparain@3402 | 296 | virtual void execute(TRAPS) { } |
fparain@3402 | 297 | virtual void reset(TRAPS); |
fparain@3402 | 298 | virtual void cleanup(); |
fparain@3402 | 299 | virtual void print_help(const char* name); |
fparain@3402 | 300 | virtual GrowableArray<const char*>* argument_name_array(); |
fparain@3402 | 301 | virtual GrowableArray<DCmdArgumentInfo*>* argument_info_array(); |
fparain@3402 | 302 | }; |
fparain@3402 | 303 | |
fparain@3329 | 304 | class DCmdMark : public StackObj { |
fparain@3329 | 305 | DCmd* _ref; |
fparain@3329 | 306 | public: |
fparain@3329 | 307 | DCmdMark(DCmd* cmd) { _ref = cmd; } |
fparain@3329 | 308 | ~DCmdMark() { |
fparain@3329 | 309 | if (_ref != NULL) { |
fparain@3329 | 310 | _ref->cleanup(); |
fparain@3329 | 311 | if (_ref->is_heap_allocated()) { |
fparain@3329 | 312 | delete _ref; |
fparain@3329 | 313 | } |
fparain@3329 | 314 | } |
fparain@3329 | 315 | } |
fparain@3329 | 316 | }; |
fparain@3329 | 317 | |
fparain@3329 | 318 | // Diagnostic commands are not directly instantiated but created with a factory. |
fparain@3329 | 319 | // Each diagnostic command class has its own factory. The DCmdFactory class also |
fparain@3329 | 320 | // manages the status of the diagnostic command (hidden, enabled). A DCmdFactory |
fparain@3329 | 321 | // has to be registered to make the diagnostic command available (see |
fparain@3329 | 322 | // management.cpp) |
zgu@3900 | 323 | class DCmdFactory: public CHeapObj<mtInternal> { |
fparain@3329 | 324 | private: |
fparain@3329 | 325 | static Mutex* _dcmdFactory_lock; |
fparain@3329 | 326 | // Pointer to the next factory in the singly-linked list of registered |
fparain@3329 | 327 | // diagnostic commands |
fparain@3329 | 328 | DCmdFactory* _next; |
fparain@3329 | 329 | // When disabled, a diagnostic command cannot be executed. Any attempt to |
fparain@3329 | 330 | // execute it will result in the printing of the disabled message without |
fparain@3329 | 331 | // instantiating the command. |
fparain@3329 | 332 | bool _enabled; |
fparain@3329 | 333 | // When hidden, a diagnostic command doesn't appear in the list of commands |
fparain@3329 | 334 | // provided by the 'help' command. |
fparain@3329 | 335 | bool _hidden; |
fparain@3329 | 336 | int _num_arguments; |
fparain@3329 | 337 | static DCmdFactory* _DCmdFactoryList; |
fparain@3329 | 338 | public: |
fparain@3329 | 339 | DCmdFactory(int num_arguments, bool enabled, bool hidden) { |
fparain@3329 | 340 | _next = NULL; |
fparain@3329 | 341 | _enabled = enabled; |
fparain@3329 | 342 | _hidden = hidden; |
fparain@3329 | 343 | _num_arguments = num_arguments; |
fparain@3329 | 344 | } |
fparain@3329 | 345 | bool is_enabled() const { return _enabled; } |
fparain@3329 | 346 | void set_enabled(bool b) { _enabled = b; } |
fparain@3329 | 347 | bool is_hidden() const { return _hidden; } |
fparain@3329 | 348 | void set_hidden(bool b) { _hidden = b; } |
fparain@3329 | 349 | int num_arguments() { return _num_arguments; } |
fparain@3329 | 350 | DCmdFactory* next() { return _next; } |
fparain@3329 | 351 | virtual DCmd* create_Cheap_instance(outputStream* output) = 0; |
fparain@3329 | 352 | virtual DCmd* create_resource_instance(outputStream* output) = 0; |
fparain@3329 | 353 | virtual const char* name() const = 0; |
fparain@3329 | 354 | virtual const char* description() const = 0; |
fparain@3329 | 355 | virtual const char* impact() const = 0; |
fparain@3329 | 356 | virtual const char* disabled_message() const = 0; |
fparain@3329 | 357 | // Register a DCmdFactory to make a diagnostic command available. |
fparain@3329 | 358 | // Once registered, a diagnostic command must not be unregistered. |
fparain@3329 | 359 | // To prevent a diagnostic command from being executed, just set the |
fparain@3329 | 360 | // enabled flag to false. |
fparain@3329 | 361 | static int register_DCmdFactory(DCmdFactory* factory); |
fparain@3329 | 362 | static DCmdFactory* factory(const char* cmd, size_t len); |
fparain@3329 | 363 | // Returns a C-heap allocated diagnostic command for the given command line |
fparain@3329 | 364 | static DCmd* create_global_DCmd(CmdLine &line, outputStream* out, TRAPS); |
fparain@3329 | 365 | // Returns a resourceArea allocated diagnostic command for the given command line |
fparain@3329 | 366 | static DCmd* create_local_DCmd(CmdLine &line, outputStream* out, TRAPS); |
fparain@3329 | 367 | static GrowableArray<const char*>* DCmd_list(); |
fparain@3329 | 368 | static GrowableArray<DCmdInfo*>* DCmdInfo_list(); |
fparain@3329 | 369 | |
fparain@3329 | 370 | friend class HelpDCmd; |
fparain@3329 | 371 | }; |
fparain@3329 | 372 | |
fparain@3329 | 373 | // Template to easily create DCmdFactory instances. See management.cpp |
fparain@3329 | 374 | // where this template is used to create and register factories. |
fparain@3329 | 375 | template <class DCmdClass> class DCmdFactoryImpl : public DCmdFactory { |
fparain@3329 | 376 | public: |
fparain@3329 | 377 | DCmdFactoryImpl(bool enabled, bool hidden) : |
fparain@3329 | 378 | DCmdFactory(DCmdClass::num_arguments(), enabled, hidden) { } |
fparain@3329 | 379 | // Returns a C-heap allocated instance |
fparain@3329 | 380 | virtual DCmd* create_Cheap_instance(outputStream* output) { |
zgu@3900 | 381 | return new (ResourceObj::C_HEAP, mtInternal) DCmdClass(output, true); |
fparain@3329 | 382 | } |
fparain@3329 | 383 | // Returns a resourceArea allocated instance |
fparain@3329 | 384 | virtual DCmd* create_resource_instance(outputStream* output) { |
fparain@3329 | 385 | return new DCmdClass(output, false); |
fparain@3329 | 386 | } |
fparain@3329 | 387 | virtual const char* name() const { |
fparain@3329 | 388 | return DCmdClass::name(); |
fparain@3329 | 389 | } |
fparain@3329 | 390 | virtual const char* description() const { |
fparain@3329 | 391 | return DCmdClass::description(); |
fparain@3329 | 392 | } |
fparain@3329 | 393 | virtual const char* impact() const { |
fparain@3329 | 394 | return DCmdClass::impact(); |
fparain@3329 | 395 | } |
fparain@3329 | 396 | virtual const char* disabled_message() const { |
fparain@3329 | 397 | return DCmdClass::disabled_message(); |
fparain@3329 | 398 | } |
fparain@3329 | 399 | }; |
fparain@3329 | 400 | |
dsamersoff@3478 | 401 | // This class provides a convenient way to register Dcmds, without a need to change |
dsamersoff@3478 | 402 | // management.cpp every time. Body of these two methods resides in |
dsamersoff@3478 | 403 | // diagnosticCommand.cpp |
dsamersoff@3478 | 404 | |
dsamersoff@3478 | 405 | class DCmdRegistrant : public AllStatic { |
dsamersoff@3478 | 406 | |
dsamersoff@3478 | 407 | private: |
dsamersoff@3478 | 408 | static void register_dcmds(); |
dsamersoff@3478 | 409 | static void register_dcmds_ext(); |
dsamersoff@3478 | 410 | |
dsamersoff@3478 | 411 | friend class Management; |
dsamersoff@3478 | 412 | }; |
dsamersoff@3478 | 413 | |
fparain@3329 | 414 | #endif // SHARE_VM_SERVICES_DIAGNOSTICFRAMEWORK_HPP |