src/share/vm/services/diagnosticCommand.cpp

Wed, 10 Apr 2013 08:55:50 -0400

author
zgu
date
Wed, 10 Apr 2013 08:55:50 -0400
changeset 4927
35f8765422b9
parent 4544
3c9bc17b9403
child 5047
31a4e55f8c9d
permissions
-rw-r--r--

8010151: nsk/regression/b6653214 fails "assert(snapshot != NULL) failed: Worker should not be started"
Summary: Fixed a racing condition when shutting down NMT while worker thread is being started, also fixed a few mis-declared volatile pointers.
Reviewed-by: dholmes, dlong

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

mercurial