当前位置:网站首页>JVM (1): introduction, structure, operation and lifecycle
JVM (1): introduction, structure, operation and lifecycle
2022-06-11 04:16:00 【Prince you】
One 、 virtual machine
The so-called virtual machine (Virtual Machine), It's a virtual computer , It's a software , Used to execute a series of virtual computer instructions . In general, virtual machine can be divided into system virtual machine and program virtual machine .
- big-name Visual Box,VMWare It belongs to the system virtual machine , They are all simulations of physical computers , It provides a software platform that can run a complete operating system .
- A typical representative of program virtual machine is java virtual machine , It's designed to execute a single computer program , stay java The instructions executed in the virtual machine are called java Bytecode instruction .
Whether it's a system virtual machine or a program virtual machine , The software running on it is limited to the resources provided by the virtual machine .
Two 、java virtual machine
java A virtual machine is an execution machine java Bytecode virtual computer , It has an independent operating mechanism , It runs java Bytecode may not be java Language compilation .
JVM Various languages of the platform can be shared java The cross platform nature of virtual machine , Excellent garbage collection mechanism and reliable just in time compiler .java The core of technology is java virtual machine (JVM,Java Virtual Machine), Because of all the java The program is running in java Inside the virtual machine .
effect
java Virtual machine is the running environment of binary bytecode , Responsible for loading bytecode into its interior , explain / Compile to execute machine instructions on the corresponding platform . Every one of them java Instructions ,java There are detailed definitions in the virtual machine specification , How to get the operands , How to deal with operands , Where is the result of the treatment .
characteristic
- A compilation , Run anywhere .
- Automatic memory management .
- Automatic garbage collection function .
3、 ... and 、JVM The location of

JDK The composition of the

Four 、JVM The overall structure
- Hotspot VM It is one of the representative works of high performance virtual machine on the market .
- It uses an interpreter and just in time compiler architecture .
- In today's ,Java The performance of the program has been completely changed , Have reached the point where you can and C/C++ The program is higher and lower .

The method area and heap are shared by multiple threads , and java Stack 、 Local method stacks and program counters are unique to each thread .
Execution engine

In the red box is the execution engine , From left to right : Interpreter 、JIT Just in time compiler 、 Garbage collector .
JIT The just in time compiler is the back end of the compiler (java Source code compiled as class Files can also become compiler front ends ), Because the bytecode file cannot call the local machine program , The bytecode needs to be compiled into the local machine language .
5、 ... and 、java Code execution process

The following figure is a detailed drawing :

- Explain to perform : Guaranteed response time , Execute line by line response to bytecode file .
- Compile implementation : The byte code with high repeatability ( Hot code ) Compile into machine instructions ( Recompilation ) And cache it .
6、 ... and 、JVM Architectural model
Java The instruction stream base of compiler input is a stack based instruction set architecture , Another instruction set architecture is register based instruction set architecture . say concretely , The difference between the two architectures :
Based on the characteristics of plank structure
- Simpler design and Implementation , For systems with limited resources .
- Avoid the problem of register allocation : Use zero address instruction to assign .
- Most of the instructions in the instruction stream are zero address instructions , Its execution depends on the operation stack . The instruction set is smaller , The compiler is easy to implement .
- No hardware support required , Better portability , Better cross platform .
Based on the characteristics of register architecture
- The typical application is x86 The binary instruction set of ; Like traditional Pc as well as Android Of Davlik virtual machine .
- The instruction set architecture is completely hardware dependent , Poor portability
- Better performance and more efficient execution .
- Spend less instruction to complete an operation .
- In most cases , The instruction set based on register architecture usually uses one address instruction 、 Two address instructions and three address instructions are the main , The instruction set based on the stack architecture is mainly zero address instruction .

summary :
Because of the cross platform design ,Java The instructions of are designed according to the stack . Different platforms CPU Different architectures , So it can't be designed as register based . The advantage is cross platform , Instruction set is small , The compiler is easy to implement , The disadvantage is that the performance is reduced , More instructions are needed to implement the same function .
today , Although embedded platforms are no longer Java The mainstream running platform of the program ( To be exact, it should be HotSpotVM Our host environment is no longer limited to embedded platforms ), So why not change the architecture to register based architecture ?
7、 ... and 、JVM Life cycle
Start of virtual machine
Java The virtual machine is started by booting the classloader (bootstrap class loader) Create an initial class (initial class) To complete , This class is specified by the specific implementation of the virtual machine .
Virtual machine execution
- A running Java The virtual machine has a clear task : perform Java Program .·
- It only runs when the program starts executing , It stops at the end of the program .
- Carry out a so-called Java When it comes to programming , What is really being implemented is a project called Java Process of virtual machine .
Virtual machine exit
There are several situations as follows :
- The normal execution of the program ends
- The program encountered an exception or error during execution and terminated abnormally
- Caused by an error in the operating system Java Virtual machine process termination
- A thread calls Runtime Class or system Class exit Method , or Runtime Class halt Method , also Java Security manager also allows this time exit or halt operation .
- besides ,JNI ( Java Native Interface) The specification describes the use of JNI Invocation API To load or unload Java When virtual machines ,Java Virtual machine exit .
边栏推荐
- Linq. pdf
- Eth Transfer
- 2022-06-10:薯队长从北向南穿过一片红薯地(南北长M,东西宽N),红薯地被划分为1x1的方格, 他可以从北边的任何一个格子出发,到达南边的任何一个格子, 但每一步只能走到东南、正南、西南方向的
- Embedded basic interface PWM
- 超简单 CameraX 人脸识别效果封装
- Several time synchronization methods of Beidou timing system (GPS timing equipment)
- Eth relay interface
- Market prospect analysis and Research Report of engraving laser in 2022
- Cloud broadcast alert, guanghetong helps intelligent camera to build a "river protection" drowning prevention system
- 6. form label
猜你喜欢

为了实现零丢包,数据中心网络到底有多拼?

Eth Transfer

NTP time server (GPS Beidou satellite synchronous clock) application boiler monitoring system

Source Insight 4.0设置注释与反注释的快捷键

Embedded basic interface-i2s
![[laser principle and application-2]: key domestic laser brands](/img/55/a87169bb75429f323159e3b8627cc6.jpg)
[laser principle and application-2]: key domestic laser brands

Statistical knowledge required by data analysts

司马炎爷爷 告诉你什么叫做内卷!

6. 表格标签

L'avenir est venu, l'ère 5G - Advanced s'ouvre
随机推荐
The future has come and the 5g advanced era has begun
A Security Analysis Of Browser Extensions
SQL injection correlation analysis
JVM(7):动态链接、方法的调用、四种方法调用指令区分非虚方法和虚方法、invokedynamic指令的使用
D structure as index of multidimensional array
七个好用的装饰器
Embedded basic interface-i2c
Esp32 gattc configuration UUID
检测php网站是否已经被攻破的方法
Market prospect analysis and Research Report of integrated scanner in 2022
[server data recovery] data recovery case of RAID5 crash of buddy storage
What great open source projects does Google have?
Lexical analyzer for compiling principle notes
Introduction to the development and production functions of shop facade transfer and rental applet
Construction of esp8266/esp32 development environment
Market prospect analysis and Research Report of digital line scan camera in 2022
6. 表格标签
数据类型的转换和条件控制语句
域名解析耗时是什么?域名解析耗时影响因素有哪些?
Market prospect analysis and Research Report of pipe and hose press fitting tools in 2022