当前位置:网站首页>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

边栏推荐
- JSP页面运行却显示源码
- 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
- Pycharm 使用过程中碰到问题
- Qi v1.2.4协议 之 定频调压方案
- RMAN备份数据库_管理备份窗口(Backup Window)
- 什么是泛型以及在集合中泛型的使用[通俗易懂]
- Batch uploading of local jar packages to nexus private server
- 【路径规划】如何给路径增加运动对象
- RMAN backup database_ Skip offline, read-only, and inaccessible files
- 【深入理解TcaplusDB技術】TcaplusDB業務數據備份
猜你喜欢

Chapter 4:win10 installing mingw64

Pycharm 使用过程中碰到问题

Deep understanding of ELF files

IVX sailing

【深入理解TcaplusDB技术】TcaplusDB机型

.NET Worker Service 添加 Serilog 日志记录
![[path planning] how to add moving objects to a path](/img/ff/2a6cc811078fa9b0f7a223f90fceac.jpg)
[path planning] how to add moving objects to a path

篇6:CLion:Toolchains are not configured Configure Disable profile

SDN system method | 9 Access network
![[daily record] - bug encountered during BigDecimal Division](/img/76/efb117986ac319987d4453bf00bec9.png)
[daily record] - bug encountered during BigDecimal Division
随机推荐
.NET Worker Service 如何优雅退出
【深入理解TcaplusDB技术】TcaplusDB机型
深度学习网路模型
connect to address IP: No route to host
Hash of redis command
How to delay the delay function
Optimization of lazyagg query rewriting in parsing data warehouse
视觉SLAM十四讲 第9讲 卡尔曼滤波
Matlab中图形对象属性gca使用
Using QT to make a beautiful login interface box
Problems encountered during the use of pychar
【深入理解TcaplusDB技术】TcaplusDB运维
Interrupt operation: abortcontroller learning notes
Uncover ges super large scale graph computing engine hyg: Graph Segmentation
广发易淘金和指南针哪个更好,更安全一些
SQL Server实时备份库要求
微服务介绍
Deep learning network model
Redis趋势—NVM内存
Introduction to microservices