JVM-class file full parsing-Attribute Table set, jvm-class set

Source: Internet
Author: User
Tags field table

JVM-class file full parsing-Attribute Table set, jvm-class set
Attribute Table set

In front of magic number, minor version number, main board number, constant pool entry, constant pool, access flag, class index, parent index, interface index set, field table set, method table set, the next step is the set of attribute tables.

 

In the class file, field tables, and method tables, you can carry your own attribute table set (like the "code" Attribute Table used in the previous method table) used to describe specific information in some scenarios.

Pre-defined attributes in virtual machines:

Attribute name Usage location Description
Code Method table Bytecode commands compiled by Java code
ConstantValue Field table Constant pool defined by the final keyword
Deprecated Class, method, field table Methods and fields declared as deprecated
Exceptions Method table Method throw an exception
EnclosingMethod Class File This attribute is available only when a class is a local class or an anonymous class. This attribute is used to identify the peripheral method of the class.
InnerClass Class File Internal class list
LineNumberTable Code attributes Correspondence between the line numbers of Java source code and bytecode commands
LocalVariableTable Code attributes Description of the Method
StackMapTable Code attributes JDK1.6 adds attributes for the new type check validator to check and process the local variables of the target method and the class required by the operands for matching.
Signature Class, method table, and field table Used to support method signatures in the case of generics
SourceFile Class File Record source file name
SourceDebugExtension Class File Used to store additional debugging information
Synthetic Class, method table, and field table The flag method or field is automatically generated by the compiler.
LocalVariableTypeTable Class The feature signature is used to replace the descriptor. It is added to describe the generic parameterization type after the generic syntax is introduced.
RuntimeVisibleAnnotations Class, method table, and field table Support for dynamic annotations
RuntimeInvisibleAnnotations Table, method table, and field table Used to specify which annotations are invisible during runtime
RuntimeVisibleParameterAnnotation Method table The role is similar to the RuntimeVisibleAnnotations attribute, but the role object is a method
RuntimeInvisibleParameterAnnotation Method table Similar to the RuntimeInvisibleAnnotations attribute, Which of the following is a method parameter of the target object?
AnnotationDefault Method table Used to record the default values of annotation Elements
BootstrapMethods Class File Used to save the guide mode qualifier referenced by the invokeddynamic command

For each attribute, its name needs to reference a constant class representation of the CONSTANT_utf8_info type from the constant pool, while the structure of the attribute value is completely custom, you only need to specify the number of digits occupied by the attribute value in the u4 Length attribute area.

Structure defined by the Attribute Table:

Type Name Quantity
U2 Attribute_name_index 1
U2 Attribute_length 1
U1 Info Attribute_length

 

Code attributes

After the Code in the Java program method body is compiled and processed by Javac, the bytecode instruction is stored in the Code attribute. the Code attribute appears in the property set of the method table, but not all method tables have this attribute. for example, the method in an interface or class does not have the Code attribute.

After the bytecode command, the explicit exception handling table set of methods is used. The exception table is not required for the Code attribute.

Structure:

Type Name Quantity
U2 Attribute_name_index 1
U4 Attribute_length 1
U2 Max_stack 1
U2 Max_locals 1
U4 Code_length 1
U1 Code Code_length
U2 Prediction_table_length 1
Prediction_info Prediction_table Prediction_length
U2 Attributes_count 1
Attribute_info Attributes Attributes_count

Exceptions attributes

The Exception attribute is used to list the checked Exceptions that can be thrown in a method, that is, the Exceptions listed after the throws keyword in the method description.

Structure:

Type Name Quantity
U2 Attribute_name_index 1
U2 Attribute_lrngth 1
U2 Attribute_of_exception 1
U2 Prediction_index_tsble Number_of_exceptions

The number_of_exceptions item in the Exception attribute indicates the number_of_exceptions type query Exception that the method may throw. Each kind of query Exception is indicated by a prediction_index_tsble item, which indicates an index pointing to a CONSTANT_Class_info type constant in the constant, indicates the type of the query exception.

LineNumberTable attributes

Structure:

Type Name Quantity
U2 Attribute_name_index 1
U4 Attribute_length 1
U2 Line_number_table_length 1
Line_number_info Line_number_table Line_number_table_length

Line_number_table is a set of line_number_table_length and line_number_info types. The line_number_info table includes two u2 data items, start_PC and line_number. The former is the bytecode line number and the latter is the Java source code line number.

 

If there are more than 20 predefined Virtual Machine attributes, we will not describe them one by one. Basically, these attributes are similar to the previous ones.

The file parsing of the calss file has finally come to an end. (For a long time, I hate to read these bytecode most, in fact, programmers only need to understand the composition and principle of the class file. There are many tools for parsing the class file, so we can directly view the parsed file ).

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.