Java Memory analysis

Source: Internet
Author: User

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 pidThe dump file can be viewed with tools such as Mat, VISUALVM, and Jhat: jhat -port 9998 /tmp/dump.datNote 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

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.