当前位置:网站首页>Chapter 7 of JVM series -- bytecode execution engine
Chapter 7 of JVM series -- bytecode execution engine
2022-04-23 14:35:00 【InfoQ】
- All kinds of instructions expressed in binary code , be calledmachine instruction code. Start , People use it to write programs , This is machine language .
- Machine language can be understood and accepted by computers , But it's so different from people's language , It's not easy to be understood and remembered by people , And programming with it is easy to make mistakes .
- Once the program written with it is input into the computer ,CPU Read directly to run , So compared with programs written in other languages , Fastest execution .
- Machine instructions and CPU Closely related , So different kinds of CPU The corresponding machine instructions are different .
- Because the machine code has 0 and 1 A binary sequence of components , The readability is really poor , So people invented instructions .
- An instruction is a machine code specific to 0 and 1 Sequence , Reduced to the corresponding instruction ( It is usually abbreviated in English , Such as mov,inc etc. ), It's a little more readable
- Because of different hardware platforms , Perform the same operation , The corresponding machine code may be different , So the same instruction from different hardware platforms ( such as mov), The corresponding machine code may be different .
- Different hardware platforms , The instructions they support , There is a difference . So the instructions that each platform supports , Call it the instruction set of the corresponding platform .
- As is common :x86 Instruction set , The corresponding is x86 Architecture platform 、ARM Instruction set , The corresponding is ARM Architecture platform
- Because the readability of the instructions is still too poor , So people invented assembly language .
- In assembly language , Use mnemonics (Mnemonics) An operation code that replaces a machine instruction , Using address symbols (Symbol) Or labelling (Label) The address of an instruction or operand . On different hardware platforms , Assembly languages correspond to different machine language instruction sets , Conversion to machine instructions by assembly process .
- Because computers only know instruction codes , Therefore, the program written in assembly language must also be translated into machine instruction code , Computers can recognize and execute .
- In order to make it easier for computer users to program , Later, various high-level computer languages appeared .
- High level language is better than machine language 、 Assembly language is closer to human language when a computer executes a program written in a high-level language , Still need to interpret and compile the program into the machine's instruction code . The program that completes this process is called an interpreter or compiler .
- High level languages are not directly translated into Machine instructions , But translated into assembly language , As mentioned below C and C++

- The compilation process can be divided into two stages :Compile and assemble.
- The build process :Is to read the source program ( Character stream ), Analyze the morphology and grammar of it , Convert high-level language instructions into functional equivalent assembly code
- Assembly process :In fact, it refers to the process of translating assembly language code into target machine instructions .

- Bytecode is an intermediate state ( Middle ) The binary code of ( file ), It's more abstract than machine code , It needs to be translated by a literal translator before it can be machine code
- Bytecode is mainly used to realize specific software operation and software environment 、 Nothing to do with the hardware environment .
- Bytecode is implemented through compilers and virtual machines . The compiler compiles the source code into bytecode , Virtual machines on specific platforms translate bytecodes into instructions that can be executed directly .
- The typical application of bytecode is :Java bytecode

- Bytecode interpreterThe execution of bytecode is simulated by pure software code , Very inefficient .
- Template interpreterAssociate 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 .
- Interpreter modular :The core function of the interpreter is realized
- Code modular :Used to manage HotSpot VM Local machine instructions generated at runtime
- The first isCompile the source code into a bytecode file, And then at run timeThe bytecode file is converted into machine code through the interpreter to execute
- The second isCompile implementation ( Directly compiled into machine code ). In order to improve the execution efficiency of modern virtual machine , Will use just in time compilation technology (JIT,Just In Time) Compile the method into machine code and then execute it
- Java Linguistic “ Compile time ” It's actually a paragraph “ Not sure ” Operation process , Because it may refer to aFront end compiler( Actually called “ The front end of the compiler ” More accurate ) hold .java The document is transformed into .class Documentation process ;
- It may also refer to the of virtual machinesBack end runtime compiler(JIT compiler ,Just In Time Compiler) The process of converting bytecode into machine code .
- It may also refer to the use ofStatic precompiler(AOT compiler ,Ahead of Time Compiler) Put... Directly .java The process of Compiling Files into local machine code .
- Java 9 The experimental method is introduced AOT Compiler tools aotc. It uses Graal compiler , Put in Java Class file to machine code , And stored in the generated dynamic shared library .>.java -> .class -> ( Use jaotc) -> .so
- benefits :Java The virtual machine load has been precompiled into a binary Library , Can be executed directly . You don't have to wait for the compiler to warm up in time , Reduce Java Application brings benefits to people “ Slow for the first time ” The bad experience of
- shortcoming :Destroyed java “ A compilation , Run anywhere ”, 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 , At first, it only supported Linux X64 java base
- 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 , Therefore, it is called stack replacement , Or for shortOSR(On Stack Replacement) compile .
- How many times does a method have to be called , Or how many cycles does a loop body need to execute to reach this standard ? There must be a clear threshold ,JIT It's the compiler that will take this “ Hot code ” Compile for local machine instruction execution . It mainly depends onHot spot detection function .
- at present HotSpot VM The hot spot detection method is based on the counter .
- Using counter based hotspot detection ,HotSpot V It will be built for every method 2 There are two different types of counters , RespectivelyMethod call counter (Invocation Counter) It is used to count the number of calls of the method and the edge returning counter (Back Edge Counter) Used to count the number of cycles executed by the loop body .
- This counter is used to count the number of times a method is called , Its default threshold is Client In mode is 1500 Time , stay Server In mode is 10000 Time . Over this threshold , It will trigger JIT compile .
- This threshold can be determined by virtual machine parameters-XX:CompileThresholdTo set .
- When a method is called , We will first check whether the method has been JIT The compiled version , If there is , The compiled local code is preferred for execution . If there is no compiled version , Add... To the call counter value of this method 1, And then determineWhether the sum of the value of the method call counter and the back edge counter exceeds the threshold of the method call counter. If the threshold has been exceeded , A code compilation request for this method will be submitted to the just in time compiler .

版权声明
本文为[InfoQ]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231433113805.html
边栏推荐
- source insight via samba
- AT89C52 MCU frequency meter (1Hz ~ 20MHz) design, LCD1602 display, including simulation, schematic diagram, PCB and code, etc
- 555定时器+74系列芯片搭建八路抢答器,30s倒计时,附Proteus仿真等
- QT interface optimization: double click effect
- The initial C language framework is suitable for review and preliminary understanding
- 全连接层的作用是什么?
- 科技的成就(二十一)
- 矩阵交换行列
- Basic regular expression
- 线程同步、生命周期
猜你喜欢

ArrayList collection basic usage

【Servlet】Servlet 详解(使用+原理)

LotusDB 设计与实现—1 基本概念

TLS/SSL 协议详解 (30) SSL中的RSA、DHE、ECDHE、ECDH流程与区别

Notes on Visio drawing topology

电容

循环队列的基本操作(实验)

Electronic perpetual calendar of DS1302_ 51 single chip microcomputer, month, day, week, hour, minute and second, lunar calendar and temperature, with alarm clock and complete set of data

抑郁症治疗的进展

AT89C51 MCU digital voltmeter development, measuring range 0 ~ 5V, proteus simulation, schematic diagram, PCB and C program, etc
随机推荐
After entering the new company, the operation and maintenance engineer can understand the deployment of the system from the following items
想要成为架构师?夯实基础最重要
DS1302的电子万年历_51单片机,年月日、星期、时分秒、农历和温度,带闹钟,全套资料
AT89C52 MCU frequency meter (1Hz ~ 20MHz) design, LCD1602 display, including simulation, schematic diagram, PCB and code, etc
Use cases of the arrays class
On the insecurity of using scanf in VS
Solve the problem of SSH configuration file optimization and slow connection
I thought I could lie down and enter Huawei, but I was confused when I received JD / didi / iqiyi offers one after another
基于TLC5615的多路可调数控直流稳压电源,51单片机,含Proteus仿真和C代码等
The initial C language framework is suitable for review and preliminary understanding
基于单片机的DS18B20的数字温度监控报警系统设计【LCD1602显示+Proteus仿真+C程序+论文+按键设置等】
一个月把字节,腾讯,阿里都面了,写点面经总结……
555 timer + 74 series chip to build eight way responder, 30s countdown, proteus simulation, etc
AT89C51 MCU digital voltmeter development, measuring range 0 ~ 5V, proteus simulation, schematic diagram, PCB and C program, etc
关于在vs中使用scanf不安全的问题
C语言知识点精细详解——初识C语言【1】——你不能不知的VS2022调试技巧及代码实操【2】
自动化的艺术
tcp_diag 内核相关实现 1 调用层次
交通灯系统51单片机设计(附Proteus仿真、C程序、原理图及PCB、论文等全套资料)
外包幹了四年,廢了...