Complete parsing of JVM-class file-field table set, jvm-class field

Source: Internet
Author: User
Tags field table uppercase character

Complete parsing of JVM-class file-field table set, jvm-class field
Field table set

This class file has been parsed for a long time. this section describes the category magic number, version number, main board number, constant pool entry, constant pool, access flag, class index, parent class index, and interface index set. the field table set should be included below. 

Then the set of interface indexes is the set of field tables.

The field table (field_info) is used to describe the variables declared in the interface or class. The fields include class-level variables and instance-level variables, but are not included in the local variables declared in the method.

Field table structure:

Type Name Quantity
U2 Access_flags 1
U2 Name_index 1
U2 Descriptor_index 1
U2 Attributes_count 1
Attribute_info Attributes Attributes_count

The field modifier is placed in the access_flags project. It is very similar to the access_flags project in the class and is a data type of u2.

Field access flag:

Flag name Flag Value Description
ACC_PUBLIC 0x00 01 Public field?
ACC_PRIVATE 0x00 02 Whether the field is private
ACC_PROTECTED 0x00 04 Whether the field is protected
ACC_STATIC 0x00 08 Whether the field is static
ACC_FINAL 0x00 10 Whether the field is final
ACC_VOLATILE 0x00 40 Whether the field is volatile
ACC_TRANSTENT 0x00 80 Whether the field is transient
ACC_SYNCHETIC 0x10 00 Is the Field automatically generated by the compiler?
ACC_ENUM 0x40 00 Whether the field is enum

The access_flags are followed by two index values: name_index and descriptor_index. They are references to the constant pool, representing the simple name of the field and the descriptor of the field method and method respectively.

The descriptor is used to describe the data type of the field, the list of parameters (including quantity, type, and order) of the method, and the return value. according to the descriptor rules, the basic data type and the void type that represents no return value are represented by an uppercase character, while the object type is represented by the character plus the full qualified name of the Object Name.

Description:

  

Identifier Description
B Basic Data Type byte
C Basic data type char
D Basic Data Type double
F Basic Data Type float
I Basic Data Type int
J Basic data type long
S Basic data type short
Z Basic data type boolean
V Basic Data Type void
L Object Type

For the array type, each dimension is described using a prefix "[" character. for example, it is defined as "java. lang. stirng [] "type two-dimensional array, will be recorded as:" [Ljava/lang/Stirng ", an integer array "int []" will be recorded as "[I ".

When a descriptor is used to describe a method, the parameters are described in the first parameter list and then the return value order. The parameter list is placed in a set of parentheses "()" In strict order.

Fields inherited from the parent class or the parent interface are not listed in the field table set, but fields that do not exist in the original Java code may be listed, 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. in addition, fields in Java cannot be reloaded. The data types and modifiers of the two fields must use different names, regardless of whether they are the same or not. However, for bytecode, if the descriptors of the connected fields are inconsistent, the field name duplication is legal.

 

Next we will continue with the class file analyzed above:

Source file:

  

The constant pool analyzed by javap:

  

Analysis:

From the analysis, we can see that 0x00 01 represents the number of data in the field table, only one. 0x00 02 indicates the private modifier of the field table, which can be seen from the access tag table above. 0x00 05 indicates that the field corresponds to 5th constant pools. From the constant pool analyzed by javap, we can see that 5th constant pools correspond to m, let's look at the source code. The defined field is m.0x00 06, which indicates the descriptor identifier. It corresponds to the 6th constant pool, which is I. Then, in the table that corresponds to the meaning of our access identifier, I corresponds to the int data type, and then the data type of source code m is indeed int.

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.