Java Memory Area

Source: Internet
Author: User

Java Memory classification: stack memory and heap memory

Heap Memory: The method area and heap memory, where the method area is a logical region of heap memory, also known as a non-heap, to differentiate itself from the Java heap memory. The method area and heap memory are areas shared by all threads.

Where stack memory is divided into: virtual machine stack, local method stack, program counter

Virtual Machine Stack: Describes the Java method of the memory model, in the execution of Java methods, will create a stack frame, this stack frame to save the local variable table, operand stack, dynamic link, method exit, local variable table is stored at compile time the basic data type (Int,double,float, Long,boolean,char, Btye), a reference to an object.

Local method Stack: a function written in C + + using the JNA JNI technology call.

Program counter: Records the line number when Java compiled bytecode is executed.

Method Area: Storage class information, static variables, constants, compiled code, which is more important is to run a constant pool, which is stored when the compile time has been confirmed by the various literal constants.

Object creation Process:

When the virtual opportunity goes to a new command, go to the constant pool to find the symbol reference for the class, and then check to see if the symbol reference represents a class that has already been loaded, initialized, and, if not, Just go find the. Class execution class loading process, after the class load completes, the virtual machine allocates the memory for the object, allocates the memory to have two methods: one is the pointer collision (has a pointer to the idle and the non-idle to separate, the object allocates the memory, only need to move the pointer position to be able, moves the distance is the object size) There is also a way when the idle list (due to the memory idle area, is a segment, is not contiguous, the virtual machine maintains an idle list, and when the object needs to allocate memory, the virtual machine finds a piece of appropriate memory from the free list). The specific way to do this depends on whether the memory in the Java heap is contiguous, and whether the memory in the Java heap is contiguous, whether the memory is collated when the virtual machine is being garbage collected.

If multiple threads need this fast memory solution at the same time: a lock operation when loading memory allocation, one is to allocate a piece of memory for each thread, when the memory is exhausted and new thread memory is needed to lock the operation, it improves efficiency.

After the memory allocation is finished, the object members need to be initialized, mainly to set the object header information (including the object's hash code, object generation information, the object is the instance of that class information).

object's memory layout: consists mainly of three parts (object header, instance data, memory needs to be aligned to fill) where instance data is really valid data. Alignment fills are generally used for memory alignment, with no practical meaning.

Common Virtual machine parameter settings:-xmx virtual machine Maximum allocated memory-XMS initialize the memory of the virtual machine, generally set to the same, avoid the program memory growth, but also for the virtual machine memory allocation, to avoid automatic expansion.

-xss Local method Stack capacity

Java Heap Memory Breakdown: Young generation and old generation, the young generation is divided into the Eden Zone from survivor District to survivor District to be continued ...

Java Memory Area

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.