src/share/vm/services/diagnosticCommand.cpp

Wed, 03 Jul 2019 20:42:37 +0800

author
aoqi
date
Wed, 03 Jul 2019 20:42:37 +0800
changeset 9637
eef07cd490d4
parent 9122
024be04bb151
permissions
-rw-r--r--

Merge

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

mercurial