Java Memory storage area and memory overflow exception (i)

Source: Internet
Author: User

**java Memory storage area and memory overflow exception (i) * *

Java virtual machines in the course of executing a Java program will divide the memory that it manages into several different data regions that have their own purpose, as well as the time of creation and destruction, some regions that exist as virtual machine processes start, and some that depend on the start and end of user processes to build and destroy , the memory managed by the Java Virtual machine will include the following runtime data regions, one.


1, here first introduce the program counter

Program Counter Register is a piece of memory with a small memory space, its role can be seen as

words executed by the frontline The line number indicator of the section code, in the concept model of the virtual machine, the bytecode interpreter works by changing this

the value of the counter to select The next byte-code instruction to execute, branching, looping, jumping, exception handling, thread recovery, and other basic functions

Need to rely on this counter to complete.

Because the multithreading of a Java Virtual machine is implemented in a way that threads take turns switching and allocating processor execution time, at any one definite moment,

A processor only executes instructions in one thread, so in order to switch back to the correct execution position, each thread needs a separate program counter,

The counters between the threads do not affect each other and are stored separately, and we call this memory storage area "thread-private memory".

Java Virtual Machine stack

The Java Virtual machine (Java Stacks) is the same as the program counter and is thread-private, with its life cycle and thread,

The virtual machine stack describes the memory model that is executed by the Java method, where each method is executed to create a stack frame to store the local variable table,

operand stack, dynamic link, method export and other information. Each method is called until the completion of the process, corresponding to a stack frame in the virtual machine from the

Stack to the process of the stack.

The local variable table holds eight basic data types (Int,double,float,byte,char,short,long,boolean), as well as object references

(reference type, which is not equivalent to the object itself, depending on the virtual machine implementation, it may be a reference pointer to the start address of the object,

It may also point to a handle representing the object or other location associated with the object) and the ReturnAddress type (the address that points to a bytecode directive).

3. Local Method Stack

The local methods Stack (Native method Stacks) is very similar to the virtual machine stack, but the difference is that the virtual machine performs the

Java method Service, and the local method stack is the native method service for virtual machines, which is used in the virtual machine specification for methods in the local method stack

Language, usage, and data structures are not mandatory, so a specific virtual machine is free to implement it.

4. Java Heap

The Java heap (Java heap) is the largest piece of memory managed by a Java virtual machine, and the Java heap is a chunk that is shared by all threads

Storage area, created at virtual machine startup, the only purpose of this memory area is to hold object instances where almost all object instances are allocated memory.

This is described in the Java Virtual Machine specification: All object instances and arrays are allocated on the heap, but with the development and escape of the JIT compiler

Analysis technology matures, stack allocation, scalar replacement optimization technology will lead to some subtle changes occur, all the objects are allocated to the heap also gradually

Become less absolute.

The Java heap is the main area of garbage collector management, so it is often referred to as a GC heap, and if you are recovering from memory,

The collector is a generational collection algorithm, so the Java heap can also be subdivided into: the new generation and the old age. However, regardless of the partitioning, it is irrelevant to the contents of the storage,

Regardless of the region, the object instance is stored, and the purpose of further partitioning is to better reclaim memory, or to allocate memory more quickly.

5. Method area

The method area, like the Java heap, is an area of memory shared by each thread that stores the class information that has been loaded by the virtual machine,

Data such as constants, static variables, and code after a timely compiler, although the Java Virtual Machine specification describes the method area as a logical part of the heap,

But it has an alias called Non-heap (Not a heap), and it may be distinguished from the Java heap.

6. Running a constant-rate pool

The runtime Constant pool is part of the method area, in addition to the class file version, field, method,

interface and other descriptive information, there is also a constant pool of information (Constant Pool), which holds the various literal and symbolic references generated during the compilation period.

Another important feature of running a constant pool with respect to the class file constants pool is its dynamic nature, and the Java language does not require constants to necessarily only

Can be generated at compile time, that is, the content of the constant pool is not pre-placed into the class file to enter the method area to run the frequent pool, during the operation can also

The new constants can be placed in the pool.

Java Memory storage area and memory overflow exception first, here, the next section writes about the exception caused by memory overflow.

Java Memory storage area and memory overflow exception (i)

Related Article

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.