JVM Title IV program counter (PC register)

  1. PC Register Introduction

JVM program counter (Program Counter Register) in, Register named for the CPU registers, the instruction register stores information related to the scene. Only the CPU load data into the register in order to run.

Here, the physical register is not referred to in the broad sense, to translate acquisition PC register (or instruction counter) would be more appropriate (also known as programs hook), the container and is not caused unnecessary misunderstanding. The JVM is an abstract register PC simulation of the physical register PC.

effect:

PC register is used to store a pointer to the address of the next instruction, the instruction code is also about to be executed. Read the next instruction by the execution engine.

  • It is a very small memory space, almost negligible. It is the fastest storage area.

  • In the JVM specification, each thread has its own program counter, the thread is private , consistent with the life cycle of the life cycle of the thread.

  • Any time a thread is only one way in the implementation, which is called the current method. The method of storing java program counter current process is executed JVM instruction address: Alternatively, if a native method execution, it is not specified value (undefined)

  • It is an indicator of program control flow, branching, looping, branching, exception handling, and other basic functions thread recovery relies on the counter to complete.

  • When the bytecode interpreter to select the next job is a bar bytecode instruction to be executed by changing the value of the counter.

  • It is the only one not specify any area OOM situation in the Java Virtual Machine Specification.

2 illustrates

3. Two common questions

Use PC register storing bytecode instruction address what is the use?

Why use the PC register records the current thread of execution address it?

Because the CPU need to keep switching the various threads, this time after the switch back, then know where to begin.

JVM byte code interpreter is by changing the value of the pc register to determine what the next bytecode instructions should be executed.

Why PC register will be set to private thread

We all know that the so-called multi-threading will only execute a certain period of time in which one thread method, CPU will continue to do the task switching, this will inevitably lead to a terminal or return frequently, to ensure that if it exactly right? In order to record the addresses of the current byte code instructions executing thread accurately, is naturally the best way each thread is assigned a pc register, so that they can be independently calculated between the respective threads to each other so that no case interference.

Since cpu polling time slice limits, during concurrent execution of many threads, any determination of a time, a core processor or a multi-core processor, will execute an instruction in a thread.

This will inevitably lead to regular terminal or resume, how to ensure that it exactly right? After each thread is created, it will have its own program counter and stack frames, the program counter between threads independently of each other.

The first chapter JVM JVM and Java architecture

The second JVM class loader subsystem

Overview and thread data area JVM is running third in

Micro-channel public number

Guess you like

Origin www.cnblogs.com/niugang0920/p/12424671.html