Java Virtual machine Memory monitoring tool jps,jinfo,jstack,jstat,jmap,jhat use

Source: Internet
Author: User
Tags stack trace visualvm

based on the Sun HotSpot JVM

Here are some of the monitoring tools that the Sun hotspot JVM comes with:

Make sure that the Java_home/bin is configured under the PATH environment variable because the tools are in the bin directory of the JDK

JPS (JVM process Status Tool): JVM machine process status Tools


Used to view the specific state of all processes based on the hotspot JVM, including the process ID, path of process initiation, and so on. Similar to PS on UNIX, used to display locally-privileged Java processes, you can view a few Java programs running locally and display their process numbers. When using JPS, you do not need to pass the process number as a parameter.
JPS can also display the Java process on a remote system, which requires the Jstat service on the remote service, as well as RMI notes and services, but is often viewed by the Java process for this pair.
Command format: JPS [options] [HostID]
Common parameter Description:
The-m output is passed to the main method parameter, and if it is an inline JVM, the output is null.
-L OUTPUT The full package name of the application main class, or the full path to the application jar file.
-V output passed to the JVM parameters.

For example:


C:\users\liu>jps-lmv4868-dexe4j.semaphorename=d:_program files (x86) _jetbrains_intellij idea 12.1.7_bin_ Idea.exe-dexe4j.modulename=d:\program Files (x86) \jetbrains\intellij idea 12.1.7\bin\idea.exe- Dexe4j.processcommfile=c:\users\liu\appdata\local\temp\e4j_p4868.tmp-dexe4j.tempdir=c:\users\liu\appdata\local \temp\e4jbf67.tmp_dir-dexe4j.unextractedposition=558234-djava.library.path=d:\program Files (x86) \JetBrains\ IntelliJ idea 12.1.7\bin\. \.\bin; C:\Program Files (x86) \common Files\netsarang; E:\PROJECT\ARACHNE\WEB\TRUNK\MURI_GM; E:\project\arachne\web\trunk\muri_im; C:windows\system32; C:\Windows; C:\Windows\System32\Wbem; C:\Windows\System32\WindowsPowerShell\v1.0\; C:\Program Files (x86) \intel\opencl sdk\2.0\bin\x86; C:\ProgramFiles (x86) \intel\opencl Sdk\2.0\bin\x64;d:\program Files\java\jdk1.7.0_07\bin;d:\program Files\Java\ Jdk1.7.0_07\jre\bin;d:\program Files\apache-maven-3.0.4-bin\apache-maven-3.0.4\bin; E:\project\arachne\web\trunk\muri_7z; E:\project\arachneweb\trunk\colorWIN;D:\Program Files\tortoisesvn\bin; C:\Python33; E:\pro2816 org.jetbrains.idea.maven.server.remotemavenserver-djava.awt.headless=true-xmx512m-dfile.encoding= GBK4304 com.muri.web.common.booter-agentlib:jdwp=transport=dt_socket,address=127.0.0.1:58490,suspend=y,server=n -dfile.encoding=utf-89432 sun.tools.jps.jps-lmv-denv.class.path=.;D: \ Program Files\java\jdk1.7.0_07lib\dt.jar;d:\program Files\java\jdk1.7.0_07lib\tools.jar;d:\program Files\ Javajdk1.7.0_07bin-dapplication.home=d:\program files\java\jdk1.7.0_07-xms8m



4848 processes for my IDE, 2816 for MAVEN process, 4304 for my test program, 9432 for JPS own process



jinfo (configuration info for Java): JVM Configuration Information Tool

You can output and modify the opts of the Java process at runtime. Simple to use for outputting Java system parameters and command line parameters

Command format: jinfo [options] [PID]

Common parameter Description:

-flag output, modify, JVM command line arguments

For example:

C:\users\liu>jinfo 4304Attaching to process ID 4304, please wait ... Debugger attached successfully. Server compiler detected. JVM version is 23.3-b01java System Properties: .... .....



jstack (stack trace for Java): JVM stack Trace Tool

Jstack is used to print out the Java stack information for a given Java process ID or core file or remote Debugging service, if it is on a 64-bit machine, you need to specify the option "-j-d64"

Command format: jstack [option] pid

Common parameter Description:

-F when ' jstack [-l] PID ' does not have a corresponding time to force the printing stack information

-L long list. Prints additional information about the lock, such as the ownable synchronizers list belonging to Java.util.concurrent.

-M prints all of the stack information for Java and Native/C + + frameworks.

-H | -help Printing Help information

For example:

C:\users\liu>jstack 43042014-09-12 10:22:42full thread dump Java HotSpot (TM) 64-bit Server VM (23.3-b01 mixed mode): "Qu Artzscheduler_scheduler-non_clustered_misfirehandler "Prio=6 tid=0x0000000012d17800 nid=0x21d0 waiting on condition [ 0X000000001DB7F000]   Java.lang.Thread.State:TIMED_WAITING (sleeping) at        Java.lang.Thread.sleep (Native Method) at        Org.quartz.impl.jdbcjobstore.jobstoresupport$misfirehandler.run (jobstoresupport.java:3963) ............



Jstat (JVM statistics monitoriing tool): JVM Statistics monitoring Tools


Real-time command line monitoring of Java application resources and performance, including monitoring of heap size and garbage collection status
Command format: jstat [option PID [interval [s | ms] [COUNT]]
Common parameter Description:
-gcutil the percentage of the total space used for the output
-gccapacity maximum and minimum space used by each region in the output heap

Example: Monitor JVM memory every 1 seconds, monitor 5 times in total

c:\users\liu>jstat-gccapacity 4304 1s 5 ngcmn    ngcmx     NGC     s0c   s1c       EC      ogcmn      ogcmx       OGC       OC      pgcmn    pgcmx     PGC       PC     ygc    FGC 32064.0 514048.0 249472.0 12416.0 11072.0 172800.0    64256.0  1028096.0    70208.0    70208.0  21248.0  83968.0  83008.0  83008.0     1 32064.0 514048.0 249472.0 12416.0 11072.0 172800.0    64256.0  1028096.0    70208.0    70208.0  21248.0  83968.0  83008.0  83008.0     1 32064.0 514048.0 249472.0 12416.0 11072.0 172800.0    64256.0  1028096.0    70208.0    70208.0  21248.0  83968.0  83008.0  83008.0     1 32064.0 514048.0 249472.0 12416.0 11072.0 172800.0    64256.0  1028096.0    70208.0    70208.0  21248.0  83968.0  83008.0  83008.0     1 32064.0 514048.0 249472.0 12416.0 11072.0 172800.0    64256.0  1028096.0    70208.0    70208.0  21248.0  83968.0  83008.0  83008.0     1



C:\users\liu>jstat-gcutil 4304 1s 5  S0     S1     E      O      P     ygc     ygct     FGC fgct GCT  0.00   0.00  73.56  57.80  49.91     0.217     1    0.218    0.435  0.00   0.00  74.13  57.80  49.91     0.217     1    0.218    0.435  0.00   0.00  74.13  57.80  49.91    0.217     1 0.218    0.435  0.00   0.00  74.13  57.80  49.91    0.217     1    0.218    0.435  0.00   0.00  74.13  57.80  49.91    0.217     1    0.218    0.435



Some terms are explained in Chinese:

S0C: Capacity of the first Survivor (Survivor area) in the Young Generation (bytes)
S1C: Capacity of the second survivor (Survivor area) in the younger generation (bytes)
S0U: The first survivor (Survivor area) of the young generation has currently used space (bytes)
S1U: The second survivor (Survivor area) of the young generation has currently used space (bytes)
EC: The Capacity of Eden (Eden) in the Young Generation (bytes)
EU: Eden (Eden) in the young generation has currently used space (bytes)
Capacity of the Oc:old generation (bytes)
Ou:old currently used space (bytes)
Pc:perm (persistent generation) capacity (bytes)
Pu:perm (persistent generation) currently used space (bytes)
YGC: Number of GC times in young generations from application startup to sampling
YGCT: The time taken by the GC in the young generation from application startup to sampling (s)
FGC: Old (full GC) GC count from application boot to sampling
FGCT: Time taken from an old (full GC) GC when the application boots to sampling (s)
GCT: GC Total time from Application boot to sample (s)

NGCMN: initial (minimum) size in Young generation (bytes)

NGCMX: Max capacity of young generation (bytes)

NGC: Current capacity in young generation (bytes)

The size (in bytes) of the initialization (minimum) in ogcmn:old generation

Maximum capacity of the Ogcmx:old generation (bytes)

The current newly generated capacity of the Ogc:old generation (bytes)

The size (in bytes) of the initialization (minimum) in pgcmn:perm generation

Maximum capacity of the Pgcmx:perm generation (bytes)

The current newly generated capacity of the Pgc:perm generation (bytes)

S0: The first survivor (Survivor area) of the young generation has been used as a percentage of current capacity

S1: The second survivor (Survivor area) in the younger generation has been used as a percentage of current capacity

E: Eden (Eden) in the young generation has been used as a percentage of current capacity

Percentage of current capacity used by O:old generation

Percentage of current capacity used by P:perm generation

S0CMX: Maximum Capacity (bytes) of the first Survivor (Survivor area) in the young generation

S1CMX: Maximum capacity of the second survivor (Survivor area) in the younger generation (bytes)

ECMX: Maximum capacity of Eden (Eden) in the Young Generation (bytes)

DSS: Capacity (bytes) currently required for Survivor (surviving area) (Eden area Full)

TT: Limited number of holds

MTT: Maximum number of hold limit

Jmap (Memory Map for Java): JVM Ram Image Tool


Print out all the ' objects ' in the memory of a Java process (using PID) (e.g., generating those objects, and their number)
Command format: jmap [option] pid
Common parameter Description:
-dump:[live,]format=b,file=<filename> output JVM's heap content to a file using binary form, the live sub-option is optional, and if you specify the live option, only the live object is exported to the file.
-histo[:live] Prints the number of instances per class, memory consumption, class full name information. The internal class name of the VM is prefixed with "*". If the live child parameter is added, only the number of live objects is counted.
-F coercion. Use the-dump or-histo parameters when the PID is not appropriate. In this mode, the live sub-argument is invalid.

For example: Enter the current heap memory image in binary form into file data.hprof

C:\users\liu>jmap-dump:live,format=b,file=data1.hprof 4304Dumping heap to C:\Users\liu\data1.hprof ... Heap dump file created



Generated files can be analyzed using the Jhat tool, which is useful for analyzing large objects when oom (memory overflow)
You can also get the dump file by starting the JVM with the following parameters:
-xx:+heapdumponoutofmemoryerror
-xx:heapdumppath=./java_pid<pid>.hprof

Generating a memory image file when a memory overflow occurs on the JVM

Jhat (JVM Heap Analysis tool): JVM Dump Snapshot Analyzer


Tools for offline Analysis of Java heap, he can analyze the heap information files exported from different virtual machines, such as files exported on Linux can be analyzed on Windows and can be used to find problems such as memory.
Command format: Jhat dumpfile (Jmap generated file)

Example: Analyzing the Jmap exported memory image

C:\users\liu>jhat data1.hprofreading from Data1.hprof ... Dump file created Fri Sep 10:27:25 CST 2014Snapshot Read, resolving ... Resolving 879257 objects ... Chasing references, expect 175 dots ......................................................................................................................... .................................................... Eliminating duplicate references ......................................................................................................................... .................................................... Snapshot resolved. Started HTTP Server on port 7000Server are ready.



after successful execution, accesshttp://localhost:7000to view memory information,

MAT (Memory Analyzer tool): An Eclipse-based analysis tools


Official website: http://www.eclipse.org/mat/
update:http://download.eclipse.org/mat/1.2/update-site/

This is a plug-in eclipse, after installation can open the Xxx.hprof file for analysis, more convenient to use than jhat , Sometimes because the online xxx.hprof file is too large, the direct use of jhat for preliminary analysis, you can copy to the local analysis of the results better.

Graphical monitoring tools:

There are two visual monitoring tools under the JDK installation directory bin
1. JConsole (Java monitoring and Management Console) is a JMX-based visual management tool.
2. VisualVM (all-in-one Java troubleshooting Tool) is the most powerful running monitoring and troubleshooting program released with the JDK.
Recommended to use VISUALVM, he has a lot of plugins that can more easily monitor the runtime JVM

Turn from: http://aub.iteye.com/blog/1873224


Java Virtual machine Memory monitoring Tool jps,jinfo,jstack,jstat,jmap,jhat use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.