The 10 main points of Java heap memory (heap memories):
1. Java heap Memory is part of the memory that the operating system allocates to the JVM.
2. When we create objects, they are stored in the Java heap memory.
3. To facilitate garbage collection, the Java heap space is divided into three zones, called New Generation, old Generation or tenured Generation, and perm space.
4. You can resize the Java heap space by using the JVM's command-line options-XMS,-xmx,-xmn. Don't forget to add "M" or "G" after the size to indicate the unit. For example, you can use-xmx256m to set the maximum heap memory size to 256MB.
5. You can use Jconsole or runtime.maxmemory (), Runtime.totalmemory (), runtime.freememory () to see the size of the heap memory in Java.
6. You can use the command "Jmap" to get heap dump and use "jhat" to analyze heap dump.
jmap -heap 21711
jmap -histo:live 21711 | more
jmap -dump:
format
=b,
file
=dumpFileName pid
The dump file can be viewed with tools such as Mat, VISUALVM, and Jhat:
jhat -port 9998 /tmp/dump.dat
Note If the dump file is too large, you may need to add-j-xmx512m This parameter specifies the maximum heap memory, which is Jhat-j-xmx512m-port 9998/tmp/dump.dat. Then you can enter the host address in the browser: 9998 viewed
7. Java heap space is different from the stack space, and the stack space is used to store the call stack and local variables.
8. The Java garbage collector is used to reclaim memory consumed by dead objects (objects that are no longer in use) and then release them into the Java heap space.
9. When you encounter Java.lang.outOfMemoryError, don't be nervous, sometimes just increase the heap space can be, but if often appear, it is necessary to see whether there is a memory leak in the Java program.
10. Use the profiler and heap dump analysis tools to view the Java heap space to see how much memory is allocated to each object.
Vmid is the Java Virtual machine ID, which is generally the process ID on the Linux/unix system. Interval is the sampling time interval. Count is the number of samples. For example, the following output is GC information, sampling time interval is 250ms, sample number is 4
jstat -gc 21711 250 4
Now to explain the meaning of each column:
1234567 |
S0C、S1C、S0U、S1U:Survivor 0 /1 区容量(Capacity)和使用量(Used) EC、EU:Eden区容量和使用量 OC、OU:年老代容量和使用量 PC、PU:永久代容量和使用量 YGC、YGT:年轻代GC次数和GC耗时 FGC、FGCT:Full GC次数和Full GC耗时 GCT:GC总耗时 |
Java Memory analysis