Home  >  Article  >  Java  >  Detailed overview of Java virtual machine

Detailed overview of Java virtual machine

PHP中文网
PHP中文网Original
2017-06-20 14:35:161615browse

1. Overview of Java virtual machine

The Java technology system officially defined by Oracle mainly includes the following parts:

  • Java Programming Language

  • Java virtual machine for various platforms

  • Class file format

  • Java API class Library

  • Third-party Java class library

The three parts of Java programming language, Java virtual machine and Java API class library can be collectively referred to as JDK (Java Development Kit), which is the minimum environment for Java program development. In addition, the Java SE API subset and Java virtual machine in the Java API are collectively called JRE (Java Runtime Environment), which is the standard environment for Java programs to run.

The reason why the Java virtual machine is called "virtual" is because it is just an abstract computer defined by a specification.

2. Java Virtual Machine Family

Many students may think that the Java virtual machine is just a virtual machine. Does it have a family? Or think that the Java virtual machine refers to Oracle's HotSpot virtual machine. Here is a brief introduction to the Java virtual machine family. Since the Sun Classic VM included in JDK1.0 released by Sun in 1996 to today, many types of virtual machines have appeared and disappeared. Here we will only briefly introduce the relatively mainstream Java virtual machines that currently exist. .

HotSpot VM
The virtual machines that come with Oracle JDK and OpenJDK are the most mainstream and widely used Java virtual machines. Technical articles introducing the Java virtual machine, unless otherwise specified, most of them introduce HotSpot VM. HotSpot VM was not developed by Sun, but was designed by Longview Technologies, a small company. It was acquired by Sun in 1997, and Sun was acquired by Oracle in 2009.
J9 VM
J9 VM is a VM developed by IBM and is currently its main development Java virtual machine. The market positioning of J9 VM is close to that of HotSpot VM. It is a multi-purpose virtual machine designed with everything from server to desktop application to embedded in mind. The current performance level of J9 VM is roughly on the same level as HotSpot VM.
Zing VM
Based on Oracle's HotSpot VM, many details that affect latency have been improved. The three biggest selling points are:

  • 1. Low latency, "no pause" C4 GC, the pause caused by GC can be controlled below 10ms, and the supported Java heap size Can reach 1TB;

  • #2. Quick warm-up function after startup.

  • 3. Manageability: Zing Vision, a monitoring tool integrated into the JVM that has zero overhead and can be turned on at all times in the production environment.

3. Java virtual machine execution process

When we execute a Java program, what is its execution process? As shown below.

As you can see from the above figure, the Java virtual machine has no necessary connection with the Java language. It is only related to a specific binary file: the Class file..

4.Java virtual machine structure

The architecture mentioned here refers to the abstract behavior of the Java virtual machine, rather than the specific implementation of HotSpot VM. . According to the Java virtual machine specification, the abstract Java virtual machine is shown in the figure below.

##JVM = classloader classloader + execution engine execution engine + runtime data area runtime data area

. classloader loads the class file on the hard disk into the runtime data area in the JVM, but it is not responsible for whether the class file can be executed, and this is the responsibility of the execution engine .

The Java virtual machine abstract specification is just a concept. Generally speaking, the Java virtual machine is a specific implementation of the specification. This implementation may come from multiple providers and exist on multiple platforms. It can be implemented entirely in software, or in a combination of hardware and software.

5. The life cycle of the virtual machine

The bounden duty of a runtime Java virtual machine instance is: responsible for running a java program.

When a Java program is started, a virtual machine instance is born. When the program is closed and exited, the virtual machine instance will also die

. If three Java programs are run simultaneously on the same computer, three Java virtual machine instances will be obtained. Each Java program runs in its own Java virtual machine instance. A Java virtual machine instance runs a Java program by calling the main() method of an initial class. The main() method must be public, static, return void, and accept a string array as a parameter. Any class with such a main() method can be used as the starting point for running a Java program.

public class Test {public static void main(String[] args) {// TODO Auto-generated method stubSystem.out.println("Hello World");
    }

}

In the above example, the main() method in the initial class of the Java program will be used as the starting point of the initial thread of the program, and any other threads are started by this initial thread.

There are two kinds of threads inside the Java virtual machine: daemon threads and non-daemon threads. Daemon threads are usually used by the virtual machine itself, such as threads that perform garbage collection tasks. However, a Java program can also mark any thread it creates as a daemon thread. The initial thread in the Java program - the one that starts in main(), is a non-daemon thread.

As long as there are any non-daemon threads running, the Java program will continue to run. When all non-daemon threads in the program terminate, the virtual machine instance will automatically exit . If the security manager allows it, the program itself can also exit by calling the exit() method of the Runtime class or the System class.

The above is the detailed content of Detailed overview of Java virtual machine. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to use JavaPoet?Next article:How to use JavaPoet?