当前位置:网站首页>JVM (4): active and passive use of classes, internal structure of runtime data area, JVM thread description, PC register
JVM (4): active and passive use of classes, internal structure of runtime data area, JVM thread description, PC register
2022-06-11 04:16:00 【Prince you】
One 、 Active and passive use of classes
stay JVM The middle represents two class There are two necessary conditions for an object to be the same class :
- The complete class name of a class must be consistent , Include package name .
- Load the classLoader( finger classLoader Instance object ) It has to be the same .
let me put it another way , stay JVM in , Even if these two class objects (class object ) From the same source class file , Loaded by the same virtual machine , But just load their ClassLoader Instance objects are different , Then the two class objects are not equal .
JVM You must know whether a type is loaded by the boot loader or the user class loader . If a type is loaded by a user class loader , that JVM A reference to the class loader is saved in the method area as part of the type information . When resolving a reference from one type to another ,JVM You need to ensure that these two types of classloaders are the same .
Java The way the program uses classes is divided into : Active use and passive use . Active use , There are seven situations ::
- Create an instance of a class
- Accessing static variables of a class or interface , Or assign a value to the static variable
- Calling static methods of a class
- Reflection ( such as :class.forName ( "com.atguigu. Test") )
- Initializing a subclass of a class
- Java The class marked as the startup class when the virtual machine starts
- JDK 7 Start with dynamic language support :java. lang.invoke.MethodHandle The parsing result of the instance REF_getstatic、REF_putstatic、REF_invokestatic The class corresponding to the handle is not initialized , Then initialize
In addition to the above seven cases , Other uses Java The way of a class is seen as a passive use of a class , Will not cause class initialization .
Two 、 The internal structure of the runtime data area


Memory is a very important system resource , It's hard disk and CPU Middle warehouse and Bridge , It carries the real-time operation of the operating system and application program .JVM The memory layout defines Java Memory request during run 、 Distribute 、 Managed policies , To ensure the JVM Efficient and stable operation of . Different JVM There are some differences between memory partition and management mechanism . combination JVM Virtual machine specification , Let's talk about the classic JVM Memory layout .




Every JVM only one Runtime example . That is, runtime environment , Equivalent to the middle frame of the memory structure : Runtime environment .
3、 ... and 、JVM Thread description in
A thread is a running unit in a program .JVM Allows an application to have multiple threads executing in parallel .
stay Hotspot JVM in , Each thread is mapped directly to the local thread of the operating system . When one Java When the thread is ready to execute , At this time, a local thread of the operating system is also created .Java After thread execution is terminated , Local threads also recycle .
The operating system is responsible for scheduling all threads to any available CPU On . Once the local thread is initialized successfully , It's going to call Java In thread run () Method .
If you use jconsoe Or any debugging tool , You can see that there are many threads running in the background . These background threads do not include calls public static void main (string[]) Of main Threads and all this main A thread created by a thread itself .
These main background system threads are in Hotspot JVM There are mainly the following :
- Virtual machine threads : This kind of thread operation needs JVM The safety point will be reached . The reason these operations have to happen in different threads is that they all need JVM Reach safety point , So the pile doesn't change . The execution types of this thread include "stop-the-world" Garbage collection , Thread stack collection , Thread suspension and biased lock revocation .
- Periodic task thread : This thread is the embodiment of time cycle events ( Like interruptions ), They are generally used for scheduling execution of periodic operations .
- GC Threads : This kind of thread pair is in JVM There are different kinds of garbage collection behaviors that support .
- Compile thread : This thread compiles bytecode into local code at run time .
- Signal scheduling thread : This thread receives signals and sends them to JVM, Inside it, it's handled by calling the appropriate method .
Four 、 Program counter (PC register ) summary

JVM Program count register in (Program counter Register) in , Register The name of comes from CPU The register of , Registers store field information about instructions .CPU Only loading data into registers can run .
here , It's not a physical register in a broad sense , Maybe translate it into pc Counter ( Or instruction counter ) It will be more appropriate ( Also known as program hook ), And it's not easy to cause some unnecessary misunderstandings .JVM Medium ec Registers are for physics Pc An abstract simulation of registers .

- It's a small piece of memory , I can almost ignore it . It's also the fastest running storage area .
- stay JVM Specification , Each thread has its own program counter , Threads are private , The life cycle is consistent with the life cycle of the thread .
- There is only one method in a thread at any time , It's the so-called current approach . The program counter stores what the current thread is executing Java Methodical JVM Instruction address ; perhaps , If it's execution native Method , The value is not specified (undefned) .
- It is an indicator of the flow of program control , Branch 、 loop 、 Jump 、 exception handling 、 Basic functions such as thread recovery rely on this counter .
- The bytecode interpreter works by changing the value of this counter to select the next bytecode instruction to execute .
- It is the only one in Java Nothing is specified in the virtual machine specification outOtMemoryError Area of situation .
PC Examples of the use of registers


solve PC Register two interview questions
problem 1:

problem 2:PC Why are registers set to thread private ?
We all know that the so-called multithreading will only execute one of the methods in a specific period of time ,CPU I'll keep switching tasks , This inevitably leads to frequent interruptions or recoveries , How to make sure there is no difference ? In order to accurately record the current bytecode instruction address that each thread is executing , The best way, of course, is to assign one to each thread PC register , In this way, each thread can be independently calculated , So that there will be no mutual interference .
because CPU Time slice wheel limit , Many threads are executing concurrently , Any definite moment , A core in a processor or multi-core processor , Only one instruction in a thread will be executed .
This inevitably leads to frequent interruptions or recoveries , How to make sure there is no difference ﹖ After each thread is created , Will produce their own program counter and stack frame , Program counters do not affect each other among threads .
CPU Time slice
CPU Time slice is CPU Time allocated to each program , Each thread is assigned a time period , It's called a time slice .
On the macro : We can open multiple applications at once , Each program runs parallel , Running at the same time .
But at the micro level : Since there is only one CPU, Only part of the program's requirements can be processed at a time , How to deal with fairness , One way is to introduce time slices , Each program is executed in turn .
边栏推荐
- Talk about data center network again
- FreeRTOS startup - based on stm32
- Esp32 development -lvgl animation display
- How does the NTP clock server (satellite clock system) coordinate the integrated system?
- Market prospect analysis and Research Report of programmable digital temperature regulator in 2022
- Eth Of Erc20 And Erc721
- Market prospect analysis and Research Report of digital line scan camera in 2022
- Market prospect analysis and Research Report of electronic pelletizing counter in 2022
- 司马炎爷爷 告诉你什么叫做内卷!
- [server data recovery] data recovery case of RAID5 crash of buddy storage
猜你喜欢

【CustomView】Glide+BitmapTransformation 图片上下边框波浪处理(WaveTransformation)

MySQL锁总结

强烈推荐这款神器,一行命令将网页转PDF!

This artifact is highly recommended. One line command will convert the web page to PDF!

2022爱分析· 隐私计算厂商全景报告 | 爱分析报告

Seven easy-to-use decorators

CES 2022 𞓜 guanghetong LTE module fm101 has obtained two important ce/fcc certifications with excellent performance

JVM(6):Slot变量槽、操作数栈、代码追踪、栈顶缓存技术

JVM(5):虚拟机栈、栈异常、栈的存储结果和运行原理、栈内部结构、局部变量表

It's 2022. When will the "module freedom" be realized?
随机推荐
A Security Analysis Of Browser Extensions
Protection and bypass of repeated contracting
JVM(4):类的主动使用与被动使用、运行时数据区域内部结构、JVM线程说明、PC寄存器
Embedded basic interface PWM
司马炎爷爷 告诉你什么叫做内卷!
L'avenir est venu, l'ère 5G - Advanced s'ouvre
Market prospect analysis and Research Report of programmable digital temperature regulator in 2022
密码找回功能可能存在的问题(补充)
Market prospect analysis and Research Report of Ethernet scanner in 2022
域名解析耗时是什么?域名解析耗时影响因素有哪些?
Radar emitter modulation signal simulation (code)
Why does the hospital comprehensive security system synchronize the NTP clock of the network server?
雷达辐射源调制信号仿真(代码)
7. 列表标签
Fundamentals of embedded audio processing
Ultra simple cameraX face recognition effect package
B - 刷墙 (C语言)
【服务器数据恢复】同友存储raid5崩溃的数据恢复案例
七个好用的装饰器
软件工程笔记之期末复习(简答)