Java memory area and memory overflow exception
Partition Memory:
The Java Virtual machine divides memory into 5 parts when executing a java program. Thread-Private has a member counter, a virtual machine stack, a local method stack, a thread-shared method area, a heap.
The program counter stores the byte code line number, which does not specify any memory overflow exceptions. The virtual machine stack stores stack frames for the Java method to run. The local method stack is used to run the native method. The method area is used to store information, constants, static variables, and so on for the loaded class. Heap is used to store Java objects.
A run-time constant pool is part of the method area that stores the literal and symbolic references generated during the compilation period.
Direct memory is not part of the virtual machine data area, which can be allocated through the NIO class.
To create an object:
How do virtual machines create an object? Load the class first, then allocate memory for the object, depending on whether the heap memory is neatly followed by a pointer collision or a free list. You can use the Tlab method to avoid inter-thread conflicts that allocate memory. The memory is then assigned a value of 0. Then set the object header. Finally, the Init method is executed.
In hotpot virtual machines, object memory is divided into object headers, instance data, and alignment fills. The first part of the object header is "Mark Word" and the second part is the type pointer. Instance data is the value of each type of field. Aligns the padding with the placeholder effect.
To access an object:
There are two ways to access objects: Handle mode and direct pointer mode. The hotpot virtual machine uses a direct pointer method.
Exception Name enumeration:
OutOfMemoryError Stackoverflowerror
Book summary-in-depth understanding of Java virtual machines