当前位置:网站首页>JVM|运行时数据区;程序计数器(PC寄存器);
JVM|运行时数据区;程序计数器(PC寄存器);
2022-06-11 21:23:00 【z754916067】
运行时数据区
- 方法区:类加载好后放在方法区中
- 程序计数器
- 本地方法栈
- 堆
- 虚拟机栈
数据区与线程的关系
每个单独线程私有的:程序计数器,栈,本地栈
线程间共享:堆,堆外内存(方法区(永久代或元空间)代码缓存)
线程
线程是一个程序里的运行单元,JVM允许一个应用有多个线程并行的执行。
一旦本地线程初始化成功,它就会调用Java线程中的run()方法。
程序计数器(PC寄存器)
- 是一块很小的内存空间,也是运行速度最快的存储区域。
- 任何一个时间一个线程都只有一个方法在执行,也就是所谓的“当前方法”。
- 程序计数器会存储当前线程正在执行的Java方法的JVM指令地址。
作用
PC寄存器用来存储指向下一条指令的地址,也即将要执行的指令代码。由执行引擎读取下一条指令。
使用举例
程序计数器中会存储下一条指令的地址,执行引擎根据这个地址去找对应的语句,进行操作。
常见问题
1.使用PC寄存器存储字节码指令地址有什么用?
答:CPU需要不停切换各个线程,等到切换回来之后必须得知道接着从哪开始继续执行。
2.为什么使用PC寄存器记录当前线程的执行地址?
答:JVM的字节码解释器需要通过改变PC寄存器的值来明确下一条应该执行什么样的字节码指令。
线程私有的原因
所谓的多线程,在一个特定的时间段只会执行其中某一个线程的方法,CPU会不停地做任务切换,这样必然导致经常中断或恢复。
为了能够准确地记录各个线程正在执行的当前字节码指令地址,最好的办法是为每一个线程都分配一个PC寄存器。
这样一来各个线程之间就可以进行独立计算了。
边栏推荐
- go语言的goto语句
- Goland中在文件模板中为go文件添加个人声明
- CANN编码的一些报错汇编
- Common file functions
- Realize the same length of tablayout subscript and text, and change the selected font size
- Go语言函数
- Live broadcast with practice | 30 minutes to build WordPress website with Alibaba cloud container service and container network file system
- ORA-04098: trigger ‘xxx. xxx‘ is invalid and failed re-validation
- [thinking about life] words and sounds
- Object creation process of JVM
猜你喜欢

Iros 2021 | new idea of laser vision fusion? Lidar intensity diagram +vpr

数据库每日一题---第9天:销售员

Why should I use iwarp, roce V2, nvme of and other protocols for 100g network transmission

Codeforces Round #744 (Div. 3) 解题报告

ORA-04098: trigger ‘xxx.xxx‘ is invalid and failed re-validation

apache 本地多端口配置

Tensorflow 2. X Getting Started tutorial

Live broadcast with practice | 30 minutes to build WordPress website with Alibaba cloud container service and container network file system

第一部分 物理层
![BZOJ3189 : [Coci2011] Slika](/img/46/c3aa54b7b3e7dfba75a7413dfd5b68.png)
BZOJ3189 : [Coci2011] Slika
随机推荐
第二部分 数据链路层
Field queryIndexFieldnameService in xxxImpl required a single bean, but 19 were found:
Application analysis of Poe image acquisition card in machine vision industrial computer
Common file functions
apache 本地多端口配置
Object creation process of JVM
2021牛客多校5 Double Strings
A man always becomes a man and a man always arrives (progress, harvest, growth, self-confidence)
Test plans and test cases
Goto statement of go language
第一部分 物理层
Release of version 5.6 of rainbow, add multiple installation methods, and optimize the topology operation experience
Go language conditional statement
One article to show you how to understand the harmonyos application on the shelves
Goland中在文件模板中为go文件添加个人声明
使用 SAP UI5 CLI 命令行工具构建和运行 SAP UI5 应用
应用业务层修改
BZOJ3189 : [Coci2011] Slika
How to Load Data from CSV (Data Preparation Part)
二分图King