Java Virtual machine Learning (1): Architecture memory model

Source: Internet
Author: User
Tags xms

One: Java technology system module diagram

Java Technology Architecture Module diagram

Two: JVM Memory area model

1. Method area

Also known as "permanent generation", "non-heap", it is used to store virtual machine loaded class information, constants, static variables, is the memory area shared by each thread. The default minimum value is 16MB and the maximum value is 64MB, which limits the size of the method area through the-xx:permsize and-xx:maxpermsize parameters.

Run a constant pool: is a part of the method area, in addition to the class file has a version of the classes, fields, methods, interfaces, and other descriptive information, there is also a const pool, used to hold the compiler generated a variety of symbol references, which will be placed in the method area after the class loaded in the run constant pool.

2. Virtual Machine stack

Describes the memory model that is executed by the Java method: Each method is executed with a "stack frame" that stores information such as the local variable table (including parameters), the Operation Stack, the method exit, and so on. Each method is called to the completion of the process, corresponding to a stack frame in the virtual machine stack from the stack to the process of the stack. The declaration period is the same as the thread and is thread-private.

A local variable table holds the various basic data types known to the compiler (Boolean, Byte, char, short, int, float, long, double), object reference (reference pointer, not the object itself), Where 64-bit long and double-type data takes up 2 local variables, the remaining data types are only 1. The memory space required for a local variable table is allocated during compilation, and when entering a method, this method requires that the local variable allocated in the stack frame is fully deterministic, and the stack frame does not change the size space of the local variable table during the run time.

3. Local Method Stack

Similar to the virtual machine stack, the difference lies in the Java method service that the virtual machine stack executes for the virtual machine, while the local method stack serves the native method.

4. Heap

Also called the Java heap, the GC heap is the largest memory area managed by the Java Virtual machine, and is a memory area shared by each thread that is created when the JVM is started. This memory area holds the object instances and arrays (all new objects). Its size is set by the-XMS (minimum) and-xmx (maximum) parameters,-xms the minimum memory requested when the JVM starts, defaults to 1/64 of the operating system's physical memory, but less than 1G,-XMX is the maximum memory that the JVM can request, and defaults to 1/4 but less than 1G of physical memory. By default, when the free heap memory is less than 40%, the JVM increases the size specified by the heap to-XMX, which can be specified by-xx:minheapfreeration=, and when the free heap memory is greater than 70%, the JVM reduces the size of the heap to the size specified by-XMS. This comparison column can be specified by xx:maxheapfreeration=, and in the case of running the system, to avoid frequent resizing of the heap at run time, the-XMS is usually set to the same value as-XMX.

Since collectors are now using generational collection algorithms, the heap is divided into the new generation and the old age. The new generation primarily stores newly created objects and objects that have not yet entered the old age. The old age stores the objects that survived by several new generation GC (Minor GC).

Cenozoic:

The newly created object of the program is to allocate memory from the Cenozoic, and the Cenozoic is made up of Eden Space and two blocks of survivor space of the same size (usually called S0 and S1 or from and to), which can be specified by the-XMN parameter, or by-XX: Survivorration to adjust the size of Eden space and survivor space.

Old Age:

For storing objects that have survived through multiple Cenozoic GC, such as cached objects, new objects may also enter the old age, mainly in two cases: ①. Large objects, which can be set by the startup parameter-xx:pretenuresizethreshold=1024 (in bytes, default = 0 ) to represent more than the age of the allocation of the new generation, but directly in the old age distribution. ②. A large Array object that has no reference to the outer object in the tangent array.

Older generations accounted for the memory size of-xmx corresponding to the value minus-xmn corresponding value.

5. Program counter

is the smallest piece of memory area, its role is the current thread executes the byte code of the line number indicator, in the virtual machine model, the bytecode interpreter works by changing the value of this counter to select the next need to execute the byte code instruction, branch, loop, exception handling, Basic functions such as thread recovery need to rely on counters to complete.

Three: Direct Memory

Direct memory is not part of the virtual machine memory, nor is it a memory area defined in the Java Virtual Machine specification. The newly added NiO in jdk1.4, which introduces the IO mode of channel and buffer, can call the native method to allocate out-of-heap memory directly, which is the native memory and does not affect the size of heap memory.

Java Virtual machine Learning (1): Architecture memory model

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.