Java Memory area management and memory overflow

Source: Internet
Author: User

First, overview:

    A Java Virtual machine executes a Java program by dividing the memory it manages into several different data regions that have their own purpose and creation and destruction times, some of which follow the startup of the virtual machine process, and some that depend on the start and end of the user thread to build and destroy.

Second, the program counter:

A program counter is a small amount of memory space that can be viewed as the line number display of the bytecode executed by the current thread. In the conceptual model, the work of the bytecode interpreter is to select the next byte-code instruction that needs to be executed by correcting the value of this counter, and the basic functions such as branching, looping, jumping, exception handling, and thread recovery need to rely on this counter to complete.

At any given moment, a processor executes only the instructions in one thread. Therefore, in order for the thread to switch back to the correct execution location, each thread needs to have a separate program counter, the counters between the threads do not affect each other, isolated storage.

If the thread is executing a Java method, this counter records the address of the executing virtual machine bytecode instruction, which is empty if the native method is being executed.

The program counter is the only area in the Java Virtual Machine specification that does not stipulate any outofmemoryerror conditions.

Third, Java Virtual machine stack

The virtual machine stack is instead thread-private. The virtual machine stack describes the memory model that the Java method executes: Each method creates a stack frame to store information such as local variable tables , operand stacks, dynamic links, method exits, and so on. Each method from the call to the completion of the process, corresponding to a stack frame in the virtual machine stack into the stack of the process.

Local variables hold various basic data types (Boolean, Byte, char, short, int, float, long, double), object references, ReturnAddress types (addresses that point to a bytecode directive) that are known at compile time

Exception Condition: 1, if the thread request the stack depth is greater than the virtual machine allowed depth, then throw Stackoverflowerror exception 2, if the virtual machine stack can be dynamically extended, if the extension cannot request enough memory, will throw OutOfMemoryError exception

Iv. Local Method Stack

Unlike the virtual machine stack, the local method stack serves the native method service.

Throws Stackoverflowerror exceptions and OutOfMemoryError exceptions.

V. Java heap

The area of memory shared by the thread.

Throws a OutOfMemoryError exception.

Vi. Method Areas

A thread-shared area of memory that stores data such as class information, constants, static variables, and code compiled by the immediate compiler that have been loaded by the virtual machine stack.

Throws a OutOfMemoryError exception.

Java Memory area management and memory overflow

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.