1. Run-time data area
1.1. Program counter
Thread-Private, byte-code line number indicator executed by the current thread,
The multithreading of a Java Virtual machine is assigned by threads that switch processor execution time in turn
1.2. Java Virtual machine stack
Thread-Private, virtual machine local variable table each method will create a stack frame for storing local variables, operand stacks, dynamic link method exits, and so on, each method from start to finish.
Corresponds to the process of a stack frame from the stack to the stack,
1.3. Local Method stack
Thread-Private, the local method stack is the native method service for virtual machines, and some virtual machine award-local method Stacks are merged with the virtual machine stack.
1.4. Java Heap
GC Heap, the main area of garbage collector management, for storing object instances, where almost all instances of Java objects allocate space,
1.5. Method Area
The class information, constants, static variables that are used to load the virtual machine, and the method area contains elements that are always unique throughout the program, such as the class,static variable
1.6. Running a constant-rate pool
When the JVM executes a class, it must be loaded, connected, initialized, and the connection includes validation, preparation, and parsing of three phases.
When the class is loaded into memory, the JVM stores the contents of the class constant pool in the run-time pool, so that the run-time pool is one of each class.
In the parsing phase, the symbolic reference is replaced with a direct reference, and the parsing process will query the string constant pool, which is what we said above, Stringtable,
To ensure that the string referenced by the run constant pool is consistent with the string constant pool.
1.7. Direct Memory
Java uses the naive library to directly allocate out-of-heap memory to avoid copying data back and forth in the Java heap and the native heap
2. Hotspot Virtual Machine
2.1. Creation of objects
If the idle memory of the Java Virtual machine is contiguous, move directly backwards to a distance equal to the object's size, called a pointer collision
If it is not contiguous, it looks for a sufficient amount of memory from the remaining memory, called the Idle list mode
How to avoid thread safety
Allocate space for each thread
CAs with failed retry
2.2 Memory layout of objects
Object header: The runtime's own data (hash code, GC generational age, lock state), type pointer
Instance data: The data that the object actually stores
Align padding: the starting address of each object must be an integer multiple of 8 bytes
2.3 Object access and positioning
Handle Access: Reference points to the handle pool then points to the specific object, avoids the modification of the object and needs to modify the reference modification, and adds a single addressing
Direct pointer positioning: direct pointing to specific objects,
Java Virtual Machine chapter II Java memory area and memory overflow exception