Mercurial > hg > truffle
annotate src/share/vm/services/diagnosticFramework.cpp @ 12207:ff8a09595db3
8017230: Internal Error (jvmtiRedefineClasses.cpp:1662): guarantee(false) failed: insert_space_at() failed
Summary: Handle pending exceptions instead of firing a guarantee()
Reviewed-by: coleenp, dholmes
Contributed-by: serguei.spitsyn@oracle.com
author | sspitsyn |
---|---|
date | Fri, 13 Sep 2013 12:46:40 -0700 |
parents | 31a4e55f8c9d |
children | 78bbf4d43a14 |
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 #include "precompiled.hpp" | |
26 #include "memory/oopFactory.hpp" | |
27 #include "runtime/javaCalls.hpp" | |
28 #include "runtime/mutexLocker.hpp" | |
29 #include "services/diagnosticArgument.hpp" | |
30 #include "services/diagnosticFramework.hpp" | |
31 #include "services/management.hpp" | |
32 | |
33 CmdLine::CmdLine(const char* line, size_t len, bool no_command_name) { | |
34 assert(line != NULL, "Command line string should not be NULL"); | |
35 const char* line_end; | |
36 const char* cmd_end; | |
37 | |
38 _cmd = line; | |
39 line_end = &line[len]; | |
40 | |
41 // Skip whitespace in the beginning of the line. | |
42 while (_cmd < line_end && isspace((int) _cmd[0])) { | |
43 _cmd++; | |
44 } | |
45 cmd_end = _cmd; | |
46 | |
47 if (no_command_name) { | |
48 _cmd = NULL; | |
49 _cmd_len = 0; | |
50 } else { | |
51 // Look for end of the command name | |
52 while (cmd_end < line_end && !isspace((int) cmd_end[0])) { | |
53 cmd_end++; | |
54 } | |
55 _cmd_len = cmd_end - _cmd; | |
56 } | |
57 _args = cmd_end; | |
58 _args_len = line_end - _args; | |
59 } | |
60 | |
61 bool DCmdArgIter::next(TRAPS) { | |
62 if (_len == 0) return false; | |
63 // skipping spaces | |
4932
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4773
diff
changeset
|
64 while (_cursor < _len - 1 && _buffer[_cursor] == _delim) { |
4133 | 65 _cursor++; |
66 } | |
67 // handling end of command line | |
68 if (_cursor >= _len - 1) { | |
69 _cursor = _len - 1; | |
70 _key_addr = &_buffer[_len - 1]; | |
71 _key_len = 0; | |
72 _value_addr = &_buffer[_len - 1]; | |
73 _value_len = 0; | |
74 return false; | |
75 } | |
76 // extracting first item, argument or option name | |
77 _key_addr = &_buffer[_cursor]; | |
6202
5a1f452f8f90
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
4932
diff
changeset
|
78 bool arg_had_quotes = false; |
4133 | 79 while (_cursor <= _len - 1 && _buffer[_cursor] != '=' && _buffer[_cursor] != _delim) { |
80 // argument can be surrounded by single or double quotes | |
81 if (_buffer[_cursor] == '\"' || _buffer[_cursor] == '\'') { | |
82 _key_addr++; | |
83 char quote = _buffer[_cursor]; | |
6202
5a1f452f8f90
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
4932
diff
changeset
|
84 arg_had_quotes = true; |
4133 | 85 while (_cursor < _len - 1) { |
86 _cursor++; | |
87 if (_buffer[_cursor] == quote && _buffer[_cursor - 1] != '\\') { | |
88 break; | |
89 } | |
90 } | |
91 if (_buffer[_cursor] != quote) { | |
92 THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), | |
93 "Format error in diagnostic command arguments", false); | |
94 } | |
95 break; | |
96 } | |
97 _cursor++; | |
98 } | |
99 _key_len = &_buffer[_cursor] - _key_addr; | |
6202
5a1f452f8f90
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
4932
diff
changeset
|
100 if (arg_had_quotes) { |
5a1f452f8f90
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
4932
diff
changeset
|
101 // if the argument was quoted, we need to step past the last quote here |
5a1f452f8f90
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
4932
diff
changeset
|
102 _cursor++; |
5a1f452f8f90
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
4932
diff
changeset
|
103 } |
4133 | 104 // check if the argument has the <key>=<value> format |
105 if (_cursor <= _len -1 && _buffer[_cursor] == '=') { | |
106 _cursor++; | |
107 _value_addr = &_buffer[_cursor]; | |
6202
5a1f452f8f90
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
4932
diff
changeset
|
108 bool value_had_quotes = false; |
4133 | 109 // extract the value |
110 while (_cursor <= _len - 1 && _buffer[_cursor] != _delim) { | |
111 // value can be surrounded by simple or double quotes | |
112 if (_buffer[_cursor] == '\"' || _buffer[_cursor] == '\'') { | |
113 _value_addr++; | |
114 char quote = _buffer[_cursor]; | |
6202
5a1f452f8f90
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
4932
diff
changeset
|
115 value_had_quotes = true; |
4133 | 116 while (_cursor < _len - 1) { |
117 _cursor++; | |
118 if (_buffer[_cursor] == quote && _buffer[_cursor - 1] != '\\') { | |
119 break; | |
120 } | |
121 } | |
122 if (_buffer[_cursor] != quote) { | |
123 THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), | |
124 "Format error in diagnostic command arguments", false); | |
125 } | |
126 break; | |
127 } | |
128 _cursor++; | |
129 } | |
130 _value_len = &_buffer[_cursor] - _value_addr; | |
6202
5a1f452f8f90
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
4932
diff
changeset
|
131 if (value_had_quotes) { |
5a1f452f8f90
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
4932
diff
changeset
|
132 // if the value was quoted, we need to step past the last quote here |
5a1f452f8f90
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
4932
diff
changeset
|
133 _cursor++; |
5a1f452f8f90
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
4932
diff
changeset
|
134 } |
4133 | 135 } else { |
136 _value_addr = NULL; | |
137 _value_len = 0; | |
138 } | |
139 return _key_len != 0; | |
140 } | |
141 | |
142 bool DCmdInfo::by_name(void* cmd_name, DCmdInfo* info) { | |
143 if (info == NULL) return false; | |
144 return strcmp((const char*)cmd_name, info->name()) == 0; | |
145 } | |
146 | |
147 void DCmdParser::add_dcmd_option(GenDCmdArgument* arg) { | |
148 assert(arg != NULL, "Sanity"); | |
149 if (_options == NULL) { | |
150 _options = arg; | |
151 } else { | |
152 GenDCmdArgument* o = _options; | |
153 while (o->next() != NULL) { | |
154 o = o->next(); | |
155 } | |
156 o->set_next(arg); | |
157 } | |
158 arg->set_next(NULL); | |
159 Thread* THREAD = Thread::current(); | |
160 arg->init_value(THREAD); | |
161 if (HAS_PENDING_EXCEPTION) { | |
162 fatal("Initialization must be successful"); | |
163 } | |
164 } | |
165 | |
166 void DCmdParser::add_dcmd_argument(GenDCmdArgument* arg) { | |
167 assert(arg != NULL, "Sanity"); | |
168 if (_arguments_list == NULL) { | |
169 _arguments_list = arg; | |
170 } else { | |
171 GenDCmdArgument* a = _arguments_list; | |
172 while (a->next() != NULL) { | |
173 a = a->next(); | |
174 } | |
175 a->set_next(arg); | |
176 } | |
177 arg->set_next(NULL); | |
178 Thread* THREAD = Thread::current(); | |
179 arg->init_value(THREAD); | |
180 if (HAS_PENDING_EXCEPTION) { | |
181 fatal("Initialization must be successful"); | |
182 } | |
183 } | |
184 | |
185 void DCmdParser::parse(CmdLine* line, char delim, TRAPS) { | |
186 GenDCmdArgument* next_argument = _arguments_list; | |
187 DCmdArgIter iter(line->args_addr(), line->args_len(), delim); | |
188 bool cont = iter.next(CHECK); | |
189 while (cont) { | |
190 GenDCmdArgument* arg = lookup_dcmd_option(iter.key_addr(), | |
191 iter.key_length()); | |
192 if (arg != NULL) { | |
193 arg->read_value(iter.value_addr(), iter.value_length(), CHECK); | |
194 } else { | |
195 if (next_argument != NULL) { | |
196 arg = next_argument; | |
197 arg->read_value(iter.key_addr(), iter.key_length(), CHECK); | |
198 next_argument = next_argument->next(); | |
199 } else { | |
6202
5a1f452f8f90
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
4932
diff
changeset
|
200 const size_t buflen = 120; |
5a1f452f8f90
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
4932
diff
changeset
|
201 const size_t argbuflen = 30; |
5a1f452f8f90
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
4932
diff
changeset
|
202 char buf[buflen]; |
5a1f452f8f90
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
4932
diff
changeset
|
203 char argbuf[argbuflen]; |
5a1f452f8f90
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
4932
diff
changeset
|
204 size_t len = MIN2<size_t>(iter.key_length(), argbuflen - 1); |
5a1f452f8f90
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
4932
diff
changeset
|
205 |
5a1f452f8f90
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
4932
diff
changeset
|
206 strncpy(argbuf, iter.key_addr(), len); |
5a1f452f8f90
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
4932
diff
changeset
|
207 argbuf[len] = '\0'; |
5a1f452f8f90
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
4932
diff
changeset
|
208 jio_snprintf(buf, buflen - 1, "Unknown argument '%s' in diagnostic command.", argbuf); |
5a1f452f8f90
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
4932
diff
changeset
|
209 |
5a1f452f8f90
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
4932
diff
changeset
|
210 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), buf); |
4133 | 211 } |
212 } | |
213 cont = iter.next(CHECK); | |
214 } | |
215 check(CHECK); | |
216 } | |
217 | |
218 GenDCmdArgument* DCmdParser::lookup_dcmd_option(const char* name, size_t len) { | |
219 GenDCmdArgument* arg = _options; | |
220 while (arg != NULL) { | |
221 if (strlen(arg->name()) == len && | |
222 strncmp(name, arg->name(), len) == 0) { | |
223 return arg; | |
224 } | |
225 arg = arg->next(); | |
226 } | |
227 return NULL; | |
228 } | |
229 | |
230 void DCmdParser::check(TRAPS) { | |
6202
5a1f452f8f90
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
4932
diff
changeset
|
231 const size_t buflen = 256; |
5a1f452f8f90
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
4932
diff
changeset
|
232 char buf[buflen]; |
4133 | 233 GenDCmdArgument* arg = _arguments_list; |
234 while (arg != NULL) { | |
235 if (arg->is_mandatory() && !arg->has_value()) { | |
6202
5a1f452f8f90
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
4932
diff
changeset
|
236 jio_snprintf(buf, buflen - 1, "The argument '%s' is mandatory.", arg->name()); |
5a1f452f8f90
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
4932
diff
changeset
|
237 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), buf); |
4133 | 238 } |
239 arg = arg->next(); | |
240 } | |
241 arg = _options; | |
242 while (arg != NULL) { | |
243 if (arg->is_mandatory() && !arg->has_value()) { | |
6202
5a1f452f8f90
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
4932
diff
changeset
|
244 jio_snprintf(buf, buflen - 1, "The option '%s' is mandatory.", arg->name()); |
5a1f452f8f90
7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents:
4932
diff
changeset
|
245 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), buf); |
4133 | 246 } |
247 arg = arg->next(); | |
248 } | |
249 } | |
250 | |
251 void DCmdParser::print_help(outputStream* out, const char* cmd_name) { | |
4773 | 252 out->print("Syntax : %s %s", cmd_name, _options == NULL ? "" : "[options]"); |
4133 | 253 GenDCmdArgument* arg = _arguments_list; |
254 while (arg != NULL) { | |
255 if (arg->is_mandatory()) { | |
256 out->print(" <%s>", arg->name()); | |
257 } else { | |
258 out->print(" [<%s>]", arg->name()); | |
259 } | |
260 arg = arg->next(); | |
261 } | |
262 out->print_cr(""); | |
263 if (_arguments_list != NULL) { | |
264 out->print_cr("\nArguments:"); | |
265 arg = _arguments_list; | |
266 while (arg != NULL) { | |
267 out->print("\t%s : %s %s (%s, ", arg->name(), | |
268 arg->is_mandatory() ? "" : "[optional]", | |
269 arg->description(), arg->type()); | |
270 if (arg->has_default()) { | |
271 out->print(arg->default_string()); | |
272 } else { | |
273 out->print("no default value"); | |
274 } | |
275 out->print_cr(")"); | |
276 arg = arg->next(); | |
277 } | |
278 } | |
279 if (_options != NULL) { | |
280 out->print_cr("\nOptions: (options must be specified using the <key> or <key>=<value> syntax)"); | |
281 arg = _options; | |
282 while (arg != NULL) { | |
283 out->print("\t%s : %s %s (%s, ", arg->name(), | |
284 arg->is_mandatory() ? "" : "[optional]", | |
285 arg->description(), arg->type()); | |
286 if (arg->has_default()) { | |
287 out->print(arg->default_string()); | |
288 } else { | |
289 out->print("no default value"); | |
290 } | |
291 out->print_cr(")"); | |
292 arg = arg->next(); | |
293 } | |
294 } | |
295 } | |
296 | |
297 void DCmdParser::reset(TRAPS) { | |
298 GenDCmdArgument* arg = _arguments_list; | |
299 while (arg != NULL) { | |
300 arg->reset(CHECK); | |
301 arg = arg->next(); | |
302 } | |
303 arg = _options; | |
304 while (arg != NULL) { | |
305 arg->reset(CHECK); | |
306 arg = arg->next(); | |
307 } | |
308 } | |
309 | |
310 void DCmdParser::cleanup() { | |
311 GenDCmdArgument* arg = _arguments_list; | |
312 while (arg != NULL) { | |
313 arg->cleanup(); | |
314 arg = arg->next(); | |
315 } | |
316 arg = _options; | |
317 while (arg != NULL) { | |
318 arg->cleanup(); | |
319 arg = arg->next(); | |
320 } | |
321 } | |
322 | |
323 int DCmdParser::num_arguments() { | |
324 GenDCmdArgument* arg = _arguments_list; | |
325 int count = 0; | |
326 while (arg != NULL) { | |
327 count++; | |
328 arg = arg->next(); | |
329 } | |
330 arg = _options; | |
331 while (arg != NULL) { | |
332 count++; | |
333 arg = arg->next(); | |
334 } | |
335 return count; | |
336 } | |
337 | |
338 GrowableArray<const char *>* DCmdParser::argument_name_array() { | |
339 int count = num_arguments(); | |
340 GrowableArray<const char *>* array = new GrowableArray<const char *>(count); | |
341 GenDCmdArgument* arg = _arguments_list; | |
342 while (arg != NULL) { | |
343 array->append(arg->name()); | |
344 arg = arg->next(); | |
345 } | |
346 arg = _options; | |
347 while (arg != NULL) { | |
348 array->append(arg->name()); | |
349 arg = arg->next(); | |
350 } | |
351 return array; | |
352 } | |
353 | |
354 GrowableArray<DCmdArgumentInfo*>* DCmdParser::argument_info_array() { | |
355 int count = num_arguments(); | |
356 GrowableArray<DCmdArgumentInfo*>* array = new GrowableArray<DCmdArgumentInfo *>(count); | |
357 int idx = 0; | |
358 GenDCmdArgument* arg = _arguments_list; | |
359 while (arg != NULL) { | |
360 array->append(new DCmdArgumentInfo(arg->name(), arg->description(), | |
361 arg->type(), arg->default_string(), arg->is_mandatory(), | |
10215
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
362 false, arg->allow_multiple(), idx)); |
4133 | 363 idx++; |
364 arg = arg->next(); | |
365 } | |
366 arg = _options; | |
367 while (arg != NULL) { | |
368 array->append(new DCmdArgumentInfo(arg->name(), arg->description(), | |
369 arg->type(), arg->default_string(), arg->is_mandatory(), | |
10215
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
370 true, arg->allow_multiple())); |
4133 | 371 arg = arg->next(); |
372 } | |
373 return array; | |
374 } | |
375 | |
376 DCmdFactory* DCmdFactory::_DCmdFactoryList = NULL; | |
10215
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
377 bool DCmdFactory::_has_pending_jmx_notification = false; |
4133 | 378 |
10215
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
379 void DCmd::parse_and_execute(DCmdSource source, outputStream* out, |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
380 const char* cmdline, char delim, TRAPS) { |
4133 | 381 |
382 if (cmdline == NULL) return; // Nothing to do! | |
383 DCmdIter iter(cmdline, '\n'); | |
384 | |
10215
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
385 int count = 0; |
4133 | 386 while (iter.has_next()) { |
10215
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
387 if(source == DCmd_Source_MBean && count > 0) { |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
388 // When diagnostic commands are invoked via JMX, each command line |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
389 // must contains one and only one command because of the Permission |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
390 // checks performed by the DiagnosticCommandMBean |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
391 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
392 "Invalid syntax"); |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
393 } |
4133 | 394 CmdLine line = iter.next(); |
395 if (line.is_stop()) { | |
396 break; | |
397 } | |
398 if (line.is_executable()) { | |
10215
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
399 DCmd* command = DCmdFactory::create_local_DCmd(source, line, out, CHECK); |
4133 | 400 assert(command != NULL, "command error must be handled before this line"); |
401 DCmdMark mark(command); | |
402 command->parse(&line, delim, CHECK); | |
10215
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
403 command->execute(source, CHECK); |
4133 | 404 } |
10215
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
405 count++; |
4133 | 406 } |
407 } | |
408 | |
4773 | 409 void DCmdWithParser::parse(CmdLine* line, char delim, TRAPS) { |
410 _dcmdparser.parse(line, delim, CHECK); | |
411 } | |
412 | |
413 void DCmdWithParser::print_help(const char* name) { | |
414 _dcmdparser.print_help(output(), name); | |
415 } | |
416 | |
417 void DCmdWithParser::reset(TRAPS) { | |
418 _dcmdparser.reset(CHECK); | |
419 } | |
420 | |
421 void DCmdWithParser::cleanup() { | |
422 _dcmdparser.cleanup(); | |
423 } | |
424 | |
425 GrowableArray<const char*>* DCmdWithParser::argument_name_array() { | |
426 return _dcmdparser.argument_name_array(); | |
427 } | |
428 | |
429 GrowableArray<DCmdArgumentInfo*>* DCmdWithParser::argument_info_array() { | |
430 return _dcmdparser.argument_info_array(); | |
431 } | |
432 | |
10215
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
433 void DCmdFactory::push_jmx_notification_request() { |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
434 MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag); |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
435 _has_pending_jmx_notification = true; |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
436 Service_lock->notify_all(); |
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 |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
439 void DCmdFactory::send_notification(TRAPS) { |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
440 DCmdFactory::send_notification_internal(THREAD); |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
441 // Clearing pending exception to avoid premature termination of |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
442 // the service thread |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
443 if (HAS_PENDING_EXCEPTION) { |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
444 CLEAR_PENDING_EXCEPTION; |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
445 } |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
446 } |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
447 void DCmdFactory::send_notification_internal(TRAPS) { |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
448 ResourceMark rm(THREAD); |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
449 HandleMark hm(THREAD); |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
450 bool notif = false; |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
451 { |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
452 MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag); |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
453 notif = _has_pending_jmx_notification; |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
454 _has_pending_jmx_notification = false; |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
455 } |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
456 if (notif) { |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
457 |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
458 Klass* k = Management::sun_management_ManagementFactoryHelper_klass(CHECK); |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
459 instanceKlassHandle mgmt_factory_helper_klass(THREAD, k); |
4133 | 460 |
10215
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
461 JavaValue result(T_OBJECT); |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
462 JavaCalls::call_static(&result, |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
463 mgmt_factory_helper_klass, |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
464 vmSymbols::getDiagnosticCommandMBean_name(), |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
465 vmSymbols::getDiagnosticCommandMBean_signature(), |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
466 CHECK); |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
467 |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
468 instanceOop m = (instanceOop) result.get_jobject(); |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
469 instanceHandle dcmd_mbean_h(THREAD, m); |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
470 |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
471 Klass* k2 = Management::sun_management_DiagnosticCommandImpl_klass(CHECK); |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
472 instanceKlassHandle dcmd_mbean_klass(THREAD, k2); |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
473 |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
474 if (!dcmd_mbean_h->is_a(k2)) { |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
475 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
476 "ManagementFactory.getDiagnosticCommandMBean didn't return a DiagnosticCommandMBean instance"); |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
477 } |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
478 |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
479 JavaValue result2(T_VOID); |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
480 JavaCallArguments args2(dcmd_mbean_h); |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
481 |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
482 JavaCalls::call_virtual(&result2, |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
483 dcmd_mbean_klass, |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
484 vmSymbols::createDiagnosticFrameworkNotification_name(), |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
485 vmSymbols::void_method_signature(), |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
486 &args2, |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
487 CHECK); |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
488 } |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
489 } |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
490 |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
491 Mutex* DCmdFactory::_dcmdFactory_lock = new Mutex(Mutex::leaf, "DCmdFactory", true); |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
492 bool DCmdFactory::_send_jmx_notification = false; |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
493 |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
494 DCmdFactory* DCmdFactory::factory(DCmdSource source, const char* name, size_t len) { |
4133 | 495 MutexLockerEx ml(_dcmdFactory_lock, Mutex::_no_safepoint_check_flag); |
496 DCmdFactory* factory = _DCmdFactoryList; | |
497 while (factory != NULL) { | |
498 if (strlen(factory->name()) == len && | |
499 strncmp(name, factory->name(), len) == 0) { | |
10215
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
500 if(factory->export_flags() & source) { |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
501 return factory; |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
502 } else { |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
503 return NULL; |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
504 } |
4133 | 505 } |
506 factory = factory->_next; | |
507 } | |
508 return NULL; | |
509 } | |
510 | |
511 int DCmdFactory::register_DCmdFactory(DCmdFactory* factory) { | |
512 MutexLockerEx ml(_dcmdFactory_lock, Mutex::_no_safepoint_check_flag); | |
513 factory->_next = _DCmdFactoryList; | |
514 _DCmdFactoryList = factory; | |
10215
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
515 if (_send_jmx_notification && !factory->_hidden |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
516 && (factory->_export_flags & DCmd_Source_MBean)) { |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
517 DCmdFactory::push_jmx_notification_request(); |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
518 } |
4133 | 519 return 0; // Actually, there's no checks for duplicates |
520 } | |
521 | |
10215
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
522 DCmd* DCmdFactory::create_global_DCmd(DCmdSource source, CmdLine &line, |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
523 outputStream* out, TRAPS) { |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
524 DCmdFactory* f = factory(source, line.cmd_addr(), line.cmd_len()); |
4133 | 525 if (f != NULL) { |
526 if (f->is_enabled()) { | |
527 THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), | |
528 f->disabled_message()); | |
529 } | |
530 return f->create_Cheap_instance(out); | |
531 } | |
532 THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), | |
533 "Unknown diagnostic command"); | |
534 } | |
535 | |
10215
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
536 DCmd* DCmdFactory::create_local_DCmd(DCmdSource source, CmdLine &line, |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
537 outputStream* out, TRAPS) { |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
538 DCmdFactory* f = factory(source, line.cmd_addr(), line.cmd_len()); |
4133 | 539 if (f != NULL) { |
540 if (!f->is_enabled()) { | |
541 THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), | |
542 f->disabled_message()); | |
543 } | |
544 return f->create_resource_instance(out); | |
545 } | |
546 THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), | |
547 "Unknown diagnostic command"); | |
548 } | |
549 | |
10215
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
550 GrowableArray<const char*>* DCmdFactory::DCmd_list(DCmdSource source) { |
4133 | 551 MutexLockerEx ml(_dcmdFactory_lock, Mutex::_no_safepoint_check_flag); |
552 GrowableArray<const char*>* array = new GrowableArray<const char*>(); | |
553 DCmdFactory* factory = _DCmdFactoryList; | |
554 while (factory != NULL) { | |
10215
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
555 if (!factory->is_hidden() && (factory->export_flags() & source)) { |
4133 | 556 array->append(factory->name()); |
557 } | |
558 factory = factory->next(); | |
559 } | |
560 return array; | |
561 } | |
562 | |
10215
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
563 GrowableArray<DCmdInfo*>* DCmdFactory::DCmdInfo_list(DCmdSource source ) { |
4133 | 564 MutexLockerEx ml(_dcmdFactory_lock, Mutex::_no_safepoint_check_flag); |
565 GrowableArray<DCmdInfo*>* array = new GrowableArray<DCmdInfo*>(); | |
566 DCmdFactory* factory = _DCmdFactoryList; | |
567 while (factory != NULL) { | |
10215
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
568 if (!factory->is_hidden() && (factory->export_flags() & source)) { |
4133 | 569 array->append(new DCmdInfo(factory->name(), |
570 factory->description(), factory->impact(), | |
10215
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
571 factory->permission(), factory->num_arguments(), |
31a4e55f8c9d
8004095: Add support for JMX interface to Diagnostic Framework and Commands
fparain
parents:
6202
diff
changeset
|
572 factory->is_enabled())); |
4133 | 573 } |
574 factory = factory->next(); | |
575 } | |
576 return array; | |
577 } |