Java memory area and memory overflow exception

Source: Internet
Author: User

Run-time data region

program Counter Register ): Can be thought of as the line number indicator of the byte code executed by the current program. In the virtual machine conceptual model (different virtual machines may have different implementations), the bytecode interpreter is to remove a bytecode instruction by changing the value of the program counter, and the basic functions such as branching, looping, jumping, exception handling, thread recovery, and so on, depend on this counter.

Java Virtual Machine Stack (Java Stacks): Like the program counter, the Java Virtual machine stack is also thread-private, and his life cycle is the same as the thread, 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 from the stack to the process of the stack.

Some people divide Java memory into heap memory and stack memory, and "stack" is the virtual machine stack that is now being talked about. The local variable table holds the relevant local variables, including basic data types, object references, return addresses, and so on.

The virtual machine stack consists of two exceptions, Stackoverflowerror: The requested stack depth is greater than the maximum allowable depth of the virtual machine stack. OutOfMemoryError: Unable to request enough memory when the virtual machine stack is extended.

Local methods Stack (Native method Stacks ): The local method stack is very similar to the virtual machine stack, except that the virtual machine performs Java method services for the virtual machine, and the local method stack executes the native method service for the virtual machine, in which the local method stack and the virtual machine stack are directly merged into the virtual machine.

Java Heap (Heap ): The virtual machine manages the largest chunk of memory, often referred to as a GC heap, and the Java heap is shared by all threads, which are created at the time of virtual machine startup to hold object instances. From a memory recovery perspective, the area can be subdivided into Eden space, from Survivor space, and to survivor space, which, from a memory allocation perspective, may divide multiple thread-private allocation buffers (thread Local Allocation buffer, Tlab). Java heap can be in a physically discontinuous memory space (logically continuous), the current mainstream virtual machine heap is extensible (-XMS,-XMX), if the heap memory is not enough to complete the instance allocation, can not be extended, will throw OutOfMemoryError exception.

Method Area ): The method area is also an area of memory shared by each thread that stores data such as class information, constants, static variables, compiler-compiled code, and so on, that have been loaded by the virtual machine. The memory reclamation target of the method area is primarily for the collection of constant pools and unloading of types, and throws a OutOfMemoryError exception when the method area does not meet the memory allocation requirements.

run a constant-rate pool (runtime Constant ): The run-time constant pool is part of the method area, and Chang (Constant pool Table) is used to hold the various literal and symbolic references generated during the compilation period, which are stored in the run constant pool of the class load backward into the method area.

Direct Memory ): Direct memory is not an area of memory defined by the Java Virtual Machine, the new Input/output class is added to JDK1.4, and a channel-to-buffer Io method is introduced, which can be used to directly allocate out-of-heap memory using the native library. This memory is then referenced by the Directbybuffer object stored in the Java heap, which is not limited by the Java heap size and is limited only by the native total memory and processor addressing space

Reference: "In-depth understanding of Java Virtual Machine JVM advanced features and best practices"

Java memory area and memory overflow exception

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.