JVM face Test (iv)

Source: Internet
Author: User
Tags field table

Take a look at the deep understanding of the JVM, and summarize the questions standing in the interview

14.CLASS file Structure
1.Class file is a set of 8-bit byte (1byte = 8bit) based on the unit of the binary stream, there is no separator, in the middle of more than 1 bytes of data, with high address corresponding low byte to split the storage.
2.class files from the front to the back in turn is
Magic number, version number, Chang count, Chang, Access ID, class index, parent class index, interface count, interface table, field count, Field table, method count, Method table, property count, property sheet.
3. The constant pool counts from 1, storing two things: literal (Literal) and symbolic references. Literal literals can be interpreted as constants (text strings, declared final variables) notation references include the fully qualified name of the class and interface, the name and description of the field (the fields can be understood as variables declared outside the method in Class), the name of the method, and the description.
The length of the string, method name (in bytes) in 4.class is represented by a 2-byte int, that is, the method name and the maximum length of the string is 2^16 * 1 bytes = 64KB that is, the method name or character Fu Yi ("xxxxx") exceeding this length will not compile
5. Access identification
Two bytes, used to identify whether public abstract interface final annotation enumeration, and so on
6. Class index, parent class index
To determine the fully qualified name of a class and the fully qualified name of the parent class
7. Field ... Let's summarize it later.


15. Class load time, when class will load
The entire lifecycle of a class in memory includes
Load
Links: Validating, preparing, parsing
Class
Use
Unloading
The parsing may occur after initialization (polymorphic, dynamic binding), except that all steps are executed sequentially.


When it will load.
1. When you encounter the * * * instructions, that is, the new object, call class static field (except FINA defined and have initial value), static method
2. Reflection Call
3. Initialization of a class requires initialization of its parent class
The class containing main () that was loaded at 4.JVM startup
Reflection invocation method in 5.jdk1.7 ... I don't understand.


16. Class Loading Process
1. Get the binary byte stream that defines this class through the fully qualified name of a class
Includes:. Class, Jar, network, even real-time generation (dynamic Agent Java.lang.reflect.Proxy), other files (JSP) ...
2. Store the static data structure of the class represented by this byte stream in the method area (converted to a dynamic structure)
3. Generates a Java.lang.Class object representing the class in memory as all data access portals in the method area that access the class


17. Class validation Process

1. File Format Verification

class file conforms to specification, current virtual machine version is able to handle

2. Meta-data validation

For semantic Analysis: whether there is a parent class, or if all the methods in the inherited abstract class are implemented ...

3. Byte code Verification

Through data flow and control flow analysis, semantics are legitimate and further semantic analysis. (The value of an int is not written as Lang)

4. Symbolic Reference Verification

Occurs when a symbolic reference is converted to a direct application (the parsing phase) to check for permissions, and to successfully parse

18. The preparation phase of the class

Formally allocate memory for class variables and set variable initial values (0 and NULL), only class variables (static adornments), excluding instance variables


19. Class parsing

The parsing phase is the process of replacing a symbolic reference within a constant pool with a direct reference

The parsed action is for: Class or interface, field, class method, interface method, method type, method handle, call point qualifier

Symbolic reference: A set of symbols (strings) to describe the referenced target, which can make any form of literal, symbolic reference independent of the memory layout of the JVM, at which time the class can not be loaded into memory

Direct reference: A pointer to a target, a relative offset, or a handle that can be positioned indirectly to the target, directly referencing the memory layout, at which point the class must have been loaded into memory.

20. Initialization of Classes

Really start executing the Java program code defined in the class, the compiler collects the assignment statements of all variables in the class and the static statement blocks into the <clinit> method (be sure to execute the method of the parent class before executing the method, so the first execution of the <clinit> in all classes) Method must be Java.lang.Objer) and perform


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.