JVM Series 1: JVM memory composition and allocation

Source: Internet
Author: User
Tags xms

Java memory composition:Heap and non-heap memory

According to the official statement: "A Java virtual machine has a heap. The heap is the runtime data area, and the memory of all class instances and arrays is allocated from this place. The heap is created when the Java Virtual Machine is started ." "Memory outside of the heap in JVM is called non-heap memory )". JVM manages two types of memory: heap and non-heap. In short, heap is JavaCodeAccessible memory is reserved for developers; non-heap memory is reserved for JVM, therefore, the method area, JVM internal processing or optimization of the required memory (such as the code cache after JIT compilation), each class structure (such as the runtime data pool, field and method data) the methods and constructor code are all in non-heap memory.

Component Diagram

    • Method stack & local method Stack:
      The stack frame is generated when the thread is created and the method is executed.
    • Method Area
      Metadata constants of storage classes
    • Heap
      All new operations in Java code
    • Native memory (C heap)
      Direct bytebuffer JNI compile GC;

 

Heap Memory Allocation

The initial memory allocated by JVM is specified by-XMS. The default value is 1/64 of the physical memory. The maximum memory allocated by JVM is determined by-xmx. The default value is 1/4 of the physical memory. By default, when the free heap memory is less than 40%, the JVM will increase the heap until the maximum limit of-xmx. When the free heap memory is greater than 70%, the JVM will reduce the minimum limit of heap until-XMS. Therefore, the server generally sets-XMS and-xmx to be equal to each other to avoid adjusting the heap size after each GC. The object heap memory is recycled by the automatic memory management system called the garbage collector.

 

Composition Details
Young Generation That is, the Eden + from space + to space in the figure

Eden

Store new objects

Survivor Space

There are two objects that are stored after each garbage collection
Old Generation Tenured generation is the old space in the figure.
Mainly stores applicationsProgramObjects with long Lifecycle

Non-heap memory allocation
JVM uses-XX: permsize to set the non-heap memory initial value. The default value is 1/64 of the physical memory. The maximum non-heap memory size is set by XX: maxpermsize. The default value is 1/4 of the physical memory.

Composition Details
Permanent generation Save the static (refective) data of the Virtual Machine
It mainly stores static objects at the class level loaded, such as class, method, field, etc.
If the permanent generation space is insufficient, full GC is triggered (For details, refer to the hotspot vm gc type)
Code Cache Memory used to compile and save native code
JVM internal processing or Optimization

JVM memory limit (maximum)

The maximum JVM memory has a lot to do with the operating system. Simply put, although the 32-bit processor has a controllable memory space of 4 GB, the specific operating system will impose a limit, this limit is generally 2 GB-3 GB (1.5 GB-2 GB in windows and 2 GB-3 GB in Linux ), the 64-bit and above processors will not be limited.

RelatedArticle: Http://www.cnblogs.com/redcreen/tag/jvm/

References:

Http://blog.csdn.net/softwave/archive/2011/03/10/6238747.aspx

Http://www.7dtest.com/site/html/74/t-4574.html

Sun JDK 1.6 Memory Management

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.