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