Jcmd: where can I find more information

jcmd is a promising tool for rearranging jmap, jsp, etc.

You can find an introduction and a man page , but still it is very easy.

On the Internet, I found that there were apparently existing commands like GC.heap_info that I could never use for my tests.

Some of these teams need special flags. -XX:NativeMemoryTracking=detail will give you the VM.native_memory command, for example.

But for some others it is not clear how to activate them, or if it depends on the jdk version, etc.
I can’t even find an exhaustive list of the existing team.

Any info?


Edit thanks to @apangin response , I started to compute a short summary of the available jvm commands.

Disclaimer: it comes only from code breaks, not from a real test

jdk8

  • help
  • VM.uptime [options]
  • VM.flags [options]
  • VM.system_properties
  • VM.command_line
  • VM.version
  • VM.native_memory [options]
  • VM.check_commercial_features
  • VM.unlock_commercial_features
  • Thread.print [options]
  • Gc.run
  • Gc.run_finalization
  • Gc.rotate_log
  • GC.class_stats [options]
  • GC.class_histogram [parameters]
  • GC.heap_dump [options]
  • ManagementAgent.start_local
  • ManagementAgent.start [parameters]
  • ManagementAgent.stopJFR.start [options]
  • JFR.stop [options]
  • JFR.dump [options]
  • JFR.check [options]

jdk9

only optional

  • VM.set_flag [options]
  • VM.info
  • VM.class_hierarchy [options]
  • VM.dynlibs
  • VM.print_touched_methods
  • JVMTI.data_dump
  • JVMTI.agent_load [parameters]
  • Gc.finalizer_info
  • Gc.heap_info
  • ManagementAgent.status
  • ManagementAgent.stop
  • Compiler.queue
  • Compiler.codelist
  • Compiler.codecache
  • Compiler.directives_print
  • Compiler.directives_remove
  • Compiler.directives_add [options]
  • Compiler.directives_clear
+5
source share
2 answers

Based on the @EricWang answer , HotSpot diagnostic command sources and personal experience, I created a complete list of jcmd commands available in JDK 8u121, with additional information about requirements, etc.


help [options] [<command name>]

For more information about a specific command, use help <command> . With no arguments, this will show a list of available commands. help -all displays help for all commands.

  • Impact: Low
 Arguments: command name : [optional] The name of the command for which we want help (STRING, no default value) Options: (options must be specified using the <key> or <key>=<value> syntax) -all : [optional] Show help for all commands (BOOLEAN, false) 

VM.uptime [options]

VM battery life.

  • Impact: Low
 Options: (options must be specified using the <key> or <key>=<value> syntax) -date : [optional] Add a prefix with current date (BOOLEAN, false) 

VM.flags [options]

Print VM flag parameters and their current values.

  • Impact: Low
 Options: (options must be specified using the <key> or <key>=<value> syntax) -all : [optional] Print all flags supported by the VM (BOOLEAN, false) 

VM.system_properties

Printing system properties. A.

  • Impact: Low

VM.command_line

Print the command line used to start this instance of the virtual machine.

  • Impact: Low

VM.version

Print JVM version information.

  • Impact: Low

VM.native_memory [options]

Downloading your own memory.

  • Impact: Medium
  • Requires: -XX:NativeMemoryTracking=[summary|detail]
 Options: (options must be specified using the <key> or <key>=<value> syntax) summary : [optional] request runtime to report current memory summary, which includes total reserved and committed memory, along with memory usage summary by each subsytem. (BOOLEAN, false) detail : [optional] request runtime to report memory allocation >= 1K by each callsite. (BOOLEAN, false) baseline : [optional] request runtime to baseline current memory usage, so it can be compared against in later time. (BOOLEAN, false) summary.diff : [optional] request runtime to report memory summary comparison against previous baseline. (BOOLEAN, false) detail.diff : [optional] request runtime to report memory detail comparison against previous baseline, which shows the memory allocation activities at different callsites. (BOOLEAN, false) shutdown : [optional] request runtime to shutdown itself and free the memory used by runtime. (BOOLEAN, false) statistics : [optional] print tracker statistics for tuning purpose. (BOOLEAN, false) scale : [optional] Memory usage in which scale, KB, MB or GB (STRING, KB) 

VM.check_commercial_features

Displays the status of commercial features.

  • Impact: Low: not affected

VM.unlock_commercial_features

Unlock commercial features.

  • Impact: Low: not affected

Thread.print [options]

Print all threads using stacktraces.

  • Impact: Medium: Depends on the number of threads.
 Options: (options must be specified using the <key> or <key>=<value> syntax) -l : [optional] print java.util.concurrent locks (BOOLEAN, false) 

Gc.run

Call java.lang.System.gc ().

  • Impact: Medium: Depends on the size and contents of the Java heap.

Gc.run_finalization

Call java.lang.System.runFinalization ().

  • Impact: Medium: Depends on Java content.

Gc.rotate_log

Force rotate the GC log file.

  • Impact: Low
  • Requires: -Xloggc:<filename> -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=<num>

GC.class_stats [options] [<columns>]

Provide metadata statistics for the Java class.

  • Impact: High: Depends on the size and contents of the Java heap.
  • Requires: -XX:+UnlockDiagnosticVMOptions
 Arguments: columns : [optional] Comma-separated list of all the columns to show. If not specified, the following columns are shown: InstBytes,KlassBytes,CpAll,annotations,MethodCount,Bytecodes,MethodAll,ROAll,RWAll,Total (STRING, no default value) Options: (options must be specified using the <key> or <key>=<value> syntax) -all : [optional] Show all columns (BOOLEAN, false) -csv : [optional] Print in CSV (comma-separated values) format for spreadsheets (BOOLEAN, false) -help : [optional] Show meaning of all the columns (BOOLEAN, false) 

GC.class_histogram [parameters]

Provide usage statistics for Java heaps.

  • Impact: High: Depends on the size and contents of the Java heap.
 Options: (options must be specified using the <key> or <key>=<value> syntax) -all : [optional] Inspect all objects, including unreachable objects (BOOLEAN, false) 

GC.heap_dump [options] <filename>

Dump the HPROF format of the Java heap.

  • Impact: High: Depends on the size and contents of the Java heap. Request full GC if the -all option is not specified.
 Arguments: filename : Name of the dump file (STRING, no default value) Options: (options must be specified using the <key> or <key>=<value> syntax) -all : [optional] Dump all objects, including unreachable objects (BOOLEAN, false) 

ManagementAgent.start_local

Launch the local management agent.

  • Impact: Low: not affected

ManagementAgent.start [parameters]

Launch the remote control agent.

  • Impact: Low: not affected
 Options: (options must be specified using the <key> or <key>=<value> syntax) config.file : [optional] set com.sun.management.config.file (STRING, no default value) jmxremote.host : [optional] set com.sun.management.jmxremote.host (STRING, no default value) jmxremote.port : [optional] set com.sun.management.jmxremote.port (STRING, no default value) jmxremote.rmi.port : [optional] set com.sun.management.jmxremote.rmi.port (STRING, no default value) jmxremote.ssl : [optional] set com.sun.management.jmxremote.ssl (STRING, no default value) jmxremote.registry.ssl : [optional] set com.sun.management.jmxremote.registry.ssl (STRING, no default value) jmxremote.authenticate : [optional] set com.sun.management.jmxremote.authenticate (STRING, no default value) jmxremote.password.file : [optional] set com.sun.management.jmxremote.password.file (STRING, no default value) jmxremote.access.file : [optional] set com.sun.management.jmxremote.access.file (STRING, no default value) jmxremote.login.config : [optional] set com.sun.management.jmxremote.login.config (STRING, no default value) jmxremote.ssl.enabled.cipher.suites : [optional] set com.sun.management.jmxremote.ssl.enabled.cipher.suite (STRING, no default value) jmxremote.ssl.enabled.protocols : [optional] set com.sun.management.jmxremote.ssl.enabled.protocols (STRING, no default value) jmxremote.ssl.need.client.auth : [optional] set com.sun.management.jmxremote.need.client.auth (STRING, no default value) jmxremote.ssl.config.file : [optional] set com.sun.management.jmxremote.ssl_config_file (STRING, no default value) jmxremote.autodiscovery : [optional] set com.sun.management.jmxremote.autodiscovery (STRING, no default value) jdp.port : [optional] set com.sun.management.jdp.port (INT, no default value) jdp.address : [optional] set com.sun.management.jdp.address (STRING, no default value) jdp.source_addr : [optional] set com.sun.management.jdp.source_addr (STRING, no default value) jdp.ttl : [optional] set com.sun.management.jdp.ttl (INT, no default value) jdp.pause : [optional] set com.sun.management.jdp.pause (INT, no default value) jdp.name : [optional] set com.sun.management.jdp.name (STRING, no default value) 

ManagementAgent.stop

Stop the remote control agent.

  • Impact: Low: not affected

JFR.start [options]

Starts a new JFR record

  • Impact: Medium: Depending on the settings for recording, the impact may vary from low to high.
  • Requires: -XX:+UnlockCommercialFeatures
 Options: (options must be specified using the <key> or <key>=<value> syntax) name : [optional] Name that can be used to identify recording, eg "My Recording" (STRING, no default value) defaultrecording : [optional] Starts the default recording, can only be combined with settings. (BOOLEAN, false) dumponexit : [optional] Dump running recording when JVM shuts down (BOOLEAN, no default value) settings : [optional] Settings file(s), eg profile or default. See JRE_HOME/lib/jfr (STRING SET, no default value) delay : [optional] Delay recording start with (s)econds, (m)inutes), (h)ours), or (d)ays, eg 5h. (NANOTIME, 0) duration : [optional] Duration of recording in (s)econds, (m)inutes, (h)ours, or (d)ays, eg 300s. (NANOTIME, 0) filename : [optional] Resulting recording filename, eg "C:\Users\user\My Recording.jfr" (STRING, no default value) compress : [optional] GZip-compress the resulting recording file (BOOLEAN, false) maxage : [optional] Maximum time to keep recorded data (on disk) in (s)econds, (m)inutes, (h)ours, or (d)ays, eg 60m, or 0 for no limit (NANOTIME, 0) maxsize : [optional] Maximum amount of bytes to keep (on disk) in (k)B, (M)B or (G)B, eg 500M, or 0 for no limit (MEMORY SIZE, 0) 

JFR.stop [options]

JFR Recording Stop

  • Impact: Low
  • Requires: -XX:+UnlockCommercialFeatures
 Options: (options must be specified using the <key> or <key>=<value> syntax) name : [optional] Recording name,.eg "My Recording" (STRING, no default value) recording : [optional] Recording number, see JFR.check for a list of available recordings (JLONG, -1) discard : [optional] Skip writing data to previously specified file (if any) (BOOLEAN, false) filename : [optional] Copy recording data to file, eg "C:\Users\user\My Recording.jfr" (STRING, no default value) compress : [optional] GZip-compress "filename" destination (BOOLEAN, false) 

JFR.dump [options]

Copies the contents of a JFR record to a file. You must provide a name or record identifier.

  • Impact: Low
  • Requires: -XX:+UnlockCommercialFeatures
 Options: (options must be specified using the <key> or <key>=<value> syntax) name : [optional] Recording name, eg "My Recording" (STRING, no default value) recording : [optional] Recording number, use JFR.check to list available recordings (JLONG, -1) filename : Copy recording data to file, ie "C:\Users\user\My Recording.jfr" (STRING, no default value) compress : [optional] GZip-compress "filename" destination (BOOLEAN, false) 

JFR.check [options]

Checks JFR Record (s)

  • Impact: Low
  • Requires: -XX:+UnlockCommercialFeatures
 Options: (options must be specified using the <key> or <key>=<value> syntax) name : [optional] Recording name, eg "My Recording" or omit to see all recordings (STRING, no default value) recording : [optional] Recording number, or omit to see all recordings (JLONG, -1) verbose : [optional] Print event settings for the recording(s) (BOOLEAN, false) 
+3
source

jcmd itself provides this information when applied to a particular Java process, and possibly to a specific subcommand.

How to get help:

  • First create java process lists via jps or jcmd -l if you don’t already know the pid of the target Java process (for example, I will take the Java process using pid 8976 as an example in the following steps).
  • Then apply the help subcommand for a specific java process, for example jcmd 8976 help , it will list the available subcommands for the process.
  • Then get help for a specific process command, for example jcmd 8976 help Thread.print , it will display help under Thread.print sub command.
  • Then run a specific helper command in the process, for example jcmd 8976 Thread.print or jcmd 8976 Thread.print | less -N jcmd 8976 Thread.print | less -N

By the way, as you already mentioned, the following link briefly describes the jcmd command: https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/tooldescr006.html

+1
source

Source: https://habr.com/ru/post/1263433/


All Articles