Deep parsing Java Virtual machine _java

Source: Internet
Author: User
Tags constant garbage collection

What is a Java virtual machine

"Java Virtual machine" may refer to the following three kinds of things:
1), abstract norms;
2), a specific implementation;
3), a running virtual machine instance;

Java Virtual machine life cycle

Start
When a Java program is started, a virtual machine instance is born.
The virtual machine instance runs a Java program by calling the public static void main (string[] args) method of an initial class.
Any class that has such a main method can be the starting point for the Java program to run, so you must tell the virtual machine the name of the initial class, and the entire program will start running from its main method.

Die
The main method of the initial class acts as the starting point for the program's initial thread, and any other threads are started by the initial thread.
There are two kinds of threads inside a Java Virtual machine: A daemon and a non-daemon thread.
A daemon thread, typically a thread used by a virtual machine, such as garbage collection. The Java program can also mark the created thread as a daemon thread.
Non-Daemon threads, the initial thread in Java, that is, the thread that starts with the main method is a non-daemon thread.
As long as a non-daemon thread is running in the program, the Java program continues to run (the virtual machine is still alive ), and the virtual machine instance exits automatically when all the non-daemon threads in the program terminate.
The program itself can also be exited by the runtime class or the exit () method of the System class.

Java Virtual Machine Architecture

Class loading Subsystem
1, is responsible for locating and loading types, divided into loading, connection and initialization, in the Java type life cycle has detailed description;
2), there are two kinds of loaders: Start class loader and user-defined class loader;
The user-defined class loader must be derived from the Java.lang.ClassLoader class.

Run-time Data area

Method area
The information of the loaded type is stored in the method area in detail as follows:
Basic information
1), the type of fully qualified name;
2), the type of direct super class fully qualified name;
3), the type is a class type or an interface type;
4), the type of access modifier;
5), the fully qualified name of the direct Super interface;

Other information
1), the type of constant pool;
2), field information;
3), method information;
4), in addition to the constant thought of all static variables;
5), a reference to the ClassLoader class;
6), a reference to class classes;

Heap
1), all class instances and arrays created at run time are placed in the heap;
2, a Java Virtual machine instance exists only one heap space, so all threads in the virtual machine share this heap;
3), a Java program exclusive of a Java Virtual machine instance, so each Java program has his own heap space;

Java stack

1, every time a new thread is started, the Java Virtual machine will assign a Java stack for him;
2), Java stack to save the running state of the thread in the frame;
3, Java Virtual machine to Java stack only perform two operations: pressure stack and out of the stack;
4), pressure stack: Whenever a thread invokes a Java method, the virtual machine presses a new frame into the Java stack of that thread. Use this frame to store parameters, local variables, intermediate operation results, etc.
5), out of the stack: When the Java method returned normal through return, or by throwing an exception to abort, the virtual machine will be the current frame pop-up Java stack and then released;
6), the stack data is thread-private, so there is no need to consider the problem of access synchronization of stack data in multi-threaded situations;

Stack frame
1), the stack frame consists of three parts: local variable area, operation number area and stack data area;

PC Registers
1, for the operation of the Java program, each thread has its own PC register;
2), create when the thread starts;
3, when a thread executes a Java method, the contents of the PC register are always the address of the next instruction to be executed.

Local method Stack
1), any local method interface will use the local method stack;

Execution engine
1), execution engine is the core of Java Virtual machine implementation;
2), "execution engine" can have three kinds of understanding:
A), one is the abstract specification;
b), one is the concrete realization;
c), one is a running instance;
3, the behavior of the execution engine is defined using the instruction set. For each instruction, the specification prescribes what should be handled when the instruction is executed, and if the processing does not make a provision;
Pending refinement ...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.