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