Jmap, jhat analysis memory, jmapjhat Analysis

Source: Internet
Author: User

Jmap, jhat analysis memory, jmapjhat Analysis

AnalysisJAVA Application memory usage,JmapIs a very practical lightweight tool. You can use jmap to view the heap space overview and get a rough grasp of the heap usage. You can also generateHeapdumpFile, and then use jhat to analyze the objects and data in the content through the web browser.

Jmap is a built-in JDK tool that is very small and convenient. Its supported parameters are as follows:

-The heap prints the heap space overview. Here, we can roughly check the heap space usage.

Jmap-heap PID

 

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 8 thread(s)Heap Configuration:   MinHeapFreeRatio = 40   MaxHeapFreeRatio = 70   MaxHeapSize      = 1073741824 (1024.0MB)   NewSize          = 1310720 (1.25MB)   MaxNewSize       = 17592186044415 MB   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 above output is very simple. Start from the fourth line and output the JAVA used by this process.Environment.

Heap Configuration: Specifies the JVM parameter set when a java application is started. Image usageMemorySize, age generation, young generation, lasting generation size, etc.

Heap Usage: the actual Usage of heap at that time. Including the new generation, the old generation and the lasting generation.

The new generation includes the Eden area size, used size, idle size, and usage. The From and To in the keep ve area are the same.

You can easily view the memory usage of this process.

It can be used to analyze whether the heap memory partition size is reasonable, and whether the size distribution of the new generation and old generation is appropriate.

The process may occupy a large amount of memory, but we can see that there is not much actually used here, many of which are "Free ". The accumulation of memory usage is mostly in the Old age, and the memory pool exposure starts here, so you need to pay special attention to "Old Generation ".

Jmap-histo PID

A statistical report of the class is generated here. This table is very simple, such as displaying the number of instances of the class and the total number of bytes. As follows:

Fs @ inspur92 :~ /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 descriptions of I, B, and C are as follows: Table 4.2.

BaseTypeCharacter 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 the memory usage status of some persistent generations, including "active" and "dead.

Class_loader classes bytes parent_loader alive? Type <bootstrap> 2099 12780072 null live <internal> 0x00000000c069dc58 1 1968 includead sun/reflect/DelegatingClassLoader @ 000000001 2008 includead sun/reflect/DelegatingClassLoader @ 000000001 1968 includead sun/reflect/DelegatingClassLoader @ 0x00000000b00685b0

Not commonly used.

-Heap: format = B

Generate a HeapDump file, which is an important parameter for generating the heapdump file. For example, jmap-heap: format = B 2657 generates a heap. bin heapdump file. It should be noted that the heapdump generated here is JDK1.5, and the format in 1.6 is jmap-dump: live, format = B, file = xxx 2657, which is more powerful here, you can specify a surviving object and a heapdump file name.

When the content used by the application under test is large (4G or above), dump takes a long time and may cause dump to fail.

It is more convenient to analyze dump files with jhat.

Jhat

Jhat is a Java heap replication browser. This tool analyzes Java heap replication files (for example, generated by the above "jmap-dump ). Jhat starts a web server that allows heap objects to be analyzed in a web browser. This tool is not intended for application systems but for "offline" analysis. "Jhat tool is platform independent", which means it can be used to observe heap replication generated on any platform. For example, we may use jhat on Linux to observe a heap replication on Solaris OS.
Export the local java memory image to heap. dmp, where PID is the java Process ID. Jmap-dump: live, format = B, file = heap. dmp PID
The exported image file can be analyzed using jhat.-J transmits a parameter to the Java Virtual Machine. For example,-mx768m indicates that the maximum available memory of the virtual machine is 768 MB. If the image file is large, you must specify a large value. Otherwise, an OutOfMemeryError occurs during the analysis.

Jhat-J-mx768m-port <port: Default: 7000> heap. dmp

 

Article

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.