1.1. Java Dump Overview
Javadump is a run-time snapshot of the Java Virtual machine. When you make and analyze dumps, you often save the state and information from the time when the Java virtual Runtime is running to the dump file.
Dump Category:
Thread dump, which contains the running state of all threads in the JVM process. Plain text format.
Heap dump containing the thread dump and the state of all heap objects. binary format.
1.2. Production and analysis of Dump1.2.1. Common Java Virtual machines
The dump specification for different Java virtual machines is not exactly the same. Thread DUNP is a plain text format, with a slightly different virtual machine.
|
Java Virtual machine Type |
Description |
|
HotSpot VMS |
The original Sun Java Virtual machine implementation. Heap dump is in hprof binary format. |
|
IBM J9 VMS |
IBM's Java Virtual machine, common to IBM's AIX and other machines. Heap dump is in the PhD binary format. |
|
OpenJDK |
The open source version of the Java Virtual Machine implementation is much the same as the Hotspot VM implementation. Heap dump is in hprof binary format. |
|
JRockit |
Java Virtual Machine Implementation of the original BEA. Heap dump is in hprof binary format. |
|
HP JDK |
Java Virtual machine Implementation on the HP server. Heap dump is in hprof binary format. |
Ibmportable Heap Dump (PHD): This proprietary IBM format contains only the type and size of each Java object in the process, and the relationships between those objects. This dump file format is much smaller than other formats and contains only the least amount of information. However, this data is often sufficient for analyzing memory leaks and understanding the basic architecture and scope of the application.
Hprof binary dump file: The hprof binary dump file contains all the data representation in the IBMPHD format, as well as the basic data types inside Java objects and threads, you can view the values of the fields in the object and see what methods are being executed when the dump file is produced. Other basic data makes the HPROF dump file significantly larger than the PHD format dump file, which is about as large as the Java heap used.
1.2.2. Making Java Dump
Use graphical or command-line tools to generate a dump of the specified Java process and save it to a file in a different operating system platform and in a different Java Virtual machine environment.
Use the JDK's own tool, connect the BES instances, create a dump
HotSpot Runtime Environment:
The HotSpot-based Java runtime is capable of generating only dump files in the HPROF format.
You can start by Ps/jps: View the process information in Java in this machine. Then use the Jstack to print the thread's stack information and make the thread dump.
|
Knowledge Points:
Solaris/usr/bin/ps will truncate the process name, and many times it is inconvenient to know the full process name. and/usr/ucb/ps has parameters to display the full name:
/USR/UCB/PS-AUXWW |grep Java |
There are several ways to make the heap dump:
|
Method |
Instructions for use |
|
Jmap Tools |
The Jmap is located in the JDK's Bin directory, which provides an option to request a HPROF dump file from a running process. In Java 5, to use:
Jmap-dump:format=b PID
In Java 6, you use the following command, where live is optional, which means that only the "live" object that is being written to the dump file process ID (PID) is returned:
Jmap-dump[live,]format=b,file=filename PID |
|
Jconsole Tools |
The dumpheap operation is provided based on the JConsole hotspotdiagnostic MBean. This operation requires that a HPROF Dump be generated. |
|
JVM Events |
When encountering OutOfMemoryError: if the running application sets the-xx:+heapdumponoutofmemoryerror command-line option, there will be a HPROF when the OutOfMemoryError error occurs. The format of the dump file is generated. Using this method in a production system is good because it almost always needs to analyze memory problems and it does not cause additional performance overhead. In the older version of the HotSpot-based Java runtime, there is no limit to the number of heap dump files generated by this event per JVM execution, whereas in the new version, the heap dump file generated by each event that the JVM executes has a maximum value. |
IBM JDK Runtime Environment:
The -Xdump:what default dump trigger event is configured with the option to view.
|
Event |
Describe |
Available filters |
Example |
|
gpf |
General protection Failures (crashes) |
-xdump:system:events=gpf |
|
User |
User-triggered information (sigquit or Ctrl+break) |
-xdump:system:events=user |
|
Vmstop |
VM shutdown, including call System.exit () |
Exit code |
-xdump:system:events=vmstop,filter= #0: #10
A system dump file with a 0 to 10 exit code is generated when the VM shuts down. |
|
Load |
Class loading |
Class name |
-xdump:system:events=load,filter=com/ibm/example/example
A system dump file is generated when the Com.ibm.example.Example class loads. |
|
Unload |
Class Unload |
Class name |
-xdump:system:events=unload,filter=com/ibm/example/example
A system dump file is generated when the Com.ibm.example.Example class unloads. |
|
Throw |
Throws an exception |
Exception class name |
-xdump:system:events=throw,filter=java/net/connectexception
Generates a system dump file when Connectexception is generated. |
|
Catch |
Snapping to an exception |
Exception class name |
-xdump:system:events=catch,filter=java/net/connectexception
Generates a system dump file when Connectexception is captured. |
|
Systhrow |
The JVM throws a Java exception. (This is different from the throw event because it can only be triggered by an error condition detected inside the JVM.) ) |
Exception class name |
-xdump:system:events=systhrow,filter=java/lang/outofmemoryerror
Generates a system dump file when OutOfMemoryError is generated. |
|
Allocation |
Assigning a Java object |
The size of the allocated object |
-xdump:system:events=allocate,filter= #5m
A system dump file is generated when an object larger than 5MB is allocated. |
Jrokit Operating Environment:
Use the command first:
Jrcmd <pid> Help
Get the relevant options.
Thread Dump:
Jrcmd <pid> Print_threads
Heap Dump:
Jrcmd <pid> Hprofdump filename=/home/bes/test.hprof
Use the BES feature to create a dump
Thread dump can be produced using CLI's Threaddump command or via BES console;
Cli:
Besconsole:
Heap dump, which needs to be used to add JVM parameters to the BES, according to the JVM parameter usage instructions;
1.2.3. Parsing thread Dump
Tools for analyzing thread dump
1. Thread Dump Analyzer (TDA)
2. IBM Thread and Monitor Dump Analyzer (TMDA)
Principle
1. Combine the reasoning of code reading. The thread dump and source code need to be mutually deduced and verified.
2. The cause of the problem is often not directly reflected on the call stack, and it is important to note that all calls before remainders are currently called by the thread.
3. Make multiple thread dump, use the comparison function of TMDA, analyze the continuous state of the system.
Thread state
NEW, not started. does not appear in dump.
RUNNABLE, executed within the virtual machine.
BLOCKED, blocked and waiting for the monitor lock.
Wating, waits indefinitely for another thread to perform a specific operation.
Timed_wating, a time-bound wait for a specific operation on another thread.
TERMINATED, has exited.
Call adornments
Locked < address > destination: Use synchronized to apply the object lock successfully, the owner of the Monitor.
Waiting to lock < address > target: Use synchronized Request object Lock unsuccessful, wait in the entry area.
Waiting on < address > target: After the object lock with synchronized is successful, release the lock shipowner wait in the waiting area.
Parking to-Wait for < address > destination: Park is a basic thread blocking primitive that is not blocked by the monitor on the object.
Thread action
Runnable: The state is generally Runnable.
In Object.wait (): Wait zone waits, status is waiting or timed_waiting.
Waiting for Monitor entry: Enter zone wait, status is blocked.
Waiting on condition: Waiting area waiting, park.
Sleeping: Dormant thread, called Thread.Sleep ().
Example
Example 1:
Symptom: A thread state blocked, thread action wait on monitor entry, call adornment waiting to lock always appears together.
Inference: Represents a call that already has a conflict at the code level. Inevitably there is a problem with the code that needs to be minimized as it happens.
Example 2:
Phenomenon: A thread locks an object, and a large number of other threads wait on the object.
Inference: There is a synchronization block blocking
Some tricks
1. Take a bold guess and prove it carefully.
2. Read the code carefully.
3. Note that the calling stack is different from the thread.
1.2.4. Analysis Heap Dump
Tools for analyzing heap dump
1. Java visualvm:jdk comes with. Physical memory is much more idle, which is a simple view of system information, virtual machine parameters, classes, and object states. Support OQL Query Language, and plug-in extension.
2. Memory Analyzer (MAT): Developed by the Eclipse Foundation. Recommended when analyzing heap dump.
3. IBM Heapanalyzer
Contents of Heap Dump
4. System Information, virtual machine properties.
5. Full thread dump.
6. State of all classes and objects.
Usage Scenarios for heap dump analysis
1. In the event of an out-of-memory, GC exception, suspect that the code has a memory leak. Make heap dump to find the object associated with the life cycle error and the associated code. The JSTAT–GC pidinterval (s/ms) can be used to monitor the BES instance GC case, for example:
2. In some complex scenarios, you need to see the state of the object.
Out of memory errors
OutOfMemoryError old generation memory is low.
Outofmemoryerror:permgen space has insufficient memory for permanent generation.
OUTOFMEMORYERROR:GC overhead limit exceed garbage collection time consumes 98% or more of the system run time.
Tips for use
1. If the program is out of memory or frequent GC, there is a high likelihood of a memory leak, which is the case with Java heap dump to view the object.
2. To make a heap dump you can directly use the Jmap command that comes with the JVM
3. You can use the JMAP-HEAP command to see how the heap is being used, and to see how each heap space is occupied.
4. Use jmap-histo:[live] To view the objects in the heap memory. If a large number of objects continue to be referenced and not released, then a memory leak is generated, and it is necessary to combine the code to release the unused objects.
5. You can also use the jmap-dump:format=b,file=<filename> command to save heap information to a file, and then view the details with the Jhat command
6. In memory leakage, overflow or other prerequisites, it is recommended to dump several times of memory, memory files for the number of archives, easy to follow-up memory collation analysis.
Analysis of Javadump in Besappserver