当前位置:网站首页>04 program counter (PC register)
04 program counter (PC register)
2022-06-25 18:22:00 【Name is too tangled】
1. PC Register Introduce

https://docs.oracle.com/javase/specs/jvms/se8/html/index.html
1.1 PC Register Introduce

- JVM Program count register in (Program Counter
Register),Register The name of comes from CPU The register of , Registers store field information about instructions .CPU Only loading data into registers can run . - here , It's not a physical register in a broad sense , Maybe translate it into PC Counter ( Or instruction counter ) It will be more appropriate ( Also known as program hook ), And it's not easy to cause some unnecessary misunderstandings .
JVM Medium PC Registers are for physics PC An abstract simulation of registers . - It's a small piece of memory , I can almost ignore it . It's also the fastest running storage area .
stay JVM Specification , Each thread has its own program counter , Threads are private , The life cycle is consistent with the life cycle of the thread .- There is only one method in a thread at any time , It's called
The current method. The program counter stores what the current thread is executing Java Methodical JVM Instruction address ; perhaps ,If it's execution native Method , The value is not specified (undefined). - It is an indicator of the flow of program control , Branch 、 loop 、 Jump 、 exception handling 、 Basic functions such as thread recovery rely on this counter
- The bytecode interpreter works by changing the value of this counter to select the next bytecode instruction to execute
It is the only one in Java Nothing is specified in the virtual machine specification OutofMemoryError Area of situation- Virtual machine stack 、 Local method area 、PC Register not GC; But the virtual machine stack and local method area may appear OOM
- The heap and method areas already exist GC There will be OOM
1.2 effect
PC Registers are used to store the address to the next instruction , That is, the instruction code to be executed . The execution engine reads the next instruction .

2. Illustrate with examples
public class PCRegisterTest {
public static void main(String[] args) {
int i = 10;
int j = 20;
int k = i+j;
String s = "abc";
System.out.println(i);
System.out.println(k);
}
}
Decompile instructions :javap -v PCRegisterTest.class
PC Registers store instruction addresses , The execution engine is based on PC The address in the register finds the operation instruction , And execute the instruction


3. Two common questions
Use PC register What's the use of storing bytecode instruction addresses ?
or
Why use PC register To record the execution address of the current thread ?
- because CPU You need to switch threads all the time , Now, after switching back , You need to know where to start after switching back
- JVM The bytecode interpreter needs to be changed PC Register to determine what kind of bytecode instruction should be executed next

PC Why is the register set to x Thread private ?
- We all know that the so-called multithreading will only execute one of the methods in a specific period of time ,CPU I'll keep switching tasks , This inevitably leads to frequent interruptions or recoveries , How to make sure there is no difference ?
In order to accurately record the current bytecode instruction address that each thread is executing , The best way, of course, is to assign one to each thread PC register , thus , Independent calculations can be performed between threads , So that there will be no mutual interference- because CPU Time slice wheel limit , Many threads are executing concurrently , Any definite moment , A core in a processor or multi-core processor , Only one instruction in a thread will be executed
- This inevitably leads to frequent interruptions or recoveries , How to make sure there is no difference ? After each thread is created , Will produce their own program counter and stack frame , Program counters do not affect each other among threads
4. Time slice
- CPU Time slice is CPU Time allocated to each program , Each thread is assigned a time period , It's called a time slice
- On the macro : We can open multiple applications at once , Each program runs parallel , Running at the same time
- But at the micro level : Since there is only one CPU, Only part of the program's requirements can be processed at a time , How to deal with fairness , One way is to introduce time slices , Each program is executed in turn

边栏推荐
- IVX sailing
- Network security algorithm
- 踩坑记录---线程池拒绝策略引起的一系列巧合
- Qi v1.2.4协议 之 定频调压方案
- Slam visuel Leçon 14 leçon 9 filtre Kalman
- 实际开户复杂吗?在线开户安全么?
- 存在重复元素III[利用排序后的有序性进行剪枝]
- Use pagoda to set up mqtt server
- [in depth understanding of tcapulusdb technology] tcapulusdb construction data
- RMAN backup database_ Skip offline, read-only, and inaccessible files
猜你喜欢

Kwai 616 war report was launched, and the essence was thrown away for the second time to lead the new wave. Fast brand jumped to the top 3 of the hot list

【深入理解TcaplusDB技术】Tmonitor后台一键安装

What is an operator?

Good news | Haitai Fangyuan has passed the cmmi-3 qualification certification, and its R & D capability has been internationally recognized

158_模型_Power BI 使用 DAX + SVG 打通制作商业图表几乎所有可能

One article solves all search backtracking problems of Jianzhi offer

What is an operator?

IVX sailing

CentOS7 安装 Redis 7.0.2

【深入理解TcaplusDB技术】TcaplusDB新增机型
随机推荐
微服务介绍
What is an operator?
篇7:CLion中没有代码提示,,,
RMAN backup database_ Use RMAN for split mirror backup
There is a repeating element iii[pruning with ordered ordering]
RMAN备份数据库_目录
[deeply understand tcapulusdb technology] tcapulusdb import data
股票开户怎么办理?证券开户哪家好 办理开户安全吗
RMAN备份数据库_双重备份备份集(Duplexing Backup Sets)
Matlab中图形对象属性gca使用
GNU nano
【深入理解TcaplusDB技术】TcaplusDB构造数据
快手616战报首发,次抛精华引新浪潮,快品牌跃入热榜top3
New typereference usage fastjson[easy to understand]
Which is better and safer, GF easy gold rush or compass
Leetcode force buckle (Sword finger offer 26-30) 26 Substructure of tree 27 Image of binary tree 28 Symmetric binary tree 29 Print matrix 30 clockwise Stack containing min function
El table highly adaptive
什么是泛型以及在集合中泛型的使用[通俗易懂]
QT中QString包含“\u0000“的处理方式
The stacks 2022:32 marketing technology stacks selected