One, run-time data area
1. Counter
The line number indicator of the byte code executed by the current thread
2. Virtual Machine stack
Thread private Each method creates a stack frame at execution time,
3. Local Method Stack
4.java Heap
All threads share a piece of memory area, and all object instances and arrays allocate memory on the heap.
-xmx-xms
5. Method area
Thread sharing, storing class information loaded by the virtual machine, constants, static variables, immediate compiler-compiled code
The method area does not meet memory allocation requirements, memory leaks outofmemoryerror
5.1 Running a constant-rate pool
The running constant pool is dynamic, and new constants can be put into the pool during operation
Hotspot Virtual Machine
Permanent Generation-xx:maxpermsize
Second, hotspot virtual machine The whole process of object assignment, layout and access in Java heap
Local thread allocation buffer (thread local Allocation buffer)
Whether the virtual machine uses Tlab-xx:+/-usetlab
2.1 Object creation
The new instruction, class load, allocates memory for the new object, and the object needs to be determined after the class is loaded. The allocated memory space is initialized to 0 values--the necessary settings for the object (metadata information for the class, the hash code of the object, the age of the GC generational of the object, which is stored in the object header object headers)-->init method
After the memory allocation is complete, the virtual machine needs to initialize the allocated memory space to a value of 0. This step ensures that the object's instance object is always not assigned to the Java code.
Directly, the program can access the 0 values corresponding to the data types of these fields.
2.2 Memory layout of objects
Objects in-memory storage layouts are divided into: object header, instance data, align padding
Object header: The first part: Store the object's own run-time data, such as hash code, GC generational age, lock status flag, thread-held lock, biased thread ID, bias timestamp.
The other part is the type pointer, which is a pointer to the class metadata of the object.
Instance data: The object really stores valid information about the various types of field content defined in the program code. The order of storage is affected by the virtual machine allocation policy parameters and the order in which the fields are defined in the Java source code. The default allocation policy for hotspot virtual machines is long/doubles, INTs, Shorts/chars, Bytes/booleans, oops (ordinary object Points) ordinary object pointers.
Align padding: acts as a placeholder. The HotSpot VM automatic memory management system requires that the object start address is an integer multiple of 8 bytes, i.e. the size of the object must be an integer multiple of 8 bytes. The object header size is a multiple of 8 bytes. When the object instance data part is not aligned, you need to align the fill to complement it.
2.3 Access Targeting
The reference type in the Java Virtual machine stack holds references to objects. There are currently 2 ways to access specific objects. Handles and direct pointers.
With handle access, the address of the handle pool is stored in reference, and the handle contains the specific address information of the object instance data and the type data.
With direct pointer access, the address of the object is stored in the reference. (Is the object type data or object instance data?) )
"Java Virtual machine" Essays in the journal