首页 > 技术文章 > Serviceability - jcmd完全指南

kelthuzadx 2021-02-20 23:31 原文

(Based on JDK 17)

jcmd Compiler.CodeHeap_Analytics

Print CodeHeap analytics

Syntax: Compiler.CodeHeap_Analytics [<function>] [<granularity>]

Arguments:

	function : [optional] Function to be performed (aggregate, UsedSpace, FreeSpace, MethodCount, MethodSpace, MethodAge, MethodNames, discard (STRING, all)
	granularity : [optional] Detail level - smaller value -> more detail (INT, 4096)

jcmd Compiler.codecache

Print code cache layout and bounds.

Syntax: Compiler.codecache

jcmd Compiler.codelist

Print all compiled methods in code cache that are alive

Syntax: Compiler.codelist

jcmd Compiler.directives_add

Add compiler directives from file.

Syntax: Compiler.directives_add <filename>

Arguments:

	filename :  Name of the directives file (STRING, no default value)

jcmd Compiler.directives_clear

Remove all compiler directives.

Syntax: Compiler.directives_clear

jcmd Compiler.directives_print

Print all active compiler directives.

Syntax: Compiler.directives_print

jcmd Compiler.directives_remove

Remove latest added compiler directive.

Syntax: Compiler.directives_remove

jcmd Compiler.perfmap

Write map file for Linux perf tool.

Syntax: Compiler.perfmap

jcmd Compiler.queue

Print methods queued for compilation.

Syntax: Compiler.queue

jcmd GC.class_histogram

Provide statistics about the Java heap usage.

Syntax: GC.class_histogram [options]

Options:

	-all : [optional] Inspect all objects, including unreachable objects (BOOLEAN, false)

jcmd GC.finalizer_info

Provide information about Java finalization queue.

Syntax: GC.finalizer_info

jcmd GC.heap_dump

Generate a HPROF format dump of the Java heap.

Syntax: GC.heap_dump [options] <filename>

Arguments:

	filename :  Name of the dump file (STRING, no default value)

Options:

	-all : [optional] Dump all objects, including unreachable objects (BOOLEAN, false)
	-gz : [optional] If specified, the heap dump is written in gzipped format using the given compression level. 1 (recommended) is the fastest, 9 the strongest compression. (INT, 1)

jcmd GC.heap_info

Provide generic Java heap information.

Syntax: GC.heap_info

jcmd GC.run

Call java.lang.System.gc().

Syntax: GC.run

jcmd GC.run_finalization

Call java.lang.System.runFinalization().

Syntax: GC.run_finalization

jcmd JFR.check

Checks running JFR recording(s)

Syntax: JFR.check [options]

Options:

	name : [optional] Recording name, e.g. \"My Recording\" or omit to see all recordings (STRING, no default value)
	verbose : [optional] Print event settings for the recording(s) (BOOLEAN, false)

jcmd JFR.configure

Configure JFR

Syntax: JFR.configure [options]

Options:

	repositorypath : [optional] Path to repository,.e.g \"My Repository\" (STRING, no default value)
	dumppath : [optional] Path to dump,.e.g \"My Dump path\" (STRING, no default value)
	stackdepth : [optional] Stack Depth (JULONG, 64)
	globalbuffercount : [optional] Number of global buffers, (JULONG, 20)
	globalbuffersize : [optional] Size of a global buffers, (MEMORY SIZE, 512k)
	thread_buffer_size : [optional] Size of a thread buffer (MEMORY SIZE, 8k)
	memorysize : [optional] Overall memory size,  (MEMORY SIZE, 10m)
	maxchunksize : [optional] Size of an individual disk chunk (MEMORY SIZE, 12m)
	samplethreads : [optional] Activate Thread sampling (BOOLEAN, true)

jcmd JFR.dump

Copies contents of a JFR recording to file. Either the name or the recording id must be specified.

Syntax: JFR.dump [options]

Options:

	name : [optional] Recording name, e.g. \"My Recording\" (STRING, no default value)
	filename : [optional] Copy recording data to file, e.g. \"/home/user/My Recording.jfr\" (STRING, no default value)
	maxage : [optional] Maximum duration to dump, in (s)econds, (m)inutes, (h)ours, or (d)ays, e.g. 60m, or 0 for no limit (NANOTIME, 0)
	maxsize : [optional] Maximum amount of bytes to dump, in (M)B or (G)B, e.g. 500M, or 0 for no limit (MEMORY SIZE, 0)
	begin : [optional] Point in time to dump data from, e.g. 09:00, 21:35:00, 2018-06-03T18:12:56.827Z, 2018-06-03T20:13:46.832, -10m, -3h, or -1d (STRING, no default value)
	end : [optional] Point in time to dump data to, e.g. 09:00, 21:35:00, 2018-06-03T18:12:56.827Z, 2018-06-03T20:13:46.832, -10m, -3h, or -1d (STRING, no default value)
	path-to-gc-roots : [optional] Collect path to GC roots (BOOLEAN, false)

jcmd JFR.start

Starts a new JFR recording

Syntax: JFR.start [options]

Options:

	name : [optional] Name that can be used to identify recording, e.g. \"My Recording\" (STRING, no default value)
	settings : [optional] Settings file(s), e.g. profile or default. See JAVA_HOME/lib/jfr (STRING SET, no default value)
	delay : [optional] Delay recording start with (s)econds, (m)inutes), (h)ours), or (d)ays, e.g. 5h. (NANOTIME, 0)
	duration : [optional] Duration of recording in (s)econds, (m)inutes, (h)ours, or (d)ays, e.g. 300s. (NANOTIME, 0)
	disk : [optional] Recording should be persisted to disk (BOOLEAN, no default value)
	filename : [optional] Resulting recording filename, e.g. \"/home/user/My Recording.jfr\" (STRING, no default value)
	maxage : [optional] Maximum time to keep recorded data (on disk) in (s)econds, (m)inutes, (h)ours, or (d)ays, e.g. 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, e.g. 500M, or 0 for no limit (MEMORY SIZE, 0)
	flush-interval : [optional] Minimum time before flushing buffers, measured in (s)econds, e.g. 4 s, or 0 for flushing when a recording ends (NANOTIME, 1s)
	dumponexit : [optional] Dump running recording when JVM shuts down (BOOLEAN, no default value)
	path-to-gc-roots : [optional] Collect path to GC roots (BOOLEAN, false)

jcmd JFR.stop

Stops a JFR recording

Syntax: JFR.stop [options]

Options:

	name :  Recording text,.e.g \"My Recording\" (STRING, no default value)
	filename : [optional] Copy recording data to file, e.g. \"/home/user/My Recording.jfr\" (STRING, no default value)

jcmd JVMTI.agent_load

Load JVMTI native agent.

Syntax: JVMTI.agent_load <library path> [<agent option>]

Arguments:

	library path :  Absolute path of the JVMTI agent to load. (STRING, no default value)
	agent option : [optional] Option string to pass the agent. (STRING, no default value)

jcmd JVMTI.data_dump

Signal the JVM to do a data-dump request for JVMTI.

Syntax: JVMTI.data_dump

jcmd ManagementAgent.start

Start remote management agent.

Syntax: ManagementAgent.start [options]

Options:

	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)

jcmd ManagementAgent.start_local

Start local management agent.

Syntax: ManagementAgent.start_local

jcmd ManagementAgent.status

Print the management agent status.

Syntax: ManagementAgent.status

jcmd ManagementAgent.stop

Stop remote management agent.

Syntax: ManagementAgent.stop

jcmd Thread.print

Print all threads with stacktraces.

Syntax: Thread.print [options]

Options:

	-l : [optional] print java.util.concurrent locks (BOOLEAN, false)
	-e : [optional] print extended thread information (BOOLEAN, false)

jcmd VM.class_hierarchy

Print a list of all loaded classes, indented to show the class hiearchy. The name of each class is followed by the ClassLoaderData* of its ClassLoader, or "null" if loaded by the bootstrap class loader.

Syntax: VM.class_hierarchy [options] [<classname>]

Arguments:

	classname : [optional] Name of class whose hierarchy should be printed. If not specified, all class hierarchies are printed. (STRING, no default value)

Options:

	-i : [optional] Inherited interfaces should be printed. (BOOLEAN, false)
	-s : [optional] If a classname is specified, print its subclasses. Otherwise only its superclasses are printed. (BOOLEAN, false)

jcmd VM.classloader_stats

Print statistics about all ClassLoaders.

Syntax: VM.classloader_stats

jcmd VM.classloaders

Prints classloader hierarchy.

Syntax: VM.classloaders [options]

Options:

	show-classes : [optional] Print loaded classes. (BOOLEAN, false)
	verbose : [optional] Print detailed information. (BOOLEAN, false)
	fold :  Show loaders of the same name and class as one. (BOOLEAN, true)

jcmd VM.command_line

Print the command line used to start this VM instance.

Syntax: VM.command_line

jcmd VM.dynlibs

Print loaded dynamic libraries.

Syntax: VM.dynlibs

jcmd VM.events

Print VM event logs

Syntax: VM.events [options]

Options:

	log : [optional] Name of log to be printed. If omitted, all logs are printed. (STRING, no default value)
	max : [optional] Maximum number of events to be printed (newest first). If omitted, all events are printed. (STRING, no default value)

jcmd VM.flags

Print VM flag options and their current values.

Syntax: VM.flags [options]

Options:

	-all : [optional] Print all flags supported by the VM (BOOLEAN, false)

jcmd VM.info

Print information about JVM environment and status.

Syntax: VM.info

jcmd VM.log

Lists current log configuration, enables/disables/configures a log output, or rotates all logs.

Syntax: VM.log [options]

Options:

	output : [optional] The name or index (#<index>) of output to configure. (STRING, no default value)
	output_options : [optional] Options for the output. (STRING, no default value)
	what : [optional] Configures what tags to log. (STRING, no default value)
	decorators : [optional] Configures which decorators to use. Use 'none' or an empty value to remove all. (STRING, no default value)
	disable : [optional] Turns off all logging and clears the log configuration. (BOOLEAN, no default value)
	list : [optional] Lists current log configuration. (BOOLEAN, no default value)
	rotate : [optional] Rotates all logs. (BOOLEAN, no default value)

jcmd VM.metaspace

Prints the statistics for the metaspace

Syntax: VM.metaspace [options]

Options:

	basic : [optional] Prints a basic summary (does not need a safepoint). (BOOLEAN, false)
	show-loaders : [optional] Shows usage by class loader. (BOOLEAN, false)
	show-classes : [optional] If show-loaders is set, shows loaded classes for each loader. (BOOLEAN, false)
	by-chunktype : [optional] Break down numbers by chunk type. (BOOLEAN, false)
	by-spacetype : [optional] Break down numbers by loader type. (BOOLEAN, false)
	vslist : [optional] Shows details about the underlying virtual space. (BOOLEAN, false)
	scale : [optional] Memory usage in which to scale. Valid values are: 1, KB, MB or GB (fixed scale) or "dynamic" for a dynamically choosen scale. (STRING, dynamic)

jcmd VM.native_memory

Print native memory usage

Syntax: VM.native_memory [options]

Options:

	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)

jcmd VM.print_touched_methods

Print all methods that have ever been touched during the lifetime of this JVM.

Syntax: VM.print_touched_methods

jcmd VM.set_flag

Sets VM flag option using the provided value.

Syntax: VM.set_flag <flag name> [<string value>]

Arguments:

	flag name :  The name of the flag we want to set (STRING, no default value)
	string value : [optional] The value we want to set (STRING, no default value)

jcmd VM.stringtable

Dump string table.

Syntax: VM.stringtable [options]

Options:

	-verbose : [optional] Dump the content of each string in the table (BOOLEAN, false)

jcmd VM.symboltable

Dump symbol table.

Syntax: VM.symboltable [options]

Options:

	-verbose : [optional] Dump the content of each symbol in the table (BOOLEAN, false)

jcmd VM.system_properties

Print system properties.

Syntax: VM.system_properties

jcmd VM.systemdictionary

Prints the statistics for dictionary hashtable sizes and bucket length

Syntax: VM.systemdictionary [options]

Options:

	-verbose : [optional] Dump the content of each dictionary entry for all class loaders (BOOLEAN, false)

jcmd VM.uptime

Print VM uptime.

Syntax: VM.uptime [options]

Options:

	-date : [optional] Add a prefix with current date (BOOLEAN, false)

jcmd VM.version

Print JVM version information.

Syntax: VM.version

推荐阅读