About viewing information
- JVM Aspect Reference
- Java Language Reference
Select the required documents based on the JDK version
Runtime Data Area
- PC Program Counter (Thread private)
Instruction location
The virtual machine runs in a loop similar to this:
while( not end ) {
Take the position of the PC, find the corresponding position of the instruction;
Execute the instruction;
PC ++;
}
- Method Area (logical concept, Perm Space and Meta Space are concrete implementations)
A. Perm Space (<1.8) permanent generation
The string constant is specified when PermSpace FGC does not clean up the size and cannot be changedCopy the code
B. Meta Space (>=1.8
String constants are in the heap
FGC cleanup is triggered
If not set, the maximum is physical memory
Think about:
How do I prove that 1.7 string constants are in Perm and 1.8 is in Heap?
Tip: With GC, always create string constants, watch the heap, and Metaspace
- Runtime Constant Pool
In the runtime data section
- Native Method Stack (thread private)
Stores JNI information
- Direct Memory
The memory of the kernel space that the JVM can directly access (os-managed memory). The old IO needs to store data transferred over the network into the kernel and then copy it from the kernel to the JVM
With NIO, data transferred from the network is stored in direct memory and can be accessed directly by the JVM
NIO, improve efficiency, zero copy
- JVM Stack (thread private)
Frame – Each method corresponds to a stack Frame
- Local Variable Table
- Operand Stack (Operand Stack)
For long processing (store and load), most virtual machine implementations are atomic
JLS 17.7, volatile is not necessary
- Dynamic Linking
A symbolic reference to a constant pool
Blog.csdn.net/qq_41813060…
JVMS 2.6.3
- Return address (return address)
A () -> b(), method A calls method b, where does the return value of method b go
example
public static void main(String[] args) {
int i = 8;
i = i++;
// i = ++i;
System.out.println(i);
}
Copy the code
Translated into assembly instructions:
0 bipush 8 push 2 istore_1 Store data on the stack to the local variable table 3 iload_1 push data on the local variable table 4 iinc 1 by 1 Store data on the local variable table +1 7 istore_1 store data on the stack to the local variable tableCopy the code
- Heap
Thread shared area
Instruction set classification
- A register-based instruction set
- A stack-based instruction set
Local Variable tables in Hotspot are similar to registers in the JVM
Simulate the stack execution flow
Return value or not
When m1() has a return value, the return value is placed at the top of the operand stack in the main() stack frame after calling the method
Recursive calls
Commonly used instructions
store
load
pop
mul
sub
invoke
Invoke instruction
- InvokeStatic
See [T01_InvokeStatic]
- InvokeVirtual
A polymorphic approach is required
- InvokeInterface
【T04_InvokeInterface】
- InovkeSpecial
Can be located directly, do not need polymorphic methods
Private method, constructor
- InvokeDynamic
See [T05_InvokeDynamic]
The JVM’s most difficult instruction lambda expressions or reflection or other dynamic languages scala, Kotlin, or CGLib ASM, dynamically generated classes, will be used