src/share/vm/services/diagnosticFramework.hpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 5047
31a4e55f8c9d
parent 0
f90c822e73f8
permissions
-rw-r--r--

merge

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

mercurial