src/share/vm/services/diagnosticFramework.hpp
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
* 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.
@@ -32,10 +32,26 @@
#include "runtime/vm_version.hpp"
#include "runtime/vmThread.hpp"
#include "utilities/ostream.hpp"
+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;
+};
+
// 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 {
@@ -111,30 +127,34 @@
// 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;
- const char* _description;
- const char* _impact;
- int _num_arguments;
- bool _is_enabled;
+ 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 */
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; }
static bool by_name(void* name, DCmdInfo* info);
};
@@ -142,52 +162,76 @@
// 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:
- const char* _name;
- const char* _description;
- const char* _type;
- const char* _default_string;
- bool _mandatory;
- bool _option;
- int _position;
+ const char* _name; /* Option/Argument name*/
+ const char* _description; /* Short description */
+ const char* _type; /* Type: STRING, BOOLEAN, etc. */
+ const char* _default_string; /* Default value in a parsable string */
+ bool _mandatory; /* True if the option/argument is mandatory */
+ bool _option; /* True if it is an option, false if it is an argument */
+ /* (see diagnosticFramework.hpp for option/argument definitions) */
+ bool _multiple; /* True is the option can be specified several time */
+ int _position; /* Expected position for this argument (this field is */
+ /* meaningless for options) */
public:
DCmdArgumentInfo(const char* name, const char* description, const char* type,
- const char* default_string, bool mandatory, bool option) {
+ const char* default_string, bool mandatory, bool option,
+ bool multiple) {
this->_name = name;
this->_description = description;
this->_type = type;
this->_default_string = default_string;
this->_option = option;
this->_mandatory = mandatory;
this->_option = option;
+ this->_multiple = multiple;
this->_position = -1;
}
DCmdArgumentInfo(const char* name, const char* description, const char* type,
const char* default_string, bool mandatory, bool option,
- int position) {
+ bool multiple, int position) {
this->_name = name;
this->_description = description;
this->_type = type;
this->_default_string = default_string;
this->_option = option;
this->_mandatory = mandatory;
this->_option = option;
+ this->_multiple = multiple;
this->_position = position;
}
const char* name() const { return _name; }
const char* description() const { return _description; }
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; }
};
// 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.
+// The DCmdParser parse 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 relatively 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.
class DCmdParser {
private:
GenDCmdArgument* _options;
GenDCmdArgument* _arguments_list;
char _delim;
@@ -247,10 +291,11 @@
// 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.
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; }
outputStream* output() { return _output; }
bool is_heap_allocated() { return _is_heap_allocated; }
virtual void print_help(const char* name) {
output()->print_cr("Syntax: %s", name);
@@ -261,11 +306,11 @@
if (has_arg) {
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
"The argument list of this diagnostic command should be empty.");
}
}
- virtual void execute(TRAPS) { }
+ virtual void execute(DCmdSource source, TRAPS) { }
virtual void reset(TRAPS) { }
virtual void cleanup() { }
// support for the JMX interface
virtual GrowableArray<const char*>* argument_name_array() {
@@ -276,11 +321,11 @@
GrowableArray<DCmdArgumentInfo*>* array = new GrowableArray<DCmdArgumentInfo*>(0);
return array;
}
// main method to invoke the framework
- static void parse_and_execute(outputStream* out, const char* cmdline,
+ static void parse_and_execute(DCmdSource source, outputStream* out, const char* cmdline,
char delim, TRAPS);
};
class DCmdWithParser : public DCmd {
protected:
@@ -289,13 +334,14 @@
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; }
virtual void parse(CmdLine *line, char delim, TRAPS);
- virtual void execute(TRAPS) { }
+ virtual void execute(DCmdSource source, TRAPS) { }
virtual void reset(TRAPS);
virtual void cleanup();
virtual void print_help(const char* name);
virtual GrowableArray<const char*>* argument_name_array();
virtual GrowableArray<DCmdArgumentInfo*>* argument_info_array();
@@ -321,10 +367,12 @@
// has to be registered to make the diagnostic command available (see
// management.cpp)
class DCmdFactory: public CHeapObj<mtInternal> {
private:
static Mutex* _dcmdFactory_lock;
+ static bool _send_jmx_notification;
+ static bool _has_pending_jmx_notification;
// 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
@@ -331,53 +379,67 @@
// instantiating the command.
bool _enabled;
// When hidden, a diagnostic command doesn't appear in the list of commands
// provided by the 'help' command.
bool _hidden;
+ uint32_t _export_flags;
int _num_arguments;
static DCmdFactory* _DCmdFactoryList;
public:
- DCmdFactory(int num_arguments, bool enabled, bool hidden) {
+ 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; }
void set_enabled(bool b) { _enabled = b; }
bool is_hidden() const { return _hidden; }
void set_hidden(bool b) { _hidden = b; }
+ uint32_t export_flags() { return _export_flags; }
+ void set_export_flags(uint32_t f) { _export_flags = f; }
int num_arguments() { return _num_arguments; }
DCmdFactory* next() { return _next; }
virtual DCmd* create_Cheap_instance(outputStream* output) = 0;
virtual DCmd* create_resource_instance(outputStream* output) = 0;
virtual const char* name() const = 0;
virtual const char* description() const = 0;
virtual const char* impact() const = 0;
+ virtual const JavaPermission permission() const = 0;
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);
- static DCmdFactory* factory(const char* cmd, size_t len);
+ static DCmdFactory* factory(DCmdSource source, const char* cmd, size_t len);
// Returns a C-heap allocated diagnostic command for the given command line
- static DCmd* create_global_DCmd(CmdLine &line, outputStream* out, TRAPS);
+ static DCmd* create_global_DCmd(DCmdSource source, CmdLine &line, outputStream* out, TRAPS);
// Returns a resourceArea allocated diagnostic command for the given command line
- static DCmd* create_local_DCmd(CmdLine &line, outputStream* out, TRAPS);
- static GrowableArray<const char*>* DCmd_list();
- static GrowableArray<DCmdInfo*>* DCmdInfo_list();
+ 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);
+
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:
- DCmdFactoryImpl(bool enabled, bool hidden) :
- DCmdFactory(DCmdClass::num_arguments(), enabled, hidden) { }
+ DCmdFactoryImpl(uint32_t flags, bool enabled, bool hidden) :
+ DCmdFactory(DCmdClass::num_arguments(), flags, enabled, hidden) { }
// Returns a C-heap allocated instance
virtual DCmd* create_Cheap_instance(outputStream* output) {
return new (ResourceObj::C_HEAP, mtInternal) DCmdClass(output, true);
}
// Returns a resourceArea allocated instance
@@ -391,10 +453,13 @@
return DCmdClass::description();
}
virtual const char* impact() const {
return DCmdClass::impact();
}
+ virtual const JavaPermission permission() const {
+ return DCmdClass::permission();
+ }
virtual const char* disabled_message() const {
return DCmdClass::disabled_message();
}
};