Deep understanding of JVM structure and jvm
JVM structure ---- 1. JVM Structure
2. JVM runtime data Zone
1) Program Counter (Program Counter Register)
The program counter is used to store the JVM commands that each thread will execute next. If this method is native, the program counter does not store any information.
2) JVM Stack)
The JVM stack is private to the thread. a jvm stack is created for each thread at the same time, variables stored in the JVM Stack are local basic types in the current thread (eight basic types defined in java: boolean, char, byte, short, int, long, float, double) partial returned results and Stack Frame. Non-basic types of objects only store one address pointing to the Stack on the JVM Stack.
3) heap)
It is the region where JVM is used to store object instances and array values. It can be considered that the memory of all objects created through new in Java is allocated here, and the memory of objects in Heap needs to be recycled by GC.
(1) The heap is shared by all threads in the JVM. Therefore, the object memory allocation on the heap needs to be locked. This also causes the overhead of the new object to be relatively large.
(2) In order to improve the efficiency of Object Memory Allocation, Sun Hotspot JVM allocates an independent space for the created Thread TLAB (Thread Local Allocation Buffer ), the size is calculated by the JVM Based on the running situation. No lock is required when objects are allocated on the TLAB. Therefore, the JVM tries its best to allocate the memory to the objects in the thread on the TLAB, in this case, the performance of allocating Object Memory in JVM is basically the same as that of C, but if the object is too large, the heap space allocation is still used directly.
(3) TLAB only applies to the new generation of Eden Space. Therefore, when writing Java programs, it is generally more efficient to allocate multiple small objects than large objects.
4) Method Area)
(1) In Sun JDK, this region corresponds to PermanetGeneration, also known as permanent generation.
(2) The method area stores the information of the loaded class (name, modifier, etc) static variables in the class, constants defined as final type in the class, Field information in the class, and method information in the class, when developers obtain information through the getName, isInterface, and other methods in the Class object in the program, the data comes from the method region, and the method region is also shared globally, under certain conditions, it will also be GC. When the memory used in the method area exceeds the permitted size, an OutOfMemory error message will be thrown.
5) Native Method Stacks)
JVM uses the local method stack to support native METHOD execution. This region is used to store the status of each native method call.
6) Runtime Constant Pool)
It stores fixed constant information, method and Field reference information in the class, and its space is allocated from the method area. When the JVM loads a class, it allocates an independent constant pool for each class, but the String constant pool in the runtime constant pool is shared globally.