Dump is a dump of information on the memory of the program runtime, allowing us to see how the program is running. Dump is a very useful tool for tuning and troubleshooting.
Heap Dump
The Java runtime objects are allocated to heap memory, and heap dump is a dump of heap memory.
Generated
There are two ways to build Heap dump:
1) Add an option when running-XX:+HeapDumpOnOutOfMemoryErrora Java program so that a Heap dump is automatically generated when the program has an out of Memory error.
2) Usejmapthe tool to generate. First we usejpsthe PID to find the program (strictly speaking is actually lvmid), and then run:
-dump:live,format=b,file=heap.bin <pid>
Analysis
You can use the Java-broughtjhattool to analyze Heap dump:
jhat
Wait a while and you'll be prompted
Started HTTP server on port 7000Server is ready.
This127.0.0.1:7000is the time to access the browser.
However, it isjhatless efficient to analyze larger Heap dumps, so it is recommended to use the Memory Analyzer (MAT) provided by Eclipse for analysis.
Thread Dump
Thread dump dumps the memory data (such as the call stack of the thread) that is related to threads. Thread dump is sometimes a javacore, but it seems that Javacore is an IBM virtual machine.
Generated
You can use your ownjstackgenerated Thread dump:
jstack <pid> >> thread.dump
Analysis
Thread dump is a text file format, open view directly.
Intellij idea provides an analysis of Stacktrace, which we can use to analyze thread dump, which makes it easy to know where a thread is running.
OpenIntellij IDEAD -> Analyze -> Anaylyze Stacktrace..., copy and paste the contents of Thread dump to confirm.
Core Dump
The Heap dump and Thread dump mentioned above are directly related to Java, and core dump is provided by the operating system, and all programs can generate a core dump when an unexpected exit occurs.
Core dump contains all the memory information when the program is running, so we can use core dump to analyze both the heap memory and the runtime stack.
Generated
The default operating system does not generate a Core dump, we need to open it first:
#If you use bashulimit - C unlimited, if you use zshlimit coredumpsize unlimited like me
Ulimit/limit is set to the size of the dump, the default is 0 is not dump. We can use the following command to see the size of the current setting:
#If you use bashulimit - C, if you use zshlimit coredumpsize like me
Once the confirmation is open, we can use itkill -ABRT <pid>to generate the core dump. However, it is important to note that using this method only Java programs running under the current Terminal can generate a core dump. That is, you have to open the Te of core dump. Rminal Run the Java program so that thekill -ABRT <pid>core dump is generated. If your Java program runs under a Terminal that does not have a core dump open, even if youkill -ABRT <pid>run the core dump Terminal, the Core dump is not generated at this time.
We can also usegcoreto generate a build core dump. It doesn't matter if you use Ulimit/limit to open core dump.
sudo gcore <pid>
The MAC under Core dump is generated under the/cores/folder.
Analysis
We can use itgdbto analyze the Core dump file.
Java comes withjstackandjmapcan also be used to analyze Core dump:
jstack <executable> <core dump file>jmap <executable> <core dump file>
This refers to the<executable>use of Java programs you run, youjavacan generally use$JAVA_HOME/bin/javainstead. If you specify a version that is not the same as the one you arejavarunningjava, it will be thrownsun.jvm.hotspot.debugger.UnmappedAddressException.
In addition you usejstackandjampalso need to be the corresponding version, otherwise you will be promptedCan‘t attach to the core file.
Transferred from: http://yoncise.com/2017/05/23/Java-Heap-Dump-Thread-Dump-and-Core-Dump/
Turn: Java-heap dump, Thread dump and Core dump