Field table Collection
The parsing of this class file is a bit too long to parse. The above describes the magic number, minor version number, motherboard number, constant pool entry, constant pool, access flag, class index, parent class index, and interface index collection. The following should be a collection of field tables.
Immediately following the interface index collection is the collection of the field tables.
A field table (Field_info) is used to describe an interface or a variable declared in a class. Fields include class-level variables and instance-level variables, but do not include local variables declared inside a method.
Structure of the Field table:
Type |
Name |
Number |
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, which is very similar to the Access_flags project in the class and is a U2 data type.
Field Access Flags:
Flag Name |
Flag value |
Meaning |
Acc_public |
0x00 01 |
Whether the field is public |
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 |
Whether the field is automatically generated by the compiler |
Acc_enum |
0x40 00 |
Whether the field is an enum |
Following the ACCESS_FLAGS flag are two index values: Name_index and Descriptor_index, which are references to constant pools, each representing the simple name of the field and the descriptor of the field method and method.
Descriptors are used to describe the data type of a field, the parameter list of a method (including quantity, type, and order), and the return value. Depending on the descriptor rules, both the base data type and the void type representing no return value are represented by an uppercase character, whereas the object type is represented by the fully qualified name of the multibyte L plus object name.
Descriptor flag Meaning:
Marker |
Meaning |
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 an array type, each dimension is described with a predecessor "[" character. A two-dimensional array, defined as a type of "java.lang.stirng[", will be recorded as: "[[Ljava/lang/stirng], an integer array" int[] "will be recorded as" [I ".
When describing a method with a descriptor, it is described in the order of the first parameter list, followed by the return value, and the parameter list is placed within a set of parentheses "()" in the strict order of the parameters.
Fields inherited from the parent or parent interfaces are not listed in the Field table collection, but it is possible to list fields that do not exist in the original Java code, such as in an inner class that, in order to maintain access to the external class, automatically adds a field to the external class instance. In addition, fields in the Java language cannot be overloaded, the data types of two fields, and modifiers, regardless of whether they are the same, must use different names, but for bytecode, if the descriptor of a field is inconsistent, the name of the field is legal.
Continue with the previously parsed class file:
Source file:
JAVAP analyzed the Chang:
Analysis:
From the analysis you can see that 0x00 01 represents the Number of field table data, only one. 0x00 02 represents the private modifier of the field table, which can be seen from the field Access flag table above. 0x00 05 indicates that the field corresponds to the 5th constant pool, the constant pool analyzed from JAVAP, you can see that the 5th constant pool corresponds to M, and then the source code we define the field is actually M. 0x00 06 represents the descriptor identifier, corresponding to the 6th constant pool, for I, then in correspondence with our Access identifier meaning table, I corresponds to the int data type, and then the data type of the source code m is indeed int.
Jvm-class file full parse-field table collection