I. jvm Memory Structure
Program Counter Register, JVM Virtual Machine stack (JVM Stacks), Native Method Stacks, Heap, and Method Area)
(1) PCR
Follows the thread life cycle and records the number of. class bytecode lines currently executed for multi-thread operations.
(2) JVM Stacks
Stores data in method execution following the thread Lifecycle
(3) Native Method Stacks
Native method, such as hashCodes () in an object
(4) Heap
Stores all instance objects and array objects with built-in GC
(5) Method Area
Heap components, but does not force GC. The stored objects include the runtime constant pool, static variables, and class information loaded by JVM.
Ii. Garbage Collection
Garbage collection is required in the heap and method areas. The other three are created and destroyed along with the thread lifecycle.
Spam Determination Algorithm
(1) Reference calculator: Objects referenced in cycles cannot be recycled.
(2) root search: inefficient
Garbage removal Algorithm
(1) mark and clear Algorithms
Process: When the memory is insufficient, stop the program, traverse the GC Root, mark the reachable objects as surviving objects, and clear all unused objects.
Disadvantages: low efficiency; non-sequential idle memory
(2) replication algorithm
Process: the memory is divided into two parts: the active zone and the idle zone. The newly allocated active zone exists. When the memory is insufficient, GC is performed.
Surviving objects are placed in idle intervals in order.
Disadvantage: half of the memory is wasted; when the object survival rate is high, the replication operation is charged.
(3) tagging and sorting algorithms
Process: similar to (1) marking all surviving objects, re-moving objects in the memory order, and clearing the end memory
Disadvantage: Low Efficiency
(4) Generational search algorithms
Process: perform different collection algorithms for different objects.
Dead objects (local variables and temporary variables): replication algorithm (80% memory allocation objects + 10% active areas + 10% idle intervals)
Old and undead objects (Cache objects, database connection objects, and Singleton objects): tagging and sorting algorithms
Non-extinct object (String pool object, class information): Tag, Sorting Algorithm