Java memory leak problem locating common commands __java

Source: Internet
Author: User
Tags epoll
Jstat-gcutil PID 10000
Lsof-p PID
Lsof-p PID | Wc-l
LS-AL/PROC/PID/FD #直接打印出当前此process all open files
jmap-histo:live pid > Info.log
Jmap-dump:live,file=mydumpfile PID
Jhat Mydumpfile
http://ip:7000 page directly to the bottom, you can see the number of instances cited ranking, where memory leaks.


Lsof-p 26674 ls-al/proc/pid/fd
There are large quantities of open anon_inode:[eventpoll] and pipe, if more than 100 eventpoll,
Typically, too many handlerthread/looper/messagequeue are turned on, threads forget to close, or Looper are not released.
Anon_inode:[eventpoll], this type of inode is created by Epoll.
Linux under the Java selector implementation is epoll combined with a pipe to implement the event notification function. So there will be anon_inode:[eventpoll and pipe types of FD in the NIO program.


Considerations for file handles in Linux: 1. In Linux, if a file is being occupied by a process, the user operations RM deletes the file, we find that the file no longer exists, but in fact the file is still on disk. The disk space occupied by the file will not be freed until the process that uses it exits.
In Linux, each file has 2 counters, I_count and I_nlink. I_count indicates the number of files being invoked. I_nlink represents the number of hard links.


The jmap Command jmap command can be used to output all in-memory objects, and can even dump the heap in the VM into text as binary. You can output details of all objects in the memory of a specified Java process, including the number of specific objects, and so on.
Jmap output of the heap information binary files, can be combined with jhat and other memory analysis tools for follow-up analysis.

Grammar:
jmap [option] <pid>//to connect to Running process
jmap [option] <executable <core>//to Connect to a core file
jmap [option] [server_id@]<remote server IP or hostname>//to connect to remote debug server

Basic parameters:
<none> to print same info as Solaris Pmap
-heap to print Java heap summary//print heap profile, GC usage algorithms, heap configuration and wise heap usage
-histo[:live] To print histogram of Java object heap; If the "Live"
Suboption is specified, only count live objects//print the number of instances per class, memory footprint, class full name information. The VM's inner class name begins with a prefix of "*". If you bring live, you only count the number of live objects.
-clstats to print class loader statistics
-finalizerinfo to print information on objects awaiting finalization//print information for objects waiting to be reclaimed
-dump:<dump-options> to dump Java heap in hprof binary format
Dump-options:
Live dump only live objects; If not specified,
All objects in the heap are dumped.
Format=b binary format
File=<file> dump Heap to <file>
Example:jmap-dump:live,format=b,file=heap.bin <pid>//binary file form dump output to file
-F Force. Use with-dump:<dump-options> <pid> Or-histo
To force a heap dump or histogram if <pid> does not
Respond. The "Live" suboption is not supported
In this mode.
-H | -help to print the
-j<flag> to pass <flag> directly to the runtime system

For example:
#jmap-dump:format=b,file=mydumpfile $pid://You can output the memory heap of the specified PID process to the specified file

#jmap-finalizerinfo 15931
Attaching to process ID 15931 ...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.77-b03
Number of objects pending for finalization:0///Waiting for collection of objects 0

Attention:
jdk1.8 started, the JVM parameters were adjusted:

1.PermGen space was removed and replaced by metaspace (meta space).
Therefore, the startup parameters need to be adjusted:-xx:permsize=128m-xx:maxpermsize=512m modified to-xx:metaspacesize=128m-xx:maxmetaspacesize=512m.
The space of the persistent generation is completely deleted, and it is replaced by a region called the meta space. After the persistence generation has been deleted, it is clear that the JVM ignores both permsize and MaxPermSize parameters.
The hotspot JVM for JDK 8 now uses local memory to represent the class's metadata, which is called the meta space.

Parameter value set how much appropriate: After the program runs, through JSTAT-GC PID can see the MC and MU situation, according to the actual situation to set:
JSTAT-GC 30648
s0c s1c s0u s1u EC EU OC OU MC MU CCSC ccsu ygc ygct FGC T GCT
11776.0 11264.0 0.0 8839.4, 1318400.0 651388.6 2682880.0 669041.2 77312.0 74831.9 8960.0 8489.2 871 6.434 3 0.247 6.681

Some tools in the meta space
Jmap-permstat changed into a jmap-clstats. It is used to print the Java Heap's class loader statistics. For each class loader, it prints out its name, whether it survives, the address, the parent loader, and the number and size of classes it has loaded. In addition, the number and size of the resident strings (intern) are also printed.
JSTAT-GC, this command outputs the meta space information rather than the persistent generation.
Jcmd Gc.class_stats provides detailed information about the size of the class metadata. You need to add the-xx:+unlockdiagnosticvmoptions option when starting a program with this feature.

2.CompressedClassSpaceSize = 1073741824 (1024.0MB) added this.
Compressedclassspacesize tuning is only effective when the-xx:+usecompressedclasspointers is open.
-xx:compressedclassspacesize=1g this size is fixed at boot time, so it's best to set it up a bit. If you don't use it, don't set it up, and the JVM may be able to grow dynamically in the future. The block does not require a contiguous area, as long as it is accessible from the base site.

Query Usecompressedclasspointers whether the currently open command:
#java-xx:+printflagsinitial | grep usecompressedclasspointers
BOOL Usecompressedclasspointers = false {lp64_product}


# Jmap-heap 29675
Attaching to process ID 29675 ...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.77-b03

Using Thread-local object allocation.
Parallel GC with 8 thread (s)

Heap Configuration://Heap Configuration
Minheapfreeratio = 0//Minimum heap usage ratio
Maxheapfreeratio = 100//maximum heap availability ratio
Maxheapsize = 4120903680 (3930.0MB)//maximum heap space size
newsize = 1373634560 (1310.0MB)//Cenozoic allocation size
Maxnewsize = 1373634560 (1310.0MB)//maximum Cenozoic allocation size
Oldsize = 2747269120 (2620.0MB)//The size of the generation
Newratio = 2//Cenozoic ratio
Survivorratio = 8//ratio of Cenozoic to Suvivor
Metaspacesize = 21807104 (20.796875MB)//JDK 1.8 introduced the new parameter meta space, 1.7 and the old version is used PermSize
Compressedclassspacesize = 1073741824 (1024.0MB)//JDK 1.8 introduced a new tuning parameter, only the-xx:+usecompressedclasspointers open case is effective
Maxmetaspacesize = 536870912 (512.0MB)//JDK 1.8 introduced the new parameter meta space, 1.7 and the old version is used MaxPermSize
g1heapregionsize = 0 (0.0MB)//Set the size of the area produced by G1 the Java heap, the default value can provide maximum ergonomics. The minimum value is 1M, the maximum is 32M, up to 1024, the recommended default value

Heap Usage://Heap usage
PS Young Generation//Cenozoic
Eden Space://Eden Area
Capacity = 1190133760 (1135.0MB)//capacity
used = 358255360 (341.658935546875MB)
Free = 831878400 (793.341064453125MB)
30.102108858755507% used
From spaces://survior1
Capacity = 88604672 (84.5MB)
used = 62335048 (59.44733428955078MB)
Free = 26269624 (25.05266571044922MB)
70.35187489887666% used
To space://survior2
Capacity = 91750400 (87.5MB)
Used = 0 (0.0MB)
Free = 91750400 (87.5MB)
0.0% used
PS old Generation//old generation
Capacity = 2747269120 (2620.0MB)
used = 56041168 (53.44502258300781MB)
Free = 2691227952 (2566.554977416992MB)
2.0398863581300692% used

33056 interned Strings occupying 3268472 bytes.

Jstat command

Jstat-gcutil PID 10000

Jstat-options: Viewing options
[Root@standalone fd_test]# Jstat-options
-class
-compiler
-gc
-gccapacity
-gccause
-gcmetacapacity
-gcnew
-gcnewcapacity
-gcold
-gcoldcapacity
-gcutil
-printcompilation


The information of the Jstat-gcnewcapacity:new object and its consumption
[Root@standalone fd_test]# jstat-gcnewcapacity 9813
NGCMN ngcmx NGC s0cmx s0c s1cmx s1c ecmx EC YGC FGC
1638400.0 1638400.0 1638400.0 545792.0 165376.0 545792.0 167424.0 1637376.0 1303552.0 20 14
[Root@standalone fd_test]#


Information for Jstat-gcold:old objects
[Root@standalone fd_test]# Jstat-gcold 9813
MC MU CCSC CCSU OC OU ygc FGC fgct GCT
81408.0 78294.9 9472.0 8923.0 3276800.0 320566.8 20 14 1.677 2.579

The information of the Jstat-gcoldcapacity:old object and its consumption
[Root@standalone fd_test]# jstat-gcoldcapacity 9813
OGCMN ogcmx OGC OC ygc FGC fgct GCT
3276800.0 3276800.0 3276800.0 3276800.0 20 14 1.677 2.579

Jstat-printcompilation: Information on current VM execution
Print every 1 seconds, and you can add-h5 every five elements to show the title
[Root@standalone fd_test]# jstat-printcompilation-h5 9813 1000
Compiled Size Type method
15349 4741 1 Sun/security/x509/ava torfc2253canonicalstring
15349 4741 1 Sun/security/x509/ava torfc2253canonicalstring
15349 4741 1 Sun/security/x509/ava torfc2253canonicalstring
15349 4741 1 Sun/security/x509/ava torfc2253canonicalstring
15349 4741 1 Sun/security/x509/ava torfc2253canonicalstring
Compiled Size Type method
15349 4741 1 Sun/security/x509/ava torfc2253canonicalstring
15349 4741 1 Sun/security/x509/ava torfc2253canonicalstring
15354 1793 1 Org/pentaho/di/core/logging/logbackeventlistener formattermsg
15356 127 1 Java/util/collections$unmodifiablemap$unmodifiableentryset iterator
15356 127 1 Java/util/collections$unmodifiablemap$unmodifiableentryset iterator
Compiled Size Type method
15356 127 1 Java/util/collections$unmodifiablemap$unmodifiableentryset iterator
15356 127 1 Java/util/collections$unmodifiablemap$unmodifiableentryset iterator
15356 127 1 Java/util/collections$unmodifiablemap$unmodifiableentryset iterator
15356 127 1 Java/util/collections$unmodifiablemap$unmodifiableentryset iterator
15356 127 1 Java/util/collections$unmodifiablemap$unmodifiableentryset iterator

Jstack command
If a Java program crashes to generate a core file, the Jstack tool can be used to obtain information about the Java stack and native stack of the core file, making it easy to know how the Java program crashes and where the problem occurs in the program.
Jstack is used to print out the Java stack information for a given Java process ID or core file or remote debugging service, and if it is on a 64-bit machine, you need to specify the option "-j-d64".
Generally, the thread information output through Jstack mainly includes the JVM's own thread, the user thread, and so on. Where the JVM thread will exist when the JVM is started. For a user thread, it is generated only when the user accesses it.

Usage:
Jstack [-l] <pid>
(to connect to running process)
Jstack-f [-M] [-l] <pid>
(to connect to a hung process)
Jstack [M] [-l] <executable> <core>
(to connect to a core file)
Jstack [-M] [-l] [server_id@]<remote server IP or hostname>
(to connect to a remote debug server)

Options:
-F to force a thread dump. Use as Jstack <pid> does not respond (process is hung)
-M to print both Java and native frames (mixed mode)
-L Long listing. Prints additional information about locks
-H or-help to print

Related 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.