JVM-class file full parsing-method table set, jvm-class set
Method table set
The previous magic number, minor version number, main board number, constant pool entry, constant pool, access flag, class index, parent index, interface index set, and field table set, then the method table will be followed.
The method table is constructed like a field table, which contains several items in sequence: access_flags, name_index, descriptor_index, and attributes.
Method 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 |
Method access flag:
Flag name |
Flag Value |
Description |
ACC_PUBLIC |
0x00 01 |
Public |
ACC_PRIVATE |
0x00 02 |
Whether the method is private |
ACC_PROTECTED |
0x00 04 |
Whether the method is protected |
ACC_STATIC |
0x00 08 |
Whether the method is static |
ACC_FINAL |
0x00 10 |
Whether the method is final |
ACC_SYHCHRONRIZED |
0x00 20 |
Whether the method is synchronized |
ACC_BRIDGE |
0x00 40 |
Is the method generated by a compiler? |
ACC_VARARGS |
0x00 80 |
Whether the method accepts parameters |
ACC_NATIVE |
0x01 00 |
Whether the method is native |
ACC_ABSTRACT |
0x04 00 |
Is the method abstract? |
ACC_STRICTFP |
0x08 00 |
Is the method strictfp? |
ACC_SYNTHETIC |
0x10 00 |
Whether the method is automatically generated by the compiler |
The Java Code in the method is compiled into bytecode instructions by the compiler and stored in an attribute named "Code" in the method Attribute Table set, attribute tables are the most extended data items in the calss file format.
In Java, to overload a method, in addition to having the same simple name as the original method, you must also have a signature different from the original method, A feature signature is a set of field symbol references of each parameter in a method in the constant pool, because the return value is not included in the feature signature, therefore, the Java language cannot reload an existing method based on different return values. however, in the class file format, the feature signature has a wider range. As long as the descriptors are not completely consistent, the two methods can coexist. that is to say, if two methods have the same name and feature signature, but the return value is different, they can also coexist legally with the same class file.
Next, continue with the class file analyzed earlier.
Source file:
Constant pool for javap analysis:
Class File Analysis:
Directly look at the method table section (a bit messy). First, methods_count: 0x00 02 in the lower right corner indicates that there are two methods in the method set. access_flags: 0x00 01 indicates that the access flag value is 1, which corresponds to the public of the access flag table of the above method. The method of viewing the source file is indeed public. name_index: 0x00 07 indicates that the method name index is 7, corresponding to the above constant pool 7, which is "<init> ". decriptor_index: 0x00 08 indicates that the index value of the descriptor is 8, which corresponds to the "() v" of the above constant pool ". attributes_count: 0x00 01 indicates that the Attribute Table set of this method has an attribute. The index of the attribute name is 0x00 09, corresponding to the above constant pool 9 as "code ", this attribute is the bytecode description of the method.