[Go deep into Java Virtual Machine] 2: Class file structure

Source: Internet
Author: User
Tags field table

 

 

The unsigned number belongs to the basic data type. u1, u2, u4, and u8 represent the unsigned number of 1, 2, 4, and 8 bytes respectively. A table is a data type that consists of multiple unsigned numbers or other tables as data items. All Tables habitually end with "_ info.

(), Its only function is to determine whether the file is a Class file that can be accepted by the virtual machine. Its value is fixed to 0 xCAFEBABE. The four bytes of magic store the minor version number and major version number of the Class file. The later version of JDK can be backward compatible with the lower version of the Class file, but cannot run a later version of the Class file.

(), Which is the data type most associated with other projects in the Class file and one of the Data projects that occupy the largest Class file space.

The literal volume is similar to the Java-level constant concepts, such as text strings and constants declared as final. Symbolic references include the following three constants:

  • A symbolic reference is a set of symbols used to describe the referenced object. A symbolic reference can be a literal of any form and can be used to locate the object without ambiguity. Symbol reference has nothing to do with the memory layout implemented by the virtual machine. The referenced target is not necessarily loaded into the memory.
  • : Direct reference can be a pointer to the target, a relative offset, or a handle that can be indirectly located to the target. Direct reference is related to the memory layout implemented by virtual machines. The direct reference translated by the same symbol reference on different virtual machine instances is generally not the same. If direct reference is available, the referenced target must already exist in the memory.

 

CONSTANT_Utf8_info

The value is

Length

U2

UF-8

Bytes

U1

The length is

 

CONSTANT_Integer_info

Tag

U1

The value is

Bytes

U4

Stored in front

 

CONSTANT_Float_info

Tag

U1

The value is

Bytes

U4

Stored in front

 

CONSTANT_Long_info

Tag

U1

The value is

Bytes

U8

Stored in front

 

CONSTANT_Double_info

Tag

U1

The value is

Bytes

U8

Stored in front

 

CONSTANT_Class_info

Tag

U1

The value is

Index

U2

Index pointing to a constant with a fully qualified name

 

CONSTANT_String_info

Tag

U1

The value is

Index

U2

Index pointing to the string literal

 

CONSTANT_Fieldref_info

Tag

U1

The value is

Index

U2

Class or interface descriptor pointing to declared Fields

Index

U2

Field name and type descriptor

 

CONSTANT_Methodref_info

Tag

U1

The value is

Index

U2

Class descriptor pointing to the declared Method

Index

U2

Method Name and type descriptor

 

CONSTANT_InrerfaceMethodref_info

Tag

U1

The value is

Index

U2

Interface descriptor pointing to the declared Method

Index

U2

Method Name and type descriptor

 

CONSTANT_NameAndType_info

Tag

U1

The value is

Index

U2

Index of a constant project pointing to a field or method name

Index

U2

Index pointing to this field or constant item of the method Descriptor

After the constant pool ends, the next two bytes represent the access_flag, which is used to identify access information at the Class or interface level, including whether the Class is a Class or an interface, whether it is defined as public or abstract, whether it is declared as final if it is a class, and so on. Each type of access information is represented by a hexadecimal flag value. If there are multiple types of access information at the same time, the obtained flag value is the logic or of the Flag values of these types of access information.

This_class, super_class, interfaces

Below is the most format of the field table:

Int m = 2; then there may be an attribute named ConstantValue, which points to constant 2. For more information about attribute_info, see the following description of the Attribute Table project.

For example, in the internal class, in order to maintain access to the external class, the field pointing to the external class instance is automatically added.

If the method table has the Code attribute, its structure will be shown in the following table:

) An exception occurs when the type is catch_type or its subclass (catch_type is the index pointing to a CONSTANT_Class_info constant ).The situation in this article.

). If the variable is not modified by final, or is not of the basic type or string, initialize the variable in the <clinit> method.

In addition, the attribute value of ConstantValue is only limited to the basic type and String type, which is obvious because it can only reference the literal values of the basic type and String type from the constant pool.

The following briefly describes the differences among final, static, and final modified field values:

 

 

 

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.