JVM学习02:运行时数据区域-程序计数器

原创
2017/07/24 08:57
阅读数 78

这里写图片描述
  由于JAVA的多线程是通过线程轮流切换分配处理时间的方式实现,为了保证能够恢复到线程的正确位置,每个线程再启动的时候都会创建一块较小的内存区域,这块区域是线程隔离的,生命周期同线程绑定,线程结束,则释放该内存区域,可以看作是当前线程所执行的字节码的行号子令器。
  字节码子令器的工作模式是通过改变这个计数器的值来选取下一条需要执行的字节码指令,分支、循环、跳转、异常处理、线程恢复等基础功能都需要依赖这个计数器来完成。
  计数器的大小是一个字长,因此既可以持有一个本地指针,又可以持有一个returnAddress。计数器中记录的内容根据方法类型就行划分,如果当前方法是java方法,这个计数器记录的是正在执行的虚拟机字节码指令的地址(可以是一个本地指针,也可以是在方法字节码中相对于该方法起始指令的偏移量);如果方法是Native方法,这个计数器记录的内容则为Undefined。

引用:Each thread of a running program has its own pc register, 
or program counter, which is created when the thread is started. 
The pc register is one word in size, 
so it can hold both a native pointer and a returnValue. 
As a thread executes a Java method, 
the pc register contains the address of the current instruction being executed by the thread. 
An "address" can be a native pointer or an offset from the beginning of a method's bytecodes. 
If a thread is executing a native method, the value of the pc register is undefined.

  此内存区域是唯一一个在Java虚拟机规范中没有规定任何OutOfMemoryError情况的区域

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部