The Java virtual machine, in the course of executing a Java program, divides the memory it manages into a number of different regions.
Note: The memory managed by the Java Virtual machine will include the following runtime data regions
1. Program counter, bytecode interpreter, is to change the value of this counter to select the next need to execute the byte code instruction branch, loop, jump, exception handling, thread recovery needs to this counter to complete.
Note: Thread-private Memory: Each thread has a program counter that does not affect each other and is stored independently.
2.java Virtual Machine Stack:
(1). Stack frame: Used to store local variable tables, operand stacks, dynamic links, method exits and other information.
Note: Each method from the beginning of the call to the completion of the process, is corresponding to a stack frame in the virtual machine from the stack into the stack process.
(2). The stack, which is often said, is the virtual machine stack, or the local variable table part inside.
Note: The local variable table holds the basic data type (boolean.byte.int.float.char.short.long.double), the object reference type (which may be a pointer to the starting address of the object), and the ReturnAddress type
64-bit long and double types of data will account for two local space, and the remainder will account for two exceptions:
The first type: when the virtual machine stack dynamically expands, unable to request enough memory, will report Outofmerryerror exception
The second type: The thread request has a stack depth greater than the virtual machine allows, and the stackoverflowerror exception is reported
(3). Local method Stack (similar to virtual machine type)
Difference: The virtual machine stack executes Java method Services for the Java Virtual machine, and the local method stack serves the native method used by the virtual machine
Same point: All of the above two types of exceptions are thrown
Note: Some virtual machines combine the two, such as: Sunhotspot
(4). Java Heap
Java is created at the start of a virtual machine, shared by all threads, and can be in a physically discontinuous memory space, as long as it is logically contiguous
Function: First, the object instance is stored, almost all of the objects are allocated memory space on the heap, but with the technology of escape analysis and scalar substitution becoming more and more mature, there are now many implementations of the stack
The Outofmerryerror exception is thrown if the object is not finished allocating memory space for the objects and the heap cannot be expanded.
Second, GC heap, which is the main area of garbage collector management
(5) Method area:
shared by various threads, used to store data such as class information, constants, static variables, and instant compiler compiled code that were loaded by the virtual machine, and throws a Outofmerryerror exception when the method area does not meet the memory allocation requirements.
(6) Direct Memory:
It is not part of the data area when the VM is running, nor is it a memory area defined by the Java Virtual Machine specification, but this part of memory is also used frequently, and may also cause outofmerryerror 10% to appear
Note: Based on the I/O mode of the channel and buffer, it can allocate out-of-heap memory directly using the native library and then operate through a Dirctbytebuffer object stored in the Java heap as a reference to this memory. Because it avoids copying data back and forth in the Java heap and the native heap, the native direct memory size is not limited by the Java heap.
(7) Run a constant-rate pool:
Running a constant pool is part of the method area, in addition to descriptive information such as the version of the class, the fields, methods, interfaces, and so on, there is a const pool that holds the compiler-generated literal and symbolic references, which will be
The class loads the run-time constant pool of the incoming method area to store.
Java Virtual machine pair. The format of each part of the class file is strictly defined, and each byte used to store that data must conform to the requirements of the specification to be recognized, loaded and executed by the virtual machine, in general, in addition to saving. The symbolic references described in the class file also present the translated direct references in the run-time-constant pool. The outofmerryerror exception is also reported when memory can no longer be extended by the method area memory limit
The above is the author's reading notes summary, mainly introduces the runtime data area of several large modules, hoping to be useful to the reader.
Java learning JVM in-depth analysis (i)