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