26 #include "gc_implementation/shared/vmGCOperations.hpp" 27 #include "runtime/javaCalls.hpp" 28 #include "services/diagnosticArgument.hpp" 29 #include "services/diagnosticCommand.hpp" 30 #include "services/diagnosticFramework.hpp" 31 #include "services/heapDumper.hpp" 32 #include "services/management.hpp" 33 34 void DCmdRegistrant::register_dcmds(){ 35 // Registration of the diagnostic commands 36 // First boolean argument specifies if the command is enabled 37 // Second boolean argument specifies if the command is hidden 38 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HelpDCmd>(true, false)); 39 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VersionDCmd>(true, false)); 40 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CommandLineDCmd>(true, false)); 41 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PrintSystemPropertiesDCmd>(true, false)); 42 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PrintVMFlagsDCmd>(true, false)); 43 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMUptimeDCmd>(true, false)); 44 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SystemGCDCmd>(true, false)); 45 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<RunFinalizationDCmd>(true, false)); 46 #ifndef SERVICES_KERNEL // Heap dumping not supported 47 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HeapDumpDCmd>(true, false)); 48 #endif // SERVICES_KERNEL 49 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassHistogramDCmd>(true, false)); 50 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ThreadDumpDCmd>(true, false)); 51 52 //Enhanced JMX Agent Support 53 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStartRemoteDCmd>(true,false)); 54 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStartLocalDCmd>(true,false)); 55 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStopRemoteDCmd>(true,false)); 56 57 } 58 59 #ifndef HAVE_EXTRA_DCMD 60 void DCmdRegistrant::register_dcmds_ext(){ 61 // Do nothing here 62 } 63 #endif 64 65 66 HelpDCmd::HelpDCmd(outputStream* output, bool heap) : DCmdWithParser(output, heap), 67 _all("-all", "Show help for all commands", "BOOLEAN", false, "false"), 68 _cmd("command name", "The name of the command for which we want help", 235 return dcmd->_dcmdparser.num_arguments(); 236 } else { 237 return 0; 238 } 239 } 240 241 void SystemGCDCmd::execute(TRAPS) { 242 Universe::heap()->collect(GCCause::_java_lang_system_gc); 243 } 244 245 void RunFinalizationDCmd::execute(TRAPS) { 246 Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_System(), 247 true, CHECK); 248 instanceKlassHandle klass(THREAD, k); 249 JavaValue result(T_VOID); 250 JavaCalls::call_static(&result, klass, 251 vmSymbols::run_finalization_name(), 252 vmSymbols::void_method_signature(), CHECK); 253 } 254 255 #ifndef SERVICES_KERNEL // Heap dumping not supported 256 HeapDumpDCmd::HeapDumpDCmd(outputStream* output, bool heap) : 257 DCmdWithParser(output, heap), 258 _filename("filename","Name of the dump file", "STRING",true), 259 _all("-all", "Dump all objects, including unreachable objects", 260 "BOOLEAN", false, "false") { 261 _dcmdparser.add_dcmd_option(&_all); 262 _dcmdparser.add_dcmd_argument(&_filename); 263 } 264 265 void HeapDumpDCmd::execute(TRAPS) { 266 // Request a full GC before heap dump if _all is false 267 // This helps reduces the amount of unreachable objects in the dump 268 // and makes it easier to browse. 269 HeapDumper dumper(!_all.value() /* request GC if _all is false*/); 270 int res = dumper.dump(_filename.value()); 271 if (res == 0) { 272 output()->print_cr("Heap dump file created"); 273 } else { 274 // heap dump failed 275 ResourceMark rm; 276 char* error = dumper.error_as_C_string(); 277 if (error == NULL) { 278 output()->print_cr("Dump failed - reason unknown"); 279 } else { 280 output()->print_cr("%s", error); 281 } 282 } 283 } 284 285 int HeapDumpDCmd::num_arguments() { 286 ResourceMark rm; 287 HeapDumpDCmd* dcmd = new HeapDumpDCmd(NULL, false); 288 if (dcmd != NULL) { 289 DCmdMark mark(dcmd); 290 return dcmd->_dcmdparser.num_arguments(); 291 } else { 292 return 0; 293 } 294 } 295 #endif // SERVICES_KERNEL 296 297 ClassHistogramDCmd::ClassHistogramDCmd(outputStream* output, bool heap) : 298 DCmdWithParser(output, heap), 299 _all("-all", "Inspect all objects, including unreachable objects", 300 "BOOLEAN", false, "false") { 301 _dcmdparser.add_dcmd_option(&_all); 302 } 303 304 void ClassHistogramDCmd::execute(TRAPS) { 305 VM_GC_HeapInspection heapop(output(), 306 !_all.value() /* request full gc if false */, 307 true /* need_prologue */); 308 VMThread::execute(&heapop); 309 } 310 311 int ClassHistogramDCmd::num_arguments() { 312 ResourceMark rm; 313 ClassHistogramDCmd* dcmd = new ClassHistogramDCmd(NULL, false); 314 if (dcmd != NULL) { 315 DCmdMark mark(dcmd); | 26 #include "gc_implementation/shared/vmGCOperations.hpp" 27 #include "runtime/javaCalls.hpp" 28 #include "services/diagnosticArgument.hpp" 29 #include "services/diagnosticCommand.hpp" 30 #include "services/diagnosticFramework.hpp" 31 #include "services/heapDumper.hpp" 32 #include "services/management.hpp" 33 34 void DCmdRegistrant::register_dcmds(){ 35 // Registration of the diagnostic commands 36 // First boolean argument specifies if the command is enabled 37 // Second boolean argument specifies if the command is hidden 38 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HelpDCmd>(true, false)); 39 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VersionDCmd>(true, false)); 40 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CommandLineDCmd>(true, false)); 41 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PrintSystemPropertiesDCmd>(true, false)); 42 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PrintVMFlagsDCmd>(true, false)); 43 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMUptimeDCmd>(true, false)); 44 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SystemGCDCmd>(true, false)); 45 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<RunFinalizationDCmd>(true, false)); 46 #if INCLUDE_SERVICES // Heap dumping supported 47 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HeapDumpDCmd>(true, false)); 48 #endif // INCLUDE_SERVICES 49 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassHistogramDCmd>(true, false)); 50 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ThreadDumpDCmd>(true, false)); 51 52 //Enhanced JMX Agent Support 53 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStartRemoteDCmd>(true,false)); 54 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStartLocalDCmd>(true,false)); 55 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStopRemoteDCmd>(true,false)); 56 57 } 58 59 #ifndef HAVE_EXTRA_DCMD 60 void DCmdRegistrant::register_dcmds_ext(){ 61 // Do nothing here 62 } 63 #endif 64 65 66 HelpDCmd::HelpDCmd(outputStream* output, bool heap) : DCmdWithParser(output, heap), 67 _all("-all", "Show help for all commands", "BOOLEAN", false, "false"), 68 _cmd("command name", "The name of the command for which we want help", 235 return dcmd->_dcmdparser.num_arguments(); 236 } else { 237 return 0; 238 } 239 } 240 241 void SystemGCDCmd::execute(TRAPS) { 242 Universe::heap()->collect(GCCause::_java_lang_system_gc); 243 } 244 245 void RunFinalizationDCmd::execute(TRAPS) { 246 Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_System(), 247 true, CHECK); 248 instanceKlassHandle klass(THREAD, k); 249 JavaValue result(T_VOID); 250 JavaCalls::call_static(&result, klass, 251 vmSymbols::run_finalization_name(), 252 vmSymbols::void_method_signature(), CHECK); 253 } 254 255 #if INCLUDE_SERVICES // Heap dumping supported 256 HeapDumpDCmd::HeapDumpDCmd(outputStream* output, bool heap) : 257 DCmdWithParser(output, heap), 258 _filename("filename","Name of the dump file", "STRING",true), 259 _all("-all", "Dump all objects, including unreachable objects", 260 "BOOLEAN", false, "false") { 261 _dcmdparser.add_dcmd_option(&_all); 262 _dcmdparser.add_dcmd_argument(&_filename); 263 } 264 265 void HeapDumpDCmd::execute(TRAPS) { 266 // Request a full GC before heap dump if _all is false 267 // This helps reduces the amount of unreachable objects in the dump 268 // and makes it easier to browse. 269 HeapDumper dumper(!_all.value() /* request GC if _all is false*/); 270 int res = dumper.dump(_filename.value()); 271 if (res == 0) { 272 output()->print_cr("Heap dump file created"); 273 } else { 274 // heap dump failed 275 ResourceMark rm; 276 char* error = dumper.error_as_C_string(); 277 if (error == NULL) { 278 output()->print_cr("Dump failed - reason unknown"); 279 } else { 280 output()->print_cr("%s", error); 281 } 282 } 283 } 284 285 int HeapDumpDCmd::num_arguments() { 286 ResourceMark rm; 287 HeapDumpDCmd* dcmd = new HeapDumpDCmd(NULL, false); 288 if (dcmd != NULL) { 289 DCmdMark mark(dcmd); 290 return dcmd->_dcmdparser.num_arguments(); 291 } else { 292 return 0; 293 } 294 } 295 #endif // INCLUDE_SERVICES 296 297 ClassHistogramDCmd::ClassHistogramDCmd(outputStream* output, bool heap) : 298 DCmdWithParser(output, heap), 299 _all("-all", "Inspect all objects, including unreachable objects", 300 "BOOLEAN", false, "false") { 301 _dcmdparser.add_dcmd_option(&_all); 302 } 303 304 void ClassHistogramDCmd::execute(TRAPS) { 305 VM_GC_HeapInspection heapop(output(), 306 !_all.value() /* request full gc if false */, 307 true /* need_prologue */); 308 VMThread::execute(&heapop); 309 } 310 311 int ClassHistogramDCmd::num_arguments() { 312 ResourceMark rm; 313 ClassHistogramDCmd* dcmd = new ClassHistogramDCmd(NULL, false); 314 if (dcmd != NULL) { 315 DCmdMark mark(dcmd); |