comparison src/share/vm/services/diagnosticCommand.cpp @ 10215:31a4e55f8c9d

8004095: Add support for JMX interface to Diagnostic Framework and Commands Reviewed-by: acorn, sla
author fparain
date Fri, 03 May 2013 05:05:31 -0700
parents 3c9bc17b9403
children f2110083203d
comparison
equal deleted inserted replaced
10167:8fe2542bdc8d 10215:31a4e55f8c9d
32 #include "services/management.hpp" 32 #include "services/management.hpp"
33 #include "utilities/macros.hpp" 33 #include "utilities/macros.hpp"
34 34
35 void DCmdRegistrant::register_dcmds(){ 35 void DCmdRegistrant::register_dcmds(){
36 // Registration of the diagnostic commands 36 // Registration of the diagnostic commands
37 // First boolean argument specifies if the command is enabled 37 // First argument specifies which interfaces will export the command
38 // Second boolean argument specifies if the command is hidden 38 // Second argument specifies if the command is enabled
39 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HelpDCmd>(true, false)); 39 // Third argument specifies if the command is hidden
40 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VersionDCmd>(true, false)); 40 uint32_t full_export = DCmd_Source_Internal | DCmd_Source_AttachAPI
41 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CommandLineDCmd>(true, false)); 41 | DCmd_Source_MBean;
42 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PrintSystemPropertiesDCmd>(true, false)); 42 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HelpDCmd>(full_export, true, false));
43 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PrintVMFlagsDCmd>(true, false)); 43 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VersionDCmd>(full_export, true, false));
44 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMUptimeDCmd>(true, false)); 44 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CommandLineDCmd>(full_export, true, false));
45 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SystemGCDCmd>(true, false)); 45 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PrintSystemPropertiesDCmd>(full_export, true, false));
46 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<RunFinalizationDCmd>(true, false)); 46 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PrintVMFlagsDCmd>(full_export, true, false));
47 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMUptimeDCmd>(full_export, true, false));
48 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SystemGCDCmd>(full_export, true, false));
49 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<RunFinalizationDCmd>(full_export, true, false));
47 #if INCLUDE_SERVICES // Heap dumping/inspection supported 50 #if INCLUDE_SERVICES // Heap dumping/inspection supported
48 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HeapDumpDCmd>(true, false)); 51 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HeapDumpDCmd>(full_export, true, false));
49 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassHistogramDCmd>(true, false)); 52 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassHistogramDCmd>(full_export, true, false));
50 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassStatsDCmd>(true, false)); 53 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassStatsDCmd>(full_export, true, false));
51 #endif // INCLUDE_SERVICES 54 #endif // INCLUDE_SERVICES
52 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ThreadDumpDCmd>(true, false)); 55 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ThreadDumpDCmd>(full_export, true, false));
53 //Enhanced JMX Agent Support 56
54 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStartRemoteDCmd>(true,false)); 57 // Enhanced JMX Agent Support
55 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStartLocalDCmd>(true,false)); 58 // These commands won't be exported via the DiagnosticCommandMBean until an
56 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStopRemoteDCmd>(true,false)); 59 // appropriate permission is created for them
60 uint32_t jmx_agent_export_flags = DCmd_Source_Internal | DCmd_Source_AttachAPI;
61 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStartRemoteDCmd>(jmx_agent_export_flags, true,false));
62 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStartLocalDCmd>(jmx_agent_export_flags, true,false));
63 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStopRemoteDCmd>(jmx_agent_export_flags, true,false));
57 64
58 } 65 }
59 66
60 #ifndef HAVE_EXTRA_DCMD 67 #ifndef HAVE_EXTRA_DCMD
61 void DCmdRegistrant::register_dcmds_ext(){ 68 void DCmdRegistrant::register_dcmds_ext(){
70 "STRING", false) { 77 "STRING", false) {
71 _dcmdparser.add_dcmd_option(&_all); 78 _dcmdparser.add_dcmd_option(&_all);
72 _dcmdparser.add_dcmd_argument(&_cmd); 79 _dcmdparser.add_dcmd_argument(&_cmd);
73 }; 80 };
74 81
75 void HelpDCmd::execute(TRAPS) { 82 void HelpDCmd::execute(DCmdSource source, TRAPS) {
76 if (_all.value()) { 83 if (_all.value()) {
77 GrowableArray<const char*>* cmd_list = DCmdFactory::DCmd_list(); 84 GrowableArray<const char*>* cmd_list = DCmdFactory::DCmd_list(source);
78 for (int i = 0; i < cmd_list->length(); i++) { 85 for (int i = 0; i < cmd_list->length(); i++) {
79 DCmdFactory* factory = DCmdFactory::factory(cmd_list->at(i), 86 DCmdFactory* factory = DCmdFactory::factory(source, cmd_list->at(i),
80 strlen(cmd_list->at(i))); 87 strlen(cmd_list->at(i)));
81 if (!factory->is_hidden()) { 88 output()->print_cr("%s%s", factory->name(),
82 output()->print_cr("%s%s", factory->name(), 89 factory->is_enabled() ? "" : " [disabled]");
83 factory->is_enabled() ? "" : " [disabled]"); 90 output()->print_cr("\t%s", factory->description());
84 output()->print_cr("\t%s", factory->description()); 91 output()->cr();
85 output()->cr();
86 }
87 factory = factory->next(); 92 factory = factory->next();
88 } 93 }
89 } else if (_cmd.has_value()) { 94 } else if (_cmd.has_value()) {
90 DCmd* cmd = NULL; 95 DCmd* cmd = NULL;
91 DCmdFactory* factory = DCmdFactory::factory(_cmd.value(), 96 DCmdFactory* factory = DCmdFactory::factory(source, _cmd.value(),
92 strlen(_cmd.value())); 97 strlen(_cmd.value()));
93 if (factory != NULL) { 98 if (factory != NULL) {
94 output()->print_cr("%s%s", factory->name(), 99 output()->print_cr("%s%s", factory->name(),
95 factory->is_enabled() ? "" : " [disabled]"); 100 factory->is_enabled() ? "" : " [disabled]");
96 output()->print_cr(factory->description()); 101 output()->print_cr(factory->description());
97 output()->print_cr("\nImpact: %s", factory->impact()); 102 output()->print_cr("\nImpact: %s", factory->impact());
103 JavaPermission p = factory->permission();
104 if(p._class != NULL) {
105 if(p._action != NULL) {
106 output()->print_cr("\nPermission: %s(%s, %s)",
107 p._class, p._name == NULL ? "null" : p._name, p._action);
108 } else {
109 output()->print_cr("\nPermission: %s(%s)",
110 p._class, p._name == NULL ? "null" : p._name);
111 }
112 }
98 output()->cr(); 113 output()->cr();
99 cmd = factory->create_resource_instance(output()); 114 cmd = factory->create_resource_instance(output());
100 if (cmd != NULL) { 115 if (cmd != NULL) {
101 DCmdMark mark(cmd); 116 DCmdMark mark(cmd);
102 cmd->print_help(factory->name()); 117 cmd->print_help(factory->name());
104 } else { 119 } else {
105 output()->print_cr("Help unavailable : '%s' : No such command", _cmd.value()); 120 output()->print_cr("Help unavailable : '%s' : No such command", _cmd.value());
106 } 121 }
107 } else { 122 } else {
108 output()->print_cr("The following commands are available:"); 123 output()->print_cr("The following commands are available:");
109 GrowableArray<const char *>* cmd_list = DCmdFactory::DCmd_list(); 124 GrowableArray<const char *>* cmd_list = DCmdFactory::DCmd_list(source);
110 for (int i = 0; i < cmd_list->length(); i++) { 125 for (int i = 0; i < cmd_list->length(); i++) {
111 DCmdFactory* factory = DCmdFactory::factory(cmd_list->at(i), 126 DCmdFactory* factory = DCmdFactory::factory(source, cmd_list->at(i),
112 strlen(cmd_list->at(i))); 127 strlen(cmd_list->at(i)));
113 if (!factory->is_hidden()) { 128 output()->print_cr("%s%s", factory->name(),
114 output()->print_cr("%s%s", factory->name(), 129 factory->is_enabled() ? "" : " [disabled]");
115 factory->is_enabled() ? "" : " [disabled]");
116 }
117 factory = factory->_next; 130 factory = factory->_next;
118 } 131 }
119 output()->print_cr("\nFor more information about a specific command use 'help <command>'."); 132 output()->print_cr("\nFor more information about a specific command use 'help <command>'.");
120 } 133 }
121 } 134 }
129 } else { 142 } else {
130 return 0; 143 return 0;
131 } 144 }
132 } 145 }
133 146
134 void VersionDCmd::execute(TRAPS) { 147 void VersionDCmd::execute(DCmdSource source, TRAPS) {
135 output()->print_cr("%s version %s", Abstract_VM_Version::vm_name(), 148 output()->print_cr("%s version %s", Abstract_VM_Version::vm_name(),
136 Abstract_VM_Version::vm_release()); 149 Abstract_VM_Version::vm_release());
137 JDK_Version jdk_version = JDK_Version::current(); 150 JDK_Version jdk_version = JDK_Version::current();
138 if (jdk_version.update_version() > 0) { 151 if (jdk_version.update_version() > 0) {
139 output()->print_cr("JDK %d.%d_%02d", jdk_version.major_version(), 152 output()->print_cr("JDK %d.%d_%02d", jdk_version.major_version(),
148 DCmdWithParser(output, heap), 161 DCmdWithParser(output, heap),
149 _all("-all", "Print all flags supported by the VM", "BOOLEAN", false, "false") { 162 _all("-all", "Print all flags supported by the VM", "BOOLEAN", false, "false") {
150 _dcmdparser.add_dcmd_option(&_all); 163 _dcmdparser.add_dcmd_option(&_all);
151 } 164 }
152 165
153 void PrintVMFlagsDCmd::execute(TRAPS) { 166 void PrintVMFlagsDCmd::execute(DCmdSource source, TRAPS) {
154 if (_all.value()) { 167 if (_all.value()) {
155 CommandLineFlags::printFlags(output(), true); 168 CommandLineFlags::printFlags(output(), true);
156 } else { 169 } else {
157 CommandLineFlags::printSetFlags(output()); 170 CommandLineFlags::printSetFlags(output());
158 } 171 }
167 } else { 180 } else {
168 return 0; 181 return 0;
169 } 182 }
170 } 183 }
171 184
172 void PrintSystemPropertiesDCmd::execute(TRAPS) { 185 void PrintSystemPropertiesDCmd::execute(DCmdSource source, TRAPS) {
173 // load sun.misc.VMSupport 186 // load sun.misc.VMSupport
174 Symbol* klass = vmSymbols::sun_misc_VMSupport(); 187 Symbol* klass = vmSymbols::sun_misc_VMSupport();
175 Klass* k = SystemDictionary::resolve_or_fail(klass, true, CHECK); 188 Klass* k = SystemDictionary::resolve_or_fail(klass, true, CHECK);
176 instanceKlassHandle ik (THREAD, k); 189 instanceKlassHandle ik (THREAD, k);
177 if (ik->should_be_initialized()) { 190 if (ik->should_be_initialized()) {
217 DCmdWithParser(output, heap), 230 DCmdWithParser(output, heap),
218 _date("-date", "Add a prefix with current date", "BOOLEAN", false, "false") { 231 _date("-date", "Add a prefix with current date", "BOOLEAN", false, "false") {
219 _dcmdparser.add_dcmd_option(&_date); 232 _dcmdparser.add_dcmd_option(&_date);
220 } 233 }
221 234
222 void VMUptimeDCmd::execute(TRAPS) { 235 void VMUptimeDCmd::execute(DCmdSource source, TRAPS) {
223 if (_date.value()) { 236 if (_date.value()) {
224 output()->date_stamp(true, "", ": "); 237 output()->date_stamp(true, "", ": ");
225 } 238 }
226 output()->time_stamp().update_to(tty->time_stamp().ticks()); 239 output()->time_stamp().update_to(tty->time_stamp().ticks());
227 output()->stamp(); 240 output()->stamp();
237 } else { 250 } else {
238 return 0; 251 return 0;
239 } 252 }
240 } 253 }
241 254
242 void SystemGCDCmd::execute(TRAPS) { 255 void SystemGCDCmd::execute(DCmdSource source, TRAPS) {
243 Universe::heap()->collect(GCCause::_java_lang_system_gc); 256 if (!DisableExplicitGC) {
244 } 257 Universe::heap()->collect(GCCause::_java_lang_system_gc);
245 258 } else {
246 void RunFinalizationDCmd::execute(TRAPS) { 259 output()->print_cr("Explicit GC is disabled, no GC has been performed.");
260 }
261 }
262
263 void RunFinalizationDCmd::execute(DCmdSource source, TRAPS) {
247 Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_System(), 264 Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_System(),
248 true, CHECK); 265 true, CHECK);
249 instanceKlassHandle klass(THREAD, k); 266 instanceKlassHandle klass(THREAD, k);
250 JavaValue result(T_VOID); 267 JavaValue result(T_VOID);
251 JavaCalls::call_static(&result, klass, 268 JavaCalls::call_static(&result, klass,
261 "BOOLEAN", false, "false") { 278 "BOOLEAN", false, "false") {
262 _dcmdparser.add_dcmd_option(&_all); 279 _dcmdparser.add_dcmd_option(&_all);
263 _dcmdparser.add_dcmd_argument(&_filename); 280 _dcmdparser.add_dcmd_argument(&_filename);
264 } 281 }
265 282
266 void HeapDumpDCmd::execute(TRAPS) { 283 void HeapDumpDCmd::execute(DCmdSource source, TRAPS) {
267 // Request a full GC before heap dump if _all is false 284 // Request a full GC before heap dump if _all is false
268 // This helps reduces the amount of unreachable objects in the dump 285 // This helps reduces the amount of unreachable objects in the dump
269 // and makes it easier to browse. 286 // and makes it easier to browse.
270 HeapDumper dumper(!_all.value() /* request GC if _all is false*/); 287 HeapDumper dumper(!_all.value() /* request GC if _all is false*/);
271 int res = dumper.dump(_filename.value()); 288 int res = dumper.dump(_filename.value());
299 _all("-all", "Inspect all objects, including unreachable objects", 316 _all("-all", "Inspect all objects, including unreachable objects",
300 "BOOLEAN", false, "false") { 317 "BOOLEAN", false, "false") {
301 _dcmdparser.add_dcmd_option(&_all); 318 _dcmdparser.add_dcmd_option(&_all);
302 } 319 }
303 320
304 void ClassHistogramDCmd::execute(TRAPS) { 321 void ClassHistogramDCmd::execute(DCmdSource source, TRAPS) {
305 VM_GC_HeapInspection heapop(output(), 322 VM_GC_HeapInspection heapop(output(),
306 !_all.value() /* request full gc if false */, 323 !_all.value() /* request full gc if false */,
307 true /* need_prologue */); 324 true /* need_prologue */);
308 VMThread::execute(&heapop); 325 VMThread::execute(&heapop);
309 } 326 }
335 _dcmdparser.add_dcmd_option(&_csv); 352 _dcmdparser.add_dcmd_option(&_csv);
336 _dcmdparser.add_dcmd_option(&_help); 353 _dcmdparser.add_dcmd_option(&_help);
337 _dcmdparser.add_dcmd_argument(&_columns); 354 _dcmdparser.add_dcmd_argument(&_columns);
338 } 355 }
339 356
340 void ClassStatsDCmd::execute(TRAPS) { 357 void ClassStatsDCmd::execute(DCmdSource source, TRAPS) {
341 if (!UnlockDiagnosticVMOptions) { 358 if (!UnlockDiagnosticVMOptions) {
342 output()->print_cr("GC.class_stats command requires -XX:+UnlockDiagnosticVMOptions"); 359 output()->print_cr("GC.class_stats command requires -XX:+UnlockDiagnosticVMOptions");
343 return; 360 return;
344 } 361 }
345 362
382 DCmdWithParser(output, heap), 399 DCmdWithParser(output, heap),
383 _locks("-l", "print java.util.concurrent locks", "BOOLEAN", false, "false") { 400 _locks("-l", "print java.util.concurrent locks", "BOOLEAN", false, "false") {
384 _dcmdparser.add_dcmd_option(&_locks); 401 _dcmdparser.add_dcmd_option(&_locks);
385 } 402 }
386 403
387 void ThreadDumpDCmd::execute(TRAPS) { 404 void ThreadDumpDCmd::execute(DCmdSource source, TRAPS) {
388 // thread stacks 405 // thread stacks
389 VM_PrintThreads op1(output(), _locks.value()); 406 VM_PrintThreads op1(output(), _locks.value());
390 VMThread::execute(&op1); 407 VMThread::execute(&op1);
391 408
392 // JNI global handles 409 // JNI global handles
524 } else { 541 } else {
525 return 0; 542 return 0;
526 } 543 }
527 } 544 }
528 545
529 void JMXStartRemoteDCmd::execute(TRAPS) { 546
547 void JMXStartRemoteDCmd::execute(DCmdSource source, TRAPS) {
530 ResourceMark rm(THREAD); 548 ResourceMark rm(THREAD);
531 HandleMark hm(THREAD); 549 HandleMark hm(THREAD);
532 550
533 // Load and initialize the sun.management.Agent class 551 // Load and initialize the sun.management.Agent class
534 // invoke startRemoteManagementAgent(string) method to start 552 // invoke startRemoteManagementAgent(string) method to start
591 DCmd(output, heap_allocated) 609 DCmd(output, heap_allocated)
592 { 610 {
593 // do nothing 611 // do nothing
594 } 612 }
595 613
596 void JMXStartLocalDCmd::execute(TRAPS) { 614 void JMXStartLocalDCmd::execute(DCmdSource source, TRAPS) {
597 ResourceMark rm(THREAD); 615 ResourceMark rm(THREAD);
598 HandleMark hm(THREAD); 616 HandleMark hm(THREAD);
599 617
600 // Load and initialize the sun.management.Agent class 618 // Load and initialize the sun.management.Agent class
601 // invoke startLocalManagementAgent(void) method to start 619 // invoke startLocalManagementAgent(void) method to start
609 JavaValue result(T_VOID); 627 JavaValue result(T_VOID);
610 JavaCalls::call_static(&result, ik, vmSymbols::startLocalAgent_name(), vmSymbols::void_method_signature(), CHECK); 628 JavaCalls::call_static(&result, ik, vmSymbols::startLocalAgent_name(), vmSymbols::void_method_signature(), CHECK);
611 } 629 }
612 630
613 631
614 void JMXStopRemoteDCmd::execute(TRAPS) { 632 void JMXStopRemoteDCmd::execute(DCmdSource source, TRAPS) {
615 ResourceMark rm(THREAD); 633 ResourceMark rm(THREAD);
616 HandleMark hm(THREAD); 634 HandleMark hm(THREAD);
617 635
618 // Load and initialize the sun.management.Agent class 636 // Load and initialize the sun.management.Agent class
619 // invoke stopRemoteManagementAgent method to stop the 637 // invoke stopRemoteManagementAgent method to stop the