Fri, 01 Feb 2013 23:48:08 +0100
8005012: Add WB APIs to better support NMT testing
Summary: Add WB API functions to enable better NMT testing
Reviewed-by: dholmes, zgu
fparain@3329 | 1 | /* |
acorn@4497 | 2 | * Copyright (c) 2011, 2013, 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" |
fparain@3329 | 33 | |
dsamersoff@3478 | 34 | void DCmdRegistrant::register_dcmds(){ |
dsamersoff@3478 | 35 | // Registration of the diagnostic commands |
dsamersoff@3478 | 36 | // First boolean argument specifies if the command is enabled |
dsamersoff@3478 | 37 | // Second boolean argument specifies if the command is hidden |
dsamersoff@3478 | 38 | DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HelpDCmd>(true, false)); |
dsamersoff@3478 | 39 | DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VersionDCmd>(true, false)); |
dsamersoff@3478 | 40 | DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CommandLineDCmd>(true, false)); |
dsamersoff@3478 | 41 | DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PrintSystemPropertiesDCmd>(true, false)); |
dsamersoff@3478 | 42 | DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PrintVMFlagsDCmd>(true, false)); |
dsamersoff@3478 | 43 | DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMUptimeDCmd>(true, false)); |
dsamersoff@3478 | 44 | DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SystemGCDCmd>(true, false)); |
dsamersoff@3478 | 45 | DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<RunFinalizationDCmd>(true, false)); |
acorn@4497 | 46 | #if INCLUDE_SERVICES // Heap dumping/inspection supported |
dsamersoff@3478 | 47 | DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HeapDumpDCmd>(true, false)); |
acorn@4497 | 48 | DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassHistogramDCmd>(true, false)); |
acorn@4497 | 49 | DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassStatsDCmd>(true, false)); |
jprovino@4165 | 50 | #endif // INCLUDE_SERVICES |
dsamersoff@3478 | 51 | DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ThreadDumpDCmd>(true, false)); |
dsamersoff@3598 | 52 | //Enhanced JMX Agent Support |
dsamersoff@3598 | 53 | DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStartRemoteDCmd>(true,false)); |
dsamersoff@3598 | 54 | DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStartLocalDCmd>(true,false)); |
dsamersoff@3598 | 55 | DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStopRemoteDCmd>(true,false)); |
dsamersoff@3598 | 56 | |
dsamersoff@3478 | 57 | } |
dsamersoff@3478 | 58 | |
dsamersoff@3478 | 59 | #ifndef HAVE_EXTRA_DCMD |
dsamersoff@3478 | 60 | void DCmdRegistrant::register_dcmds_ext(){ |
dsamersoff@3478 | 61 | // Do nothing here |
dsamersoff@3478 | 62 | } |
dsamersoff@3478 | 63 | #endif |
dsamersoff@3478 | 64 | |
dsamersoff@3478 | 65 | |
fparain@3402 | 66 | HelpDCmd::HelpDCmd(outputStream* output, bool heap) : DCmdWithParser(output, heap), |
fparain@3329 | 67 | _all("-all", "Show help for all commands", "BOOLEAN", false, "false"), |
fparain@3329 | 68 | _cmd("command name", "The name of the command for which we want help", |
fparain@3329 | 69 | "STRING", false) { |
fparain@3329 | 70 | _dcmdparser.add_dcmd_option(&_all); |
fparain@3329 | 71 | _dcmdparser.add_dcmd_argument(&_cmd); |
fparain@3329 | 72 | }; |
fparain@3329 | 73 | |
fparain@3329 | 74 | void HelpDCmd::execute(TRAPS) { |
fparain@3329 | 75 | if (_all.value()) { |
fparain@3329 | 76 | GrowableArray<const char*>* cmd_list = DCmdFactory::DCmd_list(); |
fparain@3329 | 77 | for (int i = 0; i < cmd_list->length(); i++) { |
fparain@3329 | 78 | DCmdFactory* factory = DCmdFactory::factory(cmd_list->at(i), |
fparain@3329 | 79 | strlen(cmd_list->at(i))); |
fparain@3329 | 80 | if (!factory->is_hidden()) { |
fparain@3329 | 81 | output()->print_cr("%s%s", factory->name(), |
fparain@3329 | 82 | factory->is_enabled() ? "" : " [disabled]"); |
fparain@3329 | 83 | output()->print_cr("\t%s", factory->description()); |
fparain@3329 | 84 | output()->cr(); |
fparain@3329 | 85 | } |
fparain@3329 | 86 | factory = factory->next(); |
fparain@3329 | 87 | } |
fparain@3329 | 88 | } else if (_cmd.has_value()) { |
fparain@3329 | 89 | DCmd* cmd = NULL; |
fparain@3329 | 90 | DCmdFactory* factory = DCmdFactory::factory(_cmd.value(), |
fparain@3329 | 91 | strlen(_cmd.value())); |
fparain@3329 | 92 | if (factory != NULL) { |
fparain@3329 | 93 | output()->print_cr("%s%s", factory->name(), |
fparain@3329 | 94 | factory->is_enabled() ? "" : " [disabled]"); |
fparain@3329 | 95 | output()->print_cr(factory->description()); |
fparain@3329 | 96 | output()->print_cr("\nImpact: %s", factory->impact()); |
fparain@3402 | 97 | output()->cr(); |
fparain@3329 | 98 | cmd = factory->create_resource_instance(output()); |
fparain@3329 | 99 | if (cmd != NULL) { |
fparain@3329 | 100 | DCmdMark mark(cmd); |
fparain@3402 | 101 | cmd->print_help(factory->name()); |
fparain@3329 | 102 | } |
fparain@3329 | 103 | } else { |
fparain@3329 | 104 | output()->print_cr("Help unavailable : '%s' : No such command", _cmd.value()); |
fparain@3329 | 105 | } |
fparain@3329 | 106 | } else { |
fparain@3329 | 107 | output()->print_cr("The following commands are available:"); |
fparain@3329 | 108 | GrowableArray<const char *>* cmd_list = DCmdFactory::DCmd_list(); |
fparain@3329 | 109 | for (int i = 0; i < cmd_list->length(); i++) { |
fparain@3329 | 110 | DCmdFactory* factory = DCmdFactory::factory(cmd_list->at(i), |
fparain@3329 | 111 | strlen(cmd_list->at(i))); |
fparain@3329 | 112 | if (!factory->is_hidden()) { |
fparain@3329 | 113 | output()->print_cr("%s%s", factory->name(), |
fparain@3329 | 114 | factory->is_enabled() ? "" : " [disabled]"); |
fparain@3329 | 115 | } |
fparain@3329 | 116 | factory = factory->_next; |
fparain@3329 | 117 | } |
fparain@3329 | 118 | output()->print_cr("\nFor more information about a specific command use 'help <command>'."); |
fparain@3329 | 119 | } |
fparain@3329 | 120 | } |
fparain@3329 | 121 | |
fparain@3329 | 122 | int HelpDCmd::num_arguments() { |
fparain@3329 | 123 | ResourceMark rm; |
fparain@3329 | 124 | HelpDCmd* dcmd = new HelpDCmd(NULL, false); |
fparain@3329 | 125 | if (dcmd != NULL) { |
fparain@3329 | 126 | DCmdMark mark(dcmd); |
fparain@3329 | 127 | return dcmd->_dcmdparser.num_arguments(); |
fparain@3329 | 128 | } else { |
fparain@3329 | 129 | return 0; |
fparain@3329 | 130 | } |
fparain@3329 | 131 | } |
fparain@3329 | 132 | |
fparain@3329 | 133 | void VersionDCmd::execute(TRAPS) { |
fparain@3329 | 134 | output()->print_cr("%s version %s", Abstract_VM_Version::vm_name(), |
fparain@3329 | 135 | Abstract_VM_Version::vm_release()); |
fparain@3329 | 136 | JDK_Version jdk_version = JDK_Version::current(); |
fparain@3329 | 137 | if (jdk_version.update_version() > 0) { |
fparain@3329 | 138 | output()->print_cr("JDK %d.%d_%02d", jdk_version.major_version(), |
fparain@3329 | 139 | jdk_version.minor_version(), jdk_version.update_version()); |
fparain@3329 | 140 | } else { |
fparain@3329 | 141 | output()->print_cr("JDK %d.%d", jdk_version.major_version(), |
fparain@3329 | 142 | jdk_version.minor_version()); |
fparain@3329 | 143 | } |
fparain@3329 | 144 | } |
fparain@3402 | 145 | |
fparain@3402 | 146 | PrintVMFlagsDCmd::PrintVMFlagsDCmd(outputStream* output, bool heap) : |
fparain@3402 | 147 | DCmdWithParser(output, heap), |
fparain@3402 | 148 | _all("-all", "Print all flags supported by the VM", "BOOLEAN", false, "false") { |
fparain@3402 | 149 | _dcmdparser.add_dcmd_option(&_all); |
fparain@3402 | 150 | } |
fparain@3402 | 151 | |
fparain@3402 | 152 | void PrintVMFlagsDCmd::execute(TRAPS) { |
fparain@3402 | 153 | if (_all.value()) { |
fparain@3402 | 154 | CommandLineFlags::printFlags(output(), true); |
fparain@3402 | 155 | } else { |
fparain@3402 | 156 | CommandLineFlags::printSetFlags(output()); |
fparain@3402 | 157 | } |
fparain@3402 | 158 | } |
fparain@3402 | 159 | |
fparain@3402 | 160 | int PrintVMFlagsDCmd::num_arguments() { |
fparain@3402 | 161 | ResourceMark rm; |
fparain@3402 | 162 | PrintVMFlagsDCmd* dcmd = new PrintVMFlagsDCmd(NULL, false); |
fparain@3402 | 163 | if (dcmd != NULL) { |
fparain@3402 | 164 | DCmdMark mark(dcmd); |
fparain@3402 | 165 | return dcmd->_dcmdparser.num_arguments(); |
fparain@3402 | 166 | } else { |
fparain@3402 | 167 | return 0; |
fparain@3402 | 168 | } |
fparain@3402 | 169 | } |
fparain@3402 | 170 | |
fparain@3402 | 171 | void PrintSystemPropertiesDCmd::execute(TRAPS) { |
fparain@3402 | 172 | // load sun.misc.VMSupport |
fparain@3402 | 173 | Symbol* klass = vmSymbols::sun_misc_VMSupport(); |
coleenp@4037 | 174 | Klass* k = SystemDictionary::resolve_or_fail(klass, true, CHECK); |
fparain@3402 | 175 | instanceKlassHandle ik (THREAD, k); |
fparain@3402 | 176 | if (ik->should_be_initialized()) { |
fparain@3402 | 177 | ik->initialize(THREAD); |
fparain@3402 | 178 | } |
fparain@3402 | 179 | if (HAS_PENDING_EXCEPTION) { |
fparain@3402 | 180 | java_lang_Throwable::print(PENDING_EXCEPTION, output()); |
fparain@3402 | 181 | output()->cr(); |
fparain@3402 | 182 | CLEAR_PENDING_EXCEPTION; |
fparain@3402 | 183 | return; |
fparain@3402 | 184 | } |
fparain@3402 | 185 | |
fparain@3402 | 186 | // invoke the serializePropertiesToByteArray method |
fparain@3402 | 187 | JavaValue result(T_OBJECT); |
fparain@3402 | 188 | JavaCallArguments args; |
fparain@3402 | 189 | |
fparain@3402 | 190 | Symbol* signature = vmSymbols::serializePropertiesToByteArray_signature(); |
fparain@3402 | 191 | JavaCalls::call_static(&result, |
fparain@3402 | 192 | ik, |
fparain@3402 | 193 | vmSymbols::serializePropertiesToByteArray_name(), |
fparain@3402 | 194 | signature, |
fparain@3402 | 195 | &args, |
fparain@3402 | 196 | THREAD); |
fparain@3402 | 197 | if (HAS_PENDING_EXCEPTION) { |
fparain@3402 | 198 | java_lang_Throwable::print(PENDING_EXCEPTION, output()); |
fparain@3402 | 199 | output()->cr(); |
fparain@3402 | 200 | CLEAR_PENDING_EXCEPTION; |
fparain@3402 | 201 | return; |
fparain@3402 | 202 | } |
fparain@3402 | 203 | |
fparain@3402 | 204 | // The result should be a [B |
fparain@3402 | 205 | oop res = (oop)result.get_jobject(); |
fparain@3402 | 206 | assert(res->is_typeArray(), "just checking"); |
coleenp@4142 | 207 | assert(TypeArrayKlass::cast(res->klass())->element_type() == T_BYTE, "just checking"); |
fparain@3402 | 208 | |
fparain@3402 | 209 | // copy the bytes to the output stream |
fparain@3402 | 210 | typeArrayOop ba = typeArrayOop(res); |
fparain@3402 | 211 | jbyte* addr = typeArrayOop(res)->byte_at_addr(0); |
fparain@3402 | 212 | output()->print_raw((const char*)addr, ba->length()); |
fparain@3402 | 213 | } |
fparain@3402 | 214 | |
fparain@3402 | 215 | VMUptimeDCmd::VMUptimeDCmd(outputStream* output, bool heap) : |
fparain@3402 | 216 | DCmdWithParser(output, heap), |
fparain@3402 | 217 | _date("-date", "Add a prefix with current date", "BOOLEAN", false, "false") { |
fparain@3402 | 218 | _dcmdparser.add_dcmd_option(&_date); |
fparain@3402 | 219 | } |
fparain@3402 | 220 | |
fparain@3402 | 221 | void VMUptimeDCmd::execute(TRAPS) { |
fparain@3402 | 222 | if (_date.value()) { |
fparain@3402 | 223 | output()->date_stamp(true, "", ": "); |
fparain@3402 | 224 | } |
fparain@3402 | 225 | output()->time_stamp().update_to(tty->time_stamp().ticks()); |
fparain@3402 | 226 | output()->stamp(); |
fparain@3402 | 227 | output()->print_cr(" s"); |
fparain@3402 | 228 | } |
fparain@3402 | 229 | |
fparain@3402 | 230 | int VMUptimeDCmd::num_arguments() { |
fparain@3402 | 231 | ResourceMark rm; |
fparain@3402 | 232 | VMUptimeDCmd* dcmd = new VMUptimeDCmd(NULL, false); |
fparain@3402 | 233 | if (dcmd != NULL) { |
fparain@3402 | 234 | DCmdMark mark(dcmd); |
fparain@3402 | 235 | return dcmd->_dcmdparser.num_arguments(); |
fparain@3402 | 236 | } else { |
fparain@3402 | 237 | return 0; |
fparain@3402 | 238 | } |
fparain@3402 | 239 | } |
fparain@3402 | 240 | |
fparain@3402 | 241 | void SystemGCDCmd::execute(TRAPS) { |
fparain@3402 | 242 | Universe::heap()->collect(GCCause::_java_lang_system_gc); |
fparain@3402 | 243 | } |
fparain@3402 | 244 | |
fparain@3402 | 245 | void RunFinalizationDCmd::execute(TRAPS) { |
coleenp@4037 | 246 | Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_System(), |
fparain@3402 | 247 | true, CHECK); |
fparain@3402 | 248 | instanceKlassHandle klass(THREAD, k); |
fparain@3402 | 249 | JavaValue result(T_VOID); |
fparain@3402 | 250 | JavaCalls::call_static(&result, klass, |
fparain@3402 | 251 | vmSymbols::run_finalization_name(), |
fparain@3402 | 252 | vmSymbols::void_method_signature(), CHECK); |
fparain@3402 | 253 | } |
fparain@3402 | 254 | |
acorn@4497 | 255 | #if INCLUDE_SERVICES // Heap dumping/inspection supported |
fparain@3402 | 256 | HeapDumpDCmd::HeapDumpDCmd(outputStream* output, bool heap) : |
fparain@3402 | 257 | DCmdWithParser(output, heap), |
fparain@3402 | 258 | _filename("filename","Name of the dump file", "STRING",true), |
fparain@3402 | 259 | _all("-all", "Dump all objects, including unreachable objects", |
fparain@3402 | 260 | "BOOLEAN", false, "false") { |
fparain@3402 | 261 | _dcmdparser.add_dcmd_option(&_all); |
fparain@3402 | 262 | _dcmdparser.add_dcmd_argument(&_filename); |
fparain@3402 | 263 | } |
fparain@3402 | 264 | |
fparain@3402 | 265 | void HeapDumpDCmd::execute(TRAPS) { |
fparain@3402 | 266 | // Request a full GC before heap dump if _all is false |
fparain@3402 | 267 | // This helps reduces the amount of unreachable objects in the dump |
fparain@3402 | 268 | // and makes it easier to browse. |
fparain@3402 | 269 | HeapDumper dumper(!_all.value() /* request GC if _all is false*/); |
fparain@3402 | 270 | int res = dumper.dump(_filename.value()); |
fparain@3402 | 271 | if (res == 0) { |
fparain@3402 | 272 | output()->print_cr("Heap dump file created"); |
fparain@3402 | 273 | } else { |
fparain@3402 | 274 | // heap dump failed |
fparain@3402 | 275 | ResourceMark rm; |
fparain@3402 | 276 | char* error = dumper.error_as_C_string(); |
fparain@3402 | 277 | if (error == NULL) { |
fparain@3402 | 278 | output()->print_cr("Dump failed - reason unknown"); |
fparain@3402 | 279 | } else { |
fparain@3402 | 280 | output()->print_cr("%s", error); |
fparain@3402 | 281 | } |
fparain@3402 | 282 | } |
fparain@3402 | 283 | } |
fparain@3402 | 284 | |
fparain@3402 | 285 | int HeapDumpDCmd::num_arguments() { |
fparain@3402 | 286 | ResourceMark rm; |
fparain@3402 | 287 | HeapDumpDCmd* dcmd = new HeapDumpDCmd(NULL, false); |
fparain@3402 | 288 | if (dcmd != NULL) { |
fparain@3402 | 289 | DCmdMark mark(dcmd); |
fparain@3402 | 290 | return dcmd->_dcmdparser.num_arguments(); |
fparain@3402 | 291 | } else { |
fparain@3402 | 292 | return 0; |
fparain@3402 | 293 | } |
fparain@3402 | 294 | } |
fparain@3402 | 295 | |
fparain@3402 | 296 | ClassHistogramDCmd::ClassHistogramDCmd(outputStream* output, bool heap) : |
fparain@3402 | 297 | DCmdWithParser(output, heap), |
fparain@3402 | 298 | _all("-all", "Inspect all objects, including unreachable objects", |
fparain@3402 | 299 | "BOOLEAN", false, "false") { |
fparain@3402 | 300 | _dcmdparser.add_dcmd_option(&_all); |
fparain@3402 | 301 | } |
fparain@3402 | 302 | |
fparain@3402 | 303 | void ClassHistogramDCmd::execute(TRAPS) { |
fparain@3402 | 304 | VM_GC_HeapInspection heapop(output(), |
fparain@3402 | 305 | !_all.value() /* request full gc if false */, |
fparain@3402 | 306 | true /* need_prologue */); |
fparain@3402 | 307 | VMThread::execute(&heapop); |
fparain@3402 | 308 | } |
fparain@3402 | 309 | |
fparain@3402 | 310 | int ClassHistogramDCmd::num_arguments() { |
fparain@3402 | 311 | ResourceMark rm; |
fparain@3402 | 312 | ClassHistogramDCmd* dcmd = new ClassHistogramDCmd(NULL, false); |
fparain@3402 | 313 | if (dcmd != NULL) { |
fparain@3402 | 314 | DCmdMark mark(dcmd); |
fparain@3402 | 315 | return dcmd->_dcmdparser.num_arguments(); |
fparain@3402 | 316 | } else { |
fparain@3402 | 317 | return 0; |
fparain@3402 | 318 | } |
fparain@3402 | 319 | } |
fparain@3402 | 320 | |
acorn@4497 | 321 | #define DEFAULT_COLUMNS "InstBytes,KlassBytes,CpAll,annotations,MethodCount,Bytecodes,MethodAll,ROAll,RWAll,Total" |
acorn@4497 | 322 | ClassStatsDCmd::ClassStatsDCmd(outputStream* output, bool heap) : |
acorn@4497 | 323 | DCmdWithParser(output, heap), |
acorn@4497 | 324 | _csv("-csv", "Print in CSV (comma-separated values) format for spreadsheets", |
acorn@4497 | 325 | "BOOLEAN", false, "false"), |
acorn@4497 | 326 | _all("-all", "Show all columns", |
acorn@4497 | 327 | "BOOLEAN", false, "false"), |
acorn@4497 | 328 | _help("-help", "Show meaning of all the columns", |
acorn@4497 | 329 | "BOOLEAN", false, "false"), |
acorn@4497 | 330 | _columns("columns", "Comma-separated list of all the columns to show. " |
acorn@4497 | 331 | "If not specified, the following columns are shown: " DEFAULT_COLUMNS, |
acorn@4497 | 332 | "STRING", false) { |
acorn@4497 | 333 | _dcmdparser.add_dcmd_option(&_all); |
acorn@4497 | 334 | _dcmdparser.add_dcmd_option(&_csv); |
acorn@4497 | 335 | _dcmdparser.add_dcmd_option(&_help); |
acorn@4497 | 336 | _dcmdparser.add_dcmd_argument(&_columns); |
acorn@4497 | 337 | } |
acorn@4497 | 338 | |
acorn@4497 | 339 | void ClassStatsDCmd::execute(TRAPS) { |
acorn@4497 | 340 | if (!UnlockDiagnosticVMOptions) { |
acorn@4497 | 341 | output()->print_cr("GC.class_stats command requires -XX:+UnlockDiagnosticVMOptions"); |
acorn@4497 | 342 | return; |
acorn@4497 | 343 | } |
acorn@4497 | 344 | |
acorn@4497 | 345 | VM_GC_HeapInspection heapop(output(), |
acorn@4497 | 346 | true, /* request_full_gc */ |
acorn@4497 | 347 | true /* need_prologue */); |
acorn@4497 | 348 | heapop.set_csv_format(_csv.value()); |
acorn@4497 | 349 | heapop.set_print_help(_help.value()); |
acorn@4497 | 350 | heapop.set_print_class_stats(true); |
acorn@4497 | 351 | if (_all.value()) { |
acorn@4497 | 352 | if (_columns.has_value()) { |
acorn@4497 | 353 | output()->print_cr("Cannot specify -all and individual columns at the same time"); |
acorn@4497 | 354 | return; |
acorn@4497 | 355 | } else { |
acorn@4497 | 356 | heapop.set_columns(NULL); |
acorn@4497 | 357 | } |
acorn@4497 | 358 | } else { |
acorn@4497 | 359 | if (_columns.has_value()) { |
acorn@4497 | 360 | heapop.set_columns(_columns.value()); |
acorn@4497 | 361 | } else { |
acorn@4497 | 362 | heapop.set_columns(DEFAULT_COLUMNS); |
acorn@4497 | 363 | } |
acorn@4497 | 364 | } |
acorn@4497 | 365 | VMThread::execute(&heapop); |
acorn@4497 | 366 | } |
acorn@4497 | 367 | |
acorn@4497 | 368 | int ClassStatsDCmd::num_arguments() { |
acorn@4497 | 369 | ResourceMark rm; |
acorn@4497 | 370 | ClassStatsDCmd* dcmd = new ClassStatsDCmd(NULL, false); |
acorn@4497 | 371 | if (dcmd != NULL) { |
acorn@4497 | 372 | DCmdMark mark(dcmd); |
acorn@4497 | 373 | return dcmd->_dcmdparser.num_arguments(); |
acorn@4497 | 374 | } else { |
acorn@4497 | 375 | return 0; |
acorn@4497 | 376 | } |
acorn@4497 | 377 | } |
acorn@4497 | 378 | #endif // INCLUDE_SERVICES |
acorn@4497 | 379 | |
fparain@3402 | 380 | ThreadDumpDCmd::ThreadDumpDCmd(outputStream* output, bool heap) : |
fparain@3402 | 381 | DCmdWithParser(output, heap), |
fparain@3402 | 382 | _locks("-l", "print java.util.concurrent locks", "BOOLEAN", false, "false") { |
fparain@3402 | 383 | _dcmdparser.add_dcmd_option(&_locks); |
fparain@3402 | 384 | } |
fparain@3402 | 385 | |
fparain@3402 | 386 | void ThreadDumpDCmd::execute(TRAPS) { |
fparain@3402 | 387 | // thread stacks |
fparain@3402 | 388 | VM_PrintThreads op1(output(), _locks.value()); |
fparain@3402 | 389 | VMThread::execute(&op1); |
fparain@3402 | 390 | |
fparain@3402 | 391 | // JNI global handles |
fparain@3402 | 392 | VM_PrintJNI op2(output()); |
fparain@3402 | 393 | VMThread::execute(&op2); |
fparain@3402 | 394 | |
fparain@3402 | 395 | // Deadlock detection |
fparain@3402 | 396 | VM_FindDeadlocks op3(output()); |
fparain@3402 | 397 | VMThread::execute(&op3); |
fparain@3402 | 398 | } |
fparain@3402 | 399 | |
fparain@3402 | 400 | int ThreadDumpDCmd::num_arguments() { |
fparain@3402 | 401 | ResourceMark rm; |
fparain@3402 | 402 | ThreadDumpDCmd* dcmd = new ThreadDumpDCmd(NULL, false); |
fparain@3402 | 403 | if (dcmd != NULL) { |
fparain@3402 | 404 | DCmdMark mark(dcmd); |
fparain@3402 | 405 | return dcmd->_dcmdparser.num_arguments(); |
fparain@3402 | 406 | } else { |
fparain@3402 | 407 | return 0; |
fparain@3402 | 408 | } |
fparain@3402 | 409 | } |
dsamersoff@3598 | 410 | |
dsamersoff@3598 | 411 | // Enhanced JMX Agent support |
dsamersoff@3598 | 412 | |
dsamersoff@3598 | 413 | JMXStartRemoteDCmd::JMXStartRemoteDCmd(outputStream *output, bool heap_allocated) : |
dsamersoff@3598 | 414 | |
dsamersoff@3598 | 415 | DCmdWithParser(output, heap_allocated), |
dsamersoff@3598 | 416 | |
dsamersoff@3598 | 417 | _config_file |
dsamersoff@3598 | 418 | ("config.file", |
dsamersoff@3598 | 419 | "set com.sun.management.config.file", "STRING", false), |
dsamersoff@3598 | 420 | |
dsamersoff@3598 | 421 | _jmxremote_port |
dsamersoff@3598 | 422 | ("jmxremote.port", |
dsamersoff@3598 | 423 | "set com.sun.management.jmxremote.port", "STRING", false), |
dsamersoff@3598 | 424 | |
dsamersoff@3598 | 425 | _jmxremote_rmi_port |
dsamersoff@3598 | 426 | ("jmxremote.rmi.port", |
dsamersoff@3598 | 427 | "set com.sun.management.jmxremote.rmi.port", "STRING", false), |
dsamersoff@3598 | 428 | |
dsamersoff@3598 | 429 | _jmxremote_ssl |
dsamersoff@3598 | 430 | ("jmxremote.ssl", |
dsamersoff@3598 | 431 | "set com.sun.management.jmxremote.ssl", "STRING", false), |
dsamersoff@3598 | 432 | |
dsamersoff@3598 | 433 | _jmxremote_registry_ssl |
dsamersoff@3598 | 434 | ("jmxremote.registry.ssl", |
dsamersoff@3598 | 435 | "set com.sun.management.jmxremote.registry.ssl", "STRING", false), |
dsamersoff@3598 | 436 | |
dsamersoff@3598 | 437 | _jmxremote_authenticate |
dsamersoff@3598 | 438 | ("jmxremote.authenticate", |
dsamersoff@3598 | 439 | "set com.sun.management.jmxremote.authenticate", "STRING", false), |
dsamersoff@3598 | 440 | |
dsamersoff@3598 | 441 | _jmxremote_password_file |
dsamersoff@3598 | 442 | ("jmxremote.password.file", |
dsamersoff@3598 | 443 | "set com.sun.management.jmxremote.password.file", "STRING", false), |
dsamersoff@3598 | 444 | |
dsamersoff@3598 | 445 | _jmxremote_access_file |
dsamersoff@3598 | 446 | ("jmxremote.access.file", |
dsamersoff@3598 | 447 | "set com.sun.management.jmxremote.access.file", "STRING", false), |
dsamersoff@3598 | 448 | |
dsamersoff@3598 | 449 | _jmxremote_login_config |
dsamersoff@3598 | 450 | ("jmxremote.login.config", |
dsamersoff@3598 | 451 | "set com.sun.management.jmxremote.login.config", "STRING", false), |
dsamersoff@3598 | 452 | |
dsamersoff@3598 | 453 | _jmxremote_ssl_enabled_cipher_suites |
dsamersoff@3598 | 454 | ("jmxremote.ssl.enabled.cipher.suites", |
dsamersoff@3598 | 455 | "set com.sun.management.jmxremote.ssl.enabled.cipher.suite", "STRING", false), |
dsamersoff@3598 | 456 | |
dsamersoff@3598 | 457 | _jmxremote_ssl_enabled_protocols |
dsamersoff@3598 | 458 | ("jmxremote.ssl.enabled.protocols", |
dsamersoff@3598 | 459 | "set com.sun.management.jmxremote.ssl.enabled.protocols", "STRING", false), |
dsamersoff@3598 | 460 | |
dsamersoff@3598 | 461 | _jmxremote_ssl_need_client_auth |
dsamersoff@3598 | 462 | ("jmxremote.ssl.need.client.auth", |
dsamersoff@3598 | 463 | "set com.sun.management.jmxremote.need.client.auth", "STRING", false), |
dsamersoff@3598 | 464 | |
dsamersoff@3598 | 465 | _jmxremote_ssl_config_file |
dsamersoff@3598 | 466 | ("jmxremote.ssl.config.file", |
dsamersoff@3598 | 467 | "set com.sun.management.jmxremote.ssl_config_file", "STRING", false) |
dsamersoff@3598 | 468 | |
dsamersoff@3598 | 469 | { |
dsamersoff@3598 | 470 | _dcmdparser.add_dcmd_option(&_config_file); |
dsamersoff@3598 | 471 | _dcmdparser.add_dcmd_option(&_jmxremote_port); |
dsamersoff@3598 | 472 | _dcmdparser.add_dcmd_option(&_jmxremote_rmi_port); |
dsamersoff@3598 | 473 | _dcmdparser.add_dcmd_option(&_jmxremote_ssl); |
dsamersoff@3598 | 474 | _dcmdparser.add_dcmd_option(&_jmxremote_registry_ssl); |
dsamersoff@3598 | 475 | _dcmdparser.add_dcmd_option(&_jmxremote_authenticate); |
dsamersoff@3598 | 476 | _dcmdparser.add_dcmd_option(&_jmxremote_password_file); |
dsamersoff@3598 | 477 | _dcmdparser.add_dcmd_option(&_jmxremote_access_file); |
dsamersoff@3598 | 478 | _dcmdparser.add_dcmd_option(&_jmxremote_login_config); |
dsamersoff@3598 | 479 | _dcmdparser.add_dcmd_option(&_jmxremote_ssl_enabled_cipher_suites); |
dsamersoff@3598 | 480 | _dcmdparser.add_dcmd_option(&_jmxremote_ssl_enabled_protocols); |
dsamersoff@3598 | 481 | _dcmdparser.add_dcmd_option(&_jmxremote_ssl_need_client_auth); |
dsamersoff@3598 | 482 | _dcmdparser.add_dcmd_option(&_jmxremote_ssl_config_file); |
dsamersoff@3598 | 483 | } |
dsamersoff@3598 | 484 | |
dsamersoff@3598 | 485 | |
dsamersoff@3598 | 486 | int JMXStartRemoteDCmd::num_arguments() { |
dsamersoff@3598 | 487 | ResourceMark rm; |
dsamersoff@3598 | 488 | JMXStartRemoteDCmd* dcmd = new JMXStartRemoteDCmd(NULL, false); |
dsamersoff@3598 | 489 | if (dcmd != NULL) { |
dsamersoff@3598 | 490 | DCmdMark mark(dcmd); |
dsamersoff@3598 | 491 | return dcmd->_dcmdparser.num_arguments(); |
dsamersoff@3598 | 492 | } else { |
dsamersoff@3598 | 493 | return 0; |
dsamersoff@3598 | 494 | } |
dsamersoff@3598 | 495 | } |
dsamersoff@3598 | 496 | |
dsamersoff@3598 | 497 | |
dsamersoff@3598 | 498 | void JMXStartRemoteDCmd::execute(TRAPS) { |
dsamersoff@3598 | 499 | ResourceMark rm(THREAD); |
dsamersoff@3598 | 500 | HandleMark hm(THREAD); |
dsamersoff@3598 | 501 | |
dsamersoff@3598 | 502 | // Load and initialize the sun.management.Agent class |
dsamersoff@3598 | 503 | // invoke startRemoteManagementAgent(string) method to start |
dsamersoff@3598 | 504 | // the remote management server. |
dsamersoff@3598 | 505 | // throw java.lang.NoSuchMethodError if the method doesn't exist |
dsamersoff@3598 | 506 | |
dsamersoff@3598 | 507 | Handle loader = Handle(THREAD, SystemDictionary::java_system_loader()); |
coleenp@4037 | 508 | Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::sun_management_Agent(), loader, Handle(), true, CHECK); |
dsamersoff@3598 | 509 | instanceKlassHandle ik (THREAD, k); |
dsamersoff@3598 | 510 | |
dsamersoff@3598 | 511 | JavaValue result(T_VOID); |
dsamersoff@3598 | 512 | |
dsamersoff@3598 | 513 | // Pass all command line arguments to java as key=value,... |
dsamersoff@3598 | 514 | // All checks are done on java side |
dsamersoff@3598 | 515 | |
dsamersoff@3598 | 516 | int len = 0; |
dsamersoff@3598 | 517 | stringStream options; |
dsamersoff@3598 | 518 | char comma[2] = {0,0}; |
dsamersoff@3598 | 519 | |
dsamersoff@3598 | 520 | // Leave default values on Agent.class side and pass only |
dsamersoff@3598 | 521 | // agruments explicitly set by user. All arguments passed |
dsamersoff@3598 | 522 | // to jcmd override properties with the same name set by |
dsamersoff@3598 | 523 | // command line with -D or by managmenent.properties |
dsamersoff@3598 | 524 | // file. |
dsamersoff@3598 | 525 | #define PUT_OPTION(a) \ |
dsamersoff@3598 | 526 | if ( (a).is_set() ){ \ |
dsamersoff@3598 | 527 | options.print("%scom.sun.management.%s=%s", comma, (a).name(), (a).value()); \ |
dsamersoff@3598 | 528 | comma[0] = ','; \ |
dsamersoff@3598 | 529 | } |
dsamersoff@3598 | 530 | |
dsamersoff@3598 | 531 | PUT_OPTION(_config_file); |
dsamersoff@3598 | 532 | PUT_OPTION(_jmxremote_port); |
dsamersoff@3598 | 533 | PUT_OPTION(_jmxremote_rmi_port); |
dsamersoff@3598 | 534 | PUT_OPTION(_jmxremote_ssl); |
dsamersoff@3598 | 535 | PUT_OPTION(_jmxremote_registry_ssl); |
dsamersoff@3598 | 536 | PUT_OPTION(_jmxremote_authenticate); |
dsamersoff@3598 | 537 | PUT_OPTION(_jmxremote_password_file); |
dsamersoff@3598 | 538 | PUT_OPTION(_jmxremote_access_file); |
dsamersoff@3598 | 539 | PUT_OPTION(_jmxremote_login_config); |
dsamersoff@3598 | 540 | PUT_OPTION(_jmxremote_ssl_enabled_cipher_suites); |
dsamersoff@3598 | 541 | PUT_OPTION(_jmxremote_ssl_enabled_protocols); |
dsamersoff@3598 | 542 | PUT_OPTION(_jmxremote_ssl_need_client_auth); |
dsamersoff@3598 | 543 | PUT_OPTION(_jmxremote_ssl_config_file); |
dsamersoff@3598 | 544 | |
dsamersoff@3598 | 545 | #undef PUT_OPTION |
dsamersoff@3598 | 546 | |
dsamersoff@3598 | 547 | Handle str = java_lang_String::create_from_str(options.as_string(), CHECK); |
dsamersoff@3598 | 548 | JavaCalls::call_static(&result, ik, vmSymbols::startRemoteAgent_name(), vmSymbols::string_void_signature(), str, CHECK); |
dsamersoff@3598 | 549 | } |
dsamersoff@3598 | 550 | |
dsamersoff@3598 | 551 | JMXStartLocalDCmd::JMXStartLocalDCmd(outputStream *output, bool heap_allocated) : |
dsamersoff@3598 | 552 | DCmd(output, heap_allocated) |
dsamersoff@3598 | 553 | { |
dsamersoff@3598 | 554 | // do nothing |
dsamersoff@3598 | 555 | } |
dsamersoff@3598 | 556 | |
dsamersoff@3598 | 557 | void JMXStartLocalDCmd::execute(TRAPS) { |
dsamersoff@3598 | 558 | ResourceMark rm(THREAD); |
dsamersoff@3598 | 559 | HandleMark hm(THREAD); |
dsamersoff@3598 | 560 | |
dsamersoff@3598 | 561 | // Load and initialize the sun.management.Agent class |
dsamersoff@3598 | 562 | // invoke startLocalManagementAgent(void) method to start |
dsamersoff@3598 | 563 | // the local management server |
dsamersoff@3598 | 564 | // throw java.lang.NoSuchMethodError if method doesn't exist |
dsamersoff@3598 | 565 | |
dsamersoff@3598 | 566 | Handle loader = Handle(THREAD, SystemDictionary::java_system_loader()); |
coleenp@4037 | 567 | Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::sun_management_Agent(), loader, Handle(), true, CHECK); |
dsamersoff@3598 | 568 | instanceKlassHandle ik (THREAD, k); |
dsamersoff@3598 | 569 | |
dsamersoff@3598 | 570 | JavaValue result(T_VOID); |
dsamersoff@3598 | 571 | JavaCalls::call_static(&result, ik, vmSymbols::startLocalAgent_name(), vmSymbols::void_method_signature(), CHECK); |
dsamersoff@3598 | 572 | } |
dsamersoff@3598 | 573 | |
dsamersoff@3598 | 574 | |
dsamersoff@3598 | 575 | void JMXStopRemoteDCmd::execute(TRAPS) { |
dsamersoff@3598 | 576 | ResourceMark rm(THREAD); |
dsamersoff@3598 | 577 | HandleMark hm(THREAD); |
dsamersoff@3598 | 578 | |
dsamersoff@3598 | 579 | // Load and initialize the sun.management.Agent class |
dsamersoff@3598 | 580 | // invoke stopRemoteManagementAgent method to stop the |
dsamersoff@3598 | 581 | // management server |
dsamersoff@3598 | 582 | // throw java.lang.NoSuchMethodError if method doesn't exist |
dsamersoff@3598 | 583 | |
dsamersoff@3598 | 584 | Handle loader = Handle(THREAD, SystemDictionary::java_system_loader()); |
coleenp@4037 | 585 | Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::sun_management_Agent(), loader, Handle(), true, CHECK); |
dsamersoff@3598 | 586 | instanceKlassHandle ik (THREAD, k); |
dsamersoff@3598 | 587 | |
dsamersoff@3598 | 588 | JavaValue result(T_VOID); |
dsamersoff@3598 | 589 | JavaCalls::call_static(&result, ik, vmSymbols::stopRemoteAgent_name(), vmSymbols::void_method_signature(), CHECK); |
dsamersoff@3598 | 590 | } |
dsamersoff@3598 | 591 |