Wed, 03 Jul 2019 20:42:37 +0800
Merge
1 /*
2 * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
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 */
25 #include "precompiled.hpp"
26 #include "classfile/classLoaderStats.hpp"
27 #include "gc_implementation/shared/vmGCOperations.hpp"
28 #include "runtime/javaCalls.hpp"
29 #include "runtime/os.hpp"
30 #include "services/diagnosticArgument.hpp"
31 #include "services/diagnosticCommand.hpp"
32 #include "services/diagnosticFramework.hpp"
33 #include "services/heapDumper.hpp"
34 #include "services/management.hpp"
35 #include "utilities/macros.hpp"
36 #include "oops/objArrayOop.hpp"
38 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
40 void DCmdRegistrant::register_dcmds(){
41 // Registration of the diagnostic commands
42 // First argument specifies which interfaces will export the command
43 // Second argument specifies if the command is enabled
44 // Third argument specifies if the command is hidden
45 uint32_t full_export = DCmd_Source_Internal | DCmd_Source_AttachAPI
46 | DCmd_Source_MBean;
47 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HelpDCmd>(full_export, true, false));
48 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VersionDCmd>(full_export, true, false));
49 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CommandLineDCmd>(full_export, true, false));
50 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PrintSystemPropertiesDCmd>(full_export, true, false));
51 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PrintVMFlagsDCmd>(full_export, true, false));
52 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMDynamicLibrariesDCmd>(full_export, true, false));
53 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMUptimeDCmd>(full_export, true, false));
54 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SystemGCDCmd>(full_export, true, false));
55 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<RunFinalizationDCmd>(full_export, true, false));
56 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HeapInfoDCmd>(full_export, true, false));
57 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<FinalizerInfoDCmd>(full_export, true, false));
58 #if INCLUDE_SERVICES // Heap dumping/inspection supported
59 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HeapDumpDCmd>(DCmd_Source_Internal | DCmd_Source_AttachAPI, true, false));
60 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassHistogramDCmd>(full_export, true, false));
61 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassStatsDCmd>(full_export, true, false));
62 #endif // INCLUDE_SERVICES
63 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ThreadDumpDCmd>(full_export, true, false));
64 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<RotateGCLogDCmd>(full_export, true, false));
65 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassLoaderStatsDCmd>(full_export, true, false));
67 // Enhanced JMX Agent Support
68 // These commands won't be exported via the DiagnosticCommandMBean until an
69 // appropriate permission is created for them
70 uint32_t jmx_agent_export_flags = DCmd_Source_Internal | DCmd_Source_AttachAPI;
71 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStartRemoteDCmd>(jmx_agent_export_flags, true,false));
72 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStartLocalDCmd>(jmx_agent_export_flags, true,false));
73 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStopRemoteDCmd>(jmx_agent_export_flags, true,false));
75 }
77 #ifndef HAVE_EXTRA_DCMD
78 void DCmdRegistrant::register_dcmds_ext(){
79 // Do nothing here
80 }
81 #endif
84 HelpDCmd::HelpDCmd(outputStream* output, bool heap) : DCmdWithParser(output, heap),
85 _all("-all", "Show help for all commands", "BOOLEAN", false, "false"),
86 _cmd("command name", "The name of the command for which we want help",
87 "STRING", false) {
88 _dcmdparser.add_dcmd_option(&_all);
89 _dcmdparser.add_dcmd_argument(&_cmd);
90 };
92 void HelpDCmd::execute(DCmdSource source, TRAPS) {
93 if (_all.value()) {
94 GrowableArray<const char*>* cmd_list = DCmdFactory::DCmd_list(source);
95 for (int i = 0; i < cmd_list->length(); i++) {
96 DCmdFactory* factory = DCmdFactory::factory(source, cmd_list->at(i),
97 strlen(cmd_list->at(i)));
98 output()->print_cr("%s%s", factory->name(),
99 factory->is_enabled() ? "" : " [disabled]");
100 output()->print_cr("\t%s", factory->description());
101 output()->cr();
102 factory = factory->next();
103 }
104 } else if (_cmd.has_value()) {
105 DCmd* cmd = NULL;
106 DCmdFactory* factory = DCmdFactory::factory(source, _cmd.value(),
107 strlen(_cmd.value()));
108 if (factory != NULL) {
109 output()->print_cr("%s%s", factory->name(),
110 factory->is_enabled() ? "" : " [disabled]");
111 output()->print_cr("%s", factory->description());
112 output()->print_cr("\nImpact: %s", factory->impact());
113 JavaPermission p = factory->permission();
114 if(p._class != NULL) {
115 if(p._action != NULL) {
116 output()->print_cr("\nPermission: %s(%s, %s)",
117 p._class, p._name == NULL ? "null" : p._name, p._action);
118 } else {
119 output()->print_cr("\nPermission: %s(%s)",
120 p._class, p._name == NULL ? "null" : p._name);
121 }
122 }
123 output()->cr();
124 cmd = factory->create_resource_instance(output());
125 if (cmd != NULL) {
126 DCmdMark mark(cmd);
127 cmd->print_help(factory->name());
128 }
129 } else {
130 output()->print_cr("Help unavailable : '%s' : No such command", _cmd.value());
131 }
132 } else {
133 output()->print_cr("The following commands are available:");
134 GrowableArray<const char *>* cmd_list = DCmdFactory::DCmd_list(source);
135 for (int i = 0; i < cmd_list->length(); i++) {
136 DCmdFactory* factory = DCmdFactory::factory(source, cmd_list->at(i),
137 strlen(cmd_list->at(i)));
138 output()->print_cr("%s%s", factory->name(),
139 factory->is_enabled() ? "" : " [disabled]");
140 factory = factory->_next;
141 }
142 output()->print_cr("\nFor more information about a specific command use 'help <command>'.");
143 }
144 }
146 int HelpDCmd::num_arguments() {
147 ResourceMark rm;
148 HelpDCmd* dcmd = new HelpDCmd(NULL, false);
149 if (dcmd != NULL) {
150 DCmdMark mark(dcmd);
151 return dcmd->_dcmdparser.num_arguments();
152 } else {
153 return 0;
154 }
155 }
157 void VersionDCmd::execute(DCmdSource source, TRAPS) {
158 output()->print_cr("%s version %s", Abstract_VM_Version::vm_name(),
159 Abstract_VM_Version::vm_release());
160 JDK_Version jdk_version = JDK_Version::current();
161 if (jdk_version.update_version() > 0) {
162 output()->print_cr("JDK %d.%d_%02d", jdk_version.major_version(),
163 jdk_version.minor_version(), jdk_version.update_version());
164 } else {
165 output()->print_cr("JDK %d.%d", jdk_version.major_version(),
166 jdk_version.minor_version());
167 }
168 }
170 PrintVMFlagsDCmd::PrintVMFlagsDCmd(outputStream* output, bool heap) :
171 DCmdWithParser(output, heap),
172 _all("-all", "Print all flags supported by the VM", "BOOLEAN", false, "false") {
173 _dcmdparser.add_dcmd_option(&_all);
174 }
176 void PrintVMFlagsDCmd::execute(DCmdSource source, TRAPS) {
177 if (_all.value()) {
178 CommandLineFlags::printFlags(output(), true);
179 } else {
180 CommandLineFlags::printSetFlags(output());
181 }
182 }
184 int PrintVMFlagsDCmd::num_arguments() {
185 ResourceMark rm;
186 PrintVMFlagsDCmd* dcmd = new PrintVMFlagsDCmd(NULL, false);
187 if (dcmd != NULL) {
188 DCmdMark mark(dcmd);
189 return dcmd->_dcmdparser.num_arguments();
190 } else {
191 return 0;
192 }
193 }
195 void PrintSystemPropertiesDCmd::execute(DCmdSource source, TRAPS) {
196 // load sun.misc.VMSupport
197 Symbol* klass = vmSymbols::sun_misc_VMSupport();
198 Klass* k = SystemDictionary::resolve_or_fail(klass, true, CHECK);
199 instanceKlassHandle ik (THREAD, k);
200 if (ik->should_be_initialized()) {
201 ik->initialize(THREAD);
202 }
203 if (HAS_PENDING_EXCEPTION) {
204 java_lang_Throwable::print(PENDING_EXCEPTION, output());
205 output()->cr();
206 CLEAR_PENDING_EXCEPTION;
207 return;
208 }
210 // invoke the serializePropertiesToByteArray method
211 JavaValue result(T_OBJECT);
212 JavaCallArguments args;
214 Symbol* signature = vmSymbols::serializePropertiesToByteArray_signature();
215 JavaCalls::call_static(&result,
216 ik,
217 vmSymbols::serializePropertiesToByteArray_name(),
218 signature,
219 &args,
220 THREAD);
221 if (HAS_PENDING_EXCEPTION) {
222 java_lang_Throwable::print(PENDING_EXCEPTION, output());
223 output()->cr();
224 CLEAR_PENDING_EXCEPTION;
225 return;
226 }
228 // The result should be a [B
229 oop res = (oop)result.get_jobject();
230 assert(res->is_typeArray(), "just checking");
231 assert(TypeArrayKlass::cast(res->klass())->element_type() == T_BYTE, "just checking");
233 // copy the bytes to the output stream
234 typeArrayOop ba = typeArrayOop(res);
235 jbyte* addr = typeArrayOop(res)->byte_at_addr(0);
236 output()->print_raw((const char*)addr, ba->length());
237 }
239 VMUptimeDCmd::VMUptimeDCmd(outputStream* output, bool heap) :
240 DCmdWithParser(output, heap),
241 _date("-date", "Add a prefix with current date", "BOOLEAN", false, "false") {
242 _dcmdparser.add_dcmd_option(&_date);
243 }
245 void VMUptimeDCmd::execute(DCmdSource source, TRAPS) {
246 if (_date.value()) {
247 output()->date_stamp(true, "", ": ");
248 }
249 output()->time_stamp().update_to(tty->time_stamp().ticks());
250 output()->stamp();
251 output()->print_cr(" s");
252 }
254 int VMUptimeDCmd::num_arguments() {
255 ResourceMark rm;
256 VMUptimeDCmd* dcmd = new VMUptimeDCmd(NULL, false);
257 if (dcmd != NULL) {
258 DCmdMark mark(dcmd);
259 return dcmd->_dcmdparser.num_arguments();
260 } else {
261 return 0;
262 }
263 }
265 void SystemGCDCmd::execute(DCmdSource source, TRAPS) {
266 if (!DisableExplicitGC) {
267 Universe::heap()->collect(GCCause::_java_lang_system_gc);
268 } else {
269 output()->print_cr("Explicit GC is disabled, no GC has been performed.");
270 }
271 }
273 void RunFinalizationDCmd::execute(DCmdSource source, TRAPS) {
274 Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_System(),
275 true, CHECK);
276 instanceKlassHandle klass(THREAD, k);
277 JavaValue result(T_VOID);
278 JavaCalls::call_static(&result, klass,
279 vmSymbols::run_finalization_name(),
280 vmSymbols::void_method_signature(), CHECK);
281 }
283 void HeapInfoDCmd::execute(DCmdSource source, TRAPS) {
284 Universe::heap()->print_on(output());
285 }
287 void FinalizerInfoDCmd::execute(DCmdSource source, TRAPS) {
288 ResourceMark rm;
291 Klass* k = SystemDictionary::resolve_or_null(
292 vmSymbols::finalizer_histogram_klass(), THREAD);
293 assert(k != NULL, "FinalizerHistogram class is not accessible");
295 instanceKlassHandle klass(THREAD, k);
296 JavaValue result(T_ARRAY);
298 // We are calling lang.ref.FinalizerHistogram.getFinalizerHistogram() method
299 // and expect it to return array of FinalizerHistogramEntry as Object[]
301 JavaCalls::call_static(&result, klass,
302 vmSymbols::get_finalizer_histogram_name(),
303 vmSymbols::void_finalizer_histogram_entry_array_signature(), CHECK);
305 objArrayOop result_oop = (objArrayOop) result.get_jobject();
306 if (result_oop->length() == 0) {
307 output()->print_cr("No instances waiting for finalization found");
308 return;
309 }
311 oop foop = result_oop->obj_at(0);
312 InstanceKlass* ik = InstanceKlass::cast(foop->klass());
314 fieldDescriptor count_fd, name_fd;
316 Klass* count_res = ik->find_field(
317 vmSymbols::finalizer_histogram_entry_count_field(), vmSymbols::int_signature(), &count_fd);
319 Klass* name_res = ik->find_field(
320 vmSymbols::finalizer_histogram_entry_name_field(), vmSymbols::string_signature(), &name_fd);
322 assert(count_res != NULL && name_res != NULL, "Unexpected layout of FinalizerHistogramEntry");
324 output()->print_cr("Unreachable instances waiting for finalization");
325 output()->print_cr("#instances class name");
326 output()->print_cr("-----------------------");
328 for (int i = 0; i < result_oop->length(); ++i) {
329 oop element_oop = result_oop->obj_at(i);
330 oop str_oop = element_oop->obj_field(name_fd.offset());
331 char *name = java_lang_String::as_utf8_string(str_oop);
332 int count = element_oop->int_field(count_fd.offset());
333 output()->print_cr("%10d %s", count, name);
334 }
335 }
337 #if INCLUDE_SERVICES // Heap dumping/inspection supported
338 HeapDumpDCmd::HeapDumpDCmd(outputStream* output, bool heap) :
339 DCmdWithParser(output, heap),
340 _filename("filename","Name of the dump file", "STRING",true),
341 _all("-all", "Dump all objects, including unreachable objects",
342 "BOOLEAN", false, "false") {
343 _dcmdparser.add_dcmd_option(&_all);
344 _dcmdparser.add_dcmd_argument(&_filename);
345 }
347 void HeapDumpDCmd::execute(DCmdSource source, TRAPS) {
348 // Request a full GC before heap dump if _all is false
349 // This helps reduces the amount of unreachable objects in the dump
350 // and makes it easier to browse.
351 HeapDumper dumper(!_all.value() /* request GC if _all is false*/);
352 int res = dumper.dump(_filename.value());
353 if (res == 0) {
354 output()->print_cr("Heap dump file created");
355 } else {
356 // heap dump failed
357 ResourceMark rm;
358 char* error = dumper.error_as_C_string();
359 if (error == NULL) {
360 output()->print_cr("Dump failed - reason unknown");
361 } else {
362 output()->print_cr("%s", error);
363 }
364 }
365 }
367 int HeapDumpDCmd::num_arguments() {
368 ResourceMark rm;
369 HeapDumpDCmd* dcmd = new HeapDumpDCmd(NULL, false);
370 if (dcmd != NULL) {
371 DCmdMark mark(dcmd);
372 return dcmd->_dcmdparser.num_arguments();
373 } else {
374 return 0;
375 }
376 }
378 ClassHistogramDCmd::ClassHistogramDCmd(outputStream* output, bool heap) :
379 DCmdWithParser(output, heap),
380 _all("-all", "Inspect all objects, including unreachable objects",
381 "BOOLEAN", false, "false") {
382 _dcmdparser.add_dcmd_option(&_all);
383 }
385 void ClassHistogramDCmd::execute(DCmdSource source, TRAPS) {
386 VM_GC_HeapInspection heapop(output(),
387 !_all.value() /* request full gc if false */);
388 VMThread::execute(&heapop);
389 }
391 int ClassHistogramDCmd::num_arguments() {
392 ResourceMark rm;
393 ClassHistogramDCmd* dcmd = new ClassHistogramDCmd(NULL, false);
394 if (dcmd != NULL) {
395 DCmdMark mark(dcmd);
396 return dcmd->_dcmdparser.num_arguments();
397 } else {
398 return 0;
399 }
400 }
402 #define DEFAULT_COLUMNS "InstBytes,KlassBytes,CpAll,annotations,MethodCount,Bytecodes,MethodAll,ROAll,RWAll,Total"
403 ClassStatsDCmd::ClassStatsDCmd(outputStream* output, bool heap) :
404 DCmdWithParser(output, heap),
405 _csv("-csv", "Print in CSV (comma-separated values) format for spreadsheets",
406 "BOOLEAN", false, "false"),
407 _all("-all", "Show all columns",
408 "BOOLEAN", false, "false"),
409 _help("-help", "Show meaning of all the columns",
410 "BOOLEAN", false, "false"),
411 _columns("columns", "Comma-separated list of all the columns to show. "
412 "If not specified, the following columns are shown: " DEFAULT_COLUMNS,
413 "STRING", false) {
414 _dcmdparser.add_dcmd_option(&_all);
415 _dcmdparser.add_dcmd_option(&_csv);
416 _dcmdparser.add_dcmd_option(&_help);
417 _dcmdparser.add_dcmd_argument(&_columns);
418 }
420 void ClassStatsDCmd::execute(DCmdSource source, TRAPS) {
421 if (!UnlockDiagnosticVMOptions) {
422 output()->print_cr("GC.class_stats command requires -XX:+UnlockDiagnosticVMOptions");
423 return;
424 }
426 VM_GC_HeapInspection heapop(output(),
427 true /* request_full_gc */);
428 heapop.set_csv_format(_csv.value());
429 heapop.set_print_help(_help.value());
430 heapop.set_print_class_stats(true);
431 if (_all.value()) {
432 if (_columns.has_value()) {
433 output()->print_cr("Cannot specify -all and individual columns at the same time");
434 return;
435 } else {
436 heapop.set_columns(NULL);
437 }
438 } else {
439 if (_columns.has_value()) {
440 heapop.set_columns(_columns.value());
441 } else {
442 heapop.set_columns(DEFAULT_COLUMNS);
443 }
444 }
445 VMThread::execute(&heapop);
446 }
448 int ClassStatsDCmd::num_arguments() {
449 ResourceMark rm;
450 ClassStatsDCmd* dcmd = new ClassStatsDCmd(NULL, false);
451 if (dcmd != NULL) {
452 DCmdMark mark(dcmd);
453 return dcmd->_dcmdparser.num_arguments();
454 } else {
455 return 0;
456 }
457 }
458 #endif // INCLUDE_SERVICES
460 ThreadDumpDCmd::ThreadDumpDCmd(outputStream* output, bool heap) :
461 DCmdWithParser(output, heap),
462 _locks("-l", "print java.util.concurrent locks", "BOOLEAN", false, "false") {
463 _dcmdparser.add_dcmd_option(&_locks);
464 }
466 void ThreadDumpDCmd::execute(DCmdSource source, TRAPS) {
467 // thread stacks
468 VM_PrintThreads op1(output(), _locks.value());
469 VMThread::execute(&op1);
471 // JNI global handles
472 VM_PrintJNI op2(output());
473 VMThread::execute(&op2);
475 // Deadlock detection
476 VM_FindDeadlocks op3(output());
477 VMThread::execute(&op3);
478 }
480 int ThreadDumpDCmd::num_arguments() {
481 ResourceMark rm;
482 ThreadDumpDCmd* dcmd = new ThreadDumpDCmd(NULL, false);
483 if (dcmd != NULL) {
484 DCmdMark mark(dcmd);
485 return dcmd->_dcmdparser.num_arguments();
486 } else {
487 return 0;
488 }
489 }
491 // Enhanced JMX Agent support
493 JMXStartRemoteDCmd::JMXStartRemoteDCmd(outputStream *output, bool heap_allocated) :
495 DCmdWithParser(output, heap_allocated),
497 _config_file
498 ("config.file",
499 "set com.sun.management.config.file", "STRING", false),
501 _jmxremote_host
502 ("jmxremote.host",
503 "set com.sun.management.jmxremote.host", "STRING", false),
505 _jmxremote_port
506 ("jmxremote.port",
507 "set com.sun.management.jmxremote.port", "STRING", false),
509 _jmxremote_rmi_port
510 ("jmxremote.rmi.port",
511 "set com.sun.management.jmxremote.rmi.port", "STRING", false),
513 _jmxremote_ssl
514 ("jmxremote.ssl",
515 "set com.sun.management.jmxremote.ssl", "STRING", false),
517 _jmxremote_registry_ssl
518 ("jmxremote.registry.ssl",
519 "set com.sun.management.jmxremote.registry.ssl", "STRING", false),
521 _jmxremote_authenticate
522 ("jmxremote.authenticate",
523 "set com.sun.management.jmxremote.authenticate", "STRING", false),
525 _jmxremote_password_file
526 ("jmxremote.password.file",
527 "set com.sun.management.jmxremote.password.file", "STRING", false),
529 _jmxremote_access_file
530 ("jmxremote.access.file",
531 "set com.sun.management.jmxremote.access.file", "STRING", false),
533 _jmxremote_login_config
534 ("jmxremote.login.config",
535 "set com.sun.management.jmxremote.login.config", "STRING", false),
537 _jmxremote_ssl_enabled_cipher_suites
538 ("jmxremote.ssl.enabled.cipher.suites",
539 "set com.sun.management.jmxremote.ssl.enabled.cipher.suite", "STRING", false),
541 _jmxremote_ssl_enabled_protocols
542 ("jmxremote.ssl.enabled.protocols",
543 "set com.sun.management.jmxremote.ssl.enabled.protocols", "STRING", false),
545 _jmxremote_ssl_need_client_auth
546 ("jmxremote.ssl.need.client.auth",
547 "set com.sun.management.jmxremote.need.client.auth", "STRING", false),
549 _jmxremote_ssl_config_file
550 ("jmxremote.ssl.config.file",
551 "set com.sun.management.jmxremote.ssl_config_file", "STRING", false),
553 // JDP Protocol support
554 _jmxremote_autodiscovery
555 ("jmxremote.autodiscovery",
556 "set com.sun.management.jmxremote.autodiscovery", "STRING", false),
558 _jdp_port
559 ("jdp.port",
560 "set com.sun.management.jdp.port", "INT", false),
562 _jdp_address
563 ("jdp.address",
564 "set com.sun.management.jdp.address", "STRING", false),
566 _jdp_source_addr
567 ("jdp.source_addr",
568 "set com.sun.management.jdp.source_addr", "STRING", false),
570 _jdp_ttl
571 ("jdp.ttl",
572 "set com.sun.management.jdp.ttl", "INT", false),
574 _jdp_pause
575 ("jdp.pause",
576 "set com.sun.management.jdp.pause", "INT", false),
578 _jdp_name
579 ("jdp.name",
580 "set com.sun.management.jdp.name", "STRING", false)
582 {
583 _dcmdparser.add_dcmd_option(&_config_file);
584 _dcmdparser.add_dcmd_option(&_jmxremote_host);
585 _dcmdparser.add_dcmd_option(&_jmxremote_port);
586 _dcmdparser.add_dcmd_option(&_jmxremote_rmi_port);
587 _dcmdparser.add_dcmd_option(&_jmxremote_ssl);
588 _dcmdparser.add_dcmd_option(&_jmxremote_registry_ssl);
589 _dcmdparser.add_dcmd_option(&_jmxremote_authenticate);
590 _dcmdparser.add_dcmd_option(&_jmxremote_password_file);
591 _dcmdparser.add_dcmd_option(&_jmxremote_access_file);
592 _dcmdparser.add_dcmd_option(&_jmxremote_login_config);
593 _dcmdparser.add_dcmd_option(&_jmxremote_ssl_enabled_cipher_suites);
594 _dcmdparser.add_dcmd_option(&_jmxremote_ssl_enabled_protocols);
595 _dcmdparser.add_dcmd_option(&_jmxremote_ssl_need_client_auth);
596 _dcmdparser.add_dcmd_option(&_jmxremote_ssl_config_file);
597 _dcmdparser.add_dcmd_option(&_jmxremote_autodiscovery);
598 _dcmdparser.add_dcmd_option(&_jdp_port);
599 _dcmdparser.add_dcmd_option(&_jdp_address);
600 _dcmdparser.add_dcmd_option(&_jdp_source_addr);
601 _dcmdparser.add_dcmd_option(&_jdp_ttl);
602 _dcmdparser.add_dcmd_option(&_jdp_pause);
603 _dcmdparser.add_dcmd_option(&_jdp_name);
604 }
607 int JMXStartRemoteDCmd::num_arguments() {
608 ResourceMark rm;
609 JMXStartRemoteDCmd* dcmd = new JMXStartRemoteDCmd(NULL, false);
610 if (dcmd != NULL) {
611 DCmdMark mark(dcmd);
612 return dcmd->_dcmdparser.num_arguments();
613 } else {
614 return 0;
615 }
616 }
619 void JMXStartRemoteDCmd::execute(DCmdSource source, TRAPS) {
620 ResourceMark rm(THREAD);
621 HandleMark hm(THREAD);
623 // Load and initialize the sun.management.Agent class
624 // invoke startRemoteManagementAgent(string) method to start
625 // the remote management server.
626 // throw java.lang.NoSuchMethodError if the method doesn't exist
628 Handle loader = Handle(THREAD, SystemDictionary::java_system_loader());
629 Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::sun_management_Agent(), loader, Handle(), true, CHECK);
630 instanceKlassHandle ik (THREAD, k);
632 JavaValue result(T_VOID);
634 // Pass all command line arguments to java as key=value,...
635 // All checks are done on java side
637 int len = 0;
638 stringStream options;
639 char comma[2] = {0,0};
641 // Leave default values on Agent.class side and pass only
642 // agruments explicitly set by user. All arguments passed
643 // to jcmd override properties with the same name set by
644 // command line with -D or by managmenent.properties
645 // file.
646 #define PUT_OPTION(a) \
647 if ( (a).is_set() ){ \
648 options.print(\
649 ( *((a).type()) == 'I' ) ? "%scom.sun.management.%s=%d" : "%scom.sun.management.%s=%s",\
650 comma, (a).name(), (a).value()); \
651 comma[0] = ','; \
652 }
654 PUT_OPTION(_config_file);
655 PUT_OPTION(_jmxremote_host);
656 PUT_OPTION(_jmxremote_port);
657 PUT_OPTION(_jmxremote_rmi_port);
658 PUT_OPTION(_jmxremote_ssl);
659 PUT_OPTION(_jmxremote_registry_ssl);
660 PUT_OPTION(_jmxremote_authenticate);
661 PUT_OPTION(_jmxremote_password_file);
662 PUT_OPTION(_jmxremote_access_file);
663 PUT_OPTION(_jmxremote_login_config);
664 PUT_OPTION(_jmxremote_ssl_enabled_cipher_suites);
665 PUT_OPTION(_jmxremote_ssl_enabled_protocols);
666 PUT_OPTION(_jmxremote_ssl_need_client_auth);
667 PUT_OPTION(_jmxremote_ssl_config_file);
668 PUT_OPTION(_jmxremote_autodiscovery);
669 PUT_OPTION(_jdp_port);
670 PUT_OPTION(_jdp_address);
671 PUT_OPTION(_jdp_source_addr);
672 PUT_OPTION(_jdp_ttl);
673 PUT_OPTION(_jdp_pause);
674 PUT_OPTION(_jdp_name);
676 #undef PUT_OPTION
678 Handle str = java_lang_String::create_from_str(options.as_string(), CHECK);
679 JavaCalls::call_static(&result, ik, vmSymbols::startRemoteAgent_name(), vmSymbols::string_void_signature(), str, CHECK);
680 }
682 JMXStartLocalDCmd::JMXStartLocalDCmd(outputStream *output, bool heap_allocated) :
683 DCmd(output, heap_allocated) {
684 // do nothing
685 }
687 void JMXStartLocalDCmd::execute(DCmdSource source, TRAPS) {
688 ResourceMark rm(THREAD);
689 HandleMark hm(THREAD);
691 // Load and initialize the sun.management.Agent class
692 // invoke startLocalManagementAgent(void) method to start
693 // the local management server
694 // throw java.lang.NoSuchMethodError if method doesn't exist
696 Handle loader = Handle(THREAD, SystemDictionary::java_system_loader());
697 Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::sun_management_Agent(), loader, Handle(), true, CHECK);
698 instanceKlassHandle ik (THREAD, k);
700 JavaValue result(T_VOID);
701 JavaCalls::call_static(&result, ik, vmSymbols::startLocalAgent_name(), vmSymbols::void_method_signature(), CHECK);
702 }
704 void JMXStopRemoteDCmd::execute(DCmdSource source, TRAPS) {
705 ResourceMark rm(THREAD);
706 HandleMark hm(THREAD);
708 // Load and initialize the sun.management.Agent class
709 // invoke stopRemoteManagementAgent method to stop the
710 // management server
711 // throw java.lang.NoSuchMethodError if method doesn't exist
713 Handle loader = Handle(THREAD, SystemDictionary::java_system_loader());
714 Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::sun_management_Agent(), loader, Handle(), true, CHECK);
715 instanceKlassHandle ik (THREAD, k);
717 JavaValue result(T_VOID);
718 JavaCalls::call_static(&result, ik, vmSymbols::stopRemoteAgent_name(), vmSymbols::void_method_signature(), CHECK);
719 }
721 VMDynamicLibrariesDCmd::VMDynamicLibrariesDCmd(outputStream *output, bool heap_allocated) :
722 DCmd(output, heap_allocated) {
723 // do nothing
724 }
726 void VMDynamicLibrariesDCmd::execute(DCmdSource source, TRAPS) {
727 os::print_dll_info(output());
728 output()->cr();
729 }
731 void RotateGCLogDCmd::execute(DCmdSource source, TRAPS) {
732 if (UseGCLogFileRotation) {
733 VM_RotateGCLog rotateop(output());
734 VMThread::execute(&rotateop);
735 } else {
736 output()->print_cr("Target VM does not support GC log file rotation.");
737 }
738 }