1 /* 2 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_VM_SERVICES_DIAGNOSTICCOMMAND_HPP 26 #define SHARE_VM_SERVICES_DIAGNOSTICCOMMAND_HPP 27 28 #include "runtime/arguments.hpp" 29 #include "classfile/vmSymbols.hpp" 30 #include "utilities/ostream.hpp" 31 #include "runtime/vm_version.hpp" 32 #include "runtime/vmThread.hpp" 33 #include "runtime/os.hpp" 34 #include "services/diagnosticArgument.hpp" 35 #include "services/diagnosticCommand.hpp" 36 #include "services/diagnosticFramework.hpp" 37 #include "services/diagnosticCommand_ext.hpp" 38 39 class HelpDCmd : public DCmdWithParser { 40 protected: 41 DCmdArgument<bool> _all; 42 DCmdArgument<char*> _cmd; 43 public: 44 HelpDCmd(outputStream* output, bool heap); 45 static const char* name() { return "help"; } 46 static const char* description() { 47 return "For more information about a specific command use 'help <command>'. " 48 "With no argument this will show a list of available commands. " 49 "'help all' will show help for all commands."; 50 } 51 static const char* impact() { return "Low"; } 52 static int num_arguments(); 53 virtual void execute(DCmdSource source, TRAPS); 54 }; 55 56 class VersionDCmd : public DCmd { 57 public: 58 VersionDCmd(outputStream* output, bool heap) : DCmd(output,heap) { } 59 static const char* name() { return "VM.version"; } 60 static const char* description() { 61 return "Print JVM version information."; 62 } 63 static const char* impact() { return "Low"; } 64 static const JavaPermission permission() { 65 JavaPermission p = {"java.util.PropertyPermission", 66 "java.vm.version", "read"}; 67 return p; 68 } 69 static int num_arguments() { return 0; } 70 virtual void execute(DCmdSource source, TRAPS); 71 }; 72 73 class CommandLineDCmd : public DCmd { 74 public: 75 CommandLineDCmd(outputStream* output, bool heap) : DCmd(output, heap) { } 76 static const char* name() { return "VM.command_line"; } 77 static const char* description() { 78 return "Print the command line used to start this VM instance."; 79 } 80 static const char* impact() { return "Low"; } 81 static const JavaPermission permission() { 82 JavaPermission p = {"java.lang.management.ManagementPermission", 83 "monitor", NULL}; 84 return p; 85 } 86 static int num_arguments() { return 0; } 87 virtual void execute(DCmdSource source, TRAPS) { 88 Arguments::print_on(_output); 89 } 90 }; 91 92 // See also: get_system_properties in attachListener.cpp 93 class PrintSystemPropertiesDCmd : public DCmd { 94 public: 95 PrintSystemPropertiesDCmd(outputStream* output, bool heap) : DCmd(output, heap) { } 96 static const char* name() { return "VM.system_properties"; } 97 static const char* description() { 98 return "Print system properties."; 99 } 100 static const char* impact() { 101 return "Low"; 102 } 103 static const JavaPermission permission() { 104 JavaPermission p = {"java.util.PropertyPermission", 105 "*", "read"}; 106 return p; 107 } 108 static int num_arguments() { return 0; } 109 virtual void execute(DCmdSource source, TRAPS); 110 }; 111 112 // See also: print_flag in attachListener.cpp 113 class PrintVMFlagsDCmd : public DCmdWithParser { 114 protected: 115 DCmdArgument<bool> _all; 116 public: 117 PrintVMFlagsDCmd(outputStream* output, bool heap); 118 static const char* name() { return "VM.flags"; } 119 static const char* description() { 120 return "Print VM flag options and their current values."; 121 } 122 static const char* impact() { 123 return "Low"; 124 } 125 static const JavaPermission permission() { 126 JavaPermission p = {"java.lang.management.ManagementPermission", 127 "monitor", NULL}; 128 return p; 129 } 130 static int num_arguments(); 131 virtual void execute(DCmdSource source, TRAPS); 132 }; 133 134 class VMUptimeDCmd : public DCmdWithParser { 135 protected: 136 DCmdArgument<bool> _date; 137 public: 138 VMUptimeDCmd(outputStream* output, bool heap); 139 static const char* name() { return "VM.uptime"; } 140 static const char* description() { 141 return "Print VM uptime."; 142 } 143 static const char* impact() { 144 return "Low"; 145 } 146 static int num_arguments(); 147 virtual void execute(DCmdSource source, TRAPS); 148 }; 149 150 class SystemGCDCmd : public DCmd { 151 public: 152 SystemGCDCmd(outputStream* output, bool heap) : DCmd(output, heap) { } 153 static const char* name() { return "GC.run"; } 154 static const char* description() { 155 return "Call java.lang.System.gc()."; 156 } 157 static const char* impact() { 158 return "Medium: Depends on Java heap size and content."; 159 } 160 static int num_arguments() { return 0; } 161 virtual void execute(DCmdSource source, TRAPS); 162 }; 163 164 class RunFinalizationDCmd : public DCmd { 165 public: 166 RunFinalizationDCmd(outputStream* output, bool heap) : DCmd(output, heap) { } 167 static const char* name() { return "GC.run_finalization"; } 168 static const char* description() { 169 return "Call java.lang.System.runFinalization()."; 170 } 171 static const char* impact() { 172 return "Medium: Depends on Java content."; 173 } 174 static int num_arguments() { return 0; } 175 virtual void execute(DCmdSource source, TRAPS); 176 }; 177 178 #if INCLUDE_SERVICES // Heap dumping supported 179 // See also: dump_heap in attachListener.cpp 180 class HeapDumpDCmd : public DCmdWithParser { 181 protected: 182 DCmdArgument<char*> _filename; 183 DCmdArgument<bool> _all; 184 public: 185 HeapDumpDCmd(outputStream* output, bool heap); 186 static const char* name() { 187 return "GC.heap_dump"; 188 } 189 static const char* description() { 190 return "Generate a HPROF format dump of the Java heap."; 191 } 192 static const char* impact() { 193 return "High: Depends on Java heap size and content. " 194 "Request a full GC unless the '-all' option is specified."; 195 } 196 static const JavaPermission permission() { 197 JavaPermission p = {"java.lang.management.ManagementPermission", 198 "monitor", NULL}; 199 return p; 200 } 201 static int num_arguments(); 202 virtual void execute(DCmdSource source, TRAPS); 203 }; 204 #endif // INCLUDE_SERVICES 205 206 // See also: inspeactheap in attachListener.cpp 207 class ClassHistogramDCmd : public DCmdWithParser { 208 protected: 209 DCmdArgument<bool> _all; 210 public: 211 ClassHistogramDCmd(outputStream* output, bool heap); 212 static const char* name() { 213 return "GC.class_histogram"; 214 } 215 static const char* description() { 216 return "Provide statistics about the Java heap usage."; 217 } 218 static const char* impact() { 219 return "High: Depends on Java heap size and content."; 220 } 221 static const JavaPermission permission() { 222 JavaPermission p = {"java.lang.management.ManagementPermission", 223 "monitor", NULL}; 224 return p; 225 } 226 static int num_arguments(); 227 virtual void execute(DCmdSource source, TRAPS); 228 }; 229 230 // See also: thread_dump in attachListener.cpp 231 class ThreadDumpDCmd : public DCmdWithParser { 232 protected: 233 DCmdArgument<bool> _locks; 234 public: 235 ThreadDumpDCmd(outputStream* output, bool heap); 236 static const char* name() { return "Thread.print"; } 237 static const char* description() { 238 return "Print all threads with stacktraces."; 239 } 240 static const char* impact() { 241 return "Medium: Depends on the number of threads."; 242 } 243 static const JavaPermission permission() { 244 JavaPermission p = {"java.lang.management.ManagementPermission", 245 "monitor", NULL}; 246 return p; 247 } 248 static int num_arguments(); 249 virtual void execute(DCmdSource source, TRAPS); 250 }; 251 252 // Enhanced JMX Agent support 253 254 class JMXStartRemoteDCmd : public DCmdWithParser { 255 256 // Explicitly list all properties that could be 257 // passed to Agent.startRemoteManagementAgent() 258 // com.sun.management is omitted 259 260 DCmdArgument<char *> _config_file; 261 DCmdArgument<char *> _jmxremote_port; 262 DCmdArgument<char *> _jmxremote_rmi_port; 263 DCmdArgument<char *> _jmxremote_ssl; 264 DCmdArgument<char *> _jmxremote_registry_ssl; 265 DCmdArgument<char *> _jmxremote_authenticate; 266 DCmdArgument<char *> _jmxremote_password_file; 267 DCmdArgument<char *> _jmxremote_access_file; 268 DCmdArgument<char *> _jmxremote_login_config; 269 DCmdArgument<char *> _jmxremote_ssl_enabled_cipher_suites; 270 DCmdArgument<char *> _jmxremote_ssl_enabled_protocols; 271 DCmdArgument<char *> _jmxremote_ssl_need_client_auth; 272 DCmdArgument<char *> _jmxremote_ssl_config_file; 273 274 public: 275 JMXStartRemoteDCmd(outputStream *output, bool heap_allocated); 276 277 static const char *name() { 278 return "ManagementAgent.start"; 279 } 280 281 static const char *description() { 282 return "Start remote management agent."; 283 } 284 285 static int num_arguments(); 286 287 virtual void execute(DCmdSource source, TRAPS); 288 289 }; 290 291 class JMXStartLocalDCmd : public DCmd { 292 293 // Explicitly request start of local agent, 294 // it will not be started by start dcmd 295 296 297 public: 298 JMXStartLocalDCmd(outputStream *output, bool heap_allocated); 299 300 static const char *name() { 301 return "ManagementAgent.start_local"; 302 } 303 304 static const char *description() { 305 return "Start local management agent."; 306 } 307 308 virtual void execute(DCmdSource source, TRAPS); 309 310 }; 311 312 class JMXStopRemoteDCmd : public DCmd { 313 public: 314 JMXStopRemoteDCmd(outputStream *output, bool heap_allocated) : 315 DCmd(output, heap_allocated) { 316 // Do Nothing 317 } 318 319 static const char *name() { 320 return "ManagementAgent.stop"; 321 } 322 323 static const char *description() { 324 return "Stop remote management agent."; 325 } 326 327 virtual void execute(DCmdSource source, TRAPS); 328 }; 329 330 #endif // SHARE_VM_SERVICES_DIAGNOSTICCOMMAND_HPP