Summary of Java internal----JVM virtual machine principle

Source: Internet
Author: User

Java is a semi-compiled, semi-explanatory language, and Java is first compiled into a. class. With some binary reading software, you can get to know the internal composition of the. class file. "In-depth understanding of Java Virtual Machine" a special chapter on this, I feel more trouble, not to say.

Virtual machine class loading mechanism (Java is a semi-compiled semi-interpreted language, the. java file is first compiled into a. class file, and because the compilation is JVM-oriented, this is somewhat different from C + + 's compilation mentality.) As long as the compiler is understandable to the JVM, it is not compiled as a machine code that can be executed by a computer like C + +. Java's JVM is responsible for communicating with real computers, and Java programs can only be interpreted by the JVM. So this semi-compiled, semi-explanatory feature provides a lot of flexibility that C + + cannot. ):

Is the Java loading mechanism. The first thing we need to know is the timing of the Java class initialization (initialization in the diagram):

1,new

2, Reflective

3, Initializes a class if the parent class has not been initialized, first initializes its parent class

The loading time of a class is not later than the initialization time of the class.

Class loading the first thing to do is to find this class of. class binary byte stream through the class name (including the package). Load the class information into the method area (probably still a primitive. Class content). Then instantiate an Java.lang.Class class object in memory (the information for each class is also an object in Java, which is a very philosophical concept). This Java.lang.Class object is not in the Java heap (although it is an object) and is in the method area. This object is the external interface of the class in the program Access method area.

The preparation (preparation) phase in the diagram is a continuation of the loading phase-also in the method area: initializing the static variable. Allocates only memory space, at which point the value is 0.

For example, a class is written to public static int value = 123; In the preparation phase, publi static int value = 0; public static int value = 123 at initialization stage;

However, if public static final int value = 123, then public static final int value = 123 in the prepare phase;

The parsing phase translates the symbolic reference (the data structure within the. class file) into a direct reference (really corresponds to the virtual machine memory layout) within the Chang (introduced in the sixth chapter of "Deep Understanding virtual Machine")

It can be seen that before the initialization process, the class information is loaded, connected, and also in the method area. Starting with the initialization phase, the Java execution engine is really involved.

The following code is roughly the case:

 Public class c{       publicstaticint  A;         Public method1 () {...}  }

Java internal----JVM Virtual Machine principle Summary

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.