2011-12-14 04:30:57 -08:00
|
|
|
/*
|
2019-01-10 15:13:51 -05:00
|
|
|
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
|
2011-12-14 04:30:57 -08:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-01-10 15:13:51 -05:00
|
|
|
#ifndef SHARE_SERVICES_DIAGNOSTICFRAMEWORK_HPP
|
|
|
|
#define SHARE_SERVICES_DIAGNOSTICFRAMEWORK_HPP
|
2011-12-14 04:30:57 -08:00
|
|
|
|
|
|
|
#include "classfile/vmSymbols.hpp"
|
|
|
|
#include "memory/allocation.hpp"
|
|
|
|
#include "runtime/arguments.hpp"
|
|
|
|
#include "runtime/os.hpp"
|
|
|
|
#include "runtime/vmThread.hpp"
|
|
|
|
#include "utilities/ostream.hpp"
|
|
|
|
|
|
|
|
|
2013-05-03 05:05:31 -07:00
|
|
|
enum DCmdSource {
|
|
|
|
DCmd_Source_Internal = 0x01U, // invocation from the JVM
|
|
|
|
DCmd_Source_AttachAPI = 0x02U, // invocation via the attachAPI
|
|
|
|
DCmd_Source_MBean = 0x04U // invocation via a MBean
|
|
|
|
};
|
|
|
|
|
|
|
|
// Warning: strings referenced by the JavaPermission struct are passed to
|
|
|
|
// the native part of the JDK. Avoid use of dynamically allocated strings
|
|
|
|
// that could be de-allocated before the JDK native code had time to
|
|
|
|
// convert them into Java Strings.
|
|
|
|
struct JavaPermission {
|
|
|
|
const char* _class;
|
|
|
|
const char* _name;
|
|
|
|
const char* _action;
|
|
|
|
};
|
|
|
|
|
2011-12-14 04:30:57 -08:00
|
|
|
// CmdLine is the class used to handle a command line containing a single
|
|
|
|
// diagnostic command and its arguments. It provides methods to access the
|
|
|
|
// command name and the beginning of the arguments. The class is also
|
|
|
|
// able to identify commented command lines and the "stop" keyword
|
|
|
|
class CmdLine : public StackObj {
|
|
|
|
private:
|
|
|
|
const char* _cmd;
|
|
|
|
size_t _cmd_len;
|
|
|
|
const char* _args;
|
|
|
|
size_t _args_len;
|
|
|
|
public:
|
|
|
|
CmdLine(const char* line, size_t len, bool no_command_name);
|
2018-06-16 07:05:09 +02:00
|
|
|
const char* args_addr() const { return _args; }
|
|
|
|
size_t args_len() const { return _args_len; }
|
|
|
|
const char* cmd_addr() const { return _cmd; }
|
|
|
|
size_t cmd_len() const { return _cmd_len; }
|
|
|
|
bool is_empty() const { return _cmd_len == 0; }
|
|
|
|
bool is_executable() const { return is_empty() || _cmd[0] != '#'; }
|
|
|
|
bool is_stop() const { return !is_empty() && strncmp("stop", _cmd, _cmd_len) == 0; }
|
2011-12-14 04:30:57 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Iterator class taking a character string in input and returning a CmdLine
|
|
|
|
// instance for each command line. The argument delimiter has to be specified.
|
|
|
|
class DCmdIter : public StackObj {
|
|
|
|
friend class DCmd;
|
|
|
|
private:
|
2018-06-16 07:05:09 +02:00
|
|
|
const char* const _str;
|
|
|
|
const char _delim;
|
|
|
|
const size_t _len;
|
2011-12-14 04:30:57 -08:00
|
|
|
size_t _cursor;
|
|
|
|
public:
|
|
|
|
|
2018-06-16 07:05:09 +02:00
|
|
|
DCmdIter(const char* str, char delim)
|
|
|
|
: _str(str), _delim(delim), _len(::strlen(str)),
|
|
|
|
_cursor(0) {}
|
|
|
|
bool has_next() const { return _cursor < _len; }
|
2011-12-14 04:30:57 -08:00
|
|
|
CmdLine next() {
|
|
|
|
assert(_cursor <= _len, "Cannot iterate more");
|
|
|
|
size_t n = _cursor;
|
|
|
|
while (n < _len && _str[n] != _delim) n++;
|
|
|
|
CmdLine line(&(_str[_cursor]), n - _cursor, false);
|
|
|
|
_cursor = n + 1;
|
|
|
|
// The default copy constructor of CmdLine is used to return a CmdLine
|
|
|
|
// instance to the caller.
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Iterator class to iterate over diagnostic command arguments
|
|
|
|
class DCmdArgIter : public ResourceObj {
|
2018-06-16 07:05:09 +02:00
|
|
|
const char* const _buffer;
|
|
|
|
const size_t _len;
|
2011-12-14 04:30:57 -08:00
|
|
|
size_t _cursor;
|
|
|
|
const char* _key_addr;
|
|
|
|
size_t _key_len;
|
|
|
|
const char* _value_addr;
|
|
|
|
size_t _value_len;
|
2018-06-16 07:05:09 +02:00
|
|
|
const char _delim;
|
2011-12-14 04:30:57 -08:00
|
|
|
public:
|
2018-06-16 07:05:09 +02:00
|
|
|
DCmdArgIter(const char* buf, size_t len, char delim)
|
|
|
|
: _buffer(buf), _len(len), _cursor(0), _key_addr(NULL),
|
|
|
|
_key_len(0), _value_addr(NULL), _value_len(0), _delim(delim) {}
|
|
|
|
|
2011-12-14 04:30:57 -08:00
|
|
|
bool next(TRAPS);
|
2018-06-16 07:05:09 +02:00
|
|
|
const char* key_addr() const { return _key_addr; }
|
|
|
|
size_t key_length() const { return _key_len; }
|
|
|
|
const char* value_addr() const { return _value_addr; }
|
|
|
|
size_t value_length() const { return _value_len; }
|
2011-12-14 04:30:57 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
// A DCmdInfo instance provides a description of a diagnostic command. It is
|
|
|
|
// used to export the description to the JMX interface of the framework.
|
|
|
|
class DCmdInfo : public ResourceObj {
|
|
|
|
protected:
|
2018-06-16 07:05:09 +02:00
|
|
|
const char* const _name; /* Name of the diagnostic command */
|
|
|
|
const char* const _description; /* Short description */
|
|
|
|
const char* const _impact; /* Impact on the JVM */
|
|
|
|
const JavaPermission _permission; /* Java Permission required to execute this command if any */
|
|
|
|
const int _num_arguments; /* Number of supported options or arguments */
|
|
|
|
const bool _is_enabled; /* True if the diagnostic command can be invoked, false otherwise */
|
2011-12-14 04:30:57 -08:00
|
|
|
public:
|
|
|
|
DCmdInfo(const char* name,
|
|
|
|
const char* description,
|
|
|
|
const char* impact,
|
2013-05-03 05:05:31 -07:00
|
|
|
JavaPermission permission,
|
2011-12-14 04:30:57 -08:00
|
|
|
int num_arguments,
|
2018-06-16 07:05:09 +02:00
|
|
|
bool enabled)
|
|
|
|
: _name(name), _description(description), _impact(impact), _permission(permission),
|
|
|
|
_num_arguments(num_arguments), _is_enabled(enabled) {}
|
|
|
|
const char* name() const { return _name; }
|
|
|
|
const char* description() const { return _description; }
|
|
|
|
const char* impact() const { return _impact; }
|
|
|
|
const JavaPermission& permission() const { return _permission; }
|
|
|
|
int num_arguments() const { return _num_arguments; }
|
|
|
|
bool is_enabled() const { return _is_enabled; }
|
2011-12-14 04:30:57 -08:00
|
|
|
|
|
|
|
static bool by_name(void* name, DCmdInfo* info);
|
|
|
|
};
|
|
|
|
|
|
|
|
// A DCmdArgumentInfo instance provides a description of a diagnostic command
|
|
|
|
// argument. It is used to export the description to the JMX interface of the
|
|
|
|
// framework.
|
|
|
|
class DCmdArgumentInfo : public ResourceObj {
|
|
|
|
protected:
|
2018-06-16 07:05:09 +02:00
|
|
|
const char* const _name; /* Option/Argument name*/
|
|
|
|
const char* const _description; /* Short description */
|
|
|
|
const char* const _type; /* Type: STRING, BOOLEAN, etc. */
|
|
|
|
const char* const _default_string; /* Default value in a parsable string */
|
|
|
|
const bool _mandatory; /* True if the option/argument is mandatory */
|
|
|
|
const bool _option; /* True if it is an option, false if it is an argument */
|
2013-05-03 05:05:31 -07:00
|
|
|
/* (see diagnosticFramework.hpp for option/argument definitions) */
|
2018-06-16 07:05:09 +02:00
|
|
|
const bool _multiple; /* True is the option can be specified several time */
|
|
|
|
const int _position; /* Expected position for this argument (this field is */
|
2013-05-03 05:05:31 -07:00
|
|
|
/* meaningless for options) */
|
2011-12-14 04:30:57 -08:00
|
|
|
public:
|
|
|
|
DCmdArgumentInfo(const char* name, const char* description, const char* type,
|
2013-05-03 05:05:31 -07:00
|
|
|
const char* default_string, bool mandatory, bool option,
|
2018-06-16 07:05:09 +02:00
|
|
|
bool multiple, int position = -1)
|
|
|
|
: _name(name), _description(description), _type(type),
|
|
|
|
_default_string(default_string), _mandatory(mandatory), _option(option),
|
|
|
|
_multiple(multiple), _position(position) {}
|
|
|
|
|
|
|
|
const char* name() const { return _name; }
|
2011-12-14 04:30:57 -08:00
|
|
|
const char* description() const { return _description; }
|
2018-06-16 07:05:09 +02:00
|
|
|
const char* type() const { return _type; }
|
2011-12-14 04:30:57 -08:00
|
|
|
const char* default_string() const { return _default_string; }
|
2018-06-16 07:05:09 +02:00
|
|
|
bool is_mandatory() const { return _mandatory; }
|
|
|
|
bool is_option() const { return _option; }
|
|
|
|
bool is_multiple() const { return _multiple; }
|
|
|
|
int position() const { return _position; }
|
2011-12-14 04:30:57 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
// The DCmdParser class can be used to create an argument parser for a
|
|
|
|
// diagnostic command. It is not mandatory to use it to parse arguments.
|
2013-05-03 05:05:31 -07:00
|
|
|
// The DCmdParser parses a CmdLine instance according to the parameters that
|
|
|
|
// have been declared by its associated diagnostic command. A parameter can
|
|
|
|
// either be an option or an argument. Options are identified by the option name
|
|
|
|
// while arguments are identified by their position in the command line. The
|
|
|
|
// position of an argument is defined relative to all arguments passed on the
|
|
|
|
// command line, options are not considered when defining an argument position.
|
|
|
|
// The generic syntax of a diagnostic command is:
|
|
|
|
//
|
|
|
|
// <command name> [<option>=<value>] [<argument_value>]
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// command_name option1=value1 option2=value argumentA argumentB argumentC
|
|
|
|
//
|
|
|
|
// In this command line, the diagnostic command receives five parameters, two
|
|
|
|
// options named option1 and option2, and three arguments. argumentA's position
|
|
|
|
// is 0, argumentB's position is 1 and argumentC's position is 2.
|
2011-12-14 04:30:57 -08:00
|
|
|
class DCmdParser {
|
|
|
|
private:
|
|
|
|
GenDCmdArgument* _options;
|
|
|
|
GenDCmdArgument* _arguments_list;
|
|
|
|
public:
|
2018-06-16 07:05:09 +02:00
|
|
|
DCmdParser()
|
|
|
|
: _options(NULL), _arguments_list(NULL) {}
|
2011-12-14 04:30:57 -08:00
|
|
|
void add_dcmd_option(GenDCmdArgument* arg);
|
|
|
|
void add_dcmd_argument(GenDCmdArgument* arg);
|
|
|
|
GenDCmdArgument* lookup_dcmd_option(const char* name, size_t len);
|
2018-06-16 07:05:09 +02:00
|
|
|
GenDCmdArgument* arguments_list() const { return _arguments_list; };
|
2011-12-14 04:30:57 -08:00
|
|
|
void check(TRAPS);
|
|
|
|
void parse(CmdLine* line, char delim, TRAPS);
|
2018-06-16 07:05:09 +02:00
|
|
|
void print_help(outputStream* out, const char* cmd_name) const;
|
2011-12-14 04:30:57 -08:00
|
|
|
void reset(TRAPS);
|
|
|
|
void cleanup();
|
2018-06-16 07:05:09 +02:00
|
|
|
int num_arguments() const;
|
|
|
|
GrowableArray<const char*>* argument_name_array() const;
|
|
|
|
GrowableArray<DCmdArgumentInfo*>* argument_info_array() const;
|
2011-12-14 04:30:57 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
// The DCmd class is the parent class of all diagnostic commands
|
|
|
|
// Diagnostic command instances should not be instantiated directly but
|
|
|
|
// created using the associated factory. The factory can be retrieved with
|
|
|
|
// the DCmdFactory::getFactory() method.
|
|
|
|
// A diagnostic command instance can either be allocated in the resource Area
|
|
|
|
// or in the C-heap. Allocation in the resource area is recommended when the
|
|
|
|
// current thread is the only one which will access the diagnostic command
|
|
|
|
// instance. Allocation in the C-heap is required when the diagnostic command
|
|
|
|
// is accessed by several threads (for instance to perform asynchronous
|
|
|
|
// execution).
|
|
|
|
// To ensure a proper cleanup, it's highly recommended to use a DCmdMark for
|
|
|
|
// each diagnostic command instance. In case of a C-heap allocated diagnostic
|
|
|
|
// command instance, the DCmdMark must be created in the context of the last
|
|
|
|
// thread that will access the instance.
|
|
|
|
class DCmd : public ResourceObj {
|
|
|
|
protected:
|
2018-06-16 07:05:09 +02:00
|
|
|
outputStream* const _output;
|
|
|
|
const bool _is_heap_allocated;
|
2011-12-14 04:30:57 -08:00
|
|
|
public:
|
2018-06-16 07:05:09 +02:00
|
|
|
DCmd(outputStream* output, bool heap_allocated)
|
|
|
|
: _output(output), _is_heap_allocated(heap_allocated) {}
|
|
|
|
|
|
|
|
// Child classes: please always provide these methods:
|
|
|
|
// static const char* name() { return "<command name>";}
|
|
|
|
// static const char* description() { return "<command help>";}
|
2011-12-14 04:30:57 -08:00
|
|
|
|
|
|
|
static const char* disabled_message() { return "Diagnostic command currently disabled"; }
|
2018-06-16 07:05:09 +02:00
|
|
|
|
2012-06-28 11:37:28 +02:00
|
|
|
// The impact() method returns a description of the intrusiveness of the diagnostic
|
|
|
|
// command on the Java Virtual Machine behavior. The rational for this method is that some
|
|
|
|
// diagnostic commands can seriously disrupt the behavior of the Java Virtual Machine
|
|
|
|
// (for instance a Thread Dump for an application with several tens of thousands of threads,
|
|
|
|
// or a Head Dump with a 40GB+ heap size) and other diagnostic commands have no serious
|
|
|
|
// impact on the JVM (for instance, getting the command line arguments or the JVM version).
|
|
|
|
// The recommended format for the description is <impact level>: [longer description],
|
|
|
|
// where the impact level is selected among this list: {Low, Medium, High}. The optional
|
|
|
|
// longer description can provide more specific details like the fact that Thread Dump
|
|
|
|
// impact depends on the heap size.
|
2018-06-16 07:05:09 +02:00
|
|
|
static const char* impact() { return "Low: No impact"; }
|
|
|
|
|
2013-05-03 05:05:31 -07:00
|
|
|
// The permission() method returns the description of Java Permission. This
|
|
|
|
// permission is required when the diagnostic command is invoked via the
|
|
|
|
// DiagnosticCommandMBean. The rationale for this permission check is that
|
|
|
|
// the DiagnosticCommandMBean can be used to perform remote invocations of
|
|
|
|
// diagnostic commands through the PlatformMBeanServer. The (optional) Java
|
|
|
|
// Permission associated with each diagnostic command should ease the work
|
|
|
|
// of system administrators to write policy files granting permissions to
|
|
|
|
// execute diagnostic commands to remote users. Any diagnostic command with
|
|
|
|
// a potential impact on security should overwrite this method.
|
|
|
|
static const JavaPermission permission() {
|
|
|
|
JavaPermission p = {NULL, NULL, NULL};
|
|
|
|
return p;
|
|
|
|
}
|
2018-06-16 07:05:09 +02:00
|
|
|
static int num_arguments() { return 0; }
|
|
|
|
outputStream* output() const { return _output; }
|
|
|
|
bool is_heap_allocated() const { return _is_heap_allocated; }
|
|
|
|
virtual void print_help(const char* name) const {
|
2012-01-09 10:27:24 +01:00
|
|
|
output()->print_cr("Syntax: %s", name);
|
|
|
|
}
|
|
|
|
virtual void parse(CmdLine* line, char delim, TRAPS) {
|
|
|
|
DCmdArgIter iter(line->args_addr(), line->args_len(), delim);
|
|
|
|
bool has_arg = iter.next(CHECK);
|
|
|
|
if (has_arg) {
|
|
|
|
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
|
2012-06-28 11:37:28 +02:00
|
|
|
"The argument list of this diagnostic command should be empty.");
|
2012-01-09 10:27:24 +01:00
|
|
|
}
|
|
|
|
}
|
2013-05-03 05:05:31 -07:00
|
|
|
virtual void execute(DCmdSource source, TRAPS) { }
|
2011-12-14 04:30:57 -08:00
|
|
|
virtual void reset(TRAPS) { }
|
|
|
|
virtual void cleanup() { }
|
|
|
|
|
|
|
|
// support for the JMX interface
|
2018-06-16 07:05:09 +02:00
|
|
|
virtual GrowableArray<const char*>* argument_name_array() const {
|
2011-12-14 04:30:57 -08:00
|
|
|
GrowableArray<const char*>* array = new GrowableArray<const char*>(0);
|
|
|
|
return array;
|
|
|
|
}
|
2018-06-16 07:05:09 +02:00
|
|
|
virtual GrowableArray<DCmdArgumentInfo*>* argument_info_array() const {
|
2011-12-14 04:30:57 -08:00
|
|
|
GrowableArray<DCmdArgumentInfo*>* array = new GrowableArray<DCmdArgumentInfo*>(0);
|
|
|
|
return array;
|
|
|
|
}
|
|
|
|
|
|
|
|
// main method to invoke the framework
|
2013-05-03 05:05:31 -07:00
|
|
|
static void parse_and_execute(DCmdSource source, outputStream* out, const char* cmdline,
|
2011-12-14 04:30:57 -08:00
|
|
|
char delim, TRAPS);
|
|
|
|
};
|
|
|
|
|
2012-01-09 10:27:24 +01:00
|
|
|
class DCmdWithParser : public DCmd {
|
|
|
|
protected:
|
|
|
|
DCmdParser _dcmdparser;
|
|
|
|
public:
|
|
|
|
DCmdWithParser (outputStream *output, bool heap=false) : DCmd(output, heap) { }
|
|
|
|
static const char* disabled_message() { return "Diagnostic command currently disabled"; }
|
2018-06-16 07:05:09 +02:00
|
|
|
static const char* impact() { return "Low: No impact"; }
|
2012-01-09 10:27:24 +01:00
|
|
|
virtual void parse(CmdLine *line, char delim, TRAPS);
|
2013-05-03 05:05:31 -07:00
|
|
|
virtual void execute(DCmdSource source, TRAPS) { }
|
2012-01-09 10:27:24 +01:00
|
|
|
virtual void reset(TRAPS);
|
|
|
|
virtual void cleanup();
|
2018-06-16 07:05:09 +02:00
|
|
|
virtual void print_help(const char* name) const;
|
|
|
|
virtual GrowableArray<const char*>* argument_name_array() const;
|
|
|
|
virtual GrowableArray<DCmdArgumentInfo*>* argument_info_array() const;
|
2012-01-09 10:27:24 +01:00
|
|
|
};
|
|
|
|
|
2011-12-14 04:30:57 -08:00
|
|
|
class DCmdMark : public StackObj {
|
2018-06-16 07:05:09 +02:00
|
|
|
DCmd* const _ref;
|
2011-12-14 04:30:57 -08:00
|
|
|
public:
|
2018-06-16 07:05:09 +02:00
|
|
|
DCmdMark(DCmd* cmd) : _ref(cmd) {}
|
2011-12-14 04:30:57 -08:00
|
|
|
~DCmdMark() {
|
|
|
|
if (_ref != NULL) {
|
|
|
|
_ref->cleanup();
|
|
|
|
if (_ref->is_heap_allocated()) {
|
|
|
|
delete _ref;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Diagnostic commands are not directly instantiated but created with a factory.
|
|
|
|
// Each diagnostic command class has its own factory. The DCmdFactory class also
|
|
|
|
// manages the status of the diagnostic command (hidden, enabled). A DCmdFactory
|
|
|
|
// has to be registered to make the diagnostic command available (see
|
|
|
|
// management.cpp)
|
2012-06-28 17:03:16 -04:00
|
|
|
class DCmdFactory: public CHeapObj<mtInternal> {
|
2011-12-14 04:30:57 -08:00
|
|
|
private:
|
2013-05-03 05:05:31 -07:00
|
|
|
static bool _send_jmx_notification;
|
|
|
|
static bool _has_pending_jmx_notification;
|
2018-06-16 07:05:09 +02:00
|
|
|
static DCmdFactory* _DCmdFactoryList;
|
|
|
|
|
2011-12-14 04:30:57 -08:00
|
|
|
// Pointer to the next factory in the singly-linked list of registered
|
|
|
|
// diagnostic commands
|
|
|
|
DCmdFactory* _next;
|
|
|
|
// When disabled, a diagnostic command cannot be executed. Any attempt to
|
|
|
|
// execute it will result in the printing of the disabled message without
|
|
|
|
// instantiating the command.
|
2018-06-16 07:05:09 +02:00
|
|
|
const bool _enabled;
|
2011-12-14 04:30:57 -08:00
|
|
|
// When hidden, a diagnostic command doesn't appear in the list of commands
|
|
|
|
// provided by the 'help' command.
|
2018-06-16 07:05:09 +02:00
|
|
|
const bool _hidden;
|
|
|
|
const uint32_t _export_flags;
|
|
|
|
const int _num_arguments;
|
|
|
|
|
2011-12-14 04:30:57 -08:00
|
|
|
public:
|
2018-06-16 07:05:09 +02:00
|
|
|
DCmdFactory(int num_arguments, uint32_t flags, bool enabled, bool hidden)
|
|
|
|
: _next(NULL), _enabled(enabled), _hidden(hidden),
|
|
|
|
_export_flags(flags), _num_arguments(num_arguments) {}
|
|
|
|
bool is_enabled() const { return _enabled; }
|
|
|
|
bool is_hidden() const { return _hidden; }
|
|
|
|
uint32_t export_flags() const { return _export_flags; }
|
|
|
|
int num_arguments() const { return _num_arguments; }
|
|
|
|
DCmdFactory* next() const { return _next; }
|
|
|
|
virtual DCmd* create_resource_instance(outputStream* output) const = 0;
|
2011-12-14 04:30:57 -08:00
|
|
|
virtual const char* name() const = 0;
|
|
|
|
virtual const char* description() const = 0;
|
|
|
|
virtual const char* impact() const = 0;
|
2013-05-03 05:05:31 -07:00
|
|
|
virtual const JavaPermission permission() const = 0;
|
2011-12-14 04:30:57 -08:00
|
|
|
virtual const char* disabled_message() const = 0;
|
|
|
|
// Register a DCmdFactory to make a diagnostic command available.
|
|
|
|
// Once registered, a diagnostic command must not be unregistered.
|
|
|
|
// To prevent a diagnostic command from being executed, just set the
|
|
|
|
// enabled flag to false.
|
|
|
|
static int register_DCmdFactory(DCmdFactory* factory);
|
2013-05-03 05:05:31 -07:00
|
|
|
static DCmdFactory* factory(DCmdSource source, const char* cmd, size_t len);
|
2011-12-14 04:30:57 -08:00
|
|
|
// Returns a resourceArea allocated diagnostic command for the given command line
|
2013-05-03 05:05:31 -07:00
|
|
|
static DCmd* create_local_DCmd(DCmdSource source, CmdLine &line, outputStream* out, TRAPS);
|
|
|
|
static GrowableArray<const char*>* DCmd_list(DCmdSource source);
|
|
|
|
static GrowableArray<DCmdInfo*>* DCmdInfo_list(DCmdSource source);
|
|
|
|
|
|
|
|
static void set_jmx_notification_enabled(bool enabled) {
|
|
|
|
_send_jmx_notification = enabled;
|
|
|
|
}
|
|
|
|
static void push_jmx_notification_request();
|
|
|
|
static bool has_pending_jmx_notification() { return _has_pending_jmx_notification; }
|
|
|
|
static void send_notification(TRAPS);
|
|
|
|
private:
|
|
|
|
static void send_notification_internal(TRAPS);
|
2011-12-14 04:30:57 -08:00
|
|
|
|
|
|
|
friend class HelpDCmd;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Template to easily create DCmdFactory instances. See management.cpp
|
|
|
|
// where this template is used to create and register factories.
|
|
|
|
template <class DCmdClass> class DCmdFactoryImpl : public DCmdFactory {
|
|
|
|
public:
|
2013-05-03 05:05:31 -07:00
|
|
|
DCmdFactoryImpl(uint32_t flags, bool enabled, bool hidden) :
|
|
|
|
DCmdFactory(DCmdClass::num_arguments(), flags, enabled, hidden) { }
|
2011-12-14 04:30:57 -08:00
|
|
|
// Returns a resourceArea allocated instance
|
2018-06-16 07:05:09 +02:00
|
|
|
DCmd* create_resource_instance(outputStream* output) const {
|
2011-12-14 04:30:57 -08:00
|
|
|
return new DCmdClass(output, false);
|
|
|
|
}
|
2018-06-16 07:05:09 +02:00
|
|
|
const char* name() const {
|
2011-12-14 04:30:57 -08:00
|
|
|
return DCmdClass::name();
|
|
|
|
}
|
2018-06-16 07:05:09 +02:00
|
|
|
const char* description() const {
|
2011-12-14 04:30:57 -08:00
|
|
|
return DCmdClass::description();
|
|
|
|
}
|
2018-06-16 07:05:09 +02:00
|
|
|
const char* impact() const {
|
2011-12-14 04:30:57 -08:00
|
|
|
return DCmdClass::impact();
|
|
|
|
}
|
2018-06-16 07:05:09 +02:00
|
|
|
const JavaPermission permission() const {
|
2013-05-03 05:05:31 -07:00
|
|
|
return DCmdClass::permission();
|
|
|
|
}
|
2018-06-16 07:05:09 +02:00
|
|
|
const char* disabled_message() const {
|
2011-12-14 04:30:57 -08:00
|
|
|
return DCmdClass::disabled_message();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-01-25 21:10:08 +04:00
|
|
|
// This class provides a convenient way to register Dcmds, without a need to change
|
|
|
|
// management.cpp every time. Body of these two methods resides in
|
|
|
|
// diagnosticCommand.cpp
|
|
|
|
|
|
|
|
class DCmdRegistrant : public AllStatic {
|
|
|
|
|
|
|
|
private:
|
|
|
|
static void register_dcmds();
|
|
|
|
static void register_dcmds_ext();
|
|
|
|
|
|
|
|
friend class Management;
|
|
|
|
};
|
|
|
|
|
2019-01-10 15:13:51 -05:00
|
|
|
#endif // SHARE_SERVICES_DIAGNOSTICFRAMEWORK_HPP
|