1. jvm memory model:
Memory model:
program counter
heap
the stack
native method stack
method area
2. The java code is compiled into a class file, loaded into the jvm by the class loader, and then compiled into machine code by the interpreter and JIT in real time, and the machine code is then executed by the CPU
3. Program counter:
It is a small memory space. It can be regarded as the line number indicator of the bytecode executed by the current thread . In the conceptual model of the Java virtual machine , the bytecode interpreter works by changing the value of this counter. To select the next bytecode instruction to be executed, it is an indicator of program control flow. Basic functions such as branches, loops, jumps, exception handling thread recovery all rely on this counter to complete
In plain English: It stores the execution address area of the next jvm instruction, and the interpreter relies on it to move down.
4. Program counter features:
1) Thread private
2) In the memory model, the only area where memory overflow does not occur
4.1 Thread private: The server cpu is a time slice mechanism, each thread runs within a fixed time slice, and pauses when it reaches the point. After pausing at this time, the program counter stores the position where the current method is running. Each thread has an independent program counter, which does not affect each other and is stored independently. So it is called thread private.
4.2 Memory overflow will not occur.