--- old/src/hotspot/share/services/diagnosticFramework.hpp 2018-06-14 09:36:42.694239167 +0200 +++ new/src/hotspot/share/services/diagnosticFramework.hpp 2018-06-14 09:36:42.514237476 +0200 @@ -61,13 +61,13 @@ size_t _args_len; public: CmdLine(const char* line, size_t len, bool no_command_name); - 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() { return _cmd_len == 0; } - bool is_executable() { return is_empty() || _cmd[0] != '#'; } - bool is_stop() { return !is_empty() && strncmp("stop", _cmd, _cmd_len) == 0; } + 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; } }; // Iterator class taking a character string in input and returning a CmdLine @@ -82,7 +82,10 @@ public: DCmdIter(const char* str, char delim) - : _str(str), _delim(delim), _len(::strlen(str)), _cursor(0) {} + : _str(str) + , _delim(delim) + , _len(::strlen(str)) + , _cursor(0) {} bool has_next() const { return _cursor < _len; } CmdLine next() { assert(_cursor <= _len, "Cannot iterate more"); @@ -108,45 +111,52 @@ const char _delim; public: DCmdArgIter(const char* buf, size_t len, char delim) - : _buffer(buf), _len(len), _delim(delim), _cursor(0) {} + : _buffer(buf) + , _len(len) + , _cursor(0) + , _key_addr(NULL) + , _key_len(0) + , _value_addr(NULL) + , _value_len(0) + , _delim(delim) + {} bool next(TRAPS); - 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; } + 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; } }; // 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: - const char* _name; /* Name of the diagnostic command */ - const char* _description; /* Short description */ - const char* _impact; /* Impact on the JVM */ - JavaPermission _permission; /* Java Permission required to execute this command if any */ - int _num_arguments; /* Number of supported options or arguments */ - bool _is_enabled; /* True if the diagnostic command can be invoked, false otherwise */ + 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 */ public: DCmdInfo(const char* name, const char* description, const char* impact, JavaPermission permission, int num_arguments, - bool enabled) { - this->_name = name; - this->_description = description; - this->_impact = impact; - this->_permission = permission; - this->_num_arguments = num_arguments; - this->_is_enabled = enabled; - } - const char* name() const { return _name; } - const char* description() const { return _description; } - const char* impact() const { return _impact; } - JavaPermission permission() const { return _permission; } - int num_arguments() const { return _num_arguments; } - bool is_enabled() const { return _is_enabled; } + 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; } static bool by_name(void* name, DCmdInfo* info); }; @@ -170,18 +180,23 @@ DCmdArgumentInfo(const char* name, const char* description, const char* type, const char* default_string, bool mandatory, bool option, bool multiple, int position = -1) - : _name(name), _description(description), _type(type) - , _default_string(default_string), _mandatory(mandatory) - , _option(option), _multiple(multiple), _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; } + const char* name() const { return _name; } const char* description() const { return _description; } - const char* type() const { return _type; } + const char* type() const { return _type; } const char* default_string() const { return _default_string; } - bool is_mandatory() const { return _mandatory; } - bool is_option() const { return _option; } - bool is_multiple() const { return _multiple; } - int position() const { return _position; } + bool is_mandatory() const { return _mandatory; } + bool is_option() const { return _option; } + bool is_multiple() const { return _multiple; } + int position() const { return _position; } }; // The DCmdParser class can be used to create an argument parser for a @@ -209,7 +224,8 @@ GenDCmdArgument* _arguments_list; public: DCmdParser() - : _options(NULL), _arguments_list(NULL) {} + : _options(NULL) + , _arguments_list(NULL) {} void add_dcmd_option(GenDCmdArgument* arg); void add_dcmd_argument(GenDCmdArgument* arg); GenDCmdArgument* lookup_dcmd_option(const char* name, size_t len); @@ -244,11 +260,15 @@ const bool _is_heap_allocated; public: DCmd(outputStream* output, bool heap_allocated) - : _output(output), _is_heap_allocated(heap_allocated) {} + : _output(output) + , _is_heap_allocated(heap_allocated) {} + + // Child classes: please always provide these methods: + // static const char* name() { return "";} + // static const char* description() { return "";} - static const char* name() { return "No Name";} - static const char* description() { return "No Help";} static const char* disabled_message() { return "Diagnostic command currently disabled"; } + // 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 @@ -259,7 +279,8 @@ // 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. - static const char* impact() { return "Low: No impact"; } + static const char* impact() { return "Low: No impact"; } + // 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 @@ -273,9 +294,9 @@ JavaPermission p = {NULL, NULL, NULL}; return p; } - static int num_arguments() { return 0; } - outputStream* output() const { return _output; } - bool is_heap_allocated() const { return _is_heap_allocated; } + 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 { output()->print_cr("Syntax: %s", name); } @@ -311,12 +332,8 @@ DCmdParser _dcmdparser; public: DCmdWithParser (outputStream *output, bool heap=false) : DCmd(output, heap) { } - static const char* name() { return "No Name";} - static const char* description() { return "No Help";} static const char* disabled_message() { return "Diagnostic command currently disabled"; } - static const char* impact() { return "Low: No impact"; } - static const JavaPermission permission() {JavaPermission p = {NULL, NULL, NULL}; return p; } - static int num_arguments() { return 0; } + static const char* impact() { return "Low: No impact"; } virtual void parse(CmdLine *line, char delim, TRAPS); virtual void execute(DCmdSource source, TRAPS) { } virtual void reset(TRAPS); @@ -350,6 +367,8 @@ static Mutex* _dcmdFactory_lock; static bool _send_jmx_notification; static bool _has_pending_jmx_notification; + static DCmdFactory* _DCmdFactoryList; + // Pointer to the next factory in the singly-linked list of registered // diagnostic commands DCmdFactory* _next; @@ -362,16 +381,19 @@ const bool _hidden; const uint32_t _export_flags; const int _num_arguments; - static DCmdFactory* _DCmdFactoryList; + public: DCmdFactory(int num_arguments, uint32_t flags, bool enabled, bool hidden) - : _num_arguments(num_arguments), _enabled(enabled), _hidden(hidden) - , _export_flags(flags), _next(NULL) {} - bool is_enabled() const { return _enabled; } - bool is_hidden() const { return _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; } + int num_arguments() const { return _num_arguments; } + DCmdFactory* next() const { return _next; } virtual DCmd* create_resource_instance(outputStream* output) const = 0; virtual const char* name() const = 0; virtual const char* description() const = 0; @@ -408,22 +430,22 @@ DCmdFactoryImpl(uint32_t flags, bool enabled, bool hidden) : DCmdFactory(DCmdClass::num_arguments(), flags, enabled, hidden) { } // Returns a resourceArea allocated instance - virtual DCmd* create_resource_instance(outputStream* output) const { + DCmd* create_resource_instance(outputStream* output) const { return new DCmdClass(output, false); } - virtual const char* name() const { + const char* name() const { return DCmdClass::name(); } - virtual const char* description() const { + const char* description() const { return DCmdClass::description(); } - virtual const char* impact() const { + const char* impact() const { return DCmdClass::impact(); } - virtual const JavaPermission permission() const { + const JavaPermission permission() const { return DCmdClass::permission(); } - virtual const char* disabled_message() const { + const char* disabled_message() const { return DCmdClass::disabled_message(); } };