当前位置:网站首页>Execution engine of JVM family
Execution engine of JVM family
2022-06-09 13:01:00 【a_ ittle_ pan】
introduction
Classic columns arrive as scheduled . We've learned before JVM Class loading process and basic related contents of runtime memory area , Today, let's learn about “ Execution engine ”.
Reference books :“ In depth understanding of java virtual machine ”
summary
The execution engine is JAVA One of the components of the virtual machine core “ virtual machine ” It's a comparison with “ The physical machine ” The concept of , Both machines have code execution capabilities , The difference is that the execution engine of the physical machine is built directly on the processor 、 cache 、 Instruction set and operating system level , The execution engine of virtual machine is implemented by software , Therefore, the architecture of instruction set and execution engine can be customized without physical constraints , Be able to execute instruction set formats that are not directly supported by hardware
JVM The main task of bytecode is to load bytecode into it , But bytecode cannot run directly on the operating system , Because bytecode instructions are not equivalent to local machine instructions , What it contains is only something that can be JVM Bytecode instruction identified 、 The symbol table 、 And other supporting information .
that , If you want to make a java The program runs , The task of the execution engine is to interpret bytecode instructions / It can only be compiled into the corresponding local machine instructions of the corresponding platform . Simply speaking ,JVM The execution engine acts as a translator for translating high-level languages into machine languages .
The execution process of the execution engine

- What bytecode instructions the execution engine needs to execute in the execution process completely depends on PC register .
- Every time after an instruction operation has been executed ,PC The register will update the address of the next instruction to be executed .
- Of course, the method is in the process of execution , It is possible for the execution engine to accurately locate the object reference stored in the local variable table JAVA Object instance information in the heap , And locate the type information of the target object through the metadata pointer in the object header .
What is an interpreter , What is a compiler ?
Interpreter : When java When the virtual machine is started, the bytecode will be interpreted line by line according to the defined specification , Put the contents of each bytecode file “ translate ” Execute... For the corresponding local machine instruction .
JIT(JUST IN TIME COMPILER) compiler : The virtual machine directly compiles the source code into the machine language related to the local machine platform .
stay java In the development history of , There are two sets of interpretation actuators , The ancient bytecode interpreter 、 The template interpreter now in common use .
Characteristics of different interpreters :
Bytecode interpreter simulates bytecode execution through pure software code , Very efficient
Low .The template interpreter associates each bytecode with a template function , The template function directly generates the machine code when the bytecode is executed , This greatly improves the performance of the interpreter .
- stay HotSpotVM in , The interpreter is mainly composed of Interpreter Templates and Code Template composition .
- Interpreter Templates : The core function of the interpreter is realized
- Code Templates : Used to manage HotSpotVM Local machine instructions generated at runtime
- stay HotSpotVM in , The interpreter is mainly composed of Interpreter Templates and Code Template composition .
JIT compiler :
java Linguistic “ compiler ” It's actually a paragraph “ Not sure ” Operation process , Because it could mean a front-end compiler ( Actually called “ The front end of the compiler ” More accurate ) hold .java The document is transformed into .class File transformation . It may also refer to the back-end runtime compiler of the virtual machine (JIT compiler ) The process of converting bytecode into machine code . It can also mean using a static advance compiler (AOT compiler ) Put... Directly .java The process of Compiling Files into local machine code .
Front end compiler : Sun Of Javac、Eclipse、JDT Incremental compiler side compiler in :Sun Of Javac、Eclipse、JDT Incremental compiler in
JIT compiler : HotSpotVM Of C1、C2 compiler
AOT compiler :GNU Compiler for the Java(GCJ),Excelsior JET
Hot code and detection methods :
- A method that is called many times , Or a method with more internal circulation can be called “ Hot code ”, Therefore, it can be passed JIT The compiler compiles into local machine instructions . Because this compilation occurs during the execution of a method , So it can also be called stack replacement , Or for short OSR(On Stack Replacement) compile .
- at present HotSpotVM The hot spot detection method is based on the counter .
- Using counter based hotspot detection ,HotSpotVM It will be built for every method 2 There are two different types of counters , Decibels are method call counters and back edge counters
- The method call counter is used to count the number of method calls
- The edge return counter is used to count the number of cycles executed by the loop body
JIT The classification of :
- -Client: perform java The virtual machine is running in Client In mode , And use C1 compiler :
- C1 The compiler optimizes bytecode simply and reliably , Short time . Faster compilation speed has been achieved
- -Server: perform Java The virtual machine runs on Server In mode , And use C2 compiler .
- C2 Time consuming optimization , And radical optimization . But optimized code is more efficient .
- C1 and C2 Different optimization strategies of compiler :
- C1:
- Method Inlining : Compile the referenced function code to the reference point , This can reduce the generation of stack frames , Reduce parameter passing and jump process .
- De virtualization : Inlining the only implementation class
- Redundancy elimination : Collapse code that won't execute during run time
- C2:
- Variable substitution : Use scalar values instead of attribute values of aggregate objects
- On the stack : For escaping objects, allocate objects on the stack instead of on the heap
- Synchronous elimination : Clear synchronization , Usually refers to synchronized
- C1:
AOT compiler :
benefits :java The virtual machine load has been compiled into a binary Library , It can run directly . Don't wait even if the compiler warms up , Reduce java Application brings benefits to people “ Slow for the first time ” The bad experience of .
shortcoming :
- Destroyed java“ A compilation , Execution everywhere ”, Must be for each different hardware 、OS Compile the corresponding distribution package .
- To reduce the java The dynamics of linking process , The loaded code must be known in the compiler
- We need to continue to optimize , Initial value support Linux
The design principle of the execution engine
When the program starts , The interpreter can work immediately , Save compilation time , Execute now . The compiler wants to work , Compiling code into native code , It takes a certain amount of execution time . But after compiling it into local code , High execution efficiency .
Design purpose : When java When the virtual machine starts , The interpreter works first , You don't have to wait for the instant compiler to complete its compilation before executing , This saves a lot of unnecessary compilation time . as time goes on , Compilers work , Compile more and more code into local code , Get more execution efficiency .
边栏推荐
猜你喜欢
随机推荐
[STM32] Hal library ADC
Cache and TLB
Hype plagiarism, insider fraud common NFT scams and security suggestions on opensea
【grafana基本使用】
keil5mdk安装(免费)
GDI+ 中区域的使用
Ten recommended shuttle plug-ins
AVR与ARM区别以及常用Arduino
Make qcombobox drop down a tree list with check boxes
Find container by overlay2 file name
LP流动性挖矿系统开发生态系统详解
Keil5mdk installation (free)
[001] 一天一句长难句分析
mdadm: cannot open /dev/sda1: Device or resource busy
[basic use of grafana]
Who says redis can't save big keys
Using the leetcode plug-in in vscode
[interpretation of the appender source code of logback]
.Net MVC5 富文本[wangEditor5] 的使用
GDI+ 中路径渐变画刷的使用







