Jmap,jhat Analyzing memory

Source: Internet
Author: User

When analyzing the memory usage of JAVA application,Jmap is a very useful lightweight tool. Use Jmap to see a summary of the heap space and to get a rough grasp of the heap usage. You can also generate heapdump files, and then use Jhat to analyze the objects and data in the content through a Web browser.

The Jmap is a tool that comes with the JDK and is very small and easy to support with the following parameters:

-heap Print a summary of the heap space, where you can roughly check the usage of the heap space.

Jmap-heap PID

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 fs@inspur92:~/test/llxdata/081005/tmp$ jmap -heap 30774Attaching to process ID 30774, please wait...Debugger attached successfully.Server compiler detected.JVM version is 20.1-b02using thread-local object allocation.Parallel GC with 8thread(s)Heap Configuration:   MinHeapFreeRatio = 40   MaxHeapFreeRatio = 70   MaxHeapSize      = 1073741824(1024.0MB)   NewSize          = 1310720(1.25MB)   MaxNewSize       = 17592186044415MB   OldSize          = 5439488(5.1875MB)   NewRatio         = 2   SurvivorRatio    = 8   PermSize         = 21757952(20.75MB)   MaxPermSize      = 268435456(256.0MB)Heap Usage:PS Young GenerationEden Space:   capacity = 353107968(336.75MB)   used     = 9083624(8.662818908691406MB)   free     = 344024344(328.0871810913086MB)   2.572477775409475% usedFrom Space:   capacity = 2359296(2.25MB)   used     = 0(0.0MB)   free     = 2359296(2.25MB)   0.0% usedTo Space:   capacity = 2359296(2.25MB)   used     = 0(0.0MB)   free     = 2359296(2.25MB)   0.0% usedPS Old Generation   capacity = 715849728(682.6875MB)   used     = 47522208(45.320709228515625MB)   free     = 668327520(637.3667907714844MB)   6.638573172720407% usedPS Perm Generation   capacity = 40435712(38.5625MB)   used     = 40067528(38.21137237548828MB)   free     = 368184(0.35112762451171875MB)   99.08945834810575% used

The output above is simple, and the fourth line begins to output the environment used by this process's java.

HEAP configuration: The JVM parameters that are set when the Java application is started. Like maximum use memory size, old generation, young generation, durable generation size, etc.

Heap Usage: Actual usage of the heap at that time. Including Cenozoic, Laosheng generation, and enduring generations.

The new generation includes: Eden area size, used size, idle size, and utilization. The survive area is the same from and to.

This can be a very simple view of the memory usage of this process.

can be used to analyze the size of the heap memory partition is reasonable, the new generation and Laosheng generation of the size allocation is appropriate and so on.

Maybe the process takes up a lot of total memory, but we can see here that the real use is not much, many are "free". Memory use of the accumulation of most of the old age, the memory pool Dew started here, so pay extra attention to the "older Generation".

Jmap-histo PID

This generates a statistical report of a class, which is very simple, such as showing how many instances of a class are, how many bytes are in total, and so on. As follows:

[Email protected]:~/test/llxdata/081005/tmp$ jmap-histo 30774

num     #instances          #bytes   class name---- ------------------------------------------   1:         12077        37306240     [I    2:           8404        8913528        [B    3:         55627         8311744      <constMethodKlass>    4:          55627        7576152       <methodKlass>    5:         35982         6771360     [C    6:          4838        5536240     < constantpoolklass>    7:         88849         4696992    <symbolKlass>    8:           4838        3735856    < instanceklassklass>    9:          4024         3334976    <constantPoolCacheKlass>   10:           4600        2201648     <methodDataKlass>   11:         35011         1120352    java.lang.String   12:           5286         549744    java.lang.Class   13:           6509         441272    [S   14:          7454          392128    [[I

The instructions for I, B, C, and so on are as follows  table 4.2.

BaseType  character Type interpretation
B byte signed byte
C Char Unicode character
D double double-precision floating-point value
F float single-precision floating-point value
I int integer
J long Long integer
l<classname>; Reference an instance of class De><classname>de>
S short signed short
Z boolean De>truede > or de>falsede>
[ reference one array dimension

Jmap-permstat

Print some persistent memory usage status, have "live", have "dead".

class_loader    classes bytes   parent_loader   alive?  type < bootstrap>     2099    12780072           null          live    <internal> 0x00000000c069dc58      1       1968    0x00000000c017e968      dead    sun/reflect/[email protected] 0x00000000c05c37d8      1       2008    0x00000000c017e968      dead    sun/reflect/[email protected] 0x00000000c069d900      1       1968    0x00000000c017e968      dead    sun/reflect/[email protected]

Not used.

-heap:format=b

Produces a heapdump file, which is an important parameter for generating a heapdump file. Example: Jmap-heap:format=b 2657 produces a heap.bin heapdump file. It is important to note that the parameter for this build Heapdump is JDK1.5, in 1.6 in the format: Jmap-dump:live,format=b,file=xxx 2657 is more powerful here, you can specify the object that is alive, There is also the name of the file that generated the heapdump.

When the used content of the test application is larger (4G or more), the dump takes a long time and is likely to cause the dump to fail.

Dump down the file combined with Jhat for analysis will be more convenient.

Jhat

Jhat is a Java heap replication browser. This tool parses the Java heap copy file (for example, generated by the "Jmap-dump" above). Jhat launches a Web server that allows objects in the heap to be parsed in a Web browser. This tool is not intended for use in application Systems but for "offline" analysis. The "Jhat tool is platform independent", which means that it can be used to observe the heap replication generated on any platform. For example, it is possible to use Jhat on a Linux system to observe a heap copy generated on the Solaris OS.
Export the native Java memory image to Heap.dmp, where the PID is the ID number of the Java process. Jmap-dump:live,format=b,file=heap.dmp PID
The exported image file can be analyzed using Jhat,-j is to pass a parameter to the Java virtual machine, such as-mx768m is the maximum available memory for the specified virtual machine is 768M. If the image file is large, you have to specify a large value, otherwise there will be outofmemeryerror errors during the parsing process.

Jhat-j-mx768m-port < port number: default is 7000> heap.dmp

Jmap,jhat Analyzing memory

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.