Explore JVM Memory leaks

Source: Internet
Author: User

Web services are always inexplicably run after a period of time after the JVM directly outofmemory error, memory leak problem is not easy to find, this article on some of the basic knowledge to find memory leaks to do a summary, does not involve a specific case analysis. 1 data display of JVM memory exceptions An example of 1.1 java.lang.OutOfMemoryError:PermGen space anomaly

Heap
Psyounggen total 44928K, used 916K [0x4e3c0000, 0x50fe0000, 0x51b10000)
Eden Space 44736K, 2% used [0x4e3c0000,0x4e4a5318,0x50f70000)
From space 192K, 0% used [0x50f70000,0x50f70000,0x50fa0000)
To space 192K, 0% used [0x50fb0000,0x50fb0000,0x50fe0000)
Psoldgen total 453312K, used 125529K [0x32910000, 0x4e3c0000, 0x4e3c0000)
Object Space 453312K, 27% used [0x32910000,0x3a3a6498,0x4e3c0000)
Pspermgen total 65536K, used 65535K [0x2e910000, 0x32910000, 0x32910000)
Object Space 65536K, 99% used [0x2e910000,0x3290fff8,0x32910000)

permanent space Persistence: storage for class and method objects. Spring uses cblib in AOP to generate many classes dynamically, and throws this exception when too many classes exceed maxpermsize. Parameter problems you can set JVM startup parameters: PermSize, MaxPermSize. The problem of the program will be analyzed in memory, as described below. An example of 1.2 Java.lang.OutOfMemoryError:Java heap space anomaly

Heap
Psyounggen total 88320K, used 67673K [0x44880000, 0x4ba40000, 0x4ba40000)
Eden Space 61952K, 100% used [0x44880000,0x48500000,0x48500000)
From space 26368K, 21% used [0x48500000,0x48a96490,0x49ec0000)
To space 24512K, 16% used [0x4a250000,0x4a6283e0,0x4ba40000)
Psoldgen total 932096K, used 582090K [0x0ba40000, 0x44880000, 0x44880000)
Object Space 932096K, 62% used [0x0ba40000,0x2f2b2a78,0x44880000)
Pspermgen total 131072K, used 35124K [0x03a40000, 0x0ba40000, 0x0ba40000)
Object Space 131072K, 26% used [0x03a40000,0x05c8d330,0x0ba40000)

Eden Space Usage 100%, always occupied, parameter problems can set JVM startup parameters: Xms, Xmx. The problem of the program will be analyzed in memory, as described below. 1.3 View JVM Memory Status:

Jstat-gcutil PID 1000 20

Examples of unusual situations

Jstat-gcutil PID 1000 20

S0 S1 E O P ygc ygct FGC fgct GCT
0.00 0.00 99.99 82.51 53.11 2409 1.205 10117 7250.393 7251.598
0.00 0.00 83.42 82.55 53.10 2409 1.205 10118 7252.650 7253.855
0.00 0.00 56.06 82.46 53.10 2410 1.205 10120 7254.467 7255.672
0.00 0.00 32.11 82.55 53.10 2411 1.205 10121 7256.673 7257.877
0.00 0.00 99.99 82.55 53.10 2412 1.205 10123 7257.026 7258.231
0.00 0.00 76.00 82.50 53.10 2412 1.205 10124 7259.241 7260.446

This data shows that the full GC occurs frequently.

Example of a normal situation

S0 S1 E O P ygc ygct FGC fgct GCT

0.00 0.00 0.24 55.39 99.60 171 0.667 1339 393.364 394.031

0.00 0.00 0.24 55.39 99.60 171 0.667 1339 393.364 394.031

0.00 0.00 0.24 55.39 99.60 171 0.667 1339 393.364 394.031

0.00 0.00 0.24 55.39 99.60 171 0.667 1339 393.364 394.031

0.00 0.00 0.24 55.39 99.60 171 0.667 1339 393.364 394.031

0.00 0.00 0.24 55.39 99.60 171 0.667 1339 393.364 394.031

Parameter meaning:
The percentage of space 0 used in the Survivor spaces on the S0:heap
The percentage of space 1 used in the Survivor spaces on the S1:heap
Eden space on the e:heap percentage of spaces used
The percentage of space used in the old Spaces section on the O:heap
P:perm Space percent used
YGC: Number of young GC occurrences from program startup to sampling
Ygct:young GC time (in seconds)
FGC: Number of full GC occurrences from program startup to sampling
Fgct:full GC time (in seconds)
GCT: Total time for garbage collection (in seconds)

2 dump out memory 2.1 Find the thread PID to dump

Under Windows, use the Tasklist

Under Linux, use the Ps–aux

2.2 Dump out memory usage details

You can use the command:

Jmap-dump:file=a.hprof PID

It can also be manipulated through the Jconsole graphical interface.

At the command line type: Jconsole

Jconsole Open after the artificial selection of dumpheap, input parameters p0,p1;p0 indicates the dump out of the file path, the suffix is. hprof P1 set to True, indicating that only the living object is parsed.

3 using the Memory profiling tool

There are a lot of tools for analyzing Java memory objects, such as Jprofiler tools, and the eclipse mat is an excellent source of memory object analysis. They are useful for analyzing memory overflow problems. The following is a simple example of an installation using Eclipse mat. 3.1 Install an Eclipse Memory Analysis plug-in Mat

http://download.eclipse.org/technology/mat/latest/update-site/

3.2 Switching to memory analysis mode

3.3 via file > Open Heap Dump .... View dump files

4 jdk Self-brought JVM view analysis Tools JPS, Jmap, Jstat, jconsole 4.1 /c24>

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.