JVM_05 runtime data area 2-heap_2

1. Graphical object allocation process

Insert picture description here
Special case

Insert picture description here

public class HeapInstanceTest {
    byte[] buffer = new byte[new Random().nextInt(1024 * 200)];

    public static void main(String[] args) {
        ArrayList<HeapInstanceTest> list = new ArrayList<HeapInstanceTest>();
        while (true) {
            list.add(new HeapInstanceTest());
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

Insert picture description here

2.Minor GC、Major GC、Full GC

  • Partial collection: Garbage collection is not a complete collection of the entire Java heap. Which is divided into:

    • Young generation collection (Minor GC/Young GC): only the new generation of garbage collection

    • Old age collection (Major GC/Old GC): just garbage collection in the old age

    • Mixed collection (Mixed GC): Collect garbage collection of the entire young generation and part of the old generation

  • Whole heap collection (Full GC): Collect the garbage collection of the entire java heap and method area

Insert picture description here

Full GC is to be avoided as much as possible during development or tuning, so the pause time will be shorter

Insert picture description here

3. TLAB (thread private cache area)

Insert picture description here
Why is there TLAB (Thread Local Allocation Buffer)

  • The heap area is a thread shared area, any thread can access the shared data in the heap area
  • Since the creation of object instances is very frequent in the JVM, it is unsafe to divide the memory space from the heap area in a concurrent environment.
  • In order to avoid multiple threads operating the same address, it is necessary to use mechanisms such as locking, which in turn affects the allocation speed

Guess you like

Origin blog.csdn.net/qq_43141726/article/details/114804254