"each JVM thread has its own program counter?" 是什么意思

What is meant by "each JVM thread has its own program counter?"

我正在尝试理解这句话的意思:

Each Java Virtual Machine thread has its own pc (program counter) register. At any point, each Java Virtual Machine thread is executing the code of a single method, namely the current method (§2.6) for that thread.

https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-2.html#jvms-2.5.1

我假设 JVM 线程像任何其他线程一样工作 - 每次该线程被调度到 运行(比如 Linux 内核)时它的 "program counter" 被加载从它的 task_struct data structure 来看,从 CPU 的角度来看,只有一个程序计数器 - 它只是在每次 OS 切换线程时由 OS 更新。

对吗?我很困惑,因为整个页面似乎一直在强调每个 JVM 都有自己的 PC/stack/heap 等等,但我认为这是给定的任何进程 - JVM 在某种程度上与其他进程不同吗?

assume that the JVM works like any other thread

JVM 不是线程:它是一个进程,有很多线程。

...so from the CPU's perspective there's only a single program counter

程序计数器只是构成线程上下文的几个寄存器之一。每个 CPU 都有一组物理寄存器(或两组,如果它是超线程的,但让我们保持简单并忽略超线程。)每个 CPU 因此可以 运行 在任何给定的线程即时时间。但是...

操作系统可以"switch contexts":它可以在给定的CPU上保存一个线程运行ning的所有寄存器,然后用保存的寄存器加载寄存器(包括程序计数器)来自其他线程。

在典型的桌面操作系统中,操作系统调度程序被调用,可能每秒调用 100 次或更多次,以决定哪些线程应该在那个时刻 运行ning。它将切换出当时实际上 运行ning 的线程,并切换到一直在等待 运行.

的线程

这样一来,您的计算机上的活动线程可以比 CPU 多得多。