Java Virtual runtime data area
All threads share the interface: Method area, heap;
Thread-Isolated data area: virtual machine stack (VM stack), local method stack (Native stack), program counter (Counter Register)
1. Program counter
The only area that does not specify any oom situation
The line number indicator of the bytecode executed by the current thread.
-The bytecode interpreter works by changing the value of this counter to select the next command to execute (basic functions such as Branch/loop/Jump/exception handling/thread recovery) need to rely on this counter to complete
-When multi-threading, in order to recover the correct execution location after the thread switch, each thread needs a separate program counter, the counters between the threads do not affect each other
-When the thread is executing a Java method, the counter records the virtual machine bytecode instruction address that is being executed
-The native method is being performed: The Counter value is empty (undefined)
2. Java Virtual machine stack
Thread-private, with the same life cycle as the thread.
The virtual machine stack describes the memory model that the Java method executes.
- Each method creates a stack frame (the address of the heap) that is used to store local variable tables/operand stacks/dynamic connections/method exits, etc.
-The process of ==> a stack frame to the stack in the virtual machine stack by each method from the call until the completion of the execution process
Abnormal:
-The stack depth of a thread request is greater than the allowed depth of the virtual machine: Stackoverflowerror exception
-Unable to request enough memory when the virtual machine stack dynamically expands: OutOfMemory
Memory area most closely related to object memory allocation: heap memory and Stack memory
-The stack here refers to the local variable/virtual machine stack table part of the virtual machine stack
-Local variable table storage:
-8 basic data types in the compilation period
-Object reference (reference type)
-return address type (addresses that point to a bytecode Directive)
3. Local Method Stack
Virtual machine Stack executes Java methods (that is, bytecode) services for virtual machines and local method stacks are used by native method services for virtual machines
Exception: same virtual machine stack
4. Java Heap
All threads share a piece of memory area
created at the time of virtual machine startup for holding object instances.
According to the garbage collector's generational collection algorithm, the heap can also be divided into: The new generation, the old age ..., the purpose of partitioning in order to better reclaim memory/faster allocation of memory.
The Java heap can handle logically contiguous, physically discontinuous memory spaces
-The current mainstream virtual machines are implemented as extensible (through-XMX and-XMS control, parameter consistency is not extensible)
Abnormal:
-An Oom exception when there is no memory in the heap to complete the instance assignment and the heap can no longer be expanded
5. Method area
Each thread shares a memory region
Data for storing class information that has been loaded by the virtual machine/constant/static variable/instant compiler compiled code, etc.
The method area does not require contiguous memory, can choose a fixed size or is extensible, optionally does not implement garbage collection (but does not mean that the entry method area is permanent)
-Memory reclamation target for the method area: recycling for constant pools and unloading of heap types
Abnormal:
-Oom exception when the method area does not meet the memory allocation requirements
6. Run a constant-rate pool
Running a constant pool is part of the method area.
In addition to descriptive information such as the Version/Field/method/interface of the class, there is also a Chang (Constant pool Table), which holds the various literal and symbolic references generated during the compilation period, which is stored in the run-time pool of the class load backward into the method area.
7. Direct Memory
is not part of the data area when the virtual machine is running, and is not related to the memory area defined in the Java VM specification
Channel-and buffer-based I/O mode
It can use the native library to directly allocate out-of-heap memory and then manipulate it through a Directbytebuffer object stored in the Java heap as a reference to that memory. This can significantly improve performance in some scenarios because it avoids copying data back and forth in the Java heap and the native heap
Java Virtual Runtime data area