首页 jvm命令
文章
取消

jvm命令

jps 虚拟机进程状态工具

jps (Java Virtual Machine Process Status Tool) 显示指定系统内所有的 HotSpot 虚拟机进程。

jps 命令格式

jps [options] [hostid]

jps OPTIONS

  • -q 只显示 Java 进程的 pid,不显示 class 名称、jar 文件名和传递给 main 方法的参数

  • -m 显示传递给 main 方法的参数

  • -l 显示应用的 main 类或 jar 文件的全限定名

  • -v 显示传递给 JVM 的参数

  • -V 显示通过 flag 文件传递到 JVM 中的参数(.hotspotrc 文件或 -XX:Flags=所指定的文件)

  • -Joption 传递参数到 JVM,例如 -J-Xmx1G

    用 -v 参数可以看到传入的参数,但是再次只用 -v 参数查看的时候新加入的参数就不见了

jstat 虚拟机统计信息监视工具

jstat (Java Virtual Machine Statistice Monitoring Tool) 是用于监视虚拟机各种运行状态信息到命令行工具。

jstat 命令格式

jstat [ generalOption | outputOptions vmid [ interval[s|ms] [ count ] ]

jstat OPTIONS

  • -class: Class loader statistics. Displays statistics about the behavior of the class loader.

    • Loaded: Number of classes loaded.

    • Bytes: Number of kBs loaded.

    • Unloaded: Number of classes unloaded.

    • Bytes: Number of Kbytes unloaded.

    • Time: Time spent performing class loading and unloading operations.

  • -compiler: Java HotSpot VM Just-in-Time compiler statistics. Displays statistics about the behavior of the Java HotSpot VM Just-in-Time compiler.

    • Compiled: Number of compilation tasks performed.

    • Failed: Number of compilations tasks failed.

    • Invalid: Number of compilation tasks that were invalidated.

    • Time: Time spent performing compilation tasks.

    • FailedType: Compile type of the last failed compilation.

    • FailedMethod: Class name and method of the last failed compilation.

  • -gc: Garbage-collected heap statistics. Displays statistics about the behavior of the garbage collected heap.

    • S0C: Current survivor space 0 capacity (kB).

    • S1C: Current survivor space 1 capacity (kB).

    • S0U: Survivor space 0 utilization (kB).

    • S1U: Survivor space 1 utilization (kB).

    • EC: Current eden space capacity (kB).

    • EU: Eden space utilization (kB).

    • OC: Current old space capacity (kB).

    • OU: Old space utilization (kB).

    • MC: Metaspace capacity (kB).

    • MU: Metacspace utilization (kB).

    • CCSC: Compressed class space capacity (kB).

    • CCSU: Compressed class space used (kB).

    • YGC: Number of young generation garbage collection events.

    • YGCT: Young generation garbage collection time.

    • FGC: Number of full GC events.

    • FGCT: Full garbage collection time.

    • GCT: Total garbage collection time.

  • -gccapacity: Memory pool generation and space capacities. Displays statistics about the capacities of the generations and their corresponding spaces.

    • NGCMN: Minimum new generation capacity (kB).

    • NGCMX: Maximum new generation capacity (kB).

    • NGC: Current new generation capacity (kB).

    • S0C: Current survivor space 0 capacity (kB).

    • S1C: Current survivor space 1 capacity (kB).

    • EC: Current eden space capacity (kB).

    • OGCMN: Minimum old generation capacity (kB).

    • OGCMX: Maximum old generation capacity (kB).

    • OGC: Current old generation capacity (kB).

    • OC: Current old space capacity (kB).

    • MCMN: Minimum metaspace capacity (kB).

    • MCMX: Maximum metaspace capacity (kB).

    • MC: Metaspace capacity (kB).

    • CCSMN: Compressed class space minimum capacity (kB).

    • CCSMX: Compressed class space maximum capacity (kB).

    • CCSC: Compressed class space capacity (kB).

    • YGC: Number of young generation GC events.

    • FGC: Number of full GC events.

  • -gccause: Displays a summary about garbage collection statistics (same as -gcutil), with the cause of the last and current (when applicable) garbage collection events. In addition to the columns listed for -gcutil, this option adds the following columns.

    • LGCC: Cause of last garbage collection

    • GCC: Cause of current garbage collection

  • -gcnew: New generation statistics. Displays statistics of the behavior of the new generation.

    • S0C: Current survivor space 0 capacity (kB).

    • S1C: Current survivor space 1 capacity (kB).

    • S0U: Survivor space 0 utilization (kB).

    • S1U: Survivor space 1 utilization (kB).

    • TT: Tenuring threshold.

    • MTT: Maximum tenuring threshold.

    • DSS: Desired survivor size (kB).

    • EC: Current eden space capacity (kB).

    • EU: Eden space utilization (kB).

    • YGC: Number of young generation GC events.

    • YGCT: Young generation garbage collection time.

  • -gcnewcapacity: New generation space size statistics. Displays statistics about the sizes of the new generations and its corresponding spaces.

    • NGCMN: Minimum new generation capacity (kB).

    • NGCMX: Maximum new generation capacity (kB).

    • NGC: Current new generation capacity (kB).

    • S0CMX: Maximum survivor space 0 capacity (kB).

    • S0C: Current survivor space 0 capacity (kB).

    • S1CMX: Maximum survivor space 1 capacity (kB).

    • S1C: Current survivor space 1 capacity (kB).

    • ECMX: Maximum eden space capacity (kB).

    • EC: Current eden space capacity (kB).

    • YGC: Number of young generation GC events.

    • FGC: Number of full GC events.

  • -gcold: Old generation and metaspace behavior statistics. Displays statistics about the behavior of the old generation and metaspace statistics.

    • MC: Metaspace capacity (kB).

    • MU: Metaspace utilization (kB).

    • CCSC: Compressed class space capacity (kB).

    • CCSU: Compressed class space used (kB).

    • OC: Current old space capacity (kB).

    • OU: Old space utilization (kB).

    • YGC: Number of young generation GC events.

    • FGC: Number of full GC events.

    • FGCT: Full garbage collection time.

    • GCT: Total garbage collection time.

  • -gcoldcapacity: Old generation size statistics. Displays statistics about the sizes of the old generation.

    • OGCMN: Minimum old generation capacity (kB).

    • OGCMX: Maximum old generation capacity (kB).

    • OGC: Current old generation capacity (kB).

    • OC: Current old space capacity (kB).

    • YGC: Number of young generation GC events.

    • FGC: Number of full GC events.

    • FGCT: Full garbage collection time.

    • GCT: Total garbage collection time.

  • -gcmetacapacity: Metaspace size statistics. Displays statistics about the sizes of the metaspace.

    • MCMN: Minimum metaspace capacity (kB).

    • MCMX: Maximum metaspace capacity (kB).

    • MC: Metaspace capacity (kB).

    • CCSMN: Compressed class space minimum capacity (kB).

    • CCSMX: Compressed class space maximum capacity (kB).

    • YGC: Number of young generation GC events.

    • FGC: Number of full GC events.

    • FGCT: Full garbage collection time.

    • GCT: Total garbage collection time.

  • -gcutil: Summary of garbage collection statistics. Displays a summary about garbage collection statistics.

    • S0: Survivor space 0 utilization as a percentage of the space’s current capacity.

    • S1: Survivor space 1 utilization as a percentage of the space’s current capacity.

    • E: Eden space utilization as a percentage of the space’s current capacity.

    • O: Old space utilization as a percentage of the space’s current capacity.

    • M: Metaspace utilization as a percentage of the space’s current capacity.

    • CCS: Compressed class space utilization as a percentage.

    • YGC: Number of young generation GC events.

    • YGCT: Young generation garbage collection time.

    • FGC: Number of full GC events.

    • FGCT: Full garbage collection time.

    • GCT: Total garbage collection time.

  • -printcompilation: Java HotSpot VM compiler method statistics. Displays Java HotSpot VM compilation method statistics.

    • Compiled: Number of compilation tasks performed by the most recently compiled method.

    • Size: Number of bytes of byte code of the most recently compiled method.

    • Type: Compilation type of the most recently compiled method.

    • Method: Class name and method name identifying the most recently compiled method. Class name uses slash (/) instead of dot (.) as a name space separator. Method name is the method within the specified class. The - format for these two fields is consistent with the HotSpot -XX:+PrintCompilation option.

jmap Java 内存映像工具

jmap (Memory Map for Java) 命令用于生成堆转储快照(一般称为 heapdump 或 dump 文件)。

jmap 命令格式

jmap [ options ] pid

jmap OPTIONS

  • no-option

    显示共享的对象的内存映像。

  • -dump:[live,] format=b, file=filename

    生成 Java 堆转储快照。live 子参数说明是否只 dump 出存活堆对象。可以通过 jhat 命令来浏览转储文件。

  • -finalizerinfo

    显示在 F-Queue 中等待 Finalizer 线程执行 finalize 方法堆对象。只在 Linux/Solaris 平台下有效。

  • -heap

    显示 Java 堆详细信息,如使用那种回收器、参数配置、分代状况等。只在 Linux/Solaris 平台下有效。

  • -histo[:live]

    显示堆中对象统计信息,包括类、实例数量、合计容量。

  • -clstats

    显示类加载器信息。

  • -F

    当虚拟机进程对 -dump 选项没有响应时,可使用这个选项强制生成 dump 快照。只在 Linux/Solaris 平台下有效。

jhat 虚拟机堆转储快照分析工具

jhat (Java Virtual Machine Heap Analysis Tool) 命令与 jmap 搭配使用,来分析 jmap 生成的堆转储快照。

jhat 命令格式

jhat [ options ] heap-dump-file

jhat OPTIONS

  • -stack false|true

    Turns off tracking object allocation call stack. If allocation site information is not available in the heap dump, then you have to set this flag to false. The default is true.

  • -refs false|true

    Turns off tracking of references to objects. Default is true. By default, back pointers, which are objects that point to a specified object such as referrers or incoming references, are calculated for all objects in the heap.

  • -port port-number

    Sets the port for the jhat HTTP server. Default is 7000.

  • -exclude exclude-file

    Specifies a file that lists data members that should be excluded from the reachable objects query. For example, if the file lists java.lang.String.value, then, then whenever the list of objects that are reachable from a specific object o are calculated, reference paths that involve java.lang.String.value field are not considered.

  • -baseline exclude-file

    Specifies a baseline heap dump. Objects in both heap dumps with the same object ID are marked as not being new. Other objects are marked as new. This is useful for comparing two different heap dumps.

  • -debug int

    Sets the debug level for this tool. A level of 0 means no debug output. Set higher values for more verbose modes.

jstack Java 堆栈跟踪工具

jstack (Stack Trace for Java) 命令用于生成虚拟机当前时刻的线程快照(一般称为 threaddump 或者 javacore 文件)。

jstack 命令格式

jstack [ options ] pid

jstack OPTIONS

  • -F: 当正常输出的请求不被响应时,强制输出线程堆栈。

  • -l: 除堆栈外,显示关于锁的附加信息。

  • -m: 如果调用到本地方法的话,可以显示 C/C++ 的堆栈。

jinfo Java 配置信息工具

jinfo (Configuration Info for Java) 的作用是实时地查看和调用整虚拟机各项参数。

jinfo 命令格式

jinfo [ option ] pid

jinfo OPTIONS

  • no-option:

    Prints both command-line flags and system property name-value pairs.

  • -flag name

    Prints the name and value of the specified command-line flag.

  • -flag [+|-]name

    enables or disables the specified Boolean command-line flag.

  • -flag name=value

    Sets the specified command-line flag to the specified value.

  • -flags

    Prints command-line flags passed to the JVM.

  • -sysprops

    Prints Java system properties as name-value pairs.

本文由作者按照 CC BY 4.0 进行授权