当前位置:网站首页>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 .
边栏推荐
- 司马炎爷爷 告诉你什么叫做内卷!
- Esp32 development -lvgl uses internal and external fonts
- 基于FPGA的一维卷积神经网络CNN的实现(五)数据量化(附代码)
- clickjacking漏洞的挖掘与利用
- L'avenir est venu, l'ère 5G - Advanced s'ouvre
- Sslstrip Ultimate - location hijacking
- 再聊数据中心网络
- Talk about data center network again
- Implementation of one-dimensional convolutional neural network CNN based on FPGA (V) data quantization (with code)
- Market prospect analysis and Research Report of electronic pelletizing counter in 2022
猜你喜欢

27 pieces of advice for communication young people
![[network] socket programming](/img/df/2afc300bfc2dd319247a4b75ef7e2c.png)
[network] socket programming

Rational use of thread pool and thread variables

Cloud broadcast alert, guanghetong helps intelligent camera to build a "river protection" drowning prevention system

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

【服务器数据恢复】同友存储raid5崩溃的数据恢复案例
![[laser principle and application-2]: key domestic laser brands](/img/55/a87169bb75429f323159e3b8627cc6.jpg)
[laser principle and application-2]: key domestic laser brands
![[server data recovery] data recovery case of RAID5 crash of buddy storage](/img/c4/681c542310f05192bd14757965ef0d.png)
[server data recovery] data recovery case of RAID5 crash of buddy storage

Watson K's Secret Diary

A - Eddy‘s AC难题(C语言)
随机推荐
Market prospect analysis and Research Report of programmable digital temperature regulator in 2022
Final review of software engineering notes (short answer)
Methods to detect whether PHP websites have been broken
Market prospect analysis and Research Report of modular lithium ion battery in 2022
Explain in detail the structure and working principle of the crystal oscillator
Vulkan-官方示例解读-Shadows(光栅化)
SQL injection correlation analysis
A - Eddy‘s AC难题(C语言)
Protection and bypass of repeated contracting
使用工具类按一定规则读取Excel文件
详解 | 晶振的构造及工作原理
Zhongang Mining: fluorochemical industry is the main consumption field of fluorite
编程大作战 -- 挑战高考题
27 pieces of advice for communication young people
雷达辐射源调制信号仿真
[network] socket programming
Esp32 development -lvgl uses internal and external fonts
A.前缀极差(C语言)
Ultra simple cameraX face recognition effect package
Linq. pdf