JVM first article understanding java virtual machine

Table of contents

1. What is java virtual machine

2. Java virtual machine classification

2.1. Commercial virtual machines

2.2. Embedded virtual machine

3.java virtual machine architecture

4.java virtual machine running process


1. What is java virtual machine

       A virtual machine in the traditional sense is an abstract computer that is implemented by simulating various computer functions on an actual computer. It is an operating system-level virtual machine. The Java virtual machine is a program virtual machine with its own complete hardware architecture, such as processor, stack, registers, etc., and also has a corresponding instruction system. The Java virtual machine shields the information related to the specific operating system platform, so that the Java program only needs to generate the target code (bytecode) that runs on the Java virtual machine, and it can run on a variety of platforms without modification.

2. Java virtual machine classification

2.1. Commercial virtual machines

(1) The Sun HotSpot
virtual machine has superior performance and is the default virtual machine for all sun JDK versions starting from sun JDK1.3 and later. It is the most widely used and is generally the default virtual machine.
(2) BEA JRockit
JRockit virtual machine is a virtual machine acquired by BEA from Appeal Virtual Machines in 2002.
It is a highly optimized virtual machine for server hardware and server usage scenarios. It was once known as "the fastest virtual machine in the world."
Because it focuses on server-side applications, it does not contain the implementation of the parser internally, and all codes are compiled and executed by the just-in-time compiler.
(3) IBM J9
J9 virtual machine is a high-performance virtual machine independently developed by IBM. It is not sold independently, but serves as an execution platform for various IBM products. IBM defines it as a virtual machine that can adapt to everything from embedded devices to A highly portable Java operating platform for large-scale enterprise-level applications.
(4) The Sun Classic 
virtual machine is very primitive. It is a Java virtual machine used in the JDK1.0 era and is the originator of various virtual machines. It does not have a just-in-time compiler inside and can only be run in a purely interpreted manner.
(5) Sun Exact 
This is another virtual machine of Sun Company besides HotSpot. It was briefly put into commercial use in the JDK1.2 era. It was developed at the same time as HotSpot, but was eventually replaced by HotSpot.
(6) Apache Harmony 
Harmony is a virtual machine implementation led by the Apache Software Foundation, open source, independent, and actually compatible with JDK1.5 and JDK1.6.
It indirectly gave birth to the Dalvik virtual machine of the Google Android platform. It goes without saying how influential Android is now. It is currently the most successful universal platform for digital devices.
However, due to its TCK authorization issue, Apache directly broke with Oracle and withdrew from the JCP. This is the most serious split crisis encountered by the Java camp in modern times.

2.2. Embedded virtual machine

(1) Dalvik
The Dalvik virtual machine is one of the core components of the Android mobile device platform jointly developed by Google and other manufacturers. It executes dex (Dalvik Executable) files instead of class files, and uses
register architecture instead of stack architecture. However, its development The system is inextricably related to Java, and most Java APIs can be used directly, and dex files can be directly converted from class files.
And the implementation of just-in-time compiler is provided in Android 2.2, and the performance is greatly improved.

(2) KVM
was a virtual machine widely used on mobile phone platforms before the emergence of smartphone operating systems such as Android and IOS.

(3) CDC/CLDC HotSpot
CDC and CLDC HotSpot are Sun's virtual machines for high-end embedded devices and mid- to low-end embedded devices respectively, used to replace KVM.
 

3.java virtual machine architecture

The architecture of JVM is divided into three parts: class loader, runtime data area and execution engine.
(1) Class loader The class loader is an important part of the JVM. It is responsible for loading Java classes into the JVM. The class loader loads Java class files into memory and converts them into a format that the JVM can understand. Class loaders are divided into three levels: startup class loader, extension class loader and application class loader. The startup class loader is part of the JVM and is responsible for loading Java core class libraries, such as java.lang and java.util. The extension class loader is responsible for loading Java extension class libraries, such as JDBC drivers and Java Servlet APIs. The application class loader is responsible for loading the application's class files.
(2) Runtime data area The runtime data area is the memory management system of JVM. It is divided into five parts: method area, heap, virtual machine stack, local method stack and program counter. The method area stores the structural information, constant pool, static variables, method codes, etc. of the class. The heap is the memory area where Java programs are running and is used to store object instances. The virtual machine stack is used to store local variables, operand stacks, return values, etc. of methods. The local method stack is used to store the parameters and return values ​​of local methods. The program counter is used to record the address of the bytecode instruction executed by the current thread.
(3) Execution engine The execution engine is the core part of the JVM. It is responsible for converting Java bytecode into machine code and executing Java programs. The execution engine is divided into two parts: the interpreter and the just-in-time compiler.
The interpreter interprets Java bytecode into machine code one by one and executes the Java program. The just-in-time compiler compiles Java bytecode into native machine code and executes Java programs. Just-in-time compilers can improve the execution efficiency of Java programs.

4.java virtual machine running process

Java program running process: bytecode file loading -> interpretation and execution/compilation and execution

Simple diagram:

 Complex graph:

 

Guess you like

Origin blog.csdn.net/hsy12342611/article/details/132522035