Java run-time data region

Source: Internet
Author: User

The Java Virtual machine performs a Java program by dividing the memory that he manages into several different data regions for their purposes, creation, and destruction times. Some exist with the start of a virtual machine, and some areas depend on the start and end of the thread to build and destroy.

1. Program counter

The JVM considers this count as the line number indicator of the current thread executing a byte code, and selects the next bytecode directive to be executed based on the value of the counter. This is a thread-private, non-shareable , and cannot be accurately executed by the current thread if the share causes the count to be confusing.

If a thread is executing a Java method, this counter records the address of the virtual machine bytecode instruction being executed, and if the native method is executed, the value of this counter is null (Undefined).

This zone is the only case where no outofmemoryerror is specified in the Java Virtual Machine specification.

Note: A native method is a Java interface that calls non-Java code. A native method is a Java approach: the implementation of this method is implemented by non-Java languages, such as C or C + +.

2.Java Virtual Machine Stack

Stack memory refers to the virtual machine stack. Every method in Java, from the call until the completion of the process, corresponds to a stack frame in the virtual machine stack into the stack to the process.

The virtual machine stack describes the memory model that is executed by the Java method: Each method executes at the same time, creates a stack frame, which holds the local variable table, the operand stack, the dynamic link, the method exit, and so on. The words "stack memory" is the local variable table part of the virtual machine stack, and the local variable table holds the various basic data types known by the compiler (Boolean, Byte, char, short, int, float, long, double), object reference ( The reference type, unlike the object itself, may point to a reference pointer to the starting address of an object, or to a handle representing an object or other location associated with the object, and the ReturnAddress type (the address of a bytecode directive).

One of the 64-bit long and double data types takes up two local variable space and only one of the remaining data types. The memory space required for the local variable table is allocated during compilation.

If the thread requests a stack depth greater than the virtual machine allows, the stackoverflowerror exception is thrown, and if the virtual machine stack can be dynamically extended (most of the current Java virtual machines can be dynamically extended, However, the Java Virtual Machine specification also allows a fixed-length virtual machine stack, which throws a OutOfMemoryError exception if the extension cannot request enough memory.

3. Local Method Stack

The virtual machine stack is used to execute the Java method, and the local method stack is used to execute the local method.

Throwing exceptions is like a virtual machine stack that throws Stackoverflowerror and outofmemoryerror exceptions .

4.Java Heap

is the largest memory, thread-sharing area in the JVM. A chunk of memory that is shared by all threads, created when the virtual machine is started. The only purpose is to store object instances. This is also the area that the garbage collector collects primarily (GC heap: garbagecollected heap). Because modern garbage collectors are using generational collection algorithms, the Java heap is also divided into the new generation and the old age.

The thread-shared Java heap may divide multiple thread-private allocation buffers (thread Local Allocation Buffer,tlab), regardless of the contents of the store, and the object instances are stored.

The Java heap can be in a physically discontinuous memory space as long as it is logically contiguous. Heap memory can be adjusted by parameter-xmx (JVM's maximum available memory) and-XMS (JVM initial memory), and outofmemoryerror errors occur if there are no memory completion instance allocations in the heap, and the heap expands to no longer extend.

5. Method Area ("Permanent generation")

  A region of memory-sharing in the JVM used to store class information, constants, static variables,class files. The garbage collector also recycles this part of the area, such as the cleanup of constant pools and the unloading of types, but the results are unsatisfactory. its implementation is like a heap of-xx:maxpermsize settings to manage this part of memory without having to write code specifically for the area for memory management. But it is easy to cause memory overflow, there is a gradual change to the native memory to achieve the planning of the method area,JDK1.7 has been placed in the permanent generation of the string constant pool out.
The OutOfMemoryError error will also be thrown when the method area memory is not sufficient.


6. Run a constant-rate pool

The run-time-constant pool is part of the method area (runtime Constant pool). class files In addition to the class version, fields, methods, interfaces, and other information, there is a constant pool (Constant pool Table), for the compilation period generated by a variety of literal and symbolic references, which are loaded in the class load into the method area of the run constant pool storage.

The Java Virtual machine heap class file has strict rules, but not for running a constant pool, in general, in addition to saving the symbolic references described in the class file, the translated direct references are also stored in the run-time-constant pool. new constants can also be placed in the pool during run time, such as the Inter () method of the String class.

belongs to the method area and is naturally restricted by the method area, which throws a outofmemoryerror error when the constant pool is no longer able to apply to memory.

7. Direct Memory

Direct memory is not part of the data area when the virtual machine is running, nor is it a data region defined in the VM specification.

The NIO (New Input/output) class is added to the JDK1.4, which introduces a channel-based I/O method that can be used to directly allocate out-of-heap memory using the native library. Operates as a reference to this memory through a Directbytebuffer object stored in the Java heap. In some scenarios, avoid copying data back and forth in the Java heap and the native heap.

This level of direct memory is not limited by the Java heap size and is limited by the total memory size of the machine and the processor addressing space, and outofmemoryerror Exceptions occur when the physical memory limit is exceeded dynamically

  

General overview

Java run-time data region

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.