当前位置:网站首页>JVM | runtime data area; Program counter (PC register);

JVM | runtime data area; Program counter (PC register);

2022-06-11 21:28:00 z754916067

Run time data area

  • Method area : After the class is loaded, it is placed in the method area
  • Program counter
  • Native Method Stack
  • Pile up
  • Virtual machine stack

The relationship between data area and thread

Private to each individual thread : Program counter , Stack , Local stack
Sharing between threads : Pile up , Out of heap memory ( Method area ( Permanent generation or meta space ) Code cache )

Threads

A thread is a running unit in a program ,JVM Allows an application to have multiple threads executing in parallel .
Once the local thread is initialized successfully , It's going to call Java In thread run() Method .

Program counter (PC register )

  • It's a small memory space , It's also the fastest running storage area .
  • A thread has only one method executing at any one time , It's called “ The current method ”.
  • The program counter stores what the current thread is executing Java Methodical JVM Instruction address .

effect

PC Registers are used to store the address to the next instruction , Also about to execute the instruction code . The execution engine reads the next instruction .

Use examples

The program counter stores the address of the next instruction , The execution engine looks for the corresponding statement according to this address , To operate .
 Insert picture description here

common problem

1. Use PC What's the use of registers storing bytecode instruction addresses ?
answer :CPU You need to constantly switch threads , After switching back, you have to know where to start .
2. Why use PC Register records the execution address of the current thread ?
answer :JVM The bytecode interpreter needs to be changed PC Register to determine what kind of bytecode instruction should be executed next .

The reason why threads are private

So called multithreading , The method of only one thread will be executed in a specific time period ,CPU I'll keep switching tasks , This inevitably leads to frequent interruptions or recoveries .
In order to accurately record the current bytecode instruction address that each thread is executing , The best way is to assign one to each thread PC register .
In this way, each thread can perform independent calculation .

原网站

版权声明
本文为[z754916067]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206112122430147.html